Adjust some usermods to use global I2C
* usermods only need to to `if (!pinManager.joinWire()) return;` * joinWire will * * check if global I2C are defined - return false if not defined * * aloocate HW_I2C pins - return false on error * * call Wire.begin() if needed.
This commit is contained in:
@@ -17,11 +17,18 @@ class RTCUsermod : public Usermod {
|
||||
void setup() {
|
||||
PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } };
|
||||
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; }
|
||||
|
||||
// WLEDMM join hardware I2C
|
||||
if (!pinManager.joinWire()) { // WLEDMM - this allocates global I2C pins, then starts Wire - if not started previously
|
||||
disabled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
//if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { disabled = true; return; }
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
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.
|
||||
//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.
|
||||
//Wire.begin(); // WLEDMM - i2c pins on 8266 are fixed.
|
||||
#endif
|
||||
|
||||
RTC.begin();
|
||||
|
||||
Reference in New Issue
Block a user