summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-11-21 23:55:39 +0000
committerJens Arnold <amiconn@rockbox.org>2005-11-21 23:55:39 +0000
commitb51f7dfc9b507ab9db12fe90b2ddad708f435e06 (patch)
treeefcef3411689401da21795d700a0741f8ab1072b
parente68680ac310adb8373c9f3a5194466766d64cf37 (diff)
downloadrockbox-b51f7dfc9b507ab9db12fe90b2ddad708f435e06.tar.gz
rockbox-b51f7dfc9b507ab9db12fe90b2ddad708f435e06.zip
Backlight handling: * Added 'Caption Backlight' and 'Backlight On When Charging' for the iriver remote LCD. * Enabled the backlight code for the simulator, and prepared backlight simulation. It's only a stub atm, writing messages to the console window. * Added tick task handling to the simulators for this to work. * Code cleanup in backlight.c, less dead code.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8034 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/gui/gwps-common.c22
-rw-r--r--apps/main.c2
-rw-r--r--apps/plugin.c4
-rw-r--r--apps/settings.c18
-rw-r--r--apps/settings.h4
-rw-r--r--apps/settings_menu.c31
-rw-r--r--firmware/SOURCES2
-rw-r--r--firmware/backlight.c278
-rw-r--r--firmware/drivers/button.c2
-rw-r--r--firmware/drivers/lcd-h100-remote.c18
-rw-r--r--firmware/export/backlight.h18
-rw-r--r--firmware/export/config-fmrecorder.h6
-rw-r--r--firmware/export/config-h100.h6
-rw-r--r--firmware/export/config-h120.h6
-rw-r--r--firmware/export/config-h300.h6
-rw-r--r--firmware/export/config-ipodcolor.h6
-rw-r--r--firmware/export/config-ipodnano.h6
-rw-r--r--firmware/export/config-player.h6
-rw-r--r--firmware/export/config-recorder.h6
-rw-r--r--firmware/export/config-recorderv2.h6
-rw-r--r--firmware/export/lcd-remote.h2
-rw-r--r--firmware/powermgmt.c8
-rw-r--r--uisimulator/common/stubs.c33
-rw-r--r--uisimulator/win32/button.c8
-rw-r--r--uisimulator/win32/kernel.c51
-rw-r--r--uisimulator/win32/uisw32.c11
-rw-r--r--uisimulator/x11/button-x11.c11
-rw-r--r--uisimulator/x11/kernel.c52
-rw-r--r--uisimulator/x11/thread.c6
29 files changed, 410 insertions, 225 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c
index c2a4dff3b6..16f3a6f2cc 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -1612,12 +1612,12 @@ bool gui_wps_refresh(struct gui_wps *gwps, int ffwd_offset,
1612 data->peak_meter_enabled = enable_pm; 1612 data->peak_meter_enabled = enable_pm;
1613#endif 1613#endif
1614 1614
1615#if defined(CONFIG_BACKLIGHT) && !defined(SIMULATOR) 1615#ifdef CONFIG_BACKLIGHT
1616 if (global_settings.caption_backlight && state->id3) { 1616 if (global_settings.caption_backlight && state->id3) {
1617 /* turn on backlight n seconds before track ends, and turn it off n 1617 /* turn on backlight n seconds before track ends, and turn it off n
1618 seconds into the new track. n == backlight_timeout, or 5s */ 1618 seconds into the new track. n == backlight_timeout, or 5s */
1619 int n = 1619 int n = backlight_timeout_value[global_settings.backlight_timeout]
1620 backlight_timeout_value[global_settings.backlight_timeout] * 1000; 1620 * 1000;
1621 1621
1622 if ( n < 1000 ) 1622 if ( n < 1000 )
1623 n = 5000; /* use 5s if backlight is always on or off */ 1623 n = 5000; /* use 5s if backlight is always on or off */
@@ -1627,6 +1627,22 @@ bool gui_wps_refresh(struct gui_wps *gwps, int ffwd_offset,
1627 backlight_on(); 1627 backlight_on();
1628 } 1628 }
1629#endif 1629#endif
1630#ifdef HAVE_REMOTE_LCD
1631 if (global_settings.remote_caption_backlight && state->id3) {
1632 /* turn on remote backlight n seconds before track ends, and turn it
1633 off n seconds into the new track. n == remote_backlight_timeout,
1634 or 5s */
1635 int n = backlight_timeout_value[global_settings.remote_backlight_timeout]
1636 * 1000;
1637
1638 if ( n < 1000 )
1639 n = 5000; /* use 5s if backlight is always on or off */
1640
1641 if ((state->id3->elapsed < 1000) ||
1642 ((state->id3->length - state->id3->elapsed) < (unsigned)n))
1643 remote_backlight_on();
1644 }
1645#endif
1630 return true; 1646 return true;
1631} 1647}
1632 1648
diff --git a/apps/main.c b/apps/main.c
index 9afb3e9a13..7472eb4661 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -147,6 +147,8 @@ void init(void)
147#endif 147#endif
148 font_init(); 148 font_init();
149 show_logo(); 149 show_logo();
150 button_init();
151 backlight_init();
150 lang_init(); 152 lang_init();
151 /* Must be done before any code uses the multi-screen APi */ 153 /* Must be done before any code uses the multi-screen APi */
152 screen_access_init(); 154 screen_access_init();
diff --git a/apps/plugin.c b/apps/plugin.c
index d5607aa822..7d92998e34 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -169,8 +169,8 @@ static const struct plugin_api rockbox_api = {
169 lcd_remote_update, 169 lcd_remote_update,
170 lcd_remote_update_rect, 170 lcd_remote_update_rect,
171 171
172 lcd_remote_backlight_on, 172 remote_backlight_on,
173 lcd_remote_backlight_off, 173 remote_backlight_off,
174#endif 174#endif
175 /* button */ 175 /* button */
176 button_get, 176 button_get,
diff --git a/apps/settings.c b/apps/settings.c
index 7d68daee98..939d4880e2 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -277,9 +277,15 @@ static const struct bit_entry rtc_bits[] =
277 {1, S_O(bidi_support), false, "bidi hebrew/arabic", off_on }, 277 {1, S_O(bidi_support), false, "bidi hebrew/arabic", off_on },
278#endif 278#endif
279 279
280#ifdef HAVE_REMOTE_LCD_TICKING /* move to REMOTE_LCD next time we bump version */ 280#ifdef HAVE_REMOTE_LCD /* move to REMOTE_LCD next time we bump version */
281#ifdef HAVE_REMOTE_LCD_TICKING
281 {1, S_O(remote_reduce_ticking), false, "remote reduce ticking", off_on }, 282 {1, S_O(remote_reduce_ticking), false, "remote reduce ticking", off_on },
282#endif 283#endif
284#ifdef HAVE_CHARGING
285 {1, S_O(remote_backlight_on_when_charging), false,
286 "remote backlight when plugged", off_on },
287#endif
288#endif
283 289
284 /* new stuff to be added here */ 290 /* new stuff to be added here */
285 /* If values are just added to the end, no need to bump the version. */ 291 /* If values are just added to the end, no need to bump the version. */
@@ -475,6 +481,10 @@ static const struct bit_entry hd_bits[] =
475 {8|SIGNED, S_O(rec_adc_right_gain), 0, /* 0dB */ "adc right gain", NULL }, /* -128...48 */ 481 {8|SIGNED, S_O(rec_adc_right_gain), 0, /* 0dB */ "adc right gain", NULL }, /* -128...48 */
476#endif 482#endif
477 483
484#ifdef HAVE_REMOTE_LCD
485 {1, S_O(remote_caption_backlight), false,
486 "remote caption backlight", off_on },
487#endif
478 /* If values are just added to the end, no need to bump the version. */ 488 /* If values are just added to the end, no need to bump the version. */
479 /* new stuff to be added at the end */ 489 /* new stuff to be added at the end */
480 490
@@ -862,12 +872,16 @@ void settings_apply(void)
862#endif 872#endif
863 remote_backlight_set_timeout(global_settings.remote_backlight_timeout); 873 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
864#endif 874#endif
875#ifdef CONFIG_BACKLIGHT
865 backlight_set_timeout(global_settings.backlight_timeout); 876 backlight_set_timeout(global_settings.backlight_timeout);
877#ifdef HAVE_CHARGING
866 backlight_set_on_when_charging(global_settings.backlight_on_when_charging); 878 backlight_set_on_when_charging(global_settings.backlight_on_when_charging);
867#if CONFIG_BACKLIGHT == BL_IRIVER_H100 879#endif
880#if (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR)
868 backlight_set_fade_in(global_settings.backlight_fade_in); 881 backlight_set_fade_in(global_settings.backlight_fade_in);
869 backlight_set_fade_out(global_settings.backlight_fade_out); 882 backlight_set_fade_out(global_settings.backlight_fade_out);
870#endif 883#endif
884#endif
871 ata_spindown(global_settings.disk_spindown); 885 ata_spindown(global_settings.disk_spindown);
872#if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR) 886#if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
873 dac_line_in(global_settings.line_in); 887 dac_line_in(global_settings.line_in);
diff --git a/apps/settings.h b/apps/settings.h
index a4401f8ae5..689dffc739 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -343,7 +343,9 @@ struct user_settings
343 int remote_backlight_timeout; /* backlight off timeout: 0-18 0=never, 343 int remote_backlight_timeout; /* backlight off timeout: 0-18 0=never,
344 1=always, 344 1=always,
345 then according to timeout_values[] */ 345 then according to timeout_values[] */
346#ifdef HAVE_REMOTE_LCD_TICKING 346 bool remote_backlight_on_when_charging;
347 bool remote_caption_backlight; /* turn on backlight at end and start of track */
348#ifdef HAVE_REMOTE_LCD_TICKING
347 bool remote_reduce_ticking; /* 0=normal operation, 349 bool remote_reduce_ticking; /* 0=normal operation,
348 1=EMI reduce on with cost more CPU. */ 350 1=EMI reduce on with cost more CPU. */
349#endif 351#endif
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index fc54436afb..5230dd2010 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -137,10 +137,8 @@ static bool remote_reduce_ticking(void)
137#ifdef CONFIG_BACKLIGHT 137#ifdef CONFIG_BACKLIGHT
138static bool caption_backlight(void) 138static bool caption_backlight(void)
139{ 139{
140 bool rc = set_bool( str(LANG_CAPTION_BACKLIGHT), 140 return set_bool( str(LANG_CAPTION_BACKLIGHT),
141 &global_settings.caption_backlight); 141 &global_settings.caption_backlight);
142
143 return rc;
144} 142}
145 143
146#ifdef HAVE_CHARGING 144#ifdef HAVE_CHARGING
@@ -180,7 +178,7 @@ static bool backlight_timer(void)
180 INT, names, 19, backlight_set_timeout ); 178 INT, names, 19, backlight_set_timeout );
181} 179}
182 180
183#if CONFIG_BACKLIGHT == BL_IRIVER_H100 181#if (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR)
184static bool backlight_fade_in(void) 182static bool backlight_fade_in(void)
185{ 183{
186 static const struct opt_items names[] = { 184 static const struct opt_items names[] = {
@@ -242,6 +240,22 @@ static bool remote_backlight_timer(void)
242 INT, names, 19, remote_backlight_set_timeout ); 240 INT, names, 19, remote_backlight_set_timeout );
243} 241}
244 242
243#ifdef HAVE_CHARGING
244static bool remote_backlight_on_when_charging(void)
245{
246 bool result = set_bool(str(LANG_BACKLIGHT_ON_WHEN_CHARGING),
247 &global_settings.remote_backlight_on_when_charging);
248 remote_backlight_set_on_when_charging(
249 global_settings.remote_backlight_on_when_charging);
250 return result;
251}
252#endif
253
254static bool remote_caption_backlight(void)
255{
256 return set_bool( str(LANG_CAPTION_BACKLIGHT),
257 &global_settings.remote_caption_backlight);
258}
245#endif /* HAVE_REMOTE_LCD */ 259#endif /* HAVE_REMOTE_LCD */
246 260
247static bool contrast(void) 261static bool contrast(void)
@@ -1521,7 +1535,7 @@ static bool lcd_settings_menu(void)
1521 { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), backlight_on_when_charging }, 1535 { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), backlight_on_when_charging },
1522#endif 1536#endif
1523 { ID2P(LANG_CAPTION_BACKLIGHT), caption_backlight }, 1537 { ID2P(LANG_CAPTION_BACKLIGHT), caption_backlight },
1524#if CONFIG_BACKLIGHT == BL_IRIVER_H100 1538#if (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR)
1525 { ID2P(LANG_BACKLIGHT_FADE_IN), backlight_fade_in }, 1539 { ID2P(LANG_BACKLIGHT_FADE_IN), backlight_fade_in },
1526 { ID2P(LANG_BACKLIGHT_FADE_OUT), backlight_fade_out }, 1540 { ID2P(LANG_BACKLIGHT_FADE_OUT), backlight_fade_out },
1527#endif 1541#endif
@@ -1549,6 +1563,11 @@ static bool lcd_remote_settings_menu(void)
1549 1563
1550 static const struct menu_item items[] = { 1564 static const struct menu_item items[] = {
1551 { ID2P(LANG_BACKLIGHT), remote_backlight_timer }, 1565 { ID2P(LANG_BACKLIGHT), remote_backlight_timer },
1566#ifdef HAVE_CHARGING
1567 { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING),
1568 remote_backlight_on_when_charging },
1569#endif
1570 { ID2P(LANG_CAPTION_BACKLIGHT), remote_caption_backlight },
1552 { ID2P(LANG_CONTRAST), remote_contrast }, 1571 { ID2P(LANG_CONTRAST), remote_contrast },
1553 { ID2P(LANG_INVERT), remote_invert }, 1572 { ID2P(LANG_INVERT), remote_invert },
1554 { ID2P(LANG_FLIP_DISPLAY), remote_flip_display }, 1573 { ID2P(LANG_FLIP_DISPLAY), remote_flip_display },
diff --git a/firmware/SOURCES b/firmware/SOURCES
index e5056c54df..aba4e3b622 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -1,9 +1,7 @@
1#ifdef ROCKBOX_HAS_LOGF 1#ifdef ROCKBOX_HAS_LOGF
2logf.c 2logf.c
3#endif 3#endif
4#ifndef SIMULATOR
5backlight.c 4backlight.c
6#endif
7buffer.c 5buffer.c
8common/atoi.c 6common/atoi.c
9common/ctype.c 7common/ctype.c
diff --git a/firmware/backlight.c b/firmware/backlight.c
index 26d0362c27..9cec4ea08c 100644
--- a/firmware/backlight.c
+++ b/firmware/backlight.c
@@ -28,6 +28,7 @@
28#include "power.h" 28#include "power.h"
29#include "system.h" 29#include "system.h"
30#include "timer.h" 30#include "timer.h"
31#include "backlight.h"
31 32
32#ifdef HAVE_REMOTE_LCD 33#ifdef HAVE_REMOTE_LCD
33#include "lcd-remote.h" 34#include "lcd-remote.h"
@@ -51,17 +52,17 @@ static long backlight_stack[DEFAULT_STACK_SIZE/sizeof(long)];
51static const char backlight_thread_name[] = "backlight"; 52static const char backlight_thread_name[] = "backlight";
52static struct event_queue backlight_queue; 53static struct event_queue backlight_queue;
53 54
54static bool charger_was_inserted = 0; 55static bool backlight_on_when_charging = false;
55static bool backlight_on_when_charging = 0;
56
57static int backlight_timer; 56static int backlight_timer;
58static unsigned int backlight_timeout = 5; 57static unsigned int backlight_timeout = 5;
58
59#ifdef HAVE_REMOTE_LCD 59#ifdef HAVE_REMOTE_LCD
60static bool remote_backlight_on_when_charging = false;
60static int remote_backlight_timer; 61static int remote_backlight_timer;
61static unsigned int remote_backlight_timeout = 5; 62static unsigned int remote_backlight_timeout = 5;
62#endif 63#endif
63 64
64#if CONFIG_BACKLIGHT == BL_IRIVER_H100 65#if (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR)
65/* backlight fading */ 66/* backlight fading */
66#define BL_PWM_INTERVAL 5000 /* Cycle interval in µs */ 67#define BL_PWM_INTERVAL 5000 /* Cycle interval in µs */
67#define BL_PWM_COUNT 100 68#define BL_PWM_COUNT 100
@@ -191,11 +192,52 @@ void backlight_set_fade_out(int index)
191{ 192{
192 fade_out_count = backlight_fade_value[index]; 193 fade_out_count = backlight_fade_value[index];
193} 194}
195#endif /* (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR) */
196
197static void __backlight_on(void)
198{
199#ifdef SIMULATOR
200 sim_backlight(100);
201#elif CONFIG_BACKLIGHT == BL_IRIVER_H100
202 if (fade_in_count > 0)
203 backlight_dim(BL_PWM_COUNT);
204 else
205 {
206 bl_dim_target = bl_dim_current = BL_PWM_COUNT;
207 and_l(~0x00020000, &GPIO1_OUT);
208 }
209#elif CONFIG_BACKLIGHT == BL_IRIVER_H300
210 or_l(0x00020000, &GPIO1_OUT);
211#elif CONFIG_BACKLIGHT == BL_RTC
212 /* Enable square wave */
213 rtc_write(0x0a, rtc_read(0x0a) | 0x40);
214#elif CONFIG_BACKLIGHT == BL_PA14_LO /* Player */
215 and_b(~0x40, &PADRH); /* drive and set low */
216 or_b(0x40, &PAIORH);
217#elif CONFIG_BACKLIGHT == BL_PA14_HI /* Ondio */
218 or_b(0x40, &PADRH); /* drive it high */
219#elif CONFIG_BACKLIGHT == BL_GMINI
220 P1 |= 0x10;
221#elif CONFIG_BACKLIGHT == BL_IPOD4G
222 /* brightness full */
223 outl(0x80000000 | (0xff << 16), 0x7000a010);
224
225 /* set port b bit 3 on */
226 outl(((0x100 | 1) << 3), 0x6000d824);
227#elif CONFIG_BACKLIGHT==BL_IPODNANO
228 /* set port B03 on */
229 outl(((0x100 | 1) << 3), 0x6000d824);
230
231 /* set port L07 on */
232 outl(((0x100 | 1) << 7), 0x6000d12c);
194#endif 233#endif
234}
195 235
196static void __backlight_off(void) 236static void __backlight_off(void)
197{ 237{
198#if CONFIG_BACKLIGHT == BL_IRIVER_H100 238#ifdef SIMULATOR
239 sim_backlight(0);
240#elif CONFIG_BACKLIGHT == BL_IRIVER_H100
199 if (fade_out_count > 0) 241 if (fade_out_count > 0)
200 backlight_dim(0); 242 backlight_dim(0);
201 else 243 else
@@ -227,42 +269,29 @@ static void __backlight_off(void)
227#endif 269#endif
228} 270}
229 271
230static void __backlight_on(void) 272#ifdef HAVE_REMOTE_LCD
273static void __remote_backlight_on(void)
231{ 274{
232#if CONFIG_BACKLIGHT == BL_IRIVER_H100 275#ifdef SIMULATOR
233 if (fade_in_count > 0) 276 sim_remote_backlight(100);
234 backlight_dim(BL_PWM_COUNT); 277#elif defined(IRIVER_H300_SERIES)
235 else 278 and_l(~0x00000002, &GPIO1_OUT);
236 { 279#else
237 bl_dim_target = bl_dim_current = BL_PWM_COUNT; 280 and_l(~0x00000800, &GPIO_OUT);
238 and_l(~0x00020000, &GPIO1_OUT); 281#endif
239 } 282}
240#elif CONFIG_BACKLIGHT == BL_IRIVER_H300
241 or_l(0x00020000, &GPIO1_OUT);
242#elif CONFIG_BACKLIGHT == BL_RTC
243 /* Enable square wave */
244 rtc_write(0x0a, rtc_read(0x0a) | 0x40);
245#elif CONFIG_BACKLIGHT == BL_PA14_LO /* Player */
246 and_b(~0x40, &PADRH); /* drive and set low */
247 or_b(0x40, &PAIORH);
248#elif CONFIG_BACKLIGHT == BL_PA14_HI /* Ondio */
249 or_b(0x40, &PADRH); /* drive it high */
250#elif CONFIG_BACKLIGHT == BL_GMINI
251 P1 |= 0x10;
252#elif CONFIG_BACKLIGHT == BL_IPOD4G
253 /* brightness full */
254 outl(0x80000000 | (0xff << 16), 0x7000a010);
255
256 /* set port b bit 3 on */
257 outl(((0x100 | 1) << 3), 0x6000d824);
258#elif CONFIG_BACKLIGHT==BL_IPODNANO
259 /* set port B03 on */
260 outl(((0x100 | 1) << 3), 0x6000d824);
261 283
262 /* set port L07 on */ 284static void __remote_backlight_off(void)
263 outl(((0x100 | 1) << 7), 0x6000d12c); 285{
286#ifdef SIMULATOR
287 sim_remote_backlight(0);
288#elif defined(IRIVER_H300_SERIES)
289 or_l(0x00000002, &GPIO1_OUT);
290#else
291 or_l(0x00000800, &GPIO_OUT);
264#endif 292#endif
265} 293}
294#endif /* HAVE_REMOTE_LCD */
266 295
267void backlight_thread(void) 296void backlight_thread(void)
268{ 297{
@@ -275,26 +304,34 @@ void backlight_thread(void)
275 { 304 {
276#ifdef HAVE_REMOTE_LCD 305#ifdef HAVE_REMOTE_LCD
277 case REMOTE_BACKLIGHT_ON: 306 case REMOTE_BACKLIGHT_ON:
278 remote_backlight_timer = 307 if( remote_backlight_on_when_charging && charger_inserted() )
279 HZ*backlight_timeout_value[remote_backlight_timeout]; 308 {
309 /* Forcing to zero keeps the lights on */
310 remote_backlight_timer = 0;
311 }
312 else
313 {
314 remote_backlight_timer =
315 HZ*backlight_timeout_value[remote_backlight_timeout];
316 }
280 317
281 /* Backlight == OFF in the setting? */ 318 /* Backlight == OFF in the setting? */
282 if(remote_backlight_timer < 0) 319 if(remote_backlight_timer < 0)
283 { 320 {
284 remote_backlight_timer = 0; /* Disable the timeout */ 321 remote_backlight_timer = 0; /* Disable the timeout */
285 lcd_remote_backlight_off(); 322 __remote_backlight_off();
286 } 323 }
287 else 324 else
288 { 325 {
289 lcd_remote_backlight_on(); 326 __remote_backlight_on();
290 } 327 }
291 break; 328 break;
292 329
293 case REMOTE_BACKLIGHT_OFF: 330 case REMOTE_BACKLIGHT_OFF:
294 lcd_remote_backlight_off(); 331 __remote_backlight_off();
295 break; 332 break;
296 333
297#endif 334#endif /* HAVE_REMOTE_LCD */
298 case BACKLIGHT_ON: 335 case BACKLIGHT_ON:
299 if( backlight_on_when_charging && charger_inserted() ) 336 if( backlight_on_when_charging && charger_inserted() )
300 { 337 {
@@ -321,7 +358,7 @@ void backlight_thread(void)
321 __backlight_off(); 358 __backlight_off();
322 break; 359 break;
323 360
324#if CONFIG_BACKLIGHT == BL_IRIVER_H100 361#if (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR)
325 case BACKLIGHT_UNBOOST_CPU: 362 case BACKLIGHT_UNBOOST_CPU:
326 cpu_boost(false); 363 cpu_boost(false);
327 break; 364 break;
@@ -340,74 +377,24 @@ void backlight_thread(void)
340 } 377 }
341} 378}
342 379
343void backlight_on(void) 380static void backlight_tick(void)
344{ 381{
345 queue_post(&backlight_queue, BACKLIGHT_ON, NULL); 382#ifdef HAVE_CHARGING
346} 383 static bool charger_was_inserted = false;
347 384 bool charger_is_inserted = charger_inserted();
348void backlight_off(void)
349{
350 queue_post(&backlight_queue, BACKLIGHT_OFF, NULL);
351}
352 385
386 if( charger_was_inserted != charger_is_inserted )
387 {
388 if( backlight_on_when_charging )
389 backlight_on();
353#ifdef HAVE_REMOTE_LCD 390#ifdef HAVE_REMOTE_LCD
354void remote_backlight_on(void) 391 if( remote_backlight_on_when_charging )
355{ 392 remote_backlight_on();
356 queue_post(&backlight_queue, REMOTE_BACKLIGHT_ON, NULL);
357}
358
359void remote_backlight_off(void)
360{
361 queue_post(&backlight_queue, REMOTE_BACKLIGHT_OFF, NULL);
362}
363
364void remote_backlight_set_timeout(int index)
365{
366 if((unsigned)index >= sizeof(backlight_timeout_value))
367 /* if given a weird value, use 0 */
368 index=0;
369 remote_backlight_timeout = index; /* index in the backlight_timeout_value table */
370 remote_backlight_on();
371}
372#endif
373
374int backlight_get_timeout(void)
375{
376 return backlight_timeout;
377}
378
379void backlight_set_timeout(int index)
380{
381 if((unsigned)index >= sizeof(backlight_timeout_value))
382 /* if given a weird value, use 0 */
383 index=0;
384 backlight_timeout = index; /* index in the backlight_timeout_value table */
385 backlight_on();
386}
387
388#ifdef HAVE_CHARGE_CTRL
389bool backlight_get_on_when_charging(void)
390{
391 return backlight_on_when_charging;
392}
393#endif 393#endif
394
395void backlight_set_on_when_charging(bool yesno)
396{
397 backlight_on_when_charging = yesno;
398 backlight_on();
399}
400
401void backlight_tick(void)
402{
403 bool charger_is_inserted = charger_inserted();
404 if( backlight_on_when_charging &&
405 (charger_was_inserted != charger_is_inserted) )
406 {
407 backlight_on();
408 } 394 }
409 charger_was_inserted = charger_is_inserted; 395 charger_was_inserted = charger_is_inserted;
410 396#endif /* HAVE_CHARGING */
397
411 if(backlight_timer) 398 if(backlight_timer)
412 { 399 {
413 backlight_timer--; 400 backlight_timer--;
@@ -433,8 +420,10 @@ void backlight_init(void)
433 queue_init(&backlight_queue); 420 queue_init(&backlight_queue);
434 create_thread(backlight_thread, backlight_stack, 421 create_thread(backlight_thread, backlight_stack,
435 sizeof(backlight_stack), backlight_thread_name); 422 sizeof(backlight_stack), backlight_thread_name);
436 423 tick_add_task(backlight_tick);
437#if CONFIG_BACKLIGHT == BL_IRIVER_H100 424#ifdef SIMULATOR
425 /* do nothing */
426#elif CONFIG_BACKLIGHT == BL_IRIVER_H100
438 or_l(0x00020000, &GPIO1_ENABLE); 427 or_l(0x00020000, &GPIO1_ENABLE);
439 or_l(0x00020000, &GPIO1_FUNCTION); 428 or_l(0x00020000, &GPIO1_FUNCTION);
440 and_l(~0x00020000, &GPIO1_OUT); /* Start with the backlight ON */ 429 and_l(~0x00020000, &GPIO1_OUT); /* Start with the backlight ON */
@@ -454,22 +443,77 @@ void backlight_init(void)
454#endif 443#endif
455} 444}
456 445
457#else /* no backlight, empty dummy functions */ 446void backlight_on(void)
447{
448 queue_post(&backlight_queue, BACKLIGHT_ON, NULL);
449}
458 450
459void backlight_init(void) 451void backlight_off(void)
460{ 452{
461#if defined(IRIVER_H300_SERIES) && defined(BOOTLOADER) 453 queue_post(&backlight_queue, BACKLIGHT_OFF, NULL);
462 or_l(0x00020000, &GPIO1_OUT); 454}
463 or_l(0x00020000, &GPIO1_ENABLE); 455
464 or_l(0x00020000, &GPIO1_FUNCTION); 456int backlight_get_timeout(void)
457{
458 return backlight_timeout;
459}
460
461void backlight_set_timeout(int index)
462{
463 if((unsigned)index >= sizeof(backlight_timeout_value))
464 /* if given a weird value, use 0 */
465 index=0;
466 backlight_timeout = index; /* index in the backlight_timeout_value table */
467 backlight_on();
468}
469
470#ifdef HAVE_CHARGING
471bool backlight_get_on_when_charging(void)
472{
473 return backlight_on_when_charging;
474}
475
476void backlight_set_on_when_charging(bool yesno)
477{
478 backlight_on_when_charging = yesno;
479 backlight_on();
480}
465#endif 481#endif
482
483#ifdef HAVE_REMOTE_LCD
484void remote_backlight_on(void)
485{
486 queue_post(&backlight_queue, REMOTE_BACKLIGHT_ON, NULL);
466} 487}
488
489void remote_backlight_off(void)
490{
491 queue_post(&backlight_queue, REMOTE_BACKLIGHT_OFF, NULL);
492}
493
494void remote_backlight_set_timeout(int index)
495{
496 if((unsigned)index >= sizeof(backlight_timeout_value))
497 /* if given a weird value, use 0 */
498 index=0;
499 remote_backlight_timeout = index; /* index in the backlight_timeout_value table */
500 remote_backlight_on();
501}
502
503#ifdef HAVE_CHARGING
504void remote_backlight_set_on_when_charging(bool yesno)
505{
506 remote_backlight_on_when_charging = yesno;
507 remote_backlight_on();
508}
509#endif
510#endif /* HAVE_REMOTE_LCD */
511
512#else /* no backlight, empty dummy functions */
513
467void backlight_on(void) {} 514void backlight_on(void) {}
468void backlight_off(void) {} 515void backlight_off(void) {}
469void backlight_tick(void) {}
470int backlight_get_timeout(void) {return 0;}
471void backlight_set_timeout(int index) {(void)index;} 516void backlight_set_timeout(int index) {(void)index;}
472void backlight_set_on_when_charging(bool yesno) {(void)yesno;}
473#ifdef HAVE_REMOTE_LCD 517#ifdef HAVE_REMOTE_LCD
474void remote_backlight_on(void) {} 518void remote_backlight_on(void) {}
475void remote_backlight_off(void) {} 519void remote_backlight_off(void) {}
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index 918705eb4f..c764e1392f 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -181,8 +181,6 @@ static void button_tick(void)
181 lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); 181 lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT);
182 tick = 0; 182 tick = 0;
183 } 183 }
184
185 backlight_tick();
186} 184}
187 185
188long button_get(bool block) 186long button_get(bool block)
diff --git a/firmware/drivers/lcd-h100-remote.c b/firmware/drivers/lcd-h100-remote.c
index 02a907dc89..05e7791cbb 100644
--- a/firmware/drivers/lcd-h100-remote.c
+++ b/firmware/drivers/lcd-h100-remote.c
@@ -122,24 +122,6 @@ static const char scroll_tick_table[16] = {
122/*** driver routines ***/ 122/*** driver routines ***/
123 123
124#ifndef SIMULATOR 124#ifndef SIMULATOR
125void lcd_remote_backlight_on(void)
126{
127#ifdef IRIVER_H300_SERIES
128 and_l(~0x00000002, &GPIO1_OUT);
129#else
130 and_l(~0x00000800, &GPIO_OUT);
131#endif
132}
133
134void lcd_remote_backlight_off(void)
135{
136#ifdef IRIVER_H300_SERIES
137 or_l(0x00000002, &GPIO1_OUT);
138#else
139 or_l(0x00000800, &GPIO_OUT);
140#endif
141}
142
143void lcd_remote_write_command(int cmd) 125void lcd_remote_write_command(int cmd)
144{ 126{
145 int i; 127 int i;
diff --git a/firmware/export/backlight.h b/firmware/export/backlight.h
index 6fee2c0db5..6d3d4d5451 100644
--- a/firmware/export/backlight.h
+++ b/firmware/export/backlight.h
@@ -21,24 +21,32 @@
21 21
22#include "config.h" 22#include "config.h"
23 23
24void backlight_init(void);
25void backlight_on(void); 24void backlight_on(void);
26void backlight_off(void); 25void backlight_off(void);
27void backlight_tick(void);
28int backlight_get_timeout(void);
29void backlight_set_timeout(int index); 26void backlight_set_timeout(int index);
27#ifdef CONFIG_BACKLIGHT
28void backlight_init(void);
29int backlight_get_timeout(void);
30#if CONFIG_BACKLIGHT == BL_IRIVER_H100 30#if CONFIG_BACKLIGHT == BL_IRIVER_H100
31void backlight_set_fade_in(int index); 31void backlight_set_fade_in(int index);
32void backlight_set_fade_out(int index); 32void backlight_set_fade_out(int index);
33#endif 33#endif
34bool backlight_get_on_when_charging(void); 34bool backlight_get_on_when_charging(void);
35void backlight_set_on_when_charging(bool yesno); 35void backlight_set_on_when_charging(bool yesno);
36void remote_backlight_on(void);
37void remote_backlight_off(void);
38extern const char backlight_timeout_value[]; 36extern const char backlight_timeout_value[];
37#else
38#define backlight_init()
39#endif
39 40
40#ifdef HAVE_REMOTE_LCD 41#ifdef HAVE_REMOTE_LCD
42void remote_backlight_on(void);
43void remote_backlight_off(void);
41void remote_backlight_set_timeout(int index); 44void remote_backlight_set_timeout(int index);
45void remote_backlight_set_on_when_charging(bool yesno);
42#endif 46#endif
43 47
48#ifdef SIMULATOR
49void sim_backlight(int value);
50void sim_remote_backlight(int value);
51#endif
44#endif 52#endif
diff --git a/firmware/export/config-fmrecorder.h b/firmware/export/config-fmrecorder.h
index ac6f37c8c9..28d8239c22 100644
--- a/firmware/export/config-fmrecorder.h
+++ b/firmware/export/config-fmrecorder.h
@@ -32,6 +32,9 @@
32/* Define this for S/PDIF input available */ 32/* Define this for S/PDIF input available */
33#define HAVE_SPDIF_IN 33#define HAVE_SPDIF_IN
34 34
35/* Define this for LCD backlight available */
36#define CONFIG_BACKLIGHT BL_RTC /* on I2C controlled RTC port */
37
35#ifndef SIMULATOR 38#ifndef SIMULATOR
36 39
37/* Define this if you have a SH7034 */ 40/* Define this if you have a SH7034 */
@@ -83,9 +86,6 @@
83/* Software controlled LED */ 86/* Software controlled LED */
84#define CONFIG_LED LED_REAL 87#define CONFIG_LED LED_REAL
85 88
86/* Define this for LCD backlight available */
87#define CONFIG_BACKLIGHT BL_RTC /* on I2C controlled RTC port */
88
89/* define this if the unit can be powered or charged via USB */ 89/* define this if the unit can be powered or charged via USB */
90#define HAVE_USB_POWER 90#define HAVE_USB_POWER
91 91
diff --git a/firmware/export/config-h100.h b/firmware/export/config-h100.h
index ef13380538..1327be7e27 100644
--- a/firmware/export/config-h100.h
+++ b/firmware/export/config-h100.h
@@ -38,6 +38,9 @@
38 38
39#define CONFIG_LCD LCD_S1D15E06 39#define CONFIG_LCD LCD_S1D15E06
40 40
41/* Define this for LCD backlight available */
42#define CONFIG_BACKLIGHT BL_IRIVER_H100 /* port controlled */
43
41/* Define this if you have a software controlled poweroff */ 44/* Define this if you have a software controlled poweroff */
42#define HAVE_SW_POWEROFF 45#define HAVE_SW_POWEROFF
43 46
@@ -77,9 +80,6 @@
77/* The size of the flash ROM */ 80/* The size of the flash ROM */
78#define FLASH_SIZE 0x200000 81#define FLASH_SIZE 0x200000
79 82
80/* Define this for LCD backlight available */
81#define CONFIG_BACKLIGHT BL_IRIVER_H100 /* port controlled */
82
83/* Define this to the CPU frequency */ 83/* Define this to the CPU frequency */
84#define CPU_FREQ 11289600 84#define CPU_FREQ 11289600
85 85
diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h
index d67973c0b3..fd001a470e 100644
--- a/firmware/export/config-h120.h
+++ b/firmware/export/config-h120.h
@@ -31,6 +31,9 @@
31 31
32#define CONFIG_LCD LCD_S1D15E06 32#define CONFIG_LCD LCD_S1D15E06
33 33
34/* Define this for LCD backlight available */
35#define CONFIG_BACKLIGHT BL_IRIVER_H100 /* port controlled */
36
34/* Define this if you have a software controlled poweroff */ 37/* Define this if you have a software controlled poweroff */
35#define HAVE_SW_POWEROFF 38#define HAVE_SW_POWEROFF
36 39
@@ -72,9 +75,6 @@
72/* The size of the flash ROM */ 75/* The size of the flash ROM */
73#define FLASH_SIZE 0x200000 76#define FLASH_SIZE 0x200000
74 77
75/* Define this for LCD backlight available */
76#define CONFIG_BACKLIGHT BL_IRIVER_H100 /* port controlled */
77
78/* Define this to the CPU frequency */ 78/* Define this to the CPU frequency */
79#define CPU_FREQ 11289600 79#define CPU_FREQ 11289600
80 80
diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h
index 256cdeac77..5524a55dc0 100644
--- a/firmware/export/config-h300.h
+++ b/firmware/export/config-h300.h
@@ -36,6 +36,9 @@
36/* Define this if you have an remote lcd */ 36/* Define this if you have an remote lcd */
37#define HAVE_REMOTE_LCD 37#define HAVE_REMOTE_LCD
38 38
39/* Define this for LCD backlight available */
40#define CONFIG_BACKLIGHT BL_IRIVER_H300 /* port controlled PWM */
41
39/* Define this if you have a software controlled poweroff */ 42/* Define this if you have a software controlled poweroff */
40#define HAVE_SW_POWEROFF 43#define HAVE_SW_POWEROFF
41 44
@@ -69,9 +72,6 @@
69/* The size of the flash ROM */ 72/* The size of the flash ROM */
70#define FLASH_SIZE 0x400000 73#define FLASH_SIZE 0x400000
71 74
72/* Define this for LCD backlight available */
73#define CONFIG_BACKLIGHT BL_IRIVER_H300 /* port controlled PWM */
74
75/* Define this to the CPU frequency */ 75/* Define this to the CPU frequency */
76#define CPU_FREQ 11289600 76#define CPU_FREQ 11289600
77 77
diff --git a/firmware/export/config-ipodcolor.h b/firmware/export/config-ipodcolor.h
index 0e1637d765..c1068b06eb 100644
--- a/firmware/export/config-ipodcolor.h
+++ b/firmware/export/config-ipodcolor.h
@@ -38,6 +38,9 @@
38/* Define this if you have the WM8975 audio codec */ 38/* Define this if you have the WM8975 audio codec */
39#define HAVE_WM8975 39#define HAVE_WM8975
40 40
41/* Define this for LCD backlight available */
42#define CONFIG_BACKLIGHT BL_IPOD4G /* port controlled */
43
41#ifndef SIMULATOR 44#ifndef SIMULATOR
42 45
43/* Define this if you have a PortalPlayer PP5020 */ 46/* Define this if you have a PortalPlayer PP5020 */
@@ -60,9 +63,6 @@
60/* The start address index for ROM builds */ 63/* The start address index for ROM builds */
61#define ROM_START 0x00000000 64#define ROM_START 0x00000000
62 65
63/* Define this for LCD backlight available */
64#define CONFIG_BACKLIGHT BL_IPOD4G /* port controlled */
65
66/* Define this to the CPU frequency */ 66/* Define this to the CPU frequency */
67#define CPU_FREQ 11289600 67#define CPU_FREQ 11289600
68 68
diff --git a/firmware/export/config-ipodnano.h b/firmware/export/config-ipodnano.h
index 3423079be0..99eb67b5bf 100644
--- a/firmware/export/config-ipodnano.h
+++ b/firmware/export/config-ipodnano.h
@@ -38,6 +38,9 @@
38/* Define this if you have the WM8975 audio codec */ 38/* Define this if you have the WM8975 audio codec */
39#define HAVE_WM8975 39#define HAVE_WM8975
40 40
41/* Define this for LCD backlight available */
42#define CONFIG_BACKLIGHT BL_IPODNANO /* port controlled */
43
41#ifndef SIMULATOR 44#ifndef SIMULATOR
42 45
43/* The Nano actually has a PP5021 - but it's register compatible with 46/* The Nano actually has a PP5021 - but it's register compatible with
@@ -62,9 +65,6 @@
62/* The start address index for ROM builds */ 65/* The start address index for ROM builds */
63#define ROM_START 0x00000000 66#define ROM_START 0x00000000
64 67
65/* Define this for LCD backlight available */
66#define CONFIG_BACKLIGHT BL_IPODNANO /* port controlled */
67
68/* Define this to the CPU frequency */ 68/* Define this to the CPU frequency */
69#define CPU_FREQ 11289600 69#define CPU_FREQ 11289600
70 70
diff --git a/firmware/export/config-player.h b/firmware/export/config-player.h
index e12e2234e1..f3b1bbddd7 100644
--- a/firmware/export/config-player.h
+++ b/firmware/export/config-player.h
@@ -20,6 +20,9 @@
20/* Define this if you have a DAC3550A */ 20/* Define this if you have a DAC3550A */
21#define HAVE_DAC3550A 21#define HAVE_DAC3550A
22 22
23/* Define this for LCD backlight available */
24#define CONFIG_BACKLIGHT BL_PA14_LO /* port PA14, low active */
25
23#ifndef SIMULATOR 26#ifndef SIMULATOR
24 27
25/* Define this if you have a SH7034 */ 28/* Define this if you have a SH7034 */
@@ -70,9 +73,6 @@
70/* Software controlled LED */ 73/* Software controlled LED */
71#define CONFIG_LED LED_REAL 74#define CONFIG_LED LED_REAL
72 75
73/* Define this for LCD backlight available */
74#define CONFIG_BACKLIGHT BL_PA14_LO /* port PA14, low active */
75
76#define CONFIG_LCD LCD_SSD1801 76#define CONFIG_LCD LCD_SSD1801
77 77
78#define BOOTFILE_EXT "mod" 78#define BOOTFILE_EXT "mod"
diff --git a/firmware/export/config-recorder.h b/firmware/export/config-recorder.h
index c674b63996..32c29b2ec5 100644
--- a/firmware/export/config-recorder.h
+++ b/firmware/export/config-recorder.h
@@ -26,6 +26,9 @@
26/* Define this for S/PDIF input available */ 26/* Define this for S/PDIF input available */
27#define HAVE_SPDIF_IN 27#define HAVE_SPDIF_IN
28 28
29/* Define this for LCD backlight available */
30#define CONFIG_BACKLIGHT BL_RTC /* on I2C controlled RTC port */
31
29#ifndef SIMULATOR 32#ifndef SIMULATOR
30 33
31/* Define this if you have a SH7034 */ 34/* Define this if you have a SH7034 */
@@ -74,9 +77,6 @@
74/* Software controlled LED */ 77/* Software controlled LED */
75#define CONFIG_LED LED_REAL 78#define CONFIG_LED LED_REAL
76 79
77/* Define this for LCD backlight available */
78#define CONFIG_BACKLIGHT BL_RTC /* on I2C controlled RTC port */
79
80/* Define this for S/PDIF output available */ 80/* Define this for S/PDIF output available */
81#define HAVE_SPDIF_OUT 81#define HAVE_SPDIF_OUT
82 82
diff --git a/firmware/export/config-recorderv2.h b/firmware/export/config-recorderv2.h
index 1de321799e..fbe99812dc 100644
--- a/firmware/export/config-recorderv2.h
+++ b/firmware/export/config-recorderv2.h
@@ -29,6 +29,9 @@
29/* Define this for S/PDIF input available */ 29/* Define this for S/PDIF input available */
30#define HAVE_SPDIF_IN 30#define HAVE_SPDIF_IN
31 31
32/* Define this for LCD backlight available */
33#define CONFIG_BACKLIGHT BL_RTC /* on I2C controlled RTC port */
34
32#ifndef SIMULATOR 35#ifndef SIMULATOR
33 36
34/* Define this if you have a SH7034 */ 37/* Define this if you have a SH7034 */
@@ -83,9 +86,6 @@
83/* Software controlled LED */ 86/* Software controlled LED */
84#define CONFIG_LED LED_REAL 87#define CONFIG_LED LED_REAL
85 88
86/* Define this for LCD backlight available */
87#define CONFIG_BACKLIGHT BL_RTC /* on I2C controlled RTC port */
88
89/* define this if the unit can be powered or charged via USB */ 89/* define this if the unit can be powered or charged via USB */
90#define HAVE_USB_POWER 90#define HAVE_USB_POWER
91 91
diff --git a/firmware/export/lcd-remote.h b/firmware/export/lcd-remote.h
index 6d5091fc66..491e055b17 100644
--- a/firmware/export/lcd-remote.h
+++ b/firmware/export/lcd-remote.h
@@ -30,8 +30,6 @@
30#define STYLE_INVERT 1 30#define STYLE_INVERT 1
31 31
32extern void lcd_remote_init(void); 32extern void lcd_remote_init(void);
33extern void lcd_remote_backlight_on(void);
34extern void lcd_remote_backlight_off(void);
35extern int lcd_remote_default_contrast(void); 33extern int lcd_remote_default_contrast(void);
36extern void lcd_remote_set_contrast(int val); 34extern void lcd_remote_set_contrast(int val);
37extern void lcd_remote_emireduce(bool state); 35extern void lcd_remote_emireduce(bool state);
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index ed3f42287c..72a9b90e78 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -448,7 +448,7 @@ static int runcurrent(void)
448 current = CURRENT_USB; 448 current = CURRENT_USB;
449 } 449 }
450 450
451#ifndef BOOTLOADER 451#if defined(CONFIG_BACKLIGHT) && !defined(BOOTLOADER)
452 if ((backlight_get_timeout() == 1) /* LED always on */ 452 if ((backlight_get_timeout() == 1) /* LED always on */
453#ifdef HAVE_CHARGE_CTRL 453#ifdef HAVE_CHARGE_CTRL
454 || (charger_inserted() && backlight_get_on_when_charging()) 454 || (charger_inserted() && backlight_get_on_when_charging())
@@ -915,13 +915,11 @@ void shutdown_hw(void)
915#elif HAVE_TLV320 915#elif HAVE_TLV320
916 tlv320_close(); 916 tlv320_close();
917#endif 917#endif
918#if CONFIG_KEYPAD == ONDIO_PAD
919 backlight_off(); 918 backlight_off();
920 sleep(1);
921 lcd_set_contrast(0); 919 lcd_set_contrast(0);
922#endif
923#ifdef HAVE_REMOTE_LCD 920#ifdef HAVE_REMOTE_LCD
924 lcd_remote_backlight_off(); 921 remote_backlight_off();
922 lcd_remote_set_contrast(0);
925#endif 923#endif
926 power_off(); 924 power_off();
927#endif /* #ifndef SIMULATOR */ 925#endif /* #ifndef SIMULATOR */
diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c
index 0bbecdae41..ff66c1fab3 100644
--- a/uisimulator/common/stubs.c
+++ b/uisimulator/common/stubs.c
@@ -78,21 +78,19 @@ void audio_set_buffer_margin(int seconds)
78} 78}
79#endif 79#endif
80 80
81/* Generic firmware stubs. */ 81#ifdef CONFIG_BACKLIGHT
82void backlight_on(void) 82void sim_backlight(int value)
83{ 83{
84 /* we could do something better here! */ 84 DEBUGF("backlight: %s\n", (value > 0) ? "on" : "off");
85}
86
87void backlight_off(void)
88{
89 /* we could do something better here! */
90} 85}
86#endif
91 87
92void backlight_time(int dummy) 88#ifdef HAVE_REMOTE_LCD
89void sim_remote_backlight(int value)
93{ 90{
94 (void)dummy; 91 DEBUGF("remote backlight: %s\n", (value > 0) ? "on" : "off");
95} 92}
93#endif
96 94
97int fat_startsector(void) 95int fat_startsector(void)
98{ 96{
@@ -167,21 +165,6 @@ bool simulate_usb(void)
167 return false; 165 return false;
168} 166}
169 167
170void backlight_set_timeout(int index)
171{
172 (void)index;
173}
174
175void backlight_set_on_when_charging(bool beep)
176{
177 (void)beep;
178}
179
180void remote_backlight_set_timeout(int index)
181{
182 (void)index;
183}
184
185int rtc_read(int address) 168int rtc_read(int address)
186{ 169{
187 time_t now = time(NULL); 170 time_t now = time(NULL);
diff --git a/uisimulator/win32/button.c b/uisimulator/win32/button.c
index 08ef5e15d8..47adbb485f 100644
--- a/uisimulator/win32/button.c
+++ b/uisimulator/win32/button.c
@@ -202,7 +202,13 @@ void button_event(int key, bool pressed)
202 else 202 else
203 queue_post(&button_queue, btn, NULL); 203 queue_post(&button_queue, btn, NULL);
204 204
205 backlight_on(); 205#ifdef HAVE_REMOTE_LCD
206 if(btn & BUTTON_REMOTE)
207 remote_backlight_on();
208 else
209#endif
210 backlight_on();
211
206 } 212 }
207 } 213 }
208 else 214 else
diff --git a/uisimulator/win32/kernel.c b/uisimulator/win32/kernel.c
index 8e7bb88546..eb55bf7a72 100644
--- a/uisimulator/win32/kernel.c
+++ b/uisimulator/win32/kernel.c
@@ -22,12 +22,15 @@
22#include "kernel.h" 22#include "kernel.h"
23#include "thread-win32.h" 23#include "thread-win32.h"
24#include "thread.h" 24#include "thread.h"
25#include "debug.h"
25 26
26/* (Daniel 2002-10-31) Mingw32 requires this errno variable to be present. 27/* (Daniel 2002-10-31) Mingw32 requires this errno variable to be present.
27 I'm not quite sure why and I don't know if this breaks the MSVC compile. 28 I'm not quite sure why and I don't know if this breaks the MSVC compile.
28 If it does, we should put this within #ifdef __MINGW32__ */ 29 If it does, we should put this within #ifdef __MINGW32__ */
29int errno; 30int errno;
30 31
32static void (*tick_funcs[MAX_NUM_TICK_TASKS])(void);
33
31int set_irq_level (int level) 34int set_irq_level (int level)
32{ 35{
33 static int _lv = 0; 36 static int _lv = 0;
@@ -99,6 +102,54 @@ void switch_thread (void)
99 yield (); 102 yield ();
100} 103}
101 104
105void sim_tick_tasks(void)
106{
107 int i;
108
109 /* Run through the list of tick tasks */
110 for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
111 {
112 if(tick_funcs[i])
113 {
114 tick_funcs[i]();
115 }
116 }
117}
118
119int tick_add_task(void (*f)(void))
120{
121 int i;
122
123 /* Add a task if there is room */
124 for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
125 {
126 if(tick_funcs[i] == NULL)
127 {
128 tick_funcs[i] = f;
129 return 0;
130 }
131 }
132 DEBUGF("Error! tick_add_task(): out of tasks");
133 return -1;
134}
135
136int tick_remove_task(void (*f)(void))
137{
138 int i;
139
140 /* Remove a task if it is there */
141 for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
142 {
143 if(tick_funcs[i] == f)
144 {
145 tick_funcs[i] = NULL;
146 return 0;
147 }
148 }
149
150 return -1;
151}
152
102/* TODO: Implement mutexes for win32 */ 153/* TODO: Implement mutexes for win32 */
103void mutex_init(struct mutex *m) 154void mutex_init(struct mutex *m)
104{ 155{
diff --git a/uisimulator/win32/uisw32.c b/uisimulator/win32/uisw32.c
index d098c6ef24..b31eccf794 100644
--- a/uisimulator/win32/uisw32.c
+++ b/uisimulator/win32/uisw32.c
@@ -36,7 +36,8 @@
36 36
37// extern functions 37// extern functions
38extern void app_main (void *); // mod entry point 38extern void app_main (void *); // mod entry point
39extern void new_key(int key); 39extern void new_key(int key);
40extern void sim_tick_tasks(void);
40 41
41void button_event(int key, bool pressed); 42void button_event(int key, bool pressed);
42 43
@@ -67,12 +68,18 @@ LRESULT CALLBACK GUIWndProc (
67 static HDC hMemDc; 68 static HDC hMemDc;
68 69
69 static LARGE_INTEGER persec, tick1, ticknow; 70 static LARGE_INTEGER persec, tick1, ticknow;
71 long new_tick;
70 72
71 switch (uMsg) 73 switch (uMsg)
72 { 74 {
73 case WM_TIMER: 75 case WM_TIMER:
74 QueryPerformanceCounter(&ticknow); 76 QueryPerformanceCounter(&ticknow);
75 current_tick = ((ticknow.QuadPart-tick1.QuadPart)*HZ)/persec.QuadPart; 77 new_tick = ((ticknow.QuadPart-tick1.QuadPart)*HZ)/persec.QuadPart;
78 if (new_tick != current_tick)
79 {
80 sim_tick_tasks();
81 current_tick = new_tick;
82 }
76 return TRUE; 83 return TRUE;
77 case WM_ACTIVATE: 84 case WM_ACTIVATE:
78 if (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE) 85 if (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE)
diff --git a/uisimulator/x11/button-x11.c b/uisimulator/x11/button-x11.c
index b2d8ab6c7a..e037867caf 100644
--- a/uisimulator/x11/button-x11.c
+++ b/uisimulator/x11/button-x11.c
@@ -21,6 +21,7 @@
21#include "button.h" 21#include "button.h"
22#include "kernel.h" 22#include "kernel.h"
23#include "debug.h" 23#include "debug.h"
24#include "backlight.h"
24#include "misc.h" 25#include "misc.h"
25 26
26#include "X11/keysym.h" 27#include "X11/keysym.h"
@@ -47,7 +48,7 @@ static long lastbtn; /* Last valid button status */
47/* mostly copied from real button.c */ 48/* mostly copied from real button.c */
48void button_read (void); 49void button_read (void);
49 50
50void button_tick(void) 51static void button_tick(void)
51{ 52{
52 static int tick = 0; 53 static int tick = 0;
53 static int count = 0; 54 static int count = 0;
@@ -117,6 +118,13 @@ void button_tick(void)
117 queue_post(&button_queue, BUTTON_REPEAT | btn, NULL); 118 queue_post(&button_queue, BUTTON_REPEAT | btn, NULL);
118 else 119 else
119 queue_post(&button_queue, btn, NULL); 120 queue_post(&button_queue, btn, NULL);
121#ifdef HAVE_REMOTE_LCD
122 if(btn & BUTTON_REMOTE)
123 remote_backlight_on();
124 else
125#endif
126 backlight_on();
127
120 } 128 }
121 } 129 }
122 else 130 else
@@ -276,6 +284,7 @@ long button_get_w_tmo(int ticks)
276 284
277void button_init(void) 285void button_init(void)
278{ 286{
287 tick_add_task(button_tick);
279} 288}
280 289
281int button_status(void) 290int button_status(void)
diff --git a/uisimulator/x11/kernel.c b/uisimulator/x11/kernel.c
index 7405fec52f..25f2df220c 100644
--- a/uisimulator/x11/kernel.c
+++ b/uisimulator/x11/kernel.c
@@ -17,8 +17,12 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19 19
20#include <stddef.h>
20#include "kernel.h" 21#include "kernel.h"
21#include "thread.h" 22#include "thread.h"
23#include "debug.h"
24
25static void (*tick_funcs[MAX_NUM_TICK_TASKS])(void);
22 26
23int set_irq_level (int level) 27int set_irq_level (int level)
24{ 28{
@@ -91,6 +95,54 @@ void switch_thread (void)
91 yield (); 95 yield ();
92} 96}
93 97
98void sim_tick_tasks(void)
99{
100 int i;
101
102 /* Run through the list of tick tasks */
103 for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
104 {
105 if(tick_funcs[i])
106 {
107 tick_funcs[i]();
108 }
109 }
110}
111
112int tick_add_task(void (*f)(void))
113{
114 int i;
115
116 /* Add a task if there is room */
117 for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
118 {
119 if(tick_funcs[i] == NULL)
120 {
121 tick_funcs[i] = f;
122 return 0;
123 }
124 }
125 DEBUGF("Error! tick_add_task(): out of tasks");
126 return -1;
127}
128
129int tick_remove_task(void (*f)(void))
130{
131 int i;
132
133 /* Remove a task if it is there */
134 for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
135 {
136 if(tick_funcs[i] == f)
137 {
138 tick_funcs[i] = NULL;
139 return 0;
140 }
141 }
142
143 return -1;
144}
145
94void mutex_init(struct mutex *m) 146void mutex_init(struct mutex *m)
95{ 147{
96 (void)m; 148 (void)m;
diff --git a/uisimulator/x11/thread.c b/uisimulator/x11/thread.c
index f3fe868fbc..6d9139c35d 100644
--- a/uisimulator/x11/thread.c
+++ b/uisimulator/x11/thread.c
@@ -30,7 +30,7 @@
30#endif 30#endif
31 31
32long current_tick = 0; 32long current_tick = 0;
33extern void button_tick(void); 33extern void sim_tick_tasks(void);
34 34
35static void msleep(int msec) 35static void msleep(int msec)
36{ 36{
@@ -59,10 +59,8 @@ static void update_tick_thread()
59 + (now.tv_usec - start.tv_usec) / (1000000/HZ); 59 + (now.tv_usec - start.tv_usec) / (1000000/HZ);
60 if (new_tick > current_tick) 60 if (new_tick > current_tick)
61 { 61 {
62 sim_tick_tasks();
62 current_tick = new_tick; 63 current_tick = new_tick;
63 button_tick(); /* Dirty call to button.c. This should probably
64 * be implemented as a tick task the same way
65 * as on the target. */
66 } 64 }
67 } 65 }
68} 66}