Expand uart invert feature to ESP8266 (#1727)

This commit is contained in:
Leon Loopik 2021-12-01 20:31:04 +01:00 committed by GitHub
parent fbe1bca1b9
commit 11330af05f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View file

@ -14,6 +14,7 @@ from esphome.const import (
CONF_UART_ID,
CONF_DATA,
CONF_RX_BUFFER_SIZE,
CONF_INVERTED,
CONF_INVERT,
CONF_TRIGGER_ID,
CONF_SEQUENCE,
@ -67,6 +68,19 @@ def validate_rx_pin(value):
return value
def validate_invert_esp32(config):
if (
CORE.is_esp32
and CONF_TX_PIN in config
and CONF_RX_PIN in config
and config[CONF_TX_PIN][CONF_INVERTED] != config[CONF_RX_PIN][CONF_INVERTED]
):
raise cv.Invalid(
"Different invert values for TX and RX pin are not (yet) supported for ESP32."
)
return config
def _uart_declare_type(value):
if CORE.is_esp8266:
return cv.declare_id(ESP8266UartComponent)(value)
@ -162,6 +176,7 @@ CONFIG_SCHEMA = cv.All(
}
).extend(cv.COMPONENT_SCHEMA),
cv.has_at_least_one_key(CONF_TX_PIN, CONF_RX_PIN),
validate_invert_esp32,
)

View file

@ -45,6 +45,11 @@ uint32_t ESP8266UartComponent::get_config() {
else
config |= UART_NB_STOP_BIT_2;
if (this->tx_pin_ != nullptr && this->tx_pin_->is_inverted())
config |= BIT(22);
if (this->rx_pin_ != nullptr && this->rx_pin_->is_inverted())
config |= BIT(19);
return config;
}

View file

@ -227,7 +227,9 @@ spi:
uart:
- id: uart1
tx_pin: GPIO1
tx_pin:
number: GPIO1
inverted: yes
rx_pin: GPIO3
baud_rate: 115200
- id: uart2