This file contains basic GPIO driver functions.
Definition in file gpio.h.
#include <avr32/io.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 | |
Interrupt Trigger Modes | |
| #define | GPIO_FALLING_EDGE 2 |
| #define | GPIO_PIN_CHANGE 0 |
| Interrupt triggered upon pin change. | |
| #define | GPIO_RISING_EDGE 1 |
| Interrupt triggered upon rising edge. | |
Return Values of the GPIO API | |
| #define | GPIO_INVALID_ARGUMENT 1 |
| #define | GPIO_SUCCESS 0 |
| Function successfully completed. | |
Functions | |
| void | gpio_clear_pin_interrupt_flag (unsigned int pin) |
| Clears the interrupt flag of a pin. | |
| void | gpio_clr_gpio_pin (unsigned int pin) |
| Drives a GPIO pin to 0. | |
| void | gpio_disable_pin_glitch_filter (unsigned int pin) |
| Disables the glitch filter of a pin. | |
| void | gpio_disable_pin_interrupt (unsigned int pin) |
| Disables the interrupt of a pin. | |
| void | gpio_disable_pin_open_drain (unsigned int pin) |
| Disables the open-drain mode of a pin. | |
| void | gpio_disable_pin_pull_up (unsigned int pin) |
| Disables the pull-up resistor of a pin. | |
| void | gpio_enable_gpio (const gpio_map_t gpiomap, unsigned int size) |
| Enables the GPIO mode of a set of pins. | |
| void | gpio_enable_gpio_pin (unsigned int pin) |
| Enables the GPIO mode of a pin. | |
| int | gpio_enable_module (const gpio_map_t gpiomap, unsigned int size) |
| Enables specific module modes for a set of pins. | |
| int | gpio_enable_module_pin (unsigned int pin, unsigned int function) |
| Enables a specific module mode for a pin. | |
| void | gpio_enable_pin_glitch_filter (unsigned int pin) |
| Enables the glitch filter of a pin. | |
| int | gpio_enable_pin_interrupt (unsigned int pin, unsigned int mode) |
| Enables the interrupt of a pin with the specified settings. | |
| void | gpio_enable_pin_open_drain (unsigned int pin) |
| Enables the open-drain mode of a pin. | |
| void | gpio_enable_pin_pull_up (unsigned int pin) |
| Enables the pull-up resistor of a pin. | |
| int | gpio_get_gpio_pin_output_value (unsigned int pin) |
| Returns the output value set for a GPIO pin. | |
| int | gpio_get_pin_interrupt_flag (unsigned int pin) |
| Gets the interrupt flag of a pin. | |
| int | gpio_get_pin_value (unsigned int pin) |
| Returns the value of a pin. | |
| void | gpio_set_gpio_pin (unsigned int pin) |
| Drives a GPIO pin to 1. | |
| void | gpio_tgl_gpio_pin (unsigned int pin) |
| Toggles a GPIO pin. | |
| #define GPIO_FALLING_EDGE 2 |
Interrupt triggered upon falling edge.
Definition at line 66 of file gpio.h.
Referenced by gpio_enable_pin_interrupt().
| #define GPIO_INVALID_ARGUMENT 1 |
Input parameters are out of range.
Definition at line 57 of file gpio.h.
Referenced by gpio_enable_module_pin(), and gpio_enable_pin_interrupt().
| #define GPIO_PIN_CHANGE 0 |
Interrupt triggered upon pin change.
Definition at line 64 of file gpio.h.
Referenced by gpio_enable_pin_interrupt().
| #define GPIO_RISING_EDGE 1 |
Interrupt triggered upon rising edge.
Definition at line 65 of file gpio.h.
Referenced by gpio_enable_pin_interrupt().
| #define GPIO_SUCCESS 0 |
Function successfully completed.
Definition at line 56 of file gpio.h.
Referenced by gpio_enable_module(), gpio_enable_module_pin(), and gpio_enable_pin_interrupt().
| void gpio_clear_pin_interrupt_flag | ( | unsigned int | pin | ) |
| void gpio_clr_gpio_pin | ( | unsigned int | pin | ) |
Drives a GPIO pin to 0.
| pin | The pin number. |
Definition at line 174 of file gpio.c.
References GPIO.
Referenced by main().
00175 { 00176 volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5]; 00177 00178 gpio_port->ovrc = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 0. 00179 gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin. 00180 gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin. 00181 }
| void gpio_disable_pin_glitch_filter | ( | unsigned int | pin | ) |
| void gpio_disable_pin_interrupt | ( | unsigned int | pin | ) |
| void gpio_disable_pin_open_drain | ( | unsigned int | pin | ) |
| void gpio_disable_pin_pull_up | ( | unsigned int | pin | ) |
| void gpio_enable_gpio | ( | const gpio_map_t | gpiomap, | |
| unsigned int | size | |||
| ) |
Enables the GPIO mode of a set of pins.
| gpiomap | The pin map. | |
| size | The number of pins in gpiomap. |
Definition at line 102 of file gpio.c.
References gpio_enable_gpio_pin(), and gpio_map_t::pin.
00103 { 00104 unsigned int i; 00105 00106 for (i = 0; i < size; i++) 00107 { 00108 gpio_enable_gpio_pin(gpiomap->pin); 00109 gpiomap++; 00110 } 00111 }
| void gpio_enable_gpio_pin | ( | unsigned int | pin | ) |
Enables the GPIO mode of a pin.
| 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_PWM_3_PIN for PWM channel 3 can also be used to release module pins for GPIO. |
Definition at line 114 of file gpio.c.
References GPIO.
Referenced by gpio_enable_gpio().
00115 { 00116 volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5]; 00117 gpio_port->oderc = 1 << (pin & 0x1F); 00118 gpio_port->gpers = 1 << (pin & 0x1F); 00119 }
| int gpio_enable_module | ( | const gpio_map_t | gpiomap, | |
| unsigned int | size | |||
| ) |
Enables specific module modes for a set of pins.
| gpiomap | The pin map. | |
| size | The number of pins in gpiomap. |
Definition at line 54 of file gpio.c.
References gpio_map_t::function, gpio_enable_module_pin(), GPIO_SUCCESS, and gpio_map_t::pin.
00055 { 00056 int status = GPIO_SUCCESS; 00057 unsigned int i; 00058 00059 for (i = 0; i < size; i++) 00060 { 00061 status |= gpio_enable_module_pin(gpiomap->pin, gpiomap->function); 00062 gpiomap++; 00063 } 00064 00065 return status; 00066 }
| int gpio_enable_module_pin | ( | unsigned int | pin, | |
| unsigned int | function | |||
| ) |
Enables a specific module mode for a pin.
| 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_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_PWM_3_FUNCTION for PWM channel 3. |
Definition at line 69 of file gpio.c.
References GPIO, GPIO_INVALID_ARGUMENT, and GPIO_SUCCESS.
Referenced by gpio_enable_module().
00070 { 00071 volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5]; 00072 00073 // Enable the correct function. 00074 switch (function) 00075 { 00076 case 0: // A function. 00077 gpio_port->pmr0c = 1 << (pin & 0x1F); 00078 gpio_port->pmr1c = 1 << (pin & 0x1F); 00079 break; 00080 00081 case 1: // B function. 00082 gpio_port->pmr0s = 1 << (pin & 0x1F); 00083 gpio_port->pmr1c = 1 << (pin & 0x1F); 00084 break; 00085 00086 case 2: // C function. 00087 gpio_port->pmr0c = 1 << (pin & 0x1F); 00088 gpio_port->pmr1s = 1 << (pin & 0x1F); 00089 break; 00090 00091 default: 00092 return GPIO_INVALID_ARGUMENT; 00093 } 00094 00095 // Disable GPIO control. 00096 gpio_port->gperc = 1 << (pin & 0x1F); 00097 00098 return GPIO_SUCCESS; 00099 }
| void gpio_enable_pin_glitch_filter | ( | unsigned int | 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.
| pin | The pin number. |
Definition at line 194 of file gpio.c.
References GPIO.
00195 { 00196 volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5]; 00197 gpio_port->gfers = 1 << (pin & 0x1F); 00198 }
| int gpio_enable_pin_interrupt | ( | unsigned int | pin, | |
| unsigned int | mode | |||
| ) |
Enables the interrupt of a pin with the specified settings.
| pin | The pin number. | |
| mode | The trigger mode (GPIO_PIN_CHANGE, GPIO_RISING_EDGE or GPIO_FALLING_EDGE). |
Definition at line 208 of file gpio.c.
References GPIO, GPIO_FALLING_EDGE, GPIO_INVALID_ARGUMENT, GPIO_PIN_CHANGE, GPIO_RISING_EDGE, and GPIO_SUCCESS.
00209 { 00210 volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5]; 00211 00212 // Enable the glitch filter. 00213 gpio_port->gfers = 1 << (pin & 0x1F); 00214 00215 // Configure the edge detector. 00216 switch (mode) 00217 { 00218 case GPIO_PIN_CHANGE: 00219 gpio_port->imr0c = 1 << (pin & 0x1F); 00220 gpio_port->imr1c = 1 << (pin & 0x1F); 00221 break; 00222 00223 case GPIO_RISING_EDGE: 00224 gpio_port->imr0s = 1 << (pin & 0x1F); 00225 gpio_port->imr1c = 1 << (pin & 0x1F); 00226 break; 00227 00228 case GPIO_FALLING_EDGE: 00229 gpio_port->imr0c = 1 << (pin & 0x1F); 00230 gpio_port->imr1s = 1 << (pin & 0x1F); 00231 break; 00232 00233 default: 00234 return GPIO_INVALID_ARGUMENT; 00235 } 00236 00237 // Enable interrupt. 00238 gpio_port->iers = 1 << (pin & 0x1F); 00239 00240 return GPIO_SUCCESS; 00241 }
| void gpio_enable_pin_open_drain | ( | unsigned int | pin | ) |
| void gpio_enable_pin_pull_up | ( | unsigned int | pin | ) |
| int gpio_get_gpio_pin_output_value | ( | unsigned int | pin | ) |
| int gpio_get_pin_interrupt_flag | ( | unsigned int | pin | ) |
| int gpio_get_pin_value | ( | unsigned int | pin | ) |
| void gpio_set_gpio_pin | ( | unsigned int | pin | ) |
Drives a GPIO pin to 1.
| pin | The pin number. |
Definition at line 164 of file gpio.c.
References GPIO.
Referenced by main().
00165 { 00166 volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5]; 00167 00168 gpio_port->ovrs = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 1. 00169 gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin. 00170 gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin. 00171 }
| void gpio_tgl_gpio_pin | ( | unsigned int | pin | ) |
Toggles a GPIO pin.
| pin | The pin number. |
Definition at line 184 of file gpio.c.
References GPIO.
00185 { 00186 volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5]; 00187 00188 gpio_port->ovrt = 1 << (pin & 0x1F); // Toggle the I/O line. 00189 gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin. 00190 gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin. 00191 }
1.5.3-20071008