38 explicit I2c(
const struct ove_i2c_cfg &cfg)
40#ifdef CONFIG_OVE_ZERO_HEAP
41 int err = ove_i2c_init(&handle_, &storage_, &cfg);
43 int err = ove_i2c_create(&handle_, &cfg);
45 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
52#ifdef CONFIG_OVE_ZERO_HEAP
53 ove_i2c_deinit(handle_);
55 ove_i2c_destroy(handle_);
59 I2c(
const I2c &) =
delete;
60 I2c &operator=(
const I2c &) =
delete;
62#ifdef CONFIG_OVE_ZERO_HEAP
64 I2c &operator=(I2c &&) =
delete;
67 I2c(
I2c &&o) noexcept : handle_(o.handle_)
76 ove_i2c_destroy(handle_);
86 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
93 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
100 write_read(uint16_t addr,
const void *tx,
size_t tx_len,
void *rx,
size_t rx_len,
101 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
103 return from_rc(ove_i2c_write_read(handle_, addr, tx, tx_len, rx, rx_len,
109 reg_write(uint16_t addr, uint8_t reg,
const void *data,
size_t len,
110 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
113 ove_i2c_reg_write(handle_, addr, reg, data, len,
to_timeout_ns(timeout)));
118 reg_read(uint16_t addr, uint8_t reg,
void *buf,
size_t len,
119 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
122 ove_i2c_reg_read(handle_, addr, reg, buf, len,
to_timeout_ns(timeout)));
127 std::chrono::nanoseconds timeout =
wait_forever)
noexcept
139 ove_i2c_t handle_ =
nullptr;
140#ifdef CONFIG_OVE_ZERO_HEAP
141 ove_i2c_storage_t storage_{};
RAII wrapper around an oveRTOS I2C bus controller.
Definition i2c.hpp:32
Result< void > write_read(uint16_t addr, const void *tx, size_t tx_len, void *rx, size_t rx_len, std::chrono::nanoseconds timeout=wait_forever) noexcept
Combined write-then-read transaction with a repeated start.
Definition i2c.hpp:100
I2c & operator=(I2c &&o) noexcept
Move-assignment — destroys current bus, then takes o's handle.
Definition i2c.hpp:72
ove_i2c_t handle() const
Returns the underlying C handle.
Definition i2c.hpp:133
I2c(I2c &&o) noexcept
Move constructor — transfers handle; source becomes empty.
Definition i2c.hpp:67
Result< void > read(uint16_t addr, void *buf, size_t len, std::chrono::nanoseconds timeout=wait_forever) noexcept
Read len bytes from slave addr into buf.
Definition i2c.hpp:92
Result< void > reg_read(uint16_t addr, uint8_t reg, void *buf, size_t len, std::chrono::nanoseconds timeout=wait_forever) noexcept
Read len bytes from register reg on slave addr.
Definition i2c.hpp:118
I2c(const struct ove_i2c_cfg &cfg)
Construct and initialise the I2C bus from cfg.
Definition i2c.hpp:38
Result< void > reg_write(uint16_t addr, uint8_t reg, const void *data, size_t len, std::chrono::nanoseconds timeout=wait_forever) noexcept
Write len bytes to register reg on slave addr.
Definition i2c.hpp:109
Result< void > write(uint16_t addr, const void *data, size_t len, std::chrono::nanoseconds timeout=wait_forever) noexcept
Write len bytes to slave addr.
Definition i2c.hpp:85
Result< void > probe(uint16_t addr, std::chrono::nanoseconds timeout=wait_forever) noexcept
Probe slave addr — empty Result<void> if the device ACKs.
Definition i2c.hpp:126
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.