Define a HID Report Descriptor snippet:
0x06, 0x00, 0xFF, // Usage Page (Vendor Defined)
0x09, 0x01, // Usage (Calibration)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8 bits)
0x95, 0x08, // Report Count (8 bytes)
0x82, 0x02, 0x01, // Feature (Data,Var,Vol)
In your driver’s SetFeatureReport handler, parse the 8 bytes, validate, and store calibration.
Best Practice: Do not require device reset during calibration update. Apply new parameters immediately to the next touch sample.
If you are adhering to the Microsoft HID over I2C specification, the protocol defines a specific response packet: HIDI2C_DEVICE_RESPONSE.
When the host requests the Report Descriptor, the device (or the driver acting as the device) responds. kmdf hid minidriver for touch i2c device calibration best
Example Calibration Logic (Matrix Transformation): $$X_cal = (X_raw \times A) + (Y_raw \times B) + C$$ $$Y_cal = (X_raw \times D) + (Y_raw \times E) + F$$
Where $A, B, C, D, E, F$ are the calibration coefficients.
The typical pipeline:
Touch HW → I2C → KMDF HID Minidriver → HID Class Driver → Windows Touch Input
|
Calibration (transform)
The minidriver receives raw HID reports (touch, pressure, contact ID, etc.), applies a calibration transform, and forwards modified reports up the stack. Define a HID Report Descriptor snippet: 0x06, 0x00,
When a touch interrupt fires:
Critical Optimization: Perform calibration in EvtInterruptDpc (DISpatch level), not at high IRQL. Avoid floating-point math; use fixed-point integers for speed.
Run !wdfkd.wdfverifier in WinDbg. The best drivers pass all KMDF rule checks (e.g., WdfDeviceInitApi, RequestReuse). Calibration IOCTLs must never leak WDFREQUEST objects.
Implement a second IOCTL to delete the registry key and send a "Reset to Factory" Feature Report (usually Report ID 0x01, byte 2 = 0x01). This is critical for field maintenance. In your driver’s SetFeatureReport handler, parse the 8
| Pitfall | Consequence | Solution | |---------|-------------|----------| | Modifying HID descriptor after calibration | Touch input fails HID validation | Never change descriptor; always post-process | | Applying calibration twice | Incorrect coordinates | Flag raw vs calibrated reports clearly | | Blocking in touch report path | High touch latency, dropped contacts | Do not wait for locks; use try-lock or copy parameters quickly | | Ignoring contact ID | Multi-touch confusion | Calibrate X/Y per contact, keep contact ID unchanged | | Not clamping values | Overflow in HID class driver | Clamp to logical max defined in descriptor |
Modern touch controllers—found on laptops, industrial panels, and embedded systems—commonly communicate via the I²C bus. In Windows, these devices are often managed by a HID over I²C protocol stack. While the inbox HIDI²C driver works for many generic devices, custom silicon or specific form factors require a KMDF HID Minidriver.
This article explores the architecture of a KMDF HID Minidriver for I2C touch devices and, most critically, how to implement robust calibration to ensure accurate touch-to-display mapping across different screen resolutions, rotations, and manufacturing variances.