Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sun May 14 23:18:57 2017 +0000
Revision:
18:6a4db94011d3
Publishing again

Who changed what in which revision?

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