# ESP LCD Touch CST92xx
ESP-IDF `esp_lcd_touch` driver for Hynitron CST9217 and CST9220 capacitive touch controllers.
## Features
- standard `esp_lcd_touch` API;
- CST9217 and CST9220 identity validation;
- up to two simultaneous touch points with track IDs;
- interrupt or polling operation;
- automatic acknowledgement of every successfully read touch report;
- no fixed delay in the successful report path.
The controllers use the fixed 7-bit I2C address `0x5A`. Set
`CONFIG_ESP_LCD_TOUCH_MAX_POINTS` to at least `2`.
## Add the component
For a local checkout, place this directory under your project's `components/` directory. The registry component can
be added with:
```sh
idf.py add-dependency "78/esp_lcd_touch_cst92xx^0.1.0"
```
## Usage
```c
#include "esp_lcd_touch_cst92xx.h"
esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_CST92XX_CONFIG();
esp_lcd_panel_io_handle_t io = NULL;
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(i2c_bus, &io_config, &io));
const esp_lcd_touch_config_t touch_config = {
.x_max = 360,
.y_max = 360,
.rst_gpio_num = GPIO_NUM_NC,
.int_gpio_num = GPIO_NUM_21,
.levels = {
.reset = 0,
.interrupt = 0,
},
};
esp_lcd_touch_handle_t touch = NULL;
ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_cst92xx(io, &touch_config, &touch));
```
Read data using the common API:
```c
ESP_ERROR_CHECK(esp_lcd_touch_read_data(touch));
bool touched = esp_lcd_touch_get_coordinates(touch, x, y, strength, &point_count, 2);
```
## Protocol note
After a report is read from register `0xD000`, the controller expects `0xAB` to be written back to that register.
The driver performs this acknowledgement internally for valid, empty, and malformed reports so the controller is
ready to detect the next frame without waiting for its internal timeout.
Protocol behavior was cross-checked against the MIT-licensed SensorLib `TouchDrvCST92xx` implementation. This
component does not vendor SensorLib source code.
## License
MIT. See [LICENSE](LICENSE).
idf.py add-dependency "78/esp_lcd_touch_cst92xx^0.1.0"