mirror of https://github.com/arendst/Tasmota.git
Fix ESP core 2.0.0 I2C exception
This commit is contained in:
parent
4c65de2561
commit
f8843acbde
|
@ -1997,7 +1997,24 @@ const uint8_t I2C_RETRY_COUNTER = 3;
|
||||||
uint32_t i2c_active[4] = { 0 };
|
uint32_t i2c_active[4] = { 0 };
|
||||||
uint32_t i2c_buffer = 0;
|
uint32_t i2c_buffer = 0;
|
||||||
|
|
||||||
|
void I2cBegin(int sda, int scl, uint32_t frequency = 100000);
|
||||||
|
void I2cBegin(int sda, int scl, uint32_t frequency) {
|
||||||
|
#ifdef ESP8266
|
||||||
|
Wire.begin(sda, scl);
|
||||||
|
#endif
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
|
bool result = Wire.begin(sda, scl, frequency);
|
||||||
|
AddLog(LOG_LEVEL_DEBUG, PSTR("I2C: Begin %d"), result);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef ESP32
|
||||||
|
void I2c2Begin(int sda, int scl, uint32_t frequency = 100000);
|
||||||
|
void I2c2Begin(int sda, int scl, uint32_t frequency) {
|
||||||
|
bool result = Wire1.begin(sda, scl, frequency);
|
||||||
|
AddLog(LOG_LEVEL_DEBUG, PSTR("I2C: Bus 2 begin %d"), result);
|
||||||
|
}
|
||||||
|
|
||||||
bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size, uint32_t bus = 0);
|
bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size, uint32_t bus = 0);
|
||||||
bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size, uint32_t bus)
|
bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size, uint32_t bus)
|
||||||
#else
|
#else
|
||||||
|
@ -2007,6 +2024,7 @@ bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size)
|
||||||
uint8_t retry = I2C_RETRY_COUNTER;
|
uint8_t retry = I2C_RETRY_COUNTER;
|
||||||
bool status = false;
|
bool status = false;
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
|
if (!TasmotaGlobal.i2c_enabled_2) { bus = 0; }
|
||||||
TwoWire & myWire = (bus == 0) ? Wire : Wire1;
|
TwoWire & myWire = (bus == 0) ? Wire : Wire1;
|
||||||
#else
|
#else
|
||||||
TwoWire & myWire = Wire;
|
TwoWire & myWire = Wire;
|
||||||
|
@ -2121,6 +2139,7 @@ bool I2cWrite(uint8_t addr, uint8_t reg, uint32_t val, uint8_t size)
|
||||||
uint8_t x = I2C_RETRY_COUNTER;
|
uint8_t x = I2C_RETRY_COUNTER;
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
|
if (!TasmotaGlobal.i2c_enabled_2) { bus = 0; }
|
||||||
TwoWire & myWire = (bus == 0) ? Wire : Wire1;
|
TwoWire & myWire = (bus == 0) ? Wire : Wire1;
|
||||||
#else
|
#else
|
||||||
TwoWire & myWire = Wire;
|
TwoWire & myWire = Wire;
|
||||||
|
@ -2191,6 +2210,7 @@ void I2cScan(uint32_t bus) {
|
||||||
Response_P(PSTR("{\"" D_CMND_I2CSCAN "\":\"" D_JSON_I2CSCAN_DEVICES_FOUND_AT));
|
Response_P(PSTR("{\"" D_CMND_I2CSCAN "\":\"" D_JSON_I2CSCAN_DEVICES_FOUND_AT));
|
||||||
for (address = 1; address <= 127; address++) {
|
for (address = 1; address <= 127; address++) {
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
|
if (!TasmotaGlobal.i2c_enabled_2) { bus = 0; }
|
||||||
TwoWire & myWire = (bus == 0) ? Wire : Wire1;
|
TwoWire & myWire = (bus == 0) ? Wire : Wire1;
|
||||||
#else
|
#else
|
||||||
TwoWire & myWire = Wire;
|
TwoWire & myWire = Wire;
|
||||||
|
@ -2269,6 +2289,7 @@ bool I2cSetDevice(uint32_t addr)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
|
if (!TasmotaGlobal.i2c_enabled_2) { bus = 0; }
|
||||||
TwoWire & myWire = (bus == 0) ? Wire : Wire1;
|
TwoWire & myWire = (bus == 0) ? Wire : Wire1;
|
||||||
#else
|
#else
|
||||||
TwoWire & myWire = Wire;
|
TwoWire & myWire = Wire;
|
||||||
|
|
|
@ -1901,12 +1901,12 @@ void GpioInit(void)
|
||||||
#ifdef USE_I2C
|
#ifdef USE_I2C
|
||||||
TasmotaGlobal.i2c_enabled = (PinUsed(GPIO_I2C_SCL) && PinUsed(GPIO_I2C_SDA));
|
TasmotaGlobal.i2c_enabled = (PinUsed(GPIO_I2C_SCL) && PinUsed(GPIO_I2C_SDA));
|
||||||
if (TasmotaGlobal.i2c_enabled) {
|
if (TasmotaGlobal.i2c_enabled) {
|
||||||
Wire.begin(Pin(GPIO_I2C_SDA), Pin(GPIO_I2C_SCL));
|
I2cBegin(Pin(GPIO_I2C_SDA), Pin(GPIO_I2C_SCL));
|
||||||
}
|
}
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
TasmotaGlobal.i2c_enabled_2 = (PinUsed(GPIO_I2C_SCL, 1) && PinUsed(GPIO_I2C_SDA, 1));
|
TasmotaGlobal.i2c_enabled_2 = (PinUsed(GPIO_I2C_SCL, 1) && PinUsed(GPIO_I2C_SDA, 1));
|
||||||
if (TasmotaGlobal.i2c_enabled_2) {
|
if (TasmotaGlobal.i2c_enabled_2) {
|
||||||
Wire1.begin(Pin(GPIO_I2C_SDA, 1), Pin(GPIO_I2C_SCL, 1));
|
I2c2Begin(Pin(GPIO_I2C_SDA, 1), Pin(GPIO_I2C_SCL, 1));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif // USE_I2C
|
#endif // USE_I2C
|
||||||
|
|
|
@ -31,6 +31,7 @@ TwoWire & getWire(bvm *vm) {
|
||||||
be_getmember(vm, 1, "bus");
|
be_getmember(vm, 1, "bus");
|
||||||
int32_t bus = be_toint(vm, -1); // bus is 1 or 2
|
int32_t bus = be_toint(vm, -1); // bus is 1 or 2
|
||||||
be_pop(vm, 1);
|
be_pop(vm, 1);
|
||||||
|
if (!TasmotaGlobal.i2c_enabled_2) { bus = 1; }
|
||||||
if (2 != bus) {
|
if (2 != bus) {
|
||||||
return Wire;
|
return Wire;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -161,11 +161,11 @@ uDisplay *udisp;
|
||||||
replacepin(&cp, Pin(GPIO_OLED_RESET));
|
replacepin(&cp, Pin(GPIO_OLED_RESET));
|
||||||
|
|
||||||
if (wire_n == 1) {
|
if (wire_n == 1) {
|
||||||
Wire.begin(sda, scl);
|
I2cBegin(sda, scl);
|
||||||
}
|
}
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
if (wire_n == 2) {
|
if (wire_n == 2) {
|
||||||
Wire1.begin(sda, scl);
|
I2c2Begin(sda, scl);
|
||||||
}
|
}
|
||||||
if (I2cSetDevice(i2caddr, wire_n - 1)) {
|
if (I2cSetDevice(i2caddr, wire_n - 1)) {
|
||||||
I2cSetActiveFound(i2caddr, "DSP-I2C", wire_n - 1);
|
I2cSetActiveFound(i2caddr, "DSP-I2C", wire_n - 1);
|
||||||
|
@ -257,11 +257,11 @@ uDisplay *udisp;
|
||||||
scl = replacepin(&cp, Pin(GPIO_I2C_SCL, wire_n));
|
scl = replacepin(&cp, Pin(GPIO_I2C_SCL, wire_n));
|
||||||
sda = replacepin(&cp, Pin(GPIO_I2C_SDA, wire_n));
|
sda = replacepin(&cp, Pin(GPIO_I2C_SDA, wire_n));
|
||||||
if (wire_n == 0) {
|
if (wire_n == 0) {
|
||||||
Wire.begin(sda, scl);
|
I2cBegin(sda, scl);
|
||||||
}
|
}
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
if (wire_n == 1) {
|
if (wire_n == 1) {
|
||||||
Wire1.begin(sda, scl, 400000);
|
I2c2Begin(sda, scl, 400000);
|
||||||
}
|
}
|
||||||
if (I2cSetDevice(i2caddr, wire_n)) {
|
if (I2cSetDevice(i2caddr, wire_n)) {
|
||||||
I2cSetActiveFound(i2caddr, "FT5206", wire_n);
|
I2cSetActiveFound(i2caddr, "FT5206", wire_n);
|
||||||
|
|
|
@ -165,7 +165,7 @@ void ShtDetect(void)
|
||||||
sht_type = 1;
|
sht_type = 1;
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_I2C D_SHT1X_FOUND));
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_I2C D_SHT1X_FOUND));
|
||||||
} else {
|
} else {
|
||||||
Wire.begin(sht_sda_pin, sht_scl_pin);
|
I2cBegin(sht_sda_pin, sht_scl_pin);
|
||||||
sht_type = 0;
|
sht_type = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue