Button
Sample API functions for using push-buttons.
See sl_si91x_button.c for source code.
Introduction#
The SI91x button driver is a platform-level software module responsible for managing the initialization and reading buttons. It offers a comprehensive set of functions for button operations, including initialization, state monitoring, and callback handling for state changes. The driver supports flexible interrupt configurations, enabling detection based on button state, edge transitions, or both. All button functions are called through the generic driver, which internally triggers specific functions to the respective button.
Configuration#
All button instances are configured with an sl_button_t struct. This struct is automatically generated after a button is set up using Simplicity Studio's wizard.
For more information on configuring available parameters refer to the respective peripheral example readme document and refer here https://docs.silabs.com/wiseconnect/latest/wiseconnect-api-reference-guide-si91x-peripherals/disable-uc-config.
Usage#
Once the button structures are defined, the button functions can be invoked by passing an instance of sl_button_t, which will be redirected to call the type-specific version of that function. The common functions include the following:
sl_button_init is called automatically when the application is run.
The button driver can be used with interrupt mode, with or without debounce. sl_si91x_button_pin_state can be implemented by the application if required. This function is used to determine the current state of the button. sl_si91x_button_state_toggle can be implemented by the application. This function toggles the "soft" state so that it gives the interrupts and their callbacks. sl_si91x_button_isr is a callback function that is called when the button state changes. This function can be implemented in the application to specify what the user wants to do when the button state changes.
Modules#
Macros#
A set of numerical macros for use with the button APIs.
Interrupt on low/pressed button state can be configured.
Interrupt on low/pressed button state can be configured.
Interrupt on low/pressed and high/released button state can be configured.
Interrupt on rising edge of the button press.
Interrupt on falling edge of the button press.
Interrupt on rising edge and falling edge of the button press.
Button state is pressed.
Button state is released.
Button state is invalid.
Functions#
Initializes the button, a process automatically triggered upon the creation of a button instance, sets the mode of operation, and configures interrupts based on the selected mode.
Returns the current state (pressed or released) of a button.
Returns the current state (pressed or released) of the pin associated with a button.
A callback called in interrupt context whenever a button changes its state.
Toggles the value of a local variable associated with the state of button.
Sets the state (pressed or released) of the pin associated with a button.
A callback that user can modify for the application.
Macros Documentation#
HIGH_LEVEL_INTERRUPT#
#define HIGH_LEVEL_INTERRUPTValue:
1U
Interrupt on low/pressed button state can be configured.
Interrupt on high/released button state
50
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
LOW_LEVEL_INTERRUPT#
#define LOW_LEVEL_INTERRUPTValue:
2U
Interrupt on low/pressed button state can be configured.
52
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
HIGH_LEVEL_AND_LOW_LEVEL_INTERRUPT#
#define HIGH_LEVEL_AND_LOW_LEVEL_INTERRUPTValue:
3U
Interrupt on low/pressed and high/released button state can be configured.
54
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
RISE_EDGE_INTERRUPT#
#define RISE_EDGE_INTERRUPTValue:
4U
Interrupt on rising edge of the button press.
57
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
FALL_EDGE_INTERRUPT#
#define FALL_EDGE_INTERRUPTValue:
8U
Interrupt on falling edge of the button press.
59
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
RISE_EDGE_AND_FALL_EDGE_INTERRUPT#
#define RISE_EDGE_AND_FALL_EDGE_INTERRUPTValue:
12U
Interrupt on rising edge and falling edge of the button press.
61
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
BUTTON_PRESSED
#define BUTTON_PRESSEDValue:
1
Button state is pressed.
63
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
BUTTON_RELEASED
#define BUTTON_RELEASEDValue:
0
Button state is released.
65
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
BUTTON_STATE_INVALID
#define BUTTON_STATE_INVALIDValue:
-1
Button state is invalid.
67
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
Function Documentation#
sl_si91x_button_init
void sl_si91x_button_init (const sl_button_t * handle)
Initializes the button, a process automatically triggered upon the creation of a button instance, sets the mode of operation, and configures interrupts based on the selected mode.
[in] | handle | The pointer to button structure that has the specific button information. |
Returns
none
87
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
sl_si91x_button_state_get
int8_t sl_si91x_button_state_get (uint8_t pin)
Returns the current state (pressed or released) of a button.
[in] | pin | The button pin being queried, either BUTTON0 pin or BUTTON1 pin as defined. |
Note
This function is correlated with sl_si91x_button_isr() and so returns the shadow state rather than reading the actual state of the pin.
Returns
BUTTON_PRESSED if the button is pressed or BUTTON_RELEASED if the button is not pressed.
102
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
sl_si91x_button_pin_state
int8_t sl_si91x_button_pin_state (uint8_t pin)
Returns the current state (pressed or released) of the pin associated with a button.
[in] | pin | The button pin being queried, either BUTTON0 pin or BUTTON1 pin as defined. |
This reads the actual state of the pin and can be used on startup to determine the initial position of the buttons.
Returns
BUTTON_PRESSED if the button is pressed or BUTTON_RELEASED if the button is not pressed.
118
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
sl_si91x_button_pin_isr
void sl_si91x_button_pin_isr (uint8_t pin, uint8_t state)
A callback called in interrupt context whenever a button changes its state.
[in] | pin | The button pin which has changed state, either BUTTON0 pin or BUTTON1 pin as defined. |
[out] | state | The new state of the button referenced by the button parameter, either BUTTON_PRESSED if the button has been pressed or BUTTON_RELEASED if the button has been released. |
Note
Must be implemented by the application. This function should contain the functionality to be executed in response to changes of state in each of the buttons, or callbacks to the appropriate functionality.
Returns
none
138
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
sl_si91x_button_state_toggle
void sl_si91x_button_state_toggle (uint8_t pin)
Toggles the value of a local variable associated with the state of button.
[in] | pin | The button pin which has changed state, either BUTTON0 pin or BUTTON1 pin as defined. |
Note
Must be implemented by the application. This function should contain the functionality to be executed in response to changes of state in each of the buttons, or callbacks to the appropriate functionality.
Returns
none
153
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
sl_si91x_button_state_set
void sl_si91x_button_state_set (uint8_t pin, int8_t state)
Sets the state (pressed or released) of the pin associated with a button.
[in] | pin | The button pin which has changed state, either BUTTON0 pin or BUTTON1 pin as defined. |
[in] | state | The state of the button to be set, either BUTTON_PRESSED if the button state is pressed or BUTTON_RELEASED if the button state is released. |
Note
Must be implemented by the application. This function should contain the functionality to be executed in response to changes of state in each of the buttons, or callbacks to the appropriate functionality.
Returns
none
173
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h
sl_si91x_button_isr
void sl_si91x_button_isr (uint8_t pin, int8_t state)
A callback that user can modify for the application.
[in] | pin | The button pin which has changed state, either BUTTON0 pin or BUTTON1 pin as defined. |
[in] | state | The new state of the button referenced by the button parameter, either BUTTON_PRESSED if the button is pressed or BUTTON_RELEASED if the button is released. |
Note
Must be implemented by the application. This function should contain the functionality to be executed in response to changes of state in each of the buttons, or callbacks to the appropriate functionality.
Returns
none
192
of file components/device/silabs/si91x/mcu/drivers/hardware_drivers/button/inc/sl_si91x_button.h