Do the clamping a little better.
[kugel-rb.git] / firmware / backlight.c
blob2bdfe86c77736713bc873d030bae277b0ff0b823
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
61 #endif /* SIMULATOR */
63 #if defined(HAVE_BACKLIGHT) && !defined(BOOTLOADER)
65 const signed char backlight_timeout_value[19] =
67 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 45, 60, 90
70 #define BACKLIGHT_ON 1
71 #define BACKLIGHT_OFF 2
72 #define REMOTE_BACKLIGHT_ON 3
73 #define REMOTE_BACKLIGHT_OFF 4
74 #define BACKLIGHT_UNBOOST_CPU 5
75 #ifdef HAVE_LCD_SLEEP
76 #define LCD_SLEEP 6
77 #endif
78 #ifdef HAVE_BUTTON_LIGHT
79 #define BUTTON_LIGHT_ON 7
80 #define BUTTON_LIGHT_OFF 8
81 #endif
83 static void backlight_thread(void);
84 static long backlight_stack[DEFAULT_STACK_SIZE/sizeof(long)];
85 #ifdef X5_BACKLIGHT_SHUTDOWN
86 #define BACKLIGHT_QUIT 256
87 #endif
88 static const char backlight_thread_name[] = "backlight";
89 static struct event_queue backlight_queue;
91 static int backlight_timer;
92 static int backlight_timeout = 5*HZ;
93 #if CONFIG_CHARGING
94 static int backlight_timeout_plugged = 5*HZ;
95 #endif
96 #ifdef HAS_BUTTON_HOLD
97 static int backlight_on_button_hold = 0;
98 #endif
100 #ifdef HAVE_BUTTON_LIGHT
101 static int button_backlight_timer;
102 static int button_backlight_timeout = 5*HZ;
104 /* external interface */
105 void button_backlight_on(void)
107 queue_remove_from_head(&backlight_queue, BUTTON_LIGHT_ON);
108 queue_post(&backlight_queue, BUTTON_LIGHT_ON, 0);
111 void button_backlight_off(void)
113 queue_post(&backlight_queue, BUTTON_LIGHT_OFF, 0);
116 void button_backlight_set_timeout(int index)
118 if((unsigned)index >= sizeof(backlight_timeout_value))
119 /* if given a weird value, use default */
120 index = 6;
121 button_backlight_timeout = HZ * backlight_timeout_value[index];
122 if (index == 0) /* off */
123 button_backlight_off();
124 else if (index == 1) /* on */
125 button_backlight_on();
127 if (button_backlight_timer)
128 button_backlight_timer = button_backlight_timeout;
131 /* internal interface */
132 static void _button_backlight_on(void)
134 if (button_backlight_timeout < 0)
135 return;
136 button_backlight_timer = button_backlight_timeout;
137 #ifndef SIMULATOR
138 __button_backlight_on();
139 #endif
142 static void _button_backlight_off(void)
144 if (button_backlight_timeout == 0)
145 return;
146 button_backlight_timer = 0;
147 #ifndef SIMULATOR
148 __button_backlight_off();
149 #endif
152 #endif
154 #ifdef HAVE_REMOTE_LCD
155 static int remote_backlight_timer;
156 static int remote_backlight_timeout = 5*HZ;
157 #if CONFIG_CHARGING
158 static int remote_backlight_timeout_plugged = 5*HZ;
159 #endif
160 #ifdef HAS_REMOTE_BUTTON_HOLD
161 static int remote_backlight_on_button_hold = 0;
162 #endif
163 #endif
165 #ifdef HAVE_LCD_SLEEP
166 const signed char lcd_sleep_timeout_value[10] =
168 -1, 0, 5, 10, 15, 20, 30, 45, 60, 90
170 static int lcd_sleep_timer;
171 static int lcd_sleep_timeout = 10*HZ;
172 #endif
174 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
175 /* backlight fading */
176 #define BL_PWM_INTERVAL 5000 /* Cycle interval in s */
177 #define BL_PWM_COUNT 100
178 static const char backlight_fade_value[8] = { 0, 1, 2, 4, 6, 8, 10, 20 };
179 static int fade_in_count = 1;
180 static int fade_out_count = 4;
182 static bool bl_timer_active = false;
183 static int bl_dim_current = 0;
184 static int bl_dim_target = 0;
185 static int bl_pwm_counter = 0;
186 static volatile int bl_cycle_counter = 0;
187 static enum {DIM_STATE_START, DIM_STATE_MAIN} bl_dim_state = DIM_STATE_START;
189 static void backlight_isr(void)
191 int timer_period;
192 bool idle = false;
194 timer_period = TIMER_FREQ / 1000 * BL_PWM_INTERVAL / 1000;
195 switch (bl_dim_state)
197 /* New cycle */
198 case DIM_STATE_START:
199 bl_pwm_counter = 0;
200 bl_cycle_counter++;
202 if (bl_dim_current > 0 && bl_dim_current < BL_PWM_COUNT)
204 __backlight_on();
205 bl_pwm_counter = bl_dim_current;
206 timer_period = timer_period * bl_pwm_counter / BL_PWM_COUNT;
207 bl_dim_state = DIM_STATE_MAIN;
209 else
211 if (bl_dim_current)
212 __backlight_on();
213 else
214 __backlight_off();
215 if (bl_dim_current == bl_dim_target)
216 idle = true;
219 break ;
221 /* Dim main screen */
222 case DIM_STATE_MAIN:
223 __backlight_off();
224 bl_dim_state = DIM_STATE_START;
225 timer_period = timer_period * (BL_PWM_COUNT - bl_pwm_counter) / BL_PWM_COUNT;
226 break ;
229 if ((bl_dim_target > bl_dim_current) && (bl_cycle_counter >= fade_in_count))
231 bl_dim_current++;
232 bl_cycle_counter = 0;
235 if ((bl_dim_target < bl_dim_current) && (bl_cycle_counter >= fade_out_count))
237 bl_dim_current--;
238 bl_cycle_counter = 0;
241 if (idle)
243 #ifdef CPU_COLDFIRE
244 queue_post(&backlight_queue, BACKLIGHT_UNBOOST_CPU, 0);
245 #endif
246 timer_unregister();
247 bl_timer_active = false;
249 else
250 timer_set_period(timer_period);
253 static void backlight_switch(void)
255 if (bl_dim_target > (BL_PWM_COUNT/2))
257 __backlight_on();
258 bl_dim_current = BL_PWM_COUNT;
260 else
262 __backlight_off();
263 bl_dim_current = 0;
267 static void backlight_release_timer(void)
269 #ifdef CPU_COLDFIRE
270 cpu_boost(false);
271 #endif
272 timer_unregister();
273 bl_timer_active = false;
274 backlight_switch();
277 static void backlight_dim(int value)
279 /* protect from extraneous calls with the same target value */
280 if (value == bl_dim_target)
281 return;
283 bl_dim_target = value;
285 if (bl_timer_active)
286 return ;
288 if (timer_register(0, backlight_release_timer, 2, 0, backlight_isr))
290 #ifdef CPU_COLDFIRE
291 /* Prevent cpu frequency changes while dimming. */
292 cpu_boost(true);
293 #endif
294 bl_timer_active = true;
296 else
297 backlight_switch();
300 void backlight_set_fade_in(int index)
302 fade_in_count = backlight_fade_value[index];
305 void backlight_set_fade_out(int index)
307 fade_out_count = backlight_fade_value[index];
309 #endif /* defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) */
311 static void _backlight_on(void)
313 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
314 if (fade_in_count > 0)
315 backlight_dim(BL_PWM_COUNT);
316 else
318 bl_dim_target = bl_dim_current = BL_PWM_COUNT;
319 __backlight_on();
321 #elif defined(HAVE_BACKLIGHT_SET_FADING) && !defined(SIMULATOR)
322 /* call the enable from here - it takes longer than the disable */
323 lcd_enable(true);
324 __backlight_dim(false);
325 #else
326 __backlight_on();
327 #endif
328 #ifdef HAVE_LCD_SLEEP
329 lcd_sleep_timer = 0; /* LCD should be awake already */
330 #endif
333 static void _backlight_off(void)
335 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
336 if (fade_out_count > 0)
337 backlight_dim(0);
338 else
340 bl_dim_target = bl_dim_current = 0;
341 __backlight_off();
343 #elif defined(HAVE_BACKLIGHT_SET_FADING) && !defined(SIMULATOR)
344 __backlight_dim(true);
345 #else
346 __backlight_off();
347 #endif
349 #ifdef HAVE_LCD_SLEEP
350 /* Start LCD sleep countdown */
351 if (lcd_sleep_timeout < 0)
353 lcd_sleep_timer = 0; /* Setting == Always */
354 lcd_sleep();
356 else
357 lcd_sleep_timer = lcd_sleep_timeout;
358 #endif
361 #ifdef HAVE_REMOTE_LCD
362 #ifdef SIMULATOR
363 static void __remote_backlight_on(void)
365 sim_remote_backlight(100);
368 static void __remote_backlight_off(void)
370 sim_remote_backlight(0);
372 #endif /* SIMULATOR */
373 #endif /* HAVE_REMOTE_LCD */
375 /* Update state of backlight according to timeout setting */
376 static void backlight_update_state(void)
378 #if CONFIG_CHARGING
379 if (charger_inserted()
380 #ifdef HAVE_USB_POWER
381 || usb_powered()
382 #endif
384 backlight_timer = backlight_timeout_plugged;
385 else
386 #endif
387 backlight_timer = backlight_timeout;
389 /* Backlight == OFF in the setting? */
390 if (backlight_timer < 0)
392 backlight_timer = 0; /* Disable the timeout */
393 #ifdef HAS_BUTTON_HOLD
394 if (backlight_on_button_hold == 2 && button_hold())
395 return; /* Keep on if "On" */
396 #endif
397 _backlight_off();
399 else
401 #ifdef HAS_BUTTON_HOLD
402 if (backlight_on_button_hold == 1 && button_hold())
404 /* Keep off if "Off". */
405 backlight_timer = 0; /* Disable the timeout */
406 return;
408 #endif
409 _backlight_on();
413 #ifdef HAVE_REMOTE_LCD
414 /* Update state of remote backlight according to timeout setting */
415 static void remote_backlight_update_state(void)
417 #if CONFIG_CHARGING
418 if (charger_inserted()
419 #ifdef HAVE_USB_POWER
420 || usb_powered()
421 #endif
423 remote_backlight_timer = remote_backlight_timeout_plugged;
424 else
425 #endif
426 remote_backlight_timer = remote_backlight_timeout;
428 /* Backlight == OFF in the setting? */
429 if (remote_backlight_timer < 0)
431 remote_backlight_timer = 0; /* Disable the timeout */
432 #ifdef HAS_REMOTE_BUTTON_HOLD
433 if (remote_backlight_on_button_hold == 2 && remote_button_hold())
434 return; /* Keep on if "On" */
435 #endif
436 __remote_backlight_off();
438 else
440 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
441 if (remote_type() == REMOTETYPE_H300_NONLCD)
443 backlight_update_state();
445 else
446 #endif
448 #ifdef HAS_REMOTE_BUTTON_HOLD
449 if (remote_backlight_on_button_hold == 1 && remote_button_hold())
451 /* Keep off if "Off". */
452 remote_backlight_timer = 0; /* Disable the timeout */
453 return;
455 #endif
456 __remote_backlight_on();
460 #endif /* HAVE_REMOTE_LCD */
462 void backlight_thread(void)
464 struct event ev;
466 while(1)
468 queue_wait(&backlight_queue, &ev);
469 switch(ev.id)
471 #ifdef HAVE_REMOTE_LCD
472 case REMOTE_BACKLIGHT_ON:
473 remote_backlight_update_state();
474 break;
476 case REMOTE_BACKLIGHT_OFF:
477 remote_backlight_timer = 0; /* Disable the timeout */
478 #ifdef HAS_REMOTE_BUTTON_HOLD
479 if (remote_backlight_on_button_hold == 2 &&
480 remote_button_hold())
481 break; /* Keep on if "On" */
482 #endif
483 __remote_backlight_off();
484 break;
485 #endif /* HAVE_REMOTE_LCD */
487 case BACKLIGHT_ON:
488 backlight_update_state();
489 break;
491 case BACKLIGHT_OFF:
492 backlight_timer = 0; /* Disable the timeout */
493 #ifdef HAS_BUTTON_HOLD
494 if (backlight_on_button_hold == 2 && button_hold())
495 break; /* Keep on if "On" */
496 #endif
497 _backlight_off();
498 break;
500 #ifdef HAVE_LCD_SLEEP
501 case LCD_SLEEP:
502 lcd_sleep();
503 break;
504 #endif
505 #ifdef HAVE_BUTTON_LIGHT
506 case BUTTON_LIGHT_ON:
507 _button_backlight_on();
508 break;
509 case BUTTON_LIGHT_OFF:
510 _button_backlight_off();
511 break;
512 #endif
514 #ifdef X5_BACKLIGHT_SHUTDOWN
515 case BACKLIGHT_QUIT:
516 remove_thread(NULL);
517 break;
518 #endif
520 #if defined(HAVE_BACKLIGHT_PWM_FADING) && defined(CPU_COLDFIRE) \
521 && !defined(SIMULATOR)
522 case BACKLIGHT_UNBOOST_CPU:
523 cpu_boost(false);
524 break;
525 #endif
527 case SYS_USB_CONNECTED:
528 /* Tell the USB thread that we are safe */
529 DEBUGF("backlight_thread got SYS_USB_CONNECTED\n");
530 usb_acknowledge(SYS_USB_CONNECTED_ACK);
531 break;
533 case SYS_USB_DISCONNECTED:
534 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
535 break;
536 } /* end switch */
537 } /* end while */
540 static void backlight_tick(void)
542 #if CONFIG_CHARGING
543 static bool charger_was_inserted = false;
544 bool charger_is_inserted = charger_inserted()
545 #ifdef HAVE_USB_POWER
546 || usb_powered()
547 #endif
550 if( charger_was_inserted != charger_is_inserted )
552 backlight_on();
553 #ifdef HAVE_REMOTE_LCD
554 remote_backlight_on();
555 #endif
557 charger_was_inserted = charger_is_inserted;
558 #endif /* CONFIG_CHARGING */
560 if(backlight_timer)
562 backlight_timer--;
563 if(backlight_timer == 0)
565 backlight_off();
568 #ifdef HAVE_LCD_SLEEP
569 else if(lcd_sleep_timer)
571 lcd_sleep_timer--;
572 if(lcd_sleep_timer == 0)
574 /* Queue on bl thread or freeze! */
575 queue_post(&backlight_queue, LCD_SLEEP, 0);
578 #endif /* HAVE_LCD_SLEEP */
580 #ifdef HAVE_REMOTE_LCD
581 if(remote_backlight_timer)
583 remote_backlight_timer--;
584 if(remote_backlight_timer == 0)
586 remote_backlight_off();
589 #endif /* HAVE_REMOVE_LCD */
590 #ifdef HAVE_BUTTON_LIGHT
591 if (button_backlight_timer)
593 button_backlight_timer--;
594 if (button_backlight_timer == 0)
596 button_backlight_off();
599 #endif /* HAVE_BUTTON_LIGHT */
602 void backlight_init(void)
604 queue_init(&backlight_queue, true);
605 queue_set_irq_safe(&backlight_queue, true);
607 #ifndef SIMULATOR
608 if (__backlight_init())
610 # ifdef HAVE_BACKLIGHT_PWM_FADING
611 /* If backlight is already on, don't fade in. */
612 bl_dim_current = BL_PWM_COUNT;
613 bl_dim_target = BL_PWM_COUNT;
614 # endif
616 #endif
617 backlight_on();
618 #ifdef HAVE_REMOTE_LCD
619 remote_backlight_on();
620 #endif
621 #ifdef HAVE_BUTTON_LIGHT
622 button_backlight_on();
623 #endif
625 create_thread(backlight_thread, backlight_stack,
626 sizeof(backlight_stack), backlight_thread_name
627 IF_PRIO(, PRIORITY_SYSTEM)
628 IF_COP(, CPU, false));
629 tick_add_task(backlight_tick);
632 #ifdef X5_BACKLIGHT_SHUTDOWN
633 void x5_backlight_shutdown(void)
635 /* Turn on the screen and don't let anyone else mess with it. Called
636 from clean_shutdown in misc.c. */
637 queue_empty(&backlight_queue);
638 tick_remove_task(backlight_tick);
639 /* Next time the thread runs, if at all, it will just remove itself. */
640 queue_post(&backlight_queue, BACKLIGHT_QUIT, 0);
641 __backlight_on();
643 #endif /* X5_BACKLIGHT_SHUTDOWN */
645 void backlight_on(void)
647 queue_remove_from_head(&backlight_queue, BACKLIGHT_ON);
648 queue_post(&backlight_queue, BACKLIGHT_ON, 0);
651 void backlight_off(void)
653 queue_post(&backlight_queue, BACKLIGHT_OFF, 0);
656 /* returns true when the backlight is on OR when it's set to always off */
657 bool is_backlight_on(void)
659 if (backlight_timer || backlight_get_current_timeout() <= 0)
660 return true;
661 else
662 return false;
665 /* return value in ticks; 0 means always on, <0 means always off */
666 int backlight_get_current_timeout(void)
668 #if CONFIG_CHARGING
669 if (charger_inserted()
670 #ifdef HAVE_USB_POWER
671 || usb_powered()
672 #endif
674 return backlight_timeout_plugged;
675 else
676 return backlight_timeout;
677 #else
678 return backlight_timeout;
679 #endif
682 void backlight_set_timeout(int index)
684 if((unsigned)index >= sizeof(backlight_timeout_value))
685 /* if given a weird value, use default */
686 index = 6;
687 backlight_timeout = HZ * backlight_timeout_value[index];
688 backlight_update_state();
691 #if CONFIG_CHARGING
692 void backlight_set_timeout_plugged(int index)
694 if((unsigned)index >= sizeof(backlight_timeout_value))
695 /* if given a weird value, use default */
696 index = 6;
697 backlight_timeout_plugged = HZ * backlight_timeout_value[index];
698 backlight_update_state();
700 #endif /* CONFIG_CHARGING */
702 #ifdef HAS_BUTTON_HOLD
703 /* Hold button change event handler. */
704 void backlight_hold_changed(bool hold_button)
706 /* Hold switch overrides all backlight behavior except when
707 set to "Normal" */
708 /* Queue or freeze */
709 if (hold_button && backlight_on_button_hold == 1)
710 backlight_off(); /* setting == Off */
711 else /* setting == On, Normal, no hold button, or anything else */
712 backlight_on();
715 void backlight_set_on_button_hold(int index)
717 if ((unsigned)index >= 3)
718 /* if given a weird value, use default */
719 index = 0;
721 if (index == backlight_on_button_hold)
722 return;
724 backlight_on_button_hold = index;
725 backlight_hold_changed(button_hold());
727 #endif /* HAS_BUTTON_HOLD */
729 #ifdef HAVE_LCD_SLEEP
730 void lcd_set_sleep_after_backlight_off(int index)
732 if ((unsigned)index >= sizeof(lcd_sleep_timeout_value))
733 /* if given a weird value, use default */
734 index = 3;
736 lcd_sleep_timeout = HZ * lcd_sleep_timeout_value[index];
738 if (backlight_timer > 0 || backlight_get_current_timeout() == 0)
739 /* Timer will be set when bl turns off or bl set to on. */
740 return;
742 /* Backlight is Off */
743 if (lcd_sleep_timeout < 0)
744 lcd_sleep_timer = 1; /* Always - sleep next tick */
745 else
746 lcd_sleep_timer = lcd_sleep_timeout; /* Never, other */
748 #endif /* HAVE_LCD_SLEEP */
750 #ifdef HAVE_REMOTE_LCD
751 void remote_backlight_on(void)
753 queue_post(&backlight_queue, REMOTE_BACKLIGHT_ON, 0);
756 void remote_backlight_off(void)
758 queue_post(&backlight_queue, REMOTE_BACKLIGHT_OFF, 0);
761 void remote_backlight_set_timeout(int index)
763 if((unsigned)index >= sizeof(backlight_timeout_value))
764 /* if given a weird value, use default */
765 index=6;
766 remote_backlight_timeout = HZ * backlight_timeout_value[index];
767 remote_backlight_update_state();
770 #if CONFIG_CHARGING
771 void remote_backlight_set_timeout_plugged(int index)
773 if((unsigned)index >= sizeof(backlight_timeout_value))
774 /* if given a weird value, use default */
775 index=6;
776 remote_backlight_timeout_plugged = HZ * backlight_timeout_value[index];
777 remote_backlight_update_state();
779 #endif /* CONFIG_CHARGING */
781 #ifdef HAS_REMOTE_BUTTON_HOLD
782 /* Remote hold button change event handler. */
783 void remote_backlight_hold_changed(bool rc_hold_button)
785 /* Hold switch overrides all backlight behavior except when
786 set to "Normal" */
787 /* Queue or freeze */
788 if (rc_hold_button && remote_backlight_on_button_hold == 1)
789 remote_backlight_off(); /* setting == Off */
790 else /* setting == On, Normal, no hold button, or anything else */
791 remote_backlight_on();
795 void remote_backlight_set_on_button_hold(int index)
797 if ((unsigned)index >= 3)
798 /* if given a weird value, use default */
799 index = 0;
801 if (index == remote_backlight_on_button_hold)
802 return;
804 remote_backlight_on_button_hold = index;
805 remote_backlight_hold_changed(remote_button_hold());
807 #endif /* HAS_REMOTE_BUTTON_HOLD */
809 /* return value in ticks; 0 means always on, <0 means always off */
810 int remote_backlight_get_current_timeout(void)
812 #if CONFIG_CHARGING
813 if (charger_inserted()
814 #ifdef HAVE_USB_POWER
815 || usb_powered()
816 #endif
818 return remote_backlight_timeout_plugged;
819 else
820 return remote_backlight_timeout;
821 #else
822 return remote_backlight_timeout;
823 #endif
826 /* returns true when the backlight is on OR when it's set to always off */
827 bool is_remote_backlight_on(void)
829 if (remote_backlight_timer != 0 ||
830 remote_backlight_get_current_timeout() <= 0)
831 return true;
832 else
833 return false;
836 #endif /* HAVE_REMOTE_LCD */
838 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
839 void backlight_set_brightness(int val)
841 if (val < MIN_BRIGHTNESS_SETTING)
842 val = MIN_BRIGHTNESS_SETTING;
843 else if (val > MAX_BRIGHTNESS_SETTING)
844 val = MAX_BRIGHTNESS_SETTING;
846 __backlight_set_brightness(val);
848 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */
850 #else /* !defined(HAVE_BACKLIGHT) || defined(BOOTLOADER)
851 -- no backlight, empty dummy functions */
853 #if defined(BOOTLOADER) && defined(HAVE_BACKLIGHT)
854 void backlight_init(void)
856 (void)__backlight_init();
857 __backlight_on();
859 #endif
861 void backlight_on(void) {}
862 void backlight_off(void) {}
863 void backlight_set_timeout(int index) {(void)index;}
864 bool is_backlight_on(void) {return true;}
865 #ifdef HAVE_REMOTE_LCD
866 void remote_backlight_on(void) {}
867 void remote_backlight_off(void) {}
868 void remote_backlight_set_timeout(int index) {(void)index;}
869 bool is_remote_backlight_on(void) {return true;}
870 #endif /* HAVE_REMOTE_LCD */
871 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
872 void backlight_set_brightness(int val) { (void)val; }
873 #endif
874 #endif /* defined(HAVE_BACKLIGHT) && !defined(BOOTLOADER) */