参考了韦东山老师的博客,将LVGLv8移植到了粤嵌GEC6818 Linux开发板上。
一、拉取项目源码
git clone -b release/v8.2 https://github.com/lvgl/lvgl.git
git clone https://github.com/lvgl/lv_drivers.git
git clone https://github.com/lvgl/lv_demos.git
git clone https://github.com/lvgl/lv_port_linux_frame_buffer.git
二、新建项目
新建项目文件夹,将之前拉取的lvgl整个文件夹,lvgl_drivers整个文件夹,lv_port_linux_frame_buffer中的main.c和Makefile复制到新建的文件夹中
三、添加配置头文件
将lvgl文件夹中的lv_conf_template.h复制出来并且改名为lv_conf.h,将lv_drivers中的lv_drv_conf_template.h复制出来并且改名为lv_drv_conf.h
四、修改配置文件
1)修改lv_drv_conf.h
-
将第11行的
#if 0
改成#if 1
,用于使能 -
318~324行,将
USE_FBDEV
的值改为1
,使能frame buffer设备,将FBDEV_PATH
改为"/dev/fb0"
-
441~461行,将
USE_EVDEV
使能,并且触控输入设备的名称要根据自己的板子实际情况更改:通常是/dev/input/event0
2)修改lv_conf.h
-
将一开始的
#if 0
改成#if 1
,用于使能 -
修改27行颜色深度
LV_COLOR_DEPTH
,如果板子的显示屏是ARGB
的,就写32 -
49~67行修改显存大小,可以使能
LV_MEM_CUSTOM
自己分配也可以自动分配 -
80行刷新时间
LV_DISP_DEF_REFR_PERIOD
和LV_INDEV_DEF_READ_PERIOD
,鉴于处理器的运算能力可以自己调整 -
搜索fps,可以选择使能
LV_USE_PERF_MONITOR
来打开查看CPU占用和FPS的调试窗口 -
88行
LV_TICK_CUSTOM
的配置,我们选择自己定义一个Tick定时器配置函数,在自己的应用程序中实现:使能
LV_TICK_CUSTOM
为1将
LV_TICK_CUSTOM_INCLUDE
中的"Arduino.h"
改为<stdint.h>
将
LV_TICK_CUSTOM_SYS_TIME_EXPR
中的(millis())
改为(custom_tick_get())
-
因为现在跑的是官方demo,所以去706行将widget例程使能,令
LV_USE_DEMO_WIDGETS
为 1
五、修改main.c
没有将lvgl的demos移植到工程文件中,所以需要将第2行的demos头文件注释掉:
// #include "lvgl/demos/lv_demos.h"
在32行根据自己的屏幕大小修改分辨率
disp_drv.hor_res = 800;
disp_drv.ver_res = 480;
另外我们也没有移植原本的鼠标样式,所以也需要注释掉46行的鼠标:
/*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*/
六、修改触摸屏代码
因为不同厂家板子有区别,有的板子不是单纯读出板子中的xy坐标数据就能用的,比如粤嵌的黑色LCD,读出来的数据有偏移,所以我们要到lvgl代码中进行修改:
查找包含evdev_fd
的代码,发现在evdev.c
中,将in.type == EV_ABS
条件下面的131和137行如下获取屏幕坐标代码:
evdev_root_x = in.value;
evdev_root_y = in.value;
修改为:
evdev_root_x = in.value*800/1024;
evdev_root_y = in.value*480/600;
来修正偏移。
七、修改Makefile
将第4行CC ?= gcc
修改为自己的板子的交叉编译工具链:
CC = arm-linux-gcc
因为没有用鼠标,所以将20行鼠标文件注释掉:
# CSRCS +=$(LVGL_DIR)/mouse_cursor_icon.c
此时如果直接编译,可能会报这样的错误:
arm-linux-gcc.br_real: error: unrecognized command line option ‘-Wshift-negative-value’
Makefile:37: recipe for target '/home/southio/workspace/lvgl_demo/lvgl/demos/keypad_encoder/lv_demo_keypad_encoder.o' failed
make: *** [/home/southio/workspace/lvgl_demo/lvgl/demos/keypad_encoder/lv_demo_keypad_encoder.o] Error 1
这是因为这个工具链不支持这个命令,此时我们ctrl+F
找到这个命令所在行,删掉这个命令中的这个参数,(注意:不要全部删除,不然可能会找不到lvgl.h
),即修改为:
CFLAGS ?= -O3 -g0 -I$(LVGL_DIR)/ -Wall -Wshadow -Wundef -Wmissing-prototypes -Wno-discarded-qualifiers -Wall -Wextra -Wno-unused-function -Wno-error=strict-prototypes -Wpointer-arith -fno-strict-aliasing -Wno-error=cpp -Wuninitialized -Wmaybe-uninitialized -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default -Wreturn-type -Wmultichar -Wformat-security -Wno-ignored-qualifiers -Wno-error=pedantic -Wno-sign-compare -Wno-error=missing-prototypes -Wdouble-promotion -Wclobbered -Wdeprecated -Wempty-body -Wtype-limits -Wstack-usage=2048 -Wno-unused-value -Wno-unused-parameter -Wno-missing-field-initializers -Wuninitialized -Wmaybe-uninitialized -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wpointer-arith -Wno-cast-qual -Wmissing-prototypes -Wunreachable-code -Wno-switch-default -Wreturn-type -Wmultichar -Wno-discarded-qualifiers -Wformat-security -Wno-ignored-qualifiers -Wno-sign-compare -std=c99
这时去编译可能又会发生这样的错误:
In function `smm_acquire':
smm.c:(.text+0xbd0): undefined reference to `shm_open'
smm.c:(.text+0xcd0): undefined reference to `shm_unlink'
collect2: error: ld returned 1 exit status
Makefile:42: recipe for target 'default' failed
make: *** [default] Error 1
这时要在makefile第8行`LDFLAGS ?= -lm
后面加上-lrt
,即:
LDFLAGS ?= -lm -lrt
八、编译
make clean
make -j4
得到的demo文件可以直接放到板子上运行。
如下图,可以看见demo已经成功跑了起来: