1 /* 2 * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 */ 4 #ifndef __HAL_CODEC_H__ 5 #define __HAL_CODEC_H__ 6 7 #ifdef __cplusplus 8 extern "C" { 9 #endif 10 11 #include "plat_types.h" 12 #include "hal_aud.h" 13 14 #define DB_TO_QDB(n) ((n) * 4) 15 #define QDB_TO_DB(n) ((n) / 4) 16 17 enum HAL_CODEC_ID_T { 18 HAL_CODEC_ID_0 = 0, 19 HAL_CODEC_ID_NUM, 20 }; 21 22 struct HAL_CODEC_CONFIG_T { 23 enum AUD_BITS_T bits; 24 enum AUD_SAMPRATE_T sample_rate; 25 enum AUD_CHANNEL_NUM_T channel_num; 26 enum AUD_CHANNEL_MAP_T channel_map; 27 28 uint32_t use_dma:1; 29 #ifdef ALIOS_THINGS_RELEASE 30 uint32_t vol:8; 31 #else 32 uint32_t vol:5; 33 #endif 34 enum AUD_IO_PATH_T io_path; 35 36 uint32_t set_flag; 37 }; 38 39 struct dac_classg_cfg { 40 uint8_t thd2; 41 uint8_t thd1; 42 uint8_t thd0; 43 uint8_t lr; 44 uint8_t step_4_3n; 45 uint8_t quick_down; 46 uint16_t wind_width; 47 }; 48 49 enum HAL_CODEC_CONFIG_FLAG_T{ 50 HAL_CODEC_CONFIG_NULL = 0x00, 51 52 HAL_CODEC_CONFIG_BITS = 0x01, 53 HAL_CODEC_CONFIG_SAMPLE_RATE = 0x02, 54 HAL_CODEC_CONFIG_CHANNEL_NUM = 0x04, 55 HAL_CODEC_CONFIG_CHANNEL_MAP = 0x08, 56 HAL_CODEC_CONFIG_VOL = 0x10, 57 58 HAL_CODEC_CONFIG_ALL = 0xff, 59 }; 60 61 enum HAL_CODEC_DAC_RESET_STAGE_T { 62 HAL_CODEC_DAC_PRE_RESET, 63 HAL_CODEC_DAC_POST_RESET, 64 }; 65 66 enum HAL_CODEC_SYNC_TYPE_T { 67 HAL_CODEC_SYNC_TYPE_NONE, 68 HAL_CODEC_SYNC_TYPE_GPIO, 69 HAL_CODEC_SYNC_TYPE_BT, 70 HAL_CODEC_SYNC_TYPE_WIFI, 71 }; 72 73 enum HAL_CODEC_PERF_TEST_POWER_T { 74 HAL_CODEC_PERF_TEST_30MW, 75 HAL_CODEC_PERF_TEST_10MW, 76 HAL_CODEC_PERF_TEST_5MW, 77 HAL_CODEC_PERF_TEST_M60DB, 78 79 HAL_CODEC_PERF_TEST_QTY 80 }; 81 82 typedef void (*HAL_CODEC_DAC_RESET_CALLBACK)(enum HAL_CODEC_DAC_RESET_STAGE_T stage); 83 typedef void (*HAL_CODEC_SW_OUTPUT_COEF_CALLBACK)(float coef); 84 typedef void (*HAL_CODEC_BT_TRIGGER_CALLBACK)(void); 85 typedef void (*HAL_CODEC_IRQ_CALLBACK)(uint32_t status); 86 87 uint32_t hal_codec_get_input_path_cfg(enum AUD_IO_PATH_T io_path); 88 const struct CODEC_DAC_VOL_T *hal_codec_get_dac_volume(uint32_t index); 89 const CODEC_ADC_VOL_T *hal_codec_get_adc_volume(uint32_t index); 90 uint32_t hal_codec_get_mic_chan_volume_level(uint32_t map); 91 92 int hal_codec_open(enum HAL_CODEC_ID_T id); 93 int hal_codec_close(enum HAL_CODEC_ID_T id); 94 void hal_codec_crash_mute(void); 95 void hal_codec_stop_playback_stream(enum HAL_CODEC_ID_T id); 96 void hal_codec_start_playback_stream(enum HAL_CODEC_ID_T id); 97 int hal_codec_start_stream(enum HAL_CODEC_ID_T id, enum AUD_STREAM_T stream); 98 int hal_codec_stop_stream(enum HAL_CODEC_ID_T id, enum AUD_STREAM_T stream); 99 int hal_codec_start_interface(enum HAL_CODEC_ID_T id, enum AUD_STREAM_T stream, int dma); 100 int hal_codec_stop_interface(enum HAL_CODEC_ID_T id, enum AUD_STREAM_T stream); 101 int hal_codec_setup_stream(enum HAL_CODEC_ID_T id, enum AUD_STREAM_T stream, const struct HAL_CODEC_CONFIG_T *cfg); 102 int hal_codec_anc_adc_enable(enum ANC_TYPE_T type); 103 int hal_codec_anc_adc_disable(enum ANC_TYPE_T type); 104 enum AUD_SAMPRATE_T hal_codec_anc_convert_rate(enum AUD_SAMPRATE_T rate); 105 int hal_codec_anc_dma_enable(enum HAL_CODEC_ID_T id); 106 int hal_codec_anc_dma_disable(enum HAL_CODEC_ID_T id); 107 void hal_codec_set_anc_boost_gain_attn(float attn); 108 void hal_codec_apply_anc_adc_gain_offset(uint32_t index, int8_t offset); 109 int hal_codec_aux_mic_dma_enable(enum HAL_CODEC_ID_T id); 110 int hal_codec_aux_mic_dma_disable(enum HAL_CODEC_ID_T id); 111 uint32_t hal_codec_get_alg_dac_shift(void); 112 void hal_codec_set_dac_reset_callback(HAL_CODEC_DAC_RESET_CALLBACK callback); 113 void hal_codec_set_sw_output_coef_callback(HAL_CODEC_SW_OUTPUT_COEF_CALLBACK callback); 114 void hal_codec_dac_gain_m60db_check(enum HAL_CODEC_PERF_TEST_POWER_T type); 115 void hal_codec_set_noise_reduction(bool enable); 116 void hal_codec_classg_config(const struct dac_classg_cfg *cfg); 117 void hal_codec_set_dac_dc_gain_attn(float attn); 118 void hal_codec_set_dac_dc_offset(int16_t dc_l, int16_t dc_r); 119 void hal_codec_sidetone_enable(void); 120 void hal_codec_sidetone_disable(void); 121 int hal_codec_sidetone_gain_ramp_up(float step); 122 int hal_codec_sidetone_gain_ramp_down(float step); 123 void hal_codec_select_adc_iir_mic(uint32_t index, enum AUD_CHANNEL_MAP_T mic_map); 124 void hal_codec_dac_mute(bool mute); 125 void hal_codec_adc_mute(bool mute); 126 int hal_codec_set_chan_vol(enum AUD_STREAM_T stream, enum AUD_CHANNEL_MAP_T ch_map, uint8_t vol); 127 void hal_codec_sync_dac_enable(enum HAL_CODEC_SYNC_TYPE_T type); 128 void hal_codec_sync_dac_disable(void); 129 void hal_codec_sync_adc_enable(enum HAL_CODEC_SYNC_TYPE_T type); 130 void hal_codec_sync_adc_disable(void); 131 void hal_codec_sync_dac_resample_rate_enable(enum HAL_CODEC_SYNC_TYPE_T type); 132 void hal_codec_sync_dac_resample_rate_disable(void); 133 void hal_codec_sync_adc_resample_rate_enable(enum HAL_CODEC_SYNC_TYPE_T type); 134 void hal_codec_sync_adc_resample_rate_disable(void); 135 void hal_codec_sync_dac_gain_enable(enum HAL_CODEC_SYNC_TYPE_T type); 136 void hal_codec_sync_dac_gain_disable(void); 137 void hal_codec_sync_adc_gain_enable(enum HAL_CODEC_SYNC_TYPE_T type); 138 void hal_codec_sync_adc_gain_disable(void); 139 int hal_codec_dac_reset_set(void); 140 int hal_codec_dac_reset_clear(void); 141 int hal_codec_dac_sdm_reset_set(void); 142 int hal_codec_dac_sdm_reset_clear(void); 143 void hal_codec_tune_resample_rate(enum AUD_STREAM_T stream, float ratio); 144 void hal_codec_tune_both_resample_rate(float ratio); 145 void hal_codec_get_dac_gain(float *left_gain,float *right_gain); 146 int hal_codec_select_clock_out(uint32_t cfg); 147 int hal_codec_config_digmic_phase(uint8_t phase); 148 void hal_codec_setup_mc(enum AUD_CHANNEL_NUM_T channel_num, enum AUD_BITS_T bits); 149 void hal_codec_dsd_enable(void); 150 void hal_codec_dsd_disable(void); 151 void hal_codec_swap_output(bool swap); 152 153 uint32_t hal_codec_timer_get(void); 154 uint32_t hal_codec_timer_ticks_to_us(uint32_t ticks); 155 void hal_codec_timer_trigger_read(void); 156 157 void hal_codec_anc_fb_check_set_irq_handler(HAL_CODEC_IRQ_CALLBACK cb); 158 159 int hal_codec_vad_open(const struct AUD_VAD_CONFIG_T *cfg); 160 int hal_codec_vad_close(void); 161 int hal_codec_vad_start(void); 162 int hal_codec_vad_stop(void); 163 uint32_t hal_codec_vad_recv_data(uint8_t *dst, uint32_t dst_size); 164 165 void hal_codec_set_bt_trigger_callback(HAL_CODEC_BT_TRIGGER_CALLBACK callback); 166 int hal_codec_bt_trigger_start(void); 167 int hal_codec_bt_trigger_stop(void); 168 169 #ifdef __cplusplus 170 } 171 #endif 172 173 #endif 174