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
Public Member Functions
I2c Class Reference

Detailed Description

This file defines the I2c interface for libmraa

mraa::I2c* i2c;
i2c = new mraa::I2c(0);
i2c->address(HMC5883L_I2C_ADDR);
rx_tx_buf[0] = HMC5883L_CONF_REG_B;
rx_tx_buf[1] = GA_1_3_REG;
i2c->write(rx_tx_buf, 2);

Public Member Functions

 I2c (int bus, bool raw=false)
 
 ~I2c ()
 
mraa_result_t frequency (int hz)
 
mraa_result_t address (int address)
 
unsigned char read ()
 
int read (char *data, size_t length)
 
std::string read (size_t length)
 
mraa_result_t write (char *data, size_t length)
 
mraa_result_t writeReg (char reg, char data)
 
mraa_result_t write (char data)
 

Constructor & Destructor Documentation

I2c ( int  bus,
bool  raw = false 
)
inline

Instantiates an i2c bus. Multiple instances of the same bus can exist and the bus is not guarranteed to be on the correct address before read/write.

Parameters
busThe i2c bus to use
rawWhether to disable pinmapper for your board

Here is the call graph for this function:

~I2c ( )
inline

Closes the I2c Bus used. This does not guarrantee the bus will not be usable by anyone else or communicates this disconnect to any slaves.

Here is the call graph for this function:

Member Function Documentation

mraa_result_t frequency ( int  hz)
inline

Sets the i2c Frequency for communication. Your board may not support the set frequency. Anyone can change this at any time and this will affect every slave on the bus

Parameters
hzFrequency to set the bus to in hz
Returns
Result of operation

Here is the call graph for this function:

mraa_result_t address ( int  address)
inline

Set the slave to talk to, typically called before every read/write operation

Parameters
addressCommunicate to the i2c slave on this address
Returns
Result of operation

Here is the call graph for this function:

unsigned char read ( )
inline

Read exactly one byte from the bus

Returns
char read from the bus

Here is the call graph for this function:

int read ( char *  data,
size_t  length 
)
inline

Read mutliple bytes from the bus

Parameters
dataBuffer to write into
lengthSize of read
Returns
length of the read or 0 if failed

Here is the call graph for this function:

std::string read ( size_t  length)
inline

Read length bytes from the bus, and return as a std::string note that this is not a null terminated string

Parameters
lengthSize of read to make
Returns
pointer to std::string

Here is the call graph for this function:

mraa_result_t write ( char *  data,
size_t  length 
)
inline

Write one byte to the bus

Parameters
dataBuffer to send on the bus
lengthSize of buffer to send
Returns
Result of operation

Here is the call graph for this function:

mraa_result_t writeReg ( char  reg,
char  data 
)
inline

Write to an i2c register

Parameters
regRegister to write to
dataValue to write to register
Returns
Result of operation

Here is the call graph for this function:

mraa_result_t write ( char  data)
inline

Write multiple bytes to the bus

Parameters
dataThe byte to send on the bus
Returns
Result of operation

Here is the call graph for this function:


The documentation for this class was generated from the following file: