1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-14 06:38:17 +00:00

[uart] flow control - fix ESP32 Arduino < 2.0.8

This commit is contained in:
brambo123 2025-01-17 17:06:11 +01:00
parent f96069196f
commit b608685c60
3 changed files with 19 additions and 4 deletions

View File

@ -30,6 +30,8 @@ from esphome.const import (
CONF_DUMMY_RECEIVER_ID,
CONF_LAMBDA,
PLATFORM_HOST,
KEY_CORE,
KEY_FRAMEWORK_VERSION
)
from esphome.core import CORE
@ -117,10 +119,21 @@ def validate_rx_pin(value):
raise cv.Invalid("Pins GPIO16 and GPIO17 cannot be used as RX pins on ESP8266.")
return value
def validate_flow_control_support(config):
if CONF_FLOW_CONTROL_PIN in config and not CORE.is_esp32:
raise cv.Invalid("Hardware does not support flow control.")
return config
if CORE.is_esp32 and CORE.using_arduino:
if CORE.data[KEY_CORE][
KEY_FRAMEWORK_VERSION
] >= cv.Version(2, 0, 8):
cg.add_define("USE_UART_FLOW_CONTROL")
elif CONF_FLOW_CONTROL_PIN in config:
raise cv.Invalid(
"ESP32 RS485 UART Flow Control requires Arduino framework version 2.0.8 or higher."
)
elif CORE.is_esp32:
return config
else:
raise cv.Invalid("Hardware does not support RS485 flow control.")
def validate_invert_esp32(config):

View File

@ -141,10 +141,12 @@ void ESP32ArduinoUARTComponent::load_settings(bool dump_config) {
invert = true;
this->hw_serial_->setRxBufferSize(this->rx_buffer_size_);
this->hw_serial_->begin(this->baud_rate_, get_config(), rx, tx, invert);
#ifdef USE_UART_FLOW_CONTROL
if (this->flow_control_pin_ != nullptr) {
this->hw_serial_->setPins(-1, -1, -1, this->flow_control_pin_->get_pin());
this->hw_serial_->setMode(UART_MODE_RS485_HALF_DUPLEX);
}
#endif
if (dump_config) {
ESP_LOGCONFIG(TAG, "UART %u was reloaded.", this->number_);
this->dump_config();

View File

@ -139,7 +139,7 @@ void IDFUARTComponent::setup() {
this->mark_failed();
return;
}
if (this->flow_control_pin_ != nullptr) {
err = uart_set_mode(this->uart_num_, UART_MODE_RS485_HALF_DUPLEX);
if (err != ESP_OK) {