mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2024-12-24 21:21:31 +11:00
ffa97842e2
* Improve clock frequency stuff for uninitialized clocks - Made clocks singletons so the frequency handling actually works as expected - Added initial frequencies - Improved the docs - Added a Clock trait * Add pico examples. These have the benefit of knowing which external crystal is attached. Even though it always should be a 12 MHz crystal. Thus we can setup the clocks properly I also changed the rp2040 examples to work out of the box for pico boards since that will probably be used most of the time
78 lines
1.7 KiB
Rust
78 lines
1.7 KiB
Rust
//! Blinks the LED on a Pico board
|
|
//!
|
|
//! This will fade in/out the LED attached to GP25, which is the pin the Pico uses for the on-board LED.
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use cortex_m_rt::entry;
|
|
use embedded_hal::PwmPin;
|
|
use embedded_time::fixed_point::FixedPoint;
|
|
use panic_halt as _;
|
|
use pico::{
|
|
hal::{
|
|
clocks::{init_clocks_and_plls, Clock},
|
|
pac,
|
|
pwm::*,
|
|
watchdog::Watchdog,
|
|
},
|
|
XOSC_CRYSTAL_FREQ,
|
|
};
|
|
|
|
#[link_section = ".boot2"]
|
|
#[used]
|
|
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER;
|
|
|
|
const LOW: u16 = 0;
|
|
const HIGH: u16 = 25000;
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let mut pac = pac::Peripherals::take().unwrap();
|
|
let core = pac::CorePeripherals::take().unwrap();
|
|
|
|
let mut watchdog = Watchdog::new(pac.WATCHDOG);
|
|
|
|
let clocks = init_clocks_and_plls(
|
|
XOSC_CRYSTAL_FREQ,
|
|
pac.XOSC,
|
|
pac.CLOCKS,
|
|
pac.PLL_SYS,
|
|
pac.PLL_USB,
|
|
&mut pac.RESETS,
|
|
&mut watchdog,
|
|
)
|
|
.ok()
|
|
.unwrap();
|
|
|
|
let mut delay = cortex_m::delay::Delay::new(core.SYST, *clocks.system_clock.freq().integer());
|
|
|
|
let mut pwm_pin = Pwm4::new(25);
|
|
|
|
//Instead of having it take references to all of these pac objects, eventually this should just
|
|
//take ownership of a GPIO pin.
|
|
pwm_pin.default_config(
|
|
&mut pac.PWM,
|
|
&mut pac.PADS_BANK0,
|
|
&mut pac.IO_BANK0,
|
|
&mut pac.RESETS,
|
|
);
|
|
|
|
pwm_pin.set_ph_correct();
|
|
|
|
pwm_pin.enable();
|
|
|
|
loop {
|
|
for i in (LOW..=HIGH).skip(100) {
|
|
delay.delay_us(8);
|
|
pwm_pin.set_duty(i);
|
|
}
|
|
|
|
for i in (LOW..=HIGH).rev().skip(100) {
|
|
delay.delay_us(8);
|
|
pwm_pin.set_duty(i);
|
|
}
|
|
|
|
delay.delay_ms(500);
|
|
}
|
|
}
|