Skip to content

Commit

Permalink
fix(spi): wrong transfer mode
Browse files Browse the repository at this point in the history
Signed-off-by: HaoboGu <[email protected]>
  • Loading branch information
HaoboGu committed Jul 2, 2024
1 parent eeed64d commit 57469dc
Showing 1 changed file with 36 additions and 33 deletions.
69 changes: 36 additions & 33 deletions src/spi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ impl<'d, M: Mode> Spi<'d, M> {
w.set_tokenvalue(false);
w.set_dummycnt(config.dummy_cnt);
w.set_rdtrancnt(0);
w.set_transmode(config.transfer_mode.into());
});

#[cfg(spi_v53)]
Expand Down Expand Up @@ -502,40 +503,42 @@ impl<'d, M: Mode> embedded_hal::spi::ErrorType for Spi<'d, M> {

impl<'d, M: Mode> embedded_hal::spi::SpiDevice for Spi<'d, M> {
fn transaction(&mut self, operations: &mut [embedded_hal::spi::Operation<'_, u8>]) -> Result<(), Self::Error> {
match operations {
[embedded_hal::spi::Operation::Write(buf)] => {
let config = TransferConfig::default();
self.blocking_write(buf, &config)
}
[embedded_hal::spi::Operation::Read(buf)] => {
let config = TransferConfig {
transfer_mode: TransferMode::ReadOnly,
..Default::default()
};
self.blocking_read(buf, &config)
}
[embedded_hal::spi::Operation::Transfer(read, write)] => {
let mut config = TransferConfig {
transfer_mode: TransferMode::WriteOnly,
..Default::default()
};
self.blocking_write(write, &config)?;
config.transfer_mode = TransferMode::ReadOnly;
self.blocking_read(read, &config)
}
[embedded_hal::spi::Operation::TransferInPlace(buf)] => {
let mut config = TransferConfig {
transfer_mode: TransferMode::WriteOnly,
..Default::default()
};
self.blocking_write(buf, &config)?;
config.transfer_mode = TransferMode::ReadOnly;
self.blocking_read(buf, &config)
}
[embedded_hal::spi::Operation::DelayNs(_ns)] => {
todo!();
for operation in operations {
match operation {
embedded_hal::spi::Operation::Write(buf) => {
let config = TransferConfig::default();
self.blocking_write(buf, &config)?;
}
embedded_hal::spi::Operation::Read(buf) => {
let config = TransferConfig {
transfer_mode: TransferMode::ReadOnly,
..Default::default()
};
self.blocking_read(buf, &config)?;
}
embedded_hal::spi::Operation::Transfer(read, write) => {
let mut config = TransferConfig {
transfer_mode: TransferMode::WriteOnly,
..Default::default()
};
self.blocking_write(write, &config)?;
config.transfer_mode = TransferMode::ReadOnly;
self.blocking_read(read, &config)?;
}
embedded_hal::spi::Operation::TransferInPlace(buf) => {
let mut config = TransferConfig {
transfer_mode: TransferMode::WriteOnly,
..Default::default()
};
self.blocking_write(buf, &config)?;
config.transfer_mode = TransferMode::ReadOnly;
self.blocking_read(buf, &config)?;
}
embedded_hal::spi::Operation::DelayNs(ns) => {
self.delay.delay_ns(*ns);
}
}
_ => todo!("WORD not supported"),
}
Ok(())
}
}

0 comments on commit 57469dc

Please sign in to comment.