Little VGL development: transplantation development of embedded devices

1, Foreword

    The previous blog introduces littlevgl. Littlevgl is a free open source graphics library with good portability. This blog introduces the development of littlevgl on Embedded linux system.

1. Download littlevGL source code:

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

2. The version can be switched through git. I use v8.0.1 here. All three directories need to be switched

2, Compile configuration

1. Three configuration files are used here:

lvgl/lv_conf_template.h

lv_drivers/lv_drv_conf_template.h

lv_demos/lv_demo_conf_template.h

2. Copy the three profiles from the module folder to the project folder and name it

lv_conf.h

lv_drv_conf.h

lv_demo_conf.h

3. Modify lv_conf.h file

(1) Enable on

#if 1 /*Set it to "1" to enable content*/

(2) Modify LV_COLOR_DEPTH macro indicates the number of bits used per pixel. Bloggers are configured as RGB565, so it is 16 bits.

/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/
#define LV_COLOR_DEPTH     16

4. Modify lv_drv_conf.h file

(1) Enable on

#if 1 /*Set it to "1" to enable the content*/

(2) Enable fb equipment

/*-----------------------------------------
 *  Linux frame buffer device (/dev/fbx)
 *-----------------------------------------*/
#ifndef USE_FBDEV
#  define USE_FBDEV           1
#endif

#if USE_FBDEV
#  define FBDEV_PATH          "/dev/fb0"
#endif

(3) Enable input device

         Put USE_EVDEV macro is set to 1 to enable the input device. EVDEV_ The name macro represents the input event, not necessarily event0, but event0 for bloggers. You can use the cat command to test which event corresponds to the touch screen input of your board:

         Enter cat /dev/input/event0 in the board shell. At this time, touch the screen, and the terminal will output garbled information, indicating that the touch input of the current board corresponds to this event.

#ifndef USE_EVDEV
#  define USE_EVDEV           1
#endif

#ifndef USE_BSD_EVDEV
#  define USE_BSD_EVDEV       0
#endif

#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*/
#  define EVDEV_SWAP_AXES         0               /*Swap the x and y axes of the touchscreen*/

5. About lv_conf.h,lv_drv_conf.h,lv_demo_conf.h configuration

        Note: only the simplest configuration is made here. If there is an error in compilation or a new module function is added, you need to open the corresponding macro definitions in the three configuration files, which will not be explained here;

6. Create Makefile file

#
# Makefile
#
CC = arm-nuvoton-linux-uclibceabi-gcc
LVGL_DIR_NAME = lvgl
LVGL_DIR = ${shell pwd}
INCLUDE_DIRS = $(LVGL_DIR)/

CFLAGS = -O2  -Wall  -std=c99
LDFLAGS = -lm
BIN = demo

include $(LVGL_DIR)/lvgl/lvgl.mk
include $(LVGL_DIR)/lv_drivers/lv_drivers.mk
include $(LVGL_DIR)/lv_demos/lv_demo.mk

CSRCS += ./main.c

OBJS =$(CSRCS:%.c=%.o)

all: BIN

%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@
#@echo "$(CC) $<"
    
BIN: $(OBJS) 
	$(CC) $(OBJS) $(LDFLAGS) -o $(BIN) 

clean: 
	rm -f $(BIN)  $(OBJS) 

CC is the compilation tool chain. The blogger uses arm Nuvoton Linux uclibceabi GCC

7. Writing applications

#include "lvgl/lvgl.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 * 1024)

void label_test(void)
{
    lv_obj_t * label1 = lv_label_create(lv_scr_act());
    lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP);     /*Break the long lines*/
    lv_label_set_recolor(label1, true);    /*Enable re-coloring by commands in the text*/
    lv_label_set_text(label1, "hello world");
    lv_obj_set_width(label1, 50);
    lv_obj_set_style_text_align(label1, LV_TEXT_ALIGN_CENTER, 0);
    lv_obj_align(label1, LV_ALIGN_CENTER, 0, -30);
}

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    = 800;
    disp_drv.ver_res    = 480;
    lv_disp_drv_register(&disp_drv);

    evdev_init();
    static lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&indev_drv);
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    indev_drv.read_cb = evdev_read;
    lv_indev_drv_register(&indev_drv);

    label_test();

    /*Handle LitlevGL tasks (tickless mode)*/
    while(1) {
        lv_task_handler();
        usleep(5000);
    }

    return 0;
}

8. At this time, the project file directory is as follows:

9. Download the whole project

        

  3, Run test

Use make to compile and generate the demo, and copy the application to the board to run

 

 

Tags: Linux

Posted on Thu, 09 Sep 2021 15:47:14 -0400 by billshackle