Skip to content

Commit 2011b9f

Browse files
committed
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
2 parents 28472cc + ee4de6e commit 2011b9f

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

examples/peripherals/lcd/spi_lcd_touch/main/Kconfig.projbuild

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ menu "Example Configuration"
3030
bool "STMPE610"
3131
help
3232
Touch controller STMPE610 connected via SPI.
33+
34+
config EXAMPLE_LCD_TOUCH_CONTROLLER_XPT2046
35+
bool "XPT2046"
36+
help
37+
Touch controller XPT2046 connected via SPI.
3338
endchoice
3439

40+
config EXAMPLE_LCD_MIRROR_Y
41+
int
42+
default 1 if EXAMPLE_LCD_TOUCH_ENABLED && EXAMPLE_LCD_TOUCH_CONTROLLER_XPT2046
43+
default 0
44+
help
45+
This value is 1 if XPT2046 touch controller is selected, 0 otherwise.
46+
3547
endmenu
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
dependencies:
2-
lvgl/lvgl: "9.2.0"
3-
esp_lcd_ili9341: "^1.0"
4-
esp_lcd_gc9a01: "^1.0"
5-
esp_lcd_touch_stmpe610: "^1.0"
2+
lvgl/lvgl: 9.2.0
3+
esp_lcd_ili9341: ^1.0
4+
esp_lcd_gc9a01: ^1.0
5+
esp_lcd_touch_stmpe610: ^1.0
6+
atanisoft/esp_lcd_touch_xpt2046: 1.0.5

examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
*/
@@ -28,6 +28,8 @@
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

3335
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
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

Comments
 (0)