summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJörg Hohensohn <hohensoh@rockbox.org>2004-01-01 18:33:52 +0000
committerJörg Hohensohn <hohensoh@rockbox.org>2004-01-01 18:33:52 +0000
commitfa3f60ff1c772a93bd899ddad97cefeb0f6d5d51 (patch)
tree4779dfff548e86307ef4025756b3da3464a733df
parent74976c1484d7c8a89a290ffc7e4a7525874278b4 (diff)
downloadrockbox-fa3f60ff1c772a93bd899ddad97cefeb0f6d5d51.zip
rockbox-fa3f60ff1c772a93bd899ddad97cefeb0f6d5d51.tar.gz
rockbox-fa3f60ff1c772a93bd899ddad97cefeb0f6d5d51.tar.bz2
rockbox-fa3f60ff1c772a93bd899ddad97cefeb0f6d5d51.tar.xz
nicer handling of button_flip(), swap stored value, too, and avoid race condition
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4184 a1c6a512-1295-4272-9138-f99709370657
-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 cfe98e2..06c24e0 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -34,6 +34,7 @@
struct event_queue button_queue;
long last_keypress;
+static int lastbtn;
#ifdef HAVE_RECORDER_KEYPAD
static bool flipped; /* bottons can be flipped to match the LCD flip */
#endif
@@ -59,7 +60,6 @@ static void button_tick(void)
{
static int tick = 0;
static int count = 0;
- static int lastbtn = 0;
static int repeat_speed = REPEAT_INTERVAL_START;
static int repeat_count = 0;
static bool repeat = false;
@@ -214,6 +214,7 @@ void button_init()
PBIOR &= ~(PBDR_BTN_ON|PBDR_BTN_OFF); /* Inputs */
#endif
queue_init(&button_queue);
+ lastbtn = 0;
tick_add_task(button_tick);
last_keypress = current_tick;
flipped = false;
@@ -221,16 +222,6 @@ void button_init()
/*
- * set the flip attribute
- * better only call this when the queue is empty
- */
-void button_set_flip(bool flip)
-{
- flipped = flip;
-}
-
-
-/*
* helper function to swap UP/DOWN, LEFT/RIGHT, F1/F3
*/
static int button_flip(int button)
@@ -258,6 +249,23 @@ static int button_flip(int button)
return newbutton;
}
+
+/*
+ * set the flip attribute
+ * better only call this when the queue is empty
+ */
+void button_set_flip(bool flip)
+{
+ if (flip != flipped) /* not the curent setting */
+ {
+ cli(); /* avoid race condition with the button_tick() */
+ lastbtn = button_flip(lastbtn);
+ flipped = flip;
+ sti();
+ }
+}
+
+
/*
* Get button pressed from hardware
*/
@@ -347,6 +355,7 @@ void button_init(void)
/* set port pins as input */
PAIOR &= ~0x820;
queue_init(&button_queue);
+ lastbtn = 0;
tick_add_task(button_tick);
last_keypress = current_tick;
@@ -383,6 +392,7 @@ void button_init(void)
PAIOR &= ~0x4000; //PA14 for stop button
queue_init(&button_queue);
+ lastbtn = 0;
tick_add_task(button_tick);
last_keypress = current_tick;