Skip to content

Commit 4f02678

Browse files
committed
Prototype implementation. Seems to work on raspberry pi 5 with software i2c.
1 parent bd5f200 commit 4f02678

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/linux.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,17 @@ impl<'a> I2CTransfer<'a> for LinuxI2CDevice {
300300

301301
/// Issue the provided sequence of I2C transactions
302302
fn transfer(&mut self, messages: &'a mut [Self::Message]) -> Result<u32, LinuxI2CError> {
303+
let msg_type = |flag: u16| flag & I2CMessageFlags::READ.bits();
304+
let mut prev_msg_type = !msg_type(messages[0].flags);
303305
for msg in messages.iter_mut() {
304306
msg.addr = self.slave_address;
307+
308+
let cur_msg_type = msg_type(msg.flags);
309+
if prev_msg_type == cur_msg_type {
310+
msg.flags |= I2CMessageFlags::NO_START.bits();
311+
} else {
312+
prev_msg_type = cur_msg_type;
313+
}
305314
}
306315
ffi::i2c_rdwr(self.as_raw_fd(), messages).map_err(From::from)
307316
}

0 commit comments

Comments
 (0)