8static const size_t MAX_TOUCHES = 3;
14 ESP_LOGCONFIG(TAG,
"Setting up GSL3670 touchscreen...");
16 if (this->reset_pin_ !=
nullptr) {
17 this->reset_pin_->
setup();
21 if (this->interrupt_pin_ !=
nullptr) {
22 this->interrupt_pin_->
setup();
35 this->load_firmware_();
36 this->startup_chip_();
38 this->startup_chip_();
40 ESP_LOGCONFIG(TAG,
"GSL3670 initialised OK");
45 "GSL3670 Touchscreen:\n"
50 LOG_PIN(
" Reset Pin: ", this->reset_pin_);
51 LOG_PIN(
" Interrupt Pin: ", this->interrupt_pin_);
52 ESP_LOGCONFIG(TAG,
" Firmware records: %zu", this->firmware_len_);
62 ESP_LOGW(TAG,
"I2C read failed (%d)", err);
68 for (uint8_t j = 0; j != finger_num; j++) {
70 auto x = (uint16_t) (((buf[(j + 1) * 4 + 3] & 0x0f) << 8) | buf[(j + 1) * 4 + 2]);
71 auto y = (uint16_t) ((buf[(j + 1) * 4 + 1] << 8) | buf[(j + 1) * 4 + 0]);
72 auto id = (buf[(j + 1) * 4 + 3] >> 4) & 0x0f;
73 ESP_LOGV(TAG,
"Touch id=%u, x=%u y=%u",
id,
x,
y);
74 if (
x <= 8192 &&
y <= 8192)
83void GSL3670Touchscreen::clear_reg_() {
84 ESP_LOGD(TAG,
"clear_reg");
86 pulse_reset(this->reset_pin_, {.low_ms = 1, .high_after_ms = 5});
88 this->write_reg8_(0x88, 0x01);
90 this->write_reg8_(0xe4, 0x04);
92 this->write_reg8_(0xe0, 0x00);
100void GSL3670Touchscreen::reset_() {
101 ESP_LOGD(TAG,
"reset");
103 pulse_reset(this->reset_pin_, {.low_ms = 1, .high_after_ms = 5});
105 this->write_reg8_(0xe4, 0x04);
107 uint8_t zeros[4] = {0, 0, 0, 0};
108 this->write_reg_(0xbc, zeros, 4);
111void GSL3670Touchscreen::load_firmware_() {
112 if (firmware_ ==
nullptr || firmware_len_ == 0) {
113 ESP_LOGW(TAG,
"No firmware supplied – skipping");
117 ESP_LOGD(TAG,
"Loading firmware (%zu blocks)...", firmware_len_);
119 static constexpr size_t FW_BLK_SIZE = 128 + 4;
121 for (
size_t i = 0; i != this->firmware_len_; i++) {
122 auto offset = i * FW_BLK_SIZE;
123 uint8_t
val = this->firmware_[offset + 0];
124 ESP_LOGV(TAG,
"Firmware address 0x%02X",
val);
125 this->write_reg_(0xf0, &
val, 1);
126 this->write_reg_(0, this->firmware_ + offset + 4, 128);
128 ESP_LOGD(TAG,
"Firmware load complete");
135void GSL3670Touchscreen::startup_chip_() {
136 ESP_LOGD(TAG,
"startup_chip");
137 this->write_reg8_(0xe0, 0x00);
145bool GSL3670Touchscreen::write_reg_(uint8_t reg,
const uint8_t *data,
size_t len) {
148 ESP_LOGW(TAG,
"I2C write reg 0x%02X len %zu failed (%d)",
reg,
len, err);
154bool GSL3670Touchscreen::write_reg8_(uint8_t reg, uint8_t
val) {
return write_reg_(
reg, &
val, 1); }