I'm abstracting the interrupt vector table on multiple microcontrollers. I am using template classes in the form of (InterruptVectorTable.hpp(definition, included in implementation))
template<class Device, class ResultType>
InterruptVectorTable
{
enum class IRQType : ResultType;
}
Device
is a kind of dummy class that is used to specialize the template.
class DeviceAtMega328p
{
public:
static const int s_NumInterruptVectors = {26};
};
(Here I'm still thinking about whether to pass the 26 as template parameter or in this form.)
As each microcontroller has its own types and values of interrupts, that should be checked at compile time (because of enum class), I'd like to also specialize the specific interrupts in this form(InterruptVectorTable.hpp(Implementation):
template<>
InterruptVectorTable< DeviceAtMega328p, uint8_t>
{
enum class IRQType : ResultType
{
//RESET_IRQn = 0, // Not available.
INT0_IRQn = 1,
INT1_IRQn = 2,
PCINT0_IRQn = 3,
PCINT1_IRQn = 4,
PCINT2_IRQn = 5,
WDT_IRQn = 6,
// .....
};
}
This approach seems not to work as expected(currently too many errors to specify, which explicitly one specifies this part).