一.sdk源码下载路径
1.官方源码下载路径如下:
https://github.com/lvgl/lvgl
git下载方式 git clone https://github.com/lvgl/lvgl.git
2.个人移植好的源码8.2版本下载路径:
链接:https://pan.baidu.com/s/1jyqIennsQpv-RB4RyKvZyg?pwd=c68e
提取码:c68e
注意: 以下的配置均基于个人移植的sdk上修改.
二.编译方法
解压sdk源码后修改Makefile文件,修改如下
直接修改编译器(编译器需要添加进系统的环境变量中)
修改完Makefile文件后直接 make编译
三.配置文件修改说明
配置文件位于sdk根目录下lv_conf.h
1.图层背景透明配置
有些平台的视频层位于UI图层的下方,会导致视频被UI遮挡的情况,此时需要将UI的图层背景设置成透明即可看见视频画面。
配置方法如下:
#define LV_COLOR_SCREEN_TRANSP 1 // 将此选项打开
//代码设置部件背景透明
lv_style_t tTempStyle;
lv_style_init(&tTempStyle);
v_style_set_bg_opa(&tTempStyle, LV_OPA_TRANSP);
lv_obj_add_style(lv_scr_act(), &tTempStyle, 0);
lv_obj_set_size(lv_scr_act(), 1024, 600);
2.本地图片解码显示实现
修改配置如下:
选择系统类型,开启对应的图片解码库
/*API for open, read, etc*/
#define LV_USE_FS_POSIX 1
#if LV_USE_FS_POSIX
#define LV_FS_POSIX_LETTER 'A' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
#define LV_FS_POSIX_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/
#define LV_FS_POSIX_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/
#endif
// 打开图片的解码配置
/*PNG decoder library*/
#define LV_USE_PNG 1
/*BMP decoder library*/
#define LV_USE_BMP 1
/* JPG + split JPG decoder library.
* Split JPG is a custom format optimized for embedded systems. */
#define LV_USE_SJPG 1
/*GIF decoder library*/
#define LV_USE_GIF 1
默认情况下使用的是固定内存的分配,解码大图片的时候会出错,需要修改配置文件如下:
// 打开如下配置,使用系统动态分配
/*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/
#define LV_MEM_CUSTOM 1
显示的图片的代码案例:
lv_obj_t *pTempImg = lv_img_create(lv_scr_act());
// lv_img_set_src(pTempImg, "A:./png_decoder_test.png"); // 加载png图片
lv_img_set_src(pTempImg, "A:/customer/bg1024_600.jpg");
// 加载jpg图片
lv_img_t *img = (lv_img_t *)pTempImg;
printf("Jamon ==>> img w=%d, h=%d\n", img->w, img->h);
lv_obj_set_size(pTempImg, img->w, img->h);
lv_obj_set_pos(pTempImg, 0, 0);
3.打开log调试,并使用printf输出
修改配置如下:
/*Enable the log module*/
#define LV_USE_LOG 1 // 开启log
#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 Log important events
*LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem
*LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
*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_WARN // 输出级别
/*1: Print the log with 'printf';
*0: User need to register a callback with `lv_log_register_print_cb()`*/
#define LV_LOG_PRINTF 1 // 使用系统函数printf输出
/*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*/