main.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include <stdarg.h>
  2. #include "yc11xx.h"
  3. #include "yc11xx_gpio.h"
  4. #include "yc11xx_uart.h"
  5. #include "yc_timer.h"
  6. #include "system.h"
  7. #include "yc_lpm.h"
  8. #include "ipc.h"
  9. #include "att.h"
  10. #include "core_cm0.h"
  11. #include "yc11xx_bt_interface.h"
  12. void nec_receive_enable(GPIO_NUM gpio);
  13. void Bt_NecCallBack(uint8_t len,uint8_t *dataPtr);
  14. void Bt_EvtCallBack(uint8_t len,uint8_t *dataPtr);
  15. void Bt_BleCallBack(uint8_t len,uint8_t *dataPtr);
  16. tIPCHandleCb gTIPCHandleCb[IPC_TYPE_NUM]=
  17. {
  18. 0,
  19. IpcDefaultCallBack,//cmd
  20. Bt_EvtCallBack,//evt //evt回调函数,函数在drv_bt.c实现
  21. IpcDefaultCallBack,//hid
  22. IpcDefaultCallBack,//spp
  23. Bt_BleCallBack,//ble //ble data回调函数,函数在drv_bt.c实现
  24. IpcDefaultCallBack,//24g
  25. IpcDefaultCallBack,//mesh
  26. IpcDefaultCallBack,
  27. IpcDefaultCallBack,//mesh
  28. IpcDefaultCallBack,//a2dp
  29. IpcDefaultCallBack,//hfp
  30. Bt_NecCallBack
  31. };
  32. int main(void)
  33. {
  34. if(HREAD(mem_wake_flag)==POWERON_WAKE)
  35. {
  36. IPC_init(&gTIPCHandleCb); //蓝牙回调函数初始化
  37. SYS_TimerInit();
  38. printport_init();
  39. Att_profile_Config();
  40. MyPrintf("BlueTooth send and recive Demo !\r\n");
  41. Lpm_exit();
  42. nec_receive_enable(GPIO_19); //nec接收使能
  43. }
  44. else
  45. {
  46. printport_init();
  47. SysTick_Config(SYSTEM_CLOCK/100);
  48. }
  49. SYS_ClkTicks();
  50. while(1)
  51. {
  52. switch (HREAD(IPC_MCU_STATE))
  53. {
  54. case IPC_MCU_STATE_RUNNING:
  55. IPC_HandleRxPacket(); //m0和bt交互数据类型判断,是evt还是ble data?并执行对应回调函数
  56. SYS_timerPolling();
  57. Lpm_unLockLpm(M0_LPM_FLAG);
  58. break;
  59. case IPC_MCU_STATE_LMP: //lpm
  60. if (IPC_IsTxBuffEmpty())
  61. {
  62. OS_ENTER_CRITICAL();
  63. Bt_ActionBeforeLpm();
  64. HWRITE(IPC_MCU_STATE,IPC_MCU_STATE_STOP);
  65. }
  66. else{
  67. HWRITE(IPC_MCU_STATE,IPC_MCU_STATE_RUNNING);
  68. }
  69. break;
  70. case IPC_MCU_STATE_HIBERNATE: // HIBERNATE
  71. OS_ENTER_CRITICAL();
  72. Bt_ActionBeforeHibernate();
  73. HWRITE(IPC_MCU_STATE,IPC_MCU_STATE_STOP);
  74. break;
  75. case IPC_MCU_STATE_STOP:
  76. break;
  77. }
  78. }
  79. }
  80. //选择 nec接收的gpio, 开使能
  81. void nec_receive_enable(GPIO_NUM gpio)
  82. {
  83. GPIO_SetGpioMultFunction(gpio,GPCFG_PULLUP);
  84. HWRITE(mem_nec_gpio,gpio);
  85. HWRITE(mem_nec_receive_enable,1);
  86. }
  87. #define NEC_CMD 0x01
  88. #define NEC_REPEAT_CMD 0x02
  89. void Bt_NecCallBack(uint8_t len,uint8_t *dataPtr)
  90. {
  91. switch(*dataPtr)
  92. {
  93. case NEC_CMD:
  94. for(int i=0;i<len-1;i++)
  95. {
  96. MyPrintf("nec data[%d]=%x\r\n",i,dataPtr[i+1]);
  97. }
  98. break;
  99. case NEC_REPEAT_CMD:
  100. MyPrintf("\r\n*************NEC_REPEAT_CMD****************\r\n");
  101. break;
  102. default:
  103. break;
  104. }
  105. }
  106. void Bt_EvtCallBack(uint8_t len,uint8_t *dataPtr)
  107. {
  108. }
  109. void Bt_BleCallBack(uint8_t len,uint8_t *dataPtr)
  110. {
  111. }