mirror of https://github.com/arendst/Tasmota.git
ESP32 support for secondary I2C controller
This commit is contained in:
parent
e7cbd4f001
commit
0475212b54
|
@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
|
|||
- Crash protection in ext_vnsprintf_P (#11202)
|
||||
- Extent compile time SetOptions support (#11204)
|
||||
- ESP32 Extent BLE (#11212)
|
||||
- ESP32 support for secondary I2C controller
|
||||
|
||||
### Changed
|
||||
- ESP32 core library from v1.0.5-rc6 to v1.0.5
|
||||
|
|
|
@ -1969,7 +1969,8 @@ int8_t I2cWriteBuffer(uint8_t addr, uint8_t reg, uint8_t *reg_data, uint16_t len
|
|||
return 0;
|
||||
}
|
||||
|
||||
void I2cScan(char *devs, unsigned int devs_len)
|
||||
void I2cScan(char *devs, unsigned int devs_len, uint32_t bus = 0);
|
||||
void I2cScan(char *devs, unsigned int devs_len, uint32_t bus)
|
||||
{
|
||||
// Return error codes defined in twi.h and core_esp8266_si2c.c
|
||||
// I2C_OK 0
|
||||
|
@ -1984,8 +1985,13 @@ void I2cScan(char *devs, unsigned int devs_len)
|
|||
|
||||
snprintf_P(devs, devs_len, PSTR("{\"" D_CMND_I2CSCAN "\":\"" D_JSON_I2CSCAN_DEVICES_FOUND_AT));
|
||||
for (address = 1; address <= 127; address++) {
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
#ifdef ESP32
|
||||
TwoWire & myWire = (bus == 0) ? Wire : Wire1;
|
||||
#else
|
||||
TwoWire & myWire = Wire;
|
||||
#endif
|
||||
myWire.beginTransmission(address);
|
||||
error = myWire.endTransmission();
|
||||
if (0 == error) {
|
||||
any = 1;
|
||||
snprintf_P(devs, devs_len, PSTR("%s 0x%02x"), devs, address);
|
||||
|
|
|
@ -2071,9 +2071,14 @@ void CmndWifiPower(void)
|
|||
#ifdef USE_I2C
|
||||
void CmndI2cScan(void)
|
||||
{
|
||||
if (TasmotaGlobal.i2c_enabled) {
|
||||
if ((1 == XdrvMailbox.index) && (TasmotaGlobal.i2c_enabled)) {
|
||||
I2cScan(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data));
|
||||
}
|
||||
#ifdef ESP32
|
||||
if ((2 == XdrvMailbox.index) && (TasmotaGlobal.i2c_enabled_2)) {
|
||||
I2cScan(TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void CmndI2cDriver(void)
|
||||
|
|
|
@ -1742,6 +1742,12 @@ void GpioInit(void)
|
|||
if (TasmotaGlobal.i2c_enabled) {
|
||||
Wire.begin(Pin(GPIO_I2C_SDA), Pin(GPIO_I2C_SCL));
|
||||
}
|
||||
#ifdef ESP32
|
||||
TasmotaGlobal.i2c_enabled_2 = (PinUsed(GPIO_I2C_SCL, 1) && PinUsed(GPIO_I2C_SDA, 1));
|
||||
if (TasmotaGlobal.i2c_enabled_2) {
|
||||
Wire1.begin(Pin(GPIO_I2C_SDA, 1), Pin(GPIO_I2C_SCL, 1));
|
||||
}
|
||||
#endif
|
||||
#endif // USE_I2C
|
||||
|
||||
TasmotaGlobal.devices_present = 0;
|
||||
|
|
|
@ -84,6 +84,12 @@ const uint8_t MAX_PCF8574 = 4; // Max number of PCF8574 devices
|
|||
const uint8_t MAX_RULE_SETS = 3; // Max number of rule sets of size 512 characters
|
||||
const uint16_t MAX_RULE_SIZE = 512; // Max number of characters in rules
|
||||
|
||||
#ifdef ESP32
|
||||
const uint8_t MAX_I2C = 2; // Max number of I2C controllers (ESP32 = 2)
|
||||
#else
|
||||
const uint8_t MAX_I2C = 0; // Max number of I2C controllers (ESP8266 = 0, no choice)
|
||||
#endif
|
||||
|
||||
// Changes to the following MAX_ defines need to be in line with enum SettingsTextIndex
|
||||
const uint8_t MAX_MQTT_PREFIXES = 3; // Max number of MQTT prefixes (cmnd, stat, tele)
|
||||
const uint8_t MAX_SSIDS = 2; // Max number of SSIDs
|
||||
|
|
|
@ -141,6 +141,9 @@ struct {
|
|||
bool blinkstate; // LED state
|
||||
bool pwm_present; // Any PWM channel configured with SetOption15 0
|
||||
bool i2c_enabled; // I2C configured
|
||||
#ifdef ESP32
|
||||
bool i2c_enabled_2; // I2C configured, second controller on ESP32, Wire1
|
||||
#endif
|
||||
bool ntp_force_sync; // Force NTP sync
|
||||
bool skip_light_fade; // Temporarily skip light fading
|
||||
bool restart_halt; // Do not restart but stay in wait loop
|
||||
|
|
|
@ -386,8 +386,8 @@ const uint16_t kGpioNiceList[] PROGMEM = {
|
|||
\*-------------------------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef USE_I2C
|
||||
AGPIO(GPIO_I2C_SCL), // I2C SCL
|
||||
AGPIO(GPIO_I2C_SDA), // I2C SDA
|
||||
AGPIO(GPIO_I2C_SCL) + MAX_I2C, // I2C SCL
|
||||
AGPIO(GPIO_I2C_SDA) + MAX_I2C, // I2C SDA
|
||||
#endif
|
||||
|
||||
#ifdef USE_SPI
|
||||
|
|
Loading…
Reference in New Issue