ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
esphome::uart::VirtualUARTComponent< RX_BUFFER_SIZE > Class Template Reference

UART without a wire: the derived class writes and feeds reads with inject_rx(). More...

#include <uart_virtual.h>

Inheritance diagram for esphome::uart::VirtualUARTComponent< RX_BUFFER_SIZE >:
esphome::uart::UARTComponent esphome::virtual_uart::VirtualUART< RX_BUFFER_SIZE >

Public Member Functions

 VirtualUARTComponent ()
 
bool inject_rx (const uint8_t *data, size_t len)
 Adds one whole block to the RX ring; false, and nothing kept, when it does not fit.
 
bool peek_byte (uint8_t *data) override
 
bool read_array (uint8_t *data, size_t len) override
 
size_t available () override
 
void load_settings (bool dump_config) override
 
void load_settings ()
 Load the UART settings.
 
- Public Member Functions inherited from esphome::uart::UARTComponent
void write_array (const std::vector< uint8_t > &data)
 
void write_byte (uint8_t data)
 
void write_str (const char *str)
 
virtual void write_array (const uint8_t *data, size_t len)=0
 
void write_array_progmem (const uint8_t *data, size_t len)
 
void write_array_progmem (const uint8_t *data, size_t len)
 
bool read_byte (uint8_t *data)
 
virtual size_t available_for_write ()
 
size_t paced_write_room (uint32_t last_write_ms)
 
virtual UARTFlushResult flush ()=0
 
virtual bool is_connected ()
 
virtual void set_flush_timeout (uint32_t flush_timeout_ms)
 
virtual bool set_tx_break (bool enable)
 
void set_tx_pin (InternalGPIOPin *tx_pin)
 
void set_rx_pin (InternalGPIOPin *rx_pin)
 
void set_flow_control_pin (InternalGPIOPin *flow_control_pin)
 
void set_rx_buffer_size (size_t rx_buffer_size)
 
size_t get_rx_buffer_size ()
 
virtual void set_rx_full_threshold (size_t rx_full_threshold)
 
void set_rx_full_threshold_ms (uint8_t time)
 
size_t get_rx_full_threshold ()
 
virtual void set_rx_timeout (size_t rx_timeout)
 
size_t get_rx_timeout ()
 
void set_stop_bits (uint8_t stop_bits)
 
uint8_t get_stop_bits () const
 
void set_data_bits (uint8_t data_bits)
 
uint8_t get_data_bits () const
 
void set_parity (UARTParityOptions parity)
 
UARTParityOptions get_parity () const
 
void set_baud_rate (uint32_t baud_rate)
 
uint32_t get_baud_rate () const
 
void set_flow_control (UARTFlowControl flow_control)
 
UARTFlowControl get_flow_control () const
 
void load_settings ()
 Load the UART settings.
 
template<typename F >
void add_debug_callback (F &&callback)
 

Protected Member Functions

void check_logger_conflict () override
 
void debug_tx_ (const uint8_t *data, size_t len)
 For write_array() of the derived class: hands the written bytes to a configured UART debugger.
 
- Protected Member Functions inherited from esphome::uart::UARTComponent
bool check_read_timeout_ (size_t len=1)
 

Protected Attributes

StaticRingBuffer< uint8_t, RX_BUFFER_SIZE > rx_
 
- Protected Attributes inherited from esphome::uart::UARTComponent
InternalGPIOPin * tx_pin_ {}
 
InternalGPIOPin * rx_pin_ {}
 
InternalGPIOPin * flow_control_pin_ {}
 
size_t rx_buffer_size_ {}
 
size_t rx_full_threshold_ {RX_FULL_THRESHOLD_UNSET}
 
size_t rx_timeout_ {0}
 
uint32_t baud_rate_ {0}
 
uint8_t stop_bits_ {0}
 
uint8_t data_bits_ {0}
 
UARTFlowControl flow_control_ {UART_FLOW_CONTROL_NONE}
 
UARTParityOptions parity_ {UART_CONFIG_PARITY_NONE}
 
CallbackManager< void(UARTDirection, uint8_t)> debug_callback_ {}
 

Additional Inherited Members

- Static Public Attributes inherited from esphome::uart::UARTComponent
static constexpr size_t RX_FULL_THRESHOLD_UNSET = 0
 

Detailed Description

template<size_t RX_BUFFER_SIZE>
class esphome::uart::VirtualUARTComponent< RX_BUFFER_SIZE >

UART without a wire: the derived class writes and feeds reads with inject_rx().

Reads never wait. Main loop only. The RX_BUFFER_SIZE byte ring lives in the object; set_rx_buffer_size() does not resize it.

Definition at line 10 of file uart_virtual.h.

Constructor & Destructor Documentation

◆ VirtualUARTComponent()

template<size_t RX_BUFFER_SIZE>
esphome::uart::VirtualUARTComponent< RX_BUFFER_SIZE >::VirtualUARTComponent ( )
inline

Definition at line 12 of file uart_virtual.h.

Member Function Documentation

◆ available()

template<size_t RX_BUFFER_SIZE>
size_t esphome::uart::VirtualUARTComponent< RX_BUFFER_SIZE >::available ( )
inlineoverridevirtual

Implements esphome::uart::UARTComponent.

Definition at line 38 of file uart_virtual.h.

◆ check_logger_conflict()

template<size_t RX_BUFFER_SIZE>
void esphome::uart::VirtualUARTComponent< RX_BUFFER_SIZE >::check_logger_conflict ( )
inlineoverrideprotectedvirtual

Implements esphome::uart::UARTComponent.

Definition at line 46 of file uart_virtual.h.

◆ debug_tx_()

template<size_t RX_BUFFER_SIZE>
void esphome::uart::VirtualUARTComponent< RX_BUFFER_SIZE >::debug_tx_ ( const uint8_t * data,
size_t len )
inlineprotected

For write_array() of the derived class: hands the written bytes to a configured UART debugger.

Definition at line 48 of file uart_virtual.h.

◆ inject_rx()

template<size_t RX_BUFFER_SIZE>
bool esphome::uart::VirtualUARTComponent< RX_BUFFER_SIZE >::inject_rx ( const uint8_t * data,
size_t len )
inline

Adds one whole block to the RX ring; false, and nothing kept, when it does not fit.

Definition at line 15 of file uart_virtual.h.

◆ load_settings() [1/2]

template<size_t RX_BUFFER_SIZE>
void esphome::uart::UARTComponent::load_settings ( )
inline

Load the UART settings.

Example:

id(uart1).load_settings();
uint16_t id

This will load the current UART interface with the latest settings (baud_rate, parity, etc).

Definition at line 242 of file uart_component.h.

◆ load_settings() [2/2]

template<size_t RX_BUFFER_SIZE>
void esphome::uart::VirtualUARTComponent< RX_BUFFER_SIZE >::load_settings ( bool dump_config)
inlineoverridevirtual

Implements esphome::uart::UARTComponent.

Definition at line 42 of file uart_virtual.h.

◆ peek_byte()

template<size_t RX_BUFFER_SIZE>
bool esphome::uart::VirtualUARTComponent< RX_BUFFER_SIZE >::peek_byte ( uint8_t * data)
inlineoverridevirtual

Implements esphome::uart::UARTComponent.

Definition at line 22 of file uart_virtual.h.

◆ read_array()

template<size_t RX_BUFFER_SIZE>
bool esphome::uart::VirtualUARTComponent< RX_BUFFER_SIZE >::read_array ( uint8_t * data,
size_t len )
inlineoverridevirtual

Implements esphome::uart::UARTComponent.

Definition at line 28 of file uart_virtual.h.

Field Documentation

◆ rx_

template<size_t RX_BUFFER_SIZE>
StaticRingBuffer<uint8_t, RX_BUFFER_SIZE> esphome::uart::VirtualUARTComponent< RX_BUFFER_SIZE >::rx_
protected

Definition at line 55 of file uart_virtual.h.


The documentation for this class was generated from the following file: