9static constexpr uint32_t REREAD_TIMEOUT_ID = 1;
10static constexpr uint32_t REREAD_DELAY_MS = 20;
41 if ((checkcode & 0xFFFF0000) != 0xCACA0000) {
42 ESP_LOGE(TAG,
"Invalid firmware check code: 0x%08" PRIX32, checkcode);
64 if (this->
chip_id_ != CST9220_CHIP_ID && this->
chip_id_ != CST9217_CHIP_ID) {
65 ESP_LOGE(TAG,
"Unknown chip ID: 0x%04X", this->
chip_id_);
83 uint8_t data[CST9220_DATA_LENGTH];
95 if (data[6] != TOUCH_ACK) {
102 uint8_t num_touches = data[5] & 0x7F;
103 if (num_touches > CST9220_MAX_TOUCHES)
104 num_touches = CST9220_MAX_TOUCHES;
106 for (uint8_t i = 0; i < num_touches; i++) {
109 const uint8_t *p = data + i * 5 + (i == 0 ? 0 : 2);
110 uint8_t
id = p[0] >> 4;
111 uint8_t
event = p[0] & 0x0F;
112 if (event != TOUCH_EVENT_DOWN)
115 uint16_t
x = (p[1] << 4) | (p[3] >> 4);
116 uint16_t
y = (p[2] << 4) | (p[3] & 0x0F);
117 ESP_LOGV(TAG,
"Read touch %d: %d/%d",
id,
x,
y);
124 "CST9220 Touchscreen:\n"
126 " Project ID: 0x%04X\n"
127 " X Raw Min: %d, X Raw Max: %d\n"
128 " Y Raw Min: %d, Y Raw Max: %d",
131 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 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
std::map< uint8_t, TouchPoint > touches_
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_
TouchscreenInterrupt store_
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 T encode_value_le(const uint8_t *bytes)
Encode a value from its constituent bytes (from least to most significant) in an array with length si...
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.
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.