I2C: allow any GPIO on 8266 (experimental)

as it turns out, also on 8266 any pin can be assigned to I2C. Only SPI pins are fixed, and GPIO16 should not be used as it does not support interrupts.
This commit is contained in:
Frank
2023-01-15 22:13:46 +01:00
parent 12cd6a2738
commit a320068bbe
4 changed files with 17 additions and 21 deletions

View File

@@ -310,6 +310,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
Wire.setPins(i2c_sda, i2c_scl); // this will fail if Wire is initilised (Wire.begin() called prior)
#endif
// Wire.begin(); // WLEDMM moved into pinManager
Serial.printf("pinmgr success for global i2c %d %d\n", i2c_sda, i2c_scl);
} else {
Serial.printf("pinmgr not success for global i2c %d %d\n", i2c_sda, i2c_scl);
}
@@ -324,6 +325,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
#else
SPI.begin();
#endif
Serial.printf("pinmgr success for global spi %d %d %d\n", spi_mosi, spi_miso, spi_sclk);
} else {
Serial.printf("pinmgr not success for global spi %d %d %d\n", spi_mosi, spi_miso, spi_sclk);
}

View File

@@ -518,16 +518,7 @@ bool PinManagerClass::isPinAllocated(byte gpio, PinOwner tag)
//
bool PinManagerClass::joinWire() { // shortcut in case no parameters provided
#ifdef ARDUINO_ARCH_ESP32
// ESP32 - i2c pins can be mapped to any GPIO
return joinWire(i2c_sda, i2c_scl);
#else
// ESP8266: I2C pins are fixed
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
}
bool PinManagerClass::joinWire(int8_t pinSDA, int8_t pinSCL) {
@@ -570,19 +561,22 @@ bool PinManagerClass::joinWire(int8_t pinSDA, int8_t pinSCL) {
bool wireIsOK = true;
#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)
#else // 8266 - I2C pins are fixed
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_PRINTF("%d, SCL=%d !\n",4, 5);
return(false);
}
#else // 8266 - I2C pins are fixed -> actually they are not.
//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_PRINTF("%d, SCL=%d !\n",4, 5);
// return(false);
//}
#endif
if (wireIsOK == false) {
USER_PRINTLN(F("PIN Manager: warning - wire.setPins failed!"));
}
//wireIsOK = Wire.begin(); // this will fail if wire is already running
Wire.begin(); // returns void on 8266
#ifdef ARDUINO_ARCH_ESP32
wireIsOK = Wire.begin(pinSDA, pinSCL); // this will fail if wire is already running
#else
Wire.begin(pinSDA, pinSCL); // returns void on 8266
#endif
if (wireIsOK == false) {
USER_PRINTLN(F("PIN Manager: warning - wire.begin failed!"));

View File

@@ -532,10 +532,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
}
#ifdef ESP8266
// cannot change pins on ESP8266
// cannot change pins on ESP8266 --> actually we can
// WLEDMM: HW_PIN_xx could be set to -1 --> use pins as defined by the framework! SDA = 4, SCL = 5
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;
//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
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)) {

View File

@@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2301150
#define VERSION 2301151
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG