From cd38179f7f42523fc2245df931bee4fcfa3365ff Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 3 Feb 2021 12:22:17 +0100 Subject: [PATCH] Prep ESP32S2 --- .../OneWire.h | 20 ++++++++++ .../src/esp8266toEsp32.cpp | 16 +++++--- tasmota/support_esp32.ino | 37 ++++++++++++------- tasmota/xdrv_01_webserver.ino | 3 +- tasmota/xdrv_50_filesystem.ino | 9 +++-- 5 files changed, 63 insertions(+), 22 deletions(-) diff --git a/lib/lib_basic/OneWire-Stickbreaker-20190506-1.1/OneWire.h b/lib/lib_basic/OneWire-Stickbreaker-20190506-1.1/OneWire.h index 2275b54f2..d065245e7 100644 --- a/lib/lib_basic/OneWire-Stickbreaker-20190506-1.1/OneWire.h +++ b/lib/lib_basic/OneWire-Stickbreaker-20190506-1.1/OneWire.h @@ -187,6 +187,7 @@ void directModeInput(IO_REG_TYPE pin) { if ( digitalPinIsValid(pin) ) { +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 uint32_t rtc_reg(rtc_gpio_desc[pin].reg); if ( rtc_reg ) // RTC pins PULL settings @@ -194,6 +195,15 @@ void directModeInput(IO_REG_TYPE pin) ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_gpio_desc[pin].mux); ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_gpio_desc[pin].pullup | rtc_gpio_desc[pin].pulldown); } +#elif CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2 + uint32_t rtc_reg(rtc_io_desc[pin].reg); + + if ( rtc_reg ) // RTC pins PULL settings + { + ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_io_desc[pin].mux); + ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_io_desc[pin].pullup | rtc_io_desc[pin].pulldown); + } +#endif if ( pin < 32 ) GPIO.enable_w1tc = ((uint32_t)1 << pin); @@ -215,6 +225,7 @@ void directModeOutput(IO_REG_TYPE pin) { if ( digitalPinIsValid(pin) && pin <= 33 ) // pins above 33 can be only inputs { +#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 uint32_t rtc_reg(rtc_gpio_desc[pin].reg); if ( rtc_reg ) // RTC pins PULL settings @@ -222,6 +233,15 @@ void directModeOutput(IO_REG_TYPE pin) ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_gpio_desc[pin].mux); ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_gpio_desc[pin].pullup | rtc_gpio_desc[pin].pulldown); } +#elif CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2 + uint32_t rtc_reg(rtc_io_desc[pin].reg); + + if ( rtc_reg ) // RTC pins PULL settings + { + ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_io_desc[pin].mux); + ESP_REG(rtc_reg) = ESP_REG(rtc_reg) & ~(rtc_io_desc[pin].pullup | rtc_io_desc[pin].pulldown); + } +#endif if ( pin < 32 ) GPIO.enable_w1ts = ((uint32_t)1 << pin); diff --git a/lib/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp b/lib/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp index 35b9e3e2c..0288f33df 100644 --- a/lib/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp +++ b/lib/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp @@ -18,11 +18,17 @@ #include "lwip/apps/sntp.h" #include -#if CONFIG_IDF_TARGET_ESP32 -#include -//#include "esp32/rom/rtc.h" -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "esp32s2/rom/rtc.h" +// See libraries\ESP32\examples\ResetReason.ino +#if ESP_IDF_VERSION_MAJOR > 3 // IDF 4+ + #if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 + #include "esp32/rom/rtc.h" + #elif CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2 + #include "esp32s2/rom/rtc.h" + #else + #error Target CONFIG_IDF_TARGET is not supported + #endif +#else // ESP32 Before IDF 4.0 + #include "rom/rtc.h" #endif #include diff --git a/tasmota/support_esp32.ino b/tasmota/support_esp32.ino index 78edfa838..525482974 100644 --- a/tasmota/support_esp32.ino +++ b/tasmota/support_esp32.ino @@ -103,11 +103,17 @@ void *special_malloc(uint32_t size) { #include -#if CONFIG_IDF_TARGET_ESP32 -#include -//#include "esp32/rom/rtc.h" -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "esp32s2/rom/rtc.h" +// See libraries\ESP32\examples\ResetReason.ino +#if ESP_IDF_VERSION_MAJOR > 3 // IDF 4+ + #if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 + #include "esp32/rom/rtc.h" + #elif CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2 + #include "esp32s2/rom/rtc.h" + #else + #error Target CONFIG_IDF_TARGET is not supported + #endif +#else // ESP32 Before IDF 4.0 + #include "rom/rtc.h" #endif #include @@ -211,15 +217,8 @@ void NvsInfo(void) { // Flash memory mapping // +// See Esp.cpp #include "Esp.h" - -#if CONFIG_IDF_TARGET_ESP32 -#include "rom/spi_flash.h" -//#include "esp32/rom/spi_flash.h" -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "esp32s2/rom/spi_flash.h" -#endif - #include "esp_spi_flash.h" #include #include @@ -229,6 +228,18 @@ extern "C" { #include "esp_ota_ops.h" #include "esp_image_format.h" } +#include "esp_system.h" +#if ESP_IDF_VERSION_MAJOR > 3 // IDF 4+ + #if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 + #include "esp32/rom/spi_flash.h" + #elif CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2 + #include "esp32s2/rom/spi_flash.h" + #else + #error Target CONFIG_IDF_TARGET is not supported + #endif +#else // ESP32 Before IDF 4.0 + #include "rom/spi_flash.h" +#endif uint32_t EspFlashBaseAddress(void) { const esp_partition_t* partition = esp_ota_get_next_update_partition(nullptr); diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index e2a50a409..51dfc11f7 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -465,7 +465,8 @@ void StartWebserver(int type, IPAddress ipweb) WebServer_on(uri, line.handler, pgm_read_byte(&line.method)); } Webserver->onNotFound(HandleNotFound); - Webserver->on(F("/u2"), HTTP_POST, HandleUploadDone, HandleUploadLoop); // this call requires 2 functions so we keep a direct call +// Webserver->on(F("/u2"), HTTP_POST, HandleUploadDone, HandleUploadLoop); // this call requires 2 functions so we keep a direct call + Webserver->on("/u2", HTTP_POST, HandleUploadDone, HandleUploadLoop); // this call requires 2 functions so we keep a direct call #ifndef FIRMWARE_MINIMAL XdrvCall(FUNC_WEB_ADD_HANDLER); XsnsCall(FUNC_WEB_ADD_HANDLER); diff --git a/tasmota/xdrv_50_filesystem.ino b/tasmota/xdrv_50_filesystem.ino index c5accd4a7..f748ed16a 100644 --- a/tasmota/xdrv_50_filesystem.ino +++ b/tasmota/xdrv_50_filesystem.ino @@ -762,9 +762,12 @@ bool Xdrv50(uint8_t function) { } break; case FUNC_WEB_ADD_HANDLER: - Webserver->on(F("/ufsd"), UfsDirectory); - Webserver->on(F("/ufsu"), HTTP_GET, UfsDirectory); - Webserver->on(F("/ufsu"), HTTP_POST,[](){Webserver->sendHeader(F("Location"),F("/ufsu"));Webserver->send(303);}, HandleUploadLoop); +// Webserver->on(F("/ufsd"), UfsDirectory); +// Webserver->on(F("/ufsu"), HTTP_GET, UfsDirectory); +// Webserver->on(F("/ufsu"), HTTP_POST,[](){Webserver->sendHeader(F("Location"),F("/ufsu"));Webserver->send(303);}, HandleUploadLoop); + Webserver->on("/ufsd", UfsDirectory); + Webserver->on("/ufsu", HTTP_GET, UfsDirectory); + Webserver->on("/ufsu", HTTP_POST,[](){Webserver->sendHeader(F("Location"),F("/ufsu"));Webserver->send(303);}, HandleUploadLoop); break; #endif // USE_WEBSERVER }