aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-03-17 03:06:12 +0100
committerGitHub <[email protected]>2021-03-17 03:06:12 +0100
commitf14361835fb81726d71ac85f0f562ede8c1a6472 (patch)
tree127ece39316c4a8f70c4d3358f65d20d6fc0525a
parente1cad548334f825c75ffc9f759e72d2960bf9ea3 (diff)
parent5bd705caa53030025e8de08de31e391981447612 (diff)
Merge pull request #66 from xoviat/spi-trait
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 bf5c63de7..81a847ef6 100644
--- a/embassy-traits/src/lib.rs
+++ b/embassy-traits/src/lib.rs
@@ -13,4 +13,5 @@ pub mod flash;
13pub mod gpio; 13pub mod gpio;
14pub mod i2c; 14pub mod i2c;
15pub mod qei; 15pub mod qei;
16pub mod spi;
16pub mod uart; 17pub mod uart;
diff --git a/embassy-traits/src/spi.rs b/embassy-traits/src/spi.rs
new file mode 100644
index 000000000..d0cf29e6d
--- /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 `read` call must be preceded by a `write` call.
12///
13/// - `read` calls only return the data received with the last `write` call.
14/// Previously received data is discarded
15///
16/// - Data is only guaranteed to be clocked out when the `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}