Store and use I2C address at which GT911 was found

This commit is contained in:
Scotty committed 2026-03-22 09:05:41 +01:00
1 parent f1cf2e654c
commit 67a682080d
4 files changed
+17 -11

No files matched your search

+2 -1
View File
@@ -52,7 +52,8 @@
// --- Touchscreen (GT911 capacitive) ---
#define TOUCH_INT 16
// GT911 I2C address: typically 0x5D or 0x14 (depends on INT state at boot)
#define TOUCH_I2C_ADDR 0x5D
#define TOUCH_I2C_ADDR_1 0x5D
#define TOUCH_I2C_ADDR_2 0x14
// --- Trackball ---
#define TBALL_UP 3
+12 -10
View File
@@ -9,19 +9,21 @@ bool TouchInput::begin() {
pinMode(TOUCH_INT, INPUT);
// Try GT911 at both possible addresses
Wire.beginTransmission(TOUCH_I2C_ADDR);
Wire.beginTransmission(TOUCH_I2C_ADDR_1);
uint8_t err = Wire.endTransmission();
if (err != 0) {
Wire.beginTransmission(0x14);
Wire.beginTransmission(TOUCH_I2C_ADDR_2);
err = Wire.endTransmission();
if (err != 0) {
Serial.println("[TOUCH] GT911 not found at 0x5D or 0x14");
return false;
}
Serial.println("[TOUCH] GT911 found at 0x14");
_i2cAddress = TOUCH_I2C_ADDR_2;
} else {
Serial.println("[TOUCH] GT911 found at 0x5D");
_i2cAddress = TOUCH_I2C_ADDR_1;
}
Serial.print("[TOUCH] GT911 found at 0x");
Serial.println(_i2cAddress, HEX);
Serial.println("[TOUCH] Touch input registered");
return true;
@@ -33,7 +35,7 @@ void TouchInput::update() {
bool TouchInput::readGT911() {
// Read touch status register (0x814E)
Wire.beginTransmission(TOUCH_I2C_ADDR);
Wire.beginTransmission(_i2cAddress);
Wire.write(0x81);
Wire.write(0x4E);
if (Wire.endTransmission() != 0) {
@@ -41,7 +43,7 @@ bool TouchInput::readGT911() {
return false;
}
Wire.requestFrom((uint8_t)TOUCH_I2C_ADDR, (uint8_t)1);
Wire.requestFrom(_i2cAddress, (uint8_t)1);
if (!Wire.available()) {
_touched = false;
return false;
@@ -53,7 +55,7 @@ bool TouchInput::readGT911() {
if (!bufferReady || touchCount == 0) {
_touched = false;
Wire.beginTransmission(TOUCH_I2C_ADDR);
Wire.beginTransmission(_i2cAddress);
Wire.write(0x81);
Wire.write(0x4E);
Wire.write(0x00);
@@ -62,7 +64,7 @@ bool TouchInput::readGT911() {
}
// Read first touch point (0x8150-0x8157)
Wire.beginTransmission(TOUCH_I2C_ADDR);
Wire.beginTransmission(_i2cAddress);
Wire.write(0x81);
Wire.write(0x50);
if (Wire.endTransmission() != 0) {
@@ -70,7 +72,7 @@ bool TouchInput::readGT911() {
return false;
}
Wire.requestFrom((uint8_t)TOUCH_I2C_ADDR, (uint8_t)6);
Wire.requestFrom(_i2cAddress, (uint8_t)6);
if (Wire.available() < 6) {
_touched = false;
return false;
@@ -84,7 +86,7 @@ bool TouchInput::readGT911() {
_touched = true;
// Clear buffer status
Wire.beginTransmission(TOUCH_I2C_ADDR);
Wire.beginTransmission(_i2cAddress);
Wire.write(0x81);
Wire.write(0x4E);
Wire.write(0x00);
+2
View File
@@ -18,6 +18,8 @@ public:
private:
bool readGT911();
uint8_t _i2cAddress = 0;
bool _touched = false;
int16_t _x = 0;
int16_t _y = 0;
+1
View File
@@ -121,6 +121,7 @@ void InputManager::update() {
unsigned long now = millis();
if (now - _lastTouchPoll >= TOUCH_POLL_MS) {
_lastTouchPoll = now;
// _touch->update();
if (_touch->isTouched()) {
_activity = true;
_strongActivity = true;