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, uint32_t timeout_ms)
 Write data to an I2C device.
 
int ove_hal_i2c_read (ove_i2c_t i2c, uint16_t addr, void *buf, size_t len, uint32_t timeout_ms)
 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, uint32_t timeout_ms)
 Combined write-then-read with repeated start.
 

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,
uint32_t  timeout_ms 
)

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_msMaximum 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,
uint32_t  timeout_ms 
)

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_msMaximum 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,
uint32_t  timeout_ms 
)

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_msMaximum wait time.
Returns
OVE_OK on success, negative error code on failure.