i2c: add api call to read byte from a specified register
Signed-off-by: Anton Krasovsky <anton@no-mad.net> Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
committed by
Thomas Ingleby
parent
c852685975
commit
cbf4c7447f
@@ -95,6 +95,15 @@ int mraa_i2c_read(mraa_i2c_context dev, uint8_t *data, int length);
|
|||||||
*/
|
*/
|
||||||
uint8_t mraa_i2c_read_byte(mraa_i2c_context dev);
|
uint8_t mraa_i2c_read_byte(mraa_i2c_context dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read a single byte from i2c context, from designated register
|
||||||
|
*
|
||||||
|
* @param dev The i2c context
|
||||||
|
* @param command The register
|
||||||
|
* @return The result of the read or -1 if failed
|
||||||
|
*/
|
||||||
|
uint8_t mraa_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write to an i2c context
|
* Write to an i2c context
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -143,6 +143,18 @@ class I2c {
|
|||||||
return mraa_i2c_write(m_i2c, buf, 2);
|
return mraa_i2c_write(m_i2c, buf, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read an i2c register
|
||||||
|
*
|
||||||
|
* @param reg Register to read from
|
||||||
|
|
||||||
|
* @return char read from the bus
|
||||||
|
* @return char read from register
|
||||||
|
*/
|
||||||
|
int readReg(char reg) {
|
||||||
|
return mraa_i2c_read_byte_data(m_i2c, reg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write multiple bytes to the bus
|
* Write multiple bytes to the bus
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -101,6 +101,13 @@ mraa_i2c_read_byte(mraa_i2c_context dev)
|
|||||||
return byte;
|
return byte;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t
|
||||||
|
mraa_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
|
||||||
|
{
|
||||||
|
uint8_t byte = i2c_smbus_read_byte_data(dev->fh, command);
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
mraa_result_t
|
mraa_result_t
|
||||||
mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
|
mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user