mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-26 20:26:32 +00:00
Add support for CST816S touch interface (#20213)
* Add initial version (prints coordinates) * Add CST816S_found * Revert formatting * Add supported gestures (untested) * Correct use of enums * Remove library dependency * Unification of methods * Remove redundant variables and format
This commit is contained in:
parent
2204ecdc51
commit
6b35fc8ddb
@ -71,6 +71,7 @@ typedef struct TSGlobal_t {
|
|||||||
|
|
||||||
TSGlobal_t TSGlobal;
|
TSGlobal_t TSGlobal;
|
||||||
|
|
||||||
|
bool CST816S_found = false;
|
||||||
bool FT5206_found = false;
|
bool FT5206_found = false;
|
||||||
bool GT911_found = false;
|
bool GT911_found = false;
|
||||||
bool XPT2046_found = false;
|
bool XPT2046_found = false;
|
||||||
@ -97,7 +98,7 @@ void Touch_SetStatus(uint8_t touches, uint16_t raw_x, uint16_t raw_y, uint8_t ge
|
|||||||
// return true if succesful, false if not configured
|
// return true if succesful, false if not configured
|
||||||
bool Touch_GetStatus(uint8_t* touches, uint16_t* x, uint16_t* y, uint8_t* gesture,
|
bool Touch_GetStatus(uint8_t* touches, uint16_t* x, uint16_t* y, uint8_t* gesture,
|
||||||
uint16_t* raw_x, uint16_t* raw_y) {
|
uint16_t* raw_x, uint16_t* raw_y) {
|
||||||
if (TSGlobal.external_ts || FT5206_found || XPT2046_found) {
|
if (TSGlobal.external_ts || CST816S_found || FT5206_found || XPT2046_found) {
|
||||||
if (touches) { *touches = TSGlobal.touches; }
|
if (touches) { *touches = TSGlobal.touches; }
|
||||||
if (x) { *x = TSGlobal.touch_xp; }
|
if (x) { *x = TSGlobal.touch_xp; }
|
||||||
if (y) { *y = TSGlobal.touch_yp; }
|
if (y) { *y = TSGlobal.touch_yp; }
|
||||||
@ -110,7 +111,7 @@ bool Touch_GetStatus(uint8_t* touches, uint16_t* x, uint16_t* y, uint8_t* gestur
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Touch_Status(int32_t sel) {
|
uint32_t Touch_Status(int32_t sel) {
|
||||||
if (TSGlobal.external_ts || FT5206_found || GT911_found || XPT2046_found || SRES_found) {
|
if (TSGlobal.external_ts || CST816S_found || FT5206_found || GT911_found || XPT2046_found || SRES_found) {
|
||||||
switch (sel) {
|
switch (sel) {
|
||||||
case 0:
|
case 0:
|
||||||
return TSGlobal.touched;
|
return TSGlobal.touched;
|
||||||
@ -185,6 +186,62 @@ int16_t SRES_y() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_CST816S
|
||||||
|
#undef CST816S_address
|
||||||
|
#define CST816S_address 0x15
|
||||||
|
|
||||||
|
bool CST816S_event_available = false;
|
||||||
|
uint8_t CST816S_bus = 0;
|
||||||
|
|
||||||
|
uint8_t CST816S_map_gesture(uint8_t gesture) {
|
||||||
|
switch (gesture) {
|
||||||
|
case 0x01: return TS_Gest_Move_Up; // SWIPE_UP
|
||||||
|
case 0x02: return TS_Gest_Move_Down; // SWIPE_DOWN
|
||||||
|
case 0x03: return TS_Gest_Move_Left; // SWIPE_LEFT
|
||||||
|
case 0x04: return TS_Gest_Move_Right; // SWIPE_RIGHT
|
||||||
|
case 0x05: return TS_Gest_None; // SINGLE_CLICK
|
||||||
|
case 0x0B: return TS_Gest_None; // DOUBLE_CLICK
|
||||||
|
case 0x0C: return TS_Gest_None; // LONG_PRESS
|
||||||
|
default: return TS_Gest_None; // NONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CST816S_available() {
|
||||||
|
if (CST816S_event_available) {
|
||||||
|
byte data_raw[8];
|
||||||
|
I2cReadBuffer(CST816S_address, 0x01, data_raw, 6, CST816S_bus);
|
||||||
|
TSGlobal.raw_touch_xp = ((data_raw[2] & 0xF) << 8) + data_raw[3];
|
||||||
|
TSGlobal.raw_touch_yp = ((data_raw[4] & 0xF) << 8) + data_raw[5];
|
||||||
|
TSGlobal.gesture = CST816S_map_gesture(data_raw[0]);
|
||||||
|
CST816S_event_available = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CST816S_Touch_Init(uint8_t bus, int8_t irq_pin, int8_t rst_pin, int interrupt = RISING) {
|
||||||
|
CST816S_found = false;
|
||||||
|
CST816S_bus = bus;
|
||||||
|
pinMode(irq_pin, INPUT);
|
||||||
|
pinMode(rst_pin, OUTPUT);
|
||||||
|
digitalWrite(rst_pin, HIGH);
|
||||||
|
delay(50);
|
||||||
|
digitalWrite(rst_pin, LOW);
|
||||||
|
delay(5);
|
||||||
|
digitalWrite(rst_pin, HIGH);
|
||||||
|
delay(50);
|
||||||
|
uint8_t version;
|
||||||
|
I2cReadBuffer(CST816S_address, 0x15, &version, 1, CST816S_bus);
|
||||||
|
delay(5);
|
||||||
|
uint8_t versionInfo[3];
|
||||||
|
I2cReadBuffer(CST816S_address, 0xA7, versionInfo, 3, CST816S_bus);
|
||||||
|
attachInterrupt(irq_pin, []{ CST816S_event_available = true; }, interrupt);
|
||||||
|
CST816S_found = true;
|
||||||
|
AddLog(LOG_LEVEL_INFO, PSTR("TI: CST816S, version: %d, versionInfo: %d.%d.%d"), version, versionInfo[0], versionInfo[1], versionInfo[2]);
|
||||||
|
return CST816S_found;
|
||||||
|
}
|
||||||
|
#endif // USE_CST816S
|
||||||
|
|
||||||
#ifdef USE_FT5206
|
#ifdef USE_FT5206
|
||||||
#include <FT5206.h>
|
#include <FT5206.h>
|
||||||
// touch panel controller
|
// touch panel controller
|
||||||
@ -307,6 +364,12 @@ void Touch_Check(void(*rotconvert)(int16_t *x, int16_t *y)) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_CST816S
|
||||||
|
if (CST816S_found) {
|
||||||
|
TSGlobal.touched = CST816S_available();
|
||||||
|
}
|
||||||
|
#endif // USE_CST816S
|
||||||
|
|
||||||
#ifdef USE_FT5206
|
#ifdef USE_FT5206
|
||||||
if (FT5206_found) {
|
if (FT5206_found) {
|
||||||
TSGlobal.touched = FT5206_touched();
|
TSGlobal.touched = FT5206_touched();
|
||||||
@ -360,7 +423,7 @@ void Touch_Check(void(*rotconvert)(int16_t *x, int16_t *y)) {
|
|||||||
#endif // USE_TOUCH_BUTTONS
|
#endif // USE_TOUCH_BUTTONS
|
||||||
|
|
||||||
rotconvert(&TSGlobal.touch_xp, &TSGlobal.touch_yp);
|
rotconvert(&TSGlobal.touch_xp, &TSGlobal.touch_yp);
|
||||||
AddLog(LOG_LEVEL_DEBUG_MORE, "TS : TSGlobal.touched x=%i y=%i (raw x=%i y=%i)", TSGlobal.touch_xp, TSGlobal.touch_yp, TSGlobal.raw_touch_xp, TSGlobal.raw_touch_yp);
|
AddLog(LOG_LEVEL_DEBUG_MORE, "TS : TSGlobal.touched x=%i y=%i gest=0x%02x (raw x=%i y=%i)", TSGlobal.touch_xp, TSGlobal.touch_yp, TSGlobal.gesture, TSGlobal.raw_touch_xp, TSGlobal.raw_touch_yp);
|
||||||
|
|
||||||
#ifdef USE_TOUCH_BUTTONS
|
#ifdef USE_TOUCH_BUTTONS
|
||||||
CheckTouchButtons(TSGlobal.touched, TSGlobal.touch_xp, TSGlobal.touch_yp);
|
CheckTouchButtons(TSGlobal.touched, TSGlobal.touch_xp, TSGlobal.touch_yp);
|
||||||
@ -522,7 +585,7 @@ bool Xdrv55(uint32_t function) {
|
|||||||
case FUNC_INIT:
|
case FUNC_INIT:
|
||||||
break;
|
break;
|
||||||
case FUNC_EVERY_100_MSECOND:
|
case FUNC_EVERY_100_MSECOND:
|
||||||
if (FT5206_found || XPT2046_found || GT911_found || SRES_found) {
|
if (CST816S_found || FT5206_found || XPT2046_found || GT911_found || SRES_found) {
|
||||||
Touch_Check(TS_RotConvert);
|
Touch_Check(TS_RotConvert);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -35,6 +35,8 @@ extern FS *ffsp;
|
|||||||
|
|
||||||
#undef GT911_address
|
#undef GT911_address
|
||||||
#define GT911_address 0x5D
|
#define GT911_address 0x5D
|
||||||
|
#undef CST816S_address
|
||||||
|
#define CST816S_address 0x15
|
||||||
|
|
||||||
enum {GPIO_DP_RES=GPIO_SENSOR_END-1,GPIO_DP_CS,GPIO_DP_RS,GPIO_DP_WR,GPIO_DP_RD,GPIO_DPAR0,GPIO_DPAR1,GPIO_DPAR2,GPIO_DPAR3,GPIO_DPAR4,GPIO_DPAR5,GPIO_DPAR6,GPIO_DPAR7,GPIO_DPAR8,GPIO_DPAR9,GPIO_DPAR10,GPIO_DPAR11,GPIO_DPAR12,GPIO_DPAR13,GPIO_DPAR14,GPIO_DPAR15};
|
enum {GPIO_DP_RES=GPIO_SENSOR_END-1,GPIO_DP_CS,GPIO_DP_RS,GPIO_DP_WR,GPIO_DP_RD,GPIO_DPAR0,GPIO_DPAR1,GPIO_DPAR2,GPIO_DPAR3,GPIO_DPAR4,GPIO_DPAR5,GPIO_DPAR6,GPIO_DPAR7,GPIO_DPAR8,GPIO_DPAR9,GPIO_DPAR10,GPIO_DPAR11,GPIO_DPAR12,GPIO_DPAR13,GPIO_DPAR14,GPIO_DPAR15};
|
||||||
|
|
||||||
@ -312,7 +314,7 @@ int8_t cs;
|
|||||||
udisp = new uDisplay(ddesc);
|
udisp = new uDisplay(ddesc);
|
||||||
|
|
||||||
// checck for touch option TI1 or TI2
|
// checck for touch option TI1 or TI2
|
||||||
#if defined(USE_FT5206) || defined(USE_GT911)
|
#if defined (USE_CST816S) || defined(USE_FT5206) || defined(USE_GT911)
|
||||||
cp = strstr(ddesc, ":TI");
|
cp = strstr(ddesc, ":TI");
|
||||||
if (cp) {
|
if (cp) {
|
||||||
uint8_t wire_n = 1;
|
uint8_t wire_n = 1;
|
||||||
@ -350,6 +352,8 @@ int8_t cs;
|
|||||||
if (I2cSetDevice(i2caddr, wire_n)) {
|
if (I2cSetDevice(i2caddr, wire_n)) {
|
||||||
if (i2caddr == GT911_address) {
|
if (i2caddr == GT911_address) {
|
||||||
I2cSetActiveFound(i2caddr, "GT911", wire_n);
|
I2cSetActiveFound(i2caddr, "GT911", wire_n);
|
||||||
|
} else if (i2caddr == CST816S_address) {
|
||||||
|
I2cSetActiveFound(i2caddr, "CST816S", wire_n);
|
||||||
} else {
|
} else {
|
||||||
I2cSetActiveFound(i2caddr, "FT5206", wire_n);
|
I2cSetActiveFound(i2caddr, "FT5206", wire_n);
|
||||||
}
|
}
|
||||||
@ -361,6 +365,8 @@ int8_t cs;
|
|||||||
if (I2cSetDevice(i2caddr)) {
|
if (I2cSetDevice(i2caddr)) {
|
||||||
if (i2caddr == GT911_address) {
|
if (i2caddr == GT911_address) {
|
||||||
I2cSetActiveFound(i2caddr, "GT911");
|
I2cSetActiveFound(i2caddr, "GT911");
|
||||||
|
} else if (i2caddr == CST816S_address) {
|
||||||
|
I2cSetActiveFound(i2caddr, "CST816S");
|
||||||
} else {
|
} else {
|
||||||
I2cSetActiveFound(i2caddr, "FT5206");
|
I2cSetActiveFound(i2caddr, "FT5206");
|
||||||
}
|
}
|
||||||
@ -373,6 +379,10 @@ int8_t cs;
|
|||||||
#ifdef USE_GT911
|
#ifdef USE_GT911
|
||||||
if (!wire_n) GT911_Touch_Init(&Wire, irq, rst, xs, ys);
|
if (!wire_n) GT911_Touch_Init(&Wire, irq, rst, xs, ys);
|
||||||
else GT911_Touch_Init(&Wire1, irq, rst, xs, ys);
|
else GT911_Touch_Init(&Wire1, irq, rst, xs, ys);
|
||||||
|
#endif
|
||||||
|
} else if (i2caddr == CST816S_address) {
|
||||||
|
#ifdef USE_CST816S
|
||||||
|
CST816S_Touch_Init(wire_n, irq, rst);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#ifdef USE_FT5206
|
#ifdef USE_FT5206
|
||||||
@ -386,6 +396,10 @@ int8_t cs;
|
|||||||
if (i2caddr == GT911_address) {
|
if (i2caddr == GT911_address) {
|
||||||
#ifdef USE_GT911
|
#ifdef USE_GT911
|
||||||
if (!wire_n) GT911_Touch_Init(&Wire, irq, rst, xs, ys);
|
if (!wire_n) GT911_Touch_Init(&Wire, irq, rst, xs, ys);
|
||||||
|
#endif
|
||||||
|
} else if (i2caddr == CST816S_address) {
|
||||||
|
#ifdef USE_CST816S
|
||||||
|
CST816S_Touch_Init(wire_n, irq, rst);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#ifdef USE_FT5206
|
#ifdef USE_FT5206
|
||||||
|
Loading…
x
Reference in New Issue
Block a user