I2C pin settings bugfix (8266)
* It was not possible any more to set I2C pins back to "-1", to disable I2C. This fixes the problem. * HW_PIN_SDA / HW_PIN_SCL may contain "-1" --> use PIN numbers directly on 8266 (I2C pins cannot be changed any way on 8266)
This commit is contained in:
@@ -523,7 +523,10 @@ bool PinManagerClass::joinWire() { // shortcut in case no parameters provided
|
|||||||
return joinWire(i2c_sda, i2c_scl);
|
return joinWire(i2c_sda, i2c_scl);
|
||||||
#else
|
#else
|
||||||
// ESP8266: I2C pins are fixed
|
// ESP8266: I2C pins are fixed
|
||||||
return joinWire(HW_PIN_SDA, HW_PIN_SCL);
|
if ((i2c_sda < 0) || (i2c_scl < 0))
|
||||||
|
return joinWire(i2c_sda, i2c_scl); // special case: -1 = disable i2c
|
||||||
|
else
|
||||||
|
return joinWire(4, 5); // normal case - use HW pins -> SDA = 4, SCL = 5
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,9 +571,10 @@ bool PinManagerClass::joinWire(int8_t pinSDA, int8_t pinSCL) {
|
|||||||
#ifdef ARDUINO_ARCH_ESP32 // ESP32 - i2c pins can be mapped to any GPIO
|
#ifdef ARDUINO_ARCH_ESP32 // ESP32 - i2c pins can be mapped to any GPIO
|
||||||
wireIsOK = Wire.setPins(pinSDA, pinSCL); // this will fail if Wire is initialised already (i.e. Wire.begin() called prior)
|
wireIsOK = Wire.setPins(pinSDA, pinSCL); // this will fail if Wire is initialised already (i.e. Wire.begin() called prior)
|
||||||
#else // 8266 - I2C pins are fixed
|
#else // 8266 - I2C pins are fixed
|
||||||
if((pinSDA != HW_PIN_SDA) || (pinSCL != HW_PIN_SCL)) {
|
if((pinSDA != 4) || (pinSCL != 5)) { // fixed PINS: SDA = 4, SCL = 5
|
||||||
DEBUG_PRINT(F("PIN Manager: warning ESP8266 I2C pins are fixed. please use SDA="));
|
DEBUG_PRINT(F("PIN Manager: warning ESP8266 I2C pins are fixed. please use SDA="));
|
||||||
DEBUG_PRINTF("%d, SCL=%d !\n",HW_PIN_SDA, HW_PIN_SCL);
|
DEBUG_PRINTF("%d, SCL=%d !\n",4, 5);
|
||||||
|
return(false);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (wireIsOK == false) {
|
if (wireIsOK == false) {
|
||||||
@@ -583,7 +587,9 @@ bool PinManagerClass::joinWire(int8_t pinSDA, int8_t pinSCL) {
|
|||||||
if (wireIsOK == false) {
|
if (wireIsOK == false) {
|
||||||
USER_PRINTLN(F("PIN Manager: warning - wire.begin failed!"));
|
USER_PRINTLN(F("PIN Manager: warning - wire.begin failed!"));
|
||||||
} else {
|
} else {
|
||||||
USER_PRINTLN(F("PIN Manager: wire.begin successfull."));
|
USER_PRINT(F("PIN Manager: wire.begin successfull! "));
|
||||||
|
USER_PRINT(F("I2C bus is active. SDA="));
|
||||||
|
USER_PRINTF("%d SCL=%d.\n", pinSDA, pinSCL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32S3
|
#ifdef ARDUINO_ARCH_ESP32S3
|
||||||
|
|||||||
@@ -533,8 +533,9 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
// cannot change pins on ESP8266
|
// cannot change pins on ESP8266
|
||||||
if (hw_sda_pin >= 0 && hw_sda_pin != HW_PIN_SDA) hw_sda_pin = HW_PIN_SDA;
|
// WLEDMM: HW_PIN_xx could be set to -1 --> use pins as defined by the framework! SDA = 4, SCL = 5
|
||||||
if (hw_scl_pin >= 0 && hw_scl_pin != HW_PIN_SCL) hw_scl_pin = HW_PIN_SCL;
|
if (hw_sda_pin >= 0 && hw_sda_pin != 4) hw_sda_pin = 4;
|
||||||
|
if (hw_scl_pin >= 0 && hw_scl_pin != 5) hw_scl_pin = 5;
|
||||||
#endif
|
#endif
|
||||||
PinManagerPinType i2c[2] = { { hw_sda_pin, true }, { hw_scl_pin, true } };
|
PinManagerPinType i2c[2] = { { hw_sda_pin, true }, { hw_scl_pin, true } };
|
||||||
if (hw_sda_pin >= 0 && hw_scl_pin >= 0 && pinManager.allocateMultiplePins(i2c, 2, PinOwner::HW_I2C)) {
|
if (hw_sda_pin >= 0 && hw_scl_pin >= 0 && pinManager.allocateMultiplePins(i2c, 2, PinOwner::HW_I2C)) {
|
||||||
@@ -546,6 +547,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
// Wire.begin(); // WLEDMM moved into pinManager
|
// Wire.begin(); // WLEDMM moved into pinManager
|
||||||
} else {
|
} else {
|
||||||
// there is no Wire.end()
|
// there is no Wire.end()
|
||||||
|
if (hw_sda_pin < 0 || hw_scl_pin < 0) { // WLEDMM bugfix allow pin = -1
|
||||||
|
i2c_sda = -1;
|
||||||
|
i2c_scl = -1;
|
||||||
|
}
|
||||||
DEBUG_PRINTLN(F("Could not allocate I2C pins."));
|
DEBUG_PRINTLN(F("Could not allocate I2C pins."));
|
||||||
uint8_t i2c[2] = { static_cast<uint8_t>(i2c_scl), static_cast<uint8_t>(i2c_sda) };
|
uint8_t i2c[2] = { static_cast<uint8_t>(i2c_scl), static_cast<uint8_t>(i2c_sda) };
|
||||||
pinManager.deallocateMultiplePins(i2c, 2, PinOwner::HW_I2C); // just in case deallocation of old pins
|
pinManager.deallocateMultiplePins(i2c, 2, PinOwner::HW_I2C); // just in case deallocation of old pins
|
||||||
@@ -572,6 +577,11 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
//SPI.end();
|
//SPI.end();
|
||||||
|
if (hw_mosi_pin < 0 || hw_sclk_pin < 0) { // WLEDMM bugfix allow pin = -1
|
||||||
|
spi_mosi = hw_mosi_pin;
|
||||||
|
spi_miso = hw_miso_pin;
|
||||||
|
spi_sclk = hw_sclk_pin;
|
||||||
|
}
|
||||||
DEBUG_PRINTLN(F("Could not allocate SPI pins."));
|
DEBUG_PRINTLN(F("Could not allocate SPI pins."));
|
||||||
uint8_t spi[3] = { static_cast<uint8_t>(spi_mosi), static_cast<uint8_t>(spi_miso), static_cast<uint8_t>(spi_sclk) };
|
uint8_t spi[3] = { static_cast<uint8_t>(spi_mosi), static_cast<uint8_t>(spi_miso), static_cast<uint8_t>(spi_sclk) };
|
||||||
pinManager.deallocateMultiplePins(spi, 3, PinOwner::HW_SPI); // just in case deallocation of old pins
|
pinManager.deallocateMultiplePins(spi, 3, PinOwner::HW_SPI); // just in case deallocation of old pins
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 2301111
|
#define VERSION 2301112
|
||||||
|
|
||||||
//uncomment this if you have a "my_config.h" file you'd like to use
|
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||||
//#define WLED_USE_MY_CONFIG
|
//#define WLED_USE_MY_CONFIG
|
||||||
|
|||||||
Reference in New Issue
Block a user