diff options
Diffstat (limited to 'embassy-mcxa/src')
| -rw-r--r-- | embassy-mcxa/src/adc.rs | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/embassy-mcxa/src/adc.rs b/embassy-mcxa/src/adc.rs index abcdf86f8..6500754ba 100644 --- a/embassy-mcxa/src/adc.rs +++ b/embassy-mcxa/src/adc.rs | |||
| @@ -10,7 +10,7 @@ use maitake_sync::WaitCell; | |||
| 10 | use paste::paste; | 10 | use paste::paste; |
| 11 | 11 | ||
| 12 | use crate::clocks::periph_helpers::{AdcClockSel, AdcConfig, Div4}; | 12 | use crate::clocks::periph_helpers::{AdcClockSel, AdcConfig, Div4}; |
| 13 | use crate::clocks::{Gate, PoweredClock, enable_and_reset, ClockError}; | 13 | use crate::clocks::{ClockError, Gate, PoweredClock, enable_and_reset}; |
| 14 | 14 | ||
| 15 | use crate::pac::adc1::cfg::{HptExdi, Pwrsel, Refsel, Tcmdres, Tprictrl, Tres}; | 15 | use crate::pac::adc1::cfg::{HptExdi, Pwrsel, Refsel, Tcmdres, Tprictrl, Tres}; |
| 16 | use crate::pac::adc1::cmdh1::{Avgs, Cmpen, Next, Sts}; | 16 | use crate::pac::adc1::cmdh1::{Avgs, Cmpen, Next, Sts}; |
| @@ -18,7 +18,6 @@ use crate::pac::adc1::cmdl1::{Adch, Mode}; | |||
| 18 | use crate::pac::adc1::ctrl::CalAvgs; | 18 | use crate::pac::adc1::ctrl::CalAvgs; |
| 19 | use crate::pac::adc1::tctrl::{Tcmd, Tpri}; | 19 | use crate::pac::adc1::tctrl::{Tcmd, Tpri}; |
| 20 | 20 | ||
| 21 | |||
| 22 | const G_LPADC_RESULT_SHIFT: u32 = 0; | 21 | const G_LPADC_RESULT_SHIFT: u32 = 0; |
| 23 | 22 | ||
| 24 | /// Trigger priority policy for ADC conversions. | 23 | /// Trigger priority policy for ADC conversions. |
| @@ -166,12 +165,7 @@ impl<'a, I: Instance> Adc<'a, I, Blocking> { | |||
| 166 | /// * `_inst` - ADC peripheral instance | 165 | /// * `_inst` - ADC peripheral instance |
| 167 | /// * `pin` - GPIO pin to use for ADC | 166 | /// * `pin` - GPIO pin to use for ADC |
| 168 | /// * `config` - ADC configuration | 167 | /// * `config` - ADC configuration |
| 169 | pub fn new_blocking( | 168 | pub fn new_blocking(_inst: Peri<'a, I>, pin: Peri<'a, impl AdcPin<I>>, config: LpadcConfig) -> Result<Self> { |
| 170 | _inst: Peri<'a, I>, | ||
| 171 | pin: Peri<'a, | ||
| 172 | impl AdcPin<I>>, | ||
| 173 | config: LpadcConfig | ||
| 174 | ) -> Result<Self> { | ||
| 175 | Self::new_inner(_inst, pin, config) | 169 | Self::new_inner(_inst, pin, config) |
| 176 | } | 170 | } |
| 177 | } | 171 | } |
| @@ -223,23 +217,19 @@ impl<'a, I: Instance> Adc<'a, I, Async> { | |||
| 223 | } | 217 | } |
| 224 | } | 218 | } |
| 225 | 219 | ||
| 226 | |||
| 227 | |||
| 228 | impl<'a, I: Instance, M: ModeAdc> Adc<'a, I, M> { | 220 | impl<'a, I: Instance, M: ModeAdc> Adc<'a, I, M> { |
| 229 | /// Internal initialization function shared by `new_async` and `new_blocking`. | 221 | /// Internal initialization function shared by `new_async` and `new_blocking`. |
| 230 | fn new_inner( | 222 | fn new_inner(_inst: Peri<'a, I>, pin: Peri<'a, impl AdcPin<I>>, config: LpadcConfig) -> Result<Self> { |
| 231 | _inst: Peri<'a, I>, | ||
| 232 | pin: Peri<'a, impl AdcPin<I>>, | ||
| 233 | config: LpadcConfig | ||
| 234 | ) -> Result<Self> { | ||
| 235 | let adc = I::ptr(); | 223 | let adc = I::ptr(); |
| 236 | 224 | ||
| 237 | _ = unsafe { enable_and_reset::<I>(&AdcConfig { | 225 | _ = unsafe { |
| 226 | enable_and_reset::<I>(&AdcConfig { | ||
| 238 | power: config.power, | 227 | power: config.power, |
| 239 | source: config.source, | 228 | source: config.source, |
| 240 | div: config.div, | 229 | div: config.div, |
| 241 | }) | 230 | }) |
| 242 | .map_err(Error::ClockSetup)? }; | 231 | .map_err(Error::ClockSetup)? |
| 232 | }; | ||
| 243 | 233 | ||
| 244 | pin.mux(); | 234 | pin.mux(); |
| 245 | 235 | ||
| @@ -324,9 +314,9 @@ impl<'a, I: Instance, M: ModeAdc> Adc<'a, I, M> { | |||
| 324 | // Enable ADC | 314 | // Enable ADC |
| 325 | adc.ctrl().modify(|_, w| w.adcen().enabled()); | 315 | adc.ctrl().modify(|_, w| w.adcen().enabled()); |
| 326 | 316 | ||
| 327 | Ok(Self { | 317 | Ok(Self { |
| 328 | _inst: PhantomData, | 318 | _inst: PhantomData, |
| 329 | _phantom: PhantomData, | 319 | _phantom: PhantomData, |
| 330 | }) | 320 | }) |
| 331 | } | 321 | } |
| 332 | 322 | ||
| @@ -435,7 +425,7 @@ impl<'a, I: Instance, M: ModeAdc> Adc<'a, I, M> { | |||
| 435 | /// # Arguments | 425 | /// # Arguments |
| 436 | /// * `index` - Command index | 426 | /// * `index` - Command index |
| 437 | /// * `config` - Command configuration | 427 | /// * `config` - Command configuration |
| 438 | /// | 428 | /// |
| 439 | /// # Returns | 429 | /// # Returns |
| 440 | /// * `Ok(())` if the command was configured successfully | 430 | /// * `Ok(())` if the command was configured successfully |
| 441 | /// * `Err(Error::InvalidConfig)` if the index is out of range | 431 | /// * `Err(Error::InvalidConfig)` if the index is out of range |
