/* * CST826 capacitive touch controller @ I2C 0x15. * * Note this is CST826, not the CST816 the PRD names. Same family, but the chip * ID register reads 0x11 rather than 0xB4, so a CST816 driver's probe rejects * it and the board looks broken. Register map below is taken from the * Adafruit_CST8XX library bundled with Elecrow's example for this board. * * Protocol: read register 0x02 for the touch count, then a burst from 0x03 of * 6 bytes per touch: * * byte 0: [7:6] event, [3:0] X high nibble * byte 1: X low byte * byte 2: [7:4] touch id, [3:0] Y high nibble * byte 3: Y low byte * bytes 4,5: unused */ #pragma once #include #include #include "esp_err.h" #define CST826_I2C_ADDR 0x15 #define CST826_CHIP_ID 0x11 typedef struct { uint16_t x; uint16_t y; bool pressed; } cst826_touch_t; /* * Initialise and verify the chip ID. * * Requires i2c_bus_init() and the reset pulse that display.c's power-up * sequence performs on expander P0. */ esp_err_t cst826_init(void); bool cst826_is_ready(void); /* Latest touch state. Never fails hard — an I2C error reports "not pressed" * so a flaky touch controller cannot wedge the UI task. */ void cst826_read(cst826_touch_t *out);