aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxoviat <[email protected]>2021-03-08 12:35:55 -0600
committerxoviat <[email protected]>2021-03-08 12:35:55 -0600
commitf2ab4c4ec052e7b92a41e61941c5185d6c87e879 (patch)
tree67ee28c645bffebe79ddc0ec886b7bf70fc448bb
parent16e00669aeae310451adbd1773db29cc70c9dc5f (diff)
add spi trait
-rw-r--r--embassy-traits/src/lib.rs1
-rw-r--r--embassy-traits/src/spi.rs36
2 files changed, 37 insertions, 0 deletions
diff --git a/embassy-traits/src/lib.rs b/embassy-traits/src/lib.rs
index 10d44d9de..431a02526 100644
--- a/embassy-traits/src/lib.rs
+++ b/embassy-traits/src/lib.rs
@@ -10,4 +10,5 @@ pub mod delay;
10pub mod flash; 10pub mod flash;
11pub mod gpio; 11pub mod gpio;
12pub mod i2c; 12pub mod i2c;
13pub mod spi;
13pub mod uart; 14pub mod uart;
diff --git a/embassy-traits/src/spi.rs b/embassy-traits/src/spi.rs
new file mode 100644
index 000000000..cc5c33ec8
--- /dev/null
+++ b/embassy-traits/src/spi.rs
@@ -0,0 +1,36 @@
1//! Async SPI API
2
3use core::future::Future;
4
5/// Full duplex (master mode)
6///
7/// # Notes
8///
9/// - It's the task of the user of this interface to manage the slave select lines
10///
11/// - Due to how full duplex SPI works each `try_read` call must be preceded by a `try_send` call.
12///
13/// - `try_read` calls only return the data received with the last `try_send` call.
14/// Previously received data is discarded
15///
16/// - Data is only guaranteed to be clocked out when the `try_read` call succeeds.
17/// The slave select line shouldn't be released before that.
18///
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.
21pub trait FullDuplex<Word> {
22 /// An enumeration of SPI errors
23 type Error;
24
25 type WriteFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a;
26 type ReadFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a;
27 type WriteReadFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a;
28
29 fn read<'a>(&'a mut self, data: &'a mut [Word]) -> Self::ReadFuture<'_>;
30 fn write<'a>(&'a mut self, data: &'a [Word]) -> Self::WriteFuture<'_>;
31 fn read_write<'a>(
32 &mut self,
33 read: &'a mut [Word],
34 write: &'a [Word],
35 ) -> Self::WriteReadFuture<'_>;
36}