1 /***************************************************************************//**
\r
3 * @brief General Purpose IO (GPIO) peripheral API
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
\r
8 *******************************************************************************
\r
10 * Permission is granted to anyone to use this software for any purpose,
\r
11 * including commercial applications, and to alter it and redistribute it
\r
12 * freely, subject to the following restrictions:
\r
14 * 1. The origin of this software must not be misrepresented; you must not
\r
15 * claim that you wrote the original software.
\r
16 * 2. Altered source versions must be plainly marked as such, and must not be
\r
17 * misrepresented as being the original software.
\r
18 * 3. This notice may not be removed or altered from any source distribution.
\r
20 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
\r
21 * obligation to support this Software. Silicon Labs is providing the
\r
22 * Software "AS IS", with no express or implied warranties of any kind,
\r
23 * including, but not limited to, any implied warranties of merchantability
\r
24 * or fitness for any particular purpose or warranties against infringement
\r
25 * of any proprietary rights of a third party.
\r
27 * Silicon Labs will not be liable for any consequential, incidental, or
\r
28 * special damages, or any other relief, or for any claim by any third party,
\r
29 * arising from your use of this Software.
\r
31 ******************************************************************************/
\r
34 #ifndef __SILICON_LABS_EM_GPIO_H__
\r
35 #define __SILICON_LABS_EM_GPIO_H__
\r
37 #include "em_device.h"
\r
38 #if defined(GPIO_COUNT) && (GPIO_COUNT > 0)
\r
40 #include <stdbool.h>
\r
42 #include "em_assert.h"
\r
48 /***************************************************************************//**
\r
49 * @addtogroup EM_Library
\r
51 ******************************************************************************/
\r
53 /***************************************************************************//**
\r
56 ******************************************************************************/
\r
58 /*******************************************************************************
\r
59 ******************************* DEFINES ***********************************
\r
60 ******************************************************************************/
\r
62 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
\r
63 #if defined( _EFM32_TINY_FAMILY ) || defined( _EFM32_ZERO_FAMILY )
\r
65 #define _GPIO_PORT_A_PIN_COUNT 14
\r
66 #define _GPIO_PORT_B_PIN_COUNT 10
\r
67 #define _GPIO_PORT_C_PIN_COUNT 16
\r
68 #define _GPIO_PORT_D_PIN_COUNT 9
\r
69 #define _GPIO_PORT_E_PIN_COUNT 12
\r
70 #define _GPIO_PORT_F_PIN_COUNT 6
\r
72 #define _GPIO_PORT_A_PIN_MASK 0xF77F
\r
73 #define _GPIO_PORT_B_PIN_MASK 0x79F8
\r
74 #define _GPIO_PORT_C_PIN_MASK 0xFFFF
\r
75 #define _GPIO_PORT_D_PIN_MASK 0x01FF
\r
76 #define _GPIO_PORT_E_PIN_MASK 0xFFF0
\r
77 #define _GPIO_PORT_F_PIN_MASK 0x003F
\r
79 #elif defined( _EFM32_HAPPY_FAMILY )
\r
81 #define _GPIO_PORT_A_PIN_COUNT 6
\r
82 #define _GPIO_PORT_B_PIN_COUNT 5
\r
83 #define _GPIO_PORT_C_PIN_COUNT 12
\r
84 #define _GPIO_PORT_D_PIN_COUNT 4
\r
85 #define _GPIO_PORT_E_PIN_COUNT 4
\r
86 #define _GPIO_PORT_F_PIN_COUNT 6
\r
88 #define _GPIO_PORT_A_PIN_MASK 0x0707
\r
89 #define _GPIO_PORT_B_PIN_MASK 0x6980
\r
90 #define _GPIO_PORT_C_PIN_MASK 0xEF1F
\r
91 #define _GPIO_PORT_D_PIN_MASK 0x00F0
\r
92 #define _GPIO_PORT_E_PIN_MASK 0x3C00
\r
93 #define _GPIO_PORT_F_PIN_MASK 0x003F
\r
95 #elif defined( _EFM32_GIANT_FAMILY ) \
\r
96 || defined( _EFM32_WONDER_FAMILY )
\r
98 #define _GPIO_PORT_A_PIN_COUNT 16
\r
99 #define _GPIO_PORT_B_PIN_COUNT 16
\r
100 #define _GPIO_PORT_C_PIN_COUNT 16
\r
101 #define _GPIO_PORT_D_PIN_COUNT 16
\r
102 #define _GPIO_PORT_E_PIN_COUNT 16
\r
103 #define _GPIO_PORT_F_PIN_COUNT 13
\r
105 #define _GPIO_PORT_A_PIN_MASK 0xFFFF
\r
106 #define _GPIO_PORT_B_PIN_MASK 0xFFFF
\r
107 #define _GPIO_PORT_C_PIN_MASK 0xFFFF
\r
108 #define _GPIO_PORT_D_PIN_MASK 0xFFFF
\r
109 #define _GPIO_PORT_E_PIN_MASK 0xFFFF
\r
110 #define _GPIO_PORT_F_PIN_MASK 0x1FFF
\r
112 #elif defined( _EFM32_GECKO_FAMILY )
\r
114 #define _GPIO_PORT_A_PIN_COUNT 16
\r
115 #define _GPIO_PORT_B_PIN_COUNT 16
\r
116 #define _GPIO_PORT_C_PIN_COUNT 16
\r
117 #define _GPIO_PORT_D_PIN_COUNT 16
\r
118 #define _GPIO_PORT_E_PIN_COUNT 16
\r
119 #define _GPIO_PORT_F_PIN_COUNT 10
\r
121 #define _GPIO_PORT_A_PIN_MASK 0xFFFF
\r
122 #define _GPIO_PORT_B_PIN_MASK 0xFFFF
\r
123 #define _GPIO_PORT_C_PIN_MASK 0xFFFF
\r
124 #define _GPIO_PORT_D_PIN_MASK 0xFFFF
\r
125 #define _GPIO_PORT_E_PIN_MASK 0xFFFF
\r
126 #define _GPIO_PORT_F_PIN_MASK 0x03FF
\r
128 #elif defined( _EFR32_MIGHTY_FAMILY ) \
\r
129 || defined( _EFR32_BLUE_FAMILY ) \
\r
130 || defined( _EFR32_FLEX_FAMILY ) \
\r
131 || defined( _EFR32_ZAPPY_FAMILY )
\r
133 #define _GPIO_PORT_A_PIN_COUNT 6
\r
134 #define _GPIO_PORT_B_PIN_COUNT 5
\r
135 #define _GPIO_PORT_C_PIN_COUNT 6
\r
136 #define _GPIO_PORT_D_PIN_COUNT 3
\r
137 #define _GPIO_PORT_E_PIN_COUNT 0
\r
138 #define _GPIO_PORT_F_PIN_COUNT 8
\r
140 #define _GPIO_PORT_A_PIN_MASK 0x003F
\r
141 #define _GPIO_PORT_B_PIN_MASK 0xF800
\r
142 #define _GPIO_PORT_C_PIN_MASK 0x0FC0
\r
143 #define _GPIO_PORT_D_PIN_MASK 0xE000
\r
144 #define _GPIO_PORT_E_PIN_MASK 0x0000
\r
145 #define _GPIO_PORT_F_PIN_MASK 0x00FF
\r
147 #elif defined( _EFM32_PEARL_FAMILY ) \
\r
148 || defined( _EFM32_JADE_FAMILY )
\r
150 #define _GPIO_PORT_A_PIN_COUNT 6
\r
151 #define _GPIO_PORT_B_PIN_COUNT 5
\r
152 #define _GPIO_PORT_C_PIN_COUNT 6
\r
153 #define _GPIO_PORT_D_PIN_COUNT 7
\r
154 #define _GPIO_PORT_E_PIN_COUNT 0
\r
155 #define _GPIO_PORT_F_PIN_COUNT 8
\r
157 #define _GPIO_PORT_A_PIN_MASK 0x003F
\r
158 #define _GPIO_PORT_B_PIN_MASK 0xF800
\r
159 #define _GPIO_PORT_C_PIN_MASK 0x0FC0
\r
160 #define _GPIO_PORT_D_PIN_MASK 0xFE00
\r
161 #define _GPIO_PORT_E_PIN_MASK 0x0000
\r
162 #define _GPIO_PORT_F_PIN_MASK 0x00FF
\r
165 #warning "Port and pin masks are not defined for this family."
\r
168 #if defined( _GPIO_PORT_G_PIN_COUNT ) && defined( _GPIO_PORT_H_PIN_COUNT )
\r
169 #define _GPIO_PORT_SIZE(port) ( \
\r
170 (port) == 0 ? _GPIO_PORT_A_PIN_COUNT : \
\r
171 (port) == 1 ? _GPIO_PORT_B_PIN_COUNT : \
\r
172 (port) == 2 ? _GPIO_PORT_C_PIN_COUNT : \
\r
173 (port) == 3 ? _GPIO_PORT_D_PIN_COUNT : \
\r
174 (port) == 4 ? _GPIO_PORT_E_PIN_COUNT : \
\r
175 (port) == 5 ? _GPIO_PORT_F_PIN_COUNT : \
\r
176 (port) == 6 ? _GPIO_PORT_G_PIN_COUNT : \
\r
177 (port) == 7 ? _GPIO_PORT_H_PIN_COUNT : \
\r
180 #define _GPIO_PORT_SIZE(port) ( \
\r
181 (port) == 0 ? _GPIO_PORT_A_PIN_COUNT : \
\r
182 (port) == 1 ? _GPIO_PORT_B_PIN_COUNT : \
\r
183 (port) == 2 ? _GPIO_PORT_C_PIN_COUNT : \
\r
184 (port) == 3 ? _GPIO_PORT_D_PIN_COUNT : \
\r
185 (port) == 4 ? _GPIO_PORT_E_PIN_COUNT : \
\r
186 (port) == 5 ? _GPIO_PORT_F_PIN_COUNT : \
\r
190 #if defined( _GPIO_PORT_G_PIN_MASK ) && defined( _GPIO_PORT_H_PIN_MASK )
\r
191 #define _GPIO_PORT_MASK(port) ( \
\r
192 (port) == 0 ? _GPIO_PORT_A_PIN_MASK : \
\r
193 (port) == 1 ? _GPIO_PORT_B_PIN_MASK : \
\r
194 (port) == 2 ? _GPIO_PORT_C_PIN_MASK : \
\r
195 (port) == 3 ? _GPIO_PORT_D_PIN_MASK : \
\r
196 (port) == 4 ? _GPIO_PORT_E_PIN_MASK : \
\r
197 (port) == 5 ? _GPIO_PORT_F_PIN_MASK : \
\r
198 (port) == 6 ? _GPIO_PORT_G_PIN_MASK : \
\r
199 (port) == 7 ? _GPIO_PORT_H_PIN_MASK : \
\r
202 #define _GPIO_PORT_MASK(port) ( \
\r
203 (port) == 0 ? _GPIO_PORT_A_PIN_MASK : \
\r
204 (port) == 1 ? _GPIO_PORT_B_PIN_MASK : \
\r
205 (port) == 2 ? _GPIO_PORT_C_PIN_MASK : \
\r
206 (port) == 3 ? _GPIO_PORT_D_PIN_MASK : \
\r
207 (port) == 4 ? _GPIO_PORT_E_PIN_MASK : \
\r
208 (port) == 5 ? _GPIO_PORT_F_PIN_MASK : \
\r
212 /** Validation of port and pin */
\r
213 #define GPIO_PORT_VALID(port) ( _GPIO_PORT_MASK(port) )
\r
214 #define GPIO_PORT_PIN_VALID(port, pin) ((( _GPIO_PORT_MASK(port)) >> (pin)) & 0x1 )
\r
216 /** Highest GPIO pin number */
\r
217 #define GPIO_PIN_MAX 15
\r
219 /** Highest GPIO port number */
\r
220 #if defined( _GPIO_PORT_G_PIN_COUNT ) && defined( _GPIO_PORT_H_PIN_COUNT )
\r
221 #define GPIO_PORT_MAX 7
\r
223 #define GPIO_PORT_MAX 5
\r
227 /*******************************************************************************
\r
228 ******************************** ENUMS ************************************
\r
229 ******************************************************************************/
\r
231 /** GPIO ports ids. */
\r
234 #if ( _GPIO_PORT_A_PIN_COUNT > 0 )
\r
237 #if ( _GPIO_PORT_B_PIN_COUNT > 0 )
\r
240 #if ( _GPIO_PORT_C_PIN_COUNT > 0 )
\r
243 #if ( _GPIO_PORT_D_PIN_COUNT > 0 )
\r
246 #if ( _GPIO_PORT_E_PIN_COUNT > 0 )
\r
249 #if ( _GPIO_PORT_F_PIN_COUNT > 0 )
\r
252 #if defined( _GPIO_PORT_G_PIN_COUNT ) && ( _GPIO_PORT_G_PIN_COUNT > 0 )
\r
255 #if defined( _GPIO_PORT_H_PIN_COUNT ) && ( _GPIO_PORT_H_PIN_COUNT > 0 )
\r
258 } GPIO_Port_TypeDef;
\r
260 #if defined( _GPIO_P_CTRL_DRIVEMODE_MASK )
\r
261 /** GPIO drive mode. */
\r
265 gpioDriveModeStandard = GPIO_P_CTRL_DRIVEMODE_STANDARD,
\r
267 gpioDriveModeLowest = GPIO_P_CTRL_DRIVEMODE_LOWEST,
\r
269 gpioDriveModeHigh = GPIO_P_CTRL_DRIVEMODE_HIGH,
\r
271 gpioDriveModeLow = GPIO_P_CTRL_DRIVEMODE_LOW
\r
272 } GPIO_DriveMode_TypeDef;
\r
275 #if defined( _GPIO_P_CTRL_DRIVESTRENGTH_MASK ) && defined( _GPIO_P_CTRL_DRIVESTRENGTHALT_MASK )
\r
276 /** GPIO drive strength. */
\r
279 /** GPIO weak 1mA and alternate function weak 1mA */
\r
280 gpioDriveStrengthWeakAlternateWeak = GPIO_P_CTRL_DRIVESTRENGTH_WEAK | GPIO_P_CTRL_DRIVESTRENGTHALT_WEAK,
\r
282 /** GPIO weak 1mA and alternate function strong 10mA */
\r
283 gpioDriveStrengthWeakAlternateStrong = GPIO_P_CTRL_DRIVESTRENGTH_WEAK | GPIO_P_CTRL_DRIVESTRENGTHALT_STRONG,
\r
285 /** GPIO strong 10mA and alternate function weak 1mA */
\r
286 gpioDriveStrengthStrongAlternateWeak = GPIO_P_CTRL_DRIVESTRENGTH_STRONG | GPIO_P_CTRL_DRIVESTRENGTHALT_WEAK,
\r
288 /** GPIO strong 10mA and alternate function strong 10mA */
\r
289 gpioDriveStrengthStrongAlternateStrong = GPIO_P_CTRL_DRIVESTRENGTH_STRONG | GPIO_P_CTRL_DRIVESTRENGTHALT_STRONG,
\r
290 } GPIO_DriveStrength_TypeDef;
\r
291 /* For legacy support */
\r
292 #define gpioDriveStrengthStrong gpioDriveStrengthStrongAlternateStrong
\r
293 #define gpioDriveStrengthWeak gpioDriveStrengthWeakAlternateWeak
\r
296 /** Pin mode. For more details on each mode, please refer to the
\r
297 * reference manual. */
\r
300 /** Input disabled. Pullup if DOUT is set. */
\r
301 gpioModeDisabled = _GPIO_P_MODEL_MODE0_DISABLED,
\r
302 /** Input enabled. Filter if DOUT is set */
\r
303 gpioModeInput = _GPIO_P_MODEL_MODE0_INPUT,
\r
304 /** Input enabled. DOUT determines pull direction */
\r
305 gpioModeInputPull = _GPIO_P_MODEL_MODE0_INPUTPULL,
\r
306 /** Input enabled with filter. DOUT determines pull direction */
\r
307 gpioModeInputPullFilter = _GPIO_P_MODEL_MODE0_INPUTPULLFILTER,
\r
308 /** Push-pull output */
\r
309 gpioModePushPull = _GPIO_P_MODEL_MODE0_PUSHPULL,
\r
310 #if defined( _GPIO_P_MODEL_MODE0_PUSHPULLDRIVE )
\r
311 /** Push-pull output with drive-strength set by DRIVEMODE */
\r
312 gpioModePushPullDrive = _GPIO_P_MODEL_MODE0_PUSHPULLDRIVE,
\r
314 #if defined( _GPIO_P_MODEL_MODE0_PUSHPULLALT )
\r
315 /** Push-pull using alternate control */
\r
316 gpioModePushPullAlternate = _GPIO_P_MODEL_MODE0_PUSHPULLALT,
\r
318 /** Wired-or output */
\r
319 gpioModeWiredOr = _GPIO_P_MODEL_MODE0_WIREDOR,
\r
320 /** Wired-or output with pull-down */
\r
321 gpioModeWiredOrPullDown = _GPIO_P_MODEL_MODE0_WIREDORPULLDOWN,
\r
322 /** Open-drain output */
\r
323 gpioModeWiredAnd = _GPIO_P_MODEL_MODE0_WIREDAND,
\r
324 /** Open-drain output with filter */
\r
325 gpioModeWiredAndFilter = _GPIO_P_MODEL_MODE0_WIREDANDFILTER,
\r
326 /** Open-drain output with pullup */
\r
327 gpioModeWiredAndPullUp = _GPIO_P_MODEL_MODE0_WIREDANDPULLUP,
\r
328 /** Open-drain output with filter and pullup */
\r
329 gpioModeWiredAndPullUpFilter = _GPIO_P_MODEL_MODE0_WIREDANDPULLUPFILTER,
\r
330 #if defined( _GPIO_P_MODEL_MODE0_WIREDANDDRIVE )
\r
331 /** Open-drain output with drive-strength set by DRIVEMODE */
\r
332 gpioModeWiredAndDrive = _GPIO_P_MODEL_MODE0_WIREDANDDRIVE,
\r
333 /** Open-drain output with filter and drive-strength set by DRIVEMODE */
\r
334 gpioModeWiredAndDriveFilter = _GPIO_P_MODEL_MODE0_WIREDANDDRIVEFILTER,
\r
335 /** Open-drain output with pullup and drive-strength set by DRIVEMODE */
\r
336 gpioModeWiredAndDrivePullUp = _GPIO_P_MODEL_MODE0_WIREDANDDRIVEPULLUP,
\r
337 /** Open-drain output with filter, pullup and drive-strength set by DRIVEMODE */
\r
338 gpioModeWiredAndDrivePullUpFilter = _GPIO_P_MODEL_MODE0_WIREDANDDRIVEPULLUPFILTER
\r
340 #if defined( _GPIO_P_MODEL_MODE0_WIREDANDALT )
\r
341 /** Open-drain output using alternate control */
\r
342 gpioModeWiredAndAlternate = _GPIO_P_MODEL_MODE0_WIREDANDALT,
\r
343 /** Open-drain output using alternate control with filter */
\r
344 gpioModeWiredAndAlternateFilter = _GPIO_P_MODEL_MODE0_WIREDANDALTFILTER,
\r
345 /** Open-drain output using alternate control with pullup */
\r
346 gpioModeWiredAndAlternatePullUp = _GPIO_P_MODEL_MODE0_WIREDANDALTPULLUP,
\r
347 /** Open-drain output uisng alternate control with filter and pullup */
\r
348 gpioModeWiredAndAlternatePullUpFilter = _GPIO_P_MODEL_MODE0_WIREDANDALTPULLUPFILTER,
\r
350 } GPIO_Mode_TypeDef;
\r
352 /*******************************************************************************
\r
353 ***************************** PROTOTYPES **********************************
\r
354 ******************************************************************************/
\r
356 void GPIO_DbgLocationSet(unsigned int location);
\r
358 void GPIO_IntConfig(GPIO_Port_TypeDef port,
\r
364 void GPIO_PinModeSet(GPIO_Port_TypeDef port,
\r
366 GPIO_Mode_TypeDef mode,
\r
369 # if defined( _GPIO_EM4WUEN_MASK )
\r
370 void GPIO_EM4EnablePinWakeup(uint32_t pinmask, uint32_t polaritymask);
\r
373 /***************************************************************************//**
\r
375 * Enable/disable serial wire clock pin.
\r
378 * Disabling SWDClk will disable the debug interface, which may result in
\r
379 * a lockout if done early in startup (before debugger is able to halt core).
\r
381 * @param[in] enable
\r
382 * @li false - disable serial wire clock.
\r
383 * @li true - enable serial wire clock (default after reset).
\r
384 ******************************************************************************/
\r
385 __STATIC_INLINE void GPIO_DbgSWDClkEnable(bool enable)
\r
387 #if defined( _GPIO_ROUTE_SWCLKPEN_MASK )
\r
388 BUS_RegBitWrite(&(GPIO->ROUTE), _GPIO_ROUTE_SWCLKPEN_SHIFT, enable);
\r
389 #elif defined( _GPIO_ROUTEPEN_SWCLKTCKPEN_MASK )
\r
390 BUS_RegBitWrite(&(GPIO->ROUTEPEN), _GPIO_ROUTEPEN_SWCLKTCKPEN_SHIFT, enable);
\r
392 #warning "ROUTE enable for SWCLK pin is not defined."
\r
397 /***************************************************************************//**
\r
399 * Enable/disable serial wire data I/O pin.
\r
402 * Disabling SWDClk will disable the debug interface, which may result in
\r
403 * a lockout if done early in startup (before debugger is able to halt core).
\r
405 * @param[in] enable
\r
406 * @li false - disable serial wire data pin.
\r
407 * @li true - enable serial wire data pin (default after reset).
\r
408 ******************************************************************************/
\r
409 __STATIC_INLINE void GPIO_DbgSWDIOEnable(bool enable)
\r
411 #if defined( _GPIO_ROUTE_SWDIOPEN_MASK )
\r
412 BUS_RegBitWrite(&(GPIO->ROUTE), _GPIO_ROUTE_SWDIOPEN_SHIFT, enable);
\r
413 #elif defined( _GPIO_ROUTEPEN_SWDIOTMSPEN_MASK )
\r
414 BUS_RegBitWrite(&(GPIO->ROUTEPEN), _GPIO_ROUTEPEN_SWDIOTMSPEN_SHIFT, enable);
\r
416 #warning "ROUTE enable for SWDIO pin is not defined."
\r
421 #if defined( _GPIO_ROUTE_SWOPEN_MASK ) || defined( _GPIO_ROUTEPEN_SWVPEN_MASK )
\r
422 /***************************************************************************//**
\r
424 * Enable/Disable serial wire output pin.
\r
427 * Enabling this pin is not sufficient to fully enable serial wire output
\r
428 * which is also dependent on issues outside the GPIO module. Please refer to
\r
431 * @param[in] enable
\r
432 * @li false - disable serial wire viewer pin (default after reset).
\r
433 * @li true - enable serial wire viewer pin.
\r
434 ******************************************************************************/
\r
435 __STATIC_INLINE void GPIO_DbgSWOEnable(bool enable)
\r
437 #if defined( _GPIO_ROUTE_SWOPEN_MASK )
\r
438 BUS_RegBitWrite(&(GPIO->ROUTE), _GPIO_ROUTE_SWOPEN_SHIFT, enable);
\r
439 #elif defined( _GPIO_ROUTEPEN_SWVPEN_MASK )
\r
440 BUS_RegBitWrite(&(GPIO->ROUTEPEN), _GPIO_ROUTEPEN_SWVPEN_SHIFT, enable);
\r
442 #warning "ROUTE enable for SWO/SWV pin is not defined."
\r
447 #if defined (_GPIO_P_CTRL_DRIVEMODE_MASK)
\r
448 void GPIO_DriveModeSet(GPIO_Port_TypeDef port, GPIO_DriveMode_TypeDef mode);
\r
451 #if defined( _GPIO_P_CTRL_DRIVESTRENGTH_MASK )
\r
452 void GPIO_DriveStrengthSet(GPIO_Port_TypeDef port, GPIO_DriveStrength_TypeDef strength);
\r
455 # if defined( _GPIO_EM4WUEN_MASK )
\r
456 /**************************************************************************//**
\r
458 * Disable GPIO pin wake-up from EM4.
\r
460 * @param[in] pinmask
\r
461 * Bitmask containing the bitwise logic OR of which GPIO pin(s) to disable.
\r
462 * Refer to Reference Manuals for pinmask to GPIO port/pin mapping.
\r
463 *****************************************************************************/
\r
464 __STATIC_INLINE void GPIO_EM4DisablePinWakeup(uint32_t pinmask)
\r
466 EFM_ASSERT((pinmask & ~_GPIO_EM4WUEN_MASK) == 0);
\r
468 GPIO->EM4WUEN &= ~pinmask;
\r
473 #if defined( _GPIO_EM4WUCAUSE_MASK ) || defined( _RMU_RSTCAUSE_EM4RST_MASK )
\r
474 /**************************************************************************//**
\r
476 * Check which GPIO pin(s) that caused a wake-up from EM4.
\r
479 * Bitmask containing the bitwise logic OR of which GPIO pin(s) caused the
\r
480 * wake-up. Refer to Reference Manuals for pinmask to GPIO port/pin mapping.
\r
481 *****************************************************************************/
\r
482 __STATIC_INLINE uint32_t GPIO_EM4GetPinWakeupCause(void)
\r
484 #if defined( _GPIO_EM4WUCAUSE_MASK )
\r
485 return GPIO->EM4WUCAUSE & _GPIO_EM4WUCAUSE_MASK;
\r
487 return RMU->RSTCAUSE & _RMU_RSTCAUSE_EM4RST_MASK;
\r
493 #if defined( GPIO_CTRL_EM4RET ) || defined( _EMU_EM4CTRL_EM4IORETMODE_MASK )
\r
494 /**************************************************************************//**
\r
496 * Enable GPIO pin retention of output enable, output value, pull enable and
\r
497 * pull direction in EM4.
\r
500 * For platform 2 parts, EMU_EM4Init() and EMU_UnlatchPinRetention() offers
\r
501 * more pin retention features. This function implements the EM4EXIT retention
\r
502 * mode on platform 2.
\r
504 * @param[in] enable
\r
505 * @li true - enable EM4 pin retention.
\r
506 * @li false - disable EM4 pin retention.
\r
507 *****************************************************************************/
\r
508 __STATIC_INLINE void GPIO_EM4SetPinRetention(bool enable)
\r
512 #if defined( GPIO_CTRL_EM4RET )
\r
513 GPIO->CTRL |= GPIO_CTRL_EM4RET;
\r
515 EMU->EM4CTRL = (EMU->EM4CTRL & ~_EMU_EM4CTRL_EM4IORETMODE_MASK)
\r
516 | EMU_EM4CTRL_EM4IORETMODE_EM4EXIT;
\r
521 #if defined( GPIO_CTRL_EM4RET )
\r
522 GPIO->CTRL &= ~GPIO_CTRL_EM4RET;
\r
524 EMU->EM4CTRL = (EMU->EM4CTRL & ~_EMU_EM4CTRL_EM4IORETMODE_MASK)
\r
525 | EMU_EM4CTRL_EM4IORETMODE_DISABLE;
\r
532 /***************************************************************************//**
\r
534 * Enable/disable input sensing.
\r
537 * Disabling input sensing if not used, can save some energy consumption.
\r
540 * Bitwise logic OR of one or more of:
\r
541 * @li GPIO_INSENSE_INT - interrupt input sensing.
\r
542 * @li GPIO_INSENSE_PRS - peripheral reflex system input sensing.
\r
545 * Mask containing bitwise logic OR of bits similar as for @p val used to
\r
546 * indicate which input sense options to disable/enable.
\r
547 ******************************************************************************/
\r
548 __STATIC_INLINE void GPIO_InputSenseSet(uint32_t val, uint32_t mask)
\r
550 GPIO->INSENSE = (GPIO->INSENSE & ~mask) | (val & mask);
\r
554 /***************************************************************************//**
\r
556 * Clear one or more pending GPIO interrupts.
\r
559 * Bitwise logic OR of GPIO interrupt sources to clear.
\r
560 ******************************************************************************/
\r
561 __STATIC_INLINE void GPIO_IntClear(uint32_t flags)
\r
567 /***************************************************************************//**
\r
569 * Disable one or more GPIO interrupts.
\r
572 * GPIO interrupt sources to disable.
\r
573 ******************************************************************************/
\r
574 __STATIC_INLINE void GPIO_IntDisable(uint32_t flags)
\r
576 GPIO->IEN &= ~flags;
\r
580 /***************************************************************************//**
\r
582 * Enable one or more GPIO interrupts.
\r
585 * Depending on the use, a pending interrupt may already be set prior to
\r
586 * enabling the interrupt. Consider using GPIO_IntClear() prior to enabling
\r
587 * if such a pending interrupt should be ignored.
\r
590 * GPIO interrupt sources to enable.
\r
591 ******************************************************************************/
\r
592 __STATIC_INLINE void GPIO_IntEnable(uint32_t flags)
\r
594 GPIO->IEN |= flags;
\r
598 /***************************************************************************//**
\r
600 * Get pending GPIO interrupts.
\r
603 * GPIO interrupt sources pending.
\r
604 ******************************************************************************/
\r
605 __STATIC_INLINE uint32_t GPIO_IntGet(void)
\r
611 /***************************************************************************//**
\r
613 * Get enabled and pending GPIO interrupt flags.
\r
614 * Useful for handling more interrupt sources in the same interrupt handler.
\r
617 * Interrupt flags are not cleared by the use of this function.
\r
620 * Pending and enabled GPIO interrupt sources.
\r
621 * The return value is the bitwise AND combination of
\r
622 * - the OR combination of enabled interrupt sources in GPIO_IEN register
\r
624 * - the OR combination of valid interrupt flags in GPIO_IF register.
\r
625 ******************************************************************************/
\r
626 __STATIC_INLINE uint32_t GPIO_IntGetEnabled(void)
\r
630 /* Store GPIO->IEN in temporary variable in order to define explicit order
\r
631 * of volatile accesses. */
\r
634 /* Bitwise AND of pending and enabled interrupts */
\r
635 return GPIO->IF & tmp;
\r
639 /**************************************************************************//**
\r
641 * Set one or more pending GPIO interrupts from SW.
\r
644 * GPIO interrupt sources to set to pending.
\r
645 *****************************************************************************/
\r
646 __STATIC_INLINE void GPIO_IntSet(uint32_t flags)
\r
652 /***************************************************************************//**
\r
654 * Locks the GPIO configuration.
\r
655 ******************************************************************************/
\r
656 __STATIC_INLINE void GPIO_Lock(void)
\r
658 GPIO->LOCK = GPIO_LOCK_LOCKKEY_LOCK;
\r
662 /***************************************************************************//**
\r
664 * Read the pad value for a single pin in a GPIO port.
\r
667 * The GPIO port to access.
\r
670 * The pin number to read.
\r
673 * The pin value, 0 or 1.
\r
674 ******************************************************************************/
\r
675 __STATIC_INLINE unsigned int GPIO_PinInGet(GPIO_Port_TypeDef port,
\r
678 EFM_ASSERT(GPIO_PORT_PIN_VALID(port, pin));
\r
679 return BUS_RegBitRead(&GPIO->P[port].DIN, pin);
\r
683 /***************************************************************************//**
\r
685 * Set a single pin in GPIO data out port register to 0.
\r
688 * In order for the setting to take effect on the output pad, the pin must
\r
689 * have been configured properly. If not, it will take effect whenever the
\r
690 * pin has been properly configured.
\r
693 * The GPIO port to access.
\r
697 ******************************************************************************/
\r
698 __STATIC_INLINE void GPIO_PinOutClear(GPIO_Port_TypeDef port, unsigned int pin)
\r
700 EFM_ASSERT(GPIO_PORT_PIN_VALID(port, pin));
\r
701 #if defined( _GPIO_P_DOUTCLR_MASK )
\r
702 GPIO->P[port].DOUTCLR = 1 << pin;
\r
704 BUS_RegBitWrite(&GPIO->P[port].DOUT, pin, 0);
\r
709 /***************************************************************************//**
\r
711 * Get current setting for a pin in a GPIO port data out register.
\r
714 * The GPIO port to access.
\r
717 * The pin to get setting for.
\r
720 * The DOUT setting for the requested pin, 0 or 1.
\r
721 ******************************************************************************/
\r
722 __STATIC_INLINE unsigned int GPIO_PinOutGet(GPIO_Port_TypeDef port,
\r
725 EFM_ASSERT(GPIO_PORT_PIN_VALID(port, pin));
\r
726 return BUS_RegBitRead(&GPIO->P[port].DOUT, pin);
\r
730 /***************************************************************************//**
\r
732 * Set a single pin in GPIO data out register to 1.
\r
735 * In order for the setting to take effect on the output pad, the pin must
\r
736 * have been configured properly. If not, it will take effect whenever the
\r
737 * pin has been properly configured.
\r
740 * The GPIO port to access.
\r
744 ******************************************************************************/
\r
745 __STATIC_INLINE void GPIO_PinOutSet(GPIO_Port_TypeDef port, unsigned int pin)
\r
747 EFM_ASSERT(GPIO_PORT_PIN_VALID(port, pin));
\r
748 #if defined( _GPIO_P_DOUTSET_MASK )
\r
749 GPIO->P[port].DOUTSET = 1 << pin;
\r
751 BUS_RegBitWrite(&GPIO->P[port].DOUT, pin, 1);
\r
756 /***************************************************************************//**
\r
758 * Toggle a single pin in GPIO port data out register.
\r
761 * In order for the setting to take effect on the output pad, the pin must
\r
762 * have been configured properly. If not, it will take effect whenever the
\r
763 * pin has been properly configured.
\r
766 * The GPIO port to access.
\r
769 * The pin to toggle.
\r
770 ******************************************************************************/
\r
771 __STATIC_INLINE void GPIO_PinOutToggle(GPIO_Port_TypeDef port, unsigned int pin)
\r
773 EFM_ASSERT(GPIO_PORT_PIN_VALID(port, pin));
\r
775 GPIO->P[port].DOUTTGL = 1 << pin;
\r
779 /***************************************************************************//**
\r
781 * Read the pad values for GPIO port.
\r
784 * The GPIO port to access.
\r
785 ******************************************************************************/
\r
786 __STATIC_INLINE uint32_t GPIO_PortInGet(GPIO_Port_TypeDef port)
\r
788 EFM_ASSERT(GPIO_PORT_VALID(port));
\r
790 return GPIO->P[port].DIN;
\r
794 /***************************************************************************//**
\r
796 * Set bits in DOUT register for a port to 0.
\r
799 * In order for the setting to take effect on the output pad, the pin must
\r
800 * have been configured properly. If not, it will take effect whenever the
\r
801 * pin has been properly configured.
\r
804 * The GPIO port to access.
\r
807 * Bit mask for bits to clear in DOUT register.
\r
808 ******************************************************************************/
\r
809 __STATIC_INLINE void GPIO_PortOutClear(GPIO_Port_TypeDef port, uint32_t pins)
\r
811 EFM_ASSERT(GPIO_PORT_VALID(port));
\r
812 #if defined( _GPIO_P_DOUTCLR_MASK )
\r
813 GPIO->P[port].DOUTCLR = pins;
\r
815 BUS_RegMaskedClear(&GPIO->P[port].DOUT, pins);
\r
820 /***************************************************************************//**
\r
822 * Get current setting for a GPIO port data out register.
\r
825 * The GPIO port to access.
\r
828 * The data out setting for the requested port.
\r
829 ******************************************************************************/
\r
830 __STATIC_INLINE uint32_t GPIO_PortOutGet(GPIO_Port_TypeDef port)
\r
832 EFM_ASSERT(GPIO_PORT_VALID(port));
\r
834 return GPIO->P[port].DOUT;
\r
838 /***************************************************************************//**
\r
840 * Set bits GPIO data out register to 1.
\r
843 * In order for the setting to take effect on the respective output pads, the
\r
844 * pins must have been configured properly. If not, it will take effect
\r
845 * whenever the pin has been properly configured.
\r
848 * The GPIO port to access.
\r
851 * Bit mask for bits to set to 1 in DOUT register.
\r
852 ******************************************************************************/
\r
853 __STATIC_INLINE void GPIO_PortOutSet(GPIO_Port_TypeDef port, uint32_t pins)
\r
855 EFM_ASSERT(GPIO_PORT_VALID(port));
\r
856 #if defined( _GPIO_P_DOUTSET_MASK )
\r
857 GPIO->P[port].DOUTSET = pins;
\r
859 BUS_RegMaskedSet(&GPIO->P[port].DOUT, pins);
\r
864 /***************************************************************************//**
\r
866 * Set GPIO port data out register.
\r
869 * In order for the setting to take effect on the respective output pads, the
\r
870 * pins must have been configured properly. If not, it will take effect
\r
871 * whenever the pin has been properly configured.
\r
874 * The GPIO port to access.
\r
877 * Value to write to port data out register.
\r
880 * Mask indicating which bits to modify.
\r
881 ******************************************************************************/
\r
882 __STATIC_INLINE void GPIO_PortOutSetVal(GPIO_Port_TypeDef port,
\r
886 EFM_ASSERT(GPIO_PORT_VALID(port));
\r
888 GPIO->P[port].DOUT = (GPIO->P[port].DOUT & ~mask) | (val & mask);
\r
892 /***************************************************************************//**
\r
894 * Toggle pins in GPIO port data out register.
\r
897 * In order for the setting to take effect on the output pad, the pin must
\r
898 * have been configured properly. If not, it will take effect whenever the
\r
899 * pin has been properly configured.
\r
902 * The GPIO port to access.
\r
905 * Bitmask with pins to toggle.
\r
906 ******************************************************************************/
\r
907 __STATIC_INLINE void GPIO_PortOutToggle(GPIO_Port_TypeDef port, uint32_t pins)
\r
909 EFM_ASSERT(GPIO_PORT_VALID(port));
\r
911 GPIO->P[port].DOUTTGL = pins;
\r
915 /***************************************************************************//**
\r
917 * Unlocks the GPIO configuration.
\r
918 ******************************************************************************/
\r
919 __STATIC_INLINE void GPIO_Unlock(void)
\r
921 GPIO->LOCK = GPIO_LOCK_LOCKKEY_UNLOCK;
\r
924 /** @} (end addtogroup GPIO) */
\r
925 /** @} (end addtogroup EM_Library) */
\r
931 #endif /* defined(GPIO_COUNT) && (GPIO_COUNT > 0) */
\r
932 #endif /* __SILICON_LABS_EM_GPIO_H__ */
\r