diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/button.c | 51 |
1 files changed, 2 insertions, 49 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index d3fe8e0a98..16a5494e63 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -30,7 +30,7 @@ static struct event_queue button_queue; | |||
30 | 30 | ||
31 | #define POLL_FREQUENCY HZ/10 | 31 | #define POLL_FREQUENCY HZ/10 |
32 | #define REPEAT_START 3 | 32 | #define REPEAT_START 3 |
33 | #define REPEAT_INTERVAL 3 | 33 | #define REPEAT_INTERVAL 2 |
34 | 34 | ||
35 | static int button_read(void); | 35 | static int button_read(void); |
36 | 36 | ||
@@ -105,17 +105,6 @@ int button_get(bool block) | |||
105 | #define LEVEL3 175 | 105 | #define LEVEL3 175 |
106 | #define LEVEL4 225 | 106 | #define LEVEL4 225 |
107 | 107 | ||
108 | /* Number of calls to get_button for a button to stop bouncing | ||
109 | * and to be considered held down. | ||
110 | * Should really use a hardware timer for this. | ||
111 | */ | ||
112 | #define BOUNCE_COUNT 200 | ||
113 | #define HOLD_COUNT 10000 | ||
114 | |||
115 | static int last; /* Last button pressed */ | ||
116 | static int count; /* Number of calls button has been down */ | ||
117 | |||
118 | |||
119 | /* | 108 | /* |
120 | *Initialize buttons | 109 | *Initialize buttons |
121 | */ | 110 | */ |
@@ -134,8 +123,6 @@ void button_init() | |||
134 | ADCR = 0; | 123 | ADCR = 0; |
135 | ADCSR = ADCSR_ADST | ADCSR_SCAN | 0x5; | 124 | ADCSR = ADCSR_ADST | ADCSR_SCAN | 0x5; |
136 | #endif | 125 | #endif |
137 | last = BUTTON_NONE; | ||
138 | count = 0; | ||
139 | queue_init(&button_queue); | 126 | queue_init(&button_queue); |
140 | tick_add_task(button_tick); | 127 | tick_add_task(button_tick); |
141 | } | 128 | } |
@@ -143,7 +130,7 @@ void button_init() | |||
143 | /* | 130 | /* |
144 | * Get button pressed from hardware | 131 | * Get button pressed from hardware |
145 | */ | 132 | */ |
146 | static int get_raw_button (void) | 133 | static int button_read(void) |
147 | { | 134 | { |
148 | /* Check port B pins for ON and OFF */ | 135 | /* Check port B pins for ON and OFF */ |
149 | int data = PBDR; | 136 | int data = PBDR; |
@@ -177,40 +164,6 @@ static int get_raw_button (void) | |||
177 | return BUTTON_NONE; | 164 | return BUTTON_NONE; |
178 | } | 165 | } |
179 | 166 | ||
180 | /* | ||
181 | * Get the currently pressed button. | ||
182 | * Returns one of BUTTON_xxx codes, with possibly a modifier bit set. | ||
183 | * No modifier bits are set when the button is first pressed. | ||
184 | * BUTTON_HELD bit is while the button is being held. | ||
185 | * BUTTON_REL bit is set when button has been released. | ||
186 | */ | ||
187 | static int button_read(void) | ||
188 | { | ||
189 | int btn = get_raw_button(); | ||
190 | int ret; | ||
191 | |||
192 | /* Last button pressed is still down */ | ||
193 | if (btn != BUTTON_NONE && btn == last) { | ||
194 | count++; | ||
195 | if (count == BOUNCE_COUNT) | ||
196 | return btn; | ||
197 | else if (count >= HOLD_COUNT) | ||
198 | return btn | BUTTON_HELD; | ||
199 | else | ||
200 | return BUTTON_NONE; | ||
201 | } | ||
202 | |||
203 | /* Last button pressed now released */ | ||
204 | if (btn == BUTTON_NONE && last != BUTTON_NONE) | ||
205 | ret = last | BUTTON_REL; | ||
206 | else | ||
207 | ret = BUTTON_NONE; | ||
208 | |||
209 | last = btn; | ||
210 | count = 0; | ||
211 | return ret; | ||
212 | } | ||
213 | |||
214 | #elif HAVE_PLAYER_KEYPAD | 167 | #elif HAVE_PLAYER_KEYPAD |
215 | 168 | ||
216 | /* The player has all buttons on port pins: | 169 | /* The player has all buttons on port pins: |