aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/mcxa/src/bin/clkout.rs85
1 files changed, 45 insertions, 40 deletions
diff --git a/examples/mcxa/src/bin/clkout.rs b/examples/mcxa/src/bin/clkout.rs
index 1e52912d3..ba7c8185e 100644
--- a/examples/mcxa/src/bin/clkout.rs
+++ b/examples/mcxa/src/bin/clkout.rs
@@ -4,6 +4,7 @@
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa::clkout::{ClockOut, ClockOutSel, Config, Div4}; 5use embassy_mcxa::clkout::{ClockOut, ClockOutSel, Config, Div4};
6use embassy_mcxa::clocks::PoweredClock; 6use embassy_mcxa::clocks::PoweredClock;
7use embassy_mcxa::clocks::config::{SoscConfig, SoscMode, SoscRange};
7use embassy_mcxa::gpio::{DriveStrength, Level, Output, SlewRate}; 8use embassy_mcxa::gpio::{DriveStrength, Level, Output, SlewRate};
8use embassy_time::Timer; 9use embassy_time::Timer;
9use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; 10use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
@@ -11,58 +12,62 @@ use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
11/// Demonstrate CLKOUT, using Pin P4.2 12/// Demonstrate CLKOUT, using Pin P4.2
12#[embassy_executor::main] 13#[embassy_executor::main]
13async fn main(_spawner: Spawner) { 14async fn main(_spawner: Spawner) {
14 let p = hal::init(hal::config::Config::default()); 15 let mut cfg = hal::config::Config::default();
16 cfg.clock_cfg.sosc = Some(SoscConfig {
17 mode: SoscMode::CrystalOscillator,
18 frequency: 8_000_000,
19 range: SoscRange::Mhz8To16,
20 power: PoweredClock::NormalEnabledDeepSleepDisabled,
21 });
22
23 let p = hal::init(cfg);
24
15 let mut pin = p.P4_2; 25 let mut pin = p.P4_2;
16 let mut clkout = p.CLKOUT; 26 let mut clkout = p.CLKOUT;
17 27
18 loop { 28 const K16_CONFIG: Config = Config {
19 defmt::info!("Set Low..."); 29 sel: ClockOutSel::Clk16K,
20 let mut output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); 30 div: Div4::no_div(),
21 Timer::after_millis(500).await; 31 level: PoweredClock::NormalEnabledDeepSleepDisabled,
32 };
33 const M4_CONFIG: Config = Config {
34 sel: ClockOutSel::Fro12M,
35 div: const { Div4::from_divisor(3).unwrap() },
36 level: PoweredClock::NormalEnabledDeepSleepDisabled,
37 };
38 const K512_CONFIG: Config = Config {
39 sel: ClockOutSel::ClkIn,
40 div: const { Div4::from_divisor(16).unwrap() },
41 level: PoweredClock::NormalEnabledDeepSleepDisabled,
42 };
22 43
44 let configs = [
45 ("16K -> /1 = 16K", K16_CONFIG),
46 ("12M -> /3 = 4M", M4_CONFIG),
47 ("8M -> /16 = 512K", K512_CONFIG),
48 ];
49
50 loop {
23 defmt::info!("Set High..."); 51 defmt::info!("Set High...");
24 output.set_high(); 52 let mut output = Output::new(pin.reborrow(), Level::High, DriveStrength::Normal, SlewRate::Slow);
25 Timer::after_millis(400).await; 53 Timer::after_millis(250).await;
26 54
27 defmt::info!("Set Low..."); 55 defmt::info!("Set Low...");
28 output.set_low(); 56 output.set_low();
29 Timer::after_millis(500).await; 57 Timer::after_millis(750).await;
30 58
31 defmt::info!("16k..."); 59 for (name, conf) in configs.iter() {
32 // Run Clock Out with the 16K clock 60 defmt::info!("Running {=str}", name);
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 61
44 Timer::after_millis(3000).await; 62 let _clock_out = ClockOut::new(clkout.reborrow(), pin.reborrow(), *conf).unwrap();
45
46 defmt::info!("Set Low...");
47 drop(_clock_out);
48 63
49 let _output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow); 64 Timer::after_millis(3000).await;
50 Timer::after_millis(500).await;
51 65
52 // Run Clock Out with the 12M clock, divided by 3 66 defmt::info!("Set Low...");
53 defmt::info!("4M..."); 67 drop(_clock_out);
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 68
65 // Let it run for 3 seconds... 69 let _output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow);
66 Timer::after_millis(3000).await; 70 Timer::after_millis(500).await;
71 }
67 } 72 }
68} 73}