From fa3f60ff1c772a93bd899ddad97cefeb0f6d5d51 Mon Sep 17 00:00:00 2001 From: Jörg Hohensohn Date: Thu, 1 Jan 2004 18:33:52 +0000 Subject: 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 --- firmware/drivers/button.c | 32 +++++++++++++++++++++----------- 1 file 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 @@ 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,22 +214,13 @@ 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; } -/* - * 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 */ @@ -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; -- cgit v1.2.3