Skip to content

Commit 1464fc0

Browse files
committed
I2SCodecStream: setupI2SFunction()
1 parent 773fa3b commit 1464fc0

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

examples/examples-custom-boards/lyrat-mini/mic/mic.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ void setup(void) {
3434

3535
auto cfg = i2s.defaultConfig(RX_MODE);
3636
cfg.copyFrom(info);
37-
cfg.i2s_function = PinFunction::CODEC_ADC; // or CODEC_ADC
37+
// cfg.i2s_function = PinFunction::CODEC_ADC; // determined automatically
38+
// cfg.i2s_port_no = 0; // or 1 if 0 is already in use
3839
i2s.begin(cfg);
3940

4041
// make sure that we have the correct number of channels set up

examples/examples-custom-boards/lyrat-mini/output/output.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ void setup(void) {
2929
Serial.println("starting I2S...");
3030
auto config = out.defaultConfig(TX_MODE);
3131
config.copyFrom(info);
32+
// cfg.i2s_function = PinFunction::CODEC; // determined automatically
33+
// cfg.i2s_port_no = 0; // or 1 if 0 is already in use
3234
out.begin(config);
3335

3436
// additinal settings

src/AudioTools/AudioLibs/I2SCodecStream.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct I2SCodecConfig : public I2SConfig {
2727
// to be compatible with the AudioKitStream -> do not activate SD spi if false
2828
bool sd_active = true;
2929
// define pin source in driver configuration
30-
PinFunction i2s_function = PinFunction::CODEC;
30+
PinFunction i2s_function = PinFunction::UNDEFINED; //CODEC;
3131
bool operator==(I2SCodecConfig alt) {
3232
return input_device == alt.input_device &&
3333
output_device == alt.output_device && *((AudioInfo *)this) == alt;
@@ -214,6 +214,7 @@ class I2SCodecStream : public AudioStream, public VolumeSupport {
214214

215215
bool begin1() {
216216
TRACED();
217+
setupI2SFunction();
217218
setupI2SPins();
218219
if (!beginCodec(cfg)) {
219220
TRACEE();
@@ -230,6 +231,22 @@ class I2SCodecStream : public AudioStream, public VolumeSupport {
230231
return is_active;
231232
}
232233

234+
/// if the cfg.i2s_function was not defined we determine the "correct" default value
235+
void setupI2SFunction() {
236+
if (cfg.i2s_function == PinFunction::UNDEFINED){
237+
if (cfg.rx_tx_mode == RX_MODE){
238+
auto i2s = p_board->getPins().getI2SPins(PinFunction::CODEC_ADC);
239+
if (i2s){
240+
cfg.i2s_function = PinFunction::CODEC_ADC;
241+
LOGI("using i2s_function: CODEC_ADC");
242+
} else {
243+
cfg.i2s_function = PinFunction::CODEC;
244+
}
245+
} else {
246+
cfg.i2s_function = PinFunction::CODEC;
247+
}
248+
}
249+
}
233250

234251
/// We use the board pins if they are available
235252
void setupI2SPins() {

0 commit comments

Comments
 (0)