Skip to content

Commit 46d8ca7

Browse files
Fix pure i2c block read in Linux
1 parent 101550b commit 46d8ca7

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

i2c_smbus/i2c_smbus_linux.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ s32 i2c_smbus_linux::i2c_xfer(u8 addr, char read_write, int* size, u8* data)
3434
{
3535
i2c_rdwr_ioctl_data rdwr;
3636
i2c_msg msg;
37+
s32 ret_val;
3738

3839
msg.addr = addr;
3940
msg.flags = read_write;
@@ -44,8 +45,18 @@ s32 i2c_smbus_linux::i2c_xfer(u8 addr, char read_write, int* size, u8* data)
4445
rdwr.msgs = &msg;
4546
rdwr.nmsgs = 1;
4647

47-
ioctl(handle, I2C_SLAVE, addr);
48-
return ioctl(handle, I2C_RDWR, &rdwr);
48+
ret_val = ioctl(handle, I2C_RDWR, &rdwr);
49+
50+
/*-------------------------------------------------*\
51+
| If operation was a read, copy read data and size |
52+
\*-------------------------------------------------*/
53+
if(read_write == I2C_SMBUS_READ)
54+
{
55+
*size = msg.len;
56+
memcpy(data, &msg.buf, *size);
57+
}
58+
59+
return ret_val;
4960
}
5061

5162
#include "Detector.h"

0 commit comments

Comments
 (0)