From e8f3d1d9862af8f3d2129a3a45f8714719074c09 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 13 Apr 2020 17:45:06 +0200 Subject: [PATCH] Increase ESP32 compatibility Increase ESP32 compatibility (breaks current ESP32 configuration again!) --- .../src/esp8266toEsp32.cpp | 29 +++++++++++++++---- .../src/esp8266toEsp32.h | 5 +++- tasmota/support.ino | 8 +++++ tasmota/support_command.ino | 6 ++-- tasmota/support_rtc.ino | 2 +- tasmota/support_tasmota.ino | 17 +++++++---- tasmota/support_wifi.ino | 2 +- tasmota/tasmota.h | 12 ++++---- tasmota/tasmota.ino | 4 +-- tasmota/tasmota_compat.h | 7 +++-- tasmota/tasmota_globals.h | 13 ++++++++- tasmota/xdrv_01_webserver.ino | 8 ++--- tasmota/xdrv_12_home_assistant.ino | 24 +++++++-------- tasmota/xdrv_20_hue.ino | 6 ++-- tasmota/xdrv_21_wemo.ino | 2 +- 15 files changed, 97 insertions(+), 48 deletions(-) diff --git a/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp b/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp index 0490991c4..f4a17f368 100644 --- a/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp +++ b/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp @@ -34,9 +34,9 @@ String ESP_getResetInfo(void) return String(PSTR("0")); } -String ESP_getBootVersion(void) +uint32_t ESP_getBootVersion(void) { - return String(PSTR("Unknown")); + return 1; } bool ESP_rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size) @@ -59,15 +59,32 @@ uint32_t ESP_getFlashChipId() return 0; } +uint32_t ESP_getChipId() +{ + uint32_t id = 0; + for (uint32_t i = 0; i < 17; i = i +8) { + id |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; + } + return id; +} + String String_ESP_getChipId() { uint64_t mac = ESP.getEfuseMac(); return String(uint32_t(mac >> 32)) + String(uint32_t(mac)); } -/* -uint64_t ESP_getChipId() +uint32_t ESP_getFlashChipRealSize() { - return ESP.getEfuseMac(); + return ESP.getFlashChipSize(); +} + +uint32_t ESP_getSketchSize(void) +{ + static uint32_t sketchsize = 0; + + if (!sketchsize) { + sketchsize = ESP.getSketchSize(); // This takes almost 2 seconds on an ESP32 + } + return sketchsize; } -*/ diff --git a/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.h b/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.h index 1071bfbd1..8a30da55d 100644 --- a/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.h +++ b/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.h @@ -34,13 +34,16 @@ #define ESP_flashReadHeader(offset, data, size) ESP32_flashRead(offset, data, size) #define ESP_flashRead(offset, data, size) ESP32_flashRead(offset, data, size) String ESP_getResetReason(void); -String ESP_getBootVersion(void); +uint32_t ESP_getBootVersion(void); bool ESP_rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size); bool ESP_rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size); void ESP_reset(); String ESP_getResetInfo(void); uint32_t ESP_getFlashChipId(); +uint32_t ESP_getChipId(); String String_ESP_getChipId(); +uint32_t ESP_getFlashChipRealSize(); +uint32_t ESP_getSketchSize(); // Analog inline void analogWrite(uint8_t pin, int val) diff --git a/tasmota/support.ino b/tasmota/support.ino index bb4432d2d..9c720c996 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -562,6 +562,7 @@ char* GetPowerDevice(char* dest, uint32_t idx, size_t size) void GetEspHardwareType(void) { +#ifdef ESP8266 // esptool.py get_efuses uint32_t efuse1 = *(uint32_t*)(0x3FF00050); uint32_t efuse2 = *(uint32_t*)(0x3FF00054); @@ -572,16 +573,23 @@ void GetEspHardwareType(void) if (is_8285 && (ESP.getFlashChipRealSize() > 1048576)) { is_8285 = false; // ESP8285 can only have 1M flash } +#else + is_8285 = false; // ESP8285 can only have 1M flash +#endif } String GetDeviceHardware(void) { char buff[10]; +#ifdef ESP8266 if (is_8285) { strcpy_P(buff, PSTR("ESP8285")); } else { strcpy_P(buff, PSTR("ESP8266EX")); } +#else + strcpy_P(buff, PSTR("ESP32")); +#endif return String(buff); } diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 4efde90ce..383e8d7b5 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -422,7 +422,7 @@ void CmndStatus(void) if ((0 == payload) || (2 == payload)) { Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS2_FIRMWARE "\":{\"" D_JSON_VERSION "\":\"%s%s\",\"" D_JSON_BUILDDATETIME "\":\"%s\",\"" - D_JSON_BOOTVERSION "\":%d,\"" D_JSON_COREVERSION "\":\"" ARDUINO_ESP8266_RELEASE "\",\"" D_JSON_SDKVERSION "\":\"%s\"," + D_JSON_BOOTVERSION "\":%d,\"" D_JSON_COREVERSION "\":\"" ARDUINO_CORE_RELEASE "\",\"" D_JSON_SDKVERSION "\":\"%s\"," "\"Hardware\":\"%s\"" "%s}}"), my_version, my_image, GetBuildDateAndTime().c_str(), @@ -447,8 +447,8 @@ void CmndStatus(void) Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS4_MEMORY "\":{\"" D_JSON_PROGRAMSIZE "\":%d,\"" D_JSON_FREEMEMORY "\":%d,\"" D_JSON_HEAPSIZE "\":%d,\"" D_JSON_PROGRAMFLASHSIZE "\":%d,\"" D_JSON_FLASHSIZE "\":%d,\"" D_JSON_FLASHCHIPID "\":\"%06X\",\"" D_JSON_FLASHMODE "\":%d,\"" D_JSON_FEATURES "\":[\"%08X\",\"%08X\",\"%08X\",\"%08X\",\"%08X\",\"%08X\",\"%08X\"]"), - ESP.getSketchSize()/1024, ESP.getFreeSketchSpace()/1024, ESP.getFreeHeap()/1024, - ESP.getFlashChipSize()/1024, ESP.getFlashChipRealSize()/1024, ESP_getFlashChipId(), ESP.getFlashChipMode(), + ESP_getSketchSize()/1024, ESP.getFreeSketchSpace()/1024, ESP.getFreeHeap()/1024, + ESP.getFlashChipSize()/1024, ESP_getFlashChipRealSize()/1024, ESP_getFlashChipId(), ESP.getFlashChipMode(), LANGUAGE_LCID, feature_drv1, feature_drv2, feature_sns1, feature_sns2, feature5, feature6); XsnsDriverState(); ResponseAppend_P(PSTR(",\"Sensors\":")); diff --git a/tasmota/support_rtc.ino b/tasmota/support_rtc.ino index 3b7da8e37..0b2249ec2 100644 --- a/tasmota/support_rtc.ino +++ b/tasmota/support_rtc.ino @@ -367,7 +367,7 @@ void RtcSecond(void) if ((Rtc.ntp_sync_minute > 59) && (uptime_minute > 2)) { Rtc.ntp_sync_minute = 1; // If sync prepare for a new cycle } - uint8_t offset = (uptime < 30) ? RtcTime.second : (((ESP.getChipId() & 0xF) * 3) + 3) ; // First try ASAP to sync. If fails try once every 60 seconds based on chip id + uint8_t offset = (uptime < 30) ? RtcTime.second : (((ESP_getChipId() & 0xF) * 3) + 3) ; // First try ASAP to sync. If fails try once every 60 seconds based on chip id if ( (((offset == RtcTime.second) && ( (RtcTime.year < 2016) || // Never synced (Rtc.ntp_sync_minute == uptime_minute))) || // Re-sync every hour ntp_force_sync ) ) { // Forced sync diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 44954ca26..f33f35b3d 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -39,14 +39,14 @@ char* Format(char* output, const char* input, int size) char tmp[size]; if (strchr(token, 'd')) { snprintf_P(tmp, size, PSTR("%s%c0%dd"), output, '%', digits); - snprintf_P(output, size, tmp, ESP.getChipId() & 0x1fff); // %04d - short chip ID in dec, like in hostname + snprintf_P(output, size, tmp, ESP_getChipId() & 0x1fff); // %04d - short chip ID in dec, like in hostname } else { snprintf_P(tmp, size, PSTR("%s%c0%dX"), output, '%', digits); - snprintf_P(output, size, tmp, ESP.getChipId()); // %06X - full chip ID in hex + snprintf_P(output, size, tmp, ESP_getChipId()); // %06X - full chip ID in hex } } else { if (strchr(token, 'd')) { - snprintf_P(output, size, PSTR("%s%d"), output, ESP.getChipId()); // %d - full chip ID in dec + snprintf_P(output, size, PSTR("%s%d"), output, ESP_getChipId()); // %d - full chip ID in dec digits = 8; } } @@ -61,10 +61,10 @@ char* Format(char* output, const char* input, int size) char* GetOtaUrl(char *otaurl, size_t otaurl_size) { if (strstr(SettingsText(SET_OTAURL), "%04d") != nullptr) { // OTA url contains placeholder for chip ID - snprintf(otaurl, otaurl_size, SettingsText(SET_OTAURL), ESP.getChipId() & 0x1fff); + snprintf(otaurl, otaurl_size, SettingsText(SET_OTAURL), ESP_getChipId() & 0x1fff); } else if (strstr(SettingsText(SET_OTAURL), "%d") != nullptr) { // OTA url contains placeholder for chip ID - snprintf_P(otaurl, otaurl_size, SettingsText(SET_OTAURL), ESP.getChipId()); + snprintf_P(otaurl, otaurl_size, SettingsText(SET_OTAURL), ESP_getChipId()); } else { strlcpy(otaurl, SettingsText(SET_OTAURL), otaurl_size); @@ -824,6 +824,13 @@ void PerformEverySecond(void) // Wifi keep alive to send Gratuitous ARP wifiKeepAlive(); #endif // ARDUINO_ESP8266_RELEASE_2_3_0 + + +#ifdef ESP32 + if (11 == uptime) { // Perform one-time ESP32 houskeeping + ESP_getSketchSize(); // Init sketchsize as it can take up to 2 seconds + } +#endif } /*-------------------------------------------------------------------------------------------*\ diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index dc4016b59..18c026562 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -655,7 +655,7 @@ void WifiConnect(void) WifiSetOutputPower(); WiFi.persistent(false); // Solve possible wifi init errors Wifi.status = 0; - Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + (ESP.getChipId() & 0xF); // Add extra delay to stop overrun by simultanous re-connects + Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + (ESP_getChipId() & 0xF); // Add extra delay to stop overrun by simultanous re-connects Wifi.retry = Wifi.retry_init; Wifi.counter = 1; diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index e6861ee97..042f1b1d4 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -41,14 +41,14 @@ * Power Type \*********************************************************************************************/ -#ifdef ESP8266 +//#ifdef ESP8266 typedef unsigned long power_t; // Power (Relay) type const uint32_t POWER_MASK = 0xffffffffUL; // Power (Relay) full mask -#endif // ESP8266 -#ifdef ESP32 -typedef uint64_t power_t; // Power (Relay) type -const uint64_t POWER_MASK = 0xffffffffffffffffull; // Power (Relay) full mask -#endif // ESP32 +//#endif // ESP8266 +//#ifdef ESP32 +//typedef uint64_t power_t; // Power (Relay) type +//const uint64_t POWER_MASK = 0xffffffffffffffffull; // Power (Relay) full mask +//#endif // ESP32 /*********************************************************************************************\ * Constants diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 22e33ce72..1a7c250ae 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -276,7 +276,7 @@ void setup(void) Format(mqtt_topic, SettingsText(SET_MQTT_TOPIC), sizeof(mqtt_topic)); if (strstr(SettingsText(SET_HOSTNAME), "%") != nullptr) { SettingsUpdateText(SET_HOSTNAME, WIFI_HOSTNAME); - snprintf_P(my_hostname, sizeof(my_hostname)-1, SettingsText(SET_HOSTNAME), mqtt_topic, ESP.getChipId() & 0x1FFF); + snprintf_P(my_hostname, sizeof(my_hostname)-1, SettingsText(SET_HOSTNAME), mqtt_topic, ESP_getChipId() & 0x1FFF); } else { snprintf_P(my_hostname, sizeof(my_hostname)-1, SettingsText(SET_HOSTNAME)); } @@ -290,7 +290,7 @@ void setup(void) SetPowerOnState(); - AddLog_P2(LOG_LEVEL_INFO, PSTR(D_PROJECT " %s %s " D_VERSION " %s%s-" ARDUINO_ESP8266_RELEASE), PROJECT, SettingsText(SET_FRIENDLYNAME1), my_version, my_image); + AddLog_P2(LOG_LEVEL_INFO, PSTR(D_PROJECT " %s %s " D_VERSION " %s%s-" ARDUINO_CORE_RELEASE), PROJECT, SettingsText(SET_FRIENDLYNAME1), my_version, my_image); #ifdef FIRMWARE_MINIMAL AddLog_P2(LOG_LEVEL_INFO, PSTR(D_WARNING_MINIMAL_VERSION)); #endif // FIRMWARE_MINIMAL diff --git a/tasmota/tasmota_compat.h b/tasmota/tasmota_compat.h index 97777c566..6571d0f34 100644 --- a/tasmota/tasmota_compat.h +++ b/tasmota/tasmota_compat.h @@ -6,7 +6,7 @@ // Modul #undef MODULE #define MODULE WEMOS // [Module] Select default model -#endif +#endif // ESP32 #ifdef ESP8266 // ESP8266 @@ -17,6 +17,9 @@ #define ESP_reset() ESP.reset() #define ESP_getBootVersion() ESP.getBootVersion() #define ESP_getFlashChipId() ESP.getFlashChipId() +#define ESP_getFlashChipRealSize() ESP.getFlashChipRealSize() +#define ESP_getSketchSize() ESP.getSketchSize() +#define ESP_getChipId() ESP.getChipId() // // we need different ESP_flashRead for ESP32 // @@ -28,4 +31,4 @@ // // Serial minimal type to hold the config #define SerConfu8 uint8_t -#endif // ESP32 +#endif // ESP8266 diff --git a/tasmota/tasmota_globals.h b/tasmota/tasmota_globals.h index d05db0efd..9c5cbd8c3 100644 --- a/tasmota/tasmota_globals.h +++ b/tasmota/tasmota_globals.h @@ -117,8 +117,19 @@ extern "C" void resetPins(); #define MESSZ (MQTT_MAX_PACKET_SIZE -TOPSZ -7) // Max number of characters in JSON message string #endif +#ifdef ESP8266 #ifndef ARDUINO_ESP8266_RELEASE -#define ARDUINO_ESP8266_RELEASE "STAGE" +#define ARDUINO_CORE_RELEASE "STAGE" +#else +#define ARDUINO_CORE_RELEASE ARDUINO_ESP8266_RELEASE +#endif +#endif +#ifdef ESP32 +#ifndef ARDUINO_ESP32_RELEASE +#define ARDUINO_CORE_RELEASE "STAGE" +#else +#define ARDUINO_CORE_RELEASE ARDUINO_ESP32_RELEASE +#endif #endif #ifdef USE_PWM_DIMMER_REMOTE diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 0777e15ac..5206b701d 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -2120,7 +2120,7 @@ void HandleInformation(void) WSContentSend_P(PSTR("
")); WSContentSend_P(PSTR(D_PROGRAM_VERSION "}2%s%s"), my_version, my_image); WSContentSend_P(PSTR("}1" D_BUILD_DATE_AND_TIME "}2%s"), GetBuildDateAndTime().c_str()); - WSContentSend_P(PSTR("}1" D_CORE_AND_SDK_VERSION "}2" ARDUINO_ESP8266_RELEASE "/%s"), ESP.getSdkVersion()); + WSContentSend_P(PSTR("}1" D_CORE_AND_SDK_VERSION "}2" ARDUINO_CORE_RELEASE "/%s"), ESP.getSdkVersion()); WSContentSend_P(PSTR("}1" D_UPTIME "}2%s"), GetUptime().c_str()); WSContentSend_P(PSTR("}1" D_FLASH_WRITE_COUNT "}2%d at 0x%X"), Settings.save_flag, GetSettingsAddress()); WSContentSend_P(PSTR("}1" D_BOOT_COUNT "}2%d"), Settings.bootcount); @@ -2195,11 +2195,11 @@ void HandleInformation(void) #endif // USE_DISCOVERY WSContentSend_P(PSTR("}1}2 ")); // Empty line - WSContentSend_P(PSTR("}1" D_ESP_CHIP_ID "}2%d"), ESP.getChipId()); + WSContentSend_P(PSTR("}1" D_ESP_CHIP_ID "}2%d"), ESP_getChipId()); WSContentSend_P(PSTR("}1" D_FLASH_CHIP_ID "}20x%06X"), ESP_getFlashChipId()); - WSContentSend_P(PSTR("}1" D_FLASH_CHIP_SIZE "}2%dkB"), ESP.getFlashChipRealSize() / 1024); + WSContentSend_P(PSTR("}1" D_FLASH_CHIP_SIZE "}2%dkB"), ESP_getFlashChipRealSize() / 1024); WSContentSend_P(PSTR("}1" D_PROGRAM_FLASH_SIZE "}2%dkB"), ESP.getFlashChipSize() / 1024); - WSContentSend_P(PSTR("}1" D_PROGRAM_SIZE "}2%dkB"), ESP.getSketchSize() / 1024); + WSContentSend_P(PSTR("}1" D_PROGRAM_SIZE "}2%dkB"), ESP_getSketchSize() / 1024); WSContentSend_P(PSTR("}1" D_FREE_PROGRAM_SPACE "}2%dkB"), ESP.getFreeSketchSpace() / 1024); WSContentSend_P(PSTR("}1" D_FREE_MEMORY "}2%dkB"), freeMem / 1024); WSContentSend_P(PSTR(" |
---|