diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-05-19 20:29:46 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-05-19 20:29:46 +0200 |
| commit | 22e6a35598ec91b0ef56b2292f842c371ba85b1e (patch) | |
| tree | 379ce797c4d4bda83048160206c12ecdce666f61 | |
| parent | 211fdb6e84462a84a79dc758301839659ef4a7c3 (diff) | |
| parent | e3ab02c7e3e6d3769147900645651dc99664566e (diff) | |
Merge pull request #194 from embassy-rs/saadc-unpin
nrf/saadc: remove Pin
| -rw-r--r-- | embassy-nrf/src/saadc.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 33dab8d1a..65276a309 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | use core::future::Future; | 1 | use core::future::Future; |
| 2 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 3 | use core::pin::Pin; | ||
| 4 | use core::sync::atomic::{compiler_fence, Ordering}; | 3 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 5 | use core::task::Poll; | 4 | use core::task::Poll; |
| 6 | use embassy::util::{wake_on_interrupt, Unborrow}; | 5 | use embassy::util::{wake_on_interrupt, Unborrow}; |
| @@ -138,17 +137,16 @@ pub trait Sample { | |||
| 138 | where | 137 | where |
| 139 | Self: 'a; | 138 | Self: 'a; |
| 140 | 139 | ||
| 141 | fn sample<'a>(self: Pin<&'a mut Self>) -> Self::SampleFuture<'a>; | 140 | fn sample<'a>(&'a mut self) -> Self::SampleFuture<'a>; |
| 142 | } | 141 | } |
| 143 | 142 | ||
| 144 | impl<'d, T: PositivePin> Sample for OneShot<'d, T> { | 143 | impl<'d, T: PositivePin> Sample for OneShot<'d, T> { |
| 145 | #[rustfmt::skip] | 144 | #[rustfmt::skip] |
| 146 | type SampleFuture<'a> where Self: 'a = impl Future<Output = i16> + 'a; | 145 | type SampleFuture<'a> where Self: 'a = impl Future<Output = i16> + 'a; |
| 147 | 146 | ||
| 148 | fn sample<'a>(self: Pin<&'a mut Self>) -> Self::SampleFuture<'a> { | 147 | fn sample<'a>(&'a mut self) -> Self::SampleFuture<'a> { |
| 149 | async move { | 148 | async move { |
| 150 | let this = unsafe { self.get_unchecked_mut() }; | 149 | let r = self.regs(); |
| 151 | let r = this.regs(); | ||
| 152 | 150 | ||
| 153 | // Set up the DMA | 151 | // Set up the DMA |
| 154 | let mut val: i16 = 0; | 152 | let mut val: i16 = 0; |
| @@ -161,7 +159,7 @@ impl<'d, T: PositivePin> Sample for OneShot<'d, T> { | |||
| 161 | r.events_end.reset(); | 159 | r.events_end.reset(); |
| 162 | r.intenset.write(|w| w.end().set()); | 160 | r.intenset.write(|w| w.end().set()); |
| 163 | 161 | ||
| 164 | // Don't reorder the ADC start event before the previous writes. Hopefully this | 162 | // Don't reorder the ADC start event before the previous writes. Hopefully self |
| 165 | // wouldn't happen anyway. | 163 | // wouldn't happen anyway. |
| 166 | compiler_fence(Ordering::SeqCst); | 164 | compiler_fence(Ordering::SeqCst); |
| 167 | 165 | ||
| @@ -170,14 +168,14 @@ impl<'d, T: PositivePin> Sample for OneShot<'d, T> { | |||
| 170 | 168 | ||
| 171 | // Wait for 'end' event. | 169 | // Wait for 'end' event. |
| 172 | poll_fn(|cx| { | 170 | poll_fn(|cx| { |
| 173 | let r = this.regs(); | 171 | let r = self.regs(); |
| 174 | 172 | ||
| 175 | if r.events_end.read().bits() != 0 { | 173 | if r.events_end.read().bits() != 0 { |
| 176 | r.events_end.reset(); | 174 | r.events_end.reset(); |
| 177 | return Poll::Ready(()); | 175 | return Poll::Ready(()); |
| 178 | } | 176 | } |
| 179 | 177 | ||
| 180 | wake_on_interrupt(&mut this.irq, cx.waker()); | 178 | wake_on_interrupt(&mut self.irq, cx.waker()); |
| 181 | 179 | ||
| 182 | Poll::Pending | 180 | Poll::Pending |
| 183 | }) | 181 | }) |
