diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2012-01-25 12:19:23 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2012-01-28 13:15:48 +0100 |
commit | a6c98a79b29e964268ab2debd7ebd7fd2daf709d (patch) | |
tree | 70bded30105f058e8d9ca75d4fc29d11ee6e2511 /src/target/firmware/calypso | |
parent | be142a0c2a7b18682775126a19203ab5411688a4 (diff) |
Hold function for power button to turn off the phone
In order to allow applications to use the power button, the keypad handler
will wait half a second if the key is pressed and hold, until the power
is turned off. This way the application does not need to handle it.
The power off function will then wait until the button is released, so the
phone will not start again while the button is still pressed.
Diffstat (limited to 'src/target/firmware/calypso')
-rw-r--r-- | src/target/firmware/calypso/keypad.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/target/firmware/calypso/keypad.c b/src/target/firmware/calypso/keypad.c index fd4e0ff2..f2dea9df 100644 --- a/src/target/firmware/calypso/keypad.c +++ b/src/target/firmware/calypso/keypad.c @@ -31,6 +31,7 @@ #include <calypso/irq.h> #include <abb/twl3025.h> +#include <comm/timer.h> #define KBR_LATCH_REG 0xfffe480a @@ -44,16 +45,13 @@ void emit_key(uint8_t key, uint8_t state) { printf("key=%u %s\n", key, state == PRESSED ? "pressed" : "released"); - if (state == RELEASED) - if (key == KEY_POWER) - twl3025_power_off(); - if(key_handler) { key_handler(key, state); } } volatile uint32_t lastbuttons = 0; +unsigned long power_hold = 0; #define BTN_TO_KEY(name) \ ((diff & BTN_##name) == BTN_##name) \ @@ -67,6 +65,17 @@ void dispatch_buttons(uint32_t buttons) { uint8_t state; + if ((buttons & BTN_POWER)) { + /* hold button 500ms to shut down */ + if ((lastbuttons & BTN_POWER)) { + unsigned long elapsed = jiffies - power_hold; + if (elapsed > 50) + twl3025_power_off(); + power_hold++; + } else + power_hold = jiffies; + } + if (buttons == lastbuttons) return; |