summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/drivers/button.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index cfe98e298a..06c24e0e45 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -34,6 +34,7 @@
34struct event_queue button_queue; 34struct event_queue button_queue;
35 35
36long last_keypress; 36long last_keypress;
37static int lastbtn;
37#ifdef HAVE_RECORDER_KEYPAD 38#ifdef HAVE_RECORDER_KEYPAD
38static bool flipped; /* bottons can be flipped to match the LCD flip */ 39static bool flipped; /* bottons can be flipped to match the LCD flip */
39#endif 40#endif
@@ -59,7 +60,6 @@ static void button_tick(void)
59{ 60{
60 static int tick = 0; 61 static int tick = 0;
61 static int count = 0; 62 static int count = 0;
62 static int lastbtn = 0;
63 static int repeat_speed = REPEAT_INTERVAL_START; 63 static int repeat_speed = REPEAT_INTERVAL_START;
64 static int repeat_count = 0; 64 static int repeat_count = 0;
65 static bool repeat = false; 65 static bool repeat = false;
@@ -214,6 +214,7 @@ void button_init()
214 PBIOR &= ~(PBDR_BTN_ON|PBDR_BTN_OFF); /* Inputs */ 214 PBIOR &= ~(PBDR_BTN_ON|PBDR_BTN_OFF); /* Inputs */
215#endif 215#endif
216 queue_init(&button_queue); 216 queue_init(&button_queue);
217 lastbtn = 0;
217 tick_add_task(button_tick); 218 tick_add_task(button_tick);
218 last_keypress = current_tick; 219 last_keypress = current_tick;
219 flipped = false; 220 flipped = false;
@@ -221,16 +222,6 @@ void button_init()
221 222
222 223
223/* 224/*
224 * set the flip attribute
225 * better only call this when the queue is empty
226 */
227void button_set_flip(bool flip)
228{
229 flipped = flip;
230}
231
232
233/*
234 * helper function to swap UP/DOWN, LEFT/RIGHT, F1/F3 225 * helper function to swap UP/DOWN, LEFT/RIGHT, F1/F3
235 */ 226 */
236static int button_flip(int button) 227static int button_flip(int button)
@@ -258,6 +249,23 @@ static int button_flip(int button)
258 return newbutton; 249 return newbutton;
259} 250}
260 251
252
253/*
254 * set the flip attribute
255 * better only call this when the queue is empty
256 */
257void button_set_flip(bool flip)
258{
259 if (flip != flipped) /* not the curent setting */
260 {
261 cli(); /* avoid race condition with the button_tick() */
262 lastbtn = button_flip(lastbtn);
263 flipped = flip;
264 sti();
265 }
266}
267
268
261/* 269/*
262 * Get button pressed from hardware 270 * Get button pressed from hardware
263 */ 271 */
@@ -347,6 +355,7 @@ void button_init(void)
347 /* set port pins as input */ 355 /* set port pins as input */
348 PAIOR &= ~0x820; 356 PAIOR &= ~0x820;
349 queue_init(&button_queue); 357 queue_init(&button_queue);
358 lastbtn = 0;
350 tick_add_task(button_tick); 359 tick_add_task(button_tick);
351 360
352 last_keypress = current_tick; 361 last_keypress = current_tick;
@@ -383,6 +392,7 @@ void button_init(void)
383 PAIOR &= ~0x4000; //PA14 for stop button 392 PAIOR &= ~0x4000; //PA14 for stop button
384 393
385 queue_init(&button_queue); 394 queue_init(&button_queue);
395 lastbtn = 0;
386 tick_add_task(button_tick); 396 tick_add_task(button_tick);
387 397
388 last_keypress = current_tick; 398 last_keypress = current_tick;