Skip to content

Commit 5cfb828

Browse files
committed
blocking/spi: Don't return the same buffer back.
1 parent 113cb81 commit 5cfb828

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1919
importing the `nb` crate directly in dependendent crates.
2020
- `blocking::Serial`: renamed `bwrite_all` to `write`, `bflush` to `flush.
2121
- Removed `prelude` to avoid method name conflicts between different flavors (blocking, nb) of the same trait. Traits must now be manually imported.
22+
- Removed `&[W]` returned slice in `spi::blocking::Transfer`.
2223

2324
### Removed
2425
- Removed random number generation (`rng`) traits in favor of [rand_core](https://crates.io/crates/rand_core).

src/blocking/spi.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ pub trait Transfer<W> {
55
/// Error type
66
type Error;
77

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

1214
/// Blocking write
@@ -42,13 +44,13 @@ pub mod transfer {
4244
{
4345
type Error = S::Error;
4446

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

51-
Ok(words)
53+
Ok(())
5254
}
5355
}
5456
}

0 commit comments

Comments
 (0)