ESP32 ESP-IDF TFT-LCD(ST7735 128x160) LVGL基本配置和使用
- 📍项目地址:
https://github.com/lvgl/lv_port_esp32
- 参考文章:
https://blog.csdn.net/chentuo2000/article/details/126668088
https://blog.csdn.net/p1279030826/article/details/120128339
- 🔖ESP-IDF版本:
v5.4
- ESP32引脚功能图:
- 通过git命令将项目和所需的子模块全部下载到本地:(需要提前安装好git工具)
git clone --recurse-submodules https://github.com/lvgl/lv_port_esp32.git
SPI接口和引脚说明
ESP32 提供了两个独立的SPI主机接口,HSPI 和 VSPI.
- ESP32与ST7735 HSPI连接:
- ESP32与ST7735 VSPI连接图:
📑配置和参数修改说明
- 🌿在
st7735s.h
参数修改:
//st7735s.h
#define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 / 1 offset)
#define COLSTART 0 //默认参数:26
#define ROWSTART 0 // 默认参数:1
- 🌿在SDK配置编辑器中(menuconfig)
- 屏幕像素参数配置:
-
VSPI引脚:(可以参考前面的图进行配置)
-
字体选择:
-
demo屏幕显示示例选择:
-
触摸组件控制功能没有开启
-
🛠初次编译报错处理
- 在没有使用触摸组件情况下,编译器会报找不到相关定义:
error: 'CONFIG_LV_AXP192_PIN_SDA'
参考上面文章的做法,将启用相关宏定义
CONFIG_LV_M5STICKC_HANDLE_AXP192
的判断,来跳过对应的代码。
//st7735s.h
#ifdef CONFIG_LV_M5STICKC_HANDLE_AXP192
#define AXP192_SDA CONFIG_LV_AXP192_PIN_SDA
#define AXP192_SCL CONFIG_LV_AXP192_PIN_SCL
#endif
//st7735s.c
static void i2c_master_init()
{
#ifdef CONFIG_LV_M5STICKC_HANDLE_AXP192i2c_config_t i2c_config = {.mode = I2C_MODE_MASTER,.sda_io_num = AXP192_SDA,.scl_io_num = AXP192_SCL,.sda_pullup_en = GPIO_PULLUP_ENABLE,.scl_pullup_en = GPIO_PULLUP_ENABLE,.master.clk_speed = 400000};i2c_param_config(I2C_NUM_0, &i2c_config);i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
#endif
}
- main.c中报错
error: implicit declaration of function 'esp_timer_start_periodic' [-Wimplicit-function-declaration]
添加对应的头文件
#include "esp_timer.h" // 添加这一行
- 🌿编译找不到
gpio_pad_select_gpio
函数,使用函数替代:
esp_rom_gpio_pad_select_gpio
- 编译成功并烧录后,如果配置的demo显示示例选择的是:
Show demo widgets
,屏幕可以显示一行:Hello World
所执行的是,main.c中的下面对应的函数:
static void create_demo_application(void)
{/* When using a monochrome display we only show "Hello World" centered on the* screen */
#if defined CONFIG_LV_TFT_DISPLAY_MONOCHROME || \defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S/* use a pretty small demo for monochrome displays *//* Get the current screen */lv_obj_t * scr = lv_disp_get_scr_act(NULL);/*Create a Label on the currently active screen*/lv_obj_t * label1 = lv_label_create(scr, NULL);/*Modify the Label's text*/lv_label_set_text(label1, "Hello\nworld");/* Align the Label to the center* NULL means align on parent (which is the screen now)* 0, 0 at the end means an x, y offset after alignment*/lv_obj_align(label1, NULL, LV_ALIGN_CENTER, 0, 0);
#else/* Otherwise we show the selected demo */#if defined CONFIG_LV_USE_DEMO_WIDGETSlv_demo_widgets();#elif defined CONFIG_LV_USE_DEMO_KEYPAD_AND_ENCODERlv_demo_keypad_encoder();#elif defined CONFIG_LV_USE_DEMO_BENCHMARKlv_demo_benchmark();#elif defined CONFIG_LV_USE_DEMO_STRESSlv_demo_stress();#else#error "No demo application selected."#endif
#endif
}