技术流
- 使用Gui Guider进行UI设计,生成lvgl code
- 将lvgl code移植到esp32s3开发板
模拟器Gui Guider的安装
安装下面流程一步一步进行
LVGL的移植
硬件:esp32-8048s043开发板
开发环境:PlatformIO
M1芯片安装ESP32驱动
从https://www.wch.cn/downloads/CH34XSER_MAC_ZIP.html安装驱动,开发板USB连接后若显示 /dev/cu.wchusbserial* 即安装成功,可以使用Arduino和PlatformIO进行开发。
使用PlatformIO进行ESP32S3-WROOM-1的开发配置
使用esp32-s3-devkitc-1-N8开发板,需要加一些烧录参数才可以将程序烧录进去。
[env:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
board_build.arduino.partitions = default_16MB.csv
board_build.arduino.memory_type = qio_opi
build_flags = -DBOARD_HAS_PSRAM
board_upload.flash_size = 16MB
运行LVGL Widget的Demo案例
PlatformIO新建一个Project,进行上述的烧录配置。
随后再加入开发的依赖库
lib_deps =
lvgl/lvgl@8.3.9
tamctec/TAMC_GT911@^1.0.2
moononournation/GFX Library for Arduino@1.2.8
保存,自动进行依赖库的安装
也可以将代码复制到lib文件夹中,不需要动platform的配置文件。
依赖:
|-- lvgl @8.3.5(同guider的版本)
|-- WiFi @ 2.0.0
|-- GFX Library for Arduino @ 1.2.8
|-- SPI @ 2.0.0
|-- TAMC_GT911 @ 1.0.2
|-- Wire @ 2.0.0
将touch.h 放入include文件夹中
去官网https://docs.lvgl.io/8.3/,进行lvgl的配置,主要就是修改lv_conf.h文件。
如果是初始化的项目,在main.cpp脚本最上面添加两个依赖,可直接build,看项目是否正常工作。
#include <Wire.h>
#include <SPI.h>
修改main.cpp,运行widget案例:
/*******************************************************************************
* LVGL Widgets
* This is a widgets demo for LVGL - Light and Versatile Graphics Library
* import from: https://github.com/lvgl/lv_demos.git
*
* Dependent libraries:
* LVGL: https://github.com/lvgl/lvgl.git
* Touch libraries:
* FT6X36: https://github.com/strange-v/FT6X36.git
* GT911: https://github.com/TAMCTec/gt911-arduino.git
* XPT2046: https://github.com/PaulStoffregen/XPT2046_Touchscreen.git
*
* LVGL Configuration file:
* Copy your_arduino_path/libraries/lvgl/lv_conf_template.h
* to your_arduino_path/libraries/lv_conf.h
* Then find and set:
* #define LV_COLOR_DEPTH 16
* #define LV_TICK_CUSTOM 1
*
* For SPI display set color swap can be faster, parallel screen don't set!
* #define LV_COLOR_16_SWAP 1
*
* Optional: Show CPU usage and FPS count
* #define LV_USE_PERF_MONITOR 1
******************************************************************************/
// #include "lv_demo_widgets.h"
#include <Arduino.h>
#include <lvgl.h>
#include <demos/lv_demos.h>
/*******************************************************************************
******************************************************************************/
#include <Arduino_GFX_Library.h>
#define LV_USE_PERF_MONITOR 1
#define TFT_BL 2
#define GFX_BL DF_GFX_BL // default backlight pin, you may replace DF_GFX_BL to actual backlight pin
/* More dev device declaration: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration */
#if defined(DISPLAY_DEV_KIT)
Arduino_GFX *gfx = create_default_Arduino_GFX();
#else /* !defined(DISPLAY_DEV_KIT) */
/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
// Arduino_DataBus *bus = create_default_Arduino_DataBus();
/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
// Arduino_GFX *gfx = new Arduino_ILI9341(bus, DF_GFX_RST, 0 /* rotation */, false /* IPS */);
Arduino_ESP32RGBPanel *bus = new Arduino_ESP32RGBPanel(
GFX_NOT_DEFINED /* CS */, GFX_NOT_DEFINED /* SCK */, GFX_NOT_DEFINED /* SDA */,
40 /* DE */, 41 /* VSYNC */, 39 /* HSYNC */, 42 /* PCLK */,
45 /* R0 */, 48 /* R1 */, 47 /* R2 */, 21 /* R3 */, 14 /* R4 */,
5 /* G0 */, 6 /* G1 */, 7 /* G2 */, 15 /* G3 */, 16 /* G4 */, 4 /* G5 */,
8 /* B0 */, 3 /* B1 */, 46 /* B2 */, 9 /* B3 */, 1 /* B4 */
);
// option 1:
// ST7262 IPS LCD 800x480
Arduino_RPi_DPI_RGBPanel *gfx = new Arduino_RPi_DPI_RGBPanel(
bus,
800 /* width */, 0 /* hsync_polarity */, 8 /* hsync_front_porch */, 4 /* hsync_pulse_width */, 8 /* hsync_back_porch */,
480 /* height */, 0 /* vsync_polarity */, 8 /* vsync_front_porch */, 4 /* vsync_pulse_width */, 8 /* vsync_back_porch */,
1 /* pclk_active_neg */, 14000000 /* prefer_speed */, true /* auto_flush */);
#endif /* !defined(DISPLAY_DEV_KIT) */
/*******************************************************************************
* End of Arduino_GFX setting
******************************************************************************/
/*******************************************************************************
* Please config the touch panel in touch.h
******************************************************************************/
#include "touch.h"
/* Change to your screen resolution */
static uint32_t screenWidth;
static uint32_t screenHeight;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t *disp_draw_buf;
static lv_disp_drv_t disp_drv;
/* Display flushing */
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
uint32_t w =