Simple Button Driver#

Simple Button Driver module provides APIs to initalize and read simple buttons. Subsequent sections provide more insight into button driver configuration and usage.


Introduction#

The Simple Button driver is a module of the button driver that provides the functionality to initialize and read simple buttons.


Simple Button Configuration#

Simple buttons use the sl_button_t struct and their sl_simple_button_context_t struct. These are automatically generated into the following files, as well as instance specific headers with macro definitions in them. The samples below are for a single instance called "inst0".

// sl_simple_button_instances.c

#include "sl_simple_button.h"
#include "sl_simple_button_inst0_config.h"

sl_simple_button_context_t simple_inst0_context = {
  .state = 0,
  .history = 0,
  .port = SL_SIMPLE_BUTTON_INST0_PORT,
  .pin = SL_SIMPLE_BUTTON_INST0_PIN,
  .mode = SL_SIMPLE_BUTTON_INST0_MODE,
};

const sl_button_t sl_button_inst0 = {
  .context = &simple_inst0_context,
  .init = sl_simple_button_init,
  .get_state = sl_simple_button_get_state,
  .poll = sl_simple_button_poll_step,
};

const sl_button_t *sl_simple_button_array[] = {&sl_button_inst0};
const uint8_t simple_button_count = 1;

void sl_simple_button_init_instances(void)
{
  sl_button_init(&sl_button_inst0);
}

void sl_simple_button_poll_instances(void)
{
  sl_button_poll_step(&sl_button_inst0);
}

Note

  • The sl_simple_button_instances.c file is shown with only one instance, but if more were in use they would all appear in this .c file.

// sl_simple_button_instances.h

#ifndef SL_SIMPLE_BUTTON_INSTANCES_H
#define SL_SIMPLE_BUTTON_INSTANCES_H

#include "sl_simple_button.h"

extern const sl_button_t sl_button_inst0;

void sl_simple_button_init_instances(void);
void sl_simple_button_poll_instances(void);

#endif // SL_SIMPLE_BUTTON_INSTANCES_H

Note

  • The sl_simple_button_instances.h file is shown with only one instance, but if more were in use they would all appear in this .h file.


Simple Button Usage#

The simple button driver has no differences in its usage from the common button driver. See Usage.

Modules#

sl_simple_button_context_t

Functions#

sl_status_t
sl_simple_button_init(const sl_button_t *handle)

Initialize the simple button driver.

sl_simple_button_get_state(const sl_button_t *handle)

Get the current state of the simple button.

void
sl_simple_button_poll_step(const sl_button_t *handle)

Poll the simple button.

void
sl_simple_button_enable(const sl_button_t *handle)

Enable the simple button.

void
sl_simple_button_disable(const sl_button_t *handle)

Disable the simple button.

Macros#

#define

BUTTON input capture using polling.

#define

BUTTON input capture using polling and debouncing.

#define

BUTTON input capture using interrupt.

#define

BUTTON state is disabled.

#define

BUTTON state is pressed.

#define

BUTTON state is released.

#define

BUTTON member function to get state.

#define

BUTTON member function to get port.

#define

BUTTON member function to get pin.

#define

BUTTON member function to get mode.

Function Documentation#

sl_simple_button_init#

sl_status_t sl_simple_button_init (const sl_button_t * handle)

Initialize the simple button driver.

Parameters
[in]handle

Pointer to button handle:

  • sl_button_t

Returns

  • Status Code:

    • SL_STATUS_OK


Definition at line 108 of file platform/driver/button/inc/sl_simple_button.h

sl_simple_button_get_state#

sl_button_state_t sl_simple_button_get_state (const sl_button_t * handle)

Get the current state of the simple button.

Parameters
[in]handle

Pointer to button handle:

  • sl_button_t

Returns

  • Button State: Current state of the button

    • SL_SIMPLE_BUTTON_PRESSED

    • SL_SIMPLE_BUTTON_RELEASED


Definition at line 120 of file platform/driver/button/inc/sl_simple_button.h

sl_simple_button_poll_step#

void sl_simple_button_poll_step (const sl_button_t * handle)

Poll the simple button.

Parameters
[in]handle

Pointer to button handle:

  • sl_button_t

(button mode - poll / poll and debonuce)


Definition at line 128 of file platform/driver/button/inc/sl_simple_button.h

sl_simple_button_enable#

void sl_simple_button_enable (const sl_button_t * handle)

Enable the simple button.

Parameters
[in]handle

Pointer to button handle:

  • sl_button_t


Definition at line 136 of file platform/driver/button/inc/sl_simple_button.h

sl_simple_button_disable#

void sl_simple_button_disable (const sl_button_t * handle)

Disable the simple button.

Parameters
[in]handle

Pointer to button handle:

  • sl_button_t


Definition at line 144 of file platform/driver/button/inc/sl_simple_button.h

Macro Definition Documentation#

SL_SIMPLE_BUTTON_MODE_POLL#

#define SL_SIMPLE_BUTTON_MODE_POLL
Value:
0U

BUTTON input capture using polling.


Definition at line 63 of file platform/driver/button/inc/sl_simple_button.h

SL_SIMPLE_BUTTON_MODE_POLL_AND_DEBOUNCE#

#define SL_SIMPLE_BUTTON_MODE_POLL_AND_DEBOUNCE
Value:
1U

BUTTON input capture using polling and debouncing.


Definition at line 64 of file platform/driver/button/inc/sl_simple_button.h

SL_SIMPLE_BUTTON_MODE_INTERRUPT#

#define SL_SIMPLE_BUTTON_MODE_INTERRUPT
Value:
2U

BUTTON input capture using interrupt.


Definition at line 65 of file platform/driver/button/inc/sl_simple_button.h

SL_SIMPLE_BUTTON_DISABLED#

#define SL_SIMPLE_BUTTON_DISABLED
Value:
2U

BUTTON state is disabled.


Definition at line 67 of file platform/driver/button/inc/sl_simple_button.h

SL_SIMPLE_BUTTON_PRESSED#

#define SL_SIMPLE_BUTTON_PRESSED
Value:
1U

BUTTON state is pressed.


Definition at line 68 of file platform/driver/button/inc/sl_simple_button.h

SL_SIMPLE_BUTTON_RELEASED#

#define SL_SIMPLE_BUTTON_RELEASED
Value:
0U

BUTTON state is released.


Definition at line 69 of file platform/driver/button/inc/sl_simple_button.h

SL_SIMPLE_BUTTON_GET_STATE#

#define SL_SIMPLE_BUTTON_GET_STATE
Value:
(context)

BUTTON member function to get state.


Definition at line 71 of file platform/driver/button/inc/sl_simple_button.h

SL_SIMPLE_BUTTON_GET_PORT#

#define SL_SIMPLE_BUTTON_GET_PORT
Value:
(context)

BUTTON member function to get port.


Definition at line 72 of file platform/driver/button/inc/sl_simple_button.h

SL_SIMPLE_BUTTON_GET_PIN#

#define SL_SIMPLE_BUTTON_GET_PIN
Value:
(context)

BUTTON member function to get pin.


Definition at line 73 of file platform/driver/button/inc/sl_simple_button.h

SL_SIMPLE_BUTTON_GET_MODE#

#define SL_SIMPLE_BUTTON_GET_MODE
Value:
(context)

BUTTON member function to get mode.


Definition at line 74 of file platform/driver/button/inc/sl_simple_button.h