Fix remote screen check in graphic equalizer, so that it can be used on logf-enabled...
[Rockbox.git] / firmware / backlight.c
blob897627bf5535a72c4dd588ab61125a213041ba2a
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 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
35 #include "pcf50606.h" /* iRiver, iAudio X5 brightness */
36 #endif
38 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
39 #include "lcd.h" /* for lcd_enable() and lcd_sleep() */
40 #endif
41 #ifdef HAVE_REMOTE_LCD
42 #include "lcd-remote.h"
43 #endif
44 #if defined(TARGET_TREE) && !defined(SIMULATOR)
45 #include "backlight-target.h"
46 #endif
48 #ifdef SIMULATOR
49 static inline void __backlight_on(void)
51 sim_backlight(100);
54 static inline void __backlight_off(void)
56 sim_backlight(0);
58 #else
59 /* Basic low-level code that simply switches backlight on or off. Probably
60 * a nice candidate for inclusion in the target/ dir. */
61 #ifndef TARGET_TREE
62 static inline void __backlight_on(void)
64 #if CONFIG_BACKLIGHT == BL_RTC
65 /* Enable square wave */
66 rtc_write(0x0a, rtc_read(0x0a) | 0x40);
67 #elif CONFIG_BACKLIGHT == BL_PA14_LO /* Player */
68 and_b(~0x40, &PADRH); /* drive and set low */
69 or_b(0x40, &PAIORH);
70 #elif CONFIG_BACKLIGHT == BL_PA14_HI /* Ondio */
71 or_b(0x40, &PADRH); /* drive it high */
72 #elif CONFIG_BACKLIGHT == BL_GMINI
73 P1 |= 0x10;
74 #elif CONFIG_BACKLIGHT==BL_IRIVER_IFP7XX
75 GPIO3_SET = 1;
76 #endif
79 static inline void __backlight_off(void)
81 #if CONFIG_BACKLIGHT == BL_RTC
82 /* Disable square wave */
83 rtc_write(0x0a, rtc_read(0x0a) & ~0x40);
84 #elif CONFIG_BACKLIGHT == BL_PA14_LO /* Player */
85 and_b(~0x40, &PAIORH); /* let it float (up) */
86 #elif CONFIG_BACKLIGHT == BL_PA14_HI /* Ondio */
87 and_b(~0x40, &PADRH); /* drive it low */
88 #elif CONFIG_BACKLIGHT == BL_GMINI
89 P1 &= ~0x10;
90 #elif CONFIG_BACKLIGHT==BL_IRIVER_IFP7XX
91 GPIO3_CLR = 1;
92 #endif
94 #endif
95 #endif /* SIMULATOR */
97 #if defined(CONFIG_BACKLIGHT) && !defined(BOOTLOADER)
99 const signed char backlight_timeout_value[19] =
101 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 45, 60, 90
104 #define BACKLIGHT_ON 1
105 #define BACKLIGHT_OFF 2
106 #define REMOTE_BACKLIGHT_ON 3
107 #define REMOTE_BACKLIGHT_OFF 4
108 #define BACKLIGHT_UNBOOST_CPU 5
109 #ifdef HAVE_LCD_SLEEP
110 #define LCD_SLEEP 6
111 #endif
113 static void backlight_thread(void);
114 static long backlight_stack[DEFAULT_STACK_SIZE/sizeof(long)];
115 #ifdef X5_BACKLIGHT_SHUTDOWN
116 #define BACKLIGHT_QUIT 256
117 /* Need to save this for x5 shutdown */
118 struct thread_entry* backlight_thread_id;
119 #endif
120 static const char backlight_thread_name[] = "backlight";
121 static struct event_queue backlight_queue;
123 static int backlight_timer;
124 static int backlight_timeout = 5*HZ;
125 #ifdef CONFIG_CHARGING
126 static int backlight_timeout_plugged = 5*HZ;
127 #endif
128 #ifdef HAS_BUTTON_HOLD
129 static int backlight_on_button_hold = 0;
130 #endif
132 #ifdef HAVE_REMOTE_LCD
133 static int remote_backlight_timer;
134 static int remote_backlight_timeout = 5*HZ;
135 #ifdef CONFIG_CHARGING
136 static int remote_backlight_timeout_plugged = 5*HZ;
137 #endif
138 #ifdef HAS_REMOTE_BUTTON_HOLD
139 static int remote_backlight_on_button_hold = 0;
140 #endif
141 #endif
143 #ifdef HAVE_LCD_SLEEP
144 const signed char lcd_sleep_timeout_value[10] =
146 -1, 0, 5, 10, 15, 20, 30, 45, 60, 90
148 static int lcd_sleep_timer;
149 static int lcd_sleep_timeout = 10*HZ;
150 #endif
152 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
153 /* backlight fading */
154 #define BL_PWM_INTERVAL 5000 /* Cycle interval in s */
155 #define BL_PWM_COUNT 100
156 static const char backlight_fade_value[8] = { 0, 1, 2, 4, 6, 8, 10, 20 };
157 static int fade_in_count = 1;
158 static int fade_out_count = 4;
160 static bool bl_timer_active = false;
161 static int bl_dim_current = BL_PWM_COUNT;
162 static int bl_dim_target = BL_PWM_COUNT;
163 static int bl_pwm_counter = 0;
164 static volatile int bl_cycle_counter = 0;
165 static enum {DIM_STATE_START, DIM_STATE_MAIN} bl_dim_state = DIM_STATE_START;
167 static void backlight_isr(void)
169 int timer_period;
170 bool idle = false;
172 timer_period = TIMER_FREQ / 1000 * BL_PWM_INTERVAL / 1000;
173 switch (bl_dim_state)
175 /* New cycle */
176 case DIM_STATE_START:
177 bl_pwm_counter = 0;
178 bl_cycle_counter++;
180 if (bl_dim_current > 0 && bl_dim_current < BL_PWM_COUNT)
182 __backlight_on();
183 bl_pwm_counter = bl_dim_current;
184 timer_period = timer_period * bl_pwm_counter / BL_PWM_COUNT;
185 bl_dim_state = DIM_STATE_MAIN;
187 else
189 if (bl_dim_current)
190 __backlight_on();
191 else
192 __backlight_off();
193 if (bl_dim_current == bl_dim_target)
194 idle = true;
197 break ;
199 /* Dim main screen */
200 case DIM_STATE_MAIN:
201 __backlight_off();
202 bl_dim_state = DIM_STATE_START;
203 timer_period = timer_period * (BL_PWM_COUNT - bl_pwm_counter) / BL_PWM_COUNT;
204 break ;
207 if ((bl_dim_target > bl_dim_current) && (bl_cycle_counter >= fade_in_count))
209 bl_dim_current++;
210 bl_cycle_counter = 0;
213 if ((bl_dim_target < bl_dim_current) && (bl_cycle_counter >= fade_out_count))
215 bl_dim_current--;
216 bl_cycle_counter = 0;
219 if (idle)
221 #ifdef CPU_COLDFIRE
222 queue_post(&backlight_queue, BACKLIGHT_UNBOOST_CPU, NULL);
223 #endif
224 timer_unregister();
225 bl_timer_active = false;
227 else
228 timer_set_period(timer_period);
231 static void backlight_switch(void)
233 if (bl_dim_target > (BL_PWM_COUNT/2))
235 __backlight_on();
236 bl_dim_current = BL_PWM_COUNT;
238 else
240 __backlight_off();
241 bl_dim_current = 0;
245 static void backlight_release_timer(void)
247 #ifdef CPU_COLDFIRE
248 cpu_boost_id(false, CPUBOOSTID_BACKLIGHT);
249 #endif
250 timer_unregister();
251 bl_timer_active = false;
252 backlight_switch();
255 static void backlight_dim(int value)
257 /* protect from extraneous calls with the same target value */
258 if (value == bl_dim_target)
259 return;
261 bl_dim_target = value;
263 if (bl_timer_active)
264 return ;
266 if (timer_register(0, backlight_release_timer, 2, 0, backlight_isr))
268 #ifdef CPU_COLDFIRE
269 /* Prevent cpu frequency changes while dimming. */
270 cpu_boost_id(true, CPUBOOSTID_BACKLIGHT);
271 #endif
272 bl_timer_active = true;
274 else
275 backlight_switch();
278 void backlight_set_fade_in(int index)
280 fade_in_count = backlight_fade_value[index];
283 void backlight_set_fade_out(int index)
285 fade_out_count = backlight_fade_value[index];
287 #endif /* defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) */
289 static void _backlight_on(void)
291 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
292 if (fade_in_count > 0)
293 backlight_dim(BL_PWM_COUNT);
294 else
296 bl_dim_target = bl_dim_current = BL_PWM_COUNT;
297 __backlight_on();
299 #else
300 __backlight_on();
301 #endif
302 #ifdef HAVE_LCD_SLEEP
303 lcd_sleep_timer = 0; /* LCD should be awake already */
304 #endif
307 static void _backlight_off(void)
309 #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
310 if (fade_out_count > 0)
311 backlight_dim(0);
312 else
314 bl_dim_target = bl_dim_current = 0;
315 __backlight_off();
317 #else
318 __backlight_off();
319 #endif
321 #ifdef HAVE_LCD_SLEEP
322 /* Start LCD sleep countdown */
323 if (lcd_sleep_timeout < 0)
325 lcd_sleep_timer = 0; /* Setting == Always */
326 lcd_sleep();
328 else
329 lcd_sleep_timer = lcd_sleep_timeout;
330 #endif
333 #ifdef HAVE_REMOTE_LCD
334 #ifdef SIMULATOR
335 static void __remote_backlight_on(void)
337 sim_remote_backlight(100);
340 static void __remote_backlight_off(void)
342 sim_remote_backlight(0);
344 #endif /* SIMULATOR */
345 #endif /* HAVE_REMOTE_LCD */
347 /* Update state of backlight according to timeout setting */
348 static void backlight_update_state(void)
350 #ifdef CONFIG_CHARGING
351 if (charger_inserted()
352 #ifdef HAVE_USB_POWER
353 || usb_powered()
354 #endif
356 backlight_timer = backlight_timeout_plugged;
357 else
358 #endif
359 backlight_timer = backlight_timeout;
361 /* Backlight == OFF in the setting? */
362 if (backlight_timer < 0)
364 backlight_timer = 0; /* Disable the timeout */
365 #ifdef HAS_BUTTON_HOLD
366 if (backlight_on_button_hold == 2 && button_hold())
367 return; /* Keep on if "On" */
368 #endif
369 _backlight_off();
371 else
373 #ifdef HAS_BUTTON_HOLD
374 if (backlight_on_button_hold == 1 && button_hold())
376 /* Keep off if "Off". */
377 backlight_timer = 0; /* Disable the timeout */
378 return;
380 #endif
381 _backlight_on();
385 #ifdef HAVE_REMOTE_LCD
386 /* Update state of remote backlight according to timeout setting */
387 static void remote_backlight_update_state(void)
389 #ifdef CONFIG_CHARGING
390 if (charger_inserted()
391 #ifdef HAVE_USB_POWER
392 || usb_powered()
393 #endif
395 remote_backlight_timer = remote_backlight_timeout_plugged;
396 else
397 #endif
398 remote_backlight_timer = remote_backlight_timeout;
400 /* Backlight == OFF in the setting? */
401 if (remote_backlight_timer < 0)
403 remote_backlight_timer = 0; /* Disable the timeout */
404 #ifdef HAS_REMOTE_BUTTON_HOLD
405 if (remote_backlight_on_button_hold == 2 && remote_button_hold())
406 return; /* Keep on if "On" */
407 #endif
408 __remote_backlight_off();
410 else
412 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
413 if (remote_type() == REMOTETYPE_H300_NONLCD)
415 backlight_update_state();
417 else
418 #endif
420 #ifdef HAS_REMOTE_BUTTON_HOLD
421 if (remote_backlight_on_button_hold == 1 && remote_button_hold())
423 /* Keep off if "Off". */
424 remote_backlight_timer = 0; /* Disable the timeout */
425 return;
427 #endif
428 __remote_backlight_on();
432 #endif /* HAVE_REMOTE_LCD */
434 void backlight_thread(void)
436 struct event ev;
438 while(1)
440 queue_wait(&backlight_queue, &ev);
441 switch(ev.id)
443 #ifdef HAVE_REMOTE_LCD
444 case REMOTE_BACKLIGHT_ON:
445 remote_backlight_update_state();
446 break;
448 case REMOTE_BACKLIGHT_OFF:
449 remote_backlight_timer = 0; /* Disable the timeout */
450 #ifdef HAS_REMOTE_BUTTON_HOLD
451 if (remote_backlight_on_button_hold == 2 &&
452 remote_button_hold())
453 break; /* Keep on if "On" */
454 #endif
455 __remote_backlight_off();
456 break;
457 #endif /* HAVE_REMOTE_LCD */
459 case BACKLIGHT_ON:
460 backlight_update_state();
461 break;
463 case BACKLIGHT_OFF:
464 backlight_timer = 0; /* Disable the timeout */
465 #ifdef HAS_BUTTON_HOLD
466 if (backlight_on_button_hold == 2 && button_hold())
467 break; /* Keep on if "On" */
468 #endif
469 _backlight_off();
470 break;
472 #ifdef HAVE_LCD_SLEEP
473 case LCD_SLEEP:
474 lcd_sleep();
475 break;
476 #endif
478 #ifdef X5_BACKLIGHT_SHUTDOWN
479 case BACKLIGHT_QUIT:
480 remove_thread(backlight_thread_id);
481 break;
482 #endif
484 #if defined(HAVE_BACKLIGHT_PWM_FADING) && defined(CPU_COLDFIRE) \
485 && !defined(SIMULATOR)
486 case BACKLIGHT_UNBOOST_CPU:
487 cpu_boost_id(false, CPUBOOSTID_BACKLIGHT);
488 break;
489 #endif
491 case SYS_USB_CONNECTED:
492 /* Tell the USB thread that we are safe */
493 DEBUGF("backlight_thread got SYS_USB_CONNECTED\n");
494 usb_acknowledge(SYS_USB_CONNECTED_ACK);
495 break;
497 case SYS_USB_DISCONNECTED:
498 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
499 break;
500 } /* end switch */
501 } /* end while */
504 static void backlight_tick(void)
506 #ifdef CONFIG_CHARGING
507 static bool charger_was_inserted = false;
508 bool charger_is_inserted = charger_inserted()
509 #ifdef HAVE_USB_POWER
510 || usb_powered()
511 #endif
514 if( charger_was_inserted != charger_is_inserted )
516 backlight_on();
517 #ifdef HAVE_REMOTE_LCD
518 remote_backlight_on();
519 #endif
521 charger_was_inserted = charger_is_inserted;
522 #endif /* CONFIG_CHARGING */
524 if(backlight_timer)
526 backlight_timer--;
527 if(backlight_timer == 0)
529 backlight_off();
532 #ifdef HAVE_LCD_SLEEP
533 else if(lcd_sleep_timer)
535 lcd_sleep_timer--;
536 if(lcd_sleep_timer == 0)
538 /* Queue on bl thread or freeze! */
539 queue_post(&backlight_queue, LCD_SLEEP, NULL);
542 #endif /* HAVE_LCD_SLEEP */
544 #ifdef HAVE_REMOTE_LCD
545 if(remote_backlight_timer)
547 remote_backlight_timer--;
548 if(remote_backlight_timer == 0)
550 remote_backlight_off();
553 #endif /* HAVE_REMOVE_LCD */
556 void backlight_init(void)
558 queue_init(&backlight_queue, true);
559 #ifdef X5_BACKLIGHT_SHUTDOWN
560 backlight_thread_id =
561 #endif
562 create_thread(backlight_thread, backlight_stack,
563 sizeof(backlight_stack), backlight_thread_name
564 IF_PRIO(, PRIORITY_SYSTEM));
565 tick_add_task(backlight_tick);
566 #ifdef SIMULATOR
567 /* do nothing */
568 #elif CONFIG_BACKLIGHT == BL_IRIVER_H100
569 or_l(0x00020000, &GPIO1_ENABLE);
570 or_l(0x00020000, &GPIO1_FUNCTION);
571 and_l(~0x00020000, &GPIO1_OUT); /* Start with the backlight ON */
572 #elif CONFIG_BACKLIGHT == BL_IRIVER_H300
573 or_l(0x00020000, &GPIO1_ENABLE);
574 or_l(0x00020000, &GPIO1_FUNCTION);
575 or_l(0x00020000, &GPIO1_OUT); /* Start with the backlight ON */
576 #elif CONFIG_BACKLIGHT == BL_PA14_LO || CONFIG_BACKLIGHT == BL_PA14_HI
577 PACR1 &= ~0x3000; /* Set PA14 (backlight control) to GPIO */
578 or_b(0x40, &PAIORH); /* ..and output */
579 #elif CONFIG_BACKLIGHT == BL_GMINI
580 P1CON |= 0x10; /* P1.4 C-MOS output mode */
581 #endif
582 backlight_on();
583 #ifdef HAVE_REMOTE_LCD
584 remote_backlight_on();
585 #endif
588 #ifdef X5_BACKLIGHT_SHUTDOWN
589 void x5_backlight_shutdown(void)
591 /* Turn on the screen and don't let anyone else mess with it. Called
592 from clean_shutdown in misc.c. */
593 queue_empty(&backlight_queue);
594 tick_remove_task(backlight_tick);
595 /* Next time the thread runs, if at all, it will just remove itself. */
596 queue_post(&backlight_queue, BACKLIGHT_QUIT, NULL);
597 __backlight_on();
599 #endif /* X5_BACKLIGHT_SHUTDOWN */
601 void backlight_on(void)
603 queue_remove_from_head(&backlight_queue, BACKLIGHT_ON);
604 queue_post(&backlight_queue, BACKLIGHT_ON, NULL);
607 void backlight_off(void)
609 queue_post(&backlight_queue, BACKLIGHT_OFF, NULL);
612 /* returns true when the backlight is on OR when it's set to always off */
613 bool is_backlight_on(void)
615 if (backlight_timer || backlight_get_current_timeout() <= 0)
616 return true;
617 else
618 return false;
621 /* return value in ticks; 0 means always on, <0 means always off */
622 int backlight_get_current_timeout(void)
624 #ifdef CONFIG_CHARGING
625 if (charger_inserted()
626 #ifdef HAVE_USB_POWER
627 || usb_powered()
628 #endif
630 return backlight_timeout_plugged;
631 else
632 return backlight_timeout;
633 #else
634 return backlight_timeout;
635 #endif
638 void backlight_set_timeout(int index)
640 if((unsigned)index >= sizeof(backlight_timeout_value))
641 /* if given a weird value, use default */
642 index = 6;
643 backlight_timeout = HZ * backlight_timeout_value[index];
644 backlight_update_state();
647 #ifdef CONFIG_CHARGING
648 void backlight_set_timeout_plugged(int index)
650 if((unsigned)index >= sizeof(backlight_timeout_value))
651 /* if given a weird value, use default */
652 index = 6;
653 backlight_timeout_plugged = HZ * backlight_timeout_value[index];
654 backlight_update_state();
656 #endif /* CONFIG_CHARGING */
658 #ifdef HAS_BUTTON_HOLD
659 /* Hold button change event handler. */
660 void backlight_hold_changed(bool hold_button)
662 /* Hold switch overrides all backlight behavior except when
663 set to "Normal" */
664 /* Queue or freeze */
665 if (hold_button && backlight_on_button_hold == 1)
666 backlight_off(); /* setting == Off */
667 else /* setting == On, Normal, no hold button, or anything else */
668 backlight_on();
671 void backlight_set_on_button_hold(int index)
673 if ((unsigned)index >= 3)
674 /* if given a weird value, use default */
675 index = 0;
677 if (index == backlight_on_button_hold)
678 return;
680 backlight_on_button_hold = index;
681 backlight_hold_changed(button_hold());
683 #endif /* HAS_BUTTON_HOLD */
685 #ifdef HAVE_LCD_SLEEP
686 void lcd_set_sleep_after_backlight_off(int index)
688 if ((unsigned)index >= sizeof(lcd_sleep_timeout_value))
689 /* if given a weird value, use default */
690 index = 3;
692 lcd_sleep_timeout = HZ * lcd_sleep_timeout_value[index];
694 if (backlight_timer > 0 || backlight_get_current_timeout() == 0)
695 /* Timer will be set when bl turns off or bl set to on. */
696 return;
698 /* Backlight is Off */
699 if (lcd_sleep_timeout < 0)
700 lcd_sleep_timer = 1; /* Always - sleep next tick */
701 else
702 lcd_sleep_timer = lcd_sleep_timeout; /* Never, other */
704 #endif /* HAVE_LCD_SLEEP */
706 #ifdef HAVE_REMOTE_LCD
707 void remote_backlight_on(void)
709 queue_post(&backlight_queue, REMOTE_BACKLIGHT_ON, NULL);
712 void remote_backlight_off(void)
714 queue_post(&backlight_queue, REMOTE_BACKLIGHT_OFF, NULL);
717 void remote_backlight_set_timeout(int index)
719 if((unsigned)index >= sizeof(backlight_timeout_value))
720 /* if given a weird value, use default */
721 index=6;
722 remote_backlight_timeout = HZ * backlight_timeout_value[index];
723 remote_backlight_update_state();
726 #ifdef CONFIG_CHARGING
727 void remote_backlight_set_timeout_plugged(int index)
729 if((unsigned)index >= sizeof(backlight_timeout_value))
730 /* if given a weird value, use default */
731 index=6;
732 remote_backlight_timeout_plugged = HZ * backlight_timeout_value[index];
733 remote_backlight_update_state();
735 #endif /* CONFIG_CHARGING */
737 #ifdef HAS_REMOTE_BUTTON_HOLD
738 /* Remote hold button change event handler. */
739 void remote_backlight_hold_changed(bool rc_hold_button)
741 /* Hold switch overrides all backlight behavior except when
742 set to "Normal" */
743 /* Queue or freeze */
744 if (rc_hold_button && remote_backlight_on_button_hold == 1)
745 remote_backlight_off(); /* setting == Off */
746 else /* setting == On, Normal, no hold button, or anything else */
747 remote_backlight_on();
751 void remote_backlight_set_on_button_hold(int index)
753 if ((unsigned)index >= 3)
754 /* if given a weird value, use default */
755 index = 0;
757 if (index == remote_backlight_on_button_hold)
758 return;
760 remote_backlight_on_button_hold = index;
761 remote_backlight_hold_changed(remote_button_hold());
763 #endif /* HAS_REMOTE_BUTTON_HOLD */
765 /* return value in ticks; 0 means always on, <0 means always off */
766 int remote_backlight_get_current_timeout(void)
768 #ifdef CONFIG_CHARGING
769 if (charger_inserted()
770 #ifdef HAVE_USB_POWER
771 || usb_powered()
772 #endif
774 return remote_backlight_timeout_plugged;
775 else
776 return remote_backlight_timeout;
777 #else
778 return remote_backlight_timeout;
779 #endif
782 /* returns true when the backlight is on OR when it's set to always off */
783 bool is_remote_backlight_on(void)
785 if (remote_backlight_timer != 0 ||
786 remote_backlight_get_current_timeout() <= 0)
787 return true;
788 else
789 return false;
792 #endif /* HAVE_REMOTE_LCD */
794 #else /* !defined(CONFIG_BACKLIGHT) || defined(BOOTLOADER)
795 -- no backlight, empty dummy functions */
797 #if defined(BOOTLOADER) && defined(CONFIG_BACKLIGHT)
798 void backlight_init(void)
800 #ifdef IRIVER_H300_SERIES
801 or_l(0x00020000, &GPIO1_OUT);
802 or_l(0x00020000, &GPIO1_ENABLE);
803 or_l(0x00020000, &GPIO1_FUNCTION);
804 #endif
806 #endif
808 void backlight_on(void) {}
809 void backlight_off(void) {}
810 void backlight_set_timeout(int index) {(void)index;}
811 bool is_backlight_on(void) {return true;}
812 #ifdef HAVE_REMOTE_LCD
813 void remote_backlight_on(void) {}
814 void remote_backlight_off(void) {}
815 void remote_backlight_set_timeout(int index) {(void)index;}
816 bool is_remote_backlight_on(void) {return true;}
817 #endif
818 #endif /* defined(CONFIG_BACKLIGHT) && !defined(BOOTLOADER) */
820 /* TODO: Move low level code to target/ tree. Create
821 __backlight_set_brightness and call from here. */
822 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
823 #if defined(IRIVER_H300_SERIES) || defined(IAUDIO_X5)
824 void backlight_set_brightness(int val)
826 #ifndef SIMULATOR
827 /* set brightness by changing the PWM
828 * accepts 0..15 but note that 0 and 1 give a black display on H300!
829 * 0 is black on the X5.
832 /* disable IRQs while bitbanging */
833 int old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
835 /* Clamp setting to range */
836 if(val<MIN_BRIGHTNESS_SETTING)
837 val=MIN_BRIGHTNESS_SETTING;
838 else if(val>MAX_BRIGHTNESS_SETTING)
839 val=MAX_BRIGHTNESS_SETTING;
841 pcf50606_write(0x35, (val << 1) | 0x01); /* 512Hz, Enable PWM */
843 /* enable IRQs again */
844 set_irq_level(old_irq_level);
845 #else
846 val=0;
847 #endif
849 #endif
850 #endif /* HAVE_BACKLIGHT_BRIGHTNESS */