Skip to main content

Kmdf Hid Minidriver For Touch I2c Device Calibration Info

For a KMDF HID minidriver targeting an I2C touch device, calibration is typically handled at the operating system level via standard Windows tools or by injecting specific registry parameters that the driver reads to modify incoming raw coordinates. 1. Identify Calibration Registry Path

Windows stores calibration data for touch devices in a specific registry location. If your driver needs to apply a static offset or scale factor at boot, it should query this path or its own device parameters.

Registry Path: HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\TOUCH\CalibrationData.

Driver Implementation: Use WdfRegistryOpenKey and WdfRegistryQueryValue in your EvtDeviceAdd or a specialized initialization function to read these values. 2. Implement Coordinate Transformation

In your minidriver’s HID Report processing logic, apply the calibration math before passing the data to the HID class driver. Read Raw Data: Receive the I2C packet containing Xrawcap X sub r a w end-sub Yrawcap Y sub r a w end-sub

Apply Transformation: Use a linear transformation matrix to adjust for rotation, inversion, or scaling issues. Inversion Example: If the -axis is flipped,

Coordinate Mapping: Ensure the coordinates match the logical range defined in your HID Report Descriptor (e.g., 0 to 4095). 3. Use Windows Native Calibration Tool

The preferred method for user-driven calibration is the built-in Windows tool. This generates the necessary registry entries that the OS uses to map HID inputs to screen pixels. Process: Open Control Panel. Select Tablet PC Settings. Click Calibrate under the Display tab.

Resetting: If calibration becomes corrupted, use the Reset button in the same menu to clear the registry data and return to the driver's default mapping. 4. Verify HID Report Descriptors

Calibration issues are often caused by mismatches in the HID Report Descriptor. Ensure your descriptor accurately defines the physical and logical extents of the touch surface.

Logical Maximum: Must match the highest coordinate value your firmware can produce.

Physical Maximum: Should represent the actual physical size (e.g., in millimeters) to help Windows scale the input correctly. 5. Troubleshooting Common Issues Uninstalled KMDF HID Minidriver for Touch I2C Device

The KMDF (Kernel-Mode Driver Framework) HID minidriver serves as the critical communication bridge between a Touch I2C controller and the Windows Input Stack. When dealing with touch hardware, raw electrical signals must be translated into precise screen coordinates. Without proper calibration, a user’s tap may register inches away from the actual contact point.

This guide explores the architecture, implementation, and calibration strategies for developing a KMDF HID minidriver for I2C touch devices. 1. Architecture of a HID I2C Minidriver

In the Windows Driver Model, a HID minidriver does not act alone. It fits into a specific stack:

HID Class Driver (mshidkmdf.sys): Provided by Microsoft, this handles the heavy lifting of HID report parsing and interfacing with the operating system.

Your KMDF Minidriver: This is the "glue" code. It talks to the I2C controller using the SPB (Simple Peripheral Bus) framework and reports data back to the HID Class Driver.

I2C Controller Driver: Manages the physical clock and data lines (SDA/SCL) on the SoC.

Your primary goal is to map the specific I2C registers of your touch hardware into standard HID Input Reports. 2. Defining the HID Report Descriptor kmdf hid minidriver for touch i2c device calibration

Before calibration can happen, the OS must understand what the device is. The HID Report Descriptor defines the touch surface's capabilities:

Logical Minimum/Maximum: The raw range of the ADC (e.g., 0 to 4095).

Physical Minimum/Maximum: The actual size of the panel in millimeters. Usage Page: Digitizers (0x0D). Usage: Touch Screen (0x04).

Calibration Tip: If your hardware raw values don't match the aspect ratio of the screen, the HID descriptor is where you first define the "Logical" boundaries to prevent initial distortion. 3. Implementing Calibration Logic

Calibration for touch devices generally addresses three issues: Scaling, Offset, and Orientation. Scaling and Resolution Mapping

Most I2C touch controllers output raw coordinates based on the internal resolution of the touch IC (e.g., 12-bit depth). To calibrate this in the minidriver:

Capture Raw Data: Read the X and Y bytes from the I2C register.

Apply Gains: Multiply the raw value by a calibration factor if the active touch area is smaller than the sensor grid.

Normalization: Convert the raw data to the Logical Maximum defined in your HID descriptor. Offset Correction

Mechanical misalignment can cause a constant shift in coordinates. Formula: Calculated_X = (Raw_X - X_Offset)

Implementation: These offsets should ideally be stored in the Registry or an ACPI _DSD (Device Specific Data) method so the driver can load them at boot without hardcoding values. Axis Inversion and Swapping

Depending on how the touch panel is mounted (0°, 90°, 180°, 270°), you may need to: Swap X and Y. Invert an axis: Final_X = Logical_Max_X - Calculated_X. 4. Handling Interrupts and Data Retrieval

Touch devices are interrupt-driven. Your KMDF driver must implement an EvtInterruptIsr or a Passive-level interrupt handling strategy:

Interrupt Fires: The touch hardware pulls the GPIO line low.

Work Item/DPC: The driver schedules a read operation over the I2C bus.

I2C Read: Retrieve the "Touch Digit" packet (usually containing Status, X-coord, Y-coord, and Contact ID).

Calibration Transformation: Apply the math discussed in Section 3.

Complete the Request: Send the processed HID report up the stack via WdfRequestComplete. 5. Storing Calibration Data For a KMDF HID minidriver targeting an I2C

Hardcoding calibration values is poor practice. Use one of these three methods for a professional KMDF implementation:

Registry Keys: Use WdfDeviceOpenRegistryKey. This allows user-space calibration tools (like a "Calibrate your screen" app) to write values that the driver reads during EvtDeviceSelfManagedIoInit.

ACPI Tables: For embedded systems, the BIOS/Firmware can pass calibration constants via the _DSD method in the ACPI table.

Configuration Files: Some drivers read a .ini or .bin file from System32\Drivers, though this is less common in modern KMDF designs. 6. Testing and Validation

Once the minidriver is deployed, use these tools to verify calibration:

HIDView: A tool to inspect the raw HID reports reaching the OS.

Digitizer Calibration Tool (Windows): Found in the Control Panel, this allows for a 4-point or 16-point calibration that creates an overlay transformation in the OS.

Input Test Tool: Part of the Windows Hardware Lab Kit (HLK), used to ensure the device meets "Windows Touch" certification standards for linearity and latency. Conclusion

Developing a KMDF HID minidriver for a touch I2C device requires a deep understanding of both the SPB framework and the HID specification. By implementing robust calibration logic—handling scaling, offsets, and orientation within the driver—you ensure a seamless and intuitive user experience. Always prioritize moving calibration constants out of the code and into the firmware or registry to allow for hardware variance across different production batches.

To help you refine the calibration logic, would you like to see a C++ code snippet for the coordinate transformation function or a sample HID Report Descriptor for a multi-touch device?


2.1 The HID Stack Overview

In most cases, hidi2c.sys is sufficient. However, it does NOT support custom calibration. It forwards raw HID reports directly from the I2C device to the HID class driver. To inject calibration, we must replace or layer our own KMDF HID Minidriver.

6.1 Driver Verification

4.6 Dynamic Calibration – IOCTL Interface

To support calibration changes at runtime (e.g., from a user-mode calibration app), you implement a custom IOCTL handler:

NTSTATUS TouchCalibEvtIoDeviceControl(WDFQUEUE Queue, WDFREQUEST Request, ...)
switch (ControlCode)
case IOCTL_SET_TOUCH_CALIBRATION:
            // Read calibration matrix from user buffer
            WdfRequestRetrieveInputBuffer(Request, sizeof(CALIB_PARAMS), ¶ms, &length);
            // Store in device context safely
            WdfDeviceGetDeviceContext(Device)->CalibParams = updatedParams;
            break;

The user-mode calibration tool can then call DeviceIoControl to update coefficients without a driver reload.


Part 8: Deployment and Certification

Why This Feature is Critical

  1. Reliability: I2C Touch devices are often connected via internal buses that reset during sleep/wake cycles. Without this feature, the touch screen might lose sensitivity or accuracy after the laptop lid is closed and reopened.
  2. Windows Hardware Compatibility: Microsoft's HID I2C specifications encourage storing calibration data in ACPI tables (_DSM) or utilizing a Registry backing store. Implementing this makes the driver compliant with modern Windows design principles.
  3. User Experience: It eliminates the need for end-users to manually run calibration tools (which are often inaccurate compared to factory data).

KMDF HID Minidriver for Touch I2C Device Calibration

Touchscreens and other capacitive/precision touch controllers are now standard in laptops, tablets, kiosks, and embedded systems. Making those devices feel smooth and accurate across different units, environments, and physical tolerances requires reliable calibration. For Windows drivers that expose touch controllers through the HID class and communicate over I2C, a KMDF HID minidriver is a common and robust pattern. This article explains the architecture, calibration considerations, and practical implementation patterns for building a KMDF HID minidriver that supports touch I2C device calibration — focusing on reliability, maintainability, and a solid user experience.

Contents

Why HID + KMDF for touch I2C devices

Calibration goals and challenges

Driver architecture overview

Initialization and hardware probing

Exposing HID reports and handling IO

Calibration data: formats, storage, and versioning

Common calibration models

Calibration workflows (factory, field, automatic)

Implementing calibration routines in KMDF

Handling power, suspend/resume, and system events

Validation, diagnostics, and manufacturing test

Security, robustness, and update considerations

Example: Simple affine calibration implementation (conceptual)

UX tips for calibration

Manufacturing and field tools

Summary checklist

Final note A KMDF HID minidriver for an I2C touch controller succeeds when it combines low-latency input processing with robust and easily maintainable calibration infrastructure. Prioritize clear data formats, atomic persistence, good diagnostics, and conservative automatic calibration so the device stays accurate and dependable across its lifetime.

Based on your request, the most valuable feature to implement for a KMDF HID Minidriver for a Touch I2C device is a Driver-Managed Factory Calibration Storage & Restoration Mechanism.

9.2 Checking HID Descriptor

Use Device Manager → Human Interface Devices → Properties → Details → "Hardware IDs" to confirm driver attachment.

Use HIDClient or HidDig tool to dump feature reports.