I2C High-Level Helpers¶
Convenience functions for common I2C operations. More...
Functions¶
| Name | |
|---|---|
| int | CFBD_I2CRead(CFBD_I2CHandle * handle, CFBD_I2C_IORequestParams * r) High-level helper to read from an I2C device using IORequestParams. |
| int | CFBD_I2CWrite(CFBD_I2CHandle * handle, CFBD_I2C_IORequestParams * r) High-level helper to write to an I2C device using IORequestParams. |
Detailed Description¶
Convenience functions for common I2C operations.
Simplify typical read/write patterns with automatic message construction.
Functions Documentation¶
function CFBD_I2CRead¶
High-level helper to read from an I2C device using IORequestParams.
Parameters:
- handle Pointer to I2C bus handle
- r Pointer to IORequestParams describing the read operation
Return: int I2C_OK on success or negative error code.
Par: Example - EEPROM Read
uint8_t buffer[16];
CFBD_I2C_IORequestParams req = {
.addr7 = 0x50, // EEPROM address
.mem_addr = 0x200, // Byte offset in EEPROM
.mem_addr_size = 2, // 16-bit address
.data = buffer,
.len = 16,
.timeout_ms = 1000
};
if (CFBD_I2CRead(bus_handle, &req) == I2C_OK) {
// Process 16 bytes from EEPROM address 0x200
}
Automatically constructs a read transaction that:
- Writes the device memory/register address to the device
- Reads the requested data from that address
function CFBD_I2CWrite¶
High-level helper to write to an I2C device using IORequestParams.
Parameters:
- handle Pointer to I2C bus handle
- r Pointer to IORequestParams describing the write operation
Return: int I2C_OK on success or negative error code.
Par: Example - Configuration Write
uint8_t config_data[] = { 0xAA, 0xBB, 0xCC };
CFBD_I2C_IORequestParams req = {
.addr7 = 0x30,
.mem_addr = 0x10, // Register offset
.mem_addr_size = 1,
.data = config_data,
.len = sizeof(config_data),
.timeout_ms = 500
};
int status = CFBD_I2CWrite(bus_handle, &req);
Constructs a write transaction that sends both the device memory/register address and data in a single I2C transaction.
Updated on 2026-02-03 at 13:21:55 +0000