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"
44 #include "backlight-target.h"
46 #include "backlight-sim.h"
49 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
50 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
51 #include "backlight-sw-fading.h"
54 #if defined(HAVE_BACKLIGHT) && defined(BACKLIGHT_FULL_INIT)
56 #define BACKLIGHT_FADE_IN_THREAD \
57 (CONFIG_BACKLIGHT_FADING & (BACKLIGHT_FADING_SW_SETTING \
58 |BACKLIGHT_FADING_SW_HW_REG \
59 |BACKLIGHT_FADING_PWM) )
61 #define BACKLIGHT_THREAD_TIMEOUT HZ
66 BACKLIGHT_TMO_CHANGED
,
67 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
68 BACKLIGHT_BRIGHTNESS_CHANGED
,
70 #ifdef HAVE_REMOTE_LCD
73 REMOTE_BACKLIGHT_TMO_CHANGED
,
75 #if defined(_BACKLIGHT_FADE_BOOST) || defined(_BACKLIGHT_FADE_ENABLE)
76 BACKLIGHT_FADE_FINISH
,
81 #ifdef HAVE_BUTTON_LIGHT
84 BUTTON_LIGHT_TMO_CHANGED
,
85 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
86 BUTTON_LIGHT_BRIGHTNESS_CHANGED
,
88 #endif /* HAVE_BUTTON_LIGHT */
89 #ifdef BACKLIGHT_DRIVER_CLOSE
94 static void backlight_thread(void);
95 static long backlight_stack
[DEFAULT_STACK_SIZE
/sizeof(long)];
96 static const char backlight_thread_name
[] = "backlight";
97 static struct event_queue backlight_queue
;
98 #ifdef BACKLIGHT_DRIVER_CLOSE
99 static unsigned int backlight_thread_id
= 0;
102 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
103 int backlight_brightness
= DEFAULT_BRIGHTNESS_SETTING
;
105 static int backlight_timer SHAREDBSS_ATTR
;
106 static int backlight_timeout_normal
= 5*HZ
;
108 static int backlight_timeout_plugged
= 5*HZ
;
110 #ifdef HAS_BUTTON_HOLD
111 static int backlight_on_button_hold
= 0;
113 static void backlight_timeout_handler(void);
115 #ifdef HAVE_BUTTON_LIGHT
116 static int buttonlight_timer
;
117 static int buttonlight_timeout
= 5*HZ
;
119 /* Update state of buttonlight according to timeout setting */
120 static void buttonlight_update_state(void)
122 buttonlight_timer
= buttonlight_timeout
;
124 /* Buttonlight == OFF in the setting? */
125 if (buttonlight_timer
< 0)
127 buttonlight_timer
= 0; /* Disable the timeout */
134 /* external interface */
135 void buttonlight_on(void)
137 queue_remove_from_head(&backlight_queue
, BUTTON_LIGHT_ON
);
138 queue_post(&backlight_queue
, BUTTON_LIGHT_ON
, 0);
141 void buttonlight_off(void)
143 queue_post(&backlight_queue
, BUTTON_LIGHT_OFF
, 0);
146 void buttonlight_set_timeout(int value
)
148 buttonlight_timeout
= HZ
* value
;
149 queue_post(&backlight_queue
, BUTTON_LIGHT_TMO_CHANGED
, 0);
152 int buttonlight_get_current_timeout(void)
154 return buttonlight_timeout
;
157 #endif /* HAVE_BUTTON_LIGHT */
159 #ifdef HAVE_REMOTE_LCD
160 static int remote_backlight_timer
;
161 static int remote_backlight_timeout_normal
= 5*HZ
;
163 static int remote_backlight_timeout_plugged
= 5*HZ
;
165 #ifdef HAS_REMOTE_BUTTON_HOLD
166 static int remote_backlight_on_button_hold
= 0;
168 #endif /* HAVE_REMOTE_LCD */
170 #ifdef HAVE_LCD_SLEEP
171 #ifdef HAVE_LCD_SLEEP_SETTING
172 const signed char lcd_sleep_timeout_value
[10] =
174 -1, 0, 5, 10, 15, 20, 30, 45, 60, 90
176 static int lcd_sleep_timeout
= 10*HZ
;
178 /* Target defines needed value */
179 #define lcd_sleep_timeout LCD_SLEEP_TIMEOUT
182 static int lcd_sleep_timer SHAREDDATA_ATTR
= 0;
184 static void backlight_lcd_sleep_countdown(bool start
)
188 /* Cancel the LCD sleep countdown */
193 /* Start LCD sleep countdown */
194 if (lcd_sleep_timeout
< 0)
196 lcd_sleep_timer
= 0; /* Setting == Always */
197 /* Ensure lcd_sleep() is called from backlight_thread() */
198 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
199 queue_post(&backlight_queue
, LCD_SLEEP
, 0);
206 lcd_sleep_timer
= lcd_sleep_timeout
;
209 #endif /* HAVE_LCD_SLEEP */
211 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
212 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
213 static int backlight_fading_type
= (FADING_UP
|FADING_DOWN
);
214 static int backlight_fading_state
= NOT_FADING
;
218 /* backlight fading */
219 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
220 #define BL_PWM_INTERVAL 5 /* Cycle interval in ms */
221 #define BL_PWM_BITS 8
222 #define BL_PWM_COUNT (1<<BL_PWM_BITS)
224 /* s15.16 fixed point variables */
225 static int32_t bl_fade_in_step
= ((BL_PWM_INTERVAL
*BL_PWM_COUNT
)<<16)/300;
226 static int32_t bl_fade_out_step
= ((BL_PWM_INTERVAL
*BL_PWM_COUNT
)<<16)/2000;
227 static int32_t bl_dim_fraction
= 0;
229 static int bl_dim_target
= 0;
230 static int bl_dim_current
= 0;
231 static enum {DIM_STATE_START
, DIM_STATE_MAIN
} bl_dim_state
= DIM_STATE_START
;
232 static bool bl_timer_active
= false;
234 static void backlight_isr(void)
236 int timer_period
= (TIMER_FREQ
*BL_PWM_INTERVAL
/1000);
239 switch (bl_dim_state
)
242 case DIM_STATE_START
:
243 bl_dim_current
= bl_dim_fraction
>> 16;
245 if (bl_dim_current
> 0 && bl_dim_current
< BL_PWM_COUNT
)
248 timer_period
= (timer_period
* bl_dim_current
) >> BL_PWM_BITS
;
249 bl_dim_state
= DIM_STATE_MAIN
;
256 _backlight_off_isr();
257 if (bl_dim_current
== bl_dim_target
)
260 if (bl_dim_current
< bl_dim_target
)
262 bl_dim_fraction
= MIN(bl_dim_fraction
+ bl_fade_in_step
,
265 else if (bl_dim_current
> bl_dim_target
)
267 bl_dim_fraction
= MAX(bl_dim_fraction
- bl_fade_out_step
, 0);
271 /* Dim main screen */
273 _backlight_off_isr();
274 timer_period
= (timer_period
* (BL_PWM_COUNT
- bl_dim_current
))
276 bl_dim_state
= DIM_STATE_START
;
281 #if defined(_BACKLIGHT_FADE_BOOST) || defined(_BACKLIGHT_FADE_ENABLE)
282 queue_post(&backlight_queue
, BACKLIGHT_FADE_FINISH
, 0);
285 bl_timer_active
= false;
287 #ifdef HAVE_LCD_SLEEP
288 if (bl_dim_current
== 0)
289 backlight_lcd_sleep_countdown(true);
293 timer_set_period(timer_period
);
296 static void backlight_switch(void)
298 if (bl_dim_target
> (BL_PWM_COUNT
/2))
300 _backlight_on_normal();
301 bl_dim_fraction
= (BL_PWM_COUNT
<<16);
305 _backlight_off_normal();
308 #ifdef HAVE_LCD_SLEEP
309 backlight_lcd_sleep_countdown(true);
314 static void backlight_release_timer(void)
316 #ifdef _BACKLIGHT_FADE_BOOST
320 bl_timer_active
= false;
324 static void backlight_dim(int value
)
326 /* protect from extraneous calls with the same target value */
327 if (value
== bl_dim_target
)
330 bl_dim_target
= value
;
335 if (timer_register(0, backlight_release_timer
, 2, backlight_isr
338 #ifdef _BACKLIGHT_FADE_BOOST
339 /* Prevent cpu frequency changes while dimming. */
342 bl_timer_active
= true;
348 static void backlight_setup_fade_up(void)
350 if (bl_fade_in_step
> 0)
352 #ifdef _BACKLIGHT_FADE_ENABLE
353 _backlight_hw_enable(true);
355 backlight_dim(BL_PWM_COUNT
);
359 bl_dim_target
= BL_PWM_COUNT
;
360 bl_dim_fraction
= (BL_PWM_COUNT
<<16);
361 _backlight_on_normal();
365 static void backlight_setup_fade_down(void)
367 if (bl_fade_out_step
> 0)
373 bl_dim_target
= bl_dim_fraction
= 0;
374 _backlight_off_normal();
375 #ifdef HAVE_LCD_SLEEP
376 backlight_lcd_sleep_countdown(true);
381 void backlight_set_fade_in(int value
)
384 bl_fade_in_step
= ((BL_PWM_INTERVAL
*BL_PWM_COUNT
)<<16) / value
;
389 void backlight_set_fade_out(int value
)
392 bl_fade_out_step
= ((BL_PWM_INTERVAL
*BL_PWM_COUNT
)<<16) / value
;
394 bl_fade_out_step
= 0;
397 #elif (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
398 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
400 void backlight_set_fade_out(bool value
)
403 backlight_fading_type
|= FADING_DOWN
;
405 backlight_fading_type
&= FADING_UP
;
408 void backlight_set_fade_in(bool value
)
411 backlight_fading_type
|= FADING_UP
;
413 backlight_fading_type
&= FADING_DOWN
;
416 static void backlight_setup_fade_up(void)
418 if (backlight_fading_type
& FADING_UP
)
420 if (backlight_fading_state
== NOT_FADING
)
422 /* make sure the backlight is at lowest level */
425 backlight_fading_state
= FADING_UP
;
429 backlight_fading_state
= NOT_FADING
;
430 _backlight_fade_update_state(backlight_brightness
);
432 _backlight_set_brightness(backlight_brightness
);
436 static void backlight_setup_fade_down(void)
438 if (backlight_fading_type
& FADING_DOWN
)
440 backlight_fading_state
= FADING_DOWN
;
444 backlight_fading_state
= NOT_FADING
;
445 _backlight_fade_update_state(MIN_BRIGHTNESS_SETTING
-1);
447 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
448 /* write the lowest brightness level to the hardware so that
449 * fading up is glitch free */
450 _backlight_set_brightness(MIN_BRIGHTNESS_SETTING
);
452 #ifdef HAVE_LCD_SLEEP
453 backlight_lcd_sleep_countdown(true);
457 #endif /* CONFIG_BACKLIGHT_FADING */
459 static inline void do_backlight_off(void)
462 #if BACKLIGHT_FADE_IN_THREAD
463 backlight_setup_fade_down();
466 /* targets that have fading need to start the countdown when done with
468 #ifdef HAVE_LCD_SLEEP
469 backlight_lcd_sleep_countdown(true);
474 /* Update state of backlight according to timeout setting */
475 static void backlight_update_state(void)
478 int timeout
= backlight_get_current_timeout();
480 /* Backlight == OFF in the setting? */
481 if (UNLIKELY(timeout
< 0))
484 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
485 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
486 /* necessary step to issue fading down when the setting is selected */
487 if (queue_empty(&backlight_queue
))
488 queue_post(&backlight_queue
, SYS_TIMEOUT
, 0);
493 backlight_timer
= timeout
;
495 #ifdef HAVE_LCD_SLEEP
496 backlight_lcd_sleep_countdown(false); /* wake up lcd */
499 #if BACKLIGHT_FADE_IN_THREAD
500 backlight_setup_fade_up();
507 #ifdef HAVE_REMOTE_LCD
508 /* Update state of remote backlight according to timeout setting */
509 static void remote_backlight_update_state(void)
511 int timeout
= remote_backlight_get_current_timeout();
512 /* Backlight == OFF in the setting? */
515 remote_backlight_timer
= 0; /* Disable the timeout */
516 _remote_backlight_off();
520 remote_backlight_timer
= timeout
;
521 _remote_backlight_on();
524 #endif /* HAVE_REMOTE_LCD */
526 void backlight_thread(void)
528 struct queue_event ev
;
533 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
534 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
535 if (backlight_fading_state
!= NOT_FADING
)
536 queue_wait_w_tmo(&backlight_queue
, &ev
, FADE_DELAY
);
539 queue_wait_w_tmo(&backlight_queue
, &ev
, BACKLIGHT_THREAD_TIMEOUT
);
541 { /* These events must always be processed */
542 #ifdef _BACKLIGHT_FADE_BOOST
543 case BACKLIGHT_FADE_FINISH
:
547 #ifdef _BACKLIGHT_FADE_ENABLE
548 case BACKLIGHT_FADE_FINISH
:
549 _backlight_hw_enable((bl_dim_current
|bl_dim_target
) != 0);
554 /* Here for now or else the aggressive init messes up scrolling */
555 #ifdef HAVE_REMOTE_LCD
556 case SYS_REMOTE_PLUGGED
:
561 case SYS_REMOTE_UNPLUGGED
:
564 #elif defined HAVE_REMOTE_LCD_AS_MAIN
565 case SYS_REMOTE_PLUGGED
:
570 case SYS_REMOTE_UNPLUGGED
:
573 #endif /* HAVE_REMOTE_LCD/ HAVE_REMOTE_LCD_AS_MAIN */
574 #endif /* !SIMULATOR */
575 case SYS_USB_CONNECTED
:
576 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
579 case SYS_USB_DISCONNECTED
:
580 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
583 #ifdef BACKLIGHT_DRIVER_CLOSE
584 /* Get out of here */
593 { /* These events are only processed if backlight isn't locked */
594 #ifdef HAVE_REMOTE_LCD
595 case REMOTE_BACKLIGHT_TMO_CHANGED
:
596 case REMOTE_BACKLIGHT_ON
:
597 remote_backlight_update_state();
600 case REMOTE_BACKLIGHT_OFF
:
601 remote_backlight_timer
= 0; /* Disable the timeout */
602 _remote_backlight_off();
604 #endif /* HAVE_REMOTE_LCD */
606 case BACKLIGHT_TMO_CHANGED
:
608 backlight_update_state();
614 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
615 case BACKLIGHT_BRIGHTNESS_CHANGED
:
616 backlight_brightness
= (int)ev
.data
;
617 _backlight_set_brightness((int)ev
.data
);
618 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
619 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
620 /* receive backlight brightness */
621 _backlight_fade_update_state((int)ev
.data
);
624 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
625 #ifdef HAVE_LCD_SLEEP
630 #ifdef HAVE_BUTTON_LIGHT
631 case BUTTON_LIGHT_TMO_CHANGED
:
632 case BUTTON_LIGHT_ON
:
633 buttonlight_update_state();
636 case BUTTON_LIGHT_OFF
:
637 buttonlight_timer
= 0;
640 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
641 case BUTTON_LIGHT_BRIGHTNESS_CHANGED
:
642 _buttonlight_set_brightness((int)ev
.data
);
644 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
645 #endif /* HAVE_BUTTON_LIGHT */
647 case SYS_POWEROFF
: /* Lock backlight on poweroff so it doesn't */
648 locked
= true; /* go off before power is actually cut. */
651 case SYS_CHARGER_CONNECTED
:
652 case SYS_CHARGER_DISCONNECTED
:
654 backlight_update_state();
655 #ifdef HAVE_REMOTE_LCD
656 remote_backlight_update_state();
660 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
661 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
662 if (backlight_fading_state
!= NOT_FADING
)
664 if ((_backlight_fade_step(backlight_fading_state
)))
665 { /* finished fading */
666 #ifdef HAVE_LCD_SLEEP
667 if (backlight_fading_state
== FADING_DOWN
)
668 { /* start sleep countdown */
669 backlight_lcd_sleep_countdown(true);
672 backlight_fading_state
= NOT_FADING
;
676 #endif /* CONFIG_BACKLIGHT_FADING */
677 backlight_timeout_handler();
683 static void backlight_timeout_handler(void)
685 if(backlight_timer
> 0)
687 backlight_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
688 if(backlight_timer
<= 0)
693 #ifdef HAVE_LCD_SLEEP
694 else if(lcd_sleep_timer
> 0)
696 lcd_sleep_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
697 if(lcd_sleep_timer
<= 0)
702 #endif /* HAVE_LCD_SLEEP */
703 #ifdef HAVE_REMOTE_LCD
704 if(remote_backlight_timer
> 0)
706 remote_backlight_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
707 if(remote_backlight_timer
<= 0)
709 _remote_backlight_off();
712 #endif /* HAVE_REMOVE_LCD */
713 #ifdef HAVE_BUTTON_LIGHT
714 if (buttonlight_timer
> 0)
716 buttonlight_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
717 if (buttonlight_timer
<= 0)
722 #endif /* HAVE_BUTTON_LIGHT */
725 void backlight_init(void)
727 queue_init(&backlight_queue
, true);
729 if (_backlight_init())
731 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
732 /* If backlight is already on, don't fade in. */
733 bl_dim_target
= BL_PWM_COUNT
;
734 bl_dim_fraction
= (BL_PWM_COUNT
<<16);
737 /* Leave all lights as set by the bootloader here. The settings load will
738 * call the appropriate backlight_set_*() functions, only changing light
739 * status if necessary. */
740 #ifdef BACKLIGHT_DRIVER_CLOSE
741 backlight_thread_id
=
743 create_thread(backlight_thread
, backlight_stack
,
744 sizeof(backlight_stack
), 0, backlight_thread_name
745 IF_PRIO(, PRIORITY_USER_INTERFACE
)
749 #ifdef BACKLIGHT_DRIVER_CLOSE
750 void backlight_close(void)
752 unsigned int thread
= backlight_thread_id
;
754 /* Wait for thread to exit */
758 backlight_thread_id
= 0;
760 queue_post(&backlight_queue
, BACKLIGHT_QUIT
, 0);
763 #endif /* BACKLIGHT_DRIVER_CLOSE */
765 void backlight_on(void)
767 queue_remove_from_head(&backlight_queue
, BACKLIGHT_ON
);
768 queue_post(&backlight_queue
, BACKLIGHT_ON
, 0);
771 void backlight_off(void)
773 queue_post(&backlight_queue
, BACKLIGHT_OFF
, 0);
776 /* returns true when the backlight is on,
777 * and optionally when it's set to always off. */
778 bool is_backlight_on(bool ignore_always_off
)
780 int timeout
= backlight_get_current_timeout();
781 return (backlight_timer
> 0) /* countdown */
782 || (timeout
== 0) /* always on */
783 || ((timeout
< 0) && !ignore_always_off
);
786 /* return value in ticks; 0 means always on, <0 means always off */
787 int backlight_get_current_timeout(void)
789 #ifdef HAS_BUTTON_HOLD
790 if ((backlight_on_button_hold
!= 0)
791 #ifdef HAVE_REMOTE_LCD_AS_MAIN
792 && remote_button_hold()
797 return (backlight_on_button_hold
== 2) ? 0 : -1;
798 /* always on or always off */
802 if (power_input_present())
803 return backlight_timeout_plugged
;
806 return backlight_timeout_normal
;
809 void backlight_set_timeout(int value
)
811 backlight_timeout_normal
= HZ
* value
;
812 queue_post(&backlight_queue
, BACKLIGHT_TMO_CHANGED
, 0);
816 void backlight_set_timeout_plugged(int value
)
818 backlight_timeout_plugged
= HZ
* value
;
819 queue_post(&backlight_queue
, BACKLIGHT_TMO_CHANGED
, 0);
821 #endif /* CONFIG_CHARGING */
823 #ifdef HAS_BUTTON_HOLD
824 /* Hold button change event handler. */
825 void backlight_hold_changed(bool hold_button
)
827 if (!hold_button
|| (backlight_on_button_hold
> 0))
828 /* if unlocked or override in effect */
832 void backlight_set_on_button_hold(int index
)
834 if ((unsigned)index
>= 3)
835 /* if given a weird value, use default */
838 backlight_on_button_hold
= index
;
839 queue_post(&backlight_queue
, BACKLIGHT_TMO_CHANGED
, 0);
841 #endif /* HAS_BUTTON_HOLD */
843 #ifdef HAVE_LCD_SLEEP_SETTING
844 void lcd_set_sleep_after_backlight_off(int index
)
846 if ((unsigned)index
>= sizeof(lcd_sleep_timeout_value
))
847 /* if given a weird value, use default */
850 lcd_sleep_timeout
= HZ
* lcd_sleep_timeout_value
[index
];
852 if (is_backlight_on(true))
853 /* Timer will be set when bl turns off or bl set to on. */
856 /* Backlight is Off */
857 if (lcd_sleep_timeout
< 0)
858 lcd_sleep_timer
= 1; /* Always - sleep next tick */
860 lcd_sleep_timer
= lcd_sleep_timeout
; /* Never, other */
862 #endif /* HAVE_LCD_SLEEP_SETTING */
864 #ifdef HAVE_REMOTE_LCD
865 void remote_backlight_on(void)
867 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_ON
, 0);
870 void remote_backlight_off(void)
872 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_OFF
, 0);
875 void remote_backlight_set_timeout(int value
)
877 remote_backlight_timeout_normal
= HZ
* value
;
878 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_TMO_CHANGED
, 0);
882 void remote_backlight_set_timeout_plugged(int value
)
884 remote_backlight_timeout_plugged
= HZ
* value
;
885 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_TMO_CHANGED
, 0);
887 #endif /* CONFIG_CHARGING */
889 #ifdef HAS_REMOTE_BUTTON_HOLD
890 /* Remote hold button change event handler. */
891 void remote_backlight_hold_changed(bool rc_hold_button
)
893 if (!rc_hold_button
|| (remote_backlight_on_button_hold
> 0))
894 /* if unlocked or override */
895 remote_backlight_on();
898 void remote_backlight_set_on_button_hold(int index
)
900 if ((unsigned)index
>= 3)
901 /* if given a weird value, use default */
904 remote_backlight_on_button_hold
= index
;
905 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_TMO_CHANGED
, 0);
907 #endif /* HAS_REMOTE_BUTTON_HOLD */
909 /* return value in ticks; 0 means always on, <0 means always off */
910 int remote_backlight_get_current_timeout(void)
912 #ifdef HAS_REMOTE_BUTTON_HOLD
913 if (remote_button_hold() && (remote_backlight_on_button_hold
!= 0))
914 return (remote_backlight_on_button_hold
== 2)
915 ? 0 : -1; /* always on or always off */
919 if (power_input_present())
920 return remote_backlight_timeout_plugged
;
923 return remote_backlight_timeout_normal
;
926 /* returns true when the backlight is on, and
927 * optionally when it's set to always off */
928 bool is_remote_backlight_on(bool ignore_always_off
)
930 int timeout
= remote_backlight_get_current_timeout();
931 return (remote_backlight_timer
> 0) /* countdown */
932 || (timeout
== 0) /* always on */
933 || ((timeout
< 0) && !ignore_always_off
);
936 #endif /* HAVE_REMOTE_LCD */
938 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
939 void backlight_set_brightness(int val
)
941 if (val
< MIN_BRIGHTNESS_SETTING
)
942 val
= MIN_BRIGHTNESS_SETTING
;
943 else if (val
> MAX_BRIGHTNESS_SETTING
)
944 val
= MAX_BRIGHTNESS_SETTING
;
946 queue_post(&backlight_queue
, BACKLIGHT_BRIGHTNESS_CHANGED
, val
);
948 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
950 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
951 void buttonlight_set_brightness(int val
)
953 if (val
< MIN_BRIGHTNESS_SETTING
)
954 val
= MIN_BRIGHTNESS_SETTING
;
955 else if (val
> MAX_BRIGHTNESS_SETTING
)
956 val
= MAX_BRIGHTNESS_SETTING
;
958 queue_post(&backlight_queue
, BUTTON_LIGHT_BRIGHTNESS_CHANGED
, val
);
960 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
962 #else /* !defined(HAVE_BACKLIGHT) || !defined(BACKLIGHT_FULL_INIT)
963 -- no backlight, empty dummy functions */
965 #if defined(HAVE_BACKLIGHT) && !defined(BACKLIGHT_FULL_INIT)
966 void backlight_init(void)
968 (void)_backlight_init();
973 void backlight_on(void) {}
974 void backlight_off(void) {}
975 void buttonlight_on(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
; }
997 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
998 void buttonlight_set_brightness(int val
) { (void)val
; }
1000 #endif /* defined(HAVE_BACKLIGHT) && defined(BACKLIGHT_FULL_INIT) */