#ifndef _EXTI_H_
#define _EXTI_H_
//----------------------------------------------------------------------------
///
/// \brief  Just a simple Exti
///
///         See implementation for further information.
///
/// \date   20121107
/// \author Maximilian Seesslen <development@seesslen.net>
///
//----------------------------------------------------------------------------


//---Includes-----------------------------------------------------------------


//---Own------------------------------

#include <biwak/gpio.hpp>

#if defined ( STM32 )
    #include <HALWrapper/stm32_gpio.h>         // GPIOx defines
#else
    typedef int IRQn_Type;
#endif

//---Declaration--------------------------------------------------------------

class CExti;

struct SExtiConfig
{
   #if !defined STM32
   const char* label;
   #endif
   
   IRQn_Type irqn;
   #if defined STM32
   CExti* &interrupt;
   #endif
   uint16_t pin;
};

/**   \brief class handling an external interrupt
 *
 *    The class does not need to inherit CInterrupt. It just has to know which
 *    CInterrupt pointer has to be set when other class will ask via
 *    getInterruptPtr(). The other class will set its CInterrupt there.
 **/
class CExti
{
    private:
      const SExtiConfig &m_configData;

    public:
     CExti(const SExtiConfig &configData);
     ~CExti();

     void enableInterrupt(bool enable=true, bool highPriority = false);
     virtual void interrupt();
     /*
      * static CExti *getThat(int extiIndex);
     CInterrupt* &getInterruptPtr()
     {
        return(m_configData.interrupt);
     }
     */
     uint16_t getPin()
     {
        return( m_configData.pin );
     }
};

extern CExti *interruptExti0;
extern CExti *interruptExti1;
extern CExti *interruptExti2;
extern CExti *interruptExti3;
extern CExti *interruptExti4;
extern CExti *interruptExti5;
extern CExti *interruptExti7;
extern CExti *interruptExti8;
extern CExti *interruptExti9;
extern CExti *interruptExti10;
extern CExti *interruptExti11;
extern CExti *interruptExti12;
extern CExti *interruptExti13;
extern CExti *interruptExti14;
extern CExti *interruptExti15;

//extern CExti *interruptExti4_15[12];
//extern CExti *interruptExti5_9[5];     // STM32F303
//extern CExti *interruptExti10_15[6];   // STM32F303


//---fin----------------------------------------------------------------------
#endif // ? ! _EXTI_H_
