歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Linux HID 驅動開發(2) USB HID Report 描述及usage 概念

Linux HID 驅動開發(2) USB HID Report 描述及usage 概念

日期:2017/3/1 10:56:49   编辑:Linux編程
在USB的枚舉後,即交互完 設備描述符(device descriptor),配置描述符(configure descriptor),接口描述符(interface descriptor)和終端描述符(endpointer desciptor)。如果是HID設備,即class值為3設備交互還會發送一系統的特殊包來描述HID設備的特性。 這一些描述HID的特性稱為Report Descriptor,報告描述符,可以理解它們是HID設備的上傳的包,或者接收的包的格式。設備能包含多個report.
對於每種HID動作的編碼,HID有一個專用術語usage (用法),USB協議中支持所有編碼表稱為usage tables.這裡有全部編碼表。http://www.rlocman.ru/i/File/2011/09/09/1.pdf HTML版本 http://www.freebsddiary.org/APC/usb_hid_usages.php 一.report descriptor 格式
在usb.org網站有HID decriptor tools工具下載 可以用創建和解析report descriptor包格式 http://www.usb.org/developers/hidpage/dt2_4.zip
以下是一個鍵盤的report descriptor的內容.在最右側的是原始數據,比如前二字節是0x05,0x01 表示 USAGE_PAGE.

可以換一個界面查看得更清楚


二.report,usage 格式
從各個軟件分析結果看,一個完整的report 分為二部分,一部分定長的頭,另一部分就是變長的定義,即上文中出現的Collection部分.每個collection由若干個usage組成 定長頭部分有二個定義. usage page.可理解是這個設備類型.
0x05, 0x01 (Generic Desktop Controls) 0x06,0x00 (Vendor-Defined 1) 這個在usb hid文檔裡詳細定義
接下來的字段稱為usage是表示發的包類型(?)
09 06 按鍵。 09 01 自定義
接下來的是


在Collection中,每一個組成部分以稱為item,item就是usage.(這裡術語整得太多了,但是這一些名詞在linux hid都能看到.所以都列在這裡。

Collection裡一般第一個usage是描述input,第二個描述output.當然有不同例外。


首先看usage是input類型 在input首先是取值范圍。雖然占兩個字節,只是低位字節有效
Logical Minimum
logical_maximum
physical_minimum
physical_maximum
是report size,表示report輸入字節寬度,report count表示report總數。

比如按鍵是report size 為1,report count 為8,即一個包為8字節。

然後是input hid包格式,用兩個字符來表示。0x81,0x06表示包裡的由如下格式組成.(其中0x06)有效。分析軟件解析成如下。
A1 01 與 C0之間表示Application Collection的.
絕大部分report都是Application,從USB HID文檔看,還有Logical和Physical類型

Input (Data,Var,Rel,NWrp,Lin,Pref,NNul,Bit)

普通Mouse解析成

0x81, 0x02, INPUT (Data,Var,Abs)

這是格式可能參考 HID 1.11



如0x06--> 00000110 解析(Data(0),Array(0),...)

接下來是output 描述
各個包結構可以參見 http://www.usb.org/developers/devclass_docs/HID1_11.pdf
象鍵盤包格式是有標准格式的。
三.實例分析 這是用USBlyzer分析USB Phone的結果。我個人比較習慣用這個來看 Interface 3 HID Report Descriptor Vendor-Defined 1 Item Tag (Value) Raw Data Usage Page (Vendor-Defined 1) 06 00 FF Usage (Vendor-Defined 1) 09 01 Collection (Application) A1 01 Usage (Undefined) 09 00 Logical Minimum (0) 15 00 Logical Maximum (255) 26 FF 00 Report Size (8) 75 08 Report Count (8) 95 08 Input (Data,Var,Rel,NWrp,Lin,Pref,NNul,Bit) 81 06 Usage (Undefined) 09 00 Report Count (17) 95 11 Output (Data,Var,Rel,NWrp,Lin,Pref,NNul,NVol,Bit) 91 06 Report Count (12) 95 0C Usage (Vendor-Defined 1:Vendor-Defined 1) 0B 01 00 00 FF Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02 End Collection C0
Copyright © Linux教程網 All Rights Reserved