func.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #include "include.h"
  2. #include "fota_proc.h"
  3. #include "usb_com.h"
  4. #include "usb_audio.h"
  5. #include "usb_hid.h"
  6. #include "usb_vendor.h"
  7. #include "utils_hid_usage.h"
  8. #include "wireless_client.h"
  9. func_cb_t func_cb AT(.buf.func_cb);
  10. AT(.text.app.proc.func)
  11. void func_process(void)
  12. {
  13. WDT_CLR();
  14. #if BSP_SARADC_EN
  15. bsp_saradc_process();
  16. #endif
  17. #if BSP_CHARGE_EN
  18. bsp_charge_process();
  19. #endif
  20. #if USB_EN
  21. if (sys_cb.usb_is_active) {
  22. usb_device_process();
  23. }
  24. #endif
  25. #if AB_FOT_EN
  26. fota_process();
  27. #endif
  28. #if BSP_MOUSE_SENSEN_EN
  29. bsp_mouse_sense_process();
  30. #endif
  31. prod_test_process();
  32. }
  33. //func common message process
  34. AT(.text.func.msg)
  35. void func_message(u16 msg)
  36. {
  37. bool event_valid = true;
  38. switch (msg) {
  39. #if USB_EN
  40. case MSG_SYS_PC_INSERT:
  41. printf("[MSG] usb connected\n");
  42. sys_cb.usb_is_active = 1;
  43. #if FUNC_WIRELESS_EN
  44. if (func_cb.sta == FUNC_WIRELESS) {
  45. wireless_send_ctrl_cmd(WIRELESS_CTRL_CMD_CODE_USB_CONNECTED, 0, NULL);
  46. }
  47. #endif
  48. break;
  49. case MSG_SYS_PC_REMOVE: {
  50. printf("[MSG] usb disconnected\n");
  51. func_cb.sta = func_cb.last;
  52. usb_device_exit();
  53. usb_device_deinit();
  54. #if FUNC_WIRELESS_EN
  55. if (func_cb.sta == FUNC_WIRELESS) {
  56. wireless_send_ctrl_cmd(WIRELESS_CTRL_CMD_CODE_USB_DISCONNECTED, 0, NULL);
  57. }
  58. #endif
  59. break;
  60. }
  61. #endif // USB_EN
  62. default:
  63. event_valid = false;
  64. break;
  65. }
  66. if (event_valid) {
  67. lowpwr_pwroff_delay_reset();
  68. lowpwr_sleep_delay_reset();
  69. }
  70. }
  71. ///进入一个功能的总入口
  72. AT(.text.func)
  73. void func_enter(void)
  74. {
  75. bsp_param_sync();
  76. if (func_cb.sta == FUNC_NULL) {
  77. func_cb.sta = (FUNC_BT == param_wl_bt_mode_read())? FUNC_BT: FUNC_WIRELESS;
  78. } else if (func_cb.sta == FUNC_WIRELESS || func_cb.sta == FUNC_BT) {
  79. param_wl_bt_mode_write(func_cb.sta);
  80. }
  81. lowpwr_sleep_delay_reset();
  82. lowpwr_pwroff_delay_reset();
  83. }
  84. AT(.text.func)
  85. void func_exit(void)
  86. {
  87. func_cb.sta = FUNC_IDLE;
  88. }
  89. AT(.text.func)
  90. void func_run(void)
  91. {
  92. printf("%s\n", __func__);
  93. while (1) {
  94. WDT_CLR();
  95. func_enter();
  96. switch (func_cb.sta) {
  97. #if FUNC_BT_EN
  98. case FUNC_BT:
  99. func_bt();
  100. break;
  101. #endif
  102. #if FUNC_LE_FCC_EN
  103. case FUNC_LE_FCC:
  104. func_le_fcc();
  105. break;
  106. #endif
  107. #if FUNC_LE_BQB_RF_EN
  108. case FUNC_LE_BQB_RF:
  109. func_le_bqb_rf();
  110. break;
  111. #endif
  112. #if FUNC_IODM_EN
  113. case FUNC_IODM:
  114. func_iodm();
  115. break;
  116. #endif
  117. #if FUNC_USBD_EN
  118. case FUNC_USBD:
  119. func_usbd();
  120. break;
  121. #endif
  122. #if FUNC_IDLE_EN
  123. case FUNC_IDLE:
  124. func_idle();
  125. break;
  126. #endif
  127. #if FUNC_WIRELESS_EN
  128. case FUNC_WIRELESS:
  129. func_wireless();
  130. break;
  131. #endif
  132. case FUNC_PWROFF:
  133. func_pwroff();
  134. break;
  135. default:
  136. func_exit();
  137. break;
  138. }
  139. }
  140. }