- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

# gpio.h

Go to the documentation of this file.

    00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
    00017 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
    00018  *
    00019  * Redistribution and use in source and binary forms, with or without
    00020  * modification, are permitted provided that the following conditions are met:
    00021  *
    00022  * 1. Redistributions of source code must retain the above copyright notice, this
    00023  * list of conditions and the following disclaimer.
    00024  *
    00025  * 2. Redistributions in binary form must reproduce the above copyright notice,
    00026  * this list of conditions and the following disclaimer in the documentation
    00027  * and/or other materials provided with the distribution.
    00028  *
    00029  * 3. The name of Atmel may not be used to endorse or promote products derived
    00030  * from this software without specific prior written permission.
    00031  *
    00032  * 4. This software may only be redistributed and used in connection with an Atmel
    00033  * AVR product.
    00034  *
    00035  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
    00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00037  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
    00038  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
    00039  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    00040  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    00041  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00042  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00043  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00044  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
    00045  *
    00046  */
    00047
    00048 #ifndef _GPIO_H_
    00049 #define _GPIO_H_
    00050
    00051 #include <avr32/io.h>
    00052 #include "compiler.h"
    00053
    00054
    00057
    00058 #define GPIO_SUCCESS            0
    00059 #define GPIO_INVALID_ARGUMENT   1
    00060
    00061
    00062
    00065
    00066 #define GPIO_PIN_CHANGE         0
    00067 #define GPIO_RISING_EDGE        1
    00068 #define GPIO_FALLING_EDGE       2
    00069
    00070
    00071
    00073 typedef struct
    00074 {
    00075   unsigned char pin;
    00076   unsigned char function;
    00077 } gpio_map_t[];
    00078
    00079
    00091
    00092
    00100 extern int gpio_enable_module(const gpio_map_t gpiomap, unsigned int size);
    00101
    00117 extern int gpio_enable_module_pin(unsigned int pin, unsigned int function);
    00118
    00124 extern void gpio_enable_gpio(const gpio_map_t gpiomap, unsigned int size);
    00125
    00135 extern void gpio_enable_gpio_pin(unsigned int pin);
    00136
    00137 // The open-drain mode is not synthesized on the current AVR32 products.
    00138 // If one day some AVR32 products have this feature, the corresponding part
    00139 // numbers should be listed in the #if below.
    00140 // Note that other functions are available in this driver to use pins with open
    00141 // drain in GPIO mode. The advantage of the open-drain mode functions over these
    00142 // other functions is that they can be used not only in GPIO mode but also in
    00143 // module mode.
    00144 #if 0
    00145
    00150 extern void gpio_enable_pin_open_drain(unsigned int pin);
    00151
    00156 extern void gpio_disable_pin_open_drain(unsigned int pin);
    00157
    00158 #endif
    00159
    00164 extern void gpio_enable_pin_pull_up(unsigned int pin);
    00165
    00170 extern void gpio_disable_pin_pull_up(unsigned int pin);
    00171
    00172 #if defined(AVR32_GPIO_200_H_INCLUDED) || defined(AVR32_GPIO_210_H_INCLUDED)
    00173 // Added support of Pull-up Resistor, Pull-down Resistor and Buskeeper Control.
    00174
    00179 extern void gpio_enable_pin_pull_down(unsigned int pin);
    00180
    00185 extern void gpio_disable_pin_pull_down(unsigned int pin);
    00186
    00191 extern void gpio_enable_pin_buskeeper(unsigned int pin);
    00192
    00197 extern void gpio_disable_pin_buskeeper(unsigned int pin);
    00198
    00199 #endif
    00200
    00207 extern int gpio_get_pin_value(unsigned int pin);
    00208
    00218 extern int gpio_get_gpio_pin_output_value(unsigned int pin);
    00219
    00230 extern int gpio_get_gpio_open_drain_pin_output_value(unsigned int pin);
    00231
    00236 extern void gpio_set_gpio_pin(unsigned int pin);
    00237
    00242 extern void gpio_clr_gpio_pin(unsigned int pin);
    00243
    00248 extern void gpio_tgl_gpio_pin(unsigned int pin);
    00249
    00254 extern void gpio_set_gpio_open_drain_pin(unsigned int pin);
    00255
    00260 extern void gpio_clr_gpio_open_drain_pin(unsigned int pin);
    00261
    00266 extern void gpio_tgl_gpio_open_drain_pin(unsigned int pin);
    00267
    00281 extern void gpio_enable_pin_glitch_filter(unsigned int pin);
    00282
    00287 extern void gpio_disable_pin_glitch_filter(unsigned int pin);
    00288
    00297 extern int gpio_enable_pin_interrupt(unsigned int pin, unsigned int mode);
    00298
    00303 extern void gpio_disable_pin_interrupt(unsigned int pin);
    00304
    00311 extern int gpio_get_pin_interrupt_flag(unsigned int pin);
    00312
    00317 extern void gpio_clear_pin_interrupt_flag(unsigned int pin);
    00318
    00320
    00321
    00336
    00337
    00343 #if (defined __GNUC__)
    00344 __attribute__((__always_inline__))
    00345 #endif
    00346 extern __inline__ void gpio_local_init(void)
    00347 {
    00348   Set_system_register(AVR32_CPUCR,
    00349                       Get_system_register(AVR32_CPUCR) | AVR32_CPUCR_LOCEN_MASK);
    00350 }
    00351
    00361 #if (defined __GNUC__)
    00362 __attribute__((__always_inline__))
    00363 #endif
    00364 extern __inline__ void gpio_local_enable_pin_output_driver(unsigned int pin)
    00365 {
    00366   AVR32_GPIO_LOCAL.port[pin >> 5].oders = 1 << (pin & 0x1F);
    00367 }
    00368
    00375 #if (defined __GNUC__)
    00376 __attribute__((__always_inline__))
    00377 #endif
    00378 extern __inline__ void gpio_local_disable_pin_output_driver(unsigned int pin)
    00379 {
    00380   AVR32_GPIO_LOCAL.port[pin >> 5].oderc = 1 << (pin & 0x1F);
    00381 }
    00382
    00391 #if (defined __GNUC__)
    00392 __attribute__((__always_inline__))
    00393 #endif
    00394 extern __inline__ int gpio_local_get_pin_value(unsigned int pin)
    00395 {
    00396   return (AVR32_GPIO_LOCAL.port[pin >> 5].pvr >> (pin & 0x1F)) & 1;
    00397 }
    00398
    00410 #if (defined __GNUC__)
    00411 __attribute__((__always_inline__))
    00412 #endif
    00413 extern __inline__ void gpio_local_set_gpio_pin(unsigned int pin)
    00414 {
    00415   AVR32_GPIO_LOCAL.port[pin >> 5].ovrs = 1 << (pin & 0x1F);
    00416 }
    00417
    00429 #if (defined __GNUC__)
    00430 __attribute__((__always_inline__))
    00431 #endif
    00432 extern __inline__ void gpio_local_clr_gpio_pin(unsigned int pin)
    00433 {
    00434   AVR32_GPIO_LOCAL.port[pin >> 5].ovrc = 1 << (pin & 0x1F);
    00435 }
    00436
    00448 #if (defined __GNUC__)
    00449 __attribute__((__always_inline__))
    00450 #endif
    00451 extern __inline__ void gpio_local_tgl_gpio_pin(unsigned int pin)
    00452 {
    00453   AVR32_GPIO_LOCAL.port[pin >> 5].ovrt = 1 << (pin & 0x1F);
    00454 }
    00455
    00464 #if (defined __GNUC__)
    00465 __attribute__((__always_inline__))
    00466 #endif
    00467 extern __inline__ void gpio_local_init_gpio_open_drain_pin(unsigned int pin)
    00468 {
    00469   AVR32_GPIO_LOCAL.port[pin >> 5].ovrc = 1 << (pin & 0x1F);
    00470 }
    00471
    00482 #if (defined __GNUC__)
    00483 __attribute__((__always_inline__))
    00484 #endif
    00485 extern __inline__ void gpio_local_set_gpio_open_drain_pin(unsigned int pin)
    00486 {
    00487   AVR32_GPIO_LOCAL.port[pin >> 5].oderc = 1 << (pin & 0x1F);
    00488 }
    00489
    00500 #if (defined __GNUC__)
    00501 __attribute__((__always_inline__))
    00502 #endif
    00503 extern __inline__ void gpio_local_clr_gpio_open_drain_pin(unsigned int pin)
    00504 {
    00505   AVR32_GPIO_LOCAL.port[pin >> 5].oders = 1 << (pin & 0x1F);
    00506 }
    00507
    00518 #if (defined __GNUC__)
    00519 __attribute__((__always_inline__))
    00520 #endif
    00521 extern __inline__ void gpio_local_tgl_gpio_open_drain_pin(unsigned int pin)
    00522 {
    00523   AVR32_GPIO_LOCAL.port[pin >> 5].odert = 1 << (pin & 0x1F);
    00524 }
    00525
    00527
    00528 #if (((defined __GNUC__) && ((defined __AVR32_UC3L016__) || \
    00529                              (defined __AVR32_UC3L032__) || \
    00530                              (defined __AVR32_UC3L064__)) \
    00531     ||(defined __ICCAVR32__) && ((defined __AT32UC3L016__) || \
    00532                                  (defined __AT32UC3L032__) || \
    00533                                  (defined __AT32UC3L064__) )))
    00535
    00548 #if (defined __GNUC__)
    00549 __attribute__((__always_inline__))
    00550 #endif
    00551 extern __inline__ void gpio_enable_pin_periph_event(unsigned int pin)
    00552 {
    00553   AVR32_GPIO.port[pin >> 5].oderc = 1 << (pin & 0x1F); // The GPIO output driver is disabled for that pin.
    00554   AVR32_GPIO.port[pin >> 5].evers = 1 << (pin & 0x1F);
    00555 }
    00556
    00562 #if (defined __GNUC__)
    00563 __attribute__((__always_inline__))
    00564 #endif
    00565 extern __inline__ void gpio_disable_pin_periph_event(unsigned int pin)
    00566 {
    00567   AVR32_GPIO.port[pin >> 5].everc = 1 << (pin & 0x1F);
    00568 }
    00569
    00579 extern int gpio_configure_pin_periph_event_mode(unsigned int pin, unsigned int mode, unsigned int use_igf);
    00580
    00582 #endif
    00583
    00584
    00585 #endif  // _GPIO_H_