Improve gpout example, clk_gpout_freq
This commit is contained in:
parent
c1eaad41f3
commit
5015c845c5
3 changed files with 26 additions and 10 deletions
|
@ -544,9 +544,9 @@ pub fn clk_rtc_freq() -> u32 {
|
|||
base / int
|
||||
}
|
||||
|
||||
pub fn clk_gpout_freq(num: usize) -> u32 {
|
||||
pub fn clk_gpout_freq<T: GpoutPin>(gpout: &Gpout<T>) -> u32 {
|
||||
let c = pac::CLOCKS;
|
||||
let src = unsafe { c.clk_gpout_ctrl(num).read().auxsrc() };
|
||||
let src = unsafe { c.clk_gpout_ctrl(gpout.gpout.gpout_number()).read().auxsrc() };
|
||||
|
||||
let base = match src {
|
||||
ClkGpoutCtrlAuxsrc::CLKSRC_PLL_SYS => pll_sys_freq(),
|
||||
|
@ -563,7 +563,7 @@ pub fn clk_gpout_freq(num: usize) -> u32 {
|
|||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let div = unsafe { c.clk_gpout_div(num).read() };
|
||||
let div = unsafe { c.clk_gpout_div(gpout.gpout.gpout_number()).read() };
|
||||
let int = if div.int() == 0 { 65536 } else { div.int() };
|
||||
// TODO handle fractional clock div
|
||||
let _frac = div.frac();
|
||||
|
@ -759,7 +759,7 @@ impl<'d, T: GpoutPin> Gpout<'d, T> {
|
|||
unsafe {
|
||||
let c = pac::CLOCKS;
|
||||
c.clk_gpout_ctrl(self.gpout.gpout_number()).modify(|w| {
|
||||
w.set_enable(true);
|
||||
w.set_enable(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,3 +48,6 @@ pio = "0.2.1"
|
|||
|
||||
[profile.release]
|
||||
debug = true
|
||||
|
||||
[patch.crates-io]
|
||||
rp-pac = {git = "https://github.com/CBJamo/rp-pac.git"}
|
||||
|
|
|
@ -5,17 +5,30 @@
|
|||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::{clocks, pac};
|
||||
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 mut led = Output::new(p.PIN_25, Level::Low);
|
||||
|
||||
let gpout0 = clocks::Gpout0::new(p.PIN_21);
|
||||
gpout0.set_src(pac::clocks::vals::ClkGpout0ctrlAuxsrc::CLK_SYS);
|
||||
gpout0.set_div(1000, 0);
|
||||
gpout0.enable();
|
||||
let gpout3 = clocks::Gpout::new(p.PIN_25);
|
||||
gpout3.set_div(1000, 0);
|
||||
gpout3.enable();
|
||||
|
||||
info!("Pin 21 should be toggling at {} hz", clocks::clk_gpout0_freq());
|
||||
loop {
|
||||
gpout3.set_src(pac::clocks::vals::ClkGpoutCtrlAuxsrc::CLK_SYS);
|
||||
info!(
|
||||
"Pin 25 is now outputing CLK_SYS/1000, should be toggling at {}",
|
||||
clocks::clk_gpout_freq(&gpout3)
|
||||
);
|
||||
Timer::after(Duration::from_secs(2)).await;
|
||||
|
||||
gpout3.set_src(pac::clocks::vals::ClkGpoutCtrlAuxsrc::CLK_REF);
|
||||
info!(
|
||||
"Pin 25 is now outputing CLK_REF/1000, should be toggling at {}",
|
||||
clocks::clk_gpout_freq(&gpout3)
|
||||
);
|
||||
Timer::after(Duration::from_secs(2)).await;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue