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.

Revision:
128:9bcdf88f62b0
Parent:
113:f141b2784e32
Child:
139:856d2700e60b
--- a/TARGET_EFM32HG_STK3400/TARGET_Silicon_Labs/TARGET_EFM32/emlib/inc/em_gpio.h	Fri Sep 30 16:49:46 2016 +0100
+++ b/TARGET_EFM32HG_STK3400/TARGET_Silicon_Labs/TARGET_EFM32/emlib/inc/em_gpio.h	Thu Oct 27 16:45:56 2016 +0100
@@ -1,10 +1,10 @@
 /***************************************************************************//**
  * @file em_gpio.h
  * @brief General Purpose IO (GPIO) peripheral API
- * @version 4.2.1
+ * @version 5.0.0
  *******************************************************************************
  * @section License
- * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
+ * <b>Copyright 2016 Silicon Laboratories, Inc. http://www.silabs.com</b>
  *******************************************************************************
  *
  * Permission is granted to anyone to use this software for any purpose,
@@ -31,8 +31,8 @@
  ******************************************************************************/
 
 
-#ifndef __SILICON_LABS_EM_GPIO_H__
-#define __SILICON_LABS_EM_GPIO_H__
+#ifndef EM_GPIO_H
+#define EM_GPIO_H
 
 #include "em_device.h"
 #if defined(GPIO_COUNT) && (GPIO_COUNT > 0)
@@ -46,7 +46,7 @@
 #endif
 
 /***************************************************************************//**
- * @addtogroup EM_Library
+ * @addtogroup emlib
  * @{
  ******************************************************************************/
 
@@ -133,14 +133,14 @@
 #define _GPIO_PORT_A_PIN_COUNT 6
 #define _GPIO_PORT_B_PIN_COUNT 5
 #define _GPIO_PORT_C_PIN_COUNT 6
-#define _GPIO_PORT_D_PIN_COUNT 3
+#define _GPIO_PORT_D_PIN_COUNT 6
 #define _GPIO_PORT_E_PIN_COUNT 0
 #define _GPIO_PORT_F_PIN_COUNT 8
 
 #define _GPIO_PORT_A_PIN_MASK 0x003F
 #define _GPIO_PORT_B_PIN_MASK 0xF800
 #define _GPIO_PORT_C_PIN_MASK 0x0FC0
-#define _GPIO_PORT_D_PIN_MASK 0xE000
+#define _GPIO_PORT_D_PIN_MASK 0xFC00
 #define _GPIO_PORT_E_PIN_MASK 0x0000
 #define _GPIO_PORT_F_PIN_MASK 0x00FF
 
@@ -213,15 +213,34 @@
 #define GPIO_PORT_VALID(port)          ( _GPIO_PORT_MASK(port) )
 #define GPIO_PORT_PIN_VALID(port, pin) ((( _GPIO_PORT_MASK(port)) >> (pin)) & 0x1 )
 
+#if defined(_GPIO_EXTIPINSELL_MASK)
+/** Validation of interrupt number and pin */
+#define GPIO_INTNO_PIN_VALID(intNo, pin)              \
+  ((intNo & ~_GPIO_EXTIPINSELL_EXTIPINSEL0_MASK)      \
+   == (pin & ~_GPIO_EXTIPINSELL_EXTIPINSEL0_MASK))
+#endif
+
 /** Highest GPIO pin number */
 #define GPIO_PIN_MAX  15
 
 /** Highest GPIO port number */
-#if defined( _GPIO_PORT_G_PIN_COUNT ) && defined( _GPIO_PORT_H_PIN_COUNT )
+#if defined( _GPIO_PORT_J_PIN_COUNT )
+#define GPIO_PORT_MAX  9
+#elif defined( _GPIO_PORT_I_PIN_COUNT )
+#define GPIO_PORT_MAX  8
+#elif defined( _GPIO_PORT_H_PIN_COUNT )
 #define GPIO_PORT_MAX  7
+#elif defined( _GPIO_PORT_G_PIN_COUNT )
+#define GPIO_PORT_MAX  6
+#elif defined( _GPIO_PORT_F_PIN_COUNT )
+#define GPIO_PORT_MAX  5
 #else
-#define GPIO_PORT_MAX  5
+#error "Max GPIO port number is undefined for this part."
 #endif
+
+/** Highest EXT GPIO interrupt number */
+#define GPIO_EXTINTNO_MAX   15
+
 /** @endcond */
 
 /*******************************************************************************
@@ -288,7 +307,8 @@
   /** GPIO strong 10mA and alternate function strong 10mA */
   gpioDriveStrengthStrongAlternateStrong = GPIO_P_CTRL_DRIVESTRENGTH_STRONG | GPIO_P_CTRL_DRIVESTRENGTHALT_STRONG,
 } GPIO_DriveStrength_TypeDef;
-/* For legacy support */
+
+/* Deprecated enums */
 #define gpioDriveStrengthStrong   gpioDriveStrengthStrongAlternateStrong
 #define gpioDriveStrengthWeak     gpioDriveStrengthWeakAlternateWeak
 #endif
@@ -355,21 +375,6 @@
 
 void GPIO_DbgLocationSet(unsigned int location);
 
-void GPIO_IntConfig(GPIO_Port_TypeDef port,
-                    unsigned int pin,
-                    bool risingEdge,
-                    bool fallingEdge,
-                    bool enable);
-
-void GPIO_PinModeSet(GPIO_Port_TypeDef port,
-                     unsigned int pin,
-                     GPIO_Mode_TypeDef mode,
-                     unsigned int out);
-
-# if defined( _GPIO_EM4WUEN_MASK )
-void GPIO_EM4EnablePinWakeup(uint32_t pinmask, uint32_t polaritymask);
-#endif
-
 /***************************************************************************//**
  * @brief
  *   Enable/disable serial wire clock pin.
@@ -393,7 +398,6 @@
 #endif
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Enable/disable serial wire data I/O pin.
@@ -417,7 +421,6 @@
 #endif
 }
 
-
 #if defined( _GPIO_ROUTE_SWOPEN_MASK ) || defined( _GPIO_ROUTEPEN_SWVPEN_MASK )
 /***************************************************************************//**
  * @brief
@@ -469,8 +472,11 @@
 }
 #endif
 
+# if defined( _GPIO_EM4WUEN_MASK )
+void GPIO_EM4EnablePinWakeup(uint32_t pinmask, uint32_t polaritymask);
+#endif
 
-#if defined( _GPIO_EM4WUCAUSE_MASK ) || defined( _RMU_RSTCAUSE_EM4RST_MASK )
+#if defined( _GPIO_EM4WUCAUSE_MASK ) || defined( _GPIO_IF_EM4WU_MASK )
 /**************************************************************************//**
  * @brief
  *   Check which GPIO pin(s) that caused a wake-up from EM4.
@@ -484,20 +490,19 @@
 #if defined( _GPIO_EM4WUCAUSE_MASK )
   return GPIO->EM4WUCAUSE & _GPIO_EM4WUCAUSE_MASK;
 #else
-  return RMU->RSTCAUSE & _RMU_RSTCAUSE_EM4RST_MASK;
+  return GPIO->IF & _GPIO_IF_EM4WU_MASK;
 #endif
 }
 #endif
 
-
 #if defined( GPIO_CTRL_EM4RET ) || defined( _EMU_EM4CTRL_EM4IORETMODE_MASK )
 /**************************************************************************//**
  * @brief
  *   Enable GPIO pin retention of output enable, output value, pull enable and
  *   pull direction in EM4.
- * 
+ *
  * @note
- *   For platform 2 parts, EMU_EM4Init() and EMU_UnlatchPinRetention() offers 
+ *   For platform 2 parts, EMU_EM4Init() and EMU_UnlatchPinRetention() offers
  *   more pin retention features. This function implements the EM4EXIT retention
  *   mode on platform 2.
  *
@@ -528,6 +533,12 @@
 }
 #endif
 
+void GPIO_ExtIntConfig(GPIO_Port_TypeDef port,
+                       unsigned int pin,
+                       unsigned int intNo,
+                       bool risingEdge,
+                       bool fallingEdge,
+                       bool enable);
 
 /***************************************************************************//**
  * @brief
@@ -550,7 +561,6 @@
   GPIO->INSENSE = (GPIO->INSENSE & ~mask) | (val & mask);
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Clear one or more pending GPIO interrupts.
@@ -563,7 +573,6 @@
   GPIO->IFC = flags;
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Disable one or more GPIO interrupts.
@@ -576,7 +585,6 @@
   GPIO->IEN &= ~flags;
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Enable one or more GPIO interrupts.
@@ -594,7 +602,6 @@
   GPIO->IEN |= flags;
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Get pending GPIO interrupts.
@@ -607,7 +614,6 @@
   return GPIO->IF;
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Get enabled and pending GPIO interrupt flags.
@@ -635,7 +641,6 @@
   return GPIO->IF & tmp;
 }
 
-
 /**************************************************************************//**
  * @brief
  *   Set one or more pending GPIO interrupts from SW.
@@ -648,7 +653,6 @@
   GPIO->IFS = flags;
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Locks the GPIO configuration.
@@ -658,7 +662,6 @@
   GPIO->LOCK = GPIO_LOCK_LOCKKEY_LOCK;
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Read the pad value for a single pin in a GPIO port.
@@ -679,6 +682,13 @@
   return BUS_RegBitRead(&GPIO->P[port].DIN, pin);
 }
 
+GPIO_Mode_TypeDef GPIO_PinModeGet(GPIO_Port_TypeDef port,
+                                  unsigned int pin);
+
+void GPIO_PinModeSet(GPIO_Port_TypeDef port,
+                     unsigned int pin,
+                     GPIO_Mode_TypeDef mode,
+                     unsigned int out);
 
 /***************************************************************************//**
  * @brief
@@ -705,7 +715,6 @@
 #endif
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Get current setting for a pin in a GPIO port data out register.
@@ -726,7 +735,6 @@
   return BUS_RegBitRead(&GPIO->P[port].DOUT, pin);
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Set a single pin in GPIO data out register to 1.
@@ -752,7 +760,6 @@
 #endif
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Toggle a single pin in GPIO port data out register.
@@ -775,7 +782,6 @@
   GPIO->P[port].DOUTTGL = 1 << pin;
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Read the pad values for GPIO port.
@@ -790,7 +796,6 @@
   return GPIO->P[port].DIN;
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Set bits in DOUT register for a port to 0.
@@ -816,7 +821,6 @@
 #endif
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Get current setting for a GPIO port data out register.
@@ -834,7 +838,6 @@
   return GPIO->P[port].DOUT;
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Set bits GPIO data out register to 1.
@@ -860,7 +863,6 @@
 #endif
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Set GPIO port data out register.
@@ -888,7 +890,6 @@
   GPIO->P[port].DOUT = (GPIO->P[port].DOUT & ~mask) | (val & mask);
 }
 
-
 /***************************************************************************//**
  * @brief
  *   Toggle pins in GPIO port data out register.
@@ -911,6 +912,37 @@
   GPIO->P[port].DOUTTGL = pins;
 }
 
+#if defined(_GPIO_P_CTRL_SLEWRATE_MASK)
+/***************************************************************************//**
+ * @brief
+ *   Set slewrate for pins on a GPIO port.
+ *
+ * @param[in] port
+ *   The GPIO port to configure.
+ *
+ * @param[in] slewrate
+ *   The slewrate to configure for pins on this GPIO port.
+ *
+ * @param[in] slewrateAlt
+ *   The slewrate to configure for pins using alternate modes on this GPIO port.
+ ******************************************************************************/
+__STATIC_INLINE void GPIO_SlewrateSet(GPIO_Port_TypeDef port,
+                                      uint32_t slewrate,
+                                      uint32_t slewrateAlt)
+{
+  EFM_ASSERT(GPIO_PORT_VALID(port));
+  EFM_ASSERT(slewrate <= (_GPIO_P_CTRL_SLEWRATE_MASK
+                          >> _GPIO_P_CTRL_SLEWRATE_SHIFT));
+  EFM_ASSERT(slewrateAlt <= (_GPIO_P_CTRL_SLEWRATEALT_MASK
+                             >> _GPIO_P_CTRL_SLEWRATEALT_SHIFT));
+
+  GPIO->P[port].CTRL = (GPIO->P[port].CTRL
+                        & ~(_GPIO_P_CTRL_SLEWRATE_MASK
+                            | _GPIO_P_CTRL_SLEWRATEALT_MASK))
+                       | (slewrate << _GPIO_P_CTRL_SLEWRATE_SHIFT)
+                       | (slewrateAlt << _GPIO_P_CTRL_SLEWRATEALT_SHIFT);
+}
+#endif
 
 /***************************************************************************//**
  * @brief
@@ -921,12 +953,66 @@
   GPIO->LOCK = GPIO_LOCK_LOCKKEY_UNLOCK;
 }
 
+/*******************************************************************************
+ ***********************   DEPRECATED PROTOTYPES   *****************************
+ ***********************     (will be removed)     *****************************
+ ******************************************************************************/
+
+/***************************************************************************//**
+ * @brief
+ *   Configure GPIO interrupt.
+ *
+ * @details
+ *   If reconfiguring a GPIO interrupt that is already enabled, it is generally
+ *   recommended to disable it first, see GPIO_Disable().
+ *
+ *   The actual GPIO interrupt handler must be in place before enabling the
+ *   interrupt.
+ *
+ *   Notice that any pending interrupt for the selected pin is cleared by this
+ *   function.
+ *
+ * @deprecated
+ *   Deprecated function. New code should use @ref GPIO_ExtIntConfig().
+ *
+ * @note
+ *   A certain pin number can only be associated with one port. Ie, if GPIO
+ *   interrupt 1 is assigned to port A/pin 1, then it is not possible to use
+ *   pin 1 from any other ports for interrupts. Please refer to the reference
+ *   manual. On devices which implement GPIO_EXTIPINSEL registers a more
+ *   flexible approach is possible, refer to @ref GPIO_ExtIntConfig().
+ *
+ * @param[in] port
+ *   The port to associate with @p pin.
+ *
+ * @param[in] pin
+ *   The pin number on the port ( == GPIO EXTI interrupt number).
+ *
+ * @param[in] risingEdge
+ *   Set to true if interrupts shall be enabled on rising edge, otherwise false.
+ *
+ * @param[in] fallingEdge
+ *   Set to true if interrupts shall be enabled on falling edge, otherwise false.
+ *
+ * @param[in] enable
+ *   Set to true if interrupt shall be enabled after configuration completed,
+ *   false to leave disabled. See GPIO_IntDisable() and GPIO_IntEnable().
+ ******************************************************************************/
+__STATIC_INLINE void GPIO_IntConfig(GPIO_Port_TypeDef port,
+                                    unsigned int pin,
+                                    bool risingEdge,
+                                    bool fallingEdge,
+                                    bool enable)
+{
+  GPIO_ExtIntConfig(port, pin, pin, risingEdge, fallingEdge, enable);
+}
+
 /** @} (end addtogroup GPIO) */
-/** @} (end addtogroup EM_Library) */
+/** @} (end addtogroup emlib) */
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* defined(GPIO_COUNT) && (GPIO_COUNT > 0) */
-#endif /* __SILICON_LABS_EM_GPIO_H__ */
+#endif /* EM_GPIO_H */