|
| | 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 |
| |
| 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.
|
| |
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):
EspUart uart0({.port_number = 0, .baud_rate = 115200, .tx_pin = 21, .rx_pin = 20});
EspUart uart0({.port_number = 0, .baud_rate = 115200, .tx_pin = 21, .rx_pin = 20});
if (
uart0.EnsureInitialized()) {
const char* message = "Hello World!";
}
}
ESP32 UART implementation class.
Definition EspUart.h:104
RAII soft-CS: runs assert_fn on construction and deassert_fn on destruction (including early return /...
Definition SoftChipSelectGuard.h:32
Usage Example (Interrupt mode with callbacks):
EspUart uart({.port_number = 0, .operating_mode =
}
return false;
});
@ 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.