aboutsummaryrefslogtreecommitdiff
path: root/examples/mcxa/src/bin/clkout.rs
diff options
context:
space:
mode:
authorRaul Alimbekov <[email protected]>2025-12-16 09:05:22 +0300
committerGitHub <[email protected]>2025-12-16 09:05:22 +0300
commitc9a04b4b732b7a3b696eb8223664c1a7942b1875 (patch)
tree6dbe5c02e66eed8d8762f13f95afd24f8db2b38c /examples/mcxa/src/bin/clkout.rs
parentcde24a3ef1117653ba5ed4184102b33f745782fb (diff)
parent5ae6e060ec1c90561719aabdc29d5b6e7b8b0a82 (diff)
Merge branch 'main' into main
Diffstat (limited to 'examples/mcxa/src/bin/clkout.rs')
-rw-r--r--examples/mcxa/src/bin/clkout.rs68
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
4use embassy_executor::Spawner;
5use embassy_mcxa::clkout::{ClockOut, ClockOutSel, Config, Div4};
6use embassy_mcxa::clocks::PoweredClock;
7use embassy_mcxa::gpio::{DriveStrength, Level, Output, SlewRate};
8use embassy_time::Timer;
9use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
10
11/// Demonstrate CLKOUT, using Pin P4.2
12#[embassy_executor::main]
13async 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}