Browse Source

add i2c read block data

pull/130/head
Chokri ZAGROUBA 3 years ago
parent
commit
d684de6646
2 changed files with 16 additions and 1 deletions
  1. +15
    -0
      wiringPi/wiringPiI2C.c
  2. +1
    -1
      wiringPi/wiringPiI2C.h

+ 15
- 0
wiringPi/wiringPiI2C.c View File

@@ -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:


+ 1
- 1
wiringPi/wiringPiI2C.h View File

@@ -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

Loading…
Cancel
Save