twitchyliquid64 / usbd-hid

MIT License
88 stars 37 forks source link

The generated Keyboard descriptor doesn't work under Windows #8

Closed jsaowji closed 4 years ago

jsaowji commented 4 years ago

The library works fine on devices conencted to a linux machine but not a windows one. After inspecting the usb initialisation sequence using wireshark, I noticed that wireshark also though the usbhid-report descriptor was malformed.

The offending Item is a '0x80'. After comparing the generated descriptor with the example one in the HID spec I noticed it is an abbreviation for '0x81 0x00'.

Replacing the '0x80' with '0x81 0x00' and using that as the new descriptor made my device work under Windows.

I also found someone on stackoverflow who noticed similar behavior Unspecified zero-sized items are not accepted by Windows HID parser (while they work on Mac OS, iOS and Linux). – Nipo May 7 '16 at 16:40 ( https://stackoverflow.com/questions/36750287/two-byte-report-count-for-hid-report-descriptor/36835781 )

https://github.com/twitchyliquid64/usbd-hid/blob/f0ddfa70c8b3ee94bceac695078fdc83a5de6f52/macros/src/lib.rs#L335-L344 If I understand the code correctly, it shortens Input-Items with data '0x0' down to an input Item with size zero and no extra data. This is apparently not supported under Windows even though the specification allows it.

Removing the mentioned lines would fix the problem. I don't know a lot about USB hid though, so there might be a better way.

twitchyliquid64 commented 4 years ago

That doesnt surprise me :grinning:

I'll try and get a fix in this week, it seems pretty straightforward.