aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-10-07 02:15:19 +0200
committerGitHub <[email protected]>2021-10-07 02:15:19 +0200
commit009b77c1b9874cccb9b2f81876f41e9c3d53f3a5 (patch)
treed306fd81dc3813de7841067b665df24fcbc5a9e5
parenta816776cb5cd641b152d39ac69f50bf21b86b04d (diff)
parent0e05ba688d10c8a8dc60ac46bf241811fa17fc38 (diff)
Merge pull request #414 from embassy-rs/nrf-saadc-remove-trait
nrf/saadc: remove Sample trait.
-rw-r--r--embassy-nrf/src/saadc.rs22
-rw-r--r--examples/nrf/src/bin/saadc.rs2
2 files changed, 3 insertions, 21 deletions
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs
index e909e7d5a..b6e8f4e44 100644
--- a/embassy-nrf/src/saadc.rs
+++ b/embassy-nrf/src/saadc.rs
@@ -1,4 +1,3 @@
1use core::future::Future;
2use core::marker::PhantomData; 1use core::marker::PhantomData;
3use core::sync::atomic::{compiler_fence, Ordering}; 2use core::sync::atomic::{compiler_fence, Ordering};
4use core::task::Poll; 3use core::task::Poll;
@@ -129,11 +128,11 @@ impl<'d> OneShot<'d> {
129 unsafe { &*SAADC::ptr() } 128 unsafe { &*SAADC::ptr() }
130 } 129 }
131 130
132 async fn sample_inner(&mut self, pin: PositiveChannel) -> i16 { 131 pub async fn sample(&mut self, pin: &mut impl PositivePin) -> i16 {
133 let r = Self::regs(); 132 let r = Self::regs();
134 133
135 // Set positive channel 134 // Set positive channel
136 r.ch[0].pselp.write(|w| w.pselp().variant(pin)); 135 r.ch[0].pselp.write(|w| w.pselp().variant(pin.channel()));
137 136
138 // Set up the DMA 137 // Set up the DMA
139 let mut val: i16 = 0; 138 let mut val: i16 = 0;
@@ -180,23 +179,6 @@ impl<'d> Drop for OneShot<'d> {
180 } 179 }
181} 180}
182 181
183pub trait Sample {
184 type SampleFuture<'a>: Future<Output = i16> + 'a
185 where
186 Self: 'a;
187
188 fn sample<'a, T: PositivePin>(&'a mut self, pin: &mut T) -> Self::SampleFuture<'a>;
189}
190
191impl<'d> Sample for OneShot<'d> {
192 #[rustfmt::skip]
193 type SampleFuture<'a> where Self: 'a = impl Future<Output = i16> + 'a;
194
195 fn sample<'a, T: PositivePin>(&'a mut self, pin: &mut T) -> Self::SampleFuture<'a> {
196 self.sample_inner(pin.channel())
197 }
198}
199
200/// A pin that can be used as the positive end of a ADC differential in the SAADC periperhal. 182/// A pin that can be used as the positive end of a ADC differential in the SAADC periperhal.
201/// 183///
202/// Currently negative is always shorted to ground (0V). 184/// Currently negative is always shorted to ground (0V).
diff --git a/examples/nrf/src/bin/saadc.rs b/examples/nrf/src/bin/saadc.rs
index 311ffe2eb..c4d23360e 100644
--- a/examples/nrf/src/bin/saadc.rs
+++ b/examples/nrf/src/bin/saadc.rs
@@ -7,7 +7,7 @@ mod example_common;
7use defmt::panic; 7use defmt::panic;
8use embassy::executor::Spawner; 8use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer}; 9use embassy::time::{Duration, Timer};
10use embassy_nrf::saadc::{Config, OneShot, Sample}; 10use embassy_nrf::saadc::{Config, OneShot};
11use embassy_nrf::{interrupt, Peripherals}; 11use embassy_nrf::{interrupt, Peripherals};
12use example_common::*; 12use example_common::*;
13 13