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 {
50 ESP_LOGCONFIG(TAG,
"Setting up TT21100 Touchscreen...");
53 if (this->interrupt_pin_ !=
nullptr) {
55 this->interrupt_pin_->setup();
60 if (this->reset_pin_ !=
nullptr) {
61 this->reset_pin_->setup();
66 if (this->display_ !=
nullptr) {
67 if (this->x_raw_max_ == this->x_raw_min_) {
68 this->x_raw_max_ = this->display_->get_native_width();
70 if (this->y_raw_max_ == this->y_raw_min_) {
71 this->x_raw_max_ = this->display_->get_native_height();
76 this->store_.touched =
true;
82 this->read((uint8_t *) &data_len,
sizeof(data_len));
85 uint8_t data[MAX_DATA_LEN];
86 if (data_len > 0 && data_len <
sizeof(data)) {
87 this->read(data, data_len);
91 auto *report = (TT21100ButtonReport *) data;
93 ESP_LOGV(TAG,
"Button report: Len=%d, ID=%d, Time=%5u, Value=[%u], Signal=[%04X][%04X][%04X][%04X]",
94 report->length, report->report_id, report->timestamp, report->btn_value, report->btn_signal[0],
95 report->btn_signal[1], report->btn_signal[2], report->btn_signal[3]);
97 for (uint8_t i = 0; i < 4; i++) {
98 for (
auto *listener : this->button_listeners_)
99 listener->update_button(i, report->btn_signal[i]);
102 }
else if (data_len >= 7) {
104 auto *report = (TT21100TouchReport *) data;
107 "Touch report: Len=%d, ID=%d, Time=%5u, LargeObject=%u, RecordNum=%u, RecordCounter=%u, NoiseEffect=%u",
108 report->length, report->report_id, report->timestamp, report->large_object, report->record_num,
109 report->report_counter, report->noise_effect);
111 uint8_t touch_count = (data_len - (
sizeof(*report) -
sizeof(report->touch_record))) /
sizeof(TT21100TouchRecord);
113 for (
int i = 0; i < touch_count; i++) {
114 auto *touch = &report->touch_record[i];
117 "Touch %d: Type=%u, Tip=%u, EventId=%u, TouchId=%u, X=%u, Y=%u, Pressure=%u, MajorAxisLen=%u, " 119 i, touch->touch_type, touch->tip, touch->event_id, touch->touch_id, touch->x, touch->y,
120 touch->pressure, touch->major_axis_length, touch->orientation);
122 this->add_raw_touch_position_(touch->tip, touch->x, touch->y, touch->pressure);
129 if (this->reset_pin_ !=
nullptr) {
130 this->reset_pin_->digital_write(
false);
132 this->reset_pin_->digital_write(
true);
138 ESP_LOGCONFIG(TAG,
"TT21100 Touchscreen:");
139 LOG_I2C_DEVICE(
this);
140 LOG_PIN(
" Interrupt Pin: ", this->interrupt_pin_);
141 LOG_PIN(
" Reset Pin: ", this->reset_pin_);
class esphome::tt21100::TT21100ButtonListener __attribute__
uint16_t btn_signal[MAX_BUTTONS]
void update_touches() override
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.
void dump_config() override
void IRAM_ATTR HOT delay(uint32_t ms)