bsp_music.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #include "include.h"
  2. u8 get_piano_index(u8 num);
  3. bool bt_ring_msbc_play(uint index, u32 tws_sync);
  4. void bt_tws_ring_tone_stop(void);
  5. void tws_set_sta_for_res(uint32_t res);
  6. void dac_digvol_fade(u32 flag, u32 step);
  7. int bt_ring_esbc_play(u8 index, const u8 *ptr, const u8 *sptr, u32 size, u32 tws_sync);
  8. int bt_ring_sbc_play(uint index, u32 tws_sync);
  9. bool esbc_inner_res_play(uint index, u32 tws_sync);
  10. AT(.text.music.res)
  11. bool sys_warning_play_do(uint index, uint type, u32 tws_sync)
  12. {
  13. bool res_play = false;
  14. #if VUSB_TBOX_QTEST_EN
  15. if (!get_qtest_mode())
  16. #endif
  17. {
  18. if (type == 1) {
  19. //tone音
  20. piano_warning_play(index, get_piano_index(index), tws_sync);
  21. res_play = true;
  22. } else if (type == 2) {
  23. //esbc
  24. if (!esbc_res_play(index, (const u8 *)sbcplay_cb.buf, NULL, sbcplay_cb.len, tws_sync)) {
  25. res_play = true;
  26. }
  27. } else if (type == 3) {
  28. //sbc
  29. sbc_res_play(index, tws_sync);
  30. res_play = true;
  31. } else if (type == 4) {
  32. //wav提示音
  33. wav_res_play_do((u32)sbcplay_cb.buf, sbcplay_cb.len, tws_sync);
  34. res_play = true;
  35. } else if (type == 14) {
  36. //ring
  37. res_play = bt_ring_tone_play(tws_sync);
  38. } else if (type == 15) {
  39. //call number
  40. res_play = bt_ring_msbc_play(index, tws_sync);
  41. } else if (type == 16) {
  42. //ring esbc
  43. if (!bt_ring_esbc_play(index, (const u8 *)sbcplay_cb.buf, NULL, sbcplay_cb.len, tws_sync)) {
  44. res_play = true;
  45. }
  46. } else if (type == 17) {
  47. //ring sbc
  48. if (!bt_ring_sbc_play(index, tws_sync)) {
  49. res_play = true;
  50. }
  51. } else if (type == 18) {
  52. //播放rom内置esbc提示音
  53. res_play = esbc_inner_res_play(index, tws_sync);
  54. } else {
  55. res_play = false;
  56. }
  57. }
  58. return res_play;
  59. }
  60. AT(.text.music.res)
  61. void tws_res_get_addr(u32 index, u32 *res_index, u32 *res_type)
  62. {
  63. *res_index = 0;
  64. *res_type = 0;
  65. switch(index) {
  66. case TWS_RES_CONNECTED:
  67. f_bt.w4_tws_warning = 0;
  68. *res_index = T_WARNING_BT_CONNECT;
  69. *res_type = sbcplay_set(T_WARNING_BT_CONNECT, PIANO_TWS_CH);
  70. break;
  71. case TWS_RES_NOR_CONNECTED:
  72. *res_index = T_WARNING_BT_CONNECT;
  73. *res_type = sbcplay_set(T_WARNING_BT_CONNECT, PIANO_BT_CONNECT);
  74. break;
  75. case TWS_RES_DISCONNECT:
  76. *res_index = T_WARNING_BT_DISCONNECT;
  77. *res_type = sbcplay_set(T_WARNING_BT_DISCONNECT, PIANO_BT_DISCONNECT);
  78. break;
  79. case TWS_RES_PAIRING:
  80. *res_index = T_WARNING_PAIRING;
  81. *res_type = sbcplay_set(T_WARNING_PAIRING, PIANO_PAIR);
  82. if (*res_type == 0) {
  83. *res_type = 18; //播放rom内置esbc提示音
  84. }
  85. break;
  86. case TWS_RES_MAX_VOL:
  87. *res_index = T_WARNING_MAX_VOL;
  88. *res_type = sbcplay_set(T_WARNING_MAX_VOL, PIANO_MAX_VOL);
  89. break;
  90. case TWS_RES_MIN_VOL:
  91. *res_index = T_WARNING_MIN_VOL;
  92. *res_type = sbcplay_set(T_WARNING_MIN_VOL, PIANO_MIN_VOL);
  93. break;
  94. case TWS_RES_TONE:
  95. *res_index = T_WARNING_NEXT_TRACK;
  96. *res_type = 1;
  97. break;
  98. case TWS_RES_LANGUAGE:
  99. *res_index = T_WARNING_SWITCH_LANG;
  100. *res_type = sbcplay_set(T_WARNING_SWITCH_LANG, PIANO_SWITCH_LANG);
  101. if (*res_type == 0) {
  102. *res_type = 18; //播放rom内置esbc提示音
  103. }
  104. break;
  105. case TWS_RES_MUSIC_MODE:
  106. #if TRY_TOUCH_WARNING_DELAY_FIX
  107. sys_cb1.mode_warning_flag = true;
  108. sys_cb1.mode_warning_delay = 0;
  109. #endif // TRY_TOUCH_WARNING_DELAY_FIX
  110. *res_index = T_WARNING_MUSIC_MODE;
  111. *res_type = sbcplay_set(T_WARNING_MUSIC_MODE, 2);
  112. if (*res_type == 0) {
  113. *res_type = 18; //播放rom内置esbc提示音
  114. }
  115. break;
  116. case TWS_RES_GAME_MODE:
  117. #if TRY_TOUCH_WARNING_DELAY_FIX
  118. sys_cb1.mode_warning_flag = true;
  119. sys_cb1.mode_warning_delay = 0;
  120. #endif // TRY_TOUCH_WARNING_DELAY_FIX
  121. *res_index = T_WARNING_GAME_MODE;
  122. *res_type = sbcplay_set(T_WARNING_GAME_MODE, 2);
  123. if (*res_type == 0) {
  124. *res_type = 18; //播放rom内置esbc提示音
  125. }
  126. break;
  127. case TWS_RES_WAV_TEST:
  128. *res_index = T_WARNING_TEST_WAV;
  129. *res_type = sbcplay_set(T_WARNING_TEST_WAV, 4);
  130. break;
  131. #if TRY_WARNING_SWITCH
  132. case TWS_RES_SIRI:
  133. *res_index = T_WARNING_SIRI;
  134. *res_type = sbcplay_set(T_WARNING_SIRI, 2);
  135. break;
  136. #endif // TRY_WARNING_SWITCH
  137. #if TRY_SYNC_KL_4S_FACTORY_SWITCH
  138. case TWS_SYNC_FACTORY:
  139. bt_clr_all_link_info('v');
  140. led_set_sta(0xf0,0x00,5,255);
  141. delay_5ms(250);
  142. bsp_set_volume(6);
  143. bsp_bt_vol_change();
  144. sys_cb.hfp_vol = 15;
  145. param_sys_vol_write();
  146. param_sync();
  147. reset_pwroff_delay();
  148. sys_cb1.sync_kl_flag = false;
  149. sys_cb1.factory_flag = true;
  150. break;
  151. #endif // TRY_SYNC_KL_4S_FACTORY_SWITCH
  152. #if TRY_KSE_SYNC_DUT_SWITCH
  153. case TWS_SYNC_DUT:
  154. func_cb.sta = FUNC_BT_DUT;
  155. break;
  156. #endif // TRY_KSE_SYNC_DUT_SWITCH
  157. #if LED_BREATHE_EN
  158. case TWS_BRE_LED_START:
  159. breathe_led_start(T_BRE_TWS_CON, sys_led.tws_con_bre_cfg);
  160. break;
  161. case TWS_BRE_LED_START1:
  162. breathe_led_start(T_BRE_TWS_PLAY, sys_led.tws_play_bre_cfg);
  163. break;
  164. case TWS_BRE_LED_STOP:
  165. breathe_led_stop();
  166. break;
  167. #endif // LED_BREATHE_EN
  168. case TWS_ATMOS_LED_ON:
  169. atmosphere_led_sta_set(1);
  170. break;
  171. case TWS_ATMOS_LED_OFF:
  172. atmosphere_led_sta_set(0);
  173. break;
  174. case TWS_RES_RING:
  175. *res_index = T_WARNING_BT_RING;
  176. *res_type = sbcplay_set(T_WARNING_BT_RING, 2);
  177. if (*res_type == 2) {
  178. *res_type = 16;
  179. } else if (*res_type == 0) {
  180. *res_type = 14;
  181. } else if (*res_type == 3) {
  182. *res_type = 17;
  183. }
  184. break;
  185. default:
  186. if (index >= TWS_RES_NUM_0 && index <= TWS_RES_NUM_9) {
  187. *res_index = T_WARNING_NUM_0 + index - TWS_RES_NUM_0;
  188. *res_type = 15;
  189. }
  190. break;
  191. }
  192. }
  193. AT(.text.music.res)
  194. void tws_res_proc(void)
  195. {
  196. u32 res_index, res_type;
  197. u32 res = tws_res_sync(800);
  198. if (res == -1L) {
  199. return;
  200. } else if (res == -2L) {
  201. tws_res_done();
  202. return;
  203. }
  204. res &= 0xff;
  205. sys_cb.tws_res_brk = 0;
  206. tws_res_get_addr(res, &res_index, &res_type);
  207. #if BT_LOW_LATENCY_QUICK_FIX
  208. tws_set_sta_for_res(res);
  209. #endif
  210. if (res == TWS_RES_RING_STOP) {
  211. bt_tws_ring_tone_stop();
  212. } else {
  213. if (!sys_warning_play_do(res_index, res_type, 1)) {
  214. tws_res_done();
  215. }
  216. }
  217. #if !BT_LOW_LATENCY_QUICK_FIX
  218. tws_set_sta_for_res(res);
  219. #endif
  220. }
  221. void wav_res_play(u32 addr, u32 len)
  222. {
  223. #if VUSB_TBOX_QTEST_EN
  224. if(get_qtest_mode()){
  225. return;
  226. }
  227. #endif
  228. wav_res_play_do(addr, len, 0);
  229. }