Browse Source

add i2c write block data

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

+ 12
- 0
wiringPi/wiringPiI2C.c View File

@@ -189,6 +189,18 @@ int wiringPiI2CWriteReg16 (int fd, int reg, int value)
return i2c_smbus_access (fd, I2C_SMBUS_WRITE, reg, I2C_SMBUS_WORD_DATA, &data) ;
}

int wiringPiI2CWriteBlockData (int fd, int size, int reg, uint8_t *value)
{
union i2c_smbus_data data ;

data.block[0] = size;
for(int i=0; i < size; i++) {
data.block[i+1] = value[i];
}

return i2c_smbus_access (fd, I2C_SMBUS_WRITE, reg, I2C_SMBUS_BLOCK_DATA, &data) ;
}


/*
* wiringPiI2CSetupInterface:


+ 4
- 0
wiringPi/wiringPiI2C.h View File

@@ -21,6 +21,8 @@
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdlib.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
@@ -37,6 +39,8 @@ extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
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);

#ifdef __cplusplus
}
#endif

Loading…
Cancel
Save