bitbank2 / bb_captouch

An ESP32/Arduino library to talk to CST820, FT6x36 and GT911 capacitive touch sensors (auto-detects)
Apache License 2.0
20 stars 7 forks source link

BitBank Capacitive Touch Sensor Library

Copyright (c) 2023-2024 BitBank Software, Inc.
Written by Larry Bank
email: bitbank@pobox.com

There are a growing list of development boards which include LCDs with capacitive touch plates on them. These are overwhelmingly controlled by different versions of the ESP32 MCU. The boards normally only utilize GOODiX and FocalTech capacitive touch controllers and this library supports the MXT144, CST820, GT911 and FT6x36 in a generic way. Each has different capabilities and usually come pre-programmed for the specific pixel width and height of the target application. A feature supported by this library that may not be present in the device you're using is the touch area and pressure values. Some of their controllers also have built-in gesture detection. The common features of the controllers is that they will generate an interrupt signal when a touch event is occurring. This library allows you to request the latest touch information and it returns the number of active touch points (0-5) along with the coordinates (and pressure/area of each if available). The sensor type and address is auto-detected when calling the init() method. The only info that must be correctly supplied to the library are the GPIO pins used for the SDA/SCL/INT/RESET signals. Once initialized, repeatedly call getSamples() to test for and read any touch samples available.

There are only 4 methods exposed by the class:
int init() - detects if a supported CT controller is available and initializes it
int setOrientation(int iOrientation, int iWidth, int iHeight) - allows you to rotate the coordinates to match the LCD orientation
int getSamples() - returns touch points if available
int sensorType() - returns an enumerated value of the sensor detected<> Here is the TOUCHINFO structure filled by the getSamples() method:

typedef struct _fttouchinfo
{
  int count;
  uint16_t x[5], y[5];
  uint8_t pressure[5], area[5];
} TOUCHINFO;

If you find this code useful, please consider becoming a sponsor or sending a donation.

paypal