• 【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
    
    • 1
    • 2
    • 3
    • 4

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

    配置ssh

    获取ssh key

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

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

    读取这个文件

    cat ~/.ssh/id_rsa.pub
    
    • 1

    是以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
    
    • 1
    • 2
    • 3
    • 4

    在这里插入图片描述

    切换分支

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    参考: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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    在这里插入图片描述

    修改配置

    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          /*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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    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 
    #include 
    #include 
    #include 
    
    #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;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84

    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)
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46

    编译

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    /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]~#
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    在这里插入图片描述

    至此,可以成功的使用lvgl显示demo,不过还需要自己实现功能。

  • 相关阅读:
    经典模型——AlexNet
    安全论坛和外包平台汇总
    【图像检测】基于FT算法实现图像显著性检测附matlab代码
    vue.js:用户登录切换的小案例
    网络编程:导入电子词典
    python爬虫
    littlevgl之win 窗口控件
    react04- mvc 、 mvvm
    基于SSM的健身房管理系统
    HDFS基础架构以及部署
  • 原文地址:https://blog.csdn.net/qq_38091632/article/details/134183277