2021-04-25 07:18:57 +10:00
|
|
|
//! Toggle LED based on GPIO input
|
|
|
|
//!
|
|
|
|
//! This will control an LED on GP25 based on a button hooked up to GP15. The button should be tied
|
|
|
|
//! to ground, as the input pin is pulled high internally by this example. When the button is
|
|
|
|
//! pressed, the LED will turn off.
|
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
use cortex_m_rt::entry;
|
2021-04-25 07:22:27 +10:00
|
|
|
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
2021-05-24 12:08:42 +10:00
|
|
|
use hal::pac;
|
|
|
|
use hal::sio::Sio;
|
2021-04-25 07:22:27 +10:00
|
|
|
use panic_halt as _;
|
2021-05-24 12:08:42 +10:00
|
|
|
use rp2040_hal as hal;
|
2021-04-25 07:18:57 +10:00
|
|
|
|
|
|
|
#[link_section = ".boot2"]
|
|
|
|
#[used]
|
|
|
|
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER;
|
|
|
|
|
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
2021-05-24 12:08:42 +10:00
|
|
|
let mut pac = pac::Peripherals::take().unwrap();
|
2021-04-25 07:18:57 +10:00
|
|
|
|
2021-05-10 13:33:36 +10:00
|
|
|
let sio = Sio::new(pac.SIO);
|
2021-05-24 12:08:42 +10:00
|
|
|
let pins = hal::gpio::Pins::new(
|
|
|
|
pac.IO_BANK0,
|
|
|
|
pac.PADS_BANK0,
|
|
|
|
sio.gpio_bank0,
|
|
|
|
&mut pac.RESETS,
|
|
|
|
);
|
|
|
|
let mut led_pin = pins.gpio25.into_push_pull_output();
|
2021-07-26 20:24:58 +10:00
|
|
|
let button_pin = pins.gpio23.into_pull_down_input();
|
2021-04-25 07:18:57 +10:00
|
|
|
|
|
|
|
loop {
|
2021-07-26 20:24:58 +10:00
|
|
|
if button_pin.is_low().unwrap() {
|
2021-04-25 07:18:57 +10:00
|
|
|
led_pin.set_high().unwrap();
|
|
|
|
} else {
|
|
|
|
led_pin.set_low().unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|