首页 > 编程知识 正文

ESP32学习笔记之蓝牙HID

时间:2023-05-03 07:08:23 阅读:206535 作者:4916

The Human Interface Device(HID)定义了蓝牙在人机接口设备中的协议、特征和使用规程。

典型的应用包括:蓝牙鼠标、蓝牙键盘、蓝牙游戏手柄等;该协议改编自USB HID Protocol。

蓝牙4.0以上的HID是基于HID-over-GATT,如果蓝牙IC支持GATT,那么就可以通过修改固件来实现作为蓝牙HID设备。

蓝牙HID的一些概念

HID Reports:Bluetooth HID devices支持三种Report:Input,Output,and FeatureHID建立Control Channel和Interrupt Channel两个通道,report可以在这两条channel上传输,在Control channel上传输的report称为synchronous reports;在Interrupt channel上传输的report称为asynchronous reportsFeature Protocol总是通过通过同步的方式使用GET_REPORT和SET_REPORT的请求

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

消息的长度不能超过L2CAP的MTU,大小超过MTU的message将被忽略。

Message Header的格式如下:

HANDSHAKE

该Message用来acknowledge应答SET_REPORT,SET_IDLE and  SET_PROTOCOL等request。只在Control Channel上传输,只由Bluetooth HID device。

Parameter部分定义如下:

HID_CONTROL

控制Bluetooth HID Device改变状态

 Parameter部分定义如下:

GET_REPORT

Bluetooth HID Host用来请求Bluetooth HID device的传输

Parameter部分定义如下:

SET_REPORT

Bluetooth HID Host用来向Bluetooth HID device发起传输。

格式如下:

 GET_PROTOCOL

用来获取Bluetooth HID device的Protocol Mode,然后Bluetooth HID device response一个DATA payload说明当前的Protocol Mode,格式如下:

GET_PROTOCOL Data Definition格式如下: 

SET_PROTOCOL

用来设置Bluetooth HID device的Bluetooth HID device。格式如下:

 

DATA

代表一个HID payload。格式如下:

 

 Transfers

以HID Protocol message的形式传输。

Control Channel Transfers

分为Acknowledged和Unacknowledged两种,格式如下:

Interrupt Channel Transfers

 Interrupt IN和Interrupt OUT两种,可以在任意时刻发送。【中断嘛】

其余各层对于HID的要求

HID与L2CAP的交互如下:

参考文献

https://www.cnblogs.com/senior-engineer/p/9842251.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。