Skip to content

Commit 9e87a04

Browse files
leonardocavagnisfacchinm
authored andcommitted
add touch management in LVGLDemo example
1 parent 37a2885 commit 9e87a04

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

libraries/H7_Video/examples/LVGLDemo/LVGLDemo.ino

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#include "H7_Video.h"
22
#include "lvgl.h"
3+
#include "giga_touch.h"
34

45
H7_Video Display(480,800);
56

67
//@TODO: Complete demo with 4 main features + touch management
78

89
void setup() {
10+
Serial.begin(115200);
11+
giga_touch_setup();
12+
913
Display.begin();
1014

1115
/* Change the active screen's background color */
@@ -19,6 +23,9 @@ void setup() {
1923
}
2024

2125
void loop() {
26+
/* Touch handler */
27+
giga_touch_loop();
28+
2229
/* Feed LVGL engine */
2330
lv_timer_handler();
2431
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include <Wire.h>
2+
#include "Goodix.h" // Arduino_GT911_Library
3+
#include "pinDefinitions.h"
4+
5+
Goodix touch = Goodix();
6+
7+
REDIRECT_STDOUT_TO(Serial);
8+
9+
#ifdef ARDUINO_GIGA
10+
#define Wire Wire1
11+
#define INT_PIN PinNameToIndex(PI_1)
12+
#define RST_PIN PinNameToIndex(PI_2)
13+
#endif
14+
15+
#ifdef ARDUINO_PORTENTA_H7_M7
16+
#define Wire Wire2
17+
#define INT_PIN PinNameToIndex(PD_4)
18+
#define RST_PIN PinNameToIndex(PD_5)
19+
#endif
20+
21+
uint16_t touchpad_x;
22+
uint16_t touchpad_y;
23+
bool touchpad_pressed;
24+
25+
void handleTouch(int8_t contacts, GTPoint *points) {
26+
touchpad_pressed = true;
27+
printf("Contacts: %d\n", contacts);
28+
for (uint8_t i = 0; i < contacts; i++) {
29+
if (i == 0) {
30+
touchpad_x = points[i].x;
31+
touchpad_y = points[i].y;
32+
}
33+
printf("C%d: #%d %d,%d s:%d\n", i, points[i].trackId, points[i].x, points[i].y, points[i].area);
34+
yield();
35+
}
36+
}
37+
38+
void touchStart() {
39+
if (touch.begin(INT_PIN, RST_PIN, 0xDD) != true) {
40+
Serial.println("! Module reset failed");
41+
} else {
42+
Serial.println("Module reset OK");
43+
}
44+
45+
Serial.print("Check ACK on addr request on 0x");
46+
Serial.print(touch.i2cAddr, HEX);
47+
48+
Wire.beginTransmission(touch.i2cAddr);
49+
Wire.write(0);
50+
int error = Wire.endTransmission();
51+
if (error == 0) {
52+
Serial.println(": SUCCESS");
53+
} else {
54+
Serial.print(": ERROR #");
55+
Serial.println(error);
56+
}
57+
}
58+
59+
void giga_touch_setup() {
60+
Serial.println("\nGoodix GT911x touch driver");
61+
62+
Wire.setClock(400000);
63+
Wire.begin();
64+
delay(300);
65+
66+
touch.setHandler(handleTouch);
67+
touchStart();
68+
}
69+
70+
void giga_touch_loop() {
71+
touch.loop();
72+
delay(1);
73+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extern uint16_t touchpad_x;
2+
extern uint16_t touchpad_y;
3+
extern bool touchpad_pressed;
4+
5+
void giga_touch_setup();
6+
void giga_touch_loop();

0 commit comments

Comments
 (0)