|
HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
|
STM32 UART implementation. More...
#include <StmUart.h>
Public Member Functions | |
| StmUart (UART_HandleTypeDef *huart, hf_port_num_t port=0) noexcept | |
| Construct from HAL UART handle. | |
| StmUart (const hf_stm32_uart_config_t &config) noexcept | |
| Construct from config struct. | |
| ~StmUart () noexcept override | |
| StmUart (const StmUart &)=delete | |
| StmUart & | operator= (const StmUart &)=delete |
| bool | Initialize () noexcept override |
| Initialize the UART driver. | |
| bool | Deinitialize () noexcept override |
| Deinitialize the UART driver. | |
| hf_uart_err_t | Write (const hf_u8_t *data, hf_u16_t length, hf_u32_t timeout_ms=0) noexcept override |
| Write data to the UART. | |
| hf_uart_err_t | Read (hf_u8_t *data, hf_u16_t length, hf_u32_t timeout_ms=0) noexcept override |
| Read data from the UART. | |
| hf_u16_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. | |
| int | Printf (const char *format,...) noexcept override |
| Printf-style formatted output. | |
| UART_HandleTypeDef * | GetHalHandle () const noexcept |
| void | EnableRxBuffer (hf_u8_t *buffer, hf_u16_t size) noexcept |
| Enable a software RX ring buffer. | |
| void | FeedRxByte (hf_u8_t byte) noexcept |
| Feed a byte into the RX ring buffer (call from ISR). | |
| void | FeedRxBlock (const hf_u8_t *data, hf_u16_t length) noexcept |
| Feed a block of bytes into the RX ring buffer (call from ISR/DMA). | |
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 bool | WriteByte (hf_u8_t byte) noexcept |
| Write a single byte 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. | |
| virtual hf_uart_err_t | GetStatistics (hf_uart_statistics_t &statistics) const noexcept |
| Get UART operation statistics. | |
| virtual hf_uart_err_t | GetDiagnostics (hf_uart_diagnostics_t &diagnostics) const noexcept |
| Get UART diagnostic information. | |
Private Attributes | |
| UART_HandleTypeDef * | huart_ |
| hf_u32_t | default_timeout_ms_ |
| hf_u8_t * | rx_buf_ |
| hf_u16_t | rx_buf_size_ |
| volatile hf_u16_t | rx_head_ |
| Write index (ISR writes) | |
| volatile hf_u16_t | rx_tail_ |
| Read index (user reads) | |
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. | |
STM32 UART implementation.
Design:
|
explicitnoexcept |
Construct from HAL UART handle.
| huart | CubeMX UART handle. |
| port | Logical port number (for base class). |
|
explicitnoexcept |
Construct from config struct.
|
overridenoexcept |
|
delete |
|
overridevirtualnoexcept |
Get the number of bytes available to read.
Implements BaseUart.
|
overridevirtualnoexcept |
Enable a software RX ring buffer.
| buffer | User-provided buffer. |
| size | Buffer size in bytes. |
When enabled, Read() pulls from this ring buffer instead of calling HAL_UART_Receive directly. The user must still call FeedRxByte() from HAL_UART_RxCpltCallback or a DMA half-transfer ISR.
Feed a block of bytes into the RX ring buffer (call from ISR/DMA).
|
noexcept |
Feed a byte into the RX ring buffer (call from ISR).
|
overridevirtualnoexcept |
|
overridevirtualnoexcept |
|
inlinenoexcept |
|
overridevirtualnoexcept |
|
overridevirtualnoexcept |
Printf-style formatted output.
| format | Format string |
| ... | Format 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.
|
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.
|
private |
|
private |
|
private |
|
private |
|
private |
Write index (ISR writes)
|
private |
Read index (user reads)