#ifndef __PINETIME_PLATFORM_NRF52_INTERRUPTGUARDIAN_H__
#define __PINETIME_PLATFORM_NRF52_INTERRUPTGUARDIAN_H__

#include <array>

extern "C" {
    #include "nrf52.h"
}

namespace pinetime::platform::nrf52 {

class InterruptGuardian
{
public:
    InterruptGuardian();

    enum Nrf52IrqN {
        POWER_CLOCK_IRQ,                       //!< 0 POWER_CLOCK
        RADIO_IRQ,                             //!< 1 RADIO
        UARTE0_UART0_IRQ,                      //!< 2 UARTE0_UART0
        SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQ, //!< 3 SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0
        SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQ, //!< 4 SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1
        NFCT_IRQ,                              //!< 5 NFCT
        GPIOTE_IRQ,                            //!< 6  GPIOTE
        SAADC_IRQ,                             //!< 7  SAADC
        TIMER0_IRQ,                            //!< 8  TIMER0
        TIMER1_IRQ,                            //!< 9  TIMER1
        TIMER2_IRQ,                            //!< 10 TIMER2
        RTC0_IRQ,                              //!< 11 RTC0
        TEMP_IRQ,                              //!< 12 TEMP
        RNG_IRQ,                               //!< 13 RNG
        ECB_IRQ,                               //!< 14 ECB
        CCM_AAR_IRQ,                           //!< 15 CCM_AAR
        WDT_IRQ,                               //!< 16 WDT
        RTC1_IRQ,                              //!< 17 RTC1
        QDEC_IRQ,                              //!< 18 QDEC
        COMP_LPCOMP_IRQ,                       //!< 19 COMP_LPCOMP
        SWI0_EGU0_IRQ,                         //!< 20 SWI0_EGU0
        SWI1_EGU1_IRQ,                         //!< 21 SWI1_EGU1
        SWI2_EGU2_IRQ,                         //!< 22 SWI2_EGU2
        SWI3_EGU3_IRQ,                         //!< 23 SWI3_EGU3
        SWI4_EGU4_IRQ,                         //!< 24 SWI4_EGU4
        SWI5_EGU5_IRQ,                         //!< 25 SWI5_EGU5
        TIMER3_IRQ,                            //!< 26 TIMER3
        TIMER4_IRQ,                            //!< 27 TIMER4
        PWM0_IRQ,                              //!< 28 PWM0
        PDM_IRQ,                               //!< 29 PDM
        MWU_IRQ,                               //!< 32 MWU
        PWM1_IRQ,                              //!< 33 PWM1
        PWM2_IRQ,                              //!< 34 PWM2
        SPIM2_SPIS2_SPI2_IRQ,                  //!< 35 SPIM2_SPIS2_SPI2
        RTC2_IRQ,                              //!< 36 RTC2
        I2S_IRQ,                               //!< 37 I2S
        FPU_IRQ                                //!< 38 FPU
    };

private:
    enum {
        NRF52_HANDLER_COUNT = FPU_IRQn + 1,
    };

public:
    void register_handler(Nrf52IrqN irq_nr, InterruptHandler &);

    static InterruptGuardian instance;

    std::array<InterruptHandler *, NRF52_HANDLER_COUNT> nrf52_vector;
};

}

#endif
