Add functions to i2c_smbus for pure i2c block transactions

Commit amended to rework API and change for code style by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
1000001101000 2021-11-17 23:24:09 -06:00 committed by Adam Honse
parent aaa60d7d6f
commit e36b52136c
14 changed files with 152 additions and 12 deletions

View file

@ -12,9 +12,11 @@
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
#include <sys/ioctl.h>
#include <cstring>
s32 i2c_smbus_linux::i2c_smbus_xfer(u8 addr, char read_write, u8 command, int size, union i2c_smbus_data* data)
{
struct i2c_smbus_ioctl_data args;
//Tell I2C host which slave address to transfer to
@ -28,6 +30,24 @@ s32 i2c_smbus_linux::i2c_smbus_xfer(u8 addr, char read_write, u8 command, int si
return ioctl(handle, I2C_SMBUS, &args);
}
s32 i2c_smbus_linux::i2c_xfer(u8 addr, char read_write, int* size, u8* data)
{
i2c_rdwr_ioctl_data rdwr;
i2c_msg msg;
msg.addr = addr;
msg.flags = read_write;
msg.len = *size;
msg.buf = (u8*)malloc(*size);
memcpy(&msg.buf, &data, *size);
rdwr.msgs = &msg;
rdwr.nmsgs = 1;
ioctl(handle, I2C_SLAVE, addr);
return ioctl(handle, I2C_RDWR, &rdwr);
}
#include "Detector.h"
#include <fcntl.h>
#include <unistd.h>