support for translating rbutil. Translation files (*.qm) can be in the binary folder...
[Rockbox.git] / firmware / backlight.c
blob9277f34681132cd5697358c7b20fd2f16d7403c8
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "config.h"
20 #include <stdlib.h>
21 #include "cpu.h"
22 #include "kernel.h"
23 #include "thread.h"
24 #include "i2c.h"
25 #include "debug.h"
26 #include "rtc.h"
27 #include "usb.h"
28 #include "power.h"
29 #include "system.h"
30 #include "button.h"
31 #include "timer.h"
32 #include "backlight.h"
34 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
35 #include "lcd.h" /* for lcd_enable() and lcd_sleep() */
36 #endif
37 #ifdef HAVE_REMOTE_LCD
38 #include "lcd-remote.h"
39 #endif
40 #ifndef SIMULATOR
41 #include "backlight-target.h"
42 #endif
44 #ifdef SIMULATOR
45 static inline void __backlight_on(void)
47 sim_backlight(100);
50 static inline void __backlight_off(void)
52 sim_backlight(0);
55 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
56 static inline void __backlight_set_brightness(int val)
58 (void)val;
60 #endif
62 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
63 static inline void __buttonlight_set_brightness(int val)
65 (void)val;
67 #endif
69 #endif /* SIMULATOR */
71 #if defined(HAVE_BACKLIGHT) && !defined(BOOTLOADER)
73 const signed char backlight_timeout_value[19] =
75 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 45, 60, 90
78 #define BACKLIGHT_ON 1
79 #define BACKLIGHT_OFF 2
80 #define REMOTE_BACKLIGHT_ON 3
81 #define REMOTE_BACKLIGHT_OFF 4
82 #define BACKLIGHT_UNBOOST_CPU 5
83 #ifdef HAVE_LCD_SLEEP
84 #define LCD_SLEEP 6
85 #endif
86 #ifdef HAVE_BUTTON_LIGHT
87 #define BUTTON_LIGHT_ON 7
88 #define BUTTON_LIGHT_OFF 8
89 #endif
91 static void backlight_thread(void);
92 static long backlight_stack[DEFAULT_STACK_SIZE/sizeof(long)];
93 #ifdef X5_BACKLIGHT_SHUTDOWN
94 #define BACKLIGHT_QUIT 256
95 #endif
96 static const char backlight_thread_name[] = "backlight";
97 static struct event_queue backlight_queue;
99 static int backlight_timer;
100 static int backlight_timeout = 5*HZ;
101 #if CONFIG_CHARGING
102 static int backlight_timeout_plugged = 5*HZ;
103 #endif
104 #ifdef HAS_BUTTON_HOLD
105 static int backlight_on_button_hold = 0;
106 #endif
108 #ifdef HAVE_BUTTON_LIGHT
109 static int button_backlight_timer;
110 static int button_backlight_timeout = 5*HZ;
112 /* internal interface */
113 static void _button_backlight_on(void)
115 #ifndef SIMULATOR
116 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
117 __button_backlight_dim(false);
118 #else
119 __button_backlight_on();
120 #endif
121 #endif
124 void _button_backlight_off(void)
126 #ifndef SIMULATOR
127 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
128 if(button_backlight_timeout>0)
129 __button_backlight_dim(true);
130 else
131 #endif
132 __button_backlight_off();
133 #endif
136 /* Update state of buttonlight according to timeout setting */
137 static void buttonlight_update_state(void)
139 button_backlight_timer = button_backlight_timeout;
141 /* Buttonlight == OFF in the setting? */
142 if (button_backlight_timer < 0)
144 button_backlight_timer = 0; /* Disable the timeout */
145 _button_backlight_off();
147 else
148 _button_backlight_on();
151 /* external interface */
152 void button_backlight_on(void)
154 queue_remove_from_head(&backlight_queue, BUTTON_LIGHT_ON);
155 queue_post(&backlight_queue, BUTTON_LIGHT_ON, 0);
158 void button_backlight_off(void)
160 queue_post(&backlight_queue, BUTTON_LIGHT_OFF, 0);
163 void button_backlight_set_timeout(int index)
165 if((unsigned)index >= sizeof(backlight_timeout_value))
166 /* if given a weird value, use default */
167 index = 6;
168 button_backlight_timeout = HZ * backlight_timeout_value[index];
169 buttonlight_update_state();
172 #endif
174 #ifdef HAVE_REMOTE_LCD
175 static int remote_backlight_timer;
176 static int remote_backlight_timeout = 5*HZ;
177 #if CONFIG_CHARGING
178 static int remote_backlight_timeout_plugged = 5*HZ;
179 #endif
180 #ifdef HAS_REMOTE_BUTTON_HOLD
181 static int remote_backlight_on_button_hold = 0;
182 #endif
183 #endif
185 #ifdef HAVE_LCD_SLEEP
186 const signed char lcd_sleep_timeout_value[10] =
188 -1, 0, 5, 10, 15, 20, 30, 45, 60, 90
190 static int lcd_sleep_timer;
191 static int lcd_sleep_timeout = 10*HZ;
192 #endif
194 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
195 /* backlight fading */
196 #define BL_PWM_INTERVAL 5000 /* Cycle interval in s */
197 #define BL_PWM_COUNT 100
198 static const char backlight_fade_value[8] = { 0, 1, 2, 4, 6, 8, 10, 20 };
199 static int fade_in_count = 1;
200 static int fade_out_count = 4;
202 static bool bl_timer_active = false;
203 static int bl_dim_current = 0;
204 static int bl_dim_target = 0;
205 static int bl_pwm_counter = 0;
206 static volatile int bl_cycle_counter = 0;
207 static enum {DIM_STATE_START, DIM_STATE_MAIN} bl_dim_state = DIM_STATE_START;
209 static void backlight_isr(void)
211 int timer_period;
212 bool idle = false;
214 timer_period = TIMER_FREQ / 1000 * BL_PWM_INTERVAL / 1000;
215 switch (bl_dim_state)
217 /* New cycle */
218 case DIM_STATE_START:
219 bl_pwm_counter = 0;
220 bl_cycle_counter++;
222 if (bl_dim_current > 0 && bl_dim_current < BL_PWM_COUNT)
224 __backlight_on();
225 bl_pwm_counter = bl_dim_current;
226 timer_period = timer_period * bl_pwm_counter / BL_PWM_COUNT;
227 bl_dim_state = DIM_STATE_MAIN;
229 else
231 if (bl_dim_current)
232 __backlight_on();
233 else
234 __backlight_off();
235 if (bl_dim_current == bl_dim_target)
236 idle = true;
239 break ;
241 /* Dim main screen */
242 case DIM_STATE_MAIN:
243 __backlight_off();
244 bl_dim_state = DIM_STATE_START;
245 timer_period = timer_period * (BL_PWM_COUNT - bl_pwm_counter) / BL_PWM_COUNT;
246 break ;
249 if ((bl_dim_target > bl_dim_current) && (bl_cycle_counter >= fade_in_count))
251 bl_dim_current++;
252 bl_cycle_counter = 0;
255 if ((bl_dim_target < bl_dim_current) && (bl_cycle_counter >= fade_out_count))
257 bl_dim_current--;
258 bl_cycle_counter = 0;
261 if (idle)
263 #ifdef CPU_COLDFIRE
264 queue_post(&backlight_queue, BACKLIGHT_UNBOOST_CPU, 0);
265 #endif
266 timer_unregister();
267 bl_timer_active = false;
269 else
270 timer_set_period(timer_period);
273 static void backlight_switch(void)
275 if (bl_dim_target > (BL_PWM_COUNT/2))
277 __backlight_on();
278 bl_dim_current = BL_PWM_COUNT;
280 else
282 __backlight_off();
283 bl_dim_current = 0;
287 static void backlight_release_timer(void)
289 #ifdef CPU_COLDFIRE
290 cpu_boost(false);
291 #endif
292 timer_unregister();
293 bl_timer_active = false;
294 backlight_switch();
297 static void backlight_dim(int value)
299 /* protect from extraneous calls with the same target value */
300 if (value == bl_dim_target)
301 return;
303 bl_dim_target = value;
305 if (bl_timer_active)
306 return ;
308 if (timer_register(0, backlight_release_timer, 2, 0, backlight_isr))
310 #ifdef CPU_COLDFIRE
311 /* Prevent cpu frequency changes while dimming. */
312 cpu_boost(true);
313 #endif
314 bl_timer_active = true;
316 else
317 backlight_switch();
320 void backlight_set_fade_in(int index)
322 fade_in_count = backlight_fade_value[index];
325 void backlight_set_fade_out(int index)
327 fade_out_count = backlight_fade_value[index];
329 #endif /* defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) */
331 static void _backlight_on(void)
333 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
334 if (fade_in_count > 0)
335 backlight_dim(BL_PWM_COUNT);
336 else
338 bl_dim_target = bl_dim_current = BL_PWM_COUNT;
339 __backlight_on();
341 #elif defined(HAVE_BACKLIGHT_SET_FADING) && !defined(SIMULATOR)
342 /* call the enable from here - it takes longer than the disable */
343 lcd_enable(true);
344 __backlight_dim(false);
345 #else
346 __backlight_on();
347 #endif
348 #ifdef HAVE_LCD_SLEEP
349 lcd_sleep_timer = 0; /* LCD should be awake already */
350 #endif
353 static void _backlight_off(void)
355 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
356 if (fade_out_count > 0)
357 backlight_dim(0);
358 else
360 bl_dim_target = bl_dim_current = 0;
361 __backlight_off();
363 #elif defined(HAVE_BACKLIGHT_SET_FADING) && !defined(SIMULATOR)
364 __backlight_dim(true);
365 #else
366 __backlight_off();
367 #endif
369 #ifdef HAVE_LCD_SLEEP
370 /* Start LCD sleep countdown */
371 if (lcd_sleep_timeout < 0)
373 lcd_sleep_timer = 0; /* Setting == Always */
374 lcd_sleep();
376 else
377 lcd_sleep_timer = lcd_sleep_timeout;
378 #endif
381 #ifdef HAVE_REMOTE_LCD
382 #ifdef SIMULATOR
383 static void __remote_backlight_on(void)
385 sim_remote_backlight(100);
388 static void __remote_backlight_off(void)
390 sim_remote_backlight(0);
392 #endif /* SIMULATOR */
393 #endif /* HAVE_REMOTE_LCD */
395 /* Update state of backlight according to timeout setting */
396 static void backlight_update_state(void)
398 #if CONFIG_CHARGING
399 if (charger_inserted()
400 #ifdef HAVE_USB_POWER
401 || usb_powered()
402 #endif
404 backlight_timer = backlight_timeout_plugged;
405 else
406 #endif
407 backlight_timer = backlight_timeout;
409 /* Backlight == OFF in the setting? */
410 if (backlight_timer < 0)
412 backlight_timer = 0; /* Disable the timeout */
413 #ifdef HAS_BUTTON_HOLD
414 if (backlight_on_button_hold == 2 && button_hold())
415 return; /* Keep on if "On" */
416 #endif
417 _backlight_off();
419 else
421 #ifdef HAS_BUTTON_HOLD
422 if (backlight_on_button_hold == 1 && button_hold())
424 /* Keep off if "Off". */
425 backlight_timer = 0; /* Disable the timeout */
426 return;
428 #endif
429 _backlight_on();
433 #ifdef HAVE_REMOTE_LCD
434 /* Update state of remote backlight according to timeout setting */
435 static void remote_backlight_update_state(void)
437 #if CONFIG_CHARGING
438 if (charger_inserted()
439 #ifdef HAVE_USB_POWER
440 || usb_powered()
441 #endif
443 remote_backlight_timer = remote_backlight_timeout_plugged;
444 else
445 #endif
446 remote_backlight_timer = remote_backlight_timeout;
448 /* Backlight == OFF in the setting? */
449 if (remote_backlight_timer < 0)
451 remote_backlight_timer = 0; /* Disable the timeout */
452 #ifdef HAS_REMOTE_BUTTON_HOLD
453 if (remote_backlight_on_button_hold == 2 && remote_button_hold())
454 return; /* Keep on if "On" */
455 #endif
456 __remote_backlight_off();
458 else
460 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
461 if (remote_type() == REMOTETYPE_H300_NONLCD)
463 backlight_update_state();
465 else
466 #endif
468 #ifdef HAS_REMOTE_BUTTON_HOLD
469 if (remote_backlight_on_button_hold == 1 && remote_button_hold())
471 /* Keep off if "Off". */
472 remote_backlight_timer = 0; /* Disable the timeout */
473 return;
475 #endif
476 __remote_backlight_on();
480 #endif /* HAVE_REMOTE_LCD */
482 void backlight_thread(void)
484 struct event ev;
486 while(1)
488 queue_wait(&backlight_queue, &ev);
489 switch(ev.id)
491 #ifdef HAVE_REMOTE_LCD
492 case REMOTE_BACKLIGHT_ON:
493 remote_backlight_update_state();
494 break;
496 case REMOTE_BACKLIGHT_OFF:
497 remote_backlight_timer = 0; /* Disable the timeout */
498 #ifdef HAS_REMOTE_BUTTON_HOLD
499 if (remote_backlight_on_button_hold == 2 &&
500 remote_button_hold())
501 break; /* Keep on if "On" */
502 #endif
503 __remote_backlight_off();
504 break;
505 #endif /* HAVE_REMOTE_LCD */
507 case BACKLIGHT_ON:
508 backlight_update_state();
509 break;
511 case BACKLIGHT_OFF:
512 backlight_timer = 0; /* Disable the timeout */
513 #ifdef HAS_BUTTON_HOLD
514 if (backlight_on_button_hold == 2 && button_hold())
515 break; /* Keep on if "On" */
516 #endif
517 _backlight_off();
518 break;
520 #ifdef HAVE_LCD_SLEEP
521 case LCD_SLEEP:
522 lcd_sleep();
523 break;
524 #endif
525 #ifdef HAVE_BUTTON_LIGHT
526 case BUTTON_LIGHT_ON:
527 buttonlight_update_state();
528 break;
529 case BUTTON_LIGHT_OFF:
530 button_backlight_timer = 0;
531 _button_backlight_off();
532 break;
533 #endif
535 #ifdef X5_BACKLIGHT_SHUTDOWN
536 case BACKLIGHT_QUIT:
537 remove_thread(NULL);
538 break;
539 #endif
541 #if defined(HAVE_BACKLIGHT_PWM_FADING) && defined(CPU_COLDFIRE) \
542 && !defined(SIMULATOR)
543 case BACKLIGHT_UNBOOST_CPU:
544 cpu_boost(false);
545 break;
546 #endif
548 #if defined(HAVE_REMOTE_LCD) && !defined(SIMULATOR)
549 /* Here for now or else the aggressive init messes up scrolling */
550 case SYS_REMOTE_PLUGGED:
551 lcd_remote_on();
552 lcd_remote_update();
553 break;
555 case SYS_REMOTE_UNPLUGGED:
556 lcd_remote_off();
557 break;
558 #endif /* defined(HAVE_REMOTE_LCD) && !defined(SIMULATOR) */
560 case SYS_USB_CONNECTED:
561 /* Tell the USB thread that we are safe */
562 DEBUGF("backlight_thread got SYS_USB_CONNECTED\n");
563 usb_acknowledge(SYS_USB_CONNECTED_ACK);
564 break;
566 case SYS_USB_DISCONNECTED:
567 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
568 break;
569 } /* end switch */
570 } /* end while */
573 static void backlight_tick(void)
575 #if CONFIG_CHARGING
576 static bool charger_was_inserted = false;
577 bool charger_is_inserted = charger_inserted()
578 #ifdef HAVE_USB_POWER
579 || usb_powered()
580 #endif
583 if( charger_was_inserted != charger_is_inserted )
585 backlight_on();
586 #ifdef HAVE_REMOTE_LCD
587 remote_backlight_on();
588 #endif
590 charger_was_inserted = charger_is_inserted;
591 #endif /* CONFIG_CHARGING */
593 if(backlight_timer)
595 backlight_timer--;
596 if(backlight_timer == 0)
598 backlight_off();
601 #ifdef HAVE_LCD_SLEEP
602 else if(lcd_sleep_timer)
604 lcd_sleep_timer--;
605 if(lcd_sleep_timer == 0)
607 /* Queue on bl thread or freeze! */
608 queue_post(&backlight_queue, LCD_SLEEP, 0);
611 #endif /* HAVE_LCD_SLEEP */
613 #ifdef HAVE_REMOTE_LCD
614 if(remote_backlight_timer)
616 remote_backlight_timer--;
617 if(remote_backlight_timer == 0)
619 remote_backlight_off();
622 #endif /* HAVE_REMOVE_LCD */
623 #ifdef HAVE_BUTTON_LIGHT
624 if (button_backlight_timer)
626 button_backlight_timer--;
627 if (button_backlight_timer == 0)
629 button_backlight_off();
632 #endif /* HAVE_BUTTON_LIGHT */
635 void backlight_init(void)
637 queue_init(&backlight_queue, true);
638 queue_set_irq_safe(&backlight_queue, true);
640 #ifndef SIMULATOR
641 if (__backlight_init())
643 # ifdef HAVE_BACKLIGHT_PWM_FADING
644 /* If backlight is already on, don't fade in. */
645 bl_dim_current = BL_PWM_COUNT;
646 bl_dim_target = BL_PWM_COUNT;
647 # endif
649 #endif
650 backlight_on();
651 #ifdef HAVE_REMOTE_LCD
652 remote_backlight_on();
653 #endif
654 #ifdef HAVE_BUTTON_LIGHT
655 button_backlight_on();
656 #endif
658 create_thread(backlight_thread, backlight_stack,
659 sizeof(backlight_stack), backlight_thread_name
660 IF_PRIO(, PRIORITY_SYSTEM)
661 IF_COP(, CPU, false));
662 tick_add_task(backlight_tick);
665 #ifdef X5_BACKLIGHT_SHUTDOWN
666 void x5_backlight_shutdown(void)
668 /* Turn on the screen and don't let anyone else mess with it. Called
669 from clean_shutdown in misc.c. */
670 queue_empty(&backlight_queue);
671 tick_remove_task(backlight_tick);
672 /* Next time the thread runs, if at all, it will just remove itself. */
673 queue_post(&backlight_queue, BACKLIGHT_QUIT, 0);
674 __backlight_on();
676 #endif /* X5_BACKLIGHT_SHUTDOWN */
678 void backlight_on(void)
680 queue_remove_from_head(&backlight_queue, BACKLIGHT_ON);
681 queue_post(&backlight_queue, BACKLIGHT_ON, 0);
684 void backlight_off(void)
686 queue_post(&backlight_queue, BACKLIGHT_OFF, 0);
689 /* returns true when the backlight is on OR when it's set to always off */
690 bool is_backlight_on(void)
692 if (backlight_timer || backlight_get_current_timeout() <= 0)
693 return true;
694 else
695 return false;
698 /* return value in ticks; 0 means always on, <0 means always off */
699 int backlight_get_current_timeout(void)
701 #if CONFIG_CHARGING
702 if (charger_inserted()
703 #ifdef HAVE_USB_POWER
704 || usb_powered()
705 #endif
707 return backlight_timeout_plugged;
708 else
709 return backlight_timeout;
710 #else
711 return backlight_timeout;
712 #endif
715 void backlight_set_timeout(int index)
717 if((unsigned)index >= sizeof(backlight_timeout_value))
718 /* if given a weird value, use default */
719 index = 6;
720 backlight_timeout = HZ * backlight_timeout_value[index];
721 backlight_update_state();
724 #if CONFIG_CHARGING
725 void backlight_set_timeout_plugged(int index)
727 if((unsigned)index >= sizeof(backlight_timeout_value))
728 /* if given a weird value, use default */
729 index = 6;
730 backlight_timeout_plugged = HZ * backlight_timeout_value[index];
731 backlight_update_state();
733 #endif /* CONFIG_CHARGING */
735 #ifdef HAS_BUTTON_HOLD
736 /* Hold button change event handler. */
737 void backlight_hold_changed(bool hold_button)
739 /* Hold switch overrides all backlight behavior except when
740 set to "Normal" */
741 /* Queue or freeze */
742 if (hold_button && backlight_on_button_hold == 1)
743 backlight_off(); /* setting == Off */
744 else /* setting == On, Normal, no hold button, or anything else */
745 backlight_on();
748 void backlight_set_on_button_hold(int index)
750 if ((unsigned)index >= 3)
751 /* if given a weird value, use default */
752 index = 0;
754 if (index == backlight_on_button_hold)
755 return;
757 backlight_on_button_hold = index;
758 backlight_hold_changed(button_hold());
760 #endif /* HAS_BUTTON_HOLD */
762 #ifdef HAVE_LCD_SLEEP
763 void lcd_set_sleep_after_backlight_off(int index)
765 if ((unsigned)index >= sizeof(lcd_sleep_timeout_value))
766 /* if given a weird value, use default */
767 index = 3;
769 lcd_sleep_timeout = HZ * lcd_sleep_timeout_value[index];
771 if (backlight_timer > 0 || backlight_get_current_timeout() == 0)
772 /* Timer will be set when bl turns off or bl set to on. */
773 return;
775 /* Backlight is Off */
776 if (lcd_sleep_timeout < 0)
777 lcd_sleep_timer = 1; /* Always - sleep next tick */
778 else
779 lcd_sleep_timer = lcd_sleep_timeout; /* Never, other */
781 #endif /* HAVE_LCD_SLEEP */
783 #ifdef HAVE_REMOTE_LCD
784 void remote_backlight_on(void)
786 queue_post(&backlight_queue, REMOTE_BACKLIGHT_ON, 0);
789 void remote_backlight_off(void)
791 queue_post(&backlight_queue, REMOTE_BACKLIGHT_OFF, 0);
794 void remote_backlight_set_timeout(int index)
796 if((unsigned)index >= sizeof(backlight_timeout_value))
797 /* if given a weird value, use default */
798 index=6;
799 remote_backlight_timeout = HZ * backlight_timeout_value[index];
800 remote_backlight_update_state();
803 #if CONFIG_CHARGING
804 void remote_backlight_set_timeout_plugged(int index)
806 if((unsigned)index >= sizeof(backlight_timeout_value))
807 /* if given a weird value, use default */
808 index=6;
809 remote_backlight_timeout_plugged = HZ * backlight_timeout_value[index];
810 remote_backlight_update_state();
812 #endif /* CONFIG_CHARGING */
814 #ifdef HAS_REMOTE_BUTTON_HOLD
815 /* Remote hold button change event handler. */
816 void remote_backlight_hold_changed(bool rc_hold_button)
818 /* Hold switch overrides all backlight behavior except when
819 set to "Normal" */
820 /* Queue or freeze */
821 if (rc_hold_button && remote_backlight_on_button_hold == 1)
822 remote_backlight_off(); /* setting == Off */
823 else /* setting == On, Normal, no hold button, or anything else */
824 remote_backlight_on();
827 void remote_backlight_set_on_button_hold(int index)
829 if ((unsigned)index >= 3)
830 /* if given a weird value, use default */
831 index = 0;
833 if (index == remote_backlight_on_button_hold)
834 return;
836 remote_backlight_on_button_hold = index;
837 remote_backlight_hold_changed(remote_button_hold());
839 #endif /* HAS_REMOTE_BUTTON_HOLD */
841 /* return value in ticks; 0 means always on, <0 means always off */
842 int remote_backlight_get_current_timeout(void)
844 #if CONFIG_CHARGING
845 if (charger_inserted()
846 #ifdef HAVE_USB_POWER
847 || usb_powered()
848 #endif
850 return remote_backlight_timeout_plugged;
851 else
852 return remote_backlight_timeout;
853 #else
854 return remote_backlight_timeout;
855 #endif
858 /* returns true when the backlight is on OR when it's set to always off */
859 bool is_remote_backlight_on(void)
861 if (remote_backlight_timer != 0 ||
862 remote_backlight_get_current_timeout() <= 0)
863 return true;
864 else
865 return false;
868 #endif /* HAVE_REMOTE_LCD */
870 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
871 void backlight_set_brightness(int val)
873 if (val < MIN_BRIGHTNESS_SETTING)
874 val = MIN_BRIGHTNESS_SETTING;
875 else if (val > MAX_BRIGHTNESS_SETTING)
876 val = MAX_BRIGHTNESS_SETTING;
878 __backlight_set_brightness(val);
880 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
882 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
883 void buttonlight_set_brightness(int val)
885 if (val < MIN_BRIGHTNESS_SETTING)
886 val = MIN_BRIGHTNESS_SETTING;
887 else if (val > MAX_BRIGHTNESS_SETTING)
888 val = MAX_BRIGHTNESS_SETTING;
890 __buttonlight_set_brightness(val);
892 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
894 #else /* !defined(HAVE_BACKLIGHT) || defined(BOOTLOADER)
895 -- no backlight, empty dummy functions */
897 #if defined(BOOTLOADER) && defined(HAVE_BACKLIGHT)
898 void backlight_init(void)
900 (void)__backlight_init();
901 __backlight_on();
903 #endif
905 void backlight_on(void) {}
906 void backlight_off(void) {}
907 void button_backlight_on(void) {}
908 void backlight_set_timeout(int index) {(void)index;}
909 bool is_backlight_on(void) {return true;}
910 #ifdef HAVE_REMOTE_LCD
911 void remote_backlight_on(void) {}
912 void remote_backlight_off(void) {}
913 void remote_backlight_set_timeout(int index) {(void)index;}
914 bool is_remote_backlight_on(void) {return true;}
915 #endif /* HAVE_REMOTE_LCD */
916 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
917 void backlight_set_brightness(int val) { (void)val; }
918 #endif
919 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
920 void buttonlight_set_brightness(int val) { (void)val; }
921 #endif
922 #endif /* defined(HAVE_BACKLIGHT) && !defined(BOOTLOADER) */