aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-mcxa/src/adc.rs30
-rw-r--r--examples/mcxa/src/bin/adc_interrupt.rs11
-rw-r--r--examples/mcxa/src/bin/adc_polling.rs4
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;
10use paste::paste; 10use paste::paste;
11 11
12use crate::clocks::periph_helpers::{AdcClockSel, AdcConfig, Div4}; 12use crate::clocks::periph_helpers::{AdcClockSel, AdcConfig, Div4};
13use crate::clocks::{Gate, PoweredClock, enable_and_reset, ClockError}; 13use crate::clocks::{ClockError, Gate, PoweredClock, enable_and_reset};
14 14
15use crate::pac::adc1::cfg::{HptExdi, Pwrsel, Refsel, Tcmdres, Tprictrl, Tres}; 15use crate::pac::adc1::cfg::{HptExdi, Pwrsel, Refsel, Tcmdres, Tprictrl, Tres};
16use crate::pac::adc1::cmdh1::{Avgs, Cmpen, Next, Sts}; 16use crate::pac::adc1::cmdh1::{Avgs, Cmpen, Next, Sts};
@@ -18,7 +18,6 @@ use crate::pac::adc1::cmdl1::{Adch, Mode};
18use crate::pac::adc1::ctrl::CalAvgs; 18use crate::pac::adc1::ctrl::CalAvgs;
19use crate::pac::adc1::tctrl::{Tcmd, Tpri}; 19use crate::pac::adc1::tctrl::{Tcmd, Tpri};
20 20
21
22const G_LPADC_RESULT_SHIFT: u32 = 0; 21const 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
228impl<'a, I: Instance, M: ModeAdc> Adc<'a, I, M> { 220impl<'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
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use hal::adc::{Adc, LpadcConfig, TriggerPriorityPolicy, InterruptHandler}; 5use hal::adc::{Adc, InterruptHandler, LpadcConfig, TriggerPriorityPolicy};
6use hal::bind_interrupts;
6use hal::clocks::PoweredClock; 7use hal::clocks::PoweredClock;
7use hal::config::Config;
8use hal::clocks::config::Div8; 8use hal::clocks::config::Div8;
9use hal::clocks::periph_helpers::{AdcClockSel, Div4}; 9use hal::clocks::periph_helpers::{AdcClockSel, Div4};
10use hal::config::Config;
10use hal::pac::adc1::cfg::{Pwrsel, Refsel}; 11use hal::pac::adc1::cfg::{Pwrsel, Refsel};
11use hal::pac::adc1::cmdl1::{Adch, Mode}; 12use hal::pac::adc1::cmdl1::{Adch, Mode};
12use hal::pac::adc1::ctrl::CalAvgs; 13use hal::pac::adc1::ctrl::CalAvgs;
13use hal::pac::adc1::tctrl::Tcmd; 14use hal::pac::adc1::tctrl::Tcmd;
14use hal::bind_interrupts;
15use hal::peripherals::ADC1; 15use hal::peripherals::ADC1;
16use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; 16use {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]
24async fn main(_spawner: Spawner) { 23async 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 @@
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use hal::adc::{Adc, LpadcConfig, TriggerPriorityPolicy}; 5use hal::adc::{Adc, LpadcConfig, TriggerPriorityPolicy};
6use hal::clocks::PoweredClock; 6use hal::clocks::PoweredClock;
7use hal::config::Config;
8use hal::clocks::config::Div8; 7use hal::clocks::config::Div8;
9use hal::clocks::periph_helpers::{AdcClockSel, Div4}; 8use hal::clocks::periph_helpers::{AdcClockSel, Div4};
9use hal::config::Config;
10use hal::pac::adc1::cfg::{Pwrsel, Refsel}; 10use hal::pac::adc1::cfg::{Pwrsel, Refsel};
11use hal::pac::adc1::cmdl1::{Adch, Mode}; 11use hal::pac::adc1::cmdl1::{Adch, Mode};
12use hal::pac::adc1::ctrl::CalAvgs; 12use hal::pac::adc1::ctrl::CalAvgs;
@@ -19,7 +19,7 @@ const G_LPADC_RESULT_SHIFT: u32 = 0;
19async fn main(_spawner: Spawner) { 19async 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 ===");