GPIO - General Purpose Input/Output#
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.
Enumerations#
Pin mode.
Functions#
Sets the pin location of the debug pins (Serial Wire interface).
Enable/disable serial wire clock pin.
Enable/disable serial wire data I/O pin.
Enable/Disable serial wire output pin.
Disable GPIO pin wake-up from EM4.
Enable GPIO pin wake-up from EM4.
Check which GPIO pin(s) that caused a wake-up from EM4.
Enable GPIO pin retention of output enable, output value, pull enable, and pull direction in EM4.
Configure the GPIO external pin interrupt.
Configure EM4WU pins as external level-sensitive interrupts.
Enable/disable input sensing.
Clear one or more pending GPIO interrupts.
Disable one or more GPIO interrupts.
Enable one or more GPIO interrupts.
Get enabled GPIO interrupts.
Get pending GPIO interrupts.
Get enabled and pending GPIO interrupt flags.
Set one or more pending GPIO interrupts from SW.
Lock the GPIO configuration.
Read the pad value for a single pin in a GPIO port.
Get the mode for a GPIO pin.
Set the mode for a GPIO pin.
Set a single pin in GPIO data out port register to 0.
Get current setting for a pin in a GPIO port data out register.
Set a single pin in GPIO data out register to 1.
Toggle a single pin in GPIO port data out register.
Read the pad values for GPIO port.
Set bits in DOUT register for a port to 0.
Get the current setting for a GPIO port data out register.
Set bits GPIO data out register to 1.
Set GPIO port data out register.
Toggle pins in GPIO port data out register.
Set slewrate for pins on a GPIO port.
Unlock the GPIO configuration.
Macros#
Mapping between SL_GPIO_PORT_ enums and gpioPort values.
Enumeration Documentation#
GPIO_Port_TypeDef#
GPIO_Port_TypeDef
GPIO ports IDs.
Enumerator | |
---|---|
gpioPortA | Port A. |
gpioPortB | Port B. |
gpioPortC | Port C. |
gpioPortD | Port D. |
518
of file platform/emlib/inc/em_gpio.h
GPIO_Mode_TypeDef#
GPIO_Mode_TypeDef
Pin mode.
For more details on each mode, refer to the reference manual.
Enumerator | |
---|---|
gpioModeDisabled | Input disabled. |
gpioModeInput | Input enabled. |
gpioModeInputPull | Input enabled. |
gpioModeInputPullFilter | Input enabled with filter. |
gpioModePushPull | Push-pull output. |
gpioModePushPullAlternate | Push-pull using alternate control. |
gpioModeWiredOr | Wired-or output. |
gpioModeWiredOrPullDown | Wired-or output with pull-down. |
gpioModeWiredAnd | Open-drain output. |
gpioModeWiredAndFilter | Open-drain output with filter. |
gpioModeWiredAndPullUp | Open-drain output with pull-up. |
gpioModeWiredAndPullUpFilter | Open-drain output with filter and pull-up. |
gpioModeWiredAndAlternate | Open-drain output using alternate control. |
gpioModeWiredAndAlternateFilter | Open-drain output using alternate control with filter. |
gpioModeWiredAndAlternatePullUp | Open-drain output using alternate control with pull-up. |
gpioModeWiredAndAlternatePullUpFilter | Open-drain output using alternate control with filter and pull-up. |
641
of file platform/emlib/inc/em_gpio.h
Function Documentation#
GPIO_DbgLocationSet#
void GPIO_DbgLocationSet (unsigned int location)
Sets the pin location of the debug pins (Serial Wire interface).
[in] | location | The debug pin location to use (0-3). |
Note
Changing the pins used for debugging uncontrolled, may result in a lockout.
74
of file platform/emlib/src/em_gpio.c
GPIO_DbgSWDClkEnable#
void GPIO_DbgSWDClkEnable (bool enable)
Enable/disable serial wire clock pin.
[in] | enable |
|
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).
712
of file platform/emlib/inc/em_gpio.h
GPIO_DbgSWDIOEnable#
void GPIO_DbgSWDIOEnable (bool enable)
Enable/disable serial wire data I/O pin.
[in] | enable |
|
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).
739
of file platform/emlib/inc/em_gpio.h
GPIO_DbgSWOEnable#
void GPIO_DbgSWOEnable (bool enable)
Enable/Disable serial wire output pin.
[in] | enable |
|
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().
Warnings
If debug port is locked, SWO pin is not disabled automatically. To avoid information leakage through SWO, disable SWO pin after locking debug port.
773
of file platform/emlib/inc/em_gpio.h
GPIO_EM4DisablePinWakeup#
void GPIO_EM4DisablePinWakeup (uint32_t pinmask)
Disable GPIO pin wake-up from EM4.
[in] | pinmask | Bit mask containing the bitwise logic OR of which GPIO pin(s) to disable. Refer to Reference Manuals for pinmask to GPIO port/pin mapping. |
806
of file platform/emlib/inc/em_gpio.h
GPIO_EM4EnablePinWakeup#
void GPIO_EM4EnablePinWakeup (uint32_t pinmask, uint32_t polaritymask)
Enable GPIO pin wake-up from EM4.
[in] | pinmask | A 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] | polaritymask | A bitmask containing the bitwise logic OR of GPIO pin(s) wake-up polarity. See Reference Manuals for pinmask-to-GPIO port/pin mapping. |
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.
425
of file platform/emlib/src/em_gpio.c
GPIO_EM4GetPinWakeupCause#
uint32_t GPIO_EM4GetPinWakeupCause (void )
Check which GPIO pin(s) that caused a wake-up from EM4.
N/A |
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.
827
of file platform/emlib/inc/em_gpio.h
GPIO_EM4SetPinRetention#
void GPIO_EM4SetPinRetention (bool enable)
Enable GPIO pin retention of output enable, output value, pull enable, and pull direction in EM4.
[in] | enable |
|
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.
859
of file platform/emlib/inc/em_gpio.h
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.
[in] | port | The port to associate with the |
[in] | pin | The pin number on the port. |
[in] | intNo | The interrupt number to trigger. |
[in] | risingEdge | Set to true if the interrupt will be enabled on the rising edge. Otherwise, false. |
[in] | fallingEdge | Set to true if the interrupt will be enabled on the falling edge. Otherwise, false. |
[in] | enable | Set to true if the interrupt will be enabled after the configuration is complete. False to leave disabled. See GPIO_IntDisable() and GPIO_IntEnable(). |
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)
177
of file platform/emlib/src/em_gpio.c
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.
[in] | port | The port to associate with the |
[in] | pin | The pin number on the port. |
[in] | intNo | The EM4WU interrupt number to trigger. |
[in] | polarity | true = Active high level-sensitive interrupt. false = Active low level-sensitive interrupt. |
[in] | enable | Set to true if the interrupt will be enabled after the configuration is complete. False to leave disabled. See GPIO_IntDisable() and GPIO_IntEnable(). |
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.
302
of file platform/emlib/src/em_gpio.c
GPIO_InputSenseSet#
void GPIO_InputSenseSet (uint32_t val, uint32_t mask)
Enable/disable input sensing.
[in] | val | Bitwise logic OR of one or more of:
|
[in] | mask | Mask containing bitwise logic OR of bits similar as for |
Disabling input sensing if not used, can save some energy consumption.
912
of file platform/emlib/inc/em_gpio.h
GPIO_IntClear#
void GPIO_IntClear (uint32_t flags)
Clear one or more pending GPIO interrupts.
[in] | flags | Bitwise logic OR of GPIO interrupt sources to clear. |
929
of file platform/emlib/inc/em_gpio.h
GPIO_IntDisable#
void GPIO_IntDisable (uint32_t flags)
Disable one or more GPIO interrupts.
[in] | flags | GPIO interrupt sources to disable. |
945
of file platform/emlib/inc/em_gpio.h
GPIO_IntEnable#
void GPIO_IntEnable (uint32_t flags)
Enable one or more GPIO interrupts.
[in] | flags | GPIO interrupt sources to enable. |
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.
962
of file platform/emlib/inc/em_gpio.h
GPIO_EnabledIntGet#
uint32_t GPIO_EnabledIntGet (void )
Get enabled GPIO interrupts.
N/A |
Returns
Enabled GPIO interrupt sources.
975
of file platform/emlib/inc/em_gpio.h
GPIO_IntGet#
uint32_t GPIO_IntGet (void )
Get pending GPIO interrupts.
N/A |
Returns
GPIO interrupt sources pending.
987
of file platform/emlib/inc/em_gpio.h
GPIO_IntGetEnabled#
uint32_t GPIO_IntGetEnabled (void )
Get enabled and pending GPIO interrupt flags.
N/A |
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.
1007
of file platform/emlib/inc/em_gpio.h
GPIO_IntSet#
void GPIO_IntSet (uint32_t flags)
Set one or more pending GPIO interrupts from SW.
[in] | flags | GPIO interrupt sources to set to pending. |
1026
of file platform/emlib/inc/em_gpio.h
GPIO_Lock#
void GPIO_Lock (void )
Lock the GPIO configuration.
N/A |
1039
of file platform/emlib/inc/em_gpio.h
GPIO_PinInGet#
unsigned int GPIO_PinInGet (GPIO_Port_TypeDef port, unsigned int pin)
Read the pad value for a single pin in a GPIO port.
[in] | port | The GPIO port to access. |
[in] | pin | The pin number to read. |
Returns
The pin value, 0 or 1.
1057
of file platform/emlib/inc/em_gpio.h
GPIO_PinModeGet#
GPIO_Mode_TypeDef GPIO_PinModeGet (GPIO_Port_TypeDef port, unsigned int pin)
Get the mode for a GPIO pin.
[in] | port | The GPIO port to access. |
[in] | pin | The pin number in the port. |
Returns
The pin mode.
396
of file platform/emlib/src/em_gpio.c
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.
[in] | port | The GPIO port to access. |
[in] | pin | The pin number in the port. |
[in] | mode | The desired pin mode. |
[in] | out | A 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. |
347
of file platform/emlib/src/em_gpio.c
GPIO_PinOutClear#
void GPIO_PinOutClear (GPIO_Port_TypeDef port, unsigned int pin)
Set a single pin in GPIO data out port register to 0.
[in] | port | The GPIO port to access. |
[in] | pin | The pin to set. |
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.
1105
of file platform/emlib/inc/em_gpio.h
GPIO_PinOutGet#
unsigned int GPIO_PinOutGet (GPIO_Port_TypeDef port, unsigned int pin)
Get current setting for a pin in a GPIO port data out register.
[in] | port | The GPIO port to access. |
[in] | pin | The pin to get setting for. |
Returns
The DOUT setting for the requested pin, 0 or 1.
1130
of file platform/emlib/inc/em_gpio.h
GPIO_PinOutSet#
void GPIO_PinOutSet (GPIO_Port_TypeDef port, unsigned int pin)
Set a single pin in GPIO data out register to 1.
[in] | port | The GPIO port to access. |
[in] | pin | The pin to set. |
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.
1152
of file platform/emlib/inc/em_gpio.h
GPIO_PinOutToggle#
void GPIO_PinOutToggle (GPIO_Port_TypeDef port, unsigned int pin)
Toggle a single pin in GPIO port data out register.
[in] | port | The GPIO port to access. |
[in] | pin | The pin to toggle. |
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.
1179
of file platform/emlib/inc/em_gpio.h
GPIO_PortInGet#
uint32_t GPIO_PortInGet (GPIO_Port_TypeDef port)
Read the pad values for GPIO port.
[in] | port | The GPIO port to access. |
Returns
The pad values for the GPIO port.
1202
of file platform/emlib/inc/em_gpio.h
GPIO_PortOutClear#
void GPIO_PortOutClear (GPIO_Port_TypeDef port, uint32_t pins)
Set bits in DOUT register for a port to 0.
[in] | port | The GPIO port to access. |
[in] | pins | Bit mask for bits to clear in DOUT register. |
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.
1224
of file platform/emlib/inc/em_gpio.h
GPIO_PortOutGet#
uint32_t GPIO_PortOutGet (GPIO_Port_TypeDef port)
Get the current setting for a GPIO port data out register.
[in] | port | The GPIO port to access. |
Returns
The data out setting for the requested port.
1246
of file platform/emlib/inc/em_gpio.h
GPIO_PortOutSet#
void GPIO_PortOutSet (GPIO_Port_TypeDef port, uint32_t pins)
Set bits GPIO data out register to 1.
[in] | port | The GPIO port to access. |
[in] | pins | Bit mask for bits to set to 1 in DOUT register. |
Note
To ensure that the setting takes effect on the respective output pads, the pins must be configured properly. If not, it will take effect whenever the pin has been properly configured.
1268
of file platform/emlib/inc/em_gpio.h
GPIO_PortOutSetVal#
void GPIO_PortOutSetVal (GPIO_Port_TypeDef port, uint32_t val, uint32_t mask)
Set GPIO port data out register.
[in] | port | The GPIO port to access. |
[in] | val | Value to write to port data out register. |
[in] | mask | Mask indicating which bits to modify. |
Note
To ensure that the setting takes effect on the respective output pads, the pins must be configured properly. If not, it will take effect whenever the pin has been properly configured.
1298
of file platform/emlib/inc/em_gpio.h
GPIO_PortOutToggle#
void GPIO_PortOutToggle (GPIO_Port_TypeDef port, uint32_t pins)
Toggle pins in GPIO port data out register.
[in] | port | The GPIO port to access. |
[in] | pins | Bit mask with pins to toggle. |
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.
1322
of file platform/emlib/inc/em_gpio.h
GPIO_SlewrateSet#
void GPIO_SlewrateSet (GPIO_Port_TypeDef port, uint32_t slewrate, uint32_t slewrateAlt)
Set slewrate for pins on a GPIO port.
[in] | port | The GPIO port to configure. |
[in] | slewrate | The slewrate to configure for pins on this GPIO port. |
[in] | slewrateAlt | The slewrate to configure for pins using alternate modes on this GPIO port. |
1346
of file platform/emlib/inc/em_gpio.h
GPIO_Unlock#
void GPIO_Unlock (void )
Unlock the GPIO configuration.
N/A |
1368
of file platform/emlib/inc/em_gpio.h
Macro Definition Documentation#
SL_GPIO_PORT_A#
#define SL_GPIO_PORT_AValue:
gpioPortA
Mapping between SL_GPIO_PORT_ enums and gpioPort values.
568
of file platform/emlib/inc/em_gpio.h
SL_GPIO_PORT_B#
#define SL_GPIO_PORT_BValue:
gpioPortB
571
of file platform/emlib/inc/em_gpio.h
SL_GPIO_PORT_C#
#define SL_GPIO_PORT_CValue:
gpioPortC
574
of file platform/emlib/inc/em_gpio.h
SL_GPIO_PORT_D#
#define SL_GPIO_PORT_DValue:
gpioPortD
577
of file platform/emlib/inc/em_gpio.h