浏览代码

add i2c read block data

pull/130/head
Chokri ZAGROUBA 3 年前
父节点
当前提交
d684de6646
共有 2 个文件被更改,包括 16 次插入1 次删除
  1. +15
    -0
      wiringPi/wiringPiI2C.c
  2. +1
    -1
      wiringPi/wiringPiI2C.h

+ 15
- 0
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:


+ 1
- 1
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

正在加载...
取消
保存