HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
StmUart.h
Go to the documentation of this file.
1
13#pragma once
14
15#include "BaseUart.h"
16#include "StmTypes.h"
17
18struct UART_HandleTypeDef; // Forward declaration
19
31class StmUart : public BaseUart {
32public:
33
39 explicit StmUart(UART_HandleTypeDef* huart,
40 hf_port_num_t port = 0) noexcept;
41
45 explicit StmUart(const hf_stm32_uart_config_t& config) noexcept;
46
47 ~StmUart() noexcept override;
48
49 // Non-copyable
50 StmUart(const StmUart&) = delete;
51 StmUart& operator=(const StmUart&) = delete;
52
53 // ── Pure-virtual overrides (BaseUart) ───────────────────────────────────
54 bool Initialize() noexcept override;
55 bool Deinitialize() noexcept override;
56 hf_uart_err_t Write(const hf_u8_t* data, hf_u16_t length,
57 hf_u32_t timeout_ms = 0) noexcept override;
58 hf_uart_err_t Read(hf_u8_t* data, hf_u16_t length,
59 hf_u32_t timeout_ms = 0) noexcept override;
60 hf_u16_t BytesAvailable() noexcept override;
61 hf_uart_err_t FlushTx() noexcept override;
62 hf_uart_err_t FlushRx() noexcept override;
63 int Printf(const char* format, ...) noexcept override;
64
65 // ── Accessors ───────────────────────────────────────────────────────────
66 UART_HandleTypeDef* GetHalHandle() const noexcept { return huart_; }
67
68 // ── Software RX ring buffer (optional — call EnableRxBuffer) ────────────
78 void EnableRxBuffer(hf_u8_t* buffer, hf_u16_t size) noexcept;
79
83 void FeedRxByte(hf_u8_t byte) noexcept;
84
88 void FeedRxBlock(const hf_u8_t* data, hf_u16_t length) noexcept;
89
90private:
91 UART_HandleTypeDef* huart_;
93
94 // Software RX ring buffer
97 volatile hf_u16_t rx_head_;
98 volatile hf_u16_t rx_tail_;
99};
Abstract base class for UART driver implementations in the HardFOC system.
hf_uart_err_t
Definition BaseUart.h:84
uint32_t hf_u32_t
Platform-agnostic 32-bit unsigned integer type.
Definition HardwareTypes.h:52
uint8_t hf_u8_t
Platform-agnostic 8-bit unsigned integer type.
Definition HardwareTypes.h:40
hf_u32_t hf_port_num_t
Platform-agnostic port/controller identifier type.
Definition HardwareTypes.h:120
uint16_t hf_u16_t
Platform-agnostic 16-bit unsigned integer type.
Definition HardwareTypes.h:46
STM32 platform-specific type definitions for hardware abstraction.
Abstract base class for UART driver implementations.
Definition BaseUart.h:191
STM32 UART implementation.
Definition StmUart.h:31
void EnableRxBuffer(hf_u8_t *buffer, hf_u16_t size) noexcept
Enable a software RX ring buffer.
Definition StmUart.cpp:194
hf_uart_err_t FlushTx() noexcept override
Flush the transmit buffer.
Definition StmUart.cpp:160
~StmUart() noexcept override
Definition StmUart.cpp:59
hf_uart_err_t FlushRx() noexcept override
Flush the receive buffer.
Definition StmUart.cpp:166
StmUart(const StmUart &)=delete
bool Initialize() noexcept override
Initialize the UART driver.
Definition StmUart.cpp:67
hf_u16_t BytesAvailable() noexcept override
Get the number of bytes available to read.
Definition StmUart.cpp:152
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.
Definition StmUart.cpp:92
hf_u8_t * rx_buf_
Definition StmUart.h:95
UART_HandleTypeDef * huart_
Definition StmUart.h:91
StmUart(UART_HandleTypeDef *huart, hf_port_num_t port=0) noexcept
Construct from HAL UART handle.
Definition StmUart.cpp:37
StmUart & operator=(const StmUart &)=delete
hf_u16_t rx_buf_size_
Definition StmUart.h:96
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).
Definition StmUart.cpp:213
volatile hf_u16_t rx_tail_
Read index (user reads)
Definition StmUart.h:98
UART_HandleTypeDef * GetHalHandle() const noexcept
Definition StmUart.h:66
volatile hf_u16_t rx_head_
Write index (ISR writes)
Definition StmUart.h:97
int Printf(const char *format,...) noexcept override
Printf-style formatted output.
Definition StmUart.cpp:173
hf_u32_t default_timeout_ms_
Definition StmUart.h:92
void FeedRxByte(hf_u8_t byte) noexcept
Feed a byte into the RX ring buffer (call from ISR).
Definition StmUart.cpp:201
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.
Definition StmUart.cpp:115
bool Deinitialize() noexcept override
Deinitialize the UART driver.
Definition StmUart.cpp:81
Platform-agnostic UART configuration for STM32.
Definition StmTypes.h:342