mbed library sources
Fork of mbed-src by
targets/hal/TARGET_Atmel/TARGET_SAM21/drivers/port/port.h@579:53297373a894, 2015-07-01 (annotated)
- Committer:
- mbed_official
- Date:
- Wed Jul 01 09:45:11 2015 +0100
- Revision:
- 579:53297373a894
- Child:
- 592:a274ee790e56
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081
Full URL: https://github.com/mbedmicro/mbed/commit/d5b4d2ab9c47edb4dc5776e7177b0c2263459081/
Initial version of drivers for SAMR21
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 579:53297373a894 | 1 | /** |
mbed_official | 579:53297373a894 | 2 | * \file |
mbed_official | 579:53297373a894 | 3 | * |
mbed_official | 579:53297373a894 | 4 | * \brief SAM GPIO Port Driver |
mbed_official | 579:53297373a894 | 5 | * |
mbed_official | 579:53297373a894 | 6 | * Copyright (C) 2012-2014 Atmel Corporation. All rights reserved. |
mbed_official | 579:53297373a894 | 7 | * |
mbed_official | 579:53297373a894 | 8 | * \asf_license_start |
mbed_official | 579:53297373a894 | 9 | * |
mbed_official | 579:53297373a894 | 10 | * \page License |
mbed_official | 579:53297373a894 | 11 | * |
mbed_official | 579:53297373a894 | 12 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 579:53297373a894 | 13 | * modification, are permitted provided that the following conditions are met: |
mbed_official | 579:53297373a894 | 14 | * |
mbed_official | 579:53297373a894 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 579:53297373a894 | 16 | * this list of conditions and the following disclaimer. |
mbed_official | 579:53297373a894 | 17 | * |
mbed_official | 579:53297373a894 | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 579:53297373a894 | 19 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 579:53297373a894 | 20 | * and/or other materials provided with the distribution. |
mbed_official | 579:53297373a894 | 21 | * |
mbed_official | 579:53297373a894 | 22 | * 3. The name of Atmel may not be used to endorse or promote products derived |
mbed_official | 579:53297373a894 | 23 | * from this software without specific prior written permission. |
mbed_official | 579:53297373a894 | 24 | * |
mbed_official | 579:53297373a894 | 25 | * 4. This software may only be redistributed and used in connection with an |
mbed_official | 579:53297373a894 | 26 | * Atmel microcontroller product. |
mbed_official | 579:53297373a894 | 27 | * |
mbed_official | 579:53297373a894 | 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED |
mbed_official | 579:53297373a894 | 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
mbed_official | 579:53297373a894 | 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE |
mbed_official | 579:53297373a894 | 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR |
mbed_official | 579:53297373a894 | 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 579:53297373a894 | 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
mbed_official | 579:53297373a894 | 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
mbed_official | 579:53297373a894 | 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
mbed_official | 579:53297373a894 | 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
mbed_official | 579:53297373a894 | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
mbed_official | 579:53297373a894 | 38 | * POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 579:53297373a894 | 39 | * |
mbed_official | 579:53297373a894 | 40 | * \asf_license_stop |
mbed_official | 579:53297373a894 | 41 | * |
mbed_official | 579:53297373a894 | 42 | */ |
mbed_official | 579:53297373a894 | 43 | /** |
mbed_official | 579:53297373a894 | 44 | * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> |
mbed_official | 579:53297373a894 | 45 | */ |
mbed_official | 579:53297373a894 | 46 | #ifndef PORT_H_INCLUDED |
mbed_official | 579:53297373a894 | 47 | #define PORT_H_INCLUDED |
mbed_official | 579:53297373a894 | 48 | |
mbed_official | 579:53297373a894 | 49 | /** |
mbed_official | 579:53297373a894 | 50 | * \defgroup asfdoc_sam0_port_group SAM Port Driver (PORT) |
mbed_official | 579:53297373a894 | 51 | * |
mbed_official | 579:53297373a894 | 52 | * This driver for Atmel庐 | SMART SAM devices provides an interface for the configuration |
mbed_official | 579:53297373a894 | 53 | * and management of the device's General Purpose Input/Output (GPIO) pin |
mbed_official | 579:53297373a894 | 54 | * functionality, for manual pin state reading and writing. |
mbed_official | 579:53297373a894 | 55 | * |
mbed_official | 579:53297373a894 | 56 | * The following peripherals are used by this module: |
mbed_official | 579:53297373a894 | 57 | * - PORT (GPIO Management) |
mbed_official | 579:53297373a894 | 58 | * |
mbed_official | 579:53297373a894 | 59 | * The following devices can use this module: |
mbed_official | 579:53297373a894 | 60 | * - Atmel | SMART SAM D20/D21 |
mbed_official | 579:53297373a894 | 61 | * - Atmel | SMART SAM R21 |
mbed_official | 579:53297373a894 | 62 | * - Atmel | SMART SAM D10/D11 |
mbed_official | 579:53297373a894 | 63 | * - Atmel | SMART SAM L21 |
mbed_official | 579:53297373a894 | 64 | * |
mbed_official | 579:53297373a894 | 65 | * The outline of this documentation is as follows: |
mbed_official | 579:53297373a894 | 66 | * - \ref asfdoc_sam0_port_prerequisites |
mbed_official | 579:53297373a894 | 67 | * - \ref asfdoc_sam0_port_module_overview |
mbed_official | 579:53297373a894 | 68 | * - \ref asfdoc_sam0_port_special_considerations |
mbed_official | 579:53297373a894 | 69 | * - \ref asfdoc_sam0_port_extra_info |
mbed_official | 579:53297373a894 | 70 | * - \ref asfdoc_sam0_port_examples |
mbed_official | 579:53297373a894 | 71 | * - \ref asfdoc_sam0_port_api_overview |
mbed_official | 579:53297373a894 | 72 | * |
mbed_official | 579:53297373a894 | 73 | * |
mbed_official | 579:53297373a894 | 74 | * \section asfdoc_sam0_port_prerequisites Prerequisites |
mbed_official | 579:53297373a894 | 75 | * |
mbed_official | 579:53297373a894 | 76 | * There are no prerequisites for this module. |
mbed_official | 579:53297373a894 | 77 | * |
mbed_official | 579:53297373a894 | 78 | * |
mbed_official | 579:53297373a894 | 79 | * \section asfdoc_sam0_port_module_overview Module Overview |
mbed_official | 579:53297373a894 | 80 | * |
mbed_official | 579:53297373a894 | 81 | * The device GPIO (PORT) module provides an interface between the user |
mbed_official | 579:53297373a894 | 82 | * application logic and external hardware peripherals, when general pin state |
mbed_official | 579:53297373a894 | 83 | * manipulation is required. This driver provides an easy-to-use interface to |
mbed_official | 579:53297373a894 | 84 | * the physical pin input samplers and output drivers, so that pins can be read |
mbed_official | 579:53297373a894 | 85 | * from or written to for general purpose external hardware control. |
mbed_official | 579:53297373a894 | 86 | * |
mbed_official | 579:53297373a894 | 87 | * \subsection asfdoc_sam0_port_features Driver Feature Macro Definition |
mbed_official | 579:53297373a894 | 88 | * <table> |
mbed_official | 579:53297373a894 | 89 | * <tr> |
mbed_official | 579:53297373a894 | 90 | * <th>Driver Feature Macro</th> |
mbed_official | 579:53297373a894 | 91 | * <th>Supported devices</th> |
mbed_official | 579:53297373a894 | 92 | * </tr> |
mbed_official | 579:53297373a894 | 93 | * <tr> |
mbed_official | 579:53297373a894 | 94 | * <td>FEATURE_PORT_INPUT_EVENT</td> |
mbed_official | 579:53297373a894 | 95 | * <td>SAML21</td> |
mbed_official | 579:53297373a894 | 96 | * </tr> |
mbed_official | 579:53297373a894 | 97 | * </table> |
mbed_official | 579:53297373a894 | 98 | * \note The specific features are only available in the driver when the |
mbed_official | 579:53297373a894 | 99 | * selected device supports those features. |
mbed_official | 579:53297373a894 | 100 | * |
mbed_official | 579:53297373a894 | 101 | * \subsection asfdoc_sam0_port_module_overview_pin_numbering Physical and Logical GPIO Pins |
mbed_official | 579:53297373a894 | 102 | * SAM devices use two naming conventions for the I/O pins in the device; one |
mbed_official | 579:53297373a894 | 103 | * physical and one logical. Each physical pin on a device package is assigned |
mbed_official | 579:53297373a894 | 104 | * both a physical port and pin identifier (e.g. "PORTA.0") as well as a |
mbed_official | 579:53297373a894 | 105 | * monotonically incrementing logical GPIO number (e.g. "GPIO0"). While the |
mbed_official | 579:53297373a894 | 106 | * former is used to map physical pins to their physical internal device module |
mbed_official | 579:53297373a894 | 107 | * counterparts, for simplicity the design of this driver uses the logical GPIO |
mbed_official | 579:53297373a894 | 108 | * numbers instead. |
mbed_official | 579:53297373a894 | 109 | * |
mbed_official | 579:53297373a894 | 110 | * \subsection asfdoc_sam0_port_module_overview_physical Physical Connection |
mbed_official | 579:53297373a894 | 111 | * |
mbed_official | 579:53297373a894 | 112 | * \ref asfdoc_sam0_port_module_int_connections "The diagram below" shows how |
mbed_official | 579:53297373a894 | 113 | * this module is interconnected within the device. |
mbed_official | 579:53297373a894 | 114 | * |
mbed_official | 579:53297373a894 | 115 | * \anchor asfdoc_sam0_port_module_int_connections |
mbed_official | 579:53297373a894 | 116 | * \dot |
mbed_official | 579:53297373a894 | 117 | * digraph overview { |
mbed_official | 579:53297373a894 | 118 | * node [label="Port Pad" shape=square] pad; |
mbed_official | 579:53297373a894 | 119 | * |
mbed_official | 579:53297373a894 | 120 | * subgraph driver { |
mbed_official | 579:53297373a894 | 121 | * node [label="Peripheral MUX" shape=trapezium] pinmux; |
mbed_official | 579:53297373a894 | 122 | * node [label="GPIO Module" shape=ellipse] gpio; |
mbed_official | 579:53297373a894 | 123 | * node [label="Other Peripheral Modules" shape=ellipse style=filled fillcolor=lightgray] peripherals; |
mbed_official | 579:53297373a894 | 124 | * } |
mbed_official | 579:53297373a894 | 125 | * |
mbed_official | 579:53297373a894 | 126 | * pinmux -> gpio; |
mbed_official | 579:53297373a894 | 127 | * pad -> pinmux; |
mbed_official | 579:53297373a894 | 128 | * pinmux -> peripherals; |
mbed_official | 579:53297373a894 | 129 | * } |
mbed_official | 579:53297373a894 | 130 | * \enddot |
mbed_official | 579:53297373a894 | 131 | * |
mbed_official | 579:53297373a894 | 132 | * |
mbed_official | 579:53297373a894 | 133 | * \section asfdoc_sam0_port_special_considerations Special Considerations |
mbed_official | 579:53297373a894 | 134 | * |
mbed_official | 579:53297373a894 | 135 | * The SAM port pin input sampler can be disabled when the pin is configured |
mbed_official | 579:53297373a894 | 136 | * in pure output mode to save power; reading the pin state of a pin configured |
mbed_official | 579:53297373a894 | 137 | * in output-only mode will read the logical output state that was last set. |
mbed_official | 579:53297373a894 | 138 | * |
mbed_official | 579:53297373a894 | 139 | * \section asfdoc_sam0_port_extra_info Extra Information |
mbed_official | 579:53297373a894 | 140 | * |
mbed_official | 579:53297373a894 | 141 | * For extra information, see \ref asfdoc_sam0_port_extra. This includes: |
mbed_official | 579:53297373a894 | 142 | * - \ref asfdoc_sam0_port_extra_acronyms |
mbed_official | 579:53297373a894 | 143 | * - \ref asfdoc_sam0_port_extra_dependencies |
mbed_official | 579:53297373a894 | 144 | * - \ref asfdoc_sam0_port_extra_errata |
mbed_official | 579:53297373a894 | 145 | * - \ref asfdoc_sam0_port_extra_history |
mbed_official | 579:53297373a894 | 146 | * |
mbed_official | 579:53297373a894 | 147 | * |
mbed_official | 579:53297373a894 | 148 | * \section asfdoc_sam0_port_examples Examples |
mbed_official | 579:53297373a894 | 149 | * |
mbed_official | 579:53297373a894 | 150 | * For a list of examples related to this driver, see |
mbed_official | 579:53297373a894 | 151 | * \ref asfdoc_sam0_port_exqsg. |
mbed_official | 579:53297373a894 | 152 | * |
mbed_official | 579:53297373a894 | 153 | * |
mbed_official | 579:53297373a894 | 154 | * \section asfdoc_sam0_port_api_overview API Overview |
mbed_official | 579:53297373a894 | 155 | * @{ |
mbed_official | 579:53297373a894 | 156 | */ |
mbed_official | 579:53297373a894 | 157 | |
mbed_official | 579:53297373a894 | 158 | #include <compiler.h> |
mbed_official | 579:53297373a894 | 159 | #include <pinmux.h> |
mbed_official | 579:53297373a894 | 160 | |
mbed_official | 579:53297373a894 | 161 | #ifdef __cplusplus |
mbed_official | 579:53297373a894 | 162 | extern "C" { |
mbed_official | 579:53297373a894 | 163 | #endif |
mbed_official | 579:53297373a894 | 164 | |
mbed_official | 579:53297373a894 | 165 | /** |
mbed_official | 579:53297373a894 | 166 | * \name Driver Feature Definition |
mbed_official | 579:53297373a894 | 167 | * Define port features set according to different device family. |
mbed_official | 579:53297373a894 | 168 | * @{ |
mbed_official | 579:53297373a894 | 169 | */ |
mbed_official | 579:53297373a894 | 170 | #if (SAML21) || defined(__DOXYGEN__) |
mbed_official | 579:53297373a894 | 171 | /** Event input control feature support for PORT group. */ |
mbed_official | 579:53297373a894 | 172 | # define FEATURE_PORT_INPUT_EVENT |
mbed_official | 579:53297373a894 | 173 | #endif |
mbed_official | 579:53297373a894 | 174 | /*@}*/ |
mbed_official | 579:53297373a894 | 175 | |
mbed_official | 579:53297373a894 | 176 | /** \name PORT Alias Macros |
mbed_official | 579:53297373a894 | 177 | * @{ |
mbed_official | 579:53297373a894 | 178 | */ |
mbed_official | 579:53297373a894 | 179 | |
mbed_official | 579:53297373a894 | 180 | /** Convenience definition for GPIO module group A on the device (if |
mbed_official | 579:53297373a894 | 181 | * available). */ |
mbed_official | 579:53297373a894 | 182 | #if (PORT_GROUPS > 0) || defined(__DOXYGEN__) |
mbed_official | 579:53297373a894 | 183 | # define PORTA PORT->Group[0] |
mbed_official | 579:53297373a894 | 184 | #endif |
mbed_official | 579:53297373a894 | 185 | |
mbed_official | 579:53297373a894 | 186 | #if (PORT_GROUPS > 1) || defined(__DOXYGEN__) |
mbed_official | 579:53297373a894 | 187 | /** Convenience definition for GPIO module group B on the device (if |
mbed_official | 579:53297373a894 | 188 | * available). */ |
mbed_official | 579:53297373a894 | 189 | # define PORTB PORT->Group[1] |
mbed_official | 579:53297373a894 | 190 | #endif |
mbed_official | 579:53297373a894 | 191 | |
mbed_official | 579:53297373a894 | 192 | #if (PORT_GROUPS > 2) || defined(__DOXYGEN__) |
mbed_official | 579:53297373a894 | 193 | /** Convenience definition for GPIO module group C on the device (if |
mbed_official | 579:53297373a894 | 194 | * available). */ |
mbed_official | 579:53297373a894 | 195 | # define PORTC PORT->Group[2] |
mbed_official | 579:53297373a894 | 196 | #endif |
mbed_official | 579:53297373a894 | 197 | |
mbed_official | 579:53297373a894 | 198 | #if (PORT_GROUPS > 3) || defined(__DOXYGEN__) |
mbed_official | 579:53297373a894 | 199 | /** Convenience definition for GPIO module group D on the device (if |
mbed_official | 579:53297373a894 | 200 | * available). */ |
mbed_official | 579:53297373a894 | 201 | # define PORTD PORT->Group[3] |
mbed_official | 579:53297373a894 | 202 | #endif |
mbed_official | 579:53297373a894 | 203 | |
mbed_official | 579:53297373a894 | 204 | /** @} */ |
mbed_official | 579:53297373a894 | 205 | |
mbed_official | 579:53297373a894 | 206 | /** |
mbed_official | 579:53297373a894 | 207 | * \brief Port pin direction configuration enum. |
mbed_official | 579:53297373a894 | 208 | * |
mbed_official | 579:53297373a894 | 209 | * Enum for the possible pin direction settings of the port pin configuration |
mbed_official | 579:53297373a894 | 210 | * structure, to indicate the direction the pin should use. |
mbed_official | 579:53297373a894 | 211 | */ |
mbed_official | 579:53297373a894 | 212 | enum port_pin_dir { |
mbed_official | 579:53297373a894 | 213 | /** The pin's input buffer should be enabled, so that the pin state can |
mbed_official | 579:53297373a894 | 214 | * be read. */ |
mbed_official | 579:53297373a894 | 215 | PORT_PIN_DIR_INPUT = SYSTEM_PINMUX_PIN_DIR_INPUT, |
mbed_official | 579:53297373a894 | 216 | /** The pin's output buffer should be enabled, so that the pin state can |
mbed_official | 579:53297373a894 | 217 | * be set. */ |
mbed_official | 579:53297373a894 | 218 | PORT_PIN_DIR_OUTPUT = SYSTEM_PINMUX_PIN_DIR_OUTPUT, |
mbed_official | 579:53297373a894 | 219 | /** The pin's output and input buffers should be enabled, so that the pin |
mbed_official | 579:53297373a894 | 220 | * state can be set and read back. */ |
mbed_official | 579:53297373a894 | 221 | PORT_PIN_DIR_OUTPUT_WTH_READBACK = SYSTEM_PINMUX_PIN_DIR_OUTPUT_WITH_READBACK, |
mbed_official | 579:53297373a894 | 222 | }; |
mbed_official | 579:53297373a894 | 223 | |
mbed_official | 579:53297373a894 | 224 | /** |
mbed_official | 579:53297373a894 | 225 | * \brief Port pin input pull configuration enum. |
mbed_official | 579:53297373a894 | 226 | * |
mbed_official | 579:53297373a894 | 227 | * Enum for the possible pin pull settings of the port pin configuration |
mbed_official | 579:53297373a894 | 228 | * structure, to indicate the type of logic level pull the pin should use. |
mbed_official | 579:53297373a894 | 229 | */ |
mbed_official | 579:53297373a894 | 230 | enum port_pin_pull { |
mbed_official | 579:53297373a894 | 231 | /** No logical pull should be applied to the pin. */ |
mbed_official | 579:53297373a894 | 232 | PORT_PIN_PULL_NONE = SYSTEM_PINMUX_PIN_PULL_NONE, |
mbed_official | 579:53297373a894 | 233 | /** Pin should be pulled up when idle. */ |
mbed_official | 579:53297373a894 | 234 | PORT_PIN_PULL_UP = SYSTEM_PINMUX_PIN_PULL_UP, |
mbed_official | 579:53297373a894 | 235 | /** Pin should be pulled down when idle. */ |
mbed_official | 579:53297373a894 | 236 | PORT_PIN_PULL_DOWN = SYSTEM_PINMUX_PIN_PULL_DOWN, |
mbed_official | 579:53297373a894 | 237 | }; |
mbed_official | 579:53297373a894 | 238 | |
mbed_official | 579:53297373a894 | 239 | #ifdef FEATURE_PORT_INPUT_EVENT |
mbed_official | 579:53297373a894 | 240 | /** |
mbed_official | 579:53297373a894 | 241 | * \brief Port input event action. |
mbed_official | 579:53297373a894 | 242 | * |
mbed_official | 579:53297373a894 | 243 | * List of port input events action on pin. |
mbed_official | 579:53297373a894 | 244 | */ |
mbed_official | 579:53297373a894 | 245 | enum port_input_event_action { |
mbed_official | 579:53297373a894 | 246 | /** Event out to pin. */ |
mbed_official | 579:53297373a894 | 247 | PORT_INPUT_EVENT_ACTION_OUT = 0, |
mbed_official | 579:53297373a894 | 248 | /** Set output register of pin on event. */ |
mbed_official | 579:53297373a894 | 249 | PORT_INPUT_EVENT_ACTION_SET, |
mbed_official | 579:53297373a894 | 250 | /** Clear output register pin on event. */ |
mbed_official | 579:53297373a894 | 251 | PORT_INPUT_EVENT_ACTION_CLR, |
mbed_official | 579:53297373a894 | 252 | /** Toggle output register pin on event. */ |
mbed_official | 579:53297373a894 | 253 | PORT_INPUT_EVENT_ACTION_TGL, |
mbed_official | 579:53297373a894 | 254 | }; |
mbed_official | 579:53297373a894 | 255 | |
mbed_official | 579:53297373a894 | 256 | /** |
mbed_official | 579:53297373a894 | 257 | * \brief Port input event. |
mbed_official | 579:53297373a894 | 258 | * |
mbed_official | 579:53297373a894 | 259 | * List of port input events. |
mbed_official | 579:53297373a894 | 260 | */ |
mbed_official | 579:53297373a894 | 261 | enum port_input_event { |
mbed_official | 579:53297373a894 | 262 | /** Port input event 0. */ |
mbed_official | 579:53297373a894 | 263 | PORT_INPUT_EVENT_0 = 0, |
mbed_official | 579:53297373a894 | 264 | /** Port input event 1. */ |
mbed_official | 579:53297373a894 | 265 | PORT_INPUT_EVENT_1 = 1, |
mbed_official | 579:53297373a894 | 266 | /** Port input event 2. */ |
mbed_official | 579:53297373a894 | 267 | PORT_INPUT_EVENT_2 = 2, |
mbed_official | 579:53297373a894 | 268 | /** Port input event 3. */ |
mbed_official | 579:53297373a894 | 269 | PORT_INPUT_EVENT_3 = 3, |
mbed_official | 579:53297373a894 | 270 | }; |
mbed_official | 579:53297373a894 | 271 | |
mbed_official | 579:53297373a894 | 272 | /** |
mbed_official | 579:53297373a894 | 273 | * \brief Port input event configuration structure. |
mbed_official | 579:53297373a894 | 274 | * |
mbed_official | 579:53297373a894 | 275 | * Configuration structure for a port input event. |
mbed_official | 579:53297373a894 | 276 | */ |
mbed_official | 579:53297373a894 | 277 | struct port_input_event_config { |
mbed_official | 579:53297373a894 | 278 | /** PPort input event action. */ |
mbed_official | 579:53297373a894 | 279 | enum port_input_event_action action; |
mbed_official | 579:53297373a894 | 280 | /** GPIO pin. */ |
mbed_official | 579:53297373a894 | 281 | uint8_t gpio_pin; |
mbed_official | 579:53297373a894 | 282 | }; |
mbed_official | 579:53297373a894 | 283 | #endif |
mbed_official | 579:53297373a894 | 284 | |
mbed_official | 579:53297373a894 | 285 | /** |
mbed_official | 579:53297373a894 | 286 | * \brief Port pin configuration structure. |
mbed_official | 579:53297373a894 | 287 | * |
mbed_official | 579:53297373a894 | 288 | * Configuration structure for a port pin instance. This structure should be |
mbed_official | 579:53297373a894 | 289 | * initialized by the \ref port_get_config_defaults() function before being |
mbed_official | 579:53297373a894 | 290 | * modified by the user application. |
mbed_official | 579:53297373a894 | 291 | */ |
mbed_official | 579:53297373a894 | 292 | struct port_config { |
mbed_official | 579:53297373a894 | 293 | /** Port buffer input/output direction. */ |
mbed_official | 579:53297373a894 | 294 | enum port_pin_dir direction; |
mbed_official | 579:53297373a894 | 295 | |
mbed_official | 579:53297373a894 | 296 | /** Port pull-up/pull-down for input pins. */ |
mbed_official | 579:53297373a894 | 297 | enum port_pin_pull input_pull; |
mbed_official | 579:53297373a894 | 298 | |
mbed_official | 579:53297373a894 | 299 | /** Enable lowest possible powerstate on the pin |
mbed_official | 579:53297373a894 | 300 | * |
mbed_official | 579:53297373a894 | 301 | * \note All other configurations will be ignored, the pin will be disabled. |
mbed_official | 579:53297373a894 | 302 | */ |
mbed_official | 579:53297373a894 | 303 | bool powersave; |
mbed_official | 579:53297373a894 | 304 | }; |
mbed_official | 579:53297373a894 | 305 | |
mbed_official | 579:53297373a894 | 306 | /** \name State Reading/Writing (Physical Group Orientated) |
mbed_official | 579:53297373a894 | 307 | * @{ |
mbed_official | 579:53297373a894 | 308 | */ |
mbed_official | 579:53297373a894 | 309 | |
mbed_official | 579:53297373a894 | 310 | /** |
mbed_official | 579:53297373a894 | 311 | * \brief Retrieves the PORT module group instance from a given GPIO pin number. |
mbed_official | 579:53297373a894 | 312 | * |
mbed_official | 579:53297373a894 | 313 | * Retrieves the PORT module group instance associated with a given logical |
mbed_official | 579:53297373a894 | 314 | * GPIO pin number. |
mbed_official | 579:53297373a894 | 315 | * |
mbed_official | 579:53297373a894 | 316 | * \param[in] gpio_pin Index of the GPIO pin to convert |
mbed_official | 579:53297373a894 | 317 | * |
mbed_official | 579:53297373a894 | 318 | * \return Base address of the associated PORT module. |
mbed_official | 579:53297373a894 | 319 | */ |
mbed_official | 579:53297373a894 | 320 | static inline PortGroup* port_get_group_from_gpio_pin( |
mbed_official | 579:53297373a894 | 321 | const uint8_t gpio_pin) |
mbed_official | 579:53297373a894 | 322 | { |
mbed_official | 579:53297373a894 | 323 | return system_pinmux_get_group_from_gpio_pin(gpio_pin); |
mbed_official | 579:53297373a894 | 324 | } |
mbed_official | 579:53297373a894 | 325 | |
mbed_official | 579:53297373a894 | 326 | /** |
mbed_official | 579:53297373a894 | 327 | * \brief Retrieves the state of a group of port pins that are configured as inputs. |
mbed_official | 579:53297373a894 | 328 | * |
mbed_official | 579:53297373a894 | 329 | * Reads the current logic level of a port module's pins and returns the |
mbed_official | 579:53297373a894 | 330 | * current levels as a bitmask. |
mbed_official | 579:53297373a894 | 331 | * |
mbed_official | 579:53297373a894 | 332 | * \param[in] port Base of the PORT module to read from |
mbed_official | 579:53297373a894 | 333 | * \param[in] mask Mask of the port pin(s) to read |
mbed_official | 579:53297373a894 | 334 | * |
mbed_official | 579:53297373a894 | 335 | * \return Status of the port pin(s) input buffers. |
mbed_official | 579:53297373a894 | 336 | */ |
mbed_official | 579:53297373a894 | 337 | static inline uint32_t port_group_get_input_level( |
mbed_official | 579:53297373a894 | 338 | const PortGroup *const port, |
mbed_official | 579:53297373a894 | 339 | const uint32_t mask) |
mbed_official | 579:53297373a894 | 340 | { |
mbed_official | 579:53297373a894 | 341 | /* Sanity check arguments */ |
mbed_official | 579:53297373a894 | 342 | Assert(port); |
mbed_official | 579:53297373a894 | 343 | |
mbed_official | 579:53297373a894 | 344 | return (port->IN.reg & mask); |
mbed_official | 579:53297373a894 | 345 | } |
mbed_official | 579:53297373a894 | 346 | |
mbed_official | 579:53297373a894 | 347 | /** |
mbed_official | 579:53297373a894 | 348 | * \brief Retrieves the state of a group of port pins that are configured as outputs. |
mbed_official | 579:53297373a894 | 349 | * |
mbed_official | 579:53297373a894 | 350 | * Reads the current logical output level of a port module's pins and returns |
mbed_official | 579:53297373a894 | 351 | * the current levels as a bitmask. |
mbed_official | 579:53297373a894 | 352 | * |
mbed_official | 579:53297373a894 | 353 | * \param[in] port Base of the PORT module to read from |
mbed_official | 579:53297373a894 | 354 | * \param[in] mask Mask of the port pin(s) to read |
mbed_official | 579:53297373a894 | 355 | * |
mbed_official | 579:53297373a894 | 356 | * \return Status of the port pin(s) output buffers. |
mbed_official | 579:53297373a894 | 357 | */ |
mbed_official | 579:53297373a894 | 358 | static inline uint32_t port_group_get_output_level( |
mbed_official | 579:53297373a894 | 359 | const PortGroup *const port, |
mbed_official | 579:53297373a894 | 360 | const uint32_t mask) |
mbed_official | 579:53297373a894 | 361 | { |
mbed_official | 579:53297373a894 | 362 | /* Sanity check arguments */ |
mbed_official | 579:53297373a894 | 363 | Assert(port); |
mbed_official | 579:53297373a894 | 364 | |
mbed_official | 579:53297373a894 | 365 | return (port->OUT.reg & mask); |
mbed_official | 579:53297373a894 | 366 | } |
mbed_official | 579:53297373a894 | 367 | |
mbed_official | 579:53297373a894 | 368 | /** |
mbed_official | 579:53297373a894 | 369 | * \brief Sets the state of a group of port pins that are configured as outputs. |
mbed_official | 579:53297373a894 | 370 | * |
mbed_official | 579:53297373a894 | 371 | * Sets the current output level of a port module's pins to a given logic |
mbed_official | 579:53297373a894 | 372 | * level. |
mbed_official | 579:53297373a894 | 373 | * |
mbed_official | 579:53297373a894 | 374 | * \param[out] port Base of the PORT module to write to |
mbed_official | 579:53297373a894 | 375 | * \param[in] mask Mask of the port pin(s) to change |
mbed_official | 579:53297373a894 | 376 | * \param[in] level_mask Mask of the port level(s) to set |
mbed_official | 579:53297373a894 | 377 | */ |
mbed_official | 579:53297373a894 | 378 | static inline void port_group_set_output_level( |
mbed_official | 579:53297373a894 | 379 | PortGroup *const port, |
mbed_official | 579:53297373a894 | 380 | const uint32_t mask, |
mbed_official | 579:53297373a894 | 381 | const uint32_t level_mask) |
mbed_official | 579:53297373a894 | 382 | { |
mbed_official | 579:53297373a894 | 383 | /* Sanity check arguments */ |
mbed_official | 579:53297373a894 | 384 | Assert(port); |
mbed_official | 579:53297373a894 | 385 | |
mbed_official | 579:53297373a894 | 386 | port->OUTSET.reg = (mask & level_mask); |
mbed_official | 579:53297373a894 | 387 | port->OUTCLR.reg = (mask & ~level_mask); |
mbed_official | 579:53297373a894 | 388 | } |
mbed_official | 579:53297373a894 | 389 | |
mbed_official | 579:53297373a894 | 390 | /** |
mbed_official | 579:53297373a894 | 391 | * \brief Toggles the state of a group of port pins that are configured as an outputs. |
mbed_official | 579:53297373a894 | 392 | * |
mbed_official | 579:53297373a894 | 393 | * Toggles the current output levels of a port module's pins. |
mbed_official | 579:53297373a894 | 394 | * |
mbed_official | 579:53297373a894 | 395 | * \param[out] port Base of the PORT module to write to |
mbed_official | 579:53297373a894 | 396 | * \param[in] mask Mask of the port pin(s) to toggle |
mbed_official | 579:53297373a894 | 397 | */ |
mbed_official | 579:53297373a894 | 398 | static inline void port_group_toggle_output_level( |
mbed_official | 579:53297373a894 | 399 | PortGroup *const port, |
mbed_official | 579:53297373a894 | 400 | const uint32_t mask) |
mbed_official | 579:53297373a894 | 401 | { |
mbed_official | 579:53297373a894 | 402 | /* Sanity check arguments */ |
mbed_official | 579:53297373a894 | 403 | Assert(port); |
mbed_official | 579:53297373a894 | 404 | |
mbed_official | 579:53297373a894 | 405 | port->OUTTGL.reg = mask; |
mbed_official | 579:53297373a894 | 406 | } |
mbed_official | 579:53297373a894 | 407 | |
mbed_official | 579:53297373a894 | 408 | /** @} */ |
mbed_official | 579:53297373a894 | 409 | |
mbed_official | 579:53297373a894 | 410 | /** \name Configuration and Initialization |
mbed_official | 579:53297373a894 | 411 | * @{ |
mbed_official | 579:53297373a894 | 412 | */ |
mbed_official | 579:53297373a894 | 413 | |
mbed_official | 579:53297373a894 | 414 | /** |
mbed_official | 579:53297373a894 | 415 | * \brief Initializes a Port pin/group configuration structure to defaults. |
mbed_official | 579:53297373a894 | 416 | * |
mbed_official | 579:53297373a894 | 417 | * Initializes a given Port pin/group configuration structure to a set of |
mbed_official | 579:53297373a894 | 418 | * known default values. This function should be called on all new |
mbed_official | 579:53297373a894 | 419 | * instances of these configuration structures before being modified by the |
mbed_official | 579:53297373a894 | 420 | * user application. |
mbed_official | 579:53297373a894 | 421 | * |
mbed_official | 579:53297373a894 | 422 | * The default configuration is as follows: |
mbed_official | 579:53297373a894 | 423 | * \li Input mode with internal pullup enabled |
mbed_official | 579:53297373a894 | 424 | * |
mbed_official | 579:53297373a894 | 425 | * \param[out] config Configuration structure to initialize to default values |
mbed_official | 579:53297373a894 | 426 | */ |
mbed_official | 579:53297373a894 | 427 | static inline void port_get_config_defaults( |
mbed_official | 579:53297373a894 | 428 | struct port_config *const config) |
mbed_official | 579:53297373a894 | 429 | { |
mbed_official | 579:53297373a894 | 430 | /* Sanity check arguments */ |
mbed_official | 579:53297373a894 | 431 | Assert(config); |
mbed_official | 579:53297373a894 | 432 | |
mbed_official | 579:53297373a894 | 433 | /* Default configuration values */ |
mbed_official | 579:53297373a894 | 434 | config->direction = PORT_PIN_DIR_INPUT; |
mbed_official | 579:53297373a894 | 435 | config->input_pull = PORT_PIN_PULL_UP; |
mbed_official | 579:53297373a894 | 436 | config->powersave = false; |
mbed_official | 579:53297373a894 | 437 | } |
mbed_official | 579:53297373a894 | 438 | |
mbed_official | 579:53297373a894 | 439 | void port_pin_set_config( |
mbed_official | 579:53297373a894 | 440 | const uint8_t gpio_pin, |
mbed_official | 579:53297373a894 | 441 | const struct port_config *const config); |
mbed_official | 579:53297373a894 | 442 | |
mbed_official | 579:53297373a894 | 443 | void port_group_set_config( |
mbed_official | 579:53297373a894 | 444 | PortGroup *const port, |
mbed_official | 579:53297373a894 | 445 | const uint32_t mask, |
mbed_official | 579:53297373a894 | 446 | const struct port_config *const config); |
mbed_official | 579:53297373a894 | 447 | |
mbed_official | 579:53297373a894 | 448 | /** @} */ |
mbed_official | 579:53297373a894 | 449 | |
mbed_official | 579:53297373a894 | 450 | /** \name State Reading/Writing (Logical Pin Orientated) |
mbed_official | 579:53297373a894 | 451 | * @{ |
mbed_official | 579:53297373a894 | 452 | */ |
mbed_official | 579:53297373a894 | 453 | |
mbed_official | 579:53297373a894 | 454 | /** |
mbed_official | 579:53297373a894 | 455 | * \brief Retrieves the state of a port pin that is configured as an input. |
mbed_official | 579:53297373a894 | 456 | * |
mbed_official | 579:53297373a894 | 457 | * Reads the current logic level of a port pin and returns the current |
mbed_official | 579:53297373a894 | 458 | * level as a Boolean value. |
mbed_official | 579:53297373a894 | 459 | * |
mbed_official | 579:53297373a894 | 460 | * \param[in] gpio_pin Index of the GPIO pin to read |
mbed_official | 579:53297373a894 | 461 | * |
mbed_official | 579:53297373a894 | 462 | * \return Status of the port pin's input buffer. |
mbed_official | 579:53297373a894 | 463 | */ |
mbed_official | 579:53297373a894 | 464 | static inline bool port_pin_get_input_level( |
mbed_official | 579:53297373a894 | 465 | const uint8_t gpio_pin) |
mbed_official | 579:53297373a894 | 466 | { |
mbed_official | 579:53297373a894 | 467 | PortGroup *const port_base = port_get_group_from_gpio_pin(gpio_pin); |
mbed_official | 579:53297373a894 | 468 | uint32_t pin_mask = (1UL << (gpio_pin % 32)); |
mbed_official | 579:53297373a894 | 469 | |
mbed_official | 579:53297373a894 | 470 | return (port_base->IN.reg & pin_mask); |
mbed_official | 579:53297373a894 | 471 | } |
mbed_official | 579:53297373a894 | 472 | |
mbed_official | 579:53297373a894 | 473 | /** |
mbed_official | 579:53297373a894 | 474 | * \brief Retrieves the state of a port pin that is configured as an output. |
mbed_official | 579:53297373a894 | 475 | * |
mbed_official | 579:53297373a894 | 476 | * Reads the current logical output level of a port pin and returns the current |
mbed_official | 579:53297373a894 | 477 | * level as a Boolean value. |
mbed_official | 579:53297373a894 | 478 | * |
mbed_official | 579:53297373a894 | 479 | * \param[in] gpio_pin Index of the GPIO pin to read |
mbed_official | 579:53297373a894 | 480 | * |
mbed_official | 579:53297373a894 | 481 | * \return Status of the port pin's output buffer. |
mbed_official | 579:53297373a894 | 482 | */ |
mbed_official | 579:53297373a894 | 483 | static inline bool port_pin_get_output_level( |
mbed_official | 579:53297373a894 | 484 | const uint8_t gpio_pin) |
mbed_official | 579:53297373a894 | 485 | { |
mbed_official | 579:53297373a894 | 486 | PortGroup *const port_base = port_get_group_from_gpio_pin(gpio_pin); |
mbed_official | 579:53297373a894 | 487 | uint32_t pin_mask = (1UL << (gpio_pin % 32)); |
mbed_official | 579:53297373a894 | 488 | |
mbed_official | 579:53297373a894 | 489 | return (port_base->OUT.reg & pin_mask); |
mbed_official | 579:53297373a894 | 490 | } |
mbed_official | 579:53297373a894 | 491 | |
mbed_official | 579:53297373a894 | 492 | /** |
mbed_official | 579:53297373a894 | 493 | * \brief Sets the state of a port pin that is configured as an output. |
mbed_official | 579:53297373a894 | 494 | * |
mbed_official | 579:53297373a894 | 495 | * Sets the current output level of a port pin to a given logic level. |
mbed_official | 579:53297373a894 | 496 | * |
mbed_official | 579:53297373a894 | 497 | * \param[in] gpio_pin Index of the GPIO pin to write to |
mbed_official | 579:53297373a894 | 498 | * \param[in] level Logical level to set the given pin to |
mbed_official | 579:53297373a894 | 499 | */ |
mbed_official | 579:53297373a894 | 500 | static inline void port_pin_set_output_level( |
mbed_official | 579:53297373a894 | 501 | const uint8_t gpio_pin, |
mbed_official | 579:53297373a894 | 502 | const bool level) |
mbed_official | 579:53297373a894 | 503 | { |
mbed_official | 579:53297373a894 | 504 | PortGroup *const port_base = port_get_group_from_gpio_pin(gpio_pin); |
mbed_official | 579:53297373a894 | 505 | uint32_t pin_mask = (1UL << (gpio_pin % 32)); |
mbed_official | 579:53297373a894 | 506 | |
mbed_official | 579:53297373a894 | 507 | /* Set the pin to high or low atomically based on the requested level */ |
mbed_official | 579:53297373a894 | 508 | if (level) { |
mbed_official | 579:53297373a894 | 509 | port_base->OUTSET.reg = pin_mask; |
mbed_official | 579:53297373a894 | 510 | } else { |
mbed_official | 579:53297373a894 | 511 | port_base->OUTCLR.reg = pin_mask; |
mbed_official | 579:53297373a894 | 512 | } |
mbed_official | 579:53297373a894 | 513 | } |
mbed_official | 579:53297373a894 | 514 | |
mbed_official | 579:53297373a894 | 515 | /** |
mbed_official | 579:53297373a894 | 516 | * \brief Toggles the state of a port pin that is configured as an output. |
mbed_official | 579:53297373a894 | 517 | * |
mbed_official | 579:53297373a894 | 518 | * Toggles the current output level of a port pin. |
mbed_official | 579:53297373a894 | 519 | * |
mbed_official | 579:53297373a894 | 520 | * \param[in] gpio_pin Index of the GPIO pin to toggle |
mbed_official | 579:53297373a894 | 521 | */ |
mbed_official | 579:53297373a894 | 522 | static inline void port_pin_toggle_output_level( |
mbed_official | 579:53297373a894 | 523 | const uint8_t gpio_pin) |
mbed_official | 579:53297373a894 | 524 | { |
mbed_official | 579:53297373a894 | 525 | PortGroup *const port_base = port_get_group_from_gpio_pin(gpio_pin); |
mbed_official | 579:53297373a894 | 526 | uint32_t pin_mask = (1UL << (gpio_pin % 32)); |
mbed_official | 579:53297373a894 | 527 | |
mbed_official | 579:53297373a894 | 528 | /* Toggle pin output level */ |
mbed_official | 579:53297373a894 | 529 | port_base->OUTTGL.reg = pin_mask; |
mbed_official | 579:53297373a894 | 530 | } |
mbed_official | 579:53297373a894 | 531 | |
mbed_official | 579:53297373a894 | 532 | /** @} */ |
mbed_official | 579:53297373a894 | 533 | |
mbed_official | 579:53297373a894 | 534 | #ifdef FEATURE_PORT_INPUT_EVENT |
mbed_official | 579:53297373a894 | 535 | |
mbed_official | 579:53297373a894 | 536 | /** \name Port Input Event |
mbed_official | 579:53297373a894 | 537 | * @{ |
mbed_official | 579:53297373a894 | 538 | */ |
mbed_official | 579:53297373a894 | 539 | |
mbed_official | 579:53297373a894 | 540 | /** |
mbed_official | 579:53297373a894 | 541 | * \brief Enable the port event input. |
mbed_official | 579:53297373a894 | 542 | * |
mbed_official | 579:53297373a894 | 543 | * Enable the port event input with the given pin and event. |
mbed_official | 579:53297373a894 | 544 | * |
mbed_official | 579:53297373a894 | 545 | * \param[in] gpio_pin Index of the GPIO pin |
mbed_official | 579:53297373a894 | 546 | * \param[in] n Port input event |
mbed_official | 579:53297373a894 | 547 | * |
mbed_official | 579:53297373a894 | 548 | * \retval STATUS_ERR_INVALID_ARG Invalid parameter |
mbed_official | 579:53297373a894 | 549 | * \retval STATUS_OK Successfully |
mbed_official | 579:53297373a894 | 550 | */ |
mbed_official | 579:53297373a894 | 551 | static inline enum status_code port_enable_input_event( |
mbed_official | 579:53297373a894 | 552 | const uint8_t gpio_pin, |
mbed_official | 579:53297373a894 | 553 | const enum port_input_event n) |
mbed_official | 579:53297373a894 | 554 | { |
mbed_official | 579:53297373a894 | 555 | PortGroup *const port_base = port_get_group_from_gpio_pin(gpio_pin); |
mbed_official | 579:53297373a894 | 556 | switch (n) { |
mbed_official | 579:53297373a894 | 557 | case PORT_INPUT_EVENT_0: |
mbed_official | 579:53297373a894 | 558 | port_base->EVCTRL.reg |= PORT_EVCTRL_PORTEI0; |
mbed_official | 579:53297373a894 | 559 | break; |
mbed_official | 579:53297373a894 | 560 | case PORT_INPUT_EVENT_1: |
mbed_official | 579:53297373a894 | 561 | port_base->EVCTRL.reg |= PORT_EVCTRL_PORTEI1; |
mbed_official | 579:53297373a894 | 562 | break; |
mbed_official | 579:53297373a894 | 563 | case PORT_INPUT_EVENT_2: |
mbed_official | 579:53297373a894 | 564 | port_base->EVCTRL.reg |= PORT_EVCTRL_PORTEI2; |
mbed_official | 579:53297373a894 | 565 | break; |
mbed_official | 579:53297373a894 | 566 | case PORT_INPUT_EVENT_3: |
mbed_official | 579:53297373a894 | 567 | port_base->EVCTRL.reg |= PORT_EVCTRL_PORTEI3; |
mbed_official | 579:53297373a894 | 568 | break; |
mbed_official | 579:53297373a894 | 569 | default: |
mbed_official | 579:53297373a894 | 570 | Assert(false); |
mbed_official | 579:53297373a894 | 571 | return STATUS_ERR_INVALID_ARG; |
mbed_official | 579:53297373a894 | 572 | } |
mbed_official | 579:53297373a894 | 573 | return STATUS_OK; |
mbed_official | 579:53297373a894 | 574 | } |
mbed_official | 579:53297373a894 | 575 | |
mbed_official | 579:53297373a894 | 576 | /** |
mbed_official | 579:53297373a894 | 577 | * \brief Disable the port event input. |
mbed_official | 579:53297373a894 | 578 | * |
mbed_official | 579:53297373a894 | 579 | * Disable the port event input with the given pin and event. |
mbed_official | 579:53297373a894 | 580 | * |
mbed_official | 579:53297373a894 | 581 | * \param[in] gpio_pin Index of the GPIO pin |
mbed_official | 579:53297373a894 | 582 | * \param[in] gpio_pin Port input event |
mbed_official | 579:53297373a894 | 583 | * |
mbed_official | 579:53297373a894 | 584 | * \retval STATUS_ERR_INVALID_ARG Invalid parameter |
mbed_official | 579:53297373a894 | 585 | * \retval STATUS_OK Successfully |
mbed_official | 579:53297373a894 | 586 | */ |
mbed_official | 579:53297373a894 | 587 | static inline enum status_code port_disable_input_event( |
mbed_official | 579:53297373a894 | 588 | const uint8_t gpio_pin, |
mbed_official | 579:53297373a894 | 589 | const enum port_input_event n) |
mbed_official | 579:53297373a894 | 590 | { |
mbed_official | 579:53297373a894 | 591 | PortGroup *const port_base = port_get_group_from_gpio_pin(gpio_pin); |
mbed_official | 579:53297373a894 | 592 | switch (n) { |
mbed_official | 579:53297373a894 | 593 | case PORT_INPUT_EVENT_0: |
mbed_official | 579:53297373a894 | 594 | port_base->EVCTRL.reg &= ~PORT_EVCTRL_PORTEI0; |
mbed_official | 579:53297373a894 | 595 | break; |
mbed_official | 579:53297373a894 | 596 | case PORT_INPUT_EVENT_1: |
mbed_official | 579:53297373a894 | 597 | port_base->EVCTRL.reg &= ~PORT_EVCTRL_PORTEI1; |
mbed_official | 579:53297373a894 | 598 | break; |
mbed_official | 579:53297373a894 | 599 | case PORT_INPUT_EVENT_2: |
mbed_official | 579:53297373a894 | 600 | port_base->EVCTRL.reg &= ~PORT_EVCTRL_PORTEI2; |
mbed_official | 579:53297373a894 | 601 | break; |
mbed_official | 579:53297373a894 | 602 | case PORT_INPUT_EVENT_3: |
mbed_official | 579:53297373a894 | 603 | port_base->EVCTRL.reg &= ~PORT_EVCTRL_PORTEI3; |
mbed_official | 579:53297373a894 | 604 | break; |
mbed_official | 579:53297373a894 | 605 | default: |
mbed_official | 579:53297373a894 | 606 | Assert(false); |
mbed_official | 579:53297373a894 | 607 | return STATUS_ERR_INVALID_ARG; |
mbed_official | 579:53297373a894 | 608 | } |
mbed_official | 579:53297373a894 | 609 | return STATUS_OK; |
mbed_official | 579:53297373a894 | 610 | } |
mbed_official | 579:53297373a894 | 611 | |
mbed_official | 579:53297373a894 | 612 | /** |
mbed_official | 579:53297373a894 | 613 | * \brief Retrieve the default configuration for port input event. |
mbed_official | 579:53297373a894 | 614 | * |
mbed_official | 579:53297373a894 | 615 | * Fills a configuration structure with the default configuration for port input event: |
mbed_official | 579:53297373a894 | 616 | * - Event output to pin |
mbed_official | 579:53297373a894 | 617 | * - Event action to be executed on PIN 0 |
mbed_official | 579:53297373a894 | 618 | * |
mbed_official | 579:53297373a894 | 619 | * \param[out] config Configuration structure to fill with default values |
mbed_official | 579:53297373a894 | 620 | */ |
mbed_official | 579:53297373a894 | 621 | static inline void port_input_event_get_config_defaults( |
mbed_official | 579:53297373a894 | 622 | struct port_input_event_config *const config) |
mbed_official | 579:53297373a894 | 623 | { |
mbed_official | 579:53297373a894 | 624 | Assert(config); |
mbed_official | 579:53297373a894 | 625 | config->action = PORT_INPUT_EVENT_ACTION_OUT; |
mbed_official | 579:53297373a894 | 626 | config->gpio_pin = 0; |
mbed_official | 579:53297373a894 | 627 | } |
mbed_official | 579:53297373a894 | 628 | |
mbed_official | 579:53297373a894 | 629 | /** |
mbed_official | 579:53297373a894 | 630 | * \brief Configure port input event. |
mbed_official | 579:53297373a894 | 631 | * |
mbed_official | 579:53297373a894 | 632 | * Configures port input event with the given configuration settings. |
mbed_official | 579:53297373a894 | 633 | * |
mbed_official | 579:53297373a894 | 634 | * \param[in] config Port input even configuration structure containing the new config |
mbed_official | 579:53297373a894 | 635 | * |
mbed_official | 579:53297373a894 | 636 | * \retval STATUS_ERR_INVALID_ARG Invalid parameter |
mbed_official | 579:53297373a894 | 637 | * \retval STATUS_OK Successfully |
mbed_official | 579:53297373a894 | 638 | */ |
mbed_official | 579:53297373a894 | 639 | |
mbed_official | 579:53297373a894 | 640 | static inline enum status_code port_input_event_set_config( |
mbed_official | 579:53297373a894 | 641 | const enum port_input_event n, |
mbed_official | 579:53297373a894 | 642 | struct port_input_event_config *const config) |
mbed_official | 579:53297373a894 | 643 | { |
mbed_official | 579:53297373a894 | 644 | Assert(config); |
mbed_official | 579:53297373a894 | 645 | PortGroup *const port_base = port_get_group_from_gpio_pin(config->gpio_pin); |
mbed_official | 579:53297373a894 | 646 | uint8_t pin_index = config->gpio_pin % 32; |
mbed_official | 579:53297373a894 | 647 | struct port_config pin_conf; |
mbed_official | 579:53297373a894 | 648 | |
mbed_official | 579:53297373a894 | 649 | port_get_config_defaults(&pin_conf); |
mbed_official | 579:53297373a894 | 650 | /* Configure the GPIO pin as outputs*/ |
mbed_official | 579:53297373a894 | 651 | pin_conf.direction = PORT_PIN_DIR_OUTPUT; |
mbed_official | 579:53297373a894 | 652 | port_pin_set_config(config->gpio_pin, &pin_conf); |
mbed_official | 579:53297373a894 | 653 | |
mbed_official | 579:53297373a894 | 654 | switch (n) { |
mbed_official | 579:53297373a894 | 655 | case PORT_INPUT_EVENT_0: |
mbed_official | 579:53297373a894 | 656 | port_base->EVCTRL.reg |= PORT_EVCTRL_EVACT0(config->action) |
mbed_official | 579:53297373a894 | 657 | | PORT_EVCTRL_PID0(pin_index); |
mbed_official | 579:53297373a894 | 658 | break; |
mbed_official | 579:53297373a894 | 659 | case PORT_INPUT_EVENT_1: |
mbed_official | 579:53297373a894 | 660 | port_base->EVCTRL.reg |= PORT_EVCTRL_EVACT0(config->action) |
mbed_official | 579:53297373a894 | 661 | | PORT_EVCTRL_PID0(pin_index); |
mbed_official | 579:53297373a894 | 662 | break; |
mbed_official | 579:53297373a894 | 663 | case PORT_INPUT_EVENT_2: |
mbed_official | 579:53297373a894 | 664 | port_base->EVCTRL.reg |= PORT_EVCTRL_EVACT0(config->action) |
mbed_official | 579:53297373a894 | 665 | | PORT_EVCTRL_PID0(pin_index); |
mbed_official | 579:53297373a894 | 666 | break; |
mbed_official | 579:53297373a894 | 667 | case PORT_INPUT_EVENT_3: |
mbed_official | 579:53297373a894 | 668 | port_base->EVCTRL.reg |= PORT_EVCTRL_EVACT0(config->action) |
mbed_official | 579:53297373a894 | 669 | | PORT_EVCTRL_PID0(pin_index); |
mbed_official | 579:53297373a894 | 670 | break; |
mbed_official | 579:53297373a894 | 671 | default: |
mbed_official | 579:53297373a894 | 672 | Assert(false); |
mbed_official | 579:53297373a894 | 673 | return STATUS_ERR_INVALID_ARG; |
mbed_official | 579:53297373a894 | 674 | } |
mbed_official | 579:53297373a894 | 675 | return STATUS_OK; |
mbed_official | 579:53297373a894 | 676 | } |
mbed_official | 579:53297373a894 | 677 | |
mbed_official | 579:53297373a894 | 678 | /** @} */ |
mbed_official | 579:53297373a894 | 679 | |
mbed_official | 579:53297373a894 | 680 | #endif |
mbed_official | 579:53297373a894 | 681 | |
mbed_official | 579:53297373a894 | 682 | #ifdef __cplusplus |
mbed_official | 579:53297373a894 | 683 | } |
mbed_official | 579:53297373a894 | 684 | #endif |
mbed_official | 579:53297373a894 | 685 | |
mbed_official | 579:53297373a894 | 686 | /** @} */ |
mbed_official | 579:53297373a894 | 687 | |
mbed_official | 579:53297373a894 | 688 | /** |
mbed_official | 579:53297373a894 | 689 | * \page asfdoc_sam0_port_extra Extra Information for PORT Driver |
mbed_official | 579:53297373a894 | 690 | * |
mbed_official | 579:53297373a894 | 691 | * \section asfdoc_sam0_port_extra_acronyms Acronyms |
mbed_official | 579:53297373a894 | 692 | * Below is a table listing the acronyms used in this module, along with their |
mbed_official | 579:53297373a894 | 693 | * intended meanings. |
mbed_official | 579:53297373a894 | 694 | * |
mbed_official | 579:53297373a894 | 695 | * <table> |
mbed_official | 579:53297373a894 | 696 | * <tr> |
mbed_official | 579:53297373a894 | 697 | * <th>Acronym</th> |
mbed_official | 579:53297373a894 | 698 | * <th>Description</th> |
mbed_official | 579:53297373a894 | 699 | * </tr> |
mbed_official | 579:53297373a894 | 700 | * <tr> |
mbed_official | 579:53297373a894 | 701 | * <td>GPIO</td> |
mbed_official | 579:53297373a894 | 702 | * <td>General Purpose Input/Output</td> |
mbed_official | 579:53297373a894 | 703 | * </tr> |
mbed_official | 579:53297373a894 | 704 | * <tr> |
mbed_official | 579:53297373a894 | 705 | * <td>MUX</td> |
mbed_official | 579:53297373a894 | 706 | * <td>Multiplexer</td> |
mbed_official | 579:53297373a894 | 707 | * </tr> |
mbed_official | 579:53297373a894 | 708 | * </table> |
mbed_official | 579:53297373a894 | 709 | * |
mbed_official | 579:53297373a894 | 710 | * |
mbed_official | 579:53297373a894 | 711 | * \section asfdoc_sam0_port_extra_dependencies Dependencies |
mbed_official | 579:53297373a894 | 712 | * This driver has the following dependencies: |
mbed_official | 579:53297373a894 | 713 | * |
mbed_official | 579:53297373a894 | 714 | * - \ref asfdoc_sam0_system_pinmux_group "System Pin Multiplexer Driver" |
mbed_official | 579:53297373a894 | 715 | * |
mbed_official | 579:53297373a894 | 716 | * |
mbed_official | 579:53297373a894 | 717 | * \section asfdoc_sam0_port_extra_errata Errata |
mbed_official | 579:53297373a894 | 718 | * There are no errata related to this driver. |
mbed_official | 579:53297373a894 | 719 | * |
mbed_official | 579:53297373a894 | 720 | * |
mbed_official | 579:53297373a894 | 721 | * \section asfdoc_sam0_port_extra_history Module History |
mbed_official | 579:53297373a894 | 722 | * An overview of the module history is presented in the table below, with |
mbed_official | 579:53297373a894 | 723 | * details on the enhancements and fixes made to the module since its first |
mbed_official | 579:53297373a894 | 724 | * release. The current version of this corresponds to the newest version in |
mbed_official | 579:53297373a894 | 725 | * the table. |
mbed_official | 579:53297373a894 | 726 | * |
mbed_official | 579:53297373a894 | 727 | * <table> |
mbed_official | 579:53297373a894 | 728 | * <tr> |
mbed_official | 579:53297373a894 | 729 | * <th>Changelog</th> |
mbed_official | 579:53297373a894 | 730 | * </tr> |
mbed_official | 579:53297373a894 | 731 | * <tr> |
mbed_official | 579:53297373a894 | 732 | * <td>Added input event feature and support for SAML21</td> |
mbed_official | 579:53297373a894 | 733 | * </tr> |
mbed_official | 579:53297373a894 | 734 | * <tr> |
mbed_official | 579:53297373a894 | 735 | * <td>Added support for SAMD21</td> |
mbed_official | 579:53297373a894 | 736 | * </tr> |
mbed_official | 579:53297373a894 | 737 | * <tr> |
mbed_official | 579:53297373a894 | 738 | * <td>Initial Release</td> |
mbed_official | 579:53297373a894 | 739 | * </tr> |
mbed_official | 579:53297373a894 | 740 | * </table> |
mbed_official | 579:53297373a894 | 741 | */ |
mbed_official | 579:53297373a894 | 742 | |
mbed_official | 579:53297373a894 | 743 | /** |
mbed_official | 579:53297373a894 | 744 | * \page asfdoc_sam0_port_exqsg Examples for PORT Driver |
mbed_official | 579:53297373a894 | 745 | * |
mbed_official | 579:53297373a894 | 746 | * This is a list of the available Quick Start guides (QSGs) and example |
mbed_official | 579:53297373a894 | 747 | * applications for \ref asfdoc_sam0_port_group. QSGs are simple examples with |
mbed_official | 579:53297373a894 | 748 | * step-by-step instructions to configure and use this driver in a selection of |
mbed_official | 579:53297373a894 | 749 | * use cases. Note that QSGs can be compiled as a standalone application or be |
mbed_official | 579:53297373a894 | 750 | * added to the user application. |
mbed_official | 579:53297373a894 | 751 | * |
mbed_official | 579:53297373a894 | 752 | * - \subpage asfdoc_sam0_port_basic_use_case |
mbed_official | 579:53297373a894 | 753 | * |
mbed_official | 579:53297373a894 | 754 | * \page asfdoc_sam0_port_document_revision_history Document Revision History |
mbed_official | 579:53297373a894 | 755 | * |
mbed_official | 579:53297373a894 | 756 | * <table> |
mbed_official | 579:53297373a894 | 757 | * <tr> |
mbed_official | 579:53297373a894 | 758 | * <th>Doc. Rev.</td> |
mbed_official | 579:53297373a894 | 759 | * <th>Date</td> |
mbed_official | 579:53297373a894 | 760 | * <th>Comments</td> |
mbed_official | 579:53297373a894 | 761 | * </tr> |
mbed_official | 579:53297373a894 | 762 | * <tr> |
mbed_official | 579:53297373a894 | 763 | * <td>E</td> |
mbed_official | 579:53297373a894 | 764 | * <td>11/2014</td> |
mbed_official | 579:53297373a894 | 765 | * <td>Added input event feature and support for SAML21.</td> |
mbed_official | 579:53297373a894 | 766 | * </tr> |
mbed_official | 579:53297373a894 | 767 | * <tr> |
mbed_official | 579:53297373a894 | 768 | * <td>D</td> |
mbed_official | 579:53297373a894 | 769 | * <td>12/2014</td> |
mbed_official | 579:53297373a894 | 770 | * <td>Added support for SAMR21 and SAMD10/D11.</td> |
mbed_official | 579:53297373a894 | 771 | * </tr> |
mbed_official | 579:53297373a894 | 772 | * <tr> |
mbed_official | 579:53297373a894 | 773 | * <td>C</td> |
mbed_official | 579:53297373a894 | 774 | * <td>01/2014</td> |
mbed_official | 579:53297373a894 | 775 | * <td>Added support for SAMD21.</td> |
mbed_official | 579:53297373a894 | 776 | * </tr> |
mbed_official | 579:53297373a894 | 777 | * <tr> |
mbed_official | 579:53297373a894 | 778 | * <td>B</td> |
mbed_official | 579:53297373a894 | 779 | * <td>06/2013</td> |
mbed_official | 579:53297373a894 | 780 | * <td>Corrected documentation typos.</td> |
mbed_official | 579:53297373a894 | 781 | * </tr> |
mbed_official | 579:53297373a894 | 782 | * <tr> |
mbed_official | 579:53297373a894 | 783 | * <td>A</td> |
mbed_official | 579:53297373a894 | 784 | * <td>06/2013</td> |
mbed_official | 579:53297373a894 | 785 | * <td>Initial release</td> |
mbed_official | 579:53297373a894 | 786 | * </tr> |
mbed_official | 579:53297373a894 | 787 | * </table> |
mbed_official | 579:53297373a894 | 788 | */ |
mbed_official | 579:53297373a894 | 789 | |
mbed_official | 579:53297373a894 | 790 | #endif |