i2c: Add functions for bulk read from register
Functions issue a write command for the register to read from and then a read command without a stop signal in between Signed-off-by: Gabriel Smith <ga29smith@gmail.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
f854a2b410
commit
caf1383325
@@ -115,6 +115,17 @@ uint8_t mraa_i2c_read_byte_data(mraa_i2c_context dev, const uint8_t command);
|
||||
*/
|
||||
uint16_t mraa_i2c_read_word_data(mraa_i2c_context dev, const uint8_t command);
|
||||
|
||||
/**
|
||||
* Bulk read from i2c context, starting from designated register
|
||||
*
|
||||
* @param dev The i2c context
|
||||
* @param command The register
|
||||
* @param data pointer to the byte array to read data in to
|
||||
* @param length max number of bytes to read
|
||||
* @return The length in bytes passed to the function or 0
|
||||
*/
|
||||
int mraa_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length);
|
||||
|
||||
/**
|
||||
* Write length bytes to the bus, the first byte in the array is the
|
||||
* command/register to write
|
||||
|
||||
@@ -132,6 +132,19 @@ class I2c {
|
||||
return mraa_i2c_read_word_data(m_i2c, reg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read length bytes from the bus into *data pointer starting from
|
||||
* an i2c register
|
||||
*
|
||||
* @param reg Register to read from
|
||||
* @param data pointer to the byte array to read data in to
|
||||
* @param length max number of bytes to read
|
||||
* @return length passed to the function or 0
|
||||
*/
|
||||
int readBytesReg(uint8_t reg, uint8_t* data, int length) {
|
||||
return mraa_i2c_read_bytes_data(m_i2c, reg, data, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a byte on the bus
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user