Skip to content

Commit 5352e15

Browse files
authored
Merge pull request #2657 from makermelissa/main
Update Qualia image to work with both types of touchscreens
2 parents c1adfab + ad5c48b commit 5352e15

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

Factory_Tests/Qualia_ESP32S3_RGB666_FactoryTest/Qualia_ESP32S3_RGB666_FactoryTest.ino

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <Arduino_GFX_Library.h>
66
#include <Adafruit_FT6206.h>
7+
#include <Adafruit_CST8XX.h>
78

89
Arduino_XCA9554SWSPI *expander = new Arduino_XCA9554SWSPI(
910
PCA_TFT_RESET, PCA_TFT_CS, PCA_TFT_SCK, PCA_TFT_MOSI,
@@ -49,11 +50,18 @@ Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
4950

5051
uint16_t *colorWheel;
5152

53+
// The Capacitive touchscreen overlays uses hardware I2C (SCL/SDA)
5254

53-
// The FTxxxx based CTP overlays uses hardware I2C (SCL/SDA)
54-
#define I2C_TOUCH_ADDR 0x48 // often but not always 0x38!
55-
Adafruit_FT6206 ctp = Adafruit_FT6206(); // this library also supports FT5336U!
55+
// Most touchscreens use FocalTouch with I2C Address often but not always 0x48!
56+
#define I2C_TOUCH_ADDR 0x48
57+
58+
// 2.1" 480x480 round display use CST826 touchscreen with I2C Address at 0x15
59+
//#define I2C_TOUCH_ADDR 0x15 // often but not always 0x48!
60+
61+
Adafruit_FT6206 focal_ctp = Adafruit_FT6206(); // this library also supports FT5336U!
62+
Adafruit_CST8XX cst_ctp = Adafruit_CST8XX();
5663
bool touchOK = false; // we will check if the touchscreen exists
64+
bool isFocalTouch = false;
5765

5866
void setup(void)
5967
{
@@ -85,21 +93,36 @@ void setup(void)
8593
gfx->draw16bitRGBBitmap(0, 0, colorWheel, gfx->width(), gfx->height());
8694
}
8795

88-
if (!ctp.begin(0, &Wire, I2C_TOUCH_ADDR)) {
89-
Serial.println("No touchscreen found");
90-
touchOK = false;
96+
if (!focal_ctp.begin(0, &Wire, I2C_TOUCH_ADDR)) {
97+
// Try the CST826 Touch Screen
98+
if (!cst_ctp.begin(&Wire, I2C_TOUCH_ADDR)) {
99+
Serial.print("No Touchscreen found at address 0x");
100+
Serial.println(I2C_TOUCH_ADDR, HEX);
101+
touchOK = false;
102+
} else {
103+
Serial.println("CST826 Touchscreen found");
104+
touchOK = true;
105+
isFocalTouch = false;
106+
}
91107
} else {
92-
Serial.println("Touchscreen found");
108+
Serial.println("Focal Touchscreen found");
93109
touchOK = true;
110+
isFocalTouch = true;
94111
}
95112
}
96113

97114
void loop()
98115
{
99-
if (touchOK && ctp.touched()) {
100-
TS_Point p = ctp.getPoint(0);
101-
Serial.printf("(%d, %d)\n", p.x, p.y);
102-
gfx->fillRect(p.x, p.y, 5, 5, WHITE);
116+
if (touchOK) {
117+
if (isFocalTouch && focal_ctp.touched()) {
118+
TS_Point p = focal_ctp.getPoint(0);
119+
Serial.printf("(%d, %d)\n", p.x, p.y);
120+
gfx->fillRect(p.x, p.y, 5, 5, WHITE);
121+
} else if (!isFocalTouch && cst_ctp.touched()) {
122+
CST_TS_Point p = cst_ctp.getPoint(0);
123+
Serial.printf("(%d, %d)\n", p.x, p.y);
124+
gfx->fillRect(p.x, p.y, 5, 5, WHITE);
125+
}
103126
}
104127

105128
// use the buttons to turn off

0 commit comments

Comments
 (0)