1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 * Additional work by Martin Ritter (2007) and Thomas Martitz (2008)
12 * for backlight thread fading
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
36 #include "backlight.h"
38 #include "screendump.h"
40 #ifdef HAVE_REMOTE_LCD
41 #include "lcd-remote.h"
45 #include "backlight-target.h"
47 #include "backlight-sim.h"
50 #if defined(HAVE_BACKLIGHT) && defined(BACKLIGHT_FULL_INIT)
52 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
53 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
54 #include "backlight-sw-fading.h"
57 #define BACKLIGHT_FADE_IN_THREAD \
58 (CONFIG_BACKLIGHT_FADING & (BACKLIGHT_FADING_SW_SETTING \
59 |BACKLIGHT_FADING_SW_HW_REG \
60 |BACKLIGHT_FADING_PWM) )
62 #define BACKLIGHT_THREAD_TIMEOUT HZ
67 BACKLIGHT_TMO_CHANGED
,
68 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
69 BACKLIGHT_BRIGHTNESS_CHANGED
,
71 #ifdef HAVE_REMOTE_LCD
74 REMOTE_BACKLIGHT_TMO_CHANGED
,
76 #if defined(_BACKLIGHT_FADE_BOOST) || defined(_BACKLIGHT_FADE_ENABLE)
77 BACKLIGHT_FADE_FINISH
,
82 #ifdef HAVE_BUTTON_LIGHT
85 BUTTON_LIGHT_TMO_CHANGED
,
86 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
87 BUTTON_LIGHT_BRIGHTNESS_CHANGED
,
89 #endif /* HAVE_BUTTON_LIGHT */
90 #ifdef BACKLIGHT_DRIVER_CLOSE
95 static void backlight_thread(void);
96 static long backlight_stack
[DEFAULT_STACK_SIZE
/sizeof(long)];
97 static const char backlight_thread_name
[] = "backlight";
98 static struct event_queue backlight_queue SHAREDBSS_ATTR
;
99 #ifdef BACKLIGHT_DRIVER_CLOSE
100 static unsigned int backlight_thread_id
= 0;
103 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
104 int backlight_brightness
= DEFAULT_BRIGHTNESS_SETTING
;
106 static int backlight_timer SHAREDBSS_ATTR
;
107 static int backlight_timeout_normal
= 5*HZ
;
109 static int backlight_timeout_plugged
= 5*HZ
;
111 #ifdef HAS_BUTTON_HOLD
112 static int backlight_on_button_hold
= 0;
114 static void backlight_timeout_handler(void);
116 #ifdef HAVE_BUTTON_LIGHT
117 static int buttonlight_timer
;
118 static int buttonlight_timeout
= 5*HZ
;
120 /* Update state of buttonlight according to timeout setting */
121 static void buttonlight_update_state(void)
123 buttonlight_timer
= buttonlight_timeout
;
125 /* Buttonlight == OFF in the setting? */
126 if (buttonlight_timer
< 0)
128 buttonlight_timer
= 0; /* Disable the timeout */
135 /* external interface */
136 void buttonlight_on(void)
138 queue_remove_from_head(&backlight_queue
, BUTTON_LIGHT_ON
);
139 queue_post(&backlight_queue
, BUTTON_LIGHT_ON
, 0);
142 void buttonlight_off(void)
144 queue_post(&backlight_queue
, BUTTON_LIGHT_OFF
, 0);
147 void buttonlight_set_timeout(int value
)
149 buttonlight_timeout
= HZ
* value
;
150 queue_post(&backlight_queue
, BUTTON_LIGHT_TMO_CHANGED
, 0);
153 int buttonlight_get_current_timeout(void)
155 return buttonlight_timeout
;
158 #endif /* HAVE_BUTTON_LIGHT */
160 #ifdef HAVE_REMOTE_LCD
161 static int remote_backlight_timer
;
162 static int remote_backlight_timeout_normal
= 5*HZ
;
164 static int remote_backlight_timeout_plugged
= 5*HZ
;
166 #ifdef HAS_REMOTE_BUTTON_HOLD
167 static int remote_backlight_on_button_hold
= 0;
169 #endif /* HAVE_REMOTE_LCD */
171 #ifdef HAVE_LCD_SLEEP
172 #ifdef HAVE_LCD_SLEEP_SETTING
173 const signed char lcd_sleep_timeout_value
[10] =
175 -1, 0, 5, 10, 15, 20, 30, 45, 60, 90
177 static int lcd_sleep_timeout
= 10*HZ
;
179 /* Target defines needed value */
180 #define lcd_sleep_timeout LCD_SLEEP_TIMEOUT
183 static int lcd_sleep_timer SHAREDDATA_ATTR
= 0;
185 static void backlight_lcd_sleep_countdown(bool start
)
189 /* Cancel the LCD sleep countdown */
194 /* Start LCD sleep countdown */
195 if (lcd_sleep_timeout
< 0)
197 lcd_sleep_timer
= 0; /* Setting == Always */
198 /* Ensure lcd_sleep() is called from backlight_thread() */
199 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
200 queue_post(&backlight_queue
, LCD_SLEEP
, 0);
207 lcd_sleep_timer
= lcd_sleep_timeout
;
210 #endif /* HAVE_LCD_SLEEP */
212 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
213 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
214 static int backlight_fading_type
= (FADING_UP
|FADING_DOWN
);
215 static int backlight_fading_state
= NOT_FADING
;
219 /* backlight fading */
220 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
221 #define BL_PWM_INTERVAL 5 /* Cycle interval in ms */
222 #define BL_PWM_BITS 8
223 #define BL_PWM_COUNT (1<<BL_PWM_BITS)
225 /* s15.16 fixed point variables */
226 static int32_t bl_fade_in_step
= ((BL_PWM_INTERVAL
*BL_PWM_COUNT
)<<16)/300;
227 static int32_t bl_fade_out_step
= ((BL_PWM_INTERVAL
*BL_PWM_COUNT
)<<16)/2000;
228 static int32_t bl_dim_fraction
= 0;
230 static int bl_dim_target
= 0;
231 static int bl_dim_current
= 0;
232 static enum {DIM_STATE_START
, DIM_STATE_MAIN
} bl_dim_state
= DIM_STATE_START
;
233 static bool bl_timer_active
= false;
235 static void backlight_isr(void)
237 int timer_period
= (TIMER_FREQ
*BL_PWM_INTERVAL
/1000);
240 switch (bl_dim_state
)
243 case DIM_STATE_START
:
244 bl_dim_current
= bl_dim_fraction
>> 16;
246 if (bl_dim_current
> 0 && bl_dim_current
< BL_PWM_COUNT
)
249 timer_period
= (timer_period
* bl_dim_current
) >> BL_PWM_BITS
;
250 bl_dim_state
= DIM_STATE_MAIN
;
257 _backlight_off_isr();
258 if (bl_dim_current
== bl_dim_target
)
261 if (bl_dim_current
< bl_dim_target
)
263 bl_dim_fraction
= MIN(bl_dim_fraction
+ bl_fade_in_step
,
266 else if (bl_dim_current
> bl_dim_target
)
268 bl_dim_fraction
= MAX(bl_dim_fraction
- bl_fade_out_step
, 0);
272 /* Dim main screen */
274 _backlight_off_isr();
275 timer_period
= (timer_period
* (BL_PWM_COUNT
- bl_dim_current
))
277 bl_dim_state
= DIM_STATE_START
;
282 #if defined(_BACKLIGHT_FADE_BOOST) || defined(_BACKLIGHT_FADE_ENABLE)
283 queue_post(&backlight_queue
, BACKLIGHT_FADE_FINISH
, 0);
286 bl_timer_active
= false;
288 #ifdef HAVE_LCD_SLEEP
289 if (bl_dim_current
== 0)
290 backlight_lcd_sleep_countdown(true);
294 timer_set_period(timer_period
);
297 static void backlight_switch(void)
299 if (bl_dim_target
> (BL_PWM_COUNT
/2))
301 _backlight_on_normal();
302 bl_dim_fraction
= (BL_PWM_COUNT
<<16);
306 _backlight_off_normal();
309 #ifdef HAVE_LCD_SLEEP
310 backlight_lcd_sleep_countdown(true);
315 static void backlight_release_timer(void)
317 #ifdef _BACKLIGHT_FADE_BOOST
321 bl_timer_active
= false;
325 static void backlight_dim(int value
)
327 /* protect from extraneous calls with the same target value */
328 if (value
== bl_dim_target
)
331 bl_dim_target
= value
;
336 if (timer_register(0, backlight_release_timer
, 2, backlight_isr
339 #ifdef _BACKLIGHT_FADE_BOOST
340 /* Prevent cpu frequency changes while dimming. */
343 bl_timer_active
= true;
349 static void backlight_setup_fade_up(void)
351 if (bl_fade_in_step
> 0)
353 #ifdef _BACKLIGHT_FADE_ENABLE
354 _backlight_hw_enable(true);
356 backlight_dim(BL_PWM_COUNT
);
360 bl_dim_target
= BL_PWM_COUNT
;
361 bl_dim_fraction
= (BL_PWM_COUNT
<<16);
362 _backlight_on_normal();
366 static void backlight_setup_fade_down(void)
368 if (bl_fade_out_step
> 0)
374 bl_dim_target
= bl_dim_fraction
= 0;
375 _backlight_off_normal();
376 #ifdef HAVE_LCD_SLEEP
377 backlight_lcd_sleep_countdown(true);
382 void backlight_set_fade_in(int value
)
385 bl_fade_in_step
= ((BL_PWM_INTERVAL
*BL_PWM_COUNT
)<<16) / value
;
390 void backlight_set_fade_out(int value
)
393 bl_fade_out_step
= ((BL_PWM_INTERVAL
*BL_PWM_COUNT
)<<16) / value
;
395 bl_fade_out_step
= 0;
398 #elif (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
399 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
401 void backlight_set_fade_out(bool value
)
404 backlight_fading_type
|= FADING_DOWN
;
406 backlight_fading_type
&= FADING_UP
;
409 void backlight_set_fade_in(bool value
)
412 backlight_fading_type
|= FADING_UP
;
414 backlight_fading_type
&= FADING_DOWN
;
417 static void backlight_setup_fade_up(void)
419 if (backlight_fading_type
& FADING_UP
)
421 if (backlight_fading_state
== NOT_FADING
)
423 /* make sure the backlight is at lowest level */
426 backlight_fading_state
= FADING_UP
;
430 backlight_fading_state
= NOT_FADING
;
431 _backlight_fade_update_state(backlight_brightness
);
433 _backlight_set_brightness(backlight_brightness
);
437 static void backlight_setup_fade_down(void)
439 if (backlight_fading_type
& FADING_DOWN
)
441 backlight_fading_state
= FADING_DOWN
;
445 backlight_fading_state
= NOT_FADING
;
446 _backlight_fade_update_state(MIN_BRIGHTNESS_SETTING
-1);
448 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
449 /* write the lowest brightness level to the hardware so that
450 * fading up is glitch free */
451 _backlight_set_brightness(MIN_BRIGHTNESS_SETTING
);
453 #ifdef HAVE_LCD_SLEEP
454 backlight_lcd_sleep_countdown(true);
458 #endif /* CONFIG_BACKLIGHT_FADING */
460 static inline void do_backlight_off(void)
463 #if BACKLIGHT_FADE_IN_THREAD
464 backlight_setup_fade_down();
467 /* targets that have fading need to start the countdown when done with
469 #ifdef HAVE_LCD_SLEEP
470 backlight_lcd_sleep_countdown(true);
475 /* Update state of backlight according to timeout setting */
476 static void backlight_update_state(void)
479 int timeout
= backlight_get_current_timeout();
481 /* Backlight == OFF in the setting? */
482 if (UNLIKELY(timeout
< 0))
485 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
486 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
487 /* necessary step to issue fading down when the setting is selected */
488 if (queue_empty(&backlight_queue
))
489 queue_post(&backlight_queue
, SYS_TIMEOUT
, 0);
494 backlight_timer
= timeout
;
496 #ifdef HAVE_LCD_SLEEP
497 backlight_lcd_sleep_countdown(false); /* wake up lcd */
500 #if BACKLIGHT_FADE_IN_THREAD
501 backlight_setup_fade_up();
508 #ifdef HAVE_REMOTE_LCD
509 /* Update state of remote backlight according to timeout setting */
510 static void remote_backlight_update_state(void)
512 int timeout
= remote_backlight_get_current_timeout();
513 /* Backlight == OFF in the setting? */
516 remote_backlight_timer
= 0; /* Disable the timeout */
517 _remote_backlight_off();
521 remote_backlight_timer
= timeout
;
522 _remote_backlight_on();
525 #endif /* HAVE_REMOTE_LCD */
527 void backlight_thread(void)
529 struct queue_event ev
;
534 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
535 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
536 if (backlight_fading_state
!= NOT_FADING
)
537 queue_wait_w_tmo(&backlight_queue
, &ev
, FADE_DELAY
);
540 queue_wait_w_tmo(&backlight_queue
, &ev
, BACKLIGHT_THREAD_TIMEOUT
);
542 { /* These events must always be processed */
543 #ifdef _BACKLIGHT_FADE_BOOST
544 case BACKLIGHT_FADE_FINISH
:
548 #ifdef _BACKLIGHT_FADE_ENABLE
549 case BACKLIGHT_FADE_FINISH
:
550 _backlight_hw_enable((bl_dim_current
|bl_dim_target
) != 0);
555 /* Here for now or else the aggressive init messes up scrolling */
556 #ifdef HAVE_REMOTE_LCD
557 case SYS_REMOTE_PLUGGED
:
562 case SYS_REMOTE_UNPLUGGED
:
565 #elif defined HAVE_REMOTE_LCD_AS_MAIN
566 case SYS_REMOTE_PLUGGED
:
571 case SYS_REMOTE_UNPLUGGED
:
574 #endif /* HAVE_REMOTE_LCD/ HAVE_REMOTE_LCD_AS_MAIN */
575 #endif /* !SIMULATOR */
576 case SYS_USB_CONNECTED
:
577 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
580 #ifdef BACKLIGHT_DRIVER_CLOSE
581 /* Get out of here */
590 { /* These events are only processed if backlight isn't locked */
591 #ifdef HAVE_REMOTE_LCD
592 case REMOTE_BACKLIGHT_TMO_CHANGED
:
593 case REMOTE_BACKLIGHT_ON
:
594 remote_backlight_update_state();
597 case REMOTE_BACKLIGHT_OFF
:
598 remote_backlight_timer
= 0; /* Disable the timeout */
599 _remote_backlight_off();
601 #endif /* HAVE_REMOTE_LCD */
603 case BACKLIGHT_TMO_CHANGED
:
605 backlight_update_state();
611 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
612 case BACKLIGHT_BRIGHTNESS_CHANGED
:
613 backlight_brightness
= (int)ev
.data
;
614 _backlight_set_brightness((int)ev
.data
);
615 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
616 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
617 /* receive backlight brightness */
618 _backlight_fade_update_state((int)ev
.data
);
621 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
622 #ifdef HAVE_LCD_SLEEP
627 #ifdef HAVE_BUTTON_LIGHT
628 case BUTTON_LIGHT_TMO_CHANGED
:
629 case BUTTON_LIGHT_ON
:
630 buttonlight_update_state();
633 case BUTTON_LIGHT_OFF
:
634 buttonlight_timer
= 0;
637 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
638 case BUTTON_LIGHT_BRIGHTNESS_CHANGED
:
639 _buttonlight_set_brightness((int)ev
.data
);
641 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
642 #endif /* HAVE_BUTTON_LIGHT */
644 case SYS_POWEROFF
: /* Lock backlight on poweroff so it doesn't */
645 locked
= true; /* go off before power is actually cut. */
648 case SYS_CHARGER_CONNECTED
:
649 case SYS_CHARGER_DISCONNECTED
:
651 backlight_update_state();
652 #ifdef HAVE_REMOTE_LCD
653 remote_backlight_update_state();
657 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
658 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
659 if (backlight_fading_state
!= NOT_FADING
)
661 if ((_backlight_fade_step(backlight_fading_state
)))
662 { /* finished fading */
663 #ifdef HAVE_LCD_SLEEP
664 if (backlight_fading_state
== FADING_DOWN
)
665 { /* start sleep countdown */
666 backlight_lcd_sleep_countdown(true);
669 backlight_fading_state
= NOT_FADING
;
673 #endif /* CONFIG_BACKLIGHT_FADING */
674 backlight_timeout_handler();
680 static void backlight_timeout_handler(void)
682 if(backlight_timer
> 0)
684 backlight_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
685 if(backlight_timer
<= 0)
690 #ifdef HAVE_LCD_SLEEP
691 else if(lcd_sleep_timer
> 0)
693 lcd_sleep_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
694 if(lcd_sleep_timer
<= 0)
699 #endif /* HAVE_LCD_SLEEP */
700 #ifdef HAVE_REMOTE_LCD
701 if(remote_backlight_timer
> 0)
703 remote_backlight_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
704 if(remote_backlight_timer
<= 0)
706 _remote_backlight_off();
709 #endif /* HAVE_REMOVE_LCD */
710 #ifdef HAVE_BUTTON_LIGHT
711 if (buttonlight_timer
> 0)
713 buttonlight_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
714 if (buttonlight_timer
<= 0)
719 #endif /* HAVE_BUTTON_LIGHT */
722 void backlight_init(void)
724 queue_init(&backlight_queue
, true);
726 if (_backlight_init())
728 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
729 /* If backlight is already on, don't fade in. */
730 bl_dim_target
= BL_PWM_COUNT
;
731 bl_dim_fraction
= (BL_PWM_COUNT
<<16);
734 /* Leave all lights as set by the bootloader here. The settings load will
735 * call the appropriate backlight_set_*() functions, only changing light
736 * status if necessary. */
737 #ifdef BACKLIGHT_DRIVER_CLOSE
738 backlight_thread_id
=
740 create_thread(backlight_thread
, backlight_stack
,
741 sizeof(backlight_stack
), 0, backlight_thread_name
742 IF_PRIO(, PRIORITY_USER_INTERFACE
)
746 #ifdef BACKLIGHT_DRIVER_CLOSE
747 void backlight_close(void)
749 unsigned int thread
= backlight_thread_id
;
751 /* Wait for thread to exit */
755 backlight_thread_id
= 0;
757 queue_post(&backlight_queue
, BACKLIGHT_QUIT
, 0);
760 #endif /* BACKLIGHT_DRIVER_CLOSE */
762 void backlight_on(void)
764 queue_remove_from_head(&backlight_queue
, BACKLIGHT_ON
);
765 queue_post(&backlight_queue
, BACKLIGHT_ON
, 0);
768 void backlight_off(void)
770 queue_post(&backlight_queue
, BACKLIGHT_OFF
, 0);
773 /* returns true when the backlight is on,
774 * and optionally when it's set to always off. */
775 bool is_backlight_on(bool ignore_always_off
)
777 int timeout
= backlight_get_current_timeout();
778 return (backlight_timer
> 0) /* countdown */
779 || (timeout
== 0) /* always on */
780 || ((timeout
< 0) && !ignore_always_off
);
783 /* return value in ticks; 0 means always on, <0 means always off */
784 int backlight_get_current_timeout(void)
786 #ifdef HAS_BUTTON_HOLD
787 if ((backlight_on_button_hold
!= 0)
788 #ifdef HAVE_REMOTE_LCD_AS_MAIN
789 && remote_button_hold()
794 return (backlight_on_button_hold
== 2) ? 0 : -1;
795 /* always on or always off */
799 if (power_input_present())
800 return backlight_timeout_plugged
;
803 return backlight_timeout_normal
;
806 void backlight_set_timeout(int value
)
808 backlight_timeout_normal
= HZ
* value
;
809 queue_post(&backlight_queue
, BACKLIGHT_TMO_CHANGED
, 0);
813 void backlight_set_timeout_plugged(int value
)
815 backlight_timeout_plugged
= HZ
* value
;
816 queue_post(&backlight_queue
, BACKLIGHT_TMO_CHANGED
, 0);
818 #endif /* CONFIG_CHARGING */
820 #ifdef HAS_BUTTON_HOLD
821 /* Hold button change event handler. */
822 void backlight_hold_changed(bool hold_button
)
824 if (!hold_button
|| (backlight_on_button_hold
> 0))
825 /* if unlocked or override in effect */
829 void backlight_set_on_button_hold(int index
)
831 if ((unsigned)index
>= 3)
832 /* if given a weird value, use default */
835 backlight_on_button_hold
= index
;
836 queue_post(&backlight_queue
, BACKLIGHT_TMO_CHANGED
, 0);
838 #endif /* HAS_BUTTON_HOLD */
840 #ifdef HAVE_LCD_SLEEP_SETTING
841 void lcd_set_sleep_after_backlight_off(int index
)
843 if ((unsigned)index
>= sizeof(lcd_sleep_timeout_value
))
844 /* if given a weird value, use default */
847 lcd_sleep_timeout
= HZ
* lcd_sleep_timeout_value
[index
];
849 if (is_backlight_on(true))
850 /* Timer will be set when bl turns off or bl set to on. */
853 /* Backlight is Off */
854 if (lcd_sleep_timeout
< 0)
855 lcd_sleep_timer
= 1; /* Always - sleep next tick */
857 lcd_sleep_timer
= lcd_sleep_timeout
; /* Never, other */
859 #endif /* HAVE_LCD_SLEEP_SETTING */
861 #ifdef HAVE_REMOTE_LCD
862 void remote_backlight_on(void)
864 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_ON
, 0);
867 void remote_backlight_off(void)
869 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_OFF
, 0);
872 void remote_backlight_set_timeout(int value
)
874 remote_backlight_timeout_normal
= HZ
* value
;
875 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_TMO_CHANGED
, 0);
879 void remote_backlight_set_timeout_plugged(int value
)
881 remote_backlight_timeout_plugged
= HZ
* value
;
882 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_TMO_CHANGED
, 0);
884 #endif /* CONFIG_CHARGING */
886 #ifdef HAS_REMOTE_BUTTON_HOLD
887 /* Remote hold button change event handler. */
888 void remote_backlight_hold_changed(bool rc_hold_button
)
890 if (!rc_hold_button
|| (remote_backlight_on_button_hold
> 0))
891 /* if unlocked or override */
892 remote_backlight_on();
895 void remote_backlight_set_on_button_hold(int index
)
897 if ((unsigned)index
>= 3)
898 /* if given a weird value, use default */
901 remote_backlight_on_button_hold
= index
;
902 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_TMO_CHANGED
, 0);
904 #endif /* HAS_REMOTE_BUTTON_HOLD */
906 /* return value in ticks; 0 means always on, <0 means always off */
907 int remote_backlight_get_current_timeout(void)
909 #ifdef HAS_REMOTE_BUTTON_HOLD
910 if (remote_button_hold() && (remote_backlight_on_button_hold
!= 0))
911 return (remote_backlight_on_button_hold
== 2)
912 ? 0 : -1; /* always on or always off */
916 if (power_input_present())
917 return remote_backlight_timeout_plugged
;
920 return remote_backlight_timeout_normal
;
923 /* returns true when the backlight is on, and
924 * optionally when it's set to always off */
925 bool is_remote_backlight_on(bool ignore_always_off
)
927 int timeout
= remote_backlight_get_current_timeout();
928 return (remote_backlight_timer
> 0) /* countdown */
929 || (timeout
== 0) /* always on */
930 || ((timeout
< 0) && !ignore_always_off
);
933 #endif /* HAVE_REMOTE_LCD */
935 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
936 void backlight_set_brightness(int val
)
938 if (val
< MIN_BRIGHTNESS_SETTING
)
939 val
= MIN_BRIGHTNESS_SETTING
;
940 else if (val
> MAX_BRIGHTNESS_SETTING
)
941 val
= MAX_BRIGHTNESS_SETTING
;
943 queue_post(&backlight_queue
, BACKLIGHT_BRIGHTNESS_CHANGED
, val
);
945 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
947 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
948 void buttonlight_set_brightness(int val
)
950 if (val
< MIN_BRIGHTNESS_SETTING
)
951 val
= MIN_BRIGHTNESS_SETTING
;
952 else if (val
> MAX_BRIGHTNESS_SETTING
)
953 val
= MAX_BRIGHTNESS_SETTING
;
955 queue_post(&backlight_queue
, BUTTON_LIGHT_BRIGHTNESS_CHANGED
, val
);
957 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
959 #else /* !defined(HAVE_BACKLIGHT) || !defined(BACKLIGHT_FULL_INIT)
960 -- no backlight, empty dummy functions */
962 #if defined(HAVE_BACKLIGHT) && !defined(BACKLIGHT_FULL_INIT)
963 void backlight_init(void)
965 (void)_backlight_init();
970 void backlight_on(void) {}
971 void backlight_off(void) {}
972 void backlight_set_timeout(int value
) {(void)value
;}
974 bool is_backlight_on(bool ignore_always_off
)
976 (void)ignore_always_off
;
979 #ifdef HAVE_REMOTE_LCD
980 void remote_backlight_on(void) {}
981 void remote_backlight_off(void) {}
982 void remote_backlight_set_timeout(int value
) {(void)value
;}
984 bool is_remote_backlight_on(bool ignore_always_off
)
986 (void)ignore_always_off
;
989 #endif /* HAVE_REMOTE_LCD */
990 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
991 void backlight_set_brightness(int val
) { (void)val
; }
994 #ifdef HAVE_BUTTON_LIGHT
995 void buttonlight_on(void) {}
996 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
997 void buttonlight_set_brightness(int val
) { (void)val
; }
999 #endif /* HAVE_BUTTON_LIGHT */
1001 #endif /* defined(HAVE_BACKLIGHT) && defined(BACKLIGHT_FULL_INIT) */