Skip to content

Commit 18d649a

Browse files
committed
usermods: delay I2C pin allocation
delay i2C allocation / startup if global I2C pins = -1
1 parent ef8da0d commit 18d649a

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

usermods/BH1750_v2/usermod_bh1750.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class Usermod_BH1750 : public Usermod
6666
#define HW_PIN_SCL 5
6767
#define HW_PIN_SDA 4
6868
#endif
69-
int8_t ioPin[2] = {HW_PIN_SCL, HW_PIN_SDA}; // I2C pins: SCL, SDA...defaults to Arch hardware pins but overridden at setup()
69+
//int8_t ioPin[2] = {HW_PIN_SCL, HW_PIN_SDA}; // I2C pins: SCL, SDA...defaults to Arch hardware pins but overridden at setup()
70+
int8_t ioPin[2] = {-1, -1}; // WLEDMM - I2C pins: wait until hw pins get allocated
7071
bool initDone = false;
7172
bool sensorFound = false;
7273

@@ -137,7 +138,7 @@ class Usermod_BH1750 : public Usermod
137138
if (!pinManager.allocateMultiplePins(pins, 2, po)) return;
138139

139140
#if defined(ARDUINO_ARCH_ESP32)
140-
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
141+
if (pins[1].pin < 0 || pins[0].pin < 0) { sensorFound=false; enabled=false; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid and no "-1" sneaks trough
141142
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.
142143
#else
143144
Wire.begin(); // WLEDMM - i2c pins on 8266 are fixed.
@@ -181,7 +182,7 @@ class Usermod_BH1750 : public Usermod
181182
mqttInitialized = true;
182183
}
183184
mqtt->publish(mqttLuminanceTopic.c_str(), 0, true, String(lux).c_str());
184-
DEBUG_PRINTLN(F("Brightness: ") + String(lux) + F("lx"));
185+
DEBUG_PRINTLN(String("Brightness: ") + String(lux) + String("lx")); // WLEDMM fix compilation warning
185186
}
186187
else
187188
{

usermods/RTC/usermod_rtc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class RTCUsermod : public Usermod {
1717
void setup() {
1818
PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } };
1919
#if defined(ARDUINO_ARCH_ESP32) && defined(HW_PIN_SDA) && defined(HW_PIN_SCL)
20-
if (pins[0].pin < 0) pins[0].pin = HW_PIN_SCL; //WLEDMM
21-
if (pins[1].pin < 0) pins[1].pin = HW_PIN_SDA; //WLEDMM
20+
//if (pins[0].pin < 0) pins[0].pin = HW_PIN_SCL; //WLEDMM
21+
//if (pins[1].pin < 0) pins[1].pin = HW_PIN_SDA; //WLEDMM
2222
#endif
23+
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
2324
if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { disabled = true; return; }
2425
#if defined(ARDUINO_ARCH_ESP32)
25-
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
2626
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.
2727
#else
2828
Wire.begin(); // WLEDMM - i2c pins on 8266 are fixed.

usermods/mpu6050_imu/usermod_mpu6050_imu.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,15 @@ class MPU6050Driver : public Usermod {
117117
#endif
118118

119119
void setup() {
120-
DEBUG_PRINT_IMULN("mpu setup");
121120
// WLEDMM begin
121+
USER_PRINTLN(F("mpu setup"));
122+
#if 0 // WLEDMM: delay I2C pin alloc
122123
int8_t hw_scl = i2c_scl<0 ? HW_PIN_SCL : i2c_scl;
123124
int8_t hw_sda = i2c_sda<0 ? HW_PIN_SDA : i2c_sda;
125+
#else
126+
int8_t hw_scl = i2c_scl;
127+
int8_t hw_sda = i2c_sda;
128+
#endif
124129

125130
PinManagerPinType pins[2] = { { hw_scl, true }, { hw_sda, true } };
126131
if ((hw_scl < 0) || (hw_sda < 0)) {
@@ -129,6 +134,8 @@ class MPU6050Driver : public Usermod {
129134
//return;
130135
}
131136

137+
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
138+
132139
if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) {
133140
enabled = false;
134141
USER_PRINTF("mpu6050: failed to allocate I2C sda=%d scl=%d\n", hw_sda, hw_scl);
@@ -139,7 +146,6 @@ class MPU6050Driver : public Usermod {
139146
// join I2C bus (I2Cdev library doesn't do this automatically)
140147
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
141148
#if defined(ARDUINO_ARCH_ESP32)
142-
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
143149
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.
144150
#else
145151
Wire.begin(); // WLEDMM - i2c pins on 8266 are fixed.

0 commit comments

Comments
 (0)