From 2c9cde40962274f407f70d295e6b11a0dab1be4c Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 17 Dec 2022 21:42:16 +0100 Subject: [PATCH] I2C usermods: make sure that no Wire-begin(-1, -1) sneaks through --- usermods/BH1750_v2/usermod_bh1750.h | 1 + usermods/RTC/usermod_rtc.h | 1 + usermods/mpu6050_imu/usermod_mpu6050_imu.h | 1 + 3 files changed, 3 insertions(+) diff --git a/usermods/BH1750_v2/usermod_bh1750.h b/usermods/BH1750_v2/usermod_bh1750.h index 57b8a8fb..fc9097e8 100644 --- a/usermods/BH1750_v2/usermod_bh1750.h +++ b/usermods/BH1750_v2/usermod_bh1750.h @@ -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. diff --git a/usermods/RTC/usermod_rtc.h b/usermods/RTC/usermod_rtc.h index c520d3f3..4de535db 100644 --- a/usermods/RTC/usermod_rtc.h +++ b/usermods/RTC/usermod_rtc.h @@ -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. diff --git a/usermods/mpu6050_imu/usermod_mpu6050_imu.h b/usermods/mpu6050_imu/usermod_mpu6050_imu.h index 8be53666..c8e6b96f 100644 --- a/usermods/mpu6050_imu/usermod_mpu6050_imu.h +++ b/usermods/mpu6050_imu/usermod_mpu6050_imu.h @@ -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.