1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
31 const char backlight_timeout_value
[19] =
33 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 45, 60, 90
38 #define BACKLIGHT_ON 1
39 #define BACKLIGHT_OFF 2
41 static void backlight_thread(void);
42 static char backlight_stack
[DEFAULT_STACK_SIZE
];
43 static const char backlight_thread_name
[] = "backlight";
44 static struct event_queue backlight_queue
;
46 static bool charger_was_inserted
= 0;
47 static bool backlight_on_when_charging
= 0;
49 static int backlight_timer
;
50 static unsigned int backlight_timeout
= 5;
52 void backlight_thread(void)
58 queue_wait(&backlight_queue
, &ev
);
62 if( backlight_on_when_charging
&& charger_inserted() )
64 /* Forcing to zero keeps the lights on */
69 backlight_timer
= HZ
*backlight_timeout_value
[backlight_timeout
];
72 if(backlight_timer
< 0)
74 backlight_timer
= 0; /* timer value 0 will not get ticked */
76 /* Disable square wave */
77 rtc_write(0x0a, rtc_read(0x0a) & ~0x40);
79 and_b(~0x40, &PAIORH
);
82 /* else if(backlight_timer) */
86 /* Enable square wave */
87 rtc_write(0x0a, rtc_read(0x0a) | 0x40);
97 /* Disable square wave */
98 rtc_write(0x0a, rtc_read(0x0a) & ~0x40);
100 and_b(~0x40, &PAIORH
);
104 case SYS_USB_CONNECTED
:
105 /* Tell the USB thread that we are safe */
106 DEBUGF("backlight_thread got SYS_USB_CONNECTED\n");
107 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
110 case SYS_USB_DISCONNECTED
:
111 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
117 void backlight_on(void)
119 queue_post(&backlight_queue
, BACKLIGHT_ON
, NULL
);
122 void backlight_off(void)
124 queue_post(&backlight_queue
, BACKLIGHT_OFF
, NULL
);
127 int backlight_get_timeout(void)
129 return backlight_timeout
;
132 void backlight_set_timeout(int index
)
134 if((unsigned)index
>= sizeof(backlight_timeout_value
))
135 /* if given a weird value, use 0 */
137 backlight_timeout
= index
; /* index in the backlight_timeout_value table */
141 bool backlight_get_on_when_charging(void)
143 return backlight_on_when_charging
;
146 void backlight_set_on_when_charging(bool yesno
)
148 backlight_on_when_charging
= yesno
;
152 void backlight_tick(void)
154 bool charger_is_inserted
= charger_inserted();
155 if( backlight_on_when_charging
&&
156 (charger_was_inserted
!= charger_is_inserted
) )
160 charger_was_inserted
= charger_is_inserted
;
165 if(backlight_timer
== 0)
172 void backlight_init(void)
174 queue_init(&backlight_queue
);
175 create_thread(backlight_thread
, backlight_stack
,
176 sizeof(backlight_stack
), backlight_thread_name
);
181 #else /* no backlight, empty dummy functions */
183 void backlight_init(void) {}
184 void backlight_on(void) {}
185 void backlight_off(void) {}
186 void backlight_tick(void) {}
187 int backlight_get_timeout(void) {return 0;}
188 void backlight_set_timeout(int index
) {(void)index
;}
189 bool backlight_get_on_when_charging(void) {return 0;}
190 void backlight_set_on_when_charging(bool yesno
) {(void)yesno
;}
192 #endif /* #ifdef HAVE_BACKLIGHT */