diff --git a/src/prelude.rs b/src/prelude.rs index 4d17043ad..55f0b5d8d 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -28,6 +28,8 @@ pub use digital::ToggleableOutputPin as _embedded_hal_digital_ToggleableOutputPi pub use serial::Read as _embedded_hal_serial_Read; pub use serial::Write as _embedded_hal_serial_Write; pub use spi::FullDuplex as _embedded_hal_spi_FullDuplex; +#[cfg(feature = "unproven")] +pub use spi::Send as _embedded_hal_spi_Send; pub use timer::CountDown as _embedded_hal_timer_CountDown; #[cfg(feature = "unproven")] pub use watchdog::Watchdog as _embedded_hal_watchdog_Watchdog; diff --git a/src/spi.rs b/src/spi.rs index b91e6d68b..92387a237 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -26,6 +26,38 @@ pub trait FullDuplex { fn send(&mut self, word: Word) -> nb::Result<(), Self::Error>; } +/// Write (master mode) +/// +/// # Notes +/// +/// - It's the task of the user of this interface to manage the slave select lines +/// +/// - The slave select line shouldn't be released before the `flush` call succeeds +#[cfg(feature = "unproven")] +pub trait Send { + /// An enumeration of SPI errors + type Error; + + /// Sends a word to the slave + fn send(&mut self, word: Word) -> nb::Result<(), Self::Error>; + + /// Ensures that none of the previously written words are still buffered + fn completed(&mut self) -> nb::Result<(), Self::Error>; +} + +/// Write (master mode) +#[cfg(feature = "unproven")] +impl Send for FullDuplex { + type Error = E; + fn send(&mut self, word: W) -> nb::Result<(), Self::Error> { + self.send(word) + } + + fn completed(&mut self) -> nb::Result<(), Self::Error> { + self.read().map(|_| ()) + } +} + /// Clock polarity #[derive(Clone, Copy, PartialEq, Eq)] pub enum Polarity { @@ -75,4 +107,4 @@ pub const MODE_2: Mode = Mode { pub const MODE_3: Mode = Mode { polarity: Polarity::IdleHigh, phase: Phase::CaptureOnSecondTransition, -}; \ No newline at end of file +};