add stmpe610 touch driver

This commit is contained in:
arovak 2021-02-28 00:13:15 +01:00
parent 489ccd4034
commit 51a6a73967
3 changed files with 77 additions and 0 deletions

View File

@ -23,6 +23,8 @@
#include "drv/touch/hasp_drv_ft5206.h"
#elif TOUCH_DRIVER == 6336
#include "drv/touch/hasp_drv_ft6336u.h"
#elif TOUCH_DRIVER == 610
#include "drv/touch/hasp_drv_stmpe610.h"
#else
//#include "tp_i2c.h"
//#include "ft6x36.h"
@ -56,6 +58,9 @@ void drv_touch_init(uint8_t rotation)
#elif TOUCH_DRIVER == 6336
FT6336U_init();
#elif TOUCH_DRIVER == 610
STMPE610_init();
#else
// xpt2046_alt_drv_read(indev_driver, data);
// xpt2046_read(indev_driver, data);
@ -86,6 +91,9 @@ static inline bool drv_touchpad_getXY(int16_t* touchX, int16_t* touchY)
#elif TOUCH_DRIVER == 6336
touched = FT6336U_getXY(&normal_x, &normal_y, true);
#elif TOUCH_DRIVER == 610
touched = STMPE610_getXY(&normal_x, &normal_y, drv_touch_rotation, true);
#else
// xpt2046_alt_drv_read(indev_driver, data);
// xpt2046_read(indev_driver, data);

View File

@ -0,0 +1,54 @@
#if TOUCH_DRIVER == 610
#include <SPI.h>
#include "Adafruit_STMPE610.h"
#include "ArduinoLog.h"
#include "hasp_drv_stmpe610.h"
// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 3800
#define TS_MAXX 100
#define TS_MINY 100
#define TS_MAXY 3750
static Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS);
// Read touch points from global variable
bool IRAM_ATTR STMPE610_getXY(int16_t * touchX, int16_t * touchY, uint8_t touchRotation, bool debug)
{
uint16_t x, y;
uint8_t z;
if(! touch.touched()) return false;
while (! touch.bufferEmpty()) {
touch.readData(&x, &y, &z);
if(debug) Log.trace(TAG_DRVR, F("STMPE610: x=%i y=%i z=%i r=%i"), x, y, z, touchRotation);
}
touch.writeRegister8(STMPE_INT_STA, 0xFF);
if (1 == touchRotation) {
y = map(y, TS_MINX, TS_MAXX, 0, TFT_WIDTH);
x = map(x, TS_MINY, TS_MAXY, 0, TFT_HEIGHT);
} else if (2 == touchRotation) {
x = map(x, TS_MAXX, TS_MINX, 0, TFT_WIDTH);
y = map(y, TS_MAXY, TS_MINY, 0, TFT_HEIGHT);
} else {
x = map(x, TS_MINX, TS_MAXX, 0, TFT_WIDTH);
y = map(y, TS_MINY, TS_MAXY, 0, TFT_HEIGHT);
}
*touchX = x;
*touchY = y;
return true;
}
void STMPE610_init()
{
if (! touch.begin()) {
Log.trace(TAG_DRVR, F("STMPE610 not found!"));
} else {
Log.trace(TAG_DRVR, F("STMPE610 touch driver started"));
}
}
#endif

View File

@ -0,0 +1,15 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_DRV_STMPE610_H
#define HASP_DRV_STMPE610_H
#if TOUCH_DRIVER == 610
#include "hasp_debug.h" // for TAG_DRVR
bool IRAM_ATTR STMPE610_getXY(int16_t * touchX, int16_t * touchY, uint8_t touchRotation, bool debug);
void STMPE610_init();
#endif
#endif