Kmdf Hid Minidriver For Touch I2c Device Calibration [better] (SIMPLE · Fix)
A core feature for a KMDF HID minidriver on I2C touch devices is Linearization-based Coordinate Remapping. This feature corrects physical misalignment (e.g., inverted axes or "small box" scaling) by applying a transformation matrix to raw I2C touch coordinates before they are wrapped into a HID report. Coordinate Remapping Feature This feature intercepts raw
data from the I2C bus and recalculates them based on calibration coefficients stored in the registry or device firmware.
Dynamic Scaling: Scales raw touch digitizer resolution to match the actual display resolution.
Axis Flipping/Swapping: Fixes "mirrored" touch input or portrait/landscape mismatches.
Linear Correction: Adjusts for manufacturing tolerances where touch points don't perfectly align with the LCD grid. Implementation Architecture
In a KMDF HID architecture, your driver acts as a lower filter beneath MsHidKmdf.sys.
Registry Persistence: Store calibration parameters in HKLM\HARDWARE\DEVICEMAP\TOUCH\CalibrationData to persist across reboots.
IOCTL Handling: Implement an EvtIoDeviceControl callback to process custom IOCTLs from a user-space calibration tool. Data Processing Loop: Read raw data from I2C. Apply the transformation formula:
Xfinal=(A×Xraw)+(B×Yraw)+Ccap X sub f i n a l end-sub equals open paren cap A cross cap X sub r a w end-sub close paren plus open paren cap B cross cap Y sub r a w end-sub close paren plus cap C
Yfinal=(D×Xraw)+(E×Yraw)+Fcap Y sub f i n a l end-sub equals open paren cap D cross cap X sub r a w end-sub close paren plus open paren cap E cross cap Y sub r a w end-sub close paren plus cap F Pass the corrected to the HID class driver. Maintenance & Troubleshooting
Power Management: Ensure "Allow the computer to turn off this device" is disabled in Device Manager to prevent calibration loss during sleep states.
Manual Reset: If the driver fails to load the new calibration, a "Disable/Enable" cycle in Device Manager can force a re-initialization of the device extension and registry values.
💡 Key Tip: Use the vhidmini2 sample from Windows Driver Samples as a starting point for handling HID report descriptors and I2C IO requests. To help you implement this, would you like: A C++ code snippet for the coordinate transformation? kmdf hid minidriver for touch i2c device calibration
A template for the INF file to set default calibration values?
Guidance on handling multi-touch (MT) report descriptors specifically? Creating WDF HID Minidrivers - Windows drivers
KMDF HID Minidriver for Touch I2C Device is a kernel-mode framework driver used extensively in Windows tablets and 2-in-1 devices (such as Chuwi, Irbis, and Thomson) to bridge communication between the I2C bus and the Windows HID class driver. While it provides the essential interface for touch functionality, it is frequently cited in user reviews for precision and calibration issues following Windows updates or clean installations. Performance Review & Critical Issues Inversion & Accuracy Problems:
Users commonly report that the touchscreen becomes horizontally or vertically inverted, or that touch input is restricted to a small box in the center of the screen. Calibration Failures:
Standard Windows calibration tools often fail to fix these issues because they are typically caused by a mismatch between the driver version and the specific touch panel firmware (e.g., Silead or MSSL1680). Power Management Bugs:
A known flaw involves the driver failing to restart after the device enters sleep mode. Disabling "Allow the computer to turn off this device to save power" in Device Manager is a standard fix. CHUWI | Official Forum Uninstalled KMDF HID Minidriver for Touch I2C Device
KMDF HID Minidriver for Touch I2C Device is a kernel-mode driver framework (KMDF) solution used by Windows to enable communication between a touch screen and the system via the
. Calibration issues with this driver often manifest as inverted axes, offset touch points, or dead zones. Troubleshooting Calibration Issues
If your touch screen is misaligned or non-responsive, follow these steps to reset or calibrate the driver: Standard Windows Calibration Search for "Calibrate the screen for pen or touch input" in the Start menu. If the option is missing, try running the Device Diagnostic Tool or using the command prompt to force the utility to open. Driver Reset & Reinstallation Device Manager by right-clicking the Start button. Human Interface Devices Right-click I2C HID Device HID-compliant touch screen and select Uninstall device
Restart your computer; Windows will automatically reinstall the driver. Power Management Fix
Many calibration or "frozen" touch issues are caused by the system turning off the I2C controller to save power. Device Manager System devices , right-click Intel Serial IO I2C Host Controller (or similar), and select Properties Power Management tab, uncheck "Allow the computer to turn off this device to save power" Developer & Advanced Information
For developers working with Silead-based or custom touch controllers: A core feature for a KMDF HID minidriver
Introduction to HID Over I2C - Windows drivers - Microsoft Learn
Introduction
The KMDF HID minidriver is a kernel-mode driver that enables communication between the operating system and a touch I2C device. The minidriver is responsible for calibrating the touch device, which involves adjusting the device's settings to ensure accurate touch detection and reporting.
Overview of KMDF HID Minidriver
The KMDF HID minidriver is a type of kernel-mode driver that uses the Kernel-Mode Driver Framework (KMDF) to interact with the operating system. The minidriver is designed to work with HID devices, which include touchscreens, touchpads, and other human interface devices.
The KMDF HID minidriver provides a set of APIs that allow the operating system to communicate with the touch I2C device. These APIs include:
HidStart: Starts the minidriver and initializes the touch device.HidStop: Stops the minidriver and releases any resources allocated for the touch device.HidRead: Reads data from the touch device, such as touch coordinates and button presses.HidWrite: Writes data to the touch device, such as calibration settings.
Calibration of Touch I2C Device
The calibration process for a touch I2C device involves adjusting the device's settings to ensure accurate touch detection and reporting. The calibration process typically involves the following steps:
- Initialization: The minidriver initializes the touch device and sets default calibration settings.
- Data Collection: The minidriver collects data from the touch device, such as touch coordinates and sensor readings.
- Calibration Algorithm: The minidriver applies a calibration algorithm to the collected data to determine the optimal calibration settings for the touch device.
- Settings Update: The minidriver updates the touch device's settings with the new calibration values.
KMDF HID Minidriver for Touch I2C Device Calibration
The KMDF HID minidriver for touch I2C device calibration provides a set of APIs and callback routines that allow the operating system to interact with the touch device and perform calibration.
The minidriver uses the following components to perform calibration:
- HidCalibrate: A callback routine that is called by the operating system to perform calibration.
- HidGetCalibrationData: A routine that retrieves calibration data from the touch device.
- HidSetCalibrationData: A routine that sets calibration data on the touch device.
Example Code
Here's an example code snippet that demonstrates how to use the KMDF HID minidriver to calibrate a touch I2C device:
#include <wdf.h>
#include <hid.h>
// Define the calibration data structure
typedef struct _CALIBRATION_DATA
ULONG ulXScale;
ULONG ulYScale;
ULONG ulXOffset;
ULONG ulYOffset;
CALIBRATION_DATA, *PCALIBRATION_DATA;
// Define the HidCalibrate callback routine
VOID HidCalibrate(
_In_ WDFDEVICE Device,
_In_ PCALIBRATION_DATA CalibrationData
)
// Perform calibration algorithm
// ...
// Update touch device settings with new calibration values
HidSetCalibrationData(Device, CalibrationData);
// Define the HidGetCalibrationData routine
NTSTATUS HidGetCalibrationData(
_In_ WDFDEVICE Device,
_Out_ PCALIBRATION_DATA CalibrationData
)
// Read calibration data from touch device
// ...
return STATUS_SUCCESS;
// Define the HidSetCalibrationData routine
NTSTATUS HidSetCalibrationData(
_In_ WDFDEVICE Device,
_In_ PCALIBRATION_DATA CalibrationData
)
// Write calibration data to touch device
// ...
return STATUS_SUCCESS;
Conclusion
In conclusion, the KMDF HID minidriver for touch I2C device calibration provides a set of APIs and callback routines that enable the operating system to interact with the touch device and perform calibration. The minidriver uses a calibration algorithm to determine the optimal calibration settings for the touch device and updates the device's settings with the new calibration values.
By using the KMDF HID minidriver, developers can create custom calibration solutions for touch I2C devices, ensuring accurate touch detection and reporting.
Part 4: Step-by-Step Implementation Guide
5. I2C Communication for Calibration
Since the driver does not directly own the I2C controller (HIDI2C.sys does), use WDF I2C target to send vendor commands.
9. Testing and Certification
- HLK Tests – Run HID I²C and HID Digitizer tests. Calibration must not break HID compliance.
- Performance – Calibration adds < 1 ms per report; use integer math, avoid floating point in ISR.
- Security – Validate IOCTL input to prevent buffer overruns; require admin or restricted token for calibration IOCTL.
Part 6: User-Mode Calibration Application – The Companion Tool
Your KMDF driver alone cannot perform calibration; it only applies it. A user-mode application must guide the user, collect points, compute coefficients, and call DeviceIoControl.
High-level flow of the calibration tool:
- Display targets: Show five crosshairs (center, four corners).
- Collect raw points: For each target, call
IOCTL_TOUCH_CALIBRATE_GET_RAWand record the I2C-reported coordinates. - Compute mapping: Solve the least-squares transformation matrix.
- Send coefficients: Call
IOCTL_TOUCH_CALIBRATE_SET_COEFFS. - Verify: Ask user to touch test points and validate.
This application must run with administrative privileges, as it modifies kernel-mode driver state.
2.1 Stack Diagram
User Mode (Touch input)
↑
[Windows USER32 | Touch Injection]
↑
[Microsoft HID Class Driver (hidclass.sys)]
↑
[KMDF HID Minidriver – MyTouchCalib.sys] ← Calibration logic here
↑
[SPB/I²C Controller Driver (SpbCx.sys or i2cstub.sys)]
↑
[I²C Touch Device Hardware]
Driver Entry and Device Initialization
Your driver's DriverEntry will create a WDFDRIVER object and register EvtDeviceAdd. Inside EvtDeviceAdd:
NTSTATUS DeviceAdd(WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit) // Indicate this is a HID minidriver WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_KEYBOARD); // Or appropriate type// Set up power management for I2C wake WdfDeviceInitSetPowerPolicyOwnership(DeviceInit, FALSE); // Configure I2C connection using resource list PVIDEO_PNP_DEVICE pDev = CreateDeviceContext();