24 LOG_STR(
"Failed to read chip ID")))
27 if (this->
chip_id_ != CST3240_CHIP_ID) {
28 ESP_LOGW(TAG,
"Unexpected chip ID 0x%04X", this->
chip_id_);
33 uint16_t x_max, y_max;
34 if (this->
read_words_(cstxxx::REG_RESOLUTION, x_max, y_max)) {
55 uint8_t data[CST3240_REPORT_SIZE];
61 const uint8_t
sync = data[cstxxx::SYNC_IDX];
62 if (
sync != cstxxx::SYNC_BYTE) {
65 ESP_LOGV(TAG,
"Skipping report, sync byte 0x%02X",
sync);
72 if (
count <= CST3240_MAX_TOUCHES) {
73 for (uint8_t i = 0; i <
count; i++) {
76 if ((touch.event & TOUCH_EVENT_PRESSED) == 0)
86 ESP_LOGW(TAG,
"Failed to acknowledge the report");
91 const uint8_t zeros[CST3240_REPORT_SIZE]{};
93 ESP_LOGW(TAG,
"Failed to clear the report");
99 "CST3240 Touchscreen:\n"
100 " Chip ID: 0x%04X, Project ID: 0x%04X\n"
101 " FW version: %d.%d.%d\n"
102 " X/Y resolution: %d/%d",
105 LOG_I2C_DEVICE(
this);
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
bool ESPHOME_ALWAYS_INLINE setup_check(bool ok)
Marks the component failed with message (default "Communication failed") unless ok; returns ok.
bool status_comm_check(bool ok)
Sets the warning ("Communication failed") when not ok but never clears it; returns ok.
void set_timeout(const char *name, uint32_t timeout, SchedulerCallback &&f)
Set a timeout function with a const char* name.
void dump_config() override
void clear_report_()
Zeroes the touch report block, which polling relies on to tell new reports from old.
void update_touches() override
bool ESPHOME_ALWAYS_INLINE read_words_(uint16_t reg, uint16_t &low, uint16_t &high)
Reads two little-endian words starting at reg.
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.
InternalGPIOPin * interrupt_pin_
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_reg16(uint16_t a_register, uint8_t data) const
Write one byte to a register with a 16-bit register address.
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
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, "cst3240.touchscreen")
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 uint8_t low_nibble(uint8_t byte)
The low 4 bits of a byte, e.g. low_nibble(0xA5) == 0x5.
ESPHOME_ALWAYS_INLINE void pulse_reset(GPIOPin *pin, ResetPulse pulse)
Set up an active-low reset pin and drive it through pulse.