#![deny(unsafe_code)]
#![no_main]
#![no_std]
extern crate panic_halt;
use rtfm::app;
use stm32l0xx_hal::{gpio::*, pac, prelude::*, rcc::Config, timer::Timer};
#[app(device = stm32l0xx_hal::pac)]
const APP: () = {
static mut LED: gpioa::PA1<Output<PushPull>> = ();
static mut TIMER: Timer<pac::TIM2> = ();
#[init]
fn init() -> init::LateResources {
let mut rcc = device.RCC.freeze(Config::hsi16());
let gpioa = device.GPIOA.split(&mut rcc);
let led = gpioa.pa1.into_push_pull_output();
let mut timer = device.TIM2.timer(1.hz(), &mut rcc);
timer.listen();
init::LateResources {
LED: led,
TIMER: timer,
}
}
#[interrupt(resources = [LED, TIMER])]
fn TIM2() {
static mut STATE: bool = false;
resources.TIMER.clear_irq();
if *STATE {
resources.LED.set_low().unwrap();
*STATE = false;
} else {
resources.LED.set_high().unwrap();
*STATE = true;
}
}
};