twitchyliquid64 / usbd-hid

MIT License
87 stars 37 forks source link

Include redundant report descriptor fields #45

Open FlorianUekermann opened 2 years ago

FlorianUekermann commented 2 years ago

I use the gen_hid_descriptor macro like this:

#[gen_hid_descriptor(
    (collection = APPLICATION, usage_page = 0xaaaa, usage = 0xaa) = {
        (usage = 0xbb,) = {
            input_buffer = input;
        };
        (usage = 0xcc,) = {
            output_buffer = output;
        };
    }
)]
pub struct Report {
    input_buffer: [u8; 64],
    output_buffer: [u8; 64],
}

the resulting descriptor looks like this:

0x06, 0xAA, 0xAA,  // Usage Page (Reserved 0xAAAA)
0x09, 0xAA,        // Usage (0xAA)
0xA1, 0x01,        // Collection (Application)
0x09, 0xAA,        //   Usage (0xBB)
0x15, 0x00,        //   Logical Minimum (0)
0x26, 0xFF, 0x00,  //   Logical Maximum (255)
0x75, 0x08,        //   Report Size (8)
0x95, 0x40,        //   Report Count (64)
0x81, 0x02,        //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x09, 0xBB,        //   Usage (0xCC)
0x91, 0x02,        //   Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0xC0,              // End Collection

As you can see, the logical min & max, as well as report size & count are skipped for the output. I suspect this is correct and because they are identical to the input (I'm not an expert on HID). However, I'm need them to be in there for robust device discovery. It would be great if I could disable this optimization somehow.

twitchyliquid64 commented 2 years ago

Logical min/max are global items right? so the parser should remember + use the last value.

Theres a lot of bugs caused by buggy parsers, I agree we need a quirk setting to emit all the items for every input/output thats declared.