typedef struct { PORT_PINCFG_Type pin_cfg; PORT_PMUX_Type pin_mux; uint16_t driveRegister; /* == 0 or (1<<11) */ } port_cfg; port_cfg port_config[16] = { [0].pin_cfg.bit = { .PMUXEN = 0, .INEN = 1 }, /* [1...6] */ [7].pin_cfg.bit = { .PMUXEN = 1, .INEN = 1 }, [8].pin_cfg.bit = { .PMUXEN = 1, .INEN = 1 }, [9].pin_cfg.bit = { .PMUXEN = 1, .INEN = 1 }, /* [10...15] / [0...6] */ [7].pin_mux.bit = { .PMUXO = MUX_PA11E_TC1_WO1 }, [8].pin_mux.bit = { .PMUXO = MUX_PA11C_SERCOM0_PAD3 }, [9].pin_mux.bit = { .PMUXO = MUX_PA11C_SERCOM0_PAD3 }, /* [10...15] */ }; void EIC_Handler(void) { // a shared interrupt handler for changes on five different external pins: // EXTINT0 = PA00 = SEL - interrupt on rising or falling edge // EXTINT1 = PA01 = PH0 - interrupt on rising or falling edge // EXTINT2 = PA02 = PH1 - interrupt on rising or falling edge // EXTINT3 = PA03 = PH2 - interrupt on rising or falling edge // EXTINT4 = PA04 = PH3 - interrupt on rising edge // PA11 = output uint32_t flags = EIC->INTFLAG.reg; // a 1 bit means a change was detected on that pin // clear EXTINT0-4 flags, if they were set. EIC->INTFLAG.reg = (flags & 0x1F); // writing a 1 bit clears the interrupt flags // mask the 4 lowest bits and use them as the address of the desired drive register uint32_t localSelectedDriveRegister = PORT->Group[GPIO_PORTA].IN.reg & 0xF; PORT->Group[GPIO_PORTA].OUTSET.reg = port_config[localSelectedDriveRegister].driveRegister; PORT->Group[GPIO_PORTA].OUTCLR.reg = (~port_config[localSelectedDriveRegister].driveRegister)&(1<<11); PORT->Group[GPIO_PORTA].PINCFG[11] = port_config[localSelectedDriveRegister].pin_cfg; PORT->Group[GPIO_PORTA].PMUX[11>>1] = port_config[localSelectedDriveRegister].pin_mux; selectedDriveRegister = localSelectedDriveRegister; /*...*/ }