1.1内核设置
进入内核目录。
cd /SDK目录/sysdrv/source/kernel
cp ./arch/arm/configs/luckfox_rv1106_linux_defconfig .config
make ARCH=arm menuconfig
在内核中依次开启FB相关的驱动
CONFIG_VT_CONSOLE=y
CONFIG_FRAMEBUFFER_CONSOLE=y
CONFIG_FONTS=y
将编译芯片对应驱动程序选项打开:默认是打开st7735R和ST7789v,对应程序在/luckfox-pico/sysdrv/source/kernel/drivers/staging/fbtft文件夹内,如果没有对应芯片驱动程序 ,则自行添加
保存配置
make ARCH=arm savedefconfig
cp defconfig arch/arm/configs/luckfox_rv1106_linux_defconfig
1.2 设备树文件
要驱动 LCD,除了在内核中启用 FB 相关驱动程序外,还必须确保所有与 LCD 通讯的引脚功能正常。在此之前,我们需要确定 Pico-LCD-1.3 与 Luckfox Pico Pro/Max 的连接引脚。设备树用于描述硬件资源,因此需要对设备树进行相应的修改。
按键相关的引脚如果没使用可以不设置
1.2.2设备树编写
- 在默认的设备树中, GPIO1_C7_d 的默认功能是 PWM 功能,在程序中,我们希望通过读取该引脚电平判断按键状态,所以我们需要将该引脚配置为普通IO。打开<SDK目录>/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-pro-max.dts
/{
gpio1pc7:gpio1pc7 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio1_pc7>;
regulator-name = "gpio1_pc7";
regulator-always-on;
};
};
&pinctrl {
gpio1-pc7 {
gpio1_pc7:gpio1-pc7 {
rockchip,pins = <1 RK_PC7 RK_FUNC_GPIO &pcfg_pull_up>;
};
};
};
- SPI 配置需要禁用spidev@0,否则fb无法进行初始化。
如果是st7789v等其它芯片,则将ili9341@0改为芯片名@0,如st7789@0
compatible改为"sitronix,st7789v"
&spi0 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&spi0m0_cs0 &spi0m0_pins>;
spidev@0 {//一定要禁用
status = "disabled";
};
ili9341@0{
status = "okay";
compatible = "ilitek,ili9341";
reg = <0>;
spi-max-frequency = <20000000>;
fps = <30>;
buswidth = <8>;
debug = <0x7>;
led-gpios = <&gpio2 RK_PB0 GPIO_ACTIVE_LOW>;//BL
dc = <&gpio2 RK_PB1 GPIO_ACTIVE_HIGH>; //DC
reset = <&gpio1 RK_PC3 GPIO_ACTIVE_LOW>; //RES
};
};
&pinctrl {
spi0 {
/omit-if-no-ref/
spi0m0_pins: spi0m0-pins {
rockchip,pins =
/* spi0_clk_m0 */
<1 RK_PC1 4 &pcfg_pull_none>,
/* spie_miso_m0 */
// <1 RK_PC3 6 &pcfg_pull_none>,
/* spi_mosi_m0 */
<1 RK_PC2 6 &pcfg_pull_none>;
};
};
};
完整dts文件如下:
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
* Copyright (c) 2022 Rockchip Electronics Co., Ltd.
*/
/dts-v1/;
#include "rv1106.dtsi"
#include "rv1106-evb.dtsi"
#include "rv1106-luckfox-pico-pro-max-ipc.dtsi"
/ {
model = "Luckfox Pico Max";
compatible = "rockchip,rv1103g-38x38-ipc-v10", "rockchip,rv1106";
/*LCD_BL*/
gpio2pb0:gpio2pb0 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio2_pb0>;
regulator-name = "gpio2_pb0";
regulator-always-on;
};
/*LCD_DC*/
gpio2pb1:gpio2pb1 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio2_pb1>;
regulator-name = "gpio2_pb1";
regulator-always-on;
};
/*LCD_RES*/
gpio1pc3:gpio1pc3 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio1_pc3>;
regulator-name = "gpio1_pc3";
regulator-always-on;
};
/*KEY*/
gpio2pa0:gpio2pa0 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio2_pa0>;
regulator-name = "gpio2_pa0";
regulator-always-on;
};
gpio2pa1:gpio2pa1 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio2_pa1>;
regulator-name = "gpio2_pa1";
regulator-always-on;
};
gpio2pa2:gpio2pa2 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio2_pa2>;
regulator-name = "gpio2_pa2";
regulator-always-on;
};
gpio2pa3:gpio2pa3 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio2_pa3>;
regulator-name = "gpio2_pa3";
regulator-always-on;
};
gpio2pa4:gpio2pa4 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio2_pa4>;
regulator-name = "gpio2_pa4";
regulator-always-on;
};
gpio2pa5:gpio2pa5 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio2_pa5>;
regulator-name = "gpio2_pa5";
regulator-always-on;
};
gpio1pc6:gpio1pc6 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio1_pc6>;
regulator-name = "gpio1_pc6";
regulator-always-on;
};
gpio1pc7:gpio1pc7 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio1_pc7>;
regulator-name = "gpio1_pc7";
regulator-always-on;
};
gpio1pd1:gpio1pd1 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio1_pd1>;
regulator-name = "gpio1_pd1";
regulator-always-on;
};
};
/**********GPIO**********/
&pinctrl {
/*LCD_BL*/
gpio2-pb0 {
gpio2_pb0:gpio2-pb0 {
rockchip,pins = <2 RK_PB0 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
/*LCD_DC*/
gpio2-pb1 {
gpio2_pb1:gpio2-pb1 {
rockchip,pins = <2 RK_PB1 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
/*LCD_RES*/
gpio1-pc3 {
gpio1_pc3:gpio1-pc3 {
rockchip,pins = <1 RK_PC3 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
/*KEY*/
gpio2-pa0 {
gpio2_pa0:gpio2-pa0 {
rockchip,pins = <2 RK_PA0 RK_FUNC_GPIO &pcfg_pull_up>;
};
};
gpio2-pa1 {
gpio2_pa1:gpio2-pa1 {
rockchip,pins = <2 RK_PA1 RK_FUNC_GPIO &pcfg_pull_up>;
};
};
gpio2-pa2 {
gpio2_pa2:gpio2-pa2 {
rockchip,pins = <2 RK_PA2 RK_FUNC_GPIO &pcfg_pull_up>;
};
};
gpio2-pa3 {
gpio2_pa3:gpio2-pa3 {
rockchip,pins = <2 RK_PA3 RK_FUNC_GPIO &pcfg_pull_up>;
};
};
gpio2-pa4 {
gpio2_pa4:gpio2-pa4 {
rockchip,pins = <2 RK_PA4 RK_FUNC_GPIO &pcfg_pull_up>;
};
};
gpio2-pa5 {
gpio2_pa5:gpio2-pa5 {
rockchip,pins = <2 RK_PA5 RK_FUNC_GPIO &pcfg_pull_up>;
};
};
gpio1-pc6 {
gpio1_pc6:gpio1-pc6 {
rockchip,pins = <1 RK_PC6 RK_FUNC_GPIO &pcfg_pull_up>;
};
};
gpio1-pc7 {
gpio1_pc7:gpio1-pc7 {
rockchip,pins = <1 RK_PC7 RK_FUNC_GPIO &pcfg_pull_up>;
};
};
gpio1-pd1 {
gpio1_pd1:gpio1-pd1 {
rockchip,pins = <1 RK_PD1 RK_FUNC_GPIO &pcfg_pull_up>;
};
};
};
/**********FLASH**********/
&sfc {
status = "okay";
flash@0 {
compatible = "spi-nand";
reg = <0>;
spi-max-frequency = <75000000>;
spi-rx-bus-width = <4>;
spi-tx-bus-width = <1>;
};
};
/**********SDMMC**********/
// &sdmmc {
// max-frequency = <50000000>;
// no-sdio;
// no-mmc;
// bus-width = <4>;
// cap-mmc-highspeed;
// cap-sd-highspeed;
// disable-wp;
// pinctrl-names = "default";
// pinctrl-0 = <&sdmmc0_clk &sdmmc0_cmd &sdmmc0_det &sdmmc0_bus4>;
// status = "okay";
// };
/**********SDIO**********/
// &sdio {
// max-frequency = <50000000>;
// no-sdio;
// no-mmc;
// bus-width = <4>;
// cap-mmc-highspeed;
// cap-sd-highspeed;
// disable-wp;
// pinctrl-names = "default";
// pinctrl-0 = <&sdmmc1m0_cmd &sdmmc1m0_clk &sdmmc1m0_bus4 &clk_32k>;
// status = "okay";
// };
/**********ETH**********/
&gmac {
status = "okay";
};
/**********USB**********/
&usbdrd_dwc3 {
status = "okay";
dr_mode = "peripheral";
};
/**********I2C**********/
// &i2c1 {
// status = "okay";
// pinctrl-0 = <&i2c1m1_xfer>;
// clock-frequency = <100000>;
// };
// &i2c3 {
// status = "okay";
// pinctrl-0 = <&i2c3m1_xfer>;
// clock-frequency = <100000>;
// };
// /**********SPI**********/
// &spi0 {
// status = "okay";
// pinctrl-names = "default";
// pinctrl-0 = <&spi0m0_pins>;
// cs-gpios = <&gpio1 RK_PC0 1>;
// // cs-gpios = <&gpio1 26 1>;
// #address-cells = <1>;
// #size-cells = <0>;
// spidev@0 {
// compatible = "rockchip,spidev";
// spi-max-frequency = <50000000>;
// reg = <0>;
// };
// };
&spi0 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&spi0m0_cs0 &spi0m0_pins>;
spidev@0 {
status = "disabled";
};
ili9341@0{
status = "okay";
compatible = "ilitek,ili9341";
reg = <0>;
spi-max-frequency = <20000000>;
fps = <30>;
buswidth = <8>;
debug = <0x7>;
led-gpios = <&gpio2 RK_PB0 GPIO_ACTIVE_LOW>;//BL
dc = <&gpio2 RK_PB1 GPIO_ACTIVE_HIGH>; //DC
reset = <&gpio1 RK_PC3 GPIO_ACTIVE_LOW>; //RES
};
};
&pinctrl {
spi0 {
/omit-if-no-ref/
spi0m0_pins: spi0m0-pins {
rockchip,pins =
/* spi0_clk_m0 */
<1 RK_PC1 4 &pcfg_pull_none>,
/* spie_miso_m0 */
// <1 RK_PC3 6 &pcfg_pull_none>,
/* spi_mosi_m0 */
<1 RK_PC2 6 &pcfg_pull_none>;
};
};
};
/**********UART**********/
// &uart0 {
// status = "okay";
// pinctrl-names = "default";
// pinctrl-0 = <&uart0m1_xfer>;
// };
// &uart1 {
// status = "okay";
// pinctrl-names = "default";
// pinctrl-0 = <&uart1m1_xfer>;
// };
// &uart3 {
// status = "okay";
// pinctrl-names = "default";
// pinctrl-0 = <&uart3m1_xfer>;
// };
// &uart4 {
// status = "okay";
// pinctrl-names = "default";
// pinctrl-0 = <&uart4m1_xfer>;
// };
// /**********PWM**********/
// &pwm0 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm0m0_pins>;
// // pinctrl-0 = <&pwm0m1_pins>;
// };
// &pwm1 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm1m0_pins>;
// // pinctrl-0 = <&pwm1m1_pins>;
// };
//&pwm2 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm2m2_pins>;
//};
//&pwm3 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm3m2_pins>;
//};
//&pwm4 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm4m2_pins>;
//};
// &pwm5 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm5m1_pins>;
// // pinctrl-0 = <&pwm5m2_pins>;
// };
// &pwm6 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm6m1_pins>;
// // pinctrl-0 = <&pwm6m2_pins>;
// };
//&pwm7 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm7m2_pins>;
//};
//&pwm8 {
// status = "okay";
// pinctrl-names = "active";
// // pinctrl-0 = <&pwm8m1_pins>;
// pinctrl-0 = <&pwm8m0_pins>;
//};
//&pwm9 {
// status = "okay";
// pinctrl-names = "active";
// // pinctrl-0 = <&pwm9m1_pins>;
// pinctrl-0 = <&pwm9m0_pins>;
//};
// &pwm10 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm10m1_pins>;
// // pinctrl-0 = <&pwm10m2_pins>;
// // pinctrl-0 = <&pwm10m0_pins>;
// };
// &pwm11 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm11m1_pins>;
// // pinctrl-0 = <&pwm11m2_pins>;
// // pinctrl-0 = <&pwm11m0_pins>;
// };
// &rtc {
// status = "okay";
// };
1.3编译运行
- ./build.sh lunch 选择板子对应选项
- ./build.sh 编译,生成的image在output/image文件中
- 烧录运行
注意
我是用的微雪2.4inch LCD,最开始是将电源vcc接到串口模块中长期供电,保持屏幕亮的状态,导致运行不了。
最后发现把vcc接到开发板的VSYS引脚供电,及39引脚,这样在板子重新开机时,屏幕能保持一个屏幕熄灭的状态,运行程序后才会显示。
1.4测试
修改好设备树编译镜像,测试花屏和清屏
cat /dev/urandom > /dev/fb0 #花屏
cat /dev/zero > /dev/fb0 #清屏
每次运行都会显示cat: write error: No space left on device,不用担心,这是正常的,不是因为真的内存不足,而是framebuffer是一个虚拟的内存区域,cat写程序写到区域最后才表示写完了,超出区域范围。
1.5调试信息
ls /dev/fb0
dmesg | grep fb
vi /var/log/messages
LVGL
2.1拉取资源
在根目录下创建一个文件夹存放官方源码:
luckfox@luckfox:~$ mkdir lvgl
luckfox@luckfox:~$ cd lvgl
拉取资源:
git clone -b v8.1.0 https://github.com/lvgl/lvgl.git
git clone -b v8.1.0 https://github.com/lvgl/lv_drivers.git
git clone -b v8.1.0 https://github.com/lvgl/lv_demos.git
git clone --branch release/v8.2 --single-branch https://github.com/lvgl/lv_port_linux_frame_buffer.git
成功拉取后,在根目录下创建一个工程目录,并创建一个工程:
luckfox@luckfox:~$ mkdir -p lvgl_project/project_01
luckfox@luckfox:~$ cd lvgl_project/project_01/
2.2复制文件
- 复制根目录下的 lvgl 文件夹中的 lvgl、lv_drivers 目录
- 复制 lv_port_linux_frame_buffer 中的 main.c 与 Makefile
- 复制 lvgl 中的 lv_conf_template.h 重命名为 lv_conf.h
- 复制 lv_drivers 中的 lv_drv_conf_template.h 重命名为 lv_drv_conf.h
cp -r ~/lvgl/lvgl ./
cp -r ~/lvgl/lv_drivers ./
cp ~/lvgl/lvgl/lv_conf_template.h ./lv_conf.h
cp ~/lvgl/lv_drivers/lv_drv_conf_template.h ./lv_drv_conf.h
cp ~/lvgl/lv_port_linux_frame_buffer/main.c ./
cp ~/lvgl/lv_port_linux_frame_buffer/Makefile ./
查看 project_01 工程目录下文件:
luckfox@luckfox:~/lvgl_project/project_01$ ls -l
总用量 64
-rw-rw-r-- 1 luckfox luckfox 29023 12月 27 19:14 lv_conf.h
drwxrwxr-x 12 luckfox luckfox 4096 12月 27 19:14 lv_drivers
-rw-rw-r-- 1 luckfox luckfox 15184 12月 27 19:14 lv_drv_conf.h
drwxrwxr-x 12 luckfox luckfox 4096 12月 27 19:14 lvgl
-rw-rw-r-- 1 luckfox luckfox 2350 12月 27 19:14 main.c
-rw-rw-r-- 1 luckfox luckfox 2321 12月 27 19:14 Makefile
2.3 修改文件
####### 2.3.1.lv_conf.h
- 使能,将一开始的 #if 0 改成 #if 1
/* clang-format off */
#if 1 /*Set it to "1" to enable content*/
- 分配显存,使能 LV_MEM_CUSTOM ,选择自行分配显存
/*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/
#define LV_MEM_CUSTOM 1
- 刷新时间,将原本的 30ms 调整成了 10ms
/*Default display refresh period. LVG will redraw changed areas with this period time*/
#define LV_DISP_DEF_REFR_PERIOD 10 /*[ms]*/
/*Input device read period in milliseconds*/
#define LV_INDEV_DEF_READ_PERIOD 10 /*[ms]*/
4.TICK配置,使能 LV_TICK_CUSTOM ,选择在应用程序中自定义 Tick 定时器配置函数
原内容:
#define LV_TICK_CUSTOM 0
#if LV_TICK_CUSTOM
#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*/
#endif /*LV_TICK_CUSTOM*/
更改为:
#define LV_TICK_CUSTOM 1
#if LV_TICK_CUSTOM
#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*/
#endif /*LV_TICK_CUSTOM*/
2.3.2 lv_drv_conf.h
1.使能,将一开始的 #if 0 改成 #if 1
/* clang-format off */
#if 1 /*Set it to "1" to enable the content*/
2.支持设备,使能 USE_FBDEV ,支持Framebuffer设备
/*-----------------------------------------
* Linux frame buffer device (/dev/fbx)
*-----------------------------------------*/
#ifndef USE_FBDEV
# define USE_FBDEV 1
#endif
#if USE_FBDEV
# define FBDEV_PATH "/dev/fb0"
#endif
2.4 Makefile
替换原 Makefile 内容,将 Makefile 中 修改为自己的 SDK 路径,如 /home/luckfox/luckfox-pico/
#
# Makefile
#
CC = <SDK Directory>/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-gcc
LVGL_DIR_NAME ?= lvgl
LVGL_DIR ?= .
WARNINGS := -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 -std=c99
CFLAGS ?= -O3 -g0 -I$(LVGL_DIR)/ $(WARNINGS)
LDFLAGS ?= -lm
BIN = demo
BUILD_DIR = ./build
BUILD_OBJ_DIR = $(BUILD_DIR)/obj
BUILD_BIN_DIR = $(BUILD_DIR)/bin
prefix ?= /usr
bindir ?= $(prefix)/bin
#Collect the files to compile
MAINSRC = $(wildcard ./*.c)
include $(LVGL_DIR)/lvgl/lvgl.mk
include $(LVGL_DIR)/lv_drivers/lv_drivers.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)
TARGET = $(addprefix $(BUILD_OBJ_DIR)/, $(patsubst ./%, %, $(OBJS)))
## MAINOBJ -> OBJFILES
all: default
$(BUILD_OBJ_DIR)/%.o: %.c
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -c $< -o $@
@echo "CC $<"
default: $(TARGET)
@mkdir -p $(dir $(BUILD_BIN_DIR)/)
$(CC) -o $(BUILD_BIN_DIR)/$(BIN) $(TARGET) $(LDFLAGS)
clean:
rm -rf $(BUILD_DIR)
install:
install -d $(DESTDIR)$(bindir)
install $(BUILD_BIN_DIR)/$(BIN) $(DESTDIR)$(bindir)
uninstall:
$(RM) -r $(addprefix $(DESTDIR)$(bindir)/,$(BIN))
2.5 main.c
注释头文件
// #include "lvgl/demos/lv_demos.h"
// #include "lv_drivers/indev/evdev.h"
修改屏幕分辨率
#define DISP_BUF_SIZE (240 * 240)
...
disp_drv.hor_res = 240;
disp_drv.ver_res = 240;
注释下面代码
无外部输入设备,注释下面代码:
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*/
不使用官方demo,注释下面代码:
/*Create a Demo*/
lv_demo_widgets();
2.6 编译和运行
上述文件修改完成后,在命令行输入 make 命令编译工程,编译完成后会在 /build/bin 目录下生成一个可执行文件 demo ,编译后的目录结构如下:我们只需要将 demo 拷贝至开发板,即可在板子上运行程序。后续可以根据需求自行修改 main.c 文件和添加文件,实现自己想要的显示效果。
官方LVGL demo
若需要使用官方提供的例程,在上述操作的基础上,按照下面步骤进行操作:
- 复制文件,复制根目录下的 lvgl 文件夹中的 lv_demos 目录
复制 lv_demos 中的 lv_demo_conf_template.h 重命名为 lv_demo_conf.h
cp -r ~/lvgl/lv_demos ./
cp ~/lvgl/lv_demos/lv_demo_conf_template.h ./lv_demo_conf.h
- 修改 lv_demo_conf.h
使能
/* clang-format off */
#if 1 /*Set it to "1" to enable the content*/
使能 widget demo
/*Show some widget*/
#define LV_USE_DEMO_WIDGETS 1
- 修改 lv_conf.h,使能 LV_FONT_MONTSERRAT_12 和 LV_FONT_MONTSERRAT_16
#define LV_FONT_MONTSERRAT_12 1
#define LV_FONT_MONTSERRAT_16 1
- Makefile
include $(LVGL_DIR)/lvgl/lvgl.mk
include $(LVGL_DIR)/lv_drivers/lv_drivers.mk
#Add lv_demo.mk:
include $(LVGL_DIR)/lv_demos/lv_demo.mk
- 修改 main.c
添加头文件
#include "lv_demos/lv_demo.h"
调用接口函数
lv_demo_widgets();
while(1) {
lv_timer_handler();
usleep(5000);
}```
####编译运行后build/bin文件夹中demo复制到开发板可运行