From 9cfc0b882f91aa43758328c4f0b46ef6a4c25280 Mon Sep 17 00:00:00 2001 From: lewisxhe Date: Tue, 4 Jun 2024 15:33:34 +0800 Subject: [PATCH] Update GT911 example --- .../TouchDrv_GT911_GetPoint.ino | 53 ++++++++++++------- platformio.ini | 12 +++-- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/examples/TouchDrv_GT911_GetPoint/TouchDrv_GT911_GetPoint.ino b/examples/TouchDrv_GT911_GetPoint/TouchDrv_GT911_GetPoint.ino index 007282d..e0a2223 100644 --- a/examples/TouchDrv_GT911_GetPoint/TouchDrv_GT911_GetPoint.ino +++ b/examples/TouchDrv_GT911_GetPoint/TouchDrv_GT911_GetPoint.ino @@ -58,12 +58,11 @@ void setup() Serial.begin(115200); while (!Serial); - Wire.begin(SENSOR_SDA, SENSOR_SCL); /* - * The touch reset pin uses hardware pull-up, - * and the function of setting the I2C device address cannot be used. - * Use scanning to obtain the touch device address. - * * */ + + If the touch reset pin and interrupt pin cannot be controlled by GPIO, the device address cannot be controlled and can only be obtained by scanning. + + Wire.begin(SENSOR_SDA, SENSOR_SCL); uint8_t touchAddress = 0; Wire.beginTransmission(0x14); if (Wire.endTransmission() == 0) { @@ -79,40 +78,56 @@ void setup() delay(1000); } } - touch.setPins(SENSOR_RST, SENSOR_IRQ); - if (!touch.begin(Wire, touchAddress, SENSOR_SDA, SENSOR_SCL )) { while (1) { Serial.println("Failed to find GT911 - check your wiring!"); delay(1000); } } + * + * * */ + + // If the reset pin and interrupt pin can be controlled by GPIO, the device address can be set arbitrarily + touch.setPins(SENSOR_RST, SENSOR_IRQ); + if (!touch.begin(Wire, GT911_SLAVE_ADDRESS_H, SENSOR_SDA, SENSOR_SCL )) { + while (1) { + Serial.println("Failed to find GT911 - check your wiring!"); + delay(1000); + } + } //Set to trigger on falling edge touch.setInterruptMode(FALLING); Serial.println("Init GT911 Sensor success!"); + // Set the center button to trigger the callback , Only for specific devices, e.g LilyGo-EPD47 S3 GT911 + touch.setHomeButtonCallback([](void *user_data) { + Serial.println("Home button pressed!"); + }, NULL); + } void loop() { if (touch.isPressed()) { uint8_t touched = touch.getPoint(x, y, touch.getSupportTouchPoint()); - for (int i = 0; i < touched; ++i) { - Serial.print("X["); - Serial.print(i); - Serial.print("]:"); - Serial.print(x[i]); - Serial.print(" "); - Serial.print(" Y["); - Serial.print(i); - Serial.print("]:"); - Serial.print(y[i]); - Serial.print(" "); + if (touched > 0) { + for (int i = 0; i < touched; ++i) { + Serial.print("X["); + Serial.print(i); + Serial.print("]:"); + Serial.print(x[i]); + Serial.print(" "); + Serial.print(" Y["); + Serial.print(i); + Serial.print("]:"); + Serial.print(y[i]); + Serial.print(" "); + } + Serial.println(); } - Serial.println(); } delay(5); } diff --git a/platformio.ini b/platformio.ini index b818a5c..7e8787e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,18 +51,18 @@ ; src_dir = examples/TouchDrv_GT911_LilyGo_T_RGB ; src_dir = examples/TouchDrv_Interface_T_RGB ; src_dir = examples/TouchDrv_FT6232_GetPoint -; src_dir = examples/TouchDrv_GT911_GetPoint +src_dir = examples/TouchDrv_GT911_GetPoint ; src_dir = examples/TouchDrv_CHSC5816_GetPoint ; src_dir = examples/TouchDrv_CSTxxx_GetPoint ; default_envs = esp32-s3n4r2 -; default_envs=esp32s3-opi +default_envs=esp32s3-opi ; default_envs=esp32s3-qspi ; default_envs=esp32c3 ; default_envs=esp32dev ; default_envs = rp2040 -default_envs = nrf52840 +; default_envs = nrf52840 ; Custom board variant boards_dir = ./board @@ -123,6 +123,12 @@ build_flags = ; -DSENSOR_IRQ=8 ; -DSENSOR_RST=17 + ; T-EPD47 S3 GT911 2 Point touch✅ + -DSENSOR_SDA=6 + -DSENSOR_SCL=5 + -DSENSOR_IRQ=15 + -DSENSOR_RST=41 + -DCORE_DEBUG_LEVEL=5 -Wnarrowing -Wtype-limits