10 static const char *
const TAG =
"ektf2232";
12 static const uint8_t SOFT_RESET_CMD[4] = {0x77, 0x77, 0x77, 0x77};
13 static const uint8_t HELLO[4] = {0x55, 0x55, 0x55, 0x55};
14 static const uint8_t GET_X_RES[4] = {0x53, 0x60, 0x00, 0x00};
15 static const uint8_t GET_Y_RES[4] = {0x53, 0x63, 0x00, 0x00};
16 static const uint8_t GET_POWER_STATE_CMD[4] = {0x53, 0x50, 0x00, 0x01};
19 ESP_LOGCONFIG(TAG,
"Setting up EKT2232 Touchscreen...");
29 ESP_LOGE(TAG,
"Failed to soft reset EKT2232!");
38 auto err = this->
write(GET_X_RES, 4);
40 err = this->
read(received, 4);
42 this->
x_raw_max_ = ((received[2])) | ((received[3] & 0xf0) << 4);
43 err = this->
write(GET_Y_RES, 4);
45 err = this->
read(received, 4);
47 this->
y_raw_max_ = ((received[2])) | ((received[3] & 0xf0) << 4);
53 ESP_LOGE(TAG,
"Failed to read calibration values!");
65 uint8_t touch_count = 0;
70 for (
int i = 0; i < 8; i++) {
71 if (raw[7] & (1 << i))
75 touch_count = std::min<uint8_t>(touch_count, 2);
77 ESP_LOGV(TAG,
"Touch count: %d", touch_count);
79 for (
int i = 0; i < touch_count; i++) {
80 uint8_t *d = raw + 1 + (i * 3);
81 x_raw = (d[0] & 0xF0) << 4 | d[1];
82 y_raw = (d[0] & 0x0F) << 8 | d[2];
88 uint8_t data[] = {0x54, 0x50, 0x00, 0x01};
89 data[1] |= (enable << 3);
95 this->
write(GET_POWER_STATE_CMD, 4);
97 this->
read(received, 4);
98 return (received[1] >> 3) & 1;
109 auto err = this->
write(SOFT_RESET_CMD, 4);
114 uint16_t timeout = 1000;
121 this->
read(received, 4);
124 return !memcmp(received, HELLO, 4);
128 ESP_LOGCONFIG(TAG,
"EKT2232 Touchscreen:");
129 LOG_I2C_DEVICE(
this);
131 LOG_PIN(
" RTS Pin: ", this->
rts_pin_);
virtual void digital_write(bool value)=0
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
virtual void pin_mode(gpio::Flags flags)=0
void dump_config() override
void update_touches() override
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
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.
No error found during execution of method.
TouchscreenInterrupt store_
void set_power_state(bool enable)
virtual void mark_failed()
Mark this component as failed.
void add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw=0)
virtual void detach_interrupt() const =0
InternalGPIOPin * interrupt_pin_
Implementation of SPI Controller mode.
void swap(optional< T > &x, optional< T > &y) noexcept
void IRAM_ATTR HOT delay(uint32_t ms)