bsp_dac.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "include.h"
  2. #include "bsp_dac.h"
  3. extern const u8 *dac_dvol_table;
  4. extern const u16 dig_vol_tbl[61];
  5. extern const u8 dac_dvol_tbl_16[16 + 1];
  6. extern const u8 dac_dvol_tbl_32[32 + 1];
  7. void dac_channel_configure(void);
  8. bool music_soft_gain_check(void);
  9. AT(.text.bsp.dac)
  10. void bsp_change_volume_hook(u8 vol)
  11. {
  12. u8 level = 0;
  13. sys_cb.vol_set = vol;
  14. #if VUSB_SMART_VBAT_HOUSE_EN
  15. if (vhouse_cb.ear_mute_flag) {
  16. return;
  17. }
  18. #endif
  19. #if BT_ALG_DBB_EN
  20. if (music_soft_gain_check()) {
  21. return;
  22. }
  23. #endif
  24. if (vol <= VOL_MAX) {
  25. level = dac_dvol_table[vol] + sys_cb.gain_offset;
  26. if (level > 60) {
  27. level = 60;
  28. }
  29. dac_set_dvol(dig_vol_tbl[level]);
  30. }
  31. }
  32. AT(.text.dac)
  33. void dac_set_anl_offset(u8 bt_call_flag)
  34. {
  35. if (bt_call_flag) {
  36. sys_cb.gain_offset = BT_CALL_MAX_GAIN;
  37. } else {
  38. sys_cb.gain_offset = DAC_MAX_GAIN;
  39. }
  40. }
  41. AT(.text.bsp.dac)
  42. void dac_init(void)
  43. {
  44. u32 cic_gain = xcfg_cb.dac_cic_gain + 1;
  45. if (sys_cb.vol_max == 16) {
  46. dac_dvol_table = dac_dvol_tbl_16;
  47. } else {
  48. dac_dvol_table = dac_dvol_tbl_32;
  49. }
  50. dac_set_anl_offset(0);
  51. DACDIGCON1 = (DACDIGCON1 & ~(0x3f << 26)) | (cic_gain << 26);
  52. // printf("[%s] vol_max:%d, offset: %d\n", __func__, sys_cb.vol_max, sys_cb.gain_offset);
  53. #if LINEIN_2_PWRDOWN_EN
  54. if (sys_cb.sleep_dac_en) {
  55. dac_power_off_restore_daclr();
  56. }
  57. #endif
  58. dac_obuf_init();
  59. dac_power_on();
  60. if (DAC_OUT_SPR == DAC_OUT_48K) {
  61. DACDIGCON0 |= BIT(1); //dac out sample 48K
  62. }
  63. if (xcfg_cb.dac_channel_exchange_en) {
  64. dac_channel_exchange();
  65. }
  66. #if WARING_WAV_VOL_OWN_EN
  67. dac_msc_vol_en();
  68. #endif
  69. plugin_music_eq();
  70. #if DAC_DNR_EN
  71. dac_dnr_init(2, 0x18, 90, 0x10);
  72. #endif
  73. }
  74. ////处理audio bypass时淡出收得不好的问题
  75. //void dac_fade_out_wait(void)
  76. //{
  77. // dac_unmute_set_delay(30);
  78. // dac_wait_vol_match();
  79. //}