File syn_button.c¶
FileList > input > syn_button.c
Go to the source code of this file
Debounced button implementation using syn_fsm.
#include "../drivers/syn_gpio.h"#include "../util/syn_assert.h"#include "syn_button.h"#include <string.h>
Public Types¶
| Type | Name |
|---|---|
| enum | syn__button_8c_1a06fc87d81c62e9abb8790b6e5713c55b |
Public Static Attributes¶
| Type | Name |
|---|---|
| const SYN_FSM_Transition | g_button_transitions = /* multi line expression */Button FSM transition table. |
Public Functions¶
| Type | Name |
|---|---|
| void | syn_button_combo_init (SYN_ButtonCombo * combo, const SYN_Button ** buttons, size_t count, SYN_ButtonCallback cb, void * ctx) Initialize a combination button descriptor. |
| void | syn_button_combo_update (SYN_ButtonCombo * combo) Update a combination button descriptor. |
| void | syn_button_init (SYN_Button * btn, SYN_GPIO_Pin pin, SYN_ButtonPolarity polarity, uint16_t debounce_ms) Initialize a button descriptor. |
| void | syn_button_on_double_click (SYN_Button * btn, SYN_ButtonCallback cb, void * ctx) Register a double-click callback. |
| void | syn_button_on_long_press (SYN_Button * btn, SYN_ButtonCallback cb, uint16_t hold_ms, void * ctx) Register a long-press callback. |
| void | syn_button_on_multi_click (SYN_Button * btn, SYN_ButtonCallback cb, void * ctx) Register a multi-click (4+ taps) callback. |
| void | syn_button_on_press (SYN_Button * btn, SYN_ButtonCallback cb, void * ctx) Register a press callback. |
| void | syn_button_on_release (SYN_Button * btn, SYN_ButtonCallback cb, void * ctx) Register a release callback. |
| void | syn_button_on_repeat (SYN_Button * btn, SYN_ButtonCallback cb, uint16_t interval_ms, void * ctx) Register an auto-repeat callback. |
| void | syn_button_on_single_click (SYN_Button * btn, SYN_ButtonCallback cb, void * ctx) Register a single-click callback. |
| void | syn_button_on_triple_click (SYN_Button * btn, SYN_ButtonCallback cb, void * ctx) Register a triple-click callback. |
| void | syn_button_service (SYN_Button * buttons, size_t count) Service an array of buttons. |
| void | syn_button_set_click_window (SYN_Button * btn, uint16_t window_ms) Set the multi-click evaluation window in milliseconds. |
| void | syn_button_update (SYN_Button * btn) Update a single button's state machine. |
Public Static Functions¶
| Type | Name |
|---|---|
| void | action_bounce_back (void * ctx) FSM action: raw release during debounce → return to idle. |
| void | action_confirm_press (void * ctx) FSM action: debounce confirmed, fire press event. |
| void | action_long_press (void * ctx) FSM action: held long enough, fire long-press event. |
| void | action_release (void * ctx) FSM action: button released, fire release event. |
| void | action_start_debounce (void * ctx) FSM action: start debounce timer on raw press. |
| void | button_fire_event (SYN_Button * btn, uint8_t evt, SYN_ButtonCallback cb, void * ctx) Set an event flag and invoke the callback. |
| bool | button_read_raw (const SYN_Button * btn) Read the raw (debounce-agnostic) button state. |
Public Types Documentation¶
enum syn__button_8c_1a06fc87d81c62e9abb8790b6e5713c55b¶
enum syn__button_8c_1a06fc87d81c62e9abb8790b6e5713c55b {
BTN_EV_RAW_PRESS = 0,
BTN_EV_RAW_RELEASE,
BTN_EV_DEBOUNCE_OK,
BTN_EV_LONG_PRESS
};
Public Static Attributes Documentation¶
variable g_button_transitions¶
Button FSM transition table.
Public Functions Documentation¶
function syn_button_combo_init¶
Initialize a combination button descriptor.
void syn_button_combo_init (
SYN_ButtonCombo * combo,
const SYN_Button ** buttons,
size_t count,
SYN_ButtonCallback cb,
void * ctx
)
Fires callback when ALL specified buttons are simultaneously in debounced pressed state.
Parameters:
comboCombo descriptor.buttonsArray of pointers to initialized SYN_Button descriptors.countNumber of buttons in array.cbCombo callback.ctxUser context.
function syn_button_combo_update¶
Update a combination button descriptor.
Parameters:
comboCombo descriptor.
function syn_button_init¶
Initialize a button descriptor.
void syn_button_init (
SYN_Button * btn,
SYN_GPIO_Pin pin,
SYN_ButtonPolarity polarity,
uint16_t debounce_ms
)
Parameters:
btnButton to initialize.pinGPIO pin number.polarityActive-high or active-low.debounce_msDebounce window in milliseconds (e.g., 50).
function syn_button_on_double_click¶
Register a double-click callback.
Parameters:
btnButton.cbCallback (or NULL to disable).ctxUser context.
function syn_button_on_long_press¶
Register a long-press callback.
void syn_button_on_long_press (
SYN_Button * btn,
SYN_ButtonCallback cb,
uint16_t hold_ms,
void * ctx
)
Parameters:
btnButton.cbCallback (or NULL to disable).hold_msTime the button must be held before firing (ms).ctxUser context.
function syn_button_on_multi_click¶
Register a multi-click (4+ taps) callback.
Parameters:
btnButton.cbCallback (or NULL to disable).ctxUser context.
function syn_button_on_press¶
Register a press callback.
Parameters:
btnButton.cbCallback (or NULL to disable).ctxUser context.
function syn_button_on_release¶
Register a release callback.
Parameters:
btnButton.cbCallback (or NULL to disable).ctxUser context.
function syn_button_on_repeat¶
Register an auto-repeat callback.
void syn_button_on_repeat (
SYN_Button * btn,
SYN_ButtonCallback cb,
uint16_t interval_ms,
void * ctx
)
Fires repeatedly while the button is held, after the initial press.
Parameters:
btnButton.cbCallback (or NULL to disable).interval_msRepeat interval in milliseconds.ctxUser context.
function syn_button_on_single_click¶
Register a single-click callback.
Parameters:
btnButton.cbCallback (or NULL to disable).ctxUser context.
function syn_button_on_triple_click¶
Register a triple-click callback.
Parameters:
btnButton.cbCallback (or NULL to disable).ctxUser context.
function syn_button_service¶
Service an array of buttons.
Parameters:
buttonsArray of buttons.countNumber of buttons.
function syn_button_set_click_window¶
Set the multi-click evaluation window in milliseconds.
Parameters:
btnButton.window_msMax gap between taps to group into multi-clicks (default: 250ms, 0 = disable multi-click).
function syn_button_update¶
Update a single button's state machine.
Call this from your main loop, a scheduler task, or a timer callback. Reads the GPIO, runs debouncing, evaluates multi-clicks, and fires callbacks as needed.
Parameters:
btnButton to update.
Public Static Functions Documentation¶
function action_bounce_back¶
FSM action: raw release during debounce → return to idle.
Parameters:
ctxButton (as void*).
function action_confirm_press¶
FSM action: debounce confirmed, fire press event.
Parameters:
ctxButton (as void*).
function action_long_press¶
FSM action: held long enough, fire long-press event.
Parameters:
ctxButton (as void*).
function action_release¶
FSM action: button released, fire release event.
Parameters:
ctxButton (as void*).
function action_start_debounce¶
FSM action: start debounce timer on raw press.
Parameters:
ctxButton (as void*).
function button_fire_event¶
Set an event flag and invoke the callback.
Parameters:
btnButton instance.evtEvent bitmask.cbCallback (may be NULL).ctxUser context for callback.
function button_read_raw¶
Read the raw (debounce-agnostic) button state.
Parameters:
btnButton instance.
Returns:
true if the GPIO indicates pressed.
The documentation for this class was generated from the following file src/syntropic/input/syn_button.c