mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2024-12-25 13:31: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
42 lines
1 KiB
Rust
42 lines
1 KiB
Rust
//! 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;
|
|
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
|
use hal::pac;
|
|
use hal::sio::Sio;
|
|
use panic_halt as _;
|
|
use pico::{hal, Pins};
|
|
|
|
#[link_section = ".boot2"]
|
|
#[used]
|
|
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER;
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let mut pac = pac::Peripherals::take().unwrap();
|
|
|
|
let sio = Sio::new(pac.SIO);
|
|
let pins = Pins::new(
|
|
pac.IO_BANK0,
|
|
pac.PADS_BANK0,
|
|
sio.gpio_bank0,
|
|
&mut pac.RESETS,
|
|
);
|
|
let mut led_pin = pins.led.into_push_pull_output();
|
|
let button_pin = pins.bootsel.into_pull_down_input();
|
|
|
|
loop {
|
|
if button_pin.is_low().unwrap() {
|
|
led_pin.set_high().unwrap();
|
|
} else {
|
|
led_pin.set_low().unwrap();
|
|
}
|
|
}
|
|
}
|