【lvgl】linux开发板搭建环境

news/2024/7/7 5:48:27 标签: linux, elasticsearch, 驱动开发

前言

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

抓取源码

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

注意

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


http://www.niftyadmin.cn/n/5151617.html

相关文章

软考 系统架构设计师系列知识点之数字孪生体(1)

所属章节&#xff1a; 第11章. 未来信息综合技术 第5节. 数字孪生体技术概述 数字孪生体技术是跨层级、跨尺度的现实世界和虚拟世界建立沟通的桥梁&#xff0c;是第四次工业革命的通用目的技术和核心技术体系之一&#xff0c;是支撑万物互联的综合技术体系&#xff0c;是数字经…

【LeetCode刷题-队列与栈】--225.用队列实现栈

225.用队列实现栈 class MyStack {Queue<Integer> queue1;Queue<Integer> queue2;public MyStack() {queue1 new LinkedList<Integer>();queue2 new LinkedList<Integer>();}public void push(int x) {queue2.offer(x);while(!queue1.isEmpty()){que…

【PyQt学习篇 · ⑩】:QAbstractButton的使用

文章目录 QAbstractButton简介子类化抽象类图标设置快捷键设置自动重复状态设置排他性点击设置点击有效区域可用信号 QAbstractButton简介 QAbstractButton 是一个抽象类&#xff0c;无法直接实例化&#xff0c;但它提供了很多在 PyQt 中使用按钮时常用的功能和特性。开发人员…

叶片卷曲

叶片卷曲 上卷/内卷白粉病强烈阳光&温度太高虫害&#xff08;蓟马&#xff09; 下卷 叶片卷曲的原因有很多&#xff0c;很多情况无法从外表分辨&#xff0c;并且有可能多种原因混杂&#xff0c;扰乱判断 上卷/内卷 白粉病 当植株感染白粉病时&#xff0c;白粉病菌孢子附…

GoLong的学习之路(十六)基础工具之GORM(操作数据库Mysql)(创建数据库,插入数据Insert和查询数据select))

GORM就类似于Java中的Mybatis&#xff0c;对于开发者来说简直是福音&#xff0c;并且支持主流数据库。 文章目录 安装方法1方法2 链接Mysql数据库链接现有数据库链接 创建表创建&#xff08;create&#xff09;用指定字段创建记录批量插入创建钩子根据Map创建 查询根据主键检索…

http中的Content-Type类型

浏览器的Content-Type 最近在做web端下载的时候需要给前端返回一个二进制的流&#xff0c;需要在请求头中设置一个 writer.Header().Set("Content-Type", "application/octet-stream")那么http中的Content-Type有具体有哪些呢&#xff1f;他们具体的使用场…

一文搞懂设计模式之七大原则

大家好&#xff0c;我是晴天。在接下来的一个多月里&#xff0c;我将跟大家一起学习设计模式的一些基础知识和基本应用。不要问我为什么突然想起来写一个设计模式系列的文章&#xff0c;问就是&#xff1a;爱过。。。 问题引出 作为程序猿的我们&#xff0c;隔三岔五的就会因为…

JAVA面经整理(10)

一)MyBatis有什么优缺点&#xff1f; Mybatis是⼀种典型的半自动化的ORM 框架&#xff0c;所谓的半自动&#xff0c;因为还需要⼿动的写 SQL 语句在XML文件里面&#xff0c;再由框架根据SQL以及传入数据来进行组装成要执行的SQL&#xff0c;所谓的ORM框架&#xff0c;就是对象关…