]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/emlib/inc/em_gpio.h
b20923d6773d2f8a69c7812aab3c041e78c6573f
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio / Source / SilLabs_Code / emlib / inc / em_gpio.h
1 /***************************************************************************//**\r
2  * @file em_gpio.h\r
3  * @brief General Purpose IO (GPIO) peripheral API\r
4  * @version 4.0.0\r
5  *******************************************************************************\r
6  * @section License\r
7  * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>\r
8  *******************************************************************************\r
9  *\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
13  *\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
19  *\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
26  *\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
30  *\r
31  ******************************************************************************/\r
32 \r
33 \r
34 #ifndef __SILICON_LABS_EM_GPIO_H_\r
35 #define __SILICON_LABS_EM_GPIO_H_\r
36 \r
37 #include "em_device.h"\r
38 #if defined(GPIO_COUNT) && (GPIO_COUNT > 0)\r
39 \r
40 #include <stdbool.h>\r
41 #include "em_bitband.h"\r
42 #include "em_assert.h"\r
43 \r
44 #ifdef __cplusplus\r
45 extern "C" {\r
46 #endif\r
47 \r
48 /***************************************************************************//**\r
49  * @addtogroup EM_Library\r
50  * @{\r
51  ******************************************************************************/\r
52 \r
53 /***************************************************************************//**\r
54  * @addtogroup GPIO\r
55  * @{\r
56  ******************************************************************************/\r
57 \r
58 /*******************************************************************************\r
59  ********************************   ENUMS   ************************************\r
60  ******************************************************************************/\r
61 \r
62 /** GPIO ports identificator. */\r
63 typedef enum\r
64 {\r
65   gpioPortA = 0, /**< Port A */\r
66   gpioPortB = 1, /**< Port B */\r
67   gpioPortC = 2, /**< Port C */\r
68   gpioPortD = 3, /**< Port D */\r
69   gpioPortE = 4, /**< Port E */\r
70   gpioPortF = 5  /**< Port F */\r
71 } GPIO_Port_TypeDef;\r
72 \r
73 /** GPIO drive mode. */\r
74 typedef enum\r
75 {\r
76   /** Default 6mA */\r
77   gpioDriveModeStandard = GPIO_P_CTRL_DRIVEMODE_STANDARD,\r
78   /** 0.5 mA */\r
79   gpioDriveModeLowest   = GPIO_P_CTRL_DRIVEMODE_LOWEST,\r
80   /** 20 mA */\r
81   gpioDriveModeHigh     = GPIO_P_CTRL_DRIVEMODE_HIGH,\r
82   /** 2 mA */\r
83   gpioDriveModeLow      = GPIO_P_CTRL_DRIVEMODE_LOW\r
84 } GPIO_DriveMode_TypeDef;\r
85 \r
86 /** Pin mode. For more details on each mode, please refer to the EFM32\r
87  * reference manual. */\r
88 typedef enum\r
89 {\r
90   /** Input disabled. Pullup if DOUT is set. */\r
91   gpioModeDisabled                  = _GPIO_P_MODEL_MODE0_DISABLED,\r
92   /** Input enabled. Filter if DOUT is set */\r
93   gpioModeInput                     = _GPIO_P_MODEL_MODE0_INPUT,\r
94   /** Input enabled. DOUT determines pull direction */\r
95   gpioModeInputPull                 = _GPIO_P_MODEL_MODE0_INPUTPULL,\r
96   /** Input enabled with filter. DOUT determines pull direction */\r
97   gpioModeInputPullFilter           = _GPIO_P_MODEL_MODE0_INPUTPULLFILTER,\r
98   /** Push-pull output */\r
99   gpioModePushPull                  = _GPIO_P_MODEL_MODE0_PUSHPULL,\r
100   /** Push-pull output with drive-strength set by DRIVEMODE */\r
101   gpioModePushPullDrive             = _GPIO_P_MODEL_MODE0_PUSHPULLDRIVE,\r
102   /** Wired-or output */\r
103   gpioModeWiredOr                   = _GPIO_P_MODEL_MODE0_WIREDOR,\r
104   /** Wired-or output with pull-down */\r
105   gpioModeWiredOrPullDown           = _GPIO_P_MODEL_MODE0_WIREDORPULLDOWN,\r
106   /** Open-drain output */\r
107   gpioModeWiredAnd                  = _GPIO_P_MODEL_MODE0_WIREDAND,\r
108   /** Open-drain output with filter */\r
109   gpioModeWiredAndFilter            = _GPIO_P_MODEL_MODE0_WIREDANDFILTER,\r
110   /** Open-drain output with pullup */\r
111   gpioModeWiredAndPullUp            = _GPIO_P_MODEL_MODE0_WIREDANDPULLUP,\r
112   /** Open-drain output with filter and pullup */\r
113   gpioModeWiredAndPullUpFilter      = _GPIO_P_MODEL_MODE0_WIREDANDPULLUPFILTER,\r
114   /** Open-drain output with drive-strength set by DRIVEMODE */\r
115   gpioModeWiredAndDrive             = _GPIO_P_MODEL_MODE0_WIREDANDDRIVE,\r
116   /** Open-drain output with filter and drive-strength set by DRIVEMODE */\r
117   gpioModeWiredAndDriveFilter       = _GPIO_P_MODEL_MODE0_WIREDANDDRIVEFILTER,\r
118   /** Open-drain output with pullup and drive-strength set by DRIVEMODE */\r
119   gpioModeWiredAndDrivePullUp       = _GPIO_P_MODEL_MODE0_WIREDANDDRIVEPULLUP,\r
120   /** Open-drain output with filter, pullup and drive-strength set by DRIVEMODE */\r
121   gpioModeWiredAndDrivePullUpFilter = _GPIO_P_MODEL_MODE0_WIREDANDDRIVEPULLUPFILTER\r
122 } GPIO_Mode_TypeDef;\r
123 \r
124 \r
125 /*******************************************************************************\r
126  *******************************   DEFINES   ***********************************\r
127  ******************************************************************************/\r
128 \r
129 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */\r
130 \r
131 /** Validation of pin typically usable in assert statements. */\r
132 #define GPIO_PIN_VALID(pin)           ((pin) < 16)\r
133 \r
134 /** Validation of port typically usable in assert statements. */\r
135 #define GPIO_PORT_VALID(port)         ((port) <= gpioPortF)\r
136 \r
137 /** @endcond */\r
138 \r
139 \r
140 /*******************************************************************************\r
141  *****************************   PROTOTYPES   **********************************\r
142  ******************************************************************************/\r
143 \r
144 void GPIO_DbgLocationSet(unsigned int location);\r
145 \r
146 void GPIO_IntConfig(GPIO_Port_TypeDef port,\r
147                     unsigned int pin,\r
148                     bool risingEdge,\r
149                     bool fallingEdge,\r
150                     bool enable);\r
151 \r
152 void GPIO_PinModeSet(GPIO_Port_TypeDef port,\r
153                      unsigned int pin,\r
154                      GPIO_Mode_TypeDef mode,\r
155                      unsigned int out);\r
156 \r
157 # if defined( GPIO_CTRL_EM4RET )\r
158 __STATIC_INLINE void GPIO_EM4SetPinRetention(bool enable);\r
159 #endif\r
160 \r
161 /***************************************************************************//**\r
162  * @brief\r
163  *   Enable/disable serial wire clock pin.\r
164  *\r
165  * @note\r
166  *   Disabling SWDClk will disable the debug interface, which may result in\r
167  *   a lockout if done early in startup (before debugger is able to halt core).\r
168  *\r
169  * @param[in] enable\r
170  *   @li false - disable serial wire clock.\r
171  *   @li true - enable serial wire clock (default after reset).\r
172  ******************************************************************************/\r
173 __STATIC_INLINE void GPIO_DbgSWDClkEnable(bool enable)\r
174 {\r
175   BITBAND_Peripheral(&(GPIO->ROUTE), _GPIO_ROUTE_SWCLKPEN_SHIFT, (unsigned int)enable);\r
176 }\r
177 \r
178 \r
179 /***************************************************************************//**\r
180  * @brief\r
181  *   Enable/disable serial wire data pin.\r
182  *\r
183  * @note\r
184  *   Disabling SWDClk will disable the debug interface, which may result in\r
185  *   a lockout if done early in startup (before debugger is able to halt core).\r
186  *\r
187  * @param[in] enable\r
188  *   @li false - disable serial wire data pin.\r
189  *   @li true - enable serial wire data pin (default after reset).\r
190  ******************************************************************************/\r
191 __STATIC_INLINE void GPIO_DbgSWDIOEnable(bool enable)\r
192 {\r
193   BITBAND_Peripheral(&(GPIO->ROUTE), _GPIO_ROUTE_SWDIOPEN_SHIFT, (unsigned int)enable);\r
194 }\r
195 \r
196 \r
197 #if defined( GPIO_ROUTE_SWOPEN )\r
198 /***************************************************************************//**\r
199  * @brief\r
200  *   Enable/Disable serial wire output pin.\r
201  *\r
202  * @note\r
203  *   Enabling this pin is not sufficient to fully enable serial wire output\r
204  *   which is also dependent on issues outside the GPIO module. Please refer to\r
205  *   DBG_SWOEnable().\r
206  *\r
207  * @param[in] enable\r
208  *   @li false - disable serial wire viewer pin (default after reset).\r
209  *   @li true - enable serial wire viewer pin.\r
210  ******************************************************************************/\r
211 __STATIC_INLINE void GPIO_DbgSWOEnable(bool enable)\r
212 {\r
213   BITBAND_Peripheral(&(GPIO->ROUTE), _GPIO_ROUTE_SWOPEN_SHIFT, (unsigned int)enable);\r
214 }\r
215 #endif\r
216 \r
217 void GPIO_DriveModeSet(GPIO_Port_TypeDef port, GPIO_DriveMode_TypeDef mode);\r
218 \r
219 \r
220 # if defined( _GPIO_EM4WUEN_MASK )\r
221 /**************************************************************************//**\r
222  * @brief\r
223  *   Disable GPIO pin wake-up from EM4.\r
224  *\r
225  * @param[in] pinmask\r
226  *   Bitmask containing the bitwise logic OR of which GPIO pin(s) to disable.\r
227  *   Refer to Reference Manuals for pinmask to GPIO port/pin mapping.\r
228  *****************************************************************************/\r
229 __STATIC_INLINE void GPIO_EM4DisablePinWakeup(uint32_t pinmask)\r
230 {\r
231   EFM_ASSERT((pinmask & ~_GPIO_EM4WUEN_MASK) == 0);\r
232 \r
233   GPIO->EM4WUEN &= ~pinmask;\r
234 }\r
235 #endif\r
236 \r
237 \r
238 # if defined( _GPIO_EM4WUEN_MASK )\r
239 /**************************************************************************//**\r
240  * @brief\r
241  *   Enable GPIO pin wake-up from EM4. When the function exits,\r
242  *   EM4 mode can be safely entered.\r
243  *\r
244  * @note\r
245  *   It is assumed that the GPIO pin modes are set correctly.\r
246  *   Valid modes are @ref gpioModeInput and @ref gpioModeInputPull.\r
247  *\r
248  * @param[in] pinmask\r
249  *   Bitmask containing the bitwise logic OR of which GPIO pin(s) to enable.\r
250  *   Refer to Reference Manuals for pinmask to GPIO port/pin mapping.\r
251  * @param[in] polaritymask\r
252  *   Bitmask containing the bitwise logic OR of GPIO pin(s) wake-up polarity.\r
253  *   Refer to Reference Manuals for pinmask to GPIO port/pin mapping.\r
254  *****************************************************************************/\r
255 __STATIC_INLINE void GPIO_EM4EnablePinWakeup(uint32_t pinmask,\r
256                                              uint32_t polaritymask)\r
257 {\r
258   EFM_ASSERT((pinmask & ~_GPIO_EM4WUEN_MASK) == 0);\r
259   EFM_ASSERT((polaritymask & ~_GPIO_EM4WUPOL_MASK) == 0);\r
260 \r
261   GPIO->EM4WUPOL &= ~pinmask;               /* Set wakeup polarity */\r
262   GPIO->EM4WUPOL |= pinmask & polaritymask;\r
263   GPIO->EM4WUEN  |= pinmask;                /* Enable wakeup */\r
264 \r
265   GPIO_EM4SetPinRetention(true);            /* Enable pin retention */\r
266 \r
267   GPIO->CMD = GPIO_CMD_EM4WUCLR;            /* Clear wake-up logic */\r
268 }\r
269 #endif\r
270 \r
271 #if defined( _GPIO_EM4WUCAUSE_MASK )\r
272 /**************************************************************************//**\r
273  * @brief\r
274  *   Check which GPIO pin(s) that caused a wake-up from EM4.\r
275  *\r
276  * @return\r
277  *   Bitmask containing the bitwise logic OR of which GPIO pin(s) caused the\r
278  *   wake-up. Refer to Reference Manuals for pinmask to GPIO port/pin mapping.\r
279  *****************************************************************************/\r
280 __STATIC_INLINE uint32_t GPIO_EM4GetPinWakeupCause(void)\r
281 {\r
282   return GPIO->EM4WUCAUSE & _GPIO_EM4WUCAUSE_MASK;\r
283 }\r
284 #endif\r
285 \r
286 \r
287 # if defined( GPIO_CTRL_EM4RET )\r
288 /**************************************************************************//**\r
289  * @brief\r
290  *   Enable GPIO pin retention of output enable, output value, pull enable and\r
291  *   pull direction in EM4.\r
292  *\r
293  * @param[in] enable\r
294  *   @li true - enable EM4 pin retention.\r
295  *   @li false - disable EM4 pin retention.\r
296  *****************************************************************************/\r
297 __STATIC_INLINE void GPIO_EM4SetPinRetention(bool enable)\r
298 {\r
299   if (enable)\r
300   {\r
301     GPIO->CTRL |= GPIO_CTRL_EM4RET;\r
302   }\r
303   else\r
304   {\r
305     GPIO->CTRL &= ~GPIO_CTRL_EM4RET;\r
306   }\r
307 }\r
308 #endif\r
309 \r
310 \r
311 /***************************************************************************//**\r
312  * @brief\r
313  *   Enable/disable input sensing.\r
314  *\r
315  * @details\r
316  *   Disabling input sensing if not used, can save some energy consumption.\r
317  *\r
318  * @param[in] val\r
319  *   Bitwise logic OR of one or more of:\r
320  *   @li GPIO_INSENSE_INT - interrupt input sensing.\r
321  *   @li GPIO_INSENSE_PRS - peripheral reflex system input sensing.\r
322  *\r
323  * @param[in] mask\r
324  *   Mask containing bitwise logic OR of bits similar as for @p val used to indicate\r
325  *   which input sense options to disable/enable.\r
326  ******************************************************************************/\r
327 __STATIC_INLINE void GPIO_InputSenseSet(uint32_t val, uint32_t mask)\r
328 {\r
329   GPIO->INSENSE = (GPIO->INSENSE & ~mask) | (val & mask);\r
330 }\r
331 \r
332 \r
333 /***************************************************************************//**\r
334  * @brief\r
335  *   Clear one or more pending GPIO interrupts.\r
336  *\r
337  * @param[in] flags\r
338  *   Bitwise logic OR of GPIO interrupt sources to clear.\r
339  ******************************************************************************/\r
340 __STATIC_INLINE void GPIO_IntClear(uint32_t flags)\r
341 {\r
342   GPIO->IFC = flags;\r
343 }\r
344 \r
345 \r
346 /***************************************************************************//**\r
347  * @brief\r
348  *   Disable one or more GPIO interrupts.\r
349  *\r
350  * @param[in] flags\r
351  *   GPIO interrupt sources to disable.\r
352  ******************************************************************************/\r
353 __STATIC_INLINE void GPIO_IntDisable(uint32_t flags)\r
354 {\r
355   GPIO->IEN &= ~flags;\r
356 }\r
357 \r
358 \r
359 /***************************************************************************//**\r
360  * @brief\r
361  *   Enable one or more GPIO interrupts.\r
362  *\r
363  * @note\r
364  *   Depending on the use, a pending interrupt may already be set prior to\r
365  *   enabling the interrupt. Consider using GPIO_IntClear() prior to enabling\r
366  *   if such a pending interrupt should be ignored.\r
367  *\r
368  * @param[in] flags\r
369  *   GPIO interrupt sources to enable.\r
370  ******************************************************************************/\r
371 __STATIC_INLINE void GPIO_IntEnable(uint32_t flags)\r
372 {\r
373   GPIO->IEN |= flags;\r
374 }\r
375 \r
376 \r
377 /***************************************************************************//**\r
378  * @brief\r
379  *   Get pending GPIO interrupts.\r
380  *\r
381  * @return\r
382  *   GPIO interrupt sources pending.\r
383  ******************************************************************************/\r
384 __STATIC_INLINE uint32_t GPIO_IntGet(void)\r
385 {\r
386   return(GPIO->IF);\r
387 }\r
388 \r
389 \r
390 /***************************************************************************//**\r
391  * @brief\r
392  *   Get enabled and pending GPIO interrupt flags.\r
393  *   Useful for handling more interrupt sources in the same interrupt handler.\r
394  *\r
395  * @note\r
396  *   Interrupt flags are not cleared by the use of this function.\r
397  *\r
398  * @return\r
399  *   Pending and enabled GPIO interrupt sources.\r
400  *   The return value is the bitwise AND combination of\r
401  *   - the OR combination of enabled interrupt sources in GPIO_IEN register\r
402  *     and\r
403  *   - the OR combination of valid interrupt flags in GPIO_IF register.\r
404  ******************************************************************************/\r
405 __STATIC_INLINE uint32_t GPIO_IntGetEnabled(void)\r
406 {\r
407   uint32_t tmp;\r
408 \r
409   /* Store GPIO->IEN in temporary variable in order to define explicit order\r
410    * of volatile accesses. */\r
411   tmp = GPIO->IEN;\r
412 \r
413   /* Bitwise AND of pending and enabled interrupts */\r
414   return GPIO->IF & tmp;\r
415 }\r
416 \r
417 \r
418 /**************************************************************************//**\r
419  * @brief\r
420  *   Set one or more pending GPIO interrupts from SW.\r
421  *\r
422  * @param[in] flags\r
423  *   GPIO interrupt sources to set to pending.\r
424  *****************************************************************************/\r
425 __STATIC_INLINE void GPIO_IntSet(uint32_t flags)\r
426 {\r
427   GPIO->IFS = flags;\r
428 }\r
429 \r
430 \r
431 /***************************************************************************//**\r
432  * @brief\r
433  *   Locks the GPIO configuration.\r
434  ******************************************************************************/\r
435 __STATIC_INLINE void GPIO_Lock(void)\r
436 {\r
437   GPIO->LOCK = GPIO_LOCK_LOCKKEY_LOCK;\r
438 }\r
439 \r
440 \r
441 /***************************************************************************//**\r
442  * @brief\r
443  *   Read the pad value for a single pin in a GPIO port.\r
444  *\r
445  * @param[in] port\r
446  *   The GPIO port to access.\r
447  *\r
448  * @param[in] pin\r
449  *   The pin number to read.\r
450  *\r
451  * @return\r
452  *   The pin value, 0 or 1.\r
453  ******************************************************************************/\r
454 __STATIC_INLINE unsigned int GPIO_PinInGet(GPIO_Port_TypeDef port, unsigned int pin)\r
455 {\r
456   EFM_ASSERT(GPIO_PORT_VALID(port) && GPIO_PIN_VALID(pin));\r
457 \r
458   return((unsigned int)((GPIO->P[port].DIN >> pin) & 0x1));\r
459 }\r
460 \r
461 \r
462 /***************************************************************************//**\r
463  * @brief\r
464  *   Set a single pin in GPIO data out port register to 0.\r
465  *\r
466  * @note\r
467  *   In order for the setting to take effect on the output pad, the pin must\r
468  *   have been configured properly. If not, it will take effect whenever the\r
469  *   pin has been properly configured.\r
470  *\r
471  * @param[in] port\r
472  *   The GPIO port to access.\r
473  *\r
474  * @param[in] pin\r
475  *   The pin to set.\r
476  ******************************************************************************/\r
477 __STATIC_INLINE void GPIO_PinOutClear(GPIO_Port_TypeDef port, unsigned int pin)\r
478 {\r
479   EFM_ASSERT(GPIO_PORT_VALID(port) && GPIO_PIN_VALID(pin));\r
480 \r
481   GPIO->P[port].DOUTCLR = 1 << pin;\r
482 }\r
483 \r
484 \r
485 /***************************************************************************//**\r
486  * @brief\r
487  *   Get current setting for a pin in a GPIO port data out register.\r
488  *\r
489  * @param[in] port\r
490  *   The GPIO port to access.\r
491  *\r
492  * @param[in] pin\r
493  *   The pin to get setting for.\r
494  *\r
495  * @return\r
496  *   The DOUT setting for the requested pin, 0 or 1.\r
497  ******************************************************************************/\r
498 __STATIC_INLINE unsigned int GPIO_PinOutGet(GPIO_Port_TypeDef port, unsigned int pin)\r
499 {\r
500   EFM_ASSERT(GPIO_PORT_VALID(port) && GPIO_PIN_VALID(pin));\r
501 \r
502   return((unsigned int)((GPIO->P[port].DOUT >> pin) & 0x1));\r
503 }\r
504 \r
505 \r
506 /***************************************************************************//**\r
507  * @brief\r
508  *   Set a single pin in GPIO data out register to 1.\r
509  *\r
510  * @note\r
511  *   In order for the setting to take effect on the output pad, the pin must\r
512  *   have been configured properly. If not, it will take effect whenever the\r
513  *   pin has been properly configured.\r
514  *\r
515  * @param[in] port\r
516  *   The GPIO port to access.\r
517  *\r
518  * @param[in] pin\r
519  *   The pin to set.\r
520  ******************************************************************************/\r
521 __STATIC_INLINE void GPIO_PinOutSet(GPIO_Port_TypeDef port, unsigned int pin)\r
522 {\r
523   EFM_ASSERT(GPIO_PORT_VALID(port) && GPIO_PIN_VALID(pin));\r
524 \r
525   GPIO->P[port].DOUTSET = 1 << pin;\r
526 }\r
527 \r
528 \r
529 /***************************************************************************//**\r
530  * @brief\r
531  *   Toggle a single pin in GPIO port data out register.\r
532  *\r
533  * @note\r
534  *   In order for the setting to take effect on the output pad, the pin must\r
535  *   have been configured properly. If not, it will take effect whenever the\r
536  *   pin has been properly configured.\r
537  *\r
538  * @param[in] port\r
539  *   The GPIO port to access.\r
540  *\r
541  * @param[in] pin\r
542  *   The pin to toggle.\r
543  ******************************************************************************/\r
544 __STATIC_INLINE void GPIO_PinOutToggle(GPIO_Port_TypeDef port, unsigned int pin)\r
545 {\r
546   EFM_ASSERT(GPIO_PORT_VALID(port) && GPIO_PIN_VALID(pin));\r
547 \r
548   GPIO->P[port].DOUTTGL = 1 << pin;\r
549 }\r
550 \r
551 \r
552 /***************************************************************************//**\r
553  * @brief\r
554  *   Read the pad values for GPIO port.\r
555  *\r
556  * @param[in] port\r
557  *   The GPIO port to access.\r
558  ******************************************************************************/\r
559 __STATIC_INLINE uint32_t GPIO_PortInGet(GPIO_Port_TypeDef port)\r
560 {\r
561   EFM_ASSERT(GPIO_PORT_VALID(port));\r
562 \r
563   return(GPIO->P[port].DIN & _GPIO_P_DIN_DIN_MASK);\r
564 }\r
565 \r
566 \r
567 /***************************************************************************//**\r
568  * @brief\r
569  *   Set bits in DOUT register for a port to 0.\r
570  *\r
571  * @note\r
572  *   In order for the setting to take effect on the output pad, the pin must\r
573  *   have been configured properly. If not, it will take effect whenever the\r
574  *   pin has been properly configured.\r
575  *\r
576  * @param[in] port\r
577  *   The GPIO port to access.\r
578  *\r
579  * @param[in] pins\r
580  *   Bit mask for bits to clear in DOUT register.\r
581  ******************************************************************************/\r
582 __STATIC_INLINE void GPIO_PortOutClear(GPIO_Port_TypeDef port, uint32_t pins)\r
583 {\r
584   EFM_ASSERT(GPIO_PORT_VALID(port));\r
585 \r
586   GPIO->P[port].DOUTCLR = pins & _GPIO_P_DOUTCLR_DOUTCLR_MASK;\r
587 }\r
588 \r
589 \r
590 /***************************************************************************//**\r
591  * @brief\r
592  *   Get current setting for a GPIO port data out register.\r
593  *\r
594  * @param[in] port\r
595  *   The GPIO port to access.\r
596  *\r
597  * @return\r
598  *   The data out setting for the requested port.\r
599  ******************************************************************************/\r
600 __STATIC_INLINE uint32_t GPIO_PortOutGet(GPIO_Port_TypeDef port)\r
601 {\r
602   EFM_ASSERT(GPIO_PORT_VALID(port));\r
603 \r
604   return(GPIO->P[port].DOUT & _GPIO_P_DOUT_DOUT_MASK);\r
605 }\r
606 \r
607 \r
608 /***************************************************************************//**\r
609  * @brief\r
610  *   Set bits GPIO data out register to 1.\r
611  *\r
612  * @note\r
613  *   In order for the setting to take effect on the respective output pads, the\r
614  *   pins must have been configured properly. If not, it will take effect\r
615  *   whenever the pin has been properly configured.\r
616  *\r
617  * @param[in] port\r
618  *   The GPIO port to access.\r
619  *\r
620  * @param[in] pins\r
621  *   Bit mask for bits to set to 1 in DOUT register.\r
622  ******************************************************************************/\r
623 __STATIC_INLINE void GPIO_PortOutSet(GPIO_Port_TypeDef port, uint32_t pins)\r
624 {\r
625   EFM_ASSERT(GPIO_PORT_VALID(port));\r
626 \r
627   GPIO->P[port].DOUTSET = pins & _GPIO_P_DOUTSET_DOUTSET_MASK;\r
628 }\r
629 \r
630 \r
631 /***************************************************************************//**\r
632  * @brief\r
633  *   Set GPIO port data out register.\r
634  *\r
635  * @note\r
636  *   In order for the setting to take effect on the respective output pads, the\r
637  *   pins must have been configured properly. If not, it will take effect\r
638  *   whenever the pin has been properly configured.\r
639  *\r
640  * @param[in] port\r
641  *   The GPIO port to access.\r
642  *\r
643  * @param[in] val\r
644  *   Value to write to port data out register.\r
645  *\r
646  * @param[in] mask\r
647  *   Mask indicating which bits to modify.\r
648  ******************************************************************************/\r
649 __STATIC_INLINE void GPIO_PortOutSetVal(GPIO_Port_TypeDef port, uint32_t val, uint32_t mask)\r
650 {\r
651   EFM_ASSERT(GPIO_PORT_VALID(port));\r
652 \r
653   GPIO->P[port].DOUT = (GPIO->P[port].DOUT & ~mask) | (val & mask);\r
654 }\r
655 \r
656 \r
657 /***************************************************************************//**\r
658  * @brief\r
659  *   Toggle a single pin in GPIO port data out register.\r
660  *\r
661  * @note\r
662  *   In order for the setting to take effect on the output pad, the pin must\r
663  *   have been configured properly. If not, it will take effect whenever the\r
664  *   pin has been properly configured.\r
665  *\r
666  * @param[in] port\r
667  *   The GPIO port to access.\r
668  *\r
669  * @param[in] pins\r
670  *   Bitmask with pins to toggle.\r
671  ******************************************************************************/\r
672 __STATIC_INLINE void GPIO_PortOutToggle(GPIO_Port_TypeDef port, uint32_t pins)\r
673 {\r
674   EFM_ASSERT(GPIO_PORT_VALID(port));\r
675 \r
676   GPIO->P[port].DOUTTGL = pins & _GPIO_P_DOUTTGL_DOUTTGL_MASK;\r
677 }\r
678 \r
679 \r
680 /***************************************************************************//**\r
681  * @brief\r
682  *   Unlocks the GPIO configuration.\r
683  ******************************************************************************/\r
684 __STATIC_INLINE void GPIO_Unlock(void)\r
685 {\r
686   GPIO->LOCK = GPIO_LOCK_LOCKKEY_UNLOCK;\r
687 }\r
688 \r
689 \r
690 /** @} (end addtogroup GPIO) */\r
691 /** @} (end addtogroup EM_Library) */\r
692 \r
693 #ifdef __cplusplus\r
694 }\r
695 #endif\r
696 \r
697 #endif /* defined(GPIO_COUNT) && (GPIO_COUNT > 0) */\r
698 #endif /* __SILICON_LABS_EM_GPIO_H_ */\r