GPIO - General Purpose Input/Output

Description

General Purpose Input/Output (GPIO) API.

This module contains functions to control the GPIO peripheral of Silicon Labs 32-bit MCUs and SoCs. The GPIO peripheral is used for pin configuration and direct pin manipulation and sensing as well as routing for peripheral pin connections.

Functions

void GPIO_DbgLocationSet (unsigned int location)
 Sets the pin location of the debug pins (Serial Wire interface).
 
void GPIO_DriveStrengthSet (GPIO_Port_TypeDef port, GPIO_DriveStrength_TypeDef strength)
 Sets the drive strength for a GPIO port.
 
void GPIO_ExtIntConfig (GPIO_Port_TypeDef port, unsigned int pin, unsigned int intNo, bool risingEdge, bool fallingEdge, bool enable)
 Configure the GPIO external pin interrupt.
 
void GPIO_EM4WUExtIntConfig (GPIO_Port_TypeDef port, unsigned int pin, uint32_t intNo, bool polarity, bool enable)
 Configure EM4WU pins as external level-sensitive interrupts.
 
void GPIO_PinModeSet (GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
 Set the mode for a GPIO pin.
 
GPIO_Mode_TypeDef GPIO_PinModeGet (GPIO_Port_TypeDef port, unsigned int pin)
 Get the mode for a GPIO pin.
 
void GPIO_EM4EnablePinWakeup (uint32_t pinmask, uint32_t polaritymask)
 Enable GPIO pin wake-up from EM4.
 
void GPIO_DbgSWDClkEnable (bool enable)
 Enable/disable serial wire clock pin.
 
void GPIO_DbgSWDIOEnable (bool enable)
 Enable/disable serial wire data I/O pin.
 
void GPIO_DbgSWOEnable (bool enable)
 Enable/Disable serial wire output pin.
 
void GPIO_EM4DisablePinWakeup (uint32_t pinmask)
 Disable GPIO pin wake-up from EM4.
 
uint32_t GPIO_EM4GetPinWakeupCause (void)
 Check which GPIO pin(s) that caused a wake-up from EM4.
 
void GPIO_EM4SetPinRetention (bool enable)
 Enable GPIO pin retention of output enable, output value, pull enable, and pull direction in EM4.
 
void GPIO_InputSenseSet (uint32_t val, uint32_t mask)
 Enable/disable input sensing.
 
void GPIO_IntClear (uint32_t flags)
 Clear one or more pending GPIO interrupts.
 
void GPIO_IntDisable (uint32_t flags)
 Disable one or more GPIO interrupts.
 
void GPIO_IntEnable (uint32_t flags)
 Enable one or more GPIO interrupts.
 
uint32_t GPIO_EnabledIntGet (void)
 Get enabled GPIO interrupts.
 
uint32_t GPIO_IntGet (void)
 Get pending GPIO interrupts.
 
uint32_t GPIO_IntGetEnabled (void)
 Get enabled and pending GPIO interrupt flags.
 
void GPIO_IntSet (uint32_t flags)
 Set one or more pending GPIO interrupts from SW.
 
void GPIO_Lock (void)
 Lock the GPIO configuration.
 
unsigned int GPIO_PinInGet (GPIO_Port_TypeDef port, unsigned int pin)
 Read the pad value for a single pin in a GPIO port.
 
void GPIO_PinLock (GPIO_Port_TypeDef port, unsigned int pin)
 Lock all GPIO configuration settings for a given pin.
 
void GPIO_PinOutClear (GPIO_Port_TypeDef port, unsigned int pin)
 Set a single pin in GPIO data out port register to 0.
 
unsigned int GPIO_PinOutGet (GPIO_Port_TypeDef port, unsigned int pin)
 Get current setting for a pin in a GPIO port data out register.
 
void GPIO_PinOutSet (GPIO_Port_TypeDef port, unsigned int pin)
 Set a single pin in GPIO data out register to 1.
 
void GPIO_PinOutToggle (GPIO_Port_TypeDef port, unsigned int pin)
 Toggle a single pin in GPIO port data out register.
 
uint32_t GPIO_PortInGet (GPIO_Port_TypeDef port)
 Read the pad values for GPIO port.
 
void GPIO_PortOutClear (GPIO_Port_TypeDef port, uint32_t pins)
 Set bits in DOUT register for a port to 0.
 
uint32_t GPIO_PortOutGet (GPIO_Port_TypeDef port)
 Get the current setting for a GPIO port data out register.
 
void GPIO_PortOutSet (GPIO_Port_TypeDef port, uint32_t pins)
 Set bits GPIO data out register to 1.
 
void GPIO_PortOutSetVal (GPIO_Port_TypeDef port, uint32_t val, uint32_t mask)
 Set GPIO port data out register.
 
void GPIO_PortOutToggle (GPIO_Port_TypeDef port, uint32_t pins)
 Toggle pins in GPIO port data out register.
 
void GPIO_SlewrateSet (GPIO_Port_TypeDef port, uint32_t slewrate, uint32_t slewrateAlt)
 Set slewrate for pins on a GPIO port.
 
void GPIO_Unlock (void)
 Unlock the GPIO configuration.
 
SL_DEPRECATED_API_SDK_4_1 void GPIO_IntConfig (GPIO_Port_TypeDef port, unsigned int pin, bool risingEdge, bool fallingEdge, bool enable)
 Configure GPIO interrupt.
 

Enumerations

enum  GPIO_Port_TypeDef {
  gpioPortA = 0,
  gpioPortB = 1,
  gpioPortC = 2,
  gpioPortD = 3,
  gpioPortE = 4,
  gpioPortF = 5
}
 GPIO ports IDs.
 
enum  GPIO_DriveStrength_TypeDef {
  gpioDriveStrengthWeakAlternateWeak = GPIO_P_CTRL_DRIVESTRENGTH_WEAK | GPIO_P_CTRL_DRIVESTRENGTHALT_WEAK,
  gpioDriveStrengthWeakAlternateStrong = GPIO_P_CTRL_DRIVESTRENGTH_WEAK | GPIO_P_CTRL_DRIVESTRENGTHALT_STRONG,
  gpioDriveStrengthStrongAlternateWeak = GPIO_P_CTRL_DRIVESTRENGTH_STRONG | GPIO_P_CTRL_DRIVESTRENGTHALT_WEAK,
  gpioDriveStrengthStrongAlternateStrong = GPIO_P_CTRL_DRIVESTRENGTH_STRONG | GPIO_P_CTRL_DRIVESTRENGTHALT_STRONG
}
 GPIO drive strength.
 
enum  GPIO_Mode_TypeDef {
  gpioModeDisabled = _GPIO_P_MODEL_MODE0_DISABLED,
  gpioModeInput = _GPIO_P_MODEL_MODE0_INPUT,
  gpioModeInputPull = _GPIO_P_MODEL_MODE0_INPUTPULL,
  gpioModeInputPullFilter = _GPIO_P_MODEL_MODE0_INPUTPULLFILTER,
  gpioModePushPull = _GPIO_P_MODEL_MODE0_PUSHPULL,
  gpioModePushPullAlternate = _GPIO_P_MODEL_MODE0_PUSHPULLALT,
  gpioModeWiredOr = _GPIO_P_MODEL_MODE0_WIREDOR,
  gpioModeWiredOrPullDown = _GPIO_P_MODEL_MODE0_WIREDORPULLDOWN,
  gpioModeWiredAnd = _GPIO_P_MODEL_MODE0_WIREDAND,
  gpioModeWiredAndFilter = _GPIO_P_MODEL_MODE0_WIREDANDFILTER,
  gpioModeWiredAndPullUp = _GPIO_P_MODEL_MODE0_WIREDANDPULLUP,
  gpioModeWiredAndPullUpFilter = _GPIO_P_MODEL_MODE0_WIREDANDPULLUPFILTER,
  gpioModeWiredAndAlternate = _GPIO_P_MODEL_MODE0_WIREDANDALT,
  gpioModeWiredAndAlternateFilter = _GPIO_P_MODEL_MODE0_WIREDANDALTFILTER,
  gpioModeWiredAndAlternatePullUp = _GPIO_P_MODEL_MODE0_WIREDANDALTPULLUP,
  gpioModeWiredAndAlternatePullUpFilter = _GPIO_P_MODEL_MODE0_WIREDANDALTPULLUPFILTER
}
 Pin mode.
 

Function Documentation

◆ GPIO_DbgLocationSet()

void GPIO_DbgLocationSet ( unsigned int  location)

Sets the pin location of the debug pins (Serial Wire interface).

Note
Changing the pins used for debugging uncontrolled, may result in a lockout.
Parameters
[in]locationThe debug pin location to use (0-3).

◆ GPIO_DriveStrengthSet()

void GPIO_DriveStrengthSet ( GPIO_Port_TypeDef  port,
GPIO_DriveStrength_TypeDef  strength 
)

Sets the drive strength for a GPIO port.

Parameters
[in]portThe GPIO port to access.
[in]strengthThe drive strength to use for the port.

◆ GPIO_ExtIntConfig()

void GPIO_ExtIntConfig ( GPIO_Port_TypeDef  port,
unsigned int  pin,
unsigned int  intNo,
bool  risingEdge,
bool  fallingEdge,
bool  enable 
)

Configure the GPIO external pin interrupt.

It is recommended to disable interrupts before configuring the GPIO pin interrupt. See GPIO_IntDisable() for more information.

The GPIO interrupt handler must be in place before enabling the interrupt.

Notice that any pending interrupt for the selected interrupt is cleared by this function.

Note
On series 0 devices, the pin number parameter is not used. The pin number used on these devices is hardwired to the interrupt with the same number.
On series 1 devices, the pin number can be selected freely within a group. Interrupt numbers are divided into 4 groups (intNo / 4) and valid pin number within the interrupt groups are: 0: pins 0-3 (interrupt number 0-3) 1: pins 4-7 (interrupt number 4-7) 2: pins 8-11 (interrupt number 8-11) 3: pins 12-15 (interrupt number 12-15)
Parameters
[in]portThe port to associate with the pin.
[in]pinThe pin number on the port.
[in]intNoThe interrupt number to trigger.
[in]risingEdgeSet to true if the interrupt will be enabled on the rising edge. Otherwise, false.
[in]fallingEdgeSet to true if the interrupt will be enabled on the falling edge. Otherwise, false.
[in]enableSet to true if the interrupt will be enabled after the configuration is complete. False to leave disabled. See GPIO_IntDisable() and GPIO_IntEnable().

◆ GPIO_EM4WUExtIntConfig()

void GPIO_EM4WUExtIntConfig ( GPIO_Port_TypeDef  port,
unsigned int  pin,
uint32_t  intNo,
bool  polarity,
bool  enable 
)

Configure EM4WU pins as external level-sensitive interrupts.

It is recommended to disable interrupts before configuring the GPIO pin interrupt. See GPIO_IntDisable() for more information.

The GPIO interrupt handler must be in place before enabling the interrupt.

Notice that any pending interrupt for the selected interrupt is cleared by this function.

Note
The selected port/pin must be mapped to an existant EM4WU interrupt. Each EM4WU signal is connected to a fixed pin. Refer to the Alternate Function Table in the device Datasheet for the location of each EM4WU signal. For example, on xG22 device, the interrupt of EM4WU6 is fixed to pin PC00.
Parameters
[in]portThe port to associate with the pin.
[in]pinThe pin number on the port.
[in]intNoThe EM4WU interrupt number to trigger.
[in]polaritytrue = Active high level-sensitive interrupt. false = Active low level-sensitive interrupt.
[in]enableSet to true if the interrupt will be enabled after the configuration is complete. False to leave disabled. See GPIO_IntDisable() and GPIO_IntEnable().

◆ GPIO_PinModeSet()

void GPIO_PinModeSet ( GPIO_Port_TypeDef  port,
unsigned int  pin,
GPIO_Mode_TypeDef  mode,
unsigned int  out 
)

Set the mode for a GPIO pin.

Parameters
[in]portThe GPIO port to access.
[in]pinThe pin number in the port.
[in]modeThe desired pin mode.
[in]outA value to set for the pin in the DOUT register. The DOUT setting is important for some input mode configurations to determine the pull-up/down direction.

◆ GPIO_PinModeGet()

GPIO_Mode_TypeDef GPIO_PinModeGet ( GPIO_Port_TypeDef  port,
unsigned int  pin 
)

Get the mode for a GPIO pin.

Parameters
[in]portThe GPIO port to access.
[in]pinThe pin number in the port.
Returns
The pin mode.

◆ GPIO_EM4EnablePinWakeup()

void GPIO_EM4EnablePinWakeup ( uint32_t  pinmask,
uint32_t  polaritymask 
)

Enable GPIO pin wake-up from EM4.

When the function exits, EM4 mode can be safely entered.

Note
It is assumed that the GPIO pin modes are set correctly. Valid modes are gpioModeInput and gpioModeInputPull.
Parameters
[in]pinmaskA bitmask containing the bitwise logic OR of which GPIO pin(s) to enable. See Reference Manuals for a pinmask to the GPIO port/pin mapping.
[in]polaritymaskA bitmask containing the bitwise logic OR of GPIO pin(s) wake-up polarity. See Reference Manuals for pinmask-to-GPIO port/pin mapping.

◆ GPIO_DbgSWDClkEnable()

void GPIO_DbgSWDClkEnable ( bool  enable)
inline

Enable/disable serial wire clock pin.

Note
Disabling SWDClk will disable the debug interface, which may result in a lockout if done early in startup (before debugger is able to halt core).
Parameters
[in]enable
  • false - disable serial wire clock.
  • true - enable serial wire clock (default after reset).

◆ GPIO_DbgSWDIOEnable()

void GPIO_DbgSWDIOEnable ( bool  enable)
inline

Enable/disable serial wire data I/O pin.

Note
Disabling SWDClk will disable the debug interface, which may result in a lockout if done early in startup (before debugger is able to halt core).
Parameters
[in]enable
  • false - disable serial wire data pin.
  • true - enable serial wire data pin (default after reset).

◆ GPIO_DbgSWOEnable()

void GPIO_DbgSWOEnable ( bool  enable)
inline

Enable/Disable serial wire output pin.

Note
Enabling this pin is not sufficient to fully enable serial wire output, which is also dependent on issues outside the GPIO module. Refer to DBG_SWOEnable().
Warning
If debug port is locked, SWO pin is not disabled automatically. To avoid information leakage through SWO, disable SWO pin after locking debug port.
Parameters
[in]enable
  • false - disable serial wire viewer pin (default after reset).
  • true - enable serial wire viewer pin.

◆ GPIO_EM4DisablePinWakeup()

void GPIO_EM4DisablePinWakeup ( uint32_t  pinmask)
inline

Disable GPIO pin wake-up from EM4.

Parameters
[in]pinmaskBit mask containing the bitwise logic OR of which GPIO pin(s) to disable. Refer to Reference Manuals for pinmask to GPIO port/pin mapping.

◆ GPIO_EM4GetPinWakeupCause()

uint32_t GPIO_EM4GetPinWakeupCause ( void  )
inline

Check which GPIO pin(s) that caused a wake-up from EM4.

Returns
Bit mask containing the bitwise logic OR of which GPIO pin(s) caused the wake-up. Refer to Reference Manuals for pinmask to GPIO port/pin mapping.

◆ GPIO_EM4SetPinRetention()

void GPIO_EM4SetPinRetention ( bool  enable)
inline

Enable GPIO pin retention of output enable, output value, pull enable, and pull direction in EM4.

Note
On series 0 devices EM4 gpio retention can either be turned on or off. On series 1 devices there are three EM4 GPIO retention modes available. These modes are "Disabled", "EM4EXIT" and "SWUNLATCH". Use the EMU_EM4Init() to configure the GPIO retention mode on a series 1 device.

The behavior of this function depends on the configured GPIO retention mode. If the GPIO retention mode is configured to be "SWUNLATCH" then this function will not change anything. If the retention mode is anything else then this function will set the GPIO retention mode to "EM4EXIT" when the enable argument is true, and "Disabled" when false.

Parameters
[in]enable
  • true - enable EM4 pin retention.
  • false - disable EM4 pin retention.

◆ GPIO_InputSenseSet()

void GPIO_InputSenseSet ( uint32_t  val,
uint32_t  mask 
)
inline

Enable/disable input sensing.

Disabling input sensing if not used, can save some energy consumption.

Parameters
[in]valBitwise logic OR of one or more of:
  • GPIO_INSENSE_INT - interrupt input sensing.
  • GPIO_INSENSE_PRS - peripheral reflex system input sensing.
[in]maskMask containing bitwise logic OR of bits similar as for val used to indicate which input sense options to disable/enable.

◆ GPIO_IntClear()

void GPIO_IntClear ( uint32_t  flags)
inline

Clear one or more pending GPIO interrupts.

Parameters
[in]flagsBitwise logic OR of GPIO interrupt sources to clear.

◆ GPIO_IntDisable()

void GPIO_IntDisable ( uint32_t  flags)
inline

Disable one or more GPIO interrupts.

Parameters
[in]flagsGPIO interrupt sources to disable.

◆ GPIO_IntEnable()

void GPIO_IntEnable ( uint32_t  flags)
inline

Enable one or more GPIO interrupts.

Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using GPIO_IntClear() prior to enabling the interrupt.
Parameters
[in]flagsGPIO interrupt sources to enable.

◆ GPIO_EnabledIntGet()

uint32_t GPIO_EnabledIntGet ( void  )
inline

Get enabled GPIO interrupts.

Returns
Enabled GPIO interrupt sources.

◆ GPIO_IntGet()

uint32_t GPIO_IntGet ( void  )
inline

Get pending GPIO interrupts.

Returns
GPIO interrupt sources pending.

◆ GPIO_IntGetEnabled()

uint32_t GPIO_IntGetEnabled ( void  )
inline

Get enabled and pending GPIO interrupt flags.

Useful for handling more interrupt sources in the same interrupt handler.

Note
Interrupt flags are not cleared by the use of this function.
Returns
Pending and enabled GPIO interrupt sources. The return value is the bitwise AND combination of
  • the OR combination of enabled interrupt sources in GPIO_IEN register and
  • the OR combination of valid interrupt flags in GPIO_IF register.

◆ GPIO_IntSet()

void GPIO_IntSet ( uint32_t  flags)
inline

Set one or more pending GPIO interrupts from SW.

Parameters
[in]flagsGPIO interrupt sources to set to pending.

◆ GPIO_Lock()

void GPIO_Lock ( void  )
inline

Lock the GPIO configuration.

◆ GPIO_PinInGet()

unsigned int GPIO_PinInGet ( GPIO_Port_TypeDef  port,
unsigned int  pin 
)
inline

Read the pad value for a single pin in a GPIO port.

Parameters
[in]portThe GPIO port to access.
[in]pinThe pin number to read.
Returns
The pin value, 0 or 1.

◆ GPIO_PinLock()

void GPIO_PinLock ( GPIO_Port_TypeDef  port,
unsigned int  pin 
)
inline

Lock all GPIO configuration settings for a given pin.

The lock can only be cleared by a chip reset.

Parameters
[in]portThe GPIO port to access.
[in]pinThe pin number to lock.

◆ GPIO_PinOutClear()

void GPIO_PinOutClear ( GPIO_Port_TypeDef  port,
unsigned int  pin 
)
inline

Set a single pin in GPIO data out port register to 0.

Note
To ensure that the setting takes effect on the output pad, the pin must be configured properly. If not, it will take effect whenever the pin has been properly configured.
Parameters
[in]portThe GPIO port to access.
[in]pinThe pin to set.

◆ GPIO_PinOutGet()

unsigned int GPIO_PinOutGet ( GPIO_Port_TypeDef  port,
unsigned int  pin 
)
inline

Get current setting for a pin in a GPIO port data out register.

Parameters