GPS Device
Loading...
Searching...
No Matches
button.c File Reference

Button module implementation file. More...

#include "button.h"
#include "arm_cortex_m4_systick.h"
#include "cmd.h"
#include "common.h"
#include "err.h"
#include "stm32f401re_gpio.h"
#include "configuration.h"
#include "log.h"
#include "modules.h"
#include "init.h"
Include dependency graph for button.c:

Go to the source code of this file.

Classes

struct  button_handle_s
 Internal structure representing a single button instance. More...
struct  internal_state_s
 Internal state of the SysTick driver. More...

Functions

static ERR_te button_getpushed_handler (uint32_t argc, char **argv)
 CLI handler for the "getpushed" command. Reports the debounced pushed state of a button.
static ERR_te button_getheld_handler (uint32_t argc, char **argv)
 CLI handler for the "getheld" command. Reports the held state of a button.
static ERR_te button_cmd_info_handler (uint32_t argc, char **argv)
 CLI handler for the "info" command. Logs the names of all registered buttons.
ERR_te button_init_subsys (void)
 Initializes the button subsystem.
ERR_te button_deinit_subsys (void)
 Deinitializes the button subsystem.
ERR_te button_start_subsys (void)
 Starts the button subsystem.
ERR_te button_stop_subsys (void)
 Stops the button subsystem.
ERR_te button_init_handle (BUTTON_CFG_ts *button_cfg, BUTTON_HANDLE_ts **button_handle_o)
 Initializes and registers a button handle.
ERR_te button_deinit_handle (BUTTON_HANDLE_ts const *button_handle)
 Deinitializes a button handle.
ERR_te button_run_handle (BUTTON_HANDLE_ts *button_handle)
 Runs the state machine for a single button handle.
ERR_te button_run_handle_all (void)
 Runs the state machine for all registered button handles.
ERR_te button_get_pushed_state (BUTTON_HANDLE_ts const *button_handle, bool *pushed_state_o)
 Retrieves the pushed state of a button.
ERR_te button_get_held_state (BUTTON_HANDLE_ts const *button_handle, bool *held_state_o)
 Retrieves the held state of a button.

Variables

static struct internal_state_s internal_state
 Singleton instance of the button subsystem internal state.
static CMD_INFO_ts button_cmds []
 Table of CLI commands registered by the button subsystem.
static CMD_CLIENT_INFO_ts button_cmd_client_info
 Registration descriptor passed to the command subsystem.

Detailed Description

Button module implementation file.

Author
github.com/Baksi675
Version
0.1
Date
2026-01-09

Definition in file button.c.

Variable Documentation

◆ internal_state

struct internal_state_s internal_state
static

Singleton instance of the button subsystem internal state.

Definition at line 105 of file button.c.

◆ button_cmds

CMD_INFO_ts button_cmds[]
static
Initial value:
= {
{
.name = "getpushed",
.help = "Gets the pushed state, usage: button getpushed <button>",
},
{
.name = "getheld",
.help = "Gets the held state, usage: button getheld <button>",
},
{
.name = "info",
.help = "Shows button information, usage: button info",
}
}
static ERR_te button_cmd_info_handler(uint32_t argc, char **argv)
CLI handler for the "info" command. Logs the names of all registered buttons.
Definition button.c:692
static ERR_te button_getpushed_handler(uint32_t argc, char **argv)
CLI handler for the "getpushed" command. Reports the debounced pushed state of a button.
Definition button.c:574
static ERR_te button_getheld_handler(uint32_t argc, char **argv)
CLI handler for the "getheld" command. Reports the held state of a button.
Definition button.c:634

Table of CLI commands registered by the button subsystem.

Each entry maps a command name string to its handler and a short help string. The table is registered with the command subsystem via button_cmd_client_info during button_init_subsys.

Definition at line 120 of file button.c.

120 {
121 {
122 .name = "getpushed",
123 .help = "Gets the pushed state, usage: button getpushed <button>",
124 .handler = button_getpushed_handler
125 },
126 {
127 .name = "getheld",
128 .help = "Gets the held state, usage: button getheld <button>",
129 .handler = button_getheld_handler
130 },
131 {
132 .name = "info",
133 .help = "Shows button information, usage: button info",
134 .handler = button_cmd_info_handler
135 }
136};

◆ button_cmd_client_info

CMD_CLIENT_INFO_ts button_cmd_client_info
static
Initial value:
= {
.cmds_ptr = button_cmds,
.num_cmds = sizeof(button_cmds) / sizeof(button_cmds[0]),
.name = "button",
.log_level_ptr = &internal_state.log_level
}
static struct internal_state_s internal_state
Singleton instance of the SysTick driver internal state.
static CMD_INFO_ts button_cmds[]
Table of CLI commands registered by the button subsystem.
Definition button.c:120

Registration descriptor passed to the command subsystem.

Bundles the command table, its size, the subsystem name prefix used on the CLI, and a pointer to the runtime log-level variable so that the command subsystem can adjust verbosity at runtime.

Definition at line 146 of file button.c.

146 {
147 .cmds_ptr = button_cmds,
148 .num_cmds = sizeof(button_cmds) / sizeof(button_cmds[0]),
149 .name = "button",
150 .log_level_ptr = &internal_state.log_level
151};