Skip to content

Commit fc00e2b

Browse files
authored
Merge pull request #77 from khanning/button-dir-fix
Add check for button direction
2 parents c751975 + 8906b2a commit fc00e2b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/boards.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@
4242
//------------- IMPLEMENTATION -------------//
4343
void button_init(uint32_t pin)
4444
{
45-
nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW);
45+
if (BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN) {
46+
nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_HIGH);
47+
} else {
48+
nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW);
49+
}
4650
}
4751

4852
bool button_pressed(uint32_t pin)
4953
{
50-
return (nrf_gpio_pin_read(pin) == 0) ? true : false;
54+
return (nrf_gpio_pin_read(pin) == BUTTON_DIR) ? true : false;
5155
}
5256

5357
void board_init(void)

src/boards.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
#ifndef BUTTON_FRESET
3939
#define BUTTON_FRESET BUTTON_2
4040
#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
4148

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

0 commit comments

Comments
 (0)