From ee4de6e545e4cc1588ab2c283a9c4e456751813c Mon Sep 17 00:00:00 2001 From: Quang Vinh Dang Date: Tue, 18 Feb 2025 00:17:19 -0800 Subject: [PATCH] feat(lcd): support XPT2046 in the SPI LCD example Merges https://github.com/espressif/esp-idf/pull/15414 --- .../lcd/spi_lcd_touch/main/Kconfig.projbuild | 12 ++++++++++ .../lcd/spi_lcd_touch/main/idf_component.yml | 9 ++++---- .../main/spi_lcd_touch_example_main.c | 22 ++++++++++++++----- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/examples/peripherals/lcd/spi_lcd_touch/main/Kconfig.projbuild b/examples/peripherals/lcd/spi_lcd_touch/main/Kconfig.projbuild index 683c6eb168..c457c6befc 100644 --- a/examples/peripherals/lcd/spi_lcd_touch/main/Kconfig.projbuild +++ b/examples/peripherals/lcd/spi_lcd_touch/main/Kconfig.projbuild @@ -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 diff --git a/examples/peripherals/lcd/spi_lcd_touch/main/idf_component.yml b/examples/peripherals/lcd/spi_lcd_touch/main/idf_component.yml index 9f43889e3d..e721dcc8f8 100644 --- a/examples/peripherals/lcd/spi_lcd_touch/main/idf_component.yml +++ b/examples/peripherals/lcd/spi_lcd_touch/main/idf_component.yml @@ -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 diff --git a/examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c b/examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c index 7388ae80b9..ad5d8b1bfb 100644 --- a/examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c +++ b/examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c @@ -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);