#![no_std]
#![no_main]

use cortex_m_rt::entry;
use defmt::info;
use nb::block;
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
use {defmt_rtt as _, panic_probe as _};

#[entry]
fn main() -> ! {
    let cp = cortex_m::Peripherals::take().unwrap();
    let dp = pac::Peripherals::take().unwrap();

    let mut rcc = dp.RCC.constrain();
    let mut gpioc = dp.GPIOC.split(&mut rcc);

    // Bluepill onboard LED on PC13 is active-low.
    // TODO: create LED Pin Input

    let mut timer = Timer::syst(cp.SYST, &rcc.clocks).counter_hz();
    timer.start(2.Hz()).unwrap();

    loop {
        // TODO: swap set_high/set_low and observe behavior.
        info!("led on (pc13 low)");
        led.set_low();
        block!(timer.wait()).unwrap();

        info!("led off (pc13 high)");
        led.set_high();
        block!(timer.wait()).unwrap();
    }
}
