隐藏报告描述符:填充错误

hid report descriptor: wrong padding

我的设备具有以下隐藏报告描述符:

Collection (Logical) A1 02 

Usage Page (Physical Input Device) 05

Usage (DC Enable Actuators) 09 97  
Logical Minimum (0) 15 00  
Logical Maximum (1) 25 01  
Report Size (4) 75 04  
Report Count (1) 95 01  
Output (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) 91 02

Logical Minimum (0) 15 00  
Logical Maximum (0) 25 00  
Output (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) 91 03  

Usage (Magnitude) 09 70  
Logical Minimum (0) 15 00  
Logical Maximum (100) 25 64  
Report Size (8) 75 08  
Report Count (4) 95 04  
Output (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) 91 02  

...

End Collection C0

因此我认为设备以下列方式接收数据:

8 位:报告 ID,4 位:DC 启用执行器,4 位:填充,32 位:幅度

因此,我在 linux 中的驱动程序代码看起来像这样:

...
static const u8 buf[] =  {0x03, 0b00010000, 0x00, 0x00, 0x60, 0x60, 10, 0x00, 10};
hid_hw_output_report(hid, buf, 9);
...

不幸的是,这不是设备所期望的! 事实上,它只会在数据结构如下时做出反应:

8 位:报告 ID,4 位:填充,4 位:DC 启用执行器,32 位:幅度

即:

...
static const u8 buf[] =  {0x03, 0b00000001, 0x00, 0x00, 0x60, 0x60, 10, 0x00, 10};
hid_hw_output_report(hid, buf, 9);
...

这意味着填充出现在 DC Enable Actuators 字段之前,而不是之后。

有谁明白为什么这两个字段会互换?

提前致谢!

我认为您对二进制文字的工作原理感到困惑。在您的第一个示例中,0b00010000 表示 0x10,或十进制的 16。在您的第二个示例中,0b00000001 表示 0x01,或十进制的 1。这些位的重要性从 right 增加到 left,就像十六进制或十进制的数字一样。因此 0b00010000 表示四位填充 (0b0000),后跟 DC 启用执行器字段 (0b0001),这不是此 HID 报告的正确格式。您的第二个示例显示了正确的顺序 (0b00000001),DC 启用执行器字段(最低 4 位,在右侧)后跟 4 位填充(最高 4 位,在左侧)。