CFBD_I2COperations¶
Module: I2C Backend Implementation
Function table that a backend must implement to drive an I2C bus. More...
#include <iic.h>
Public Attributes¶
| Name | |
|---|---|
| int(*)(CFBD_I2CHandle *handle) | init Initialize the I2C hardware/peripheral. |
| int(*)(CFBD_I2CHandle *handle) | deinit Deinitialize the I2C hardware/peripheral. |
| int(*)(CFBD_I2CHandle *bus, CFBD_I2C_Message *msgs, int num, uint32_t timeout_ms) | transfer Perform a sequence of I2C messages. |
| int(*)(CFBD_I2CHandle *bus, uint16_t addr, uint32_t trials, uint32_t timeout_ms) | is_device_ready Check whether a device is ready (acknowledges) within trials. |
| int(*)(CFBD_I2CHandle *bus) | recover_bus Attempt to recover the I2C bus (clock recovery, toggling lines). |
| int(*)(CFBD_I2CHandle *bus) | get_error Retrieve the last backend-specific error code. |
| int(*)(CFBD_I2CHandle *bus, const uint8_t *buf, size_t len) | tx_dma_start Initiate DMA transmission (optional). |
| int(*)(CFBD_I2CHandle *bus, uint8_t *buf, size_t len) | rx_dma_start Initiate DMA reception (optional). |
Detailed Description¶
Function table that a backend must implement to drive an I2C bus.
Backends populate this table with pointers to concrete functions that implement initialization, transfers and optional DMA operations. This design enables pluggable I2C backends (STM32, ESP32, etc.) while maintaining a unified public interface.
Public Attributes Documentation¶
variable init¶
Initialize the I2C hardware/peripheral.
Return: I2C_OK on success, or negative error code on failure
Called once during system startup to configure clock, pins, and I2C peripheral registers.
variable deinit¶
Deinitialize the I2C hardware/peripheral.
Return: I2C_OK on success, or negative error code on failure
Clean shutdown: disables interrupts, releases DMA, powers down hardware.
variable transfer¶
Perform a sequence of I2C messages.
Parameters:
- bus I2C bus handle
- msgs Array of messages to transfer
- num Number of messages
- timeout_ms Operation timeout in milliseconds
Return: I2C_OK on success, or negative error code
Core transfer function. Must support multiple messages in a single transaction (write-read patterns, repeated START, etc.).
variable is_device_ready¶
Check whether a device is ready (acknowledges) within trials.
Parameters:
- bus I2C bus handle
- addr Device address (7-bit)
- trials Number of probe attempts
- timeout_ms Per-trial timeout
Return: I2C_OK if device acknowledged, negative error otherwise
Probes device presence by attempting multiple transactions. Useful for detecting device hotplug, power-on sequences, etc.
variable recover_bus¶
Attempt to recover the I2C bus (clock recovery, toggling lines).
Return: I2C_OK if recovered, negative error if recovery failed
Handles stuck bus scenarios by toggling SCL, sending dummy clocks, or performing platform-specific recovery procedures.
variable get_error¶
Retrieve the last backend-specific error code.
Return: Backend-specific error code
Returns additional error details beyond the standard error codes, such as hardware-specific status registers or state flags.
variable tx_dma_start¶
Initiate DMA transmission (optional).
Return: I2C_OK if DMA started, error code otherwise
Enables efficient bulk data transmission via DMA. Can return I2C_ERR_INVAL if DMA not supported.
variable rx_dma_start¶
Initiate DMA reception (optional).
Return: I2C_OK if DMA started, error code otherwise
Enables efficient bulk data reception via DMA.
Updated on 2026-02-03 at 13:21:55 +0000