tinyusb icon indicating copy to clipboard operation
tinyusb copied to clipboard

remove hid host enumeration assumption

Open dinsfire64 opened this issue 1 month ago • 3 comments

Describe the PR Remove assumption that HID Report descriptor is before HID Endpoint.

Additional context I have been using tinyusb's HID Host stack in my project and came across a game controller that has an...odd configuration.

Most HID Devices have the HID Report Descriptor preceding the endpoint, however I came across a device that has it following the endpoint.

you can see it in this lsusb call where it tails the endpoint with DEVICE CLASS which is actually the Report type that we need to parse.

[dinsfire@hyrule ~]$ lsusb -d 1ccf:1020 -v

Bus 001 Device 055: ID 1ccf:1020 Konami Amusement DDR MAT controller
Negotiated speed: Full Speed (12Mbps)
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 [unknown]
  bDeviceSubClass         0 [unknown]
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x1ccf Konami Amusement
  idProduct          0x1020 DDR MAT controller
  bcdDevice            4.10
  iManufacturer           1 Konami Amusement
  iProduct                2 DDR MAT controller
  iSerial                 3 BF010
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0022
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              200mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 [unknown]
      bInterfaceProtocol      0 
      iInterface              1 Konami Amusement
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval               4
        DEVICE CLASS:  09 21 11 01 21 01 22 32 00
Device Status:     0x0000
  (Bus Powered)

I noticed that tinyusb's hidh_open has this order hard coded, so I added a small function to seek the descriptor for the HID_DTYPE_HID that we want to parse.

This successfully has the device attached to the hidh stack and I can continue to poll it.

If you are interested the project in question I'm using this in is a gamepad adapter for retro consoles. It's been a fun project!

https://github.com/dinsfire64/snekbox_firmware

Thank you as always for your work and effort, tinyusb has been a blast to implement.

dinsfire64 avatar Nov 15 '25 14:11 dinsfire64

seems like lsusb also got confused by the device as well, this device is clearly out of specs. I am ok to add support for it. But the change seems to be more complicated than it should be. Let keep most the code intact, and only change to allow the hid descriptor to either before (as current) or after endpoint descriptor

hathach avatar Nov 19 '25 09:11 hathach

So are you imagining changing the original assert into a check TU_ASSERT(HID_DESC_TYPE_HID == desc_hid->bDescriptorType);

if it fails, attempt to flip the order and parse it that way?

Then assert if that fails?

dinsfire64 avatar Nov 19 '25 13:11 dinsfire64

@dinsfire64 I push the update, please try to see if that works for you.

hathach avatar Nov 20 '25 04:11 hathach

Apologies for the delay, the holidays have eaten up my time to test.

Your suggested commit works correctly with the quirky device and I am happy with the solution if you are.

dinsfire64 avatar Dec 07 '25 14:12 dinsfire64

perfect, thank you

hathach avatar Dec 08 '25 03:12 hathach