diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 703565959..b5270f0d2 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -20,14 +20,14 @@ // Location specific includes #ifndef ESP32_STAGE // ESP32 Stage has no core_version.h file. Disable include via PlatformIO Option #include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_7_1) -#endif // ESP32_STAGE +#endif // ESP32_STAGE #include "include/tasmota_compat.h" #include "include/tasmota_version.h" // Tasmota version information #include "include/tasmota.h" // Enumeration used in my_user_config.h #include "my_user_config.h" // Fixed user configurable options #ifdef USE_TLS - #include // We need to include before "tasmota_globals.h" to take precedence over the BearSSL version in Arduino -#endif // USE_TLS +#include // We need to include before "tasmota_globals.h" to take precedence over the BearSSL version in Arduino +#endif // USE_TLS #include "include/tasmota_globals.h" // Function prototypes and global configuration #include "include/i18n.h" // Language support configured by my_user_config.h #include "include/tasmota_template.h" // Hardware configuration @@ -36,7 +36,7 @@ // If IPv6 is not support by the underlying esp-idf, disable it // ------------------------------------------------------------------------------------------ #if !LWIP_IPV6 - #undef USE_IPV6 +#undef USE_IPV6 #endif // Libraries @@ -44,10 +44,10 @@ #include // Ota #include // Ota #ifdef ESP32 - #ifdef USE_TLS - #include "HTTPUpdateLight.h" // Ota over HTTPS for ESP32 - #endif // USE_TLS -#endif +#ifdef USE_TLS +#include "HTTPUpdateLight.h" // Ota over HTTPS for ESP32 +#endif // USE_TLS +#endif // ESP32 #include // Webserver, Updater #include #include @@ -56,20 +56,18 @@ #include #ifdef ESP8266 #ifdef USE_ARDUINO_OTA - #include // Arduino OTA - #ifndef USE_DISCOVERY - #define USE_DISCOVERY - #endif +#include // Arduino OTA +#ifndef USE_DISCOVERY +#define USE_DISCOVERY +#endif // USE_DISCOVERY #endif // USE_ARDUINO_OTA #endif // ESP8266 #ifdef USE_DISCOVERY - #include // MQTT, Webserver, Arduino OTA +#include // MQTT, Webserver, Arduino OTA #endif // USE_DISCOVERY -//#ifdef USE_I2C - #include // I2C support library -//#endif // USE_I2C +#include // I2C support library #ifdef USE_SPI - #include // SPI support, TFT, SDcard +#include // SPI support, TFT, SDcard #endif // USE_SPI #ifdef USE_UFILESYS @@ -92,22 +90,21 @@ #endif // ESP32 #endif // USE_UFILESYS -#if ESP_IDF_VERSION_MAJOR >= 5 +#ifdef ESP32 #include "include/tasconsole.h" #if SOC_USB_SERIAL_JTAG_SUPPORTED #include "hal/usb_serial_jtag_ll.h" #include "esp_private/rtc_clk.h" #endif // SOC_USB_SERIAL_JTAG_SUPPORTED -#endif // ESP_IDF_VERSION_MAJOr - -// Structs -#include "include/tasmota_types.h" - #ifdef CONFIG_IDF_TARGET_ESP32 #include "driver/gpio.h" #include "soc/efuse_reg.h" #include "bootloader_common.h" #endif +#endif // ESP32 + +// Structs +#include "include/tasmota_types.h" /*********************************************************************************************\ * Global variables @@ -209,8 +206,6 @@ struct XDRVMAILBOX { WiFiUDP PortUdp; // UDP Syslog and Alexa #ifdef ESP32 -#if ESP_IDF_VERSION_MAJOR >= 5 - /* #if CONFIG_IDF_TARGET_ESP32C3 || // support USB via HWCDC using JTAG interface CONFIG_IDF_TARGET_ESP32C6 || // support USB via HWCDC using JTAG interface @@ -226,11 +221,9 @@ bool tasconsole_serial = false; #if ARDUINO_USB_MODE //#warning **** TasConsole ARDUINO_USB_MODE **** -#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,1,3)) #if !ARDUINO_USB_CDC_ON_BOOT HWCDC HWCDCSerial; #endif // ARDUINO_USB_CDC_ON_BOOT -#endif TASCONSOLE TasConsole{HWCDCSerial}; // ESP32C3/C6/S3 embedded USB using JTAG interface //#warning **** TasConsole uses HWCDC **** #else // No ARDUINO_USB_MODE @@ -243,58 +236,17 @@ TASCONSOLE TasConsole{USBSerial}; // ESP32Sx embedded USB interface //#warning **** TasConsole uses USBCDC **** #endif // ARDUINO_USB_MODE -#else // No USE_USB_CDC_CONSOLE -TASCONSOLE TasConsole{Serial}; -bool tasconsole_serial = true; -//#warning **** TasConsole uses Serial **** -#endif // USE_USB_CDC_CONSOLE -#else // No ESP32C3, S2 or S3 -TASCONSOLE TasConsole{Serial}; -bool tasconsole_serial = true; -//#warning **** TasConsole uses Serial **** -#endif // ESP32C3, S2 or S3 - -#else // ESP_IDF_VERSION_MAJOR < 5 - -/* -#if CONFIG_IDF_TARGET_ESP32C3 || // support USB via HWCDC using JTAG interface - CONFIG_IDF_TARGET_ESP32C6 || // support USB via HWCDC using JTAG interface - CONFIG_IDF_TARGET_ESP32S2 || // support USB via USBCDC - CONFIG_IDF_TARGET_ESP32S3 // support USB via HWCDC using JTAG interface or USBCDC -*/ -#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 - -//#if CONFIG_TINYUSB_CDC_ENABLED // This define is not recognized here so use USE_USB_CDC_CONSOLE -#ifdef USE_USB_CDC_CONSOLE -//#warning **** TasConsole use USB **** - -#if ARDUINO_USB_MODE -//#warning **** TasConsole ARDUINO_USB_MODE **** -HWCDC TasConsole; // ESP32C3/C6/S3 embedded USB using JTAG interface -bool tasconsole_serial = false; -//#warning **** TasConsole uses HWCDC **** -#else // No ARDUINO_USB_MODE -#include "USB.h" -#include "USBCDC.h" -USBCDC TasConsole; // ESP32Sx embedded USB interface -bool tasconsole_serial = false; -//#warning **** TasConsole uses USBCDC **** -#endif // ARDUINO_USB_MODE - #else // No USE_USB_CDC_CONSOLE -HardwareSerial TasConsole = Serial; // Fallback serial interface for ESP32C3, S2 and S3 if no USB_SERIAL defined +TASCONSOLE TasConsole{Serial}; bool tasconsole_serial = true; //#warning **** TasConsole uses Serial **** #endif // USE_USB_CDC_CONSOLE - #else // No ESP32C3, S2 or S3 -HardwareSerial TasConsole = Serial; // Fallback serial interface for non ESP32C3, S2 and S3 +TASCONSOLE TasConsole{Serial}; bool tasconsole_serial = true; //#warning **** TasConsole uses Serial **** #endif // ESP32C3, S2 or S3 -#endif // ESP_IDF_VERSION_MAJOR >= 5 - #else // No ESP32 HardwareSerial TasConsole = Serial; // Only serial interface #endif // ESP32 @@ -349,7 +301,7 @@ struct TasmotaGlobal_t { int16_t pwm_cur_phase[MAX_PWMS]; // Current phase values of PWMs as applied to GPIOs int16_t pwm_value[MAX_PWMS]; // Wanted values of PWMs after update - -1 means no change int16_t pwm_phase[MAX_PWMS]; // Wanted phase of PWMs after update - -1 means no change -#endif // ESP32 +#endif // ESP32 bool serial_local; // Handle serial locally bool fallback_topic_flag; // Use Topic or FallbackTopic @@ -429,7 +381,7 @@ struct TasmotaGlobal_t { #ifdef USE_BERRY bool berry_fast_loop_enabled = false; // is Berry fast loop enabled, i.e. control is passed at each loop iteration -#endif // USE_BERRY +#endif // USE_BERRY } TasmotaGlobal; TSettings* Settings = nullptr; @@ -452,14 +404,8 @@ void setup(void) { // restore GPIO16/17 if no PSRAM is found if (!FoundPSRAM()) { // test if the CPU is not pico -#if (ESP_IDF_VERSION_MAJOR >= 5) uint32_t pkg_version = bootloader_common_get_chip_ver_pkg(); if (pkg_version <= 3) { // D0WD, S0WD, D2WD -#else // ESP_IDF_VERSION_MAJOR >= 5 - uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG); - uint32_t pkg_version = chip_ver & 0x7; - if (pkg_version <= 3) { // D0WD, S0WD, D2WD -#endif // ESP_IDF_VERSION_MAJOR >= 5 gpio_reset_pin(GPIO_NUM_16); gpio_reset_pin(GPIO_NUM_17); } @@ -493,13 +439,13 @@ void setup(void) { } #ifdef FIRMWARE_MINIMAL RtcReboot.fast_reboot_count = 0; // Disable fast reboot and quick power cycle detection -#else +#else // No FIRMWARE_MINIMAL if (ResetReason() == REASON_DEEP_SLEEP_AWAKE) { RtcReboot.fast_reboot_count = 0; // Disable fast reboot and quick power cycle detection } else { RtcReboot.fast_reboot_count++; } -#endif +#endif // FIRMWARE_MINIMAL RtcRebootSave(); if (RtcSettingsLoad(0)) { @@ -525,8 +471,6 @@ void setup(void) { } #ifdef ESP32 -#if ESP_IDF_VERSION_MAJOR >= 5 - #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 #ifdef USE_USB_CDC_CONSOLE @@ -573,31 +517,6 @@ void setup(void) { TasConsole = Serial; #endif // ESP32C3, S2 or S3 -#else // ESP_IDF_VERSION_MAJOR < 5 - - // Init command console (either serial or USB) preparing for AddLog use - Serial.begin(TasmotaGlobal.baudrate); - Serial.println(); -// Serial.setRxBufferSize(INPUT_BUFFER_SIZE); // Default is 256 chars -#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 -#ifdef USE_USB_CDC_CONSOLE - TasConsole.setRxBufferSize(INPUT_BUFFER_SIZE); -// TasConsole.setTxBufferSize(INPUT_BUFFER_SIZE); - TasConsole.begin(115200); // Will always be 115200 bps -#if !ARDUINO_USB_MODE - USB.begin(); // This needs a serial console with DTR/DSR support -#endif // No ARDUINO_USB_MODE - TasConsole.println(); - AddLog(LOG_LEVEL_INFO, PSTR("CMD: Using USB CDC")); -#else // No USE_USB_CDC_CONSOLE - TasConsole = Serial; -#endif // USE_USB_CDC_CONSOLE -#else // No ESP32C3, S2 or S3 - TasConsole = Serial; -#endif // ESP32C3, S2 or S3 - -#endif // ESP_IDF_VERSION_MAJOR >= 5 - #else // No ESP32 // Init command serial console preparing for AddLog use Serial.begin(TasmotaGlobal.baudrate); @@ -613,18 +532,18 @@ void setup(void) { AddLog(LOG_LEVEL_INFO, PSTR("HDW: %s %s"), GetDeviceHardwareRevision().c_str(), FoundPSRAM() ? (CanUsePSRAM() ? "(PSRAM)" : "(PSRAM disabled)") : "" ); // AddLog(LOG_LEVEL_DEBUG, PSTR("HDW: FoundPSRAM=%i CanUsePSRAM=%i"), FoundPSRAM(), CanUsePSRAM()); - #if !defined(HAS_PSRAM_FIX) +#if !defined(HAS_PSRAM_FIX) if (FoundPSRAM() && !CanUsePSRAM()) { AddLog(LOG_LEVEL_INFO, PSTR("HDW: PSRAM is disabled, requires specific compilation on this hardware (see doc)")); } - #endif -#else // ESP32 +#endif // HAS_PSRAM_FIX +#else // ESP8266 AddLog(LOG_LEVEL_INFO, PSTR("HDW: %s"), GetDeviceHardware().c_str()); -#endif // ESP32 +#endif // ESP32 #ifdef USE_UFILESYS UfsInit(); // xdrv_50_filesystem.ino -#endif +#endif // USE_UFILESYS SettingsLoad(); SettingsDelta(); @@ -648,12 +567,12 @@ void setup(void) { if (ResetReason() != REASON_DEEP_SLEEP_AWAKE) { #ifdef ESP8266 Settings->flag4.network_wifi = 1; // Make sure we're in control -#endif +#endif // ESP8266 #ifdef ESP32 if (!Settings->flag4.network_ethernet) { Settings->flag4.network_wifi = 1; // Make sure we're in control } -#endif +#endif // ESP32 } TasmotaGlobal.stop_flash_rotate = Settings->flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location @@ -661,13 +580,13 @@ void setup(void) { TasmotaGlobal.sleep = Settings->sleep; #ifndef USE_EMULATION Settings->flag2.emulation = 0; -#else +#else // No USE_EMULATION #ifndef USE_EMULATION_WEMO if (EMUL_WEMO == Settings->flag2.emulation) { Settings->flag2.emulation = 0; } -#endif +#endif // USE_EMULATION_WEMO #ifndef USE_EMULATION_HUE if (EMUL_HUE == Settings->flag2.emulation) { Settings->flag2.emulation = 0; } -#endif +#endif // USE_EMULATION_HUE #endif // USE_EMULATION // AddLog(LOG_LEVEL_INFO, PSTR("DBG: TasmotaGlobal size %d, data %100_H"), sizeof(TasmotaGlobal), (uint8_t*)&TasmotaGlobal); @@ -740,7 +659,7 @@ void setup(void) { if (!TasmotaGlobal.no_autoexec) { BerryInit(); // Load preinit.be } -#endif // USE_BERRY +#endif // USE_BERRY XdrvXsnsCall(FUNC_PRE_INIT); // FUNC_PRE_INIT @@ -764,7 +683,7 @@ void setup(void) { XdrvXsnsCall(FUNC_INIT); // FUNC_INIT #ifdef USE_SCRIPT if (bitRead(Settings->rule_enabled, 0)) Run_Scripter(">BS",3,0); -#endif +#endif // USE_SCRIPT TasmotaGlobal.rules_flag.system_init = 1; }