Skip to content

Commit e0803ff

Browse files
committed
i2s: add Internal DAC Output config
1 parent 34fd679 commit e0803ff

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

main/Kconfig.projbuild

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,23 +179,53 @@ config SLEEP_KEY_PIN
179179
endmenu
180180

181181
menu "Audio Configuration"
182-
config ENABLE_AUDIO_PROMPT
183-
bool "Enable Audio Prompt"
184-
default y
182+
choice AUDIO_OUTPUT
183+
prompt "Audio Output"
184+
default AUDIO_OUTPUT_EXTERNAL_I2S
185185
help
186-
Select this to enable Audio Prompt.
186+
Select to use Internal DAC or External I2S CODEC.
187+
188+
config AUDIO_OUTPUT_INTERNAL_DAC
189+
bool "Internal DAC"
190+
config AUDIO_OUTPUT_EXTERNAL_I2S
191+
bool "External I2S CODEC"
192+
endchoice
193+
194+
choice INTERNAL_DAC_MODE
195+
prompt "Internal DAC Mode"
196+
default INTERNAL_DAC_MODE_BOTH
197+
depends on AUDIO_OUTPUT_INTERNAL_DAC
198+
help
199+
Select the Internal DAC Output Mode.
200+
201+
config INTERNAL_DAC_MODE_LEFT
202+
bool "Left Channel Only (GPIO26)"
203+
config INTERNAL_DAC_MODE_RIGHT
204+
bool "Right Channel Only (GPIO25)"
205+
config INTERNAL_DAC_MODE_BOTH
206+
bool "Both Channel Enabled"
207+
endchoice
187208

188209
config I2S_BCLK_PIN
189210
int "I2S BCLK Pin"
190211
default 22
212+
depends on AUDIO_OUTPUT_EXTERNAL_I2S
191213

192214
config I2S_LRCK_PIN
193215
int "I2S LRCK Pin"
194216
default 21
217+
depends on AUDIO_OUTPUT_EXTERNAL_I2S
195218

196219
config I2S_DOUT_PIN
197220
int "I2S DOUT Pin"
198221
default 19
222+
depends on AUDIO_OUTPUT_EXTERNAL_I2S
223+
224+
config ENABLE_AUDIO_PROMPT
225+
bool "Enable Audio Prompt"
226+
default y
227+
help
228+
Select this to enable Audio Prompt.
199229
endmenu
200230

201231
config FIRMWARE_VERSION

main/src/chip/i2s.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ void i2s0_init(void)
2222
{
2323
esp_chip_info(&chip_info);
2424
i2s_config_t i2s_config = {
25+
#ifdef CONFIG_AUDIO_OUTPUT_INTERNAL_DAC
26+
.mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN, // Only TX
27+
#else
2528
.mode = I2S_MODE_MASTER | I2S_MODE_TX, // Only TX
29+
#endif
2630
.communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB,
2731
.use_apll = chip_info.revision, // Don't use apll on rev0 chips
2832
.sample_rate = i2s0_sample_rate,
@@ -32,14 +36,27 @@ void i2s0_init(void)
3236
.dma_buf_len = 60,
3337
.tx_desc_auto_clear = true // Auto clear tx descriptor on underflow
3438
};
39+
ESP_ERROR_CHECK(i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL));
40+
#ifdef CONFIG_AUDIO_OUTPUT_INTERNAL_DAC
41+
42+
#ifdef CONFIG_INTERNAL_DAC_MODE_LEFT
43+
ESP_ERROR_CHECK(i2s_set_dac_mode(I2S_DAC_CHANNEL_LEFT_EN));
44+
#elif defined(CONFIG_INTERNAL_DAC_MODE_RIGHT)
45+
ESP_ERROR_CHECK(i2s_set_dac_mode(I2S_DAC_CHANNEL_RIGHT_EN));
46+
#else
47+
ESP_ERROR_CHECK(i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN));
48+
#endif
49+
ESP_ERROR_CHECK(i2s_set_pin(0, NULL));
50+
51+
#else
3552
i2s_pin_config_t pin_config = {
3653
.bck_io_num = CONFIG_I2S_BCLK_PIN,
3754
.ws_io_num = CONFIG_I2S_LRCK_PIN,
3855
.data_out_num = CONFIG_I2S_DOUT_PIN,
3956
.data_in_num = -1 // Not used
4057
};
41-
ESP_ERROR_CHECK(i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL));
4258
ESP_ERROR_CHECK(i2s_set_pin(I2S_NUM_0, &pin_config));
59+
#endif // CONFIG_AUDIO_OUTPUT_INTERNAL_DAC
4360
ESP_LOGI(TAG, "i2s-0 initialized.");
4461
}
4562

0 commit comments

Comments
 (0)