usb hid report descriptor

usb 设备固件中通常会烧写一些描述信息。

根据usb设计规范, 通常描述符信息包含以下几类:

设备描述符

    |-- 配置描述符

        |-- 接口描述符

             |--端点描述符

     | -- 字符串描述符

 

分别描述该usb设备的厂商, 类别,  ID, 配置, 接口, 端点等等。

 

对于usb hid设备来说,  比较特殊的是其固件描述信息中包含一种hid report descriptor。

由于hid包含鼠标, 键盘, 游戏手柄等多种用户输入设备。

usb hid设备通常使用interrupt即中断传输。

中断传输的数据, 包含坐标, 按键等信息, 这些信息该如何定义。(鼠标和键盘肯定是相差很多)

hid report 描述符就是为了解决这种问题。

例如下面为鼠标的report描述符信息:

Usage Page (Desktop),                   ; Generic desktop controls (01h)
Usage (Mouse),                          ; Mouse (02h, application collection)
Collection (Application),
    Usage Page (Button),                ; Button (09h) 按键
    Usage Minimum (01h),                ; 
    Usage Maximum (05h),                ; 有5种按键(左, 右, 中...)
    Logical Minimum (0),                ;
    Logical Maximum (1),                ; 按键的逻辑值(0 - 松开, 1 - 按下)
    Report Count (5),                   ; 报告的数量5位数据(Byte0[bit0...4])
    Report Size (1),                    ; 报告的大小, 1位
    Input (Variable),                   ; 主项目, 作为输入
    Report Count (1),                   ; 后面1位数据, 即Byte0 bit5
    Report Size (3),                    ; 3位大小, 即bit5...7
    Input (Constant, Variable),         ; 作为常量输入
    Usage Page (Desktop),               ; Generic desktop controls (01h)
    Usage (Pointer),                    ; Pointer (01h, physical collection)
    Collection (Physical),
        Usage (X),                      ; X (30h, dynamic value)
        Usage (Y),                      ; Y (31h, dynamic value)
        Logical Minimum (-127),
        Logical Maximum (127),
        Report Size (8),                ; 8位大小
        Report Count (2),               ; 有两个8位大小
        Input (Variable, Relative),     ; 作为输入,  相对值
    End Collection,                     ; 结束这个集合
    Usage (Wheel),                      ; Wheel (38h, dynamic value), 滚轮
    Report Count (1),                   ; 1位数据
    Input (Variable, Relative),         ; 作为输入
    Usage (Motion Wakeup),              ; Motion wakeup (3Ch, one-shot control)
    Logical Minimum (0),
    Logical Maximum (1),
    Report Size (1),
    Report Count (1),
    Feature (Variable, No Preferred),
    Report Count (7),                   ; 7位数据
    Feature (Constant),
End Collection

主要关键字如下:

主项目

全域项目

区域项目

标签

代码

标签

代码

标签

代码

Input

X08?

Usage Page

0x0?

Usage

0x0?

Output

0x9?

Logical Minimum

0x1?

Usage Minimum

0x1?

Feature

0x0b?

Logical Maximum

0x2?

Usage Maximum

0x2?

 

 

Physical Minimum

0x3?

Designator Minimum

0x3?

Collection

0xa1

Physical Maximum

0x4?

Designator Minimum

0x4?

End Collection

0xc0

Unit Exponent

0x5?

Designator Maximum

0x5?

 

 

Unit

0x6?

String

0x7?

 

 

Report Size

0x7?

Sreing Minimum

0x8?

 

 

Report ID

0x8?

String Maximum

0x9?

 

 

Report Coumt

0x9?

Delimiter

0xa?

 

 

Push

0xA?

 

 

 

 

Pop

0xb?

 

 


具体含义有待进一步理解,  简单来说, report descriptor是对中断传输数据结构的一种描述。

 


我的键盘hid report描述信息如下: (相对鼠标来书信息更多.)

river@river-VirtualBox:/media/sf_vbox_sf/share_workspace/usbhid/usbmouse$ sudo usbhid-dump -d 0x1532 | grep -v : | xxd -r -p | hidrd-convert -o spec
[sudo] password for river: 
Usage Page (Desktop),               ; Generic desktop controls (01h)
Usage (Mouse),                      ; Mouse (02h, application collection)
Collection (Application),
    Usage (Pointer),                ; Pointer (01h, physical collection)
    Collection (Physical),
        Usage Page (Button),        ; Button (09h)
        Usage Minimum (01h),
        Usage Maximum (03h),
        Logical Minimum (0),
        Logical Maximum (1),
        Report Count (3),
        Report Size (1),
        Input (Variable),
        Report Size (1),
        Report Count (5),
        Input (Constant, Variable),
        Usage Page (FF00h),         ; FF00h, vendor-defined
        Usage (40h),
        Report Count (2),
        Report Size (8),
        Logical Minimum (-127),
        Logical Maximum (127),
        Input (Variable),
        Usage Page (Desktop),       ; Generic desktop controls (01h)
        Usage (Wheel),              ; Wheel (38h, dynamic value)
        Logical Minimum (-127),
        Logical Maximum (127),
        Report Size (8),
        Report Count (1),
        Input (Variable, Relative),
        Usage (X),                  ; X (30h, dynamic value)
        Usage (Y),                  ; Y (31h, dynamic value)
        Logical Minimum (-32768),
        Logical Maximum (32767),
        Report Size (16),
        Report Count (2),
        Input (Variable, Relative),
    End Collection,
    Usage Page (FF00h),             ; FF00h, vendor-defined
    Usage (02h),
    Logical Minimum (0),
    Logical Maximum (1),
    Report Size (8),
    Report Count (90),
    Feature (Constant),
End Collection,
Usage Page (Desktop),               ; Generic desktop controls (01h)
Usage (Keyboard),                   ; Keyboard (06h, application collection)
Collection (Application),
    Report ID (1),
    Usage Page (Keyboard),          ; Keyboard/keypad (07h)
    Usage Minimum (KB Leftcontrol), ; Keyboard left control (E0h, dynamic value)
    Usage Maximum (KB Right GUI),   ; Keyboard right GUI (E7h, dynamic value)
    Logical Minimum (0),
    Logical Maximum (1),
    Report Size (1),
    Report Count (8),
    Input (Variable),
    Usage Minimum (None),           ; No event (00h, selector)
    Usage Maximum (FFh),
    Logical Minimum (0),
    Logical Maximum (255),
    Report Size (8),
    Report Count (14),
    Input,
End Collection,
Usage Page (Consumer),              ; Consumer (0Ch)
Usage (Consumer Control),           ; Consumer control (01h, application collection)
Collection (Application),
    Report ID (2),
    Usage Minimum (00h),
    Usage Maximum (AC Format),      ; AC format (023Ch, selector)
    Logical Minimum (0),
    Logical Maximum (572),
    Report Count (1),
    Report Size (16),
    Input,
    Report Size (8),
    Report Count (13),
    Input (Constant),
End Collection,
Usage Page (Desktop),               ; Generic desktop controls (01h)
Usage (Sys Control),                ; System control (80h, application collection)
Collection (Application),
    Report ID (3),
    Usage Minimum (Sys Power Down), ; System power down (81h, one-shot control)
    Usage Maximum (Sys Wake Up),    ; System wake up (83h, one-shot control)
    Logical Minimum (0),
    Logical Maximum (1),
    Report Size (1),
    Report Count (3),
    Input (Variable),
    Report Count (5),
    Input (Constant),
    Report Size (8),
    Report Count (14),
    Input (Constant),
End Collection,
Usage Page (Desktop),               ; Generic desktop controls (01h)
Usage (00h),
Collection (Application),
    Report ID (4),
    Usage (03h),
    Logical Minimum (0),
    Logical Maximum (255),
    Physical Minimum (0),
    Physical Maximum (255),
    Report Size (8),
    Report Count (15),
    Input,
End Collection,
Usage Page (Desktop),               ; Generic desktop controls (01h)
Usage (00h),
Collection (Application),
    Report ID (5),
    Usage (03h),
    Logical Minimum (0),
    Logical Maximum (255),
    Physical Minimum (0),
    Physical Maximum (255),
    Report Size (8),
    Report Count (15),
    Input,
End Collection,
Usage Page (Desktop),               ; Generic desktop controls (01h)
Usage (Keyboard),                   ; Keyboard (06h, application collection)
Collection (Application),
    Usage Page (Keyboard),          ; Keyboard/keypad (07h)
    Usage Minimum (KB Leftcontrol), ; Keyboard left control (E0h, dynamic value)
    Usage Maximum (KB Right GUI),   ; Keyboard right GUI (E7h, dynamic value)
    Logical Minimum (0),
    Logical Maximum (1),
    Report Size (1),
    Report Count (8),
    Input (Variable),
    Input (Constant),
    Usage Minimum (None),           ; No event (00h, selector)
    Usage Maximum (FFh),
    Logical Minimum (0),
    Logical Maximum (255),
    Report Size (8),
    Report Count (6),
    Input,
    Usage Page (LED),               ; LEDs (08h)
    Usage Minimum (01h),
    Usage Maximum (03h),
    Logical Minimum (0),
    Logical Maximum (1),
    Report Size (1),
    Report Count (3),
    Output (Variable),
    Report Count (5),
    Output (Constant),
End Collection

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值