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
@@ -200,6 +200,27 @@ mraa_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
|
||||
return 0xFFFF & d.word;
|
||||
}
|
||||
|
||||
int
|
||||
mraa_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length)
|
||||
{
|
||||
struct i2c_rdwr_ioctl_data d;
|
||||
struct i2c_msg m[2];
|
||||
|
||||
m[0].addr = dev->addr;
|
||||
m[0].flags = I2C_M_RD;
|
||||
m[0].len = 1;
|
||||
m[0].buf = &command;
|
||||
m[1].addr = dev->addr;
|
||||
m[1].flags = 0x00;
|
||||
m[1].len = length;
|
||||
m[1].buf = data;
|
||||
|
||||
d.msgs = m;
|
||||
d.nmsgs = 2;
|
||||
|
||||
return ioctl(dev->fh, I2C_RDWR, &d) < 0 ? -1 : length;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user