mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
[gt911] Add reset pin config (#7373)
This commit is contained in:
parent
acb00c9c59
commit
725e50348b
9 changed files with 56 additions and 125 deletions
|
@ -1,11 +1,10 @@
|
||||||
import esphome.codegen as cg
|
|
||||||
import esphome.config_validation as cv
|
|
||||||
|
|
||||||
from esphome import pins
|
from esphome import pins
|
||||||
|
import esphome.codegen as cg
|
||||||
from esphome.components import i2c, touchscreen
|
from esphome.components import i2c, touchscreen
|
||||||
from esphome.const import CONF_INTERRUPT_PIN, CONF_ID
|
import esphome.config_validation as cv
|
||||||
from .. import gt911_ns
|
from esphome.const import CONF_ID, CONF_INTERRUPT_PIN, CONF_RESET_PIN
|
||||||
|
|
||||||
|
from .. import gt911_ns
|
||||||
|
|
||||||
GT911ButtonListener = gt911_ns.class_("GT911ButtonListener")
|
GT911ButtonListener = gt911_ns.class_("GT911ButtonListener")
|
||||||
GT911Touchscreen = gt911_ns.class_(
|
GT911Touchscreen = gt911_ns.class_(
|
||||||
|
@ -18,6 +17,7 @@ CONFIG_SCHEMA = touchscreen.TOUCHSCREEN_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
cv.GenerateID(): cv.declare_id(GT911Touchscreen),
|
cv.GenerateID(): cv.declare_id(GT911Touchscreen),
|
||||||
cv.Optional(CONF_INTERRUPT_PIN): pins.internal_gpio_input_pin_schema,
|
cv.Optional(CONF_INTERRUPT_PIN): pins.internal_gpio_input_pin_schema,
|
||||||
|
cv.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
|
||||||
}
|
}
|
||||||
).extend(i2c.i2c_device_schema(0x5D))
|
).extend(i2c.i2c_device_schema(0x5D))
|
||||||
|
|
||||||
|
@ -29,3 +29,5 @@ async def to_code(config):
|
||||||
|
|
||||||
if interrupt_pin := config.get(CONF_INTERRUPT_PIN):
|
if interrupt_pin := config.get(CONF_INTERRUPT_PIN):
|
||||||
cg.add(var.set_interrupt_pin(await cg.gpio_pin_expression(interrupt_pin)))
|
cg.add(var.set_interrupt_pin(await cg.gpio_pin_expression(interrupt_pin)))
|
||||||
|
if reset_pin := config.get(CONF_RESET_PIN):
|
||||||
|
cg.add(var.set_reset_pin(await cg.gpio_pin_expression(reset_pin)))
|
||||||
|
|
|
@ -26,6 +26,23 @@ static const size_t MAX_BUTTONS = 4; // max number of buttons scanned
|
||||||
void GT911Touchscreen::setup() {
|
void GT911Touchscreen::setup() {
|
||||||
i2c::ErrorCode err;
|
i2c::ErrorCode err;
|
||||||
ESP_LOGCONFIG(TAG, "Setting up GT911 Touchscreen...");
|
ESP_LOGCONFIG(TAG, "Setting up GT911 Touchscreen...");
|
||||||
|
if (this->reset_pin_ != nullptr) {
|
||||||
|
this->reset_pin_->setup();
|
||||||
|
this->reset_pin_->digital_write(false);
|
||||||
|
if (this->interrupt_pin_ != nullptr) {
|
||||||
|
// The interrupt pin is used as an input during reset to select the I2C address.
|
||||||
|
this->interrupt_pin_->pin_mode(gpio::FLAG_OUTPUT);
|
||||||
|
this->interrupt_pin_->setup();
|
||||||
|
this->interrupt_pin_->digital_write(false);
|
||||||
|
}
|
||||||
|
delay(2);
|
||||||
|
this->reset_pin_->digital_write(true);
|
||||||
|
delay(50); // NOLINT
|
||||||
|
if (this->interrupt_pin_ != nullptr) {
|
||||||
|
this->interrupt_pin_->pin_mode(gpio::FLAG_INPUT);
|
||||||
|
this->interrupt_pin_->setup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check the configuration of the int line.
|
// check the configuration of the int line.
|
||||||
uint8_t data[4];
|
uint8_t data[4];
|
||||||
|
|
|
@ -19,12 +19,14 @@ class GT911Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
|
|
||||||
void set_interrupt_pin(InternalGPIOPin *pin) { this->interrupt_pin_ = pin; }
|
void set_interrupt_pin(InternalGPIOPin *pin) { this->interrupt_pin_ = pin; }
|
||||||
|
void set_reset_pin(GPIOPin *pin) { this->reset_pin_ = pin; }
|
||||||
void register_button_listener(GT911ButtonListener *listener) { this->button_listeners_.push_back(listener); }
|
void register_button_listener(GT911ButtonListener *listener) { this->button_listeners_.push_back(listener); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void update_touches() override;
|
void update_touches() override;
|
||||||
|
|
||||||
InternalGPIOPin *interrupt_pin_{};
|
InternalGPIOPin *interrupt_pin_{};
|
||||||
|
GPIOPin *reset_pin_{};
|
||||||
std::vector<GT911ButtonListener *> button_listeners_;
|
std::vector<GT911ButtonListener *> button_listeners_;
|
||||||
uint8_t button_state_{0xFF}; // last button state. Initial FF guarantees first update.
|
uint8_t button_state_{0xFF}; // last button state. Initial FF guarantees first update.
|
||||||
};
|
};
|
||||||
|
|
25
tests/components/gt911/common.yaml
Normal file
25
tests/components/gt911/common.yaml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
i2c:
|
||||||
|
- id: i2c_gt911
|
||||||
|
scl: 5
|
||||||
|
sda: 4
|
||||||
|
|
||||||
|
display:
|
||||||
|
- platform: ssd1306_i2c
|
||||||
|
id: ssd1306_display
|
||||||
|
model: SSD1306_128X64
|
||||||
|
reset_pin: 10
|
||||||
|
pages:
|
||||||
|
- id: page1
|
||||||
|
lambda: |-
|
||||||
|
it.rectangle(0, 0, it.get_width(), it.get_height());
|
||||||
|
|
||||||
|
touchscreen:
|
||||||
|
- platform: gt911
|
||||||
|
display: ssd1306_display
|
||||||
|
interrupt_pin: 20
|
||||||
|
reset_pin: 21
|
||||||
|
|
||||||
|
binary_sensor:
|
||||||
|
- platform: gt911
|
||||||
|
id: touch_key_911
|
||||||
|
index: 0
|
|
@ -1,24 +1 @@
|
||||||
i2c:
|
<<: !include common.yaml
|
||||||
- id: i2c_gt911
|
|
||||||
scl: 16
|
|
||||||
sda: 17
|
|
||||||
|
|
||||||
display:
|
|
||||||
- platform: ssd1306_i2c
|
|
||||||
id: ssd1306_display
|
|
||||||
model: SSD1306_128X64
|
|
||||||
reset_pin: 13
|
|
||||||
pages:
|
|
||||||
- id: page1
|
|
||||||
lambda: |-
|
|
||||||
it.rectangle(0, 0, it.get_width(), it.get_height());
|
|
||||||
|
|
||||||
touchscreen:
|
|
||||||
- platform: gt911
|
|
||||||
display: ssd1306_display
|
|
||||||
interrupt_pin: 14
|
|
||||||
|
|
||||||
binary_sensor:
|
|
||||||
- platform: gt911
|
|
||||||
id: touch_key_911
|
|
||||||
index: 0
|
|
||||||
|
|
|
@ -1,24 +1 @@
|
||||||
i2c:
|
<<: !include common.yaml
|
||||||
- id: i2c_gt911
|
|
||||||
scl: 5
|
|
||||||
sda: 4
|
|
||||||
|
|
||||||
display:
|
|
||||||
- platform: ssd1306_i2c
|
|
||||||
id: ssd1306_display
|
|
||||||
model: SSD1306_128X64
|
|
||||||
reset_pin: 3
|
|
||||||
pages:
|
|
||||||
- id: page1
|
|
||||||
lambda: |-
|
|
||||||
it.rectangle(0, 0, it.get_width(), it.get_height());
|
|
||||||
|
|
||||||
touchscreen:
|
|
||||||
- platform: gt911
|
|
||||||
display: ssd1306_display
|
|
||||||
interrupt_pin: 6
|
|
||||||
|
|
||||||
binary_sensor:
|
|
||||||
- platform: gt911
|
|
||||||
id: touch_key_911
|
|
||||||
index: 0
|
|
||||||
|
|
|
@ -1,24 +1 @@
|
||||||
i2c:
|
<<: !include common.yaml
|
||||||
- id: i2c_gt911
|
|
||||||
scl: 5
|
|
||||||
sda: 4
|
|
||||||
|
|
||||||
display:
|
|
||||||
- platform: ssd1306_i2c
|
|
||||||
id: ssd1306_display
|
|
||||||
model: SSD1306_128X64
|
|
||||||
reset_pin: 3
|
|
||||||
pages:
|
|
||||||
- id: page1
|
|
||||||
lambda: |-
|
|
||||||
it.rectangle(0, 0, it.get_width(), it.get_height());
|
|
||||||
|
|
||||||
touchscreen:
|
|
||||||
- platform: gt911
|
|
||||||
display: ssd1306_display
|
|
||||||
interrupt_pin: 6
|
|
||||||
|
|
||||||
binary_sensor:
|
|
||||||
- platform: gt911
|
|
||||||
id: touch_key_911
|
|
||||||
index: 0
|
|
||||||
|
|
|
@ -1,24 +1 @@
|
||||||
i2c:
|
<<: !include common.yaml
|
||||||
- id: i2c_gt911
|
|
||||||
scl: 16
|
|
||||||
sda: 17
|
|
||||||
|
|
||||||
display:
|
|
||||||
- platform: ssd1306_i2c
|
|
||||||
id: ssd1306_display
|
|
||||||
model: SSD1306_128X64
|
|
||||||
reset_pin: 13
|
|
||||||
pages:
|
|
||||||
- id: page1
|
|
||||||
lambda: |-
|
|
||||||
it.rectangle(0, 0, it.get_width(), it.get_height());
|
|
||||||
|
|
||||||
touchscreen:
|
|
||||||
- platform: gt911
|
|
||||||
display: ssd1306_display
|
|
||||||
interrupt_pin: 14
|
|
||||||
|
|
||||||
binary_sensor:
|
|
||||||
- platform: gt911
|
|
||||||
id: touch_key_911
|
|
||||||
index: 0
|
|
||||||
|
|
|
@ -1,24 +1 @@
|
||||||
i2c:
|
<<: !include common.yaml
|
||||||
- id: i2c_gt911
|
|
||||||
scl: 5
|
|
||||||
sda: 4
|
|
||||||
|
|
||||||
display:
|
|
||||||
- platform: ssd1306_i2c
|
|
||||||
id: ssd1306_display
|
|
||||||
model: SSD1306_128X64
|
|
||||||
reset_pin: 3
|
|
||||||
pages:
|
|
||||||
- id: page1
|
|
||||||
lambda: |-
|
|
||||||
it.rectangle(0, 0, it.get_width(), it.get_height());
|
|
||||||
|
|
||||||
touchscreen:
|
|
||||||
- platform: gt911
|
|
||||||
display: ssd1306_display
|
|
||||||
interrupt_pin: 6
|
|
||||||
|
|
||||||
binary_sensor:
|
|
||||||
- platform: gt911
|
|
||||||
id: touch_key_911
|
|
||||||
index: 0
|
|
||||||
|
|
Loading…
Reference in a new issue