7 namespace lilygo_t5_47 {
9 static const char *
const TAG =
"lilygo_t5_47.touchscreen";
11 static const uint8_t POWER_REGISTER = 0xD6;
12 static const uint8_t TOUCH_REGISTER = 0xD0;
14 static const uint8_t WAKEUP_CMD[1] = {0x06};
15 static const uint8_t READ_FLAGS[1] = {0x00};
16 static const uint8_t CLEAR_FLAGS[2] = {0x00, 0xAB};
17 static const uint8_t READ_TOUCH[1] = {0x07};
19 #define ERROR_CHECK(err) \ 20 if ((err) != i2c::ERROR_OK) { \ 21 ESP_LOGE(TAG, "Failed to communicate!"); \ 22 this->status_set_warning(); \ 27 ESP_LOGCONFIG(TAG,
"Setting up Lilygo T5 4.7 Touchscreen...");
34 ESP_LOGE(TAG,
"Failed to communicate!");
53 uint8_t buffer[40] = {0};
59 err = this->
read(buffer, 7);
62 if (buffer[0] == 0xAB) {
67 point = buffer[5] & 0xF;
72 err = this->
read(&buffer[5], 2);
75 }
else if (point > 1) {
78 err = this->
read(&buffer[5], 5 * (point - 1) + 3);
87 uint16_t
id, x_raw, y_raw;
88 for (uint8_t i = 0; i < point; i++) {
89 id = (buffer[i * 5] >> 4) & 0x0F;
90 y_raw = (uint16_t) ((buffer[i * 5 + 1] << 4) | ((buffer[i * 5 + 3] >> 4) & 0x0F));
91 x_raw = (uint16_t) ((buffer[i * 5 + 2] << 4) | (buffer[i * 5 + 3] & 0x0F));
99 ESP_LOGCONFIG(TAG,
"Lilygo T5 47 Touchscreen:");
100 LOG_I2C_DEVICE(
this);
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
int get_native_height()
Get the native (original) height of the display in pixels.
virtual void pin_mode(gpio::Flags flags)=0
T id(T value)
Helper function to make id(var) known from lambdas work in custom components.
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
int get_native_width()
Get the native (original) width of the display in pixels.
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.
void status_clear_warning()
void dump_config() override
InternalGPIOPin * interrupt_pin_
void update_touches() override
display::Display * display_
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
Implementation of SPI Controller mode.
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a specific register in the I²C device
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.