2021-11-08 09:19:35 +11:00
|
|
|
//! # GPIO 'Blinky' Example
|
|
|
|
//!
|
2021-12-05 01:00:09 +11:00
|
|
|
//! Blinks the LED on a Adafruit itsy-bitsy RP2040 board
|
2021-11-08 09:19:35 +11:00
|
|
|
//!
|
|
|
|
//! It may need to be adapted to your particular board layout and/or pin assignment.
|
|
|
|
//!
|
2022-04-18 20:49:41 +10:00
|
|
|
//! See the `Cargo.toml` file for Copyright and license details.
|
2021-11-08 09:19:35 +11:00
|
|
|
|
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
// The macro for our start-up function
|
2022-04-10 21:54:56 +10:00
|
|
|
use adafruit_itsy_bitsy_rp2040::entry;
|
2021-11-08 09:19:35 +11:00
|
|
|
|
|
|
|
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
|
|
|
// be linked)
|
|
|
|
use panic_halt as _;
|
|
|
|
|
|
|
|
// Some traits we need
|
|
|
|
use embedded_hal::digital::v2::OutputPin;
|
|
|
|
use embedded_time::fixed_point::FixedPoint;
|
|
|
|
|
2021-12-21 08:28:00 +11:00
|
|
|
use adafruit_itsy_bitsy_rp2040::{
|
2021-12-05 01:00:09 +11:00
|
|
|
hal::{
|
|
|
|
clocks::{init_clocks_and_plls, Clock},
|
|
|
|
pac,
|
|
|
|
sio::Sio,
|
|
|
|
watchdog::Watchdog,
|
|
|
|
},
|
|
|
|
Pins, XOSC_CRYSTAL_FREQ,
|
|
|
|
};
|
2021-11-08 09:19:35 +11:00
|
|
|
|
2021-12-05 01:00:09 +11:00
|
|
|
use cortex_m::delay::Delay;
|
2021-11-08 09:19:35 +11:00
|
|
|
|
|
|
|
/// Entry point to our bare-metal application.
|
|
|
|
///
|
|
|
|
/// The `#[entry]` macro ensures the Cortex-M start-up code calls this function
|
|
|
|
/// as soon as all global variables are initialised.
|
|
|
|
///
|
|
|
|
/// The function configures the RP2040 peripherals, then toggles a GPIO pin in
|
|
|
|
/// an infinite loop. If there is an LED connected to that pin, it will blink.
|
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
// Grab our singleton objects
|
|
|
|
let mut pac = pac::Peripherals::take().unwrap();
|
|
|
|
let core = pac::CorePeripherals::take().unwrap();
|
|
|
|
|
|
|
|
// Set up the watchdog driver - needed by the clock setup code
|
2021-12-05 01:00:09 +11:00
|
|
|
let mut watchdog = Watchdog::new(pac.WATCHDOG);
|
2021-11-08 09:19:35 +11:00
|
|
|
|
|
|
|
// Configure the clocks
|
2021-12-05 01:00:09 +11:00
|
|
|
let clocks = init_clocks_and_plls(
|
|
|
|
XOSC_CRYSTAL_FREQ,
|
2021-11-08 09:19:35 +11:00
|
|
|
pac.XOSC,
|
|
|
|
pac.CLOCKS,
|
|
|
|
pac.PLL_SYS,
|
|
|
|
pac.PLL_USB,
|
|
|
|
&mut pac.RESETS,
|
|
|
|
&mut watchdog,
|
|
|
|
)
|
|
|
|
.ok()
|
|
|
|
.unwrap();
|
|
|
|
|
2021-12-05 01:00:09 +11:00
|
|
|
let mut delay = Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
2021-11-08 09:19:35 +11:00
|
|
|
|
|
|
|
// The single-cycle I/O block controls our GPIO pins
|
2021-12-05 01:00:09 +11:00
|
|
|
let sio = Sio::new(pac.SIO);
|
2021-11-08 09:19:35 +11:00
|
|
|
|
2021-12-05 01:00:09 +11:00
|
|
|
let pins = Pins::new(
|
2021-11-08 09:19:35 +11:00
|
|
|
pac.IO_BANK0,
|
|
|
|
pac.PADS_BANK0,
|
|
|
|
sio.gpio_bank0,
|
|
|
|
&mut pac.RESETS,
|
|
|
|
);
|
2021-12-05 01:00:09 +11:00
|
|
|
let mut led_pin = pins.d13.into_push_pull_output();
|
2021-11-08 09:19:35 +11:00
|
|
|
|
|
|
|
loop {
|
|
|
|
led_pin.set_high().unwrap();
|
|
|
|
delay.delay_ms(500);
|
|
|
|
led_pin.set_low().unwrap();
|
|
|
|
delay.delay_ms(500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// End of file
|