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
31extern "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
43 /* Indicates that a button is released. */
45 /* Indicates that a button is pressed. */
47};
48
50 /* Indicates that a button is active low. */
52 /* Indicates that a button is active high. */
54};
55
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
72typedef void (*bm_buttons_handler_t)(uint8_t pin_number, enum bm_buttons_evt_type action);
73
78 /* Pin to be used as a button. */
79 uint8_t pin_number;
80 /* BM_BUTTONS_ACTIVE_HIGH or BM_BUTTONS_ACTIVE_LOW. */
82 /* Pull-up or pull-down configuration. */
84 /* Handler to be called when the button is pressed. */
86};
87
114int bm_buttons_init(const struct bm_buttons_config *configs, uint8_t num_configs,
115 uint32_t detection_delay);
116
127
135
144
152bool 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
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
Definition bm_buttons.h:64
@ BM_BUTTONS_PIN_PULLUP
Definition bm_buttons.h:66
@ BM_BUTTONS_PIN_NOPULL
Definition bm_buttons.h:62
int bm_buttons_disable(void)
Disable button detection.
int bm_buttons_init(const struct bm_buttons_config *configs, uint8_t num_configs, uint32_t detection_delay)
Initialize buttons.
void(* bm_buttons_handler_t)(uint8_t pin_number, enum bm_buttons_evt_type action)
Button event handler type.
Definition bm_buttons.h:72
int bm_buttons_deinit(void)
Deinitialize buttons.
bm_buttons_active_state
Definition bm_buttons.h:49
@ BM_BUTTONS_ACTIVE_HIGH
Definition bm_buttons.h:53
@ BM_BUTTONS_ACTIVE_LOW
Definition bm_buttons.h:51
int bm_buttons_enable(void)
Enable button detection.
bm_buttons_evt_type
Definition bm_buttons.h:42
@ BM_BUTTONS_PRESS
Definition bm_buttons.h:46
@ BM_BUTTONS_RELEASE
Definition bm_buttons.h:44
bool bm_buttons_is_pressed(uint8_t pin)
Check if a button is being pressed.
uint8_t pin_number
Definition bm_buttons.h:79
enum bm_buttons_active_state active_state
Definition bm_buttons.h:81
enum bm_buttons_pin_pull pull_config
Definition bm_buttons.h:83
bm_buttons_handler_t handler
Definition bm_buttons.h:85
Button configuration.
Definition bm_buttons.h:77