LVGL 在framebuffer设备上的移植
| Item | Desc | 
|---|---|
| Date | 2023-12-31 | 
| Author | hongxi.zhu | 
| platform | NXP I.MX6ULL | 
| LCD | SPI TFTLCD NV3030B | 
文章目录
- LVGL 在framebuffer设备上的移植
- 一、LVGL源码获取
- 二、源码修改适配
- 三、编译&运行
- 补充
 
 
一、LVGL源码获取
- 新建lvgl_imx6ull文件夹,分别git clone以下三个仓库:
| 仓库 | 地址 | 
|---|---|
| lv_port_linux_frame_buffer | https://github.com/lvgl/lv_port_linux_frame_buffer.git | 
| lv_drivers | https://github.com/lvgl/lv_drivers.git | 
| lvgl | https://github.com/lvgl/lvgl.git | 
如果没有足够的能力解决库兼容问题,lvgl和lvgl_drivers仓库尽量拉取同一个TAG对应的版本
- 新建lvgl_demo文件夹,拷贝如下文件到该文件夹下:
1. 拷贝lvgl和lvgl_drivers文件夹
2. 分别拷贝lv_port_linux_frame_buffer下的main.c lv_conf.h lv_drv_conf.h Makefile
二、源码修改适配
- lv_drv_conf.h
# 修改1:修改为自己板子配置的对应的fb设备节点,比如我的触摸屏fb设备是"/dev/fb0"
/*-----------------------------------------*  Linux frame buffer device (/dev/fbx)*-----------------------------------------*/
#ifndef USE_FBDEV
#  define USE_FBDEV           1
#endif#if USE_FBDEV
#  define FBDEV_PATH          "/dev/fb0"
#endif...
# 修改2:修改为自己板子配置的对应的input设备节点,比如这里我的触摸屏input节点是"/dev/input/event0"
# 如果不知道可以通过hexdump /dev/input/event0 测试看是哪个event
#if USE_EVDEV || USE_BSD_EVDEV
#  define EVDEV_NAME   "/dev/input/event0"        /*You can use the "evtest" Linux tool to get the list of devices and test them*/...
#endif  /*USE_EVDEV*/
- lv_conf.h
# 修改1:修改BPP为自己屏幕对应的值,比如我的屏幕BPP为16(RGB565),具体要看屏的spec
/*====================COLOR SETTINGS*====================*//*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/
#define LV_COLOR_DEPTH 16
...#修改2:LV_MEM_CUSTOM设置为1,使用malloc和free管理显存,因为使用lvgl此类设备内存较小,一般都不使用自动内存管理
/*=========================MEMORY SETTINGS*=========================*//*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/
#define LV_MEM_CUSTOM 1
#if LV_MEM_CUSTOM == 0...#else       /*LV_MEM_CUSTOM*/...
#endif     /*LV_MEM_CUSTOM*/
...
- main.c
# 修改1:修改为自己屏幕分辨率
#define DISP_BUF_SIZE (280 * 240)
.../*Initialize and register a display driver*/static lv_disp_drv_t disp_drv;lv_disp_drv_init(&disp_drv);disp_drv.draw_buf   = &disp_buf;disp_drv.flush_cb   = fbdev_flush;disp_drv.hor_res    = 280;disp_drv.ver_res    = 240;lv_disp_drv_register(&disp_drv);
...# 修改2: 如果不用鼠标则注释下面/*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*/
- Makefile
# 修改1: 修改为自己的交叉编译器
CC 			?= arm-linux-gnueabihf-gcc# 修改2: 如果不用鼠标则注释下面
#CSRCS 			+=$(LVGL_DIR)/mouse_cursor_icon.c 
三、编译&运行
lvgl_demo目录下执行:
make
拷贝/build/bin/demo到板子上
./demo
效果:
 
补充
错误&异常
-  gcc编译报错 error: ‘for‘ loop initial declarations are only allowed in C99 mode # 修改makefile,在编译命令加上使用c99选项 $(BUILD_OBJ_DIR)/%.o: %.c@mkdir -p $(dir $@)@$(CC) $(CFLAGS) -c $< -std=c99 -o $@@echo "GCC $<"default: $(TARGET)@mkdir -p $(dir $(BUILD_BIN_DIR)/)$(CC) -std=c99 -o $(BUILD_BIN_DIR)/$(BIN) $(TARGET) $(LDFLAGS)
-  arm-linux-gnueabihf-gcc: 错误: unrecognized command line option ‘-Wshift-negative-value’ # 修改makefile,屏蔽gcc的警告,例如这个左移负值警告,gcc版本和代码实际语法不兼容#CFLAGS ?= -O3 -g0 -I$(LVGL_DIR)/ $(WARNINGS)CFLAGS ?= -O3 -g0 -I$(LVGL_DIR)/
最后:
 文章参考于网友的经验