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 queue_post(&backlight_queue
, SYS_TIMEOUT
, 0);
492 backlight_timer
= timeout
;
494 #ifdef HAVE_LCD_SLEEP
495 backlight_lcd_sleep_countdown(false); /* wake up lcd */
498 #if BACKLIGHT_FADE_IN_THREAD
499 backlight_setup_fade_up();
506 #ifdef HAVE_REMOTE_LCD
507 /* Update state of remote backlight according to timeout setting */
508 static void remote_backlight_update_state(void)
510 int timeout
= remote_backlight_get_current_timeout();
511 /* Backlight == OFF in the setting? */
514 remote_backlight_timer
= 0; /* Disable the timeout */
515 _remote_backlight_off();
519 remote_backlight_timer
= timeout
;
520 _remote_backlight_on();
523 #endif /* HAVE_REMOTE_LCD */
525 void backlight_thread(void)
527 struct queue_event ev
;
532 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
533 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
534 if (backlight_fading_state
!= NOT_FADING
)
535 queue_wait_w_tmo(&backlight_queue
, &ev
, FADE_DELAY
);
538 queue_wait_w_tmo(&backlight_queue
, &ev
, BACKLIGHT_THREAD_TIMEOUT
);
540 { /* These events must always be processed */
541 #ifdef _BACKLIGHT_FADE_BOOST
542 case BACKLIGHT_FADE_FINISH
:
546 #ifdef _BACKLIGHT_FADE_ENABLE
547 case BACKLIGHT_FADE_FINISH
:
548 _backlight_hw_enable((bl_dim_current
|bl_dim_target
) != 0);
553 /* Here for now or else the aggressive init messes up scrolling */
554 #ifdef HAVE_REMOTE_LCD
555 case SYS_REMOTE_PLUGGED
:
560 case SYS_REMOTE_UNPLUGGED
:
563 #elif defined HAVE_REMOTE_LCD_AS_MAIN
564 case SYS_REMOTE_PLUGGED
:
569 case SYS_REMOTE_UNPLUGGED
:
572 #endif /* HAVE_REMOTE_LCD/ HAVE_REMOTE_LCD_AS_MAIN */
573 #endif /* !SIMULATOR */
574 case SYS_USB_CONNECTED
:
575 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
578 case SYS_USB_DISCONNECTED
:
579 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
582 #ifdef BACKLIGHT_DRIVER_CLOSE
583 /* Get out of here */
592 { /* These events are only processed if backlight isn't locked */
593 #ifdef HAVE_REMOTE_LCD
594 case REMOTE_BACKLIGHT_TMO_CHANGED
:
595 case REMOTE_BACKLIGHT_ON
:
596 remote_backlight_update_state();
599 case REMOTE_BACKLIGHT_OFF
:
600 remote_backlight_timer
= 0; /* Disable the timeout */
601 _remote_backlight_off();
603 #endif /* HAVE_REMOTE_LCD */
605 case BACKLIGHT_TMO_CHANGED
:
607 backlight_update_state();
613 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
614 case BACKLIGHT_BRIGHTNESS_CHANGED
:
615 backlight_brightness
= (int)ev
.data
;
616 _backlight_set_brightness((int)ev
.data
);
617 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
618 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
619 /* receive backlight brightness */
620 _backlight_fade_update_state((int)ev
.data
);
623 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
624 #ifdef HAVE_LCD_SLEEP
629 #ifdef HAVE_BUTTON_LIGHT
630 case BUTTON_LIGHT_TMO_CHANGED
:
631 case BUTTON_LIGHT_ON
:
632 buttonlight_update_state();
635 case BUTTON_LIGHT_OFF
:
636 buttonlight_timer
= 0;
639 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
640 case BUTTON_LIGHT_BRIGHTNESS_CHANGED
:
641 _buttonlight_set_brightness((int)ev
.data
);
643 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
644 #endif /* HAVE_BUTTON_LIGHT */
646 case SYS_POWEROFF
: /* Lock backlight on poweroff so it doesn't */
647 locked
= true; /* go off before power is actually cut. */
650 case SYS_CHARGER_CONNECTED
:
651 case SYS_CHARGER_DISCONNECTED
:
653 backlight_update_state();
654 #ifdef HAVE_REMOTE_LCD
655 remote_backlight_update_state();
659 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
660 || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
661 if (backlight_fading_state
!= NOT_FADING
)
663 if ((_backlight_fade_step(backlight_fading_state
)))
664 { /* finished fading */
665 #ifdef HAVE_LCD_SLEEP
666 if (backlight_fading_state
== FADING_DOWN
)
667 { /* start sleep countdown */
668 backlight_lcd_sleep_countdown(true);
671 backlight_fading_state
= NOT_FADING
;
675 #endif /* CONFIG_BACKLIGHT_FADING */
676 backlight_timeout_handler();
682 static void backlight_timeout_handler(void)
684 if(backlight_timer
> 0)
686 backlight_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
687 if(backlight_timer
<= 0)
692 #ifdef HAVE_LCD_SLEEP
693 else if(lcd_sleep_timer
> 0)
695 lcd_sleep_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
696 if(lcd_sleep_timer
<= 0)
701 #endif /* HAVE_LCD_SLEEP */
702 #ifdef HAVE_REMOTE_LCD
703 if(remote_backlight_timer
> 0)
705 remote_backlight_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
706 if(remote_backlight_timer
<= 0)
708 _remote_backlight_off();
711 #endif /* HAVE_REMOVE_LCD */
712 #ifdef HAVE_BUTTON_LIGHT
713 if (buttonlight_timer
> 0)
715 buttonlight_timer
-= BACKLIGHT_THREAD_TIMEOUT
;
716 if (buttonlight_timer
<= 0)
721 #endif /* HAVE_BUTTON_LIGHT */
724 void backlight_init(void)
726 queue_init(&backlight_queue
, true);
728 if (_backlight_init())
730 #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
731 /* If backlight is already on, don't fade in. */
732 bl_dim_target
= BL_PWM_COUNT
;
733 bl_dim_fraction
= (BL_PWM_COUNT
<<16);
736 /* Leave all lights as set by the bootloader here. The settings load will
737 * call the appropriate backlight_set_*() functions, only changing light
738 * status if necessary. */
739 #ifdef BACKLIGHT_DRIVER_CLOSE
740 backlight_thread_id
=
742 create_thread(backlight_thread
, backlight_stack
,
743 sizeof(backlight_stack
), 0, backlight_thread_name
744 IF_PRIO(, PRIORITY_USER_INTERFACE
)
748 #ifdef BACKLIGHT_DRIVER_CLOSE
749 void backlight_close(void)
751 unsigned int thread
= backlight_thread_id
;
753 /* Wait for thread to exit */
757 backlight_thread_id
= 0;
759 queue_post(&backlight_queue
, BACKLIGHT_QUIT
, 0);
762 #endif /* BACKLIGHT_DRIVER_CLOSE */
764 void backlight_on(void)
766 queue_remove_from_head(&backlight_queue
, BACKLIGHT_ON
);
767 queue_post(&backlight_queue
, BACKLIGHT_ON
, 0);
770 void backlight_off(void)
772 queue_post(&backlight_queue
, BACKLIGHT_OFF
, 0);
775 /* returns true when the backlight is on,
776 * and optionally when it's set to always off. */
777 bool is_backlight_on(bool ignore_always_off
)
779 int timeout
= backlight_get_current_timeout();
780 return (backlight_timer
> 0) /* countdown */
781 || (timeout
== 0) /* always on */
782 || ((timeout
< 0) && !ignore_always_off
);
785 /* return value in ticks; 0 means always on, <0 means always off */
786 int backlight_get_current_timeout(void)
788 #ifdef HAS_BUTTON_HOLD
789 if ((backlight_on_button_hold
!= 0)
790 #ifdef HAVE_REMOTE_LCD_AS_MAIN
791 && remote_button_hold()
796 return (backlight_on_button_hold
== 2) ? 0 : -1;
797 /* always on or always off */
801 if (power_input_present())
802 return backlight_timeout_plugged
;
805 return backlight_timeout_normal
;
808 void backlight_set_timeout(int value
)
810 backlight_timeout_normal
= HZ
* value
;
811 queue_post(&backlight_queue
, BACKLIGHT_TMO_CHANGED
, 0);
815 void backlight_set_timeout_plugged(int value
)
817 backlight_timeout_plugged
= HZ
* value
;
818 queue_post(&backlight_queue
, BACKLIGHT_TMO_CHANGED
, 0);
820 #endif /* CONFIG_CHARGING */
822 #ifdef HAS_BUTTON_HOLD
823 /* Hold button change event handler. */
824 void backlight_hold_changed(bool hold_button
)
826 if (!hold_button
|| (backlight_on_button_hold
> 0))
827 /* if unlocked or override in effect */
831 void backlight_set_on_button_hold(int index
)
833 if ((unsigned)index
>= 3)
834 /* if given a weird value, use default */
837 backlight_on_button_hold
= index
;
838 queue_post(&backlight_queue
, BACKLIGHT_TMO_CHANGED
, 0);
840 #endif /* HAS_BUTTON_HOLD */
842 #ifdef HAVE_LCD_SLEEP_SETTING
843 void lcd_set_sleep_after_backlight_off(int index
)
845 if ((unsigned)index
>= sizeof(lcd_sleep_timeout_value
))
846 /* if given a weird value, use default */
849 lcd_sleep_timeout
= HZ
* lcd_sleep_timeout_value
[index
];
851 if (is_backlight_on(true))
852 /* Timer will be set when bl turns off or bl set to on. */
855 /* Backlight is Off */
856 if (lcd_sleep_timeout
< 0)
857 lcd_sleep_timer
= 1; /* Always - sleep next tick */
859 lcd_sleep_timer
= lcd_sleep_timeout
; /* Never, other */
861 #endif /* HAVE_LCD_SLEEP_SETTING */
863 #ifdef HAVE_REMOTE_LCD
864 void remote_backlight_on(void)
866 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_ON
, 0);
869 void remote_backlight_off(void)
871 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_OFF
, 0);
874 void remote_backlight_set_timeout(int value
)
876 remote_backlight_timeout_normal
= HZ
* value
;
877 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_TMO_CHANGED
, 0);
881 void remote_backlight_set_timeout_plugged(int value
)
883 remote_backlight_timeout_plugged
= HZ
* value
;
884 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_TMO_CHANGED
, 0);
886 #endif /* CONFIG_CHARGING */
888 #ifdef HAS_REMOTE_BUTTON_HOLD
889 /* Remote hold button change event handler. */
890 void remote_backlight_hold_changed(bool rc_hold_button
)
892 if (!rc_hold_button
|| (remote_backlight_on_button_hold
> 0))
893 /* if unlocked or override */
894 remote_backlight_on();
897 void remote_backlight_set_on_button_hold(int index
)
899 if ((unsigned)index
>= 3)
900 /* if given a weird value, use default */
903 remote_backlight_on_button_hold
= index
;
904 queue_post(&backlight_queue
, REMOTE_BACKLIGHT_TMO_CHANGED
, 0);
906 #endif /* HAS_REMOTE_BUTTON_HOLD */
908 /* return value in ticks; 0 means always on, <0 means always off */
909 int remote_backlight_get_current_timeout(void)
911 #ifdef HAS_REMOTE_BUTTON_HOLD
912 if (remote_button_hold() && (remote_backlight_on_button_hold
!= 0))
913 return (remote_backlight_on_button_hold
== 2)
914 ? 0 : -1; /* always on or always off */
918 if (power_input_present())
919 return remote_backlight_timeout_plugged
;
922 return remote_backlight_timeout_normal
;
925 /* returns true when the backlight is on, and
926 * optionally when it's set to always off */
927 bool is_remote_backlight_on(bool ignore_always_off
)
929 int timeout
= remote_backlight_get_current_timeout();
930 return (remote_backlight_timer
> 0) /* countdown */
931 || (timeout
== 0) /* always on */
932 || ((timeout
< 0) && !ignore_always_off
);
935 #endif /* HAVE_REMOTE_LCD */
937 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
938 void backlight_set_brightness(int val
)
940 if (val
< MIN_BRIGHTNESS_SETTING
)
941 val
= MIN_BRIGHTNESS_SETTING
;
942 else if (val
> MAX_BRIGHTNESS_SETTING
)
943 val
= MAX_BRIGHTNESS_SETTING
;
945 queue_post(&backlight_queue
, BACKLIGHT_BRIGHTNESS_CHANGED
, val
);
947 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
949 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
950 void buttonlight_set_brightness(int val
)
952 if (val
< MIN_BRIGHTNESS_SETTING
)
953 val
= MIN_BRIGHTNESS_SETTING
;
954 else if (val
> MAX_BRIGHTNESS_SETTING
)
955 val
= MAX_BRIGHTNESS_SETTING
;
957 queue_post(&backlight_queue
, BUTTON_LIGHT_BRIGHTNESS_CHANGED
, val
);
959 #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
961 #else /* !defined(HAVE_BACKLIGHT) || !defined(BACKLIGHT_FULL_INIT)
962 -- no backlight, empty dummy functions */
964 #if defined(HAVE_BACKLIGHT) && !defined(BACKLIGHT_FULL_INIT)
965 void backlight_init(void)
967 (void)_backlight_init();
972 void backlight_on(void) {}
973 void backlight_off(void) {}
974 void buttonlight_on(void) {}
975 void backlight_set_timeout(int value
) {(void)value
;}
977 bool is_backlight_on(bool ignore_always_off
)
979 (void)ignore_always_off
;
982 #ifdef HAVE_REMOTE_LCD
983 void remote_backlight_on(void) {}
984 void remote_backlight_off(void) {}
985 void remote_backlight_set_timeout(int value
) {(void)value
;}
987 bool is_remote_backlight_on(bool ignore_always_off
)
989 (void)ignore_always_off
;
992 #endif /* HAVE_REMOTE_LCD */
993 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
994 void backlight_set_brightness(int val
) { (void)val
; }
996 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
997 void buttonlight_set_brightness(int val
) { (void)val
; }
999 #endif /* defined(HAVE_BACKLIGHT) && defined(BACKLIGHT_FULL_INIT) */