aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob McWhirter <[email protected]>2021-07-20 09:43:25 -0400
committerBob McWhirter <[email protected]>2021-07-23 13:22:39 -0400
commit22901938ce4199c6545906226abecbe174a2e553 (patch)
tree909df33c38ac9f1dba51073400c2bf9756fddb60
parent372884422aab45f9fd09890c85e317cadd71c0d0 (diff)
Split up the SPI trait into several with shared Error associated type.
-rw-r--r--embassy-traits/src/spi.rs32
1 files changed, 23 insertions, 9 deletions
diff --git a/embassy-traits/src/spi.rs b/embassy-traits/src/spi.rs
index 227b8bfea..d19a1e58a 100644
--- a/embassy-traits/src/spi.rs
+++ b/embassy-traits/src/spi.rs
@@ -18,25 +18,39 @@ use core::future::Future;
18/// 18///
19/// - Some SPIs can work with 8-bit *and* 16-bit words. You can overload this trait with different 19/// - Some SPIs can work with 8-bit *and* 16-bit words. You can overload this trait with different
20/// `Word` types to allow operation in both modes. 20/// `Word` types to allow operation in both modes.
21pub trait FullDuplex<Word> { 21
22pub trait Spi<Word> {
22 /// An enumeration of SPI errors 23 /// An enumeration of SPI errors
23 type Error; 24 type Error;
25}
26
27pub trait FullDuplex<Word> : Spi<Word> + Write<Word> + Read<Word> {
24 28
25 type WriteFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
26 where
27 Self: 'a;
28 type ReadFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
29 where
30 Self: 'a;
31 type WriteReadFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a 29 type WriteReadFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
32 where 30 where
33 Self: 'a; 31 Self: 'a;
34 32
35 fn read<'a>(&'a mut self, data: &'a mut [Word]) -> Self::ReadFuture<'a>;
36 fn write<'a>(&'a mut self, data: &'a [Word]) -> Self::WriteFuture<'a>;
37 fn read_write<'a>( 33 fn read_write<'a>(
38 &'a mut self, 34 &'a mut self,
39 read: &'a mut [Word], 35 read: &'a mut [Word],
40 write: &'a [Word], 36 write: &'a [Word],
41 ) -> Self::WriteReadFuture<'a>; 37 ) -> Self::WriteReadFuture<'a>;
42} 38}
39
40pub trait Write<Word> : Spi<Word>{
41
42 type WriteFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
43 where
44 Self: 'a;
45
46 fn write<'a>(&'a mut self, data: &'a [Word]) -> Self::WriteFuture<'a>;
47}
48
49pub trait Read<Word> : Spi<Word>{
50
51 type ReadFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
52 where
53 Self: 'a;
54
55 fn read<'a>(&'a mut self, data: &'a mut [Word]) -> Self::ReadFuture<'a>;
56} \ No newline at end of file