Skip to content

Commit a184e32

Browse files
committed
[nrf noup] boot: zephyr: Fix bm IO button check
nrf-squash! [nrf noup] boot: zephyr: Add bm firmware loader code Fixes IO in BM mode to use the hal directly rather than a library that increases the build size by 2.5KiB for a simple button check Signed-off-by: Jamie McCrae <[email protected]>
1 parent bc5eb3f commit a184e32

File tree

1 file changed

+9
-36
lines changed

1 file changed

+9
-36
lines changed

boot/zephyr/io_bm.c

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,13 @@ void io_led_set(int value)
8989

9090
bool io_detect_pin(void)
9191
{
92-
int rc;
9392
bool pin_active;
9493

95-
rc = bm_buttons_init(
96-
&(struct bm_buttons_config){
97-
.pin_number = BOARD_PIN_BTN_0,
98-
.active_state = BM_BUTTONS_ACTIVE_LOW,
99-
.pull_config = BM_BUTTONS_PIN_PULLUP,
100-
},
101-
1,
102-
BM_BUTTONS_DETECTION_DELAY_MIN_US);
103-
if (rc) {
104-
BOOT_LOG_ERR("Failed to initialize buttons: %d", rc);
105-
return false;
106-
}
94+
nrf_gpio_cfg_input(BOARD_PIN_BTN_0, BM_BUTTONS_PIN_PULLUP);
10795

108-
rc = bm_buttons_enable();
109-
if (rc) {
110-
BOOT_LOG_ERR("Failed to enable button detection: %d", rc);
111-
return false;
112-
}
96+
pin_active = (bool)nrf_gpio_pin_read(BOARD_PIN_BTN_0);
11397

114-
pin_active = bm_buttons_is_pressed(BOARD_PIN_BTN_0);
115-
116-
if (pin_active) {
98+
if (!pin_active) {
11799
if (BUTTON_0_DETECT_DELAY > 0) {
118100
#ifdef CONFIG_MULTITHREADING
119101
k_sleep(K_MSEC(50));
@@ -125,13 +107,15 @@ bool io_detect_pin(void)
125107
int64_t timestamp = k_uptime_get();
126108

127109
for(;;) {
128-
pin_active = bm_buttons_is_pressed(BOARD_PIN_BTN_0);
110+
uint32_t delta;
111+
112+
pin_active = (bool)nrf_gpio_pin_read(BOARD_PIN_BTN_0);
129113

130114
/* Get delta from when this started */
131-
uint32_t delta = k_uptime_get() - timestamp;
115+
delta = k_uptime_get() - timestamp;
132116

133117
/* If not pressed OR if pressed > debounce period, stop. */
134-
if (delta >= BUTTON_0_DETECT_DELAY || !pin_active) {
118+
if (delta >= BUTTON_0_DETECT_DELAY || pin_active) {
135119
break;
136120
}
137121

@@ -145,18 +129,7 @@ bool io_detect_pin(void)
145129
}
146130
}
147131

148-
rc = bm_buttons_disable();
149-
150-
if (rc) {
151-
BOOT_LOG_ERR("Failed to disable buttons: %d", rc);
152-
}
153-
154-
rc = bm_buttons_deinit();
155-
if (rc) {
156-
BOOT_LOG_ERR("Failed to de-initialize buttons: %d", rc);
157-
}
158-
159-
return (bool)pin_active;
132+
return (bool)!pin_active;
160133
}
161134
#endif
162135

0 commit comments

Comments
 (0)