Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SAM4L General-Purpose Input/Output (GPIO) Driver

This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the on-chip General-Purpose Input/Output (GPIO) controller with both interrupt and event support.

Devices from the following series can use this module:

The outline of this documentation is as follows:

Prerequisites

The GPIO module depends on the following modules:

Module Overview

The General Purpose Input/Output Controller (GPIO) controls the I/O pins of the microcontroller. Each GPIO pin may be used as a general-purpose I/O or be assigned to a function of an embedded peripheral.

The GPIO is configured using the Peripheral Bus (PB).

Special Considerations

There are no special considerations for this module.

Extra Information

For extra information, see Extra Information for GPIO. This includes:

Examples

For a list of examples related to this driver, see Examples for GPIO.

API Overview

Typedefs

typedef void(* gpio_pin_callback_t )(void)
 Interrupt callback function type for a GPIO pin. More...
 

Interrupt Support

The GPIO can be configured to generate an interrupt when it detects a change on a GPIO pin.

bool gpio_set_pin_callback (ioport_pin_t pin, gpio_pin_callback_t callback, uint8_t irq_level)
 Set callback for given GPIO pin. More...
 
static void gpio_enable_pin_interrupt (ioport_pin_t pin)
 Enable the interrupt of a pin. More...
 
static void gpio_disable_pin_interrupt (ioport_pin_t pin)
 Disable the interrupt of a pin. More...
 
static uint32_t gpio_get_pin_interrupt_flag (ioport_pin_t pin)
 Get the interrupt flag of a pin. More...
 
static void gpio_clear_pin_interrupt_flag (ioport_pin_t pin)
 Clear the interrupt flag of a pin. More...
 

Peripheral Event System Support

The GPIO can be programmed to output peripheral events whenever an interrupt condition is detected, such as pin value change, or only when a rising or falling edge is detected.

static void gpio_enable_pin_periph_event (ioport_pin_t pin)
 Enable the peripheral event generation of a pin. More...
 
static void gpio_disable_pin_periph_event (ioport_pin_t pin)
 Disable the peripheral event generation of a pin. More...
 

typedef void(* gpio_pin_callback_t)(void)

Interrupt callback function type for a GPIO pin.

The interrupt handler can be configured to do a function callback, the callback function must match the gpio_pin_callback_t type.

static void gpio_clear_pin_interrupt_flag ( ioport_pin_t  pin)
inlinestatic

Clear the interrupt flag of a pin.

Parameters
[in]pinThe pin number

References ioport_pin_to_mask(), and ioport_pin_to_port_id().

static void gpio_disable_pin_interrupt ( ioport_pin_t  pin)
inlinestatic

Disable the interrupt of a pin.

Parameters
[in]pinThe pin number

References ioport_pin_to_mask(), and ioport_pin_to_port_id().

Referenced by io_pad_init().

static void gpio_disable_pin_periph_event ( ioport_pin_t  pin)
inlinestatic

Disable the peripheral event generation of a pin.

Parameters
[in]pinThe pin number

References ioport_pin_to_mask(), and ioport_pin_to_port_id().

static void gpio_enable_pin_interrupt ( ioport_pin_t  pin)
inlinestatic

Enable the interrupt of a pin.

Parameters
[in]pinThe pin number

References ioport_pin_to_mask(), and ioport_pin_to_port_id().

Referenced by io_pad_init().

static void gpio_enable_pin_periph_event ( ioport_pin_t  pin)
inlinestatic

Enable the peripheral event generation of a pin.

Parameters
[in]pinThe pin number

References ioport_pin_to_mask(), and ioport_pin_to_port_id().

static uint32_t gpio_get_pin_interrupt_flag ( ioport_pin_t  pin)
inlinestatic

Get the interrupt flag of a pin.

Parameters
[in]pinThe pin number
Return values
uint32_tThe pin interrupt flag (0/1)

References ioport_pin_to_mask(), and ioport_pin_to_port_id().

bool gpio_set_pin_callback ( ioport_pin_t  pin,
gpio_pin_callback_t  callback,
uint8_t  irq_level 
)

Set callback for given GPIO pin.

Parameters
[in]pinThe pin number
[in]callbackcallback function pointer
[in]irq_levelinterrupt level
Return values
trueSet successfully
falseWrong parameters or maximum number of interrupt sources has been exceeding

References gpio_interrupt_source::callback, callback, GPIO_INT_GROUP_MASK, gpio_int_sources, GPIO_MAX_INTERRUPT_SOURCES, gpio_nb_sources, ioport_pin_to_mask(), ioport_pin_to_port_id(), and gpio_interrupt_source::pin.

Referenced by io_pad_init().