Atmel Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GPIO - General-Purpose Input/Output

GPIO gives access to the MCU pins.

Modules

 

Data Structures

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

Peripheral Bus Interface

static uint32_t gpio_configure_edge_detector (uint32_t pin, uint32_t mode)
 Configure the edge detector of an input pin. More...
 

Return Values of the GPIO API

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

Interrupt Trigger Modes

#define GPIO_PIN_CHANGE   0
 Interrupt triggered upon pin change. More...
 
#define GPIO_RISING_EDGE   1
 Interrupt triggered upon rising edge. More...
 
#define GPIO_FALLING_EDGE   2
 Interrupt triggered upon falling edge. More...
 

Common defines for GPIO_FLAGS parameter

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

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

Local Bus Interface

High-speed interface with only one clock cycle per access.

This interface operates with high clock frequency (fCPU), and its timing is deterministic since it does not need to access a shared bus which may be heavily loaded.

Warning
To use this interface, the clock frequency of the peripheral bus on which the GPIO peripheral is connected must be set to the CPU clock frequency (fPB = fCPU).
Note
This interface has to be initialized in order to be available.
static __always_inline void gpio_local_init (void)
 Enables the local bus interface for GPIO. More...
 
static __always_inline void gpio_local_enable_pin_output_driver (uint32_t pin)
 Enables the output driver of a pin. More...
 
static __always_inline void gpio_local_disable_pin_output_driver (uint32_t pin)
 Disables the output driver of a pin. More...
 
static __always_inline bool gpio_local_get_pin_value (uint32_t pin)
 Returns the value of a pin. More...
 
static __always_inline void gpio_local_set_gpio_pin (uint32_t pin)
 Drives a GPIO pin to 1. More...
 
static __always_inline void gpio_local_clr_gpio_pin (uint32_t pin)
 Drives a GPIO pin to 0. More...
 
static __always_inline void gpio_local_tgl_gpio_pin (uint32_t pin)
 Toggles a GPIO pin. More...
 
static __always_inline void gpio_local_init_gpio_open_drain_pin (uint32_t pin)
 Initializes the configuration of a GPIO pin so that it can be used with GPIO open-drain functions. More...
 
static __always_inline void gpio_local_set_gpio_open_drain_pin (uint32_t pin)
 Drives a GPIO pin to 1 using open drain. More...
 
static __always_inline void gpio_local_clr_gpio_open_drain_pin (uint32_t pin)
 Drives a GPIO pin to 0 using open drain. More...
 
static __always_inline void gpio_local_tgl_gpio_open_drain_pin (uint32_t pin)
 Toggles a GPIO pin using open drain. More...
 

#define GPIO_BOTHEDGES   (3 << 7)

Sense Both Edges.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_BUSKEEPER   (3 << 2)

Bus Keeper.

#define GPIO_DIR_INPUT   (0 << 0)

Pin is Input.

#define GPIO_DIR_OUTPUT   (1 << 0)

Pin is Output.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_DRIVE_HIGH   (2 << 4)

Drive High Configuration.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_DRIVE_LOW   (1 << 4)

Drive Low Configuration.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_DRIVE_MAX   (3 << 4)

Drive Max Configuration.

#define GPIO_DRIVE_MIN   (0 << 4)

Drive Min Configuration.

#define GPIO_FALLING   (7 << 7)

Sense Falling Edge.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_FALLING_EDGE   2
#define GPIO_INIT_HIGH   (1 << 1)

Initial Output State is High.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_INIT_LOW   (0 << 1)

Initial Output State is Low.

#define GPIO_INTERRUPT   (1 << 7)

Enable Pin/Group Interrupt.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_INVALID_ARGUMENT   1

Input parameters are out of range.

Referenced by gpio_configure_edge_detector(), gpio_enable_module_pin(), and gpio_enable_pin_interrupt().

#define GPIO_OPEN_DRAIN   (1 << 6)

Open-Drain (when output)

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_PIN_CHANGE   0

Interrupt triggered upon pin change.

Referenced by b_joystick_init(), b_pushb1_init(), b_pushb2_init(), b_pushb3_init(), gpio_configure_edge_detector(), and main().

#define GPIO_PULL_DOWN   (2 << 2)

Pull-Down (when input)

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_PULL_UP   (1 << 2)

Pull-Up (when input)

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_RISING   (5 << 7)

Sense Rising Edge.

Referenced by gpio_configure_group(), and gpio_configure_pin().

#define GPIO_RISING_EDGE   1

Interrupt triggered upon rising edge.

Referenced by dip204_example_configure_push_buttons_IT(), gpio_configure_edge_detector(), main(), and usb_suspend().

#define GPIO_SUCCESS   0

void gpio_clr_gpio_open_drain_pin ( uint32_t  pin)

Drives a GPIO pin to 0 using open drain.

Parameters
pinThe pin number.
static uint32_t gpio_configure_edge_detector ( uint32_t  pin,
uint32_t  mode 
)
static

Configure the edge detector of an input pin.

Parameters
pinThe pin number.
modeThe edge detection mode (GPIO_PIN_CHANGE, GPIO_RISING_EDGE or GPIO_FALLING_EDGE).
Returns
GPIO_SUCCESS or GPIO_INVALID_ARGUMENT.

References GPIO_FALLING_EDGE, GPIO_INVALID_ARGUMENT, GPIO_PIN_CHANGE, GPIO_RISING_EDGE, and GPIO_SUCCESS.

Referenced by gpio_enable_pin_interrupt().

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

Configuration functionality on a port.

Parameters
portThe port number.
maskThe mask.
flagsThe configuration.

References 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.

void gpio_configure_pin ( uint32_t  pin,
uint32_t  flags 
)

Configuration functionality on a pin.

Parameters
pinThe pin number.
flagsThe configuration.

References 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.

Referenced by sensor_board_init().

void gpio_disable_pin_glitch_filter ( uint32_t  pin)

Disables the glitch filter of a pin.

Parameters
pinThe pin number.
void gpio_disable_pin_interrupt ( uint32_t  pin)

Disables the interrupt of a pin.

Parameters
pinThe pin number.

Referenced by rtouch_disable_detect_int(), touch_button_isr(), v_joystick_stop(), v_pushb1_stop(), v_pushb2_stop(), and v_pushb3_stop().

void gpio_disable_pin_pull_up ( uint32_t  pin)

Disables the pull-up resistor of a pin.

Parameters
pinThe pin number.

Referenced by rtouch_gradient_x_surface(), rtouch_gradient_y_surface(), rtouch_tristate_x_surface(), and rtouch_tristate_y_surface().

void gpio_enable_gpio ( const gpio_map_t  gpiomap,
uint32_t  size 
)

Enables the GPIO mode of a set of pins.

Parameters
gpiomapThe pin map.
sizeThe number of pins in gpiomap.

References gpio_enable_gpio_pin(), i, and gpio_map_t::pin.

Referenced by aic23b_dac_stop(), ms3_dac_mute(), ms3_dac_stop(), pwm_dac_stop(), and tpa6130_dac_stop().

void gpio_enable_gpio_pin ( uint32_t  pin)

Enables the GPIO mode of a pin.

Parameters
pinThe 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.

Referenced by et024006_SetupInterface(), gpio_enable_gpio(), main(), qt60168_check_device_ready(), rtouch_gradient_x_surface(), rtouch_gradient_y_surface(), rtouch_ground_x_surface(), rtouch_ground_y_surface(), rtouch_pullup_y_surface(), rtouch_tristate_x_surface(), and rtouch_tristate_y_surface().

uint32_t gpio_enable_module_pin ( uint32_t  pin,
uint32_t  function 
)

Enables a specific module mode for a pin.

Note
A pin and pin function index can be found in the device part header file. The AVR32_*_PIN constants map a GPIO number from the device datasheet to the appropriate pin function, while the corresponding AVR32_*_FUNCTION macro contains the appropriate function index.

For example, the constants AVR32_PWM_3_PIN and AVR32_PWM_3_FUNCTION contain the pin and function index of the PWM module, channel 3, for the current device (if available).
Parameters
pinThe pin number.
functionThe pin function.
Returns
GPIO_SUCCESS or GPIO_INVALID_ARGUMENT.

References GPIO_INVALID_ARGUMENT, and GPIO_SUCCESS.

Referenced by b_light_init(), b_potentiometer_init(), b_temperature_init(), dip204_init(), et024006_SetupInterface(), gpio_enable_module(), init_codec_gclk(), local_enable_gclk_on_gpio(), local_start_gc(), main(), prvMMI_Init(), rtouch_tristate_x_surface(), rtouch_tristate_y_surface(), and xUsartInit().

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
pinThe pin number.
uint32_t gpio_enable_pin_interrupt ( uint32_t  pin,
uint32_t  mode 
)
void gpio_enable_pin_pull_up ( uint32_t  pin)

Enables the pull-up resistor of a pin.

Parameters
pinThe pin number.

Referenced by init_spi(), main(), and rtouch_pullup_y_surface().

bool gpio_get_gpio_open_drain_pin_output_value ( uint32_t  pin)

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

Parameters
pinThe 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.
bool gpio_get_gpio_pin_output_value ( uint32_t  pin)

Returns the output value set for a GPIO pin.

Parameters
pinThe 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.
bool gpio_get_pin_interrupt_flag ( uint32_t  pin)

Gets the interrupt flag of a pin.

Parameters
pinThe pin number.
Returns
The pin interrupt flag.

Referenced by dip204_example_Joy_int_handler(), dip204_example_PB_int_handler(), ISR(), prvjoystick_ISR_NonNakedBehaviour(), and prvpushb_ISR_NonNakedBehaviour().

static __always_inline void gpio_local_clr_gpio_open_drain_pin ( uint32_t  pin)
static

Drives a GPIO pin to 0 using open drain.

Parameters
pinThe pin number.
Note
gpio_local_init and gpio_local_init_gpio_open_drain_pin must have been called beforehand.
This function does not enable the GPIO mode of the pin. gpio_enable_gpio_pin can be called for this purpose.
static __always_inline void gpio_local_clr_gpio_pin ( uint32_t  pin)
static

Drives a GPIO pin to 0.

Parameters
pinThe pin number.
Note
gpio_local_init must have been called beforehand.
This function does not enable the GPIO mode of the pin nor its output driver. gpio_enable_gpio_pin and gpio_local_enable_pin_output_driver can be called for this purpose.
static __always_inline void gpio_local_disable_pin_output_driver ( uint32_t  pin)
static

Disables the output driver of a pin.

Parameters
pinThe pin number.
Note
gpio_local_init must have been called beforehand.
static __always_inline void gpio_local_enable_pin_output_driver ( uint32_t  pin)
static

Enables the output driver of a pin.

Parameters
pinThe pin number.
Note
gpio_local_init must have been called beforehand.
This function does not enable the GPIO mode of the pin. gpio_enable_gpio_pin can be called for this purpose.

Referenced by main().

static __always_inline bool gpio_local_get_pin_value ( uint32_t  pin)
static

Returns the value of a pin.

Parameters
pinThe pin number.
Returns
The pin value.
Note
gpio_local_init must have been called beforehand.
static __always_inline void gpio_local_init ( void  )
static

Enables the local bus interface for GPIO.

Note
This function must have been called at least once before using other functions in this interface.

References Get_system_register, and Set_system_register.

Referenced by main().

static __always_inline void gpio_local_init_gpio_open_drain_pin ( uint32_t  pin)
static

Initializes the configuration of a GPIO pin so that it can be used with GPIO open-drain functions.

Note
This function must have been called at least once before using gpio_local_set_gpio_open_drain_pin, gpio_local_clr_gpio_open_drain_pin or gpio_local_tgl_gpio_open_drain_pin.
static __always_inline void gpio_local_set_gpio_open_drain_pin ( uint32_t  pin)
static

Drives a GPIO pin to 1 using open drain.

Parameters
pinThe pin number.
Note
gpio_local_init and gpio_local_init_gpio_open_drain_pin must have been called beforehand.
This function does not enable the GPIO mode of the pin. gpio_enable_gpio_pin can be called for this purpose.
static __always_inline void gpio_local_set_gpio_pin ( uint32_t  pin)
static

Drives a GPIO pin to 1.

Parameters
pinThe pin number.
Note
gpio_local_init must have been called beforehand.
This function does not enable the GPIO mode of the pin nor its output driver. gpio_enable_gpio_pin and gpio_local_enable_pin_output_driver can be called for this purpose.
static __always_inline void gpio_local_tgl_gpio_open_drain_pin ( uint32_t  pin)
static

Toggles a GPIO pin using open drain.

Parameters
pinThe pin number.
Note
gpio_local_init and gpio_local_init_gpio_open_drain_pin must have been called beforehand.
This function does not enable the GPIO mode of the pin. gpio_enable_gpio_pin can be called for this purpose.
static __always_inline void gpio_local_tgl_gpio_pin ( uint32_t  pin)
static

Toggles a GPIO pin.

Parameters
pinThe pin number.
Note
gpio_local_init must have been called beforehand.
This function does not enable the GPIO mode of the pin nor its output driver. gpio_enable_gpio_pin and gpio_local_enable_pin_output_driver can be called for this purpose.
static __always_inline bool gpio_pin_is_high ( uint32_t  pin)
static

Check if the pin is in high logical level.

Parameters
pinThe pin number.
Returns
bool true if the pin is in high logical level false if the pin is not in high logical level

References gpio_get_pin_value().

Referenced by wait_for_switches().

static __always_inline bool gpio_pin_is_low ( uint32_t  pin)
static

Check if the pin is in low logical level.

Parameters
pinThe pin number.
Returns
bool true if the pin is in low logical level false if the pin is not in low logical level

References gpio_get_pin_value().

Referenced by ak8975_get_data(), hmc5883l_get_data(), main(), and wait_for_switches().

void gpio_set_gpio_open_drain_pin ( uint32_t  pin)

Drives a GPIO pin to 1 using open drain.

Parameters
pinThe pin number.
void gpio_set_group_high ( uint32_t  port,
uint32_t  mask 
)

Drives a GPIO port to 1.

Parameters
portThe port number.
maskThe mask.
void gpio_set_group_low ( uint32_t  port,
uint32_t  mask 
)

Drives a GPIO port to 0.

Parameters
portThe port number.
maskThe mask.
void gpio_set_pin_high ( uint32_t  pin)

Drives a GPIO pin to 1.

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

Referenced by main(), and test_ko().

void gpio_set_pin_low ( uint32_t  pin)

Drives a GPIO pin to 0.

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

Referenced by main().

void gpio_tgl_gpio_open_drain_pin ( uint32_t  pin)

Toggles a GPIO pin using open drain.

Parameters
pinThe pin number.
void gpio_tgl_gpio_pin ( uint32_t  pin)

Toggles a GPIO pin.

Parameters
pinThe pin number.

Referenced by gpio_pin_change_interrupt_handler(), main(), tc_irq(), toggle_led(), and touch_button_isr().

void gpio_toggle_group ( uint32_t  port,
uint32_t  mask 
)

Toggles a GPIO group.

Parameters
portThe port number.
maskThe mask.
void gpio_toggle_pin ( uint32_t  pin)

Toggles a GPIO pin.

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

Referenced by ISR(), and main().