func.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. func_enter();
  95. switch (func_cb.sta) {
  96. #if FUNC_BT_EN
  97. case FUNC_BT:
  98. func_bt();
  99. break;
  100. #endif
  101. #if FUNC_LE_FCC_EN
  102. case FUNC_LE_FCC:
  103. func_le_fcc();
  104. break;
  105. #endif
  106. #if FUNC_LE_BQB_RF_EN
  107. case FUNC_LE_BQB_RF:
  108. func_le_bqb_rf();
  109. break;
  110. #endif
  111. #if FUNC_IODM_EN
  112. case FUNC_IODM:
  113. func_iodm();
  114. break;
  115. #endif
  116. #if FUNC_USBD_EN
  117. case FUNC_USBD:
  118. func_usbd();
  119. break;
  120. #endif
  121. #if FUNC_IDLE_EN
  122. case FUNC_IDLE:
  123. func_idle();
  124. break;
  125. #endif
  126. #if FUNC_WIRELESS_EN
  127. case FUNC_WIRELESS:
  128. func_wireless();
  129. break;
  130. #endif
  131. case FUNC_PWROFF:
  132. func_pwroff();
  133. break;
  134. default:
  135. func_exit();
  136. break;
  137. }
  138. }
  139. }