-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathArduino_GigaDisplayTouch.h
138 lines (120 loc) · 4.88 KB
/
Arduino_GigaDisplayTouch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Copyright 2023 Arduino SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/**
* @file Arduino_GigaDisplayTouch.h
* @author Leonardo Cavagnis
* @brief Header file for the Arduino Giga Display Touch library.
*
* This library allows to capture up to 5 concurrent touch points on Arduino Giga Display Shield.
* Supported controller: Goodix GT911
*/
#ifndef __ARDUINO_GIGADISPLAYTOUCH_H
#define __ARDUINO_GIGADISPLAYTOUCH_H
/* Includes ------------------------------------------------------------------*/
#include <Arduino.h>
#include "Wire.h"
#include "mbed.h"
#include "pinDefinitions.h"
/* Exported defines ----------------------------------------------------------*/
#define GT911_I2C_ADDR_BA_BB (0x5D | 0x80) // 0xBA/0xBB - 0x5D (7bit address)
#define GT911_I2C_ADDR_28_29 (0x14 | 0x80) // 0x28/0x29 - 0x14 (7bit address)
#define GT911_CONTACT_SIZE 8
#define GT911_MAX_CONTACTS 5
/* Exported types ------------------------------------------------------------*/
typedef struct GDTpoint_s GDTpoint_t;
/* Exported enumeration ------------------------------------------------------*/
/* Exported struct -----------------------------------------------------------*/
/**
* @brief Struct representing a touch point.
*/
struct GDTpoint_s {
// 0x814F-0x8156, ... 0x8176 (5 points)
uint8_t trackId;
uint16_t x;
uint16_t y;
uint16_t area;
uint8_t reserved;
};
/* Class ----------------------------------------------------------------------*/
/**
* @class Arduino_GigaDisplayTouch
* @brief Class for Giga Display Touch controller driver.
*/
class Arduino_GigaDisplayTouch {
public:
/**
* @brief Construct a new touch controller for Giga Display Shield.
*
* @param wire A reference to the Wire interface to be used for communication with the touch controller.
* @param intPin The interrupt pin number for the touch controller.
* @param rstPin The reset pin number for the touch controller.
* @param addr The device address for the touch controller.
*/
#if defined(ARDUINO_GIGA)
Arduino_GigaDisplayTouch(TwoWire& wire = Wire1,
uint8_t intPin = PinNameToIndex(PI_1),
uint8_t rstPin = PinNameToIndex(PI_2),
uint8_t addr = GT911_I2C_ADDR_BA_BB);
#elif defined(ARDUINO_PORTENTA_H7_M7)
Arduino_GigaDisplayTouch(TwoWire& wire = Wire,
uint8_t intPin = PinNameToIndex(PD_4),
uint8_t rstPin = PinNameToIndex(PD_5),
uint8_t addr = GT911_I2C_ADDR_BA_BB);
#else
Arduino_GigaDisplayTouch(TwoWire& wire,
uint8_t intPin,
uint8_t rstPin,
uint8_t addr);
#endif
~Arduino_GigaDisplayTouch();
/**
* @brief Initialize the touch controller.
*
* @return true If the touch controller is successfully initialized, false Otherwise
*/
bool begin();
/**
* @brief De-initialize the touch controller.
*/
void end();
/**
* @brief Check if a touch event is detected and get the touch points.
* @param points The array containing the coordinates of the touch points.
* @return uint8_t The number of detected touch points.
*/
uint8_t getTouchPoints(GDTpoint_t* points);
/**
* @brief Attach an interrupt handler function for touch detection callbacks.
* @param handler The pointer to the user-defined handler function.
*/
void onDetect(void (*handler)(uint8_t, GDTpoint_t*));
private:
TwoWire& _wire;
uint8_t _intPin;
mbed::InterruptIn _irqInt;
uint8_t _rstPin;
uint8_t _addr;
GDTpoint_t _points[GT911_MAX_CONTACTS];
void (*_gt911TouchHandler)(uint8_t, GDTpoint_t*);
uint8_t _gt911WriteOp(uint16_t reg, uint8_t data);
uint8_t _gt911WriteBytesOp(uint16_t reg, uint8_t * data, uint8_t len);
uint8_t _gt911ReadOp(uint16_t reg, uint8_t * data, uint8_t len);
void _gt911onIrq();
uint8_t _gt911ReadInputCoord(uint8_t * pointsbuf, uint8_t& contacts);
};
#endif /* __ARDUINO_GIGADISPLAYTOUCH_H */