aboutsummaryrefslogtreecommitdiff
path: root/examples/mcxa/src/bin/clkout.rs
blob: bfd963540755f582479f9c67e89fcf9a905ee459 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#![no_std]
#![no_main]

use embassy_executor::Spawner;
use embassy_mcxa::clkout::{ClockOut, ClockOutSel, Config, Div4};
use embassy_mcxa::clocks::PoweredClock;
use embassy_mcxa::gpio::{DriveStrength, SlewRate};
use embassy_mcxa::{Level, Output};
use embassy_time::Timer;
use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};

/// Demonstrate CLKOUT, using Pin P4.2
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
    let p = hal::init(hal::config::Config::default());
    let mut pin = p.P4_2;
    let mut clkout = p.CLKOUT;

    loop {
        defmt::info!("Set Low...");
        let mut output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow);
        Timer::after_millis(500).await;

        defmt::info!("Set High...");
        output.set_high();
        Timer::after_millis(400).await;

        defmt::info!("Set Low...");
        output.set_low();
        Timer::after_millis(500).await;

        defmt::info!("16k...");
        // Run Clock Out with the 16K clock
        let _clock_out = ClockOut::new(
            clkout.reborrow(),
            pin.reborrow(),
            Config {
                sel: ClockOutSel::Clk16K,
                div: Div4::no_div(),
                level: PoweredClock::NormalEnabledDeepSleepDisabled,
            },
        )
        .unwrap();

        Timer::after_millis(3000).await;

        defmt::info!("Set Low...");
        drop(_clock_out);

        let _output = Output::new(pin.reborrow(), Level::Low, DriveStrength::Normal, SlewRate::Slow);
        Timer::after_millis(500).await;

        // Run Clock Out with the 12M clock, divided by 3
        defmt::info!("4M...");
        let _clock_out = ClockOut::new(
            clkout.reborrow(),
            pin.reborrow(),
            Config {
                sel: ClockOutSel::Fro12M,
                div: const { Div4::from_divisor(3).unwrap() },
                level: PoweredClock::NormalEnabledDeepSleepDisabled,
            },
        )
        .unwrap();

        // Let it run for 3 seconds...
        Timer::after_millis(3000).await;
    }
}