I2C bus master driver.
More...
|
| int | ove_i2c_init (ove_i2c_t *i2c, ove_i2c_storage_t *storage, const struct ove_i2c_cfg *cfg) |
| | Initialise an I2C bus using caller-provided static storage.
|
| |
| void | ove_i2c_deinit (ove_i2c_t i2c) |
| | Deinitialise a statically-allocated I2C bus.
|
| |
| int | ove_i2c_create (ove_i2c_t *i2c, const struct ove_i2c_cfg *cfg) |
| | Create a heap-allocated I2C bus controller.
|
| |
| void | ove_i2c_destroy (ove_i2c_t i2c) |
| | Destroy a heap-allocated I2C bus controller.
|
| |
| int | ove_i2c_write (ove_i2c_t i2c, uint16_t addr, const void *data, size_t len, uint64_t timeout_ns) |
| | Write data to an I2C device.
|
| |
| int | ove_i2c_read (ove_i2c_t i2c, uint16_t addr, void *buf, size_t len, uint64_t timeout_ns) |
| | Read data from an I2C device.
|
| |
| int | ove_i2c_write_read (ove_i2c_t i2c, uint16_t addr, const void *tx, size_t tx_len, void *rx, size_t rx_len, uint64_t timeout_ns) |
| | Combined write-then-read with I2C repeated start.
|
| |
| int | ove_i2c_reg_write (ove_i2c_t i2c, uint16_t addr, uint8_t reg, const void *data, size_t len, uint64_t timeout_ns) |
| | Write to a single-byte-addressed register.
|
| |
| int | ove_i2c_reg_read (ove_i2c_t i2c, uint16_t addr, uint8_t reg, void *buf, size_t len, uint64_t timeout_ns) |
| | Read from a single-byte-addressed register.
|
| |
| int | ove_i2c_probe (ove_i2c_t i2c, uint16_t addr, uint64_t timeout_ns) |
| | Probe for a device at the given address.
|
| |
| int | ove_i2c_write_read_async (ove_i2c_t i2c, uint16_t addr, const void *tx, size_t tx_len, void *rx, size_t rx_len, ove_dma_complete_cb cb, void *user_data) |
| | Submit an I2C write-then-read transaction asynchronously.
|
| |
I2C bus master driver.
Provides a portable I2C master API with configurable bus speed, thread-safe bus locking, register-level convenience functions, and device probing.
Two allocation strategies are supported:
_create() / _destroy() — heap-allocated. Available only when OVE_HEAP_I2C is defined (i.e. CONFIG_OVE_ZERO_HEAP is not set).
_init() / _deinit() — caller-supplied storage. Available in both modes. See OVE_I2C_DEFINE_STATIC for a one-step static helper.
All addresses are 7-bit (e.g. 0x50 for a typical EEPROM). The HAL shifts left and adds the R/W bit internally.
- Note
- Requires
CONFIG_OVE_I2C. When the option is disabled every function is replaced by a no-op stub that returns OVE_ERR_NOT_SUPPORTED.
◆ OVE_I2C_REG_WRITE_MAX
| #define OVE_I2C_REG_WRITE_MAX 32 |
◆ ove_i2c_speed_t
I2C bus speed grade.
| Enumerator |
|---|
| OVE_I2C_SPEED_STANDARD | 100 kHz.
|
| OVE_I2C_SPEED_FAST | 400 kHz.
|
| OVE_I2C_SPEED_FAST_PLUS | 1 MHz.
|
◆ ove_i2c_init()
Initialise an I2C bus using caller-provided static storage.
- Parameters
-
| [out] | i2c | Receives the initialised I2C handle. |
| [in] | storage | Pointer to statically-allocated I2C storage. |
| [in] | cfg | Bus configuration descriptor. |
- Returns
- OVE_OK on success, negative error code on failure.
◆ ove_i2c_deinit()
Deinitialise a statically-allocated I2C bus.
- Parameters
-
◆ ove_i2c_create()
Create a heap-allocated I2C bus controller.
- Parameters
-
| [out] | i2c | Receives the created I2C handle. |
| [in] | cfg | Bus configuration descriptor. |
- Returns
- OVE_OK on success, negative error code on failure.
◆ ove_i2c_destroy()
Destroy a heap-allocated I2C bus controller.
- Parameters
-
◆ ove_i2c_write()
| int ove_i2c_write |
( |
ove_i2c_t |
i2c, |
|
|
uint16_t |
addr, |
|
|
const void * |
data, |
|
|
size_t |
len, |
|
|
uint64_t |
timeout_ns |
|
) |
| |
Write data to an I2C device.
- Parameters
-
| [in] | i2c | I2C handle. |
| [in] | addr | 7-bit device address. |
| [in] | data | Data to write. |
| [in] | len | Number of bytes to write. |
| [in] | timeout_ns | Maximum wait time; OVE_WAIT_FOREVER to block. |
- Returns
- OVE_OK on success, negative error code on failure.
◆ ove_i2c_read()
| int ove_i2c_read |
( |
ove_i2c_t |
i2c, |
|
|
uint16_t |
addr, |
|
|
void * |
buf, |
|
|
size_t |
len, |
|
|
uint64_t |
timeout_ns |
|
) |
| |
Read data from an I2C device.
- Parameters
-
| [in] | i2c | I2C handle. |
| [in] | addr | 7-bit device address. |
| [out] | buf | Buffer to receive data. |
| [in] | len | Number of bytes to read. |
| [in] | timeout_ns | Maximum wait time; OVE_WAIT_FOREVER to block. |
- Returns
- OVE_OK on success, negative error code on failure.
◆ ove_i2c_write_read()
| int ove_i2c_write_read |
( |
ove_i2c_t |
i2c, |
|
|
uint16_t |
addr, |
|
|
const void * |
tx, |
|
|
size_t |
tx_len, |
|
|
void * |
rx, |
|
|
size_t |
rx_len, |
|
|
uint64_t |
timeout_ns |
|
) |
| |
Combined write-then-read with I2C repeated start.
Writes tx_len bytes from tx, then reads rx_len bytes into rx without releasing the bus (repeated start condition). This is the standard pattern for register reads on I2C sensors and codecs.
- Parameters
-
| [in] | i2c | I2C handle. |
| [in] | addr | 7-bit device address. |
| [in] | tx | Transmit buffer (e.g. register address). |
| [in] | tx_len | Number of bytes to write. |
| [out] | rx | Receive buffer. |
| [in] | rx_len | Number of bytes to read. |
| [in] | timeout_ns | Maximum wait time; OVE_WAIT_FOREVER to block. |
- Returns
- OVE_OK on success, negative error code on failure.
◆ ove_i2c_reg_write()
| int ove_i2c_reg_write |
( |
ove_i2c_t |
i2c, |
|
|
uint16_t |
addr, |
|
|
uint8_t |
reg, |
|
|
const void * |
data, |
|
|
size_t |
len, |
|
|
uint64_t |
timeout_ns |
|
) |
| |
Write to a single-byte-addressed register.
Prepends reg to data and performs a single I2C write. Implemented in the portable layer — not a HAL function.
- Note
len must not exceed OVE_I2C_REG_WRITE_MAX (32 bytes).
- Parameters
-
| [in] | i2c | I2C handle. |
| [in] | addr | 7-bit device address. |
| [in] | reg | Register address byte. |
| [in] | data | Data to write after the register byte. |
| [in] | len | Number of data bytes (max OVE_I2C_REG_WRITE_MAX). |
| [in] | timeout_ns | Maximum wait time. |
- Returns
- OVE_OK on success, negative error code on failure.
◆ ove_i2c_reg_read()
| int ove_i2c_reg_read |
( |
ove_i2c_t |
i2c, |
|
|
uint16_t |
addr, |
|
|
uint8_t |
reg, |
|
|
void * |
buf, |
|
|
size_t |
len, |
|
|
uint64_t |
timeout_ns |
|
) |
| |
Read from a single-byte-addressed register.
Writes reg, then reads len bytes via repeated start. Implemented in the portable layer — not a HAL function.
- Parameters
-
| [in] | i2c | I2C handle. |
| [in] | addr | 7-bit device address. |
| [in] | reg | Register address byte. |
| [out] | buf | Buffer to receive register data. |
| [in] | len | Number of bytes to read. |
| [in] | timeout_ns | Maximum wait time. |
- Returns
- OVE_OK on success, negative error code on failure.
◆ ove_i2c_probe()
| int ove_i2c_probe |
( |
ove_i2c_t |
i2c, |
|
|
uint16_t |
addr, |
|
|
uint64_t |
timeout_ns |
|
) |
| |
Probe for a device at the given address.
Sends a zero-length write and checks for ACK. Useful for device enumeration and presence detection.
- Parameters
-
| [in] | i2c | I2C handle. |
| [in] | addr | 7-bit device address to probe. |
| [in] | timeout_ns | Maximum wait time. |
- Returns
- OVE_OK if the device ACKs, OVE_ERR_BUS_NACK if not, other negative error code on bus failure.
◆ ove_i2c_write_read_async()
| int ove_i2c_write_read_async |
( |
ove_i2c_t |
i2c, |
|
|
uint16_t |
addr, |
|
|
const void * |
tx, |
|
|
size_t |
tx_len, |
|
|
void * |
rx, |
|
|
size_t |
rx_len, |
|
|
ove_dma_complete_cb |
cb, |
|
|
void * |
user_data |
|
) |
| |
Submit an I2C write-then-read transaction asynchronously.
Equivalent to ove_i2c_write_read but returns immediately. The completion callback fires when the device has been written, the repeated-start completed, and the read finished — or when an error (NACK, bus error, timeout) terminates the transaction.
Same backend completion-context contract as ove_spi_transfer_async (ISR on STM32 + FreeRTOS DMA, thread on Zephyr signal / NuttX-POSIX worker fallback).
- Parameters
-
| [in] | i2c | I2C handle. |
| [in] | addr | 7-bit device address. |
| [in] | tx | Bytes to write before the repeated start. Must outlive the transaction. May be NULL if tx_len is 0 (pure read). |
| [in] | tx_len | Number of bytes to write. |
| [in] | rx | Buffer for read bytes. Must outlive the transaction. May be NULL if rx_len is 0 (pure write). |
| [in] | rx_len | Number of bytes to read. |
| [in] | cb | Completion callback. Must not be NULL. |
| [in] | user_data | Opaque pointer forwarded to cb. |
- Returns
- OVE_OK if accepted; negative on submission failure (no callback in that case).