From bc8fa31a7605c729ac48fc40b0bc944deeef9867 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Thu, 10 Sep 2026 20:32:31 +0000 Subject: [PATCH] [serial_proxy] Implement a no-op hardware flow control --- esphome/components/serial_proxy/serial_proxy.cpp | 9 +++------ esphome/components/serial_proxy/serial_proxy.h | 4 +--- esphome/components/uart/uart_component.h | 9 +++++++++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/esphome/components/serial_proxy/serial_proxy.cpp b/esphome/components/serial_proxy/serial_proxy.cpp index 61263287c4..cd9e1ae4b9 100644 --- a/esphome/components/serial_proxy/serial_proxy.cpp +++ b/esphome/components/serial_proxy/serial_proxy.cpp @@ -212,11 +212,6 @@ SerialProxyResult SerialProxy::configure(api::APIConnection *api_connection, uin ESP_LOGW(TAG, "Invalid parity: %u (must be 0-2)", parity); return SerialProxyResult::SERIAL_PROXY_RESULT_INVALID_ARGUMENT; } - if (flow_control) { - ESP_LOGW(TAG, "Hardware flow control requested but is not yet supported"); - return SerialProxyResult::SERIAL_PROXY_RESULT_NOT_SUPPORTED; - } - // Skip a no-op reconfigure. Clients routinely re-send identical settings on every // port open, and on a USB UART each apply is a CDC SET_LINE_CODING control transfer. // Some bridges watch line-coding changes as a signalling channel (a magic baud @@ -227,7 +222,8 @@ SerialProxyResult SerialProxy::configure(api::APIConnection *api_connection, uin uart::UART_CONFIG_PARITY_ODD, }; if (uart_comp->get_baud_rate() == baudrate && uart_comp->get_stop_bits() == stop_bits && - uart_comp->get_data_bits() == data_size && uart_comp->get_parity() == PARITY_MAP[parity]) { + uart_comp->get_data_bits() == data_size && uart_comp->get_parity() == PARITY_MAP[parity] && + uart_comp->get_flow_control() == flow_control) { ESP_LOGV(TAG, "Settings unchanged, skipping reconfigure [%" PRIu32 "]", this->instance_index_); return SerialProxyResult::SERIAL_PROXY_RESULT_OK; } @@ -236,6 +232,7 @@ SerialProxyResult SerialProxy::configure(api::APIConnection *api_connection, uin uart_comp->set_baud_rate(baudrate); uart_comp->set_stop_bits(stop_bits); uart_comp->set_data_bits(data_size); + uart_comp->set_flow_control(flow_control); uart_comp->set_parity(PARITY_MAP[parity]); diff --git a/esphome/components/serial_proxy/serial_proxy.h b/esphome/components/serial_proxy/serial_proxy.h index 8ebb9ea94f..33b65c68b7 100644 --- a/esphome/components/serial_proxy/serial_proxy.h +++ b/esphome/components/serial_proxy/serial_proxy.h @@ -121,14 +121,13 @@ class SerialProxy final : public uart::UARTDevice, public Component { /// Get the port type api::enums::SerialProxyPortType get_port_type() const { return this->port_type_; } - /// Handle a mode change requested by an API client SerialProxyResult set_mode_from_client(api::APIConnection *api_connection, api::enums::SerialProxyMode mode); /// Configure UART parameters and apply them /// @param api_connection The API connection requesting the change /// @param baudrate Baud rate in bits per second - /// @param flow_control True to enable hardware flow control + /// @param flow_control True to request hardware flow control /// @param parity Parity setting (0=none, 1=even, 2=odd) /// @param stop_bits Number of stop bits (1 or 2) /// @param data_size Number of data bits (5-8) @@ -278,7 +277,6 @@ class SerialProxy final : public uart::UARTDevice, public Component { /// Current modem pin states bool rts_state_{false}; bool dtr_state_{false}; - #ifdef USE_SERIAL_PROXY_TAP SerialProxyTap *tap_{nullptr}; #endif diff --git a/esphome/components/uart/uart_component.h b/esphome/components/uart/uart_component.h index 3e52531791..01b17624b9 100644 --- a/esphome/components/uart/uart_component.h +++ b/esphome/components/uart/uart_component.h @@ -166,6 +166,14 @@ class UARTComponent { // @return Baud rate in bits per second. uint32_t get_baud_rate() const { return baud_rate_; } + // Requests hardware (RTS/CTS) flow control. + // @param flow_control True to request hardware flow control. + void set_flow_control(bool flow_control) { this->flow_control_ = flow_control; } + + // Gets whether hardware flow control was requested. + // @return True when hardware flow control was requested. + bool get_flow_control() const { return this->flow_control_; } + #if defined(USE_ESP8266) || defined(USE_ESP32) /** * Load the UART settings. @@ -213,6 +221,7 @@ class UARTComponent { uint8_t stop_bits_{0}; uint8_t data_bits_{0}; UARTParityOptions parity_{UART_CONFIG_PARITY_NONE}; + bool flow_control_{false}; #ifdef USE_UART_DEBUGGER CallbackManager debug_callback_{}; #endif