felis / USB_Host_Shield_2.0

Revision 2.0 of USB Host Library for Arduino.
https://chome.nerpa.tech
1.8k stars 779 forks source link

Need help understanding HID report descriptor #704

Open dexterdy opened 2 years ago

dexterdy commented 2 years ago

Hey peeps,

I need some help understanding the last part of this usb hid report descriptor. It is rather straight forward for the most part, except for the last 3 fields of 16 bits (line 60 - 67). I am going to use this for what should be a rather simple arduino esp32 project.

Logical Minimum (0),
Usage (Gamepad),                    ; Gamepad (05h, application collection)
Collection (Application),
    Report ID (1),
    Usage Page (Button),            ; Button (09h)
    Logical Minimum (0),
    Logical Maximum (1),
    Report Size (1),
    Report Count (10),
    Usage (01h),
    Usage (02h),
    Usage (04h),
    Usage (05h),
    Usage (07h),
    Usage (08h),
    Usage (0Eh),
    Usage (0Fh),
    Usage (09h),
    Usage (0Ch),
    Input (Variable),
    Usage Page (Consumer),          ; Consumer (0Ch)
    Report Count (6),
    Usage (Mute),                   ; Mute (E2h, on/off control)
    Usage (Volume Inc),             ; Volume increment (E9h, re-trigger control)
    Usage (Volume Dec),             ; Volume decrement (EAh, re-trigger control)
    Usage (Power),                  ; Power (30h, on/off control)
    Usage (AC Back),                ; AC back (0224h, selector)
    Usage (AC Home),                ; AC home (0223h, selector)
    Input (Variable),
    Usage Page (Desktop),           ; Generic desktop controls (01h)
    Usage (Hat Switch),             ; Hat switch (39h, dynamic value)
    Logical Maximum (7),
    Physical Minimum (0),
    Physical Maximum (270),
    Unit (Degrees),
    Report Size (4),
    Report Count (1),
    Input (Variable),
    Input (Constant, Variable),
    Usage (Pointer),                ; Pointer (01h, physical collection)
    Collection (Physical),
        Report Size (16),
        Report Count (4),
        Logical Minimum (0),
        Logical Maximum (-1),
        Physical Minimum (0),
        Physical Maximum (-1),
        Usage (X),                  ; X (30h, dynamic value)
        Usage (Y),                  ; Y (31h, dynamic value)
        Usage (Z),                  ; Z (32h, dynamic value)
        Usage (Rz),                 ; Rz (35h, dynamic value)
        Input (Variable),
        Usage Page (Simulation),    ; Simulation controls (02h)
        Report Count (2),
        Usage (C5h),
        Usage (C4h),
        Input (Variable),
    End Collection,
    Collection (Application),
        Usage Minimum (01h),
        Usage Maximum (03h),
        Logical Maximum (-1),
        Report Count (3),
        Report Size (16),
        Output (Variable),
    End Collection,
End Collection,

It is a generic gamepad, but with rumble motors, so my first guess was that those are controls for the rumble feature on the device. They are declared as outputs which would support that guess. However, the usage types don't make sense for that use case at all and I don't see why you would need 3 reports of 16 bits to control that.

It also doesn't seem to be padding, since the total amount of bits comes up to 164, which is rather random, and you don't need to declare usage types for that. It is also declared as an output, which is strange for padding.

Can anybody help me understand this? I have read the HID documentation, but could not find any clear answers.

xxxajk commented 2 years ago

For a generic guide, see the USB HID spec. Also a good reference is Linux drivers, as well as the code within the library.