oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
Functions
HAL I2C Interface

Hardware Abstraction Layer interface for I2C bus operations. More...

Functions

int ove_hal_i2c_open (ove_i2c_t i2c, const struct ove_i2c_cfg *cfg)
 Configure and enable the I2C peripheral.
 
void ove_hal_i2c_close (ove_i2c_t i2c)
 Disable and release the I2C peripheral.
 
int ove_hal_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_hal_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_hal_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 repeated start.
 
int ove_hal_i2c_write_read_async (ove_i2c_t i2c, uint16_t addr, const void *tx, size_t tx_len, void *rx, size_t rx_len)
 Submit an async I2C write+read.
 
void ove_i2c_async_complete (ove_i2c_t i2c, int result)
 Completion notification from the HAL.
 

Detailed Description

Hardware Abstraction Layer interface for I2C bus operations.

Declares the low-level I2C functions that every platform HAL must implement. The portable I2C layer delegates to these functions after performing parameter validation and bus locking.

Function Documentation

◆ ove_hal_i2c_open()

int ove_hal_i2c_open ( ove_i2c_t  i2c,
const struct ove_i2c_cfg cfg 
)

Configure and enable the I2C peripheral.

Called by ove_i2c_init() after validation. The HAL must map the instance index to the correct hardware peripheral, configure the clock speed, and enable the I2C controller.

Parameters
[in]i2cI2C handle with storage already assigned.
[in]cfgBus configuration descriptor.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_hal_i2c_close()

void ove_hal_i2c_close ( ove_i2c_t  i2c)

Disable and release the I2C peripheral.

Called by ove_i2c_deinit().

Parameters
[in]i2cI2C handle.

◆ ove_hal_i2c_write()

int ove_hal_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.

Called under the bus mutex.

Parameters
[in]i2cI2C handle.
[in]addr7-bit device address.
[in]dataData to transmit.
[in]lenNumber of bytes.
[in]timeout_nsMaximum wait time.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_hal_i2c_read()

int ove_hal_i2c_read ( ove_i2c_t  i2c,
uint16_t  addr,
void *  buf,
size_t  len,
uint64_t  timeout_ns 
)

Read data from an I2C device.

Called under the bus mutex.

Parameters
[in]i2cI2C handle.
[in]addr7-bit device address.
[out]bufBuffer to receive data.
[in]lenNumber of bytes.
[in]timeout_nsMaximum wait time.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_hal_i2c_write_read()

int ove_hal_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 repeated start.

Called under the bus mutex. All four backends support this atomically (STM32 HAL_I2C_Mem_Read, Zephyr i2c_write_read, NuttX I2C_TRANSFER, POSIX I2C_RDWR).

Parameters
[in]i2cI2C handle.
[in]addr7-bit device address.
[in]txTransmit buffer.
[in]tx_lenNumber of bytes to write.
[out]rxReceive buffer.
[in]rx_lenNumber of bytes to read.
[in]timeout_nsMaximum wait time.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_hal_i2c_write_read_async()

int ove_hal_i2c_write_read_async ( ove_i2c_t  i2c,
uint16_t  addr,
const void *  tx,
size_t  tx_len,
void *  rx,
size_t  rx_len 
)

Submit an async I2C write+read.

Optional HAL hook, gated by CONFIG_OVE_ASYNC. Backends must call ove_i2c_async_complete with the transaction result; the portable layer takes care of busy-flag clearing and user callback dispatch.

Parameters
[in]i2cI2C handle.
[in]addr7-bit device address.
[in]txTransmit buffer (may be NULL for pure read).
[in]tx_lenBytes to write.
[in]rxReceive buffer (may be NULL for pure write).
[in]rx_lenBytes to read.
Returns
OVE_OK if accepted, negative error code on submission failure (no completion in that case).

◆ ove_i2c_async_complete()

void ove_i2c_async_complete ( ove_i2c_t  i2c,
int  result 
)

Completion notification from the HAL.

Called by the HAL backend on transaction completion.

Parameters
[in]i2cI2C handle.
[in]resultOVE_OK on success, negative error code on failure.