HID profile的简单建立

目标:在BLE设备上建立HIDprofile,实现按键拍照功能。

1、服务的特征选择

本着最简原则,这里建立两个特征。特征1:report map。这里选择REPORT_MAP_CHAR(程序内的值),作为特征申明。REPORT_MAP_VAL作为report map(uuid:0x2a4b)在程序里面的att值。
特征2:report。申明特征,表明特征带report(uuid:0x2a4d)并且选择report引用(uuid:0x2908)。

2、report map

static const uint8_t app_hid_report_map[] = 
{
	// Report ID 1: Advanced buttons
	0x05, 0x0C, 	  // Usage Page (Consumer)
	0x09, 0x01, 	  // Usage (Consumer Control)
	0xA1, 0x01, 	  // Collection (Application)
	0x85, 0x01, 	  // Report Id (1)
	0x15, 0x00, 	  // Logical minimum (0)
	0x25, 0x01, 	  // Logical maximum (1)
	0x75, 0x01, 	  // Report Size (1)
	0x95, 0x01, 	  // Report Count (1)
	
	0x09, 0xCD, 	  // Usage (Play/Pause)
	0x81, 0x06, 	  // Input (Data,Value,Relative,Bit Field)
	0x0A, 0x83, 0x01, // Usage (AL Consumer Control Configuration)
	0x81, 0x06, 	  // Input (Data,Value,Relative,Bit Field)
	0x09, 0xB5, 	  // Usage (Scan Next Track)
	0x81, 0x06, 	  // Input (Data,Value,Relative,Bit Field)
	0x09, 0xB6, 	  // Usage (Scan Previous Track)
	0x81, 0x06, 	  // Input (Data,Value,Relative,Bit Field)
	
	0x09, 0xEA, 	  // Usage (Volume Down)
	0x81, 0x06, 	  // Input (Data,Value,Relative,Bit Field)
	0x09, 0xE9, 	  // Usage (Volume Up)
	0x81, 0x06, 	  // Input (Data,Value,Relative,Bit Field)
	0x0A, 0x25, 0x02, // Usage (AC Forward)
	0x81, 0x06, 	  // Input (Data,Value,Relative,Bit Field)
	0x0A, 0x24, 0x02, // Usage (AC Back)
	0x81, 0x06, 	  // Input (Data,Value,Relative,Bit Field)
	0xC0,			  // End Collection

};

map解析可以看HID设备描述符的解析这篇文章

3、服务handler

1、响应写指令:host端会发送写指令,这里不作处理也行,只要不发送错误即可。
2、响应读指令:host端会发送读指令获取report map,可以在此将map发送。

4、report数据

hid功能最重要的是report,这是实现拍照功能的关键。我们只需要将report 数据和ATT_CHAR_REPORT对应的句柄用notify的形式发送即可。

5、注意

我们的report特征是需要有value的,需要将report id与report type写入,否则host端无法将收到的report id与report map中的id对应起来。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值