aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/adc/v2.rs7
-rw-r--r--embassy-stm32/src/adc/v3.rs15
-rw-r--r--embassy-stm32/src/adc/v4.rs9
3 files changed, 12 insertions, 19 deletions
diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs
index 30ac5d872..2cdaa00dc 100644
--- a/embassy-stm32/src/adc/v2.rs
+++ b/embassy-stm32/src/adc/v2.rs
@@ -94,7 +94,6 @@ impl Prescaler {
94 94
95pub struct Adc<'d, T: Instance> { 95pub struct Adc<'d, T: Instance> {
96 sample_time: SampleTime, 96 sample_time: SampleTime,
97 resolution: Resolution,
98 phantom: PhantomData<&'d mut T>, 97 phantom: PhantomData<&'d mut T>,
99} 98}
100 99
@@ -120,7 +119,6 @@ where
120 119
121 Self { 120 Self {
122 sample_time: Default::default(), 121 sample_time: Default::default(),
123 resolution: Resolution::default(),
124 phantom: PhantomData, 122 phantom: PhantomData,
125 } 123 }
126 } 124 }
@@ -130,7 +128,9 @@ where
130 } 128 }
131 129
132 pub fn set_resolution(&mut self, resolution: Resolution) { 130 pub fn set_resolution(&mut self, resolution: Resolution) {
133 self.resolution = resolution; 131 unsafe {
132 T::regs().cr1().modify(|reg| reg.set_res(resolution.into()));
133 }
134 } 134 }
135 135
136 /// Enables internal voltage reference and returns [VrefInt], which can be used in 136 /// Enables internal voltage reference and returns [VrefInt], which can be used in
@@ -214,7 +214,6 @@ where
214 214
215 unsafe fn read_channel(&mut self, channel: u8) -> u16 { 215 unsafe fn read_channel(&mut self, channel: u8) -> u16 {
216 // Configure ADC 216 // Configure ADC
217 T::regs().cr1().modify(|reg| reg.set_res(self.resolution.into()));
218 217
219 // Select channel 218 // Select channel
220 T::regs().sqr3().write(|reg| reg.set_sq(0, channel)); 219 T::regs().sqr3().write(|reg| reg.set_sq(0, channel));
diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs
index 7962f2414..c6898f54a 100644
--- a/embassy-stm32/src/adc/v3.rs
+++ b/embassy-stm32/src/adc/v3.rs
@@ -62,7 +62,6 @@ impl<T: Instance> super::sealed::AdcPin<T> for Vbat {
62 62
63pub struct Adc<'d, T: Instance> { 63pub struct Adc<'d, T: Instance> {
64 sample_time: SampleTime, 64 sample_time: SampleTime,
65 resolution: Resolution,
66 phantom: PhantomData<&'d mut T>, 65 phantom: PhantomData<&'d mut T>,
67} 66}
68 67
@@ -99,7 +98,6 @@ impl<'d, T: Instance> Adc<'d, T> {
99 98
100 Self { 99 Self {
101 sample_time: Default::default(), 100 sample_time: Default::default(),
102 resolution: Resolution::default(),
103 phantom: PhantomData, 101 phantom: PhantomData,
104 } 102 }
105 } 103 }
@@ -145,7 +143,12 @@ impl<'d, T: Instance> Adc<'d, T> {
145 } 143 }
146 144
147 pub fn set_resolution(&mut self, resolution: Resolution) { 145 pub fn set_resolution(&mut self, resolution: Resolution) {
148 self.resolution = resolution; 146 unsafe {
147 #[cfg(not(stm32g0))]
148 T::regs().cfgr().modify(|reg| reg.set_res(resolution.into()));
149 #[cfg(stm32g0)]
150 T::regs().cfgr1().modify(|reg| reg.set_res(resolution.into()));
151 }
149 } 152 }
150 153
151 /* 154 /*
@@ -197,12 +200,6 @@ impl<'d, T: Instance> Adc<'d, T> {
197 // spin 200 // spin
198 } 201 }
199 202
200 // Configure ADC
201 #[cfg(not(stm32g0))]
202 T::regs().cfgr().modify(|reg| reg.set_res(self.resolution.into()));
203 #[cfg(stm32g0)]
204 T::regs().cfgr1().modify(|reg| reg.set_res(self.resolution.into()));
205
206 // Configure channel 203 // Configure channel
207 Self::set_channel_sample_time(pin.channel(), self.sample_time); 204 Self::set_channel_sample_time(pin.channel(), self.sample_time);
208 205
diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs
index dc5f62d3c..750f3480f 100644
--- a/embassy-stm32/src/adc/v4.rs
+++ b/embassy-stm32/src/adc/v4.rs
@@ -227,7 +227,6 @@ impl Prescaler {
227 227
228pub struct Adc<'d, T: Instance> { 228pub struct Adc<'d, T: Instance> {
229 sample_time: SampleTime, 229 sample_time: SampleTime,
230 resolution: Resolution,
231 phantom: PhantomData<&'d mut T>, 230 phantom: PhantomData<&'d mut T>,
232} 231}
233 232
@@ -264,7 +263,6 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> {
264 263
265 let mut s = Self { 264 let mut s = Self {
266 sample_time: Default::default(), 265 sample_time: Default::default(),
267 resolution: Resolution::default(),
268 phantom: PhantomData, 266 phantom: PhantomData,
269 }; 267 };
270 s.power_up(delay); 268 s.power_up(delay);
@@ -367,7 +365,9 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> {
367 } 365 }
368 366
369 pub fn set_resolution(&mut self, resolution: Resolution) { 367 pub fn set_resolution(&mut self, resolution: Resolution) {
370 self.resolution = resolution; 368 unsafe {
369 T::regs().cfgr().modify(|reg| reg.set_res(resolution.into()));
370 }
371 } 371 }
372 372
373 /// Perform a single conversion. 373 /// Perform a single conversion.
@@ -408,9 +408,6 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> {
408 } 408 }
409 409
410 unsafe fn read_channel(&mut self, channel: u8) -> u16 { 410 unsafe fn read_channel(&mut self, channel: u8) -> u16 {
411 // Configure ADC
412 T::regs().cfgr().modify(|reg| reg.set_res(self.resolution.into()));
413
414 // Configure channel 411 // Configure channel
415 Self::set_channel_sample_time(channel, self.sample_time); 412 Self::set_channel_sample_time(channel, self.sample_time);
416 413