The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_MAX32625MBED/TOOLCHAIN_GCC_ARM/gpio.h@171:3a7713b1edbc, 2018-11-08 (annotated)
- Committer:
- AnnaBridge
- Date:
- Thu Nov 08 11:45:42 2018 +0000
- Revision:
- 171:3a7713b1edbc
- Parent:
- TARGET_MAX32625PICO_NO_BOOT/TARGET_Maxim/TARGET_MAX32625/mxc/gpio.h@169:a7c7b631e539
mbed library. Release version 164
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anna Bridge |
169:a7c7b631e539 | 1 | /** |
Anna Bridge |
169:a7c7b631e539 | 2 | * @file gpio.h |
Anna Bridge |
169:a7c7b631e539 | 3 | * @brief General-Purpose Input/Output (GPIO) function prototypes and data types. |
Anna Bridge |
169:a7c7b631e539 | 4 | */ |
Anna Bridge |
169:a7c7b631e539 | 5 | |
Anna Bridge |
169:a7c7b631e539 | 6 | /* **************************************************************************** |
Anna Bridge |
169:a7c7b631e539 | 7 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
Anna Bridge |
169:a7c7b631e539 | 8 | * |
Anna Bridge |
169:a7c7b631e539 | 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
Anna Bridge |
169:a7c7b631e539 | 10 | * copy of this software and associated documentation files (the "Software"), |
Anna Bridge |
169:a7c7b631e539 | 11 | * to deal in the Software without restriction, including without limitation |
Anna Bridge |
169:a7c7b631e539 | 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Anna Bridge |
169:a7c7b631e539 | 13 | * and/or sell copies of the Software, and to permit persons to whom the |
Anna Bridge |
169:a7c7b631e539 | 14 | * Software is furnished to do so, subject to the following conditions: |
Anna Bridge |
169:a7c7b631e539 | 15 | * |
Anna Bridge |
169:a7c7b631e539 | 16 | * The above copyright notice and this permission notice shall be included |
Anna Bridge |
169:a7c7b631e539 | 17 | * in all copies or substantial portions of the Software. |
Anna Bridge |
169:a7c7b631e539 | 18 | * |
Anna Bridge |
169:a7c7b631e539 | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
Anna Bridge |
169:a7c7b631e539 | 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
Anna Bridge |
169:a7c7b631e539 | 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
Anna Bridge |
169:a7c7b631e539 | 22 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
Anna Bridge |
169:a7c7b631e539 | 23 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
Anna Bridge |
169:a7c7b631e539 | 24 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
Anna Bridge |
169:a7c7b631e539 | 25 | * OTHER DEALINGS IN THE SOFTWARE. |
Anna Bridge |
169:a7c7b631e539 | 26 | * |
Anna Bridge |
169:a7c7b631e539 | 27 | * Except as contained in this notice, the name of Maxim Integrated |
Anna Bridge |
169:a7c7b631e539 | 28 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
Anna Bridge |
169:a7c7b631e539 | 29 | * Products, Inc. Branding Policy. |
Anna Bridge |
169:a7c7b631e539 | 30 | * |
Anna Bridge |
169:a7c7b631e539 | 31 | * The mere transfer of this software does not imply any licenses |
Anna Bridge |
169:a7c7b631e539 | 32 | * of trade secrets, proprietary technology, copyrights, patents, |
Anna Bridge |
169:a7c7b631e539 | 33 | * trademarks, maskwork rights, or any other form of intellectual |
Anna Bridge |
169:a7c7b631e539 | 34 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
Anna Bridge |
169:a7c7b631e539 | 35 | * ownership rights. |
Anna Bridge |
169:a7c7b631e539 | 36 | * |
Anna Bridge |
169:a7c7b631e539 | 37 | * $Date: 2016-08-15 20:04:11 -0500 (Mon, 15 Aug 2016) $ |
Anna Bridge |
169:a7c7b631e539 | 38 | * $Revision: 24085 $ |
Anna Bridge |
169:a7c7b631e539 | 39 | * |
Anna Bridge |
169:a7c7b631e539 | 40 | *************************************************************************** */ |
Anna Bridge |
169:a7c7b631e539 | 41 | |
Anna Bridge |
169:a7c7b631e539 | 42 | /* Define to prevent redundant inclusion */ |
Anna Bridge |
169:a7c7b631e539 | 43 | #ifndef _GPIO_H_ |
Anna Bridge |
169:a7c7b631e539 | 44 | #define _GPIO_H_ |
Anna Bridge |
169:a7c7b631e539 | 45 | |
Anna Bridge |
169:a7c7b631e539 | 46 | /* **** Includes **** */ |
Anna Bridge |
169:a7c7b631e539 | 47 | #include "mxc_config.h" |
Anna Bridge |
169:a7c7b631e539 | 48 | #include "gpio_regs.h" |
Anna Bridge |
169:a7c7b631e539 | 49 | |
Anna Bridge |
169:a7c7b631e539 | 50 | #ifdef __cplusplus |
Anna Bridge |
169:a7c7b631e539 | 51 | extern "C" { |
Anna Bridge |
169:a7c7b631e539 | 52 | #endif |
Anna Bridge |
169:a7c7b631e539 | 53 | |
Anna Bridge |
169:a7c7b631e539 | 54 | // Doxy group definition for this peripheral module |
Anna Bridge |
169:a7c7b631e539 | 55 | /** |
Anna Bridge |
169:a7c7b631e539 | 56 | * @defgroup gpio General-Purpose Input/Output (GPIO) |
Anna Bridge |
169:a7c7b631e539 | 57 | * @ingroup periphlibs |
Anna Bridge |
169:a7c7b631e539 | 58 | * @{ |
Anna Bridge |
169:a7c7b631e539 | 59 | */ |
Anna Bridge |
169:a7c7b631e539 | 60 | |
Anna Bridge |
169:a7c7b631e539 | 61 | /* **** Definitions **** */ |
Anna Bridge |
169:a7c7b631e539 | 62 | /** |
Anna Bridge |
169:a7c7b631e539 | 63 | * @defgroup gpio_port_pin Port and Pin Definitions |
Anna Bridge |
169:a7c7b631e539 | 64 | * @ingroup gpio |
Anna Bridge |
169:a7c7b631e539 | 65 | * @{ |
Anna Bridge |
169:a7c7b631e539 | 66 | * @defgroup gpio_port Port Definitions |
Anna Bridge |
169:a7c7b631e539 | 67 | * @ingroup gpio_port_pin |
Anna Bridge |
169:a7c7b631e539 | 68 | * @{ |
Anna Bridge |
169:a7c7b631e539 | 69 | */ |
Anna Bridge |
169:a7c7b631e539 | 70 | #define PORT_0 (0) /**< Port 0 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 71 | #define PORT_1 (1) /**< Port 1 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 72 | #define PORT_2 (2) /**< Port 2 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 73 | #define PORT_3 (3) /**< Port 3 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 74 | #define PORT_4 (4) /**< Port 4 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 75 | #define PORT_5 (5) /**< Port 5 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 76 | #define PORT_6 (6) /**< Port 6 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 77 | #define PORT_7 (7) /**< Port 7 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 78 | #define PORT_8 (8) /**< Port 8 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 79 | #define PORT_9 (9) /**< Port 9 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 80 | #define PORT_10 (10) /**< Port 10 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 81 | #define PORT_11 (11) /**< Port 11 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 82 | #define PORT_12 (12) /**< Port 12 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 83 | #define PORT_13 (13) /**< Port 13 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 84 | #define PORT_14 (14) /**< Port 14 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 85 | #define PORT_15 (15) /**< Port 15 Define*/ |
Anna Bridge |
169:a7c7b631e539 | 86 | /**@} end of gpio_port group*/ |
Anna Bridge |
169:a7c7b631e539 | 87 | /** |
Anna Bridge |
169:a7c7b631e539 | 88 | * @defgroup gpio_pin Pin Definitions |
Anna Bridge |
169:a7c7b631e539 | 89 | * @ingroup gpio_port_pin |
Anna Bridge |
169:a7c7b631e539 | 90 | * @{ |
Anna Bridge |
169:a7c7b631e539 | 91 | */ |
Anna Bridge |
169:a7c7b631e539 | 92 | #define PIN_0 (1 << 0) /**< Pin 0 Define */ |
Anna Bridge |
169:a7c7b631e539 | 93 | #define PIN_1 (1 << 1) /**< Pin 1 Define */ |
Anna Bridge |
169:a7c7b631e539 | 94 | #define PIN_2 (1 << 2) /**< Pin 2 Define */ |
Anna Bridge |
169:a7c7b631e539 | 95 | #define PIN_3 (1 << 3) /**< Pin 3 Define */ |
Anna Bridge |
169:a7c7b631e539 | 96 | #define PIN_4 (1 << 4) /**< Pin 4 Define */ |
Anna Bridge |
169:a7c7b631e539 | 97 | #define PIN_5 (1 << 5) /**< Pin 5 Define */ |
Anna Bridge |
169:a7c7b631e539 | 98 | #define PIN_6 (1 << 6) /**< Pin 6 Define */ |
Anna Bridge |
169:a7c7b631e539 | 99 | #define PIN_7 (1 << 7) /**< Pin 7 Define */ |
Anna Bridge |
169:a7c7b631e539 | 100 | /**@} end of gpio_pin group */ |
Anna Bridge |
169:a7c7b631e539 | 101 | /**@} end of gpio_port_pin group */ |
Anna Bridge |
169:a7c7b631e539 | 102 | |
Anna Bridge |
169:a7c7b631e539 | 103 | /** |
Anna Bridge |
169:a7c7b631e539 | 104 | * Enumeration type for the GPIO Function Type |
Anna Bridge |
169:a7c7b631e539 | 105 | */ |
Anna Bridge |
169:a7c7b631e539 | 106 | typedef enum { |
Anna Bridge |
169:a7c7b631e539 | 107 | GPIO_FUNC_GPIO = MXC_V_GPIO_FUNC_SEL_MODE_GPIO, /**< GPIO Function Selection */ |
Anna Bridge |
169:a7c7b631e539 | 108 | GPIO_FUNC_PT = MXC_V_GPIO_FUNC_SEL_MODE_PT, /**< Pulse Train Function Selection */ |
Anna Bridge |
169:a7c7b631e539 | 109 | GPIO_FUNC_TMR = MXC_V_GPIO_FUNC_SEL_MODE_TMR /**< Timer Function Selection */ |
Anna Bridge |
169:a7c7b631e539 | 110 | } |
Anna Bridge |
169:a7c7b631e539 | 111 | gpio_func_t; |
Anna Bridge |
169:a7c7b631e539 | 112 | |
Anna Bridge |
169:a7c7b631e539 | 113 | /** |
Anna Bridge |
169:a7c7b631e539 | 114 | * Enumeration type for the type of GPIO pad on a given pin. |
Anna Bridge |
169:a7c7b631e539 | 115 | */ |
Anna Bridge |
169:a7c7b631e539 | 116 | typedef enum { |
Anna Bridge |
169:a7c7b631e539 | 117 | GPIO_PAD_INPUT_PULLUP = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP, /**< Set pad to high impedance, weak pull-up */ |
Anna Bridge |
169:a7c7b631e539 | 118 | GPIO_PAD_OPEN_DRAIN = MXC_V_GPIO_OUT_MODE_OPEN_DRAIN, /**< Set pad to open-drain with high impedance with input buffer */ |
Anna Bridge |
169:a7c7b631e539 | 119 | GPIO_PAD_OPEN_DRAIN_PULLUP = MXC_V_GPIO_OUT_MODE_OPEN_DRAIN_WEAK_PULLUP, /**< Set pad to open-drain with weak pull-up */ |
Anna Bridge |
169:a7c7b631e539 | 120 | GPIO_PAD_INPUT = MXC_V_GPIO_OUT_MODE_NORMAL_HIGH_Z, /**< Set pad to high impednace, input buffer enabled */ |
Anna Bridge |
169:a7c7b631e539 | 121 | GPIO_PAD_NORMAL = MXC_V_GPIO_OUT_MODE_NORMAL, /**< Set pad to normal drive mode for high an low output */ |
Anna Bridge |
169:a7c7b631e539 | 122 | GPIO_PAD_SLOW = MXC_V_GPIO_OUT_MODE_SLOW_DRIVE, /**< Set pad to slow drive mode, which is normal mode with negative feedback to slow edge transitions */ |
Anna Bridge |
169:a7c7b631e539 | 123 | GPIO_PAD_FAST = MXC_V_GPIO_OUT_MODE_FAST_DRIVE, /**< Set pad to fash drive mode, which is normal mode with a transistor drive to drive fast high and low */ |
Anna Bridge |
169:a7c7b631e539 | 124 | GPIO_PAD_INPUT_PULLDOWN = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLDOWN, /**< Set pad to weak pulldown mode */ |
Anna Bridge |
169:a7c7b631e539 | 125 | GPIO_PAD_OPEN_SOURCE = MXC_V_GPIO_OUT_MODE_OPEN_SOURCE, /**< Set pad to open source mode, transistor drive to high */ |
Anna Bridge |
169:a7c7b631e539 | 126 | GPIO_PAD_OPEN_SOURCE_PULLDOWN = MXC_V_GPIO_OUT_MODE_OPEN_SOURCE_WEAK_PULLDOWN /**< Set pad to open source with weak pulldown mode, transistor drive to high, weak pulldown to GND for low */ |
Anna Bridge |
169:a7c7b631e539 | 127 | } gpio_pad_t; |
Anna Bridge |
169:a7c7b631e539 | 128 | |
Anna Bridge |
169:a7c7b631e539 | 129 | /** |
Anna Bridge |
169:a7c7b631e539 | 130 | * Structure type for configuring a GPIO port. |
Anna Bridge |
169:a7c7b631e539 | 131 | */ |
Anna Bridge |
169:a7c7b631e539 | 132 | typedef struct { |
Anna Bridge |
169:a7c7b631e539 | 133 | uint32_t port; /// Index of GPIO port |
Anna Bridge |
169:a7c7b631e539 | 134 | uint32_t mask; /// Pin mask. Multiple bits can be set. |
Anna Bridge |
169:a7c7b631e539 | 135 | gpio_func_t func; /// Function type |
Anna Bridge |
169:a7c7b631e539 | 136 | gpio_pad_t pad; /// Pad type |
Anna Bridge |
169:a7c7b631e539 | 137 | } gpio_cfg_t; |
Anna Bridge |
169:a7c7b631e539 | 138 | |
Anna Bridge |
169:a7c7b631e539 | 139 | /** |
Anna Bridge |
169:a7c7b631e539 | 140 | * Enumeration type for the interrupt type on a GPIO port. |
Anna Bridge |
169:a7c7b631e539 | 141 | */ |
Anna Bridge |
169:a7c7b631e539 | 142 | typedef enum { |
Anna Bridge |
169:a7c7b631e539 | 143 | GPIO_INT_DISABLE = MXC_V_GPIO_INT_MODE_DISABLE, /**< Disable interrupts */ |
Anna Bridge |
169:a7c7b631e539 | 144 | GPIO_INT_FALLING_EDGE = MXC_V_GPIO_INT_MODE_FALLING_EDGE, /**< Interrupt on Falling Edge */ |
Anna Bridge |
169:a7c7b631e539 | 145 | GPIO_INT_RISING_EDGE = MXC_V_GPIO_INT_MODE_RISING_EDGE, /**< Interrupt on Rising Edge */ |
Anna Bridge |
169:a7c7b631e539 | 146 | GPIO_INT_ANY_EDGE = MXC_V_GPIO_INT_MODE_ANY_EDGE, /**< Interrupt on Falling or Rising Edge */ |
Anna Bridge |
169:a7c7b631e539 | 147 | GPIO_INT_LOW_LEVEL = MXC_V_GPIO_INT_MODE_LOW_LVL, /**< Interrupt on a low level input detection */ |
Anna Bridge |
169:a7c7b631e539 | 148 | GPIO_INT_HIGH_LEVEL = MXC_V_GPIO_INT_MODE_HIGH_LVL /**< Interrupt on a high level input detection */ |
Anna Bridge |
169:a7c7b631e539 | 149 | } gpio_int_mode_t; |
Anna Bridge |
169:a7c7b631e539 | 150 | |
Anna Bridge |
169:a7c7b631e539 | 151 | /* **** Function Prototypes **** */ |
Anna Bridge |
169:a7c7b631e539 | 152 | |
Anna Bridge |
169:a7c7b631e539 | 153 | /** |
Anna Bridge |
169:a7c7b631e539 | 154 | * @brief Configure GPIO pin(s). |
Anna Bridge |
169:a7c7b631e539 | 155 | * @param cfg Pointer to configuration structure describing the pin. |
Anna Bridge |
169:a7c7b631e539 | 156 | * |
Anna Bridge |
169:a7c7b631e539 | 157 | * @return #E_NO_ERROR if everything is successful. |
Anna Bridge |
169:a7c7b631e539 | 158 | * |
Anna Bridge |
169:a7c7b631e539 | 159 | */ |
Anna Bridge |
169:a7c7b631e539 | 160 | int GPIO_Config(const gpio_cfg_t *cfg); |
Anna Bridge |
169:a7c7b631e539 | 161 | |
Anna Bridge |
169:a7c7b631e539 | 162 | /** |
Anna Bridge |
169:a7c7b631e539 | 163 | * @brief Gets the pin(s) input state. |
Anna Bridge |
169:a7c7b631e539 | 164 | * @param cfg Pointer to configuration structure describing the pin. |
Anna Bridge |
169:a7c7b631e539 | 165 | * |
Anna Bridge |
169:a7c7b631e539 | 166 | * @return The requested pin state. |
Anna Bridge |
169:a7c7b631e539 | 167 | * |
Anna Bridge |
169:a7c7b631e539 | 168 | */ |
Anna Bridge |
169:a7c7b631e539 | 169 | __STATIC_INLINE uint32_t GPIO_InGet(const gpio_cfg_t *cfg) |
Anna Bridge |
169:a7c7b631e539 | 170 | { |
Anna Bridge |
169:a7c7b631e539 | 171 | return (MXC_GPIO->in_val[cfg->port] & cfg->mask); |
Anna Bridge |
169:a7c7b631e539 | 172 | } |
Anna Bridge |
169:a7c7b631e539 | 173 | |
Anna Bridge |
169:a7c7b631e539 | 174 | /** |
Anna Bridge |
169:a7c7b631e539 | 175 | * @brief Sets the pin(s) to a high level output. |
Anna Bridge |
169:a7c7b631e539 | 176 | * @param cfg Pointer to configuration structure describing the pin. |
Anna Bridge |
169:a7c7b631e539 | 177 | * |
Anna Bridge |
169:a7c7b631e539 | 178 | */ |
Anna Bridge |
169:a7c7b631e539 | 179 | __STATIC_INLINE void GPIO_OutSet(const gpio_cfg_t *cfg) |
Anna Bridge |
169:a7c7b631e539 | 180 | { |
Anna Bridge |
169:a7c7b631e539 | 181 | MXC_GPIO->out_val[cfg->port] |= cfg->mask; |
Anna Bridge |
169:a7c7b631e539 | 182 | } |
Anna Bridge |
169:a7c7b631e539 | 183 | |
Anna Bridge |
169:a7c7b631e539 | 184 | /** |
Anna Bridge |
169:a7c7b631e539 | 185 | * @brief Clears the pin(s) to a low level output. |
Anna Bridge |
169:a7c7b631e539 | 186 | * @param cfg Pointer to configuration structure describing the pin. |
Anna Bridge |
169:a7c7b631e539 | 187 | * |
Anna Bridge |
169:a7c7b631e539 | 188 | */ |
Anna Bridge |
169:a7c7b631e539 | 189 | __STATIC_INLINE void GPIO_OutClr(const gpio_cfg_t *cfg) |
Anna Bridge |
169:a7c7b631e539 | 190 | { |
Anna Bridge |
169:a7c7b631e539 | 191 | MXC_GPIO->out_val[cfg->port] &= ~(cfg->mask); |
Anna Bridge |
169:a7c7b631e539 | 192 | } |
Anna Bridge |
169:a7c7b631e539 | 193 | |
Anna Bridge |
169:a7c7b631e539 | 194 | /** |
Anna Bridge |
169:a7c7b631e539 | 195 | * @brief Gets the pin(s) output state. |
Anna Bridge |
169:a7c7b631e539 | 196 | * @param cfg Pointer to configuration structure describing the pin. |
Anna Bridge |
169:a7c7b631e539 | 197 | * |
Anna Bridge |
169:a7c7b631e539 | 198 | * @return The state of the requested pin. |
Anna Bridge |
169:a7c7b631e539 | 199 | * |
Anna Bridge |
169:a7c7b631e539 | 200 | */ |
Anna Bridge |
169:a7c7b631e539 | 201 | __STATIC_INLINE uint32_t GPIO_OutGet(const gpio_cfg_t *cfg) |
Anna Bridge |
169:a7c7b631e539 | 202 | { |
Anna Bridge |
169:a7c7b631e539 | 203 | return (MXC_GPIO->out_val[cfg->port] & cfg->mask); |
Anna Bridge |
169:a7c7b631e539 | 204 | } |
Anna Bridge |
169:a7c7b631e539 | 205 | |
Anna Bridge |
169:a7c7b631e539 | 206 | /** |
Anna Bridge |
169:a7c7b631e539 | 207 | * @brief Write the pin(s) to a desired output level. |
Anna Bridge |
169:a7c7b631e539 | 208 | * @param cfg Pointer to configuration structure describing the pin. |
Anna Bridge |
169:a7c7b631e539 | 209 | * @param val Desired output level of the pin(s). This will be masked |
Anna Bridge |
169:a7c7b631e539 | 210 | * with the configuration mask. |
Anna Bridge |
169:a7c7b631e539 | 211 | * |
Anna Bridge |
169:a7c7b631e539 | 212 | */ |
Anna Bridge |
169:a7c7b631e539 | 213 | __STATIC_INLINE void GPIO_OutPut(const gpio_cfg_t *cfg, uint32_t val) |
Anna Bridge |
169:a7c7b631e539 | 214 | { |
Anna Bridge |
169:a7c7b631e539 | 215 | MXC_GPIO->out_val[cfg->port] = (MXC_GPIO->out_val[cfg->port] & ~cfg->mask) | (val & cfg->mask); |
Anna Bridge |
169:a7c7b631e539 | 216 | } |
Anna Bridge |
169:a7c7b631e539 | 217 | |
Anna Bridge |
169:a7c7b631e539 | 218 | /** |
Anna Bridge |
169:a7c7b631e539 | 219 | * @brief Toggles the the pin(s) output level. |
Anna Bridge |
169:a7c7b631e539 | 220 | * @param cfg Pointer to configuration structure describing the pin. |
Anna Bridge |
169:a7c7b631e539 | 221 | * |
Anna Bridge |
169:a7c7b631e539 | 222 | */ |
Anna Bridge |
169:a7c7b631e539 | 223 | __STATIC_INLINE void GPIO_OutToggle(const gpio_cfg_t *cfg) |
Anna Bridge |
169:a7c7b631e539 | 224 | { |
Anna Bridge |
169:a7c7b631e539 | 225 | MXC_GPIO->out_val[cfg->port] ^= cfg->mask; |
Anna Bridge |
169:a7c7b631e539 | 226 | } |
Anna Bridge |
169:a7c7b631e539 | 227 | |
Anna Bridge |
169:a7c7b631e539 | 228 | /** |
Anna Bridge |
169:a7c7b631e539 | 229 | * @brief Configure GPIO interrupt(s) |
Anna Bridge |
169:a7c7b631e539 | 230 | * @param cfg Pointer to configuration structure describing the pin. |
Anna Bridge |
169:a7c7b631e539 | 231 | * @param mode Requested interrupt mode. |
Anna Bridge |
169:a7c7b631e539 | 232 | * |
Anna Bridge |
169:a7c7b631e539 | 233 | */ |
Anna Bridge |
169:a7c7b631e539 | 234 | void GPIO_IntConfig(const gpio_cfg_t *cfg, gpio_int_mode_t mode); |
Anna Bridge |
169:a7c7b631e539 | 235 | |
Anna Bridge |
169:a7c7b631e539 | 236 | /** |
Anna Bridge |
169:a7c7b631e539 | 237 | * @brief Enables the specified GPIO interrupt |
Anna Bridge |
169:a7c7b631e539 | 238 | * @param cfg Pointer to configuration structure describing the pin. |
Anna Bridge |
169:a7c7b631e539 | 239 | * |
Anna Bridge |
169:a7c7b631e539 | 240 | */ |
Anna Bridge |
169:a7c7b631e539 | 241 | __STATIC_INLINE void GPIO_IntEnable(const gpio_cfg_t *cfg) |
Anna Bridge |
169:a7c7b631e539 | 242 | { |
Anna Bridge |
169:a7c7b631e539 | 243 | MXC_GPIO->inten[cfg->port] |= cfg->mask; |
Anna Bridge |
169:a7c7b631e539 | 244 | } |
Anna Bridge |
169:a7c7b631e539 | 245 | |
Anna Bridge |
169:a7c7b631e539 | 246 | /** |
Anna Bridge |
169:a7c7b631e539 | 247 | * @brief Disables the specified GPIO interrupt. |
Anna Bridge |
169:a7c7b631e539 | 248 | * @param cfg Pointer to configuration structure describing the pin. |
Anna Bridge |
169:a7c7b631e539 | 249 | * |
Anna Bridge |
169:a7c7b631e539 | 250 | */ |
Anna Bridge |
169:a7c7b631e539 | 251 | __STATIC_INLINE void GPIO_IntDisable(const gpio_cfg_t *cfg) |
Anna Bridge |
169:a7c7b631e539 | 252 | { |
Anna Bridge |
169:a7c7b631e539 | 253 | MXC_GPIO->inten[cfg->port] &= ~cfg->mask; |
Anna Bridge |
169:a7c7b631e539 | 254 | } |
Anna Bridge |
169:a7c7b631e539 | 255 | |
Anna Bridge |
169:a7c7b631e539 | 256 | /** |
Anna Bridge |
169:a7c7b631e539 | 257 | * @brief Gets the interrupt(s) status on a GPIO pin. |
Anna Bridge |
169:a7c7b631e539 | 258 | * @param cfg Pointer to configuration structure describing the pin |
Anna Bridge |
169:a7c7b631e539 | 259 | * for which the status is being requested. |
Anna Bridge |
169:a7c7b631e539 | 260 | * |
Anna Bridge |
169:a7c7b631e539 | 261 | * @return The requested interrupt status. |
Anna Bridge |
169:a7c7b631e539 | 262 | * |
Anna Bridge |
169:a7c7b631e539 | 263 | */ |
Anna Bridge |
169:a7c7b631e539 | 264 | __STATIC_INLINE uint32_t GPIO_IntStatus(const gpio_cfg_t *cfg) |
Anna Bridge |
169:a7c7b631e539 | 265 | { |
Anna Bridge |
169:a7c7b631e539 | 266 | return (MXC_GPIO->intfl[cfg->port] & cfg->mask); |
Anna Bridge |
169:a7c7b631e539 | 267 | } |
Anna Bridge |
169:a7c7b631e539 | 268 | |
Anna Bridge |
169:a7c7b631e539 | 269 | /** |
Anna Bridge |
169:a7c7b631e539 | 270 | * @brief Clears the interrupt(s) status on a GPIO pin. |
Anna Bridge |
169:a7c7b631e539 | 271 | * @param cfg Pointer to configuration structure describing the pin |
Anna Bridge |
169:a7c7b631e539 | 272 | * to clear the interrupt state of. |
Anna Bridge |
169:a7c7b631e539 | 273 | * |
Anna Bridge |
169:a7c7b631e539 | 274 | */ |
Anna Bridge |
169:a7c7b631e539 | 275 | __STATIC_INLINE void GPIO_IntClr(const gpio_cfg_t *cfg) |
Anna Bridge |
169:a7c7b631e539 | 276 | { |
Anna Bridge |
169:a7c7b631e539 | 277 | MXC_GPIO->intfl[cfg->port] = cfg->mask; |
Anna Bridge |
169:a7c7b631e539 | 278 | } |
Anna Bridge |
169:a7c7b631e539 | 279 | |
Anna Bridge |
169:a7c7b631e539 | 280 | /** |
Anna Bridge |
169:a7c7b631e539 | 281 | * @brief Type alias for a GPIO callback function with prototype: |
Anna Bridge |
169:a7c7b631e539 | 282 | * @code |
Anna Bridge |
169:a7c7b631e539 | 283 | * void callback_fn(void *cbdata); |
Anna Bridge |
169:a7c7b631e539 | 284 | * @endcode |
Anna Bridge |
169:a7c7b631e539 | 285 | * @param cbdata A void pointer to the data type as registered when |
Anna Bridge |
169:a7c7b631e539 | 286 | * @c GPIO_RegisterCallback() was called. |
Anna Bridge |
169:a7c7b631e539 | 287 | * |
Anna Bridge |
169:a7c7b631e539 | 288 | */ |
Anna Bridge |
169:a7c7b631e539 | 289 | typedef void (*gpio_callback_fn)(void *cbdata); |
Anna Bridge |
169:a7c7b631e539 | 290 | |
Anna Bridge |
169:a7c7b631e539 | 291 | /** |
Anna Bridge |
169:a7c7b631e539 | 292 | * @brief Registers a callback for the interrupt on a given port and pin. |
Anna Bridge |
169:a7c7b631e539 | 293 | * @param cfg Pointer to configuration structure describing the pin |
Anna Bridge |
169:a7c7b631e539 | 294 | * @param callback A pointer to a function of type #callback_fn. |
Anna Bridge |
169:a7c7b631e539 | 295 | * @param cbdata The parameter to be passed to the callback function, #callback_fn, when an interrupt occurs. |
Anna Bridge |
169:a7c7b631e539 | 296 | * |
Anna Bridge |
169:a7c7b631e539 | 297 | */ |
Anna Bridge |
169:a7c7b631e539 | 298 | void GPIO_RegisterCallback(const gpio_cfg_t *cfg, gpio_callback_fn callback, void *cbdata); |
Anna Bridge |
169:a7c7b631e539 | 299 | |
Anna Bridge |
169:a7c7b631e539 | 300 | /** |
Anna Bridge |
169:a7c7b631e539 | 301 | * @brief GPIO IRQ Handler. @note If a callback is registered for a given |
Anna Bridge |
169:a7c7b631e539 | 302 | * interrupt, the callback function will be called. |
Anna Bridge |
169:a7c7b631e539 | 303 | * |
Anna Bridge |
169:a7c7b631e539 | 304 | * @param port number of the port that generated the interrupt service routine. |
Anna Bridge |
169:a7c7b631e539 | 305 | * |
Anna Bridge |
169:a7c7b631e539 | 306 | */ |
Anna Bridge |
169:a7c7b631e539 | 307 | void GPIO_Handler(unsigned int port); |
Anna Bridge |
169:a7c7b631e539 | 308 | |
Anna Bridge |
169:a7c7b631e539 | 309 | /**@} end of group gpio */ |
Anna Bridge |
169:a7c7b631e539 | 310 | |
Anna Bridge |
169:a7c7b631e539 | 311 | #ifdef __cplusplus |
Anna Bridge |
169:a7c7b631e539 | 312 | } |
Anna Bridge |
169:a7c7b631e539 | 313 | #endif |
Anna Bridge |
169:a7c7b631e539 | 314 | |
Anna Bridge |
169:a7c7b631e539 | 315 | #endif /* _GPIO_H_ */ |