diff options
-rw-r--r-- | firmware/backlight.c | 11 | ||||
-rw-r--r-- | firmware/drivers/button.c | 210 | ||||
-rw-r--r-- | firmware/export/backlight.h | 4 |
3 files changed, 119 insertions, 106 deletions
diff --git a/firmware/backlight.c b/firmware/backlight.c index 9ee84b0ca4..9c7a16808c 100644 --- a/firmware/backlight.c +++ b/firmware/backlight.c | |||
@@ -1065,3 +1065,14 @@ void buttonlight_set_brightness(int val) { (void)val; } | |||
1065 | #endif /* HAVE_BUTTON_LIGHT */ | 1065 | #endif /* HAVE_BUTTON_LIGHT */ |
1066 | 1066 | ||
1067 | #endif /* defined(HAVE_BACKLIGHT) && defined(BACKLIGHT_FULL_INIT) */ | 1067 | #endif /* defined(HAVE_BACKLIGHT) && defined(BACKLIGHT_FULL_INIT) */ |
1068 | |||
1069 | #ifndef HAVE_BUTTON_LIGHT /* Dummy Functions */ | ||
1070 | void buttonlight_on(void) {} | ||
1071 | void buttonlight_on_ignore(bool value, int timeout){(void)value;(void)timeout;} | ||
1072 | void buttonlight_off(void) {} | ||
1073 | void buttonlight_set_timeout(int value) {(void)value;} | ||
1074 | #endif /* ndef HAVE_BUTTON_LIGHT */ | ||
1075 | |||
1076 | #ifndef HAVE_BUTTONLIGHT_BRIGHTNESS /* Dummy Functions */ | ||
1077 | void buttonlight_set_brightness(int val) { (void)val; } | ||
1078 | #endif /* ndef HAVE_BUTTONLIGHT_BRIGHTNESS */ | ||
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 9979bc0155..3220f18ed7 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -51,18 +51,14 @@ static long lastbtn; /* Last valid button status */ | |||
51 | static long last_read; /* Last button status, for debouncing/filtering */ | 51 | static long last_read; /* Last button status, for debouncing/filtering */ |
52 | static intptr_t button_data; /* data value from last message dequeued */ | 52 | static intptr_t button_data; /* data value from last message dequeued */ |
53 | static bool flipped; /* buttons can be flipped to match the LCD flip */ | 53 | static bool flipped; /* buttons can be flipped to match the LCD flip */ |
54 | #ifdef HAVE_BACKLIGHT | 54 | |
55 | static bool filter_first_keypress; | 55 | #ifdef HAVE_BACKLIGHT /* Filter first keypress function pointer */ |
56 | static bool (*keypress_filter_fn)(int, int); | ||
56 | #ifdef HAVE_REMOTE_LCD | 57 | #ifdef HAVE_REMOTE_LCD |
57 | static bool remote_filter_first_keypress; | 58 | static bool (*remote_keypress_filter_fn)(int, int); |
58 | #endif | 59 | #endif |
59 | #endif /* HAVE_BACKLIGHT */ | 60 | #endif /* HAVE_BACKLIGHT */ |
60 | #ifdef HAVE_HEADPHONE_DETECTION | 61 | |
61 | static bool phones_present = false; | ||
62 | #endif | ||
63 | #ifdef HAVE_LINEOUT_DETECTION | ||
64 | static bool lineout_present = false; | ||
65 | #endif | ||
66 | #ifdef HAVE_SW_POWEROFF | 62 | #ifdef HAVE_SW_POWEROFF |
67 | static bool enable_sw_poweroff = true; | 63 | static bool enable_sw_poweroff = true; |
68 | #endif | 64 | #endif |
@@ -72,7 +68,7 @@ static bool enable_sw_poweroff = true; | |||
72 | 68 | ||
73 | /* The next two make repeat "accelerate", which is nice for lists | 69 | /* The next two make repeat "accelerate", which is nice for lists |
74 | * which begin to scroll a bit faster when holding until the | 70 | * which begin to scroll a bit faster when holding until the |
75 | * real list accerelation kicks in (this smooths acceleration). | 71 | * real list acceleration kicks in (this smooths acceleration). |
76 | * | 72 | * |
77 | * Note that touchscreen pointing events are not subject to this | 73 | * Note that touchscreen pointing events are not subject to this |
78 | * acceleration and always use REPEAT_INTERVAL_TOUCH. (Do repeat | 74 | * acceleration and always use REPEAT_INTERVAL_TOUCH. (Do repeat |
@@ -86,19 +82,24 @@ static bool enable_sw_poweroff = true; | |||
86 | /* repeat interval for touch events */ | 82 | /* repeat interval for touch events */ |
87 | #define REPEAT_INTERVAL_TOUCH (5*HZ/100) | 83 | #define REPEAT_INTERVAL_TOUCH (5*HZ/100) |
88 | 84 | ||
89 | #ifdef HAVE_BUTTON_DATA | ||
90 | static int button_read(int *data); | ||
91 | static int lastdata = 0; | 85 | static int lastdata = 0; |
92 | #else | 86 | static int button_read(int *data); |
93 | static int button_read(void); | ||
94 | #endif | ||
95 | 87 | ||
96 | #ifdef HAVE_TOUCHSCREEN | 88 | #ifdef HAVE_TOUCHSCREEN |
97 | static long last_touchscreen_touch; | 89 | static long last_touchscreen_touch; |
98 | #endif | 90 | #endif |
99 | #if defined(HAVE_HEADPHONE_DETECTION) | ||
100 | static struct timeout hp_detect_timeout; /* Debouncer for headphone plug/unplug */ | ||
101 | 91 | ||
92 | static void button_remote_post(void) | ||
93 | { | ||
94 | #if defined(HAS_SERIAL_REMOTE) && !defined(SIMULATOR) | ||
95 | /* Post events for the remote control */ | ||
96 | int btn = remote_control_rx(); | ||
97 | if(btn) | ||
98 | button_try_post(btn, 0); | ||
99 | #endif | ||
100 | } | ||
101 | |||
102 | #if defined(HAVE_HEADPHONE_DETECTION) | ||
102 | static int hp_detect_callback(struct timeout *tmo) | 103 | static int hp_detect_callback(struct timeout *tmo) |
103 | { | 104 | { |
104 | /* Try to post only transistions */ | 105 | /* Try to post only transistions */ |
@@ -111,8 +112,6 @@ static int hp_detect_callback(struct timeout *tmo) | |||
111 | #endif | 112 | #endif |
112 | 113 | ||
113 | #if defined(HAVE_LINEOUT_DETECTION) | 114 | #if defined(HAVE_LINEOUT_DETECTION) |
114 | static struct timeout lo_detect_timeout; /* Debouncer for lineout plug/unplug */ | ||
115 | |||
116 | static int lo_detect_callback(struct timeout *tmo) | 115 | static int lo_detect_callback(struct timeout *tmo) |
117 | { | 116 | { |
118 | /* Try to post only transistions */ | 117 | /* Try to post only transistions */ |
@@ -124,6 +123,34 @@ static int lo_detect_callback(struct timeout *tmo) | |||
124 | } | 123 | } |
125 | #endif | 124 | #endif |
126 | 125 | ||
126 | static void check_audio_peripheral_state(void) | ||
127 | { | ||
128 | #if defined(HAVE_HEADPHONE_DETECTION) | ||
129 | static struct timeout hp_detect_timeout; /* Debouncer for headphone plug/unplug */ | ||
130 | static bool phones_present = false; | ||
131 | |||
132 | if (headphones_inserted() != phones_present) | ||
133 | { | ||
134 | /* Use the autoresetting oneshot to debounce the detection signal */ | ||
135 | phones_present = !phones_present; | ||
136 | timeout_register(&hp_detect_timeout, hp_detect_callback, | ||
137 | HZ/2, phones_present); | ||
138 | } | ||
139 | #endif | ||
140 | #if defined(HAVE_LINEOUT_DETECTION) | ||
141 | static struct timeout lo_detect_timeout; /* Debouncer for lineout plug/unplug */ | ||
142 | static bool lineout_present = false; | ||
143 | |||
144 | if (lineout_inserted() != lineout_present) | ||
145 | { | ||
146 | /* Use the autoresetting oneshot to debounce the detection signal */ | ||
147 | lineout_present = !lineout_present; | ||
148 | timeout_register(&lo_detect_timeout, lo_detect_callback, | ||
149 | HZ/2, lineout_present); | ||
150 | } | ||
151 | #endif | ||
152 | } | ||
153 | |||
127 | static bool button_try_post(int button, int data) | 154 | static bool button_try_post(int button, int data) |
128 | { | 155 | { |
129 | #ifdef HAVE_TOUCHSCREEN | 156 | #ifdef HAVE_TOUCHSCREEN |
@@ -153,6 +180,43 @@ static bool button_try_post(int button, int data) | |||
153 | return ret; | 180 | return ret; |
154 | } | 181 | } |
155 | 182 | ||
183 | #ifdef HAVE_BACKLIGHT | ||
184 | /* disabled function is shared between Main & Remote LCDs */ | ||
185 | static bool filter_first_keypress_disabled(int button, int data) | ||
186 | { | ||
187 | button_try_post(button, data); | ||
188 | return false; | ||
189 | } | ||
190 | |||
191 | static bool filter_first_keypress_enabled(int button, int data) | ||
192 | { | ||
193 | #if defined(HAVE_TRANSFLECTIVE_LCD) && defined(HAVE_LCD_SLEEP) | ||
194 | if (is_backlight_on(false) && lcd_active()) | ||
195 | #else | ||
196 | if (is_backlight_on(false)) | ||
197 | #endif | ||
198 | { | ||
199 | return filter_first_keypress_disabled(button, data); | ||
200 | } | ||
201 | return true; | ||
202 | } | ||
203 | |||
204 | #ifdef HAVE_REMOTE_LCD | ||
205 | static bool filter_first_remote_keypress_enabled(int button, int data) | ||
206 | { | ||
207 | if (is_remote_backlight_on(false) | ||
208 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) | ||
209 | || (remote_type()==REMOTETYPE_H300_NONLCD) | ||
210 | #endif | ||
211 | ) | ||
212 | { | ||
213 | return filter_first_keypress_disabled(button, data); | ||
214 | } | ||
215 | return true; | ||
216 | } | ||
217 | #endif /* def HAVE_REMOTE_LCD */ | ||
218 | #endif /* def HAVE_BACKLIGHT */ | ||
219 | |||
156 | static void button_tick(void) | 220 | static void button_tick(void) |
157 | { | 221 | { |
158 | static int count = 0; | 222 | static int count = 0; |
@@ -168,42 +232,13 @@ static void button_tick(void) | |||
168 | #endif | 232 | #endif |
169 | int diff; | 233 | int diff; |
170 | int btn; | 234 | int btn; |
171 | #ifdef HAVE_BUTTON_DATA | ||
172 | int data = 0; | 235 | int data = 0; |
173 | #else | ||
174 | const int data = 0; | ||
175 | #endif | ||
176 | 236 | ||
177 | #if defined(HAS_SERIAL_REMOTE) && !defined(SIMULATOR) | 237 | button_remote_post(); |
178 | /* Post events for the remote control */ | ||
179 | btn = remote_control_rx(); | ||
180 | if(btn) | ||
181 | button_try_post(btn, 0); | ||
182 | #endif | ||
183 | 238 | ||
184 | #ifdef HAVE_BUTTON_DATA | ||
185 | btn = button_read(&data); | 239 | btn = button_read(&data); |
186 | #else | 240 | |
187 | btn = button_read(); | 241 | check_audio_peripheral_state(); |
188 | #endif | ||
189 | #if defined(HAVE_HEADPHONE_DETECTION) | ||
190 | if (headphones_inserted() != phones_present) | ||
191 | { | ||
192 | /* Use the autoresetting oneshot to debounce the detection signal */ | ||
193 | phones_present = !phones_present; | ||
194 | timeout_register(&hp_detect_timeout, hp_detect_callback, | ||
195 | HZ/2, phones_present); | ||
196 | } | ||
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 | ||
207 | 242 | ||
208 | /* Find out if a key has been released */ | 243 | /* Find out if a key has been released */ |
209 | diff = btn ^ lastbtn; | 244 | diff = btn ^ lastbtn; |
@@ -348,48 +383,21 @@ static void button_tick(void) | |||
348 | #ifdef HAVE_BACKLIGHT | 383 | #ifdef HAVE_BACKLIGHT |
349 | #ifdef HAVE_REMOTE_LCD | 384 | #ifdef HAVE_REMOTE_LCD |
350 | if (btn & BUTTON_REMOTE) { | 385 | if (btn & BUTTON_REMOTE) { |
351 | if (!remote_filter_first_keypress | 386 | skip_remote_release = remote_keypress_filter_fn(btn, data); |
352 | || is_remote_backlight_on(false) | 387 | remote_backlight_on(); |
353 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) | ||
354 | || (remote_type()==REMOTETYPE_H300_NONLCD) | ||
355 | #endif | ||
356 | ) | ||
357 | button_try_post(btn, data); | ||
358 | else | ||
359 | skip_remote_release = true; | ||
360 | } | 388 | } |
361 | else | 389 | else |
362 | #endif | 390 | #endif |
363 | if (!filter_first_keypress | 391 | { |
364 | #if defined(HAVE_TRANSFLECTIVE_LCD) && defined(HAVE_LCD_SLEEP) | 392 | skip_release = keypress_filter_fn(btn, data); |
365 | || (is_backlight_on(false) && lcd_active()) | 393 | backlight_on(); |
366 | #else | 394 | buttonlight_on(); |
367 | || is_backlight_on(false) | 395 | } |
368 | #endif | ||
369 | #if BUTTON_REMOTE | ||
370 | || (btn & BUTTON_REMOTE) | ||
371 | #endif | ||
372 | ) | ||
373 | button_try_post(btn, data); | ||
374 | else | ||
375 | skip_release = true; | ||
376 | #else /* no backlight, nothing to skip */ | 396 | #else /* no backlight, nothing to skip */ |
377 | button_try_post(btn, data); | 397 | button_try_post(btn, data); |
378 | #endif | 398 | #endif |
379 | post = false; | 399 | post = false; |
380 | } | 400 | } |
381 | #ifdef HAVE_REMOTE_LCD | ||
382 | if(btn & BUTTON_REMOTE) | ||
383 | remote_backlight_on(); | ||
384 | else | ||
385 | #endif | ||
386 | { | ||
387 | backlight_on(); | ||
388 | #ifdef HAVE_BUTTON_LIGHT | ||
389 | buttonlight_on(); | ||
390 | #endif | ||
391 | } | ||
392 | |||
393 | reset_poweroff_timer(); | 401 | reset_poweroff_timer(); |
394 | } | 402 | } |
395 | } | 403 | } |
@@ -400,9 +408,8 @@ static void button_tick(void) | |||
400 | } | 408 | } |
401 | } | 409 | } |
402 | lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); | 410 | lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); |
403 | #ifdef HAVE_BUTTON_DATA | 411 | |
404 | lastdata = data; | 412 | lastdata = data; |
405 | #endif | ||
406 | } | 413 | } |
407 | 414 | ||
408 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 415 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
@@ -515,30 +522,23 @@ intptr_t button_get_data(void) | |||
515 | 522 | ||
516 | void button_init(void) | 523 | void button_init(void) |
517 | { | 524 | { |
525 | int temp; | ||
518 | /* Init used objects first */ | 526 | /* Init used objects first */ |
519 | queue_init(&button_queue, true); | 527 | queue_init(&button_queue, true); |
520 | 528 | ||
521 | #ifdef HAVE_BUTTON_DATA | ||
522 | int temp; | ||
523 | #endif | ||
524 | /* hardware inits */ | 529 | /* hardware inits */ |
525 | button_init_device(); | 530 | button_init_device(); |
526 | 531 | ||
527 | #ifdef HAVE_BUTTON_DATA | ||
528 | button_read(&temp); | 532 | button_read(&temp); |
529 | lastbtn = button_read(&temp); | 533 | lastbtn = button_read(&temp); |
530 | #else | ||
531 | button_read(); | ||
532 | lastbtn = button_read(); | ||
533 | #endif | ||
534 | 534 | ||
535 | reset_poweroff_timer(); | 535 | reset_poweroff_timer(); |
536 | 536 | ||
537 | flipped = false; | 537 | flipped = false; |
538 | #ifdef HAVE_BACKLIGHT | 538 | #ifdef HAVE_BACKLIGHT |
539 | filter_first_keypress = false; | 539 | set_backlight_filter_keypress(false); |
540 | #ifdef HAVE_REMOTE_LCD | 540 | #ifdef HAVE_REMOTE_LCD |
541 | remote_filter_first_keypress = false; | 541 | set_remote_backlight_filter_keypress(false); |
542 | #endif | 542 | #endif |
543 | #endif | 543 | #endif |
544 | #ifdef HAVE_TOUCHSCREEN | 544 | #ifdef HAVE_TOUCHSCREEN |
@@ -649,12 +649,18 @@ void button_set_flip(bool flip) | |||
649 | #ifdef HAVE_BACKLIGHT | 649 | #ifdef HAVE_BACKLIGHT |
650 | void set_backlight_filter_keypress(bool value) | 650 | void set_backlight_filter_keypress(bool value) |
651 | { | 651 | { |
652 | filter_first_keypress = value; | 652 | if (!value) |
653 | keypress_filter_fn = filter_first_keypress_disabled; | ||
654 | else | ||
655 | keypress_filter_fn = filter_first_keypress_enabled; | ||
653 | } | 656 | } |
654 | #ifdef HAVE_REMOTE_LCD | 657 | #ifdef HAVE_REMOTE_LCD |
655 | void set_remote_backlight_filter_keypress(bool value) | 658 | void set_remote_backlight_filter_keypress(bool value) |
656 | { | 659 | { |
657 | remote_filter_first_keypress = value; | 660 | if (!value) |
661 | remote_keypress_filter_fn = filter_first_keypress_disabled; | ||
662 | else | ||
663 | remote_keypress_filter_fn = filter_first_remote_keypress_enabled; | ||
658 | } | 664 | } |
659 | #endif | 665 | #endif |
660 | #endif | 666 | #endif |
@@ -662,13 +668,13 @@ void set_remote_backlight_filter_keypress(bool value) | |||
662 | /* | 668 | /* |
663 | * Get button pressed from hardware | 669 | * Get button pressed from hardware |
664 | */ | 670 | */ |
665 | #ifdef HAVE_BUTTON_DATA | 671 | |
666 | static int button_read(int *data) | 672 | static int button_read(int *data) |
667 | { | 673 | { |
674 | #ifdef HAVE_BUTTON_DATA | ||
668 | int btn = button_read_device(data); | 675 | int btn = button_read_device(data); |
669 | #else | 676 | #else |
670 | static int button_read(void) | 677 | (void) data; |
671 | { | ||
672 | int btn = button_read_device(); | 678 | int btn = button_read_device(); |
673 | #endif | 679 | #endif |
674 | int retval; | 680 | int retval; |
diff --git a/firmware/export/backlight.h b/firmware/export/backlight.h index 6d029790b3..f4ce5d8568 100644 --- a/firmware/export/backlight.h +++ b/firmware/export/backlight.h | |||
@@ -98,16 +98,12 @@ extern int backlight_brightness; | |||
98 | void backlight_set_brightness(int val); | 98 | void backlight_set_brightness(int val); |
99 | #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ | 99 | #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ |
100 | 100 | ||
101 | #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS | ||
102 | void buttonlight_set_brightness(int val); | 101 | void buttonlight_set_brightness(int val); |
103 | #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ | ||
104 | 102 | ||
105 | #ifdef HAVE_BUTTON_LIGHT | ||
106 | void buttonlight_on_ignore(bool value, int timeout); | 103 | void buttonlight_on_ignore(bool value, int timeout); |
107 | void buttonlight_on(void); | 104 | void buttonlight_on(void); |
108 | void buttonlight_off(void); | 105 | void buttonlight_off(void); |
109 | void buttonlight_set_timeout(int value); | 106 | void buttonlight_set_timeout(int value); |
110 | #endif | ||
111 | 107 | ||
112 | /* Private API for use in target tree backlight code only */ | 108 | /* Private API for use in target tree backlight code only */ |
113 | #ifdef HAVE_BUTTON_LIGHT | 109 | #ifdef HAVE_BUTTON_LIGHT |