45 lines
1 KiB
Rust
Executable file
45 lines
1 KiB
Rust
Executable file
#![no_main]
|
|
#![no_std]
|
|
|
|
extern crate panic_halt;
|
|
|
|
use cortex_m_rt::entry;
|
|
use hal::{pac, prelude::*, rcc::Config};
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let dp = pac::Peripherals::take().unwrap();
|
|
let cp = cortex_m::Peripherals::take().unwrap();
|
|
|
|
// Configure the clock.
|
|
let mut rcc = dp.RCC.freeze(Config::hsi16());
|
|
|
|
let gpioa = dp.GPIOA.split(&mut rcc);
|
|
let gpioc = dp.GPIOC.split(&mut rcc);
|
|
|
|
// Configure PA5 as output.
|
|
let mut led = gpioa.pa5.into_push_pull_output();
|
|
let button = gpioc.pc13.into_pull_down_input();
|
|
|
|
// Get the delay provider.
|
|
let mut _delay = cp.SYST.delay(rcc.clocks);
|
|
|
|
let mut is_on: bool;
|
|
let mut was_on: bool = false;
|
|
#[allow(unused_variables)] // it is used later??
|
|
let mut enable_led: bool = false;
|
|
|
|
loop {
|
|
is_on = button.is_low().unwrap();
|
|
if is_on != was_on {
|
|
enable_led ^= true;
|
|
}
|
|
if is_on {
|
|
led.set_high().unwrap();
|
|
} else {
|
|
led.set_low().unwrap();
|
|
}
|
|
|
|
was_on = is_on;
|
|
}
|
|
}
|