2022-07-28 11:43:49 +00:00
|
|
|
//! Blinks the LED on a Pico board
|
|
|
|
//!
|
|
|
|
//! This will blink an LED attached to GP25, which is the pin the Pico uses for the on-board LED.
|
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
use bsp::entry;
|
|
|
|
use defmt::*;
|
|
|
|
use defmt_rtt as _;
|
|
|
|
use embedded_hal::digital::v2::OutputPin;
|
|
|
|
use embedded_time::fixed_point::FixedPoint;
|
|
|
|
use panic_probe as _;
|
|
|
|
|
|
|
|
// Provide an alias for our BSP so we can switch targets quickly.
|
|
|
|
// Uncomment the BSP you included in Cargo.toml, the rest of the code does not need to change.
|
|
|
|
use rp_pico as bsp;
|
|
|
|
// use sparkfun_pro_micro_rp2040 as bsp;
|
|
|
|
|
|
|
|
use bsp::hal::{
|
|
|
|
clocks::{init_clocks_and_plls, Clock},
|
|
|
|
pac,
|
|
|
|
sio::Sio,
|
|
|
|
watchdog::Watchdog,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
info!("Program start");
|
2022-10-23 12:44:11 +00:00
|
|
|
|
2022-07-28 11:43:49 +00:00
|
|
|
let mut pac = pac::Peripherals::take().unwrap();
|
|
|
|
let core = pac::CorePeripherals::take().unwrap();
|
|
|
|
let mut watchdog = Watchdog::new(pac.WATCHDOG);
|
|
|
|
|
|
|
|
// External high-speed crystal on the pico board is 12Mhz
|
|
|
|
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();
|
|
|
|
|
2022-10-23 12:44:11 +00:00
|
|
|
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
|
|
|
|
|
|
|
let sio = Sio::new(pac.SIO);
|
2022-07-28 11:43:49 +00:00
|
|
|
|
|
|
|
let pins = bsp::Pins::new(
|
|
|
|
pac.IO_BANK0,
|
|
|
|
pac.PADS_BANK0,
|
|
|
|
sio.gpio_bank0,
|
|
|
|
&mut pac.RESETS,
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut led_pin = pins.led.into_push_pull_output();
|
|
|
|
|
|
|
|
loop {
|
|
|
|
info!("on!");
|
|
|
|
led_pin.set_high().unwrap();
|
2022-10-23 12:44:11 +00:00
|
|
|
|
2022-07-28 11:43:49 +00:00
|
|
|
delay.delay_ms(200);
|
2022-10-23 12:44:11 +00:00
|
|
|
|
2022-07-28 11:43:49 +00:00
|
|
|
info!("off!");
|
|
|
|
led_pin.set_low().unwrap();
|
2022-10-23 12:44:11 +00:00
|
|
|
|
2022-07-28 11:43:49 +00:00
|
|
|
delay.delay_ms(200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// End of file
|