You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
1.8 KiB

9 months ago
  1. #define TOUCH_MODULES_GT911
  2. //#define TOUCH_MODULES_CST_SELF
  3. //#define TOUCH_MODULES_CST_MUTUAL
  4. //#define TOUCH_MODULES_ZTW622
  5. //#define TOUCH_MODULES_L58
  6. #include "Arduino.h"
  7. #include "TouchLib.h"
  8. #include "Wire.h"
  9. #define PIN_IIC_SCL 48
  10. #define PIN_IIC_SDA 8
  11. #define PIN_TOUCH_INT 1
  12. #define PIN_TOUCH_RES 2
  13. #define TOUCH_READ_FROM_INTERRNUPT 0
  14. TouchLib touch(Wire, PIN_IIC_SDA, PIN_IIC_SCL, GT911_SLAVE_ADDRESS2);
  15. void scan_i2c_device(TwoWire &i2c)
  16. {
  17. Serial.println("Scanning for I2C devices ...");
  18. Serial.print(" ");
  19. for (int i = 0; i < 0x10; i++)
  20. {
  21. Serial.printf("0x%02X|", i);
  22. }
  23. uint8_t error;
  24. for (int j = 0; j < 0x80; j += 0x10)
  25. {
  26. Serial.println();
  27. Serial.printf("0x%02X |", j);
  28. for (int i = 0; i < 0x10; i++)
  29. {
  30. Wire.beginTransmission(i | j);
  31. error = Wire.endTransmission();
  32. if (error == 0)
  33. Serial.printf("0x%02X|", i | j);
  34. else
  35. Serial.print(" -- |");
  36. }
  37. }
  38. Serial.println();
  39. }
  40. bool get_int = false;
  41. void setup()
  42. {
  43. Serial.begin(115200);
  44. Serial.println("Hello T-Display-S3");
  45. pinMode(PIN_TOUCH_RES, OUTPUT);
  46. digitalWrite(PIN_TOUCH_RES, 0);
  47. delay(200);
  48. digitalWrite(PIN_TOUCH_RES, 1);
  49. delay(200);
  50. Wire.begin(PIN_IIC_SDA, PIN_IIC_SCL);
  51. scan_i2c_device(Wire);
  52. touch.init();
  53. #if (TOUCH_READ_FROM_INTERRNUPT)
  54. attachInterrupt(
  55. PIN_TOUCH_INT,
  56. []
  57. {
  58. get_int = 1;
  59. Serial.println("get_int");
  60. },
  61. CHANGE);
  62. #endif
  63. }
  64. void loop()
  65. {
  66. delay(5);
  67. #if (TOUCH_READ_FROM_INTERRNUPT)
  68. if (get_int)
  69. {
  70. get_int = 0;
  71. touch.read();
  72. #else
  73. if (touch.read())
  74. {
  75. #endif
  76. uint8_t n = touch.getPointNum();
  77. Serial.printf("getPointNum: %d ", n);
  78. for (uint8_t i = 0; i < n; i++)
  79. {
  80. TP_Point t = touch.getPoint(i);
  81. Serial.printf("[%d] point x: %d point y: %d \r\n", i, t.x, t.y);
  82. }
  83. }
  84. }