Skip to content

Commit 7f1b99b

Browse files
committed
Change impls for transfer/write/write_iter in normal/bidi modes
1 parent d8aaf60 commit 7f1b99b

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

src/spi.rs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,7 @@ where
719719
}
720720
}
721721

722-
impl<SPI, PINS, TRANSFER_MODE> embedded_hal::blocking::spi::Write<u8>
723-
for Spi<SPI, PINS, TRANSFER_MODE>
722+
impl<SPI, PINS> embedded_hal::blocking::spi::Write<u8> for Spi<SPI, PINS, TransferModeNormal>
724723
where
725724
Self: spi::FullDuplex<u8>,
726725
SPI: Instance,
@@ -738,8 +737,24 @@ where
738737
}
739738
}
740739

741-
impl<SPI, PINS, TRANSFER_MODE> embedded_hal::blocking::spi::WriteIter<u8>
742-
for Spi<SPI, PINS, TRANSFER_MODE>
740+
impl<SPI, PINS> embedded_hal::blocking::spi::Write<u8> for Spi<SPI, PINS, TransferModeBidi>
741+
where
742+
Self: spi::FullDuplex<u8>,
743+
SPI: Instance,
744+
{
745+
type Error = <Self as spi::FullDuplex<u8>>::Error;
746+
747+
fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> {
748+
use spi::FullDuplex;
749+
for word in words {
750+
nb::block!(self.send(*word))?;
751+
}
752+
753+
Ok(())
754+
}
755+
}
756+
757+
impl<SPI, PINS> embedded_hal::blocking::spi::WriteIter<u8> for Spi<SPI, PINS, TransferModeNormal>
743758
where
744759
Self: spi::FullDuplex<u8>,
745760
SPI: Instance,
@@ -759,3 +774,23 @@ where
759774
Ok(())
760775
}
761776
}
777+
778+
impl<SPI, PINS> embedded_hal::blocking::spi::WriteIter<u8> for Spi<SPI, PINS, TransferModeBidi>
779+
where
780+
Self: spi::FullDuplex<u8>,
781+
SPI: Instance,
782+
{
783+
type Error = <Self as spi::FullDuplex<u8>>::Error;
784+
785+
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
786+
where
787+
WI: IntoIterator<Item = u8>,
788+
{
789+
use spi::FullDuplex;
790+
for word in words.into_iter() {
791+
nb::block!(self.send(word))?;
792+
}
793+
794+
Ok(())
795+
}
796+
}

0 commit comments

Comments
 (0)