USB HID Report Descriptor 报告描述符详解(节选自HID1.11协议)

来源:互联网 发布:apache storm 源码 编辑:程序博客网 时间:2024/05/16 17:08

本文摘取自HID1.11协议文档,并通过自己的整理。
通过对本文的阅读,你将能明白HID报告描述符各Item的意义,以一个USB鼠标的报告描述符为例。并能根据自己的需要对报告描述符做修改。
本文大部分为英文原文,但是结构与原文有所差异。
HID1.11协议的原文我在以下帖子中有上传
http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=4823160&bbs_page_no=1&search_mode=3&search_text=lugang_2920213&bbs_id=9999


Report descriptors are composed of pieces of information. Each piece of information is called an Item.
报告描述符由一些数据片组成。这些数据片被叫做Item。
All items have a one-byte prefix that contains the item tag, item type, and item size.
每一个Item都包含一个字节的前缀,这个前缀中包含了三个信息--item tag,、item type、item size。
An item may include optional item data。
Item可以包含一个可选的数据段。
The size of the data portion of an item is determined by its fundamental type.
Item的数据部分的长度取决于Item的基本类型。
There are two basic types of items: short items and long items.
Item有两种基本类型:short items and long item。

long item格式 (原文件名:long item.jpg)


short item格式 (原文件名:short item.jpg)

There are three categories of short item tags: Main, Global, and Local.
short item 的 item tags 有三种类型:Main, Global, and Local.

Main items: </center>
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. Data-type 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.jpg)

(原文件名:MAIN Item1.jpg)
好了,到此我们应该可以对照实际应用的报告描述符,寻找其中的 Main items了。

至此我们已经可以明白报告描述符中的几个MAIN Item的意义,接下来继续看Global Item 和 Local Item.

Global Item: </center>
Global items describe rather than define data from a control. A new Main item 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.jpg)

(原文件名:Global Item1.jpg)

至此我们已经可以明白报告描述符中的几个Global Item的意义

Local Item: </center>
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.jpg)
至此我们已经可以明白报告描述符中的几个Local Item的意义

//该报告描述符号由HID Descriptor tool生成   
以下是一个USB鼠标的报告描述符
code char MouseReportDescriptor[63] = {   
    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)   
    0x09, 0x06,                  // USAGE (Keyboard)   
    0xa1, 0x01,                    // COLLECTION (Application)   这就是一个MAIN Item,可以对应上图查看   
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)   
    0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)   
    0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)   
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)   
    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)   
    0x75, 0x01,                    //   REPORT_SIZE (1)   
    0x95, 0x08,                    //   REPORT_COUNT (8)   
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)     这就是一个MAIN Item,可以对应上图查看  
    0x95, 0x01,                    //   REPORT_COUNT (1)   
    0x75, 0x08,                    //   REPORT_SIZE (8)   
    0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)     这就是一个MAIN Item,可以对应上图查看  
    0x95, 0x05,                    //   REPORT_COUNT (5)   
    0x75, 0x01,                    //   REPORT_SIZE (1)   
    0x05, 0x08,                    //   USAGE_PAGE (LEDs)   
    0x19, 0x01,                    //   USAGE_MINIMUM (Num Lock)   
    0x29, 0x05,                    //   USAGE_MAXIMUM (Kana)   
    0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)     这就是一个MAIN Item,可以对应上图查看   
    0x95, 0x01,                    //   REPORT_COUNT (1)   
    0x75, 0x03,                    //   REPORT_SIZE (3)   
    0x91, 0x03,                    //   OUTPUT (Cnst,Var,Abs)     这就是一个MAIN Item,可以对应上图查看  
    0x95, 0x06,                    //   REPORT_COUNT (6)   
    0x75, 0x08,                    //   REPORT_SIZE (8)   
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)   
    0x25, 0xFF,                    //   LOGICAL_MAXIMUM (255)   
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)   
    0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))   
    0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)   
    0x81, 0x00,                    //   INPUT (Data,Ary,Abs)     这就是一个MAIN Item,可以对应上图查看   
    0xc0                           // END_COLLECTION             这就是一个MAIN Item,可以对应上图查看         
};

如果你耐心的看完了本文,我想你也已经明白了USB鼠标描述符中每个item的意义。

点击此处下载HID报告描述符生成软件 ourdev_651648M4ST0A.rar(文件大小:884K) (原文件名:USBMonitor2_26.rar)

 

http://www.amobbs.com/thread-4827807-1-1.html

0 0
原创粉丝点击