added prescaler for 16 bit pwm in LPC1347 target
Fork of mbed-dev by
targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/emlib/src/em_gpio.c@50:a417edff4437, 2016-01-15 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Jan 15 07:45:16 2016 +0000
- Revision:
- 50:a417edff4437
- Parent:
- 0:9b334a45a8ff
- Child:
- 144:ef7eb2e8f9f7
Synchronized with git revision 6010f32619bfcbb01cc73747d4ff9040863482d9
Full URL: https://github.com/mbedmicro/mbed/commit/6010f32619bfcbb01cc73747d4ff9040863482d9/
Remove doubling of buffer size in realiseEndpoint()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:9b334a45a8ff | 1 | /***************************************************************************//** |
bogdanm | 0:9b334a45a8ff | 2 | * @file em_gpio.c |
bogdanm | 0:9b334a45a8ff | 3 | * @brief General Purpose IO (GPIO) peripheral API |
bogdanm | 0:9b334a45a8ff | 4 | * devices. |
mbed_official | 50:a417edff4437 | 5 | * @version 4.2.1 |
bogdanm | 0:9b334a45a8ff | 6 | ******************************************************************************* |
bogdanm | 0:9b334a45a8ff | 7 | * @section License |
mbed_official | 50:a417edff4437 | 8 | * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b> |
bogdanm | 0:9b334a45a8ff | 9 | ******************************************************************************* |
bogdanm | 0:9b334a45a8ff | 10 | * |
bogdanm | 0:9b334a45a8ff | 11 | * Permission is granted to anyone to use this software for any purpose, |
bogdanm | 0:9b334a45a8ff | 12 | * including commercial applications, and to alter it and redistribute it |
bogdanm | 0:9b334a45a8ff | 13 | * freely, subject to the following restrictions: |
bogdanm | 0:9b334a45a8ff | 14 | * |
bogdanm | 0:9b334a45a8ff | 15 | * 1. The origin of this software must not be misrepresented; you must not |
bogdanm | 0:9b334a45a8ff | 16 | * claim that you wrote the original software. |
bogdanm | 0:9b334a45a8ff | 17 | * 2. Altered source versions must be plainly marked as such, and must not be |
bogdanm | 0:9b334a45a8ff | 18 | * misrepresented as being the original software. |
bogdanm | 0:9b334a45a8ff | 19 | * 3. This notice may not be removed or altered from any source distribution. |
bogdanm | 0:9b334a45a8ff | 20 | * |
bogdanm | 0:9b334a45a8ff | 21 | * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no |
bogdanm | 0:9b334a45a8ff | 22 | * obligation to support this Software. Silicon Labs is providing the |
bogdanm | 0:9b334a45a8ff | 23 | * Software "AS IS", with no express or implied warranties of any kind, |
bogdanm | 0:9b334a45a8ff | 24 | * including, but not limited to, any implied warranties of merchantability |
bogdanm | 0:9b334a45a8ff | 25 | * or fitness for any particular purpose or warranties against infringement |
bogdanm | 0:9b334a45a8ff | 26 | * of any proprietary rights of a third party. |
bogdanm | 0:9b334a45a8ff | 27 | * |
bogdanm | 0:9b334a45a8ff | 28 | * Silicon Labs will not be liable for any consequential, incidental, or |
bogdanm | 0:9b334a45a8ff | 29 | * special damages, or any other relief, or for any claim by any third party, |
bogdanm | 0:9b334a45a8ff | 30 | * arising from your use of this Software. |
bogdanm | 0:9b334a45a8ff | 31 | * |
bogdanm | 0:9b334a45a8ff | 32 | ******************************************************************************/ |
bogdanm | 0:9b334a45a8ff | 33 | |
bogdanm | 0:9b334a45a8ff | 34 | |
bogdanm | 0:9b334a45a8ff | 35 | #include "em_gpio.h" |
bogdanm | 0:9b334a45a8ff | 36 | |
bogdanm | 0:9b334a45a8ff | 37 | #if defined(GPIO_COUNT) && (GPIO_COUNT > 0) |
mbed_official | 50:a417edff4437 | 38 | |
bogdanm | 0:9b334a45a8ff | 39 | /***************************************************************************//** |
bogdanm | 0:9b334a45a8ff | 40 | * @addtogroup EM_Library |
bogdanm | 0:9b334a45a8ff | 41 | * @{ |
bogdanm | 0:9b334a45a8ff | 42 | ******************************************************************************/ |
bogdanm | 0:9b334a45a8ff | 43 | |
bogdanm | 0:9b334a45a8ff | 44 | /***************************************************************************//** |
bogdanm | 0:9b334a45a8ff | 45 | * @addtogroup GPIO |
bogdanm | 0:9b334a45a8ff | 46 | * @brief General Purpose Input/Output (GPIO) API |
bogdanm | 0:9b334a45a8ff | 47 | * @{ |
bogdanm | 0:9b334a45a8ff | 48 | ******************************************************************************/ |
bogdanm | 0:9b334a45a8ff | 49 | |
bogdanm | 0:9b334a45a8ff | 50 | /******************************************************************************* |
bogdanm | 0:9b334a45a8ff | 51 | ******************************* DEFINES *********************************** |
bogdanm | 0:9b334a45a8ff | 52 | ******************************************************************************/ |
bogdanm | 0:9b334a45a8ff | 53 | |
bogdanm | 0:9b334a45a8ff | 54 | /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */ |
bogdanm | 0:9b334a45a8ff | 55 | |
bogdanm | 0:9b334a45a8ff | 56 | /** Validation of pin typically usable in assert statements. */ |
bogdanm | 0:9b334a45a8ff | 57 | #define GPIO_DRIVEMODE_VALID(mode) ((mode) <= 3) |
mbed_official | 50:a417edff4437 | 58 | #define GPIO_STRENGHT_VALID(strenght) (!((strenght) & \ |
mbed_official | 50:a417edff4437 | 59 | ~(_GPIO_P_CTRL_DRIVESTRENGTH_MASK \ |
mbed_official | 50:a417edff4437 | 60 | | _GPIO_P_CTRL_DRIVESTRENGTHALT_MASK))) |
bogdanm | 0:9b334a45a8ff | 61 | /** @endcond */ |
bogdanm | 0:9b334a45a8ff | 62 | |
bogdanm | 0:9b334a45a8ff | 63 | |
bogdanm | 0:9b334a45a8ff | 64 | /******************************************************************************* |
bogdanm | 0:9b334a45a8ff | 65 | ************************** GLOBAL FUNCTIONS ******************************* |
bogdanm | 0:9b334a45a8ff | 66 | ******************************************************************************/ |
bogdanm | 0:9b334a45a8ff | 67 | |
bogdanm | 0:9b334a45a8ff | 68 | /***************************************************************************//** |
bogdanm | 0:9b334a45a8ff | 69 | * @brief |
bogdanm | 0:9b334a45a8ff | 70 | * Sets the pin location of the debug pins (Serial Wire interface). |
bogdanm | 0:9b334a45a8ff | 71 | * |
bogdanm | 0:9b334a45a8ff | 72 | * @note |
bogdanm | 0:9b334a45a8ff | 73 | * Changing the pins used for debugging uncontrolled, may result in a lockout. |
bogdanm | 0:9b334a45a8ff | 74 | * |
bogdanm | 0:9b334a45a8ff | 75 | * @param[in] location |
bogdanm | 0:9b334a45a8ff | 76 | * The debug pin location to use (0-3). |
bogdanm | 0:9b334a45a8ff | 77 | ******************************************************************************/ |
bogdanm | 0:9b334a45a8ff | 78 | void GPIO_DbgLocationSet(unsigned int location) |
bogdanm | 0:9b334a45a8ff | 79 | { |
bogdanm | 0:9b334a45a8ff | 80 | #if defined ( _GPIO_ROUTE_SWLOCATION_MASK ) |
bogdanm | 0:9b334a45a8ff | 81 | EFM_ASSERT(location < AFCHANLOC_MAX); |
bogdanm | 0:9b334a45a8ff | 82 | |
bogdanm | 0:9b334a45a8ff | 83 | GPIO->ROUTE = (GPIO->ROUTE & ~_GPIO_ROUTE_SWLOCATION_MASK) | |
bogdanm | 0:9b334a45a8ff | 84 | (location << _GPIO_ROUTE_SWLOCATION_SHIFT); |
bogdanm | 0:9b334a45a8ff | 85 | #else |
bogdanm | 0:9b334a45a8ff | 86 | (void)location; |
bogdanm | 0:9b334a45a8ff | 87 | #endif |
bogdanm | 0:9b334a45a8ff | 88 | } |
bogdanm | 0:9b334a45a8ff | 89 | |
mbed_official | 50:a417edff4437 | 90 | #if defined (_GPIO_P_CTRL_DRIVEMODE_MASK) |
bogdanm | 0:9b334a45a8ff | 91 | /***************************************************************************//** |
bogdanm | 0:9b334a45a8ff | 92 | * @brief |
bogdanm | 0:9b334a45a8ff | 93 | * Sets the drive mode for a GPIO port. |
bogdanm | 0:9b334a45a8ff | 94 | * |
bogdanm | 0:9b334a45a8ff | 95 | * @param[in] port |
bogdanm | 0:9b334a45a8ff | 96 | * The GPIO port to access. |
bogdanm | 0:9b334a45a8ff | 97 | * |
bogdanm | 0:9b334a45a8ff | 98 | * @param[in] mode |
bogdanm | 0:9b334a45a8ff | 99 | * Drive mode to use for port. |
bogdanm | 0:9b334a45a8ff | 100 | ******************************************************************************/ |
bogdanm | 0:9b334a45a8ff | 101 | void GPIO_DriveModeSet(GPIO_Port_TypeDef port, GPIO_DriveMode_TypeDef mode) |
bogdanm | 0:9b334a45a8ff | 102 | { |
bogdanm | 0:9b334a45a8ff | 103 | EFM_ASSERT(GPIO_PORT_VALID(port) && GPIO_DRIVEMODE_VALID(mode)); |
bogdanm | 0:9b334a45a8ff | 104 | |
bogdanm | 0:9b334a45a8ff | 105 | GPIO->P[port].CTRL = (GPIO->P[port].CTRL & ~(_GPIO_P_CTRL_DRIVEMODE_MASK)) |
bogdanm | 0:9b334a45a8ff | 106 | | (mode << _GPIO_P_CTRL_DRIVEMODE_SHIFT); |
bogdanm | 0:9b334a45a8ff | 107 | } |
mbed_official | 50:a417edff4437 | 108 | #endif |
bogdanm | 0:9b334a45a8ff | 109 | |
bogdanm | 0:9b334a45a8ff | 110 | |
mbed_official | 50:a417edff4437 | 111 | #if defined (_GPIO_P_CTRL_DRIVESTRENGTH_MASK) |
mbed_official | 50:a417edff4437 | 112 | /***************************************************************************//** |
mbed_official | 50:a417edff4437 | 113 | * @brief |
mbed_official | 50:a417edff4437 | 114 | * Sets the drive strength for a GPIO port. |
mbed_official | 50:a417edff4437 | 115 | * |
mbed_official | 50:a417edff4437 | 116 | * @param[in] port |
mbed_official | 50:a417edff4437 | 117 | * The GPIO port to access. |
mbed_official | 50:a417edff4437 | 118 | * |
mbed_official | 50:a417edff4437 | 119 | * @param[in] strength |
mbed_official | 50:a417edff4437 | 120 | * Drive strength to use for port. |
mbed_official | 50:a417edff4437 | 121 | ******************************************************************************/ |
mbed_official | 50:a417edff4437 | 122 | void GPIO_DriveStrengthSet(GPIO_Port_TypeDef port, |
mbed_official | 50:a417edff4437 | 123 | GPIO_DriveStrength_TypeDef strength) |
mbed_official | 50:a417edff4437 | 124 | { |
mbed_official | 50:a417edff4437 | 125 | EFM_ASSERT(GPIO_PORT_VALID(port) && GPIO_STRENGHT_VALID(strength)); |
mbed_official | 50:a417edff4437 | 126 | BUS_RegMaskedWrite(&GPIO->P[port].CTRL, |
mbed_official | 50:a417edff4437 | 127 | _GPIO_P_CTRL_DRIVESTRENGTH_MASK | _GPIO_P_CTRL_DRIVESTRENGTHALT_MASK, |
mbed_official | 50:a417edff4437 | 128 | strength); |
mbed_official | 50:a417edff4437 | 129 | } |
mbed_official | 50:a417edff4437 | 130 | #endif |
mbed_official | 50:a417edff4437 | 131 | |
bogdanm | 0:9b334a45a8ff | 132 | /***************************************************************************//** |
bogdanm | 0:9b334a45a8ff | 133 | * @brief |
bogdanm | 0:9b334a45a8ff | 134 | * Configure GPIO interrupt. |
bogdanm | 0:9b334a45a8ff | 135 | * |
bogdanm | 0:9b334a45a8ff | 136 | * @details |
bogdanm | 0:9b334a45a8ff | 137 | * If reconfiguring a GPIO interrupt that is already enabled, it is generally |
bogdanm | 0:9b334a45a8ff | 138 | * recommended to disable it first, see GPIO_Disable(). |
bogdanm | 0:9b334a45a8ff | 139 | * |
bogdanm | 0:9b334a45a8ff | 140 | * The actual GPIO interrupt handler must be in place before enabling the |
bogdanm | 0:9b334a45a8ff | 141 | * interrupt. |
bogdanm | 0:9b334a45a8ff | 142 | * |
bogdanm | 0:9b334a45a8ff | 143 | * Notice that any pending interrupt for the selected pin is cleared by this |
bogdanm | 0:9b334a45a8ff | 144 | * function. |
bogdanm | 0:9b334a45a8ff | 145 | * |
bogdanm | 0:9b334a45a8ff | 146 | * @note |
bogdanm | 0:9b334a45a8ff | 147 | * A certain pin number can only be associated with one port. Ie, if GPIO |
bogdanm | 0:9b334a45a8ff | 148 | * interrupt 1 is assigned to port A/pin 1, then it is not possibly to use |
bogdanm | 0:9b334a45a8ff | 149 | * pin 1 from any other ports for interrupts. Please refer to the reference |
bogdanm | 0:9b334a45a8ff | 150 | * manual. |
bogdanm | 0:9b334a45a8ff | 151 | * |
bogdanm | 0:9b334a45a8ff | 152 | * @param[in] port |
bogdanm | 0:9b334a45a8ff | 153 | * The port to associate with @p pin. |
bogdanm | 0:9b334a45a8ff | 154 | * |
bogdanm | 0:9b334a45a8ff | 155 | * @param[in] pin |
bogdanm | 0:9b334a45a8ff | 156 | * The GPIO interrupt number (= port pin). |
bogdanm | 0:9b334a45a8ff | 157 | * |
bogdanm | 0:9b334a45a8ff | 158 | * @param[in] risingEdge |
bogdanm | 0:9b334a45a8ff | 159 | * Set to true if interrupts shall be enabled on rising edge, otherwise false. |
bogdanm | 0:9b334a45a8ff | 160 | * |
bogdanm | 0:9b334a45a8ff | 161 | * @param[in] fallingEdge |
bogdanm | 0:9b334a45a8ff | 162 | * Set to true if interrupts shall be enabled on falling edge, otherwise false. |
bogdanm | 0:9b334a45a8ff | 163 | * |
bogdanm | 0:9b334a45a8ff | 164 | * @param[in] enable |
bogdanm | 0:9b334a45a8ff | 165 | * Set to true if interrupt shall be enabled after configuration completed, |
bogdanm | 0:9b334a45a8ff | 166 | * false to leave disabled. See GPIO_IntDisable() and GPIO_IntEnable(). |
bogdanm | 0:9b334a45a8ff | 167 | ******************************************************************************/ |
bogdanm | 0:9b334a45a8ff | 168 | void GPIO_IntConfig(GPIO_Port_TypeDef port, |
bogdanm | 0:9b334a45a8ff | 169 | unsigned int pin, |
bogdanm | 0:9b334a45a8ff | 170 | bool risingEdge, |
bogdanm | 0:9b334a45a8ff | 171 | bool fallingEdge, |
bogdanm | 0:9b334a45a8ff | 172 | bool enable) |
bogdanm | 0:9b334a45a8ff | 173 | { |
bogdanm | 0:9b334a45a8ff | 174 | uint32_t tmp; |
bogdanm | 0:9b334a45a8ff | 175 | |
mbed_official | 50:a417edff4437 | 176 | EFM_ASSERT(GPIO_PORT_PIN_VALID(port, pin)); |
bogdanm | 0:9b334a45a8ff | 177 | |
bogdanm | 0:9b334a45a8ff | 178 | /* There are two registers controlling the interrupt configuration: |
bogdanm | 0:9b334a45a8ff | 179 | * The EXTIPSELL register controls pins 0-7 and EXTIPSELH controls |
bogdanm | 0:9b334a45a8ff | 180 | * pins 8-15. */ |
bogdanm | 0:9b334a45a8ff | 181 | if (pin < 8) |
bogdanm | 0:9b334a45a8ff | 182 | { |
mbed_official | 50:a417edff4437 | 183 | BUS_RegMaskedWrite(&GPIO->EXTIPSELL, |
mbed_official | 50:a417edff4437 | 184 | 0xF << (4 * pin), |
mbed_official | 50:a417edff4437 | 185 | port << (4 * pin)); |
bogdanm | 0:9b334a45a8ff | 186 | } |
bogdanm | 0:9b334a45a8ff | 187 | else |
bogdanm | 0:9b334a45a8ff | 188 | { |
bogdanm | 0:9b334a45a8ff | 189 | tmp = pin - 8; |
mbed_official | 50:a417edff4437 | 190 | BUS_RegMaskedWrite(&GPIO->EXTIPSELH, |
mbed_official | 50:a417edff4437 | 191 | 0xF << (4 * tmp), |
mbed_official | 50:a417edff4437 | 192 | port << (4 * tmp)); |
bogdanm | 0:9b334a45a8ff | 193 | } |
bogdanm | 0:9b334a45a8ff | 194 | |
bogdanm | 0:9b334a45a8ff | 195 | /* Enable/disable rising edge */ |
mbed_official | 50:a417edff4437 | 196 | BUS_RegBitWrite(&(GPIO->EXTIRISE), pin, risingEdge); |
bogdanm | 0:9b334a45a8ff | 197 | |
bogdanm | 0:9b334a45a8ff | 198 | /* Enable/disable falling edge */ |
mbed_official | 50:a417edff4437 | 199 | BUS_RegBitWrite(&(GPIO->EXTIFALL), pin, fallingEdge); |
bogdanm | 0:9b334a45a8ff | 200 | |
bogdanm | 0:9b334a45a8ff | 201 | /* Clear any pending interrupt */ |
bogdanm | 0:9b334a45a8ff | 202 | GPIO->IFC = 1 << pin; |
bogdanm | 0:9b334a45a8ff | 203 | |
bogdanm | 0:9b334a45a8ff | 204 | /* Finally enable/disable interrupt */ |
mbed_official | 50:a417edff4437 | 205 | BUS_RegBitWrite(&(GPIO->IEN), pin, enable); |
bogdanm | 0:9b334a45a8ff | 206 | } |
bogdanm | 0:9b334a45a8ff | 207 | |
bogdanm | 0:9b334a45a8ff | 208 | |
bogdanm | 0:9b334a45a8ff | 209 | /***************************************************************************//** |
bogdanm | 0:9b334a45a8ff | 210 | * @brief |
bogdanm | 0:9b334a45a8ff | 211 | * Set the mode for a GPIO pin. |
bogdanm | 0:9b334a45a8ff | 212 | * |
bogdanm | 0:9b334a45a8ff | 213 | * @param[in] port |
bogdanm | 0:9b334a45a8ff | 214 | * The GPIO port to access. |
bogdanm | 0:9b334a45a8ff | 215 | * |
bogdanm | 0:9b334a45a8ff | 216 | * @param[in] pin |
bogdanm | 0:9b334a45a8ff | 217 | * The pin number in the port. |
bogdanm | 0:9b334a45a8ff | 218 | * |
bogdanm | 0:9b334a45a8ff | 219 | * @param[in] mode |
bogdanm | 0:9b334a45a8ff | 220 | * The desired pin mode. |
bogdanm | 0:9b334a45a8ff | 221 | * |
bogdanm | 0:9b334a45a8ff | 222 | * @param[in] out |
bogdanm | 0:9b334a45a8ff | 223 | * Value to set for pin in DOUT register. The DOUT setting is important for |
bogdanm | 0:9b334a45a8ff | 224 | * even some input mode configurations, determining pull-up/down direction. |
bogdanm | 0:9b334a45a8ff | 225 | ******************************************************************************/ |
bogdanm | 0:9b334a45a8ff | 226 | void GPIO_PinModeSet(GPIO_Port_TypeDef port, |
bogdanm | 0:9b334a45a8ff | 227 | unsigned int pin, |
bogdanm | 0:9b334a45a8ff | 228 | GPIO_Mode_TypeDef mode, |
bogdanm | 0:9b334a45a8ff | 229 | unsigned int out) |
bogdanm | 0:9b334a45a8ff | 230 | { |
mbed_official | 50:a417edff4437 | 231 | EFM_ASSERT(GPIO_PORT_PIN_VALID(port, pin)); |
bogdanm | 0:9b334a45a8ff | 232 | |
bogdanm | 0:9b334a45a8ff | 233 | /* If disabling pin, do not modify DOUT in order to reduce chance for */ |
bogdanm | 0:9b334a45a8ff | 234 | /* glitch/spike (may not be sufficient precaution in all use cases) */ |
bogdanm | 0:9b334a45a8ff | 235 | if (mode != gpioModeDisabled) |
bogdanm | 0:9b334a45a8ff | 236 | { |
bogdanm | 0:9b334a45a8ff | 237 | if (out) |
bogdanm | 0:9b334a45a8ff | 238 | { |
mbed_official | 50:a417edff4437 | 239 | GPIO_PinOutSet(port, pin); |
bogdanm | 0:9b334a45a8ff | 240 | } |
bogdanm | 0:9b334a45a8ff | 241 | else |
bogdanm | 0:9b334a45a8ff | 242 | { |
mbed_official | 50:a417edff4437 | 243 | GPIO_PinOutClear(port, pin); |
bogdanm | 0:9b334a45a8ff | 244 | } |
bogdanm | 0:9b334a45a8ff | 245 | } |
bogdanm | 0:9b334a45a8ff | 246 | |
bogdanm | 0:9b334a45a8ff | 247 | /* There are two registers controlling the pins for each port. The MODEL |
bogdanm | 0:9b334a45a8ff | 248 | * register controls pins 0-7 and MODEH controls pins 8-15. */ |
bogdanm | 0:9b334a45a8ff | 249 | if (pin < 8) |
bogdanm | 0:9b334a45a8ff | 250 | { |
mbed_official | 50:a417edff4437 | 251 | BUS_RegMaskedWrite(&GPIO->P[port].MODEL, |
mbed_official | 50:a417edff4437 | 252 | 0xF << (pin * 4), |
mbed_official | 50:a417edff4437 | 253 | mode << (pin * 4)); |
bogdanm | 0:9b334a45a8ff | 254 | } |
bogdanm | 0:9b334a45a8ff | 255 | else |
bogdanm | 0:9b334a45a8ff | 256 | { |
mbed_official | 50:a417edff4437 | 257 | BUS_RegMaskedWrite(&GPIO->P[port].MODEH, |
mbed_official | 50:a417edff4437 | 258 | 0xF << ((pin - 8) * 4), |
mbed_official | 50:a417edff4437 | 259 | mode << ((pin - 8) * 4)); |
bogdanm | 0:9b334a45a8ff | 260 | } |
bogdanm | 0:9b334a45a8ff | 261 | |
bogdanm | 0:9b334a45a8ff | 262 | if (mode == gpioModeDisabled) |
bogdanm | 0:9b334a45a8ff | 263 | { |
bogdanm | 0:9b334a45a8ff | 264 | if (out) |
bogdanm | 0:9b334a45a8ff | 265 | { |
mbed_official | 50:a417edff4437 | 266 | GPIO_PinOutSet(port, pin); |
bogdanm | 0:9b334a45a8ff | 267 | } |
bogdanm | 0:9b334a45a8ff | 268 | else |
bogdanm | 0:9b334a45a8ff | 269 | { |
mbed_official | 50:a417edff4437 | 270 | GPIO_PinOutClear(port, pin); |
bogdanm | 0:9b334a45a8ff | 271 | } |
bogdanm | 0:9b334a45a8ff | 272 | } |
bogdanm | 0:9b334a45a8ff | 273 | } |
bogdanm | 0:9b334a45a8ff | 274 | |
mbed_official | 50:a417edff4437 | 275 | #if defined( _GPIO_EM4WUEN_MASK ) |
mbed_official | 50:a417edff4437 | 276 | /**************************************************************************//** |
mbed_official | 50:a417edff4437 | 277 | * @brief |
mbed_official | 50:a417edff4437 | 278 | * Enable GPIO pin wake-up from EM4. When the function exits, |
mbed_official | 50:a417edff4437 | 279 | * EM4 mode can be safely entered. |
mbed_official | 50:a417edff4437 | 280 | * |
mbed_official | 50:a417edff4437 | 281 | * @note |
mbed_official | 50:a417edff4437 | 282 | * It is assumed that the GPIO pin modes are set correctly. |
mbed_official | 50:a417edff4437 | 283 | * Valid modes are @ref gpioModeInput and @ref gpioModeInputPull. |
mbed_official | 50:a417edff4437 | 284 | * |
mbed_official | 50:a417edff4437 | 285 | * @param[in] pinmask |
mbed_official | 50:a417edff4437 | 286 | * Bitmask containing the bitwise logic OR of which GPIO pin(s) to enable. |
mbed_official | 50:a417edff4437 | 287 | * Refer to Reference Manuals for pinmask to GPIO port/pin mapping. |
mbed_official | 50:a417edff4437 | 288 | * @param[in] polaritymask |
mbed_official | 50:a417edff4437 | 289 | * Bitmask containing the bitwise logic OR of GPIO pin(s) wake-up polarity. |
mbed_official | 50:a417edff4437 | 290 | * Refer to Reference Manuals for pinmask to GPIO port/pin mapping. |
mbed_official | 50:a417edff4437 | 291 | *****************************************************************************/ |
mbed_official | 50:a417edff4437 | 292 | void GPIO_EM4EnablePinWakeup(uint32_t pinmask, uint32_t polaritymask) |
mbed_official | 50:a417edff4437 | 293 | { |
mbed_official | 50:a417edff4437 | 294 | EFM_ASSERT((pinmask & ~_GPIO_EM4WUEN_MASK) == 0); |
mbed_official | 50:a417edff4437 | 295 | |
mbed_official | 50:a417edff4437 | 296 | #if defined( _GPIO_EM4WUPOL_MASK ) |
mbed_official | 50:a417edff4437 | 297 | EFM_ASSERT((polaritymask & ~_GPIO_EM4WUPOL_MASK) == 0); |
mbed_official | 50:a417edff4437 | 298 | GPIO->EM4WUPOL &= ~pinmask; /* Set wakeup polarity */ |
mbed_official | 50:a417edff4437 | 299 | GPIO->EM4WUPOL |= pinmask & polaritymask; |
mbed_official | 50:a417edff4437 | 300 | #elif defined( _GPIO_EXTILEVEL_MASK ) |
mbed_official | 50:a417edff4437 | 301 | EFM_ASSERT((polaritymask & ~_GPIO_EXTILEVEL_MASK) == 0); |
mbed_official | 50:a417edff4437 | 302 | GPIO->EXTILEVEL &= ~pinmask; |
mbed_official | 50:a417edff4437 | 303 | GPIO->EXTILEVEL |= pinmask & polaritymask; |
mbed_official | 50:a417edff4437 | 304 | #endif |
mbed_official | 50:a417edff4437 | 305 | GPIO->EM4WUEN |= pinmask; /* Enable wakeup */ |
mbed_official | 50:a417edff4437 | 306 | |
mbed_official | 50:a417edff4437 | 307 | GPIO_EM4SetPinRetention(true); /* Enable pin retention */ |
mbed_official | 50:a417edff4437 | 308 | |
mbed_official | 50:a417edff4437 | 309 | #if defined( _GPIO_CMD_EM4WUCLR_MASK ) |
mbed_official | 50:a417edff4437 | 310 | GPIO->CMD = GPIO_CMD_EM4WUCLR; /* Clear wake-up logic */ |
mbed_official | 50:a417edff4437 | 311 | #elif defined( _GPIO_IFC_EM4WU_MASK ) |
mbed_official | 50:a417edff4437 | 312 | GPIO_IntClear(pinmask); |
mbed_official | 50:a417edff4437 | 313 | #endif |
mbed_official | 50:a417edff4437 | 314 | } |
mbed_official | 50:a417edff4437 | 315 | #endif |
mbed_official | 50:a417edff4437 | 316 | |
bogdanm | 0:9b334a45a8ff | 317 | /** @} (end addtogroup GPIO) */ |
bogdanm | 0:9b334a45a8ff | 318 | /** @} (end addtogroup EM_Library) */ |
bogdanm | 0:9b334a45a8ff | 319 | |
bogdanm | 0:9b334a45a8ff | 320 | #endif /* defined(GPIO_COUNT) && (GPIO_COUNT > 0) */ |