add xpt2046 option for spi bus 2 (#18480)

* allow spi bus 2

* xpt spi bus 2

* xpt option bus

* xpt option spi bus 2

* exclude c3

* exclude s2

* fix s3

* typo
This commit is contained in:
gemu 2023-04-23 10:19:31 +02:00 committed by GitHub
parent f9e3b25c9b
commit 799ba675eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 10 deletions

View File

@ -30,10 +30,31 @@
static XPT2046_Touchscreen *isrPinptr;
void isrPin(void);
bool XPT2046_Touchscreen::begin(SPIClass &wspi)
{
bool XPT2046_Touchscreen::begin(SPIClass &wspi) {
#ifdef ESP32
if (!bus) {
_pspi = &wspi;
} else {
#ifndef CONFIG_IDF_TARGET_ESP32C3
#ifndef CONFIG_IDF_TARGET_ESP32S2
if (bus == 1) {
_pspi = new SPIClass(HSPI);
} else {
#ifndef CONFIG_IDF_TARGET_ESP32S3
_pspi = new SPIClass(VSPI);
#endif
}
#endif
#endif
}
//Serial.printf("sclk=%d :: miso=%d, mosi=%d, irq=%d, bus=%d ", sclk, miso, mosi, tirqPin, bus);
_pspi->begin(sclk, miso, mosi, -1);
#else
_pspi = &wspi;
_pspi->begin();
#endif
pinMode(csPin, OUTPUT);
digitalWrite(csPin, HIGH);
if (255 != tirqPin) {

View File

@ -47,8 +47,8 @@ public:
class XPT2046_Touchscreen {
public:
constexpr XPT2046_Touchscreen(uint8_t cspin, uint8_t tirq=255)
: csPin(cspin), tirqPin(tirq) { }
constexpr XPT2046_Touchscreen(uint8_t cspin, uint8_t tirq=255, uint8_t bus=0, uint8_t sclk=0, uint8_t miso=0, uint8_t mosi=0)
: csPin(cspin), tirqPin(tirq), bus(bus), sclk(sclk), miso(miso), mosi(mosi) { }
bool begin(SPIClass &wspi = SPI);
#if defined(_FLEXIO_SPI_H_)
bool begin(FlexIOSPI &wflexspi);
@ -66,7 +66,7 @@ public:
private:
void update();
uint8_t csPin, tirqPin, rotation=1;
uint8_t csPin, tirqPin, rotation=1, bus=0, sclk=0, miso=0, mosi=0;
int16_t xraw=0, yraw=0, zraw=0;
uint32_t msraw=0x80000000;
SPIClass *_pspi = nullptr;

View File

@ -228,6 +228,8 @@ bool GT911_Touch_Init(TwoWire *i2c, int8_t irq_pin, int8_t rst_pin, uint16_t xs,
if (ESP_OK == GT911_touchp->begin(i2c, irq_pin, rst_pin, xs, ys)) {
AddLog(LOG_LEVEL_INFO, PSTR("TI: GT911"));
GT911_found = true;
} else {
AddLog(LOG_LEVEL_INFO, PSTR("TI: GT911 failed"));
}
return GT911_found;
}
@ -247,8 +249,31 @@ void GT911_CheckTouch(void) {
#include <XPT2046_Touchscreen.h>
XPT2046_Touchscreen *XPT2046_touchp;
bool XPT2046_Touch_Init(uint16_t CS) {
XPT2046_touchp = new XPT2046_Touchscreen(CS);
bool XPT2046_Touch_Init(uint16_t CS, int8_t irqpin, uint8_t bus) {
int8_t sclk = -1;
int8_t mosi = -1;
int8_t miso = -1;
uint8_t xbus = bus;
bus &= 1;
#ifdef ESP32
if (PinUsed(GPIO_SPI_CLK, bus) && PinUsed(GPIO_SPI_MISO, bus) && PinUsed(GPIO_SPI_MOSI, bus)) {
// must init SPI with pins
sclk = Pin(GPIO_SPI_CLK, bus);
miso = Pin(GPIO_SPI_MISO, bus);
mosi = Pin(GPIO_SPI_MOSI, bus);
}
#endif // ESP32
#ifdef ESP8266
if (PinUsed(GPIO_SPI_CLK) && PinUsed(GPIO_SPI_MISO) && PinUsed(GPIO_SPI_MOSI)) {
// must init SPI with pins
sclk = Pin(GPIO_SPI_CLK);
miso = Pin(GPIO_SPI_MISO);
mosi = Pin(GPIO_SPI_MOSI);
}
#endif // ESP8266
XPT2046_touchp = new XPT2046_Touchscreen(CS, irqpin, xbus, sclk, miso, mosi);
XPT2046_found = XPT2046_touchp->begin();
if (XPT2046_found) {
AddLog(LOG_LEVEL_INFO, PSTR("TS: XPT2046"));

View File

@ -132,7 +132,7 @@ void ILI9341_InitDriver()
#endif // ESP32
#ifdef USE_XPT2046
XPT2046_Touch_Init(Pin(GPIO_XPT2046_CS));
XPT2046_Touch_Init(Pin(GPIO_XPT2046_CS),-1,0);
#endif
tft_init_done = true;

View File

@ -392,9 +392,19 @@ int8_t cs;
#ifdef USE_XPT2046
cp = strstr(ddesc, ":TS,");
if (cp) {
cp+=4;
cp += 4;
uint8_t touch_cs = replacepin(&cp, Pin(GPIO_XPT2046_CS));
XPT2046_Touch_Init(touch_cs);
int8_t irqpin = -1;
if (*(cp - 1) == ',') {
irqpin = strtol(cp, &cp, 10);
}
uint8_t bus = 1;
if (*cp == ',') {
cp++;
bus = strtol(cp, &cp, 10);
if (bus < 1) bus = 1;
}
XPT2046_Touch_Init(touch_cs, irqpin, bus - 1);
}
#endif // USE_XPT2046