|
HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
|
ESP32 UART implementation class. More...
#include <EspUart.h>
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 | |
| EspUart & | operator= (const EspUart &)=delete |
| EspUart (EspUart &&)=delete | |
| EspUart & | operator= (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_t & | GetPortConfig () 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 | |
| BaseUart & | operator= (const BaseUart &)=delete |
| BaseUart (BaseUart &&)=delete | |
| BaseUart & | operator= (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. | |
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:
Usage Example (Single UART Port):
Usage Example (Interrupt mode with callbacks):
|
explicitnoexcept |
Constructor for ESP32 UART controller.
| config | UART port configuration |
|
overridevirtualnoexcept |
Destructor - ensures clean shutdown.
|
delete |
|
delete |
|
overridevirtualnoexcept |
Get the number of bytes available to read.
Implements BaseUart.
|
noexcept |
Configure UART interrupt settings.
| intr_enable_mask | Interrupt enable mask (UART_INTR_RXFIFO_FULL | UART_INTR_RXFIFO_TOUT) |
| rxfifo_full_thresh | RX FIFO full threshold |
| rx_timeout_thresh | RX timeout threshold |
|
noexcept |
Configure IrDA mode.
| irda_config | IrDA configuration |
|
privatenoexcept |
Configure UART pins.
|
noexcept |
Configure RS485 mode.
| rs485_config | RS485 configuration |
|
noexcept |
Configure software flow control (XON/XOFF).
| enable | true to enable, false to disable |
| xon_threshold | XON threshold (default: 20) |
| xoff_threshold | XOFF threshold (default: 80) |
|
privatenoexcept |
Configure UART parameters.
|
noexcept |
Configure UART wakeup from light sleep.
| wakeup_config | Wakeup configuration |
|
privatenoexcept |
Convert platform error to HardFOC error.
| platform_error | Platform error code |
|
overrideprivatevirtualnoexcept |
|
noexcept |
Disable pattern detection.
|
noexcept |
Enable pattern detection for repeated byte sequences.
| pattern_chr | Byte to detect (e.g., ' ', '+') |
| chr_num | Number of repeats to trigger detection (>=1) |
| chr_tout | Max idle between pattern bytes (baud periods) |
| post_idle | Required idle after pattern (baud periods) |
| pre_idle | Required idle before pattern (baud periods) |
|
overridevirtualnoexcept |
|
overridevirtualnoexcept |
|
noexcept |
Get current communication mode.
|
overridevirtualnoexcept |
Get UART diagnostics.
| diagnostics | Output diagnostics structure |
Reimplemented from BaseUart.
|
noexcept |
Get the ESP-IDF event queue handle for user task creation.
|
noexcept |
Get the last error that occurred.
|
noexcept |
Get current operating mode.
|
noexcept |
Get current UART configuration.
|
overridevirtualnoexcept |
Get UART statistics.
| statistics | Output statistics structure |
Reimplemented from BaseUart.
|
privatenoexcept |
Get timeout value in milliseconds.
| timeout_ms | Requested timeout |
|
overrideprivatevirtualnoexcept |
Initialize the UART driver.
Implements BaseUart.
|
privatenoexcept |
Install UART driver.
|
privatenoexcept |
Internal printf implementation.
| format | Format string |
| args | Variable arguments |
|
noexcept |
Check if break condition was detected.
|
noexcept |
Check if event queue is available.
|
noexcept |
Check if reception is active.
|
noexcept |
Check if transmission is in progress.
|
noexcept |
|
noexcept |
Check if wakeup is enabled.
|
noexcept |
Peek pattern position without consuming.
|
privatenoexcept |
Platform-specific deinitialization.
|
privatenoexcept |
Platform-specific initialization.
|
noexcept |
Pop pattern position from queue (consumes entry).
|
virtualnoexcept |
Print formatted string to UART.
| format | Format string |
| ... | Variable arguments |
Implements BaseUart.
|
overridevirtualnoexcept |
Read data from the UART.
| data | Buffer to store received data |
| length | Number of bytes to read |
| timeout_ms | Timeout in milliseconds (0 = use default) |
Implements BaseUart.
|
noexcept |
Read a line of text (until newline).
| buffer | Buffer to store the line |
| max_length | Maximum line length |
| timeout_ms | Timeout in milliseconds |
|
noexcept |
Read data until a specific terminator is found.
| data | Buffer to store received data |
| max_length | Maximum number of bytes to read |
| terminator | Terminator byte to search for |
| timeout_ms | Timeout in milliseconds |
|
noexcept |
Reset event queue (clear all pending events).
|
noexcept |
Reset pattern detection queue.
| queue_length | Pattern position queue length |
|
noexcept |
Send a break condition.
| duration_ms | Break duration in milliseconds |
|
noexcept |
Set the baud rate.
| baud_rate | New baud rate |
|
noexcept |
Set UART communication mode (UART/RS485/IrDA).
| mode | Communication mode |
|
noexcept |
Enable or disable hardware flow control.
| enable | true to enable, false to disable |
|
noexcept |
Enable or disable loopback mode.
| enable | true to enable, false to disable |
|
noexcept |
Set UART operating mode.
| mode | Operating mode (polling/interrupt/DMA) |
|
noexcept |
Set RTS line state.
| active | true for active, false for inactive |
|
noexcept |
Set signal inversion mask.
| inverse_mask | Inversion mask (UART_SIGNAL_INV_DISABLE, UART_SIGNAL_INV_TXD, etc.) |
|
noexcept |
Get number of bytes waiting in TX buffer.
|
privatenoexcept |
Uninstall UART driver.
|
privatenoexcept |
Update diagnostics.
| error | Error that occurred |
|
privatenoexcept |
Update statistics.
| result | Operation result |
| start_time_us | Operation start time |
|
privatenoexcept |
Validate configuration.
|
noexcept |
Print formatted string to UART with va_list.
| format | Format string |
| args | Variable arguments |
|
noexcept |
Wait for transmission to complete.
| timeout_ms | Timeout in milliseconds |
|
overridevirtualnoexcept |
Write data to the UART.
| data | Data buffer to transmit |
| length | Number of bytes to write |
| timeout_ms | Timeout in milliseconds (0 = use default) |
Implements BaseUart.
|
overridevirtualnoexcept |
Write a single byte to the UART.
| byte | Byte to write |
Reimplemented from BaseUart.
|
private |
Break condition detected.
|
private |
Current communication mode.
|
staticconstexpr |
Default baud rate.
|
staticconstexpr |
Default buffer size.
|
private |
UART diagnostics.
|
private |
ESP-IDF UART event queue handle.
|
private |
Initialization state (atomic for lazy init)
|
private |
Last error that occurred.
|
staticconstexpr |
Maximum baud rate.
|
staticconstexpr |
Maximum buffer size.
|
staticconstexpr |
Maximum UART ports.
|
staticconstexpr |
Minimum baud rate.
|
mutableprivate |
Thread safety mutex.
|
private |
Current operating mode.
|
private |
Port configuration.
|
private |
Printf buffer.
|
private |
Software flow control enabled.
|
private |
UART statistics.
|
private |
Transmission in progress.
|
private |
Native UART port handle.
|
private |
Wakeup enabled.