From 67796eaead26634f4175c41b4a4d1b05d6ca9476 Mon Sep 17 00:00:00 2001 From: Rene Zeldenthuis Date: Sun, 24 Sep 2023 00:53:12 +0200 Subject: [PATCH] - ESP32_2432S024N does not have touch! - Optiomize x/y calculation --- src/esp32_smartdisplay.cpp | 2 +- src/touch_cst820.cpp | 21 ++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/esp32_smartdisplay.cpp b/src/esp32_smartdisplay.cpp index 2937a1c..61500ba 100644 --- a/src/esp32_smartdisplay.cpp +++ b/src/esp32_smartdisplay.cpp @@ -159,7 +159,7 @@ void smartdisplay_init() // Clear screen lv_obj_clean(lv_scr_act()); -#if !defined(ESP32_8048S070N) +#if !defined(ESP32_2432S024N) && !defined(ESP32_8048S070N) // Setup touch lvgl_touch_init(); static lv_indev_drv_t indev_drv; diff --git a/src/touch_cst820.cpp b/src/touch_cst820.cpp index 9de9c3d..61938be 100644 --- a/src/touch_cst820.cpp +++ b/src/touch_cst820.cpp @@ -58,26 +58,21 @@ bool cst820_read_touch(uint16_t *x, uint16_t *y, uint8_t *gesture) if (!cst820_read_register(0x03, data, 4)) return false; - *x = ((data[0] & 0x0f) << 8) | data[1]; - *y = ((data[2] & 0x0f) << 8) | data[3]; - #ifdef TFT_ORIENTATION_PORTRAIT - *x = TFT_WIDTH - *x; - *y = TFT_HEIGHT - *y; + *x = TFT_WIDTH - (((data[0] & 0x0f) << 8) | data[1]); + *y = TFT_HEIGHT - (((data[2] & 0x0f) << 8) | data[3]); #else #ifdef TFT_ORIENTATION_LANDSCAPE - uint16_t swap; - swap = *x; - *x = *y; - *y = TFT_WIDTH - swap; + *x = ((data[2] & 0x0f) << 8) | data[3]; + *y = TFT_WIDTH - (((data[0] & 0x0f) << 8) | data[1]); #else #ifdef TFT_ORIENTATION_PORTRAIT_INV + *x = ((data[0] & 0x0f) << 8) | data[1]; + *y = ((data[2] & 0x0f) << 8) | data[3]; #else #ifdef TFT_ORIENTATION_LANDSCAPE_INV - uint16_t swap; - swap = *x; - *x = TFT_HEIGHT - *y; - *y = swap; + *x = TFT_HEIGHT - (((data[2] & 0x0f) << 8) | data[3]); + *y = ((data[0] & 0x0f) << 8) | data[1]; #else #error TFT_ORIENTATION not defined! #endif