Merge branch 'contrib/github_pr_15414' into 'master'

feat(esp32/lcd/spi_lcd_touch):Adding driver for XPT2 (GitHub PR)

Closes IDFGH-14670

See merge request espressif/esp-idf!37439
This commit is contained in:
morris
2025-03-11 15:17:49 +08:00
3 changed files with 33 additions and 10 deletions

View File

@@ -30,6 +30,18 @@ menu "Example Configuration"
bool "STMPE610"
help
Touch controller STMPE610 connected via SPI.
config EXAMPLE_LCD_TOUCH_CONTROLLER_XPT2046
bool "XPT2046"
help
Touch controller XPT2046 connected via SPI.
endchoice
config EXAMPLE_LCD_MIRROR_Y
int
default 1 if EXAMPLE_LCD_TOUCH_ENABLED && EXAMPLE_LCD_TOUCH_CONTROLLER_XPT2046
default 0
help
This value is 1 if XPT2046 touch controller is selected, 0 otherwise.
endmenu

View File

@@ -1,5 +1,6 @@
dependencies:
lvgl/lvgl: "9.2.0"
esp_lcd_ili9341: "^1.0"
esp_lcd_gc9a01: "^1.0"
esp_lcd_touch_stmpe610: "^1.0"
lvgl/lvgl: 9.2.0
esp_lcd_ili9341: ^1.0
esp_lcd_gc9a01: ^1.0
esp_lcd_touch_stmpe610: ^1.0
atanisoft/esp_lcd_touch_xpt2046: 1.0.5

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
@@ -28,6 +28,8 @@
#if CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
#include "esp_lcd_touch_stmpe610.h"
#elif CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_XPT2046
#include "esp_lcd_touch_xpt2046.h"
#endif
static const char *TAG = "example";
@@ -126,7 +128,7 @@ static void example_lvgl_flush_cb(lv_display_t *disp, const lv_area_t *area, uin
}
#if CONFIG_EXAMPLE_LCD_TOUCH_ENABLED
static void example_lvgl_touch_cb(lv_indev_t * indev, lv_indev_data_t * data)
static void example_lvgl_touch_cb(lv_indev_t *indev, lv_indev_data_t *data)
{
uint16_t touchpad_x[1] = {0};
uint16_t touchpad_y[1] = {0};
@@ -271,7 +273,12 @@ void app_main(void)
#if CONFIG_EXAMPLE_LCD_TOUCH_ENABLED
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
esp_lcd_panel_io_spi_config_t tp_io_config = ESP_LCD_TOUCH_IO_SPI_STMPE610_CONFIG(EXAMPLE_PIN_NUM_TOUCH_CS);
esp_lcd_panel_io_spi_config_t tp_io_config =
#ifdef CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
ESP_LCD_TOUCH_IO_SPI_STMPE610_CONFIG(EXAMPLE_PIN_NUM_TOUCH_CS);
#elif CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_XPT2046
ESP_LCD_TOUCH_IO_SPI_XPT2046_CONFIG(EXAMPLE_PIN_NUM_TOUCH_CS);
#endif
// Attach the TOUCH to the SPI bus
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_HOST, &tp_io_config, &tp_io_handle));
@@ -283,7 +290,7 @@ void app_main(void)
.flags = {
.swap_xy = 0,
.mirror_x = 0,
.mirror_y = 0,
.mirror_y = CONFIG_EXAMPLE_LCD_MIRROR_Y,
},
};
esp_lcd_touch_handle_t tp = NULL;
@@ -291,10 +298,13 @@ void app_main(void)
#if CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
ESP_LOGI(TAG, "Initialize touch controller STMPE610");
ESP_ERROR_CHECK(esp_lcd_touch_new_spi_stmpe610(tp_io_handle, &tp_cfg, &tp));
#endif // CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
#elif CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_XPT2046
ESP_LOGI(TAG, "Initialize touch controller XPT2046");
ESP_ERROR_CHECK(esp_lcd_touch_new_spi_xpt2046(tp_io_handle, &tp_cfg, &tp));
#endif
static lv_indev_t *indev;
indev = lv_indev_create(); // Input device driver (Touch)
indev = lv_indev_create(); // Input device driver (Touch)
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_display(indev, display);
lv_indev_set_user_data(indev, tp);