diff options
Diffstat (limited to 'examples/mcxa/src/bin/clkout.rs')
| -rw-r--r-- | examples/mcxa/src/bin/clkout.rs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/examples/mcxa/src/bin/clkout.rs b/examples/mcxa/src/bin/clkout.rs new file mode 100644 index 000000000..1e52912d3 --- /dev/null +++ b/examples/mcxa/src/bin/clkout.rs | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use embassy_executor::Spawner; | ||
| 5 | use embassy_mcxa::clkout::{ClockOut, ClockOutSel, Config, Div4}; | ||
| 6 | use embassy_mcxa::clocks::PoweredClock; | ||
| 7 | use embassy_mcxa::gpio::{DriveStrength, Level, Output, SlewRate}; | ||
| 8 | use embassy_time::Timer; | ||
| 9 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | ||
| 10 | |||
| 11 | /// Demonstrate CLKOUT, using Pin P4.2 | ||
| 12 | #[embassy_executor::main] | ||
| 13 | async fn main(_spawner: Spawner) { | ||
| 14 | let p = hal::init(hal::config::Config::default()); | ||
| 15 | let mut pin = p.P4_2; | ||
| 16 | let mut clkout = p.CLKOUT; | ||
| 17 | |||
| 18 | loop { | ||
| 19 | defmt::info!("Set Low..."); | ||
| 20 | let mut output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); | ||
| 21 | Timer::after_millis(500).await; | ||
| 22 | |||
| 23 | defmt::info!("Set High..."); | ||
| 24 | output.set_high(); | ||
| 25 | Timer::after_millis(400).await; | ||
| 26 | |||
| 27 | defmt::info!("Set Low..."); | ||
| 28 | output.set_low(); | ||
| 29 | Timer::after_millis(500).await; | ||
| 30 | |||
| 31 | defmt::info!("16k..."); | ||
| 32 | // Run Clock Out with the 16K clock | ||
| 33 | let _clock_out = ClockOut::new( | ||
| 34 | clkout.reborrow(), | ||
| 35 | pin.reborrow(), | ||
| 36 | Config { | ||
| 37 | sel: ClockOutSel::Clk16K, | ||
| 38 | div: Div4::no_div(), | ||
| 39 | level: PoweredClock::NormalEnabledDeepSleepDisabled, | ||
| 40 | }, | ||
| 41 | ) | ||
| 42 | .unwrap(); | ||
| 43 | |||
| 44 | Timer::after_millis(3000).await; | ||
| 45 | |||
| 46 | defmt::info!("Set Low..."); | ||
| 47 | drop(_clock_out); | ||
| 48 | |||
| 49 | let _output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); | ||
| 50 | Timer::after_millis(500).await; | ||
| 51 | |||
| 52 | // Run Clock Out with the 12M clock, divided by 3 | ||
| 53 | defmt::info!("4M..."); | ||
| 54 | let _clock_out = ClockOut::new( | ||
| 55 | clkout.reborrow(), | ||
| 56 | pin.reborrow(), | ||
| 57 | Config { | ||
| 58 | sel: ClockOutSel::Fro12M, | ||
| 59 | div: const { Div4::from_divisor(3).unwrap() }, | ||
| 60 | level: PoweredClock::NormalEnabledDeepSleepDisabled, | ||
| 61 | }, | ||
| 62 | ) | ||
| 63 | .unwrap(); | ||
| 64 | |||
| 65 | // Let it run for 3 seconds... | ||
| 66 | Timer::after_millis(3000).await; | ||
| 67 | } | ||
| 68 | } | ||
