Button API
Generic Button API.
Introduction#
The button driver is a platfom level software module that manages the initialization and reading of various types of buttons. There is currently one type of button supported by the button driver:
All button functions are called through the generic driver, which then references functions in the simple button and other potential future button drivers.
Configuration#
All button instances are configured with an sl_button_t struct and a type specific context struct. These structs are automatically generated after a button is set up using Simplicity Studio's wizard, along with a function definition for initializing all LEDs of that type. Specific setup for the simple button is in the following section.
Usage#
Once the button structs are defined, the common button functions can be called being passed an instance of sl_button_t, which will be redirected to calling the type specific version of that function. The common functions include the following:
sl_button_init must be called before attempting to read the state of the button.
The button driver can either be used with interrupt mode, polling or polling with debounce. In the case of using interrupt mode, sl_button_on_change can be implemented by the application if required. This function can contain functionality to be executed in response to button event or callbacks to appropriate functionality. In the case of polling and polling with debounce mode, sl_button_poll_step is used to update the state, and needs to be called from a tick function or similar by the user. These mode can be configured per button instance in the instance specific config file.
Both the interrupt and polling methods obtain the button state for the user by calling sl_button_get_state.
Modules#
Functions#
Button driver init.
Get button state.
Enable the button.
Disable the button.
Poll the button.
A callback called in interrupt context whenever a button changes its state.
Macros#
Error when trying to return state.
Typedef Documentation#
sl_button_mode_t
typedef uint8_t sl_button_mode_t
BUTTON mode.
57
of file platform/driver/button/inc/sl_button.h
sl_button_state_t
typedef uint8_t sl_button_state_t
BUTTON state.
58
of file platform/driver/button/inc/sl_button.h
Function Documentation#
sl_button_init
sl_status_t sl_button_init (const sl_button_t * handle)
Button driver init.
[in] | handle | Pointer to button instance |
This function should be called before calling any other button function. Sets up the GPIO. Sets the mode of operation. Sets up the interrupts based on the mode of operation.
Returns
Status Code:
SL_STATUS_OK
85
of file platform/driver/button/inc/sl_button.h
sl_button_get_state
sl_button_state_t sl_button_get_state (const sl_button_t * handle)
Get button state.
[in] | handle | Pointer to button instance |
Returns
Button state Current state of the button
94
of file platform/driver/button/inc/sl_button.h
sl_button_enable
void sl_button_enable (const sl_button_t * handle)
Enable the button.
[in] | handle | Pointer to button instance |
102
of file platform/driver/button/inc/sl_button.h
sl_button_disable
void sl_button_disable (const sl_button_t * handle)
Disable the button.
[in] | handle | Pointer to button instance |
110
of file platform/driver/button/inc/sl_button.h
sl_button_poll_step
void sl_button_poll_step (const sl_button_t * handle)
Poll the button.
[in] | handle | Pointer to button instance |
117
of file platform/driver/button/inc/sl_button.h
sl_button_on_change
void sl_button_on_change (const sl_button_t * handle)
A callback called in interrupt context whenever a button changes its state.
[out] | handle | Pointer to button instance |
Remarks
Can be implemented by the application if required. This function can contain the functionality to be executed in response to changes of state in each of the buttons, or callbacks to appropriate functionality.
Note
The button state should not be updated in this function, it is updated by specific button driver prior to arriving here
131
of file platform/driver/button/inc/sl_button.h
Macro Definition Documentation#
BUTTON_ERROR
#define BUTTON_ERRORValue:
0xFFFF
Error when trying to return state.
51
of file platform/driver/button/inc/sl_button.h