lvgl解析照片的时候出现能显示白框但是no data,证明了lvgl内置的解码器找到了图片。因为是初次使用,不太了解,从lvgl的文件管理系统的fsopen fsread 每一个涉及到的地方都分别抓包,再到lvgl解码器的底层也分别抓包看看哪个数据出现了问题。过程十分繁琐,走了很多坑。 最后发现是lvgl分配空间不足。因为照片是3k的,我申请了100k的空间,所以没有考虑过这个问题。
1.解决方法
lv_conf.h中修改。 #define LV_MEM_SIZE (256 * 1024U) /*[bytes]*/
#if LV_MEM_CUSTOM == 0
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
#define LV_MEM_SIZE (256 * 1024U) /*[bytes]*/
/*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/
#define LV_MEM_ADR 0 /*0: unused*/
/*Instead of an address give a memory allocator that will be called to get a memory pool for LVGL. E.g. my_malloc*/
#if LV_MEM_ADR == 0
#undef LV_MEM_POOL_INCLUDE
#undef LV_MEM_POOL_ALLOC
#endif
芯片的ram空间是很悠闲的 这里最好使用psram 或者 LV_MEM_CUSTOM 将它改为1,让它自己申请空间。
2.建议
2.1打开lvgl调试接口
最好将lv_conf.h的调试信息打开,我上手太急了,一些教程没有看全基础打的不够牢靠。将
#define LV_USE_LOG 1改成1 。空间不足的问题我也是在log里查到的,不启动的话lvgl出问题也不会打印。 开始我也没想到一个3k的照片解析会占用120k空间。
/*Enable the log module*/
#define LV_USE_LOG 1
#if LV_USE_LOG
/*How important log should be added:
*LV_LOG_LEVEL_TRACE A lot of logs to give detailed information
*LV_LOG_LEVEL_INFO 记录重要事件
*LV_LOG_LEVEL_WARN 记录那些本不希望发生但实际上并未发生的事情
cause a problem
*LV_LOG_LEVEL_ERROR 只有关键问题,即系统可能发生故障时
*LV_LOG_LEVEL_USER Only logs added by the user
*LV_LOG_LEVEL_NONE Do not log anything*/
#define LV_LOG_LEVEL LV_LOG_LEVEL_INFO
/*1: Print the log with 'printf';
*0: User need to register a callback with `lv_log_register_print_cb()`*/
#define LV_LOG_PRINTF 1
/*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/
#define LV_LOG_TRACE_MEM 1
#define LV_LOG_TRACE_TIMER 1
#define LV_LOG_TRACE_INDEV 1
#define LV_LOG_TRACE_DISP_REFR 1
#define LV_LOG_TRACE_EVENT 1
#define LV_LOG_TRACE_OBJ_CREATE 1
#define LV_LOG_TRACE_LAYOUT 1
#define LV_LOG_TRACE_ANIM 1
#endif /*LV_USE_LOG*/
2.2 尽可能本地化部署lvgl和其他库。
个人认为espidf提供的组件方便是挺方便的 ,但是没法改底层,有些时候一知半解。就是将项目组装起来对自己的提升也很微小。 并且espidf 的menuconfig非常反人类,就是随便更改一个小参数,重新编译windows下也得五六分钟,如果本地化部署的话就自由快速多了。