#![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 rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.sysclk(24.MHz()).freeze();
let mut timer = dp.TIM1.counter_ms(&clocks);
timer.start(1.secs()).unwrap();
hprintln!("hello!").unwrap();
nb::block!(timer.wait()).unwrap();
hprintln!("timer expired 1").unwrap();
nb::block!(timer.wait()).unwrap();
hprintln!("timer expired 2").unwrap();
timer.cancel().unwrap();
timer.start(1.secs()).unwrap();
nb::block!(timer.wait()).unwrap();
hprintln!("timer expired 3").unwrap();
timer.cancel().unwrap();
let cancel_outcome = timer.cancel();
assert_eq!(cancel_outcome, Err(Error::Disabled));
hprintln!("ehy, you cannot cancel a timer two times!").unwrap();
nb::block!(timer.wait()).unwrap();
hprintln!("if you see this there is something wrong").unwrap();
panic!();
}