aboutsummaryrefslogtreecommitdiff
path: root/examples/rp/src/bin/gpout.rs
blob: 0a3b5fa9845beebc107e0932d1788907144c2cd6 (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
//! This example shows how GPOUT (General purpose clock outputs) can toggle a output pin.
//!
//! The LED on the RP Pico W board is connected differently. Add a LED and resistor to another pin.

#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]

use defmt::*;
use embassy_executor::Spawner;
use embassy_rp::clocks;
use embassy_time::{Duration, Timer};
use {defmt_rtt as _, panic_probe as _};

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
    let p = embassy_rp::init(Default::default());

    let gpout3 = clocks::Gpout::new(p.PIN_25);
    gpout3.set_div(1000, 0);
    gpout3.enable();

    loop {
        gpout3.set_src(clocks::GpoutSrc::Sys);
        info!(
            "Pin 25 is now outputing CLK_SYS/1000, should be toggling at {}",
            gpout3.get_freq()
        );
        Timer::after(Duration::from_secs(2)).await;

        gpout3.set_src(clocks::GpoutSrc::Ref);
        info!(
            "Pin 25 is now outputing CLK_REF/1000, should be toggling at {}",
            gpout3.get_freq()
        );
        Timer::after(Duration::from_secs(2)).await;
    }
}