一、简介
The Human Interface Device (HID) ,即人机交互设备。定义了蓝牙在人机接口设备中的协议、特征和使用规程。典型的应用包括蓝牙鼠标、蓝牙键盘、蓝牙游戏手柄等。该协议改编自USB HID Protocol。
host和device
是USB中的角色概念
- H OST相当于PC主机,device相当于鼠标、键盘这些USB外设
- ble hid中,可以看做蓝牙设备就是device,手机就是host
二、HID Reports
Bluetooth HID devices支持三种Report:Input, Output, and Feature。
1. Input Reports 输入报告
表示Bluetooth HID device发送数据给 Bluetooth HID Host。
2. Output Reports 输出报告
表示Ble HID host 发送数据给 Ble HID device
3. Feature Reports 特征报告
Ble中双向数据通道
三、HID Channel
HID建立Control Channel和Interrupt Channel两个通道。
- report可以在这两条channel上传输,在Control channel上传输的report称为synchronous reports ;
- 在Interrupt channel上传输的report称为asynchronous reports。
- Feature reports are always transferred synchronously using GET_REPORT or SET_REPORT requests。
特征报告 通常同步传输发送GET_REPORT 和 SET_REPORT请求
四、HID Report Modes
Report Protocol Mode和Boot Protocol Mode。
Bluetooth HID Hosts至少支持一种,Bluetooth HID Device则需要支持Report Protocol Mode,并且Report Protocol Mode是Bluetooth HID Device的默认Mode。
五、Bluetooth HID Protocol Messages
这些message不能超过L2CAP的MTU,大小超过MTU的message将被忽略。
Message Header的格式如下:
(1)HANDSHAKE
该Message用来acknowledgeSET_REPORT, SET_IDLE and SET_PROTOCOL等request。只在Control Channel上传输,只由Bluetooth HID device。
Parameter部分定义如下:
(2)HID_CONTROL
控制Bluetooth HID device改变状态。
Parameter部分定义如下:
(3)GET_REPORT
Bluetooth HID Host用来请求Bluetooth HID device的传输。
定义如下:
(4)SET_REPORT
Bluetooth HID Host用来向Bluetooth HID device发起传输。
格式如下:
(5)GET_PROTOCOL
用来获取Bluetooth HID device的Protocol Mode,然后Bluetooth HID device response一个DATA payload说明当前的Protocol Mode。
格式如下:
GET_PROTOCOL Data Definition格式如下:
(6)SET_PROTOCOL
用来设置Bluetooth HID device的Bluetooth HID device Protocol。格式如下:
(7)DATA
代表一个a HID payload。格式如下:
六、Transfers
以HID Protocol messages的形式传输。
(1)Control Channel Transfers
分为Acknowledged和Unacknowledged两种,格式如下:
(2)Interrupt Channel Transfers(中断)
Interrupt IN和Interrupt OUT两种,可以在任意时刻发送。