func.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. touch_process();
  33. }
  34. //func common message process
  35. AT(.text.func.msg)
  36. void func_message(u16 msg)
  37. {
  38. bool event_valid = true;
  39. switch (msg) {
  40. #if USB_EN
  41. case MSG_SYS_PC_INSERT:
  42. printf("[MSG] usb connected\n");
  43. sys_cb.usb_is_active = 1;
  44. #if FUNC_WIRELESS_EN
  45. if (func_cb.sta == FUNC_WIRELESS) {
  46. wireless_send_ctrl_cmd(WIRELESS_CTRL_CMD_CODE_USB_CONNECTED, 0, NULL);
  47. }
  48. #endif
  49. break;
  50. case MSG_SYS_PC_REMOVE: {
  51. printf("[MSG] usb disconnected\n");
  52. func_cb.sta = func_cb.last;
  53. usb_device_exit();
  54. usb_device_deinit();
  55. #if FUNC_WIRELESS_EN
  56. if (func_cb.sta == FUNC_WIRELESS) {
  57. wireless_send_ctrl_cmd(WIRELESS_CTRL_CMD_CODE_USB_DISCONNECTED, 0, NULL);
  58. }
  59. #endif
  60. break;
  61. }
  62. #endif // USB_EN
  63. default:
  64. event_valid = false;
  65. break;
  66. }
  67. if (event_valid) {
  68. lowpwr_pwroff_delay_reset();
  69. lowpwr_sleep_delay_reset();
  70. }
  71. }
  72. ///进入一个功能的总入口
  73. AT(.text.func)
  74. void func_enter(void)
  75. {
  76. bsp_param_sync();
  77. if (func_cb.sta == FUNC_NULL) {
  78. func_cb.sta = (FUNC_BT == param_wl_bt_mode_read())? FUNC_BT: FUNC_WIRELESS;
  79. } else if (func_cb.sta == FUNC_WIRELESS || func_cb.sta == FUNC_BT) {
  80. param_wl_bt_mode_write(func_cb.sta);
  81. }
  82. lowpwr_sleep_delay_reset();
  83. lowpwr_pwroff_delay_reset();
  84. }
  85. AT(.text.func)
  86. void func_exit(void)
  87. {
  88. func_cb.sta = FUNC_IDLE;
  89. }
  90. AT(.text.func)
  91. void func_run(void)
  92. {
  93. printf("%s\n", __func__);
  94. while (1) {
  95. WDT_CLR();
  96. func_enter();
  97. switch (func_cb.sta) {
  98. #if FUNC_BT_EN
  99. case FUNC_BT:
  100. func_bt();
  101. break;
  102. #endif
  103. #if FUNC_LE_FCC_EN
  104. case FUNC_LE_FCC:
  105. func_le_fcc();
  106. break;
  107. #endif
  108. #if FUNC_LE_BQB_RF_EN
  109. case FUNC_LE_BQB_RF:
  110. func_le_bqb_rf();
  111. break;
  112. #endif
  113. #if FUNC_IODM_EN
  114. case FUNC_IODM:
  115. func_iodm();
  116. break;
  117. #endif
  118. #if FUNC_USBD_EN
  119. case FUNC_USBD:
  120. func_usbd();
  121. break;
  122. #endif
  123. #if FUNC_IDLE_EN
  124. case FUNC_IDLE:
  125. func_idle();
  126. break;
  127. #endif
  128. #if FUNC_WIRELESS_EN
  129. case FUNC_WIRELESS:
  130. func_wireless();
  131. break;
  132. #endif
  133. case FUNC_PWROFF:
  134. func_pwroff();
  135. break;
  136. default:
  137. func_exit();
  138. break;
  139. }
  140. }
  141. }