33template <
size_t RxBufSize = 0>
36 explicit Uart(
const struct ove_uart_cfg &cfg)
requires (RxBufSize > 0) {
37#ifdef CONFIG_OVE_ZERO_HEAP
38 static_assert(RxBufSize > 0,
39 "RxBufSize must be > 0 in zero-heap mode");
40 int err = ove_uart_init(&handle_, &storage_,
43 int err = ove_uart_create(&handle_, &cfg);
45 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
50#ifdef CONFIG_OVE_ZERO_HEAP
51 ove_uart_deinit(handle_);
53 ove_uart_destroy(handle_);
57 Uart(
const Uart &) =
delete;
58 Uart &operator=(
const Uart &) =
delete;
60#ifdef CONFIG_OVE_ZERO_HEAP
61 Uart(Uart &&) =
delete;
62 Uart &operator=(Uart &&) =
delete;
64 Uart(Uart &&o) noexcept : handle_(o.handle_) { o.handle_ =
nullptr; }
65 Uart &operator=(Uart &&o)
noexcept {
67 if (handle_) ove_uart_destroy(handle_);
75 [[nodiscard]]
int write(
const void *data,
size_t len,
76 uint32_t timeout_ms = OVE_WAIT_FOREVER,
77 size_t *bytes_written =
nullptr) {
78 return ove_uart_write(handle_, data, len,
79 timeout_ms, bytes_written);
82 [[nodiscard]]
int read(
void *buf,
size_t len,
83 uint32_t timeout_ms = OVE_WAIT_FOREVER,
84 size_t *bytes_read =
nullptr) {
85 return ove_uart_read(handle_, buf, len,
86 timeout_ms, bytes_read);
89 size_t bytes_available()
const {
90 return ove_uart_bytes_available(handle_);
93 [[nodiscard]]
int flush() {
94 return ove_uart_flush(handle_);
97 ove_uart_t native_handle()
const {
return handle_; }
100 ove_uart_t handle_ =
nullptr;
101#ifdef CONFIG_OVE_ZERO_HEAP
102 ove_uart_storage_t storage_{};
103 uint8_t rx_buf_[RxBufSize > 0 ? RxBufSize : 1]{};
void write(const char *data, unsigned int len)
Writes a buffer of bytes to the console output.
Definition console.hpp:71
int read(const char *key, void *buf, size_t len, size_t *out)
Reads the value associated with a key from NVS.
Definition nvs.hpp:55
Top-level namespace for all oveRTOS C++ abstractions.
Definition app.hpp:19
Common type definitions and concepts for the C++ wrapper layer.