HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
EspUart Class Reference

ESP32 UART implementation class. More...

#include <EspUart.h>

Inheritance diagram for EspUart:
[legend]
Collaboration diagram for EspUart:
[legend]

Classes

struct  UartState
 UART state tracking structure. More...
 

Public Member Functions

 EspUart (const hf_uart_config_t &config) noexcept
 Constructor for ESP32 UART controller.
 
virtual ~EspUart () noexcept override
 Destructor - ensures clean shutdown.
 
 EspUart (const EspUart &)=delete
 
EspUartoperator= (const EspUart &)=delete
 
 EspUart (EspUart &&)=delete
 
EspUartoperator= (EspUart &&)=delete
 
hf_uart_err_t Write (const uint8_t *data, uint16_t length, uint32_t timeout_ms=0) noexcept override
 Write data to the UART.
 
hf_uart_err_t Read (uint8_t *data, uint16_t length, uint32_t timeout_ms=0) noexcept override
 Read data from the UART.
 
bool WriteByte (uint8_t byte) noexcept override
 Write a single byte to the UART.
 
bool SetBaudRate (uint32_t baud_rate) noexcept
 Set the baud rate.
 
hf_uart_err_t SetFlowControl (bool enable) noexcept
 Enable or disable hardware flow control.
 
hf_uart_err_t SetRTS (bool active) noexcept
 Set RTS line state.
 
hf_uart_err_t SendBreak (uint32_t duration_ms) noexcept
 Send a break condition.
 
hf_uart_err_t SetLoopback (bool enable) noexcept
 Enable or disable loopback mode.
 
bool WaitTransmitComplete (uint32_t timeout_ms) noexcept
 Wait for transmission to complete.
 
hf_uart_err_t SetOperatingMode (hf_uart_operating_mode_t mode) noexcept
 Set UART operating mode.
 
uint16_t ReadUntil (uint8_t *data, uint16_t max_length, uint8_t terminator, uint32_t timeout_ms) noexcept
 Read data until a specific terminator is found.
 
uint16_t ReadLine (char *buffer, uint16_t max_length, uint32_t timeout_ms) noexcept
 Read a line of text (until newline).
 
hf_uart_err_t SetCommunicationMode (hf_uart_mode_t mode) noexcept
 Set UART communication mode (UART/RS485/IrDA).
 
hf_uart_err_t ConfigureRS485 (const hf_uart_rs485_config_t &rs485_config) noexcept
 Configure RS485 mode.
 
hf_uart_err_t ConfigureIrDA (const hf_uart_irda_config_t &irda_config) noexcept
 Configure IrDA mode.
 
hf_uart_err_t ConfigureSoftwareFlowControl (bool enable, uint8_t xon_threshold=20, uint8_t xoff_threshold=80) noexcept
 Configure software flow control (XON/XOFF).
 
hf_uart_err_t ConfigureWakeup (const hf_uart_wakeup_config_t &wakeup_config) noexcept
 Configure UART wakeup from light sleep.
 
hf_uart_err_t SetSignalInversion (uint32_t inverse_mask) noexcept
 Set signal inversion mask.
 
QueueHandle_t GetEventQueue () const noexcept
 Get the ESP-IDF event queue handle for user task creation.
 
bool IsEventQueueAvailable () const noexcept
 Check if event queue is available.
 
hf_uart_err_t ConfigureInterrupts (uint32_t intr_enable_mask, uint8_t rxfifo_full_thresh=100, uint8_t rx_timeout_thresh=10) noexcept
 Configure UART interrupt settings.
 
hf_uart_err_t ResetEventQueue () noexcept
 Reset event queue (clear all pending events).
 
hf_uart_err_t EnablePatternDetection (char pattern_chr, uint8_t chr_num=1, int chr_tout=9, int post_idle=0, int pre_idle=0) noexcept
 Enable pattern detection for repeated byte sequences.
 
hf_uart_err_t DisablePatternDetection () noexcept
 Disable pattern detection.
 
hf_uart_err_t ResetPatternQueue (int queue_length=32) noexcept
 Reset pattern detection queue.
 
int PopPatternPosition () noexcept
 Pop pattern position from queue (consumes entry).
 
int PeekPatternPosition () noexcept
 Peek pattern position without consuming.
 
hf_uart_err_t GetStatistics (hf_uart_statistics_t &statistics) const noexcept override
 Get UART statistics.
 
hf_uart_err_t GetDiagnostics (hf_uart_diagnostics_t &diagnostics) const noexcept override
 Get UART diagnostics.
 
hf_uart_err_t GetLastError () const noexcept
 Get the last error that occurred.
 
const hf_uart_config_tGetPortConfig () const noexcept
 Get current UART configuration.
 
hf_uart_operating_mode_t GetOperatingMode () const noexcept
 Get current operating mode.
 
hf_uart_mode_t GetCommunicationMode () const noexcept
 Get current communication mode.
 
bool IsWakeupEnabled () const noexcept
 Check if wakeup is enabled.
 
bool IsTransmitting () const noexcept
 Check if transmission is in progress.
 
bool IsReceiving () const noexcept
 Check if reception is active.
 
bool IsBreakDetected () noexcept
 Check if break condition was detected.
 
uint16_t TxBytesWaiting () noexcept
 Get number of bytes waiting in TX buffer.
 
int Printf (const char *format,...) noexcept
 Print formatted string to UART.
 
int VPrintf (const char *format, va_list args) noexcept
 Print formatted string to UART with va_list.
 
uint16_t BytesAvailable () noexcept override
 Get the number of bytes available to read.
 
hf_uart_err_t FlushTx () noexcept override
 Flush the transmit buffer.
 
hf_uart_err_t FlushRx () noexcept override
 Flush the receive buffer.
 
bool IsTxBusy () noexcept
 
- Public Member Functions inherited from BaseUart
virtual ~BaseUart () noexcept=default
 Virtual destructor ensures proper cleanup in derived classes.
 
 BaseUart (const BaseUart &)=delete
 
BaseUartoperator= (const BaseUart &)=delete
 
 BaseUart (BaseUart &&)=delete
 
BaseUartoperator= (BaseUart &&)=delete
 
bool EnsureInitialized () noexcept
 Ensures that the UART is initialized (lazy initialization).
 
bool EnsureDeinitialized () noexcept
 Ensures that the UART is deinitialized (lazy deinitialization).
 
bool IsInitialized () const noexcept
 Checks if the driver is initialized.
 
hf_port_num_t GetPort () const noexcept
 Get the UART port number.
 
virtual bool Open () noexcept
 Open the UART (alias for Initialize).
 
virtual bool Close () noexcept
 Close the UART (alias for Deinitialize).
 
virtual bool WriteString (const char *str) noexcept
 Write a string to the UART.
 
virtual hf_uart_err_t ResetStatistics () noexcept
 Reset UART operation statistics.
 
virtual hf_uart_err_t ResetDiagnostics () noexcept
 Reset UART diagnostic information.
 

Static Public Attributes

static constexpr hf_u8_t MAX_PORTS = 3
 Maximum UART ports.
 
static constexpr hf_u32_t MAX_BAUD_RATE = 5000000
 Maximum baud rate.
 
static constexpr hf_u32_t MIN_BAUD_RATE = 110
 Minimum baud rate.
 
static constexpr hf_u32_t DEFAULT_BAUD_RATE = 115200
 Default baud rate.
 
static constexpr hf_u16_t MAX_BUFFER_SIZE = 1024
 Maximum buffer size.
 
static constexpr hf_u16_t DEFAULT_BUFFER_SIZE = 256
 Default buffer size.
 

Private Member Functions

bool Initialize () noexcept override
 Initialize the UART driver.
 
bool Deinitialize () noexcept override
 Deinitialize the UART driver.
 
hf_uart_err_t ValidateConfiguration () const noexcept
 Validate configuration.
 
hf_uart_err_t PlatformInitialize () noexcept
 Platform-specific initialization.
 
hf_uart_err_t PlatformDeinitialize () noexcept
 Platform-specific deinitialization.
 
hf_uart_err_t InstallDriver () noexcept
 Install UART driver.
 
hf_uart_err_t UninstallDriver () noexcept
 Uninstall UART driver.
 
hf_uart_err_t ConfigureUart () noexcept
 Configure UART parameters.
 
hf_uart_err_t ConfigurePins () noexcept
 Configure UART pins.
 
hf_uart_err_t ConvertPlatformError (int32_t platform_error) noexcept
 Convert platform error to HardFOC error.
 
hf_uart_err_t UpdateStatistics (hf_uart_err_t result, uint64_t start_time_us) noexcept
 Update statistics.
 
void UpdateDiagnostics (hf_uart_err_t error) noexcept
 Update diagnostics.
 
uint32_t GetTimeoutMs (uint32_t timeout_ms) const noexcept
 Get timeout value in milliseconds.
 
int InternalPrintf (const char *format, va_list args) noexcept
 Internal printf implementation.
 

Private Attributes

PlatformMutex mutex_
 Thread safety mutex.
 
hf_uart_config_t port_config_
 Port configuration.
 
std::atomic< bool > initialized_
 Initialization state (atomic for lazy init)
 
uart_port_t uart_port_
 Native UART port handle.
 
QueueHandle_t event_queue_
 ESP-IDF UART event queue handle.
 
hf_uart_operating_mode_t operating_mode_
 Current operating mode.
 
hf_uart_mode_t communication_mode_
 Current communication mode.
 
bool software_flow_enabled_
 Software flow control enabled.
 
bool wakeup_enabled_
 Wakeup enabled.
 
bool break_detected_
 Break condition detected.
 
bool tx_in_progress_
 Transmission in progress.
 
hf_uart_err_t last_error_
 Last error that occurred.
 
hf_uart_statistics_t statistics_
 UART statistics.
 
hf_uart_diagnostics_t diagnostics_
 UART diagnostics.
 
char printf_buffer_ [256]
 Printf buffer.
 

Additional Inherited Members

- Protected Member Functions inherited from BaseUart
 BaseUart (hf_port_num_t port) noexcept
 Protected constructor with port.
 
- Protected Attributes inherited from BaseUart
hf_port_num_t port_
 UART port number.
 
bool initialized_
 Initialization status.
 
hf_uart_statistics_t statistics_
 UART operation statistics.
 
hf_uart_diagnostics_t diagnostics_
 UART diagnostic information.
 

Detailed Description

ESP32 UART implementation class.

This class provides a complete implementation of the BaseUart interface for ESP32 variants. It supports both polling and interrupt-driven UART modes with comprehensive feature support. Each instance represents a single UART port on the ESP32.

Key Features:

  • Polling mode: Blocking read/write operations for simple applications
  • Interrupt mode: Non-blocking operations with event queue and callbacks
  • Hardware flow control: RTS/CTS support for reliable communication
  • Pattern detection: AT command and custom pattern detection
  • Wakeup support: UART wakeup from light sleep mode
  • RS485 support: Half-duplex and collision detection modes
  • IrDA support: Infrared communication mode
  • Thread safety: Proper mutex protection for multi-threaded access
  • Error handling: Comprehensive error reporting and recovery
  • Resource management: Automatic cleanup and proper resource lifecycle
  • Multi-variant support: Works across all ESP32 variants (C6, Classic, S2, S3, C3, C2, H2)

Usage Example (Single UART Port):

// For ESP32-C6 (3 ports)
EspUart uart0({.port_number = 0, .baud_rate = 115200, .tx_pin = 21, .rx_pin = 20});
// For ESP32-C3 (2 ports)
EspUart uart0({.port_number = 0, .baud_rate = 115200, .tx_pin = 21, .rx_pin = 20});
if (uart0.EnsureInitialized()) {
const char* message = "Hello World!";
if (uart0.Write(reinterpret_cast<const uint8_t*>(message), strlen(message)) ==
// Message sent successfully
}
}
ESP32 UART implementation class.
Definition EspUart.h:104

Usage Example (Interrupt mode with callbacks):

EspUart uart({.port_number = 0, .operating_mode =
hf_uart_operating_mode_t::HF_UART_MODE_INTERRUPT}); uart.SetEventCallback([](const
hf_uart_event_native_t* event, void* user_data) { if (event->type == UART_DATA) {
// Handle received data
}
return false; // Return true to yield to higher priority task
});
@ HF_UART_MODE_INTERRUPT
Interrupt mode.
bool EnsureInitialized() noexcept
Ensures that the UART is initialized (lazy initialization).
Definition BaseUart.h:208
Note
EspUart instances cannot be copied or moved due to hardware resource management.
If you need to transfer ownership, use std::unique_ptr<EspUart> or similar smart pointers.

Constructor & Destructor Documentation

◆ EspUart() [1/3]

EspUart::EspUart ( const hf_uart_config_t & config)
explicitnoexcept

Constructor for ESP32 UART controller.

Parameters
configUART port configuration
Note
Uses lazy initialization - no hardware action until first operation

◆ ~EspUart()

EspUart::~EspUart ( )
overridevirtualnoexcept

Destructor - ensures clean shutdown.

◆ EspUart() [2/3]

EspUart::EspUart ( const EspUart & )
delete

◆ EspUart() [3/3]

EspUart::EspUart ( EspUart && )
delete

Member Function Documentation

◆ BytesAvailable()

hf_u16_t EspUart::BytesAvailable ( )
overridevirtualnoexcept

Get the number of bytes available to read.

Returns
Number of bytes available in the receive buffer

Implements BaseUart.

◆ ConfigureInterrupts()

hf_uart_err_t EspUart::ConfigureInterrupts ( uint32_t intr_enable_mask,
uint8_t rxfifo_full_thresh = 100,
uint8_t rx_timeout_thresh = 10 )
noexcept

Configure UART interrupt settings.

Parameters
intr_enable_maskInterrupt enable mask (UART_INTR_RXFIFO_FULL | UART_INTR_RXFIFO_TOUT)
rxfifo_full_threshRX FIFO full threshold
rx_timeout_threshRX timeout threshold
Returns
hf_uart_err_t result code
Note
Use ESP-IDF constants: UART_INTR_RXFIFO_FULL, UART_INTR_RXFIFO_TOUT, etc.

◆ ConfigureIrDA()

hf_uart_err_t EspUart::ConfigureIrDA ( const hf_uart_irda_config_t & irda_config)
noexcept

Configure IrDA mode.

Parameters
irda_configIrDA configuration
Returns
hf_uart_err_t result code

◆ ConfigurePins()

hf_uart_err_t EspUart::ConfigurePins ( )
privatenoexcept

Configure UART pins.

Returns
UART_SUCCESS on success, error code on failure

◆ ConfigureRS485()

hf_uart_err_t EspUart::ConfigureRS485 ( const hf_uart_rs485_config_t & rs485_config)
noexcept

Configure RS485 mode.

Parameters
rs485_configRS485 configuration
Returns
hf_uart_err_t result code

◆ ConfigureSoftwareFlowControl()

hf_uart_err_t EspUart::ConfigureSoftwareFlowControl ( bool enable,
uint8_t xon_threshold = 20,
uint8_t xoff_threshold = 80 )
noexcept

Configure software flow control (XON/XOFF).

Parameters
enabletrue to enable, false to disable
xon_thresholdXON threshold (default: 20)
xoff_thresholdXOFF threshold (default: 80)
Returns
hf_uart_err_t result code

◆ ConfigureUart()

hf_uart_err_t EspUart::ConfigureUart ( )
privatenoexcept

Configure UART parameters.

Returns
UART_SUCCESS on success, error code on failure

◆ ConfigureWakeup()

hf_uart_err_t EspUart::ConfigureWakeup ( const hf_uart_wakeup_config_t & wakeup_config)
noexcept

Configure UART wakeup from light sleep.

Parameters
wakeup_configWakeup configuration
Returns
hf_uart_err_t result code

◆ ConvertPlatformError()

hf_uart_err_t EspUart::ConvertPlatformError ( int32_t platform_error)
privatenoexcept

Convert platform error to HardFOC error.

Parameters
platform_errorPlatform error code
Returns
HardFOC error code

◆ Deinitialize()

bool EspUart::Deinitialize ( )
overrideprivatevirtualnoexcept

Deinitialize the UART driver.

Returns
true if successful, false otherwise

Implements BaseUart.

◆ DisablePatternDetection()

hf_uart_err_t EspUart::DisablePatternDetection ( )
noexcept

Disable pattern detection.

Returns
hf_uart_err_t result code

◆ EnablePatternDetection()

hf_uart_err_t EspUart::EnablePatternDetection ( char pattern_chr,
uint8_t chr_num = 1,
int chr_tout = 9,
int post_idle = 0,
int pre_idle = 0 )
noexcept

Enable pattern detection for repeated byte sequences.

Parameters
pattern_chrByte to detect (e.g., '
', '+')
chr_numNumber of repeats to trigger detection (>=1)
chr_toutMax idle between pattern bytes (baud periods)
post_idleRequired idle after pattern (baud periods)
pre_idleRequired idle before pattern (baud periods)
Returns
hf_uart_err_t result code
Note
Uses uart_enable_pattern_det_baud_intr from ESP-IDF v5.5

◆ FlushRx()

hf_uart_err_t EspUart::FlushRx ( )
overridevirtualnoexcept

Flush the receive buffer.

Returns
hf_uart_err_t result code

Implements BaseUart.

◆ FlushTx()

hf_uart_err_t EspUart::FlushTx ( )
overridevirtualnoexcept

Flush the transmit buffer.

Returns
hf_uart_err_t result code

Implements BaseUart.

◆ GetCommunicationMode()

hf_uart_mode_t EspUart::GetCommunicationMode ( ) const
noexcept

Get current communication mode.

Returns
Current communication mode

◆ GetDiagnostics()

hf_uart_err_t EspUart::GetDiagnostics ( hf_uart_diagnostics_t & diagnostics) const
overridevirtualnoexcept

Get UART diagnostics.

Parameters
diagnosticsOutput diagnostics structure
Returns
hf_uart_err_t result code

Reimplemented from BaseUart.

◆ GetEventQueue()

QueueHandle_t EspUart::GetEventQueue ( ) const
noexcept

Get the ESP-IDF event queue handle for user task creation.

Returns
QueueHandle_t for ESP-IDF uart_event_t structures, or nullptr if not available
Note
User is responsible for creating FreeRTOS task to handle events
Only available when driver is installed with event queue

◆ GetLastError()

hf_uart_err_t EspUart::GetLastError ( ) const
noexcept

Get the last error that occurred.

Returns
Last error code

◆ GetOperatingMode()

hf_uart_operating_mode_t EspUart::GetOperatingMode ( ) const
noexcept

Get current operating mode.

Returns
Current operating mode

◆ GetPortConfig()

const hf_uart_config_t & EspUart::GetPortConfig ( ) const
noexcept

Get current UART configuration.

Returns
Current port configuration

◆ GetStatistics()

hf_uart_err_t EspUart::GetStatistics ( hf_uart_statistics_t & statistics) const
overridevirtualnoexcept

Get UART statistics.

Parameters
statisticsOutput statistics structure
Returns
hf_uart_err_t result code

Reimplemented from BaseUart.

◆ GetTimeoutMs()

hf_u32_t EspUart::GetTimeoutMs ( uint32_t timeout_ms) const
privatenoexcept

Get timeout value in milliseconds.

Parameters
timeout_msRequested timeout
Returns
Actual timeout value

◆ Initialize()

bool EspUart::Initialize ( )
overrideprivatevirtualnoexcept

Initialize the UART driver.

Returns
true if successful, false otherwise
Note
This is called automatically by EnsureInitialized() on first use

Implements BaseUart.

◆ InstallDriver()

hf_uart_err_t EspUart::InstallDriver ( )
privatenoexcept

Install UART driver.

Returns
UART_SUCCESS on success, error code on failure

◆ InternalPrintf()

int EspUart::InternalPrintf ( const char * format,
va_list args )
privatenoexcept

Internal printf implementation.

Parameters
formatFormat string
argsVariable arguments
Returns
Number of characters written

◆ IsBreakDetected()

bool EspUart::IsBreakDetected ( )
noexcept

Check if break condition was detected.

Returns
true if break detected, false otherwise

◆ IsEventQueueAvailable()

bool EspUart::IsEventQueueAvailable ( ) const
noexcept

Check if event queue is available.

Returns
true if event queue is available, false otherwise

◆ IsReceiving()

bool EspUart::IsReceiving ( ) const
noexcept

Check if reception is active.

Returns
true if receiving, false otherwise

◆ IsTransmitting()

bool EspUart::IsTransmitting ( ) const
noexcept

Check if transmission is in progress.

Returns
true if transmitting, false otherwise

◆ IsTxBusy()

bool EspUart::IsTxBusy ( )
noexcept

◆ IsWakeupEnabled()

bool EspUart::IsWakeupEnabled ( ) const
noexcept

Check if wakeup is enabled.

Returns
true if enabled, false otherwise

◆ operator=() [1/2]

EspUart & EspUart::operator= ( const EspUart & )
delete

◆ operator=() [2/2]

EspUart & EspUart::operator= ( EspUart && )
delete

◆ PeekPatternPosition()

int EspUart::PeekPatternPosition ( )
noexcept

Peek pattern position without consuming.

Returns
Pattern position index, or -1 if queue empty

◆ PlatformDeinitialize()

hf_uart_err_t EspUart::PlatformDeinitialize ( )
privatenoexcept

Platform-specific deinitialization.

Returns
UART_SUCCESS on success, error code on failure

◆ PlatformInitialize()

hf_uart_err_t EspUart::PlatformInitialize ( )
privatenoexcept

Platform-specific initialization.

Returns
UART_SUCCESS on success, error code on failure

◆ PopPatternPosition()

int EspUart::PopPatternPosition ( )
noexcept

Pop pattern position from queue (consumes entry).

Returns
Pattern position index, or -1 if queue empty/overflow
Note
Call immediately before uart_read_bytes() to maintain data integrity

◆ Printf()

int EspUart::Printf ( const char * format,
... )
virtualnoexcept

Print formatted string to UART.

Parameters
formatFormat string
...Variable arguments
Returns
Number of characters written

Implements BaseUart.

◆ Read()

hf_uart_err_t EspUart::Read ( uint8_t * data,
uint16_t length,
uint32_t timeout_ms = 0 )
overridevirtualnoexcept

Read data from the UART.

Parameters
dataBuffer to store received data
lengthNumber of bytes to read
timeout_msTimeout in milliseconds (0 = use default)
Returns
hf_uart_err_t result code

Implements BaseUart.

◆ ReadLine()

hf_u16_t EspUart::ReadLine ( char * buffer,
uint16_t max_length,
uint32_t timeout_ms )
noexcept

Read a line of text (until newline).

Parameters
bufferBuffer to store the line
max_lengthMaximum line length
timeout_msTimeout in milliseconds
Returns
Number of characters read (excluding newline)

◆ ReadUntil()

hf_u16_t EspUart::ReadUntil ( uint8_t * data,
uint16_t max_length,
uint8_t terminator,
uint32_t timeout_ms )
noexcept

Read data until a specific terminator is found.

Parameters
dataBuffer to store received data
max_lengthMaximum number of bytes to read
terminatorTerminator byte to search for
timeout_msTimeout in milliseconds
Returns
Number of bytes read (including terminator)

◆ ResetEventQueue()

hf_uart_err_t EspUart::ResetEventQueue ( )
noexcept

Reset event queue (clear all pending events).

Returns
hf_uart_err_t result code

◆ ResetPatternQueue()

hf_uart_err_t EspUart::ResetPatternQueue ( int queue_length = 32)
noexcept

Reset pattern detection queue.

Parameters
queue_lengthPattern position queue length
Returns
hf_uart_err_t result code

◆ SendBreak()

hf_uart_err_t EspUart::SendBreak ( uint32_t duration_ms)
noexcept

Send a break condition.

Parameters
duration_msBreak duration in milliseconds
Returns
hf_uart_err_t result code

◆ SetBaudRate()

bool EspUart::SetBaudRate ( uint32_t baud_rate)
noexcept

Set the baud rate.

Parameters
baud_rateNew baud rate
Returns
true if successful, false otherwise

◆ SetCommunicationMode()

hf_uart_err_t EspUart::SetCommunicationMode ( hf_uart_mode_t mode)
noexcept

Set UART communication mode (UART/RS485/IrDA).

Parameters
modeCommunication mode
Returns
hf_uart_err_t result code

◆ SetFlowControl()

hf_uart_err_t EspUart::SetFlowControl ( bool enable)
noexcept

Enable or disable hardware flow control.

Parameters
enabletrue to enable, false to disable
Returns
hf_uart_err_t result code

◆ SetLoopback()

hf_uart_err_t EspUart::SetLoopback ( bool enable)
noexcept

Enable or disable loopback mode.

Parameters
enabletrue to enable, false to disable
Returns
hf_uart_err_t result code

◆ SetOperatingMode()

hf_uart_err_t EspUart::SetOperatingMode ( hf_uart_operating_mode_t mode)
noexcept

Set UART operating mode.

Parameters
modeOperating mode (polling/interrupt/DMA)
Returns
hf_uart_err_t result code

◆ SetRTS()

hf_uart_err_t EspUart::SetRTS ( bool active)
noexcept

Set RTS line state.

Parameters
activetrue for active, false for inactive
Returns
hf_uart_err_t result code

◆ SetSignalInversion()

hf_uart_err_t EspUart::SetSignalInversion ( uint32_t inverse_mask)
noexcept

Set signal inversion mask.

Parameters
inverse_maskInversion mask (UART_SIGNAL_INV_DISABLE, UART_SIGNAL_INV_TXD, etc.)
Returns
hf_uart_err_t result code

◆ TxBytesWaiting()

hf_u16_t EspUart::TxBytesWaiting ( )
noexcept

Get number of bytes waiting in TX buffer.

Returns
Number of bytes waiting

◆ UninstallDriver()

hf_uart_err_t EspUart::UninstallDriver ( )
privatenoexcept

Uninstall UART driver.

Returns
UART_SUCCESS on success, error code on failure

◆ UpdateDiagnostics()

void EspUart::UpdateDiagnostics ( hf_uart_err_t error)
privatenoexcept

Update diagnostics.

Parameters
errorError that occurred

◆ UpdateStatistics()

hf_uart_err_t EspUart::UpdateStatistics ( hf_uart_err_t result,
uint64_t start_time_us )
privatenoexcept

Update statistics.

Parameters
resultOperation result
start_time_usOperation start time
Returns
Result for chaining

◆ ValidateConfiguration()

hf_uart_err_t EspUart::ValidateConfiguration ( ) const
privatenoexcept

Validate configuration.

Returns
UART_SUCCESS if valid, error code otherwise

◆ VPrintf()

int EspUart::VPrintf ( const char * format,
va_list args )
noexcept

Print formatted string to UART with va_list.

Parameters
formatFormat string
argsVariable arguments
Returns
Number of characters written

◆ WaitTransmitComplete()

bool EspUart::WaitTransmitComplete ( uint32_t timeout_ms)
noexcept

Wait for transmission to complete.

Parameters
timeout_msTimeout in milliseconds
Returns
true if successful, false on timeout

◆ Write()

hf_uart_err_t EspUart::Write ( const uint8_t * data,
uint16_t length,
uint32_t timeout_ms = 0 )
overridevirtualnoexcept

Write data to the UART.

Parameters
dataData buffer to transmit
lengthNumber of bytes to write
timeout_msTimeout in milliseconds (0 = use default)
Returns
hf_uart_err_t result code

Implements BaseUart.

◆ WriteByte()

bool EspUart::WriteByte ( uint8_t byte)
overridevirtualnoexcept

Write a single byte to the UART.

Parameters
byteByte to write
Returns
true if successful, false otherwise

Reimplemented from BaseUart.

Member Data Documentation

◆ break_detected_

bool EspUart::break_detected_
private

Break condition detected.

◆ communication_mode_

hf_uart_mode_t EspUart::communication_mode_
private

Current communication mode.

◆ DEFAULT_BAUD_RATE

constexpr hf_u32_t EspUart::DEFAULT_BAUD_RATE = 115200
staticconstexpr

Default baud rate.

◆ DEFAULT_BUFFER_SIZE

constexpr hf_u16_t EspUart::DEFAULT_BUFFER_SIZE = 256
staticconstexpr

Default buffer size.

◆ diagnostics_

hf_uart_diagnostics_t EspUart::diagnostics_
private

UART diagnostics.

◆ event_queue_

QueueHandle_t EspUart::event_queue_
private

ESP-IDF UART event queue handle.

◆ initialized_

std::atomic<bool> EspUart::initialized_
private

Initialization state (atomic for lazy init)

◆ last_error_

hf_uart_err_t EspUart::last_error_
private

Last error that occurred.

◆ MAX_BAUD_RATE

constexpr hf_u32_t EspUart::MAX_BAUD_RATE = 5000000
staticconstexpr

Maximum baud rate.

◆ MAX_BUFFER_SIZE

constexpr hf_u16_t EspUart::MAX_BUFFER_SIZE = 1024
staticconstexpr

Maximum buffer size.

◆ MAX_PORTS

constexpr hf_u8_t EspUart::MAX_PORTS = 3
staticconstexpr

Maximum UART ports.

◆ MIN_BAUD_RATE

constexpr hf_u32_t EspUart::MIN_BAUD_RATE = 110
staticconstexpr

Minimum baud rate.

◆ mutex_

PlatformMutex EspUart::mutex_
mutableprivate

Thread safety mutex.

◆ operating_mode_

hf_uart_operating_mode_t EspUart::operating_mode_
private

Current operating mode.

◆ port_config_

hf_uart_config_t EspUart::port_config_
private

Port configuration.

◆ printf_buffer_

char EspUart::printf_buffer_[256]
private

Printf buffer.

◆ software_flow_enabled_

bool EspUart::software_flow_enabled_
private

Software flow control enabled.

◆ statistics_

hf_uart_statistics_t EspUart::statistics_
private

UART statistics.

◆ tx_in_progress_

bool EspUart::tx_in_progress_
private

Transmission in progress.

◆ uart_port_

uart_port_t EspUart::uart_port_
private

Native UART port handle.

◆ wakeup_enabled_

bool EspUart::wakeup_enabled_
private

Wakeup enabled.


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