Merge pull request #77 from khanning/button-dir-fix

Add check for button direction
This commit is contained in:
hathach 2019-09-25 11:55:20 +07:00 committed by GitHub
commit fc00e2b202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -42,12 +42,16 @@
//------------- IMPLEMENTATION -------------//
void button_init(uint32_t pin)
{
nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW);
if (BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN) {
nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_HIGH);
} 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) == 0) ? true : false;
return (nrf_gpio_pin_read(pin) == BUTTON_DIR) ? true : false;
}
void board_init(void)

View File

@ -38,6 +38,13 @@
#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