armatmelstudiosamd21

Interrupts on SAMD21 with ASF


I am starting on learning programming Atmel SAMD devices using ASF, and trying to do a simple test interrupt application. I have found this source from Microchip about interrupts.

In this code snippet, it populates a configuration struct and then attaches it to the interrupt channel. Three macros, BUTTON_0_EIC_PIN, BUTTON_0_EIC_MUX and BUTTON_0_EIC_LINE, are predefined macros specific to the board. I want to attach interrupt to a regular, non-predefined pin, in such case, what the syntax would be?

void configure_extint_channel(void)
{
    struct extint_chan_conf config_extint_chan;
    extint_chan_get_config_defaults(&config_extint_chan);
    config_extint_chan.gpio_pin           = BUTTON_0_EIC_PIN;
    config_extint_chan.gpio_pin_mux       = BUTTON_0_EIC_MUX;
    config_extint_chan.gpio_pin_pull      = EXTINT_PULL_UP;
    config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;
    extint_chan_set_config(BUTTON_0_EIC_LINE, &config_extint_chan);
}

I cannot seem to find any sources that provides a general syntax as opposed to using predefined board pins for buttons and leds, and I couldn't find the related section on either ASF documentation or the datasheet of the device.

Say, for instance, I want to use PA18, the 18th pin of port-A, that is connected to 2nd interrupt channel, EXTINT[2], what would the corresponding terms be in place of those three macros?


Solution

  • After creating an example project using a known board template, and digging into an uncomfortable amount of macros expanding to other macros, I have found the actual definitions.

    //                               v----- peripheral group A, where EIC resides
    BUTTON_0_EIC_PIN  --> PIN_P<X><#>A_EIC_EXTINT<#>
    BUTTON_0_EIC_MUX  --> MUX_P<X><#>A_EIC_EXTINT<#>
    BUTTON_0_EIC_LINE --> <EXTINT channel number>
    

    For instance PA18 connected to EXTINT2 would be:

    PIN_PA18A_EIC_EXTINT2
    MUX_PA18A_EIC_EXTINT2
    2