diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-03-18 01:27:30 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-03-18 01:27:30 +0100 |
| commit | 3de2d5c5bde44f1aec0e1727cfb2af3052c1bda4 (patch) | |
| tree | a337a563ce519ff73123f5b219587e3570adf0c1 /embassy-nrf/src | |
| parent | c403a47b7f77252c26356d69173169b5fe393d52 (diff) | |
Implement FullDuplex for nrf spim
Diffstat (limited to 'embassy-nrf/src')
| -rw-r--r-- | embassy-nrf/src/spim.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index 4921bae3b..61d415e02 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs | |||
| @@ -2,9 +2,11 @@ use core::future::Future; | |||
| 2 | use core::pin::Pin; | 2 | use core::pin::Pin; |
| 3 | use core::sync::atomic::{compiler_fence, Ordering}; | 3 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | use embassy::traits; | ||
| 5 | use embassy::util::WakerRegistration; | 6 | use embassy::util::WakerRegistration; |
| 6 | use embassy_extras::peripheral::{PeripheralMutex, PeripheralState}; | 7 | use embassy_extras::peripheral::{PeripheralMutex, PeripheralState}; |
| 7 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
| 9 | use traits::spi::FullDuplex; | ||
| 8 | 10 | ||
| 9 | use crate::interrupt::{self, Interrupt}; | 11 | use crate::interrupt::{self, Interrupt}; |
| 10 | use crate::{pac, slice_in_ram_or}; | 12 | use crate::{pac, slice_in_ram_or}; |
| @@ -123,15 +125,33 @@ impl<T: Instance> Spim<T> { | |||
| 123 | let (state, irq) = self.inner().free(); | 125 | let (state, irq) = self.inner().free(); |
| 124 | (state.spim, irq) | 126 | (state.spim, irq) |
| 125 | } | 127 | } |
| 128 | } | ||
| 129 | |||
| 130 | impl<T: Instance> FullDuplex<u8> for Spim<T> { | ||
| 131 | type Error = Error; | ||
| 132 | |||
| 133 | #[rustfmt::skip] | ||
| 134 | type WriteFuture<'a> where Self: 'a = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 135 | #[rustfmt::skip] | ||
| 136 | type ReadFuture<'a> where Self: 'a = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 137 | #[rustfmt::skip] | ||
| 138 | type WriteReadFuture<'a> where Self: 'a = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 139 | |||
| 140 | fn read<'a>(self: Pin<&'a mut Self>, data: &'a mut [u8]) -> Self::ReadFuture<'a> { | ||
| 141 | async move { todo!() } | ||
| 142 | } | ||
| 143 | fn write<'a>(self: Pin<&'a mut Self>, data: &'a [u8]) -> Self::WriteFuture<'a> { | ||
| 144 | async move { todo!() } | ||
| 145 | } | ||
| 126 | 146 | ||
| 127 | pub fn send_receive<'a>( | 147 | fn read_write<'a>( |
| 128 | mut self: Pin<&'a mut Self>, | 148 | mut self: Pin<&'a mut Self>, |
| 129 | tx: &'a [u8], | ||
| 130 | rx: &'a mut [u8], | 149 | rx: &'a mut [u8], |
| 131 | ) -> impl Future<Output = Result<(), Error>> + 'a { | 150 | tx: &'a [u8], |
| 151 | ) -> Self::WriteReadFuture<'a> { | ||
| 132 | async move { | 152 | async move { |
| 133 | slice_in_ram_or(tx, Error::DMABufferNotInDataMemory)?; | ||
| 134 | slice_in_ram_or(rx, Error::DMABufferNotInDataMemory)?; | 153 | slice_in_ram_or(rx, Error::DMABufferNotInDataMemory)?; |
| 154 | slice_in_ram_or(tx, Error::DMABufferNotInDataMemory)?; | ||
| 135 | 155 | ||
| 136 | self.as_mut().inner().with(|s, _irq| { | 156 | self.as_mut().inner().with(|s, _irq| { |
| 137 | // Conservative compiler fence to prevent optimizations that do not | 157 | // Conservative compiler fence to prevent optimizations that do not |
