From 23f2a59865ef4752d943decd4c48aede12c737cc Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Thu, 23 Sep 2004 22:36:15 +0000 Subject: [PATCH] Added debouncing to the Ondio button driver. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5115 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/button.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 6e4106fbae..ebe3389454 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c @@ -458,6 +458,8 @@ void button_init(void) static int button_read(void) { int btn = BUTTON_NONE; + int retval; + int data = adc_read(ADC_BUTTON_ROW1); if(adc_read(ADC_BUTTON_OPTION) > 0x200) /* active high */ @@ -475,7 +477,15 @@ static int button_read(void) else if (data >= 0x0A1) btn |= BUTTON_DOWN; - return btn; + /* Filter the button status. It is only accepted if we get the same + status twice in a row. */ + if(btn != last_read) + retval = lastbtn; + else + retval = btn; + last_read = btn; + + return retval; } #endif