mirror of
https://github.com/esphome/esphome.git
synced 2025-03-16 15:48:16 +00:00
[uart] flow control - fix ESP32 Arduino < 2.0.8
This commit is contained in:
parent
f96069196f
commit
b608685c60
@ -30,6 +30,8 @@ from esphome.const import (
|
|||||||
CONF_DUMMY_RECEIVER_ID,
|
CONF_DUMMY_RECEIVER_ID,
|
||||||
CONF_LAMBDA,
|
CONF_LAMBDA,
|
||||||
PLATFORM_HOST,
|
PLATFORM_HOST,
|
||||||
|
KEY_CORE,
|
||||||
|
KEY_FRAMEWORK_VERSION
|
||||||
)
|
)
|
||||||
from esphome.core import CORE
|
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.")
|
raise cv.Invalid("Pins GPIO16 and GPIO17 cannot be used as RX pins on ESP8266.")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
def validate_flow_control_support(config):
|
def validate_flow_control_support(config):
|
||||||
if CONF_FLOW_CONTROL_PIN in config and not CORE.is_esp32:
|
if CORE.is_esp32 and CORE.using_arduino:
|
||||||
raise cv.Invalid("Hardware does not support flow control.")
|
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
|
return config
|
||||||
|
else:
|
||||||
|
raise cv.Invalid("Hardware does not support RS485 flow control.")
|
||||||
|
|
||||||
|
|
||||||
def validate_invert_esp32(config):
|
def validate_invert_esp32(config):
|
||||||
|
@ -141,10 +141,12 @@ void ESP32ArduinoUARTComponent::load_settings(bool dump_config) {
|
|||||||
invert = true;
|
invert = true;
|
||||||
this->hw_serial_->setRxBufferSize(this->rx_buffer_size_);
|
this->hw_serial_->setRxBufferSize(this->rx_buffer_size_);
|
||||||
this->hw_serial_->begin(this->baud_rate_, get_config(), rx, tx, invert);
|
this->hw_serial_->begin(this->baud_rate_, get_config(), rx, tx, invert);
|
||||||
|
#ifdef USE_UART_FLOW_CONTROL
|
||||||
if (this->flow_control_pin_ != nullptr) {
|
if (this->flow_control_pin_ != nullptr) {
|
||||||
this->hw_serial_->setPins(-1, -1, -1, this->flow_control_pin_->get_pin());
|
this->hw_serial_->setPins(-1, -1, -1, this->flow_control_pin_->get_pin());
|
||||||
this->hw_serial_->setMode(UART_MODE_RS485_HALF_DUPLEX);
|
this->hw_serial_->setMode(UART_MODE_RS485_HALF_DUPLEX);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (dump_config) {
|
if (dump_config) {
|
||||||
ESP_LOGCONFIG(TAG, "UART %u was reloaded.", this->number_);
|
ESP_LOGCONFIG(TAG, "UART %u was reloaded.", this->number_);
|
||||||
this->dump_config();
|
this->dump_config();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user