Arduino Zero TCC Capture

Hi Parnal,

In the earlier builds of the Arduino core code, it was possible to set-up a pin as an interrupt by using the attachInterrupt() function and passing a NULL argument as the function callback pointer:

attachInterrupt(12, NULL, HIGH);           // Attach interrupts to digital pin 12 (external interrupt 3)

However, in the later builds this was changed so that attachInterrupt() would skip pin set-up if a NULL pointer was detected.

This means at the moment it's necessary to either use attachInterrupt() with a dummy (empty) callback function, or set-up the pin using regsiter manipulation.

I've raised the isse on Github with the Arduino SAMD core developers, as this changes reduces the flexibility of this function.

The first section of code just switches the pin from GPIO to the peripheral multiplexer and then selects the peripheral as the External Interrupt Controller (EIC):

// Enable the port multiplexer on digital pin D12
PORT->Group[g_APinDescription[12].ulPort].PINCFG[g_APinDescription[12].ulPin].bit.PMUXEN = 1;
// Set-up the pin as an EIC (interrupt) peripheral on D12
PORT->Group[g_APinDescription[12].ulPort].PMUX[g_APinDescription[12].ulPin >> 1].reg |= PORT_PMUX_PMUXO_A;

The following lines then just activate the interrupt on D12, which is on EIC channel 3 and set the pin sensing to interrupt on a HIGH level:

REG_EIC_EVCTRL |= EIC_EVCTRL_EXTINTEO3;       // Enable event output on external interrupt 3
REG_EIC_CONFIG0 |= EIC_CONFIG_SENSE3_HIGH;           // Set event detecting a HIGH level
REG_EIC_CTRL |= EIC_CTRL_ENABLE;                            // Enable EIC peripheral
while (EIC->STATUS.bit.SYNCBUSY);                             // Wait for synchronization