pihwm
A lightweight C library for Raspberry Pi hardware modules.
 All Data Structures Files Functions Groups Pages
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)
 
int i2c_init_name (char *devname)
 Initialises the i2c-dev interface for the sysfs entry specified by the devname parameter.
 
int i2c_select_device (unsigned int fd, unsigned int addr)
 Selects a specific I2C slave device.
 
int i2c_write (unsigned int fd, unsigned int addr, unsigned char *data, unsigned int len)
 Initiates an I2C write operation.
 
int i2c_read (unsigned int fd, unsigned int addr, unsigned char *data, unsigned int len)
 Initiates an I2C read operation.
 

Detailed Description

I2C library functions.

Function Documentation

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 57 of file pi_i2c.c.

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 100 of file pi_i2c.c.

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 179 of file pi_i2c.c.

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 124 of file pi_i2c.c.

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 148 of file pi_i2c.c.