Skip to content

Commit

Permalink
I2SCodecConfig add PinFunction for i2s
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Nov 2, 2024
1 parent cd30f14 commit 9f5957d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/examples-custom-boards/lyrat-mini/mic/mic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void setup(void) {

auto cfg = i2s.defaultConfig(RX_MODE);
cfg.copyFrom(info);
//cfg.input_device = ADC_INPUT_LINE2;
// cfg.i2s_function = CODEC; // or CODEC_ADC
i2s.begin(cfg);

// make sure that we have the correct number of channels set up
Expand Down
15 changes: 11 additions & 4 deletions examples/examples-custom-boards/lyrat-mini/sd/sd.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@
#define PIN_SD_CARD_MISO 2
#define PIN_SD_CARD_MOSI 15
#define PIN_SD_CARD_CLK 14
#define PIN_SD_CARD_DET 34


// Arduino Setup
void setup(void) {
Serial.begin(115200);

// setup SPI
SPI.begin(PIN_SD_CARD_CLK, PIN_SD_CARD_MISO, PIN_SD_CARD_MOSI, PIN_SD_CARD_CLK);
SPI.begin(PIN_SD_CARD_CLK, PIN_SD_CARD_MISO, PIN_SD_CARD_MOSI, PIN_SD_CARD_CS);

// Determin if there is an SD card
pinMode(PIN_SD_CARD_DET, INPUT);
if (digitalRead(PIN_SD_CARD_DET)!=0){
Serial.println("No SD Card detected");
}

// Setup SD and open file
if (!SD.begin(PIN_SD_CARD_CLK, SPI)){
if (!SD.begin(PIN_SD_CARD_CS)){
Serial.println("SD.begin failed");
while(true);
}
Expand All @@ -33,5 +41,4 @@ void setup(void) {
}

// Arduino loop - repeated processing
void loop() {
}
void loop() {}
21 changes: 3 additions & 18 deletions src/AudioTools/AudioLibs/I2SCodecStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct I2SCodecConfig : public I2SConfig {
output_device_t output_device = DAC_OUTPUT_ALL;
// to be compatible with the AudioKitStream -> do not activate SD spi if false
bool sd_active = true;

PinFunction i2s_function = PinFunction::CODEC;
bool operator==(I2SCodecConfig alt) {
return input_device == alt.input_device &&
output_device == alt.output_device && *((AudioInfo *)this) == alt;
Expand Down Expand Up @@ -253,23 +253,8 @@ class I2SCodecStream : public AudioStream, public VolumeSupport {
audio_driver_local::Optional<PinsI2S> getI2SPins(){
TRACED();
audio_driver_local::Optional<PinsI2S> i2s;
// special logic if we have a board which has a dedicated microphone I2S port
if (cfg.rx_tx_mode == RX_MODE){
i2s = p_board->getPins().getI2SPins(PinFunction::CODEC_ADC);
#ifdef ESP32
if (i2s){
cfg.port_no = i2s.value().port;
LOGI("Using port %d for input", cfg.port_no);
}
#endif
}

// Deterine regular I2S pins
if (!i2s){
// setup pins in i2s config
i2s = p_board->getPins().getI2SPins();
}
return i2s;
// Deterine I2S pins
return p_board->getPins().getI2SPins(cfg.i2s_function);
}

bool beginCodec(I2SCodecConfig info) {
Expand Down

0 comments on commit 9f5957d

Please sign in to comment.