#include <array>

#include "platform/cm4/InterruptHandler.h"
#include "platform/cm4/InterruptGuardian.h"
#include "platform/cm4/SystemTick.h"

#include "platform/nrf52/gpio.h"
#include "platform/nrf52/InterruptHandler.h"
#include "platform/nrf52/InterruptGuardian.h"

using namespace pinetime::platform;

enum {
    PIN_NUMBER_LED_1 = 17,
    PIN_NUMBER_LED_2 = 18,
    PIN_NUMBER_LED_3 = 19,
    PIN_NUMBER_LED_4 = 20
};

nrf52::Gpio led_1(PIN_NUMBER_LED_1);
nrf52::Gpio led_2(PIN_NUMBER_LED_2);
nrf52::Gpio led_3(PIN_NUMBER_LED_3);
nrf52::Gpio led_4(PIN_NUMBER_LED_4);

std::array<nrf52::Gpio *, 4> leds = {&led_1, &led_2, &led_3, &led_4};

nrf52::InterruptGuardian nrf52::InterruptGuardian::instance;
cm4::InterruptGuardian cm4::InterruptGuardian::instance;


int main(void)
{
    cm4::SystemTick ticker;
    ticker.enable();
    uint32_t last_tick = 0;

    cm4::InterruptGuardian::enable_interrupts();
    while(true) {
        for(auto it = std::begin(leds); it != std::end(leds); ++it) {
            volatile uint32_t tick = ticker.tick() / 1000;
            if(tick != last_tick) {
                nrf52::Gpio * tmp = *it;
                tmp->toggle();
                last_tick = tick;
            }
        }
    }
    return 0;
}
