Merge pull request #122 from zhouzi88/master

support SMBus block read
This commit is contained in:
Jeffrey Townsend
2016-11-02 13:14:26 -07:00
committed by GitHub
2 changed files with 13 additions and 2 deletions

View File

@@ -66,6 +66,11 @@
*/
#define ONLP_I2C_F_USE_BLOCK_READ 0x20
/**
* Use SMBUS block reads if possible.
*/
#define ONLP_I2C_F_USE_SMBUS_BLOCK_READ 0x40
/**
* @brief Open and prepare for reading or writing.
* @param bus The i2c bus number.

View File

@@ -105,11 +105,17 @@ onlp_i2c_block_read(int bus, uint8_t addr, uint8_t offset, int size,
int count = size;
uint8_t* p = rdata;
while(count > 0) {
int rv;
int rsize = (count >= ONLPLIB_CONFIG_I2C_BLOCK_SIZE) ? ONLPLIB_CONFIG_I2C_BLOCK_SIZE : count;
int rv = i2c_smbus_read_i2c_block_data(fd,
p - rdata,
if(flags & ONLP_I2C_F_USE_SMBUS_BLOCK_READ) {
rv = i2c_smbus_read_block_data(fd, offset, p);
} else {
rv = i2c_smbus_read_i2c_block_data(fd,
offset,
rsize,
p);
offset += rsize;
}
if(rv != rsize) {
AIM_LOG_ERROR("i2c-%d: reading address 0x%x, offset %d, size=%d failed: %{errno}",