Kmdf Hid Minidriver For Touch I2c Device Calibration Best 💯 Quick
Implementing a KMDF HID Minidriver for I2C touch devices requires navigating a unique "driver pair" architecture. Because the HID class driver ( hidclass.sys
) must own the driver dispatch table, a standard KMDF driver cannot act as the function driver directly. Instead, you must use a lower filter driver
model where a minimal WDM driver handles the HID registration and forwards requests to your KMDF filter. Microsoft Learn Architecture & Calibration Best Practices
For touch device calibration, accuracy depends on how the driver handles coordinate mapping and data persistence. Calibration Persistence : Store calibration data (matrices or offsets) in the device's hardware registry key or the driver's Parameters\Wdf
subkey. This ensures that calibration settings survive reboots and driver updates. Coordinate Mapping kmdf hid minidriver for touch i2c device calibration best
: Ensure your driver maps raw I2C controller values to the expected Windows HID units. Some touch drivers require sending coordinates in specific increments, such as 4ths of a pixel. HID Descriptor Accuracy HID Minidriver Sample
to test your report descriptor. A common pitfall in touch calibration is an incorrectly defined LOGICAL_MAXIMUM for the X and Y axes, which causes scaling errors. Power Management Stability
: I2C controllers often have aggressive power management. For stable calibration and touch response, it is a best practice to disable "Allow the computer to turn off this device to save power" in the Intel Serial IO I2C Host Controller properties. Toradex Community Implementation Workflow Driver Initialization WdfFdoInitSetFilter EvtDriverDeviceAdd callback to define your driver as a lower filter. I/O Queue Handling : Create queues to process IOCTLs passed from MsHidKmdf.sys . You must handle specific WDF HID Minidriver IOCTLs to report device capabilities. User-Space Interaction
: For end-user calibration tools, leverage the built-in Windows Tablet PC Settings tool to generate the calibration matrix. Hardware Verification Implementing a KMDF HID Minidriver for I2C touch
: Before software debugging, use I2C tools to confirm the device is detected at the expected address (e.g., ) on the bus. Toradex Community Troubleshooting Common Issues
8. Conclusion
Implementing calibration inside a KMDF HID Minidriver for I2C touch gives OEMs and driver developers fine-grained control over touch accuracy. By following these best practices—registry-based parameters, DPC-level transformation, support for dynamic updates, and careful edge handling—you ensure a seamless, responsive, and accurate touch experience across devices and display configurations.
The line between firmware and driver calibration is often blurred, but when your touch controller’s raw data needs just a little extra polish, the KMDF minidriver is the right place to do it—cleanly, safely, and efficiently.
Further Reading:
- MSDN: HID Over I²C Protocol Specification
- KMDF I²C Target Samples (GitHub: Windows-driver-samples)
- Windows Touch Input Stack Internals
2.1 Typical I2C Transaction for Touch
A touch controller (e.g., Goodix, Elan, Cypress) exposes registers:
- Device ID register (0x00)
- Mode register (0x40 for calibration)
- Finger count + coordinates (burst read from 0x50)
Your KMDF driver must handle:
- I2C read/write via
SpbRequestXxx(SPB – Simple Peripheral Bus). - Interrupt management – Typically, a GPIO pin (touch interrupt) triggers the driver to read data.
3. Calibration Model: Linear + Optional Polynomial
Most I²C touch devices provide sufficiently linear output. A 2D affine transformation is often enough:
X_display = A * X_raw + B * Y_raw + C
Y_display = D * X_raw + E * Y_raw + F
For many touchscreens (single-touch or MT), this simplifies to scaling and offset: Further Reading:
X_display = (X_raw - X_min) * (DisplayWidth / (X_max - X_min))
Y_display = (Y_raw - Y_min) * (DisplayHeight / (Y_max - Y_min))
3. Stress Testing with KMDF Verifier
Run !wdfkd.wdfverifier in WinDbg. The best drivers pass all KMDF rule checks (e.g., WdfDeviceInitApi, RequestReuse). Calibration IOCTLs must never leak WDFREQUEST objects.
Part 3: Implementing Calibration in the KMDF HID Minidriver
Here is the step-by-step implementation of a calibration subroutine within a KMDF HID minidriver for an I2C touch device.