35template <
size_t RxBufSize = 0>
class Uart
42 explicit Uart(
const struct ove_uart_cfg &cfg)
43 requires(RxBufSize > 0)
45#ifdef CONFIG_OVE_ZERO_HEAP
46 static_assert(RxBufSize > 0,
"RxBufSize must be > 0 in zero-heap mode");
47 int err = ove_uart_init(&handle_, &storage_, rx_buf_, &cfg);
49 int err = ove_uart_create(&handle_, &cfg);
51 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
58#ifdef CONFIG_OVE_ZERO_HEAP
59 ove_uart_deinit(handle_);
61 ove_uart_destroy(handle_);
65 Uart(
const Uart &) =
delete;
66 Uart &operator=(
const Uart &) =
delete;
68#ifdef CONFIG_OVE_ZERO_HEAP
69 Uart(Uart &&) =
delete;
70 Uart &operator=(Uart &&) =
delete;
82 ove_uart_destroy(handle_);
96 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
98 size_t bytes_written = 0;
100 ove_uart_write(handle_, data, len,
to_timeout_ns(timeout), &bytes_written);
101 return from_rc(rc, bytes_written);
110 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
112 size_t bytes_read = 0;
114 ove_uart_read(handle_, buf, len,
to_timeout_ns(timeout), &bytes_read);
115 return from_rc(rc, bytes_read);
121 return ove_uart_bytes_available(handle_);
127 return from_rc(ove_uart_flush(handle_));
137 ove_uart_t handle_ =
nullptr;
138#ifdef CONFIG_OVE_ZERO_HEAP
139 ove_uart_storage_t storage_{};
140 uint8_t rx_buf_[RxBufSize > 0 ? RxBufSize : 1]{};
RAII wrapper around an oveRTOS UART peripheral.
Definition uart.hpp:36
ove_uart_t handle() const
Returns the underlying C handle.
Definition uart.hpp:131
Uart(Uart &&o) noexcept
Move constructor — transfers handle; source becomes empty.
Definition uart.hpp:73
Uart & operator=(Uart &&o) noexcept
Move-assignment — destroys current port, then takes o's handle.
Definition uart.hpp:78
Uart(const struct ove_uart_cfg &cfg)
Construct and initialise a UART port from cfg.
Definition uart.hpp:42
Result< size_t > read(void *buf, size_t len, std::chrono::nanoseconds timeout=wait_forever) noexcept
Read bytes from the RX buffer.
Definition uart.hpp:109
Result< void > flush() noexcept
Block until all pending TX bytes have been drained.
Definition uart.hpp:125
size_t bytes_available() const
Bytes currently available in the RX buffer.
Definition uart.hpp:119
Result< size_t > write(const void *data, size_t len, std::chrono::nanoseconds timeout=wait_forever) noexcept
Write bytes to the port.
Definition uart.hpp:95
Strong ove::Error type, Result<T> alias, and std::error_code interop for the oveRTOS C++ binding.
Top-level namespace for all oveRTOS C++ abstractions.
Definition app.hpp:20
constexpr uint64_t to_timeout_ns(std::chrono::duration< Rep, Period > d) noexcept
Convert a chrono duration to uint64_t nanoseconds for the C API.
Definition types.hpp:129
constexpr std::chrono::nanoseconds wait_forever
Sentinel duration meaning "block indefinitely".
Definition types.hpp:119
Result< void > from_rc(int rc) noexcept
Lifts a substrate rc-code into a Result<void>.
Definition error.hpp:254
std::expected< T, Error > Result
std::expected-based result alias.
Definition error.hpp:139
Common type definitions and concepts for the C++ wrapper layer.