123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- #include <stdarg.h>
- #include "yc11xx.h"
- #include "yc11xx_gpio.h"
- #include "yc11xx_uart.h"
- #include "yc_timer.h"
- #include "system.h"
- #include "yc_lpm.h"
- #include "ipc.h"
- #include "att.h"
- #include "core_cm0.h"
- #include "yc11xx_bt_interface.h"
- void nec_receive_enable(GPIO_NUM gpio);
- void Bt_NecCallBack(uint8_t len,uint8_t *dataPtr);
- void Bt_EvtCallBack(uint8_t len,uint8_t *dataPtr);
- void Bt_BleCallBack(uint8_t len,uint8_t *dataPtr);
- tIPCHandleCb gTIPCHandleCb[IPC_TYPE_NUM]=
- {
- 0,
- IpcDefaultCallBack,//cmd
- Bt_EvtCallBack,//evt //evt回调函数,函数在drv_bt.c实现
- IpcDefaultCallBack,//hid
- IpcDefaultCallBack,//spp
- Bt_BleCallBack,//ble //ble data回调函数,函数在drv_bt.c实现
- IpcDefaultCallBack,//24g
- IpcDefaultCallBack,//mesh
- IpcDefaultCallBack,
- IpcDefaultCallBack,//mesh
- IpcDefaultCallBack,//a2dp
- IpcDefaultCallBack,//hfp
- Bt_NecCallBack
- };
- int main(void)
- {
- if(HREAD(mem_wake_flag)==POWERON_WAKE)
- {
- IPC_init(&gTIPCHandleCb); //蓝牙回调函数初始化
- SYS_TimerInit();
- printport_init();
- Att_profile_Config();
- MyPrintf("BlueTooth send and recive Demo !\r\n");
- Lpm_exit();
- nec_receive_enable(GPIO_19); //nec接收使能
- }
- else
- {
- printport_init();
- SysTick_Config(SYSTEM_CLOCK/100);
- }
- SYS_ClkTicks();
- while(1)
- {
- switch (HREAD(IPC_MCU_STATE))
- {
- case IPC_MCU_STATE_RUNNING:
- IPC_HandleRxPacket(); //m0和bt交互数据类型判断,是evt还是ble data?并执行对应回调函数
- SYS_timerPolling();
- Lpm_unLockLpm(M0_LPM_FLAG);
- break;
- case IPC_MCU_STATE_LMP: //lpm
- if (IPC_IsTxBuffEmpty())
- {
- OS_ENTER_CRITICAL();
- Bt_ActionBeforeLpm();
- HWRITE(IPC_MCU_STATE,IPC_MCU_STATE_STOP);
- }
- else{
- HWRITE(IPC_MCU_STATE,IPC_MCU_STATE_RUNNING);
- }
- break;
- case IPC_MCU_STATE_HIBERNATE: // HIBERNATE
- OS_ENTER_CRITICAL();
- Bt_ActionBeforeHibernate();
- HWRITE(IPC_MCU_STATE,IPC_MCU_STATE_STOP);
- break;
- case IPC_MCU_STATE_STOP:
- break;
- }
- }
- }
- //选择 nec接收的gpio, 开使能
- void nec_receive_enable(GPIO_NUM gpio)
- {
- GPIO_SetGpioMultFunction(gpio,GPCFG_PULLUP);
- HWRITE(mem_nec_gpio,gpio);
- HWRITE(mem_nec_receive_enable,1);
- }
- #define NEC_CMD 0x01
- #define NEC_REPEAT_CMD 0x02
- void Bt_NecCallBack(uint8_t len,uint8_t *dataPtr)
- {
- switch(*dataPtr)
- {
- case NEC_CMD:
- for(int i=0;i<len-1;i++)
- {
- MyPrintf("nec data[%d]=%x\r\n",i,dataPtr[i+1]);
- }
- break;
- case NEC_REPEAT_CMD:
- MyPrintf("\r\n*************NEC_REPEAT_CMD****************\r\n");
- break;
- default:
- break;
- }
- }
- void Bt_EvtCallBack(uint8_t len,uint8_t *dataPtr)
- {
- }
- void Bt_BleCallBack(uint8_t len,uint8_t *dataPtr)
- {
- }
|