b luo / mbed-dev

Fork of mbed-dev by mbed official

Committer:
mbed_official
Date:
Tue Apr 05 18:15:12 2016 +0100
Revision:
107:414e9c822e99
Synchronized with git revision dd3c5f7fa8473776950ec6e15c0e4adedb21cf2f

Full URL: https://github.com/mbedmicro/mbed/commit/dd3c5f7fa8473776950ec6e15c0e4adedb21cf2f/

* * Base Commit for SAMG55J19. No errors and no implementations.

* * Added gpio files.

* * Added pinmap files.

* * Base commit for usticker implementation.

* * Added gcc_arm export functionality

* * added files for usticker.
* added template file for samd55j19

* * GPIO IRQ base commit.

* * updated with changes in gpio irq driver.

* * Reverted back unexpected commit in SAM0 gpio driver.

* * updated gpio_irq driver.

* * correction in gpio and gpio_irq drivers.
* added support for some test for gpio.

* * base commit for peripheralpins for usart.
* update in serial apis.

* * updated serial apis.

* * updated serial apis and test.

* * update serial apis for asynch apis.

* * updated peripheral pins for i2c and spi.
* added test support for serial flow control

* * Base commit for low power ticker implementation.

* * base commit for port apis.
* update in lp ticker apis.

* * Added test support for port.

* * base commit for sleep apis.

* * Base commit for spi.

* * updated with corrections in gpio irq.
* usticker file updated with latest source.

* * updated with corrections for unexpected board reset.
* updated gpio irq apis and added test for the same.

* * updated sleep api for deepsleep.

* * updated serial apis.

* Added uc_ticker and SPI api implementations

* Removed unused SPI pin map

* Updated review feedback

* * implemented lpticker with TC module.
* updated files for KnR Coding Statndard.
* updated serial and usticker apis.

* * Base commit for AnalogueIn apis.

* * RTC apis base commit without implementation.

* * Updated with corrections in lpticker implementations.

* * Added implementation for rtc apis.

* * updated with implementations for pwm.
* changed usticker from TC0 to TC1.

* Added I2C support

* * removed setvector usage from usticker and lpticker implementations
* added tests for SAMG55J19

* * Removed unwanted .o and .d files.
* Updated I2C files for KnR Coding Standards.
* Update for reducing compiler warnings in peripheralpins,c
* Updated with PWM free implementation.

* * Removed unwanted headers file inclusion.
* Compiler warning corrections in serial_api.c

* * Updated ADC with 16 bit mode initialization and code refinements.
* Updated PWM with code refinements.

* Updated I2C review feedback and fixed style

* Updated target name for SAMG55

* * Added Test Support for I2C with AT30TSE75X and Added Support for SAMG55J19 in atmelstudio project exporter

* * Added Test Support for I2C with AT30TSE75X and Added Support for SAMG55J19 in atmelstudio project exporter

* Used NVIC_SetVector for interrupt callback

* Removed Target macro define in test

* Updated test cases to have SAMG55 support

* * Updated with corrections in Serial and SPI asynchronous implementations.
* Updated deepsleep api implementation
* Merged LP_Ticker with latest code from mbed 3.0 repository.

* * updated with corrections in I2C Asynch implementation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 107:414e9c822e99 1 /**
mbed_official 107:414e9c822e99 2 * \file
mbed_official 107:414e9c822e99 3 *
mbed_official 107:414e9c822e99 4 * \brief Common IOPORT service main header file for AVR, UC3 and ARM
mbed_official 107:414e9c822e99 5 * architectures.
mbed_official 107:414e9c822e99 6 *
mbed_official 107:414e9c822e99 7 * Copyright (c) 2012-2015 Atmel Corporation. All rights reserved.
mbed_official 107:414e9c822e99 8 *
mbed_official 107:414e9c822e99 9 * \asf_license_start
mbed_official 107:414e9c822e99 10 *
mbed_official 107:414e9c822e99 11 * \page License
mbed_official 107:414e9c822e99 12 *
mbed_official 107:414e9c822e99 13 * Redistribution and use in source and binary forms, with or without
mbed_official 107:414e9c822e99 14 * modification, are permitted provided that the following conditions are met:
mbed_official 107:414e9c822e99 15 *
mbed_official 107:414e9c822e99 16 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 107:414e9c822e99 17 * this list of conditions and the following disclaimer.
mbed_official 107:414e9c822e99 18 *
mbed_official 107:414e9c822e99 19 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 107:414e9c822e99 20 * this list of conditions and the following disclaimer in the documentation
mbed_official 107:414e9c822e99 21 * and/or other materials provided with the distribution.
mbed_official 107:414e9c822e99 22 *
mbed_official 107:414e9c822e99 23 * 3. The name of Atmel may not be used to endorse or promote products derived
mbed_official 107:414e9c822e99 24 * from this software without specific prior written permission.
mbed_official 107:414e9c822e99 25 *
mbed_official 107:414e9c822e99 26 * 4. This software may only be redistributed and used in connection with an
mbed_official 107:414e9c822e99 27 * Atmel microcontroller product.
mbed_official 107:414e9c822e99 28 *
mbed_official 107:414e9c822e99 29 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
mbed_official 107:414e9c822e99 30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 107:414e9c822e99 31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
mbed_official 107:414e9c822e99 32 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
mbed_official 107:414e9c822e99 33 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 107:414e9c822e99 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
mbed_official 107:414e9c822e99 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
mbed_official 107:414e9c822e99 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
mbed_official 107:414e9c822e99 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 107:414e9c822e99 38 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 107:414e9c822e99 39 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 107:414e9c822e99 40 *
mbed_official 107:414e9c822e99 41 * \asf_license_stop
mbed_official 107:414e9c822e99 42 *
mbed_official 107:414e9c822e99 43 */
mbed_official 107:414e9c822e99 44 /*
mbed_official 107:414e9c822e99 45 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
mbed_official 107:414e9c822e99 46 */
mbed_official 107:414e9c822e99 47 #ifndef IOPORT_H
mbed_official 107:414e9c822e99 48 #define IOPORT_H
mbed_official 107:414e9c822e99 49
mbed_official 107:414e9c822e99 50 #ifdef __cplusplus
mbed_official 107:414e9c822e99 51 extern "C" {
mbed_official 107:414e9c822e99 52 #endif
mbed_official 107:414e9c822e99 53
mbed_official 107:414e9c822e99 54 #include <parts.h>
mbed_official 107:414e9c822e99 55 #include <compiler.h>
mbed_official 107:414e9c822e99 56
mbed_official 107:414e9c822e99 57 /**
mbed_official 107:414e9c822e99 58 * \defgroup ioport_group Common IOPORT API
mbed_official 107:414e9c822e99 59 *
mbed_official 107:414e9c822e99 60 * See \ref ioport_quickstart.
mbed_official 107:414e9c822e99 61 *
mbed_official 107:414e9c822e99 62 * This is common IOPORT service for GPIO pin configuration and control in a
mbed_official 107:414e9c822e99 63 * standardized manner across the MEGA, MEGA_RF, XMEGA, UC3 and ARM devices.
mbed_official 107:414e9c822e99 64 *
mbed_official 107:414e9c822e99 65 * Port pin control code is optimized for each platform, and should produce
mbed_official 107:414e9c822e99 66 * both compact and fast execution times when used with constant values.
mbed_official 107:414e9c822e99 67 *
mbed_official 107:414e9c822e99 68 * \section dependencies Dependencies
mbed_official 107:414e9c822e99 69 * This driver depends on the following modules:
mbed_official 107:414e9c822e99 70 * - \ref sysclk_group for clock speed and functions.
mbed_official 107:414e9c822e99 71 * @{
mbed_official 107:414e9c822e99 72 */
mbed_official 107:414e9c822e99 73
mbed_official 107:414e9c822e99 74 /**
mbed_official 107:414e9c822e99 75 * \def IOPORT_CREATE_PIN(port, pin)
mbed_official 107:414e9c822e99 76 * \brief Create IOPORT pin number
mbed_official 107:414e9c822e99 77 *
mbed_official 107:414e9c822e99 78 * Create a IOPORT pin number for use with the IOPORT functions.
mbed_official 107:414e9c822e99 79 *
mbed_official 107:414e9c822e99 80 * \param port IOPORT port (e.g. PORTA, PA or PIOA depending on chosen
mbed_official 107:414e9c822e99 81 * architecture)
mbed_official 107:414e9c822e99 82 * \param pin IOPORT zero-based index of the I/O pin
mbed_official 107:414e9c822e99 83 */
mbed_official 107:414e9c822e99 84
mbed_official 107:414e9c822e99 85 /** \brief IOPORT pin directions */
mbed_official 107:414e9c822e99 86 enum ioport_direction {
mbed_official 107:414e9c822e99 87 IOPORT_DIR_INPUT, /*!< IOPORT input direction */
mbed_official 107:414e9c822e99 88 IOPORT_DIR_OUTPUT, /*!< IOPORT output direction */
mbed_official 107:414e9c822e99 89 };
mbed_official 107:414e9c822e99 90
mbed_official 107:414e9c822e99 91 /** \brief IOPORT levels */
mbed_official 107:414e9c822e99 92 enum ioport_value {
mbed_official 107:414e9c822e99 93 IOPORT_PIN_LEVEL_LOW, /*!< IOPORT pin value low */
mbed_official 107:414e9c822e99 94 IOPORT_PIN_LEVEL_HIGH, /*!< IOPORT pin value high */
mbed_official 107:414e9c822e99 95 };
mbed_official 107:414e9c822e99 96
mbed_official 107:414e9c822e99 97 #if MEGA_RF
mbed_official 107:414e9c822e99 98 /** \brief IOPORT edge sense modes */
mbed_official 107:414e9c822e99 99 enum ioport_sense {
mbed_official 107:414e9c822e99 100 IOPORT_SENSE_LEVEL, /*!< IOPORT sense low level */
mbed_official 107:414e9c822e99 101 IOPORT_SENSE_BOTHEDGES, /*!< IOPORT sense both rising and falling edges */
mbed_official 107:414e9c822e99 102 IOPORT_SENSE_FALLING, /*!< IOPORT sense falling edges */
mbed_official 107:414e9c822e99 103 IOPORT_SENSE_RISING, /*!< IOPORT sense rising edges */
mbed_official 107:414e9c822e99 104 };
mbed_official 107:414e9c822e99 105 #elif SAM && !SAM4L
mbed_official 107:414e9c822e99 106 /** \brief IOPORT edge sense modes */
mbed_official 107:414e9c822e99 107 enum ioport_sense {
mbed_official 107:414e9c822e99 108 IOPORT_SENSE_BOTHEDGES, /*!< IOPORT sense both rising and falling edges */
mbed_official 107:414e9c822e99 109 IOPORT_SENSE_FALLING, /*!< IOPORT sense falling edges */
mbed_official 107:414e9c822e99 110 IOPORT_SENSE_RISING, /*!< IOPORT sense rising edges */
mbed_official 107:414e9c822e99 111 IOPORT_SENSE_LEVEL_LOW, /*!< IOPORT sense low level */
mbed_official 107:414e9c822e99 112 IOPORT_SENSE_LEVEL_HIGH,/*!< IOPORT sense High level */
mbed_official 107:414e9c822e99 113 };
mbed_official 107:414e9c822e99 114 #else
mbed_official 107:414e9c822e99 115 enum ioport_sense {
mbed_official 107:414e9c822e99 116 IOPORT_SENSE_BOTHEDGES, /*!< IOPORT sense both rising and falling edges */
mbed_official 107:414e9c822e99 117 IOPORT_SENSE_RISING, /*!< IOPORT sense rising edges */
mbed_official 107:414e9c822e99 118 IOPORT_SENSE_FALLING, /*!< IOPORT sense falling edges */
mbed_official 107:414e9c822e99 119 };
mbed_official 107:414e9c822e99 120 #endif
mbed_official 107:414e9c822e99 121
mbed_official 107:414e9c822e99 122
mbed_official 107:414e9c822e99 123 #if XMEGA
mbed_official 107:414e9c822e99 124 # include "xmega/ioport.h"
mbed_official 107:414e9c822e99 125 # if defined(IOPORT_XMEGA_COMPAT)
mbed_official 107:414e9c822e99 126 # include "xmega/ioport_compat.h"
mbed_official 107:414e9c822e99 127 # endif
mbed_official 107:414e9c822e99 128 #elif MEGA
mbed_official 107:414e9c822e99 129 # include "mega/ioport.h"
mbed_official 107:414e9c822e99 130 #elif UC3
mbed_official 107:414e9c822e99 131 # include "uc3/ioport.h"
mbed_official 107:414e9c822e99 132 #elif SAM
mbed_official 107:414e9c822e99 133 # if SAM4L
mbed_official 107:414e9c822e99 134 # include "sam/ioport_gpio.h"
mbed_official 107:414e9c822e99 135 # elif (SAMD20 | SAMD21)
mbed_official 107:414e9c822e99 136 # include "sam0/ioport.h"
mbed_official 107:414e9c822e99 137 # else
mbed_official 107:414e9c822e99 138 # include "sam/ioport_pio.h"
mbed_official 107:414e9c822e99 139 # endif
mbed_official 107:414e9c822e99 140 #endif
mbed_official 107:414e9c822e99 141
mbed_official 107:414e9c822e99 142 /**
mbed_official 107:414e9c822e99 143 * \brief Initializes the IOPORT service, ready for use.
mbed_official 107:414e9c822e99 144 *
mbed_official 107:414e9c822e99 145 * This function must be called before using any other functions in the IOPORT
mbed_official 107:414e9c822e99 146 * service.
mbed_official 107:414e9c822e99 147 */
mbed_official 107:414e9c822e99 148 static inline void ioport_init(void)
mbed_official 107:414e9c822e99 149 {
mbed_official 107:414e9c822e99 150 arch_ioport_init();
mbed_official 107:414e9c822e99 151 }
mbed_official 107:414e9c822e99 152
mbed_official 107:414e9c822e99 153 /**
mbed_official 107:414e9c822e99 154 * \brief Enable an IOPORT pin, based on a pin created with \ref
mbed_official 107:414e9c822e99 155 * IOPORT_CREATE_PIN().
mbed_official 107:414e9c822e99 156 *
mbed_official 107:414e9c822e99 157 * \param pin IOPORT pin to enable
mbed_official 107:414e9c822e99 158 */
mbed_official 107:414e9c822e99 159 static inline void ioport_enable_pin(ioport_pin_t pin)
mbed_official 107:414e9c822e99 160 {
mbed_official 107:414e9c822e99 161 arch_ioport_enable_pin(pin);
mbed_official 107:414e9c822e99 162 }
mbed_official 107:414e9c822e99 163
mbed_official 107:414e9c822e99 164 /**
mbed_official 107:414e9c822e99 165 * \brief Enable multiple pins in a single IOPORT port.
mbed_official 107:414e9c822e99 166 *
mbed_official 107:414e9c822e99 167 * \param port IOPORT port to enable
mbed_official 107:414e9c822e99 168 * \param mask Mask of pins within the port to enable
mbed_official 107:414e9c822e99 169 */
mbed_official 107:414e9c822e99 170 static inline void ioport_enable_port(ioport_port_t port,
mbed_official 107:414e9c822e99 171 ioport_port_mask_t mask)
mbed_official 107:414e9c822e99 172 {
mbed_official 107:414e9c822e99 173 arch_ioport_enable_port(port, mask);
mbed_official 107:414e9c822e99 174 }
mbed_official 107:414e9c822e99 175
mbed_official 107:414e9c822e99 176 /**
mbed_official 107:414e9c822e99 177 * \brief Disable IOPORT pin, based on a pin created with \ref
mbed_official 107:414e9c822e99 178 * IOPORT_CREATE_PIN().
mbed_official 107:414e9c822e99 179 *
mbed_official 107:414e9c822e99 180 * \param pin IOPORT pin to disable
mbed_official 107:414e9c822e99 181 */
mbed_official 107:414e9c822e99 182 static inline void ioport_disable_pin(ioport_pin_t pin)
mbed_official 107:414e9c822e99 183 {
mbed_official 107:414e9c822e99 184 arch_ioport_disable_pin(pin);
mbed_official 107:414e9c822e99 185 }
mbed_official 107:414e9c822e99 186
mbed_official 107:414e9c822e99 187 /**
mbed_official 107:414e9c822e99 188 * \brief Disable multiple pins in a single IOPORT port.
mbed_official 107:414e9c822e99 189 *
mbed_official 107:414e9c822e99 190 * \param port IOPORT port to disable
mbed_official 107:414e9c822e99 191 * \param mask Pin mask of pins to disable
mbed_official 107:414e9c822e99 192 */
mbed_official 107:414e9c822e99 193 static inline void ioport_disable_port(ioport_port_t port,
mbed_official 107:414e9c822e99 194 ioport_port_mask_t mask)
mbed_official 107:414e9c822e99 195 {
mbed_official 107:414e9c822e99 196 arch_ioport_disable_port(port, mask);
mbed_official 107:414e9c822e99 197 }
mbed_official 107:414e9c822e99 198
mbed_official 107:414e9c822e99 199 /**
mbed_official 107:414e9c822e99 200 * \brief Set multiple pin modes in a single IOPORT port, such as pull-up,
mbed_official 107:414e9c822e99 201 * pull-down, etc. configuration.
mbed_official 107:414e9c822e99 202 *
mbed_official 107:414e9c822e99 203 * \param port IOPORT port to configure
mbed_official 107:414e9c822e99 204 * \param mask Pin mask of pins to configure
mbed_official 107:414e9c822e99 205 * \param mode Mode masks to configure for the specified pins (\ref
mbed_official 107:414e9c822e99 206 * ioport_modes)
mbed_official 107:414e9c822e99 207 */
mbed_official 107:414e9c822e99 208 static inline void ioport_set_port_mode(ioport_port_t port,
mbed_official 107:414e9c822e99 209 ioport_port_mask_t mask, ioport_mode_t mode)
mbed_official 107:414e9c822e99 210 {
mbed_official 107:414e9c822e99 211 arch_ioport_set_port_mode(port, mask, mode);
mbed_official 107:414e9c822e99 212 }
mbed_official 107:414e9c822e99 213
mbed_official 107:414e9c822e99 214 /**
mbed_official 107:414e9c822e99 215 * \brief Set pin mode for one single IOPORT pin.
mbed_official 107:414e9c822e99 216 *
mbed_official 107:414e9c822e99 217 * \param pin IOPORT pin to configure
mbed_official 107:414e9c822e99 218 * \param mode Mode masks to configure for the specified pin (\ref ioport_modes)
mbed_official 107:414e9c822e99 219 */
mbed_official 107:414e9c822e99 220 static inline void ioport_set_pin_mode(ioport_pin_t pin, ioport_mode_t mode)
mbed_official 107:414e9c822e99 221 {
mbed_official 107:414e9c822e99 222 arch_ioport_set_pin_mode(pin, mode);
mbed_official 107:414e9c822e99 223 }
mbed_official 107:414e9c822e99 224
mbed_official 107:414e9c822e99 225 /**
mbed_official 107:414e9c822e99 226 * \brief Reset multiple pin modes in a specified IOPORT port to defaults.
mbed_official 107:414e9c822e99 227 *
mbed_official 107:414e9c822e99 228 * \param port IOPORT port to configure
mbed_official 107:414e9c822e99 229 * \param mask Mask of pins whose mode configuration is to be reset
mbed_official 107:414e9c822e99 230 */
mbed_official 107:414e9c822e99 231 static inline void ioport_reset_port_mode(ioport_port_t port,
mbed_official 107:414e9c822e99 232 ioport_port_mask_t mask)
mbed_official 107:414e9c822e99 233 {
mbed_official 107:414e9c822e99 234 arch_ioport_set_port_mode(port, mask, 0);
mbed_official 107:414e9c822e99 235 }
mbed_official 107:414e9c822e99 236
mbed_official 107:414e9c822e99 237 /**
mbed_official 107:414e9c822e99 238 * \brief Reset pin mode configuration for a single IOPORT pin
mbed_official 107:414e9c822e99 239 *
mbed_official 107:414e9c822e99 240 * \param pin IOPORT pin to configure
mbed_official 107:414e9c822e99 241 */
mbed_official 107:414e9c822e99 242 static inline void ioport_reset_pin_mode(ioport_pin_t pin)
mbed_official 107:414e9c822e99 243 {
mbed_official 107:414e9c822e99 244 arch_ioport_set_pin_mode(pin, 0);
mbed_official 107:414e9c822e99 245 }
mbed_official 107:414e9c822e99 246
mbed_official 107:414e9c822e99 247 /**
mbed_official 107:414e9c822e99 248 * \brief Set I/O direction for a group of pins in a single IOPORT.
mbed_official 107:414e9c822e99 249 *
mbed_official 107:414e9c822e99 250 * \param port IOPORT port to configure
mbed_official 107:414e9c822e99 251 * \param mask Pin mask of pins to configure
mbed_official 107:414e9c822e99 252 * \param dir Direction to set for the specified pins (\ref ioport_direction)
mbed_official 107:414e9c822e99 253 */
mbed_official 107:414e9c822e99 254 static inline void ioport_set_port_dir(ioport_port_t port,
mbed_official 107:414e9c822e99 255 ioport_port_mask_t mask, enum ioport_direction dir)
mbed_official 107:414e9c822e99 256 {
mbed_official 107:414e9c822e99 257 arch_ioport_set_port_dir(port, mask, dir);
mbed_official 107:414e9c822e99 258 }
mbed_official 107:414e9c822e99 259
mbed_official 107:414e9c822e99 260 /**
mbed_official 107:414e9c822e99 261 * \brief Set direction for a single IOPORT pin.
mbed_official 107:414e9c822e99 262 *
mbed_official 107:414e9c822e99 263 * \param pin IOPORT pin to configure
mbed_official 107:414e9c822e99 264 * \param dir Direction to set for the specified pin (\ref ioport_direction)
mbed_official 107:414e9c822e99 265 */
mbed_official 107:414e9c822e99 266 static inline void ioport_set_pin_dir(ioport_pin_t pin,
mbed_official 107:414e9c822e99 267 enum ioport_direction dir)
mbed_official 107:414e9c822e99 268 {
mbed_official 107:414e9c822e99 269 arch_ioport_set_pin_dir(pin, dir);
mbed_official 107:414e9c822e99 270 }
mbed_official 107:414e9c822e99 271
mbed_official 107:414e9c822e99 272 /**
mbed_official 107:414e9c822e99 273 * \brief Set an IOPORT pin to a specified logical value.
mbed_official 107:414e9c822e99 274 *
mbed_official 107:414e9c822e99 275 * \param pin IOPORT pin to configure
mbed_official 107:414e9c822e99 276 * \param level Logical value of the pin
mbed_official 107:414e9c822e99 277 */
mbed_official 107:414e9c822e99 278 static inline void ioport_set_pin_level(ioport_pin_t pin, bool level)
mbed_official 107:414e9c822e99 279 {
mbed_official 107:414e9c822e99 280 arch_ioport_set_pin_level(pin, level);
mbed_official 107:414e9c822e99 281 }
mbed_official 107:414e9c822e99 282
mbed_official 107:414e9c822e99 283 /**
mbed_official 107:414e9c822e99 284 * \brief Set a group of IOPORT pins in a single port to a specified logical
mbed_official 107:414e9c822e99 285 * value.
mbed_official 107:414e9c822e99 286 *
mbed_official 107:414e9c822e99 287 * \param port IOPORT port to write to
mbed_official 107:414e9c822e99 288 * \param mask Pin mask of pins to modify
mbed_official 107:414e9c822e99 289 * \param level Level of the pins to be modified
mbed_official 107:414e9c822e99 290 */
mbed_official 107:414e9c822e99 291 static inline void ioport_set_port_level(ioport_port_t port,
mbed_official 107:414e9c822e99 292 ioport_port_mask_t mask, ioport_port_mask_t level)
mbed_official 107:414e9c822e99 293 {
mbed_official 107:414e9c822e99 294 arch_ioport_set_port_level(port, mask, level);
mbed_official 107:414e9c822e99 295 }
mbed_official 107:414e9c822e99 296
mbed_official 107:414e9c822e99 297 /**
mbed_official 107:414e9c822e99 298 * \brief Get current value of an IOPORT pin, which has been configured as an
mbed_official 107:414e9c822e99 299 * input.
mbed_official 107:414e9c822e99 300 *
mbed_official 107:414e9c822e99 301 * \param pin IOPORT pin to read
mbed_official 107:414e9c822e99 302 * \return Current logical value of the specified pin
mbed_official 107:414e9c822e99 303 */
mbed_official 107:414e9c822e99 304 static inline bool ioport_get_pin_level(ioport_pin_t pin)
mbed_official 107:414e9c822e99 305 {
mbed_official 107:414e9c822e99 306 return arch_ioport_get_pin_level(pin);
mbed_official 107:414e9c822e99 307 }
mbed_official 107:414e9c822e99 308
mbed_official 107:414e9c822e99 309 /**
mbed_official 107:414e9c822e99 310 * \brief Get current value of several IOPORT pins in a single port, which have
mbed_official 107:414e9c822e99 311 * been configured as an inputs.
mbed_official 107:414e9c822e99 312 *
mbed_official 107:414e9c822e99 313 * \param port IOPORT port to read
mbed_official 107:414e9c822e99 314 * \param mask Pin mask of pins to read
mbed_official 107:414e9c822e99 315 * \return Logical levels of the specified pins from the read port, returned as
mbed_official 107:414e9c822e99 316 * a mask.
mbed_official 107:414e9c822e99 317 */
mbed_official 107:414e9c822e99 318 static inline ioport_port_mask_t ioport_get_port_level(ioport_pin_t port,
mbed_official 107:414e9c822e99 319 ioport_port_mask_t mask)
mbed_official 107:414e9c822e99 320 {
mbed_official 107:414e9c822e99 321 return arch_ioport_get_port_level(port, mask);
mbed_official 107:414e9c822e99 322 }
mbed_official 107:414e9c822e99 323
mbed_official 107:414e9c822e99 324 /**
mbed_official 107:414e9c822e99 325 * \brief Toggle the value of an IOPORT pin, which has previously configured as
mbed_official 107:414e9c822e99 326 * an output.
mbed_official 107:414e9c822e99 327 *
mbed_official 107:414e9c822e99 328 * \param pin IOPORT pin to toggle
mbed_official 107:414e9c822e99 329 */
mbed_official 107:414e9c822e99 330 static inline void ioport_toggle_pin_level(ioport_pin_t pin)
mbed_official 107:414e9c822e99 331 {
mbed_official 107:414e9c822e99 332 arch_ioport_toggle_pin_level(pin);
mbed_official 107:414e9c822e99 333 }
mbed_official 107:414e9c822e99 334
mbed_official 107:414e9c822e99 335 /**
mbed_official 107:414e9c822e99 336 * \brief Toggle the values of several IOPORT pins located in a single port.
mbed_official 107:414e9c822e99 337 *
mbed_official 107:414e9c822e99 338 * \param port IOPORT port to modify
mbed_official 107:414e9c822e99 339 * \param mask Pin mask of pins to toggle
mbed_official 107:414e9c822e99 340 */
mbed_official 107:414e9c822e99 341 static inline void ioport_toggle_port_level(ioport_port_t port,
mbed_official 107:414e9c822e99 342 ioport_port_mask_t mask)
mbed_official 107:414e9c822e99 343 {
mbed_official 107:414e9c822e99 344 arch_ioport_toggle_port_level(port, mask);
mbed_official 107:414e9c822e99 345 }
mbed_official 107:414e9c822e99 346
mbed_official 107:414e9c822e99 347 /**
mbed_official 107:414e9c822e99 348 * \brief Set the pin sense mode of a single IOPORT pin.
mbed_official 107:414e9c822e99 349 *
mbed_official 107:414e9c822e99 350 * \param pin IOPORT pin to configure
mbed_official 107:414e9c822e99 351 * \param pin_sense Edge to sense for the pin (\ref ioport_sense)
mbed_official 107:414e9c822e99 352 */
mbed_official 107:414e9c822e99 353 static inline void ioport_set_pin_sense_mode(ioport_pin_t pin,
mbed_official 107:414e9c822e99 354 enum ioport_sense pin_sense)
mbed_official 107:414e9c822e99 355 {
mbed_official 107:414e9c822e99 356 arch_ioport_set_pin_sense_mode(pin, pin_sense);
mbed_official 107:414e9c822e99 357 }
mbed_official 107:414e9c822e99 358
mbed_official 107:414e9c822e99 359 /**
mbed_official 107:414e9c822e99 360 * \brief Set the pin sense mode of a multiple IOPORT pins on a single port.
mbed_official 107:414e9c822e99 361 *
mbed_official 107:414e9c822e99 362 * \param port IOPORT port to configure
mbed_official 107:414e9c822e99 363 * \param mask Bitmask if pins whose edge sense is to be configured
mbed_official 107:414e9c822e99 364 * \param pin_sense Edge to sense for the pins (\ref ioport_sense)
mbed_official 107:414e9c822e99 365 */
mbed_official 107:414e9c822e99 366 static inline void ioport_set_port_sense_mode(ioport_port_t port,
mbed_official 107:414e9c822e99 367 ioport_port_mask_t mask,
mbed_official 107:414e9c822e99 368 enum ioport_sense pin_sense)
mbed_official 107:414e9c822e99 369 {
mbed_official 107:414e9c822e99 370 arch_ioport_set_port_sense_mode(port, mask, pin_sense);
mbed_official 107:414e9c822e99 371 }
mbed_official 107:414e9c822e99 372
mbed_official 107:414e9c822e99 373 /**
mbed_official 107:414e9c822e99 374 * \brief Convert a pin ID into a its port ID.
mbed_official 107:414e9c822e99 375 *
mbed_official 107:414e9c822e99 376 * \param pin IOPORT pin ID to convert
mbed_official 107:414e9c822e99 377 * \retval Port ID for the given pin ID
mbed_official 107:414e9c822e99 378 */
mbed_official 107:414e9c822e99 379 static inline ioport_port_t ioport_pin_to_port_id(ioport_pin_t pin)
mbed_official 107:414e9c822e99 380 {
mbed_official 107:414e9c822e99 381 return arch_ioport_pin_to_port_id(pin);
mbed_official 107:414e9c822e99 382 }
mbed_official 107:414e9c822e99 383
mbed_official 107:414e9c822e99 384 /**
mbed_official 107:414e9c822e99 385 * \brief Convert a pin ID into a bitmask mask for the given pin on its port.
mbed_official 107:414e9c822e99 386 *
mbed_official 107:414e9c822e99 387 * \param pin IOPORT pin ID to convert
mbed_official 107:414e9c822e99 388 * \retval Bitmask with a bit set that corresponds to the given pin ID in its port
mbed_official 107:414e9c822e99 389 */
mbed_official 107:414e9c822e99 390 static inline ioport_port_mask_t ioport_pin_to_mask(ioport_pin_t pin)
mbed_official 107:414e9c822e99 391 {
mbed_official 107:414e9c822e99 392 return arch_ioport_pin_to_mask(pin);
mbed_official 107:414e9c822e99 393 }
mbed_official 107:414e9c822e99 394
mbed_official 107:414e9c822e99 395 /** @} */
mbed_official 107:414e9c822e99 396
mbed_official 107:414e9c822e99 397 /**
mbed_official 107:414e9c822e99 398 * \page ioport_quickstart Quick start guide for the common IOPORT service
mbed_official 107:414e9c822e99 399 *
mbed_official 107:414e9c822e99 400 * This is the quick start guide for the \ref ioport_group, with
mbed_official 107:414e9c822e99 401 * step-by-step instructions on how to configure and use the service in a
mbed_official 107:414e9c822e99 402 * selection of use cases.
mbed_official 107:414e9c822e99 403 *
mbed_official 107:414e9c822e99 404 * The use cases contain several code fragments. The code fragments in the
mbed_official 107:414e9c822e99 405 * steps for setup can be copied into a custom initialization function, while
mbed_official 107:414e9c822e99 406 * the steps for usage can be copied into, e.g., the main application function.
mbed_official 107:414e9c822e99 407 *
mbed_official 107:414e9c822e99 408 * \section ioport_quickstart_basic Basic use case
mbed_official 107:414e9c822e99 409 * In this use case we will configure one IO pin for button input and one for
mbed_official 107:414e9c822e99 410 * LED control. Then it will read the button state and output it on the LED.
mbed_official 107:414e9c822e99 411 *
mbed_official 107:414e9c822e99 412 * \section ioport_quickstart_basic_setup Setup steps
mbed_official 107:414e9c822e99 413 *
mbed_official 107:414e9c822e99 414 * \subsection ioport_quickstart_basic_setup_code Example code
mbed_official 107:414e9c822e99 415 * \code
mbed_official 107:414e9c822e99 416 #define MY_LED IOPORT_CREATE_PIN(PORTA, 5)
mbed_official 107:414e9c822e99 417 #define MY_BUTTON IOPORT_CREATE_PIN(PORTA, 6)
mbed_official 107:414e9c822e99 418
mbed_official 107:414e9c822e99 419 ioport_init();
mbed_official 107:414e9c822e99 420
mbed_official 107:414e9c822e99 421 ioport_set_pin_dir(MY_LED, IOPORT_DIR_OUTPUT);
mbed_official 107:414e9c822e99 422 ioport_set_pin_dir(MY_BUTTON, IOPORT_DIR_INPUT);
mbed_official 107:414e9c822e99 423 ioport_set_pin_mode(MY_BUTTON, IOPORT_MODE_PULLUP);
mbed_official 107:414e9c822e99 424 \endcode
mbed_official 107:414e9c822e99 425 *
mbed_official 107:414e9c822e99 426 * \subsection ioport_quickstart_basic_setup_flow Workflow
mbed_official 107:414e9c822e99 427 * -# It's useful to give the GPIOs symbolic names and this can be done with
mbed_official 107:414e9c822e99 428 * the \ref IOPORT_CREATE_PIN macro. We define one for a LED and one for a
mbed_official 107:414e9c822e99 429 * button.
mbed_official 107:414e9c822e99 430 * - \code
mbed_official 107:414e9c822e99 431 #define MY_LED IOPORT_CREATE_PIN(PORTA, 5)
mbed_official 107:414e9c822e99 432 #define MY_BUTTON IOPORT_CREATE_PIN(PORTA, 6)
mbed_official 107:414e9c822e99 433 \endcode
mbed_official 107:414e9c822e99 434 * - \note The usefulness of the \ref IOPORT_CREATE_PIN macro and port names
mbed_official 107:414e9c822e99 435 * differ between architectures:
mbed_official 107:414e9c822e99 436 * - MEGA, MEGA_RF and XMEGA: Use \ref IOPORT_CREATE_PIN macro with port definitions
mbed_official 107:414e9c822e99 437 * PORTA, PORTB ...
mbed_official 107:414e9c822e99 438 * - UC3: Most convenient to pick up the device header file pin definition
mbed_official 107:414e9c822e99 439 * and us it directly. E.g.: AVR32_PIN_PB06
mbed_official 107:414e9c822e99 440 * - SAM: Most convenient to pick up the device header file pin definition
mbed_official 107:414e9c822e99 441 * and us it directly. E.g.: PIO_PA5_IDX<br>
mbed_official 107:414e9c822e99 442 * \ref IOPORT_CREATE_PIN can also be used with port definitions
mbed_official 107:414e9c822e99 443 * PIOA, PIOB ...
mbed_official 107:414e9c822e99 444 * -# Initialize the ioport service. This typically enables the IO module if
mbed_official 107:414e9c822e99 445 * needed.
mbed_official 107:414e9c822e99 446 * - \code ioport_init(); \endcode
mbed_official 107:414e9c822e99 447 * -# Set the LED GPIO as output:
mbed_official 107:414e9c822e99 448 * - \code ioport_set_pin_dir(MY_LED, IOPORT_DIR_OUTPUT); \endcode
mbed_official 107:414e9c822e99 449 * -# Set the button GPIO as input:
mbed_official 107:414e9c822e99 450 * - \code ioport_set_pin_dir(MY_BUTTON, IOPORT_DIR_INPUT); \endcode
mbed_official 107:414e9c822e99 451 * -# Enable pull-up for the button GPIO:
mbed_official 107:414e9c822e99 452 * - \code ioport_set_pin_mode(MY_BUTTON, IOPORT_MODE_PULLUP); \endcode
mbed_official 107:414e9c822e99 453 *
mbed_official 107:414e9c822e99 454 * \section ioport_quickstart_basic_usage Usage steps
mbed_official 107:414e9c822e99 455 *
mbed_official 107:414e9c822e99 456 * \subsection ioport_quickstart_basic_usage_code Example code
mbed_official 107:414e9c822e99 457 * \code
mbed_official 107:414e9c822e99 458 bool value;
mbed_official 107:414e9c822e99 459
mbed_official 107:414e9c822e99 460 value = ioport_get_pin_level(MY_BUTTON);
mbed_official 107:414e9c822e99 461 ioport_set_pin_level(MY_LED, value);
mbed_official 107:414e9c822e99 462 \endcode
mbed_official 107:414e9c822e99 463 *
mbed_official 107:414e9c822e99 464 * \subsection ioport_quickstart_basic_usage_flow Workflow
mbed_official 107:414e9c822e99 465 * -# Define a boolean variable for state storage:
mbed_official 107:414e9c822e99 466 * - \code bool value; \endcode
mbed_official 107:414e9c822e99 467 * -# Read out the button level into variable value:
mbed_official 107:414e9c822e99 468 * - \code value = ioport_get_pin_level(MY_BUTTON); \endcode
mbed_official 107:414e9c822e99 469 * -# Set the LED to read out value from the button:
mbed_official 107:414e9c822e99 470 * - \code ioport_set_pin_level(MY_LED, value); \endcode
mbed_official 107:414e9c822e99 471 *
mbed_official 107:414e9c822e99 472 * \section ioport_quickstart_advanced Advanced use cases
mbed_official 107:414e9c822e99 473 * - \subpage ioport_quickstart_use_case_1 : Port access
mbed_official 107:414e9c822e99 474 */
mbed_official 107:414e9c822e99 475
mbed_official 107:414e9c822e99 476 /**
mbed_official 107:414e9c822e99 477 * \page ioport_quickstart_use_case_1 Advanced use case doing port access
mbed_official 107:414e9c822e99 478 *
mbed_official 107:414e9c822e99 479 * In this case we will read out the pins from one whole port and write the
mbed_official 107:414e9c822e99 480 * read value to another port.
mbed_official 107:414e9c822e99 481 *
mbed_official 107:414e9c822e99 482 * \section ioport_quickstart_use_case_1_setup Setup steps
mbed_official 107:414e9c822e99 483 *
mbed_official 107:414e9c822e99 484 * \subsection ioport_quickstart_use_case_1_setup_code Example code
mbed_official 107:414e9c822e99 485 * \code
mbed_official 107:414e9c822e99 486 #define IN_PORT IOPORT_PORTA
mbed_official 107:414e9c822e99 487 #define OUT_PORT IOPORT_PORTB
mbed_official 107:414e9c822e99 488 #define MASK 0x00000060
mbed_official 107:414e9c822e99 489
mbed_official 107:414e9c822e99 490 ioport_init();
mbed_official 107:414e9c822e99 491
mbed_official 107:414e9c822e99 492 ioport_set_port_dir(IN_PORT, MASK, IOPORT_DIR_INPUT);
mbed_official 107:414e9c822e99 493 ioport_set_port_dir(OUT_PORT, MASK, IOPORT_DIR_OUTPUT);
mbed_official 107:414e9c822e99 494 \endcode
mbed_official 107:414e9c822e99 495 *
mbed_official 107:414e9c822e99 496 * \subsection ioport_quickstart_basic_setup_flow Workflow
mbed_official 107:414e9c822e99 497 * -# It's useful to give the ports symbolic names:
mbed_official 107:414e9c822e99 498 * - \code
mbed_official 107:414e9c822e99 499 #define IN_PORT IOPORT_PORTA
mbed_official 107:414e9c822e99 500 #define OUT_PORT IOPORT_PORTB
mbed_official 107:414e9c822e99 501 \endcode
mbed_official 107:414e9c822e99 502 * - \note The port names differ between architectures:
mbed_official 107:414e9c822e99 503 * - MEGA_RF, MEGA and XMEGA: There are predefined names for ports: IOPORT_PORTA,
mbed_official 107:414e9c822e99 504 * IOPORT_PORTB ...
mbed_official 107:414e9c822e99 505 * - UC3: Use the index value of the different IO blocks: 0, 1 ...
mbed_official 107:414e9c822e99 506 * - SAM: There are predefined names for ports: IOPORT_PIOA, IOPORT_PIOB
mbed_official 107:414e9c822e99 507 * ...
mbed_official 107:414e9c822e99 508 * -# Also useful to define a mask for the bits to work with:
mbed_official 107:414e9c822e99 509 * - \code #define MASK 0x00000060 \endcode
mbed_official 107:414e9c822e99 510 * -# Initialize the ioport service. This typically enables the IO module if
mbed_official 107:414e9c822e99 511 * needed.
mbed_official 107:414e9c822e99 512 * - \code ioport_init(); \endcode
mbed_official 107:414e9c822e99 513 * -# Set one of the ports as input:
mbed_official 107:414e9c822e99 514 * - \code ioport_set_pin_dir(IN_PORT, MASK, IOPORT_DIR_INPUT); \endcode
mbed_official 107:414e9c822e99 515 * -# Set the other port as output:
mbed_official 107:414e9c822e99 516 * - \code ioport_set_pin_dir(OUT_PORT, MASK, IOPORT_DIR_OUTPUT); \endcode
mbed_official 107:414e9c822e99 517 *
mbed_official 107:414e9c822e99 518 * \section ioport_quickstart_basic_usage Usage steps
mbed_official 107:414e9c822e99 519 *
mbed_official 107:414e9c822e99 520 * \subsection ioport_quickstart_basic_usage_code Example code
mbed_official 107:414e9c822e99 521 * \code
mbed_official 107:414e9c822e99 522 ioport_port_mask_t value;
mbed_official 107:414e9c822e99 523
mbed_official 107:414e9c822e99 524 value = ioport_get_port_level(IN_PORT, MASK);
mbed_official 107:414e9c822e99 525 ioport_set_port_level(OUT_PORT, MASK, value);
mbed_official 107:414e9c822e99 526 \endcode
mbed_official 107:414e9c822e99 527 *
mbed_official 107:414e9c822e99 528 * \subsection ioport_quickstart_basic_usage_flow Workflow
mbed_official 107:414e9c822e99 529 * -# Define a variable for port date storage:
mbed_official 107:414e9c822e99 530 * - \code ioport_port_mask_t value; \endcode
mbed_official 107:414e9c822e99 531 * -# Read out from one port:
mbed_official 107:414e9c822e99 532 * - \code value = ioport_get_port_level(IN_PORT, MASK); \endcode
mbed_official 107:414e9c822e99 533 * -# Put the read data out on the other port:
mbed_official 107:414e9c822e99 534 * - \code ioport_set_port_level(OUT_PORT, MASK, value); \endcode
mbed_official 107:414e9c822e99 535 */
mbed_official 107:414e9c822e99 536
mbed_official 107:414e9c822e99 537 #ifdef __cplusplus
mbed_official 107:414e9c822e99 538 }
mbed_official 107:414e9c822e99 539 #endif
mbed_official 107:414e9c822e99 540
mbed_official 107:414e9c822e99 541 #endif /* IOPORT_H */