nRF Connect SDK Bare Metal API
2.0.99
Loading...
Searching...
No Matches
bm_buttons.h
1
/*
2
* Copyright (c) 2012-2025 Nordic Semiconductor ASA
3
*
4
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5
*/
6
21
#ifndef BM_BUTTONS_H__
22
#define BM_BUTTONS_H__
23
24
#include <stdint.h>
25
#include <stdbool.h>
26
27
#include <bm/bm_timer.h>
28
#include <nrfx_gpiote.h>
29
30
#ifdef __cplusplus
31
extern
"C"
{
32
#endif
33
39
#define BM_BUTTONS_DETECTION_DELAY_MIN_US \
40
(2 * k_ticks_to_us_ceil32(MAX(1, BM_TIMER_MIN_TIMEOUT_TICKS)))
41
42
enum
bm_buttons_evt_type
{
43
/* Indicates that a button is released. */
44
BM_BUTTONS_RELEASE
= 0,
45
/* Indicates that a button is pressed. */
46
BM_BUTTONS_PRESS
= 1
47
};
48
49
enum
bm_buttons_active_state
{
50
/* Indicates that a button is active low. */
51
BM_BUTTONS_ACTIVE_LOW
= 0,
52
/* Indicates that a button is active high. */
53
BM_BUTTONS_ACTIVE_HIGH
= 1
54
};
55
60
enum
bm_buttons_pin_pull
{
61
/* Pin pull-up resistor disabled. */
62
BM_BUTTONS_PIN_NOPULL
= NRF_GPIO_PIN_NOPULL,
63
/* Pin pull-down resistor enabled. */
64
BM_BUTTONS_PIN_PULLDOWN
= NRF_GPIO_PIN_PULLDOWN,
65
/* Pin pull-up resistor enabled. */
66
BM_BUTTONS_PIN_PULLUP
= NRF_GPIO_PIN_PULLUP,
67
};
68
72
typedef
void (*
bm_buttons_handler_t
)(uint8_t pin_number,
enum
bm_buttons_evt_type
action);
73
77
struct
bm_buttons_config
{
78
/* Pin to be used as a button. */
79
uint8_t
pin_number
;
80
/* BM_BUTTONS_ACTIVE_HIGH or BM_BUTTONS_ACTIVE_LOW. */
81
enum
bm_buttons_active_state
active_state
;
82
/* Pull-up or pull-down configuration. */
83
enum
bm_buttons_pin_pull
pull_config
;
84
/* Handler to be called when the button is pressed. */
85
bm_buttons_handler_t
handler
;
86
};
87
114
int
bm_buttons_init
(
const
struct
bm_buttons_config
*configs, uint8_t num_configs,
115
uint32_t detection_delay);
116
126
int
bm_buttons_deinit
(
void
);
127
134
int
bm_buttons_enable
(
void
);
135
143
int
bm_buttons_disable
(
void
);
144
152
bool
bm_buttons_is_pressed
(uint8_t pin);
153
154
#ifdef __cplusplus
155
}
156
#endif
157
158
#endif
/* BM_BUTTONS_H__ */
159
bm_buttons_pin_pull
bm_buttons_pin_pull
Enumerator used for selecting the pin to be pulled down or up at the time of pin configuration.
Definition
bm_buttons.h:60
BM_BUTTONS_PIN_PULLDOWN
@ BM_BUTTONS_PIN_PULLDOWN
Definition
bm_buttons.h:64
BM_BUTTONS_PIN_PULLUP
@ BM_BUTTONS_PIN_PULLUP
Definition
bm_buttons.h:66
BM_BUTTONS_PIN_NOPULL
@ BM_BUTTONS_PIN_NOPULL
Definition
bm_buttons.h:62
bm_buttons_disable
int bm_buttons_disable(void)
Disable button detection.
bm_buttons_init
int bm_buttons_init(const struct bm_buttons_config *configs, uint8_t num_configs, uint32_t detection_delay)
Initialize buttons.
bm_buttons_handler_t
void(* bm_buttons_handler_t)(uint8_t pin_number, enum bm_buttons_evt_type action)
Button event handler type.
Definition
bm_buttons.h:72
bm_buttons_deinit
int bm_buttons_deinit(void)
Deinitialize buttons.
bm_buttons_active_state
bm_buttons_active_state
Definition
bm_buttons.h:49
BM_BUTTONS_ACTIVE_HIGH
@ BM_BUTTONS_ACTIVE_HIGH
Definition
bm_buttons.h:53
BM_BUTTONS_ACTIVE_LOW
@ BM_BUTTONS_ACTIVE_LOW
Definition
bm_buttons.h:51
bm_buttons_enable
int bm_buttons_enable(void)
Enable button detection.
bm_buttons_evt_type
bm_buttons_evt_type
Definition
bm_buttons.h:42
BM_BUTTONS_PRESS
@ BM_BUTTONS_PRESS
Definition
bm_buttons.h:46
BM_BUTTONS_RELEASE
@ BM_BUTTONS_RELEASE
Definition
bm_buttons.h:44
bm_buttons_is_pressed
bool bm_buttons_is_pressed(uint8_t pin)
Check if a button is being pressed.
bm_buttons_config::pin_number
uint8_t pin_number
Definition
bm_buttons.h:79
bm_buttons_config::active_state
enum bm_buttons_active_state active_state
Definition
bm_buttons.h:81
bm_buttons_config::pull_config
enum bm_buttons_pin_pull pull_config
Definition
bm_buttons.h:83
bm_buttons_config::handler
bm_buttons_handler_t handler
Definition
bm_buttons.h:85
bm_buttons_config
Button configuration.
Definition
bm_buttons.h:77
include
bm
bm_buttons.h
Generated on Wed Jun 17 2026 10:54:29 for nRF Connect SDK Bare Metal API by
1.12.0