greatscottgadgets / python-usb-protocol

python library providing utilities, data structures, constants, parsers, and tools for working with USB data
BSD 3-Clause "New" or "Revised" License
55 stars 32 forks source link

Minimal change to allow support of HID descriptors #17

Closed mubes closed 3 years ago

mubes commented 3 years ago

This is a minimum, conservative, change set extracted from https://github.com/usb-tools/python-usb-protocol/pull/6 to allow the addition (as binary blobs) of HID Report Descriptors. These do not contain their type in the first octet so the existing mechanisms don't work. With this PR a HID Report Descriptor can be attached directly to a DeviceDescriptorCollection provided it's HID Descriptor has been attached to an interface. A typical configuration would be;

interface.add_subordinate_descriptor(b"\x09\x21\x11\x01\x00\x01\x22\x21\x00")
descriptors.add_descriptor(b"\x06\x00\xFF\x09\x01\xA1\x01\x15\x00\x26\xFF\x00\x75\x08\x95\x40\x09\x01\x81"
    b"\x02\x95\x40\x09\x01\x91\x02\x95\x01\x09\x01\xB1\x02\xC0",descriptor_type=0x22)

I don't think this is a complete solution to support HIDs, but it does allow them to be used today while the issues in the above PR are resolved.

ktemkin commented 3 years ago

That works. :)

Thanks!