#![no_std]
#![no_main]
use panic_halt as _;
use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
use hal::timer::Error;
use stm32f4xx_hal as hal;
use crate::hal::{pac, prelude::*};
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let cp = cortex_m::peripheral::Peripherals::take().unwrap();
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.sysclk(24.MHz()).freeze();
let mut timer = cp.SYST.counter_us(&clocks);
timer.start(42.millis()).unwrap();
hprintln!("hello!");
nb::block!(timer.wait()).unwrap();
hprintln!("timer expired 1");
nb::block!(timer.wait()).unwrap();
hprintln!("timer expired 2");
timer.cancel().unwrap();
timer.start(42.millis()).unwrap();
nb::block!(timer.wait()).unwrap();
hprintln!("timer expired 3");
timer.cancel().unwrap();
let cancel_outcome = timer.cancel();
assert_eq!(cancel_outcome, Err(Error::Disabled));
hprintln!("ehy, you cannot cancel a timer two times!");
nb::block!(timer.wait()).unwrap();
hprintln!("if you see this there is something wrong");
panic!();
}