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