#include <cassert>

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

extern "C" {
    void POWER_CLOCK_IRQHandler(void);
    void RADIO_IRQHandler(void);
    void UARTE0_UART0_IRQHandler(void);
    void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void);
    void SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler(void);
    void NFCT_IRQHandler(void);
    void GPIOTE_IRQHandler(void);
    void SAADC_IRQHandler(void);
    void TIMER0_IRQHandler(void);
    void TIMER1_IRQHandler(void);
    void TIMER2_IRQHandler(void);
    void RTC0_IRQHandler(void);
    void TEMP_IRQHandler(void);
    void RNG_IRQHandler(void);
    void ECB_IRQHandler(void);
    void CCM_AAR_IRQHandler(void);
    void WDT_IRQHandler(void);
    void RTC1_IRQHandler(void);
    void QDEC_IRQHandler(void);
    void COMP_LPCOMP_IRQHandler(void);
    void SWI0_EGU0_IRQHandler(void);
    void SWI1_EGU1_IRQHandler(void);
    void SWI2_EGU2_IRQHandler(void);
    void SWI3_EGU3_IRQHandler(void);
    void SWI4_EGU4_IRQHandler(void);
    void SWI5_EGU5_IRQHandler(void);
    void TIMER3_IRQHandler(void);
    void TIMER4_IRQHandler(void);
    void PWM0_IRQHandler(void);
    void PDM_IRQHandler(void);
    void MWU_IRQHandler(void);
    void PWM1_IRQHandler(void);
    void PWM2_IRQHandler(void);
    void SPIM2_SPIS2_SPI2_IRQHandler(void);
    void RTC2_IRQHandler(void);
    void I2S_IRQHandler(void);
    void FPU_IRQHandler(void);
}

using namespace pinetime::platform::nrf52;

void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void)
{
    uint32_t irq_nr = InterruptGuardian::Nrf52IrqN::SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQ;
    InterruptHandler *h = InterruptGuardian::instance.nrf52_vector[irq_nr];

    assert(h != nullptr);

    h->handle();
}
