pihwm  r1
A lightweight C library for Raspberry Pi hardware modules.
I2C

I2C library functions. More...

Functions

int i2c_init ()
 Initialises the i2c-dev interface for the I2C peripheral exposed on the P1 header (which is dependent on the board revision) More...
 
int i2c_init_name (char *devname)
 Initialises the i2c-dev interface for the sysfs entry specified by the devname parameter. More...
 
int i2c_select_device (unsigned int fd, unsigned int addr)
 Selects a specific I2C slave device. More...
 
int i2c_write (unsigned int fd, unsigned int addr, unsigned char *data, unsigned int len)
 Initiates an I2C write operation. More...
 
int i2c_read (unsigned int fd, unsigned int addr, unsigned char *data, unsigned int len)
 Initiates an I2C read operation. More...
 

Detailed Description

I2C library functions.

Function Documentation

◆ i2c_init()

int i2c_init ( )

Initialises the i2c-dev interface for the I2C peripheral exposed on the P1 header (which is dependent on the board revision)

Returns
The file descriptor for the relevant i2c-dev interface, -1 for failure

Definition at line 54 of file pi_i2c.c.

◆ i2c_init_name()

int i2c_init_name ( char *  devname)

Initialises the i2c-dev interface for the sysfs entry specified by the devname parameter.

Parameters
devnameThe sysfs entry for a particular I2C peripheral
Returns
The file descriptor for the relevant i2c-dev interface, -1 for failure

Definition at line 97 of file pi_i2c.c.

◆ i2c_read()

int i2c_read ( unsigned int  fd,
unsigned int  addr,
unsigned char *  data,
unsigned int  len 
)

Initiates an I2C read operation.

Parameters
fdFile descriptor for the i2c-dev interface
addrI2C slave device address
dataPointer to the read buffer
lenLength of data
Returns
1 for success, -1 for failure

Definition at line 176 of file pi_i2c.c.

◆ i2c_select_device()

int i2c_select_device ( unsigned int  fd,
unsigned int  addr 
)

Selects a specific I2C slave device.

Parameters
fdFile descriptor for the i2c-dev interface
addrI2C slave device address
Returns
1 for success, -1 for failure

Definition at line 121 of file pi_i2c.c.

◆ i2c_write()

int i2c_write ( unsigned int  fd,
unsigned int  addr,
unsigned char *  data,
unsigned int  len 
)

Initiates an I2C write operation.

Parameters
fdFile descriptor for the i2c-dev interface
addrI2C slave device address
dataData to write to the device
lenLength of data
Returns
1 for success, -1 for failure

Definition at line 145 of file pi_i2c.c.