diff --git a/wiringPi/wiringPiI2C.c b/wiringPi/wiringPiI2C.c index 3cfbaf6..8360b3f 100644 --- a/wiringPi/wiringPiI2C.c +++ b/wiringPi/wiringPiI2C.c @@ -201,6 +201,21 @@ int wiringPiI2CWriteBlockData (int fd, int size, int reg, uint8_t *value) return i2c_smbus_access (fd, I2C_SMBUS_WRITE, reg, I2C_SMBUS_BLOCK_DATA, &data) ; } +/* Returns the number of read bytes */ +int wiringPiI2CReadBlockData(int fd, uint8_t reg, uint8_t *values) +{ + union i2c_smbus_data data; + int i, err; + + err = i2c_smbus_access(fd, I2C_SMBUS_READ, reg, + I2C_SMBUS_BLOCK_DATA, &data); + if (err < 0) + return err; + + for (i = 1; i <= data.block[0]; i++) + values[i-1] = data.block[i]; + return data.block[0]; +} /* * wiringPiI2CSetupInterface: diff --git a/wiringPi/wiringPiI2C.h b/wiringPi/wiringPiI2C.h index 58b6823..15c9c38 100644 --- a/wiringPi/wiringPiI2C.h +++ b/wiringPi/wiringPiI2C.h @@ -40,7 +40,7 @@ extern int wiringPiI2CSetupInterface (const char *device, int devId) ; extern int wiringPiI2CSetup (const int devId) ; extern int wiringPiI2CWriteBlockData (int fd, int size, int reg, uint8_t *value); - +extern int wiringPiI2CReadBlockData (int fd, uint8_t reg, uint8_t *values); #ifdef __cplusplus } #endif