#![no_std]
#![no_main]

use cortex_m_rt::entry;
use panic_halt as _;
use tm4c123x_hal::{Peripherals, prelude::*};
use tm4c123x_hal::tm4c123x as _;
use embedded_hal::digital::OutputPin;
use core::sync::atomic::{AtomicU32, Ordering};

static SYS_TICKS: AtomicU32 = AtomicU32::new(0);

#[cortex_m_rt::exception]
fn SysTick() {
    SYS_TICKS.fetch_add(1, Ordering::Relaxed);
}

fn millis() -> u32 {
    SYS_TICKS.load(Ordering::Relaxed)
}

#[entry]
fn main() -> ! {
    let p = Peripherals::take().unwrap();
    let mut sc = p.SYSCTL.constrain();
    let ports = p.GPIO_PORTF.split(&sc.power_control);
    let mut led = ports.pf1.into_push_pull_output();

    loop {
        led.set_high();
        cortex_m::asm::delay(1_000_000); // ~0.5 s @ 16 MHz
        led.set_low();
        cortex_m::asm::delay(1_000_000); // ~0.5 s
    }
}
