嵌入式开发_USB(HID)_6.2.2 Report Descriptor

https://www.usb.org/hid

阅读本文前请下载hid1_11.pdfhut1_12v2.pdf以及一个小工具dt2_4.zip

目的

下面是一个鼠标的report descriptor,本章目的是为了弄明白它!

{
    /**
     *  --------------------------------------------------------------------------
     *  Bit      |   7   |   6   |   5   |   4   |   3   |   2   |   1   |   0   |
     *  --------------------------------------------------------------------------
     *  Byte 0   |               Not Used                | Middle| Right | Left  |
     *  --------------------------------------------------------------------------
     *  Byte 1   |                     X Axis Relative Movement                  |
     *  --------------------------------------------------------------------------
     *  Byte 2   |                     Y Axis Relative Movement                  |
     *  --------------------------------------------------------------------------
     *  Byte 3   |                     Wheel Relative Movement                   |
     *  --------------------------------------------------------------------------
     */

    0x05, 0x01,     /// USAGE PAGE (Generic Desktop)
    0x09, 0x02,     /// USAGE (Mouse)
    0xA1, 0x01,     /// COLLECTION (Application)
    0x85, 0x01,     /// REPORT ID (1) - MANDATORY
    0x09, 0x01,     ///     USAGE (Pointer)
    0xA1, 0x00,     ///     COLLECTION (Physical)

    /**
     * ----------------------------------------------------------------------------
     * BUTTONS
     * ----------------------------------------------------------------------------
     */
    0x05, 0x09,     ///         USAGE PAGE (Buttons)
    0x19, 0x01,     ///         USAGE MINIMUM (1)
    0x29, 0x08,     ///         USAGE MAXIMUM (8)
    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)

    /**
     * ----------------------------------------------------------------------------
     * MOVEMENT DATA
     * ----------------------------------------------------------------------------
     */
    0x05, 0x01,     ///         USAGE PAGE (Generic Desktop)
    0x16, 0x08, 0xFF, ///       LOGICAL MINIMUM (-255)
    0x26, 0xFF, 0x00, ///       LOGICAL MAXIMUM (255)
    0x75, 0x10,     ///         REPORT SIZE (16)
    0x95, 0x02,     ///         REPORT COUNT (2)
    0x09, 0x30,     ///         USAGE (X)
    0x09, 0x31,     ///         USAGE (Y)
    0x81, 0x06,     ///         INPUT (Data, Variable, Relative)

    0x15, 0x81,     ///         LOGICAL MINIMUM (-127)
    0x25, 0x7F,     ///         LOGICAL MAXIMUM (127)
    0x75, 0x08,     ///         REPORT SIZE (8)
    0x95, 0x01,     ///         REPORT COUNT (1)
    0x09, 0x38,     ///         USAGE (Wheel)
    0x81, 0x06,     ///         INPUT (Data, Variable, Relative)

    0xC0,           ///     END COLLECTION (Physical)
    0xC0            /// END COLLECTION (Application)
};

6.2.2.1  Items Types and Tags

 All items contain a 1-byte prefix which denotes the basic type of the item. The HIDclass defines two basic formats for items: 

  • Short items: 1 – 5 bytes total length; used for the most commonly occurring items. A short item typically contains 1 or 0 bytes of optional data. 
  • Long items: 3 – 258 bytes in length; used for items that require larger data structures for parts. 

这段话告诉我们所有的items都包含一个1-byte前缀,用来表示这个item的基本类型。

备注:本章节只对short item分析,因为我们常见的都是short item,long item保留给未来使用。 

6.2.2.2 Short Items

The short item format packs the item size, type, and tag into the first byte. The first byte may be followed by 0, 1, 2, or 4 optional data bytes depending on the size of the data. 

6.2.2.4 Main Items

Main items are used to either define or group certain types of data fields within a Report descriptor. There are two types of Main items: data and non-data. Datatype Main items are used to create a field within a report and include Input, Output, and Feature. Other items do not create fields and are subsequently referred to as non-data Main items. 

 Main item用来定义或者分组report descriptor的数据域的特定类型。

有两种Main item分别是有data和non-data。

Datatype Main item用于创建一个域,包含input、output、feature。

除这些之外的其他item不创建域。

 

 6.2.2.7 Global Items

Global items describe rather than define data from a control. A new Mainitem assumes the characteristics of the item state table.Global items can change the state table. As a result Global item tags apply to all subsequently defined items 
unless overridden by another Global item. 

 Global item描述控制数据。

一个新的Main item假设item状态表的属性。

Global item可以改变这个状态表。

因此,Global item适用于所有之后定义的item,这是它的全局性,除非被另外一个Global item覆盖。

6.2.2.8 Local Items

Local item tags define characteristics of controls. These items do not carry over to the next Main item. If a Main item defines more than one control, it may be preceded by several similar Local item tags. For example, an Input item may 
have several Usage tags associated with it, one for each control.

Local item定义控制单元的属性。

这些item不能跨越Main item,这就是局域性。

如果一个Main item定义了多个控制单元,前面应该会有几个类似的Local item。

比如,一个input item可能会有几个相关的Usage标签,分别对应每个控制单元。

分析

看到这里,我们就可以上菜了(手边请准备好hid1_11.pdfhut1_12v2.pdf)。

index item 字节 0 1 2 3
10 32 7654      
bSize bType bTag data data data
0 0x05, 0x01,     /// USAGE PAGE (Generic Desktop) 1 1(Global) 0 0x01 x x
1 0x09, 0x02, /// USAGE (Mouse) 1 2(Local) 0 0x02 x x
2 0xA1, 0x01, /// COLLECTION (Application) 1 0(Main) A 0x01 x x
3 0x85, 0x01, /// REPORT ID (1) - MANDATORY 1 1(Global) 8 0x01 x x
4 0x09, 0x01, ///     USAGE (Pointer) 1 2(Local) 0 0x01 x x
5 0xA1, 0x00, ///     COLLECTION (Physical) 1 0(Main) A 0x00 x x
6 0x05, 0x09, ///         USAGE PAGE (Buttons) 1 1(Global) 0 0x09 x x
7 0x19, 0x01, ///         USAGE MINIMUM (1) 1 2(Local) 1      
8 0x29, 0x08, ///         USAGE MAXIMUM (8) 1 2(Local) 2      
9 0x15, 0x00, ///         LOGICAL MINIMUM (0) 1 1(Global) 1      
10 0x25, 0x01, ///         LOGICAL MAXIMUM (1) 1 1(Global) 2      
11 0x75, 0x01, ///         REPORT SIZE (1) 1 1(Global) 7      
12 0x95, 0x08, ///         REPORT COUNT (8) 1 1(Global) 9      
13 0x81, 0x02, ///         INPUT (Data, Variable, Absolute) 1 0(Main) 8      
14 0x05, 0x01, ///         USAGE PAGE (Generic Desktop) 1 1(Global) 0      
15 0x16, 0x08, 0xFF, ///       LOGICAL MINIMUM (-255) 2 1(Global) 1      
16 0x26, 0xFF, 0x00, ///       LOGICAL MAXIMUM (255) 2 1(Global) 2      
17 0x75, 0x10, ///         REPORT SIZE (16) 1 1(Global) 7      
18 0x95, 0x02, ///         REPORT COUNT (2) 1 1(Global) 9      
19 0x09, 0x30, ///         USAGE (X) 1 2(Local) 0      
20 0x09, 0x31, ///         USAGE (Y) 1 2(Local) 0      
21 0x81, 0x06, ///         INPUT (Data, Variable, Relative) 1 0(Main) 8      
22 0x15, 0x81, ///         LOGICAL MINIMUM (-127) 1 1(Global) 1      
23 0x25, 0x7F, ///         LOGICAL MAXIMUM (127) 1 1(Global) 2      
24 0x75, 0x08, ///         REPORT SIZE (8) 1 1(Global) 7      
25 0x95, 0x01, ///         REPORT COUNT (1) 1 1(Global) 9      
26 0x09, 0x38, ///         USAGE (Wheel) 1 2(Local) 0 0x38    
27 0x81, 0x06, ///         INPUT (Data, Variable, Relative) 1 0(Main) 8      
28 0xC0, ///     END COLLECTION (Physical) 0 0(Main) C      
29 0xC0, /// END COLLECTION (Application) 0 0(Main) C      

Usage Page (Generic Desktop), 
Usage (Mouse), 
Collection (Application),
    Report ID (1), 
    Usage (Pointer), 
    Collection (Physical), 
        Usage Page (Buttons), 
        Usage Minimum (1), 
        Usage Maximun (8), 
        Logical Minimum (0), 
        Logical Maximum (1), 
        Report Size (1),
        Report Count (8),
        Input (Data, Variable, Absolute),  ;8 bits(button)
        
        Usage Page (Generic Desktop),
        Logical Minimum (-255),
        Logical Maximum (255), 
        Report Size (16), 
        Report Count (2),
        Usage (X),
        Usage (Y),
        Input (Data, Variable, Relative),  ;2 position half word (X & Y)
        
        Logical Minimum (-127), 
        Logical Maximum (127), 
        Report Size (8), 
        Report Count (1),
        Usage (Wheel),
        Input (Data, Variable, Relative),  ;1 bytes (Wheel)
        
    End Collection, 
End Collection

特别推荐:

http://usb.baiheee.com/special/usb_hid_spec/usb_hid_spec_74.html 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章