ESPHome  2024.11.3
cst226_touchscreen.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include "esphome/core/hal.h"
7 #include "esphome/core/log.h"
8 
9 namespace esphome {
10 namespace cst226 {
11 
12 static const char *const TAG = "cst226.touchscreen";
13 
14 static const uint8_t CST226_REG_STATUS = 0x00;
15 
17  public:
18  void setup() override;
19  void update_touches() override;
20  void dump_config() override;
21 
22  void set_interrupt_pin(InternalGPIOPin *pin) { this->interrupt_pin_ = pin; }
23  void set_reset_pin(GPIOPin *pin) { this->reset_pin_ = pin; }
24  bool can_proceed() override { return this->setup_complete_ || this->is_failed(); }
25 
26  protected:
27  bool read16_(uint16_t addr, uint8_t *data, size_t len) {
28  if (this->read_register16(addr, data, len) != i2c::ERROR_OK) {
29  esph_log_e(TAG, "Read data from 0x%04X failed", addr);
30  this->mark_failed();
31  return false;
32  }
33  return true;
34  }
35  void continue_setup_();
36 
39  uint8_t chip_id_{};
41 };
42 
43 } // namespace cst226
44 } // namespace esphome
bool read16_(uint16_t addr, uint8_t *data, size_t len)
bool is_failed() const
Definition: component.cpp:143
No error found during execution of method.
Definition: i2c_bus.h:13
std::string size_t len
Definition: helpers.h:293
virtual void mark_failed()
Mark this component as failed.
Definition: component.cpp:118
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
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
Definition: i2c.cpp:17
void set_interrupt_pin(InternalGPIOPin *pin)
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133