From 22901938ce4199c6545906226abecbe174a2e553 Mon Sep 17 00:00:00 2001 From: Bob McWhirter Date: Tue, 20 Jul 2021 09:43:25 -0400 Subject: [PATCH] Split up the SPI trait into several with shared Error associated type. --- embassy-traits/src/spi.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/embassy-traits/src/spi.rs b/embassy-traits/src/spi.rs index 227b8bfe..d19a1e58 100644 --- a/embassy-traits/src/spi.rs +++ b/embassy-traits/src/spi.rs @@ -18,25 +18,39 @@ use core::future::Future; /// /// - Some SPIs can work with 8-bit *and* 16-bit words. You can overload this trait with different /// `Word` types to allow operation in both modes. -pub trait FullDuplex { + +pub trait Spi { /// An enumeration of SPI errors type Error; +} + +pub trait FullDuplex : Spi + Write + Read { - type WriteFuture<'a>: Future> + 'a - where - Self: 'a; - type ReadFuture<'a>: Future> + 'a - where - Self: 'a; type WriteReadFuture<'a>: Future> + 'a where Self: 'a; - fn read<'a>(&'a mut self, data: &'a mut [Word]) -> Self::ReadFuture<'a>; - fn write<'a>(&'a mut self, data: &'a [Word]) -> Self::WriteFuture<'a>; fn read_write<'a>( &'a mut self, read: &'a mut [Word], write: &'a [Word], ) -> Self::WriteReadFuture<'a>; } + +pub trait Write : Spi{ + + type WriteFuture<'a>: Future> + 'a + where + Self: 'a; + + fn write<'a>(&'a mut self, data: &'a [Word]) -> Self::WriteFuture<'a>; +} + +pub trait Read : Spi{ + + type ReadFuture<'a>: Future> + 'a + where + Self: 'a; + + fn read<'a>(&'a mut self, data: &'a mut [Word]) -> Self::ReadFuture<'a>; +} \ No newline at end of file