diff options
| author | James Munns <[email protected]> | 2025-12-11 15:34:38 +0100 |
|---|---|---|
| committer | James Munns <[email protected]> | 2025-12-11 15:34:38 +0100 |
| commit | efdfb3c0892f45223e8d8527e5f032fef475944e (patch) | |
| tree | 1dbcae8f17a065bb307d4a95a330c6413571c0ac /examples/mcxa/src/bin/adc_interrupt.rs | |
| parent | e932dc131e94f30db32b3fc9fbce8cd929555820 (diff) | |
Refactor the API
Diffstat (limited to 'examples/mcxa/src/bin/adc_interrupt.rs')
| -rw-r--r-- | examples/mcxa/src/bin/adc_interrupt.rs | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/examples/mcxa/src/bin/adc_interrupt.rs b/examples/mcxa/src/bin/adc_interrupt.rs index 5876923a1..d2cda631c 100644 --- a/examples/mcxa/src/bin/adc_interrupt.rs +++ b/examples/mcxa/src/bin/adc_interrupt.rs | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 5 | use embassy_time::{Duration, Ticker}; | ||
| 5 | use hal::adc::{Adc, InterruptHandler, LpadcConfig, TriggerPriorityPolicy}; | 6 | use hal::adc::{Adc, InterruptHandler, LpadcConfig, TriggerPriorityPolicy}; |
| 6 | use hal::bind_interrupts; | 7 | use hal::bind_interrupts; |
| 7 | use hal::clocks::PoweredClock; | 8 | use hal::clocks::PoweredClock; |
| @@ -9,9 +10,8 @@ use hal::clocks::config::Div8; | |||
| 9 | use hal::clocks::periph_helpers::{AdcClockSel, Div4}; | 10 | use hal::clocks::periph_helpers::{AdcClockSel, Div4}; |
| 10 | use hal::config::Config; | 11 | use hal::config::Config; |
| 11 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; | 12 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; |
| 12 | use hal::pac::adc1::cmdl1::{Adch, Mode}; | 13 | use hal::pac::adc1::cmdl1::Mode; |
| 13 | use hal::pac::adc1::ctrl::CalAvgs; | 14 | use hal::pac::adc1::ctrl::CalAvgs; |
| 14 | use hal::pac::adc1::tctrl::Tcmd; | ||
| 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 | ||
| @@ -38,7 +38,6 @@ async fn main(_spawner: Spawner) { | |||
| 38 | trigger_priority_policy: TriggerPriorityPolicy::ConvPreemptImmediatelyNotAutoResumed, | 38 | trigger_priority_policy: TriggerPriorityPolicy::ConvPreemptImmediatelyNotAutoResumed, |
| 39 | enable_conv_pause: false, | 39 | enable_conv_pause: false, |
| 40 | conv_pause_delay: 0, | 40 | conv_pause_delay: 0, |
| 41 | fifo_watermark: 0, | ||
| 42 | power: PoweredClock::NormalEnabledDeepSleepDisabled, | 41 | power: PoweredClock::NormalEnabledDeepSleepDisabled, |
| 43 | source: AdcClockSel::FroLfDiv, | 42 | source: AdcClockSel::FroLfDiv, |
| 44 | div: Div4::no_div(), | 43 | div: Div4::no_div(), |
| @@ -47,23 +46,16 @@ async fn main(_spawner: Spawner) { | |||
| 47 | 46 | ||
| 48 | adc.do_offset_calibration(); | 47 | adc.do_offset_calibration(); |
| 49 | adc.do_auto_calibration(); | 48 | adc.do_auto_calibration(); |
| 50 | 49 | adc.set_resolution(Mode::Data16Bits); | |
| 51 | let mut conv_command_config = adc.get_default_conv_command_config(); | ||
| 52 | conv_command_config.channel_number = Adch::SelectCorrespondingChannel8; | ||
| 53 | conv_command_config.conversion_resolution_mode = Mode::Data16Bits; | ||
| 54 | adc.set_conv_command_config(1, &conv_command_config).unwrap(); | ||
| 55 | |||
| 56 | let mut conv_trigger_config = adc.get_default_conv_trigger_config(); | ||
| 57 | conv_trigger_config.target_command_id = Tcmd::ExecuteCmd1; | ||
| 58 | conv_trigger_config.enable_hardware_trigger = false; | ||
| 59 | adc.set_conv_trigger_config(0, &conv_trigger_config); | ||
| 60 | 50 | ||
| 61 | defmt::info!("ADC configuration done..."); | 51 | defmt::info!("ADC configuration done..."); |
| 52 | let mut ticker = Ticker::every(Duration::from_millis(100)); | ||
| 62 | 53 | ||
| 63 | loop { | 54 | loop { |
| 55 | ticker.next().await; | ||
| 64 | match adc.read().await { | 56 | match adc.read().await { |
| 65 | Ok(value) => { | 57 | Ok(value) => { |
| 66 | defmt::info!("*** ADC interrupt TRIGGERED! *** -- value: {}", value); | 58 | defmt::info!("ADC value: {}", value); |
| 67 | } | 59 | } |
| 68 | Err(e) => { | 60 | Err(e) => { |
| 69 | defmt::error!("ADC read error: {:?}", e); | 61 | defmt::error!("ADC read error: {:?}", e); |
