7 static const char *
const TAG =
"tt21100";
9 static const uint8_t MAX_BUTTONS = 4;
10 static const uint8_t MAX_TOUCH_POINTS = 5;
11 static const uint8_t MAX_DATA_LEN = (7 + MAX_TOUCH_POINTS * 10);
13 struct TT21100ButtonReport {
21 struct TT21100TouchRecord {
34 struct TT21100TouchReport {
52 ESP_LOGCONFIG(TAG,
"Setting up TT21100 Touchscreen...");
56 this->interrupt_pin_->setup();
57 this->store_.pin = this->interrupt_pin_->to_isr();
62 if (this->reset_pin_ !=
nullptr) {
63 this->reset_pin_->setup();
68 this->display_width_ = this->display_->get_width();
69 this->display_height_ = this->display_->get_height();
70 this->rotation_ =
static_cast<TouchRotation>(this->display_->get_rotation());
73 this->store_.touch =
true;
77 if (!this->store_.touch)
79 this->store_.touch =
false;
83 this->read((uint8_t *) &data_len,
sizeof(data_len));
86 uint8_t data[MAX_DATA_LEN];
87 if (data_len > 0 && data_len <
sizeof(data)) {
88 this->read(data, data_len);
92 auto *report = (TT21100ButtonReport *) data;
94 ESP_LOGV(TAG,
"Button report: Len=%d, ID=%d, Time=%5u, Value=[%u], Signal=[%04X][%04X][%04X][%04X]",
95 report->length, report->report_id, report->timestamp, report->btn_value, report->btn_signal[0],
96 report->btn_signal[1], report->btn_signal[2], report->btn_signal[3]);
98 for (uint8_t i = 0; i < 4; i++) {
99 for (
auto *listener : this->button_listeners_)
100 listener->update_button(i, report->btn_signal[i]);
103 }
else if (data_len >= 7) {
105 auto *report = (TT21100TouchReport *) data;
108 "Touch report: Len=%d, ID=%d, Time=%5u, LargeObject=%u, RecordNum=%u, RecordCounter=%u, NoiseEffect=%u",
109 report->length, report->report_id, report->timestamp, report->large_object, report->record_num,
110 report->report_counter, report->noise_effect);
112 uint8_t touch_count = (data_len - (
sizeof(*report) -
sizeof(report->touch_record))) /
sizeof(TT21100TouchRecord);
114 if (touch_count == 0) {
115 for (
auto *listener : this->touch_listeners_)
120 for (
int i = 0; i < touch_count; i++) {
121 auto *touch = &report->touch_record[i];
124 "Touch %d: Type=%u, Tip=%u, EventId=%u, TouchId=%u, X=%u, Y=%u, Pressure=%u, MajorAxisLen=%u, " 126 i, touch->touch_type, touch->tip, touch->event_id, touch->touch_id, touch->x, touch->y,
127 touch->pressure, touch->major_axis_length, touch->orientation);
130 switch (this->rotation_) {
133 tp.
x = this->display_width_ - touch->x;
142 tp.
y = this->display_height_ - touch->y;
145 tp.
x = this->display_height_ - touch->y;
146 tp.
y = this->display_width_ - touch->x;
150 tp.
state = touch->pressure;
152 this->defer([
this, tp]() { this->send_touch_(tp); });
159 if (this->reset_pin_ !=
nullptr) {
160 this->reset_pin_->digital_write(
false);
162 this->reset_pin_->digital_write(
true);
168 ESP_LOGCONFIG(TAG,
"TT21100 Touchscreen:");
169 LOG_I2C_DEVICE(
this);
170 LOG_PIN(
" Interrupt Pin: ", this->interrupt_pin_);
171 LOG_PIN(
" Reset Pin: ", this->reset_pin_);
struct esphome::tt21100::TT21100TouchscreenStore __attribute__
uint16_t btn_signal[MAX_BUTTONS]
uint16_t major_axis_length
float get_setup_priority() const override
TT21100TouchRecord touch_record[MAX_TOUCH_POINTS]
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Implementation of SPI Controller mode.
static void gpio_intr(TT21100TouchscreenStore *store)
void dump_config() override
void IRAM_ATTR HOT delay(uint32_t ms)