Skip to content

Commit

Permalink
Fix order of single word transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
Finomnis committed Dec 9, 2023
1 parent 69fc170 commit fe98166
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/common/lpspi/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,21 @@ impl<'a, const N: u8> Lpspi<'a, N> {

if let Some(data) = write_data {
let mut tx_buffer = [0u8; 4];
let active_buffer = &mut tx_buffer[(4 - len.get())..];
if reverse_bytes {
for i in 0..len.get() {
tx_buffer[i] = data.add(len.get() - i - 1).read();
}
active_buffer
.iter_mut()
.rev()
.enumerate()
.for_each(|(pos, val)| *val = data.add(pos).read());
} else {
for i in 0..len.get() {
tx_buffer[i] = data.add(i).read();
}
active_buffer
.iter_mut()
.enumerate()
.for_each(|(pos, val)| *val = data.add(pos).read());
}

ral::write_reg!(ral::lpspi, self.lpspi(), TDR, u32::from_be_bytes(tx_buffer));
ral::write_reg!(ral::lpspi, self.lpspi(), TDR, u32::from_le_bytes(tx_buffer));
}
}

Expand Down

0 comments on commit fe98166

Please sign in to comment.