1. 前提条件
- 使用 arduino IDE开发
- 使用 ESP32 作为主控
- 屏幕使用 ST7789 驱动,240*240像素TFT屏幕
注意:屏幕驱动部分不再这个赘述,以后开贴另行发布
2. 安装 LVGL 库
打开 arduino 菜单栏中 -> 项目 -> 加载库 -> 管理库
搜索 LVGL 本人使用版本是8.0.2, 8.0一下版本貌似不支持GIF
1. 成功安装后,LVGL库就安装到了 首选项中, 项目文件夹位置 一栏中所设置的项目文件夹位置,我这里设置的是把库文件安装在该项目文件下。
2. 编译, 编译的时候会报各种错误,这里主要是 lv_conf.h 找不到一类的,因为库只给了模板,我们把lvgl文件下的 lv_conf_templet.h 改为 lv_conf.h,然后使能 lv_conf.h 文件
3. 搜索 lv_conf_internal.h 文件,修改一下 lv_conf.h 的路径,如下图所示:
3. 工程测试
- 在库文件lvgl中example文件下有arduino的测试demo,我们拷贝到我们的自己工程目录,以下是拷贝完毕的
- 我的工程没有用到 touchpad 触摸屏幕功能,所以我都去掉了
- 我的屏幕背光由ESP32控制,所以加入了背光控制,如果直接点亮可以去掉这个功能
//#include <lv_demo.h>
#include <stdint.h>
#include <lvgl.h>
#include <TFT_eSPI.h>
/*If you want to use the LVGL examples,
make sure to install the lv_examples Arduino library
and uncomment the following line.
#include <lv_examples.h>
*/
#include "lv_gif.h"
#define LCD_BL_PIN 5
#define LCD_BL_PWM_CHANNEL 0
TFT_eSPI tft = TFT_eSPI(); /* TFT instance */
/*Change to your screen resolution*/
static const uint32_t screenWidth = 240;
static const uint32_t screenHeight = 240;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[ screenWidth * 10 ];
#if LV_USE_LOG != 0
/* Serial debugging */
void my_print(