Skip to content

Commit e44d65f

Browse files
committed
I2SCodecStream: support for CODEC_ADC
1 parent 99ef796 commit e44d65f

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/AudioTools/AudioLibs/I2SCodecStream.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class I2SCodecStream : public AudioStream, public VolumeSupport {
6464
cfg.input_device = ADC_INPUT_LINE1;
6565
cfg.output_device = DAC_OUTPUT_ALL;
6666
cfg.sd_active = true;
67+
cfg.rx_tx_mode = mode;
6768
return cfg;
6869
}
6970

@@ -205,6 +206,7 @@ class I2SCodecStream : public AudioStream, public VolumeSupport {
205206
bool is_active = false;
206207

207208
bool begin1() {
209+
TRACED();
208210
setupI2SPins();
209211
if (!beginCodec(cfg)) {
210212
TRACEE();
@@ -224,8 +226,9 @@ class I2SCodecStream : public AudioStream, public VolumeSupport {
224226

225227
/// We use the board pins if they are available
226228
void setupI2SPins() {
227-
// setup pins in i2s config
228-
auto i2s = p_board->getPins().getI2SPins();
229+
TRACED();
230+
// determine relevant I2S pins from driver configuration
231+
auto i2s = getI2SPins();
229232
if (i2s) {
230233
// determine i2s pins from board definition
231234
PinsI2S i2s_pins = i2s.value();
@@ -247,7 +250,30 @@ class I2SCodecStream : public AudioStream, public VolumeSupport {
247250
}
248251
}
249252

253+
audio_driver_local::Optional<PinsI2S> getI2SPins(){
254+
TRACED();
255+
audio_driver_local::Optional<PinsI2S> i2s;
256+
// special logic if we have a board which has a dedicated microphone I2S port
257+
if (cfg.rx_tx_mode == RX_MODE){
258+
i2s = p_board->getPins().getI2SPins(PinFunction::CODEC_ADC);
259+
#ifdef ESP32
260+
if (i2s){
261+
cfg.port_no = i2s.value().port;
262+
LOGI("Using port %d for input", cfg.port_no);
263+
}
264+
#endif
265+
}
266+
267+
// Deterine regular I2S pins
268+
if (!i2s){
269+
// setup pins in i2s config
270+
i2s = p_board->getPins().getI2SPins();
271+
}
272+
return i2s;
273+
}
274+
250275
bool beginCodec(I2SCodecConfig info) {
276+
TRACED();
251277
switch (cfg.rx_tx_mode) {
252278
case RX_MODE:
253279
codec_cfg.input_device = info.input_device;

0 commit comments

Comments
 (0)