Kmdf Hid Minidriver For Touch I2c Device Calibration -
NTSTATUS EvtHidDeviceReadReport(DEVICE_OBJECT *DeviceObject, PHID_XFER_PACKET Packet)
// Clamp to HID Logical range (e.g., 0..32767) calibratedX = max(0, min(32767, calibratedX)); calibratedY = max(0, min(32767, calibratedY));
// Get raw X,Y from Packet->Buffer USHORT rawX = *(PUSHORT)(Packet->Buffer + X_OFFSET); USHORT rawY = *(PUSHORT)(Packet->Buffer + Y_OFFSET); // Apply calibration LONG calibratedX = (LONG)(rawX * CalibA + rawY * CalibB + CalibC); LONG calibratedY = (LONG)(rawX * CalibD + rawY * CalibE + CalibF); Kmdf Hid Minidriver For Touch I2c Device Calibration
// Write back *(PUSHORT)(Packet->Buffer + X_OFFSET) = (USHORT)calibratedX; *(PUSHORT)(Packet->Buffer + Y_OFFSET) = (USHORT)calibratedY;
[ User Mode ] Touch API (WM_POINTER) ↑ [ Kernel Mode ] HID Class Driver (hidclass.sys) ↑ HID Transport Minidriver (Your Driver) ↑ KMDF I2C Lower Filter / HIDI2C Shim ↑ I2C Controller Driver (SpbCx) Your minidriver must implement the HID_DEVICE_EXTENSION structure and callback functions defined in hidport.h . However, for I2C calibration, we typically implement a (using HID_TRANSPORT_MINIDRIVER_REGISTRATION ) that attaches to the existing HID-I2C transport. 3. The Calibration Model: Linear Transformation Touchscreen calibration is a projective transformation. For most industrial I2C devices, we assume a simple linear mapping: NTSTATUS EvtHidDeviceReadReport(DEVICE_OBJECT *DeviceObject
While user-space calibration tools exist, they fail before the logon screen or during OS recovery environments. The industry solution is a that intercepts, transforms, and corrects touch coordinates at the HID report level. 2. Architecture of a KMDF HID Minidriver A HID minidriver is not a full HID class driver; it is a lightweight adapter that sits between the HID class driver ( HIDCLASS.SYS ) and the I2C controller driver ( HIX2C.SYS or SPB ).
X_screen = A * X_touch + B * Y_touch + C Y_screen = D * X_touch + E * Y_touch + F Where (X_touch, Y_touch) are raw ADC/register values from the I2C device, and (X_screen, Y_screen) are the final HID coordinates reported to the OS. 0..32767) calibratedX = max(0
// Write screen resolution to controller's internal mapping I2C_Write(Device, GT911_X_RESOLUTION, SCREEN_WIDTH); I2C_Write(Device, GT911_Y_RESOLUTION, SCREEN_HEIGHT); // Now the controller itself produces transformed coordinates
#define GT911_X_RESOLUTION 0x8140 // Register for max X #define GT911_Y_RESOLUTION 0x8142 // Register for max Y VOID ApplyHardwareCalibration(WDFDEVICE Device)
| Method | Storage Location | Read Access in Driver | Use Case | |--------|----------------|----------------------|-----------| | | \_SB.I2C0.TS1.CALX , CALY | IoGetDeviceProperty + ACPI parser | Firmware-defined, immutable | | Registry | HKLM\SYSTEM\CurrentControlSet\...\Parameters | RtlQueryRegistryValues | User-modifiable, dynamic | | Private IOCTL | Passed from service | EvtIoDeviceControl | Live calibration from UI app |