ESP32S3 基于IDF 5.1版本移植 lvgl 8.3
本次以及基于ESP-IDF v5.1-dirty,lvgl-8.3版本移植
ESP32 IDF V4.3 与V 5.1有较大的改动,网上主要是基于IDF 4.3的。总是移植不成功,研究了很久才实现了功能移植,完成了例程的运行。
本次以及基于ESP-IDF v5.1-dirty,lvgl-8.3版本移植
新建一个idf hello world工程
新建文件夹 components
下载lvgl源码
git clone https://github.com/lvgl/lvgl.git
下载适配esp32的lvgl驱动
git clone https://github.com/lvgl/lvgl_esp32_drivers.git
将lvgl -->>
lv_conf_template.h复制到 ../components/lvgl/src/lv_conf.h //注意需要重命名去掉template,进入使能文件,if 0 -->> if 1
将lvgl -->>
example -->>
porting -->> 文件复制到lvgl同级目录,新建文件porting。本次例程仅使用lv_port_disp.c/h,进入使能文件,if 0 -->> if 1
完成后目录为
components -->>
lvgl
lvgl_esp32_drivers
porting -->>
lv_conf.h
lv_port_disp.c
lv_port_disp.h
/* clang-format off */
#if 1 /*Set it to "1" to enable content*/ 将0设置为1
在lvgl_helpers.h 中添加屏幕尺寸
本次移植未报错SPI_HOST_MAX问题,idf v4.4可能会出问题
// #ifndef SPI_HOST_MAX
// #define SPI_HOST_MAX 3
// #endif // !SPI_HOST_MAX
#define LV_VER_RES_MAX 240
#define LV_HOR_RES_MAX 240
如果报错无法找到 portTICK_PERIOD_MS
打开sdk configuration editor -->>
FAT filesystem support -->>
FreeRTOS -->>
勾选 configENABLE_BACKWARD_COMPATIBILITY
需要在lvgl_esp32_drivers -->> CMakeLists.txt中修改编译路径如下:
idf_component_register(SRCS ${SOURCES}
INCLUDE_DIRS ${LVGL_INCLUDE_DIRS}
REQUIRES lvgl
REQUIRES driver
REQUIRES esp_rom)
如果报错头文件包含问题需要添加头文件路径:里面包含了#define SIG_GPIO_OUT_IDX256
在esp_lcd_backlight.c 中添加头文件 #include "soc/gpio_sig_map.h"
gpio_matrix_out -->> esp_rom_gpio_connect_out_signal
gpio_pad_select_gpio -->> esp_rom_gpio_pad_select_gpio
file main
CMakeLists.txt
修改为:
file(GLOB MUSIC_ASSETS_FILES "../components/lvgl/demos/music/assets/*.c") //意思是查找文件中的全部文件并且包含进来。也可以使用下面的方式包含编译文件
idf_component_register(SRCS "hello_world_main.c"
"../components/lvgl/demos/music/lv_demo_music.c"
"../components/lvgl/demos/music/lv_demo_music_list.c"
"../components/lvgl/demos/music/lv_demo_music_main.c"
${MUSIC_ASSETS_FILES}
INCLUDE_DIRS "")
然后打开sdk configuration editor ,vscode下方齿轮 或者 idf.py menuconfig
设置controller model 当前使用ST7789
修改控制引脚,查看原理图
component config 取消 Uncheck this to use custom lv_conf.h
打开Font
勾选√ Enable Montserrat 10
勾选√ Enable Montserrat 12
勾选√ Enable Montserrat 14
勾选√ Enable Montserrat 16
勾选√ Enable Montserrat 18
搜索swap
勾选√ Swap the 2 bytes of RGB565 color. Useful if the display has an 8-bit interface (e.g. SPI).
勾选√ Invert colors in display
如果找不到定时器启动和err返回值,需要在mian.c中添加头文件
#include "esp_err.h"
#include "esp_timer.h"
lvgl_esp32_drivers -->>
lvgl_helpers.c
报错DMA channel 错误只能使用AUTO DMA channel
修改为:esp_err_t ret = spi_bus_initialize(host, &buscfg, (spi_dma_chan_t)SPI_DMA_CH_AUTO);
移植完成,生成工程hello_lvgl_demo
如果发现描述不清晰的,可以直接到CSDN下载中自行下载运行:
hello_lvgl_demo