Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Use manual impls for blocking spi instead of `Default`.
- Split `Stream` trait on `Stream` and `StreamISR`.
Use const generics for `Stream` and `Channel`.
- [breaking-change] `Timer::new` now just initializes peripheral.
Expand Down
52 changes: 48 additions & 4 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,12 +587,56 @@ where
}
}

impl<SPI, PINS> embedded_hal::blocking::spi::transfer::Default<u8> for Spi<SPI, PINS> where
SPI: Instance
impl<SPI, PINS> embedded_hal::blocking::spi::Transfer<u8> for Spi<SPI, PINS>
where
SPI: Instance,
{
type Error = Error;

fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> {
use spi::FullDuplex;
for word in words.iter_mut() {
nb::block!(self.send(*word))?;
*word = nb::block!(self.read())?;
}

Ok(words)
}
}

impl<SPI, PINS> embedded_hal::blocking::spi::Write<u8> for Spi<SPI, PINS>
where
SPI: Instance,
{
type Error = Error;

fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> {
use spi::FullDuplex;
for word in words {
nb::block!(self.send(*word))?;
nb::block!(self.read())?;
}

Ok(())
}
}

impl<SPI, PINS> embedded_hal::blocking::spi::write::Default<u8> for Spi<SPI, PINS> where
SPI: Instance
impl<SPI, PINS> embedded_hal::blocking::spi::WriteIter<u8> for Spi<SPI, PINS>
where
SPI: Instance,
{
type Error = Error;

fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
where
WI: IntoIterator<Item = u8>,
{
use spi::FullDuplex;
for word in words.into_iter() {
nb::block!(self.send(word))?;
nb::block!(self.read())?;
}

Ok(())
}
}