usermods: delay I2C pin allocation

delay i2C allocation / startup if global I2C pins = -1
This commit is contained in:
Frank
2022-12-18 23:12:38 +01:00
parent ef8da0d3e8
commit 18d649a3a5
3 changed files with 15 additions and 8 deletions

View File

@@ -17,12 +17,12 @@ class RTCUsermod : public Usermod {
void setup() {
PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } };
#if defined(ARDUINO_ARCH_ESP32) && defined(HW_PIN_SDA) && defined(HW_PIN_SCL)
if (pins[0].pin < 0) pins[0].pin = HW_PIN_SCL; //WLEDMM
if (pins[1].pin < 0) pins[1].pin = HW_PIN_SDA; //WLEDMM
//if (pins[0].pin < 0) pins[0].pin = HW_PIN_SCL; //WLEDMM
//if (pins[1].pin < 0) pins[1].pin = HW_PIN_SDA; //WLEDMM
#endif
if (pins[1].pin < 0 || pins[0].pin < 0) { disabled=true; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid and no "-1" sneaks trough
if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { disabled = true; return; }
#if defined(ARDUINO_ARCH_ESP32)
if (pins[1].pin < 0 || pins[0].pin < 0) { disabled=true; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid and no "-1" sneaks trough
Wire.begin(pins[1].pin, pins[0].pin); // WLEDMM this might silently fail, which is OK as it just means that I2C bus is already running.
#else
Wire.begin(); // WLEDMM - i2c pins on 8266 are fixed.