clean up I2C pin handling in audioreactive (ES7243+ES8388)

* remove double Wire.begin() - Wire cannot be re-initialized; its already started by pinManager.joinWire()
* Only use global I2C pins; make sure that audireactive I2C settings are aligned with global I2C pins
* minor cleanup
* remove I2C pins from AudioSource::initialize()

Note to self: sdaPin, sclPin are just dummy values now, good for UI consistency, but unused otherwise. Could be removed.
This commit is contained in:
Frank
2023-09-19 19:33:36 +02:00
parent b3d9621427
commit acc2d3aa10
2 changed files with 49 additions and 87 deletions

View File

@@ -1687,7 +1687,13 @@ class AudioReactive : public Usermod {
//useInputFilter = 0; // in case you need to disable low-cut software filtering
audioSource = new ES7243(SAMPLE_RATE, BLOCK_SIZE);
delay(100);
if (audioSource) audioSource->initialize(sdaPin, sclPin, i2swsPin, i2ssdPin, i2sckPin, mclkPin);
// WLEDMM align global pins
if ((sdaPin >= 0) && (i2c_sda < 0)) i2c_sda = sdaPin; // copy usermod prefs into globals (if globals not defined)
if ((sclPin >= 0) && (i2c_scl < 0)) i2c_scl = sclPin;
if (i2c_sda >= 0) sdaPin = -1; // -1 = use global
if (i2c_scl >= 0) sclPin = -1;
if (audioSource) audioSource->initialize(i2swsPin, i2ssdPin, i2sckPin, mclkPin);
break;
case 3:
DEBUGSR_PRINT(F("AR: SPH0645 Microphone - ")); DEBUGSR_PRINTLN(F(I2S_MIC_CHANNEL_TEXT));
@@ -1719,11 +1725,21 @@ class AudioReactive : public Usermod {
break;
#endif
case 6:
DEBUGSR_PRINTLN(F("AR: ES8388 Source"));
#ifdef use_es8388_mic
DEBUGSR_PRINTLN(F("AR: ES8388 Source (Mic)"));
#else
DEBUGSR_PRINTLN(F("AR: ES8388 Source (Line-In)"));
#endif
audioSource = new ES8388Source(SAMPLE_RATE, BLOCK_SIZE, 1.0f);
//useInputFilter = 0; // to disable low-cut software filtering and restore previous behaviour
delay(100);
if (audioSource) audioSource->initialize(sdaPin, sclPin, i2swsPin, i2ssdPin, i2sckPin, mclkPin);
// WLEDMM align global pins
if ((sdaPin >= 0) && (i2c_sda < 0)) i2c_sda = sdaPin; // copy usermod prefs into globals (if globals not defined)
if ((sclPin >= 0) && (i2c_scl < 0)) i2c_scl = sclPin;
if (i2c_sda >= 0) sdaPin = -1; // -1 = use global
if (i2c_scl >= 0) sclPin = -1;
if (audioSource) audioSource->initialize(i2swsPin, i2ssdPin, i2sckPin, mclkPin);
break;
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
@@ -2366,6 +2382,11 @@ class AudioReactive : public Usermod {
JsonObject dmic = top.createNestedObject(FPSTR(_digitalmic));
dmic[F("type")] = dmType;
// WLEDMM: align with globals I2C pins
if ((dmType == 2) || (dmType == 6)) { // only for ES7243 and ES8388
if (i2c_sda >= 0) sdaPin = -1; // -1 = use global
if (i2c_scl >= 0) sclPin = -1; // -1 = use global
}
JsonArray pinArray = dmic.createNestedArray("pin");
pinArray.add(i2ssdPin);
pinArray.add(i2swsPin);