The supported board list:
- SAM D20 Xplained Pro
- SAM D21 Xplained Pro
- SAM R21 Xplained Pro
- SAM L21 Xplained Pro
- SAM L22 Xplained Pro
- SAM DA1 Xplained Pro
- SAM C21 Xplained Pro
- SAM HA1G16A Xplained Pro
In this use case, the EXTINT module is configured for:
- External interrupt channel connected to the board LED is used
- External interrupt channel is configured to detect both input signal edges
- Callbacks are used to handle detections from the External Interrupt
This use case configures a physical I/O pin of the device so that it is routed to a logical External Interrupt Controller channel to detect rising and falling edges of the incoming signal. A callback function is used to handle detection events from the External Interrupt module asynchronously.
When the board button is pressed, the board LED will light up. When the board button is released, the LED will turn off.
Setup
Prerequisites
There are no special setup requirements for this use-case.
Code
Copy-paste the following setup code to your user application:
void configure_extint_channel(void)
{
config_extint_chan.gpio_pin = BUTTON_0_EIC_PIN;
config_extint_chan.gpio_pin_mux = BUTTON_0_EIC_MUX;
}
void configure_extint_callbacks(void)
{
BUTTON_0_EIC_LINE,
}
void extint_detection_callback(void)
{
}
Add to user application initialization (typically the start of main()
):
configure_extint_channel();
configure_extint_callbacks();
Workflow
- Create an EXTINT module channel configuration struct, which can be filled out to adjust the configuration of a single external interrupt channel.
- Initialize the channel configuration struct with the module's default values.
- Note
- This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
- Adjust the configuration struct to configure the pin MUX (to route the desired physical pin to the logical channel) to the board button, and to configure the channel to detect both rising and falling edges.
config_extint_chan.gpio_pin = BUTTON_0_EIC_PIN;
config_extint_chan.gpio_pin_mux = BUTTON_0_EIC_MUX;
- Configure external interrupt channel with the desired channel settings.
- Register a callback function
extint_handler()
to handle detections from the External Interrupt controller.
- Enable the registered callback function for the configured External Interrupt channel, so that it will be called by the module when the channel detects an edge.
- Define the EXTINT callback that will be fired when a detection event occurs. For this example, a LED will mirror the new button state on each detection edge.
void extint_detection_callback(void)
{
}
Use Case
Code
Copy-paste the following code to your user application:
Workflow
- External interrupt events from the driver are detected asynchronously; no special application
main()
code is required.