The ONLP_I2C_F_USE_BLOCK_READ flag can be used to request block reads from onlp_i2c_dev_read().

This commit is contained in:
Jeffrey Townsend
2016-09-19 20:12:01 +00:00
parent 759db3f675
commit 6b5c4c1c33
2 changed files with 13 additions and 1 deletions

View File

@@ -61,6 +61,10 @@
*/
#define ONLP_I2C_F_NO_MUX_SELECT 0x10
/**
* Use block reads if possible.
*/
#define ONLP_I2C_F_USE_BLOCK_READ 0x20
/**
* @brief Open and prepare for reading or writing.

View File

@@ -144,6 +144,7 @@ onlp_i2c_read(int bus, uint8_t addr, uint8_t offset, int size,
for(i = 0; i < size; i++) {
int rv = i2c_smbus_read_byte_data(fd, offset+i);
if(rv < 0) {
AIM_LOG_ERROR("i2c-%d: reading address 0x%x, offset %d failed: %{errno}",
bus, addr, offset+i, errno);
@@ -392,7 +393,14 @@ onlp_i2c_dev_read(onlp_i2c_dev_t* dev, uint8_t offset, int size,
return error;
}
if( (rv = onlp_i2c_read(dev->bus, dev->addr, offset, size, rdata, flags)) < 0) {
if(flags & ONLP_I2C_F_USE_BLOCK_READ) {
rv = onlp_i2c_block_read(dev->bus, dev->addr, offset, size, rdata, flags);
}
else {
rv = onlp_i2c_read(dev->bus, dev->addr, offset, size, rdata, flags);
}
if( rv < 0 ) {
AIM_LOG_ERROR("Device %s: read() failed: %d",
dev->name, rv);
return rv;