mraa  2.0.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
Functions | Typedefs
i2c.h File Reference

API Description

An i2c context represents a master on an i2c bus and that context can communicate to multiple i2c slaves by configuring the address. 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.

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, mraa_i2c_mode_t mode)
 
int mraa_i2c_read (mraa_i2c_context dev, uint8_t *data, int length)
 
int mraa_i2c_read_byte (mraa_i2c_context dev)
 
int mraa_i2c_read_byte_data (mraa_i2c_context dev, const uint8_t command)
 
int mraa_i2c_read_word_data (mraa_i2c_context dev, const uint8_t command)
 
int mraa_i2c_read_bytes_data (mraa_i2c_context dev, uint8_t command, uint8_t *data, int length)
 
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_write_byte_data (mraa_i2c_context dev, const uint8_t data, const uint8_t command)
 
mraa_result_t mraa_i2c_write_word_data (mraa_i2c_context dev, const uint16_t data, const uint8_t command)
 
mraa_result_t mraa_i2c_address (mraa_i2c_context dev, uint8_t address)
 
mraa_result_t mraa_i2c_stop (mraa_i2c_context dev)
 

Typedefs

typedef struct _i2c * mraa_i2c_context
 

Function Documentation

mraa_result_t mraa_i2c_address ( mraa_i2c_context  dev,
uint8_t  address 
)

Sets the i2c slave address.

Parameters
devThe i2c context
addressThe address to set for the slave (7-bit address)
Returns
Result of operation
mraa_result_t mraa_i2c_frequency ( mraa_i2c_context  dev,
mraa_i2c_mode_t  mode 
)

Sets the frequency of the i2c context. Most platforms do not support this.

Parameters
devThe i2c context
modeThe bus mode
Returns
Result of operation
mraa_i2c_context mraa_i2c_init ( int  bus)

Initialise i2c context, using board defintions

Parameters
busi2c bus to use
Returns
i2c context or NULL
mraa_i2c_context mraa_i2c_init_raw ( unsigned int  bus)

Initialise i2c context, passing in the i2c bus to use.

Parameters
busThe i2c bus to use i.e. /dev/i2c-2 would be "2"
Returns
i2c context or NULL
int mraa_i2c_read ( mraa_i2c_context  dev,
uint8_t *  data,
int  length 
)

Simple bulk 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 -1
int mraa_i2c_read_byte ( mraa_i2c_context  dev)

Simple read for a single byte from the i2c context

Parameters
devThe i2c context
Returns
The result of the read or -1 if failed
int mraa_i2c_read_byte_data ( mraa_i2c_context  dev,
const uint8_t  command 
)

Read a single byte from i2c context, from designated register

Parameters
devThe i2c context
commandThe register
Returns
The result of the read or -1 if failed
int mraa_i2c_read_bytes_data ( mraa_i2c_context  dev,
uint8_t  command,
uint8_t *  data,
int  length 
)

Bulk read from i2c context, starting from designated register

Parameters
devThe i2c context
commandThe register
datapointer to the byte array to read data in to
lengthmax number of bytes to read
Returns
The length in bytes passed to the function or -1
int mraa_i2c_read_word_data ( mraa_i2c_context  dev,
const uint8_t  command 
)

Read a single word from i2c context, from designated register

Parameters
devThe i2c context
commandThe register
Returns
The result of the read or -1 if failed
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
mraa_result_t mraa_i2c_write ( mraa_i2c_context  dev,
const uint8_t *  data,
int  length 
)

Write length bytes to the bus, the first byte in the array is the command/register to write

Parameters
devThe i2c context
datapointer to the byte array to be written
lengththe number of bytes to transmit
Returns
Result of operation
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
mraa_result_t mraa_i2c_write_byte_data ( mraa_i2c_context  dev,
const uint8_t  data,
const uint8_t  command 
)

Write a single byte to an i2c context

Parameters
devThe i2c context
dataThe byte to write
commandThe register
Returns
Result of operation
mraa_result_t mraa_i2c_write_word_data ( mraa_i2c_context  dev,
const uint16_t  data,
const uint8_t  command 
)

Write a single word to an i2c context

Parameters
devThe i2c context
dataThe word to write
commandThe register
Returns
Result of operation

Typedef Documentation

typedef struct _i2c* mraa_i2c_context

Opaque pointer definition to the internal struct _i2c

Include dependency graph for i2c.h: