diff --git a/wled00/audio_reactive.h b/wled00/audio_reactive.h index eaab1f77b6..227426bc2b 100644 --- a/wled00/audio_reactive.h +++ b/wled00/audio_reactive.h @@ -268,8 +268,6 @@ double fftAdd( int from, int to) { // FFT main code void FFTcode( void * parameter) { DEBUG_PRINT("FFT running on core: "); DEBUG_PRINTLN(xPortGetCoreID()); - //double beatSample = 0; // COMMENTED OUT - UNUSED VARIABLE COMPILER WARNINGS - //double envelope = 0; // COMMENTED OUT - UNUSED VARIABLE COMPILER WARNINGS for(;;) { delay(1); // DO NOT DELETE THIS LINE! It is needed to give the IDLE(0) task enough time and to keep the watchdog happy. diff --git a/wled00/audio_source.h b/wled00/audio_source.h index d3e2a840f8..b269aae1f1 100644 --- a/wled00/audio_source.h +++ b/wled00/audio_source.h @@ -110,11 +110,16 @@ class I2SSource : public AudioSource { virtual void initialize() { - if (!pinManager.allocatePin(i2sckPin, true, PinOwner::DigitalMic) || - !pinManager.allocatePin(i2swsPin, true, PinOwner::DigitalMic) || + if (!pinManager.allocatePin(i2swsPin, true, PinOwner::DigitalMic) || !pinManager.allocatePin(i2ssdPin, true, PinOwner::DigitalMic)) { return; - } + } + + // i2ssckPin needs special treatment, since it might be unused on PDM mics + if (i2sckPin != -1) { + if (!pinManager.allocatePin(i2sckPin, true, PinOwner::DigitalMic)) + return; + } esp_err_t err = i2s_driver_install(I2S_NUM_0, &_config, 0, nullptr); if (err != ESP_OK) { @@ -138,6 +143,12 @@ class I2SSource : public AudioSource { Serial.printf("Failed to uninstall i2s driver: %d\n", err); return; } + pinManager.deallocatePin(i2swsPin, PinOwner::DigitalMic); + pinManager.deallocatePin(i2ssdPin, PinOwner::DigitalMic); + // i2ssckPin needs special treatment, since it might be unused on PDM mics + if (i2sckPin != -1) { + pinManager.deallocatePin(i2sckPin, PinOwner::DigitalMic); + } } virtual void getSamples(double *buffer, uint16_t num_samples) { @@ -357,10 +368,19 @@ class I2SAdcSource : public I2SSource { void deinitialize() { pinManager.deallocatePin(audioPin, PinOwner::AnalogMic); - I2SSource::deinitialize(); + _initialized = false; + esp_err_t err = i2s_driver_uninstall(I2S_NUM_0); + if (err != ESP_OK) { + Serial.printf("Failed to uninstall i2s driver: %d\n", err); + return; + } } }; +/* SPH0645 Microphone + This is an I2S microphone with some timing quirks that need + special consideration. +*/ class SPH0654 : public I2SSource { public: @@ -372,4 +392,27 @@ class SPH0654 : public I2SSource { REG_SET_BIT(I2S_TIMING_REG(I2S_NUM_0), BIT(9)); REG_SET_BIT(I2S_CONF_REG(I2S_NUM_0), I2S_RX_MSB_SHIFT); } -}; \ No newline at end of file +}; + +/* I2S PDM Microphone + This is an I2S PDM microphone, these microphones only use a clock and + data line, to make it simpler to debug, use the WS pin as CLK and SD + pin as DATA +*/ + +class I2SPdmSource : public I2SSource { + +public: + I2SPdmSource(int sampleRate, int blockSize, uint16_t lshift, uint32_t mask) : + I2SSource(sampleRate, blockSize, lshift, mask) { + + _config.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); // Change mode to pdm + + _pinConfig = { + .bck_io_num = I2S_PIN_NO_CHANGE, // bck is unused in PDM mics + .ws_io_num = i2swsPin, // clk pin for PDM mic + .data_out_num = I2S_PIN_NO_CHANGE, + .data_in_num = i2ssdPin + }; + } +}; diff --git a/wled00/data/settings_sound.htm b/wled00/data/settings_sound.htm index 76471544f4..364ce7ef26 100644 --- a/wled00/data/settings_sound.htm +++ b/wled00/data/settings_sound.htm @@ -44,8 +44,9 @@