Microchip® Advanced Software Framework

Quickstart guide for SAM EIC driver

This is the quickstart guide for the SAM4L External Interrupt Controller (EIC) Driver, with step-by-step instructions on how to configure and use the driver in a selection of use cases.

The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.

Basic Use Case

In this basic use case, the EIC module and single line are configured for:

  • Falling edge trigger and async mode
  • Interrupt-based handling
  • GPIO_PUSH_BUTTON_EIC_IRQ as input

Prerequisites

System Clock Management (Sysclock).

Setup Steps

Example Code

Add to application C-file:

static void eic_callback(void)
{
/* Check if EIC push button line interrupt line is pending. */
if (eic_line_interrupt_is_pending(EIC, GPIO_PUSH_BUTTON_EIC_LINE)) {
eic_line_clear_interrupt(EIC, GPIO_PUSH_BUTTON_EIC_LINE);
bToggle = 1;
}
}
static void eic_setup(void)
{
eic_enable(EIC);
struct eic_line_config eic_line_conf;
eic_line_conf.eic_edge = EIC_EDGE_FALLING_EDGE;
eic_line_conf.eic_level = EIC_LEVEL_LOW_LEVEL;
eic_line_conf.eic_filter = EIC_FILTER_DISABLED;
eic_line_conf.eic_async = EIC_ASYNCH_MODE;
eic_line_set_config(EIC, GPIO_PUSH_BUTTON_EIC_LINE, &eic_line_conf);
eic_line_set_callback(EIC, GPIO_PUSH_BUTTON_EIC_LINE, eic_callback,
GPIO_PUSH_BUTTON_EIC_IRQ, 1);
eic_line_enable(EIC, GPIO_PUSH_BUTTON_EIC_LINE);
}

Workflow

Define the interrupt callback function in the application:

static void eic_callback(void)
{
/* Check if EIC push button line interrupt line is pending. */
if (eic_line_interrupt_is_pending(EIC, GPIO_PUSH_BUTTON_EIC_LINE)) {
eic_line_clear_interrupt(EIC, GPIO_PUSH_BUTTON_EIC_LINE);
bToggle = 1;
}
}

Enable EIC module:

eic_enable(EIC);
Note
Including enable module clock and lock sleep mode.

Configure EIC line with specified mode:

eic_line_set_config(EIC, GPIO_PUSH_BUTTON_EIC_LINE, &eic_line_conf);

Set the EIC callback function and enable EIC interrupt.

eic_line_set_callback(EIC, GPIO_PUSH_BUTTON_EIC_LINE, eic_callback,
GPIO_PUSH_BUTTON_EIC_IRQ, 1);

Enable EIC line:

eic_line_enable(EIC, GPIO_PUSH_BUTTON_EIC_LINE);