diff --git a/src/drv/touch/touch_driver.h b/src/drv/touch/touch_driver.h index f3e2ccfd..a7b07d6f 100644 --- a/src/drv/touch/touch_driver.h +++ b/src/drv/touch/touch_driver.h @@ -1,110 +1,113 @@ -/* MIT License - Copyright (c) 2019-2024 Francis Van Roie - For full license information read the LICENSE file in the project folder */ - -#ifndef HASP_BASE_TOUCH_DRIVER_H -#define HASP_BASE_TOUCH_DRIVER_H - -#ifdef ARDUINO -#include -#endif - -#include "hasplib.h" -#include "lvgl.h" - -namespace dev { - -class BaseTouch { - public: - void init(int w, int h) - {} - // void loop() - // {} - void show_info() - {} - void set_rotation(uint8_t rotation) - {} - void set_invert(bool invert_display) - {} - IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data) - { - data->state = LV_INDEV_STATE_REL; - return false; - } - void calibrate(uint16_t* calData) - {} - void set_calibration(uint16_t* calData) - {} - bool is_driver_pin(uint8_t) - { - return false; - } - const char* get_touch_model() - { - return ""; - } -}; - -} // namespace dev - -#ifndef TOUCH_DRIVER -#define TOUCH_DRIVER -1 // No Touch -#endif - -#if TOUCH_DRIVER == 0x2046 && defined(USER_SETUP_LOADED) -#warning Building for TFT_eSPI XPT2046 -//#include "touch_driver_xpt2046.h" -#include "touch_driver_tftespi.h" -#elif TOUCH_DRIVER == 0x2046 && defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH) -#warning Building for LovyanGFX XPT2046 -#include "touch_driver_lovyangfx.h" -#elif TOUCH_DRIVER == 0x0911 && defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH) -#warning Building for LovyanGFX GT911 -#include "touch_driver_lovyangfx.h" -#elif TOUCH_DRIVER == 0x6336 && defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH) -#warning Building for LovyanGFX FT6336 -#include "touch_driver_lovyangfx.h" -#elif defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH) -#warning Building for LovyanGFX -#include "touch_driver_lovyangfx.h" -#elif TOUCH_DRIVER == 0x5206 -#warning Building for FT5206 -#include "touch_driver_ft5206.h" -#elif TOUCH_DRIVER == 0x6336 -#warning Building for FT6336 -#include "touch_driver_ft6336u.h" -#elif TOUCH_DRIVER == 0x0610 -#warning Building for STMPE610 -#include "touch_driver_stmpe610.h" -#elif TOUCH_DRIVER == 0x0911 -#warning Building for GT911 -#include "touch_driver_gt911.h" -#elif TOUCH_DRIVER == 0x0ADC -#warning Building for analog touch -#include "touch_driver_analog.h" -#elif TOUCH_DRIVER == 0x1680 -#warning Building for GSL1680 -#include "touch_driver_gslx680.h" -#elif TOUCH_DRIVER == 0x2007 -#warning Building for TSC2007 -#include "touch_driver_tsc2007.h" -#elif defined(LGFX_USE_V1) -#warning Building for LovyanGfx Touch -#include "touch_driver_lovyangfx.h" -#elif TOUCH_DRIVER == 0x3240 -#warning Building for CST3240 -#include "touch_driver_cst3240.h" -#else -#warning Building for Generic Touch -using dev::BaseTouch; -extern dev::BaseTouch haspTouch; -// IRAM_ATTR bool touch_read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data) -// { -// data->state = LV_INDEV_STATE_REL; -// return false; -// } -#endif - -#endif - -// #elif TOUCH_DRIVER == 0x2046B -// touched = XPT2046_getXY(&normal_x, &normal_y, true); +/* MIT License - Copyright (c) 2019-2024 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_BASE_TOUCH_DRIVER_H +#define HASP_BASE_TOUCH_DRIVER_H + +#ifdef ARDUINO +#include +#endif + +#include "hasplib.h" +#include "lvgl.h" + +namespace dev { + +class BaseTouch { + public: + void init(int w, int h) + {} + // void loop() + // {} + void show_info() + {} + void set_rotation(uint8_t rotation) + {} + void set_invert(bool invert_display) + {} + IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data) + { + data->state = LV_INDEV_STATE_REL; + return false; + } + void calibrate(uint16_t* calData) + {} + void set_calibration(uint16_t* calData) + {} + bool is_driver_pin(uint8_t) + { + return false; + } + const char* get_touch_model() + { + return ""; + } +}; + +} // namespace dev + +#ifndef TOUCH_DRIVER +#define TOUCH_DRIVER -1 // No Touch +#endif + +#if TOUCH_DRIVER == 0x2046 && defined(USER_SETUP_LOADED) +#warning Building for TFT_eSPI XPT2046 +//#include "touch_driver_xpt2046.h" +#include "touch_driver_tftespi.h" +#elif TOUCH_DRIVER == 0x2046 && defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH) +#warning Building for LovyanGFX XPT2046 +#include "touch_driver_lovyangfx.h" +#elif TOUCH_DRIVER == 0x0911 && defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH) +#warning Building for LovyanGFX GT911 +#include "touch_driver_lovyangfx.h" +#elif TOUCH_DRIVER == 0x6336 && defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH) +#warning Building for LovyanGFX FT6336 +#include "touch_driver_lovyangfx.h" +#elif defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH) +#warning Building for LovyanGFX +#include "touch_driver_lovyangfx.h" +#elif TOUCH_DRIVER == 0x5206 +#warning Building for FT5206 +#include "touch_driver_ft5206.h" +#elif TOUCH_DRIVER == 0x6336 +#warning Building for FT6336 +#include "touch_driver_ft6336u.h" +#elif TOUCH_DRIVER == 0x0610 +#warning Building for STMPE610 +#include "touch_driver_stmpe610.h" +#elif TOUCH_DRIVER == 0x0911 +#warning Building for GT911 +#include "touch_driver_gt911.h" +#elif TOUCH_DRIVER == 0x0ADC +#warning Building for analog touch +#include "touch_driver_analog.h" +#elif TOUCH_DRIVER == 0x1680 +#warning Building for GSL1680 +#include "touch_driver_gslx680.h" +#elif TOUCH_DRIVER == 0x2007 +#warning Building for TSC2007 +#include "touch_driver_tsc2007.h" +#elif defined(LGFX_USE_V1) +#warning Building for LovyanGfx Touch +#include "touch_driver_lovyangfx.h" +#elif TOUCH_DRIVER == 0x3240 +#warning Building for CST3240 +#include "touch_driver_cst3240.h" +#elif TOUCH_DRIVER == 0x816 +#warning Building for CST816S +#include "touch_driver_cst816.h" +#else +#warning Building for Generic Touch +using dev::BaseTouch; +extern dev::BaseTouch haspTouch; +// IRAM_ATTR bool touch_read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data) +// { +// data->state = LV_INDEV_STATE_REL; +// return false; +// } +#endif + +#endif + +// #elif TOUCH_DRIVER == 0x2046B +// touched = XPT2046_getXY(&normal_x, &normal_y, true); diff --git a/src/drv/touch/touch_driver_cst816.cpp b/src/drv/touch/touch_driver_cst816.cpp new file mode 100644 index 00000000..1cba9435 --- /dev/null +++ b/src/drv/touch/touch_driver_cst816.cpp @@ -0,0 +1,70 @@ +/* MIT License - Copyright (c) 2019-2024 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#if defined(ARDUINO) && (TOUCH_DRIVER == 0x816) +#include +#include "ArduinoLog.h" +#include "hasp_conf.h" +#include "touch_driver_cst816.h" + +#include +#include "cst816t.h" + +#include "touch_driver.h" // base class +#include "touch_helper.h" // i2c scanner + +#include "../../hasp/hasp.h" // for hasp_sleep_state +extern uint8_t hasp_sleep_state; + +cst816t touchpad(Wire, TOUCH_RST, TOUCH_IRQ); + +namespace dev { + +IRAM_ATTR bool TouchCst816::read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data) +{ + if(touchpad.available()) { + + if(hasp_sleep_state != HASP_SLEEP_OFF) hasp_update_sleep_state(); // update Idle + //LOG_INFO(TAG_DRVR, "CST816 touched x:%d, y:%d", touchpad.x, touchpad.y); + +#ifdef TOUCH_WIDTH + data->point.x = map(x, 0, TOUCH_WIDTH - 1, 0, TFT_WIDTH - 1); +#else + data->point.x = touchpad.x; +#endif + +#ifdef TOUCH_HEIGHT + data->point.y = map(y, 0, TOUCH_HEIGHT - 1, 0, TFT_HEIGHT - 1); +#else + data->point.y = touchpad.y; +#endif + + data->state = LV_INDEV_STATE_PR; + hasp_set_sleep_offset(0); // Reset the offset + + } else { + data->state = LV_INDEV_STATE_REL; + } + + /*Return `false` because we are not buffering and no more data to read*/ + return false; +} + +void TouchCst816::init(int w, int h) +{ + Wire.begin(TOUCH_SDA, TOUCH_SCL, (uint32_t)I2C_TOUCH_FREQUENCY); + if(touchpad.begin(mode_touch) == true) { + LOG_INFO(TAG_DRVR, "CST816 %s (170X320)", D_SERVICE_STARTED); + } else { + LOG_WARNING(TAG_DRVR, "CST816 %s", D_SERVICE_START_FAILED); + } + + Wire.begin(TOUCH_SDA, TOUCH_SCL, (uint32_t)I2C_TOUCH_FREQUENCY); + touch_scan(Wire); // The address could change during begin, so scan afterwards +} + +} // namespace dev + +dev::TouchCst816 haspTouch; + +#endif // ARDUINO diff --git a/src/drv/touch/touch_driver_cst816.h b/src/drv/touch/touch_driver_cst816.h new file mode 100644 index 00000000..8b632e06 --- /dev/null +++ b/src/drv/touch/touch_driver_cst816.h @@ -0,0 +1,27 @@ +/* MIT License - Copyright (c) 2019-2024 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_CST816_TOUCH_DRIVER_H +#define HASP_CST816_TOUCH_DRIVER_H + +#ifdef ARDUINO +#include "lvgl.h" +#include "touch_driver.h" + +namespace dev { + +class TouchCst816 : public BaseTouch { + public: + IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data); + void init(int w, int h); +}; + +} // namespace dev + +using dev::TouchCst816; +extern dev::TouchCst816 haspTouch; + +#endif // ARDUINO + +#endif // HASP_CST816_TOUCH_DRIVER_H + \ No newline at end of file