30#include "../SensorBuildOpt.h"
31#if !SENSORLIB_EXCLUDE_TOUCH_GT911
67 static constexpr uint8_t POINT_BUFFER_SIZE = (MAX_FINGER_NUM * BYTES_PER_POINT);
68 uint8_t buffer[POINT_BUFFER_SIZE] = {0};
87 if (numPoints <= 0 || numPoints > MAX_FINGER_NUM) {
91 uint8_t expectedBytes = numPoints * BYTES_PER_POINT;
97 for (
int i = 0;
i < numPoints;
i++) {
98 const uint8_t
id = buffer[
i * BYTES_PER_POINT];
99 const uint16_t
x = buffer[1 +
i * BYTES_PER_POINT] | (buffer[2 +
i * BYTES_PER_POINT] << 8);
100 const uint16_t
y = buffer[3 +
i * BYTES_PER_POINT] | (buffer[4 +
i * BYTES_PER_POINT] << 8);
101 const uint16_t
pressure = buffer[5 +
i * BYTES_PER_POINT] | (buffer[6 +
i * BYTES_PER_POINT] << 8);
122 irqMode &= (~IRQ_TRIGGER_MASK);
174 char product_id[4] = {0};
176 for (
int i = 0;
i < 4; ++
i) {
179 return atoi(product_id);
184 uint8_t fw_ver[2] = {0};
186 for (
int i = 0;
i < 2; ++
i) {
189 return fw_ver[0] | (fw_ver[1] << 8);
221#ifdef ENABLE_GT911_CONFIG
222bool TouchDrvGT911::writeConfig(
const uint8_t *config_buffer,
size_t buffer_size)
224 uint8_t check_sum = 0;
226 check_sum += config_buffer[
i];
228 check_sum = (~check_sum) + 1;
245 if (!buffer)
return NULL;
251 printf(
"const unsigned char config[186] = {");
256 printf(
" 0x%02X", buffer[
i]);
276 uint8_t check_sum = 0;
278 check_sum += buffer[
i];
280 check_sum = (~check_sum) + 1;
290 if (num > 5) num = 5;
295uint8_t TouchDrvGT911::readGT911(uint16_t
cmd)
297 uint8_t value = 0x00;
304int TouchDrvGT911::writeGT911(uint16_t
cmd, uint8_t value)
310void TouchDrvGT911::writeCommand(uint8_t command)
313 uint8_t write_buffer[3] = {0x80, 0x40, command};
317void TouchDrvGT911::clearBuffer()
322bool TouchDrvGT911::probeAddress()
324 const uint8_t device_address[2] = {GT911_SLAVE_ADDRESS_L, GT911_SLAVE_ADDRESS_H};
325 for (
size_t i = 0;
i <
arraySize(device_address); ++
i) {
327 for (
int retry = 0; retry < 3; ++retry) {
335 SENSORLIB_LOG_E(
"GT911 not found, touch device 7-bit address should be 0x5D or 0x14");
339bool TouchDrvGT911::initImpl(uint8_t)
350 hal->delayMicroseconds(120);
366 hal->delayMicroseconds(120);
402 uint8_t x_resolution[2] = {0}, y_resolution[2] = {0};
403 for (
int i = 0;
i < 2; ++
i) {
406 for (
int i = 0;
i < 2; ++
i) {
446bool TouchDrvGT911::autoProbe()
456 if (!probeAddress()) {
constexpr size_t arraySize(const T(&arr)[N])
Returns the number of elements in a C‑style array at compile time.
#define SENSORLIB_LOG_I(...)
#define SENSORLIB_LOG_E(...)
#define SENSORLIB_LOG_D(...)
SensorPressure pressure(bhy)
std::unique_ptr< SensorHal > hal
int writeBuff(uint8_t *buf, size_t len)
int writeThenRead(const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len)
void setAddress(uint8_t address)
static constexpr uint16_t GT911_Y_RESOLUTION
bool setInterruptMode(InterruptMode mode)
Set the interrupt mode.
static constexpr uint16_t GT911_CONFIG_FRESH
static constexpr uint16_t GT911_FIRMWARE_VERSION
void wakeup() override
Wake up the touch driver.
uint32_t getChipID() override
Get the chip ID.
bool reloadConfig()
Reload the configuration data.
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_POINT_INFO
uint8_t * loadConfig(size_t *output_size, bool print_out=false)
Load the configuration data.
static constexpr uint16_t COMMAND_SIZE
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_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_MODULE_SWITCH_1
uint16_t getFwVersion()
Get the firmware version.
static constexpr uint16_t GT911_CONFIG_VERSION
static constexpr uint16_t GT911_POINT_1
static constexpr uint8_t GT911_REG_LENGTH
static constexpr uint16_t GT911_CONFIG_CHKSUM
const char * getModelName() override
Get the model name.
static constexpr uint16_t GT911_DEV_ID
static constexpr uint16_t GT911_TOUCH_NUMBER
int getVendorID()
Get the vendor ID.
const TouchPoints & getTouchPoints() override
Get the touch points.
void updateRefreshRate(uint8_t rate_ms)
Get the refresh rate.
uint32_t _chipID
Chip identification value.
TouchConfig _touchConfig
Configuration for coordinate transformations.
virtual void reset()
Reset the touch controller.
void * _userData
User data for home button callback.
virtual void updateXY(TouchPoints &points) const
Apply coordinate transformations (swap, scale, mirror) to all touch points.
TouchPinsCfg _pinsCfg
Configuration for reset and interrupt pins.
TouchPoints _touchPoints
Touch points data.
uint8_t _maxTouchPoints
Maximum supported touch points.
HomeButtonCallback _HButtonCallback
Home button callback function.
Container for touch point data and optional gesture information.
bool addPoint(uint16_t x, uint16_t y, uint16_t pressure=0, uint8_t id=0, uint8_t event=0)
Adds a touch point to the container.
void clear()
Clears all stored touch points and gesture.
constexpr uint8_t _lowByte(uint16_t w)
constexpr uint8_t _highByte(uint16_t w)
const uint16_t buffer_size