diff --git a/src/input/TouchScreenCST226SE.cpp b/src/input/TouchScreenCST226SE.cpp index ff0b39a7a..b99ff067b 100644 --- a/src/input/TouchScreenCST226SE.cpp +++ b/src/input/TouchScreenCST226SE.cpp @@ -3,35 +3,38 @@ #ifdef HAS_CST226SE +#ifndef TOUCH_IRQ +#define TOUCH_IRQ -1 +#endif + #include "PowerFSM.h" #include "Wire.h" #include "configuration.h" #include "modules/ExternalNotificationModule.h" -volatile bool CST_IRQ = false; +volatile bool isPressed = false; TouchScreenCST226SE *TouchScreenCST226SE::instance = nullptr; TouchScreenCST226SE *touchScreenCST226SE; TouchScreenCST226SE::TouchScreenCST226SE(uint16_t width, uint16_t height, bool (*getTouch)(int16_t *, int16_t *)) - : TouchScreenBase("touchscreen1", width, height), _getTouch(getTouch) + : TouchScreenBase("CST226", width, height), _getTouch(getTouch) { instance = this; } void TouchScreenCST226SE::init() { + touch.setPins(-1, TOUCH_IRQ); + touch.setTouchDrvModel(TouchDrv_CST226); for (uint8_t addr : PossibleAddresses) { if (touch.begin(Wire, addr, I2C_SDA, I2C_SCL)) { i2cAddress = addr; - - // #ifdef TOUCHSCREEN_INT - // pinMode(TOUCHSCREEN_INT, INPUT); - // attachInterrupt( - // TOUCHSCREEN_INT, [] { CST_IRQ = true; }, RISING); - // #endif - + attachInterrupt( + TOUCH_IRQ, []() { isPressed = true; }, FALLING); LOG_DEBUG("CST226SE init OK at address 0x%02X", addr); + touch.setMaxCoordinates(TFT_WIDTH + 5, TFT_HEIGHT + 5); + touch.setMirrorXY(true, true); return; } } @@ -41,17 +44,18 @@ void TouchScreenCST226SE::init() bool TouchScreenCST226SE::getTouch(int16_t &x, int16_t &y) { - if (!touch.isPressed()) + if (!touch.isPressed()) { return false; - int16_t x_array[1], y_array[1]; - uint8_t count = touch.getPoint(x_array, y_array, 1); - if (count > 0) { - x = x_array[0]; - y = y_array[0]; - return true; + int16_t x_array[1], y_array[1]; + uint8_t touched = touch.getPoint(x_array, y_array, 1); + if (touched > 0) { + x = x_array[0]; + y = y_array[0]; + LOG_DEBUG("TouchScreen touched %dx %dy", x, y); + return true; + } } - return false; } @@ -59,10 +63,10 @@ bool TouchScreenCST226SE::forwardGetTouch(int16_t *x, int16_t *y) { if (instance) { return instance->getTouch(*x, *y); - LOG_DEBUG("TouchScreen touched %dx %dy", x, y); + LOG_DEBUG("TouchScreen parsed %dx %dy", x, y); + } else { + return false; } - - return false; } void TouchScreenCST226SE::onEvent(const TouchEvent &event) diff --git a/src/input/TouchScreenCST226SE.h b/src/input/TouchScreenCST226SE.h index fe5b81229..26bc7a449 100644 --- a/src/input/TouchScreenCST226SE.h +++ b/src/input/TouchScreenCST226SE.h @@ -6,8 +6,8 @@ #include "modules/CannedMessageModule.h" +#include "TouchDrvCSTXXX.hpp" #include "TouchScreenBase.h" -#include "touch/TouchClassCST226.h" class TouchScreenCST226SE : public TouchScreenBase { @@ -17,14 +17,12 @@ class TouchScreenCST226SE : public TouchScreenBase static bool forwardGetTouch(int16_t *x, int16_t *y); bool (*_getTouch)(int16_t *, int16_t *); - - protected: virtual bool getTouch(int16_t &x, int16_t &y); virtual void onEvent(const TouchEvent &event); private: static TouchScreenCST226SE *instance; - TouchClassCST226 touch; + TouchDrvCSTXXX touch; uint8_t i2cAddress = 0; static constexpr uint8_t PossibleAddresses[2] = {CST226SE_ADDR, CST226SE_ADDR_ALT}; diff --git a/variants/tbeam/platformio.ini b/variants/tbeam/platformio.ini index d345b164b..41a805849 100644 --- a/variants/tbeam/platformio.ini +++ b/variants/tbeam/platformio.ini @@ -22,4 +22,4 @@ build_flags = lib_deps = ${env:tbeam.lib_deps} https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.5.zip ; display addon - lewisxhe/SensorLib@0.2.0 ; touchscreen addon + lewisxhe/SensorLib@0.3.1 ; touchscreen addon diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 04801e678..4cf409165 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -53,7 +53,7 @@ #define HAS_CST226SE 1 #define HAS_TOUCHSCREEN 1 -#define TOUCHSCREEN_INT 35 +#define TOUCH_IRQ 35 #define ST7796_NSS 25 #define ST7796_RS 13 // DC