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