diff options
Diffstat (limited to 'firmware/backlight.c')
-rw-r--r-- | firmware/backlight.c | 278 |
1 files changed, 161 insertions, 117 deletions
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)]; | |||
51 | static const char backlight_thread_name[] = "backlight"; | 52 | static const char backlight_thread_name[] = "backlight"; |
52 | static struct event_queue backlight_queue; | 53 | static struct event_queue backlight_queue; |
53 | 54 | ||
54 | static bool charger_was_inserted = 0; | 55 | static bool backlight_on_when_charging = false; |
55 | static bool backlight_on_when_charging = 0; | ||
56 | |||
57 | static int backlight_timer; | 56 | static int backlight_timer; |
58 | static unsigned int backlight_timeout = 5; | 57 | static unsigned int backlight_timeout = 5; |
58 | |||
59 | #ifdef HAVE_REMOTE_LCD | 59 | #ifdef HAVE_REMOTE_LCD |
60 | static bool remote_backlight_on_when_charging = false; | ||
60 | static int remote_backlight_timer; | 61 | static int remote_backlight_timer; |
61 | static unsigned int remote_backlight_timeout = 5; | 62 | static 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 | |||
197 | static 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 | ||
196 | static void __backlight_off(void) | 236 | static 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 | ||
230 | static void __backlight_on(void) | 272 | #ifdef HAVE_REMOTE_LCD |
273 | static 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 */ | 284 | static 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 | ||
267 | void backlight_thread(void) | 296 | void 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 | ||
343 | void backlight_on(void) | 380 | static 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(); | |
348 | void 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 |
354 | void 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 | |||
359 | void remote_backlight_off(void) | ||
360 | { | ||
361 | queue_post(&backlight_queue, REMOTE_BACKLIGHT_OFF, NULL); | ||
362 | } | ||
363 | |||
364 | void 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 | |||
374 | int backlight_get_timeout(void) | ||
375 | { | ||
376 | return backlight_timeout; | ||
377 | } | ||
378 | |||
379 | void 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 | ||
389 | bool backlight_get_on_when_charging(void) | ||
390 | { | ||
391 | return backlight_on_when_charging; | ||
392 | } | ||
393 | #endif | 393 | #endif |
394 | |||
395 | void backlight_set_on_when_charging(bool yesno) | ||
396 | { | ||
397 | backlight_on_when_charging = yesno; | ||
398 | backlight_on(); | ||
399 | } | ||
400 | |||
401 | void 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 */ | 446 | void backlight_on(void) |
447 | { | ||
448 | queue_post(&backlight_queue, BACKLIGHT_ON, NULL); | ||
449 | } | ||
458 | 450 | ||
459 | void backlight_init(void) | 451 | void 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); | 456 | int backlight_get_timeout(void) |
457 | { | ||
458 | return backlight_timeout; | ||
459 | } | ||
460 | |||
461 | void 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 | ||
471 | bool backlight_get_on_when_charging(void) | ||
472 | { | ||
473 | return backlight_on_when_charging; | ||
474 | } | ||
475 | |||
476 | void 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 | ||
484 | void remote_backlight_on(void) | ||
485 | { | ||
486 | queue_post(&backlight_queue, REMOTE_BACKLIGHT_ON, NULL); | ||
466 | } | 487 | } |
488 | |||
489 | void remote_backlight_off(void) | ||
490 | { | ||
491 | queue_post(&backlight_queue, REMOTE_BACKLIGHT_OFF, NULL); | ||
492 | } | ||
493 | |||
494 | void 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 | ||
504 | void 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 | |||
467 | void backlight_on(void) {} | 514 | void backlight_on(void) {} |
468 | void backlight_off(void) {} | 515 | void backlight_off(void) {} |
469 | void backlight_tick(void) {} | ||
470 | int backlight_get_timeout(void) {return 0;} | ||
471 | void backlight_set_timeout(int index) {(void)index;} | 516 | void backlight_set_timeout(int index) {(void)index;} |
472 | void backlight_set_on_when_charging(bool yesno) {(void)yesno;} | ||
473 | #ifdef HAVE_REMOTE_LCD | 517 | #ifdef HAVE_REMOTE_LCD |
474 | void remote_backlight_on(void) {} | 518 | void remote_backlight_on(void) {} |
475 | void remote_backlight_off(void) {} | 519 | void remote_backlight_off(void) {} |