GPIO - General Purpose Input Output#
General Purpose Input Output driver.
Introduction#
This module contains functions to control the GPIO peripheral of Silicon Labs 32-bit MCUs and SoCs. The GPIO driver is used for external and EM4 interrupt configuration, port and pin configuration. as well as manages the interrupt handler.
Modules#
Enumerations#
GPIO Pin directions.
Typedefs#
GPIO interrupt callback function pointer.
Functions#
Initialization of GPIO driver module.
Sets the pin direction of GPIO pin.
Set the pin mode and set/clear the pin for GPIO pin.
Gets the current configuration selected pin on selected port.
Sets the selected pin of the selected port.
Clears the selected pin of the selected port.
Toggles the state of selected pin on selected port.
Gets the output state of selected pin on selected port.
Gets the input state of selected pin on selected port.
Sets the selected pin(s) of selected port.
Clears the selected pin(s) of selected port.
Gets the output state of pins of selected port.
Gets the input state of pins of selected port.
Configures the GPIO pin interrupt.
Deconfigures the GPIO external pin interrupt.
Enables one or more GPIO Interrupts.
Disables one or more GPIO Interrupts.
Configuration EM4WU pins as external level-sensitive interrupts.
Utilize this function to deconfigure the EM4 GPIO pin interrupt.
Enable EM4 GPIO pin Wake-up bit.
Disabled the GPIO wake up from EM4.
Enable/Disable GPIO pin retention of output enable, output value, pull enable, and pull direction in EM4.
Sets slewrate for selected port.
Gets slewrate for selected port.
Locks the GPIO Configuration.
Unlocks the GPIO Configuration.
Gets current GPIO Lock status.
Enumeration Documentation#
sl_gpio_pin_direction_t#
sl_gpio_pin_direction_t
GPIO Pin directions.
Enumerator | |
---|---|
SL_GPIO_PIN_DIRECTION_IN | Input direction. |
SL_GPIO_PIN_DIRECTION_OUT | Output direction. |
Typedef Documentation#
sl_gpio_irq_callback_t#
typedef void(* sl_gpio_irq_callback_t) (uint8_t int_no, void *context) )(uint8_t int_no, void *context)
GPIO interrupt callback function pointer.
Type | Direction | Argument Name | Description |
---|---|---|---|
N/A | int_no | The pin interrupt number to which the callback function is invoked for. | |
N/A | context | Pointer to callback context. |
Function Documentation#
sl_gpio_init#
sl_status_t sl_gpio_init (void )
Initialization of GPIO driver module.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
SL_STATUS_OK if initialization is successful.
Initialization of GPIO driver module.
sl_gpio_set_pin_direction#
sl_status_t sl_gpio_set_pin_direction (const sl_gpio_t * gpio, sl_gpio_pin_direction_t pin_direction)
Sets the pin direction of GPIO pin.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_gpio_t * | [in] | gpio | Pointer to GPIO structure with port and pin |
sl_gpio_pin_direction_t | [in] | pin_direction | Pin direction of GPIO pin. |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMATER if any of the port, pin, direction parameters are invalid. SL_STATUS_INVALID_STATE if GPIO configuration is in lock state.
Sets the pin direction of GPIO pin.
sl_gpio_set_pin_mode#
sl_status_t sl_gpio_set_pin_mode (const sl_gpio_t * gpio, sl_gpio_mode_t mode, bool output_value)
Set the pin mode and set/clear the pin for GPIO pin.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_gpio_t * | [in] | gpio | Pointer to GPIO structure with port and pin |
sl_gpio_mode_t | [in] | mode | The desired pin mode. |
bool | [in] | output_value | Value to set/clear for pin output on the port. Determines the pull-up/pull-down direction of the pin for some input mode configurations. |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMETER if any of the port, pin, mode parameters are invalid. SL_STATUS_INVALID_STATE if GPIO configuration is in locked state.
Set the pin mode and set/clear the pin for GPIO pin.
sl_gpio_get_pin_config#
sl_status_t sl_gpio_get_pin_config (const sl_gpio_t * gpio, sl_gpio_pin_config_t * pin_config)
Gets the current configuration selected pin on selected port.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_gpio_t * | [in] | gpio | Pointer to GPIO structure with port and pin |
sl_gpio_pin_config_t * | [out] | pin_config | Pointer to pin configuration such as mode and direction. Pointer acts as an output and returns the configuration of selected pin on selected port. |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMETER if any of the port, pin parameters are invalid. SL_STATUS_NULL_POINTER if pin_config is passed as null.
sl_gpio_set_pin#
sl_status_t sl_gpio_set_pin (const sl_gpio_t * gpio)
Sets the selected pin of the selected port.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_gpio_t * | [in] | gpio | Pointer to GPIO structure with port and pin |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMATER if any of the port, pin parameters are invalid.
Sets the selected pin of the selected port.
sl_gpio_clear_pin#
sl_status_t sl_gpio_clear_pin (const sl_gpio_t * gpio)
Clears the selected pin of the selected port.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_gpio_t * | [in] | gpio | Pointer to GPIO structure with port and pin |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMATER if any of the port, pin parameters are invalid.
Clears the selected pin of the selected port.
sl_gpio_toggle_pin#
sl_status_t sl_gpio_toggle_pin (const sl_gpio_t * gpio)
Toggles the state of selected pin on selected port.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_gpio_t * | [in] | gpio | Pointer to GPIO structure with port and pin |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMATER if any of the port, pin parameters are invalid.
Toggles the state of selected pin on selected port.
sl_gpio_get_pin_output#
sl_status_t sl_gpio_get_pin_output (const sl_gpio_t * gpio, bool * pin_value)
Gets the output state of selected pin on selected port.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_gpio_t * | [in] | gpio | Pointer to GPIO structure with port and pin |
bool * | [out] | pin_value | Pointer to return output state of selected pin on selected port when configured to output mode. |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMATER if any of the port, pin parameters are invalid. SL_STATUS_NULL_POINTER if pin_value passed as null.
sl_gpio_get_pin_input#
sl_status_t sl_gpio_get_pin_input (const sl_gpio_t * gpio, bool * pin_value)
Gets the input state of selected pin on selected port.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_gpio_t * | [in] | gpio | Pointer to GPIO structure with port and pin |
bool * | [out] | pin_value | Pointer to return input state of selected pin on selected port when configured to input mode. |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMATER if any of the port, pin parameters are invalid. SL_STATUS_NULL_POINTER if pin_value passed as null.
sl_gpio_set_port#
sl_status_t sl_gpio_set_port (sl_gpio_port_t port, uint32_t pins)
Sets the selected pin(s) of selected port.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_gpio_port_t | [in] | port | The GPIO port to access. |
uint32_t | [in] | pins | Bit mask for pins to set. |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMETER if port is invalid.
Sets the selected pin(s) of selected port.
sl_gpio_clear_port#
sl_status_t sl_gpio_clear_port (sl_gpio_port_t port, uint32_t pins)
Clears the selected pin(s) of selected port.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_gpio_port_t | [in] | port | The GPIO Port to access. |
uint32_t | [in] | pins | Bit mask for bits to clear. |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMETER if port is invalid.
Clears the selected pin(s) of selected port.
sl_gpio_get_port_output#
sl_status_t sl_gpio_get_port_output (sl_gpio_port_t port, uint32_t * port_value)
Gets the output state of pins of selected port.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_gpio_port_t | [in] | port | The GPIO Port to access. |
uint32_t * | [out] | port_value | Pointer to return output state of pins on selected port. |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMETER if port is invalid. SL_STATUS_NULL_POINTER if port_value passed as null.
sl_gpio_get_port_input#
sl_status_t sl_gpio_get_port_input (sl_gpio_port_t port, uint32_t * port_value)
Gets the input state of pins of selected port.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_gpio_port_t | [in] | port | The GPIO Port to access. |
uint32_t * | [out] | port_value | Pointer to return output state of pins on selected port. |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMETER if port is invalid. SL_STATUS_NULL_POINTER if port_value passed as null.
sl_gpio_configure_external_interrupt#
sl_status_t sl_gpio_configure_external_interrupt (const sl_gpio_t * gpio, int32_t * int_no, sl_gpio_interrupt_flag_t flags, sl_gpio_irq_callback_t gpio_callback, void * context)
Configures the GPIO pin interrupt.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_gpio_t * | [in] | gpio | Pointer to GPIO structure with port and pin |
int32_t * | N/A | int_no | int_no Pointer to interrupt number to trigger. Pointer that serves as both an input and an output to return int_no when the user lacks an int_no. |
sl_gpio_interrupt_flag_t | [in] | flags | Interrupt flags for interrupt configuration. Determines the interrupt to get trigger based on rising/falling edge. |
sl_gpio_irq_callback_t | [in] | gpio_callback | A pointer to gpio callback function. |
void * | [in] | context | A pointer to the callback context. |
By default, this function can be used to register a callback which shall be called upon interrupt generated for a given pin interrupt number and enables interrupt. This function configures and enables the external interrupt and performs callback registration. It is recommended to use sl_gpio_deconfigure_external_interrupt() to disable the interrupt and unregister the callback. see sl_gpio_deconfigure_external_interrupt for more information. If a valid interrupt number is provided, operation will proceed accordingly. Otherwise, a valid interrupt number will be generated based on provided port and pin and used for subsequent operations.
Note
If the user has a valid interrupt number to provide as input, it can be used. If the user does not have an interrupt number, they can pass -1 (SL_GPIO_INTERRUPT_UNAVAILABLE) as value to variable int_no. The int_no parameter serves even as an output, a pointer to convey the interrupt number for cases where user lacks an interrupt number.
the pin number can be selected freely within a group. Interrupt numbers are divided into 4 groups (int_no / 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)
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMETER if any of the port, pin, flag parameters are invalid. SL_STATUS_NULL_POINTER if the int_no is passed as NULL. SL_STATUS_NOT_FOUND if there's no available interrupt number.
Configures the GPIO pin interrupt.
This API can be used to configure interrupt and to register the callback.
sl_gpio_deconfigure_external_interrupt#
sl_status_t sl_gpio_deconfigure_external_interrupt (int32_t int_no)
Deconfigures the GPIO external pin interrupt.
Type | Direction | Argument Name | Description |
---|---|---|---|
int32_t | [in] | int_no | Interrupt number to unregister and disable. |
This function can be used to deconfigure the external GPIO interrupt. This function performs callback unregistration, clears and disables the given interrupt.
Note
the pin number can be selected freely within a group. Interrupt numbers are divided into 4 groups (int_no / 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)
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMETER if int_no is invalid.
This API can be used to deconfigure the interrupt and to unregister the callback.
sl_gpio_enable_interrupts#
sl_status_t sl_gpio_enable_interrupts (uint32_t flags)
Enables one or more GPIO Interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | flags | Mask for GPIO Interrupt sources to enable. |
Returns
SL_STATUS_OK if there's no error.
Enables one or more GPIO Interrupts.
sl_gpio_disable_interrupts#
sl_status_t sl_gpio_disable_interrupts (uint32_t flags)
Disables one or more GPIO Interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | flags | Mask for GPIO Interrupt sources to disable. |
Returns
SL_STATUS_OK if there's no error.
Disables one or more GPIO Interrupts.
sl_gpio_configure_wakeup_em4_interrupt#
sl_status_t sl_gpio_configure_wakeup_em4_interrupt (const sl_gpio_t * gpio, int32_t * em4_int_no, bool polarity, sl_gpio_irq_callback_t gpio_callback, void * context)
Configuration EM4WU pins as external level-sensitive interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_gpio_t * | [in] | gpio | Pointer to GPIO structure with port and pin |
int32_t * | N/A | em4_int_no | em4_int_no Pointer to interrupt number to trigger. Pointer that serves as both an input and an output to return em4_int_no when the user lacks an em4_int_no. |
bool | [in] | polarity | Determines the wakeup polarity. true = Active high level-sensitive interrupt. false = Active low level-sensitive interrupt. |
sl_gpio_irq_callback_t | [in] | gpio_callback | A pointer to callback. |
void * | [in] | context | A pointer to callback context. |
By default, this function performs callback registration, enables GPIO pin wake-up from EM4, sets the wake-up polarity, enables GPIO pin retention and enables the EM4 wake-up interrupt. It is recommended to use sl_gpio_deconfigure_wakeup_em4_interrupt() to unregister the callback and disable the em4 interrupt as well as GPIO pin wake-up from EM4. It is recommended to use sl_gpio_set_pin_em4_retention() to enable/disable the GPIO pin retention. see sl_gpio_deconfigure_wakeup_em4_interrupt() and sl_gpio_set_pin_em4_retention(). If a valid EM4 wake-up interrupt number is provided, operation will proceed accordingly. Otherwise, a valid EM4 interrupt number will be generated based on provided EM4 configured port and pin and used for subsequent operations.
Note
If the user has a valid em4 interrupt number to provide as input, it can be used. If the user does not have an interrupt number, they can pass -1 (SL_GPIO_INTERRUPT_UNAVAILABLE) as value to variable em4_int_no. The em4_int_no parameter serves even as an output, a pointer to convey the em4 interrupt number for cases where user lacks an em4 interrupt number.
There are specific ports and pins mapped to an existent EM4WU interrupt Each EM4WU signal is connected to a fixed pin and port. Based on chip, EM4 wake up interrupts configured port and pin might vary.
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMETER if any of the port, pin parameters are invalid. SL_STATUS_NULL_POINTER if the int_no is passed as NULL. SL_STATUS_NOT_FOUND if there's no available interrupt number.
Configuration EM4WU pins as external level-sensitive interrupts.
Registering/unregistering the callbacks and Configuring the EM4 interrupts to enable/disable
sl_gpio_deconfigure_wakeup_em4_interrupt#
sl_status_t sl_gpio_deconfigure_wakeup_em4_interrupt (int32_t em4_int_no)
Utilize this function to deconfigure the EM4 GPIO pin interrupt.
Type | Direction | Argument Name | Description |
---|---|---|---|
int32_t | [in] | em4_int_no | EM4 wakeup interrupt number. |
It serves to unregister a callback, disable/clear interrupt and clear em4 wakeup source.
This function performs callback unregistration, clears and disables given em4 interrupt and disables GPIO pin wake-up from EM4.
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMETER if em4_int_no is invalid.
Utilize this function to deconfigure the EM4 GPIO pin interrupt.
Unregisters a callback, disable/clear interrupt and clear em4 wakeup source
sl_gpio_enable_pin_em4_wakeup#
sl_status_t sl_gpio_enable_pin_em4_wakeup (uint32_t em4_int_mask, uint32_t em4_polarity_mask)
Enable EM4 GPIO pin Wake-up bit.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | em4_int_mask | Mask for setting desired EM4 wake up interrupt to enable. Mask contains the bitwise logic OR of which EM4 wake up interrupt to enable. |
uint32_t | [in] | em4_polarity_mask | Mask for setting the wake up polarity for the EM4 wake up interrupt. Mask contains the bitwise logic OR of EM4 wake-up interrupt polarity. |
Sets the wakeup and polarity of the EM4 wakeup.
Returns
SL_STATUS_OK if there's no error.
Enable EM4 GPIO pin Wake-up bit.
sl_gpio_disable_pin_em4_wakeup#
sl_status_t sl_gpio_disable_pin_em4_wakeup (uint32_t em4_int_mask)
Disabled the GPIO wake up from EM4.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | em4_int_mask | Mask for clearing desired EM4 wake up interrupt to disable. Mask contains the bitwise logic OR of which EM4 wake up interrupt to disable. |
Returns
SL_STATUS_OK if there's no error.
Disabled the GPIO wake up from EM4.
sl_gpio_set_pin_em4_retention#
sl_status_t sl_gpio_set_pin_em4_retention (bool enable)
Enable/Disable GPIO pin retention of output enable, output value, pull enable, and pull direction in EM4.
Type | Direction | Argument Name | Description |
---|---|---|---|
bool | [in] | enable | true - enables EM4 pin retention. false - disables EM4 pin retention. |
Returns
SL_STATUS_OK if there's no error.
Enable/Disable GPIO pin retention of output enable, output value, pull enable, and pull direction in EM4.
sl_gpio_set_slew_rate#
sl_status_t sl_gpio_set_slew_rate (const sl_gpio_t * gpio, uint8_t slewrate)
Sets slewrate for selected port.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_gpio_t * | [in] | gpio | Pointer to GPIO structure with port and pin |
uint8_t | [in] | slewrate | The slewrate to configure the GPIO port. |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMETER if port is invalid.
sl_gpio_get_slew_rate#
sl_status_t sl_gpio_get_slew_rate (const sl_gpio_t * gpio, uint8_t * slewrate, slewrate)
Gets slewrate for selected port.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_gpio_t * | [in] | gpio | Pointer to GPIO structure with port and pin |
uint8_t * | [out] | slewrate | Pointer to store the slewrate of selected port. |
[out] | slewrate | Pointer to store the slewrate of selected port. |
Returns
SL_STATUS_OK if there's no error. SL_STATUS_INVALID_PARAMETER if port is invalid. SL_STATUS_NULL_POINTER if slewrate is passed as null. SL_STATUS_NOT_SUPPORTED if slewrate is not supported.
sl_gpio_lock#
sl_status_t sl_gpio_lock (void )
Locks the GPIO Configuration.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Note
This API locks the functionalities such as sl_gpio_set_pin_mode(), sl_gpio_configure_external_interrupt() and sl_gpio_configure_wakeup_em4_interrupt(). After locking the GPIO configuration, use sl_gpio_unlock API to unlock the GPIO configuration to use mentioned functionalities.
Returns
SL_STATUS_OK if there's no error.
sl_gpio_unlock#
sl_status_t sl_gpio_unlock (void )
Unlocks the GPIO Configuration.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Note
After locking the GPIO configuration it is recommended to unlock the GPIO configuration using sl_gpio_unlock(). You can determine if the GPIO configuration is locked or unlocked by using the sl_gpio_is_locked() function. Before using certain functions like sl_gpio_set_pin_mode(), sl_gpio_configure_external_interrupt(), and sl_gpio_configure_wakeup_em4_interrupt(), it's important to check if the GPIO configuration lock is unlocked.
Returns
SL_STATUS_OK if there's no error.
sl_gpio_is_locked#
sl_status_t sl_gpio_is_locked (bool * state)
Gets current GPIO Lock status.
Type | Direction | Argument Name | Description |
---|---|---|---|
bool * | [out] | state | Pointer to current state of GPIO configuration (lock/unlock). |
Note
This function helps check the current status of GPIO configuration.
Returns
SL_STATUS_OK if there's no error. SL_STATUS_NULL_POINTER if state is passed as null.
Gets current GPIO Lock status.