31 explicit I2c(
const struct ove_i2c_cfg &cfg) {
32#ifdef CONFIG_OVE_ZERO_HEAP
33 int err = ove_i2c_init(&handle_, &storage_, &cfg);
35 int err = ove_i2c_create(&handle_, &cfg);
37 OVE_STATIC_INIT_ASSERT(err == OVE_OK);
42#ifdef CONFIG_OVE_ZERO_HEAP
43 ove_i2c_deinit(handle_);
45 ove_i2c_destroy(handle_);
49 I2c(
const I2c &) =
delete;
50 I2c &operator=(
const I2c &) =
delete;
52#ifdef CONFIG_OVE_ZERO_HEAP
54 I2c &operator=(I2c &&) =
delete;
56 I2c(I2c &&o) noexcept : handle_(o.handle_) { o.handle_ =
nullptr; }
57 I2c &operator=(I2c &&o)
noexcept {
59 if (handle_) ove_i2c_destroy(handle_);
67 [[nodiscard]]
int write(uint16_t addr,
const void *data,
size_t len,
68 uint32_t timeout_ms = OVE_WAIT_FOREVER) {
69 return ove_i2c_write(handle_, addr, data, len, timeout_ms);
72 [[nodiscard]]
int read(uint16_t addr,
void *buf,
size_t len,
73 uint32_t timeout_ms = OVE_WAIT_FOREVER) {
74 return ove_i2c_read(handle_, addr, buf, len, timeout_ms);
77 [[nodiscard]]
int write_read(uint16_t addr,
78 const void *tx,
size_t tx_len,
79 void *rx,
size_t rx_len,
80 uint32_t timeout_ms = OVE_WAIT_FOREVER) {
81 return ove_i2c_write_read(handle_, addr,
82 tx, tx_len, rx, rx_len, timeout_ms);
85 [[nodiscard]]
int reg_write(uint16_t addr, uint8_t reg,
86 const void *data,
size_t len,
87 uint32_t timeout_ms = OVE_WAIT_FOREVER) {
88 return ove_i2c_reg_write(handle_, addr, reg, data, len,
92 [[nodiscard]]
int reg_read(uint16_t addr, uint8_t reg,
93 void *buf,
size_t len,
94 uint32_t timeout_ms = OVE_WAIT_FOREVER) {
95 return ove_i2c_reg_read(handle_, addr, reg, buf, len,
99 [[nodiscard]]
int probe(uint16_t addr,
100 uint32_t timeout_ms = OVE_WAIT_FOREVER) {
101 return ove_i2c_probe(handle_, addr, timeout_ms);
104 ove_i2c_t native_handle()
const {
return handle_; }
107 ove_i2c_t handle_ =
nullptr;
108#ifdef CONFIG_OVE_ZERO_HEAP
109 ove_i2c_storage_t storage_{};
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.