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 this->
write(GET_X_RES, 4);
39 if (this->
read(received, 4)) {
40 ESP_LOGE(TAG,
"Failed to read X resolution!");
45 this->
x_raw_max_ = ((received[2])) | ((received[3] & 0xf0) << 4);
49 this->
write(GET_Y_RES, 4);
50 if (this->
read(received, 4)) {
51 ESP_LOGE(TAG,
"Failed to read Y resolution!");
56 this->
y_raw_max_ = ((received[2])) | ((received[3] & 0xf0) << 4);
62 uint8_t touch_count = 0;
67 for (
int i = 0; i < 8; i++) {
68 if (raw[7] & (1 << i))
72 touch_count = std::min<uint8_t>(touch_count, 2);
74 ESP_LOGV(TAG,
"Touch count: %d", touch_count);
76 for (
int i = 0; i < touch_count; i++) {
77 uint8_t *d = raw + 1 + (i * 3);
78 x_raw = (d[0] & 0xF0) << 4 | d[1];
79 y_raw = (d[0] & 0x0F) << 8 | d[2];
85 uint8_t data[] = {0x54, 0x50, 0x00, 0x01};
86 data[1] |= (enable << 3);
92 this->
write(GET_POWER_STATE_CMD, 4);
94 this->
read(received, 4);
95 return (received[1] >> 3) & 1;
106 auto err = this->
write(SOFT_RESET_CMD, 4);
111 uint16_t timeout = 1000;
118 this->
read(received, 4);
121 return !memcmp(received, HELLO, 4);
125 ESP_LOGCONFIG(TAG,
"EKT2232 Touchscreen:");
126 LOG_I2C_DEVICE(
this);
128 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 IRAM_ATTR HOT delay(uint32_t ms)