常见问题
UI 图片未加载
现象
UI 界面未显示要加载的图片。
原因分析
逐步排除以下原因:
1.Using File System Image 0 与 Using File System Image 1 中打包的资源文件路径是否正确。
2.Using File System Image 0 与 Using File System Image 1 在 image_cfg.json 中对应的分区表配置是否正确。
3.所需要的文件系统的编译选项是否打开,例如:Using File System Image 0 使用 FATFS。
LVGL 线程 TIMEOUT
现象
通过 ps
命令查看线程运行状况,LVGL 显示 TIMEOUT,但 UI 依然在正常运行。
原因分析
通常情况下,TIMEOUT 的显示是因为查看线程状态时,LVGL 刚好休眠,多次使用 ps
命令查看,即可看到 LVGL 线程 OK 的状态。
性能优化
1.增加图片缓存
LVGL 内部的图片缓存机制,可以设置图片缓存张数,缓存越多速度越快,但是占用的内存也会越多,只要没有达到图片缓存张数的上限,新的图片就会在内存中缓存下来,LVGL 在下次使用同样的图片的时候,就不需要重复解码,加快了显示速度。对于 D13x/D12x 平台内存空间有限,图片缓存太多,可能会导致分配不到内存的情况。我们可以在程序中控制释放图片缓存的时机,一般选择释放使用频率不高的图片或者占用过多内存的图片,释放图片缓存的接口:
// 释放对象 img_obj 的图片缓存
lv_img_cache_invalidate_src(lv_img_get_src(img_obj));
// 释放所有的图片缓存,在场景切换时,确定不需要已有的图片缓存可以这么调用
lv_img_cache_invalidate_src(NULL);
2
3
4
5
如下配置中设置了 8 张图片缓存:
Application options --->
* Filesystem related *
[*] Using File System Image 0 --->
[ ] Using File System Image 1 ----
* lvgl demo select related *
-*- LVGL (official): powerful and easy-to-use embedded GUI library --->
-*- ArtInChip lvgl demo
select lvgl demo (lvgl demo with basic function) --->
(X) lvgl demo with basic function
( ) lvgl demo of meter
(16) LVGL color depth(32/16)
(8) LVGL image cached number
(/rodata/lvgl_data) LVGL Resource Directory
2
3
4
5
6
7
8
9
10
11
12
13
2.显示采用 rgb565 格式
显示采用 rgb565 格式和 argb8888 相比减少了处理的数据量,可以提升 UI 的处理速度,需要配置 LVGL color depth 为 16,并且配置 framebuffer 为 rgb565:
Application options --->
* Filesystem related *
[*] Using File System Image 0 --->
[ ] Using File System Image 1 ----
* lvgl demo select related *
-*- LVGL (official): powerful and easy-to-use embedded GUI library --->
-*- ArtInChip lvgl demo
select lvgl demo (lvgl demo with basic function) --->
(X) lvgl demo with basic function
( ) lvgl demo of meter
(16) LVGL color depth(32/16)
(8) LVGL image cached number
(/rodata/lvgl_data) LVGL Resource Directory
2
3
4
5
6
7
8
9
10
11
12
13
Board options --->
[*] Using Display Engine (DE)
Display Parameter --->
select framebuffer format (rgb565) --->
[*] Support double framebuffer
[*] Enable Display Dither
2
3
4
5
6
3.对于不需要透明度的图片可以选择采用 JPG/JPEG 格式图片,JPG 图片的解码速度会比 PNG 速度快。
4.LVGL 的 UI 绘制是单线程的,我们在使用 LVGL 的定时器/动画等接口的时候,要避免在回调函数中执行阻塞时间过久的函数,否则会影响 UI 的流畅性。