Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fulfillment of the I2c trait contract #85

Merged
merged 5 commits into from
May 8, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,17 @@ impl<'a> I2CTransfer<'a> for LinuxI2CDevice {

/// Issue the provided sequence of I2C transactions
fn transfer(&mut self, messages: &'a mut [Self::Message]) -> Result<u32, LinuxI2CError> {
let msg_type = |flag: u16| flag & I2CMessageFlags::READ.bits();
let mut prev_msg_type = None;
for msg in messages.iter_mut() {
msg.addr = self.slave_address;

let cur_msg_type = msg_type(msg.flags);
if prev_msg_type.is_some_and(|prev| prev == cur_msg_type) {
ohunter marked this conversation as resolved.
Show resolved Hide resolved
msg.flags |= I2CMessageFlags::NO_START.bits();
} else {
prev_msg_type = Some(cur_msg_type);
}
}
ffi::i2c_rdwr(self.as_raw_fd(), messages).map_err(From::from)
}
Expand Down
Loading