summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2019-08-12 17:30:48 -0700
committerKeith Packard <keithp@keithp.com>2019-08-12 17:30:48 -0700
commitfcb5d55e94058810fc8b31ad5e8caa99fa61200c (patch)
tree3f2192b8ca74fdfc5fa68e6cc59ee294dd02e315
parent5e738fd2e3602c6a92f205df99361dbe06c1719e (diff)
altos: Use fast timer for buttons instead of edge-triggered ISR
If the button bounces between the triggering interrupt and the button state check, we could lose the final state change of the button and send an incorrect event to the application. In the worst case, the button would end up in exactly the wrong state, toggling in the wrong direction. Use the fast timer to poll all buttons instead so that there is only one check of each button at each poll interval (instead of the interrupt and the state check). This makes buttons reliably debounced. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--src/drivers/ao_button.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/drivers/ao_button.c b/src/drivers/ao_button.c
index c8103e88..53728bce 100644
--- a/src/drivers/ao_button.c
+++ b/src/drivers/ao_button.c
@@ -19,6 +19,7 @@
#include <ao.h>
#include <ao_button.h>
#include <ao_exti.h>
+#include <ao_fast_timer.h>
#if AO_EVENT
#include <ao_event.h>
#define ao_button_queue(b,v) ao_event_put_isr(AO_EVENT_BUTTON, b, v)
@@ -149,12 +150,7 @@ ao_button_isr(void)
}
#define init(b) do { \
- ao_enable_port(port(b)); \
- \
- ao_exti_setup(port(b), bit(b), \
- AO_BUTTON_MODE|AO_EXTI_MODE_FALLING|AO_EXTI_MODE_RISING|AO_EXTI_PRIORITY_MED, \
- ao_button_isr); \
- ao_exti_enable(port(b), bit(b)); \
+ ao_enable_input(port(b), bit(b), AO_BUTTON_MODE); \
_ao_button_init(b); \
} while (0)
@@ -212,4 +208,6 @@ ao_button_init(void)
#if AO_BUTTON_COUNT > 16
#error too many buttons
#endif
+ ao_fast_timer_init();
+ ao_fast_timer_on(ao_button_isr);
}