From 698fa01d7ea2e698e24e2e0be95c0398c8da9a36 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 12 Feb 2022 11:07:01 +0100 Subject: [PATCH] Add GSL1680 touch driver #250 --- platformio.ini | 2 +- src/drv/touch/touch_driver.h | 3 + src/drv/touch/touch_driver_gslx680.h | 100 +++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/drv/touch/touch_driver_gslx680.h diff --git a/platformio.ini b/platformio.ini index 4795c51f..817ff48d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -76,7 +76,7 @@ lib_deps = bblanchon/ArduinoJson@^6.19.1 ; Json(l) parser bblanchon/StreamUtils@1.6.1 ; for EEPromStream knolleary/PubSubClient@^2.8.0 ; MQTT client - git+https://github.com/fvanroie/ConsoleInput.git + ;git+https://github.com/fvanroie/ConsoleInput.git ;git+https://github.com/andrethomas/TasmotaSlave.git ;git+https://github.com/lvgl/lvgl.git git+https://github.com/lvgl/lvgl.git#release/v7 diff --git a/src/drv/touch/touch_driver.h b/src/drv/touch/touch_driver.h index 1142bb34..aa63a493 100644 --- a/src/drv/touch/touch_driver.h +++ b/src/drv/touch/touch_driver.h @@ -70,6 +70,9 @@ class BaseTouch { #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" #else #warning Building for Generic Touch using dev::BaseTouch; diff --git a/src/drv/touch/touch_driver_gslx680.h b/src/drv/touch/touch_driver_gslx680.h new file mode 100644 index 00000000..9d76563c --- /dev/null +++ b/src/drv/touch/touch_driver_gslx680.h @@ -0,0 +1,100 @@ +/* MIT License - Copyright (c) 2019-2022 Francis Van Roie + For full license information read the LICENSE file in the project folder */ + +#ifndef HASP_GSL1680_TOUCH_DRIVER_H +#define HASP_GSL1680_TOUCH_DRIVER_H + +#ifdef ARDUINO +#include "hasp_conf.h" + +#include +#include +#include "GSL2038.h" +#include "ArduinoLog.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; + +namespace dev { + +class TouchGsl1680 : public BaseTouch { + private: + // Interrupt handling + volatile uint8_t gsl16380IRQ = 0; + static GSL2038 TS = GSL2038(1, 1); // error & info + + // Store touch points into global variable + void ICACHE_RAM_ATTR ontouch_irq() + { + noInterrupts(); + gsl16380IRQ = 1; + interrupts(); + } + + public: + IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data) + { + noInterrupts(); + uint8_t irq = gsl16380IRQ; + gsl16380IRQ = 0; + interrupts(); + + if(irq && TS.dataread() > 0) { + + if(hasp_sleep_state != HASP_SLEEP_OFF) hasp_update_sleep_state(); // update Idle + + data->point.x = map(TS.readFingerX(0), 0, 1024, 0, TFT_WIDTH); + data->point.y = map(TS.readFingerY(0), 45, 660, 0, TFT_HEIGHT); + + if(data->point.x < 0) + data->point.x = 0; + else if(data->point.x > TFT_WIDTH) + data->point.x = TFT_WIDTH; + + if(data->point.y < 0) + data->point.y = 0; + else if(data->point.y > TFT_HEIGHT) + data->point.y = TFT_HEIGHT; + + data->state = LV_INDEV_STATE_PR; + + } else { + data->state = LV_INDEV_STATE_REL; + } + + /*Return `false` because we are not buffering and no more data to read*/ + return false; + } + + void init(int w, int h) + { + Wire.begin(TOUCH_SDA, TOUCH_SCL, (uint32_t)I2C_TOUCH_FREQUENCY); + // delay(300); // already happens in touch.begin() + touch_scan(Wire); + + // Startup sequence CONTROLER part + TS.begin(TOUCH_SDA, TOUCH_SCL, TOUCH_RST, TOUCH_IRQ); + + // Setup Interrupt handler + pinMode(TOUCH_IRQ, INPUT); + attachInterrupt(TOUCH_IRQ, ontouch_irq, RISING); + + // if(touch.begin(INT_PIN, RST_PIN)) { + LOG_INFO(TAG_DRVR, F("GSL1680 " D_SERVICE_STARTED)); + // } else { + // LOG_WARNING(TAG_DRVR, F("GSL1680 " D_SERVICE_START_FAILED)); + // } + } +}; + +} // namespace dev + +using dev::TouchGsl1680; +extern dev::TouchGsl1680 haspTouch; + +#endif // ARDUINO + +#endif // HASP_GSL1680_TOUCH_DRIVER_H