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 ****************************************************************************/
30 #define BACKLIGHT_ON 1
31 #define BACKLIGHT_OFF 2
33 static void backlight_thread(void);
34 static char backlight_stack
[DEFAULT_STACK_SIZE
];
35 static char backlight_thread_name
[] = "backlight";
36 static struct event_queue backlight_queue
;
38 static bool charger_was_inserted
= 0;
39 static bool backlight_on_when_charging
= 0;
41 static int backlight_timer
;
42 static int backlight_timeout
= 5;
44 static char timeout_value
[19] =
46 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 45, 60, 90
49 void backlight_thread(void)
55 queue_wait(&backlight_queue
, &ev
);
59 if( backlight_on_when_charging
&& charger_inserted() )
61 /* Forcing to zero keeps the lights on */
66 backlight_timer
= HZ
*timeout_value
[backlight_timeout
];
69 if(backlight_timer
< 0)
71 backlight_timer
= 0; /* timer value 0 will not get ticked */
73 /* Disable square wave */
74 rtc_write(0x0a, rtc_read(0x0a) & ~0x40);
79 /* else if(backlight_timer) */
83 /* Enable square wave */
84 rtc_write(0x0a, rtc_read(0x0a) | 0x40);
93 /* Disable square wave */
94 rtc_write(0x0a, rtc_read(0x0a) & ~0x40);
100 case SYS_USB_CONNECTED
:
101 /* Tell the USB thread that we are safe */
102 DEBUGF("backlight_thread got SYS_USB_CONNECTED\n");
103 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
106 case SYS_USB_DISCONNECTED
:
107 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
113 void backlight_on(void)
115 queue_post(&backlight_queue
, BACKLIGHT_ON
, NULL
);
118 void backlight_off(void)
120 queue_post(&backlight_queue
, BACKLIGHT_OFF
, NULL
);
123 void backlight_set_timeout(int seconds
)
125 backlight_timeout
= seconds
;
129 void backlight_set_on_when_charging(bool yesno
)
131 backlight_on_when_charging
= yesno
;
135 void backlight_tick(void)
137 bool charger_is_inserted
= charger_inserted();
138 if( backlight_on_when_charging
&&
139 (charger_was_inserted
!= charger_is_inserted
) )
143 charger_was_inserted
= charger_is_inserted
;
148 if(backlight_timer
== 0)
155 void backlight_init(void)
157 queue_init(&backlight_queue
);
158 create_thread(backlight_thread
, backlight_stack
,
159 sizeof(backlight_stack
), backlight_thread_name
);
166 /* -----------------------------------------------------------------
168 * eval: (load-file "rockbox-mode.el")