mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 04:36:31 +00:00
Consolidate ESP specific functions
This commit is contained in:
parent
d178b0e021
commit
b073905a2e
@ -713,44 +713,6 @@ char* GetPowerDevice(char* dest, uint32_t idx, size_t size)
|
|||||||
return GetPowerDevice(dest, idx, size, 0);
|
return GetPowerDevice(dest, idx, size, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetEspHardwareType(void)
|
|
||||||
{
|
|
||||||
#ifdef ESP8266
|
|
||||||
// esptool.py get_efuses
|
|
||||||
uint32_t efuse1 = *(uint32_t*)(0x3FF00050);
|
|
||||||
uint32_t efuse2 = *(uint32_t*)(0x3FF00054);
|
|
||||||
// uint32_t efuse3 = *(uint32_t*)(0x3FF00058);
|
|
||||||
// uint32_t efuse4 = *(uint32_t*)(0x3FF0005C);
|
|
||||||
|
|
||||||
TasmotaGlobal.is_8285 = ( (efuse1 & (1 << 4)) || (efuse2 & (1 << 16)) );
|
|
||||||
if (TasmotaGlobal.is_8285 && (ESP.getFlashChipRealSize() > 1048576)) {
|
|
||||||
TasmotaGlobal.is_8285 = false; // ESP8285 can only have 1M flash
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
TasmotaGlobal.is_8285 = false; // ESP8285 can only have 1M flash
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
String GetDeviceHardware(void)
|
|
||||||
{
|
|
||||||
char buff[10];
|
|
||||||
#ifdef ESP8266
|
|
||||||
if (TasmotaGlobal.is_8285) {
|
|
||||||
strcpy_P(buff, PSTR("ESP8285"));
|
|
||||||
} else {
|
|
||||||
strcpy_P(buff, PSTR("ESP8266EX"));
|
|
||||||
}
|
|
||||||
#endif // ESP8266
|
|
||||||
#ifdef ESP32
|
|
||||||
#if CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2
|
|
||||||
strcpy_P(buff, PSTR("ESP32-S2"));
|
|
||||||
#else
|
|
||||||
strcpy_P(buff, PSTR("ESP32"));
|
|
||||||
#endif // CONFIG_IDF_TARGET_ESP32S2
|
|
||||||
#endif // ESP32
|
|
||||||
return String(buff);
|
|
||||||
}
|
|
||||||
|
|
||||||
float ConvertTemp(float c)
|
float ConvertTemp(float c)
|
||||||
{
|
{
|
||||||
float result = c;
|
float result = c;
|
||||||
@ -1585,7 +1547,6 @@ uint32_t ValidPin(uint32_t pin, uint32_t gpio) {
|
|||||||
return GPIO_NONE; // Disable flash pins GPIO6, GPIO7, GPIO8 and GPIO11
|
return GPIO_NONE; // Disable flash pins GPIO6, GPIO7, GPIO8 and GPIO11
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (!TasmotaGlobal.is_8285 && !Settings.flag3.user_esp8285_enable) { // SetOption51 - Enable ESP8285 user GPIO's
|
|
||||||
if ((WEMOS == Settings.module) && !Settings.flag3.user_esp8285_enable) { // SetOption51 - Enable ESP8285 user GPIO's
|
if ((WEMOS == Settings.module) && !Settings.flag3.user_esp8285_enable) { // SetOption51 - Enable ESP8285 user GPIO's
|
||||||
if ((9 == pin) || (10 == pin)) {
|
if ((9 == pin) || (10 == pin)) {
|
||||||
return GPIO_NONE; // Disable possible flash GPIO9 and GPIO10
|
return GPIO_NONE; // Disable possible flash GPIO9 and GPIO10
|
||||||
@ -2312,28 +2273,3 @@ String Decompress(const char * compressed, size_t uncompressed_size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // USE_UNISHOX_COMPRESSION
|
#endif // USE_UNISHOX_COMPRESSION
|
||||||
|
|
||||||
/*********************************************************************************************\
|
|
||||||
* High entropy hardware random generator
|
|
||||||
* Thanks to DigitalAlchemist
|
|
||||||
\*********************************************************************************************/
|
|
||||||
// Based on code from https://raw.githubusercontent.com/espressif/esp-idf/master/components/esp32/hw_random.c
|
|
||||||
uint32_t HwRandom(void) {
|
|
||||||
#if ESP8266
|
|
||||||
// https://web.archive.org/web/20160922031242/http://esp8266-re.foogod.com/wiki/Random_Number_Generator
|
|
||||||
#define _RAND_ADDR 0x3FF20E44UL
|
|
||||||
#endif // ESP8266
|
|
||||||
#ifdef ESP32
|
|
||||||
#define _RAND_ADDR 0x3FF75144UL
|
|
||||||
#endif // ESP32
|
|
||||||
static uint32_t last_ccount = 0;
|
|
||||||
uint32_t ccount;
|
|
||||||
uint32_t result = 0;
|
|
||||||
do {
|
|
||||||
ccount = ESP.getCycleCount();
|
|
||||||
result ^= *(volatile uint32_t *)_RAND_ADDR;
|
|
||||||
} while (ccount - last_ccount < 64);
|
|
||||||
last_ccount = ccount;
|
|
||||||
return result ^ *(volatile uint32_t *)_RAND_ADDR;
|
|
||||||
#undef _RAND_ADDR
|
|
||||||
}
|
|
||||||
|
@ -484,8 +484,7 @@ void CmndStatus(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((0 == payload) || (4 == payload)) {
|
if ((0 == payload) || (4 == payload)) {
|
||||||
float freeMem = ESP_getFreeHeap1024();
|
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS4_MEMORY "\":{\"" D_JSON_PROGRAMSIZE "\":%d,\"" D_JSON_FREEMEMORY "\":%d,\"" D_JSON_HEAPSIZE "\":%d,\""
|
||||||
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS4_MEMORY "\":{\"" D_JSON_PROGRAMSIZE "\":%d,\"" D_JSON_FREEMEMORY "\":%d,\"" D_JSON_HEAPSIZE "\":%1_f,\""
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
D_JSON_PSRMAXMEMORY "\":%d,\"" D_JSON_PSRFREEMEMORY "\":%d,\""
|
D_JSON_PSRMAXMEMORY "\":%d,\"" D_JSON_PSRFREEMEMORY "\":%d,\""
|
||||||
#endif // ESP32
|
#endif // ESP32
|
||||||
@ -494,7 +493,7 @@ void CmndStatus(void)
|
|||||||
",\"" D_JSON_FLASHCHIPID "\":\"%06X\""
|
",\"" D_JSON_FLASHCHIPID "\":\"%06X\""
|
||||||
#endif // ESP8266
|
#endif // ESP8266
|
||||||
",\"FlashFrequency\":%d,\"" D_JSON_FLASHMODE "\":%d"),
|
",\"FlashFrequency\":%d,\"" D_JSON_FLASHMODE "\":%d"),
|
||||||
ESP_getSketchSize()/1024, ESP.getFreeSketchSpace()/1024, &freeMem,
|
ESP_getSketchSize()/1024, ESP.getFreeSketchSpace()/1024, ESP_getFreeHeap1024(),
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
ESP.getPsramSize()/1024, ESP.getFreePsram()/1024,
|
ESP.getPsramSize()/1024, ESP.getFreePsram()/1024,
|
||||||
#endif // ESP32
|
#endif // ESP32
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
support_esp32.ino - ESP32 specific code for Tasmota
|
support_esp.ino - ESP specific code for Tasmota
|
||||||
|
|
||||||
Copyright (C) 2021 Theo Arends / Jörg Schüler-Maroldt
|
Copyright (C) 2021 Theo Arends / Jörg Schüler-Maroldt
|
||||||
|
|
||||||
@ -17,6 +17,12 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*********************************************************************************************\
|
||||||
|
* ESP8266 and ESP32 specific code
|
||||||
|
*
|
||||||
|
* At the end the common Tasmota calls are provided
|
||||||
|
\*********************************************************************************************/
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* ESP8266 Support
|
* ESP8266 Support
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
@ -47,10 +53,6 @@ uint32_t ESP_getFreeHeap(void) {
|
|||||||
return ESP.getFreeHeap();
|
return ESP.getFreeHeap();
|
||||||
}
|
}
|
||||||
|
|
||||||
float ESP_getFreeHeap1024(void) {
|
|
||||||
return ((float)ESP_getFreeHeap()) / 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ESP_Restart(void) {
|
void ESP_Restart(void) {
|
||||||
// ESP.restart(); // This results in exception 3 on restarts on core 2.3.0
|
// ESP.restart(); // This results in exception 3 on restarts on core 2.3.0
|
||||||
ESP.reset();
|
ESP.reset();
|
||||||
@ -415,10 +417,6 @@ uint32_t ESP_getFreeHeap(void) {
|
|||||||
return ESP.getFreeHeap();
|
return ESP.getFreeHeap();
|
||||||
}
|
}
|
||||||
|
|
||||||
float ESP_getFreeHeap1024(void) {
|
|
||||||
return ((float)ESP_getFreeHeap()) / 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t ESP_getMaxAllocHeap(void) {
|
uint32_t ESP_getMaxAllocHeap(void) {
|
||||||
// largest block of heap that can be allocated at once
|
// largest block of heap that can be allocated at once
|
||||||
uint32_t free_block_size = ESP.getMaxAllocHeap();
|
uint32_t free_block_size = ESP.getMaxAllocHeap();
|
||||||
@ -465,3 +463,72 @@ void *special_malloc(uint32_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // ESP32
|
#endif // ESP32
|
||||||
|
|
||||||
|
/*********************************************************************************************\
|
||||||
|
* ESP Support
|
||||||
|
\*********************************************************************************************/
|
||||||
|
|
||||||
|
String GetDeviceHardware(void) {
|
||||||
|
char buff[10];
|
||||||
|
#ifdef ESP8266
|
||||||
|
// esptool.py get_efuses
|
||||||
|
uint32_t efuse1 = *(uint32_t*)(0x3FF00050);
|
||||||
|
uint32_t efuse2 = *(uint32_t*)(0x3FF00054);
|
||||||
|
// uint32_t efuse3 = *(uint32_t*)(0x3FF00058);
|
||||||
|
// uint32_t efuse4 = *(uint32_t*)(0x3FF0005C);
|
||||||
|
|
||||||
|
bool is_8285 = ( (efuse1 & (1 << 4)) || (efuse2 & (1 << 16)) );
|
||||||
|
if (is_8285 && (ESP.getFlashChipRealSize() > 1048576)) {
|
||||||
|
is_8285 = false; // ESP8285 can only have 1M flash
|
||||||
|
}
|
||||||
|
if (is_8285) {
|
||||||
|
strcpy_P(buff, PSTR("ESP8285"));
|
||||||
|
} else {
|
||||||
|
strcpy_P(buff, PSTR("ESP8266EX"));
|
||||||
|
}
|
||||||
|
#endif // ESP8266
|
||||||
|
|
||||||
|
#ifdef ESP32
|
||||||
|
#if CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2
|
||||||
|
strcpy_P(buff, PSTR("ESP32-S2"));
|
||||||
|
#else
|
||||||
|
strcpy_P(buff, PSTR("ESP32"));
|
||||||
|
#endif // CONFIG_IDF_TARGET_ESP32S2
|
||||||
|
#endif // ESP32
|
||||||
|
|
||||||
|
return String(buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ESP_getFreeHeap1024(void) {
|
||||||
|
return ESP_getFreeHeap() / 1024;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
float ESP_getFreeHeap1024(void) {
|
||||||
|
return ((float)ESP_getFreeHeap()) / 1024;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*********************************************************************************************\
|
||||||
|
* High entropy hardware random generator
|
||||||
|
* Thanks to DigitalAlchemist
|
||||||
|
\*********************************************************************************************/
|
||||||
|
// Based on code from https://raw.githubusercontent.com/espressif/esp-idf/master/components/esp32/hw_random.c
|
||||||
|
uint32_t HwRandom(void) {
|
||||||
|
#if ESP8266
|
||||||
|
// https://web.archive.org/web/20160922031242/http://esp8266-re.foogod.com/wiki/Random_Number_Generator
|
||||||
|
#define _RAND_ADDR 0x3FF20E44UL
|
||||||
|
#endif // ESP8266
|
||||||
|
#ifdef ESP32
|
||||||
|
#define _RAND_ADDR 0x3FF75144UL
|
||||||
|
#endif // ESP32
|
||||||
|
static uint32_t last_ccount = 0;
|
||||||
|
uint32_t ccount;
|
||||||
|
uint32_t result = 0;
|
||||||
|
do {
|
||||||
|
ccount = ESP.getCycleCount();
|
||||||
|
result ^= *(volatile uint32_t *)_RAND_ADDR;
|
||||||
|
} while (ccount - last_ccount < 64);
|
||||||
|
last_ccount = ccount;
|
||||||
|
return result ^ *(volatile uint32_t *)_RAND_ADDR;
|
||||||
|
#undef _RAND_ADDR
|
||||||
|
}
|
@ -658,7 +658,6 @@ void MqttShowPWMState(void)
|
|||||||
void MqttShowState(void)
|
void MqttShowState(void)
|
||||||
{
|
{
|
||||||
char stemp1[TOPSZ];
|
char stemp1[TOPSZ];
|
||||||
float freeMem = ESP_getFreeHeap1024();
|
|
||||||
|
|
||||||
ResponseAppendTime();
|
ResponseAppendTime();
|
||||||
ResponseAppend_P(PSTR(",\"" D_JSON_UPTIME "\":\"%s\",\"UptimeSec\":%u"), GetUptime().c_str(), UpTime());
|
ResponseAppend_P(PSTR(",\"" D_JSON_UPTIME "\":\"%s\",\"UptimeSec\":%u"), GetUptime().c_str(), UpTime());
|
||||||
@ -670,8 +669,8 @@ void MqttShowState(void)
|
|||||||
#endif // USE_ADC_VCC
|
#endif // USE_ADC_VCC
|
||||||
#endif // ESP8266
|
#endif // ESP8266
|
||||||
|
|
||||||
ResponseAppend_P(PSTR(",\"" D_JSON_HEAPSIZE "\":%1_f,\"SleepMode\":\"%s\",\"Sleep\":%u,\"LoadAvg\":%u,\"MqttCount\":%u"),
|
ResponseAppend_P(PSTR(",\"" D_JSON_HEAPSIZE "\":%d,\"SleepMode\":\"%s\",\"Sleep\":%u,\"LoadAvg\":%u,\"MqttCount\":%u"),
|
||||||
&freeMem, GetTextIndexed(stemp1, sizeof(stemp1), Settings.flag3.sleep_normal, kSleepMode), // SetOption60 - Enable normal sleep instead of dynamic sleep
|
ESP_getFreeHeap1024(), GetTextIndexed(stemp1, sizeof(stemp1), Settings.flag3.sleep_normal, kSleepMode), // SetOption60 - Enable normal sleep instead of dynamic sleep
|
||||||
TasmotaGlobal.sleep, TasmotaGlobal.loop_load_avg, MqttConnectCount());
|
TasmotaGlobal.sleep, TasmotaGlobal.loop_load_avg, MqttConnectCount());
|
||||||
|
|
||||||
for (uint32_t i = 1; i <= TasmotaGlobal.devices_present; i++) {
|
for (uint32_t i = 1; i <= TasmotaGlobal.devices_present; i++) {
|
||||||
|
@ -142,7 +142,6 @@ struct {
|
|||||||
bool pwm_present; // Any PWM channel configured with SetOption15 0
|
bool pwm_present; // Any PWM channel configured with SetOption15 0
|
||||||
bool i2c_enabled; // I2C configured
|
bool i2c_enabled; // I2C configured
|
||||||
bool ntp_force_sync; // Force NTP sync
|
bool ntp_force_sync; // Force NTP sync
|
||||||
bool is_8285; // Hardware device ESP8266EX (0) or ESP8285 (1)
|
|
||||||
bool skip_light_fade; // Temporarily skip light fading
|
bool skip_light_fade; // Temporarily skip light fading
|
||||||
bool restart_halt; // Do not restart but stay in wait loop
|
bool restart_halt; // Do not restart but stay in wait loop
|
||||||
bool module_changed; // Indicate module changed since last restart
|
bool module_changed; // Indicate module changed since last restart
|
||||||
@ -334,7 +333,6 @@ void setup(void) {
|
|||||||
snprintf_P(TasmotaGlobal.hostname, sizeof(TasmotaGlobal.hostname)-1, SettingsText(SET_HOSTNAME));
|
snprintf_P(TasmotaGlobal.hostname, sizeof(TasmotaGlobal.hostname)-1, SettingsText(SET_HOSTNAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
GetEspHardwareType();
|
|
||||||
GpioInit();
|
GpioInit();
|
||||||
|
|
||||||
WifiConnect();
|
WifiConnect();
|
||||||
|
@ -2066,8 +2066,6 @@ void HandleInformation(void)
|
|||||||
|
|
||||||
char stopic[TOPSZ];
|
char stopic[TOPSZ];
|
||||||
|
|
||||||
float freeMem = ESP_getFreeHeap1024();
|
|
||||||
|
|
||||||
WSContentStart_P(PSTR(D_INFORMATION));
|
WSContentStart_P(PSTR(D_INFORMATION));
|
||||||
// Save 1k of code space replacing table html with javascript replace codes
|
// Save 1k of code space replacing table html with javascript replace codes
|
||||||
// }1 = </td></tr><tr><th>
|
// }1 = </td></tr><tr><th>
|
||||||
@ -2183,13 +2181,13 @@ void HandleInformation(void)
|
|||||||
WSContentSend_P(PSTR("}1" D_FREE_PROGRAM_SPACE "}2%d kB"), ESP.getFreeSketchSpace() / 1024);
|
WSContentSend_P(PSTR("}1" D_FREE_PROGRAM_SPACE "}2%d kB"), ESP.getFreeSketchSpace() / 1024);
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
int32_t freeMaxMem = 100 - (int32_t)(ESP_getMaxAllocHeap() * 100 / ESP_getFreeHeap());
|
int32_t freeMaxMem = 100 - (int32_t)(ESP_getMaxAllocHeap() * 100 / ESP_getFreeHeap());
|
||||||
WSContentSend_P(PSTR("}1" D_FREE_MEMORY "}2%1_f kB (" D_FRAGMENTATION " %d%%)"), &freeMem, freeMaxMem);
|
WSContentSend_P(PSTR("}1" D_FREE_MEMORY "}2%d kB (" D_FRAGMENTATION " %d%%)"), ESP_getFreeHeap1024(), freeMaxMem);
|
||||||
if (psramFound()) {
|
if (psramFound()) {
|
||||||
WSContentSend_P(PSTR("}1" D_PSR_MAX_MEMORY "}2%d kB"), ESP.getPsramSize() / 1024);
|
WSContentSend_P(PSTR("}1" D_PSR_MAX_MEMORY "}2%d kB"), ESP.getPsramSize() / 1024);
|
||||||
WSContentSend_P(PSTR("}1" D_PSR_FREE_MEMORY "}2%d kB"), ESP.getFreePsram() / 1024);
|
WSContentSend_P(PSTR("}1" D_PSR_FREE_MEMORY "}2%d kB"), ESP.getFreePsram() / 1024);
|
||||||
}
|
}
|
||||||
#else // ESP32
|
#else // ESP32
|
||||||
WSContentSend_P(PSTR("}1" D_FREE_MEMORY "}2%1_f kB"), &freeMem);
|
WSContentSend_P(PSTR("}1" D_FREE_MEMORY "}2%d kB"), ESP_getFreeHeap1024());
|
||||||
#endif // ESP32
|
#endif // ESP32
|
||||||
WSContentSend_P(PSTR("</td></tr></table>"));
|
WSContentSend_P(PSTR("</td></tr></table>"));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user