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

本文详细解析了USB HID鼠标报告描述符的结构和功能,涵盖了报告ID、按键、移动数据等字段的定义和作用,深入分析了短项格式、主项、全局项和局部项的概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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)。

indexitem字节0123
10327654   
bSizebTypebTagdatadatadata
00x05, 0x01,    /// USAGE PAGE (Generic Desktop)11(Global)00x01xx
10x09, 0x02,/// USAGE (Mouse)12(Local)00x02xx
20xA1, 0x01,/// COLLECTION (Application)10(Main)A0x01xx
30x85, 0x01,/// REPORT ID (1) - MANDATORY11(Global)80x01xx
40x09, 0x01,///     USAGE (Pointer)12(Local)00x01xx
50xA1, 0x00,///     COLLECTION (Physical)10(Main)A0x00xx
60x05, 0x09,///         USAGE PAGE (Buttons)11(Global)00x09xx
70x19, 0x01,///         USAGE MINIMUM (1)12(Local)1   
80x29, 0x08,///         USAGE MAXIMUM (8)12(Local)2   
90x15, 0x00,///         LOGICAL MINIMUM (0)11(Global)1   
100x25, 0x01,///         LOGICAL MAXIMUM (1)11(Global)2   
110x75, 0x01,///         REPORT SIZE (1)11(Global)7   
120x95, 0x08,///         REPORT COUNT (8)11(Global)9   
130x81, 0x02,///         INPUT (Data, Variable, Absolute)10(Main)8   
140x05, 0x01,///         USAGE PAGE (Generic Desktop)11(Global)0   
150x16, 0x08, 0xFF,///       LOGICAL MINIMUM (-255)21(Global)1   
160x26, 0xFF, 0x00,///       LOGICAL MAXIMUM (255)21(Global)2   
170x75, 0x10,///         REPORT SIZE (16)11(Global)7   
180x95, 0x02,///         REPORT COUNT (2)11(Global)9   
190x09, 0x30,///         USAGE (X)12(Local)0   
200x09, 0x31,///         USAGE (Y)12(Local)0   
210x81, 0x06,///         INPUT (Data, Variable, Relative)10(Main)8   
220x15, 0x81,///         LOGICAL MINIMUM (-127)11(Global)1   
230x25, 0x7F,///         LOGICAL MAXIMUM (127)11(Global)2   
240x75, 0x08,///         REPORT SIZE (8)11(Global)7   
250x95, 0x01,///         REPORT COUNT (1)11(Global)9   
260x09, 0x38,///         USAGE (Wheel)12(Local)00x38  
270x81, 0x06,///         INPUT (Data, Variable, Relative)10(Main)8   
280xC0,///     END COLLECTION (Physical)00(Main)C   
290xC0,/// END COLLECTION (Application)00(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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值