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,可以對應上圖查看
};
-------------------------------------------------------------------------------------------------------------------------------------------------------------- 補充HID報告描述符說明.
在USB中,USB Host是通過各種描述符來識別識別設備的,有設備描述符/配置描述符/接口描述符/斷點描述符/字符串描述符/報告描述符等等.
USB報告描述符是HID設備中的一個描述符,它是比較復雜的一個描述符.
USB HID設備是通過報告來給傳送數據的,報告有輸入報告和輸出報告.
輸入報告是USB設備發送數據給Host.PS:USB鼠標將鼠標移動和鼠標點擊等信息返回給電腦,鍵盤將按鍵數據返回給電腦等.
輸出報告是Host發送數據給USB設備,PS:鍵盤上的數字鍵盤鎖定燈和大寫字母鎖定燈等.
報告是一個數據包,里面包含的是索要傳送的數據.輸入報告是通過中斷輸入斷點輸入的,而輸出報告有點區別,當沒有中斷輸出斷點時,可以通過控制輸出斷電0發送,當有中斷輸出斷點時,通過中斷輸出斷點發出.
而報告描述符,是描述一個報告以及報告里面的數據是用來干什么的.通過它,USB Host可以解析出報告里面的數據所表示的含義.它通過控制輸入斷點0返回,Host使用獲取報告描述符命令來獲取報告描述符,注意這個請求是發送到Interface,而不是設備.一個報告描述符可以描述多個報告,不同的報告通過Report ID來區分,Reort ID在報告最前面,即第一個byte.而當報告描述符中沒有規定Report ID時,報告中就沒有ID字段,開始就是數據.