6static const char *
const TAG =
"cst226.touchscreen";
9 ESP_LOGCONFIG(TAG,
"Setting up CST226 Touchscreen...");
25 if (!this->
read_bytes(CST226_REG_STATUS, data,
sizeof data)) {
31 if (data[0] == 0x83 && data[1] == 0x17 && data[5] == 0x80) {
36 if (data[6] != 0xAB || data[0] == 0xAB || data[5] == 0x80) {
40 uint8_t num_of_touches = data[5] & 0x7F;
41 if (num_of_touches == 0 || num_of_touches > 5) {
47 for (uint8_t i = 0; i != num_of_touches; i++) {
48 uint8_t
id = data[index] >> 4;
49 int16_t
x = (data[index + 1] << 4) | ((data[index + 3] >> 4) & 0x0F);
50 int16_t
y = (data[index + 2] << 4) | (data[index + 3] & 0x0F);
51 int16_t
z = data[index + 4];
53 ESP_LOGV(TAG,
"Read touch %d: %d/%d",
id,
x,
y);
62 ESP_LOGE(TAG,
"Read data from 0x%04X failed", addr);
76 ESP_LOGE(TAG,
"Write byte to 0xD1 failed");
81 if (this->
read16_(0xD204, buffer, 4)) {
82 uint16_t chip_id = buffer[2] + (buffer[3] << 8);
83 uint16_t project_id = buffer[0] + (buffer[1] << 8);
84 ESP_LOGCONFIG(TAG,
"Chip ID %X, project ID %x", chip_id, project_id);
87 if (this->
read16_(0xD1F8, buffer, 4)) {
88 this->
x_raw_max_ = buffer[0] + (buffer[1] << 8);
89 this->
y_raw_max_ = buffer[2] + (buffer[3] << 8);
98 ESP_LOGCONFIG(TAG,
"CST226 Touchscreen setup complete");
105 listener->update_button(
state);
109 ESP_LOGCONFIG(TAG,
"CST226 Touchscreen:");
110 LOG_I2C_DEVICE(
this);
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message="unspecified")
void status_clear_warning()
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
virtual void digital_write(bool value)=0
void dump_config() override
void update_button_state_(bool state)
std::vector< CST226ButtonListener * > button_listeners_
InternalGPIOPin * interrupt_pin_
void update_touches() override
bool read16_(uint16_t addr, uint8_t *data, size_t len)
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, bool stop=true)
write an array of bytes to a specific register in the I²C device
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
ErrorCode read_register16(uint16_t a_register, uint8_t *data, size_t len, bool stop=true)
reads an array of bytes from a specific register in the I²C device
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
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.
display::Display * display_
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)