10static const char *
const TAG =
"ektf2232";
12static const uint8_t SOFT_RESET_CMD[4] = {0x77, 0x77, 0x77, 0x77};
13static const uint8_t HELLO[4] = {0x55, 0x55, 0x55, 0x55};
14static const uint8_t GET_X_RES[4] = {0x53, 0x60, 0x00, 0x00};
15static const uint8_t GET_Y_RES[4] = {0x53, 0x63, 0x00, 0x00};
16static const uint8_t GET_POWER_STATE_CMD[4] = {0x53, 0x50, 0x00, 0x01};
28 ESP_LOGE(TAG,
"Failed to soft reset EKT2232!");
37 auto err = this->
write(GET_X_RES, 4);
39 err = this->
read(received, 4);
41 this->
x_raw_max_ = ((received[2])) | ((received[3] & 0xf0) << 4);
42 err = this->
write(GET_Y_RES, 4);
44 err = this->
read(received, 4);
46 this->
y_raw_max_ = ((received[2])) | ((received[3] & 0xf0) << 4);
52 ESP_LOGE(TAG,
"Failed to read calibration values!");
64 uint8_t touch_count = 0;
69 for (
int i = 0; i < 8; i++) {
70 if (
raw[7] & (1 << i))
74 touch_count = std::min<uint8_t>(touch_count, 2);
76 ESP_LOGV(TAG,
"Touch count: %d", touch_count);
78 for (
int i = 0; i < touch_count; i++) {
79 uint8_t *d =
raw + 1 + (i * 3);
80 x_raw = (d[0] & 0xF0) << 4 | d[1];
81 y_raw = (d[0] & 0x0F) << 8 | d[2];
87 uint8_t data[] = {0x54, 0x50, 0x00, 0x01};
88 data[1] |= (enable << 3);
94 this->
write(GET_POWER_STATE_CMD, 4);
96 this->
read(received, 4);
97 return (received[1] >> 3) & 1;
108 auto err = this->
write(SOFT_RESET_CMD, 4);
113 uint16_t timeout = 1000;
120 this->
read(received, 4);
123 return !memcmp(received, HELLO, 4);
127 ESP_LOGCONFIG(TAG,
"EKT2232 Touchscreen:");
128 LOG_I2C_DEVICE(
this);
130 LOG_PIN(
" RTS Pin: ", this->
rts_pin_);
virtual void mark_failed()
Mark this component as failed.
virtual void pin_mode(gpio::Flags flags)=0
virtual void digital_write(bool value)=0
virtual void detach_interrupt() const =0
void update_touches() override
void dump_config() override
void set_power_state(bool enable)
InternalGPIOPin * interrupt_pin_
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the 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.
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.
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delay(uint32_t ms)