summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2011-11-12 18:30:56 -0800
committerKeith Packard <keithp@keithp.com>2011-11-12 18:30:56 -0800
commit4de8bf6da4d725bb0514d032b0708c5cf420e8fa (patch)
treef3ebcb2dc916fa0703c6193268a718ae9a975bbe /src
parentad41b5820c2e252627959e4627473f07784be23e (diff)
altos: debounce buttons
Provide API to clear out any button events that happen during startup, and then discard button events 'too close' together. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src')
-rw-r--r--src/cc1111/ao_arch.h3
-rw-r--r--src/cc1111/ao_button.c19
2 files changed, 20 insertions, 2 deletions
diff --git a/src/cc1111/ao_arch.h b/src/cc1111/ao_arch.h
index 001165fa..eb8ce9be 100644
--- a/src/cc1111/ao_arch.h
+++ b/src/cc1111/ao_arch.h
@@ -231,6 +231,9 @@ ao_button_init(void);
char
ao_button_get(void) __critical;
+void
+ao_button_clear(void) __critical;
+
/* ao_string.c */
void
diff --git a/src/cc1111/ao_button.c b/src/cc1111/ao_button.c
index 77a8dde8..69f3475f 100644
--- a/src/cc1111/ao_button.c
+++ b/src/cc1111/ao_button.c
@@ -36,11 +36,17 @@ static __code struct {
#define NUM_BUTTONS ((sizeof ao_buttons) / sizeof (ao_buttons[0]))
+static __xdata uint16_t ao_button_tick[NUM_BUTTONS];
+
static void
ao_button_insert(char n)
{
- ao_fifo_insert(ao_button_fifo, n);
- ao_wakeup(&ao_button_fifo);
+ uint16_t now = ao_time();
+ if ((now - ao_button_tick[n]) > 20) {
+ ao_button_tick[n] = now;
+ ao_fifo_insert(ao_button_fifo, n);
+ ao_wakeup(&ao_button_fifo);
+ }
}
static void
@@ -78,6 +84,15 @@ ao_button_get(void) __critical
}
void
+ao_button_clear(void) __critical
+{
+ char b;
+
+ while (!ao_fifo_empty(ao_button_fifo))
+ ao_fifo_remove(ao_button_fifo, b);
+}
+
+void
ao_p0_isr(void) ao_arch_interrupt(13)
{
P0IF = 0;