aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-nrf/src/saadc.rs30
1 files changed, 14 insertions, 16 deletions
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs
index c1afd00de..660096b4b 100644
--- a/embassy-nrf/src/saadc.rs
+++ b/embassy-nrf/src/saadc.rs
@@ -30,9 +30,9 @@ pub use saadc::{
30pub enum Error {} 30pub enum Error {}
31 31
32/// One-shot saadc. Continuous sample mode TODO. 32/// One-shot saadc. Continuous sample mode TODO.
33pub struct OneShot<'d, T: PositivePin> { 33pub struct OneShot<'d> {
34 irq: interrupt::SAADC, 34 irq: interrupt::SAADC,
35 phantom: PhantomData<(&'d mut peripherals::SAADC, &'d mut T)>, 35 phantom: PhantomData<(&'d mut peripherals::SAADC)>,
36} 36}
37 37
38/// Used to configure the SAADC peripheral. 38/// Used to configure the SAADC peripheral.
@@ -66,14 +66,13 @@ impl Default for Config {
66 } 66 }
67} 67}
68 68
69impl<'d, T: PositivePin> OneShot<'d, T> { 69impl<'d> OneShot<'d> {
70 pub fn new( 70 pub fn new(
71 _saadc: impl Unborrow<Target = peripherals::SAADC> + 'd, 71 _saadc: impl Unborrow<Target = peripherals::SAADC> + 'd,
72 irq: impl Unborrow<Target = interrupt::SAADC> + 'd, 72 irq: impl Unborrow<Target = interrupt::SAADC> + 'd,
73 positive_pin: impl Unborrow<Target = T> + 'd,
74 config: Config, 73 config: Config,
75 ) -> Self { 74 ) -> Self {
76 unborrow!(irq, positive_pin); 75 unborrow!(irq);
77 76
78 let r = unsafe { &*SAADC::ptr() }; 77 let r = unsafe { &*SAADC::ptr() };
79 78
@@ -106,11 +105,6 @@ impl<'d, T: PositivePin> OneShot<'d, T> {
106 w 105 w
107 }); 106 });
108 107
109 // Set positive channel
110 r.ch[0]
111 .pselp
112 .write(|w| w.pselp().variant(positive_pin.channel()));
113
114 // Disable all events interrupts 108 // Disable all events interrupts
115 r.intenclr.write(|w| unsafe { w.bits(0x003F_FFFF) }); 109 r.intenclr.write(|w| unsafe { w.bits(0x003F_FFFF) });
116 110
@@ -125,7 +119,7 @@ impl<'d, T: PositivePin> OneShot<'d, T> {
125 } 119 }
126} 120}
127 121
128impl<'d, T: PositivePin> Drop for OneShot<'d, T> { 122impl<'d> Drop for OneShot<'d> {
129 fn drop(&mut self) { 123 fn drop(&mut self) {
130 let r = self.regs(); 124 let r = self.regs();
131 r.enable.write(|w| w.enable().disabled()); 125 r.enable.write(|w| w.enable().disabled());
@@ -133,21 +127,25 @@ impl<'d, T: PositivePin> Drop for OneShot<'d, T> {
133} 127}
134 128
135pub trait Sample { 129pub trait Sample {
136 type SampleFuture<'a>: Future<Output = i16> + 'a 130 type SampleFuture<'a, T>: Future<Output = i16> + 'a
137 where 131 where
132 T: PositivePin + 'a,
138 Self: 'a; 133 Self: 'a;
139 134
140 fn sample<'a>(&'a mut self) -> Self::SampleFuture<'a>; 135 fn sample<'a, T: PositivePin>(&'a mut self, pin: &'a T) -> Self::SampleFuture<'a, T>;
141} 136}
142 137
143impl<'d, T: PositivePin> Sample for OneShot<'d, T> { 138impl<'d> Sample for OneShot<'d> {
144 #[rustfmt::skip] 139 #[rustfmt::skip]
145 type SampleFuture<'a> where Self: 'a = impl Future<Output = i16> + 'a; 140 type SampleFuture<'a, T> where Self: 'a, T: PositivePin + 'a = impl Future<Output = i16> + 'a;
146 141
147 fn sample<'a>(&'a mut self) -> Self::SampleFuture<'a> { 142 fn sample<'a, T: PositivePin>(&'a mut self, pin: &'a T) -> Self::SampleFuture<'a, T> {
148 async move { 143 async move {
149 let r = self.regs(); 144 let r = self.regs();
150 145
146 // Set positive channel
147 r.ch[0].pselp.write(|w| w.pselp().variant(pin.channel()));
148
151 // Set up the DMA 149 // Set up the DMA
152 let mut val: i16 = 0; 150 let mut val: i16 = 0;
153 r.result 151 r.result