IntergatedCircuits / HidSharp

HIDSharp is a multiplatform C# library for USB HID devices by James F. Bellinger
https://www.zer7.com/software/hidsharp
Other
121 stars 34 forks source link

Discard high nibble when decoding Unit Exponent #17

Closed Joop-Schilder closed 1 year ago

Joop-Schilder commented 1 year ago

HidSharp assumes the high nibble in a unit exponent field is meaningful, while the HID Usage Tables 1.3 defines the unit exponent as a 4-bit value (Exponent 0 through F, page 302 / 303). Report Descriptors only support values in multitudes of 8 bits, so the first 4 bits are padding / meaningless. This means we should ignore the high nibble when decoding the report descriptor and not make any assumptions about its meaning.

There are some devices which define the unit exponent as 0xF0 through 0xFF. Reconstructing the report descriptor fails on these devices.

See the definition in https://www.usb.org/sites/default/files/hut1_3_0.pdf (page 302).

This is how the Linux kernel does it as well: https://github.com/torvalds/linux/blob/master/drivers/hid/hid-core.c#L422

benedekkupper commented 1 year ago

The change looks good, I have only one minor wish: can you change the "first nibble" phrasing to "high nibble" (in the comment and in the commit message)? That makes it clearer, first nibble is more up to interpretation, especially in LSB vs MSB first context.

Joop-Schilder commented 1 year ago

I changed the phrasing. You are right, "first" is a bit ambiguous.

benedekkupper commented 1 year ago

Thank you for your contribution! Looking forward to more :)