summaryrefslogtreecommitdiff
path: root/firmware/drivers/button.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/button.c')
-rw-r--r--firmware/drivers/button.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index 3e35e0eea4..5532ad4432 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -20,9 +20,38 @@
20 * Archos Jukebox Recorder button functions 20 * Archos Jukebox Recorder button functions
21 */ 21 */
22 22
23#include <stdlib.h>
23#include "config.h" 24#include "config.h"
24#include "sh7034.h" 25#include "sh7034.h"
25#include "button.h" 26#include "button.h"
27#include "kernel.h"
28
29static struct event_queue button_queue;
30
31#define POLL_FREQUENCY HZ/10
32
33static int button_read(void);
34
35static void button_tick(void)
36{
37 static int counter=0;
38
39 /* only poll every X ticks */
40 if ( counter++ > POLL_FREQUENCY ) {
41 int btn = button_read();
42 queue_post(&button_queue, btn, NULL);
43 counter=0;
44 }
45}
46
47int button_get(void)
48{
49 struct event ev;
50
51 if ( !queue_empty(&button_queue) )
52 queue_wait(&button_queue, &ev);
53 return ev.id;
54}
26 55
27#ifdef HAVE_RECORDER_KEYPAD 56#ifdef HAVE_RECORDER_KEYPAD
28 57
@@ -73,6 +102,8 @@ void button_init()
73#endif 102#endif
74 last = BUTTON_NONE; 103 last = BUTTON_NONE;
75 count = 0; 104 count = 0;
105 queue_init(&button_queue);
106 tick_add_task(button_tick);
76} 107}
77 108
78/* 109/*
@@ -119,7 +150,7 @@ static int get_raw_button (void)
119 * BUTTON_HELD bit is while the button is being held. 150 * BUTTON_HELD bit is while the button is being held.
120 * BUTTON_REL bit is set when button has been released. 151 * BUTTON_REL bit is set when button has been released.
121 */ 152 */
122int button_get(void) 153static int button_read(void)
123{ 154{
124 int btn = get_raw_button(); 155 int btn = get_raw_button();
125 int ret; 156 int ret;
@@ -162,9 +193,11 @@ void button_init(void)
162{ 193{
163 /* set port pins as input */ 194 /* set port pins as input */
164 PAIOR &= ~0x820; 195 PAIOR &= ~0x820;
196 queue_init(&button_queue);
197 tick_add_task(button_tick);
165} 198}
166 199
167int button_get(void) 200static int button_read(void)
168{ 201{
169 int porta = PADR; 202 int porta = PADR;
170 int portc = PCDR; 203 int portc = PCDR;