From b7aeb2cf95ef3a99a57d0b860fbf63a925770837 Mon Sep 17 00:00:00 2001 From: Andrew Dikarev Date: Fri, 2 Dec 2022 21:45:06 +0200 Subject: [PATCH 1/3] Remove delay Remove additional delay to avoid an indeterminate state. --- wled00/usermod.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/wled00/usermod.cpp b/wled00/usermod.cpp index fb4e4287ce..cd99f4dd68 100644 --- a/wled00/usermod.cpp +++ b/wled00/usermod.cpp @@ -30,7 +30,6 @@ void userSetup() { disableSoundProcessing = true; // just to be safe // Reset I2S peripheral for good measure i2s_driver_uninstall(I2S_NUM_0); - delay(100); // Give this peripheral time to disable to avoid an indeterminate state. periph_module_reset(PERIPH_I2S0_MODULE); delay(100); // Give that poor microphone some time to setup. From 121f5638656645cd644598bae918dbae331a8f70 Mon Sep 17 00:00:00 2001 From: Andrew Dikarev Date: Fri, 2 Dec 2022 23:35:42 +0200 Subject: [PATCH 2/3] Reset entire I2S peripheral. Better option solving the problem as we reset entire I2S peripheral, may which it may be in an indeterminate state after a soft reset, in which the analog microphone does not work. --- wled00/audio_source.h | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/wled00/audio_source.h b/wled00/audio_source.h index e500702ca8..59ca6b21b5 100644 --- a/wled00/audio_source.h +++ b/wled00/audio_source.h @@ -463,7 +463,41 @@ class I2SAdcSource : public I2SSource { void initialize() { - // check if "analog buttons" are configured for ADC1, and issue warning +#if IDF_TARGET == esp32 + // Reset some i2s configuration (possibly redundant as we reset entire + // I2S peripheral further down). + CLEAR_PERI_REG_MASK(I2S_CONF_REG(0), I2S_RX_START); + SET_PERI_REG_MASK(I2S_CONF_REG(0), I2S_RX_RESET); + CLEAR_PERI_REG_MASK(I2S_CONF_REG(0), I2S_RX_RESET); + CLEAR_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_CAMERA_EN); + CLEAR_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_LCD_EN); + CLEAR_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_DATA_ENABLE_TEST_EN); + CLEAR_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_DATA_ENABLE); + + // Disable i2s clock + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_I2S0_CLK_EN); + + // Restore SYSCON mode registers + CLEAR_PERI_REG_MASK(SENS_SAR_READ_CTRL_REG, SENS_SAR1_DIG_FORCE); + CLEAR_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DIG_FORCE); + + // Restore SAR ADC mode + CLEAR_PERI_REG_MASK(SENS_SAR_START_FORCE_REG, SENS_SAR2_EN_TEST); + CLEAR_PERI_REG_MASK(SYSCON_SARADC_CTRL_REG, SYSCON_SARADC_SAR2_MUX + | SYSCON_SARADC_SAR_SEL | SYSCON_SARADC_DATA_TO_I2S); + SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 0, SENS_FORCE_XPD_SAR_S); + SET_PERI_REG_BITS(SYSCON_SARADC_FSM_REG, SYSCON_SARADC_START_WAIT, 8, SYSCON_SARADC_START_WAIT_S); + + // Reset i2s peripheral + DPORT_SET_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_I2S0_RST); + DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_I2S0_RST); + + // Disable pull supply voltage to SAR ADC + CLEAR_PERI_REG_MASK(RTC_CNTL_TEST_MUX_REG, RTC_CNTL_ENT_RTC); + SET_PERI_REG_BITS(RTC_CNTL_TEST_MUX_REG, RTC_CNTL_DTEST_RTC, 0, RTC_CNTL_DTEST_RTC_S); +#endif + + // check if "analog buttons" are configured for ADC1, and issue warning for (int b=0; b= 0) && (buttonType[b] == BTN_TYPE_ANALOG || buttonType[b] == BTN_TYPE_ANALOG_INVERTED) && (digitalPinToAnalogChannel(btnPin[b]) < 10)) { if ((btnPin[b] >= 0) && (buttonType[b] == BTN_TYPE_ANALOG || buttonType[b] == BTN_TYPE_ANALOG_INVERTED) && (digitalPinToAnalogChannel(btnPin[b]) >= 0)) { From 0a93275ac4bf656481504c8796e5e15d540cff74 Mon Sep 17 00:00:00 2001 From: Andrew Dikarev Date: Sat, 3 Dec 2022 00:02:05 +0200 Subject: [PATCH 3/3] Update audio_source.h Add an required includes --- wled00/audio_source.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wled00/audio_source.h b/wled00/audio_source.h index 59ca6b21b5..37350054b9 100644 --- a/wled00/audio_source.h +++ b/wled00/audio_source.h @@ -9,6 +9,11 @@ #include #endif +#include "soc/rtc_cntl_reg.h" +#include "soc/sens_reg.h" +#include "soc/syscon_reg.h" +#include "soc/i2s_reg.h" + //#include //#include //#include