device.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #include "include.h"
  2. #if SD_SOFT_DETECT_EN
  3. AT(.text.bsp.sys.init)
  4. void sd_soft_detect_poweron_check(void) //开机检测
  5. {
  6. if (!SD_IS_SOFT_DETECT()) { //配置工具中是否配置sd检测.
  7. return;
  8. }
  9. dev_delay_times(DEV_SDCARD, 1); //检测到1次成功, 则认为SD在线.
  10. u8 i = 5;
  11. while(i--) {
  12. sd_soft_cmd_detect(0);
  13. if (dev_is_online(DEV_SDCARD)) {
  14. break;
  15. }
  16. delay_ms(10);
  17. }
  18. dev_delay_times(DEV_SDCARD, 3);
  19. }
  20. AT(.com_text.detect)
  21. void sd_soft_cmd_detect(u32 check_ms) //check_ms 时间间隔检测一次. //主循环中执行检测.
  22. {
  23. static u32 check_ticks = 0;
  24. if (!SD_IS_SOFT_DETECT()) { //配置工具中是否配置sd检测.
  25. return;
  26. }
  27. if (tick_check_expire(check_ticks, check_ms) || (0 == check_ticks)) { //每隔100ms才检测一次.
  28. check_ticks = tick_get();
  29. }else {
  30. return;
  31. }
  32. if (sd_soft_detect()) {
  33. if (dev_online_filter(DEV_SDCARD)) {
  34. sd_insert();
  35. msg_enqueue(EVT_SD_INSERT);
  36. // printf("sd soft insert\n");
  37. }
  38. } else {
  39. if (dev_offline_filter(DEV_SDCARD)) {
  40. sd_remove();
  41. msg_enqueue(EVT_SD_REMOVE);
  42. }
  43. }
  44. }
  45. #endif
  46. #if MUSIC_SDCARD_EN
  47. AT(.com_text.detect)
  48. void sd_detect(void)
  49. {
  50. if ((!is_sd_support()) || (SD_DETECT_IS_BUSY())) {
  51. return;
  52. }
  53. #if SD_SOFT_DETECT_EN
  54. if (SD_IS_SOFT_DETECT()) {
  55. return;
  56. }
  57. #endif
  58. if (SD_IS_ONLINE()) {
  59. if (dev_online_filter(DEV_SDCARD)) {
  60. sd_insert();
  61. msg_enqueue(EVT_SD_INSERT);
  62. // printf("sd insert\n");
  63. }
  64. } else {
  65. if (dev_offline_filter(DEV_SDCARD)) {
  66. sd_remove();
  67. msg_enqueue(EVT_SD_REMOVE);
  68. // printf("sd remove\n");
  69. }
  70. }
  71. }
  72. #endif // MUSIC_SDCARD_EN
  73. AT(.com_text.detect)
  74. u8 get_usbtf_muxio(void)
  75. {
  76. #if SD_USB_MUX_IO_EN
  77. return 1;
  78. #else
  79. return 0;
  80. #endif
  81. }
  82. //AT(.com_text.const)
  83. //const char usb_detect_str[] = "USB STA:%d\r\n";
  84. //AT(.com_text.const)
  85. //const char usb_insert_str[] = "udisk insert\n";
  86. //AT(.com_text.const)
  87. //const char usb_remove_str[] = "udisk remove\n";
  88. #if USB_SUPPORT_EN
  89. AT(.com_text.detect)
  90. void usb_detect(void)
  91. {
  92. if (!is_usb_support()) {
  93. return;
  94. }
  95. u8 usb_sta;
  96. #if USB_DET_VER_SEL
  97. usb_sta = usb_connect();
  98. #else
  99. #if FUNC_USBDEV_EN
  100. usb_sta = usbchk_connect(USBCHK_OTG);
  101. #else
  102. usb_sta = usbchk_connect(USBCHK_ONLY_HOST);
  103. #endif
  104. #endif
  105. if (usb_sta == USB_UDISK_CONNECTED) {
  106. if (dev_online_filter(DEV_UDISK)) {
  107. udisk_insert();
  108. msg_enqueue(EVT_UDISK_INSERT);
  109. // printf(usb_insert_str);
  110. }
  111. } else {
  112. if (dev_offline_filter(DEV_UDISK)) {
  113. udisk_remove();
  114. msg_enqueue(EVT_UDISK_REMOVE);
  115. // printf(usb_remove_str);
  116. }
  117. }
  118. #if FUNC_USBDEV_EN
  119. if (usb_sta == USB_PC_CONNECTED) {
  120. if (dev_online_filter(DEV_USBPC)) {
  121. msg_enqueue(EVT_PC_INSERT);
  122. //printf("pc insert\n");
  123. }
  124. } else {
  125. if (dev_offline_filter(DEV_USBPC)) {
  126. msg_enqueue(EVT_PC_REMOVE);
  127. pc_remove();
  128. // printf("pc remove\n");
  129. }
  130. }
  131. #endif
  132. }
  133. #endif // USB_SUPPORT_EN
  134. #if LINEIN_DETECT_EN
  135. AT(.com_text.detect)
  136. void linein_detect(void)
  137. {
  138. if (LINEIN_DETECT_IS_BUSY()) {
  139. return;
  140. }
  141. if (LINEIN_IS_ONLINE()) {
  142. if (dev_online_filter(DEV_LINEIN)) {
  143. msg_enqueue(EVT_LINEIN_INSERT);
  144. // printf("linein insert\n");
  145. }
  146. } else {
  147. if (dev_offline_filter(DEV_LINEIN)) {
  148. msg_enqueue(EVT_LINEIN_REMOVE);
  149. // printf("linein remove\n");
  150. }
  151. }
  152. }
  153. #endif // LINEIN_DETECT_EN
  154. #if USER_INEAR_DETECT_EN
  155. AT(.com_text.detect)
  156. void earin_detect(void)
  157. {
  158. if (INEAR_IS_ONLINE()) {
  159. if (dev_online_filter(DEV_EARIN)) {
  160. }
  161. } else {
  162. if (dev_offline_filter(DEV_EARIN)) {
  163. }
  164. }
  165. }
  166. #endif