4ec8c7a935
The 2 ms reset of ESPHome's expander support (0.2.81) left the chip silent: "Calibration error" with the PCA9557 answering at 0x18. A component of smart_display's (elecrow_touch_reset.h, setup priority 700: after the I2C bus, before the GT911 driver) writes the expander as Elecrow's V3.0 ESPHome example does: every pin an output and low, 20 ms, the reset released, 100 ms, the interrupt line back to an input. The driver's reset and interrupt pins are gone.
42 lines
2.2 KiB
C++
42 lines
2.2 KiB
C++
#pragma once
|
|
// The GT911 of the Elecrow CrowPanel 7.0" V3.0 hangs on a PCA9557 I/O expander (I2C 0x18): IO0 is its reset, IO1 its
|
|
// interrupt line, and it stays in reset until something drives them (firmware 0.2.82). This is Elecrow's own sequence
|
|
// from their V3.0 ESPHome example, byte for byte: every expander pin an output and low (the reset held, the interrupt
|
|
// line low so the chip takes address 0x5D), 20 ms, the reset released, 100 ms for the chip to come up, then the
|
|
// interrupt line back to an input. It runs after the I2C bus is up and before the GT911 driver looks for the chip
|
|
// (setup priority 700, between the bus's 1000 and the driver's 600), so the driver finds it at 0x5D. A V2.0 board
|
|
// has no expander: the writes fail, the log says so, and the GT911 boots by its pull-up as before.
|
|
//
|
|
// Only the Elecrow's board file builds this (`smart_display: elecrow_touch_reset:`, which sets the flag), so the
|
|
// header adds nothing to a CYD, which has no I2C at all.
|
|
#if defined(ESP_SCREENS_ELECROW_TOUCH_RESET) && ESP_SCREENS_ELECROW_TOUCH_RESET
|
|
#include "esphome/components/i2c/i2c.h"
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/hal.h"
|
|
#include "esphome/core/log.h"
|
|
|
|
namespace elecrow {
|
|
class TouchReset : public esphome::Component, public esphome::i2c::I2CDevice {
|
|
public:
|
|
float get_setup_priority() const override { return 700.0f; }
|
|
void setup() override {
|
|
auto write = [this](uint8_t reg, uint8_t value) {
|
|
const uint8_t data[2] = {reg, value};
|
|
return this->write(data, sizeof(data)) == esphome::i2c::ERROR_OK;
|
|
};
|
|
bool ok = write(0x03, 0x00); // configuration: every pin an output
|
|
ok = write(0x01, 0x00) && ok; // output: reset low, interrupt low (address 0x5D), the rest low
|
|
esphome::delay(20);
|
|
ok = write(0x01, 0x01) && ok; // reset released, the interrupt line still low
|
|
esphome::delay(100);
|
|
ok = write(0x03, 0x02) && ok; // the interrupt line an input again; the GT911 drives it from here
|
|
if (ok) {
|
|
ESP_LOGI("touch", "GT911 reset through the PCA9557 at 0x%02X", this->address_);
|
|
} else {
|
|
ESP_LOGW("touch", "No PCA9557 at 0x%02X: the GT911 was not reset (a V2.0 board boots it by its pull-up)", this->address_);
|
|
}
|
|
}
|
|
};
|
|
} // namespace elecrow
|
|
#endif
|