1
0
Fork 0

boards: Add support for active high buttons

The button on the PineTime isn't a simple pull low design. Instead
the switch is connected across two GPIO pins *and* has external
pull downs on both pins. This circuit requires special handling since
it must be active high and we need to configure the other pin as an
output for the pin to work correctly.
wasp-os-next
Daniel Thompson 2020-01-18 20:53:15 +00:00
parent 282fd12bba
commit 1d2dfa955d
2 changed files with 17 additions and 11 deletions

View File

@ -42,20 +42,22 @@
//------------- IMPLEMENTATION -------------//
void button_init(uint32_t pin)
{
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);
}
nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW);
#ifdef BUTTON_ENABLE
/*
* BUTTON_ENABLE is used when a switch is connected to another GPIO pin
* rather than the Vcc or ground. In the bootloader we'll just permanently
* push the enable pin to whatever value the sense pin thinks is the
* active one.
*/
nrf_gpio_cfg_output(BUTTON_ENABLE);
nrf_gpio_pin_write(BUTTON_ENABLE, BUTTON_ACTIVE);
#endif
}
bool button_pressed(uint32_t pin)
{
uint32_t const active_state = (BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN ? 1 : 0);
return nrf_gpio_pin_read(pin) == active_state;
return (nrf_gpio_pin_read(pin) == BUTTON_ACTIVE) ? true : false;
}
void board_init(void)
@ -68,7 +70,7 @@ void board_init(void)
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
button_init(BUTTON_DFU);
#ifndef BUTTON_FRESET
#ifdef BUTTON_FRESET
button_init(BUTTON_FRESET);
#endif
NRFX_DELAY_US(100); // wait for the pin state is stable

View File

@ -39,6 +39,10 @@
#if !defined(BUTTON_FRESET) && BUTTONS_NUMBER > 1
#define BUTTON_FRESET BUTTON_2
#endif
#ifndef BUTTON_ACTIVE
/* default to active-low signals */
#define BUTTON_ACTIVE 0
#endif
// The primary LED is usually Red but not in all cases.
#define LED_PRIMARY 0