mraa  0.4.5
Low Level Skeleton Library for Communication on GNU/Linux platforms
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Functions | Typedefs
i2c.h File Reference
Include dependency graph for i2c.h:

API Description

This file defines the i2c/Iic interface for libmraa. A context represents a bus and that bus may contain multiple addresses or i2c slaves. It is considered best practice to make sure the address is correct before doing any calls on i2c, in case another application or even thread changed the addres on that bus. Multiple instances of the same bus can exist.

i2c = mraa_i2c_init(0);
mraa_i2c_address(i2c, HMC5883L_I2C_ADDR);
rx_tx_buf[0] = HMC5883L_CONF_REG_B;
rx_tx_buf[1] = GA_1_3_REG;
mraa_i2c_write(i2c, rx_tx_buf, 2);

Go to the source code of this file.

Functions

mraa_i2c_context mraa_i2c_init (int bus)
 
mraa_i2c_context mraa_i2c_init_raw (unsigned int bus)
 
mraa_result_t mraa_i2c_frequency (mraa_i2c_context dev, int hz)
 
int mraa_i2c_read (mraa_i2c_context dev, uint8_t *data, int length)
 
uint8_t mraa_i2c_read_byte (mraa_i2c_context dev)
 
mraa_result_t mraa_i2c_write (mraa_i2c_context dev, const uint8_t *data, int length)
 
mraa_result_t mraa_i2c_write_byte (mraa_i2c_context dev, const uint8_t data)
 
mraa_result_t mraa_i2c_address (mraa_i2c_context dev, int address)
 
mraa_result_t mraa_i2c_stop (mraa_i2c_context dev)
 

Typedefs

typedef struct _i2c * mraa_i2c_context
 

Function Documentation

mraa_i2c_context mraa_i2c_init ( int  bus)

Initialise i2c context, using board defintions

Parameters
busi2c bus to use
Returns
i2c context or NULL

Here is the caller graph for this function:

mraa_i2c_context mraa_i2c_init_raw ( unsigned int  bus)

Initialise i2c context, passing in spi bus to use.

Parameters
busThe i2c bus to use i.e. /dev/i2c-2 would be "2"
Returns
i2c context or NULL

Here is the caller graph for this function:

mraa_result_t mraa_i2c_frequency ( mraa_i2c_context  dev,
int  hz 
)

Sets the frequency of the i2c context

Parameters
devThe i2c context
hzThe bus frequency in hertz
Returns
Result of operation

Here is the caller graph for this function:

int mraa_i2c_read ( mraa_i2c_context  dev,
uint8_t *  data,
int  length 
)

Read from an i2c context

Parameters
devThe i2c context
datapointer to the byte array to read data in to
lengthmax number of bytes to read
Returns
length of the read in bytes or 0

Here is the caller graph for this function:

uint8_t mraa_i2c_read_byte ( mraa_i2c_context  dev)

Read a single byte from the i2c context

Parameters
devThe i2c context
Returns
The result of the read or -1 if failed

Here is the caller graph for this function:

mraa_result_t mraa_i2c_write ( mraa_i2c_context  dev,
const uint8_t *  data,
int  length 
)

Write to an i2c context

Parameters
devThe i2c context
datapointer to the byte array to be written
lengththe number of bytes to transmit
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_i2c_write_byte ( mraa_i2c_context  dev,
const uint8_t  data 
)

Write a single byte to an i2c context

Parameters
devThe i2c context
dataThe byte to write
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_i2c_address ( mraa_i2c_context  dev,
int  address 
)

Sets the i2c context address.

Parameters
devThe i2c context
addressThe address to set for the slave (ignoring the least signifcant bit). If set to 0, the slave will only respond to the general call address.
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_i2c_stop ( mraa_i2c_context  dev)

De-inits an mraa_i2c_context device

Parameters
devThe i2c context
Returns
Result of operation

Here is the caller graph for this function:

Typedef Documentation

typedef struct _i2c* mraa_i2c_context

Opaque pointer definition to the internal struct _i2c