C语言 更改长度时 HID 报告不起作用



我正在使用stm32f103构建自定义键盘。

我第一次使用标准 8 字节的试用效果很好:

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)

然后我试图使报告长度更长以支持同时按下更多键,所以我改变了这个

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

对此

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

并相应地

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

但是我发现任何按键都不起作用,我错过了什么? 谢谢

如果您的接口将键盘定义为"BOOT 键盘",例如:

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

。那么我很确定 HID 报告描述符将被忽略。"BOOT 键盘"的想法是它使用固定大小的缓冲区(1 字节键盘修饰符、1 字节保留、6 字节键盘使用索引),以便在启动期间识别它(例如修改 CMOS 设置),而无需在 BIOS 中实现完整的 USB 堆栈。

类、子类、协议的有效组合如下:

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

以上信息记录在附录 E.3"接口描述符(键盘)"中 来自 www.usb.org 的"人机接口设备 (HID) v1.11 的设备类定义"文档 (HID1_11.pdf

)编辑:缓冲区大小超过6个键的用例无论如何都是有问题的,因为缓冲区表示在特定时间点同时按下的那些键。任何人都不太可能需要同时按下超过 6 个键。

最新更新