monorepo/pico-blink/src/main.rs

48 lines
1.3 KiB
Rust
Raw Normal View History

#![no_main]
#![no_std]
use rp_pico::entry;
use panic_halt as _;
use embedded_hal::digital::v2::OutputPin;
use rp_pico::{hal, hal::{clocks, pac, watchdog::Watchdog, clocks::{Clock, init_clocks_and_plls}}};
#[entry]
fn main() -> ! {
let mut pac = pac::Peripherals::take().unwrap();
let core = pac::CorePeripherals::take().unwrap();
let sio = hal::Sio::new(pac.SIO);
let mut watchdog = Watchdog::new(pac.WATCHDOG);
let pins = rp_pico::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);
let external_xtal_freq_hz = 12_000_000u32;
let clocks = init_clocks_and_plls(
external_xtal_freq_hz,
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().to_Hz());
let mut led_pin = pins.led.into_push_pull_output();
let mut blue_pin = pins.gpio3.into_push_pull_output();
led_pin.set_high().unwrap();
loop {
led_pin.set_high().unwrap();
blue_pin.set_low().unwrap();
delay.delay_ms(500);
led_pin.set_low().unwrap();
blue_pin.set_high().unwrap();
delay.delay_ms(500);
}
}