diff --git a/lib/libesp32/Berry/default/berry_conf.h b/lib/libesp32/Berry/default/berry_conf.h index 1136d0a5c..05c799c6e 100644 --- a/lib/libesp32/Berry/default/berry_conf.h +++ b/lib/libesp32/Berry/default/berry_conf.h @@ -168,22 +168,25 @@ #ifdef __cplusplus extern "C" { #endif - extern void *berry_malloc(uint32_t size); + extern void *berry_malloc(size_t size); + extern void berry_free(void *ptr); extern void *berry_realloc(void *ptr, size_t size); #ifdef __cplusplus } #endif #define BE_EXPLICIT_MALLOC berry_malloc + #define BE_EXPLICIT_FREE berry_free #define BE_EXPLICIT_REALLOC berry_realloc #else #define BE_EXPLICIT_MALLOC malloc + #define BE_EXPLICIT_FREE free #define BE_EXPLICIT_REALLOC realloc #endif // USE_BERRY_PSRAM #define BE_EXPLICIT_ABORT abort #define BE_EXPLICIT_EXIT exit // #define BE_EXPLICIT_MALLOC malloc -#define BE_EXPLICIT_FREE free +// #define BE_EXPLICIT_FREE free // #define BE_EXPLICIT_REALLOC realloc /* Macro: be_assert diff --git a/tasmota/lvgl_berry/tasmota_lv_conf.h b/tasmota/lvgl_berry/tasmota_lv_conf.h index a9eec7018..9aa9e726a 100644 --- a/tasmota/lvgl_berry/tasmota_lv_conf.h +++ b/tasmota/lvgl_berry/tasmota_lv_conf.h @@ -87,7 +87,7 @@ typedef int16_t lv_coord_t; * The graphical objects and other related data are stored here. */ /* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */ -#define LV_MEM_CUSTOM 0 +#define LV_MEM_CUSTOM 1 #if LV_MEM_CUSTOM == 0 /* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/ #ifdef ARDUINO_SAMD_ZERO @@ -106,9 +106,9 @@ typedef int16_t lv_coord_t; /* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */ # define LV_MEM_AUTO_DEFRAG 1 #else /*LV_MEM_CUSTOM*/ -# define LV_MEM_CUSTOM_INCLUDE /*Header for the dynamic memory function*/ -# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/ -# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/ +# define LV_MEM_CUSTOM_INCLUDE /*Header for the dynamic memory function*/ +# define LV_MEM_CUSTOM_ALLOC lvbe_malloc /*Wrapper to malloc*/ /* PSRAM support */ +# define LV_MEM_CUSTOM_FREE lvbe_free /*Wrapper to free*/ #endif /*LV_MEM_CUSTOM*/ /* Use the standard memcpy and memset instead of LVGL's own functions. diff --git a/tasmota/lvgl_berry/tasmota_lv_stdlib.h b/tasmota/lvgl_berry/tasmota_lv_stdlib.h new file mode 100644 index 000000000..67e822eeb --- /dev/null +++ b/tasmota/lvgl_berry/tasmota_lv_stdlib.h @@ -0,0 +1,23 @@ +/* + tasmota_lv_stdlib.h - internationalization for Tasmota + + Copyright (C) 2021 Theo Arends + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +// replacement for used for PSRAM malloc in LVGL + +extern void *lvbe_malloc(size_t size); +extern void lvbe_free(void *ptr); \ No newline at end of file diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 6b05379e0..2864624f8 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -922,6 +922,7 @@ // -- LVGL Graphics Library --------------------------------- //#define USE_LVGL // LVGL Engine, requires Berry, takes 440k of Flash + #define USE_LVGL_PSRAM // Allocate LVGL memory in PSRAM if PSRAM is connected - this might be slightly slower but leaves main memory intact #define USE_LVGL_BG_DEFAULT 0x000000 // Default color for the uninitialized background screen (black) diff --git a/tasmota/support_esp.ino b/tasmota/support_esp.ino index e03d1bdf2..597bcb9d5 100644 --- a/tasmota/support_esp.ino +++ b/tasmota/support_esp.ino @@ -78,6 +78,10 @@ void *special_realloc(void *ptr, size_t size) { return realloc(ptr, size); } +void *special_calloc(size_t num, size_t size) { + return calloc(num, size); +} + String GetDeviceHardware(void) { // esptool.py get_efuses uint32_t efuse1 = *(uint32_t*)(0x3FF00050); @@ -488,6 +492,13 @@ void *special_realloc(void *ptr, size_t size) { return realloc(ptr, size); } } +void *special_calloc(size_t num, size_t size) { + if (psramFound()) { + return heap_caps_calloc(num, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); + } else { + return calloc(num, size); + } +} float CpuTemperature(void) { return ConvertTemp(temperatureRead()); diff --git a/tasmota/xdrv_52_9_berry.ino b/tasmota/xdrv_52_9_berry.ino index 50fd22b97..96ed357a9 100644 --- a/tasmota/xdrv_52_9_berry.ino +++ b/tasmota/xdrv_52_9_berry.ino @@ -63,6 +63,9 @@ extern "C" { void *berry_realloc(void *ptr, size_t size) { return special_realloc(ptr, size); } + void *berry_calloc(size_t num, size_t size) { + return special_calloc(num, size); + } #else void *berry_malloc(uint32_t size) { return malloc(size); @@ -70,8 +73,14 @@ extern "C" { void *berry_realloc(void *ptr, size_t size) { return realloc(ptr, size); } + void *berry_calloc(size_t num, size_t size) { + return calloc(num, size); + } #endif // USE_BERRY_PSRAM + void berry_free(void *ptr) { + free(ptr); + } } diff --git a/tasmota/xdrv_54_lvgl.ino b/tasmota/xdrv_54_lvgl.ino index 14de77984..961b9317c 100644 --- a/tasmota/xdrv_54_lvgl.ino +++ b/tasmota/xdrv_54_lvgl.ino @@ -296,6 +296,48 @@ static lv_fs_res_t lvbe_fs_remove(lv_fs_drv_t * drv, const char *path) { } #endif // USE_UFILESYS +/*********************************************************************************************\ + * Memory handler + * Use PSRAM if available +\*********************************************************************************************/ +extern "C" { + /* + Use the following + + extern void *lvbe_malloc(size_t size); + extern void lvbe_free(void *ptr); + extern void *lvbe_realloc(void *ptr, size_t size); + extern void *lvbe_calloc(size_t num, size_t size); + */ + void *lvbe_malloc(uint32_t size); + void *lvbe_realloc(void *ptr, size_t size); +#ifdef USE_BERRY_PSRAM + void *lvbe_malloc(uint32_t size) { + return special_malloc(size); + } + void *lvbe_realloc(void *ptr, size_t size) { + return special_realloc(ptr, size); + } + void *lvbe_calloc(size_t num, size_t size) { + return special_calloc(num, size); + } +#else // USE_BERRY_PSRAM + void *lvbe_malloc(uint32_t size) { + return malloc(size); + } + void *lvbe_realloc(void *ptr, size_t size) { + return realloc(ptr, size); + } + void *lvbe_calloc(size_t num, size_t size) { + return calloc(num, size); + } +#endif // USE_BERRY_PSRAM + + void lvbe_free(void *ptr) { + free(ptr); + } +} + /************************************************************ * Initialize the display / touchscreen drivers then launch lvgl *