Start clean-up code

This commit is contained in:
Theo Arends 2024-04-15 15:12:17 +02:00
parent 440a7a689e
commit cb0e2938e5

View File

@ -47,7 +47,7 @@
#ifdef USE_TLS
#include "HTTPUpdateLight.h" // Ota over HTTPS for ESP32
#endif // USE_TLS
#endif
#endif // ESP32
#include <StreamString.h> // Webserver, Updater
#include <ext_printf.h>
#include <SBuffer.hpp>
@ -59,15 +59,13 @@
#include <ArduinoOTA.h> // Arduino OTA
#ifndef USE_DISCOVERY
#define USE_DISCOVERY
#endif
#endif // USE_DISCOVERY
#endif // USE_ARDUINO_OTA
#endif // ESP8266
#ifdef USE_DISCOVERY
#include <ESP8266mDNS.h> // MQTT, Webserver, Arduino OTA
#endif // USE_DISCOVERY
//#ifdef USE_I2C
#include <Wire.h> // I2C support library
//#endif // USE_I2C
#ifdef USE_SPI
#include <SPI.h> // SPI support, TFT, SDcard
#endif // USE_SPI
@ -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
@ -254,47 +247,6 @@ 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
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
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
@ -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);
@ -617,14 +536,14 @@ void setup(void) {
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
#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);
@ -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;
}