Skip to content

Commit 9556f2a

Browse files
committed
follow up to PR #77
1 parent ef4d0e7 commit 9556f2a

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/boards.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,20 @@
4242
//------------- IMPLEMENTATION -------------//
4343
void button_init(uint32_t pin)
4444
{
45-
if (BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN) {
45+
if ( BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN )
46+
{
4647
nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_HIGH);
47-
} else {
48+
}
49+
else
50+
{
4851
nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW);
4952
}
5053
}
5154

5255
bool button_pressed(uint32_t pin)
5356
{
54-
return (nrf_gpio_pin_read(pin) == BUTTON_DIR) ? true : false;
57+
uint32_t const active_state = (BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN ? 1 : 0);
58+
return nrf_gpio_pin_read(pin) == active_state;
5559
}
5660

5761
void board_init(void)

src/boards.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,10 @@
3535
#ifndef BUTTON_DFU
3636
#define BUTTON_DFU BUTTON_1
3737
#endif
38+
3839
#ifndef BUTTON_FRESET
3940
#define BUTTON_FRESET BUTTON_2
4041
#endif
41-
#ifndef BUTTON_DIR
42-
#if BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN
43-
#define BUTTON_DIR 1
44-
#elif BUTTON_PULL == NRF_GPIO_PIN_PULLUP
45-
#define BUTTON_DIR 0
46-
#endif
47-
#endif
4842

4943
// The primary LED is usually Red but not in all cases.
5044
#define LED_PRIMARY 0

0 commit comments

Comments
 (0)