From 2b89b7a134ebce268a9815e794dc683b4a3fd853 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 11 Mar 2023 15:52:02 +0100 Subject: [PATCH] Fix init order of device drivers (#18124) --- tasmota/include/tasmota.h | 2 +- tasmota/tasmota.ino | 2 +- tasmota/tasmota_support/support_tasmota.ino | 31 +++++++++++-------- .../xdrv_28_pcf8574_v2.ino | 2 +- .../tasmota_xdrv_driver/xdrv_56_rtc_chips.ino | 2 +- .../tasmota_xdrv_driver/xdrv_66_tm1638.ino | 2 +- .../tasmota_xdrv_driver/xdrv_67_mcp23xxx.ino | 2 +- .../xdrv_88_esp32_shelly_pro_v2.ino | 2 +- .../tasmota_xsns_sensor/xsns_02_analog.ino | 2 +- tasmota/tasmota_xsns_sensor/xsns_04_snfsc.ino | 3 ++ 10 files changed, 29 insertions(+), 21 deletions(-) diff --git a/tasmota/include/tasmota.h b/tasmota/include/tasmota.h index 19d098a26..7cf0af7d3 100644 --- a/tasmota/include/tasmota.h +++ b/tasmota/include/tasmota.h @@ -387,7 +387,7 @@ enum LightSubtypes { LST_NONE, LST_SINGLE, LST_COLDWARM, LST_RGB, LST_RGBW, LS enum LightTypes { LT_BASIC, LT_PWM1, LT_PWM2, LT_PWM3, LT_PWM4, LT_PWM5, LT_PWM6, LT_PWM7, LT_NU8, LT_SERIAL1, LT_SERIAL2, LT_RGB, LT_RGBW, LT_RGBWC, LT_NU14, LT_NU15 }; // Do not insert new fields -enum XsnsFunctions { FUNC_SETTINGS_OVERRIDE, FUNC_I2C_INIT, FUNC_PRE_INIT, FUNC_INIT, +enum XsnsFunctions { FUNC_SETTINGS_OVERRIDE, FUNC_SETUP_RING1, FUNC_SETUP_RING2, FUNC_PRE_INIT, FUNC_INIT, FUNC_LOOP, FUNC_SLEEP_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_200_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_SECOND, FUNC_SAVE_SETTINGS, FUNC_SAVE_AT_MIDNIGHT, FUNC_SAVE_BEFORE_RESTART, FUNC_INTERRUPT_STOP, FUNC_INTERRUPT_START, FUNC_AFTER_TELEPERIOD, FUNC_JSON_APPEND, FUNC_WEB_SENSOR, FUNC_WEB_COL_SENSOR, diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index b0772932b..85c0f0d72 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -615,7 +615,7 @@ void setup(void) { snprintf_P(TasmotaGlobal.mqtt_topic, sizeof(TasmotaGlobal.mqtt_topic), ResolveToken(TasmotaGlobal.mqtt_topic).c_str()); RtcInit(); - GpioInit(); // FUNC_I2C_INIT -> FUNC_MODULE_INIT -> FUNC_LED_LINK + GpioInit(); // FUNC_SETUP_RING1 -> FUNC_SETUP_RING2 -> FUNC_MODULE_INIT -> FUNC_LED_LINK ButtonInit(); // FUNC_ADD_BUTTON SwitchInit(); // FUNC_ADD_SWITCH #ifdef ROTARY_V1 diff --git a/tasmota/tasmota_support/support_tasmota.ino b/tasmota/tasmota_support/support_tasmota.ino index 21da21b1f..e22ad5cba 100644 --- a/tasmota/tasmota_support/support_tasmota.ino +++ b/tasmota/tasmota_support/support_tasmota.ino @@ -556,6 +556,18 @@ void SetLedLink(uint32_t state) { #endif // USE_PWM_DIMMER } +void DebugLed(uint32_t mode) { + static bool toggle = false; + + if (PinUsed(GPIO_LEDLNK)) { + if (2 == mode) { + toggle != toggle; + mode = toggle; + } + digitalWrite(Pin(GPIO_LEDLNK), (TasmotaGlobal.ledlnk_inverted) ? !mode : mode); + } +} + void SetPulseTimer(uint32_t index, uint32_t time) { TasmotaGlobal.pulse_timer[index] = (time > 111) ? millis() + (1000 * (time - 100)) : (time > 0) ? millis() + (100 * time) : 0L; @@ -2193,8 +2205,6 @@ void GpioInit(void) #endif #endif // USE_I2C - XdrvCall(FUNC_I2C_INIT); // Init RTC - TasmotaGlobal.devices_present = 0; uint32_t bi_device = 0; for (uint32_t i = 0; i < MAX_RELAYS; i++) { @@ -2212,31 +2222,26 @@ void GpioInit(void) } } + XdrvCall(FUNC_SETUP_RING1); // Setup RTC hardware + XsnsXdrvCall(FUNC_SETUP_RING2); // Setup hardware supporting virtual switches/buttons/relays + TasmotaGlobal.light_type = LT_BASIC; // Use basic PWM control if SetOption15 = 0 - XsnsCall(FUNC_MODULE_INIT); - - if (XdrvCall(FUNC_MODULE_INIT)) { + if (XdrvCall(FUNC_MODULE_INIT)) { // Init and claim single module (like tuya, armtronix, ifan, light) // Serviced } #ifdef ESP8266 else if (YTF_IR_BRIDGE == TasmotaGlobal.module_type) { ClaimSerial(); // Stop serial loopback mode -// TasmotaGlobal.devices_present = 1; } else if (SONOFF_DUAL == TasmotaGlobal.module_type) { - TasmotaGlobal.devices_present = 2; + UpdateDevicesPresent(2); SetSerial(19200, TS_SERIAL_8N1); } else if (CH4 == TasmotaGlobal.module_type) { - TasmotaGlobal.devices_present = 4; + UpdateDevicesPresent(4); SetSerial(19200, TS_SERIAL_8N1); } -#ifdef USE_SONOFF_SC - else if (SONOFF_SC == TasmotaGlobal.module_type) { - SetSerial(19200, TS_SERIAL_8N1); - } -#endif // USE_SONOFF_SC #endif // ESP8266 GpioInitPwm(); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_28_pcf8574_v2.ino b/tasmota/tasmota_xdrv_driver/xdrv_28_pcf8574_v2.ino index 0ccaef4ab..898849613 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_28_pcf8574_v2.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_28_pcf8574_v2.ino @@ -644,7 +644,7 @@ bool Xdrv28(uint32_t function) { bool result = false; - if (FUNC_MODULE_INIT == function) { + if (FUNC_SETUP_RING2 == function) { Pcf8574ModuleInit(); } else if (1 == Pcf8574.mode) { switch (function) { diff --git a/tasmota/tasmota_xdrv_driver/xdrv_56_rtc_chips.ino b/tasmota/tasmota_xdrv_driver/xdrv_56_rtc_chips.ino index b68c96c6d..1b4e4f598 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_56_rtc_chips.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_56_rtc_chips.ino @@ -504,7 +504,7 @@ bool Xdrv56(uint32_t function) { } #endif // RTC_NTP_SERVER - if (FUNC_I2C_INIT == function) { + if (FUNC_SETUP_RING1 == function) { RtcChipDetect(); } else if (RtcChip.detected) { diff --git a/tasmota/tasmota_xdrv_driver/xdrv_66_tm1638.ino b/tasmota/tasmota_xdrv_driver/xdrv_66_tm1638.ino index 4065b212c..e7d5f5a63 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_66_tm1638.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_66_tm1638.ino @@ -215,7 +215,7 @@ bool TmAddKey(void) { bool Xdrv66(uint32_t function) { bool result = false; - if (FUNC_MODULE_INIT == function) { + if (FUNC_SETUP_RING2 == function) { TmInit(); } else if (Tm1638.detected) { switch (function) { diff --git a/tasmota/tasmota_xdrv_driver/xdrv_67_mcp23xxx.ino b/tasmota/tasmota_xdrv_driver/xdrv_67_mcp23xxx.ino index 0f0bf34b3..32e7e7fae 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_67_mcp23xxx.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_67_mcp23xxx.ino @@ -783,7 +783,7 @@ bool Xdrv67(uint32_t function) { bool result = false; - if (FUNC_MODULE_INIT == function) { + if (FUNC_SETUP_RING2 == function) { MCP23xModuleInit(); } else if (Mcp23x.max_devices) { switch (function) { diff --git a/tasmota/tasmota_xdrv_driver/xdrv_88_esp32_shelly_pro_v2.ino b/tasmota/tasmota_xdrv_driver/xdrv_88_esp32_shelly_pro_v2.ino index d9f7dd4a0..f7bea6ca5 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_88_esp32_shelly_pro_v2.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_88_esp32_shelly_pro_v2.ino @@ -484,7 +484,7 @@ void ShellyProLedLinkWifiOff(void) { bool Xdrv88(uint32_t function) { bool result = false; - if (FUNC_MODULE_INIT == function) { + if (FUNC_SETUP_RING2 == function) { ShellyProPreInit(); } else if (SPro.detected) { switch (function) { diff --git a/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino b/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino index afccacbc8..acc697e81 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino @@ -851,7 +851,7 @@ bool Xsns02(uint32_t function) { case FUNC_COMMAND: result = DecodeCommand(kAdcCommands, AdcCommand); break; - case FUNC_MODULE_INIT: + case FUNC_SETUP_RING2: AdcInit(); break; default: diff --git a/tasmota/tasmota_xsns_sensor/xsns_04_snfsc.ino b/tasmota/tasmota_xsns_sensor/xsns_04_snfsc.ino index 16bc77212..46aaf598b 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_04_snfsc.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_04_snfsc.ino @@ -165,6 +165,9 @@ bool Xsns04(uint32_t function) case FUNC_INIT: SonoffScInit(); break; + case FUNC_MODULE_INIT: + SetSerial(19200, TS_SERIAL_8N1); + break; } } return result;