HID report not working while changed length

二次信任 提交于 2021-02-08 05:45:56

问题


I'm building a custom keyboard with stm32f103.

My first trial with standard 8 byte works pretty well:

0x05, 0x01,                         // Usage Page (Generic Desktop)
0x09, 0x06,                         // Usage (Keyboard)
0xA1, 0x01,                         // Collection (Application)

//Modifiers
0x05, 0x07,                         //     Usage Page (Key Codes)
0x19, 0xe0,                         //     Usage Minimum (224)
0x29, 0xe7,                         //     Usage Maximum (231)
0x15, 0x00,                         //     Logical Minimum (0)
0x25, 0x01,                         //     Logical Maximum (1)
0x75, 0x01,                         //     Report Size (1)
0x95, 0x08,                         //     Report Count (8)
0x81, 0x02,                         //     Input (Data, Variable, Absolute)

//Reserveds
0x95, 0x01,                         //     Report Count (1)
0x75, 0x08,                         //     Report Size (8)
0x81, 0x01,                         //     Input (Constant) reserved byte(1)

//Regular Keypads
0x95, 0x06,                         //     Report Count (normally 6)
0x75, 0x08,                         //     Report Size (8)
0x26, 0xff, 0x00,
0x05, 0x07,                         //     Usage Page (Key codes)
0x19, 0x00,                         //     Usage Minimum (0)
0x29, 0xbc,                         //     Usage Maximum (188)
0x81, 0x00,                         //     Input (Data, Array) Key array(6 bytes)

0xC0                                // End Collection (Application)

then I tried to make the report length longer to support more key press at the same time, so I change this

0x95, 0x06,                         //     Report Count (normally 6)

to this

0x95, 0x30,                         //     Report Count (normally 6)

and accordingly

struct HIDreport
{
    int8_t mod;
    int8_t reserv;
    int8_t key[lenth];
};
struct HIDreport report;

but I found any of the key press do not work, what am I missing? thanks


回答1:


If your Interface defines the keyboard as a "BOOT keyboard", for example:

  0x03, /*bInterfaceClass: HID*/
  0x01, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
  0x01, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/

...then I'm pretty sure the HID report descriptor will be ignored. The idea of a "BOOT keyboard" is that it uses a fixed size buffer (1 byte keyboard modifiers, 1 byte reserved, 6 bytes of keyboard usage indexes) so that it can be recognised during boot up (e.g. to modify CMOS settings) without having to implement a full USB stack in the BIOS.

Valid combinations of Class, Subclass, Protocol are as follows:

Class Subclass Protocol Meaning
  3       0       0     Class=HID with no specific Subclass or Protocol:
                        Can have ANY size reports (not just 8-byte reports)
  3       1       1     Class=HID, Subclass=BOOT device, Protocol=keyboard:
                        REQUIRES 8-byte reports in order for it to be recognised by BIOS when booting.
                        That is because the entire USB protocol cannot be implemented in BIOS, so
                        motherboard manufacturers have agreed to use a fixed 8-byte report during booting.
  3       1       2     Class=HID, Subclass=BOOT device, Protocol=mouse

The above information is documented in Appendix E.3 "Interface Descriptor (Keyboard)" of the "Device Class Definition for Human Interface Devices (HID) v1.11" document (HID1_11.pdf) from www.usb.org

Edit: The use case for a buffer size of more than 6 keys is questionable anyway because the buffer represents those keys that are simultaneously pressed at a particular point in time. It is unlikely that anyone would need to press more than 6 keys simultaneously.



来源:https://stackoverflow.com/questions/48248023/hid-report-not-working-while-changed-length

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!