From 9556f2ace847cde9b2d4fdc9e528bb2619db854c Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 25 Sep 2019 12:17:46 +0700 Subject: [PATCH] follow up to PR #77 --- src/boards.c | 10 +++++++--- src/boards.h | 8 +------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/boards.c b/src/boards.c index c33e94f..3b03081 100644 --- a/src/boards.c +++ b/src/boards.c @@ -42,16 +42,20 @@ //------------- IMPLEMENTATION -------------// void button_init(uint32_t pin) { - if (BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN) { + if ( BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN ) + { nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_HIGH); - } else { + } + else + { nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW); } } bool button_pressed(uint32_t pin) { - return (nrf_gpio_pin_read(pin) == BUTTON_DIR) ? true : false; + uint32_t const active_state = (BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN ? 1 : 0); + return nrf_gpio_pin_read(pin) == active_state; } void board_init(void) diff --git a/src/boards.h b/src/boards.h index 48db99c..852f5fd 100644 --- a/src/boards.h +++ b/src/boards.h @@ -35,16 +35,10 @@ #ifndef BUTTON_DFU #define BUTTON_DFU BUTTON_1 #endif + #ifndef BUTTON_FRESET #define BUTTON_FRESET BUTTON_2 #endif -#ifndef BUTTON_DIR -#if BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN - #define BUTTON_DIR 1 -#elif BUTTON_PULL == NRF_GPIO_PIN_PULLUP - #define BUTTON_DIR 0 -#endif -#endif // The primary LED is usually Red but not in all cases. #define LED_PRIMARY 0