22 if (data[0] == 0x83 && data[1] == 0x17 && data[5] == 0x80) {
27 if (data[6] != 0xAB || data[0] == 0xAB || data[5] == 0x80) {
31 uint8_t num_of_touches = data[5] & 0x7F;
32 if (num_of_touches == 0 || num_of_touches > 5) {
38 for (uint8_t i = 0; i != num_of_touches; i++) {
39 uint8_t
id = data[index] >> 4;
40 int16_t
x = (data[index + 1] << 4) | ((data[index + 3] >> 4) & 0x0F);
41 int16_t
y = (data[index + 2] << 4) | (data[index + 3] & 0x0F);
42 int16_t
z = data[index + 4];
44 ESP_LOGV(TAG,
"Read touch %d: %d/%d",
id,
x,
y);
53 ESP_LOGE(TAG,
"Read data from 0x%04X failed", addr);
67 ESP_LOGE(TAG,
"Write byte to 0xD1 failed");
72 if (this->
read16_(0xD204, buffer, 4)) {
75 ESP_LOGCONFIG(TAG,
"Chip ID %X, project ID %x", chip_id, project_id);
78 if (this->
read16_(0xD1F8, buffer, 4)) {
95 listener->update_button(
state);
99 ESP_LOGCONFIG(TAG,
"CST226 Touchscreen:");
100 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.
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)
ESPHOME_ALWAYS_INLINE void pulse_reset(GPIOPin *pin, ResetPulse pulse)
Set up an active-low reset pin and drive it through pulse.