Skip to content

Commit

Permalink
Use iterator in I2C read
Browse files Browse the repository at this point in the history
Roll `transmit_stop()` into the loop
  • Loading branch information
RossPorter506 committed Jan 5, 2025
1 parent f8a7e73 commit 81534e4
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,17 +406,16 @@ impl<USCI: I2cUsci> I2cBus<USCI> {
return Err::<(), I2CErr>(I2CErr::GotNACK);
}

for i in 0..buffer.len() - 1 {
let len = buffer.len();
for (idx, byte) in buffer.iter_mut().enumerate() {
while !ifg.ucrxifg0() {
ifg = usci.ifg_rd();
}
buffer[i] = usci.ucrxbuf_rd();
}
usci.transmit_stop();
while !ifg.ucrxifg0() {
ifg = usci.ifg_rd();
*byte = usci.ucrxbuf_rd();
if idx == len - 2 {
usci.transmit_stop();
}
}
buffer[buffer.len() - 1] = usci.ucrxbuf_rd();

while usci.uctxstp_rd() {
asm::nop();
Expand Down

0 comments on commit 81534e4

Please sign in to comment.