38 explicit Spi(
const struct ove_spi_cfg &cfg)
40#ifdef CONFIG_OVE_ZERO_HEAP
41 int err = ove_spi_init(&handle_, &storage_, &cfg);
43 int err = ove_spi_create(&handle_, &cfg);
45 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
52#ifdef CONFIG_OVE_ZERO_HEAP
53 ove_spi_deinit(handle_);
55 ove_spi_destroy(handle_);
59 Spi(
const Spi &) =
delete;
60 Spi &operator=(
const Spi &) =
delete;
62#ifdef CONFIG_OVE_ZERO_HEAP
64 Spi &operator=(Spi &&) =
delete;
67 Spi(
Spi &&o) noexcept : handle_(o.handle_)
76 ove_spi_destroy(handle_);
86 transfer(
const struct ove_spi_cs *cs,
const void *tx,
void *rx,
size_t len,
87 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
94 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
101 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
108 transfer_seq(
const struct ove_spi_cs *cs,
const struct ove_spi_xfer *xfers,
109 unsigned int num_xfers,
110 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
112 return from_rc(ove_spi_transfer_seq(handle_, cs, xfers, num_xfers,
123 ove_spi_t handle_ =
nullptr;
124#ifdef CONFIG_OVE_ZERO_HEAP
125 ove_spi_storage_t storage_{};
RAII wrapper around an oveRTOS SPI bus controller.
Definition spi.hpp:32
Spi & operator=(Spi &&o) noexcept
Move-assignment — destroys current bus, then takes o's handle.
Definition spi.hpp:72
Spi(Spi &&o) noexcept
Move constructor — transfers handle; source becomes empty.
Definition spi.hpp:67
Result< void > transfer_seq(const struct ove_spi_cs *cs, const struct ove_spi_xfer *xfers, unsigned int num_xfers, std::chrono::nanoseconds timeout=wait_forever) noexcept
Execute a sequence of transfers under a single CS assertion.
Definition spi.hpp:108
ove_spi_t handle() const
Returns the underlying C handle.
Definition spi.hpp:117
Result< void > read(const struct ove_spi_cs *cs, void *buf, size_t len, std::chrono::nanoseconds timeout=wait_forever) noexcept
Read-only transfer — transmit sends zeros.
Definition spi.hpp:100
Spi(const struct ove_spi_cfg &cfg)
Construct and initialise the SPI bus from cfg.
Definition spi.hpp:38
Result< void > transfer(const struct ove_spi_cs *cs, const void *tx, void *rx, size_t len, std::chrono::nanoseconds timeout=wait_forever) noexcept
Full-duplex transfer — sends tx and receives into rx.
Definition spi.hpp:86
Result< void > write(const struct ove_spi_cs *cs, const void *data, size_t len, std::chrono::nanoseconds timeout=wait_forever) noexcept
Write-only transfer — receive data is discarded.
Definition spi.hpp:93
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.