Button Part Drivers API Documentation - GPIO

This page documents the API of the GPIO flavor of the Button Part Drivers.

An overview of the driver is also available here: main_doc .

Functions

Functions

button_status_t button_init ( button_t * p_button , uint32_t id )

logical button initialization.

Parameters :
  • p_button – button object to initialize

  • id – configuration id to apply to the button (used by button_io_init)

Return values :

error – status

int32_t button_io_init ( button_t * p_button )

low-level IO init function.

Parameters :

p_button – pointer to the button object to initialize

Return values :

0 – in case of success, -1 otherwise

button_status_t button_register_callback ( button_t * p_button , button_callback_t callback , button_event_t event , void * arg )

This function registers a callback function for the button. The callback function is called on the selected button event.

Parameters :
  • p_button – pointer to the button object.

  • callback – callback function pointer.

  • event – button event to trigger the callback: pushed, released, or both.

  • arg – additional argument passed to the callback function.

Return values :

error – status.

button_state_t button_get_state ( button_t * p_button )

This function returns the state of the button BUTTON_PRESSED or BUTTON_UNPRESSED.

Parameters :

p_button – A pointer to the type button_t, that can be defined using the macro DEFINE_BUTTON for button defined using STM32CubeMX2.

Return values :

error – status

button_status_t button_enableit ( button_t * p_button )

This function enables interrupt request on button event.

Parameters :

p_button – A pointer to the type button_t, that can be defined using the macro DEFINE_BUTTON for button defined using STM32CubeMX2.

Return values :

error – status

button_status_t button_disableit ( button_t * p_button )

This function disables the interrupt for the button.

Parameters :

p_button – A pointer to the type button_t, that can be defined using the macro DEFINE_BUTTON for button defined using STM32CubeMX2.

Return values :

error – status

Types

Enums

enum button_state_t

Enumeration defining the state of a Button.

Values:

enumerator BUTTON_UNPRESSED

Indicate that the button state is not pressed

enumerator BUTTON_PRESSED

Indicate that the button state is pressed

enum button_event_t

Enumeration representing the button state change event, used to register callbacks function.

Values:

enumerator BUTTON_EVENT_PRESSED

Event when the button state changes from unpressed to pressed

enumerator BUTTON_EVENT_UNPRESSED

Event when the button state changes from pressed to unpressed

enumerator BUTTON_EVENT_ANY

Event when the button state changes

enum button_status_t

Enumeration defining return status for button APIs.

Values:

enumerator BUTTON_OK

Operation completed successfully

enumerator BUTTON_ERROR

Operation failed

Typedefs

typedef struct button_s button_t

Button object structure type

typedef void ( * button_callback_t ) ( button_t * button , void * arg )

callback function pointer definition

struct button_s

Structure defining the properties for a Button.

Public Members

uint32_t id

configuration ID

hal_gpio_t port

Button input GPIO port

uint16_t pin

Button input GPIO pin

hal_gpio_pin_state_t active_state

Button input GPIO pin state (high or low) define the button active state

hal_exti_handle_t * exti_handle

EXTI handle for asynchronous features

button_ctx_t cb_ctx

Callback context: function pointer and argument

uint32_t debounce_duration

timeout for software debounce

volatile uint32_t last_event_tick

timestamp of the last event taken into account

volatile hal_exti_trigger_t last_event

edge direction of the last event taken into account

struct button_ctx_t

Callback registration context associated with a button.

Public Members

button_callback_t cb

callback executed from EXTI interrupt

button_event_t event

event to react to (pressed, unpressed, any)

void * arg

optional argument given to that callback

Constants and macros

Defines

BUTTON_CALLBACKS 1

This feature flag enables the callback features of the button part driver.

BUTTON_CALLBACKS

Note

This feature is necessary for software debounce (cf BUTTON_DEBOUNCE).