【lvgl】linux开发板搭建环境

前言

本章介绍如何在linux开发板准备好了fb0的情况下移植lvgl。

资料

https://www.cnblogs.com/sky-heaven/p/16241310.html

https://community.milkv.io/t/milkv-duo-lvgl/296

Linux+VS Code搭建lvgl开发环境
https://blog.csdn.net/qq_36347513/article/details/123223491

m1搭建lvgl环境
https://blog.csdn.net/qq_29387165/article/details/126200870

LVGL linux arm平台上的详细移植过程
https://blog.csdn.net/weixin_41176628/article/details/119892395

Linux移植LVGL
https://blog.csdn.net/yangshuoSB/article/details/129145562

测试fb0:
https://blog.csdn.net/weixin_46836491/article/details/124209737

抓取源码

git clone 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

注意:如果https一直无法成功,可以配一下ssh

配置ssh

获取ssh key

ssh-keygen -t rsa -C "xxx@qq.com"
#一直回车

结束之后会显示你的ssh存在哪里,比如~/.ssh/id_rsa.pub

读取这个文件

cat ~/.ssh/id_rsa.pub

是以ssh-rsa开头的内容,将其全部复制。

github网页中,选择setting,添加ssh key并保存。

使用下述命令抓取代码。

git clone git@github.com:lvgl/lvgl.git
git clone git@github.com:lvgl/lv_drivers.git
git clone git@github.com:lvgl/lv_demos.git
git clone git@github.com: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

参考:https://blog.csdn.net/dhy_el/article/details/132791764

在这里插入图片描述

复制文件

cp lvgl/lv_conf_template.h pro/milkv/lv_conf.h
cp -r lvgl pro/milkv
cp lv_drivers/lv_drv_conf_template.h  pro/milkv/lv_drv_conf.h
cp -r lv_drivers pro/milkv
cp lv_demos/lv_demo_conf_template.h pro/milkv/lv_demo_conf.h
cp -r lv_demos pro/milkv
cp lv_port_linux_frame_buffer/main.c pro/milkv
cp lv_port_linux_frame_buffer/Makefile pro/milkv

在这里插入图片描述

修改配置

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

注意

  1. CC是你使用的gcc路径
  2. 需要添加demo的mk
  3. 移除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.c

include $(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.c

OBJEXT ?= .o

AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))

MAINOBJ = $(MAINSRC:.c=$(OBJEXT))

SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
OBJS = $(AOBJS) $(COBJS)

## MAINOBJ -> OBJFILES

all: 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 stripped

youkai@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,不过还需要自己实现功能。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
LVGL是一个用于嵌入式图形界面开发的开源库。根据引用,LVGL可以被移植到Linux开发板上,并且可以运行一些LVGL的例程。移植LVGLLinux开发板需要进行以下步骤: 1. 从LVGL的官方仓库中获取所需的文件。根据引用,需要获取lvgl、lv_drivers、lv_demos和lv_port_linux_frame_buffer这四个仓库的文件。 2. 将lvgl、lv_drivers和lv_port_linux_frame_buffer中的文件复制到项目文件夹中。根据引用,可以将这些文件复制到lvgl_demo文件夹中。 3. 确保项目文件夹中包含了lvgl、lv_drivers和lv_port_linux_frame_buffer的源码文件,以及主程序文件main.c和Makefile。 4. 根据项目的需求进行相关配置和修改。可以根据需要对LVGL的源码进行修改,并在main.c中编写应用程序。 5. 使用适当的编译器对项目进行编译和构建。 通过以上步骤,就可以在Linux开发板上成功移植和运行LVGL图形界面库了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [【嵌入式Linux应用开发】移植LVGLLinux开发板](https://blog.csdn.net/thisway_diy/article/details/125522360)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值