bsp_eq.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. #include "include.h"
  2. #define TRACE_EN 0
  3. #if TRACE_EN
  4. #define TRACE(...) printf(__VA_ARGS__)
  5. #else
  6. #define TRACE(...)
  7. #endif
  8. #define EQ_CRC_SEED 0xffff
  9. bool bsp_eq_check_res_crc(u8 *eq_buf);
  10. void eq_tx_ack(u8 bank_num, u8 ack);
  11. void eq_dbg_huart_init(void);
  12. void tx_ack(uint8_t *packet, uint16_t len);
  13. u8 check_sum(u8 *buf, u16 size);
  14. void bt_call_test_set_mic(u8 flag);
  15. extern const char tbl_anc_header[3];
  16. extern const char tbl_eq_version[10];
  17. extern const int tbl_eq_gain[16];
  18. AT(.rodata.eq.table)
  19. const eq_param music_eq_tbl[MUSIC_EQ_TBL_LEN] = {
  20. {&RES_BUF_EQ_NORMAL_EQ, &RES_LEN_EQ_NORMAL_EQ}, //normal
  21. {&RES_BUF_EQ_POP_EQ, &RES_LEN_EQ_POP_EQ}, //pop
  22. {&RES_BUF_EQ_JAZZ_EQ, &RES_LEN_EQ_JAZZ_EQ}, //jazz
  23. {&RES_BUF_EQ_ROCK_EQ, &RES_LEN_EQ_ROCK_EQ}, //rock
  24. {&RES_BUF_EQ_CLASSIC_EQ, &RES_LEN_EQ_CLASSIC_EQ},//classic
  25. {&RES_BUF_EQ_COUNTRY_EQ, &RES_LEN_EQ_COUNTRY_EQ},//country
  26. };
  27. u8 eq_get_check_res_sel(void)
  28. {
  29. return EQ_CHECK_RES_SEL;
  30. }
  31. const u8* eq_get_check_res_buf(void)
  32. {
  33. return (const u8 *)RES_BUF_EQ_CHECK_RES_EQ;
  34. }
  35. AT(.text.eq)
  36. void music_set_eq_by_num(u8 num)
  37. {
  38. if (num > (MUSIC_EQ_TBL_LEN - 1)) {
  39. return;
  40. }
  41. music_set_eq_by_res(*music_eq_tbl[num].addr, *music_eq_tbl[num].len);
  42. }
  43. AT(.text.eq)
  44. void sys_set_eq(void)
  45. {
  46. sys_cb.eq_mode++;
  47. if (sys_cb.eq_mode > 5) {
  48. sys_cb.eq_mode = 0;
  49. }
  50. music_set_eq_by_num(sys_cb.eq_mode);
  51. }
  52. AT(.text.eq)
  53. void bt_sco_eq_drc_init(u32 msbc_flag)
  54. {
  55. u32 mic_eq_addr, mic_eq_len, mic_drc_addr, mic_drc_len;
  56. if (msbc_flag) {
  57. mic_eq_addr = RES_BUF_EQ_BT_MIC_16K_EQ;
  58. mic_eq_len = RES_LEN_EQ_BT_MIC_16K_EQ;
  59. mic_drc_addr = RES_BUF_EQ_BT_MIC_16K_DRC;
  60. mic_drc_len = RES_LEN_EQ_BT_MIC_16K_DRC;
  61. } else {
  62. mic_eq_addr = RES_BUF_EQ_BT_MIC_8K_EQ;
  63. mic_eq_len = RES_LEN_EQ_BT_MIC_8K_EQ;
  64. mic_drc_addr = RES_BUF_EQ_BT_MIC_8K_DRC;
  65. mic_drc_len = RES_LEN_EQ_BT_MIC_8K_DRC;
  66. }
  67. if (mic_set_eq_by_res(mic_eq_addr, mic_eq_len)) {
  68. xcfg_cb.mic_eq_en = 1;
  69. } else {
  70. xcfg_cb.mic_eq_en = 0;
  71. }
  72. mic_set_drc_by_res(mic_drc_addr, mic_drc_len);
  73. #ifdef RES_BUF_EQ_CALL_NORMAL_EQ
  74. music_set_eq_by_res(RES_BUF_EQ_CALL_NORMAL_EQ, RES_LEN_EQ_CALL_NORMAL_EQ);
  75. #else
  76. music_eq_off();
  77. #endif
  78. #ifdef RES_BUF_EQ_CALL_DAC_DRC
  79. if (!music_set_drc_by_res(RES_BUF_EQ_CALL_DAC_DRC, RES_LEN_EQ_CALL_DAC_DRC)) {
  80. music_drc_off();
  81. }
  82. #else
  83. music_drc_off();
  84. #endif
  85. }
  86. void bt_sco_eq_drc_exit(void)
  87. {
  88. mic_drc_off();
  89. mic_eq_off();
  90. music_set_eq_by_num(sys_cb.eq_mode);
  91. music_set_drc_by_res(RES_BUF_EQ_DAC_DRC, RES_LEN_EQ_DAC_DRC);
  92. }
  93. void eq_tx_version(void)
  94. {
  95. // eq_tx_buf[0] = 'E';
  96. // eq_tx_buf[1] = 'Q';
  97. // eq_tx_buf[2] = '1'; //version
  98. // eq_tx_buf[3] = '*';
  99. // eq_tx_buf[4] = 6; //size
  100. // eq_tx_buf[5] = 0;
  101. // eq_tx_buf[6] = 10; //band_cnt
  102. // eq_tx_buf[7] = 4; //param size
  103. // eq_tx_buf[8] = 5; //param cnt
  104. // eq_tx_buf[9] = 0; //rsvd
  105. memcpy(eq_tx_buf, tbl_eq_version, 10);
  106. #if ANC_EN
  107. eq_tx_buf[9] |= BIT(0);
  108. #endif
  109. u16 crc = calc_crc(eq_tx_buf, 10, EQ_CRC_SEED);
  110. eq_tx_buf[10] = crc;
  111. eq_tx_buf[11] = crc >> 8;
  112. tx_ack(eq_tx_buf, 12);
  113. }
  114. #if ANC_EN
  115. #define FF_EQ_NAME_NUM 4
  116. static const char anc_fffb_eq_name[FF_EQ_NAME_NUM][13] = {
  117. "L0_NOS.EQ",
  118. "R0_NOS.EQ",
  119. "TP_L0_NOS.EQ",
  120. "TP_R0_NOS.EQ",
  121. };
  122. bool bsp_eq_tws_sync_param(void)
  123. {
  124. u8 right_channel = 0;
  125. u8 anc_packet = eq_dbg_cb.anc_packet;
  126. if (anc_packet > 2) {
  127. anc_packet -= 2;
  128. }
  129. if (anc_packet > 1) {
  130. right_channel = 1;
  131. }
  132. if (xcfg_cb.bt_tws_en && (right_channel == func_bt_tws_get_channel())) { //声道不相等,转发
  133. if(bt_tws_is_connected()) {
  134. bt_tws_sync(TWS_SYNC_INFO_EQ);
  135. }
  136. return true;
  137. }
  138. return false;
  139. }
  140. #endif
  141. #if BT_ALG_DBB_EN
  142. /* 该文件代码由Dynamic Bass Boost Tool (for 565X)生成。 */
  143. AT(.text.rodata)
  144. const u8 dbb_coef_param[863] = {
  145. /* 滤波器类型:low shelf */
  146. /* 中心频率:200 */
  147. /* Q值:0.75 */
  148. /* 增益:0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, */
  149. 0x02, 0x15, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
  150. 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x00, 0x00, 0x00, 0x08, 0xda, 0xbe, 0xb9, 0x07, 0xb1,
  151. 0x5d, 0xb8, 0x0f, 0x50, 0xa2, 0x47, 0xf0, 0x27, 0x41, 0x46, 0xf8, 0x28, 0x10, 0x02, 0x08, 0xa5,
  152. 0xb8, 0xb9, 0x07, 0xe3, 0x66, 0xba, 0x0f, 0x78, 0xad, 0x45, 0xf0, 0x8d, 0x4b, 0x44, 0xf8, 0x4a,
  153. 0x21, 0x04, 0x08, 0xce, 0xa3, 0xb9, 0x07, 0x3f, 0x61, 0xbc, 0x0f, 0x8c, 0xc7, 0x43, 0xf0, 0xb3,
  154. 0x63, 0x42, 0xf8, 0xd6, 0x33, 0x06, 0x08, 0x52, 0x80, 0xb9, 0x07, 0x32, 0x4d, 0xbe, 0x0f, 0x30,
  155. 0xf0, 0x41, 0xf0, 0x3b, 0x89, 0x40, 0xf8, 0x3e, 0x48, 0x08, 0x08, 0x29, 0x4e, 0xb9, 0x07, 0x26,
  156. 0x2b, 0xc0, 0x0f, 0x0c, 0x27, 0x40, 0xf0, 0xcc, 0xbb, 0x3e, 0xf8, 0xf5, 0x5e, 0x0a, 0x08, 0x4c,
  157. 0x0d, 0xb9, 0x07, 0x81, 0xfb, 0xc1, 0x0f, 0xcd, 0x6b, 0x3e, 0xf0, 0x0c, 0xfb, 0x3c, 0xf8, 0x70,
  158. 0x78, 0x0c, 0x08, 0xae, 0xbd, 0xb8, 0x07, 0xa5, 0xbe, 0xc3, 0x0f, 0x1f, 0xbe, 0x3c, 0xf0, 0xa6,
  159. 0x46, 0x3b, 0xf8, 0x22, 0x95, 0x0e, 0x08, 0x43, 0x5f, 0xb8, 0x07, 0xf3, 0x74, 0xc5, 0x0f, 0xb5,
  160. 0x1d, 0x3b, 0xf0, 0x45, 0x9e, 0x39, 0xf8, 0x81, 0xb5, 0x10, 0x08, 0xf8, 0xf1, 0xb7, 0x07, 0xca,
  161. 0x1e, 0xc7, 0x0f, 0x44, 0x8a, 0x39, 0xf0, 0x96, 0x01, 0x38, 0xf8, 0x04, 0xda, 0x12, 0x08, 0xba,
  162. 0x75, 0xb7, 0x07, 0x83, 0xbc, 0xc8, 0x0f, 0x84, 0x03, 0x38, 0xf0, 0x4a, 0x70, 0x36, 0xf8, 0x23,
  163. 0x03, 0x15, 0x08, 0x72, 0xea, 0xb6, 0x07, 0x77, 0x4e, 0xca, 0x0f, 0x30, 0x89, 0x36, 0xf0, 0x12,
  164. 0xea, 0x34, 0xf8, 0x58, 0x31, 0x17, 0x08, 0x07, 0x50, 0xb6, 0x07, 0xfd, 0xd4, 0xcb, 0x0f, 0x05,
  165. 0x1b, 0x35, 0xf0, 0xa3, 0x6e, 0x33, 0xf8, 0x1e, 0x65, 0x19, 0x08, 0x5d, 0xa6, 0xb5, 0x07, 0x67,
  166. 0x50, 0xcd, 0x0f, 0xc6, 0xb8, 0x33, 0xf0, 0xb2, 0xfd, 0x31, 0xf8, 0xf1, 0x9e, 0x1b, 0x08, 0x54,
  167. 0xed, 0xb4, 0x07, 0x07, 0xc1, 0xce, 0x0f, 0x36, 0x62, 0x32, 0xf0, 0xf7, 0x96, 0x30, 0xf8, 0x50,
  168. 0xdf, 0x1d, 0x08, 0xcc, 0x24, 0xb4, 0x07, 0x2a, 0x27, 0xd0, 0x0f, 0x1d, 0x17, 0x31, 0xf0, 0x2c,
  169. 0x3a, 0x2f, 0xf8, 0xba, 0x26, 0x20, 0x08, 0xa0, 0x4c, 0xb3, 0x07, 0x1f, 0x83, 0xd1, 0x0f, 0x46,
  170. 0xd7, 0x2f, 0xf0, 0x0b, 0xe7, 0x2d, 0xf8, 0xb3, 0x75, 0x22, 0x08, 0xa7, 0x64, 0xb2, 0x07, 0x2e,
  171. 0xd5, 0xd2, 0x0f, 0x7d, 0xa2, 0x2e, 0xf0, 0x52, 0x9d, 0x2c, 0xf8, 0xbd, 0xcc, 0x24, 0x08, 0xb8,
  172. 0x6c, 0xb1, 0x07, 0xa1, 0x1d, 0xd4, 0x0f, 0x94, 0x78, 0x2d, 0xf0, 0xbf, 0x5c, 0x2b, 0xf8, 0x61,
  173. 0x2c, 0x27, 0x08, 0xa7, 0x64, 0xb0, 0x07, 0xbd, 0x5c, 0xd5, 0x0f, 0x5e, 0x59, 0x2c, 0xf0, 0x13,
  174. 0x25, 0x2a, 0xf8, 0x27, 0x95, 0x29, 0x08, 0x42, 0x4c, 0xaf, 0x07, 0xc6, 0x92, 0xd6, 0x0f, 0xb3,
  175. 0x44, 0x2b, 0xf0, 0x10, 0xf6, 0x28, 0xf8, 0x9a, 0x07, 0x2c, 0x08, 0x57, 0x23, 0xae, 0x07, 0xfe,
  176. 0xbf, 0xd7, 0x0f, 0x6c, 0x3a, 0x2a, 0xf0, 0x7a, 0xcf, 0x27, 0xf8, 0x00, 0x00, 0x00, 0x08, 0x61,
  177. 0xa6, 0xb3, 0x07, 0xa3, 0x04, 0xb2, 0x0f, 0x5e, 0xfb, 0x4d, 0xf0, 0xa0, 0x59, 0x4c, 0xf8, 0xfd,
  178. 0x3e, 0x02, 0x08, 0xc1, 0x9f, 0xb3, 0x07, 0x14, 0x3c, 0xb4, 0x0f, 0x00, 0xdc, 0x4b, 0xf0, 0x56,
  179. 0x39, 0x4a, 0xf8, 0x15, 0x7f, 0x04, 0x08, 0x41, 0x89, 0xb3, 0x07, 0x5f, 0x63, 0xb6, 0x0f, 0xe3,
  180. 0xcc, 0x49, 0xf0, 0xec, 0x27, 0x48, 0xf8, 0xc6, 0xc0, 0x06, 0x08, 0xdc, 0x62, 0xb3, 0x07, 0xf9,
  181. 0x7a, 0xb8, 0x0f, 0xa5, 0xcd, 0x47, 0xf0, 0xfd, 0x24, 0x46, 0xf8, 0x8b, 0x04, 0x09, 0x08, 0x8c,
  182. 0x2c, 0xb3, 0x07, 0x55, 0x83, 0xba, 0x0f, 0xea, 0xdd, 0x45, 0xf0, 0x28, 0x30, 0x44, 0xf8, 0xe1,
  183. 0x4a, 0x0b, 0x08, 0x49, 0xe6, 0xb2, 0x07, 0xe2, 0x7c, 0xbc, 0x0f, 0x56, 0xfd, 0x43, 0xf0, 0x0e,
  184. 0x49, 0x42, 0xf8, 0x47, 0x94, 0x0d, 0x08, 0x06, 0x90, 0xb2, 0x07, 0x0c, 0x68, 0xbe, 0x0f, 0x92,
  185. 0x2b, 0x42, 0xf0, 0x52, 0x6f, 0x40, 0xf8, 0x3b, 0xe1, 0x0f, 0x08, 0xb3, 0x29, 0xb2, 0x07, 0x3d,
  186. 0x45, 0xc0, 0x0f, 0x4b, 0x68, 0x40, 0xf0, 0x99, 0xa2, 0x3e, 0xf8, 0x3f, 0x32, 0x12, 0x08, 0x3f,
  187. 0xb3, 0xb1, 0x07, 0xd9, 0x14, 0xc2, 0x0f, 0x30, 0xb3, 0x3e, 0xf0, 0x8b, 0xe2, 0x3c, 0xf8, 0xd4,
  188. 0x87, 0x14, 0x08, 0x95, 0x2c, 0xb1, 0x07, 0x45, 0xd7, 0xc3, 0x0f, 0xf5, 0x0b, 0x3d, 0xf0, 0xd1,
  189. 0x2e, 0x3b, 0xf8, 0x7d, 0xe2, 0x16, 0x08, 0x9c, 0x95, 0xb0, 0x07, 0xe0, 0x8c, 0xc5, 0x0f, 0x51,
  190. 0x72, 0x3b, 0xf0, 0x18, 0x87, 0x39, 0xf8, 0xbf, 0x42, 0x19, 0x08, 0x3a, 0xee, 0xaf, 0x07, 0x08,
  191. 0x36, 0xc7, 0x0f, 0xfe, 0xe5, 0x39, 0xf0, 0x0d, 0xeb, 0x37, 0xf8, 0x21, 0xa9, 0x1b, 0x08, 0x4f,
  192. 0x36, 0xaf, 0x07, 0x18, 0xd3, 0xc8, 0x0f, 0xb9, 0x66, 0x38, 0xf0, 0x60, 0x5a, 0x36, 0xf8, 0x2b,
  193. 0x16, 0x1e, 0x08, 0xbd, 0x6d, 0xae, 0x07, 0x68, 0x64, 0xca, 0x0f, 0x43, 0xf4, 0x36, 0xf0, 0xc3,
  194. 0xd4, 0x34, 0xf8, 0x66, 0x8a, 0x20, 0x08, 0x5d, 0x94, 0xad, 0x07, 0x4e, 0xea, 0xcb, 0x0f, 0x61,
  195. 0x8e, 0x35, 0xf0, 0xeb, 0x59, 0x33, 0xf8, 0x60, 0x06, 0x23, 0x08, 0x09, 0xaa, 0xac, 0x07, 0x1d,
  196. 0x65, 0xcd, 0x0f, 0xda, 0x34, 0x34, 0xf0, 0x8d, 0xe9, 0x31, 0xf8, 0xa7, 0x8a, 0x25, 0x08, 0x98,
  197. 0xae, 0xab, 0x07, 0x25, 0xd5, 0xce, 0x0f, 0x7b, 0xe7, 0x32, 0xf0, 0x61, 0x83, 0x30, 0xf8, 0xcc,
  198. 0x17, 0x28, 0x08, 0xdc, 0xa1, 0xaa, 0x07, 0xb7, 0x3a, 0xd0, 0x0f, 0x11, 0xa6, 0x31, 0xf0, 0x20,
  199. 0x27, 0x2f, 0xf8, 0x62, 0xae, 0x2a, 0x08, 0xa5, 0x83, 0xa9, 0x07, 0x1d, 0x96, 0xd1, 0x0f, 0x70,
  200. 0x70, 0x30, 0xf0, 0x86, 0xd4, 0x2d, 0xf8, 0xff, 0x4e, 0x2d, 0x08, 0xc0, 0x53, 0xa8, 0x07, 0xa2,
  201. 0xe7, 0xd2, 0x0f, 0x6d, 0x46, 0x2f, 0xf0, 0x51, 0x8b, 0x2c, 0xf8, 0x3c, 0xfa, 0x2f, 0x08, 0xf6,
  202. 0x11, 0xa7, 0x07, 0x8e, 0x2f, 0xd4, 0x0f, 0xe2, 0x27, 0x2e, 0xf0, 0x3e, 0x4b, 0x2b, 0xf8,
  203. };
  204. #define BT_ALG_DBB_TABLE_LEVEL_MAX 20 //eq参数table最大20dB增益(不支持修改)
  205. #if BT_ALG_DBB_KEY_EN
  206. u8 bt_alg_dbb_on = 1;
  207. #endif
  208. #if EQ_CHECK_RES_SEL == 2 || EQ_CHECK_RES_SEL == 3
  209. AT(.com_text.dbb)
  210. WEAK const u8 *music_dbb_eq_coef_enc_param_get(u8 *table_max_level, u8 *max_level, u8* dac_spr,u32 *len)
  211. {
  212. *table_max_level = BT_ALG_DBB_TABLE_LEVEL_MAX;
  213. * max_level = BT_ALG_DBB_LEVEL_MAX;
  214. * dac_spr = DAC_OUT_SPR;
  215. * len = sizeof(dbb_coef_param);
  216. return (u8*) &dbb_coef_param;
  217. }
  218. #else
  219. AT(.text.dbb)
  220. const s32 *music_dbb_eq_coef_param_get(u8 level)
  221. {
  222. u16 offset = 1 + 1 + BT_ALG_DBB_TABLE_LEVEL_MAX + 1;
  223. u16 total_len = (BT_ALG_DBB_TABLE_LEVEL_MAX + 1) * 20;
  224. if(level > BT_ALG_DBB_LEVEL_MAX) {
  225. level = BT_ALG_DBB_LEVEL_MAX;
  226. }
  227. if(DAC_OUT_SPR == DAC_OUT_48K) {
  228. return (s32*) &dbb_coef_param[offset + level * 20];
  229. }else if (DAC_OUT_SPR == DAC_OUT_44K1) {
  230. return (s32*) &dbb_coef_param[offset + total_len + level * 20];
  231. }
  232. return NULL;
  233. }
  234. #endif
  235. AT(.com_text.music)
  236. u8 bt_alg_dbb_is_enable(void)
  237. {
  238. return BT_ALG_DBB_EN;
  239. }
  240. #endif
  241. void eq_parse_cmd(void)
  242. {
  243. eq_dbg_cb.eq_spp_cb.rx_size = EQ_BUFFER_LEN;
  244. if (eq_rx_buf[0] != 'E' || eq_rx_buf[1] != 'Q') {
  245. return;
  246. }
  247. if (eq_rx_buf[2] == '?' && eq_rx_buf[3] == '#') {
  248. eq_tx_version();
  249. return;
  250. } else if (eq_rx_buf[2] == '0' && eq_rx_buf[3] == ':') {
  251. eq_tx_ack(0, 0);
  252. eq_dbg_cb.anc_packet = 0;
  253. #if ANC_EN
  254. for (int i = 0; i < FF_EQ_NAME_NUM; i++) {
  255. if (strcmp(anc_fffb_eq_name[i], (char *)&eq_rx_buf[6]) == 0) {
  256. eq_dbg_cb.anc_packet = i + 1;
  257. if (!sys_cb.anc_start || sys_cb.anc_user_mode != 1) {
  258. bsp_anc_set_mode(1);
  259. }
  260. bsp_eq_tws_sync_param();
  261. break;
  262. }
  263. }
  264. #endif
  265. return;
  266. }
  267. #if ANC_EN
  268. if (eq_dbg_cb.anc_packet && bsp_eq_tws_sync_param()) {
  269. delay_5ms(20); //wait tws send complete
  270. eq_tx_ack(eq_rx_buf[6], 0);
  271. return;
  272. }
  273. #endif
  274. // print_r(eq_rx_buf, EQ_BUFFER_LEN);
  275. if (!bsp_eq_check_res_crc(eq_rx_buf)) {
  276. return;
  277. }
  278. u8 band_cnt = eq_rx_buf[7];
  279. #if ANC_EN
  280. if (eq_dbg_cb.anc_packet) {
  281. bsp_anc_dbg_eq_param(eq_dbg_cb.anc_packet, band_cnt, (u32 *)&eq_rx_buf[14]);
  282. } else
  283. #endif
  284. {
  285. music_set_eq(band_cnt, (u32 *)&eq_rx_buf[14]);
  286. }
  287. // printf("%08x\n", little_endian_read_32(eq_rx_buf, 14));
  288. // u8 k;
  289. // u32 *ptr = (u32 *)&eq_rx_buf[18];
  290. // for (k = 0; k < band_cnt*5; k++) {
  291. // printf("%08x", *ptr++);
  292. // if (k % 5 == 4) {
  293. // printf("\n");
  294. // } else {
  295. // printf(" ");
  296. // }
  297. // }
  298. memset(eq_rx_buf, 0, EQ_BUFFER_LEN);
  299. }
  300. #if ANC_EN
  301. void bsp_anc_dbg_ack_inquiry(void)
  302. {
  303. memset(eq_tx_buf, 0, 4);
  304. eq_tx_buf[0] = 'A';
  305. eq_tx_buf[1] = 'N';
  306. eq_tx_buf[2] = 'C';
  307. eq_tx_buf[3] = '*';
  308. tx_ack(eq_tx_buf, 4);
  309. }
  310. void bsp_anc_dbg_ack(u8 error_code)
  311. {
  312. memset(eq_tx_buf, 0, 4);
  313. eq_tx_buf[0] = 'Y';
  314. eq_tx_buf[2] = error_code;
  315. eq_tx_buf[3] = check_sum(eq_tx_buf, 3);
  316. tx_ack(eq_tx_buf, 4);
  317. }
  318. void bsp_anc_parse_cmd(void)
  319. {
  320. u8 *ptr = eq_rx_buf;
  321. if (memcmp((char *)ptr, tbl_anc_header, 3) != 0) {
  322. return;
  323. }
  324. if (ptr[3] == '?') {
  325. bsp_anc_dbg_ack_inquiry();
  326. return;
  327. }
  328. u16 size = ptr[4] + 3;
  329. u16 crc = calc_crc(ptr, size, 0xffff);
  330. if (crc != little_endian_read_16(ptr, size)) {
  331. bsp_anc_dbg_ack(1); //error code 1:crc error
  332. return;
  333. }
  334. u8 channel = ptr[5];
  335. if (channel > 3 || channel == 0) {
  336. bsp_anc_dbg_ack(2); //error code 2:param error
  337. return;
  338. }
  339. if (!xcfg_cb.anc_en) {
  340. bsp_anc_dbg_ack(3); //error code 3:anc close
  341. return;
  342. }
  343. bsp_anc_parse_cmd_process(ptr);
  344. bsp_anc_dbg_ack(0); //error code 0:succeed
  345. }
  346. #endif
  347. #if SMIC_DBG_EN
  348. static void bsp_enc_dbg_ack(u8 channel, u8 errcode )
  349. {
  350. u8 ack[4];
  351. memset(ack, 0, 4);
  352. if(errcode>0){
  353. ack[0] = 'N';
  354. }else{
  355. ack[0] = 'Y';
  356. }
  357. ack[1] = channel;
  358. ack[2] = errcode;
  359. ack[3] = 0xff;
  360. tx_ack(ack, 4);
  361. }
  362. const char tbl_smic_header[4] = "SMIC";
  363. void bsp_smic_parse_cmd(void)
  364. {
  365. u8 *ptr = eq_rx_buf;
  366. // printf("channel = %c;%c;%c\n",ptr[0],ptr[1],ptr[2]);
  367. if (memcmp((char *)ptr, tbl_smic_header, 4) != 0) {
  368. bsp_enc_dbg_ack(0, 1); //error code 1:head error
  369. return;
  370. }
  371. u8 channel = ptr[6];
  372. u8 ctlcmd = ptr[7];
  373. // printf("channel = %c; ctlcmd = %c\n",channel,ctlcmd);
  374. if(ctlcmd == 'N'){ //smic close
  375. bt_call_test_set_mic(1);
  376. bsp_enc_dbg_ack(channel, 0); //sucess
  377. }else if(ctlcmd == 'Y'){ //smic open
  378. bt_call_test_set_mic(0);
  379. bsp_enc_dbg_ack(channel, 0); //sucess
  380. }else{
  381. bsp_enc_dbg_ack(channel, 3); //error code 3:ctlcmd error
  382. return;
  383. }
  384. }
  385. #endif
  386. void eq_dbg_init(void)
  387. {
  388. #if VUSB_TBOX_QTEST_EN
  389. if(get_qtest_mode()){
  390. return;
  391. }
  392. #endif
  393. memset(eq_rx_buf, 0, EQ_BUFFER_LEN);
  394. memset(&eq_dbg_cb, 0, sizeof(eq_dbg_cb_t));
  395. #if EQ_DBG_IN_UART
  396. eq_dbg_huart_init();
  397. #endif
  398. }