Skip to content

Commit

Permalink
blocking/spi: Don't return the same buffer back.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Jul 13, 2021
1 parent 113cb81 commit 1eebe4b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/blocking/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ pub trait Transfer<W> {
/// Error type
type Error;

/// Writes `words` to the slave. Returns the `words` received from the slave
fn transfer<'w>(&mut self, words: &'w mut [W]) -> Result<&'w [W], Self::Error>;
/// Writes and reads simultaneously. The contents of `words` are
/// written to the slave, and the received words are stored into the same
/// `words` buffer, overwriting it.
fn transfer(&mut self, words: &mut [W]) -> Result<(), Self::Error>;
}

/// Blocking write
Expand Down Expand Up @@ -42,13 +44,13 @@ pub mod transfer {
{
type Error = S::Error;

fn transfer<'w>(&mut self, words: &'w mut [W]) -> Result<&'w [W], S::Error> {
fn transfer(&mut self, words: &mut [W]) -> Result<(), S::Error> {
for word in words.iter_mut() {
nb::block!(self.write(word.clone()))?;
*word = nb::block!(self.read())?;
}

Ok(words)
Ok(())
}
}
}
Expand Down

0 comments on commit 1eebe4b

Please sign in to comment.