44 if ((checkcode & 0xFFFF0000) != 0xCACA0000) {
45 ESP_LOGE(TAG,
"Invalid firmware check code: 0x%08" PRIX32, checkcode);
67 if (this->
chip_id_ != CST9220_CHIP_ID && this->
chip_id_ != CST9217_CHIP_ID) {
68 ESP_LOGE(TAG,
"Unknown chip ID: 0x%04X", this->
chip_id_);
86 uint8_t data[CST9220_DATA_LENGTH];
98 uint8_t
ack = TOUCH_ACK;
104 if (data[0] == TOUCH_ACK || data[0] == 0x00 || data[6] != TOUCH_ACK)
107 uint8_t num_touches = data[5] & 0x7F;
108 if (num_touches > CST9220_MAX_TOUCHES)
109 num_touches = CST9220_MAX_TOUCHES;
111 for (uint8_t i = 0; i < num_touches; i++) {
114 const uint8_t *p = data + i * 5 + (i == 0 ? 0 : 2);
115 uint8_t
id = p[0] >> 4;
116 uint8_t
event = p[0] & 0x0F;
117 if (event != TOUCH_EVENT_DOWN)
120 uint16_t
x = (p[1] << 4) | (p[3] >> 4);
121 uint16_t
y = (p[2] << 4) | (p[3] & 0x0F);
122 ESP_LOGV(TAG,
"Read touch %d: %d/%d",
id,
x,
y);
129 "CST9220 Touchscreen:\n"
131 " Project ID: 0x%04X\n"
132 " X Raw Min: %d, X Raw Max: %d\n"
133 " Y Raw Min: %d, Y Raw Max: %d",
136 LOG_I2C_DEVICE(
this);
void mark_failed()
Mark this component as failed.
void status_set_warning()
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void status_clear_warning()
virtual void digital_write(bool value)=0
void update_touches() override
InternalGPIOPin * interrupt_pin_
void dump_config() override
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
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.
display::Display * display_
void add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw=0)
@ ERROR_OK
No error found during execution of method.
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
void HOT delay(uint32_t ms)