rbutil caches no the preview images of the themes.
[Rockbox.git] / firmware / backlight.c
blob5549430c4563f30606457be94f6d28d2e3f2568d
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 case SYS_USB_CONNECTED:
549 /* Tell the USB thread that we are safe */
550 DEBUGF("backlight_thread got SYS_USB_CONNECTED\n");
551 usb_acknowledge(SYS_USB_CONNECTED_ACK);
552 break;
554 case SYS_USB_DISCONNECTED:
555 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
556 break;
557 } /* end switch */
558 } /* end while */
561 static void backlight_tick(void)
563 #if CONFIG_CHARGING
564 static bool charger_was_inserted = false;
565 bool charger_is_inserted = charger_inserted()
566 #ifdef HAVE_USB_POWER
567 || usb_powered()
568 #endif
571 if( charger_was_inserted != charger_is_inserted )
573 backlight_on();
574 #ifdef HAVE_REMOTE_LCD
575 remote_backlight_on();
576 #endif
578 charger_was_inserted = charger_is_inserted;
579 #endif /* CONFIG_CHARGING */
581 if(backlight_timer)
583 backlight_timer--;
584 if(backlight_timer == 0)
586 backlight_off();
589 #ifdef HAVE_LCD_SLEEP
590 else if(lcd_sleep_timer)
592 lcd_sleep_timer--;
593 if(lcd_sleep_timer == 0)
595 /* Queue on bl thread or freeze! */
596 queue_post(&backlight_queue, LCD_SLEEP, 0);
599 #endif /* HAVE_LCD_SLEEP */
601 #ifdef HAVE_REMOTE_LCD
602 if(remote_backlight_timer)
604 remote_backlight_timer--;
605 if(remote_backlight_timer == 0)
607 remote_backlight_off();
610 #endif /* HAVE_REMOVE_LCD */
611 #ifdef HAVE_BUTTON_LIGHT
612 if (button_backlight_timer)
614 button_backlight_timer--;
615 if (button_backlight_timer == 0)
617 button_backlight_off();
620 #endif /* HAVE_BUTTON_LIGHT */
623 void backlight_init(void)
625 queue_init(&backlight_queue, true);
626 queue_set_irq_safe(&backlight_queue, true);
628 #ifndef SIMULATOR
629 if (__backlight_init())
631 # ifdef HAVE_BACKLIGHT_PWM_FADING
632 /* If backlight is already on, don't fade in. */
633 bl_dim_current = BL_PWM_COUNT;
634 bl_dim_target = BL_PWM_COUNT;
635 # endif
637 #endif
638 backlight_on();
639 #ifdef HAVE_REMOTE_LCD
640 remote_backlight_on();
641 #endif
642 #ifdef HAVE_BUTTON_LIGHT
643 button_backlight_on();
644 #endif
646 create_thread(backlight_thread, backlight_stack,
647 sizeof(backlight_stack), backlight_thread_name
648 IF_PRIO(, PRIORITY_SYSTEM)
649 IF_COP(, CPU, false));
650 tick_add_task(backlight_tick);
653 #ifdef X5_BACKLIGHT_SHUTDOWN
654 void x5_backlight_shutdown(void)
656 /* Turn on the screen and don't let anyone else mess with it. Called
657 from clean_shutdown in misc.c. */
658 queue_empty(&backlight_queue);
659 tick_remove_task(backlight_tick);
660 /* Next time the thread runs, if at all, it will just remove itself. */
661 queue_post(&backlight_queue, BACKLIGHT_QUIT, 0);
662 __backlight_on();
664 #endif /* X5_BACKLIGHT_SHUTDOWN */
666 void backlight_on(void)
668 queue_remove_from_head(&backlight_queue, BACKLIGHT_ON);
669 queue_post(&backlight_queue, BACKLIGHT_ON, 0);
672 void backlight_off(void)
674 queue_post(&backlight_queue, BACKLIGHT_OFF, 0);
677 /* returns true when the backlight is on OR when it's set to always off */
678 bool is_backlight_on(void)
680 if (backlight_timer || backlight_get_current_timeout() <= 0)
681 return true;
682 else
683 return false;
686 /* return value in ticks; 0 means always on, <0 means always off */
687 int backlight_get_current_timeout(void)
689 #if CONFIG_CHARGING
690 if (charger_inserted()
691 #ifdef HAVE_USB_POWER
692 || usb_powered()
693 #endif
695 return backlight_timeout_plugged;
696 else
697 return backlight_timeout;
698 #else
699 return backlight_timeout;
700 #endif
703 void backlight_set_timeout(int index)
705 if((unsigned)index >= sizeof(backlight_timeout_value))
706 /* if given a weird value, use default */
707 index = 6;
708 backlight_timeout = HZ * backlight_timeout_value[index];
709 backlight_update_state();
712 #if CONFIG_CHARGING
713 void backlight_set_timeout_plugged(int index)
715 if((unsigned)index >= sizeof(backlight_timeout_value))
716 /* if given a weird value, use default */
717 index = 6;
718 backlight_timeout_plugged = HZ * backlight_timeout_value[index];
719 backlight_update_state();
721 #endif /* CONFIG_CHARGING */
723 #ifdef HAS_BUTTON_HOLD
724 /* Hold button change event handler. */
725 void backlight_hold_changed(bool hold_button)
727 /* Hold switch overrides all backlight behavior except when
728 set to "Normal" */
729 /* Queue or freeze */
730 if (hold_button && backlight_on_button_hold == 1)
731 backlight_off(); /* setting == Off */
732 else /* setting == On, Normal, no hold button, or anything else */
733 backlight_on();
736 void backlight_set_on_button_hold(int index)
738 if ((unsigned)index >= 3)
739 /* if given a weird value, use default */
740 index = 0;
742 if (index == backlight_on_button_hold)
743 return;
745 backlight_on_button_hold = index;
746 backlight_hold_changed(button_hold());
748 #endif /* HAS_BUTTON_HOLD */
750 #ifdef HAVE_LCD_SLEEP
751 void lcd_set_sleep_after_backlight_off(int index)
753 if ((unsigned)index >= sizeof(lcd_sleep_timeout_value))
754 /* if given a weird value, use default */
755 index = 3;
757 lcd_sleep_timeout = HZ * lcd_sleep_timeout_value[index];
759 if (backlight_timer > 0 || backlight_get_current_timeout() == 0)
760 /* Timer will be set when bl turns off or bl set to on. */
761 return;
763 /* Backlight is Off */
764 if (lcd_sleep_timeout < 0)
765 lcd_sleep_timer = 1; /* Always - sleep next tick */
766 else
767 lcd_sleep_timer = lcd_sleep_timeout; /* Never, other */
769 #endif /* HAVE_LCD_SLEEP */
771 #ifdef HAVE_REMOTE_LCD
772 void remote_backlight_on(void)
774 queue_post(&backlight_queue, REMOTE_BACKLIGHT_ON, 0);
777 void remote_backlight_off(void)
779 queue_post(&backlight_queue, REMOTE_BACKLIGHT_OFF, 0);
782 void remote_backlight_set_timeout(int index)
784 if((unsigned)index >= sizeof(backlight_timeout_value))
785 /* if given a weird value, use default */
786 index=6;
787 remote_backlight_timeout = HZ * backlight_timeout_value[index];
788 remote_backlight_update_state();
791 #if CONFIG_CHARGING
792 void remote_backlight_set_timeout_plugged(int index)
794 if((unsigned)index >= sizeof(backlight_timeout_value))
795 /* if given a weird value, use default */
796 index=6;
797 remote_backlight_timeout_plugged = HZ * backlight_timeout_value[index];
798 remote_backlight_update_state();
800 #endif /* CONFIG_CHARGING */
802 #ifdef HAS_REMOTE_BUTTON_HOLD
803 /* Remote hold button change event handler. */
804 void remote_backlight_hold_changed(bool rc_hold_button)
806 /* Hold switch overrides all backlight behavior except when
807 set to "Normal" */
808 /* Queue or freeze */
809 if (rc_hold_button && remote_backlight_on_button_hold == 1)
810 remote_backlight_off(); /* setting == Off */
811 else /* setting == On, Normal, no hold button, or anything else */
812 remote_backlight_on();
815 void remote_backlight_set_on_button_hold(int index)
817 if ((unsigned)index >= 3)
818 /* if given a weird value, use default */
819 index = 0;
821 if (index == remote_backlight_on_button_hold)
822 return;
824 remote_backlight_on_button_hold = index;
825 remote_backlight_hold_changed(remote_button_hold());
827 #endif /* HAS_REMOTE_BUTTON_HOLD */
829 /* return value in ticks; 0 means always on, <0 means always off */
830 int remote_backlight_get_current_timeout(void)
832 #if CONFIG_CHARGING
833 if (charger_inserted()
834 #ifdef HAVE_USB_POWER
835 || usb_powered()
836 #endif
838 return remote_backlight_timeout_plugged;
839 else
840 return remote_backlight_timeout;
841 #else
842 return remote_backlight_timeout;
843 #endif
846 /* returns true when the backlight is on OR when it's set to always off */
847 bool is_remote_backlight_on(void)
849 if (remote_backlight_timer != 0 ||
850 remote_backlight_get_current_timeout() <= 0)
851 return true;
852 else
853 return false;
856 #endif /* HAVE_REMOTE_LCD */
858 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
859 void backlight_set_brightness(int val)
861 if (val < MIN_BRIGHTNESS_SETTING)
862 val = MIN_BRIGHTNESS_SETTING;
863 else if (val > MAX_BRIGHTNESS_SETTING)
864 val = MAX_BRIGHTNESS_SETTING;
866 __backlight_set_brightness(val);
868 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
870 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
871 void buttonlight_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 __buttonlight_set_brightness(val);
880 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
882 #else /* !defined(HAVE_BACKLIGHT) || defined(BOOTLOADER)
883 -- no backlight, empty dummy functions */
885 #if defined(BOOTLOADER) && defined(HAVE_BACKLIGHT)
886 void backlight_init(void)
888 (void)__backlight_init();
889 __backlight_on();
891 #endif
893 void backlight_on(void) {}
894 void backlight_off(void) {}
895 void button_backlight_on(void) {}
896 void backlight_set_timeout(int index) {(void)index;}
897 bool is_backlight_on(void) {return true;}
898 #ifdef HAVE_REMOTE_LCD
899 void remote_backlight_on(void) {}
900 void remote_backlight_off(void) {}
901 void remote_backlight_set_timeout(int index) {(void)index;}
902 bool is_remote_backlight_on(void) {return true;}
903 #endif /* HAVE_REMOTE_LCD */
904 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
905 void backlight_set_brightness(int val) { (void)val; }
906 #endif
907 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
908 void buttonlight_set_brightness(int val) { (void)val; }
909 #endif
910 #endif /* defined(HAVE_BACKLIGHT) && !defined(BOOTLOADER) */