mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-27 05:06:44 +00:00
Add GSL1680 touch driver #250
This commit is contained in:
parent
1dd847af03
commit
698fa01d7e
@ -76,7 +76,7 @@ lib_deps =
|
|||||||
bblanchon/ArduinoJson@^6.19.1 ; Json(l) parser
|
bblanchon/ArduinoJson@^6.19.1 ; Json(l) parser
|
||||||
bblanchon/StreamUtils@1.6.1 ; for EEPromStream
|
bblanchon/StreamUtils@1.6.1 ; for EEPromStream
|
||||||
knolleary/PubSubClient@^2.8.0 ; MQTT client
|
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/andrethomas/TasmotaSlave.git
|
||||||
;git+https://github.com/lvgl/lvgl.git
|
;git+https://github.com/lvgl/lvgl.git
|
||||||
git+https://github.com/lvgl/lvgl.git#release/v7
|
git+https://github.com/lvgl/lvgl.git#release/v7
|
||||||
|
@ -70,6 +70,9 @@ class BaseTouch {
|
|||||||
#elif TOUCH_DRIVER == 0x0ADC
|
#elif TOUCH_DRIVER == 0x0ADC
|
||||||
#warning Building for analog touch
|
#warning Building for analog touch
|
||||||
#include "touch_driver_analog.h"
|
#include "touch_driver_analog.h"
|
||||||
|
#elif TOUCH_DRIVER == 0x1680
|
||||||
|
#warning Building for GSL1680
|
||||||
|
#include "touch_driver_gslx680.h"
|
||||||
#else
|
#else
|
||||||
#warning Building for Generic Touch
|
#warning Building for Generic Touch
|
||||||
using dev::BaseTouch;
|
using dev::BaseTouch;
|
||||||
|
100
src/drv/touch/touch_driver_gslx680.h
Normal file
100
src/drv/touch/touch_driver_gslx680.h
Normal file
@ -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 <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#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
|
Loading…
x
Reference in New Issue
Block a user