USB初学(一)---USB-HID的初步认识【转】(二)
pe |
1 |
常量 |
HID相关描述符的类型 0x21:HID描述符 0x22:报告描述符 0x23:物理描述符 |
7 |
wDescriptorLength |
2 |
数字 |
报告描述符总长度 |
9 |
bDescriptorType |
1 |
常量用于识别描述符类型的常量,使用在有一个以上描述符的设备 |
10 |
wDescriptorLength |
2 |
数字 |
描述符总长度,使用在有一个以上描述符的设备 |
报告描述符
报告描述符比较复杂,它是以item形式排列组合而成,无固定长途,用户可以自定义长度以及每一bit的含义。item类型分三种:main,global和local,其中main类型又可分为5种tag:
- input item tag:指的是从设备的一个或多个类似控制管道得到的数据
- output item tag:指的是发送给一个或多个类似控制管道的数据
- feature item tag:表示设备的输入输出不面向最终用户
- collection item tag:一个有意义的input,output和feature的组合项目
- end collection item tag:指定一个collectionitem的终止
每一个main item tag(input,output,feature)都表明了来自一个特定管道的数据的大小,数据相对还是独立,以及其他相关信息。在此之前,global和local item定义了数据的最大值和最小值,等等。local item仅仅描述下一个main item定义的数据域,而global item是这一个报告描述符中所有后续数据段的默认属性。
一个报告描述符可能包含多个main item,为了准确描述来自一个控制管道的数据,一个报告描述符必须包括以下内容:
- input(output,feature)
- usage
- usage page
- Logical Minimum
- Logical Maximum
- Report Size
- Report Count
Usage Page (Generic Desktop); //global item
Usage (Mouse); //global item
Collection (Application); //Start Mouse collection
Usage (Pointer); //
Collection (Physical); //Start Pointer collection
Usage Page (Buttons)
Usage Minimum (1),
Usage Maximum (3),
Logical Minimum (0),
Logical Maximum (1) ; //Fields return values from 0 to 1
Report Count (3),
Report Size (1); //Create three 1 bit fields (button 1, 2, & 3)
Input (Data, Variable, Absolute); //Add fields to the input report.
Report Count (1),
Report Size (5); //Create 5 bit constant field
Input (Constant), ;Add field to the input report
Usage Page (Generic Desktop),
Usage (X),
Usage (Y),
Logical Minimum (-127),
Logical Maximum (127); //Fields return values from -127 to 127
Report Size (8),
Report Count (2); //Create two 8 bit fields (X & Y position)
Input (Data, Variable, Relative); //Add fields to the input report
End Collection; //Close Pointer collection
End Collection; //Close Mouse collection
item的数据格式有两种,分别是短item和长item。
短item格式
bType |
0:main 1:global 2:local 3:保留 |
bTag |
item类型 8:input 9:output A:collection B:feature C:end collection
|
长item,其bType位值为3,bTag值为F
bLongItemTag |
bLongItemTag 0:main 1:global 2:local 3:保留 |
data |
数据 |
物理描述符
物理描述符被用来描述设备的行为特性,物理描述符是可选的,HID设备可以根据其本体的设备特性选择是否包含物理描述符。下表是HID的物理描述符结构。
HID物理描述符的结构
物理描述符用来描述行为特性,是可选的。
0 |
bDesignator |
1 |
用来指定本体的哪一部分影响项目 |
1 |
bFlags |
1 |
位指定标志 位0~4:Effort 位5~7:Qualifier |
bDesignator取值含义表
0x00 |
无 |
0x15 |
小指 |
0x01 |
手 |
0x16 |
头 |
0x02 |
眼球 |
0x17 |
肩 |
0x03 |
眉 |
0x18 |
腰骨 |
0x04 |
眼皮 |
0x19 |
腰 |
0x05 |
耳 |
0x1A |
大腿 |
0x06 |
鼻 |
0x1B |
膝盖 |
0x07 |
嘴 |
0x1C |
小腿 |
0x08 |
上唇 |
0x1D |
足 |
0x09 |
下唇 |
0x1E |
脚 |
0x0A |
颚 |
0x1F |
脚跟 |
0x0B |
颈 |
0x20 |
拇指 |
0x0C |
上臂 |
0x21 |
大拇指 |
0x0D |
手肘 |
0x22 |
第二指 |
0x0E |
前臂 |
0x23 |
第三指 |
0x0F |
手腕 |
0x24 |
第四指 |
0x10 |
手掌 |
0x25 |
小拇指 |
0x11 |
拇指 |
0x26 |
眉 |
0x12 |
食指 |
0x27 |
脸 |
0x13 |
中指 |
0x28~0xFF |
保留 |
0x14 |
无名指 |
- |
- |
Qualifier取值含义
0x00 |
无 |
0x04 |
其中之一 |
0x01 |
右 |
0x05 |
中间 |
0x02 |
左 |
0x06 |
保留 |
0x03 |
同时 |
0x07 |
保留 |
USB HID类可采用的通信管道
所有的HID设备通过USB的控制管道(默认管道,即端点0)和中断管道与主机通信。
控制管道主要用于以下3个方面:
中断管道主要用于以下两个方面:
表1、USB HID规范定义的HID设备可用端点
|