嵌入式開發_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 

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