1、样例解读
下面是一个伪代码描述的样例,其中涉及到的页码可查看第 5 段用途表:
Usage Page (Generic Desktop), //定位到Generic Desktop页,这个相当于指针跳转一样的东西
Usage (Mouse), //指定Generic Desktop里的mouse,表示这是一个鼠标
Collection (Application), // Collection Application,是对Mouse的解释
Usage (Pointer), //表示指针形式
Collection (Physical), // Collection Physical,是对Pointer的解释
Report ID (0A), //id为0x0A的报告
Usage (X), Usage (Y), //上报X,Y两个数据
Logical Minimum (-127), //Report data values range from -127
Logical Maximum (127), //X,Y的取值范围是-127~127
Report Size (8), Report Count (2), //总共要上报2个字节,即x一个字节,y一个字节
Input (Data, Variable, Relative), //将X,Y这两个字节添加到0x0A的报告里,且这两个值是可写并且是相对的
Logical Minimum (0),
Logical Maximum (1), //下面Button的取值范围是0~1
Report Size (1), Report Count (3), //3个1位的数据
Usage Page (Button Page),//是一个BUTTON
Usage Minimum (1),
Usage Maximum (3),//共有 BUTTON1~BUTTON3,即总共有 3 个 BUTTON
Input (Data, Variable, Absolute),//将3个分别代表的BUTTON1,BUTTON2,BUTTON3的位添加到0x0A的报告
Report Size (5),
Input (Constant), //增加5个无效的位与上面3位凑成一个字节
End Collection,
End Collection
综上所示,上面样例所表达的意思就是下图所示的:
这里先简单介绍用图表(鼠标):具体看 HID Usage Tables 1.12(用图表).pdf ,或下一章
0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x02, // Usage (Mouse)
再 举 一 个 实 际 的 例 子 进 行 解 读 , 下 面 是 摘 自 TI CC2540/CC2541 SDK 里 的BLE-CC254x_v1.4.0\Projects\ble\Profiles\HIDDevKbM\hidkbmservice.c
static CONST uint8 hidReportMap[] =
{
0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x02, // Usage (Mouse)
0xA1, 0x01, // Collection (Application)
0x85, 0x01, // Report Id (1)
0x09, 0x01, // Usage (Pointer)
0xA1, 0x00, // Collection (Physical)
0x05, 0x09, // Usage Page (Buttons)
0x19, 0x01, // Usage Minimum (01) - Button 1
0x29, 0x03, // Usage Maximum (03) - Button 3
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x75, 0x01, // Report Size (1)
0x95, 0x03, // Report Count (3)
0x81, 0x02, // Input (Data, Variable,Absolute) - Button states
0x75, 0x05, // Report Size (5)
0x95, 0x01, // Report Count (1)
0x81, 0x01, // Input (Constant) - Padding or Reserved bits
0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x09, 0x38, // Usage (Wheel)
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
0x75, 0x08, // Report Size (8)
0x95, 0x03, // Report Count (3)
0x81, 0x06, // Input (Data, Variable, Relative) - X & Y coordinate
0xC0, // End Collection
0xC0, // End Collection
0x05, 0x01, // Usage Pg (Generic Desktop)
0x09, 0x06, // Usage (Keyboard)
0xA1, 0x01, // Collection: (Application)
0x85, 0x02, // Report Id (2)