11/*
2- * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: CC0-1.0
55 */
2828
2929#if CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
3030#include "esp_lcd_touch_stmpe610.h"
31+ #elif CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_XPT2046
32+ #include "esp_lcd_touch_xpt2046.h"
3133#endif
3234
3335static const char * TAG = "example" ;
@@ -126,7 +128,7 @@ static void example_lvgl_flush_cb(lv_display_t *disp, const lv_area_t *area, uin
126128}
127129
128130#if CONFIG_EXAMPLE_LCD_TOUCH_ENABLED
129- static void example_lvgl_touch_cb (lv_indev_t * indev , lv_indev_data_t * data )
131+ static void example_lvgl_touch_cb (lv_indev_t * indev , lv_indev_data_t * data )
130132{
131133 uint16_t touchpad_x [1 ] = {0 };
132134 uint16_t touchpad_y [1 ] = {0 };
@@ -271,7 +273,12 @@ void app_main(void)
271273
272274#if CONFIG_EXAMPLE_LCD_TOUCH_ENABLED
273275 esp_lcd_panel_io_handle_t tp_io_handle = NULL ;
274- esp_lcd_panel_io_spi_config_t tp_io_config = ESP_LCD_TOUCH_IO_SPI_STMPE610_CONFIG (EXAMPLE_PIN_NUM_TOUCH_CS );
276+ esp_lcd_panel_io_spi_config_t tp_io_config =
277+ #ifdef CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
278+ ESP_LCD_TOUCH_IO_SPI_STMPE610_CONFIG (EXAMPLE_PIN_NUM_TOUCH_CS );
279+ #elif CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_XPT2046
280+ ESP_LCD_TOUCH_IO_SPI_XPT2046_CONFIG (EXAMPLE_PIN_NUM_TOUCH_CS );
281+ #endif
275282 // Attach the TOUCH to the SPI bus
276283 ESP_ERROR_CHECK (esp_lcd_new_panel_io_spi ((esp_lcd_spi_bus_handle_t )LCD_HOST , & tp_io_config , & tp_io_handle ));
277284
@@ -283,18 +290,21 @@ void app_main(void)
283290 .flags = {
284291 .swap_xy = 0 ,
285292 .mirror_x = 0 ,
286- .mirror_y = 0 ,
293+ .mirror_y = CONFIG_EXAMPLE_LCD_MIRROR_Y ,
287294 },
288295 };
289296 esp_lcd_touch_handle_t tp = NULL ;
290297
291298#if CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
292299 ESP_LOGI (TAG , "Initialize touch controller STMPE610" );
293300 ESP_ERROR_CHECK (esp_lcd_touch_new_spi_stmpe610 (tp_io_handle , & tp_cfg , & tp ));
294- #endif // CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
301+ #elif CONFIG_EXAMPLE_LCD_TOUCH_CONTROLLER_XPT2046
302+ ESP_LOGI (TAG , "Initialize touch controller XPT2046" );
303+ ESP_ERROR_CHECK (esp_lcd_touch_new_spi_xpt2046 (tp_io_handle , & tp_cfg , & tp ));
304+ #endif
295305
296306 static lv_indev_t * indev ;
297- indev = lv_indev_create (); // Input device driver (Touch)
307+ indev = lv_indev_create (); // Input device driver (Touch)
298308 lv_indev_set_type (indev , LV_INDEV_TYPE_POINTER );
299309 lv_indev_set_display (indev , display );
300310 lv_indev_set_user_data (indev , tp );
0 commit comments