diff options
| author | Mathis Deroo <[email protected]> | 2025-12-09 15:13:07 -0800 |
|---|---|---|
| committer | Mathis Deroo <[email protected]> | 2025-12-09 15:13:07 -0800 |
| commit | 4f0eb421de9e08bbbf7f9a58f8b29c451de59894 (patch) | |
| tree | 3443f4b877101a88e18a4eb4eada7627aa1e6365 | |
| parent | 06c16ca54dc846efa4b256620b4658a5b8378f81 (diff) | |
run rustfmt
Signed-off-by: Mathis Deroo <[email protected]>
| -rw-r--r-- | embassy-mcxa/src/adc.rs | 30 | ||||
| -rw-r--r-- | examples/mcxa/src/bin/adc_interrupt.rs | 11 | ||||
| -rw-r--r-- | examples/mcxa/src/bin/adc_polling.rs | 4 |
3 files changed, 17 insertions, 28 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 |
diff --git a/examples/mcxa/src/bin/adc_interrupt.rs b/examples/mcxa/src/bin/adc_interrupt.rs index 257e04491..5876923a1 100644 --- a/examples/mcxa/src/bin/adc_interrupt.rs +++ b/examples/mcxa/src/bin/adc_interrupt.rs | |||
| @@ -2,16 +2,16 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 5 | use hal::adc::{Adc, LpadcConfig, TriggerPriorityPolicy, InterruptHandler}; | 5 | use hal::adc::{Adc, InterruptHandler, LpadcConfig, TriggerPriorityPolicy}; |
| 6 | use hal::bind_interrupts; | ||
| 6 | use hal::clocks::PoweredClock; | 7 | use hal::clocks::PoweredClock; |
| 7 | use hal::config::Config; | ||
| 8 | use hal::clocks::config::Div8; | 8 | use hal::clocks::config::Div8; |
| 9 | use hal::clocks::periph_helpers::{AdcClockSel, Div4}; | 9 | use hal::clocks::periph_helpers::{AdcClockSel, Div4}; |
| 10 | use hal::config::Config; | ||
| 10 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; | 11 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; |
| 11 | use hal::pac::adc1::cmdl1::{Adch, Mode}; | 12 | use hal::pac::adc1::cmdl1::{Adch, Mode}; |
| 12 | use hal::pac::adc1::ctrl::CalAvgs; | 13 | use hal::pac::adc1::ctrl::CalAvgs; |
| 13 | use hal::pac::adc1::tctrl::Tcmd; | 14 | use hal::pac::adc1::tctrl::Tcmd; |
| 14 | use hal::bind_interrupts; | ||
| 15 | use hal::peripherals::ADC1; | 15 | use hal::peripherals::ADC1; |
| 16 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | 16 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; |
| 17 | 17 | ||
| @@ -19,12 +19,11 @@ bind_interrupts!(struct Irqs { | |||
| 19 | ADC1 => InterruptHandler<ADC1>; | 19 | ADC1 => InterruptHandler<ADC1>; |
| 20 | }); | 20 | }); |
| 21 | 21 | ||
| 22 | |||
| 23 | #[embassy_executor::main] | 22 | #[embassy_executor::main] |
| 24 | async fn main(_spawner: Spawner) { | 23 | async fn main(_spawner: Spawner) { |
| 25 | let mut config = Config::default(); | 24 | let mut config = Config::default(); |
| 26 | config.clock_cfg.sirc.fro_lf_div = Div8::from_divisor(1); | 25 | config.clock_cfg.sirc.fro_lf_div = Div8::from_divisor(1); |
| 27 | 26 | ||
| 28 | let p = hal::init(config); | 27 | let p = hal::init(config); |
| 29 | 28 | ||
| 30 | defmt::info!("ADC interrupt Example"); | 29 | defmt::info!("ADC interrupt Example"); |
| @@ -62,7 +61,7 @@ async fn main(_spawner: Spawner) { | |||
| 62 | defmt::info!("ADC configuration done..."); | 61 | defmt::info!("ADC configuration done..."); |
| 63 | 62 | ||
| 64 | loop { | 63 | loop { |
| 65 | match adc.read().await { | 64 | match adc.read().await { |
| 66 | Ok(value) => { | 65 | Ok(value) => { |
| 67 | defmt::info!("*** ADC interrupt TRIGGERED! *** -- value: {}", value); | 66 | defmt::info!("*** ADC interrupt TRIGGERED! *** -- value: {}", value); |
| 68 | } | 67 | } |
diff --git a/examples/mcxa/src/bin/adc_polling.rs b/examples/mcxa/src/bin/adc_polling.rs index b11b8957f..d048bb56f 100644 --- a/examples/mcxa/src/bin/adc_polling.rs +++ b/examples/mcxa/src/bin/adc_polling.rs | |||
| @@ -4,9 +4,9 @@ | |||
| 4 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 5 | use hal::adc::{Adc, LpadcConfig, TriggerPriorityPolicy}; | 5 | use hal::adc::{Adc, LpadcConfig, TriggerPriorityPolicy}; |
| 6 | use hal::clocks::PoweredClock; | 6 | use hal::clocks::PoweredClock; |
| 7 | use hal::config::Config; | ||
| 8 | use hal::clocks::config::Div8; | 7 | use hal::clocks::config::Div8; |
| 9 | use hal::clocks::periph_helpers::{AdcClockSel, Div4}; | 8 | use hal::clocks::periph_helpers::{AdcClockSel, Div4}; |
| 9 | use hal::config::Config; | ||
| 10 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; | 10 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; |
| 11 | use hal::pac::adc1::cmdl1::{Adch, Mode}; | 11 | use hal::pac::adc1::cmdl1::{Adch, Mode}; |
| 12 | use hal::pac::adc1::ctrl::CalAvgs; | 12 | use hal::pac::adc1::ctrl::CalAvgs; |
| @@ -19,7 +19,7 @@ const G_LPADC_RESULT_SHIFT: u32 = 0; | |||
| 19 | async fn main(_spawner: Spawner) { | 19 | async fn main(_spawner: Spawner) { |
| 20 | let mut config = Config::default(); | 20 | let mut config = Config::default(); |
| 21 | config.clock_cfg.sirc.fro_lf_div = Div8::from_divisor(1); | 21 | config.clock_cfg.sirc.fro_lf_div = Div8::from_divisor(1); |
| 22 | 22 | ||
| 23 | let p = hal::init(config); | 23 | let p = hal::init(config); |
| 24 | 24 | ||
| 25 | defmt::info!("=== ADC polling Example ==="); | 25 | defmt::info!("=== ADC polling Example ==="); |
