}
#else /*LODEPNG_COMPILE_ALLOCATORS*/
/* TODO: support giving additional void* payload to the custom allocators */
+#include "lvgl/lvgl.h"
+
+/* 结构体用于保存每个已分配的内存块的信息 */
+typedef struct {
+ void * ptr;
+} malloc_info_t;
+
+static lv_ll_t malloc_ll;
+static char is_first = 1;
+
+static void my_mem_init(void) {
+ _lv_ll_init(&malloc_ll, sizeof(malloc_info_t));
+}
+
+static void * my_lv_mem_alloc(size_t size) {
+ if(is_first) {
+ is_first = 0;
+ my_mem_init();
+ }
+ void * ptr = malloc(size);
+ if (ptr) {
+ malloc_info_t * info = (malloc_info_t *)_lv_ll_ins_tail(&malloc_ll);
+ info->ptr = ptr;
+ }
+ return ptr;
+}
+
+static void * my_lv_mem_realloc(void * ptr, size_t new_size) {
+ void * new_ptr = realloc(ptr, new_size);
+ if (new_ptr && new_ptr != ptr) {
+ malloc_info_t * info;
+ _LV_LL_READ(&malloc_ll, info) {
+ if (info->ptr == ptr) {
+ info->ptr = new_ptr;
+ break;
+ }
+ }
+ }
+ return new_ptr;
+}
+
+static void my_lv_mem_free(void * ptr) {
+ malloc_info_t * info;
+ _LV_LL_READ(&malloc_ll, info) {
+ if (info->ptr == ptr) {
+ _lv_ll_remove(&malloc_ll, info);
+ return;
+ }
+ }
+ free(ptr);
+}
+
+void my_lodpng_lv_free_all(void) {
+ malloc_info_t * info;
+ _LV_LL_READ(&malloc_ll, info) {
+ free(info->ptr);
+ }
+ _lv_ll_clear(&malloc_ll);
+}
+
+
+
+
void* lodepng_malloc(size_t size) {
- return malloc(size);
+ return my_lv_mem_alloc(size);
}
void* lodepng_realloc(void* ptr, size_t new_size) {
- return realloc(ptr, new_size);
+ return my_lv_mem_realloc(ptr, new_size);
}
void lodepng_free(void* ptr) {
if(ptr)
- free(ptr);
+ my_lv_mem_free(ptr);
}
#endif /*LODEPNG_COMPILE_ALLOCATORS*/
#include "lv_png.h"
#include "lodepng.h"
#include <stdlib.h>
+#include "lv_ll.h"
+
+typedef struct {
+ void * ptr;
+} malloc_info_t;
+
+static lv_ll_t malloc_ll;
+static char is_first = 1;
+
+static void my_mem_init(void) {
+ _lv_ll_init(&malloc_ll, sizeof(malloc_info_t));
+}
+
+static void * my_lv_mem_alloc(size_t size) {
+ if(is_first) {
+ is_first = 0;
+ my_mem_init();
+ }
+ void * ptr = malloc(size);
+ if (ptr) {
+ malloc_info_t * info = (malloc_info_t *)_lv_ll_ins_tail(&malloc_ll);
+ info->ptr = ptr;
+ }
+ return ptr;
+}
+
+static void * my_lv_mem_realloc(void * ptr, size_t new_size) {
+ void * new_ptr = realloc(ptr, new_size);
+ if (new_ptr && new_ptr != ptr) {
+ malloc_info_t * info;
+ _LV_LL_READ(&malloc_ll, info) {
+ if (info->ptr == ptr) {
+ info->ptr = new_ptr;
+ break;
+ }
+ }
+ }
+ return new_ptr;
+}
+
+static void my_lv_mem_free(void * ptr) {
+ malloc_info_t * info;
+ _LV_LL_READ(&malloc_ll, info) {
+ if (info->ptr == ptr) {
+ _lv_ll_remove(&malloc_ll, info);
+ return;
+ }
+ }
+ free(ptr);
+}
+
+void my_png_lv_free_all(void) {
+ malloc_info_t * info;
+ _LV_LL_READ(&malloc_ll, info) {
+ free(info->ptr);
+ }
+ _lv_ll_clear(&malloc_ll);
+}
+
+
+
#undef lv_mem_alloc
-#define lv_mem_alloc malloc
+#define lv_mem_alloc my_lv_mem_alloc
#undef lv_mem_realloc
-#define lv_mem_realloc realloc
+#define lv_mem_realloc my_lv_mem_realloc
static void png_free(void *ptr)
{
if(ptr) {
- free(ptr);
+ my_lv_mem_free(ptr);
ptr = NULL;
}
}
* TYPEDEFS
**********************/
#include <stdlib.h>
+
+
+typedef struct {
+ void * ptr;
+} malloc_info_t;
+
+static lv_ll_t malloc_ll;
+static char is_first = 1;
+
+static void my_mem_init(void) {
+ _lv_ll_init(&malloc_ll, sizeof(malloc_info_t));
+}
+
+static void * my_lv_mem_alloc(size_t size) {
+ if(is_first) {
+ is_first = 0;
+ my_mem_init();
+ }
+ void * ptr = malloc(size);
+ if (ptr) {
+ malloc_info_t * info = (malloc_info_t *)_lv_ll_ins_tail(&malloc_ll);
+ info->ptr = ptr;
+ }
+ return ptr;
+}
+
+static void * my_lv_mem_realloc(void * ptr, size_t new_size) {
+ void * new_ptr = realloc(ptr, new_size);
+ if (new_ptr && new_ptr != ptr) {
+ malloc_info_t * info;
+ _LV_LL_READ(&malloc_ll, info) {
+ if (info->ptr == ptr) {
+ info->ptr = new_ptr;
+ break;
+ }
+ }
+ }
+ return new_ptr;
+}
+
+static void my_lv_mem_free(void * ptr) {
+ malloc_info_t * info;
+ _LV_LL_READ(&malloc_ll, info) {
+ if (info->ptr == ptr) {
+ _lv_ll_remove(&malloc_ll, info);
+ return;
+ }
+ }
+ free(ptr);
+}
+
+void my_sjpg_lv_free_all(void) {
+ malloc_info_t * info;
+ _LV_LL_READ(&malloc_ll, info) {
+ free(info->ptr);
+ }
+ _lv_ll_clear(&malloc_ll);
+}
+
+
+
#undef lv_mem_alloc
-#define lv_mem_alloc malloc
+#define lv_mem_alloc my_lv_mem_alloc
#undef lv_mem_realloc
-#define lv_mem_realloc realloc
+#define lv_mem_realloc my_lv_mem_realloc
static void png_free(void *ptr)
{
if(ptr) {
- free(ptr);
+ my_lv_mem_free(ptr);
ptr = NULL;
}
}
// lv_fs_file_t font_f;
// lv_fs_res_t font_res;
// uint32_t font_resCount;
- uint8_t __g_font_buf[1024];//ÈçbinÎļþ´æÔÚSPI FLASH¿ÉʹÓôËbuff
+ uint8_t __g_font_buf[1024];//如bin文件存在SPI FLASH可使用此buff
}user_font_t;
//forrest.liu@20230217 add for test
}
static uint8_t *__user_font_getdata(user_font_t *font_user, int offset, int size){
- //Èç×ÖÄ£±£´æÔÚSPI FLASH, SPIFLASH_Read(__g_font_buf,offset,size);
+ //如字模保存在SPI FLASH, SPIFLASH_Read(__g_font_buf,offset,size);
/*if(0 == font_mutex1) {
font_mutex1 = Helios_Mutex_Create();
}
lv_fs_file_t font_f;
lv_fs_res_t font_res;
uint32_t font_resCount;
- uint8_t __g_font_buf[1024];//ÈçbinÎļþ´æÔÚSPI FLASH¿ÉʹÓôËbuff
+ uint8_t __g_font_buf[1024];//如bin文件存在SPI FLASH可使用此buff
}user_font_t;
// static uint8_t fontisopen = 0;
static uint8_t *__user_font_getdata(user_font_t *font_user, int offset, int size){
- //Èç×ÖÄ£±£´æÔÚSPI FLASH, SPIFLASH_Read(__g_font_buf,offset,size);
+ //如字模保存在SPI FLASH, SPIFLASH_Read(__g_font_buf,offset,size);
if(0 == font_mutex1) {
font_mutex1 = Helios_Mutex_Create();
}
*/
// args contains, eg: arg0 arg1 key0 value0 key1 value1
-
- static void helios_lv_handler_task()
+extern void my_sjpg_lv_free_all(void);
+extern void my_png_lv_free_all(void);
+extern void my_lodpng_lv_free_all(void);
+ static void helios_lv_handler_task(void)
{
mp_state_thread_t ts;
}
nlr_pop();
} else {
+ my_sjpg_lv_free_all();
+ my_png_lv_free_all();
+ my_lodpng_lv_free_all();
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
}
MP_THREAD_GIL_EXIT();