15static constexpr uint16_t REG_TOUCH_DATA = 0xD000;
16static constexpr uint16_t REG_FINGER_COUNT = 0xD005;
17static constexpr uint16_t REG_COMMAND_MODE = 0xD101;
18static constexpr uint16_t REG_NORMAL_MODE = 0xD109;
19static constexpr uint16_t REG_RESOLUTION = 0xD1F8;
20static constexpr uint16_t REG_FW_CHECK_CODE = 0xD1FC;
21static constexpr uint16_t REG_CHIP_INFO = 0xD204;
22static constexpr uint16_t REG_FW_VERSION = 0xD208;
24static constexpr uint8_t FINGER_COUNT_IDX = REG_FINGER_COUNT - REG_TOUCH_DATA;
25static constexpr uint8_t SYNC_IDX = FINGER_COUNT_IDX + 1;
26static constexpr uint8_t SYNC_BYTE = 0xAB;
27static constexpr uint16_t FW_CHECK_CODE = 0xCACA;
30constexpr size_t report_size(uint8_t points) {
return points * 5 + 2; }
44 const uint8_t *r = report + index * 5 + (index == 0 ? 0 : 2);
68 bool ESPHOME_ALWAYS_INLINE
read_words_(uint16_t
reg, uint16_t &low, uint16_t &high) {
79 LOG_STR(
"Failed to enter command mode"));
83 uint16_t boot_time, check_code;
86 if (check_code == FW_CHECK_CODE)
bool ESPHOME_ALWAYS_INLINE setup_check(bool ok)
Marks the component failed with message (default "Communication failed") unless ok; returns ok.
void fail_check_code_(uint16_t check_code)
Logs a wrong firmware check code and marks the component failed.
bool ESPHOME_ALWAYS_INLINE read_words_(uint16_t reg, uint16_t &low, uint16_t &high)
Reads two little-endian words starting at reg.
bool check_firmware_()
Checks the firmware check code, marking the component failed if it is unreadable or wrong.
void set_interrupt_pin(InternalGPIOPin *pin)
bool enter_command_mode_()
Enters command mode, marking the component failed if the write fails.
void setup_interrupt_pin_(gpio::InterruptType type)
Sets up the interrupt pin, if configured, to fire on type.
void set_reset_pin(GPIOPin *pin)
InternalGPIOPin * interrupt_pin_
This Class provides the methods to read/write bytes from/to an i2c device.
ErrorCode write_register16(uint16_t a_register, const uint8_t *data, size_t len) const
write an array of bytes to a specific register in the I²C device
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
ErrorCode read_register16(uint16_t a_register, uint8_t *data, size_t len)
reads an array of bytes from a specific register in the I²C device
void attach_interrupt_(InternalGPIOPin *irq_pin, esphome::gpio::InterruptType type)
Call this function to send touch points to the on_touch listener and the binary_sensors.
constexpr size_t report_size(uint8_t points)
Bytes of a touch report holding points records; two status bytes follow the first record.
TouchRecord decode_touch(const uint8_t *report, uint8_t index)
Decodes record index of a touch report.
@ ERROR_OK
No error found during execution of method.
constexpr T convert_little_endian(T val)
Convert a value between host byte order and little endian (least significant byte first) order.
constexpr uint8_t high_nibble(uint8_t byte)
The high 4 bits of a byte, e.g. high_nibble(0xA5) == 0xA.
constexpr uint16_t encode_uint12(uint8_t high_bits, uint8_t low_bits)
Encode a 12-bit value from its high 8 and low 4 bits, e.g.
constexpr uint8_t low_nibble(uint8_t byte)
The low 4 bits of a byte, e.g. low_nibble(0xA5) == 0x5.