Skip to content

Commit 9f5957d

Browse files
committed
I2SCodecConfig add PinFunction for i2s
1 parent cd30f14 commit 9f5957d

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void setup(void) {
1515

1616
auto cfg = i2s.defaultConfig(RX_MODE);
1717
cfg.copyFrom(info);
18-
//cfg.input_device = ADC_INPUT_LINE2;
18+
// cfg.i2s_function = CODEC; // or CODEC_ADC
1919
i2s.begin(cfg);
2020

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

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@
99
#define PIN_SD_CARD_MISO 2
1010
#define PIN_SD_CARD_MOSI 15
1111
#define PIN_SD_CARD_CLK 14
12+
#define PIN_SD_CARD_DET 34
13+
1214

1315
// Arduino Setup
1416
void setup(void) {
1517
Serial.begin(115200);
1618

1719
// setup SPI
18-
SPI.begin(PIN_SD_CARD_CLK, PIN_SD_CARD_MISO, PIN_SD_CARD_MOSI, PIN_SD_CARD_CLK);
20+
SPI.begin(PIN_SD_CARD_CLK, PIN_SD_CARD_MISO, PIN_SD_CARD_MOSI, PIN_SD_CARD_CS);
21+
22+
// Determin if there is an SD card
23+
pinMode(PIN_SD_CARD_DET, INPUT);
24+
if (digitalRead(PIN_SD_CARD_DET)!=0){
25+
Serial.println("No SD Card detected");
26+
}
1927

2028
// Setup SD and open file
21-
if (!SD.begin(PIN_SD_CARD_CLK, SPI)){
29+
if (!SD.begin(PIN_SD_CARD_CS)){
2230
Serial.println("SD.begin failed");
2331
while(true);
2432
}
@@ -33,5 +41,4 @@ void setup(void) {
3341
}
3442

3543
// Arduino loop - repeated processing
36-
void loop() {
37-
}
44+
void loop() {}

src/AudioTools/AudioLibs/I2SCodecStream.h

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct I2SCodecConfig : public I2SConfig {
2626
output_device_t output_device = DAC_OUTPUT_ALL;
2727
// to be compatible with the AudioKitStream -> do not activate SD spi if false
2828
bool sd_active = true;
29-
29+
PinFunction i2s_function = PinFunction::CODEC;
3030
bool operator==(I2SCodecConfig alt) {
3131
return input_device == alt.input_device &&
3232
output_device == alt.output_device && *((AudioInfo *)this) == alt;
@@ -253,23 +253,8 @@ class I2SCodecStream : public AudioStream, public VolumeSupport {
253253
audio_driver_local::Optional<PinsI2S> getI2SPins(){
254254
TRACED();
255255
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;
256+
// Deterine I2S pins
257+
return p_board->getPins().getI2SPins(cfg.i2s_function);
273258
}
274259

275260
bool beginCodec(I2SCodecConfig info) {

0 commit comments

Comments
 (0)