SYD8801是一款低功耗高性能蓝牙低功耗SOC,集成了高性能2.4GHz射频收发机、32位ARM Cortex-M0处理器、128kB Flash存储器、以及丰富的数字接口。SYD8801片上集成了Balun无需阻抗匹配网络、高效率DCDC降压转换器,适合用于可穿戴、物联网设备等。具体可咨询:http://www.sydtek.com/
本文摘录于:http://blog.csdn.net/bypb2008/article/details/70059624
BLE芯片兴起已经有好几年了,从最初的TICC254x的火热到后期之秀Dialog在小米手环的绽放,产品形态也从最初的防丢器应用延时到可穿戴产品,智能家居和消费类产品等各个方面。
采用BLE技术的蓝牙遥控器,也是最近兴起的产品,有很大的市场空间。相比普通的红外遥控器,蓝牙遥控有很明显的优点:1.360°无死角遥控,遥控距离更远 2.通过与智能电视或者机顶盒配对,可以实现独立无干扰的控制 3.可扩展性强,可以集成简单的语音控制和体感游戏控制 4.增加很低的成本,即可兼具红外遥控器功能和红外学习功能。
本文描述了基于SYD8801的蓝牙遥控器设计方案,供开发人员参考。
1. 首先看看SYD8801的系统框图和改芯片的主要性能参数,对芯片有大致的了解:
2. 原理图设计
由于SYD8801 片上集成了Balun ,无需阻抗匹配网络,无需外挂晶振负载电容,最大限度地节省BOM 成本。外部也只需要矩阵键盘和简单的元器件,极具成本优势。
3. 软件架构描述
int main(void)
{
__disable_irq();
ble_init(); //clk init
gpio_init();
dbg_init();dbg_printf("RCU Power On!\r\n");
#ifdef CONFIG_LED
led_config(LEDALL);
led_flash();
#endif
RCU_set_work_mode(RCU_MODE_BT);
io_irq_enable(BIT16|BIT17|BIT18|BIT19|IFR, &gpio_int_callback);
__enable_irq();
while(1)
{
if(work_mode == RCU_MODE_IR_RECEIVING)//瞬态的自加模式,会自动降到下一模式
{
__disable_irq();
pulse_time++;
__enable_irq();
}
else if(work_mode == RCU_MODE_IR_RECEIVE_WAITING)//红外学习模式
{
if(IR_receive_CMP == 1)
{
IR_receive_CMP = 0;
RCU_receive_decode();
enable_IR_receive(1);
}
KeyEvent_Handle();
}
else //蓝牙模式、红外发射模式
{
ble_sched_execute();
KeyEvent_Handle();
SystemSleep();
}
}
}
在BLE初始化中调用:
evt.evt_mask=(GAP_EVT_CONNECTION_SLEEP|GAP_EVT_CONNECTION_INTERVAL);
evt.p_callback=&ble_evt_callback;
SetEvtCallback(&evt);
给底层协议栈注册ble_evt_callback(),当发生蓝牙事件的时候,会调用:
static void ble_evt_callback(struct gap_ble_evt *p_evt)
{
if(p_evt->evt_code == GAP_EVT_ADV_END)
{
//广播结束
}
else if(p_evt->evt_code == GAP_EVT_ATT_READ)
{
//读特征
}
else if(p_evt->evt_code == GAP_EVT_ATT_HANDLE_CONFIGURE)
{
//配置服务
}
else if(p_evt->evt_code == GAP_EVT_ENC_KEY)
{
//配对
}
else if(p_evt->evt_code == GAP_EVT_CONNECTED)
{
//连接
}
else if(p_evt->evt_code == GAP_EVT_DISCONNECTED)
{
//断开
}
}
通过调用该函数,处理相应的蓝牙事件。
矩阵扫描通过中断触发gpio_int_callback();
按键事件处理函数KeyEvent_Handle();
通过主函数可以看到,遥控器一共有3种主要的运行模式:蓝牙模式、红外发送模式、红外接收(学习)模式。
红外学习也采用中断方式解码红外接收头数据,目前红外主要采用NEC模式的红外协议。红外接收解码基本上准确无误。
4. 蓝牙服务描述
The Remote control reference application implements the following services:
--GAP
--GATT
--DIS
--HID over GATT
--Battery
其中HID服务可支持keyborad,mouse,system control,consumer key等HID报告。
5. 功耗测试情况
目前已经在iphone4s,iphone5s,iphone6,华为P9,创维电视盒子上运行OK。
6. 软件开发环境采用MDK,目前蓝牙遥控器的代码空间使用情况
功能:蓝牙遥控、红外遥控、红外学习
Program Size: Code=18962 RO-data=546 RW-data=212 ZI-data=7804
按键功能
官方手册上指定的按键功能如下:
注意:音量加和减按键为上图中的UP和DOWN按键,这里删除flash中的绑定数据后系统会重启,并且开始新的广播,也就说可以连接新的设备。
如果不知道按键的功能下载好程序后按下遥控器的按键,在串口上会显示按键的意义。
比如有如下的按键功能:
DVD:控制主机的音量加
VCR:控制主机的音量减
安卓手机功能演示
这里下载好程序后复位SYD8801可以在设置中看到蓝牙设备,然后点击进行连接,并且进行配对,然后进行连接,最后连接成功:
连接成功后按下音量DVD按钮(音量加)即可控制手机音量:
操作视频可看:https://download.csdn.net/download/chengdong1314/10337251
整个流程串口打印如下(连接上一段时间不按下按键后断开连接然后按下按键重新连接):
RCU Power On!
start_adv - ADV_TYPE: RANDOM_ADDRESS_TYPE
Adv Completely!
key 8080400
start_adv - ADV_TYPE: RANDOM_ADDRESS_TYPE
key 18 Pressed:DOWN
Delete bond info & reset!!!
RCU Power On!
start_adv - ADV_TYPE: No bonds_device
GAP_EVT_CONNECTED
GAP_EVT_ENC_START
GAP_EVT_ENC_KEY
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020000
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8020000
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
PDown:send Disconnect req!
GAP_EVT_DISCONNECTED
key 8020100
start_adv - ADV_TYPE: RANDOM_ADDRESS_TYPE
key 8 Pressed:VOL-
key 8 Loose:VOL-
GAP_EVT_CONNECTED
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ENC_START
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010000
key 0 Pressed:VOL+
key 7 Pressed:RECORD
key 0 Loose:VOL+
key 7 Loose:RECORD
key 8010000
key 0 Pressed:VOL+
key 7 Pressed:RECORD
key 0 Loose:VOL+
key 7 Loose:RECORD
key 8010000
key 0 Pressed:VOL+
key 7 Pressed:RECORD
key 0 Loose:VOL+
key 7 Loose:RECORD
key 8010100
key 0 Pressed:VOL+
key 6 Pressed:RETURN
key 7 Pressed:RECORD
key 0 Loose:VOL+
key 6 Loose:RETURN
key 7 Loose:RECORD
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 14 Pressed:HOME
key 8 Loose:VOL-
key 14 Loose:HOME
key 8020100
key 8 Pressed:VOL-
key 14 Pressed:HOME
key 14 Loose:HOME
key 8 Loose:VOL-
key 8020000
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020000
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020000
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010000
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010000
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010000
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010000
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8020000
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020000
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020000
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8010000
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010000
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010000
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010000
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8010000
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020000
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
PDown:send Disconnect req!
GAP_EVT_DISCONNECTED
ios功能演示
下载好代码后在IOS的设置中可以看到蓝牙遥控器,然后连接、配对、最后连接成功:
下来按下遥控器的音量控制按钮(VCR或者DVD按键)就可以控制IOS手机的音量了:
实际情况如下:
操作视频可看:https://download.csdn.net/download/chengdong1314/10337404
整个流程串口打印如下(从安卓删除绑定,并且绑定到IOS,最后发送音量按键):
key c080000
start_adv - ADV_TYPE: No bonds_device
key 18 Pressed:DOWN
Delete bond info & reset!!!
RCU Power On!
start_adv - ADV_TYPE: No bonds_device
GAP_EVT_CONNECTED
GAP_EVT_ENC_START
GAP_EVT_ENC_KEY
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
PDown:send Disconnect req!
GAP_EVT_DISCONNECTED
key 8010100
start_adv - ADV_TYPE: RANDOM_ADDRESS_TYPE
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 PresGAP_EVT_CONNECTED
NNECTED
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ENC_START
key 0 Loose:VOL+
key 8010100
keyGAP_EVT_ATT_HANDLE_CONFIGURE
_EVT_ATT_HANDLE_CGAP_EVT_ATT_HANDLE_CONFIGURE
GAP_EVT_ATT_HANDLE_CONFIGURE
key 0 LGAP_EVT_ATT_HANDLE_CONFIGURE
_ATT_HANDLE_Ckey 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8010100
key 0 Pressed:VOL+
key 0 Loose:VOL+
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020000
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
key 8020100
key 8 Pressed:VOL-
key 8 Loose:VOL-
PDown:send Disconnect req!
GAP_EVT_DISCONNECTED