summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bavin <pondlife@pondlife.me>2008-11-26 08:26:13 +0000
committerSteve Bavin <pondlife@pondlife.me>2008-11-26 08:26:13 +0000
commitf6847265804b650b007eb8ecdc86876214ee7302 (patch)
tree5f92d0097167f2e5c257b42427fd182e704ae4c1
parent756bcc4bd53b34371c073c8468cbd8c01ffe094a (diff)
downloadrockbox-f6847265804b650b007eb8ecdc86876214ee7302.tar.gz
rockbox-f6847265804b650b007eb8ecdc86876214ee7302.zip
Add software backlight fading for E100/H300/X5/D2, by Thomas Martitz and others - see FS#6800 for credits.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19221 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/features.txt2
-rw-r--r--apps/menus/display_menu.c8
-rw-r--r--apps/settings.c3
-rw-r--r--apps/settings.h6
-rw-r--r--apps/settings_list.c5
-rw-r--r--firmware/SOURCES4
-rw-r--r--firmware/backlight-thread-fading.c87
-rw-r--r--firmware/backlight.c126
-rw-r--r--firmware/export/backlight-thread-fading.h46
-rw-r--r--firmware/export/backlight.h8
-rw-r--r--firmware/export/config-c200.h4
-rw-r--r--firmware/export/config-cowond2.h4
-rw-r--r--firmware/export/config-e200.h4
-rw-r--r--firmware/export/config-h300.h5
-rw-r--r--firmware/export/config-iaudiox5.h3
-rw-r--r--firmware/target/arm/sandisk/backlight-c200_e200.c14
-rw-r--r--firmware/target/arm/sandisk/backlight-target.h1
-rw-r--r--firmware/target/arm/tcc780x/cowond2/backlight-cowond2.c13
18 files changed, 304 insertions, 39 deletions
diff --git a/apps/features.txt b/apps/features.txt
index 118465a535..0a01eb92c7 100644
--- a/apps/features.txt
+++ b/apps/features.txt
@@ -20,7 +20,7 @@ albumart
20backlight_brightness 20backlight_brightness
21#endif 21#endif
22 22
23#if defined(HAVE_BACKLIGHT_PWM_FADING) 23#if defined(HAVE_BACKLIGHT_PWM_FADING) || defined(USE_BACKLIGHT_SW_FADING)
24backlight_fade 24backlight_fade
25#endif 25#endif
26 26
diff --git a/apps/menus/display_menu.c b/apps/menus/display_menu.c
index 016255bad1..744a9e9354 100644
--- a/apps/menus/display_menu.c
+++ b/apps/menus/display_menu.c
@@ -91,7 +91,8 @@ MENUITEM_SETTING(backlight_on_button_hold,
91 &global_settings.backlight_on_button_hold, NULL); 91 &global_settings.backlight_on_button_hold, NULL);
92#endif 92#endif
93MENUITEM_SETTING(caption_backlight, &global_settings.caption_backlight, NULL); 93MENUITEM_SETTING(caption_backlight, &global_settings.caption_backlight, NULL);
94#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) 94#if (defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)) || \
95 defined(USE_BACKLIGHT_SW_FADING)
95MENUITEM_SETTING(backlight_fade_in, &global_settings.backlight_fade_in, NULL); 96MENUITEM_SETTING(backlight_fade_in, &global_settings.backlight_fade_in, NULL);
96MENUITEM_SETTING(backlight_fade_out, &global_settings.backlight_fade_out, NULL); 97MENUITEM_SETTING(backlight_fade_out, &global_settings.backlight_fade_out, NULL);
97#endif 98#endif
@@ -130,9 +131,10 @@ MAKE_MENU(lcd_settings,ID2P(LANG_LCD_MENU),
130 ,&backlight_on_button_hold 131 ,&backlight_on_button_hold
131# endif 132# endif
132 ,&caption_backlight 133 ,&caption_backlight
133# if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) 134#if (defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)) || \
135 defined(USE_BACKLIGHT_SW_FADING)
134 ,&backlight_fade_in, &backlight_fade_out 136 ,&backlight_fade_in, &backlight_fade_out
135# endif 137#endif
136 ,&bl_filter_first_keypress 138 ,&bl_filter_first_keypress
137# ifdef HAVE_LCD_SLEEP_SETTING 139# ifdef HAVE_LCD_SLEEP_SETTING
138 ,&lcd_sleep_after_backlight_off 140 ,&lcd_sleep_after_backlight_off
diff --git a/apps/settings.c b/apps/settings.c
index bdfaba2f44..2cab26a4a1 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -768,7 +768,8 @@ void settings_apply(bool read_disk)
768#if CONFIG_CHARGING 768#if CONFIG_CHARGING
769 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged); 769 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
770#endif 770#endif
771#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) 771#if (defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)) \
772 || defined(USE_BACKLIGHT_SW_FADING)
772 backlight_set_fade_in(global_settings.backlight_fade_in); 773 backlight_set_fade_in(global_settings.backlight_fade_in);
773 backlight_set_fade_out(global_settings.backlight_fade_out); 774 backlight_set_fade_out(global_settings.backlight_fade_out);
774#endif 775#endif
diff --git a/apps/settings.h b/apps/settings.h
index c5658aaf09..56b7d3e80a 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -421,10 +421,14 @@ struct user_settings
421 int backlight_timeout_plugged; 421 int backlight_timeout_plugged;
422#endif 422#endif
423 423
424#ifdef HAVE_BACKLIGHT_PWM_FADING 424#if defined(HAVE_BACKLIGHT_PWM_FADING)
425 int backlight_fade_in; /* backlight fade in timing: 0..3 */ 425 int backlight_fade_in; /* backlight fade in timing: 0..3 */
426 int backlight_fade_out; /* backlight fade in timing: 0..7 */ 426 int backlight_fade_out; /* backlight fade in timing: 0..7 */
427#elif defined(USE_BACKLIGHT_SW_FADING)
428 bool backlight_fade_in;
429 bool backlight_fade_out;
427#endif 430#endif
431
428#ifdef HAVE_BACKLIGHT_BRIGHTNESS 432#ifdef HAVE_BACKLIGHT_BRIGHTNESS
429 int brightness; 433 int brightness;
430#endif 434#endif
diff --git a/apps/settings_list.c b/apps/settings_list.c
index 6a7fcc3aec..f4519f5975 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -679,6 +679,11 @@ const struct settings_list settings[] = {
679 UNIT_MS, formatter_unit_0_is_off, getlang_unit_0_is_off, 679 UNIT_MS, formatter_unit_0_is_off, getlang_unit_0_is_off,
680 backlight_set_fade_out, 10, 680 backlight_set_fade_out, 10,
681 0,100,200,300,500,1000,2000,3000,5000,10000), 681 0,100,200,300,500,1000,2000,3000,5000,10000),
682#elif defined(USE_BACKLIGHT_SW_FADING)
683 OFFON_SETTING(0, backlight_fade_in, LANG_BACKLIGHT_FADE_IN,
684 true, "backlight fade in", backlight_set_fade_in),
685 OFFON_SETTING(0, backlight_fade_out, LANG_BACKLIGHT_FADE_OUT,
686 true, "backlight fade out", backlight_set_fade_out),
682#endif 687#endif
683 INT_SETTING(F_PADTITLE, scroll_speed, LANG_SCROLL_SPEED, 9,"scroll speed", 688 INT_SETTING(F_PADTITLE, scroll_speed, LANG_SCROLL_SPEED, 9,"scroll speed",
684 UNIT_INT, 0, 15, 1, NULL, NULL, lcd_scroll_speed), 689 UNIT_INT, 0, 15, 1, NULL, NULL, lcd_scroll_speed),
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 4e40d11cf7..47dcfe5c86 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -96,6 +96,10 @@ drivers/lcd-remote-2bit-vi.c
96#endif /* LCD_REMOTE_DEPTH */ 96#endif /* LCD_REMOTE_DEPTH */
97#endif /* HAVE_REMOTE_LCD */ 97#endif /* HAVE_REMOTE_LCD */
98 98
99#ifdef USE_BACKLIGHT_SW_FADING
100backlight-thread-fading.c
101#endif /* USE_BACKLIGHT_SW_FADING */
102
99/* Misc. */ 103/* Misc. */
100drivers/led.c 104drivers/led.c
101drivers/button.c 105drivers/button.c
diff --git a/firmware/backlight-thread-fading.c b/firmware/backlight-thread-fading.c
new file mode 100644
index 0000000000..30778a9912
--- /dev/null
+++ b/firmware/backlight-thread-fading.c
@@ -0,0 +1,87 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Thomas Martitz
11 * Copyright (C) 2008 by Martin Ritter
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22
23#include <stdbool.h>
24#include "backlight-target.h"
25#include "config.h"
26#include "system.h"
27#include "backlight.h"
28#include "backlight-thread-fading.h"
29
30/* To adapt a target do:
31 * - make sure _backlight_on doesn't set the brightness to something other than
32 * the previous value (lowest brightness in most cases)
33 * - #define USE_BACKLIGHT_SW_FADING in config-<target>.h
34 */
35
36/* can be MIN_BRIGHTNESS_SETTING-1 */
37static int current_brightness = DEFAULT_BRIGHTNESS_SETTING;
38
39void _backlight_fade_update_state(int brightness)
40{
41 current_brightness = brightness;
42}
43
44/* returns true if fade is finished */
45static bool _backlight_fade_up(void)
46{
47 if (LIKELY(current_brightness < backlight_brightness))
48 {
49 _backlight_set_brightness(++current_brightness);
50 }
51 return(current_brightness >= backlight_brightness);
52}
53
54/* returns true if fade is finished */
55static bool _backlight_fade_down(void)
56{
57 if (LIKELY(current_brightness > MIN_BRIGHTNESS_SETTING))
58 {
59 _backlight_set_brightness(--current_brightness);
60 return false;
61 }
62 else
63 {
64 /* decrement once more, since backlight is off */
65 current_brightness--;
66 _backlight_off();
67 return true;
68 }
69}
70
71bool _backlight_fade_step(int direction)
72{
73 bool done;
74 switch(direction)
75 {
76 case FADING_UP:
77 done = _backlight_fade_up();
78 break;
79 case FADING_DOWN:
80 done = _backlight_fade_down();
81 break;
82 default:
83 done = true;
84 break;
85 }
86 return(done);
87}
diff --git a/firmware/backlight.c b/firmware/backlight.c
index b8becfa69f..fe9c215af5 100644
--- a/firmware/backlight.c
+++ b/firmware/backlight.c
@@ -8,6 +8,8 @@
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing 10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 * Additional work by Martin Ritter (2007) and Thomas Martitz (2008)
12 * for backlight thread fading
11 * 13 *
12 * This program is free software; you can redistribute it and/or 14 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License 15 * modify it under the terms of the GNU General Public License
@@ -46,6 +48,9 @@
46#define BACKLIGHT_FULL_INIT 48#define BACKLIGHT_FULL_INIT
47#endif 49#endif
48 50
51#ifdef USE_BACKLIGHT_SW_FADING
52#include "backlight-thread-fading.h"
53#endif
49#ifdef SIMULATOR 54#ifdef SIMULATOR
50/* TODO: find a better way to do it but we need a kernel thread somewhere to 55/* TODO: find a better way to do it but we need a kernel thread somewhere to
51 handle this */ 56 handle this */
@@ -134,6 +139,10 @@ static int backlight_timeout_plugged = 5*HZ;
134static int backlight_on_button_hold = 0; 139static int backlight_on_button_hold = 0;
135#endif 140#endif
136 141
142#ifdef HAVE_BACKLIGHT_BRIGHTNESS
143int backlight_brightness = DEFAULT_BRIGHTNESS_SETTING;
144#endif
145
137#ifdef HAVE_BUTTON_LIGHT 146#ifdef HAVE_BUTTON_LIGHT
138static int buttonlight_timer; 147static int buttonlight_timer;
139int _buttonlight_timeout = 5*HZ; 148int _buttonlight_timeout = 5*HZ;
@@ -221,6 +230,12 @@ void backlight_lcd_sleep_countdown(bool start)
221} 230}
222#endif /* HAVE_LCD_SLEEP */ 231#endif /* HAVE_LCD_SLEEP */
223 232
233#ifdef USE_BACKLIGHT_SW_FADING
234static int backlight_fading_type = (FADING_UP|FADING_DOWN);
235static int backlight_fading_state = NOT_FADING;
236#endif
237
238
224#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) 239#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
225/* backlight fading */ 240/* backlight fading */
226#define BL_PWM_INTERVAL 5 /* Cycle interval in ms */ 241#define BL_PWM_INTERVAL 5 /* Cycle interval in ms */
@@ -397,6 +412,66 @@ void backlight_set_fade_out(int value)
397} 412}
398#endif /* defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) */ 413#endif /* defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) */
399 414
415#ifdef USE_BACKLIGHT_SW_FADING
416
417void backlight_set_fade_out(bool value)
418{
419 if(value) /* on */
420 backlight_fading_type |= FADING_DOWN;
421 else
422 backlight_fading_type &= FADING_UP;
423}
424
425void backlight_set_fade_in(bool value)
426{
427 if(value) /* on */
428 backlight_fading_type |= FADING_UP;
429 else
430 backlight_fading_type &= FADING_DOWN;
431}
432
433static void backlight_set_up_fade_up(void)
434{
435 if (backlight_fading_type & FADING_UP)
436 {
437 if (backlight_fading_state == NOT_FADING)
438 {
439 /* make sure the backlight is at lowest level */
440 _backlight_on();
441 }
442 backlight_fading_state = FADING_UP;
443 }
444 else
445 {
446 backlight_fading_state = NOT_FADING;
447 _backlight_fade_update_state(backlight_brightness);
448 _backlight_on();
449 _backlight_set_brightness(backlight_brightness);
450 }
451}
452
453static void backlight_set_up_fade_down(void)
454{
455 if (backlight_fading_type & FADING_DOWN)
456 {
457 backlight_fading_state = FADING_DOWN;
458 }
459 else
460 {
461 backlight_fading_state = NOT_FADING;
462 _backlight_fade_update_state(MIN_BRIGHTNESS_SETTING-1);
463 _backlight_off();
464 /* h300/x5/d2 go to the last known brightness level at backight_on(),which
465 * should be the lowest level to keep fading up glitch free
466 * sansa e200/c200 make the backlight on only by setting the brightness,
467 * so this step would be noticeable */
468#if !defined(SANSA_E200) && !defined(SANSA_C200)
469 _backlight_set_brightness(MIN_BRIGHTNESS_SETTING);
470#endif
471 }
472}
473#endif /* USE_BACKLIGHT_SW_FADING */
474
400/* Update state of backlight according to timeout setting */ 475/* Update state of backlight according to timeout setting */
401static void backlight_update_state(void) 476static void backlight_update_state(void)
402{ 477{
@@ -424,15 +499,25 @@ static void backlight_update_state(void)
424 backlight_timeout = backlight_timeout_normal; 499 backlight_timeout = backlight_timeout_normal;
425 500
426 /* Backlight == OFF in the setting? */ 501 /* Backlight == OFF in the setting? */
427 if (backlight_timeout < 0) 502 if (UNLIKELY(backlight_timeout < 0))
428 { 503 {
429 backlight_timer = 0; /* Disable the timeout */ 504 backlight_timer = 0; /* Disable the timeout */
505#ifdef USE_BACKLIGHT_SW_FADING
506 backlight_set_up_fade_down();
507 /* necessary step to issue fading down when the setting is selected */
508 queue_post(&backlight_queue, SYS_TIMEOUT, 0);
509#else
430 _backlight_off(); 510 _backlight_off();
511#endif
431 } 512 }
432 else 513 else
433 { 514 {
434 backlight_timer = backlight_timeout; 515 backlight_timer = backlight_timeout;
516#if defined(USE_BACKLIGHT_SW_FADING)
517 backlight_set_up_fade_up();
518#else
435 _backlight_on(); 519 _backlight_on();
520#endif
436 } 521 }
437} 522}
438 523
@@ -478,7 +563,15 @@ void backlight_thread(void)
478 563
479 while(1) 564 while(1)
480 { 565 {
481 queue_wait(&backlight_queue, &ev); 566#if defined(USE_BACKLIGHT_SW_FADING)
567 if (backlight_fading_state)
568 queue_wait_w_tmo(&backlight_queue, &ev, FADE_DELAY);
569 else
570#endif
571 queue_wait(&backlight_queue, &ev);
572/*
573#endif
574*/
482 switch(ev.id) 575 switch(ev.id)
483 { /* These events must always be processed */ 576 { /* These events must always be processed */
484#ifdef _BACKLIGHT_FADE_BOOST 577#ifdef _BACKLIGHT_FADE_BOOST
@@ -558,9 +651,12 @@ void backlight_thread(void)
558 651
559 case BACKLIGHT_OFF: 652 case BACKLIGHT_OFF:
560 backlight_timer = 0; /* Disable the timeout */ 653 backlight_timer = 0; /* Disable the timeout */
654#ifndef USE_BACKLIGHT_SW_FADING
561 _backlight_off(); 655 _backlight_off();
656#else
657 backlight_set_up_fade_down();
658#endif /* USE_BACKLIGHT_SW_FADING */
562 break; 659 break;
563
564#ifdef HAVE_LCD_SLEEP 660#ifdef HAVE_LCD_SLEEP
565 case LCD_SLEEP: 661 case LCD_SLEEP:
566 lcd_sleep(); 662 lcd_sleep();
@@ -589,6 +685,12 @@ void backlight_thread(void)
589 remote_backlight_update_state(); 685 remote_backlight_update_state();
590#endif 686#endif
591 break; 687 break;
688#if defined(USE_BACKLIGHT_SW_FADING)
689 case SYS_TIMEOUT:
690 if ((_backlight_fade_step(backlight_fading_state)))
691 backlight_fading_state = NOT_FADING;
692 break;
693#endif /* USE_BACKLIGHT_SW_FADING */
592 } 694 }
593 } /* end while */ 695 } /* end while */
594} 696}
@@ -597,8 +699,7 @@ static void backlight_tick(void)
597{ 699{
598 if(backlight_timer) 700 if(backlight_timer)
599 { 701 {
600 backlight_timer--; 702 if(--backlight_timer == 0)
601 if(backlight_timer == 0)
602 { 703 {
603 backlight_off(); 704 backlight_off();
604 } 705 }
@@ -606,20 +707,17 @@ static void backlight_tick(void)
606#ifdef HAVE_LCD_SLEEP 707#ifdef HAVE_LCD_SLEEP
607 else if(lcd_sleep_timer) 708 else if(lcd_sleep_timer)
608 { 709 {
609 lcd_sleep_timer--; 710 if(--lcd_sleep_timer == 0)
610 if(lcd_sleep_timer == 0)
611 { 711 {
612 /* Queue on bl thread or freeze! */ 712 /* Queue on bl thread or freeze! */
613 queue_post(&backlight_queue, LCD_SLEEP, 0); 713 queue_post(&backlight_queue, LCD_SLEEP, 0);
614 } 714 }
615 } 715 }
616#endif /* HAVE_LCD_SLEEP */ 716#endif /* HAVE_LCD_SLEEP */
617
618#ifdef HAVE_REMOTE_LCD 717#ifdef HAVE_REMOTE_LCD
619 if(remote_backlight_timer) 718 if(remote_backlight_timer)
620 { 719 {
621 remote_backlight_timer--; 720 if(--remote_backlight_timer == 0)
622 if(remote_backlight_timer == 0)
623 { 721 {
624 remote_backlight_off(); 722 remote_backlight_off();
625 } 723 }
@@ -628,8 +726,7 @@ static void backlight_tick(void)
628#ifdef HAVE_BUTTON_LIGHT 726#ifdef HAVE_BUTTON_LIGHT
629 if (buttonlight_timer) 727 if (buttonlight_timer)
630 { 728 {
631 buttonlight_timer--; 729 if (--buttonlight_timer == 0)
632 if (buttonlight_timer == 0)
633 { 730 {
634 buttonlight_off(); 731 buttonlight_off();
635 } 732 }
@@ -832,6 +929,11 @@ void backlight_set_brightness(int val)
832 val = MAX_BRIGHTNESS_SETTING; 929 val = MAX_BRIGHTNESS_SETTING;
833 930
834 _backlight_set_brightness(val); 931 _backlight_set_brightness(val);
932 backlight_brightness = val;
933#ifdef USE_BACKLIGHT_SW_FADING
934 /* receive backlight brightness */
935 _backlight_fade_update_state(val);
936#endif
835} 937}
836#endif /* HAVE_BACKLIGHT_BRIGHTNESS */ 938#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
837 939
diff --git a/firmware/export/backlight-thread-fading.h b/firmware/export/backlight-thread-fading.h
new file mode 100644
index 0000000000..ca9c195480
--- /dev/null
+++ b/firmware/export/backlight-thread-fading.h
@@ -0,0 +1,46 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id:$
9 *
10 * Copyright (C) 2007 by Will Robertson
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef BACKLIGHT_THREAD_FADING_H
23#define BACKLIGHT_THREAD_FADING_H
24
25#include "config.h"
26
27#ifdef USE_BACKLIGHT_SW_FADING
28
29/* delay supposed to be MAX_BRIGHTNESS_SETTING*2 rounded to the next multiple
30 * of 5, however not more than 40 */
31#define _FADE_DELAY (((MAX_BRIGHTNESS_SETTING*2+4)/5)*5)
32#define FADE_DELAY (HZ/(MIN(_FADE_DELAY, 40)))
33
34void _backlight_fade_update_state(int brightness);
35bool _backlight_fade_step(int direction);
36
37/* enum used for both, fading state and fading type selected through the settings */
38
39enum {
40 NOT_FADING = 0,
41 FADING_UP,
42 FADING_DOWN,
43};
44#endif /* USE_BACKLIGHT_SW_FADING */
45
46#endif /* _BACKLIGHT_THREAD_FADING_ */
diff --git a/firmware/export/backlight.h b/firmware/export/backlight.h
index e0980658dc..a177fe740f 100644
--- a/firmware/export/backlight.h
+++ b/firmware/export/backlight.h
@@ -34,10 +34,16 @@ void backlight_close(void);
34 34
35int backlight_get_current_timeout(void); 35int backlight_get_current_timeout(void);
36 36
37#ifdef HAVE_BACKLIGHT_PWM_FADING 37#if defined(HAVE_BACKLIGHT_PWM_FADING)
38void backlight_set_fade_in(int value); 38void backlight_set_fade_in(int value);
39void backlight_set_fade_out(int value); 39void backlight_set_fade_out(int value);
40#endif 40#endif
41#ifdef USE_BACKLIGHT_SW_FADING
42void backlight_set_fade_in(bool value);
43void backlight_set_fade_out(bool value);
44#endif
45
46extern int backlight_brightness;
41 47
42void backlight_set_timeout_plugged(int value); 48void backlight_set_timeout_plugged(int value);
43 49
diff --git a/firmware/export/config-c200.h b/firmware/export/config-c200.h
index a96b9c7ef8..8e26585e94 100644
--- a/firmware/export/config-c200.h
+++ b/firmware/export/config-c200.h
@@ -132,6 +132,10 @@
132/** Non-simulator section **/ 132/** Non-simulator section **/
133#ifndef SIMULATOR 133#ifndef SIMULATOR
134 134
135/* define this if the backlight thread is used for fade, not for sim, needs
136 * HAVE_BACKLIGHT_BRIGHTNESS */
137#define USE_BACKLIGHT_SW_FADING
138
135/* Define this if you have a PortalPlayer PP5024 */ 139/* Define this if you have a PortalPlayer PP5024 */
136#define CONFIG_CPU PP5022 140#define CONFIG_CPU PP5022
137 141
diff --git a/firmware/export/config-cowond2.h b/firmware/export/config-cowond2.h
index fd696aae66..b723201340 100644
--- a/firmware/export/config-cowond2.h
+++ b/firmware/export/config-cowond2.h
@@ -122,6 +122,10 @@
122 122
123#ifndef SIMULATOR 123#ifndef SIMULATOR
124 124
125/* define this if the backlight thread is used for fade, not for sim, needs
126 * HAVE_BACKLIGHT_BRIGHTNESS */
127#define USE_BACKLIGHT_SW_FADING
128
125/* Define this if you have a TCC7801 */ 129/* Define this if you have a TCC7801 */
126#define CONFIG_CPU TCC7801 130#define CONFIG_CPU TCC7801
127 131
diff --git a/firmware/export/config-e200.h b/firmware/export/config-e200.h
index 075f490ee4..d9bebef9bc 100644
--- a/firmware/export/config-e200.h
+++ b/firmware/export/config-e200.h
@@ -129,6 +129,10 @@
129/** Non-simulator section **/ 129/** Non-simulator section **/
130#ifndef SIMULATOR 130#ifndef SIMULATOR
131 131
132/* define this if the backlight thread is used for fade, not for sim, needs
133 * HAVE_BACKLIGHT_BRIGHTNESS */
134#define USE_BACKLIGHT_SW_FADING
135
132/* Define this if you have a PortalPlayer PP5024 */ 136/* Define this if you have a PortalPlayer PP5024 */
133#define CONFIG_CPU PP5024 137#define CONFIG_CPU PP5024
134 138
diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h
index f45b694fe0..2af426f048 100644
--- a/firmware/export/config-h300.h
+++ b/firmware/export/config-h300.h
@@ -114,6 +114,11 @@
114 114
115#ifndef SIMULATOR 115#ifndef SIMULATOR
116 116
117/* define this if the backlight thread is used for fade, not for sim, needs
118 * HAVE_BACKLIGHT_BRIGHTNESS */
119#define USE_BACKLIGHT_SW_FADING
120
121
117/* Define this if your LCD can be enabled/disabled */ 122/* Define this if your LCD can be enabled/disabled */
118#define HAVE_LCD_ENABLE 123#define HAVE_LCD_ENABLE
119 124
diff --git a/firmware/export/config-iaudiox5.h b/firmware/export/config-iaudiox5.h
index cdae55af4f..089d219534 100644
--- a/firmware/export/config-iaudiox5.h
+++ b/firmware/export/config-iaudiox5.h
@@ -124,6 +124,9 @@
124 124
125#ifndef SIMULATOR 125#ifndef SIMULATOR
126 126
127/* define this if the backlight thread is used for fade, not for sim */
128#define USE_BACKLIGHT_SW_FADING
129
127/* Define this if your LCD can set contrast */ 130/* Define this if your LCD can set contrast */
128#define HAVE_LCD_CONTRAST 131#define HAVE_LCD_CONTRAST
129 132
diff --git a/firmware/target/arm/sandisk/backlight-c200_e200.c b/firmware/target/arm/sandisk/backlight-c200_e200.c
index b3984ca9ad..67e0cddac9 100644
--- a/firmware/target/arm/sandisk/backlight-c200_e200.c
+++ b/firmware/target/arm/sandisk/backlight-c200_e200.c
@@ -26,16 +26,9 @@
26#include "ascodec.h" 26#include "ascodec.h"
27#include "as3514.h" 27#include "as3514.h"
28 28
29static unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING;
30
31void _backlight_set_brightness(int brightness) 29void _backlight_set_brightness(int brightness)
32{ 30{
33 backlight_brightness = brightness; 31 ascodec_write(AS3514_DCDC15, brightness);
34
35 if (brightness > 0)
36 _backlight_on();
37 else
38 _backlight_off();
39} 32}
40 33
41void _backlight_on(void) 34void _backlight_on(void)
@@ -46,7 +39,10 @@ void _backlight_on(void)
46#ifdef HAVE_LCD_ENABLE 39#ifdef HAVE_LCD_ENABLE
47 lcd_enable(true); /* power on lcd + visible display */ 40 lcd_enable(true); /* power on lcd + visible display */
48#endif 41#endif
49 ascodec_write(AS3514_DCDC15, backlight_brightness); 42#ifndef USE_BACKLIGHT_SW_FADING
43 /* that part ain't useful when fading */
44 _backlight_set_brightness(backlight_brightness);
45#endif
50} 46}
51 47
52void _backlight_off(void) 48void _backlight_off(void)
diff --git a/firmware/target/arm/sandisk/backlight-target.h b/firmware/target/arm/sandisk/backlight-target.h
index 21fad6d22e..1f5e475a42 100644
--- a/firmware/target/arm/sandisk/backlight-target.h
+++ b/firmware/target/arm/sandisk/backlight-target.h
@@ -25,7 +25,6 @@
25void _backlight_on(void); 25void _backlight_on(void);
26void _backlight_off(void); 26void _backlight_off(void);
27void _backlight_set_brightness(int brightness); 27void _backlight_set_brightness(int brightness);
28int __backlight_is_on(void);
29 28
30void _buttonlight_on(void); 29void _buttonlight_on(void);
31void _buttonlight_off(void); 30void _buttonlight_off(void);
diff --git a/firmware/target/arm/tcc780x/cowond2/backlight-cowond2.c b/firmware/target/arm/tcc780x/cowond2/backlight-cowond2.c
index 6d286aee8f..39a9abf073 100644
--- a/firmware/target/arm/tcc780x/cowond2/backlight-cowond2.c
+++ b/firmware/target/arm/tcc780x/cowond2/backlight-cowond2.c
@@ -24,27 +24,20 @@
24#include "pcf50606.h" 24#include "pcf50606.h"
25#include "tcc780x.h" 25#include "tcc780x.h"
26 26
27static unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING;
28
29int _backlight_init(void) 27int _backlight_init(void)
30{ 28{
31 _backlight_set_brightness(DEFAULT_BRIGHTNESS_SETTING); 29 _backlight_set_brightness(DEFAULT_BRIGHTNESS_SETTING);
30 /* set backlight on by default, since the screen is unreadable without it */
31 _backlight_on();
32 return true; 32 return true;
33} 33}
34 34
35void _backlight_set_brightness(int brightness) 35void _backlight_set_brightness(int brightness)
36{ 36{
37 backlight_brightness = brightness;
38
39 int level = disable_irq_save(); 37 int level = disable_irq_save();
40 pcf50606_write(PCF5060X_PWMC1, 0xe1 | (14-backlight_brightness)<<1); 38 pcf50606_write(PCF5060X_PWMC1, 0xe1 | (MAX_BRIGHTNESS_SETTING-brightness)<<1);
41 pcf50606_write(PCF5060X_GPOC1, 0x3); 39 pcf50606_write(PCF5060X_GPOC1, 0x3);
42 restore_irq(level); 40 restore_irq(level);
43
44 if (brightness > 0)
45 _backlight_on();
46 else
47 _backlight_off();
48} 41}
49 42
50void _backlight_on(void) 43void _backlight_on(void)