I2C usermods: make sure that no Wire-begin(-1, -1) sneaks through

This commit is contained in:
Frank
2022-12-17 21:42:16 +01:00
parent dae6de76f1
commit 2c9cde4096
3 changed files with 3 additions and 0 deletions

View File

@@ -137,6 +137,7 @@ public:
if (!pinManager.allocateMultiplePins(pins, 2, po)) return;
#if defined(ARDUINO_ARCH_ESP32)
if (pins[1].pin < 0 || pins[0].pin < 0) { sensorFound=false; 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.

View File

@@ -22,6 +22,7 @@ class RTCUsermod : public Usermod {
#endif
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.

View File

@@ -139,6 +139,7 @@ class MPU6050Driver : public Usermod {
// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#if defined(ARDUINO_ARCH_ESP32)
if (pins[1].pin < 0 || pins[0].pin < 0) { enabled=false; dmpReady = false; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid and no "-1" sneaks trough
Wire.begin(pins[1].pin, pins[0].pin); // WLEDMM fix - need to use proper pins, in case that Wire was not started yet. Call will silently fail if Wire is initialized already.
#else
Wire.begin(); // WLEDMM - i2c pins on 8266 are fixed.