不写任何代码-ESP32S3_espidf组件管理器使用ILI9488_LVGL
一、vscode通过组件管理器直接创建工程
1.1 使用vscode最新版本和esprssif插件最新版本
1.2 打开组件管理器后搜索ili9488
1.3 创建example project
1.4 打开工程
选择目录,创建完成后,直接打开, 删除mian.c文件下的idf_component.yml
二、使用组件管理器拉取组件
2.1 打开espidf终端,vscode左下角
2.2 拉取组件
2.3 拉取lvgl
拷贝命令,粘贴vscode插件终端里,按下回车即可
2.4 拉取其他组件
同样方法拉取其他组件
idf.py add-dependency "lvgl/lvgl^8.3.11"
idf.py add-dependency "espressif/esp_lcd_touch^1.1.1"
idf.py add-dependency "espressif/esp_lcd_touch_gt911^1.1.0"
idf.py add-dependency "atanisoft/esp_lcd_ili9488^1.0.9"
三、配置工程
3.1 编译工程
组件全部拉取后,直接编译,编译过程中会下载源码,没有意外情况都会编译成功
使用menucogfig修改管脚和LVGL相关**
3.2 修改工程kconfig
修改工程kconfig,拉取下来的不对劲,导致配置不了CS DC等管脚
menu "Pin Configuration"
menu "SPI Pins"
# SPI pin mapping is only configurable on the ESP32-S3
visible if IDF_TARGET_ESP32S3
config SPI_MISO
int "MISO pin"
default 2 if IDF_TARGET_ESP32
default 13 if IDF_TARGET_ESP32S3
range 0 48 if IDF_TARGET_ESP32S3
config SPI_MOSI
int "MOSI pin"
default 15 if IDF_TARGET_ESP32
default 10 if IDF_TARGET_ESP32S3
range 0 48 if IDF_TARGET_ESP32S3
config SPI_CLOCK
int "Clock pin"
default 14 if IDF_TARGET_ESP32
default 11 if IDF_TARGET_ESP32S3
range 0 48 if IDF_TARGET_ESP32S3
endmenu
menu "TFT Pins"
config TFT_CS_PIN
int "CS pin"
range -1 33 if IDF_TARGET_ESP32
range -1 48 if IDF_TARGET_ESP32S3
default 3 if IDF_TARGET_ESP32S3
default 16
config TFT_RESET_PIN
int "RESET pin"
range -1 33 if IDF_TARGET_ESP32
range -1 48 if IDF_TARGET_ESP32S3
default 46 if IDF_TARGET_ESP32S3
default -1
config TFT_DC_PIN
int "DC pin"
range -1 33 if IDF_TARGET_ESP32
range -1 48 if IDF_TARGET_ESP32S3
default 9 if IDF_TARGET_ESP32S3
default 17
config TFT_BACKLIGHT_PIN
int "BACKLIGHT pin"
range -1 33 if IDF_TARGET_ESP32
range -1 48 if IDF_TARGET_ESP32S3
default 12 if IDF_TARGET_ESP32S3
default 18
endmenu
endmenu
choice DISPLAY_COLOR_MODE
bool "Color Mode"
default DISPLAY_COLOR_MODE_BGR
config DISPLAY_COLOR_MODE_BGR
bool "Blue,Green,Red"
config DISPLAY_COLOR_MODE_RGB
bool "Red,Green,Blue"
endchoice
config DISPLAY_COLOR_MODE
int
default 1 if DISPLAY_COLOR_MODE_BGR
default 0 if DISPLAY_COLOR_MODE_RGB
3.3 配置LCD SPI管脚
3.4 配置LVLG相关
保存配置再次编译,编译完成后,直接烧录,如果烧录没反应,看下屏幕SPI管脚是不是占用Strapping,先把屏幕断电,再次烧录
烧录完成,直接复位,demo
四、修改屏幕显示方向
4.1 修改显示驱动
demo显示的图像是镜像的,需要修改,ili9488默认竖屏的
找到main.c里的void initialize_display()函数
需要修改以下2个函数
//注意,修改横屏竖屏,响应的lvgl显示X和Y最大值也需要对应调换
//注意,修改横屏竖屏,响应的lvgl显示X和Y最大值也需要对应调换
void initialize_lvgl()
{
ESP_LOGI(TAG, "Initializing LVGL");
lv_init();
ESP_LOGI(TAG, "Allocating %zu bytes for LVGL buffer", LV_BUFFER_SIZE * sizeof(lv_color_t));
lv_buf_1 = (lv_color_t *)heap_caps_malloc(LV_BUFFER_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
#if USE_DOUBLE_BUFFERING
ESP_LOGI(TAG, "Allocating %zu bytes for second LVGL buffer", LV_BUFFER_SIZE * sizeof(lv_color_t));
lv_buf_2 = (lv_color_t *)heap_caps_malloc(LV_BUFFER_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
#endif
ESP_LOGI(TAG, "Creating LVLG display buffer");
lv_disp_draw_buf_init(&lv_disp_buf, lv_buf_1, lv_buf_2, LV_BUFFER_SIZE);
ESP_LOGI(TAG, "Initializing %dx%d display", DISPLAY_HORIZONTAL_PIXELS, DISPLAY_VERTICAL_PIXELS);
lv_disp_drv_init(&lv_disp_drv);
lv_disp_drv.hor_res = DISPLAY_HORIZONTAL_PIXELS;//竖屏DISPLAY_HORIZONTAL_PIXELS,横屏 = DISPLAY_VERTICAL_PIXELS
lv_disp_drv.ver_res = DISPLAY_VERTICAL_PIXELS;//竖屏DISPLAY_VERTICAL_PIXELS,横屏 = DISPLAY_HORIZONTAL_PIXELS
lv_disp_drv.flush_cb = lvgl_flush_cb;
lv_disp_drv.draw_buf = &lv_disp_buf;
lv_disp_drv.user_data = lcd_handle;
lv_display = lv_disp_drv_register(&lv_disp_drv);
五、添加GT911触摸
5.1 复制触摸代码
#include "esp_lcd_touch_gt911.h"
#include "esp_lcd_touch.h"
#include "driver/i2c.h"
#define LCD_TOUCH_I2C_SDA_GPIO GPIO_NUM_39 //按自己的定义
#define LCD_TOUCH_I2C_SCL_GPIO GPIO_NUM_38
#define LCD_TOUC_I2C_PORT I2C_NUM_0
static lv_indev_drv_t indev_drv;
static lv_indev_t * lv_index = NULL;
static const char *TAGA = "GT911";
static void lvgl_touch_cb(lv_indev_drv_t * drv, lv_indev_data_t * data)
{
uint16_t touchpad_x[1] = {0};
uint16_t touchpad_y[1] = {0};
uint8_t touchpad_cnt = 0;
/* Read touch controller data */
esp_lcd_touch_read_data(drv->user_data);
/* Get coordinates */
bool touchpad_pressed = esp_lcd_touch_get_coordinates(drv->user_data, touchpad_x, touchpad_y, NULL, &touchpad_cnt, 1);
if (touchpad_pressed && touchpad_cnt > 0) {
data->point.x = touchpad_x[0];
data->point.y = touchpad_y[0];
data->state = LV_INDEV_STATE_PRESSED;
ESP_LOGI(TAG, "X=%u Y=%u", data->point.x, data->point.y);
ESP_LOGV(TAG, "X=%u Y=%u", data->point.x, data->point.y);
} else {
data->state = LV_INDEV_STATE_RELEASED;
}
}
void init_i2c(void)
{
ESP_LOGI(TAGA, "Initialize I2C");
const i2c_config_t i2c_conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = LCD_TOUCH_I2C_SDA_GPIO,
.scl_io_num = LCD_TOUCH_I2C_SCL_GPIO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = 400000,
};
/* Initialize I2C */
ESP_ERROR_CHECK(i2c_param_config(LCD_TOUC_I2C_PORT, &i2c_conf));
ESP_ERROR_CHECK(i2c_driver_install(LCD_TOUC_I2C_PORT, i2c_conf.mode, 0, 0, 0));
}
static esp_lcd_touch_handle_t tp = NULL;
void gt911_touch_init(void)
{
init_i2c();
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG();
ESP_LOGI(TAGA, "Initialize touch IC IO (I2C)");
/* Touch IO handle */
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)LCD_TOUC_I2C_PORT, &tp_io_config, &tp_io_handle));
esp_lcd_touch_config_t tp_cfg = {
.x_max = DISPLAY_HORIZONTAL_PIXELS,
.y_max = DISPLAY_VERTICAL_PIXELS,
.rst_gpio_num = -1,
.int_gpio_num = -1,
.flags = {
.swap_xy = 1,
.mirror_x = 0,
.mirror_y = 1,
},
};
/* Initialize touch */
ESP_LOGI(TAGA, "Initialize touch controller GT911");
ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_gt911(tp_io_handle, &tp_cfg, &tp));
ESP_LOGI(TAGA, "Init touch ic GT911 OK..");
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.disp = lv_display;
indev_drv.read_cb = lvgl_touch_cb;
indev_drv.user_data = tp;
lv_index = lv_indev_drv_register(&indev_drv);
if (lv_index != NULL)
{
ESP_LOGI(TAGA, "LVGL TCP register OK");
}
else
{
ESP_LOGI(TAGA, "LVGL TCP register failed");
}
}
触摸函数初始化放在主函数
5.2 修改GT911的i2c地址(非必须)
编译完成之后,如果发现GT911初始化失败,可能是GT911的i2c地址原因,修改地址
找到“esp_lcd_touch_gt911.h”
5.3 横屏显示,相应触摸也有修改
如果需要横屏显示,需要修改2处地方
上述修改,始终有问题
最后发现esp_lcd_touch.c好像有点问题
不知道是不是我没搞清楚,反正最后,修改了esp_lcd_touch.c结果是对的
链接:https://pan.baidu.com/s/1dtIEz_KWf2xUryJ8B–A5w?pwd=3qns
提取码:3qns