@@ -15,6 +15,29 @@ static i2s_chan_handle_t i2s_tx_chan = NULL;
1515static i2s_chan_handle_t i2s_rx_chan = NULL ;
1616static const audio_codec_data_if_t * i2s_data_if = NULL ; /* Codec data interface */
1717
18+ /* Can be used for i2s_std_gpio_config_t and/or i2s_std_config_t initialization */
19+ #define BSP_I2S_GPIO_CFG \
20+ { \
21+ .mclk = BSP_I2S_MCLK, \
22+ .bclk = BSP_I2S_SCLK, \
23+ .ws = BSP_I2S_LCLK, \
24+ .dout = BSP_I2S_DOUT, \
25+ .din = BSP_I2S_DSIN, \
26+ .invert_flags = { \
27+ .mclk_inv = false, \
28+ .bclk_inv = false, \
29+ .ws_inv = false, \
30+ }, \
31+ }
32+
33+ /* This configuration is used by default in bsp_audio_init() */
34+ #define BSP_I2S_DUPLEX_MONO_CFG (_sample_rate ) \
35+ { \
36+ .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(_sample_rate), \
37+ .slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO), \
38+ .gpio_cfg = BSP_I2S_GPIO_CFG, \
39+ }
40+
1841esp_err_t bsp_adc_initialize (void )
1942{
2043 /* ADC was initialized before */
@@ -50,7 +73,7 @@ esp_err_t bsp_audio_init(const i2s_std_config_t *i2s_config)
5073 ESP_ERROR_CHECK (i2s_new_channel (& chan_cfg , & i2s_tx_chan , & i2s_rx_chan ));
5174
5275 /* Setup I2S channels */
53- const i2s_std_config_t std_cfg_default = BSP_I2S_DUPLEX_MONO_CFG (22050 );
76+ const i2s_std_config_t std_cfg_default = BSP_I2S_DUPLEX_MONO_CFG (16000 );
5477 const i2s_std_config_t * p_i2s_cfg = & std_cfg_default ;
5578 if (i2s_config != NULL ) {
5679 p_i2s_cfg = i2s_config ;
@@ -75,99 +98,7 @@ esp_err_t bsp_audio_init(const i2s_std_config_t *i2s_config)
7598 return ESP_OK ;
7699}
77100
78- esp_codec_dev_handle_t bsp_audio_codec_speaker_init (void )
79- {
80- if (i2s_data_if == NULL ) {
81- /* Initilize I2C */
82- ESP_ERROR_CHECK (bsp_i2c_init ());
83- /* Configure I2S peripheral and Power Amplifier */
84- ESP_ERROR_CHECK (bsp_extra_audio_init (NULL ));
85- }
86- assert (i2s_data_if );
87-
88- const audio_codec_gpio_if_t * gpio_if = audio_codec_new_gpio ();
89-
90- audio_codec_i2c_cfg_t i2c_cfg = {
91- .port = BSP_I2C_NUM ,
92- .addr = ES8311_CODEC_DEFAULT_ADDR ,
93- };
94- const audio_codec_ctrl_if_t * i2c_ctrl_if = audio_codec_new_i2c_ctrl (& i2c_cfg );
95- assert (i2c_ctrl_if );
96-
97- esp_codec_dev_hw_gain_t gain = {
98- .pa_voltage = 5.0 ,
99- .codec_dac_voltage = 3.3 ,
100- };
101-
102- es8311_codec_cfg_t es8311_cfg = {
103- .ctrl_if = i2c_ctrl_if ,
104- .gpio_if = gpio_if ,
105- .codec_mode = ESP_CODEC_DEV_TYPE_OUT ,
106- .pa_pin = BSP_POWER_AMP_IO ,
107- .pa_reverted = false,
108- .master_mode = false,
109- .use_mclk = true,
110- .digital_mic = false,
111- .invert_mclk = false,
112- .invert_sclk = false,
113- .hw_gain = gain ,
114- };
115- const audio_codec_if_t * es8311_dev = es8311_codec_new (& es8311_cfg );
116- assert (es8311_dev );
117-
118- esp_codec_dev_cfg_t codec_dev_cfg = {
119- .dev_type = ESP_CODEC_DEV_TYPE_IN_OUT ,
120- .codec_if = es8311_dev ,
121- .data_if = i2s_data_if ,
122- };
123- return esp_codec_dev_new (& codec_dev_cfg );
124- }
125-
126- esp_codec_dev_handle_t bsp_audio_codec_microphone_init (void )
101+ const audio_codec_data_if_t * bsp_audio_get_codec_itf (void )
127102{
128- if (i2s_data_if == NULL ) {
129- /* Initilize I2C */
130- ESP_ERROR_CHECK (bsp_i2c_init ());
131- /* Configure I2S peripheral and Power Amplifier */
132- ESP_ERROR_CHECK (bsp_extra_audio_init (NULL ));
133- }
134- assert (i2s_data_if );
135-
136- const audio_codec_gpio_if_t * gpio_if = audio_codec_new_gpio ();
137-
138- audio_codec_i2c_cfg_t i2c_cfg = {
139- .port = BSP_I2C_NUM ,
140- .addr = ES8311_CODEC_DEFAULT_ADDR ,
141- };
142- const audio_codec_ctrl_if_t * i2c_ctrl_if = audio_codec_new_i2c_ctrl (& i2c_cfg );
143- assert (i2c_ctrl_if );
144-
145- esp_codec_dev_hw_gain_t gain = {
146- .pa_voltage = 5.0 ,
147- .codec_dac_voltage = 3.3 ,
148- };
149-
150- es8311_codec_cfg_t es8311_cfg = {
151- .ctrl_if = i2c_ctrl_if ,
152- .gpio_if = gpio_if ,
153- .codec_mode = ESP_CODEC_DEV_WORK_MODE_BOTH ,
154- .pa_pin = BSP_POWER_AMP_IO ,
155- .pa_reverted = false,
156- .master_mode = false,
157- .use_mclk = true,
158- .digital_mic = false,
159- .invert_mclk = false,
160- .invert_sclk = false,
161- .hw_gain = gain ,
162- };
163-
164- const audio_codec_if_t * es8311_dev = es8311_codec_new (& es8311_cfg );
165- assert (es8311_dev );
166-
167- esp_codec_dev_cfg_t codec_es8311_dev_cfg = {
168- .dev_type = ESP_CODEC_DEV_TYPE_IN ,
169- .codec_if = es8311_dev ,
170- .data_if = i2s_data_if ,
171- };
172- return esp_codec_dev_new (& codec_es8311_dev_cfg );
103+ return i2s_data_if ;
173104}
0 commit comments