mraa  2.0.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
Public Member Functions | List of all members
I2c Class Reference

Detailed Description

An I2c object represents an i2c master and can talk multiple i2c slaves by selecting the correct 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.

I2c i2c = new I2c(0);
i2c.address(HMC5883L_I2C_ADDR);
conf_buf[0] = HMC5883L_CONF_REG_B;
conf_buf[1] = GA_1_3_REG;
i2c.write(conf_buf);

Public Member Functions

synchronized void delete ()
 
 I2c (int bus, boolean raw)
 
 I2c (int bus)
 
Result frequency (I2cMode mode)
 
Result address (short address)
 
short readByte ()
 
int read (byte[] data)
 
short readReg (short reg)
 
int readWordReg (short reg)
 
int readBytesReg (short reg, byte[] data)
 
Result writeByte (short data)
 
Result write (byte[] data)
 
Result writeReg (short reg, short data)
 
Result writeWordReg (short reg, int data)
 

Constructor & Destructor Documentation

I2c ( int  bus,
boolean  raw 
)

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

Parameters
busThe i2c bus to use
rawWhether to disable pinmapper for your board
I2c ( int  bus)

I2C constructor, takes a pointer to a I2C context and initialises the I2C class

Parameters
i2c_contextvoid * to an I2C context

Member Function Documentation

Result address ( short  address)

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
Result frequency ( I2cMode  mode)

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
modeFrequency to set the bus to
Returns
Result of operation
short readByte ( )

Read exactly one byte from the bus

Exceptions
std::invalid_argumentin case of error
Returns
char read from the bus
short readReg ( short  reg)

Read byte from an i2c register

Parameters
regRegister to read from
Exceptions
std::invalid_argumentin case of error
Returns
char read from register
int readWordReg ( short  reg)

Read word from an i2c register

Parameters
regRegister to read from
Exceptions
std::invalid_argumentin case of error
Returns
char read from register
Result writeByte ( short  data)

Write a byte on the bus

Parameters
dataThe byte to send on the bus
Returns
Result of operation
Result writeReg ( short  reg,
short  data 
)

Write a byte to an i2c register

Parameters
regRegister to write to
dataValue to write to register
Returns
Result of operation
Result writeWordReg ( short  reg,
int  data 
)

Write a word to an i2c register

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

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