Data Structures

gpio.h File Reference

GPIO software driver interface for AVR UC3. More...

#include <avr32/io.h>
#include "compiler.h"

Go to the source code of this file.

Data Structures

struct  gpio_map_t
 A type definition of pins and modules connectivity. More...

Defines

Return Values of the GPIO API

#define GPIO_SUCCESS   0
 Function successfully completed.
#define GPIO_INVALID_ARGUMENT   1
 Input parameters are out of range.
Interrupt Trigger Modes

#define GPIO_PIN_CHANGE   0
 Interrupt triggered upon pin change.
#define GPIO_RISING_EDGE   1
 Interrupt triggered upon rising edge.
#define GPIO_FALLING_EDGE   2
 Interrupt triggered upon falling edge.
Common defines for GPIO_FLAGS parameter

#define GPIO_DIR_INPUT   (0 << 0)
 Pin is Input.
#define GPIO_DIR_OUTPUT   (1 << 0)
 Pin is Output.
#define GPIO_INIT_LOW   (0 << 1)
 Initial Ouptput State is Low.
#define GPIO_INIT_HIGH   (1 << 1)
 Initial Ouptput State is High.
#define GPIO_PULL_UP   (1 << 2)
 Pull-Up (when input).
#define GPIO_PULL_DOWN   (2 << 2)
 Pull-Down (when input).
#define GPIO_BUSKEEPER   (3 << 2)
 Bus Keeper.
#define GPIO_DRIVE_MIN   (0 << 4)
 Drive Min Configuration.
#define GPIO_DRIVE_LOW   (1 << 4)
 Drive Low Configuration.
#define GPIO_DRIVE_HIGH   (2 << 4)
 Drive High Configuration.
#define GPIO_DRIVE_MAX   (3 << 4)
 Drive Max Configuration.
#define GPIO_OPEN_DRAIN   (1 << 6)
 Open-Drain (when output).
#define GPIO_INTERRUPT   (1 << 7)
 Enable Pin/Group Interrupt.
#define GPIO_BOTHEDGES   (3 << 7)
 Sense Both Edges.
#define GPIO_RISING   (5 << 7)
 Sense Risign Edge.
#define GPIO_FALLING   (7 << 7)
 Sense Falling Edge.

Peripheral Bus Interface

Low-speed interface with a non-deterministic number of clock cycles per access.

This interface operates with lower clock frequencies (fPB <= fCPU), and its timing is not deterministic since it needs to access a shared bus which may be heavily loaded.

Note:
This interface is immediately available without initialization.


#define gpio_pin_is_low(pin)   !gpio_get_pin_value(pin)?1:0
 Check if the pin is in low logical level.
#define gpio_pin_is_high(pin)   gpio_get_pin_value(pin)?1:0
 Check if the pin is in high logical level.
int gpio_enable_module (const gpio_map_t gpiomap, uint32_t size)
 Enables specific module modes for a set of pins.
int gpio_enable_module_pin (uint32_t pin, uint32_t function)
 Enables a specific module mode for a pin.
void gpio_enable_gpio (const gpio_map_t gpiomap, uint32_t size)
 Enables the GPIO mode of a set of pins.
void gpio_enable_gpio_pin (uint32_t pin)
 Enables the GPIO mode of a pin.
void gpio_enable_pin_pull_up (uint32_t pin)
 Enables the pull-up resistor of a pin.
void gpio_disable_pin_pull_up (uint32_t pin)
 Disables the pull-up resistor of a pin.
void gpio_configure_pin (uint32_t pin, uint32_t flags)
 Configuration functionality on a pin.
void gpio_configure_group (uint32_t port, uint32_t mask, uint32_t flags)
 Configuration functionality on a port.
int gpio_get_pin_value (uint32_t pin)
 Returns the value of a pin.
int gpio_get_gpio_pin_output_value (uint32_t pin)
 Returns the output value set for a GPIO pin.
int gpio_get_gpio_open_drain_pin_output_value (uint32_t pin)
 Returns the output value set for a GPIO pin using open drain.
void gpio_set_gpio_pin (uint32_t pin)
 Drives a GPIO pin to 1.
void gpio_set_pin_high (uint32_t pin)
 Drives a GPIO pin to 1.
void gpio_set_group_high (uint32_t port, uint32_t mask)
 Drives a GPIO port to 1.
void gpio_clr_gpio_pin (uint32_t pin)
 Drives a GPIO pin to 0.
void gpio_set_pin_low (uint32_t pin)
 Drives a GPIO pin to 0.
void gpio_set_group_low (uint32_t port, uint32_t mask)
 Drives a GPIO port to 0.
void gpio_tgl_gpio_pin (uint32_t pin)
 Toggles a GPIO pin.
void gpio_toggle_pin (uint32_t pin)
 Toggles a GPIO pin.
void gpio_toggle_group (uint32_t port, uint32_t mask)
 Toggles a GPIO group.
void gpio_set_gpio_open_drain_pin (uint32_t pin)
 Drives a GPIO pin to 1 using open drain.
void gpio_clr_gpio_open_drain_pin (uint32_t pin)
 Drives a GPIO pin to 0 using open drain.
void gpio_tgl_gpio_open_drain_pin (uint32_t pin)
 Toggles a GPIO pin using open drain.
void gpio_enable_pin_glitch_filter (uint32_t pin)
 Enables the glitch filter of a pin.
void gpio_disable_pin_glitch_filter (uint32_t pin)
 Disables the glitch filter of a pin.
int gpio_enable_pin_interrupt (uint32_t pin, uint32_t mode)
 Enables the interrupt of a pin with the specified settings.
void gpio_disable_pin_interrupt (uint32_t pin)
 Disables the interrupt of a pin.
int gpio_get_pin_interrupt_flag (uint32_t pin)
 Gets the interrupt flag of a pin.
void gpio_clear_pin_interrupt_flag (uint32_t pin)
 Clears the interrupt flag of a pin.

Detailed Description

GPIO software driver interface for AVR UC3.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file gpio.h.


Define Documentation

#define GPIO_BOTHEDGES   (3 << 7)

Sense Both Edges.

Definition at line 86 of file gpio.h.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_BUSKEEPER   (3 << 2)

Bus Keeper.

Definition at line 79 of file gpio.h.

#define GPIO_DIR_INPUT   (0 << 0)

Pin is Input.

Definition at line 73 of file gpio.h.

#define GPIO_DIR_OUTPUT   (1 << 0)

Pin is Output.

Definition at line 74 of file gpio.h.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_DRIVE_HIGH   (2 << 4)

Drive High Configuration.

Definition at line 82 of file gpio.h.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_DRIVE_LOW   (1 << 4)

Drive Low Configuration.

Definition at line 81 of file gpio.h.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_DRIVE_MAX   (3 << 4)

Drive Max Configuration.

Definition at line 83 of file gpio.h.

#define GPIO_DRIVE_MIN   (0 << 4)

Drive Min Configuration.

Definition at line 80 of file gpio.h.

#define GPIO_FALLING   (7 << 7)

Sense Falling Edge.

Definition at line 88 of file gpio.h.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_FALLING_EDGE   2

Interrupt triggered upon falling edge.

Definition at line 67 of file gpio.h.

Referenced by gpio_configure_edge_detector().

#define GPIO_INIT_HIGH   (1 << 1)

Initial Ouptput State is High.

Definition at line 76 of file gpio.h.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_INIT_LOW   (0 << 1)

Initial Ouptput State is Low.

Definition at line 75 of file gpio.h.

#define GPIO_INTERRUPT   (1 << 7)

Enable Pin/Group Interrupt.

Definition at line 85 of file gpio.h.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_INVALID_ARGUMENT   1

Input parameters are out of range.

Definition at line 58 of file gpio.h.

Referenced by gpio_enable_pin_interrupt().

#define GPIO_OPEN_DRAIN   (1 << 6)

Open-Drain (when output).

Definition at line 84 of file gpio.h.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_PIN_CHANGE   0

Interrupt triggered upon pin change.

Definition at line 65 of file gpio.h.

Referenced by gpio_configure_edge_detector().

#define gpio_pin_is_high (   pin  )     gpio_get_pin_value(pin)?1:0

Check if the pin is in high logical level.

Parameters:
pin The pin number.
Returns:
Bool 1 if the pin is in high logical level 0 if the pin is not in high logical level

Definition at line 260 of file gpio.h.

#define gpio_pin_is_low (   pin  )     !gpio_get_pin_value(pin)?1:0

Check if the pin is in low logical level.

Parameters:
pin The pin number.
Returns:
Bool 1 if the pin is in low logical level 0 if the pin is not in low logical level

Definition at line 250 of file gpio.h.

#define GPIO_PULL_DOWN   (2 << 2)

Pull-Down (when input).

Definition at line 78 of file gpio.h.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_PULL_UP   (1 << 2)

Pull-Up (when input).

Definition at line 77 of file gpio.h.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_RISING   (5 << 7)

Sense Risign Edge.

Definition at line 87 of file gpio.h.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_RISING_EDGE   1

Interrupt triggered upon rising edge.

Definition at line 66 of file gpio.h.

Referenced by gpio_configure_edge_detector().

#define GPIO_SUCCESS   0

Function successfully completed.

Definition at line 57 of file gpio.h.


Function Documentation

void gpio_clear_pin_interrupt_flag ( uint32_t  pin  ) 

Clears the interrupt flag of a pin.

Parameters:
pin The pin number.

Definition at line 605 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  gpio_port->ifrc = 1 << (pin & 0x1F);
}

void gpio_clr_gpio_open_drain_pin ( uint32_t  pin  ) 

Drives a GPIO pin to 0 using open drain.

Parameters:
pin The pin number.

Definition at line 502 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];

  gpio_port->ovrc  = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 0.
  gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
  gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
}

void gpio_clr_gpio_pin ( uint32_t  pin  ) 

Drives a GPIO pin to 0.

Parameters:
pin The pin number.

Definition at line 459 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  gpio_port->ovrc  = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 0.
  gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
  gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.  
}

void gpio_configure_group ( uint32_t  port,
uint32_t  mask,
uint32_t  flags 
)

Configuration functionality on a port.

Parameters:
port The port number.
mask The mask.
flags The configuration.

Definition at line 336 of file gpio.c.

References GPIO, GPIO_BOTHEDGES, GPIO_DIR_OUTPUT, GPIO_DRIVE_HIGH, GPIO_DRIVE_LOW, GPIO_FALLING, GPIO_INIT_HIGH, GPIO_INTERRUPT, GPIO_OPEN_DRAIN, GPIO_PULL_DOWN, GPIO_PULL_UP, and GPIO_RISING.

{  
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[port];  

  /* Both pull-up and pull-down set means buskeeper */
#if defined(AVR32_GPIO_200_H_INCLUDED) || defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)  
    if (flags & GPIO_PULL_DOWN)
            gpio_port->pders = mask;
    else
            gpio_port->pderc = mask;
#endif    
    if (flags & GPIO_PULL_UP)
            gpio_port->puers = mask;
    else
            gpio_port->puerc = mask;

    /* Enable open-drain mode if requested */
#if defined(AVR32_GPIO_200_H_INCLUDED) || defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)  
            if (flags & GPIO_OPEN_DRAIN)
                    gpio_port->odmers = mask;
            else
                    gpio_port->odmerc = mask;            

            if (flags & GPIO_OPEN_DRAIN)
                    gpio_port->pders = mask;
            else
                    gpio_port->pderc = mask;
#endif 
            
#if defined(AVR32_GPIO_200_H_INCLUDED) || defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)  
            /* Select drive strength */
            if (flags & GPIO_DRIVE_LOW)
                    gpio_port->odcr0s = mask;
            else
                    gpio_port->odcr0c = mask;
            if (flags & GPIO_DRIVE_HIGH)
                    gpio_port->odcr1s = mask;
            else
                    gpio_port->odcr1c = mask;
#endif

    /* Select interrupt level for group */
    if (flags & GPIO_INTERRUPT) {
            if (flags & GPIO_BOTHEDGES)
            {
                   gpio_port->imr0c = mask;
                   gpio_port->imr1c = mask;
            }
            else if (flags & GPIO_RISING)
            {
                   gpio_port->imr0s = mask;
                   gpio_port->imr1c = mask;
            }
            else if (flags & GPIO_FALLING)
            {
                   gpio_port->imr0c = mask;
                   gpio_port->imr1s = mask;
            }
    }

    /* Select direction and initial pin state */
    if (flags & GPIO_DIR_OUTPUT) {
            if (flags & GPIO_INIT_HIGH)
                    gpio_port->ovrs = mask;
            else
                    gpio_port->ovrc = mask;
            gpio_port->oders = mask;
    } else {
            gpio_port->oderc = mask;
    }
    
    /* Enable GPIO */
    gpio_port->gpers = mask;
}

void gpio_configure_pin ( uint32_t  pin,
uint32_t  flags 
)

Configuration functionality on a pin.

Parameters:
pin The pin number.
flags The configuration.

Definition at line 261 of file gpio.c.

References GPIO, GPIO_BOTHEDGES, GPIO_DIR_OUTPUT, GPIO_DRIVE_HIGH, GPIO_DRIVE_LOW, GPIO_FALLING, GPIO_INIT_HIGH, GPIO_INTERRUPT, GPIO_OPEN_DRAIN, GPIO_PULL_DOWN, GPIO_PULL_UP, and GPIO_RISING.

{  
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];  

  /* Both pull-up and pull-down set means buskeeper */
#if defined(AVR32_GPIO_200_H_INCLUDED) || defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)  
    if (flags & GPIO_PULL_DOWN)
            gpio_port->pders = 1 << (pin & 0x1F);
    else
            gpio_port->pderc = 1 << (pin & 0x1F);
#endif    
    if (flags & GPIO_PULL_UP)
            gpio_port->puers = 1 << (pin & 0x1F);
    else
            gpio_port->puerc = 1 << (pin & 0x1F);

    /* Enable open-drain mode if requested */
#if defined(AVR32_GPIO_200_H_INCLUDED) || defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)  
            if (flags & GPIO_OPEN_DRAIN)
                    gpio_port->odmers = 1 << (pin & 0x1F);
            else
                    gpio_port->odmerc = 1 << (pin & 0x1F);            

            if (flags & GPIO_OPEN_DRAIN)
                    gpio_port->pders = 1 << (pin & 0x1F);
            else
                    gpio_port->pderc = 1 << (pin & 0x1F);
#endif 
            
#if defined(AVR32_GPIO_200_H_INCLUDED) || defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)  
            /* Select drive strength */
            if (flags & GPIO_DRIVE_LOW)
                    gpio_port->odcr0s = 1 << (pin & 0x1F);
            else
                    gpio_port->odcr0c = 1 << (pin & 0x1F);
            if (flags & GPIO_DRIVE_HIGH)
                    gpio_port->odcr1s = 1 << (pin & 0x1F);
            else
                    gpio_port->odcr1c = 1 << (pin & 0x1F);
#endif

    /* Select interrupt level for group */
    if (flags & GPIO_INTERRUPT) {
            if (flags & GPIO_BOTHEDGES)
            {
                   gpio_port->imr0c = 1 << (pin & 0x1F);
                   gpio_port->imr1c = 1 << (pin & 0x1F);
            }
            else if (flags & GPIO_RISING)
            {
                   gpio_port->imr0s = 1 << (pin & 0x1F);
                   gpio_port->imr1c = 1 << (pin & 0x1F);
            }
            else if (flags & GPIO_FALLING)
            {
                   gpio_port->imr0c = 1 << (pin & 0x1F);
                   gpio_port->imr1s = 1 << (pin & 0x1F);
            }
    }

    /* Select direction and initial pin state */
    if (flags & GPIO_DIR_OUTPUT) {
            if (flags & GPIO_INIT_HIGH)
                    gpio_port->ovrs = 1 << (pin & 0x1F);
            else
                    gpio_port->ovrc = 1 << (pin & 0x1F);
            gpio_port->oders = 1 << (pin & 0x1F);
    } else {
            gpio_port->oderc = 1 << (pin & 0x1F);
    }

    /* Enable GPIO */
    gpio_port->gpers = 1 << (pin & 0x1F);
}

void gpio_disable_pin_glitch_filter ( uint32_t  pin  ) 

Disables the glitch filter of a pin.

Parameters:
pin The pin number.

Definition at line 529 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  gpio_port->gferc = 1 << (pin & 0x1F);
}

void gpio_disable_pin_interrupt ( uint32_t  pin  ) 

Disables the interrupt of a pin.

Parameters:
pin The pin number.

Definition at line 591 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  gpio_port->ierc = 1 << (pin & 0x1F);
}

void gpio_disable_pin_pull_up ( uint32_t  pin  ) 

Disables the pull-up resistor of a pin.

Parameters:
pin The pin number.

Definition at line 207 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  gpio_port->puerc = 1 << (pin & 0x1F);
}

void gpio_enable_gpio ( const gpio_map_t  gpiomap,
uint32_t  size 
)

Enables the GPIO mode of a set of pins.

Parameters:
gpiomap The pin map.
size The number of pins in gpiomap.

Definition at line 150 of file gpio.c.

References gpio_enable_gpio_pin(), and gpio_map_t::pin.

{
  uint32_t i;

  for (i = 0; i < size; i++)
  {
    gpio_enable_gpio_pin(gpiomap->pin);
    gpiomap++;
  }
}

void gpio_enable_gpio_pin ( uint32_t  pin  ) 

Enables the GPIO mode of a pin.

Parameters:
pin The pin number.
Refer to the product header file `uc3x.h' (where x is the part number; e.g. x = a0512) for pin definitions. E.g., to enable the GPIO mode of PX21, AVR32_PIN_PX21 can be used. Module pins such as AVR32_PWM_3_PIN for PWM channel 3 can also be used to release module pins for GPIO.

Definition at line 162 of file gpio.c.

References GPIO.

Referenced by gpio_enable_gpio().

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  gpio_port->oderc = 1 << (pin & 0x1F);
  gpio_port->gpers = 1 << (pin & 0x1F);
}

int gpio_enable_module ( const gpio_map_t  gpiomap,
uint32_t  size 
)

Enables specific module modes for a set of pins.

Parameters:
gpiomap The pin map.
size The number of pins in gpiomap.
Returns:
GPIO_SUCCESS or GPIO_INVALID_ARGUMENT.

Definition at line 59 of file gpio.c.

References gpio_map_t::function, gpio_enable_module_pin(), and gpio_map_t::pin.

{
  int status = GPIO_SUCCESS;
  uint32_t i;

  for (i = 0; i < size; i++)
  {
    status |= gpio_enable_module_pin(gpiomap->pin, gpiomap->function);
    gpiomap++;
  }

  return status;
}

int gpio_enable_module_pin ( uint32_t  pin,
uint32_t  function 
)

Enables a specific module mode for a pin.

Parameters:
pin The pin number.
Refer to the product header file `uc3x.h' (where x is the part number; e.g. x = a0512) for module pins. E.g., to enable a PWM channel output, the pin number can be AVR32_PWM_3_PIN for PWM channel 3.
function The pin function.
Refer to the product header file `uc3x.h' (where x is the part number; e.g. x = a0512) for module pin functions. E.g., to enable a PWM channel output, the pin function can be AVR32_PWM_3_FUNCTION for PWM channel 3.
Returns:
GPIO_SUCCESS or GPIO_INVALID_ARGUMENT.

Definition at line 74 of file gpio.c.

References GPIO.

Referenced by gpio_enable_module().

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];

  // Enable the correct function.
  switch (function)
  {
  case 0: // A function.
    gpio_port->pmr0c = 1 << (pin & 0x1F);
    gpio_port->pmr1c = 1 << (pin & 0x1F);
#if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
    gpio_port->pmr2c = 1 << (pin & 0x1F);
#endif
    break;

  case 1: // B function.
    gpio_port->pmr0s = 1 << (pin & 0x1F);
    gpio_port->pmr1c = 1 << (pin & 0x1F);
#if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
    gpio_port->pmr2c = 1 << (pin & 0x1F);
#endif
    break;

  case 2: // C function.
    gpio_port->pmr0c = 1 << (pin & 0x1F);
    gpio_port->pmr1s = 1 << (pin & 0x1F);
#if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
    gpio_port->pmr2c = 1 << (pin & 0x1F);
#endif
    break;

  case 3: // D function.
    gpio_port->pmr0s = 1 << (pin & 0x1F);
    gpio_port->pmr1s = 1 << (pin & 0x1F);
#if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
    gpio_port->pmr2c = 1 << (pin & 0x1F);
#endif
    break;

#if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
  case 4: // E function.
    gpio_port->pmr0c = 1 << (pin & 0x1F);
    gpio_port->pmr1c = 1 << (pin & 0x1F);
    gpio_port->pmr2s = 1 << (pin & 0x1F);
    break;
    
  case 5: // F function.
    gpio_port->pmr0s = 1 << (pin & 0x1F);
    gpio_port->pmr1c = 1 << (pin & 0x1F);
    gpio_port->pmr2s = 1 << (pin & 0x1F);
    break;
    
  case 6: // G function.
    gpio_port->pmr0c = 1 << (pin & 0x1F);
    gpio_port->pmr1s = 1 << (pin & 0x1F);
    gpio_port->pmr2s = 1 << (pin & 0x1F);
    break;
    
  case 7: // H function.
    gpio_port->pmr0s = 1 << (pin & 0x1F);
    gpio_port->pmr1s = 1 << (pin & 0x1F);
    gpio_port->pmr2s = 1 << (pin & 0x1F);
    break;
#endif

  default:
    return GPIO_INVALID_ARGUMENT;
  }

  // Disable GPIO control.
  gpio_port->gperc = 1 << (pin & 0x1F);

  return GPIO_SUCCESS;
}

void gpio_enable_pin_glitch_filter ( uint32_t  pin  ) 

Enables the glitch filter of a pin.

When the glitch filter is enabled, a glitch with duration of less than 1 clock cycle is automatically rejected, while a pulse with duration of 2 clock cycles or more is accepted. For pulse durations between 1 clock cycle and 2 clock cycles, the pulse may or may not be taken into account, depending on the precise timing of its occurrence. Thus for a pulse to be guaranteed visible it must exceed 2 clock cycles, whereas for a glitch to be reliably filtered out, its duration must not exceed 1 clock cycle. The filter introduces 2 clock cycles latency.

Parameters:
pin The pin number.

Definition at line 522 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  gpio_port->gfers = 1 << (pin & 0x1F);
}

int gpio_enable_pin_interrupt ( uint32_t  pin,
uint32_t  mode 
)

Enables the interrupt of a pin with the specified settings.

Parameters:
pin The pin number.
mode The trigger mode (GPIO_PIN_CHANGE, GPIO_RISING_EDGE or GPIO_FALLING_EDGE).
Returns:
GPIO_SUCCESS or GPIO_INVALID_ARGUMENT.

Definition at line 573 of file gpio.c.

References GPIO, gpio_configure_edge_detector(), and GPIO_INVALID_ARGUMENT.

{
  volatile avr32_gpio_port_t  *gpio_port = &GPIO.port[pin >> 5];

  // Enable the glitch filter.
  gpio_port->gfers = 1 << (pin & 0x1F);

  // Configure the edge detector.
  if(GPIO_INVALID_ARGUMENT == gpio_configure_edge_detector(pin, mode))
    return(GPIO_INVALID_ARGUMENT);

  // Enable interrupt.
  gpio_port->iers = 1 << (pin & 0x1F);

  return GPIO_SUCCESS;
}

void gpio_enable_pin_pull_up ( uint32_t  pin  ) 

Enables the pull-up resistor of a pin.

Parameters:
pin The pin number.

Definition at line 197 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  gpio_port->puers = 1 << (pin & 0x1F);
#if defined(AVR32_GPIO_200_H_INCLUDED) || defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
  gpio_port->pderc = 1 << (pin & 0x1F);
#endif
}

int gpio_get_gpio_open_drain_pin_output_value ( uint32_t  pin  ) 

Returns the output value set for a GPIO pin using open drain.

Parameters:
pin The pin number.
Returns:
The pin output value.
Note:
This function must be used in conjunction with gpio_set_gpio_open_drain_pin, gpio_clr_gpio_open_drain_pin and gpio_tgl_gpio_open_drain_pin.

Definition at line 425 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  return ((gpio_port->oder >> (pin & 0x1F)) & 1) ^ 1;
}

int gpio_get_gpio_pin_output_value ( uint32_t  pin  ) 

Returns the output value set for a GPIO pin.

Parameters:
pin The pin number.
Returns:
The pin output value.
Note:
This function must be used in conjunction with gpio_set_gpio_pin, gpio_clr_gpio_pin and gpio_tgl_gpio_pin.

Definition at line 418 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  return (gpio_port->ovr >> (pin & 0x1F)) & 1;
}

int gpio_get_pin_interrupt_flag ( uint32_t  pin  ) 

Gets the interrupt flag of a pin.

Parameters:
pin The pin number.
Returns:
The pin interrupt flag.

Definition at line 598 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  return (gpio_port->ifr >> (pin & 0x1F)) & 1;
}

int gpio_get_pin_value ( uint32_t  pin  ) 

Returns the value of a pin.

Parameters:
pin The pin number.
Returns:
The pin value.

Definition at line 411 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  return (gpio_port->pvr >> (pin & 0x1F)) & 1;
}

void gpio_set_gpio_open_drain_pin ( uint32_t  pin  ) 

Drives a GPIO pin to 1 using open drain.

Parameters:
pin The pin number.

Definition at line 493 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];

  gpio_port->oderc = 1 << (pin & 0x1F); // The GPIO output driver is disabled for that pin.
  gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
}

void gpio_set_gpio_pin ( uint32_t  pin  ) 

Drives a GPIO pin to 1.

Parameters:
pin The pin number.

Definition at line 432 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  gpio_port->ovrs  = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 1.
  gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
  gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
}

void gpio_set_group_high ( uint32_t  port,
uint32_t  mask 
)

Drives a GPIO port to 1.

Parameters:
port The port number.
mask The mask.

Definition at line 446 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[port];
  gpio_port->ovrs  = mask; // Value to be driven on the I/O group: 1.
}

void gpio_set_group_low ( uint32_t  port,
uint32_t  mask 
)

Drives a GPIO port to 0.

Parameters:
port The port number.
mask The mask.

Definition at line 467 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[port];
  gpio_port->ovrc  = mask; // Value to be driven on the I/O group: 0.
}

void gpio_set_pin_high ( uint32_t  pin  ) 

Drives a GPIO pin to 1.

Parameters:
pin The pin number.
Note:
The function gpio_configure_pin must be called before.

Definition at line 440 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  gpio_port->ovrs  = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 1.
}

void gpio_set_pin_low ( uint32_t  pin  ) 

Drives a GPIO pin to 0.

Parameters:
pin The pin number.
Note:
The function gpio_configure_pin must be called before.

Definition at line 453 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  gpio_port->ovrc  = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 0.
}

void gpio_tgl_gpio_open_drain_pin ( uint32_t  pin  ) 

Toggles a GPIO pin using open drain.

Parameters:
pin The pin number.

Definition at line 512 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];

  gpio_port->ovrc  = 1 << (pin & 0x1F); // Value to be driven on the I/O line if the GPIO output driver is enabled: 0.
  gpio_port->odert = 1 << (pin & 0x1F); // The GPIO output driver is toggled for that pin.
  gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
}

void gpio_tgl_gpio_pin ( uint32_t  pin  ) 

Toggles a GPIO pin.

Parameters:
pin The pin number.

Definition at line 473 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  gpio_port->ovrt  = 1 << (pin & 0x1F); // Toggle the I/O line.
  gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
  gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
}

void gpio_toggle_group ( uint32_t  port,
uint32_t  mask 
)

Toggles a GPIO group.

Parameters:
port The port number.
mask The mask.

Definition at line 487 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[port];
  gpio_port->ovrt  = mask; // Toggle the I/O port.
}

void gpio_toggle_pin ( uint32_t  pin  ) 

Toggles a GPIO pin.

Parameters:
pin The pin number.
Note:
The function gpio_configure_pin must be called before.

Definition at line 481 of file gpio.c.

References GPIO.

{
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
  gpio_port->ovrt  = 1 << (pin & 0x1F); // Toggle the I/O line.
}