7 esph_log_config(TAG,
"Setting up CST226 Touchscreen...");
23 if (!this->
read_bytes(CST226_REG_STATUS, data,
sizeof data)) {
29 if (data[6] != 0xAB || data[0] == 0xAB || data[5] == 0x80) {
33 uint8_t num_of_touches = data[5] & 0x7F;
34 if (num_of_touches == 0 || num_of_touches > 5) {
40 for (uint8_t i = 0; i != num_of_touches; i++) {
41 uint8_t
id = data[index] >> 4;
42 int16_t
x = (data[index + 1] << 4) | ((data[index + 3] >> 4) & 0x0F);
43 int16_t
y = (data[index + 2] << 4) | (data[index + 3] & 0x0F);
44 int16_t z = data[index + 4];
46 esph_log_v(TAG,
"Read touch %d: %d/%d",
id, x, y);
61 esph_log_e(TAG,
"Write byte to 0xD1 failed");
66 if (this->
read16_(0xD204, buffer, 4)) {
67 uint16_t chip_id = buffer[2] + (buffer[3] << 8);
68 uint16_t project_id = buffer[0] + (buffer[1] << 8);
69 esph_log_config(TAG,
"Chip ID %X, project ID %x", chip_id, project_id);
72 if (this->
read16_(0xD1F8, buffer, 4)) {
73 this->
x_raw_max_ = buffer[0] + (buffer[1] << 8);
74 this->
y_raw_max_ = buffer[2] + (buffer[3] << 8);
81 esph_log_config(TAG,
"CST226 Touchscreen setup complete");
85 ESP_LOGCONFIG(TAG,
"CST226 Touchscreen:");
virtual void digital_write(bool value)=0
void status_set_warning(const char *message="unspecified")
bool read16_(uint16_t addr, uint8_t *data, size_t len)
void update_touches() override
int get_native_height()
Get the native (original) height of the display in pixels.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
InternalGPIOPin * interrupt_pin_
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()
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
display::Display * display_
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
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)
void dump_config() override
Implementation of SPI Controller mode.
void IRAM_ATTR HOT delay(uint32_t ms)