From e44c4ff12a0a30b2de35bdaae32302aaa5bf72a7 Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Fri, 6 Sep 2024 10:17:08 +0200 Subject: [PATCH] upd --- lib/libesp32/berry/generate/be_const_bytes.h | 10 +- .../berry/generate/be_const_bytes_def.h | 10 +- tasmota/Plugins/module_defines.h | 35 ++- tasmota/Plugins/modules_def.h | 35 --- tasmota/Plugins/xdrv_42_i2s.cpp | 33 +- .../tasmota_xdrv_driver/xdrv_123_plugins.ino | 293 +++--------------- variants/tasmota/esp32/pins_arduino.h | 8 +- 7 files changed, 115 insertions(+), 309 deletions(-) diff --git a/lib/libesp32/berry/generate/be_const_bytes.h b/lib/libesp32/berry/generate/be_const_bytes.h index 4994297ae9c7..84baa78cc003 100644 --- a/lib/libesp32/berry/generate/be_const_bytes.h +++ b/lib/libesp32/berry/generate/be_const_bytes.h @@ -1,21 +1,21 @@ /* extern binary arrays */ extern const binstance_arg3 be_const_instance_; -extern const binstance_arg3 be_const_instance_00000001FFF8FFF9FFFAFFFBFFFCFFFD; +extern const binstance_arg3 be_const_instance_0000FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_00030005000A000F00110012FFF8FFF9FFFAFFFBFFFCFFFD; +extern const binstance_arg3 be_const_instance_00000001FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_0000000100020003FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_000000010002000300040005FFF8FFF9FFFAFFFBFFFCFFFD; -extern const binstance_arg3 be_const_instance_0000FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_000000010002FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_000000020003000F0011FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_000000050007000A000B000D000E0017FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_00070008000F400B400CFFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_00000001000200080009FFF8FFF9FFFAFFFBFFFCFFFD; +extern const binstance_arg3 be_const_instance_000000010007FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD; -extern const binstance_arg3 be_const_instance_0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_00030004FFF8FFF9FFFAFFFBFFFCFFFD; -extern const binstance_arg3 be_const_instance_000000010007FFF8FFF9FFFAFFFBFFFCFFFD; -extern const binstance_arg3 be_const_instance_FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_0000000200030004FFF8FFF9FFFAFFFBFFFCFFFD; +extern const binstance_arg3 be_const_instance_0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_00000001000200030004FFF8FFF9FFFAFFFBFFFCFFFD; +extern const binstance_arg3 be_const_instance_FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_000000050007000A000B000C000D000E000F0017FFF8FFF9FFFAFFFBFFFCFFFD; extern const binstance_arg3 be_const_instance_0000000100070008000F4001400AFFF8FFF9FFFAFFFBFFFCFFFD; diff --git a/lib/libesp32/berry/generate/be_const_bytes_def.h b/lib/libesp32/berry/generate/be_const_bytes_def.h index ce5d381d9433..da352bc513b1 100644 --- a/lib/libesp32/berry/generate/be_const_bytes_def.h +++ b/lib/libesp32/berry/generate/be_const_bytes_def.h @@ -1,21 +1,21 @@ /* binary arrays */ be_define_const_bytes_empty(); -be_define_const_bytes(00000001FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); +be_define_const_bytes(0000FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(00030005000A000F00110012FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x03, 0x00, 0x05, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x12, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); +be_define_const_bytes(00000001FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(0000000100020003FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(000000010002000300040005FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); -be_define_const_bytes(0000FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(000000010002FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(000000020003000F0011FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x0F, 0x00, 0x11, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(000000050007000A000B000D000E0017FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x0A, 0x00, 0x0B, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x17, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(00070008000F400B400CFFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x0B, 0x40, 0x0C, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(00000001000200080009FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x08, 0x00, 0x09, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); +be_define_const_bytes(000000010007FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); -be_define_const_bytes(0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x08, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(00030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); -be_define_const_bytes(000000010007FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); -be_define_const_bytes(FFF8FFF9FFFAFFFBFFFCFFFD, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(0000000200030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); +be_define_const_bytes(0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x08, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(00000001000200030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); +be_define_const_bytes(FFF8FFF9FFFAFFFBFFFCFFFD, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(000000050007000A000B000C000D000E000F0017FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x0A, 0x00, 0x0B, 0x00, 0x0C, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x0F, 0x00, 0x17, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); be_define_const_bytes(0000000100070008000F4001400AFFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x01, 0x40, 0x0A, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD); diff --git a/tasmota/Plugins/module_defines.h b/tasmota/Plugins/module_defines.h index 4efc588d0576..41b9f380e512 100644 --- a/tasmota/Plugins/module_defines.h +++ b/tasmota/Plugins/module_defines.h @@ -9,10 +9,41 @@ typedef struct { char *topic; char *data; char *command; -}XdrvMailbox; +} XdrvMailbox; extern void AddLog(uint32_t loglevel, PGM_P formatP, ...); +#ifndef MAX_MOD_STORES +#define MAX_MOD_STORES 4 +#endif + +// this descriptor is in flash so only 32 bit access allowed +#pragma pack(4) +typedef struct { + MD_TYPE sync; + MD_TYPE arch; + MD_TYPE type; + MD_TYPE revision; + char name[16]; + // 32 => 0x20 + int32_t (*mod_func_execute)(uint32_t); + void (*end_of_module)(void); + MD_TYPE size; + // 40 => 0x28 + MD_TYPE execution_offset; + // 44 => 0x2c + MD_TYPE mtv; + MD_TYPE jtab; + // 52 = 0x34 + uint32_t mod_start_org; + int32_t (*mod_func_execute_org)(uint32_t); + + // 56 + MODULE_STORE ms[MAX_MOD_STORES]; +} FLASH_MODULE; + + + #ifdef ESP8266 #define portMUX_TYPE void #endif @@ -476,7 +507,7 @@ extern MODULES_TABLE modules[]; #define ALLOCMEM GET_MTBL; GET_JT; mt->mem_size = sizeof(MODULE_MEMORY);mt->mem_size += mt->mem_size % 4;mt->mod_memory = jcalloc(mt->mem_size / 4, 4);if (!mt->mod_memory) {return -1;};MODULE_MEMORY *mem = (MODULE_MEMORY*)mt->mod_memory;SETTINGS *jsettings = *asettings;FLASH_MODULE *mp = (FLASH_MODULE*)mt->mod_addr; #define RETMEM if (mt->mem_size) {jfree(mt->mod_memory);mt->mem_size = 0;} #define MODULE_DESCRIPTOR(NAME,TYPE,REV,GPIO1,PIN1,GPIO2,PIN2,GPIO3,PIN3,GPIO4,PIN4) __attribute__((section(SECTION_DESC))) extern const FLASH_MODULE MODULE_HEADER = {MODULE_SYNC,CURR_ARCH,(TYPE),(REV),(NAME),mod_func_execute,END_OF_MODULE,0,0,(uint32_t)&modules,(uint32_t)&MODULE_JUMPTABLE,(uint32_t)&module_header,mod_func_execute,{GPIO1,PIN1,GPIO2,PIN2,GPIO3,PIN3,GPIO4,PIN4}}; -#define MODULE_DESCRIPTOR6(NAME,TYPE,REV,GPIO1,PIN1,GPIO2,PIN2,GPIO3,PIN3,GPIO4,PIN4,GPIO5,PIN5,GPIO6,PIN6) __attribute__((section(SECTION_DESC))) extern const FLASH_MODULE MODULE_HEADER = {MODULE_SYNC,CURR_ARCH|MAX_MOD_STORESn<<24,(TYPE),(REV),(NAME),mod_func_execute,END_OF_MODULE,0,0,(uint32_t)&modules,(uint32_t)&MODULE_JUMPTABLE,(uint32_t)&module_header,mod_func_execute,{GPIO1,PIN1,GPIO2,PIN2,GPIO3,PIN3,GPIO4,PIN4,GPIO5,PIN5,GPIO6,PIN6}}; +#define MODULE_DESCRIPTOR6(NAME,TYPE,REV,GPIO1,PIN1,GPIO2,PIN2,GPIO3,PIN3,GPIO4,PIN4,GPIO5,PIN5,GPIO6,PIN6) __attribute__((section(SECTION_DESC))) extern const FLASH_MODULE MODULE_HEADER = {MODULE_SYNC,CURR_ARCH|MAX_MOD_STORES<<24,(TYPE),(REV),(NAME),mod_func_execute,END_OF_MODULE,0,0,(uint32_t)&modules,(uint32_t)&MODULE_JUMPTABLE,(uint32_t)&module_header,mod_func_execute,{GPIO1,PIN1,GPIO2,PIN2,GPIO3,PIN3,GPIO4,PIN4,GPIO5,PIN5,GPIO6,PIN6}}; #define MOD_FUNC(A, ...) A(MODULES_TABLE *mt, ##__VA_ARGS__) //#define MOD_FUNC(A, ...) A(##__VA_ARGS__) diff --git a/tasmota/Plugins/modules_def.h b/tasmota/Plugins/modules_def.h index 18831fc02a9c..e72bb015b915 100644 --- a/tasmota/Plugins/modules_def.h +++ b/tasmota/Plugins/modules_def.h @@ -53,12 +53,8 @@ typedef struct { MOD_FLAGS flags; } MODULES_TABLE; - -//#define EXEC_OFFSET mt->execution_offset - #define EXEC_OFFSET ((FLASH_MODULE*)mt->mod_addr)->execution_offset - #define MD_TYPE uint32_t #define MOD_STORE_NAMESIZE 8 @@ -68,37 +64,6 @@ typedef struct { volatile MD_TYPE value; } MODULE_STORE; -#ifndef MAX_MOD_STORESn -#define MAX_MOD_STORESn 6 -#endif - -#define MAX_MOD_STORES 4 - - -// this descriptor is in .text so only 32 bit access allowed -#pragma pack(4) -typedef struct { - MD_TYPE sync; - MD_TYPE arch; - MD_TYPE type; - MD_TYPE revision; - char name[16]; - // 32 => 0x20 - int32_t (*mod_func_execute)(uint32_t); - void (*end_of_module)(void); - MD_TYPE size; - // 40 => 0x28 - MD_TYPE execution_offset; - // 44 => 0x2c - MD_TYPE mtv; - MD_TYPE jtab; - // 52 = 0x34 - uint32_t mod_start_org; - int32_t (*mod_func_execute_org)(uint32_t); - - // 56 - MODULE_STORE ms[MAX_MOD_STORESn]; -} FLASH_MODULE; enum { temperature_celsius = 0, tele_period, global_update, humidity, uptime, rel_inverted, devices_present diff --git a/tasmota/Plugins/xdrv_42_i2s.cpp b/tasmota/Plugins/xdrv_42_i2s.cpp index f0b43a827fa4..3d97cec17442 100644 --- a/tasmota/Plugins/xdrv_42_i2s.cpp +++ b/tasmota/Plugins/xdrv_42_i2s.cpp @@ -22,6 +22,10 @@ #ifdef USE_I2S_MOD #define XDRV_42 42 +#ifdef ESP32 +#define MAX_MOD_STORES 6 +#endif + #include "module.h" #include "module_defines.h" @@ -31,7 +35,7 @@ #ifdef ESP32 #define USE_MP3_PSRAM #define USE_MP3 -//#define USE_WEBRADIO +#define USE_WEBRADIO // select a codec #define USE_WM8960 @@ -153,6 +157,7 @@ typedef struct { #define I2S_REV 1 << 16 | 5 #ifdef ESP8266 MODULE_DESCRIPTOR(MODNAME, MODULE_TYPE_DRIVER, I2S_REV, "", 0, "", 0, "", 0, "", 0) +//MODULE_DESCRIPTOR6(MODNAME, MODULE_TYPE_DRIVER, I2S_REV, "", 0, "", 0, "", 0, "", 0, "", 0, "", 0) #else //MODULE_DESCRIPTOR(MODNAME, MODULE_TYPE_DRIVER, I2S_REV, "DOUT", GPIO_DOUT, "BCK", GPIO_BCK, "WS", GPIO_WS, "MODE", 0x01000200) MODULE_DESCRIPTOR6(MODNAME, MODULE_TYPE_DRIVER, I2S_REV, "DOUT", GPIO_DOUT, "BCK", GPIO_BCK, "WS", GPIO_WS, "MODE", 0x01000200,"CODEC", 0x01000200,"", 0) @@ -219,7 +224,8 @@ int32_t I2SAudio_Init() { i2sp = i2s_begin(dout_pin, bck_pin, ws_pin, mode); - const int32_t *icp = (const int32_t *) ((uint8_t *)i32_const+EXEC_OFFSET); + // voltile is needed due to by eps8266 asm error + volatile const int32_t *icp = (const int32_t *) ((uint8_t *)i32_const+EXEC_OFFSET); pclamp = icp[0]; mclamp = icp[1]; @@ -794,8 +800,8 @@ void I2sTaskWR(char *url) { } #endif -// i2xwr http://dispatcher.rndfnk.com/hr/hr3/live/mp3/48/stream.mp3 -// i2xwr http://wdr-1live-live.icecast.wdr.de/wdr/1live/live/mp3/128/stream.mp3 +// i2swr http://dispatcher.rndfnk.com/hr/hr3/live/mp3/48/stream.mp3 +// i2swr http://wdr-1live-live.icecast.wdr.de/wdr/1live/live/mp3/128/stream.mp3 void WebRadio(void) { SETREGS @@ -822,13 +828,9 @@ void WebRadio(void) { return; #else - char curr_ip[16]; - - GetHostbyName(url, curr_ip); - - AddLog(LOG_LEVEL_INFO, PSTR("ip = %s"), curr_ip); - - return; + //char curr_ip[16]; + //GetHostbyName(url, curr_ip); + //AddLog(LOG_LEVEL_INFO, PSTR("ip = %s"), curr_ip); if (!wclient) { wclient = New_WiFiClient(); @@ -861,19 +863,22 @@ void WebRadio(void) { AddLog(LOG_LEVEL_INFO, PSTR("WR result: %d"), code); - /* + + uint32_t samplerate=44100; + uint32_t has_bitrate; if (http_hasHeader(http, PSTR("icy-br"))) { char *ret = http_header(http, PSTR("icy-br")); - AddLog(LOG_LEVEL_INFO, PSTR("WR br = %d"),ret); + AddLog(LOG_LEVEL_INFO, PSTR("WR br = %s"),ret); + free(ret); has_bitrate = 1; // ret.toInt(); } else { has_bitrate = 0; } int32_t size = http_getSize(http); -*/ + #endif busy = true; diff --git a/tasmota/tasmota_xdrv_driver/xdrv_123_plugins.ino b/tasmota/tasmota_xdrv_driver/xdrv_123_plugins.ino index be0063e0deff..9b6c166d06c2 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_123_plugins.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_123_plugins.ino @@ -41,6 +41,35 @@ to doo: #define MINREV 0x00010004 #define CURR_MINREV 0x00010005 + + +#define MAX_MOD_STORES 4 +// this descriptor is in flash so only 32 bit access allowed +#pragma pack(4) +typedef struct { + MD_TYPE sync; + MD_TYPE arch; + MD_TYPE type; + MD_TYPE revision; + char name[16]; + // 32 => 0x20 + int32_t (*mod_func_execute)(uint32_t); + void (*end_of_module)(void); + MD_TYPE size; + // 40 => 0x28 + MD_TYPE execution_offset; + // 44 => 0x2c + MD_TYPE mtv; + MD_TYPE jtab; + // 52 = 0x34 + uint32_t mod_start_org; + int32_t (*mod_func_execute_org)(uint32_t); + + // 56 + MODULE_STORE ms[MAX_MOD_STORES]; +} FLASH_MODULE; + + #ifdef EXECUTE_FROM_BINARY extern const FLASH_MODULE module_header; #else @@ -650,7 +679,9 @@ uint32_t tmod_wifi(uint32_t sel, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t char *cp = copyStr((char*)p2); String hd = http->header(cp); free(cp); - return (uint32_t) hd.c_str(); + cp = (char*)malloc(32); + strlcpy(cp, hd.c_str(), 32); + return (uint32_t) cp; } case 42: { @@ -884,6 +915,12 @@ i2s_chan_handle_t tx_handle = (i2s_chan_handle_t)p1; break; case 7: #if defined(ESP32) && ESP_IDF_VERSION_MAJOR >= 5 + /* does not work ??? + uint8_t zero_buffer[240] = {0}; + for (uint32_t i = 0; i < 6; i++) { + i2s_channel_write(tx_handle, zero_buffer, sizeof(zero_buffer), nullptr, 5); // fill DMA buffer with silence + } + */ return i2s_channel_disable(tx_handle); #endif break; @@ -2135,99 +2172,14 @@ uint32_t eeprom_block; return 0; } -//#define OLD_LOADER - - -uint32_t Store_Module(uint8_t *fdesc, uint32_t size, uint32_t *ioffset, uint8_t flag, uint8_t index) { - - //AddLog(LOG_LEVEL_INFO, PSTR("store module size: %d"), size); - - uint16_t block; - uint32_t eeprom_block = Module_CheckFree(size, &block); - if (!eeprom_block) { - return 0; - } - - //AddLog(LOG_LEVEL_INFO, PSTR(" >>>")); - -#ifdef ESP8266 - const FLASH_MODULE *fm = (FLASH_MODULE*)fdesc; - uint32_t new_pc = (uint32_t)eeprom_block + plugins.flashbase; - - uint32_t offset = new_pc - fm->mod_start_org; - uint32_t *lp = (uint32_t*)&fm->execution_offset; - *lp = offset; - - lp = (uint32_t*)&fm->mod_func_execute; - *lp = (uint32_t)fm->mod_func_execute_org + fm->execution_offset;; - - lp = (uint32_t*)&fm->mtv; - *lp = (uint32_t)&modules[index]; - - lp = (uint32_t*)&fm->jtab; - *lp = (uint32_t)&MODULE_JUMPTABLE; - - uint32_t *lwp=(uint32_t*)fdesc; -#endif // ESP8266 - -#ifdef ESP32 - FLASH_MODULE *fm = (FLASH_MODULE*)fdesc; - fm->execution_offset = (uint32_t)eeprom_block - fm->mod_start_org; - - uint32_t *lp = (uint32_t*)&fm->mod_func_execute; - *lp = (uint32_t)fm->mod_func_execute_org + fm->execution_offset; - - fm->mtv = (uint32_t)&modules[index]; - fm->jtab = (uint32_t)&MODULE_JUMPTABLE; - - uint32_t *lwp=(uint32_t*)fdesc; - uint32_t new_pc = eeprom_block; -#endif // ESP32 - -#ifdef ESP8266 -// AddLog(LOG_LEVEL_INFO, PSTR("Module offset %x: %x: %x: %x: %x: %x"),old_pc, new_pc, offset, corr_pc, (uint32_t)fm->mod_func_execute, (uint32_t)&module_header); - uint8_t blocks = (size / SPI_FLASH_SEC_SIZE) + 1; - for (uint8_t cnt = 0; cnt < blocks; cnt++) { - ESP.flashEraseSector(eeprom_block / SPI_FLASH_SEC_SIZE); - ESP.flashWrite(eeprom_block , lwp, SPI_FLASH_SEC_SIZE); - lwp += SPI_FLASH_SEC_SIZE / 4; - eeprom_block += SPI_FLASH_SEC_SIZE; - yield(); - } -#endif // ESP8266 - -#ifdef ESP32 - AddLog(LOG_LEVEL_INFO, PSTR("save module: %08x, size: %d"),eeprom_block, size); - uint32_t offset = eeprom_block - plugins.free_flash_start; - uint8_t blocks = (size / ESP32_PLUGIN_HSIZE) + 1; - for (uint8_t cnt = 0; cnt < blocks; cnt++) { - esp_err_t err = err = esp_partition_erase_range(plugins.flash_pptr, offset, ESP32_PLUGIN_HSIZE); - uint32_t ssize = ESP32_PLUGIN_HSIZE; - if (size < ESP32_PLUGIN_HSIZE) { - ssize = size; - } - err = esp_partition_write(plugins.flash_pptr, offset, (void*)lwp, ssize); - lwp += ESP32_PLUGIN_HSIZE / sizeof(uint32_t); - offset += ESP32_PLUGIN_HSIZE; - size -= ESP32_PLUGIN_HSIZE; - yield(); - //AddLog(LOG_LEVEL_INFO, PSTR("progress: %d"),offset); - } -#endif // ESP32 - return new_pc; -} - -#ifndef OLD_LOADER +// store a single Block to Flash uint32_t Store_Module_Block(uint8_t *fdesc, uint8_t index) { - AddLog(LOG_LEVEL_INFO,PSTR("store: %d"), index); + //AddLog(LOG_LEVEL_INFO,PSTR("store: %d"), index); - //return 0; uint32_t new_pc = 0; uint32_t eeprom_block = plugins.eeprom_start_block; - uint32_t size = SPI_FLASH_SEC_SIZE; - uint32_t *lwp=(uint32_t*)fdesc; if (!plugins.upload_start_block) { @@ -2267,33 +2219,17 @@ uint32_t Store_Module_Block(uint8_t *fdesc, uint8_t index) { #ifdef ESP8266 // AddLog(LOG_LEVEL_INFO, PSTR("Module offset %x: %x: %x: %x: %x: %x"),old_pc, new_pc, offset, corr_pc, (uint32_t)fm->mod_func_execute, (uint32_t)&module_header); - uint8_t blocks = (size / SPI_FLASH_SEC_SIZE) + 1; - for (uint8_t cnt = 0; cnt < blocks; cnt++) { - ESP.flashEraseSector(eeprom_block / SPI_FLASH_SEC_SIZE); - ESP.flashWrite(eeprom_block , lwp, SPI_FLASH_SEC_SIZE); - lwp += SPI_FLASH_SEC_SIZE / 4; - eeprom_block += SPI_FLASH_SEC_SIZE; - yield(); - } + ESP.flashEraseSector(eeprom_block / SPI_FLASH_SEC_SIZE); + ESP.flashWrite(eeprom_block , lwp, SPI_FLASH_SEC_SIZE); + yield(); #endif // ESP8266 #ifdef ESP32 - AddLog(LOG_LEVEL_INFO, PSTR("save module: %08x, size: %d"),eeprom_block, size); + //AddLog(LOG_LEVEL_INFO, PSTR("save module: %08x, size: %d"),eeprom_block, size); uint32_t offset = eeprom_block - plugins.free_flash_start; - uint8_t blocks = (size / ESP32_PLUGIN_HSIZE) + 1; - for (uint8_t cnt = 0; cnt < blocks; cnt++) { - esp_err_t err = err = esp_partition_erase_range(plugins.flash_pptr, offset, ESP32_PLUGIN_HSIZE); - uint32_t ssize = ESP32_PLUGIN_HSIZE; - if (size < ESP32_PLUGIN_HSIZE) { - ssize = size; - } - err = esp_partition_write(plugins.flash_pptr, offset, (void*)lwp, ssize); - lwp += ESP32_PLUGIN_HSIZE / sizeof(uint32_t); - offset += ESP32_PLUGIN_HSIZE; - size -= ESP32_PLUGIN_HSIZE; - yield(); - //AddLog(LOG_LEVEL_INFO, PSTR("progress: %d"),offset); - } + esp_err_t err = err = esp_partition_erase_range(plugins.flash_pptr, offset, ESP32_PLUGIN_HSIZE); + err = esp_partition_write(plugins.flash_pptr, offset, (void*)lwp, ESP32_PLUGIN_HSIZE); + yield(); #endif // ESP32 if (!plugins.upload_start_block) { @@ -2302,9 +2238,6 @@ uint32_t Store_Module_Block(uint8_t *fdesc, uint8_t index) { return new_pc;; } -#endif - - void AddModules(void) { uint16_t module = 0; uint32_t *lp = (uint32_t*) ( plugins.flashbase + plugins.free_flash_start ); @@ -2395,72 +2328,6 @@ void Module_mdir(void) { free(vp); } -void LinkModule(uint8_t *mp, uint32_t size, char *name) { - uint8_t cnt; - const FLASH_MODULE *fm = (FLASH_MODULE*)mp; - - if (mp) { - if (fm->sync != MODULE_SYNC) { - free(mp); - AddLog(LOG_LEVEL_INFO,PSTR("module sync error")); - return; - } - - if ((fm->arch & 0x000000ff) != CURR_ARCH) { - free(mp); - AddLog(LOG_LEVEL_INFO,PSTR("plugin architecture error")); - return; - } - - if (fm->revision < MINREV) { - free(mp); - AddLog(LOG_LEVEL_INFO,PSTR("plugin revision to old")); - return; - } - -/* - if (fm->revision < CURR_MINREV ) { - free(mp); - AddLog(LOG_LEVEL_INFO,PSTR("plugin handler revision to old")); - return; - } - */ - - Unlink_Named_Module(name); - - uint8_t sfree = 0; - for (cnt = 0; cnt < MAX_PLUGINS; cnt++) { - if (!modules[cnt].mod_addr) { - sfree = 1; - break; - } - } - if (!sfree) { - free(mp); - AddLog(LOG_LEVEL_INFO,PSTR("no free slot!")); - return; - } - - uint32_t offset; - -#ifdef ESP32 - modules[cnt].mod_addr = (void *) Store_Module(mp, size, &offset, 1, cnt); - free(mp); -#else - modules[cnt].mod_addr = (void *) Store_Module(mp, size, &offset, 0, cnt); - free(mp); -#endif - - //AddLog(LOG_LEVEL_INFO,PSTR("module stored in flash at: %08x"),modules[cnt].mod_addr); - const FLASH_MODULE *fm = (FLASH_MODULE*)modules[cnt].mod_addr; - modules[cnt].jt = MODULE_JUMPTABLE; - modules[cnt].flags.data = 0; - AddLog(LOG_LEVEL_INFO,PSTR("module %s loaded at slot %d"), name, cnt + 1); - } else { - // error - AddLog(LOG_LEVEL_INFO,PSTR("module error")); - } -} void Unlink_Named_Module(char *name) { @@ -2598,8 +2465,8 @@ void Module_link(void) { if (XdrvMailbox.data_len) { uint32_t size; #ifdef USE_UFILESYS - uint8_t *mp = Load_Module(XdrvMailbox.data, &size); - LinkModule(mp, size, XdrvMailbox.data); + //uint8_t *mp = Load_Module(XdrvMailbox.data, &size); + //LinkModule(mp, size, XdrvMailbox.data); #endif } ResponseCmndDone(); @@ -3231,66 +3098,6 @@ void Module_upload() { Webserver->send(303); } - - -#ifdef OLD_LOADER -bool Module_upload_start(const char* upload_filename) { - strlcpy(plugins.mod_name, upload_filename, sizeof(plugins.mod_name)); - plugins.module_bytes_read = 0; - return true; -} - -bool Module_upload_write(uint8_t *upload_buf, size_t current_size) { - - if (0 == plugins.module_bytes_read) { - // 1. block - FLASH_MODULE *fm = (FLASH_MODULE*)upload_buf; - plugins.module_size = fm->size; - uint32_t size = (fm->size / SPI_FLASH_SEC_SIZE) + 1 ; - size *= SPI_FLASH_SEC_SIZE; - uint16_t block; - plugins.eeprom_start_block = Module_CheckFree(size, &block); - if (!plugins.eeprom_start_block) { - AddLog(LOG_LEVEL_INFO,PSTR("flash slot memory error")); - return false; - } - plugins.module_input_buffer = (uint8_t *)special_malloc(size + 4); - if (!plugins.module_input_buffer) { - AddLog(LOG_LEVEL_INFO,PSTR("memory error")); - return false; - } - plugins.module_input_ptr = plugins.module_input_buffer; - } - - delay(0); - - //AddLog(LOG_LEVEL_INFO,PSTR("progress; %d"),plugins.module_bytes_read); - - if ((plugins.module_size - plugins.module_bytes_read) > current_size) { - memcpy(plugins.module_input_ptr, upload_buf, current_size); - plugins.module_bytes_read += current_size; - plugins.module_input_ptr += current_size; - return true; - } else { - current_size = plugins.module_size - plugins.module_bytes_read; - memcpy(plugins.module_input_ptr, upload_buf, current_size); - plugins.module_bytes_read += current_size; - plugins.module_input_ptr += current_size; - return false; - } -} - -void Module_upload_stop(void) { - if (plugins.module_input_buffer) { - char *cp = strchr(plugins.mod_name, '_'); - if (cp) { - *cp = 0; - } - LinkModule(plugins.module_input_buffer, plugins.module_bytes_read, plugins.mod_name); - } -} - -#else bool Check_Arch(FLASH_MODULE *fm); bool Check_Arch(FLASH_MODULE *fm) { if (fm->sync != MODULE_SYNC) { @@ -3420,8 +3227,6 @@ void Module_upload_stop(void) { free(plugins.module_input_buffer); } } -#endif - void Module_HandleUploadLoop(void) { diff --git a/variants/tasmota/esp32/pins_arduino.h b/variants/tasmota/esp32/pins_arduino.h index 27ecc063483b..3663de76cd4c 100644 --- a/variants/tasmota/esp32/pins_arduino.h +++ b/variants/tasmota/esp32/pins_arduino.h @@ -9,10 +9,10 @@ static const uint8_t RX = 3; static const uint8_t SDA = 21; static const uint8_t SCL = 22; -static const uint8_t SS = 5; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; static const uint8_t A0 = 36; static const uint8_t A3 = 39;