LVGL移植到IMX6ULL笔记
所需库文件及版本问题
所需库文件及版本如下:
| 库文件 | 版本 | 仓库地址 | 描述 |
|---|---|---|---|
| lv_port_linux_frame_buffer | release/v8.2 | https://github.com/lvgl/lv_port_linux.git | 适配有frame buffer的linux系统的接口 |
| lv_drivers | release/v8.2(49c4b17) | https://github.com/lvgl/lv_drivers.git | 包含了驱动LVGL图形界面的驱动接口源代码 |
| lvgl | release/v8.2.0(0b5a1d4) | https://github.com/lvgl/lvgl.git | LVGL图形库源代码,包含所需demo |
| 注意一定要版本对应,不然会出现各种稀奇古怪的问题,可以使用下面的方法下载特定版本: |
选择对应版本后,选择
Download ZIP使用git命令克隆特定版本
先git整个仓库
1
git clone https://github.com/lvgl/lvgl.git
然后切换到对应版本
1
git checkout v8.2.0
移植文件
将上述下载到的lv_drivers lvgl 和 lv_port_linux_frame_buffer中 main.c和 Makefile文件的 放在同一目录下,比如我放在了新建的lvgl_demo目录下。
将lvgl_demo/lvgl/lv_conf_template.h复制到lvgl_demo/下并且改名位lvgl_demo/lv_conf.h
将lvgl_demo/lv_drivers/lv_drv_conf_template.h复制到lvgl_demo/下并且改名位lvgl_demo/lv_drv_conf.h
此时查看
1 | book@100ask:~/Desktop/lvgl_demo2$ ls |
此时目录结构为:
1 | lvgl_demo |
二级目录使用tree -L 2查看我的lvgl_demo目录结构如下:
1 | lvgl_demo |
修改配置文件
修改lv_drv_conf.h
- 使能驱动
将#if 1 /*Set it to "1" to enable the content*/改为#if 1 /*Set it to "1" to enable the content*/ - 使能frame buffer设备,将USE_FBDEV的值改为1
1
2
3
4
5
6
7
8
9
10/*-----------------------------------------
* Linux frame buffer device (/dev/fbx)
*-----------------------------------------*/ - 使能USE_EVDEV,将/dev/input/event0改为/dev/input/event1,这里是使触摸设备生效
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16/*-------------------------------------------------
* Mouse or touchpad as evdev interface (for Linux based systems)
*------------------------------------------------*/
修改lv_conf.h
- 使能,这里和上述步骤相同
将#if 1 /*Set it to "1" to enable the content*/改为#if 1 /*Set it to "1" to enable the content*/ - 修改显存大小
可以使能LV_MEM_CUSTOM自己分配也可以自动分配,我选择的是自己分配显存:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20/*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
/*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/
/*Instead of an address give a memory allocator that will be called to get a memory pool for LVGL. E.g. my_malloc*/
//#define LV_MEM_POOL_INCLUDE your_alloc_library /* Uncomment if using an external allocator*/
//#define LV_MEM_POOL_ALLOC your_alloc /* Uncomment if using an external allocator*/
- 刷新时间
可修改可以不修改,记录说明这里可以按需修改1
2
3
4
5
6
7
8
9
10/*====================
HAL SETTINGS
*====================*/
/*Default display refresh period. LVG will redraw changed areas with this period time*/
/*Input device read period in milliseconds*/
- TICK的配置
这里选择自己定义一个Tick定时器配置函数,更改后的配置如下:1
2
3
4
5
6
7
8/*Use a custom tick source that tells the elapsed time in milliseconds.
*It removes the need to manually update the tick with `lv_tick_inc()`)*/
uint32_t custom_tick_get(void); - LV_COLOR_DEPTH设置颜色深度设置为32位,容易遗忘的设置,否则lvgl颜色显示不正常
1
2
3
4
5
6
7
8
9/*====================
COLOR SETTINGS
*====================*/
/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/
/*Swap the 2 bytes of RGB565 color. Useful if the display has an 8-bit interface (e.g. SPI)*/ - 使能相应的demo模板
这里使用的是LV_USE_DEMO_WIDGETS1
2
3
4
5
6
7
8
9/*===================
* DEMO USAGE
====================*/
/*Show some widget. It might be required to increase `LV_MEM_SIZE` */
修改main.c
- 修改显示器分辨率
1
2disp_drv.hor_res = 1024;
disp_drv.ver_res = 600; - 注释鼠标输入
1
2
3
4
5/*Set a cursor for the mouse*/
// LV_IMG_DECLARE(mouse_cursor_icon)
// lv_obj_t * cursor_obj = lv_img_create(lv_scr_act()); /*Create an image object for the cursor */
// lv_img_set_src(cursor_obj, &mouse_cursor_icon); /*Set the image source*/
// lv_indev_set_cursor(mouse_indev, cursor_obj); /*Connect the image object to the driver*/ - 注释其他不需要的地方,防止编译不通过,比如:
// #include "lvgl/demos/lv_demos.h"
到这里main函数就修改完了,注意到main.c中就有custom_tick_get实现,其他可以按需修改
完整的main.c代码如下:
1 |
|
Makefile配置
- 修改了交叉编译工具链为:
CC := arm-buildroot-linux-gnueabihf-gcc.
使用echo $CROSS_COMPILE可以查看交叉编译链是什么
- 将鼠标样式的连接源文件注释掉
# CSRCS +=$(LVGL_DIR)/mouse_cursor_icon.c
完整的Makefile如下:
1 | # |
运行和结果
使用make编译后,将生成demo可执行文件。然后通过mount挂载,将编译好的demo放到开发板的/mnt/目录下
开发板上切换到/mnt目录,执行.demo运行
结果




注意事项
1.注意版本一致,不然容易出现各种各样稀奇古怪的问题,有可能无法编译。我甚至遇到过编译成功之后出来的可执行文件是64位的,而开发板是32位的,导致无法运行。
2.修改配置或者源码之后,如果不是预期的效果,可以试试先make clean,然后再make。