From 0c3b5596301e0d579d5807797041c5f8328e0dda Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 21 Aug 2023 16:00:20 +0200 Subject: [PATCH] Phase 1 support C2/C6 --- tasmota/include/tasmota.h | 73 ++++---- tasmota/include/tasmota_globals.h | 8 +- tasmota/include/tasmota_template.h | 163 ++++++++++++++++-- tasmota/include/tasmota_types.h | 24 ++- tasmota/tasmota.ino | 9 +- tasmota/tasmota_support/settings.ino | 19 +- tasmota/tasmota_support/support.ino | 86 +++++---- tasmota/tasmota_support/support_command.ino | 14 +- .../support_crash_recorder.ino | 2 +- tasmota/tasmota_support/support_esp.ino | 18 +- tasmota/tasmota_support/support_rotary.ino | 2 +- tasmota/tasmota_support/support_tasmota.ino | 3 +- 12 files changed, 317 insertions(+), 104 deletions(-) diff --git a/tasmota/include/tasmota.h b/tasmota/include/tasmota.h index b37be129a..ba9645e9b 100644 --- a/tasmota/include/tasmota.h +++ b/tasmota/include/tasmota.h @@ -60,21 +60,18 @@ const uint8_t MAX_INTERLOCKS_SET = 14; // Max number of interlock groups (M const uint8_t MAX_SWITCHES_SET = 28; // Max number of switches const uint8_t MAX_LEDS = 4; // Max number of leds const uint8_t MAX_PWMS_LEGACY = 5; // Max number of PWM channels in first settings block - Legacy limit for ESP8266, but extended for ESP32 (see below) -#ifdef ESP32 - // Max number of PWM channels (total including extended) - ESP32 only - #if defined(CONFIG_IDF_TARGET_ESP32) - const uint8_t MAX_PWMS = 16; // ESP32: 16 ledc PWM channels in total - TODO for now - #elif defined(CONFIG_IDF_TARGET_ESP32S2) - const uint8_t MAX_PWMS = 8; // ESP32S2: 8 ledc PWM channels in total - #elif defined(CONFIG_IDF_TARGET_ESP32S3) - const uint8_t MAX_PWMS = 8; // ESP32S3: 8 ledc PWM channels in total - #elif defined(CONFIG_IDF_TARGET_ESP32C3) - const uint8_t MAX_PWMS = 6; // ESP32C3: 6 ledc PWM channels in total +#ifdef ESP32 // Max number of PWM channels (total including extended) - ESP32 only + #if CONFIG_IDF_TARGET_ESP32 + const uint8_t MAX_PWMS = 16; // ESP32: 16 ledc PWM channels in total - TODO for now + #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + const uint8_t MAX_PWMS = 8; // ESP32S2/S3: 8 ledc PWM channels in total + #elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 + const uint8_t MAX_PWMS = 6; // ESP32C2/C3/C6: 6 ledc PWM channels in total #else - const uint8_t MAX_PWMS = 5; // Unknown - revert to 5 PWM max + const uint8_t MAX_PWMS = 5; // Unknown - revert to 5 PWM max #endif #else - const uint8_t MAX_PWMS = 5; // (not used on ESP8266) +const uint8_t MAX_PWMS = 5; // (not used on ESP8266) #endif const uint8_t MAX_COUNTERS = 4; // Max number of counter sensors const uint8_t MAX_TIMERS = 16; // Max number of Timers @@ -100,19 +97,17 @@ const uint16_t VL53LXX_MAX_SENSORS = 8; // Max number of VL53L0X sensors const uint8_t MAX_I2C = 2; // Max number of I2C controllers (ESP32 = 2) const uint8_t MAX_SPI = 2; // Max number of Hardware SPI controllers (ESP32 = 2) const uint8_t MAX_I2S = 2; // Max number of Hardware I2S controllers (ESP32 = 2) - -#if CONFIG_IDF_TARGET_ESP32 -const uint8_t MAX_RMT = 8; // Max number or RMT channels (ESP32 only) -#elif CONFIG_IDF_TARGET_ESP32S2 -const uint8_t MAX_RMT = 4; // Max number or RMT channels (ESP32S2 only) -#elif CONFIG_IDF_TARGET_ESP32S3 -const uint8_t MAX_RMT = 1; // Max number or RMT channels (ESP32S3 only) -#elif CONFIG_IDF_TARGET_ESP32C3 -const uint8_t MAX_RMT = 2; // Max number or RMT channels (ESP32C3 only) -#else -const uint8_t MAX_RMT = 0; // Max number or RMT channels (0 if unknown) -#endif - + #if CONFIG_IDF_TARGET_ESP32 + const uint8_t MAX_RMT = 8; // Max number or RMT channels (ESP32 only) + #elif CONFIG_IDF_TARGET_ESP32S2 + const uint8_t MAX_RMT = 4; // Max number or RMT channels (ESP32S2 only) + #elif CONFIG_IDF_TARGET_ESP32S3 + const uint8_t MAX_RMT = 1; // Max number or RMT channels (ESP32S3 only) + #elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 + const uint8_t MAX_RMT = 2; // Max number or RMT channels (ESP32C3 only) + #else + const uint8_t MAX_RMT = 0; // Max number or RMT channels (0 if unknown) + #endif #else const uint8_t MAX_I2C = 0; // Max number of I2C controllers (ESP8266 = 0, no choice) const uint8_t MAX_SPI = 0; // Max number of Hardware SPI controllers (ESP8266 = 0, no choice) @@ -138,11 +133,13 @@ const uint8_t MAX_ADCS = 1; // Max number of ESP8266 ADC pins const uint8_t MAX_SWITCHES_TXT = 8; // Max number of switches user text #endif // ESP8266 #ifdef ESP32 -#ifdef CONFIG_IDF_TARGET_ESP32C3 -const uint8_t MAX_ADCS = 5; // Max number of ESP32-C3 ADC pins (ADC2 pins are unusable with Wifi enabled) -#else // ESP32 -const uint8_t MAX_ADCS = 8; // Max number of ESP32 ADC pins (ADC2 pins are unusable with Wifi enabled) -#endif // ESP32C3 + #if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 + const uint8_t MAX_ADCS = 5; // Max number of ESP32-C3 ADC pins (ADC2 pins are unusable with Wifi enabled) + #elif CONFIG_IDF_TARGET_ESP32C6 + const uint8_t MAX_ADCS = 7; // Max number of ESP32 ADC pins (ADC2 pins are unusable with Wifi enabled) + #else // ESP32 + const uint8_t MAX_ADCS = 8; // Max number of ESP32 ADC pins (ADC2 pins are unusable with Wifi enabled) + #endif // ESP32C3 const uint8_t MAX_SWITCHES_TXT = 28; // Max number of switches user text #endif // ESP32 @@ -206,11 +203,11 @@ const uint16_t CMDSZ = 24; // Max number of characters in comma const uint16_t TOPSZ = 151; // Max number of characters in topic string #ifdef ESP8266 -#ifdef PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED -const uint16_t LOG_BUFFER_SIZE = 6096; // Max number of characters in logbuffer used by weblog, syslog and mqttlog -#else -const uint16_t LOG_BUFFER_SIZE = 4096; // Max number of characters in logbuffer used by weblog, syslog and mqttlog -#endif // PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED + #ifdef PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED + const uint16_t LOG_BUFFER_SIZE = 6096; // Max number of characters in logbuffer used by weblog, syslog and mqttlog + #else + const uint16_t LOG_BUFFER_SIZE = 4096; // Max number of characters in logbuffer used by weblog, syslog and mqttlog + #endif // PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED #else // Not ESP8266 const uint16_t LOG_BUFFER_SIZE = 6096; // Max number of characters in logbuffer used by weblog, syslog and mqttlog #endif // ESP8266 @@ -305,21 +302,21 @@ const uint32_t LOOP_SLEEP_DELAY = 50; // Lowest number of milliseconds to #define XPT2046_MAXY 3870 #ifdef ESP32 - #if defined(CONFIG_IDF_TARGET_ESP32S2) + #if CONFIG_IDF_TARGET_ESP32S2 #define MAX_TX_PWR_DBM_11b 195 #define MAX_TX_PWR_DBM_54g 150 #define MAX_TX_PWR_DBM_n 130 #define WIFI_SENSITIVITY_11b -880 #define WIFI_SENSITIVITY_54g -750 #define WIFI_SENSITIVITY_n -720 - #elif defined(CONFIG_IDF_TARGET_ESP32S3) + #elif CONFIG_IDF_TARGET_ESP32S3 #define MAX_TX_PWR_DBM_11b 210 #define MAX_TX_PWR_DBM_54g 190 #define MAX_TX_PWR_DBM_n 185 #define WIFI_SENSITIVITY_11b -880 #define WIFI_SENSITIVITY_54g -760 #define WIFI_SENSITIVITY_n -720 - #elif defined(CONFIG_IDF_TARGET_ESP32C3) + #elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 #define MAX_TX_PWR_DBM_11b 210 #define MAX_TX_PWR_DBM_54g 190 #define MAX_TX_PWR_DBM_n 185 diff --git a/tasmota/include/tasmota_globals.h b/tasmota/include/tasmota_globals.h index a6f964e77..3da0af66d 100644 --- a/tasmota/include/tasmota_globals.h +++ b/tasmota/include/tasmota_globals.h @@ -137,15 +137,15 @@ String EthernetMacAddress(void); \*-------------------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------------------*\ - * Start ESP32-C32 specific parameters - disable features not present in ESP32-C3 + * Start ESP32-C3/C6 specific parameters - disable features not present in ESP32-C3/C6 \*-------------------------------------------------------------------------------------------*/ -#if CONFIG_IDF_TARGET_ESP32C3 // ESP32-C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 // ESP32-C3/C6 //#ifdef USE_ETHERNET -//#undef USE_ETHERNET // ESP32-C3 does not support ethernet +//#undef USE_ETHERNET // ESP32-C3/C6 does not support ethernet //#endif -#endif // CONFIG_IDF_TARGET_ESP32C3 +#endif // CONFIG_IDF_TARGET_ESP32C3/C6 /*-------------------------------------------------------------------------------------------*\ * End ESP32-C3 specific parameters diff --git a/tasmota/include/tasmota_template.h b/tasmota/include/tasmota_template.h index 009934be7..d4bbc5264 100644 --- a/tasmota/include/tasmota_template.h +++ b/tasmota/include/tasmota_template.h @@ -1257,8 +1257,22 @@ typedef struct MYTMPLT8266 { } mytmplt8266; // 12 bytes #endif // ESP8266 + #ifdef ESP32 -#ifdef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C2 + +/* **************************************** + * ESP32C2 + * ****************************************/ +#define MAX_GPIO_PIN 21 // Number of supported GPIO +#define MIN_FLASH_PINS 0 // Number of flash chip pins unusable for configuration (GPIO11 to 17) +#define MAX_USER_PINS 21 // MAX_GPIO_PIN - MIN_FLASH_PINS +#define WEMOS_MODULE 0 // Wemos module + +// 0 1 2 3 4 5 6 7 8 91011121314151617181920 +const char PINS_WEMOS[] PROGMEM = "AOAOAOAOAOIOIOIOIOIOIOFLFLFLFLFLFLFLIORXTX"; + +#elif CONFIG_IDF_TARGET_ESP32C3 /* **************************************** * ESP32C3 @@ -1271,7 +1285,20 @@ typedef struct MYTMPLT8266 { // 0 1 2 3 4 5 6 7 8 9101112131415161718192021 const char PINS_WEMOS[] PROGMEM = "AOAOAOAOAOAOIOIOIOIOIOFLFLFLFLFLFLFLIOIORXTX"; -#elif defined(CONFIG_IDF_TARGET_ESP32S2) +#elif CONFIG_IDF_TARGET_ESP32C6 + +/* **************************************** + * ESP32C6 + * ****************************************/ +#define MAX_GPIO_PIN 31 // Number of supported GPIO +#define MIN_FLASH_PINS 0 // Number of flash chip pins unusable for configuration (GPIO24 to 30) +#define MAX_USER_PINS 31 // MAX_GPIO_PIN - MIN_FLASH_PINS +#define WEMOS_MODULE 0 // Wemos module + +// 0 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930 +const char PINS_WEMOS[] PROGMEM = "AOAOAOAOAOAOAOIOIOIOIOIOIOIOIOIOTXRXIOIOIOIOIOIOFLFLFLFLFLFLFL"; + +#elif CONFIG_IDF_TARGET_ESP32S2 /* **************************************** * ESP32S2 @@ -1284,7 +1311,7 @@ const char PINS_WEMOS[] PROGMEM = "AOAOAOAOAOAOIOIOIOIOIOFLFLFLFLFLFLFLIOIORXTX" // 0 1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334353637383940414243444546 const char PINS_WEMOS[] PROGMEM = "IOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOIO--------FLFLFLFLFLFLFLIOIOIOIOIOIOIOIOIOIOIOIOIOI "; -#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#elif CONFIG_IDF_TARGET_ESP32S3 /* **************************************** * ESP32S3 * GPIOs 0..21 + 33..48 @@ -1300,7 +1327,7 @@ const char PINS_WEMOS[] PROGMEM = "IOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOIO- // 0 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930313233343536373839404142434445464748 const char PINS_WEMOS[] PROGMEM = "IOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOIO--------FLFLFLFLFLFLFLIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIO"; -#else // not CONFIG_IDF_TARGET_ESP32C3 nor CONFIG_IDF_TARGET_ESP32S2 - ESP32 +#else // not CONFIG_IDF_TARGET_ESP32C2/C3/C6 nor CONFIG_IDF_TARGET_ESP32S2 - ESP32 /* **************************************** * ESP32 - including Pico @@ -1331,7 +1358,7 @@ const char PINS_WEMOS[] PROGMEM = "IOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOAOIO- // 0 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930313233343536373839 const char PINS_WEMOS[] PROGMEM = "IOTXIORXIOIOFLFLFLFLFLFLIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIO--------AOAOIAIAIAIAIAIA"; -#endif // ESP32/S2/C3 selection +#endif // ESP32/S2/C2/C3/C6 selection #endif // ESP32 /********************************************************************************************\ @@ -2791,7 +2818,61 @@ const mytmplt8285 kModules8285[TMP_MAXMODULE_8266 - TMP_WEMOS] PROGMEM = { #endif // ESP8266 #ifdef ESP32 -#ifdef CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C2 +/********************************************************************************************\ + * ESP32-C2 Module templates +\********************************************************************************************/ + +#define USER_MODULE 255 + +// Supported hardware modules +enum SupportedModulesESP32C2 { + WEMOS, // not really correct, a placeholder for now + MAXMODULE }; + +// Default module settings +const uint8_t kModuleNiceList[] PROGMEM = { + WEMOS, +}; + +// !!! Update this list in the same order as kModuleNiceList !!! +const char kModuleNames[] PROGMEM = + "ESP32C2|" + ; + +// !!! Update this list in the same order as SupportedModulesESP32C2 !!! +const mytmplt kModules[] PROGMEM = { + { // Generic ESP32C2 device + AGPIO(GPIO_USER), // 0 IO GPIO0, ADC1_CH0, RTC + AGPIO(GPIO_USER), // 1 IO GPIO1, ADC1_CH1, RTC + AGPIO(GPIO_USER), // 2 IO GPIO2, ADC1_CH2, RTC + AGPIO(GPIO_USER), // 3 IO GPIO3, ADC1_CH3, RTC + AGPIO(GPIO_USER), // 4 IO GPIO4, ADC1_CH4, RTC + AGPIO(GPIO_USER), // 5 IO GPIO5, RTC + AGPIO(GPIO_USER), // 6 IO GPIO6, + AGPIO(GPIO_USER), // 7 IO GPIO7, + AGPIO(GPIO_USER), // 8 IO GPIO8, Strapping + AGPIO(GPIO_USER), // 9 IO GPIO9, Strapping + AGPIO(GPIO_USER), // 10 IO GPIO10 + 0, // 11 IO GPIO11, output power supply for flash + 0, // 12 IO GPIO12, SPIHD + 0, // 13 IO GPIO13, SPIWP + 0, // 14 IO GPIO14, SPICS0 + 0, // 15 IO GPIO15, SPICLK + 0, // 16 IO GPIO16, SPID + 0, // 17 IO GPIO17, SPIQ + AGPIO(GPIO_USER), // 18 IO GPIO18, + AGPIO(GPIO_USER), // 19 IO RXD0 GPIO19, U0RXD + AGPIO(GPIO_USER), // 20 IO TXD0 GPIO20, U0TXD + 0 // Flag + }, +}; + +/*********************************************************************************************\ + Known templates +\*********************************************************************************************/ + +#elif CONFIG_IDF_TARGET_ESP32C3 /********************************************************************************************\ * ESP32-C3 Module templates \********************************************************************************************/ @@ -2846,8 +2927,71 @@ const mytmplt kModules[] PROGMEM = { Known templates \*********************************************************************************************/ -#elif defined(CONFIG_IDF_TARGET_ESP32S2) +#elif CONFIG_IDF_TARGET_ESP32C6 +/********************************************************************************************\ + * ESP32-C6 Module templates +\********************************************************************************************/ +#define USER_MODULE 255 + +// Supported hardware modules +enum SupportedModulesESP32C6 { + WEMOS, // not really correct, a placeholder for now + MAXMODULE }; + +// Default module settings +const uint8_t kModuleNiceList[] PROGMEM = { + WEMOS, +}; + +// !!! Update this list in the same order as kModuleNiceList !!! +const char kModuleNames[] PROGMEM = + "ESP32C6|" + ; + +// !!! Update this list in the same order as SupportedModulesESP32C6 !!! +const mytmplt kModules[] PROGMEM = { + { // Generic ESP32C6 device + AGPIO(GPIO_USER), // 0 IO GPIO0, ADC1_CH0, LP_GPIO0 + AGPIO(GPIO_USER), // 1 IO GPIO1, ADC1_CH1, LP_GPIO1 + AGPIO(GPIO_USER), // 2 IO GPIO2, ADC1_CH2, LP_GPIO2 + AGPIO(GPIO_USER), // 3 IO GPIO3, ADC1_CH3, LP_GPIO3 + AGPIO(GPIO_USER), // 4 IO GPIO4, ADC1_CH4, LP_GPIO4, Strapping + AGPIO(GPIO_USER), // 5 IO GPIO5, ADC1_CH5, LP_GPIO5, Strapping + AGPIO(GPIO_USER), // 6 IO GPIO6, ADC1_CH6, LP_GPIO6 + AGPIO(GPIO_USER), // 7 IO GPIO7, LP_GPIO7 + AGPIO(GPIO_USER), // 8 IO GPIO8, Strapping + AGPIO(GPIO_USER), // 9 IO GPIO9, Strapping + AGPIO(GPIO_USER), // 10 IO GPIO10 (QFN40 only) + AGPIO(GPIO_USER), // 11 IO GPIO11 (QFN40 only) + AGPIO(GPIO_USER), // 12 IO GPIO12, USB-JTAG + AGPIO(GPIO_USER), // 13 IO GPIO13, USB-JTAG + AGPIO(GPIO_USER), // 14 IO GPIO14 (QFN32 only) + AGPIO(GPIO_USER), // 15 IO GPIO15, Strapping + AGPIO(GPIO_USER), // 16 IO TXD0 GPIO16, U0TXD + AGPIO(GPIO_USER), // 17 IO RXD0 GPIO17, U0RXD + AGPIO(GPIO_USER), // 18 IO GPIO18, SDIO_CMD + AGPIO(GPIO_USER), // 19 IO GPIO19, SDIO_CLK + AGPIO(GPIO_USER), // 20 IO GPIO20, SDIO_DATA0 + AGPIO(GPIO_USER), // 21 IO GPIO21, SDIO_DATA1 + AGPIO(GPIO_USER), // 22 IO GPIO22, SDIO_DATA2 + AGPIO(GPIO_USER), // 23 IO GPIO23, SDIO_DATA3 + 0, // 24 IO GPIO24, SPICS1, PSRAM + 0, // 25 IO GPIO25, SPIQ + 0, // 26 IO GPIO26, SPIWP + 0, // 27 IO GPIO27, SPIVDD + 0, // 28 IO GPIO28, SPIHD + 0, // 29 IO GPIO29, SPICLK + 0, // 30 IO GPIO30, SPID + 0 // Flag + }, +}; + +/*********************************************************************************************\ + Known templates +\*********************************************************************************************/ + +#elif CONFIG_IDF_TARGET_ESP32S2 /********************************************************************************************\ * ESP32-S2 Module templates \********************************************************************************************/ @@ -2927,8 +3071,7 @@ const mytmplt kModules[] PROGMEM = { Known templates \*********************************************************************************************/ -#elif defined(CONFIG_IDF_TARGET_ESP32S3) - +#elif CONFIG_IDF_TARGET_ESP32S3 /********************************************************************************************\ * ESP32-S3 Module templates \********************************************************************************************/ @@ -3010,7 +3153,7 @@ const mytmplt kModules[] PROGMEM = { Known templates \*********************************************************************************************/ -#else // not CONFIG_IDF_TARGET_ESP32C3 nor CONFIG_IDF_TARGET_ESP32S2 - ESP32 +#else // not CONFIG_IDF_TARGET_ESP32C2/C3/C6 nor CONFIG_IDF_TARGET_ESP32S2 - ESP32 /********************************************************************************************\ * ESP32 Module templates \********************************************************************************************/ diff --git a/tasmota/include/tasmota_types.h b/tasmota/include/tasmota_types.h index ef5fc44f4..b533a069d 100644 --- a/tasmota/include/tasmota_types.h +++ b/tasmota/include/tasmota_types.h @@ -602,32 +602,40 @@ typedef struct { // End of remapping, next is all other CPUs // ---------------------------------------- #else - myio my_gp; // 3AC 2x18 bytes (ESP8266) / 2x40 bytes (ESP32) / 2x22 bytes (ESP32-C3) / 2x47 bytes (ESP32-S2) + myio my_gp; // 3AC 2x18 bytes (ESP8266) / 2x40 bytes (ESP32) / 2x21 bytes (ESP32-C2) / 2x22 bytes (ESP32-C3) / 2x31 bytes (ESP32-C6) / 2x47 bytes (ESP32-S2) #ifdef ESP8266 uint16_t gpio16_converted; // 3D0 uint8_t free_esp8266_3D2[42]; // 3D2 #endif // ESP8266 #ifdef ESP32 -#ifdef CONFIG_IDF_TARGET_ESP32C3 + #if CONFIG_IDF_TARGET_ESP32C2 + uint8_t free_esp32c2_3D6[38]; // 3D6 - Due to smaller myio + #elif CONFIG_IDF_TARGET_ESP32C3 uint8_t free_esp32c3_3D8[36]; // 3D8 - Due to smaller myio -#endif // CONFIG_IDF_TARGET_ESP32C3 + #elif CONFIG_IDF_TARGET_ESP32C6 + uint8_t free_esp32c6_3EA[18]; // 3EA - Due to smaller myio + #endif // CONFIG_IDF_TARGET_ESP32C2/3/6 #endif // ESP32 - mytmplt user_template; // 3FC 2x15 bytes (ESP8266) / 2x37 bytes (ESP32) / 2x23 bytes (ESP32-C3) / 2x37 bytes (ESP32-S2) + mytmplt user_template; // 3FC 2x15 bytes (ESP8266) / 2x37 bytes (ESP32) / 2x22 bytes (ESP32-C2) / 2x23 bytes (ESP32-C3) / 2x32 bytes (ESP32-C6) / 2x37 bytes (ESP32-S2) #ifdef ESP8266 uint8_t free_esp8266_41A[55]; // 41A #endif // ESP8266 #ifdef ESP32 -#ifdef CONFIG_IDF_TARGET_ESP32C3 + #if CONFIG_IDF_TARGET_ESP32C2 + uint8_t free_esp32c2_428[30]; // 428 - Due to smaller mytmplt + #elif CONFIG_IDF_TARGET_ESP32C3 uint8_t free_esp32c3_42A[28]; // 42A - Due to smaller mytmplt -#endif // CONFIG_IDF_TARGET_ESP32C3 + #elif CONFIG_IDF_TARGET_ESP32C6 + uint8_t free_esp32c3_43C[10]; // 43C - Due to smaller mytmplt + #endif // CONFIG_IDF_TARGET_ESP32C2/3/6 uint8_t eth_type; // 446 uint8_t eth_clk_mode; // 447 uint8_t free_esp32_448[4]; // 448 -#ifdef CONFIG_IDF_TARGET_ESP32S2 + #ifdef CONFIG_IDF_TARGET_ESP32S2 uint8_t free_esp32s2_456[2]; // 456 - fix 32-bit offset for WebCamCfg -#endif + #endif WebCamCfg webcam_config; // 44C uint8_t eth_address; // 450 diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index a74efb45f..fe07ff400 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -200,10 +200,11 @@ WiFiUDP PortUdp; // UDP Syslog and Alexa #ifdef ESP32 /* #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_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#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 @@ -211,7 +212,7 @@ WiFiUDP PortUdp; // UDP Syslog and Alexa #if ARDUINO_USB_MODE //#warning **** TasConsole ARDUINO_USB_MODE **** -HWCDC TasConsole; // ESP32C3/S3 embedded USB using JTAG interface +HWCDC TasConsole; // ESP32C3/C6/S3 embedded USB using JTAG interface bool tasconsole_serial = false; //#warning **** TasConsole uses HWCDC **** #else // No ARDUINO_USB_MODE @@ -400,11 +401,11 @@ TSettings* Settings = nullptr; void setup(void) { #ifdef ESP32 +#ifdef CONFIG_IDF_TARGET_ESP32 #ifdef DISABLE_ESP32_BROWNOUT DisableBrownout(); // Workaround possible weak LDO resulting in brownout detection during Wifi connection #endif // DISABLE_ESP32_BROWNOUT -#ifdef CONFIG_IDF_TARGET_ESP32 // restore GPIO16/17 if no PSRAM is found #if ESP_IDF_VERSION_MAJOR < 5 // TODO for esp-idf 5 if (!FoundPSRAM()) { @@ -482,7 +483,7 @@ void setup(void) { Serial.println(); // Serial.setRxBufferSize(INPUT_BUFFER_SIZE); // Default is 256 chars #ifdef ESP32 -#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#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); diff --git a/tasmota/tasmota_support/settings.ino b/tasmota/tasmota_support/settings.ino index e6ac6e6b8..dc0c31f9b 100644 --- a/tasmota/tasmota_support/settings.ino +++ b/tasmota/tasmota_support/settings.ino @@ -536,13 +536,16 @@ bool SettingsConfigRestore(void) { valid_settings = (0 == settings_buffer[0xF36]); // Settings->config_version #endif // ESP8266 #ifdef ESP32 - -#ifdef CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S3 valid_settings = (2 == settings_buffer[0xF36]); // Settings->config_version ESP32S3 #elif CONFIG_IDF_TARGET_ESP32S2 valid_settings = (3 == settings_buffer[0xF36]); // Settings->config_version ESP32S2 #elif CONFIG_IDF_TARGET_ESP32C3 valid_settings = (4 == settings_buffer[0xF36]); // Settings->config_version ESP32C3 +#elif CONFIG_IDF_TARGET_ESP32C2 + valid_settings = (5 == settings_buffer[0xF36]); // Settings->config_version ESP32C2 +#elif CONFIG_IDF_TARGET_ESP32C6 + valid_settings = (6 == settings_buffer[0xF36]); // Settings->config_version ESP32C6 #else valid_settings = (1 == settings_buffer[0xF36]); // Settings->config_version ESP32 all other #endif // CONFIG_IDF_TARGET_ESP32S3 @@ -956,12 +959,16 @@ void SettingsDefaultSet2(void) { // Settings->config_version = 0; // ESP8266 (Has been 0 for long time) #endif // ESP8266 #ifdef ESP32 -#ifdef CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S3 Settings->config_version = 2; // ESP32S3 #elif CONFIG_IDF_TARGET_ESP32S2 Settings->config_version = 3; // ESP32S2 #elif CONFIG_IDF_TARGET_ESP32C3 Settings->config_version = 4; // ESP32C3 +#elif CONFIG_IDF_TARGET_ESP32C2 + Settings->config_version = 5; // ESP32C2 +#elif CONFIG_IDF_TARGET_ESP32C6 + Settings->config_version = 6; // ESP32C6 #else Settings->config_version = 1; // ESP32 #endif // CONFIG_IDF_TARGET_ESP32S3 @@ -1520,12 +1527,16 @@ void SettingsDelta(void) { Settings->config_version = 0; // ESP8266 (Has been 0 for long time) #endif // ESP8266 #ifdef ESP32 -#ifdef CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32S3 Settings->config_version = 2; // ESP32S3 #elif CONFIG_IDF_TARGET_ESP32S2 Settings->config_version = 3; // ESP32S2 #elif CONFIG_IDF_TARGET_ESP32C3 Settings->config_version = 4; // ESP32C3 +#elif CONFIG_IDF_TARGET_ESP32C2 + Settings->config_version = 5; // ESP32C2 +#elif CONFIG_IDF_TARGET_ESP32C6 + Settings->config_version = 6; // ESP32C6 #else Settings->config_version = 1; // ESP32 #endif // CONFIG_IDF_TARGET_ESP32S3 diff --git a/tasmota/tasmota_support/support.ino b/tasmota/tasmota_support/support.ino index 55f8cfe46..fefd0549f 100755 --- a/tasmota/tasmota_support/support.ino +++ b/tasmota/tasmota_support/support.ino @@ -1588,6 +1588,7 @@ void TemplateGpios(myio *gp) // Expand template to physical GPIO array, j=phy_GPIO, i=template_GPIO uint32_t j = 0; for (uint32_t i = 0; i < nitems(Settings->user_template.gp.io); i++) { +/* #if defined(ESP32) && CONFIG_IDF_TARGET_ESP32C3 dest[i] = src[i]; #elif defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) @@ -1602,6 +1603,24 @@ void TemplateGpios(myio *gp) dest[j] = src[i]; j++; #endif +*/ +#ifdef ESP8266 + if (6 == i) { j = 9; } + if (8 == i) { j = 12; } + dest[j] = src[i]; + j++; +#endif // ESP8266 +#ifdef ESP32 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 + dest[i] = src[i]; +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + if (22 == i) { j = 33; } // skip 22-32 + dest[j] = src[i]; + j++; +#else // ESP32 + dest[Esp32TemplateToPhy[i]] = src[i]; +#endif // ESP32C2/C3/C6 and S2/S3 +#endif // ESP32 } // 11 85 00 85 85 00 00 00 00 00 00 00 15 38 85 00 00 81 @@ -1655,33 +1674,39 @@ void SetModuleType(void) #endif } -bool FlashPin(uint32_t pin) -{ -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32C3 - return (((pin > 10) && (pin < 12)) || ((pin > 13) && (pin < 18))); // ESP32C3 has GPIOs 11-17 reserved for Flash, with some boards GPIOs 12 13 are useable -#elif defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) - return (pin > 21) && (pin < 33); // ESP32S2 skip 22-32 -#elif defined(CONFIG_IDF_TARGET_ESP32) - return (pin >= 28) && (pin <= 31); // ESP21 skip 28-31 -#else // ESP8266 +bool FlashPin(uint32_t pin) { +#ifdef ESP8266 return (((pin > 5) && (pin < 9)) || (11 == pin)); -#endif +#endif // ESP8266 +#ifdef ESP32 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 + return (((pin > 10) && (pin < 12)) || ((pin > 13) && (pin < 18))); // ESP32C3 has GPIOs 11-17 reserved for Flash, with some boards GPIOs 12 13 are useable +#elif CONFIG_IDF_TARGET_ESP32C6 + return (pin > 23); // ESP32C6 flash pins 24-30 +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + return (pin > 21) && (pin < 33); // ESP32S2 skip 22-32 +#else + return (pin >= 28) && (pin <= 31); // ESP32 skip 28-31 +#endif // ESP32C2/C3/C6 and S2/S3 +#endif // ESP32 } -bool RedPin(uint32_t pin) // pin may be dangerous to change, display in RED in template console -{ -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32C3 - return (12==pin)||(13==pin); // ESP32C3: GPIOs 12 13 are usually used for Flash (mode QIO/QOUT) -#elif defined(CONFIG_IDF_TARGET_ESP32S2) - return false; // no red pin on ESP32S3 -#elif defined(CONFIG_IDF_TARGET_ESP32S3) - return (33<=pin) && (37>=pin); // ESP32S3: GPIOs 33..37 are usually used for PSRAM -#elif defined(CONFIG_IDF_TARGET_ESP32) // red pins are 6-11 for original ESP32, other models like PICO are not impacted if flash pins are condfigured +bool RedPin(uint32_t pin) { // Pin may be dangerous to change, display in RED in template console +#ifdef ESP8266 + return (9 == pin) || (10 == pin); +#endif // ESP8266 +#ifdef ESP32 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 + return (12 == pin) || (13 == pin); // ESP32C3: GPIOs 12 13 are usually used for Flash (mode QIO/QOUT) +#elif CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S2 + return false; // No red pin on ESP32C6 and ESP32S3 +#elif CONFIG_IDF_TARGET_ESP32S3 + return (33 <= pin) && (37 >= pin); // ESP32S3: GPIOs 33..37 are usually used for PSRAM +#else // ESP32 red pins are 6-11 for original ESP32, other models like PICO are not impacted if flash pins are condfigured // PICO can also have 16/17/18/23 not available - return ((6<=pin) && (11>=pin)) || (16==pin) || (17==pin); // TODO adapt depending on the exact type of ESP32 -#else // ESP8266 - return (9==pin)||(10==pin); -#endif + return ((6 <= pin) && (11 >= pin)) || (16 == pin) || (17 == pin); // TODO adapt depending on the exact type of ESP32 +#endif // ESP32C2/C3/C6 and S2/S3 +#endif // ESP32 } uint32_t ValidPin(uint32_t pin, uint32_t gpio, uint8_t isTuya = false) { @@ -1689,11 +1714,15 @@ uint32_t ValidPin(uint32_t pin, uint32_t gpio, uint8_t isTuya = false) { return GPIO_NONE; // Disable flash pins GPIO6, GPIO7, GPIO8 and GPIO11 } -#if defined(CONFIG_IDF_TARGET_ESP32C3) +#if CONFIG_IDF_TARGET_ESP32C2 // ignore -#elif defined(CONFIG_IDF_TARGET_ESP32S2) +#elif CONFIG_IDF_TARGET_ESP32C3 // ignore -#elif defined(CONFIG_IDF_TARGET_ESP32) +#elif CONFIG_IDF_TARGET_ESP32C6 +// ignore +#elif CONFIG_IDF_TARGET_ESP32S2 +// ignore +#elif CONFIG_IDF_TARGET_ESP32 // ignore #else // not ESP32C3 and not ESP32S2 if (((WEMOS == Settings->module) || isTuya) && !Settings->flag3.user_esp8285_enable) { // SetOption51 - Enable ESP8285 user GPIO's @@ -2067,18 +2096,17 @@ void SetSerial(uint32_t baudrate, uint32_t serial_config) { void ClaimSerial(void) { #ifdef ESP32 -#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 #ifdef USE_USB_CDC_CONSOLE return; // USB console does not use serial #endif // USE_USB_CDC_CONSOLE -#endif // ESP32C3, S2 or S3 +#endif // ESP32C3/C6, S2 or S3 #endif // ESP32 TasmotaGlobal.serial_local = true; AddLog(LOG_LEVEL_INFO, PSTR("SNS: Hardware Serial")); SetSeriallog(LOG_LEVEL_NONE); TasmotaGlobal.baudrate = GetSerialBaudrate(); Settings->baudrate = TasmotaGlobal.baudrate / 300; - } void SerialSendRaw(char *codes) diff --git a/tasmota/tasmota_support/support_command.ino b/tasmota/tasmota_support/support_command.ino index d074df54e..9fb41fa3e 100644 --- a/tasmota/tasmota_support/support_command.ino +++ b/tasmota/tasmota_support/support_command.ino @@ -1846,11 +1846,19 @@ void CmndTemplate(void) SettingsUpdateText(SET_TEMPLATE_NAME, PSTR("Merged")); uint32_t j = 0; for (uint32_t i = 0; i < nitems(Settings->user_template.gp.io); i++) { -#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32C3 -#else +#ifdef ESP8266 if (6 == i) { j = 9; } if (8 == i) { j = 12; } -#endif +#endif // ESP8266 +#ifdef ESP32 +#if CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 + // No change +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +// if (22 == i) { j = 33; } // TODO 20230821 verify +#else // ESP32 +// if (28 == i) { j = 32; } // TODO 20230821 verify +#endif // Non plain ESP32 +#endif // ESP32 if (TasmotaGlobal.my_module.io[j] > GPIO_NONE) { Settings->user_template.gp.io[i] = TasmotaGlobal.my_module.io[j]; } diff --git a/tasmota/tasmota_support/support_crash_recorder.ino b/tasmota/tasmota_support/support_crash_recorder.ino index bf55869cd..4814c0552 100644 --- a/tasmota/tasmota_support/support_crash_recorder.ino +++ b/tasmota/tasmota_support/support_crash_recorder.ino @@ -256,7 +256,7 @@ void CrashDump(void) } ResponseJsonEnd(); } -#elif CONFIG_IDF_TARGET_ESP32C3 +#elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 extern "C" { // esp-idf 3.x diff --git a/tasmota/tasmota_support/support_esp.ino b/tasmota/tasmota_support/support_esp.ino index fb353bb65..615ee24ee 100644 --- a/tasmota/tasmota_support/support_esp.ino +++ b/tasmota/tasmota_support/support_esp.ino @@ -227,8 +227,12 @@ String GetCodeCores(void) { #define ESP32_ARCH "esp32s2" #elif CONFIG_IDF_TARGET_ESP32S3 #define ESP32_ARCH "esp32s3" +#elif CONFIG_IDF_TARGET_ESP32C2 + #define ESP32_ARCH "esp32c2" #elif CONFIG_IDF_TARGET_ESP32C3 #define ESP32_ARCH "esp32c3" +#elif CONFIG_IDF_TARGET_ESP32C6 + #define ESP32_ARCH "esp32c6" #else #define ESP32_ARCH "" #endif @@ -246,8 +250,12 @@ String GetCodeCores(void) { #include "esp32s2/rom/rtc.h" #elif CONFIG_IDF_TARGET_ESP32S3 // ESP32-S3 #include "esp32s3/rom/rtc.h" + #elif CONFIG_IDF_TARGET_ESP32C2 // ESP32-C2 + #include "esp32c2/rom/rtc.h" #elif CONFIG_IDF_TARGET_ESP32C3 // ESP32-C3 #include "esp32c3/rom/rtc.h" + #elif CONFIG_IDF_TARGET_ESP32C6 // ESP32-C6 + #include "esp32c6/rom/rtc.h" #else #error Target CONFIG_IDF_TARGET is not supported #endif @@ -422,9 +430,15 @@ extern "C" { #elif CONFIG_IDF_TARGET_ESP32S3 // ESP32-S3 #include "esp32s3/rom/spi_flash.h" #define ESP_FLASH_IMAGE_BASE 0x0000 // Esp32s3 is located at 0x0000 + #elif CONFIG_IDF_TARGET_ESP32C2 // ESP32-C2 + #include "esp32c2/rom/spi_flash.h" + #define ESP_FLASH_IMAGE_BASE 0x0000 // Esp32c2 is located at 0x0000 #elif CONFIG_IDF_TARGET_ESP32C3 // ESP32-C3 #include "esp32c3/rom/spi_flash.h" #define ESP_FLASH_IMAGE_BASE 0x0000 // Esp32c3 is located at 0x0000 + #elif CONFIG_IDF_TARGET_ESP32C6 // ESP32-C6 + #include "esp32c6/rom/spi_flash.h" + #define ESP_FLASH_IMAGE_BASE 0x0000 // Esp32c6 is located at 0x0000 #else #error Target CONFIG_IDF_TARGET is not supported #endif @@ -566,6 +580,7 @@ int32_t EspPartitionMmap(uint32_t action) { // ESP32 specific // +#ifdef CONFIG_IDF_TARGET_ESP32 #include "soc/soc.h" #include "soc/rtc_cntl_reg.h" @@ -573,6 +588,7 @@ void DisableBrownout(void) { // https://github.com/espressif/arduino-esp32/issues/863#issuecomment-347179737 WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // Disable brownout detector } +#endif // ESP32 // // ESP32 Alternatives @@ -739,7 +755,7 @@ extern "C" { // `psramFound()` can return true even if no PSRAM is actually installed // This new version also checks `esp_spiram_is_initialized` to know if the PSRAM is initialized bool FoundPSRAM(void) { -#if CONFIG_IDF_TARGET_ESP32C3 +#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 return psramFound(); #else #if ESP_IDF_VERSION_MAJOR >= 5 diff --git a/tasmota/tasmota_support/support_rotary.ino b/tasmota/tasmota_support/support_rotary.ino index e39913f73..1462f4093 100644 --- a/tasmota/tasmota_support/support_rotary.ino +++ b/tasmota/tasmota_support/support_rotary.ino @@ -106,7 +106,7 @@ bool RotaryButtonPressed(uint32_t button_index) { return false; } -void IRAM_ATTR RotaryIsrArgMiDesk(void *arg) { +static void IRAM_ATTR RotaryIsrArgMiDesk(void *arg) { tEncoder* encoder = static_cast(arg); // https://github.com/PaulStoffregen/Encoder/blob/master/Encoder.h diff --git a/tasmota/tasmota_support/support_tasmota.ino b/tasmota/tasmota_support/support_tasmota.ino index feb98c8a0..792c7dc83 100644 --- a/tasmota/tasmota_support/support_tasmota.ino +++ b/tasmota/tasmota_support/support_tasmota.ino @@ -201,7 +201,8 @@ void ZeroCrossMomentEnd(void) { #endif } -void IRAM_ATTR ZeroCrossIsr(void) { +void IRAM_ATTR ZeroCrossIsr(void); +void ZeroCrossIsr(void) { uint32_t time = micros(); TasmotaGlobal.zc_interval = ((int32_t) (time - TasmotaGlobal.zc_time)); TasmotaGlobal.zc_time = time;