7static const char *
const TAG =
"gsl3670.touchscreen";
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");
87 if (this->reset_pin_ !=
nullptr) {
94 this->write_reg8_(0x88, 0x01);
96 this->write_reg8_(0xe4, 0x04);
98 this->write_reg8_(0xe0, 0x00);
106void GSL3670Touchscreen::reset_() {
107 ESP_LOGD(TAG,
"reset");
109 if (this->reset_pin_ !=
nullptr) {
116 this->write_reg8_(0xe4, 0x04);
118 uint8_t zeros[4] = {0, 0, 0, 0};
119 this->write_reg_(0xbc, zeros, 4);
122void GSL3670Touchscreen::load_firmware_() {
123 if (firmware_ ==
nullptr || firmware_len_ == 0) {
124 ESP_LOGW(TAG,
"No firmware supplied – skipping");
128 ESP_LOGD(TAG,
"Loading firmware (%zu blocks)...", firmware_len_);
130 static constexpr size_t FW_BLK_SIZE = 128 + 4;
132 for (
size_t i = 0; i != this->firmware_len_; i++) {
133 auto offset = i * FW_BLK_SIZE;
134 uint8_t
val = this->firmware_[offset + 0];
135 ESP_LOGV(TAG,
"Firmware address 0x%02X",
val);
136 this->write_reg_(0xf0, &
val, 1);
137 this->write_reg_(0, this->firmware_ + offset + 4, 128);
139 ESP_LOGD(TAG,
"Firmware load complete");
146void GSL3670Touchscreen::startup_chip_() {
147 ESP_LOGD(TAG,
"startup_chip");
148 this->write_reg8_(0xe0, 0x00);
156bool GSL3670Touchscreen::write_reg_(uint8_t reg,
const uint8_t *data,
size_t len) {
159 ESP_LOGW(TAG,
"I2C write reg 0x%02X len %zu failed (%d)",
reg,
len, err);
165bool GSL3670Touchscreen::write_reg8_(uint8_t reg, uint8_t
val) {
return write_reg_(
reg, &
val, 1); }