From 3503ccd958d3191951b926893e63ff9bfc19a735 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Mon, 7 Aug 2023 18:06:31 +0200 Subject: [PATCH] Use MM specific I2C related functions for ES8388 and ES7243 In contrast to upstream, MM follows a "no pin stealing" approach, so the Wire interfaces are only initialized when needed. pinManager.joinWire() will take care of the details, and will return false if something went wrong. --- usermods/audioreactive/audio_source.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/usermods/audioreactive/audio_source.h b/usermods/audioreactive/audio_source.h index 13a00f5b..7101fe09 100644 --- a/usermods/audioreactive/audio_source.h +++ b/usermods/audioreactive/audio_source.h @@ -456,6 +456,15 @@ public: void initialize(int8_t i2swsPin, int8_t i2ssdPin, int8_t i2sckPin, int8_t mclkPin) { // check that pins are valid + if ((i2c_sda < 0) || (i2c_scl < 0)) { // check that global I2C pins are not "undefined" + ERRORSR_PRINTF("\nAR: invalid ES7243 global I2C pins: SDA=%d, SCL=%d\n", i2c_sda, i2c_scl); + return; + } + if (!pinManager.joinWire()) { // WLEDMM specific: start I2C with globally defined pins + ERRORSR_PRINTF("\nAR: failed to start I2C bus with SDA=%d, SCL=%d\n", i2c_sda, i2c_scl); + return; + } + if ((i2sckPin < 0) || (mclkPin < 0)) { ERRORSR_PRINTF("\nAR: invalid I2S pin: SCK=%d, MCLK=%d\n", i2sckPin, mclkPin); return; @@ -574,6 +583,15 @@ class ES8388Source : public I2SSource { void initialize(int8_t i2swsPin, int8_t i2ssdPin, int8_t i2sckPin, int8_t mclkPin) { + if ((i2c_sda < 0) || (i2c_scl < 0)) { // check that global I2C pins are not "undefined" + ERRORSR_PRINTF("\nAR: invalid ES8388 global I2C pins: SDA=%d, SCL=%d\n", i2c_sda, i2c_scl); + return; + } + if (!pinManager.joinWire()) { // WLEDMM specific: start I2C with globally defined pins + ERRORSR_PRINTF("\nAR: failed to start I2C bus with SDA=%d, SCL=%d\n", i2c_sda, i2c_scl); + return; + } + if ((i2sckPin < 0) || (mclkPin < 0)) { ERRORSR_PRINTF("\nAR: invalid I2S pin: SCK=%d, MCLK=%d\n", i2sckPin, mclkPin); return;