diff options
Diffstat (limited to 'firmware/drivers/button.c')
-rw-r--r-- | firmware/drivers/button.c | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 64668b4ebf..608fe7e33a 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -59,6 +59,9 @@ static bool remote_filter_first_keypress; | |||
59 | #ifdef HAVE_HEADPHONE_DETECTION | 59 | #ifdef HAVE_HEADPHONE_DETECTION |
60 | static bool phones_present = false; | 60 | static bool phones_present = false; |
61 | #endif | 61 | #endif |
62 | #ifdef HAVE_LINEOUT_DETECTION | ||
63 | static bool lineout_present = false; | ||
64 | #endif | ||
62 | 65 | ||
63 | /* how long until repeat kicks in, in centiseconds */ | 66 | /* how long until repeat kicks in, in centiseconds */ |
64 | #define REPEAT_START (30*HZ/100) | 67 | #define REPEAT_START (30*HZ/100) |
@@ -94,12 +97,11 @@ static int button_read(void); | |||
94 | 97 | ||
95 | #ifdef HAVE_TOUCHSCREEN | 98 | #ifdef HAVE_TOUCHSCREEN |
96 | static int last_touchscreen_touch; | 99 | static int last_touchscreen_touch; |
97 | #endif | 100 | #endif |
98 | #if defined(HAVE_HEADPHONE_DETECTION) | 101 | #if defined(HAVE_HEADPHONE_DETECTION) |
99 | static struct timeout hp_detect_timeout; /* Debouncer for headphone plug/unplug */ | 102 | static struct timeout hp_detect_timeout; /* Debouncer for headphone plug/unplug */ |
100 | /* This callback can be used for many different functions if needed - | 103 | |
101 | just check to which object tmo points */ | 104 | static int hp_detect_callback(struct timeout *tmo) |
102 | static int btn_detect_callback(struct timeout *tmo) | ||
103 | { | 105 | { |
104 | /* Try to post only transistions */ | 106 | /* Try to post only transistions */ |
105 | const long id = tmo->data ? SYS_PHONE_PLUGGED : SYS_PHONE_UNPLUGGED; | 107 | const long id = tmo->data ? SYS_PHONE_PLUGGED : SYS_PHONE_UNPLUGGED; |
@@ -109,6 +111,19 @@ static int btn_detect_callback(struct timeout *tmo) | |||
109 | } | 111 | } |
110 | #endif | 112 | #endif |
111 | 113 | ||
114 | #if defined(HAVE_LINEOUT_DETECTION) | ||
115 | static struct timeout lo_detect_timeout; /* Debouncer for lineout plug/unplug */ | ||
116 | |||
117 | static int lo_detect_callback(struct timeout *tmo) | ||
118 | { | ||
119 | /* Try to post only transistions */ | ||
120 | const long id = tmo->data ? SYS_LINEOUT_PLUGGED : SYS_LINEOUT_UNPLUGGED; | ||
121 | queue_remove_from_head(&button_queue, id); | ||
122 | queue_post(&button_queue, id, 0); | ||
123 | return 0; | ||
124 | } | ||
125 | #endif | ||
126 | |||
112 | static bool button_try_post(int button, int data) | 127 | static bool button_try_post(int button, int data) |
113 | { | 128 | { |
114 | #ifdef HAVE_TOUCHSCREEN | 129 | #ifdef HAVE_TOUCHSCREEN |
@@ -176,10 +191,19 @@ static void button_tick(void) | |||
176 | { | 191 | { |
177 | /* Use the autoresetting oneshot to debounce the detection signal */ | 192 | /* Use the autoresetting oneshot to debounce the detection signal */ |
178 | phones_present = !phones_present; | 193 | phones_present = !phones_present; |
179 | timeout_register(&hp_detect_timeout, btn_detect_callback, | 194 | timeout_register(&hp_detect_timeout, hp_detect_callback, |
180 | HZ/2, phones_present); | 195 | HZ/2, phones_present); |
181 | } | 196 | } |
182 | #endif | 197 | #endif |
198 | #if defined(HAVE_LINEOUT_DETECTION) | ||
199 | if (lineout_inserted() != lineout_present) | ||
200 | { | ||
201 | /* Use the autoresetting oneshot to debounce the detection signal */ | ||
202 | lineout_present = !lineout_present; | ||
203 | timeout_register(&lo_detect_timeout, lo_detect_callback, | ||
204 | HZ/2, lineout_present); | ||
205 | } | ||
206 | #endif | ||
183 | 207 | ||
184 | /* Find out if a key has been released */ | 208 | /* Find out if a key has been released */ |
185 | diff = btn ^ lastbtn; | 209 | diff = btn ^ lastbtn; |
@@ -318,7 +342,7 @@ static void button_tick(void) | |||
318 | #ifdef HAVE_BACKLIGHT | 342 | #ifdef HAVE_BACKLIGHT |
319 | #ifdef HAVE_REMOTE_LCD | 343 | #ifdef HAVE_REMOTE_LCD |
320 | if (btn & BUTTON_REMOTE) { | 344 | if (btn & BUTTON_REMOTE) { |
321 | if (!remote_filter_first_keypress | 345 | if (!remote_filter_first_keypress |
322 | || is_remote_backlight_on(false) | 346 | || is_remote_backlight_on(false) |
323 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) | 347 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) |
324 | || (remote_type()==REMOTETYPE_H300_NONLCD) | 348 | || (remote_type()==REMOTETYPE_H300_NONLCD) |
@@ -427,7 +451,7 @@ static void button_queue_wait(struct queue_event *evp, int timeout) | |||
427 | #endif | 451 | #endif |
428 | button_boost(true); | 452 | button_boost(true); |
429 | 453 | ||
430 | break; | 454 | break; |
431 | } | 455 | } |
432 | 456 | ||
433 | if (button_boosted && TIME_AFTER(current_tick, button_unboost_tick)) | 457 | if (button_boosted && TIME_AFTER(current_tick, button_unboost_tick)) |
@@ -462,7 +486,7 @@ long button_get(bool block) | |||
462 | 486 | ||
463 | long button_get_w_tmo(int ticks) | 487 | long button_get_w_tmo(int ticks) |
464 | { | 488 | { |
465 | struct queue_event ev; | 489 | struct queue_event ev; |
466 | button_queue_wait(&ev, ticks); | 490 | button_queue_wait(&ev, ticks); |
467 | 491 | ||
468 | if (ev.id == SYS_TIMEOUT) | 492 | if (ev.id == SYS_TIMEOUT) |
@@ -496,7 +520,7 @@ void button_init(void) | |||
496 | button_read(); | 520 | button_read(); |
497 | lastbtn = button_read(); | 521 | lastbtn = button_read(); |
498 | #endif | 522 | #endif |
499 | 523 | ||
500 | reset_poweroff_timer(); | 524 | reset_poweroff_timer(); |
501 | 525 | ||
502 | #ifdef HAVE_LCD_BITMAP | 526 | #ifdef HAVE_LCD_BITMAP |
@@ -506,11 +530,11 @@ void button_init(void) | |||
506 | filter_first_keypress = false; | 530 | filter_first_keypress = false; |
507 | #ifdef HAVE_REMOTE_LCD | 531 | #ifdef HAVE_REMOTE_LCD |
508 | remote_filter_first_keypress = false; | 532 | remote_filter_first_keypress = false; |
509 | #endif | 533 | #endif |
510 | #endif | 534 | #endif |
511 | #ifdef HAVE_TOUCHSCREEN | 535 | #ifdef HAVE_TOUCHSCREEN |
512 | last_touchscreen_touch = 0xffff; | 536 | last_touchscreen_touch = 0xffff; |
513 | #endif | 537 | #endif |
514 | /* Start polling last */ | 538 | /* Start polling last */ |
515 | tick_add_task(button_tick); | 539 | tick_add_task(button_tick); |
516 | } | 540 | } |
@@ -647,7 +671,7 @@ static int button_read(void) | |||
647 | #ifdef HAVE_TOUCHSCREEN | 671 | #ifdef HAVE_TOUCHSCREEN |
648 | if (btn & BUTTON_TOUCHSCREEN) | 672 | if (btn & BUTTON_TOUCHSCREEN) |
649 | last_touchscreen_touch = current_tick; | 673 | last_touchscreen_touch = current_tick; |
650 | #endif | 674 | #endif |
651 | /* Filter the button status. It is only accepted if we get the same | 675 | /* Filter the button status. It is only accepted if we get the same |
652 | status twice in a row. */ | 676 | status twice in a row. */ |
653 | #ifndef HAVE_TOUCHSCREEN | 677 | #ifndef HAVE_TOUCHSCREEN |
@@ -696,8 +720,8 @@ int touchscreen_last_touch(void) | |||
696 | * [23:0] Velocity - degree/sec | 720 | * [23:0] Velocity - degree/sec |
697 | * | 721 | * |
698 | * WHEEL_ACCEL_FACTOR: | 722 | * WHEEL_ACCEL_FACTOR: |
699 | * Value in degree/sec -- configurable via settings -- above which | 723 | * Value in degree/sec -- configurable via settings -- above which |
700 | * the accelerated scrolling starts. Factor is internally scaled by | 724 | * the accelerated scrolling starts. Factor is internally scaled by |
701 | * 1<<16 in respect to the following 32bit integer operations. | 725 | * 1<<16 in respect to the following 32bit integer operations. |
702 | */ | 726 | */ |
703 | int button_apply_acceleration(const unsigned int data) | 727 | int button_apply_acceleration(const unsigned int data) |