#include <libsimpleio/libi2c.h> void I2C_open(const char *name, int32_t *fd, int32_t *error); void I2C_close(int32_t fd, int32_t *error); void I2C_transaction(int32_t fd, int32_t slaveaddr, void *cmd, int32_t cmdlen, void *resp, int32_t resplen, int32_t *error);Link with -lsimpleio.
I2C_open() opens an I2C bus controller device. The device name, /dev/i2c-x, must be passed in the name parameter. Upon success, a file descriptor for the I2C bus controller device is returned in *fd.
I2C_close() closes a previously opened I2C bus controller device.
I2C_transaction() performs a single I2C bus transaction, with optional transmit and receive phases. The I2C slave device address must be passed in the slaveaddr parameter. Either the address of a command message and its length must be passed in the cmd and cmdlen parameters, or NULL and 0 for a receive only transaction. Either the address of a receive buffer and its size must be passed in the resp and resplen parameters, or NULL and 0 for a transmit only transaction.