27 if (data[0] == 0x83 && data[1] == 0x17 && data[5] == 0x80) {
32 if (data[6] != 0xAB || data[0] == 0xAB || data[5] == 0x80) {
36 uint8_t num_of_touches = data[5] & 0x7F;
37 if (num_of_touches == 0 || num_of_touches > 5) {
43 for (uint8_t i = 0; i != num_of_touches; i++) {
44 uint8_t
id = data[index] >> 4;
45 int16_t
x = (data[index + 1] << 4) | ((data[index + 3] >> 4) & 0x0F);
46 int16_t
y = (data[index + 2] << 4) | (data[index + 3] & 0x0F);
47 int16_t
z = data[index + 4];
49 ESP_LOGV(TAG,
"Read touch %d: %d/%d",
id,
x,
y);
58 ESP_LOGE(TAG,
"Read data from 0x%04X failed", addr);
72 ESP_LOGE(TAG,
"Write byte to 0xD1 failed");
77 if (this->
read16_(0xD204, buffer, 4)) {
80 ESP_LOGCONFIG(TAG,
"Chip ID %X, project ID %x", chip_id, project_id);
83 if (this->
read16_(0xD1F8, buffer, 4)) {
100 listener->update_button(
state);
104 ESP_LOGCONFIG(TAG,
"CST226 Touchscreen:");
105 LOG_I2C_DEVICE(
this);
void mark_failed()
Mark this component as failed.
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
virtual void digital_write(bool value)=0
void dump_config() override
void update_button_state_(bool state)
std::vector< CST226ButtonListener * > button_listeners_
InternalGPIOPin * interrupt_pin_
void update_touches() override
bool read16_(uint16_t addr, uint8_t *data, size_t len)
int get_native_width()
Get the native (original) width of the display in pixels.
int get_native_height()
Get the native (original) height of the display in pixels.
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
bool write_byte(uint8_t a_register, uint8_t data) const
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
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
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.
display::Display * display_
void add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw=0)
ESPHOME_LOG_TAG(TAG, "CST226.binary_sensor")
@ ERROR_OK
No error found during execution of method.
void HOT delay(uint32_t ms)