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
;
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 case SYS_USB_DISCONNECTED
:
581 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
584 #ifdef BACKLIGHT_DRIVER_CLOSE
585 /* Get out of here */
594 { /* These events are only processed if backlight isn't locked */
595 #ifdef HAVE_REMOTE_LCD
596 case REMOTE_BACKLIGHT_TMO_CHANGED
:
597 case REMOTE_BACKLIGHT_ON
:
598 remote_backlight_update_state();
601 case REMOTE_BACKLIGHT_OFF
:
602 remote_backlight_timer
= 0; /* Disable the timeout */
603 _remote_backlight_off();
605 #endif /* HAVE_REMOTE_LCD */
607 case BACKLIGHT_TMO_CHANGED
:
609 backlight_update_state();
615 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
616 case BACKLIGHT_BRIGHTNESS_CHANGED
:
617 backlight_brightness
= (int)ev
.data
;
618 _backlight_set_brightness((int)ev
.data
);
619 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
620 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
621 /* receive backlight brightness */
622 _backlight_fade_update_state((int)ev
.data
);
625 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
626 #ifdef HAVE_LCD_SLEEP
631 #ifdef HAVE_BUTTON_LIGHT
632 case BUTTON_LIGHT_TMO_CHANGED
:
633 case BUTTON_LIGHT_ON
:
634 buttonlight_update_state();
637 case BUTTON_LIGHT_OFF
:
638 buttonlight_timer
= 0;
641 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
642 case BUTTON_LIGHT_BRIGHTNESS_CHANGED
:
643 _buttonlight_set_brightness((int)ev
.data
);
645 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
646 #endif /* HAVE_BUTTON_LIGHT */
648 case SYS_POWEROFF
: /* Lock backlight on poweroff so it doesn't */
649 locked
= true; /* go off before power is actually cut. */
652 case SYS_CHARGER_CONNECTED
:
653 case SYS_CHARGER_DISCONNECTED
:
655 backlight_update_state();
656 #ifdef HAVE_REMOTE_LCD
657 remote_backlight_update_state();
661 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
662 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
663 if (backlight_fading_state
!= NOT_FADING
)
665 if ((_backlight_fade_step(backlight_fading_state
)))
666 { /* finished fading */
667 #ifdef HAVE_LCD_SLEEP
668 if (backlight_fading_state
== FADING_DOWN
)
669 { /* start sleep countdown */
670 backlight_lcd_sleep_countdown(true);
673 backlight_fading_state
= NOT_FADING
;
677 #endif /* CONFIG_BACKLIGHT_FADING */
678 backlight_timeout_handler();
684 static void backlight_timeout_handler(void)
686 if(backlight_timer
> 0)
688 backlight_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
689 if(backlight_timer
<= 0)
694 #ifdef HAVE_LCD_SLEEP
695 else if(lcd_sleep_timer
> 0)
697 lcd_sleep_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
698 if(lcd_sleep_timer
<= 0)
703 #endif /* HAVE_LCD_SLEEP */
704 #ifdef HAVE_REMOTE_LCD
705 if(remote_backlight_timer
> 0)
707 remote_backlight_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
708 if(remote_backlight_timer
<= 0)
710 _remote_backlight_off();
713 #endif /* HAVE_REMOVE_LCD */
714 #ifdef HAVE_BUTTON_LIGHT
715 if (buttonlight_timer
> 0)
717 buttonlight_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
718 if (buttonlight_timer
<= 0)
723 #endif /* HAVE_BUTTON_LIGHT */
726 void backlight_init(void)
728 queue_init(&backlight_queue
, true);
730 if (_backlight_init())
732 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
733 /* If backlight is already on, don't fade in. */
734 bl_dim_target
= BL_PWM_COUNT
;
735 bl_dim_fraction
= (BL_PWM_COUNT
<<16);
738 /* Leave all lights as set by the bootloader here. The settings load will
739 * call the appropriate backlight_set_*() functions, only changing light
740 * status if necessary. */
741 #ifdef BACKLIGHT_DRIVER_CLOSE
742 backlight_thread_id
=
744 create_thread(backlight_thread
, backlight_stack
,
745 sizeof(backlight_stack
), 0, backlight_thread_name
746 IF_PRIO(, PRIORITY_USER_INTERFACE
)
750 #ifdef BACKLIGHT_DRIVER_CLOSE
751 void backlight_close(void)
753 unsigned int thread
= backlight_thread_id
;
755 /* Wait for thread to exit */
759 backlight_thread_id
= 0;
761 queue_post(&backlight_queue
, BACKLIGHT_QUIT
, 0);
764 #endif /* BACKLIGHT_DRIVER_CLOSE */
766 void backlight_on(void)
768 queue_remove_from_head(&backlight_queue
, BACKLIGHT_ON
);
769 queue_post(&backlight_queue
, BACKLIGHT_ON
, 0);
772 void backlight_off(void)
774 queue_post(&backlight_queue
, BACKLIGHT_OFF
, 0);
777 /* returns true when the backlight is on,
778 * and optionally when it's set to always off. */
779 bool is_backlight_on(bool ignore_always_off
)
781 int timeout
= backlight_get_current_timeout();
782 return (backlight_timer
> 0) /* countdown */
783 || (timeout
== 0) /* always on */
784 || ((timeout
< 0) && !ignore_always_off
);
787 /* return value in ticks; 0 means always on, <0 means always off */
788 int backlight_get_current_timeout(void)
790 #ifdef HAS_BUTTON_HOLD
791 if ((backlight_on_button_hold
!= 0)
792 #ifdef HAVE_REMOTE_LCD_AS_MAIN
793 && remote_button_hold()
798 return (backlight_on_button_hold
== 2) ? 0 : -1;
799 /* always on or always off */
803 if (power_input_present())
804 return backlight_timeout_plugged
;
807 return backlight_timeout_normal
;
810 void backlight_set_timeout(int value
)
812 backlight_timeout_normal
= HZ
* value
;
813 queue_post(&backlight_queue
, BACKLIGHT_TMO_CHANGED
, 0);
817 void backlight_set_timeout_plugged(int value
)
819 backlight_timeout_plugged
= HZ
* value
;
820 queue_post(&backlight_queue
, BACKLIGHT_TMO_CHANGED
, 0);
822 #endif /* CONFIG_CHARGING */
824 #ifdef HAS_BUTTON_HOLD
825 /* Hold button change event handler. */
826 void backlight_hold_changed(bool hold_button
)
828 if (!hold_button
|| (backlight_on_button_hold
> 0))
829 /* if unlocked or override in effect */
833 void backlight_set_on_button_hold(int index
)
835 if ((unsigned)index
>= 3)
836 /* if given a weird value, use default */
839 backlight_on_button_hold
= index
;
840 queue_post(&backlight_queue
, BACKLIGHT_TMO_CHANGED
, 0);
842 #endif /* HAS_BUTTON_HOLD */
844 #ifdef HAVE_LCD_SLEEP_SETTING
845 void lcd_set_sleep_after_backlight_off(int index
)
847 if ((unsigned)index
>= sizeof(lcd_sleep_timeout_value
))
848 /* if given a weird value, use default */
851 lcd_sleep_timeout
= HZ
* lcd_sleep_timeout_value
[index
];
853 if (is_backlight_on(true))
854 /* Timer will be set when bl turns off or bl set to on. */
857 /* Backlight is Off */
858 if (lcd_sleep_timeout
< 0)
859 lcd_sleep_timer
= 1; /* Always - sleep next tick */
861 lcd_sleep_timer
= lcd_sleep_timeout
; /* Never, other */
863 #endif /* HAVE_LCD_SLEEP_SETTING */
865 #ifdef HAVE_REMOTE_LCD
866 void remote_backlight_on(void)
868 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_ON
, 0);
871 void remote_backlight_off(void)
873 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_OFF
, 0);
876 void remote_backlight_set_timeout(int value
)
878 remote_backlight_timeout_normal
= HZ
* value
;
879 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_TMO_CHANGED
, 0);
883 void remote_backlight_set_timeout_plugged(int value
)
885 remote_backlight_timeout_plugged
= HZ
* value
;
886 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_TMO_CHANGED
, 0);
888 #endif /* CONFIG_CHARGING */
890 #ifdef HAS_REMOTE_BUTTON_HOLD
891 /* Remote hold button change event handler. */
892 void remote_backlight_hold_changed(bool rc_hold_button
)
894 if (!rc_hold_button
|| (remote_backlight_on_button_hold
> 0))
895 /* if unlocked or override */
896 remote_backlight_on();
899 void remote_backlight_set_on_button_hold(int index
)
901 if ((unsigned)index
>= 3)
902 /* if given a weird value, use default */
905 remote_backlight_on_button_hold
= index
;
906 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_TMO_CHANGED
, 0);
908 #endif /* HAS_REMOTE_BUTTON_HOLD */
910 /* return value in ticks; 0 means always on, <0 means always off */
911 int remote_backlight_get_current_timeout(void)
913 #ifdef HAS_REMOTE_BUTTON_HOLD
914 if (remote_button_hold() && (remote_backlight_on_button_hold
!= 0))
915 return (remote_backlight_on_button_hold
== 2)
916 ? 0 : -1; /* always on or always off */
920 if (power_input_present())
921 return remote_backlight_timeout_plugged
;
924 return remote_backlight_timeout_normal
;
927 /* returns true when the backlight is on, and
928 * optionally when it's set to always off */
929 bool is_remote_backlight_on(bool ignore_always_off
)
931 int timeout
= remote_backlight_get_current_timeout();
932 return (remote_backlight_timer
> 0) /* countdown */
933 || (timeout
== 0) /* always on */
934 || ((timeout
< 0) && !ignore_always_off
);
937 #endif /* HAVE_REMOTE_LCD */
939 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
940 void backlight_set_brightness(int val
)
942 if (val
< MIN_BRIGHTNESS_SETTING
)
943 val
= MIN_BRIGHTNESS_SETTING
;
944 else if (val
> MAX_BRIGHTNESS_SETTING
)
945 val
= MAX_BRIGHTNESS_SETTING
;
947 queue_post(&backlight_queue
, BACKLIGHT_BRIGHTNESS_CHANGED
, val
);
949 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
951 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
952 void buttonlight_set_brightness(int val
)
954 if (val
< MIN_BRIGHTNESS_SETTING
)
955 val
= MIN_BRIGHTNESS_SETTING
;
956 else if (val
> MAX_BRIGHTNESS_SETTING
)
957 val
= MAX_BRIGHTNESS_SETTING
;
959 queue_post(&backlight_queue
, BUTTON_LIGHT_BRIGHTNESS_CHANGED
, val
);
961 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
963 #else /* !defined(HAVE_BACKLIGHT) || !defined(BACKLIGHT_FULL_INIT)
964 -- no backlight, empty dummy functions */
966 #if defined(HAVE_BACKLIGHT) && !defined(BACKLIGHT_FULL_INIT)
967 void backlight_init(void)
969 (void)_backlight_init();
974 void backlight_on(void) {}
975 void backlight_off(void) {}
976 void backlight_set_timeout(int value
) {(void)value
;}
978 bool is_backlight_on(bool ignore_always_off
)
980 (void)ignore_always_off
;
983 #ifdef HAVE_REMOTE_LCD
984 void remote_backlight_on(void) {}
985 void remote_backlight_off(void) {}
986 void remote_backlight_set_timeout(int value
) {(void)value
;}
988 bool is_remote_backlight_on(bool ignore_always_off
)
990 (void)ignore_always_off
;
993 #endif /* HAVE_REMOTE_LCD */
994 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
995 void backlight_set_brightness(int val
) { (void)val
; }
998 #ifdef HAVE_BUTTON_LIGHT
999 void buttonlight_on(void) {}
1000 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
1001 void buttonlight_set_brightness(int val
) { (void)val
; }
1003 #endif /* HAVE_BUTTON_LIGHT */
1005 #endif /* defined(HAVE_BACKLIGHT) && defined(BACKLIGHT_FULL_INIT) */