The DPC routine or a continuous reader thread must apply calibration before submitting the HID report to the class driver.
Pseudo-code:
VOID ApplyCalibration(PTOUCH_POINT RawPoint, PTOUCH_POINT CalibratedPoint)
CalibratedPoint->X = (RawPoint->X * pContext->CoeffA) +
(RawPoint->Y * pContext->CoeffB) +
pContext->CoeffC;
CalibratedPoint->Y = (RawPoint->X * pContext->CoeffD) +
(RawPoint->Y * pContext->CoeffE) +
pContext->CoeffF;
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. kmdf hid minidriver for touch i2c device calibration
High-level flow of the calibration tool:
This application must run with administrative privileges, as it modifies kernel-mode driver state. The DPC routine or a continuous reader thread
NTSTATUS GetInputReport(WDFDEVICE Device, PVOID ReportBuffer, ULONG BufferLength) // 1. Raw read from I2C BYTE rawReport[64]; NTSTATUS status = I2CReadRawData(Device, rawReport, sizeof(rawReport)); if (!NT_SUCCESS(status)) return status;// 2. Apply calibration (depends on report format) PTOUCH_REPORT pReport = (PTOUCH_REPORT)rawReport; for (int i = 0; i < pReport->ContactCount; i++) ApplyCalibration(&pReport->Contacts[i].X, &pReport->Contacts[i].Y, &g_Calibration); // 3. Copy to output RtlCopyMemory(ReportBuffer, rawReport, min(BufferLength, rawReportSize)); return STATUS_SUCCESS;
For a multi-touch device, your HID Report Descriptor must conform to the Windows Precision Touchpad (PTP) or HID-over-I2C v1.0 spec. A minimal single-touch descriptor:
0x05, 0x0D, // Usage Page (Digitizer)
0x09, 0x04, // Usage (Touch Screen)
0xA1, 0x01, // Collection (Application)
0x85, 0x01, // Report ID 1
0x09, 0x22, // Usage (Finger)
0xA1, 0x00, // Collection (Physical)
0x09, 0x42, // Usage (Tip Switch)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x75, 0x01, // Report Size (1)
0x95, 0x01, // Report Count (1)
0x81, 0x02, // Input (Data,Var,Abs)
0x09, 0x30, // Usage (X)
0x27, 0xFF, 0xFF, 0x00, 0x00, // Logical Maximum (65535)
0x75, 0x10, // Report Size (16)
0x95, 0x01, // Report Count (1)
0x81, 0x02, // Input (Data,Var,Abs)
... etc ...
0xC0, 0xC0
Your minidriver returns this descriptor in TouchCalibEvtGetDescriptor. The calibrated X and Y values must fit within the logical maximum defined here. Your KMDF driver alone cannot perform calibration; it