SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
touch/TouchDrvGT911.hpp
Go to the documentation of this file.
1
30#pragma once
31
32#include "../SensorBuildOpt.h"
33#if !SENSORLIB_EXCLUDE_TOUCH_GT911
34
35#include "TouchDrvInterface.hpp"
36
38// #define ENABLE_GT911_CONFIG
39
40
41#if defined(ARDUINO_ARCH_NRF52)
42// NRF52840 I2C BUFFER : 64 Bytes ,
43#warning "NRF Platform I2C Buffer expansion is not implemented , GT911 requires at least 188 bytes to read all configurations"
44#endif
45
46static constexpr uint8_t GT911_SLAVE_ADDRESS_H = (0x14);
47static constexpr uint8_t GT911_SLAVE_ADDRESS_L = (0x5D);
48static constexpr uint8_t GT911_SLAVE_ADDRESS_UNKNOWN = (0xFF);
49
51{
52public:
54
61
66 TouchDrvGT911() = default;
67
72 ~TouchDrvGT911() = default;
73
81 void sleep() override;
82
88 void wakeup() override;
89
95 const TouchPoints &getTouchPoints() override;
96
102 const char *getModelName() override;
103
111
122
128 uint32_t getChipID() override;
129
135 uint16_t getFwVersion();
136
142 uint8_t getConfigVersion();
143
150 void updateRefreshRate(uint8_t rate_ms);
151
157 uint8_t getRefreshRate();
158
164 int getVendorID();
165
166#ifdef ENABLE_GT911_CONFIG
174 bool writeConfig(const uint8_t *config_buffer, size_t buffer_size);
175#endif
176
185 uint8_t *loadConfig(size_t *output_size, bool print_out = false);
186
192 bool reloadConfig();
193
200 void setMaxTouchPoint(uint8_t num);
201
202
203private:
210 uint8_t readGT911(uint16_t cmd);
218 int writeGT911(uint16_t cmd, uint8_t value);
219
226 void writeCommand(uint8_t command);
227
233 void clearBuffer();
234
240 bool probeAddress();
241
242 bool initImpl(uint8_t) override;
243
244 bool autoProbe();
245
246
247
248 static constexpr uint8_t MAX_FINGER_NUM = (5);
249 static constexpr uint8_t BYTES_PER_POINT = (8);
250
251protected:
252 // Real-time command (Write only)
253 static constexpr uint16_t GT911_COMMAND = (0x8040);
254 static constexpr uint16_t GT911_ESD_CHECK = (0x8041);
255 static constexpr uint16_t GT911_COMMAND_CHECK = (0x8046);
256 static constexpr uint8_t IRQ_TRIGGER_MASK = (0x03);
257
258 // Configuration information (R/W)
259 static constexpr uint16_t GT911_CONFIG_START = (0x8047);
260 static constexpr uint16_t GT911_CONFIG_VERSION = (0x8047);
261 static constexpr uint16_t GT911_X_OUTPUT_MAX_LOW = (0x8048);
262 static constexpr uint16_t GT911_X_OUTPUT_MAX_HIGH = (0x8049);
263 static constexpr uint16_t GT911_Y_OUTPUT_MAX_LOW = (0x804A);
264 static constexpr uint16_t GT911_Y_OUTPUT_MAX_HIGH = (0x804B);
265 static constexpr uint16_t GT911_TOUCH_NUMBER = (0x804C);
266 static constexpr uint16_t GT911_MODULE_SWITCH_1 = (0x804D);
267 static constexpr uint16_t GT911_MODULE_SWITCH_2 = (0x804E);
268 static constexpr uint16_t GT911_SHAKE_COUNT = (0x804F);
269 static constexpr uint16_t GT911_FILTER = (0x8050);
270 static constexpr uint16_t GT911_LARGE_TOUCH = (0x8051);
271 static constexpr uint16_t GT911_NOISE_REDUCTION = (0x8052);
272 static constexpr uint16_t GT911_SCREEN_TOUCH_LEVEL = (0x8053);
273 static constexpr uint16_t GT911_SCREEN_RELEASE_LEVEL = (0x8054);
274 static constexpr uint16_t GT911_LOW_POWER_CONTROL = (0x8055);
275 static constexpr uint16_t GT911_REFRESH_RATE = (0x8056);
276 static constexpr uint16_t GT911_X_THRESHOLD = (0x8057);
277 static constexpr uint16_t GT911_Y_THRESHOLD = (0x8058);
278 static constexpr uint16_t GT911_X_SPEED_LIMIT = (0x8059); // Reserve
279 static constexpr uint16_t GT911_Y_SPEED_LIMIT = (0x805A); // Reserve
280 static constexpr uint16_t GT911_SPACE_TOP_BOTTOM = (0x805B);
281 static constexpr uint16_t GT911_SPACE_LEFT_RIGHT = (0x805C);
282 static constexpr uint16_t GT911_MINI_FILTER = (0x805D);
283 static constexpr uint16_t GT911_STRETCH_R0 = (0x805E);
284 static constexpr uint16_t GT911_STRETCH_R1 = (0x805F);
285 static constexpr uint16_t GT911_STRETCH_R2 = (0x8060);
286 static constexpr uint16_t GT911_STRETCH_RM = (0x8061);
287 static constexpr uint16_t GT911_DRV_GROUPA_NUM = (0x8062);
288 static constexpr uint16_t GT911_DRV_GROUPB_NUM = (0x8063);
289 static constexpr uint16_t GT911_SENSOR_NUM = (0x8064);
290 static constexpr uint16_t GT911_FREQ_A_FACTOR = (0x8065);
291 static constexpr uint16_t GT911_FREQ_B_FACTOR = (0x8066);
292 static constexpr uint16_t GT911_PANEL_BIT_FREQ_L = (0x8067);
293 static constexpr uint16_t GT911_PANEL_BIT_FREQ_H = (0x8068);
294 static constexpr uint16_t GT911_PANEL_SENSOR_TIME_L = (0x8069); // Reserve
295 static constexpr uint16_t GT911_PANEL_SENSOR_TIME_H = (0x806A);
296 static constexpr uint16_t GT911_PANEL_TX_GAIN = (0x806B);
297 static constexpr uint16_t GT911_PANEL_RX_GAIN = (0x806C);
298 static constexpr uint16_t GT911_PANEL_DUMP_SHIFT = (0x806D);
299 static constexpr uint16_t GT911_DRV_FRAME_CONTROL = (0x806E);
300 static constexpr uint16_t GT911_CHARGING_LEVEL_UP = (0x806F);
301 static constexpr uint16_t GT911_MODULE_SWITCH3 = (0x8070);
302 static constexpr uint16_t GT911_GESTURE_DIS = (0X8071);
303 static constexpr uint16_t GT911_GESTURE_LONG_PRESS_TIME = (0x8072);
304 static constexpr uint16_t GT911_X_Y_SLOPE_ADJUST = (0X8073);
305 static constexpr uint16_t GT911_GESTURE_CONTROL = (0X8074);
306 static constexpr uint16_t GT911_GESTURE_SWITCH1 = (0X8075);
307 static constexpr uint16_t GT911_GESTURE_SWITCH2 = (0X8076);
308 static constexpr uint16_t GT911_GESTURE_REFRESH_RATE = (0x8077);
309 static constexpr uint16_t GT911_GESTURE_TOUCH_LEVEL = (0x8078);
310 static constexpr uint16_t GT911_NEWGREENWAKEUPLEVEL = (0x8079);
311 static constexpr uint16_t GT911_FREQ_HOPPING_START = (0x807A);
312 static constexpr uint16_t GT911_FREQ_HOPPING_END = (0X807B);
313 static constexpr uint16_t GT911_NOISE_DETECT_TIMES = (0x807C);
314 static constexpr uint16_t GT911_HOPPING_FLAG = (0X807D);
315 static constexpr uint16_t GT911_HOPPING_THRESHOLD = (0X807E);
316 static constexpr uint16_t GT911_NOISE_THRESHOLD = (0X807F); // Reserve
317 static constexpr uint16_t GT911_NOISE_MIN_THRESHOLD = (0X8080);
318 static constexpr uint16_t GT911_HOPPING_SENSOR_GROUP = (0X8082);
319 static constexpr uint16_t GT911_HOPPING_SEG1_NORMALIZE = (0X8083);
320 static constexpr uint16_t GT911_HOPPING_SEG1_FACTOR = (0X8084);
321 static constexpr uint16_t GT911_MAIN_CLOCK_ADJUST = (0X8085);
322 static constexpr uint16_t GT911_HOPPING_SEG2_NORMALIZE = (0X8086);
323 static constexpr uint16_t GT911_HOPPING_SEG2_FACTOR = (0X8087);
324 static constexpr uint16_t GT911_HOPPING_SEG3_NORMALIZE = (0X8089);
325 static constexpr uint16_t GT911_HOPPING_SEG3_FACTOR = (0X808A);
326 static constexpr uint16_t GT911_HOPPING_SEG4_NORMALIZE = (0X808C);
327 static constexpr uint16_t GT911_HOPPING_SEG4_FACTOR = (0X808D);
328 static constexpr uint16_t GT911_HOPPING_SEG5_NORMALIZE = (0X808F);
329 static constexpr uint16_t GT911_HOPPING_SEG5_FACTOR = (0X8090);
330 static constexpr uint16_t GT911_HOPPING_SEG6_NORMALIZE = (0X8092);
331 static constexpr uint16_t GT911_KEY_1 = (0X8093);
332 static constexpr uint16_t GT911_KEY_2 = (0X8094);
333 static constexpr uint16_t GT911_KEY_3 = (0X8095);
334 static constexpr uint16_t GT911_KEY_4 = (0X8096);
335 static constexpr uint16_t GT911_KEY_AREA = (0X8097);
336 static constexpr uint16_t GT911_KEY_TOUCH_LEVEL = (0X8098);
337 static constexpr uint16_t GT911_KEY_LEAVE_LEVEL = (0X8099);
338 static constexpr uint16_t GT911_KEY_SENS_1_2 = (0X809A);
339 static constexpr uint16_t GT911_KEY_SENS_3_4 = (0X809B);
340 static constexpr uint16_t GT911_KEY_RESTRAIN = (0X809C);
341 static constexpr uint16_t GT911_KEY_RESTRAIN_TIME = (0X809D);
342 static constexpr uint16_t GT911_GESTURE_LARGE_TOUCH = (0X809E);
343 static constexpr uint16_t GT911_HOTKNOT_NOISE_MAP = (0X80A1);
344 static constexpr uint16_t GT911_LINK_THRESHOLD = (0X80A2);
345 static constexpr uint16_t GT911_PXY_THRESHOLD = (0X80A3);
346 static constexpr uint16_t GT911_GHOT_DUMP_SHIFT = (0X80A4);
347 static constexpr uint16_t GT911_GHOT_RX_GAIN = (0X80A5);
348 static constexpr uint16_t GT911_FREQ_GAIN0 = (0X80A6);
349 static constexpr uint16_t GT911_FREQ_GAIN1 = (0X80A7);
350 static constexpr uint16_t GT911_FREQ_GAIN2 = (0X80A8);
351 static constexpr uint16_t GT911_FREQ_GAIN3 = (0X80A9);
352 static constexpr uint16_t GT911_COMBINE_DIS = (0X80B3);
353 static constexpr uint16_t GT911_SPLIT_SET = (0X80B4);
354 static constexpr uint16_t GT911_SENSOR_CH0 = (0X80B7);
355 static constexpr uint16_t GT911_DRIVER_CH0 = (0X80D5);
356 static constexpr uint16_t GT911_CONFIG_CHKSUM = (0X80FF);
357 static constexpr uint16_t GT911_CONFIG_FRESH = (0X8100);
358 static constexpr uint16_t GT911_CONFIG_SIZE = (0xFF - 0x46);
359 // Coordinate information
360 static constexpr uint16_t GT911_PRODUCT_ID = (0x8140);
361 static constexpr uint16_t GT911_FIRMWARE_VERSION = (0x8144);
362 static constexpr uint16_t GT911_X_RESOLUTION = (0x8146);
363 static constexpr uint16_t GT911_Y_RESOLUTION = (0x8148);
364
365 static constexpr uint16_t GT911_VENDOR_ID = (0X8140);
366 static constexpr uint16_t GT911_INFORMATION = (0X8140);
367 static constexpr uint16_t GT911_POINT_INFO = (0X814E);
368 static constexpr uint16_t GT911_POINT_1 = (0X814F);
369 static constexpr uint16_t GT911_POINT_2 = (0X8157);
370 static constexpr uint16_t GT911_POINT_3 = (0X815F);
371 static constexpr uint16_t GT911_POINT_4 = (0X8167);
372 static constexpr uint16_t GT911_POINT_5 = (0X816F);
373
374 static constexpr uint16_t COMMAND_SIZE = (2);
375
376 static constexpr uint16_t GT911_DEV_ID = (911);
377 static constexpr uint8_t GT911_BASE_REF_RATE = (5);
378 static constexpr uint8_t GT911_REG_LENGTH = (186);
379};
380
381#endif
static constexpr uint16_t GT911_X_OUTPUT_MAX_LOW
static constexpr uint16_t GT911_Y_RESOLUTION
static constexpr uint16_t GT911_LARGE_TOUCH
static constexpr uint16_t GT911_DRV_GROUPB_NUM
static constexpr uint16_t GT911_LOW_POWER_CONTROL
bool setInterruptMode(InterruptMode mode)
Set the interrupt mode.
static constexpr uint16_t GT911_CONFIG_FRESH
static constexpr uint16_t GT911_GESTURE_REFRESH_RATE
static constexpr uint16_t GT911_HOPPING_SEG6_NORMALIZE
static constexpr uint16_t GT911_HOPPING_SEG3_FACTOR
static constexpr uint16_t GT911_MAIN_CLOCK_ADJUST
static constexpr uint16_t GT911_SENSOR_CH0
static constexpr uint16_t GT911_DRV_FRAME_CONTROL
static constexpr uint16_t GT911_FIRMWARE_VERSION
void wakeup() override
Wake up the touch driver.
static constexpr uint16_t GT911_FREQ_GAIN0
static constexpr uint16_t GT911_PANEL_RX_GAIN
static constexpr uint16_t GT911_KEY_SENS_1_2
static constexpr uint16_t GT911_NOISE_MIN_THRESHOLD
static constexpr uint16_t GT911_PANEL_BIT_FREQ_L
static constexpr uint16_t GT911_MODULE_SWITCH_2
static constexpr uint16_t GT911_STRETCH_RM
static constexpr uint16_t GT911_SENSOR_NUM
uint32_t getChipID() override
Get the chip ID.
static constexpr uint16_t GT911_DRIVER_CH0
static constexpr uint16_t GT911_SCREEN_TOUCH_LEVEL
static constexpr uint16_t GT911_GESTURE_LARGE_TOUCH
bool reloadConfig()
Reload the configuration data.
static constexpr uint16_t GT911_STRETCH_R0
TouchDrvGT911()=default
Constructor for the touch driver.
static constexpr uint16_t GT911_COMMAND
static constexpr uint16_t GT911_HOPPING_SEG3_NORMALIZE
void setMaxTouchPoint(uint8_t num)
Set the maximum touch points.
static constexpr uint16_t GT911_X_RESOLUTION
static constexpr uint16_t GT911_PRODUCT_ID
static constexpr uint16_t GT911_GESTURE_DIS
static constexpr uint16_t GT911_KEY_RESTRAIN
static constexpr uint16_t GT911_POINT_INFO
static constexpr uint16_t GT911_PANEL_BIT_FREQ_H
static constexpr uint16_t GT911_KEY_AREA
static constexpr uint16_t GT911_HOPPING_SENSOR_GROUP
static constexpr uint16_t GT911_KEY_1
static constexpr uint16_t GT911_Y_OUTPUT_MAX_LOW
static constexpr uint16_t GT911_CONFIG_START
static constexpr uint16_t GT911_HOPPING_THRESHOLD
uint8_t * loadConfig(size_t *output_size, bool print_out=false)
Load the configuration data.
static constexpr uint16_t GT911_NOISE_DETECT_TIMES
static constexpr uint16_t COMMAND_SIZE
static constexpr uint16_t GT911_FREQ_HOPPING_START
static constexpr uint16_t GT911_X_Y_SLOPE_ADJUST
static constexpr uint16_t GT911_PANEL_SENSOR_TIME_L
static constexpr uint16_t GT911_COMMAND_CHECK
static constexpr uint8_t IRQ_TRIGGER_MASK
static constexpr uint8_t GT911_BASE_REF_RATE
void sleep() override
Puts the touch driver to sleep.
InterruptMode getInterruptMode()
Get the interrupt mode.
static constexpr uint16_t GT911_MODULE_SWITCH3
static constexpr uint16_t GT911_ESD_CHECK
static constexpr uint16_t GT911_NEWGREENWAKEUPLEVEL
static constexpr uint16_t GT911_HOPPING_SEG1_NORMALIZE
static constexpr uint16_t GT911_COMBINE_DIS
static constexpr uint16_t GT911_FREQ_GAIN2
static constexpr uint16_t GT911_SCREEN_RELEASE_LEVEL
static constexpr uint16_t GT911_Y_THRESHOLD
static constexpr uint16_t GT911_KEY_SENS_3_4
static constexpr uint16_t GT911_POINT_2
static constexpr uint16_t GT911_DRV_GROUPA_NUM
static constexpr uint16_t GT911_LINK_THRESHOLD
static constexpr uint16_t GT911_FREQ_HOPPING_END
static constexpr uint16_t GT911_HOTKNOT_NOISE_MAP
static constexpr uint16_t GT911_CHARGING_LEVEL_UP
static constexpr uint16_t GT911_KEY_3
static constexpr uint16_t GT911_KEY_4
static constexpr uint16_t GT911_GESTURE_LONG_PRESS_TIME
static constexpr uint16_t GT911_VENDOR_ID
uint8_t getConfigVersion()
Get the configuration version.
uint8_t getRefreshRate()
Get the refresh rate.
static constexpr uint16_t GT911_REFRESH_RATE
static constexpr uint16_t GT911_PANEL_TX_GAIN
static constexpr uint16_t GT911_X_OUTPUT_MAX_HIGH
static constexpr uint16_t GT911_MODULE_SWITCH_1
static constexpr uint16_t GT911_KEY_RESTRAIN_TIME
static constexpr uint16_t GT911_KEY_TOUCH_LEVEL
static constexpr uint16_t GT911_MINI_FILTER
static constexpr uint16_t GT911_HOPPING_SEG5_NORMALIZE
static constexpr uint16_t GT911_KEY_2
static constexpr uint16_t GT911_Y_OUTPUT_MAX_HIGH
static constexpr uint16_t GT911_SPACE_LEFT_RIGHT
~TouchDrvGT911()=default
Destructor for the touch driver.
static constexpr uint16_t GT911_HOPPING_SEG4_FACTOR
static constexpr uint16_t GT911_PXY_THRESHOLD
uint16_t getFwVersion()
Get the firmware version.
static constexpr uint16_t GT911_FREQ_B_FACTOR
static constexpr uint16_t GT911_CONFIG_VERSION
static constexpr uint16_t GT911_GESTURE_CONTROL
static constexpr uint16_t GT911_HOPPING_SEG2_NORMALIZE
static constexpr uint16_t GT911_STRETCH_R1
static constexpr uint16_t GT911_STRETCH_R2
static constexpr uint16_t GT911_NOISE_REDUCTION
static constexpr uint16_t GT911_HOPPING_SEG2_FACTOR
static constexpr uint16_t GT911_SPLIT_SET
static constexpr uint16_t GT911_GHOT_DUMP_SHIFT
static constexpr uint16_t GT911_GESTURE_SWITCH2
static constexpr uint16_t GT911_POINT_1
static constexpr uint8_t GT911_REG_LENGTH
static constexpr uint16_t GT911_HOPPING_SEG1_FACTOR
static constexpr uint16_t GT911_GESTURE_SWITCH1
static constexpr uint16_t GT911_SHAKE_COUNT
static constexpr uint16_t GT911_FREQ_GAIN1
static constexpr uint16_t GT911_NOISE_THRESHOLD
static constexpr uint16_t GT911_PANEL_DUMP_SHIFT
static constexpr uint16_t GT911_POINT_3
static constexpr uint16_t GT911_X_SPEED_LIMIT
static constexpr uint16_t GT911_HOPPING_FLAG
static constexpr uint16_t GT911_CONFIG_SIZE
static constexpr uint16_t GT911_CONFIG_CHKSUM
static constexpr uint16_t GT911_HOPPING_SEG5_FACTOR
const char * getModelName() override
Get the model name.
static constexpr uint16_t GT911_X_THRESHOLD
static constexpr uint16_t GT911_HOPPING_SEG4_NORMALIZE
static constexpr uint16_t GT911_DEV_ID
static constexpr uint16_t GT911_POINT_4
static constexpr uint16_t GT911_PANEL_SENSOR_TIME_H
static constexpr uint16_t GT911_INFORMATION
static constexpr uint16_t GT911_GESTURE_TOUCH_LEVEL
static constexpr uint16_t GT911_POINT_5
static constexpr uint16_t GT911_GHOT_RX_GAIN
static constexpr uint16_t GT911_SPACE_TOP_BOTTOM
static constexpr uint16_t GT911_FREQ_A_FACTOR
static constexpr uint16_t GT911_TOUCH_NUMBER
static constexpr uint16_t GT911_FILTER
int getVendorID()
Get the vendor ID.
static constexpr uint16_t GT911_KEY_LEAVE_LEVEL
static constexpr uint16_t GT911_Y_SPEED_LIMIT
const TouchPoints & getTouchPoints() override
Get the touch points.
static constexpr uint16_t GT911_FREQ_GAIN3
void updateRefreshRate(uint8_t rate_ms)
Get the refresh rate.
Abstract base class for touch screen drivers.
virtual uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point=1) __attribute__((deprecated("use getTouchPoints instead of getPoint")))
Retrieve touch point coordinates (deprecated).
Container for touch point data and optional gesture information.
const uint16_t buffer_size