环境"/>
【lvgl】linux开发板搭建环境
前言
本章介绍如何在linux开发板准备好了fb0的情况下移植lvgl。
抓取源码
git clone .git
git clone .git
git clone .git
git clone .git
注意:如果https一直无法成功,可以配一下ssh
配置ssh
获取ssh key
ssh-keygen -t rsa -C "xxx@qq"
#一直回车
结束之后会显示你的ssh存在哪里,比如~/.ssh/id_rsa.pub
读取这个文件
cat ~/.ssh/id_rsa.pub
是以ssh-rsa开头的内容,将其全部复制。
github网页中,选择setting,添加ssh key并保存。
使用下述命令抓取代码。
git clone git@github:lvgl/lvgl.git
git clone git@github:lvgl/lv_drivers.git
git clone git@github:lvgl/lv_demos.git
git clone git@github:lvgl/lv_port_linux_frame_buffer.git
切换分支
cd lvgl
git checkout release/v8.1
cd ../lv_drivers
git checkout release/v8.1
cd ../lv_demos
git checkout release/v8.1
cd ../lv_port_linux_frame_buffer
git checkout release/v8.2
git branch -a
参考:
复制文件
cp lvgl/lv_conf_template.h test/lv_conf.h
cp -r lvgl test/
cp lv_drivers/lv_drv_conf_template.h test/lv_drv_conf.h
cp -r lv_drivers test/
cp lv_demos/lv_demo_conf_template.h test/lv_demo_conf.h
cp -r lv_demos test/
cp lv_port_linux_frame_buffer/main.c test
cp lv_port_linux_frame_buffer/Makefile test
修改配置
lv_conf.h
youkai@ubuntu:~/0_pro/lvgl/lv_port_linux_frame_buffer$ diff lv_conf.h lvgl/lv_conf_template.h
15c15
< #if 1 /*Set it to "1" to enable content*/
---
> #if 0 /*Set it to "1" to enable content*/
52c52
< # define LV_MEM_SIZE (10U * 1024U * 1024U) /*[bytes]*/
---
> # define LV_MEM_SIZE (32U * 1024U) /*[bytes]*/
81c81
< #define LV_DISP_DEF_REFR_PERIOD 10 /*[ms]*/
---
> #define LV_DISP_DEF_REFR_PERIOD 30 /*[ms]*/
84c84
< #define LV_INDEV_DEF_READ_PERIOD 10 /*[ms]*/
---
> #define LV_INDEV_DEF_READ_PERIOD 30 /*[ms]*/
88c88
< #define LV_TICK_CUSTOM 1
---
> #define LV_TICK_CUSTOM 0
90,93c90,91
< // #define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the system time function*/
< // #define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/
< #define LV_TICK_CUSTOM_INCLUDE <stdint.h> /*Header for the system time function*/
< #define LV_TICK_CUSTOM_SYS_TIME_EXPR (custom_tick_get()) /*Expression evaluating to current system time in ms*/
---
> #define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the system time function*/
> #define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/
176c174
< #define LV_USE_LOG 1
---
> #define LV_USE_LOG 0
190c188
< # define LV_LOG_PRINTF 1
---
> # define LV_LOG_PRINTF 0
307,309c305,307
< #define LV_FONT_MONTSERRAT_8 1
< #define LV_FONT_MONTSERRAT_10 1
< #define LV_FONT_MONTSERRAT_12 1
---
> #define LV_FONT_MONTSERRAT_8 0
> #define LV_FONT_MONTSERRAT_10 0
> #define LV_FONT_MONTSERRAT_12 0
311c309
< #define LV_FONT_MONTSERRAT_16 1
---
> #define LV_FONT_MONTSERRAT_16 0
lv_drv_conf.h
youkai@ubuntu:~/0_pro/lvgl/lv_port_linux_frame_buffer$ diff lv_drv_conf.h lv_drivers/lv_drv_conf_template.h
11c11
< #if 1 /*Set it to "1" to enable the content*/
---
> #if 0 /*Set it to "1" to enable the content*/
319c319
< # define USE_FBDEV 1
---
> # define USE_FBDEV 0
lv_demo_conf.h
youkai@ubuntu:~/0_pro/lvgl/lv_port_linux_frame_buffer$ diff lv_demo_conf.h lv_demos/lv_demo_conf_template.h
11c11
< #if 1 /*Set it to "1" to enable the content*/
---
> #if 0 /*Set it to "1" to enable the content*/
29c29
< #define LV_USE_DEMO_WIDGETS 1
---
> #define LV_USE_DEMO_WIDGETS 0
main.c
#include "lvgl/lvgl.h"
// #include "lvgl/demos/lv_demos.h"
#include "lv_demos/lv_demo.h"
#include "lv_drivers/display/fbdev.h"
// #include "lv_drivers/indev/evdev.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>#define DISP_BUF_SIZE (128 * 160 * 2)int main(void)
{/*LittlevGL init*/lv_init();/*Linux frame buffer device init*/fbdev_init();/*A small buffer for LittlevGL to draw the screen's content*/static lv_color_t buf[DISP_BUF_SIZE];/*Initialize a descriptor for the buffer*/static lv_disp_draw_buf_t disp_buf;lv_disp_draw_buf_init(&disp_buf, buf, NULL, DISP_BUF_SIZE);/*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 = 128;disp_drv.ver_res = 160;lv_disp_drv_register(&disp_drv);// evdev_init();// static lv_indev_drv_t indev_drv_1;// lv_indev_drv_init(&indev_drv_1); /*Basic initialization*/// indev_drv_1.type = LV_INDEV_TYPE_POINTER;// /*This function will be called periodically (by the library) to get the mouse position and state*/// indev_drv_1.read_cb = evdev_read;// lv_indev_t *mouse_indev = lv_indev_drv_register(&indev_drv_1);// /*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*//*Create a Demo*/lv_demo_widgets();/*Handle LitlevGL tasks (tickless mode)*/while(1) {lv_timer_handler();usleep(5000);}return 0;
}/*Set in lv_conf.h as `LV_TICK_CUSTOM_SYS_TIME_EXPR`*/
uint32_t custom_tick_get(void)
{static uint64_t start_ms = 0;if(start_ms == 0) {struct timeval tv_start;gettimeofday(&tv_start, NULL);start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;}struct timeval tv_now;gettimeofday(&tv_now, NULL);uint64_t now_ms;now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;uint32_t time_ms = now_ms - start_ms;return time_ms;
}
makefile
注意
- CC是你使用的gcc路径
- 需要添加demo的mk
- 移除mouse_cursor_icon.c,对应代码中也移除了。
#
# Makefile
#
CC = /home/youkai/0_pro/luckfox/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-gcc
# CC = /home/youkai/0_pro/milkv/duo_buildroot_sdk/duo-buildroot-sdk/host-tools/gcc/riscv64-linux-musl-x86_64/bin/riscv64-unknown-linux-musl-gcc
LVGL_DIR_NAME ?= lvgl
LVGL_DIR ?= ${shell pwd}
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 -Wshift-negative-value -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
LDFLAGS ?= -lm
BIN = demo#Collect the files to compile
MAINSRC = ./main.cinclude $(LVGL_DIR)/lvgl/lvgl.mk
include $(LVGL_DIR)/lv_drivers/lv_drivers.mk
include $(LVGL_DIR)/lv_demos/lv_demo.mk# CSRCS +=$(LVGL_DIR)/mouse_cursor_icon.cOBJEXT ?= .oAOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))MAINOBJ = $(MAINSRC:.c=$(OBJEXT))SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
OBJS = $(AOBJS) $(COBJS)## MAINOBJ -> OBJFILESall: default%.o: %.c@$(CC) $(CFLAGS) -c $< -o $@@echo "CC $<"default: $(AOBJS) $(COBJS) $(MAINOBJ)$(CC) -o $(BIN) $(MAINOBJ) $(AOBJS) $(COBJS) $(LDFLAGS)clean: rm -f $(BIN) $(AOBJS) $(COBJS) $(MAINOBJ)
编译
youkai@ubuntu:~/0_pro/lvgl/pro_lvgl/test$ make
youkai@ubuntu:~/0_pro/lvgl/pro_lvgl/test$ file demo
demo: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-uClibc.so.0, with debug_info, not strippedyoukai@ubuntu:~/0_pro/lvgl/pro_lvgl/test$ file demo
demo: ELF 64-bit LSB executable, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-riscv64xthead.so.1, with debug_info, not stripped
/lib/ld-uClibc.so.0 —— luckfox所需要的so。
/lib/ld-musl-riscv64xthead.so.1 —— milkv-duo所需要的so。
运行——milkv-duo
[root@milkv]~# ls
demo_milkv
[root@milkv]~# chmod 777 demo_milkv
[root@milkv]~# ./demo_milkv
[Warn] (0.023, +23) lv_demo_widgets: LV_FONT_MONTSERRAT_18 is not enabled for the widgets demo. Using LV_FONT_DEFAULT instead. (in lv_demo_widgets.c line #130)
^C
[root@milkv]~#
至此,可以成功的使用lvgl显示demo,不过还需要自己实现功能。
更多推荐
【lvgl】linux开发板搭建环境
发布评论