Merge branch 'mdev' into ES8388S
This commit is contained in:
@@ -56,9 +56,17 @@ constexpr SRate_t SAMPLE_RATE = 22050; // Base sample rate in Hz - 22Kh
|
||||
|
||||
// globals
|
||||
static uint8_t inputLevel = 128; // UI slider value
|
||||
static uint8_t soundSquelch = 10; // squelch value for volume reactive routines (config value)
|
||||
static uint8_t sampleGain = 60; // sample gain (config value)
|
||||
static uint8_t soundAgc = 0; // Automagic gain control: 0 - none, 1 - normal, 2 - vivid, 3 - lazy (config value)
|
||||
#ifndef SR_SQUELCH
|
||||
uint8_t soundSquelch = 10; // squelch value for volume reactive routines (config value)
|
||||
#else
|
||||
uint8_t soundSquelch = SR_SQUELCH; // squelch value for volume reactive routines (config value)
|
||||
#endif
|
||||
#ifndef SR_GAIN
|
||||
uint8_t sampleGain = 60; // sample gain (config value)
|
||||
#else
|
||||
uint8_t sampleGain = SR_GAIN; // sample gain (config value)
|
||||
#endif
|
||||
static uint8_t soundAgc = 1; // Automagic gain control: 0 - none, 1 - normal, 2 - vivid, 3 - lazy (config value)
|
||||
static uint8_t audioSyncEnabled = 0; // bit field: bit 0 - send, bit 1 - receive (config value)
|
||||
static bool udpSyncConnected = false; // UDP connection status -> true if connected to multicast group
|
||||
|
||||
@@ -68,7 +76,11 @@ static uint16_t attackTime = 50; // int: attack time in millisecond
|
||||
static uint16_t decayTime = 300; // int: decay time in milliseconds. New default 300ms. Old default was 1.40sec
|
||||
// user settable options for FFTResult scaling
|
||||
static uint8_t FFTScalingMode = 3; // 0 none; 1 optimized logarithmic; 2 optimized linear; 3 optimized sqare root
|
||||
static uint8_t pinkIndex = 0; // 0: default; 1: line-in; 2: IMNP441
|
||||
#ifndef SR_FREQ_PROF
|
||||
static uint8_t pinkIndex = 0; // 0: default; 1: line-in; 2: IMNP441
|
||||
#else
|
||||
static uint8_t pinkIndex = SR_FREQ_PROF; // 0: default; 1: line-in; 2: IMNP441
|
||||
#endif
|
||||
|
||||
//
|
||||
// AGC presets
|
||||
@@ -167,7 +179,8 @@ static uint64_t sampleTime = 0;
|
||||
#define MAX_PINK 9 // 0 = standard, 1= line-in (pink moise only), 2..4 = IMNP441, 5..6 = ICS-43434, 6..7 = userdef, 9= flat (no pink noise adjustment)
|
||||
static const float fftResultPink[MAX_PINK+1][NUM_GEQ_CHANNELS] = {
|
||||
{ 1.70f, 1.71f, 1.73f, 1.78f, 1.68f, 1.56f, 1.55f, 1.63f, 1.79f, 1.62f, 1.80f, 2.06f, 2.47f, 3.35f, 6.83f, 9.55f }, // default from SR WLED
|
||||
{ 1.30f, 1.32f, 1.40f, 1.46f, 1.52f, 1.57f, 1.68f, 1.80f, 1.89f, 2.00f, 2.11f, 2.21f, 2.30f, 2.39f, 3.09f, 4.34f }, // Line-In - pink noise adjustment only, without microphone distortion
|
||||
// { 1.30f, 1.32f, 1.40f, 1.46f, 1.52f, 1.57f, 1.68f, 1.80f, 1.89f, 2.00f, 2.11f, 2.21f, 2.30f, 2.39f, 3.09f, 4.34f }, // Line-In Generic -> pink noise adjustment only
|
||||
{ 1.24f, 1.20f, 1.30f, 1.40f, 1.48f, 1.57f, 1.68f, 1.80f, 1.89f, 2.00f, 2.14f, 2.26f, 2.60f, 3.00f, 3.70f, 5.20f }, // Line-In CS5343
|
||||
|
||||
{ 1.82f, 1.72f, 1.70f, 1.50f, 1.52f, 1.57f, 1.68f, 1.80f, 1.89f, 2.00f, 2.11f, 2.21f, 2.30f, 2.90f, 3.86f, 6.29f}, // IMNP441 datasheet response profile * pink noise
|
||||
{ 2.80f, 2.20f, 1.30f, 1.15f, 1.55f, 2.45f, 4.20f, 2.80f, 3.20f, 3.60f, 4.20f, 4.90f, 5.70f, 6.05f,10.50f,14.85f}, // IMNP441 - big speaker, strong bass
|
||||
@@ -285,10 +298,11 @@ void FFTcode(void * parameter)
|
||||
// band pass filter - can reduce noise floor by a factor of 50
|
||||
// downside: frequencies below 100Hz will be ignored
|
||||
if (useBandPassFilter) {
|
||||
// low frequency cutoff parameter
|
||||
//constexpr float alpha = 0.04f; // 100hz
|
||||
constexpr float alpha = 0.03f; // 80hz
|
||||
//constexpr float alpha = 0.0225f; // 60hz
|
||||
// low frequency cutoff parameter - see https://dsp.stackexchange.com/questions/40462/exponential-moving-average-cut-off-frequency
|
||||
//constexpr float alpha = 0.04f; // 150Hz
|
||||
//constexpr float alpha = 0.03f; // 110Hz
|
||||
constexpr float alpha = 0.0225f; // 80hz
|
||||
//constexpr float alpha = 0.01693f;// 60hz
|
||||
// high frequency cutoff parameter
|
||||
//constexpr float beta1 = 0.75; // 11Khz
|
||||
//constexpr float beta1 = 0.82; // 15Khz
|
||||
@@ -597,10 +611,10 @@ class AudioReactive : public Usermod {
|
||||
#else
|
||||
int8_t audioPin = AUDIOPIN;
|
||||
#endif
|
||||
#ifndef DMTYPE // I2S mic type
|
||||
#ifndef SR_DMTYPE // I2S mic type
|
||||
uint8_t dmType = 1; // 0=none/disabled/analog; 1=generic I2S
|
||||
#else
|
||||
uint8_t dmType = DMTYPE;
|
||||
uint8_t dmType = SR_DMTYPE;
|
||||
#endif
|
||||
#ifndef I2S_SDPIN // aka DOUT
|
||||
int8_t i2ssdPin = 32;
|
||||
@@ -1194,6 +1208,7 @@ class AudioReactive : public Usermod {
|
||||
break;
|
||||
case 2:
|
||||
DEBUGSR_PRINTLN(F("AR: ES7243 Microphone (right channel only)."));
|
||||
//useBandPassFilter = true;
|
||||
audioSource = new ES7243(SAMPLE_RATE, BLOCK_SIZE);
|
||||
delay(100);
|
||||
if (audioSource) audioSource->initialize(sdaPin, sclPin, i2swsPin, i2ssdPin, i2sckPin, mclkPin);
|
||||
@@ -1206,6 +1221,7 @@ class AudioReactive : public Usermod {
|
||||
break;
|
||||
case 4:
|
||||
DEBUGSR_PRINT(F("AR: Generic I2S Microphone with Master Clock - ")); DEBUGSR_PRINTLN(F(I2S_MIC_CHANNEL_TEXT));
|
||||
//useBandPassFilter = true;
|
||||
audioSource = new I2SSource(SAMPLE_RATE, BLOCK_SIZE, true, 1.0f/24.0f);
|
||||
//audioSource = new I2SSource(SAMPLE_RATE, BLOCK_SIZE, false, 1.0f/16.0f); // I2S SLAVE mode - does not work, unfortunately
|
||||
delay(100);
|
||||
@@ -1232,6 +1248,7 @@ class AudioReactive : public Usermod {
|
||||
case 0:
|
||||
default:
|
||||
DEBUGSR_PRINTLN(F("AR: Analog Microphone (left channel only)."));
|
||||
//useBandPassFilter = true;
|
||||
audioSource = new I2SAdcSource(SAMPLE_RATE, BLOCK_SIZE);
|
||||
delay(100);
|
||||
if (audioSource) audioSource->initialize(audioPin);
|
||||
@@ -1246,7 +1263,11 @@ class AudioReactive : public Usermod {
|
||||
if (enabled) disableSoundProcessing = false; // all good - enable audio processing
|
||||
|
||||
if((!audioSource) || (!audioSource->isInitialized())) { // audio source failed to initialize. Still stay "enabled", as there might be input arriving via UDP Sound Sync
|
||||
#ifdef WLED_DEBUG
|
||||
DEBUG_PRINTLN(F("AR: Failed to initialize sound input driver. Please check input PIN settings."));
|
||||
#else
|
||||
DEBUGSR_PRINTLN(F("AR: Failed to initialize sound input driver. Please check input PIN settings."));
|
||||
#endif
|
||||
disableSoundProcessing = true;
|
||||
}
|
||||
|
||||
@@ -1728,19 +1749,19 @@ class AudioReactive : public Usermod {
|
||||
pinArray.add(sdaPin);
|
||||
pinArray.add(sclPin);
|
||||
|
||||
JsonObject cfg = top.createNestedObject("cfg");
|
||||
JsonObject cfg = top.createNestedObject("config");
|
||||
cfg[F("squelch")] = soundSquelch;
|
||||
cfg[F("gain")] = sampleGain;
|
||||
cfg[F("AGC")] = soundAgc;
|
||||
|
||||
JsonObject dynLim = top.createNestedObject("dynamics");
|
||||
dynLim[F("Limiter")] = limiterOn;
|
||||
dynLim[F("Rise")] = attackTime;
|
||||
dynLim[F("Fall")] = decayTime;
|
||||
dynLim[F("limiter")] = limiterOn;
|
||||
dynLim[F("rise")] = attackTime;
|
||||
dynLim[F("fall")] = decayTime;
|
||||
|
||||
JsonObject freqScale = top.createNestedObject("Frequency");
|
||||
freqScale[F("Scale")] = FFTScalingMode;
|
||||
freqScale[F("Profile")] = pinkIndex;
|
||||
JsonObject freqScale = top.createNestedObject("frequency");
|
||||
freqScale[F("scale")] = FFTScalingMode;
|
||||
freqScale[F("profile")] = pinkIndex;
|
||||
|
||||
JsonObject sync = top.createNestedObject("sync");
|
||||
sync[F("port")] = audioSyncPort;
|
||||
@@ -1780,16 +1801,16 @@ class AudioReactive : public Usermod {
|
||||
configComplete &= getJsonValue(top[FPSTR(_digitalmic)]["pin"][4], sdaPin);
|
||||
configComplete &= getJsonValue(top[FPSTR(_digitalmic)]["pin"][5], sclPin);
|
||||
|
||||
configComplete &= getJsonValue(top["cfg"][F("squelch")], soundSquelch);
|
||||
configComplete &= getJsonValue(top["cfg"][F("gain")], sampleGain);
|
||||
configComplete &= getJsonValue(top["cfg"][F("AGC")], soundAgc);
|
||||
configComplete &= getJsonValue(top["config"][F("squelch")], soundSquelch);
|
||||
configComplete &= getJsonValue(top["config"][F("gain")], sampleGain);
|
||||
configComplete &= getJsonValue(top["config"][F("AGC")], soundAgc);
|
||||
|
||||
configComplete &= getJsonValue(top["dynamics"][F("Limiter")], limiterOn);
|
||||
configComplete &= getJsonValue(top["dynamics"][F("Rise")], attackTime);
|
||||
configComplete &= getJsonValue(top["dynamics"][F("Fall")], decayTime);
|
||||
configComplete &= getJsonValue(top["dynamics"][F("limiter")], limiterOn);
|
||||
configComplete &= getJsonValue(top["dynamics"][F("rise")], attackTime);
|
||||
configComplete &= getJsonValue(top["dynamics"][F("fall")], decayTime);
|
||||
|
||||
configComplete &= getJsonValue(top["Frequency"][F("Scale")], FFTScalingMode);
|
||||
configComplete &= getJsonValue(top["Frequency"][F("Profile")], pinkIndex);
|
||||
configComplete &= getJsonValue(top["frequency"][F("scale")], FFTScalingMode);
|
||||
configComplete &= getJsonValue(top["frequency"][F("profile")], pinkIndex);
|
||||
|
||||
configComplete &= getJsonValue(top["sync"][F("port")], audioSyncPort);
|
||||
configComplete &= getJsonValue(top["sync"][F("mode")], audioSyncEnabled);
|
||||
@@ -1812,26 +1833,26 @@ class AudioReactive : public Usermod {
|
||||
oappend(SET_F("addOption(dd,'Generic I2S PDM',5);"));
|
||||
#endif
|
||||
oappend(SET_F("addOption(dd,'ES8388',6);"));
|
||||
oappend(SET_F("dd=addDropdown('AudioReactive','cfg:AGC');"));
|
||||
oappend(SET_F("dd=addDropdown('AudioReactive','config:AGC');"));
|
||||
oappend(SET_F("addOption(dd,'Off',0);"));
|
||||
oappend(SET_F("addOption(dd,'Normal',1);"));
|
||||
oappend(SET_F("addOption(dd,'Vivid',2);"));
|
||||
oappend(SET_F("addOption(dd,'Lazy',3);"));
|
||||
|
||||
oappend(SET_F("dd=addDropdown('AudioReactive','dynamics:Limiter');"));
|
||||
oappend(SET_F("dd=addDropdown('AudioReactive','dynamics:limiter');"));
|
||||
oappend(SET_F("addOption(dd,'Off',0);"));
|
||||
oappend(SET_F("addOption(dd,'On',1);"));
|
||||
oappend(SET_F("addInfo('AudioReactive:dynamics:Limiter',0,' On ');")); // 0 is field type, 1 is actual field
|
||||
oappend(SET_F("addInfo('AudioReactive:dynamics:Rise',1,'ms <i>(♪ effects only)</i>');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:dynamics:Fall',1,'ms <i>(♪ effects only)</i>');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:dynamics:limiter',0,' On ');")); // 0 is field type, 1 is actual field
|
||||
oappend(SET_F("addInfo('AudioReactive:dynamics:rise',1,'ms <i>(♪ effects only)</i>');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:dynamics:fall',1,'ms <i>(♪ effects only)</i>');"));
|
||||
|
||||
oappend(SET_F("dd=addDropdown('AudioReactive','Frequency:Scale');"));
|
||||
oappend(SET_F("dd=addDropdown('AudioReactive','frequency:scale');"));
|
||||
oappend(SET_F("addOption(dd,'None',0);"));
|
||||
oappend(SET_F("addOption(dd,'Linear (Amplitude)',2);"));
|
||||
oappend(SET_F("addOption(dd,'Square Root (Energy)',3);"));
|
||||
oappend(SET_F("addOption(dd,'Logarithmic (Loudness)',1);"));
|
||||
|
||||
oappend(SET_F("dd=addDropdown('AudioReactive','Frequency:Profile');"));
|
||||
oappend(SET_F("dd=addDropdown('AudioReactive','frequency:profile');"));
|
||||
oappend(SET_F("addOption(dd,'Generic Microphone',0);"));
|
||||
oappend(SET_F("addOption(dd,'Generic Line-In',1);"));
|
||||
oappend(SET_F("addOption(dd,'IMNP441',2);"));
|
||||
@@ -1848,16 +1869,16 @@ class AudioReactive : public Usermod {
|
||||
oappend(SET_F("addOption(dd,'Send',1);"));
|
||||
oappend(SET_F("addOption(dd,'Receive',2);"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:type',1,'<i>requires reboot!</i>');")); // 0 is field type, 1 is actual field
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',0,'I2S SD');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',1,'I2S WS');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',2,'I2S SCK');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',0,'I2S Serial Data', '<i><span class=\"h\">sd/data/dout</span></i>');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',1,'I2S L/R Clock','<i><span class=\"h\">ws/clk/lrck</span></i>');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',2,'I2S Serial Clock','<i>sck/bclk</i>');"));
|
||||
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'I2S Master CLK <br/><i>only use -1, 0, 1 or 3 for MCLK</i>');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'I2S Master CLK','<i>only use -1, 0, 1 or 3</i>');"));
|
||||
#else
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'I2S Master CLK');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'I2S Master CLK','');"));
|
||||
#endif
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',4,'I2C SDA');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',5,'I2C SCL');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',4,'I2C SDA',' ');"));
|
||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',5,'I2C SCL',' ');"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,11 +24,15 @@
|
||||
|
||||
// see https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/chip-series-comparison.html#related-documents
|
||||
// and https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/i2s.html#overview-of-all-modes
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C5) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2)
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C5) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2) || defined(ESP8266) || defined(ESP8265)
|
||||
// there are two things in these MCUs that could lead to problems with audio processing:
|
||||
// * no floating point hardware (FPU) support - FFT uses float calculations. If done in software, a strong slow-down can be expected (between 8x and 20x)
|
||||
// * single core, so FFT task might slow down other things like LED updates
|
||||
#if !defined(SOC_I2S_NUM) || (SOC_I2S_NUM < 1)
|
||||
#error This audio reactive usermod does not support ESP32-C2, ESP32-C3 or ESP32-S2.
|
||||
#else
|
||||
#warning This audio reactive usermod does not support ESP32-C2, ESP32-C3 or ESP32-S2.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* ToDo: remove. ES7243 is controlled via compiler defines
|
||||
@@ -227,11 +231,23 @@ class I2SSource : public AudioSource {
|
||||
}
|
||||
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
|
||||
if ((_i2sMaster == false) && (_config.mode & I2S_MODE_SLAVE)) { // I2S slave mode (experimental).
|
||||
// Seems we need to drive clocks in slave mode
|
||||
_config.use_apll = true;
|
||||
_config.fixed_mclk = 512 * int(_config.sample_rate);
|
||||
}
|
||||
|
||||
if (mclkPin != I2S_PIN_NO_CHANGE) {
|
||||
_config.use_apll = true; // experimental - use aPLL clock source to improve sampling quality, and to avoid glitches.
|
||||
// //_config.fixed_mclk = 512 * _sampleRate;
|
||||
// //_config.fixed_mclk = 256 * _sampleRate;
|
||||
}
|
||||
|
||||
#if !defined(SOC_I2S_SUPPORTS_APLL)
|
||||
#warning this MCU does not have an APLL high accuracy clock for audio
|
||||
// S3: not supported; S2: supported; C3: not supported
|
||||
_config.use_apll = false; // APLL not supported on this MCU
|
||||
#endif
|
||||
#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
if (ESP.getChipRevision() == 0) _config.use_apll = false; // APLL is broken on ESP32 revision 0
|
||||
#endif
|
||||
@@ -263,6 +279,8 @@ class I2SSource : public AudioSource {
|
||||
.data_in_num = i2ssdPin
|
||||
};
|
||||
|
||||
//DEBUGSR_PRINTF("[AR] I2S: SD=%d, WS=%d, SCK=%d, MCLK=%d\n", i2ssdPin, i2swsPin, i2sckPin, mclkPin);
|
||||
|
||||
esp_err_t err = i2s_driver_install(I2S_NUM_0, &_config, 0, nullptr);
|
||||
if (err != ESP_OK) {
|
||||
DEBUGSR_PRINTF("AR: Failed to install i2s driver: %d\n", err);
|
||||
@@ -274,7 +292,8 @@ class I2SSource : public AudioSource {
|
||||
if(_config.mode & I2S_MODE_MASTER) {
|
||||
if (_config.mode & I2S_MODE_PDM)
|
||||
DEBUGSR_PRINTLN(F("AR: I2S#0 driver installed in PDM MASTER mode."));
|
||||
else DEBUGSR_PRINTLN(F("AR: I2S#0 driver installed in MASTER mode."));
|
||||
else
|
||||
DEBUGSR_PRINTLN(F("AR: I2S#0 driver installed in MASTER mode."));
|
||||
} else
|
||||
DEBUGSR_PRINTLN(F("AR: I2S#0 driver installed in SLAVE mode."));
|
||||
|
||||
@@ -412,9 +431,22 @@ public:
|
||||
};
|
||||
|
||||
void initialize(int8_t sdaPin, int8_t sclPin, int8_t i2swsPin, int8_t i2ssdPin, int8_t i2sckPin, int8_t mclkPin) {
|
||||
// check that pins are valid
|
||||
if ((sdaPin < 0) || (sclPin < 0)) {
|
||||
DEBUGSR_PRINTF("\nAR: invalid ES7243 I2C pins: SDA=%d, SCL=%d\n", sdaPin, sclPin);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((i2sckPin < 0) || (mclkPin < 0)) {
|
||||
DEBUGSR_PRINTF("\nAR: invalid I2S pin: SCK=%d, MCLK=%d\n", i2sckPin, mclkPin);
|
||||
return;
|
||||
}
|
||||
|
||||
// Reserve SDA and SCL pins of the I2C interface
|
||||
if (!pinManager.allocatePin(sdaPin, true, PinOwner::HW_I2C) ||
|
||||
!pinManager.allocatePin(sclPin, true, PinOwner::HW_I2C)) {
|
||||
PinManagerPinType es7243Pins[2] = { { sdaPin, true }, { sclPin, true } };
|
||||
if (!pinManager.allocateMultiplePins(es7243Pins, 2, PinOwner::HW_I2C)) {
|
||||
pinManager.deallocateMultiplePins(es7243Pins, 2, PinOwner::HW_I2C);
|
||||
DEBUGSR_PRINTF("\nAR: Failed to allocate ES7243 I2C pins: SDA=%d, SCL=%d\n", sdaPin, sclPin);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -428,8 +460,8 @@ public:
|
||||
|
||||
void deinitialize() {
|
||||
// Release SDA and SCL pins of the I2C interface
|
||||
pinManager.deallocatePin(pin_ES7243_SDA, PinOwner::HW_I2C);
|
||||
pinManager.deallocatePin(pin_ES7243_SCL, PinOwner::HW_I2C);
|
||||
PinManagerPinType es7243Pins[2] = { { pin_ES7243_SDA, true }, { pin_ES7243_SCL, true } };
|
||||
pinManager.deallocateMultiplePins(es7243Pins, 2, PinOwner::HW_I2C);
|
||||
I2SSource::deinitialize();
|
||||
}
|
||||
|
||||
@@ -495,6 +527,12 @@ public:
|
||||
|
||||
|
||||
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
|
||||
#if !defined(SOC_I2S_SUPPORTS_ADC) && !defined(SOC_I2S_SUPPORTS_ADC_DAC)
|
||||
#warning this MCU does not support analog sound input
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
// ADC over I2S is only availeable in "classic" ESP32
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ All parameters are runtime configurable though some may require hard boot after
|
||||
|
||||
If you want to define default GPIOs during compile time use the following (default values in parentheses):
|
||||
|
||||
- `DMTYPE=x` : defines digital microphone type: 0=analog, 1=generic I2S, 2=ES7243 I2S, 3=SPH0645 I2S, 4=generic I2S with master clock, 5=PDM I2S
|
||||
- `SR_DMTYPE=x` : defines digital microphone type: 0=analog, 1=generic I2S, 2=ES7243 I2S, 3=SPH0645 I2S, 4=generic I2S with master clock, 5=PDM I2S
|
||||
- `AUDIOPIN=x` : GPIO for analog microphone/AUX-in (36)
|
||||
- `I2S_SDPIN=x` : GPIO for SD pin on digital mcrophone (32)
|
||||
- `I2S_WSPIN=x` : GPIO for WS pin on digital mcrophone (15)
|
||||
|
||||
@@ -1036,11 +1036,11 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
oappend(SET_F("addOption(dd,'SSD1305 128x64',5);"));
|
||||
oappend(SET_F("addOption(dd,'SSD1306 SPI',6);"));
|
||||
oappend(SET_F("addOption(dd,'SSD1306 SPI 128x64',7);"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',0,'I2C/SPI CLK (-1 use global)');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',1,'I2C/SPI DTA (-1 use global)');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',2,'SPI CS');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',3,'SPI DC');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',4,'SPI RST');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',0,'I2C/SPI CLK','<i>-1 use global</i>');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',1,'I2C/SPI DTA','<i>-1 use global</i>');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',2,'SPI CS',' ');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',3,'SPI DC',' ');"));
|
||||
oappend(SET_F("addInfo('4LineDisplay:pin[]',4,'SPI RST',' ');"));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -54,8 +54,8 @@
|
||||
class RotaryEncoderUIUsermod : public Usermod {
|
||||
private:
|
||||
int fadeAmount = 10; // Amount to change every step (brightness)
|
||||
unsigned long currentTime;
|
||||
unsigned long loopTime;
|
||||
unsigned long currentTime = 0;
|
||||
unsigned long loopTime = 0;
|
||||
int8_t pinA = ENCODER_DT_PIN; // DT from encoder
|
||||
int8_t pinB = ENCODER_CLK_PIN; // CLK from encoder
|
||||
int8_t pinC = ENCODER_SW_PIN; // SW from encoder
|
||||
@@ -107,6 +107,7 @@ public:
|
||||
// tracking the owner tags....
|
||||
pinA = pinB = pinC = -1;
|
||||
enabled = false;
|
||||
DEBUG_PRINTLN(F("Failed to alocate GPIO pins for Usermod Rotary Encoder.")); //WLEDMM add debug info
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ static int re_qstringCmp(const void *ap, const void *bp) {
|
||||
class RotaryEncoderUIUsermod : public Usermod {
|
||||
private:
|
||||
int8_t fadeAmount = 5; // Amount to change every step (brightness)
|
||||
unsigned long loopTime;
|
||||
unsigned long loopTime = 0;
|
||||
|
||||
unsigned long buttonPressedTime = 0;
|
||||
unsigned long buttonWaitTime = 0;
|
||||
@@ -275,6 +275,7 @@ public:
|
||||
// tracking the owner tags....
|
||||
pinA = pinB = pinC = -1;
|
||||
enabled = false;
|
||||
DEBUG_PRINTLN(F("Failed to alocate GPIO pins for Usermod Rotary Encoder (ALT).")); //WLEDMM add debug info
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -327,9 +328,11 @@ public:
|
||||
*/
|
||||
void loop()
|
||||
{
|
||||
if (!enabled || strip.isUpdating()) return;
|
||||
if (!enabled) return;
|
||||
unsigned long currentTime = millis(); // get the current elapsed time
|
||||
|
||||
if (strip.isUpdating() && (currentTime - loopTime < 4)) return; // WLEDMM: be nice, but not too nice
|
||||
|
||||
// Initialize effectCurrentIndex and effectPaletteIndex to
|
||||
// current state. We do it here as (at least) effectCurrent
|
||||
// is not yet initialized when setup is called.
|
||||
@@ -342,7 +345,7 @@ public:
|
||||
currentEffectAndPaletteInitialized = false;
|
||||
}
|
||||
|
||||
if (currentTime >= (loopTime + 2)) // 2ms since last check of encoder = 500Hz
|
||||
if (currentTime - loopTime >= 2) // 2ms since last check of encoder = 500Hz
|
||||
{
|
||||
loopTime = currentTime; // Updates loopTime
|
||||
|
||||
@@ -642,8 +645,8 @@ public:
|
||||
}
|
||||
lampUdated();
|
||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||
char lineBuffer[64];
|
||||
sprintf(lineBuffer, "%d", val);
|
||||
char lineBuffer[64] = { '\0' };
|
||||
snprintf(lineBuffer, 63, "%d", val); // WLEDMM: avoid string buffer overflow
|
||||
display->overlay(lineBuffer, 500, 10); // use star
|
||||
#endif
|
||||
}
|
||||
@@ -702,8 +705,8 @@ public:
|
||||
}
|
||||
lampUdated();
|
||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||
char lineBuffer[64];
|
||||
sprintf(lineBuffer, "%d", currentHue1);
|
||||
char lineBuffer[64] = { '\0' };
|
||||
snprintf(lineBuffer, 63, "%d", currentHue1); // WLEDMM: avoid string buffer overflow
|
||||
display->overlay(lineBuffer, 500, 7); // use brush
|
||||
#endif
|
||||
}
|
||||
@@ -731,8 +734,8 @@ public:
|
||||
}
|
||||
lampUdated();
|
||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||
char lineBuffer[64];
|
||||
sprintf(lineBuffer, "%d", currentSat1);
|
||||
char lineBuffer[64] = { '\0' };
|
||||
snprintf(lineBuffer, 63, "%d", currentSat1); // WLEDMM: avoid string buffer overflow
|
||||
display->overlay(lineBuffer, 500, 8); // use contrast
|
||||
#endif
|
||||
}
|
||||
@@ -748,7 +751,7 @@ public:
|
||||
#endif
|
||||
if (presetHigh && presetLow && presetHigh > presetLow) {
|
||||
StaticJsonDocument<64> root;
|
||||
char str[64];
|
||||
char str[64] = { '\0' };
|
||||
sprintf_P(str, PSTR("%d~%d~%s"), presetLow, presetHigh, increase?"":"-");
|
||||
root[F("ps")] = str;
|
||||
deserializeState(root.as<JsonObject>(), CALL_MODE_BUTTON_PRESET);
|
||||
@@ -763,7 +766,7 @@ public:
|
||||
*/
|
||||
lampUdated();
|
||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||
sprintf(str, "%d", currentPreset);
|
||||
snprintf(str, 63, "%d", currentPreset); // WLEDMM: avoid string buffer overflow
|
||||
display->overlay(str, 500, 11); // use heart
|
||||
#endif
|
||||
}
|
||||
@@ -791,8 +794,8 @@ public:
|
||||
// }
|
||||
lampUdated();
|
||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||
char lineBuffer[64];
|
||||
sprintf(lineBuffer, "%d", currentCCT);
|
||||
char lineBuffer[64] = { '\0' };
|
||||
snprintf(lineBuffer, 63, "%d", currentCCT); // WLEDMM: avoid string buffer overflow
|
||||
display->overlay(lineBuffer, 500, 10); // use star
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user