1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
Index: apps/settings.c
===================================================================
--- apps/settings.c  (Revision 19818)
+++ apps/settings.c  (Arbeitskopie)
@@ -773,9 +773,8 @@
 #if CONFIG_CHARGING
     backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
 #endif
-#if (defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)) \
-        || defined(USE_BACKLIGHT_SW_FADING) \
-        || defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
+#if    defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
+    || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
     backlight_set_fade_in(global_settings.backlight_fade_in);
     backlight_set_fade_out(global_settings.backlight_fade_out);
 #endif
Index: apps/settings.h
===================================================================
--- apps/settings.h  (Revision 19818)
+++ apps/settings.h  (Arbeitskopie)
@@ -681,11 +681,10 @@
     int lcd_sleep_after_backlight_off; /* when to put lcd to sleep after backlight
                                           has turned off */
 #endif
-#if defined(HAVE_BACKLIGHT_PWM_FADING)
+#if defined(HAVE_BACKLIGHT_FADING_INT_SETTING)
     int backlight_fade_in;  /* backlight fade in timing: 0..3 */
     int backlight_fade_out; /* backlight fade in timing: 0..7 */
-#elif defined(USE_BACKLIGHT_SW_FADING) \
-    || defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
+#elif defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
     bool backlight_fade_in;
     bool backlight_fade_out;
 #endif
Index: apps/menus/display_menu.c
===================================================================
--- apps/menus/display_menu.c  (Revision 19818)
+++ apps/menus/display_menu.c  (Arbeitskopie)
@@ -91,9 +91,8 @@
                 &global_settings.backlight_on_button_hold, NULL);
 #endif
 MENUITEM_SETTING(caption_backlight, &global_settings.caption_backlight, NULL);
-#if (defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)) || \
-        defined(USE_BACKLIGHT_SW_FADING) || \
-        defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
+#if    defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
+    || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
 MENUITEM_SETTING(backlight_fade_in, &global_settings.backlight_fade_in, NULL);
 MENUITEM_SETTING(backlight_fade_out, &global_settings.backlight_fade_out, NULL);
 #endif
@@ -132,9 +131,8 @@
             ,&backlight_on_button_hold
 # endif
             ,&caption_backlight
-#if (defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)) || \
-        defined(USE_BACKLIGHT_SW_FADING) || \
-        defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
+#if    defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
+    || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
             ,&backlight_fade_in, &backlight_fade_out
 #endif
             ,&bl_filter_first_keypress
Index: apps/settings_list.c
===================================================================
--- apps/settings_list.c  (Revision 19818)
+++ apps/settings_list.c  (Arbeitskopie)
@@ -671,15 +671,14 @@
     OFFON_SETTING(0, remote_caption_backlight, LANG_CAPTION_BACKLIGHT,
                   false, "remote caption backlight", NULL),
 #endif
-#endif /* HAVE_BACKLIGHT */
 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
     INT_SETTING(F_NO_WRAP, brightness, LANG_BRIGHTNESS,
                 DEFAULT_BRIGHTNESS_SETTING, "brightness",UNIT_INT,
                 MIN_BRIGHTNESS_SETTING, MAX_BRIGHTNESS_SETTING, 1,
                 NULL, NULL, backlight_set_brightness),
 #endif
-#if defined(HAVE_BACKLIGHT_PWM_FADING)  && !defined(SIMULATOR)
     /* backlight fading */
+#if defined(HAVE_BACKLIGHT_FADING_INT_SETTING)
     TABLE_SETTING(F_ALLOW_ARBITRARY_VALS, backlight_fade_in,
                   LANG_BACKLIGHT_FADE_IN, 300, "backlight fade in", "off",
                   UNIT_MS, formatter_unit_0_is_off, getlang_unit_0_is_off,
@@ -689,13 +688,13 @@
                   UNIT_MS, formatter_unit_0_is_off, getlang_unit_0_is_off,
                   backlight_set_fade_out, 10,
                   0,100,200,300,500,1000,2000,3000,5000,10000),
-#elif defined(USE_BACKLIGHT_SW_FADING) \
-    || defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
+#elif defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
     OFFON_SETTING(0, backlight_fade_in, LANG_BACKLIGHT_FADE_IN,
                     true, "backlight fade in", backlight_set_fade_in),
     OFFON_SETTING(0, backlight_fade_out, LANG_BACKLIGHT_FADE_OUT,
                     true, "backlight fade out", backlight_set_fade_out),
 #endif
+#endif /* HAVE_BACKLIGHT */
     INT_SETTING(F_PADTITLE, scroll_speed, LANG_SCROLL_SPEED, 9,"scroll speed",
                 UNIT_INT, 0, 15, 1, NULL, NULL, lcd_scroll_speed),
     INT_SETTING(F_PADTITLE, scroll_delay, LANG_SCROLL_DELAY, 1000,
Index: apps/features.txt
===================================================================
--- apps/features.txt  (Revision 19818)
+++ apps/features.txt  (Arbeitskopie)
@@ -20,12 +20,10 @@
 backlight_brightness
 #endif

-#if defined(HAVE_BACKLIGHT_PWM_FADING)
-backlight_fade_pwm
-#elif defined(USE_BACKLIGHT_SW_FADING)
-backlight_fade_sw
-#elif defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
-backlight_fade_custom_bool
+#if defined(HAVE_BACKLIGHT_FADING_INT_SETTING)
+backlight_fade_int
+#elif defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
+backlight_fade_bool
 #endif

 #if BATTERY_TYPES_COUNT > 1
Index: apps/apps.make
===================================================================
--- apps/apps.make  (Revision 19818)
+++ apps/apps.make  (Arbeitskopie)
@@ -19,7 +19,8 @@
   $(SILENT)mkdir -p $(BUILDDIR)/apps
   $(call PRINTS,PP $(<F))
   $(SILENT)$(CC) $(PPCFLAGS) \
-                 -E -P -imacros "config.h" -imacros "button.h" -x c $< | \
+                 -E -P -imacros "config.h" -imacros "backlight.h" \
+         -imacros "button.h" -x c $< | \
     grep -v "^\#" | grep -v "^$$" > $(BUILDDIR)/apps/features; \
     for f in `cat $(BUILDDIR)/apps/features`; do feat="$$feat:$$f" ; done ; \
     echo "$$feat" >$(BUILDDIR)/apps/genlang-features
Index: firmware/export/config-c200.h
===================================================================
--- firmware/export/config-c200.h  (Revision 19818)
+++ firmware/export/config-c200.h  (Arbeitskopie)
@@ -111,6 +111,14 @@
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS

+/* Main LCD backlight brightness range and defaults */
+#define MIN_BRIGHTNESS_SETTING      1
+#define MAX_BRIGHTNESS_SETTING     12
+#define DEFAULT_BRIGHTNESS_SETTING  6
+
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
+
 /* define this if you have a flash memory storage */
 #define HAVE_FLASH_STORAGE

@@ -138,12 +146,6 @@
 /** Non-simulator section **/
 #ifndef SIMULATOR

-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if you have a PortalPlayer PP5024 */
 #define CONFIG_CPU PP5022

@@ -203,13 +205,6 @@

 #endif /* SIMULATOR */

-/** Port-specific settings **/
-
-/* Main LCD backlight brightness range and defaults */
-#define MIN_BRIGHTNESS_SETTING      1
-#define MAX_BRIGHTNESS_SETTING     12
-#define DEFAULT_BRIGHTNESS_SETTING  6
-
 /* Default recording levels */
 #define DEFAULT_REC_MIC_GAIN    23
 #define DEFAULT_REC_LEFT_GAIN   23
Index: firmware/export/config-fuze.h
===================================================================
--- firmware/export/config-fuze.h  (Revision 19818)
+++ firmware/export/config-fuze.h  (Arbeitskopie)
@@ -106,6 +106,14 @@
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS

+/* Main LCD backlight brightness range and defaults */
+#define MIN_BRIGHTNESS_SETTING      1
+#define MAX_BRIGHTNESS_SETTING     12
+#define DEFAULT_BRIGHTNESS_SETTING  6
+
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
+
 /* define this if the unit uses a scrollwheel for navigation */
 #define HAVE_SCROLLWHEEL
 /* define from which rotation speed [degree/sec] on the acceleration starts */
@@ -134,12 +142,6 @@
 /** Non-simulator section **/
 #ifndef SIMULATOR

-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if you have an AMS AS3525*/
 #define CONFIG_CPU AS3525

@@ -195,13 +197,6 @@

 #endif /* SIMULATOR */

-/** Port-specific settings **/
-
-/* Main LCD backlight brightness range and defaults */
-#define MIN_BRIGHTNESS_SETTING      1
-#define MAX_BRIGHTNESS_SETTING     12
-#define DEFAULT_BRIGHTNESS_SETTING  6
-
 /* Default recording levels */
 #define DEFAULT_REC_MIC_GAIN    23
 #define DEFAULT_REC_LEFT_GAIN   23
Index: firmware/export/config-e200v2.h
===================================================================
--- firmware/export/config-e200v2.h  (Revision 19818)
+++ firmware/export/config-e200v2.h  (Arbeitskopie)
@@ -106,6 +106,14 @@
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS

+/* Main LCD backlight brightness range and defaults */
+#define MIN_BRIGHTNESS_SETTING      1
+#define MAX_BRIGHTNESS_SETTING     12
+#define DEFAULT_BRIGHTNESS_SETTING  6
+
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
+
 /* define this if the unit uses a scrollwheel for navigation */
 #define HAVE_SCROLLWHEEL
 /* define from which rotation speed [degree/sec] on the acceleration starts */
@@ -134,12 +142,6 @@
 /** Non-simulator section **/
 #ifndef SIMULATOR

-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if you have an AMS AS3525*/
 #define CONFIG_CPU AS3525

@@ -195,13 +197,6 @@

 #endif /* SIMULATOR */

-/** Port-specific settings **/
-
-/* Main LCD backlight brightness range and defaults */
-#define MIN_BRIGHTNESS_SETTING      1
-#define MAX_BRIGHTNESS_SETTING     12
-#define DEFAULT_BRIGHTNESS_SETTING  6
-
 /* Default recording levels */
 #define DEFAULT_REC_MIC_GAIN    23
 #define DEFAULT_REC_LEFT_GAIN   23
Index: firmware/export/config-mrobe100.h
===================================================================
--- firmware/export/config-mrobe100.h  (Revision 19818)
+++ firmware/export/config-mrobe100.h  (Arbeitskopie)
@@ -70,7 +70,7 @@
 #define HAVE_BACKLIGHT

 /* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM

 /* Main LCD backlight brightness range and defaults */
 #define MIN_BRIGHTNESS_SETTING      1
Index: firmware/export/config-e200.h
===================================================================
--- firmware/export/config-e200.h  (Revision 19818)
+++ firmware/export/config-e200.h  (Arbeitskopie)
@@ -101,6 +101,9 @@
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS

+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
+
 /* define this if the unit uses a scrollwheel for navigation */
 #define HAVE_SCROLLWHEEL
 /* define from which rotation speed [degree/sec] on the acceleration starts */
@@ -135,12 +138,6 @@
 /** Non-simulator section **/
 #ifndef SIMULATOR

-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if you have a PortalPlayer PP5024 */
 #define CONFIG_CPU PP5024

Index: firmware/export/config-ipodvideo.h
===================================================================
--- firmware/export/config-ipodvideo.h  (Revision 19818)
+++ firmware/export/config-ipodvideo.h  (Arbeitskopie)
@@ -86,13 +86,14 @@
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS

+/* We can fade the backlight by using PWM */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM
+
 /* Main LCD backlight brightness range and defaults */
 #define MIN_BRIGHTNESS_SETTING      1
 #define MAX_BRIGHTNESS_SETTING      32
 #define DEFAULT_BRIGHTNESS_SETTING  16

-/* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING

 /* define this if the unit uses a scrollwheel for navigation */
 #define HAVE_SCROLLWHEEL
Index: firmware/export/backlight.h
===================================================================
--- firmware/export/backlight.h  (Revision 19818)
+++ firmware/export/backlight.h  (Arbeitskopie)
@@ -23,6 +23,27 @@

 #include "config.h"

+#if !defined(SIMULATOR) && !defined(BOOTLOADER)
+
+/* decide which setting to use in, possibly overridden in target config */
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
+
+#ifndef HAVE_BACKLIGHT_FADING_INT_SETTING
+#define HAVE_BACKLIGHT_FADING_INT_SETTING
+#endif
+
+#elif  (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_TARGET)
+#ifndef HAVE_BACKLIGHT_FADING_BOOL_SETTING
+#define HAVE_BACKLIGHT_FADING_BOOL_SETTING
+#endif
+#endif
+
+#endif
+
+
+
 bool is_backlight_on(bool ignore_always_off);
 void backlight_on(void);
 void backlight_off(void);
@@ -34,12 +55,10 @@

 int  backlight_get_current_timeout(void);

-#if defined(HAVE_BACKLIGHT_PWM_FADING)
+#if defined(HAVE_BACKLIGHT_FADING_INT_SETTING)
 void backlight_set_fade_in(int value);
 void backlight_set_fade_out(int value);
-#endif
-#if defined(USE_BACKLIGHT_SW_FADING) \
-    || defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
+#elif defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
 void backlight_set_fade_in(bool value);
 void backlight_set_fade_out(bool value);
 #endif
Index: firmware/export/config-ipodmini.h
===================================================================
--- firmware/export/config-ipodmini.h  (Revision 19818)
+++ firmware/export/config-ipodmini.h  (Arbeitskopie)
@@ -101,7 +101,7 @@
 #define HAVE_BACKLIGHT

 /* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM

 /* Define this if you can detect headphones */
 #define HAVE_HEADPHONE_DETECTION
Index: firmware/export/config-h120.h
===================================================================
--- firmware/export/config-h120.h  (Revision 19818)
+++ firmware/export/config-h120.h  (Arbeitskopie)
@@ -69,7 +69,7 @@
 #define HAVE_BACKLIGHT

 /* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM

 /* Define this if you have a software controlled poweroff */
 #define HAVE_SW_POWEROFF
Index: firmware/export/config-c200v2.h
===================================================================
--- firmware/export/config-c200v2.h  (Revision 19818)
+++ firmware/export/config-c200v2.h  (Arbeitskopie)
@@ -136,12 +136,6 @@
 /** Non-simulator section **/
 #ifndef SIMULATOR

-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if you have a PortalPlayer PP5024 */
 #define CONFIG_CPU AS3525

Index: firmware/export/config-ipodmini2g.h
===================================================================
--- firmware/export/config-ipodmini2g.h  (Revision 19818)
+++ firmware/export/config-ipodmini2g.h  (Arbeitskopie)
@@ -101,7 +101,7 @@
 #define HAVE_BACKLIGHT

 /* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM

 /* define this if the unit uses a scrollwheel for navigation */
 #define HAVE_SCROLLWHEEL
Index: firmware/export/config.h
===================================================================
--- firmware/export/config.h  (Revision 19818)
+++ firmware/export/config.h  (Arbeitskopie)
@@ -113,6 +113,24 @@
 #define H300_REMOTE 2
 #define X5_REMOTE   3

+/* CONFIG_BACKLIGHT_FADING */
+/* No fading capabilities at all (yet) */
+#define BACKLIGHT_NO_FADING         0x0
+/* Backlight fading is controlled using a hardware PWM mechanism */
+#define BACKLIGHT_FADING_PWM        0x1
+/* Backlight is controlled using a software implementation
+ * BACKLIGHT_FADING_SW_SETTING means that backlight is turned on by only setting
+ * the brightness (i.e. no real difference between backlight_on and
+ * backlight_set_brightness)
+ * BACKLIGHT_FADING_SW_SETTING means that backlight brightness is restored
+ * "in hardware", from a hardware register upon backlight_on
+ * Both types need to have minor adjustments in the software fading code */
+#define BACKLIGHT_FADING_SW_SETTING 0x2
+#define BACKLIGHT_FADING_SW_HW_REG  0x4
+/* Backlight fading is done in a target specific way
+ * for example in hardware, but not controllable*/
+#define BACKLIGHT_FADING_TARGET     0x8
+
 /* CONFIG_CHARGING */

 /* Generic types */
@@ -347,6 +365,20 @@
 /* setup basic macros from capability masks */
 #include "config_caps.h"

+/* some backlight fading specific defines */
+/* Neither backlight fade algorithm to be used on the sim or bootloader */
+
+#if defined(BOOTLOADER) || defined(SIMULATOR)
+#if defined(CONFIG_BACKLIGHT_FADING)
+#undef CONFIG_BACKLIGHT_FADING
+#endif
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_NO_FADING
+#endif
+
+#if !defined(CONFIG_BACKLIGHT_FADING)
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_NO_FADING /* 0 */
+#endif
+
 /* now set any CONFIG_ defines correctly if they are not used,
    No need to do this on CONFIG_'s which are compulsary (e.g CONFIG_CODEC ) */
 #ifndef CONFIG_TUNER
Index: firmware/export/config-ipodnano.h
===================================================================
--- firmware/export/config-ipodnano.h  (Revision 19818)
+++ firmware/export/config-ipodnano.h  (Arbeitskopie)
@@ -81,15 +81,14 @@
 /* Define this for LCD backlight available */
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS
+/* We can fade the backlight by using PWM */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM
 
 /* Main LCD backlight brightness range and defaults */
 #define MIN_BRIGHTNESS_SETTING      1
 #define MAX_BRIGHTNESS_SETTING      32
 #define DEFAULT_BRIGHTNESS_SETTING  16
 
-/* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING
-
 /* define this if the unit uses a scrollwheel for navigation */
 #define HAVE_SCROLLWHEEL
 /* define from which rotation speed [degree/sec] on the acceleration starts */
Index: firmware/export/config-sa9200.h
===================================================================
--- firmware/export/config-sa9200.h  (Revision 19818)
+++ firmware/export/config-sa9200.h  (Arbeitskopie)
@@ -90,6 +90,9 @@
 #define MAX_BRIGHTNESS_SETTING     12
 #define DEFAULT_BRIGHTNESS_SETTING  6
 
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
+
 /* define this if you have a flash memory storage */
 #define HAVE_FLASH_STORAGE
 
Index: firmware/export/config-h100.h
===================================================================
--- firmware/export/config-h100.h  (Revision 19818)
+++ firmware/export/config-h100.h  (Arbeitskopie)
@@ -74,7 +74,7 @@
 #define HAVE_BACKLIGHT
 
 /* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM
 
 /* Define this if you have a software controlled poweroff */
 #define HAVE_SW_POWEROFF
Index: firmware/export/config-h300.h
===================================================================
--- firmware/export/config-h300.h  (Revision 19818)
+++ firmware/export/config-h300.h  (Arbeitskopie)
@@ -68,6 +68,8 @@
 /* Define this for LCD backlight available */
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_HW_REG
 
 /* Define this if you have a software controlled poweroff */
 #define HAVE_SW_POWEROFF
@@ -125,12 +127,6 @@
 
 #ifndef SIMULATOR
 
-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if your LCD can be enabled/disabled */
 #define HAVE_LCD_ENABLE
 
Index: firmware/export/config-iaudiox5.h
===================================================================
--- firmware/export/config-iaudiox5.h  (Revision 19818)
+++ firmware/export/config-iaudiox5.h  (Arbeitskopie)
@@ -90,6 +90,8 @@
 /* Define this for LCD backlight available */
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_HW_REG
 
 /* define this if you have a disk storage, i.e. something
    that needs spinups and can cause skips when shaked */
@@ -127,12 +129,6 @@
 
 #ifndef SIMULATOR
 
-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if your LCD can set contrast */
 #define HAVE_LCD_CONTRAST
 
Index: firmware/export/backlight-sw-fading.h
===================================================================
--- firmware/export/backlight-sw-fading.h  (Revision 19818)
+++ firmware/export/backlight-sw-fading.h  (Arbeitskopie)
@@ -22,10 +22,6 @@
 #ifndef BACKLIGHT_THREAD_FADING_H
 #define BACKLIGHT_THREAD_FADING_H
 
-#include "config.h"
-
-#ifdef USE_BACKLIGHT_SW_FADING
-
 /* delay supposed to be MAX_BRIGHTNESS_SETTING*2 rounded to the next multiple
  * of 5, however not more than 40 */
 #define _FADE_DELAY (((MAX_BRIGHTNESS_SETTING*2+4)/5)*5)
@@ -41,6 +37,5 @@
     FADING_UP,
     FADING_DOWN,
 };
-#endif /* USE_BACKLIGHT_SW_FADING */
 
 #endif /* _BACKLIGHT_THREAD_FADING_ */
Index: firmware/export/config-gigabeat-s.h
===================================================================
--- firmware/export/config-gigabeat-s.h  (Revision 19818)
+++ firmware/export/config-gigabeat-s.h  (Arbeitskopie)
@@ -117,15 +117,14 @@
 #define MAX_BRIGHTNESS_SETTING          24
 #define DEFAULT_BRIGHTNESS_SETTING      12
 
+/* Implementation-defined fading type with bool settings */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_TARGET
 
 #define HAVE_HEADPHONE_DETECTION
 #endif /* BOOTLOADER */
 
 #ifndef SIMULATOR
 
-/* Implementation-defined fading type with bool settings */
-#define USE_BACKLIGHT_CUSTOM_FADING_BOOL
-
 /* The LCD on a Gigabeat is 240x320 - it is portrait */
 #define HAVE_PORTRAIT_LCD
 
Index: firmware/export/config-cowond2.h
===================================================================
--- firmware/export/config-cowond2.h  (Revision 19818)
+++ firmware/export/config-cowond2.h  (Arbeitskopie)
@@ -108,9 +108,10 @@
 
 /* Define this for LCD backlight available */
 #define HAVE_BACKLIGHT
-
 /* Enable LCD brightness control */
 #define HAVE_BACKLIGHT_BRIGHTNESS
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_HW_REG
 
 /* Main LCD backlight brightness range and defaults */
 #define MIN_BRIGHTNESS_SETTING      1
@@ -129,13 +130,6 @@
 #define CONFIG_CHARGING CHARGING_SIMPLE
 
 #ifndef SIMULATOR
-
-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if you have a TCC7801 */
 #define CONFIG_CPU TCC7801
 
Index: firmware/backlight-sw-fading.c
===================================================================
--- firmware/backlight-sw-fading.c  (Revision 19818)
+++ firmware/backlight-sw-fading.c  (Arbeitskopie)
@@ -30,7 +30,7 @@
 /* To adapt a target do:
  * - make sure _backlight_on doesn't set the brightness to something other than
  *  the previous value (lowest brightness in most cases)
- * - #define USE_BACKLIGHT_SW_FADING in config-<target>.h
+ * add proper #defines for software fading
  */

 /* can be MIN_BRIGHTNESS_SETTING-1 */
Index: firmware/backlight.c
===================================================================
--- firmware/backlight.c  (Revision 19818)
+++ firmware/backlight.c  (Arbeitskopie)
@@ -52,7 +52,8 @@
 int backlight_brightness = DEFAULT_BRIGHTNESS_SETTING;
 #endif

-#ifdef USE_BACKLIGHT_SW_FADING
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
 #include "backlight-sw-fading.h"
 #endif
 #ifdef SIMULATOR
@@ -230,14 +231,15 @@
 }
 #endif /* HAVE_LCD_SLEEP */

-#ifdef USE_BACKLIGHT_SW_FADING
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
 static int backlight_fading_type = (FADING_UP|FADING_DOWN);
 static int backlight_fading_state = NOT_FADING;
 #endif


-#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
 /* backlight fading */
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
 #define BL_PWM_INTERVAL 5  /* Cycle interval in ms */
 #define BL_PWM_BITS     8
 #define BL_PWM_COUNT    (1<<BL_PWM_BITS)
@@ -410,9 +412,9 @@
     else
         bl_fade_out_step = 0;
 }
-#endif /* defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) */

-#ifdef USE_BACKLIGHT_SW_FADING
+#elif  (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)

 void backlight_set_fade_out(bool value)
 {
@@ -430,7 +432,7 @@
         backlight_fading_type &= FADING_DOWN;
 }

-static void backlight_set_up_fade_up(void)
+static void backlight_setup_fade_up(void)
 {
     if (backlight_fading_type & FADING_UP)
     {
@@ -450,7 +452,7 @@
     }
 }

-static void backlight_set_up_fade_down(void)
+static void backlight_setup_fade_down(void)
 {
     if (backlight_fading_type & FADING_DOWN)
     {
@@ -461,16 +463,14 @@
         backlight_fading_state = NOT_FADING;
         _backlight_fade_update_state(MIN_BRIGHTNESS_SETTING-1);
         _backlight_off();
-    /* h300/x5/d2 go to the last known brightness level at backight_on(),which
-     * should be the lowest level to keep fading up glitch free
-     * targets which set brightness over AS3514 I2C make the backlight on only
-     * by setting the brightness, so this step would be noticeable */
-#if !defined(HAVE_AS3514)
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
+        /* write the lowest brightness level to the hardware so that
+         * fading up is glitch free */
         _backlight_set_brightness(MIN_BRIGHTNESS_SETTING);
 #endif
     }
 }
-#endif /* USE_BACKLIGHT_SW_FADING */
+#endif /* CONFIG_BACKLIGHT_FADING */

 /* Update state of backlight according to timeout setting */
 static void backlight_update_state(void)
@@ -498,8 +498,9 @@
     if (UNLIKELY(backlight_timeout < 0))
     {
         backlight_timer = 0; /* Disable the timeout */
-#ifdef USE_BACKLIGHT_SW_FADING
-        backlight_set_up_fade_down();
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
+        backlight_setup_fade_down();
         /* necessary step to issue fading down when the setting is selected */
         queue_post(&backlight_queue, SYS_TIMEOUT, 0);
 #else
@@ -509,8 +510,9 @@
     else
     {
         backlight_timer = backlight_timeout;
-#if defined(USE_BACKLIGHT_SW_FADING)
-        backlight_set_up_fade_up();
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
+        backlight_setup_fade_up();
 #else
         _backlight_on();
 #endif
@@ -555,15 +557,13 @@

     while(1)
     {
-#if defined(USE_BACKLIGHT_SW_FADING)
+#if  (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
         if (backlight_fading_state)
             queue_wait_w_tmo(&backlight_queue, &ev, FADE_DELAY);
         else
 #endif
             queue_wait(&backlight_queue, &ev);
-/*
-#endif
-*/
         switch(ev.id)
         {   /* These events must always be processed */
 #ifdef _BACKLIGHT_FADE_BOOST
@@ -643,11 +643,12 @@

             case BACKLIGHT_OFF:
                 backlight_timer = 0; /* Disable the timeout */
-#ifndef USE_BACKLIGHT_SW_FADING
+#if  (CONFIG_BACKLIGHT_FADING != BACKLIGHT_FADING_SW_SETTING) \
+    && (CONFIG_BACKLIGHT_FADING != BACKLIGHT_FADING_SW_HW_REG)
                 _backlight_off();
 #else
-                backlight_set_up_fade_down();
-#endif /* USE_BACKLIGHT_SW_FADING */
+                backlight_setup_fade_down();
+#endif /* CONFIG_BACKLIGHT_FADING */
                 break;
 #ifdef HAVE_LCD_SLEEP
             case LCD_SLEEP:
@@ -677,12 +678,13 @@
                 remote_backlight_update_state();
 #endif
                 break;
-#if defined(USE_BACKLIGHT_SW_FADING)
+#if  (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
             case SYS_TIMEOUT:
                 if ((_backlight_fade_step(backlight_fading_state)))
-                    backlight_fading_state = NOT_FADING;
+                    backlight_fading_state = NOT_FADING; /* finished fading */
                 break;
-#endif /* USE_BACKLIGHT_SW_FADING */
+#endif /* CONFIG_BACKLIGHT_FADING */
         }
     } /* end while */
 }
@@ -733,11 +735,11 @@
 #ifndef SIMULATOR
     if (_backlight_init())
     {
-# ifdef HAVE_BACKLIGHT_PWM_FADING
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
         /* If backlight is already on, don't fade in. */
         bl_dim_target = BL_PWM_COUNT;
         bl_dim_fraction = (BL_PWM_COUNT<<16);
-# endif
+#endif
     }
 #endif
     /* Leave all lights as set by the bootloader here. The settings load will
@@ -922,7 +924,8 @@
 
     backlight_brightness = val;
     _backlight_set_brightness(val);
-#ifdef USE_BACKLIGHT_SW_FADING
+#if  (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
     /* receive backlight brightness */
     _backlight_fade_update_state(val);
 #endif
Index: firmware/SOURCES
===================================================================
--- firmware/SOURCES  (Revision 19818)
+++ firmware/SOURCES  (Arbeitskopie)
@@ -96,9 +96,10 @@
 #endif /* LCD_REMOTE_DEPTH */
 #endif /* HAVE_REMOTE_LCD */
 
-#ifdef USE_BACKLIGHT_SW_FADING
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
 backlight-sw-fading.c
-#endif /* USE_BACKLIGHT_SW_FADING */
+#endif /* CONFIG_BACKLIGHT_FADING */
 
 /* Misc. */
 drivers/led.c
Index: firmware/target/arm/as3525/backlight-e200v2-fuze.c
===================================================================
--- firmware/target/arm/as3525/backlight-e200v2-fuze.c  (Revision 19818)
+++ firmware/target/arm/as3525/backlight-e200v2-fuze.c  (Arbeitskopie)
@@ -39,7 +39,9 @@
 #ifdef HAVE_LCD_ENABLE
     lcd_enable(true); /* power on lcd + visible display */
 #endif
-#ifndef USE_BACKLIGHT_SW_FADING
+#if (CONFIG_BACKLIGHT_FADING != BACKLIGHT_FADING_SW_SETTING) /* in bootloader/sim */
+    /* if we set the brightness to the settings value, then fading up
+     * is glitchy */
     ascodec_write(AS3514_DCDC15, backlight_brightness);
 #endif
 }
Index: firmware/target/arm/ipod/backlight-target.h
===================================================================
--- firmware/target/arm/ipod/backlight-target.h  (Revision 19818)
+++ firmware/target/arm/ipod/backlight-target.h  (Arbeitskopie)
@@ -50,7 +50,8 @@
 void _backlight_on(void);
 void _backlight_off(void);
 
-#elif defined HAVE_BACKLIGHT_PWM_FADING  /* Mini G1, G2 */
+/* Mini G1, G2, Video, Nano */
+#elif (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM) 
 
 #define _backlight_init() true
 void _backlight_hw_on(void);
Index: firmware/target/arm/sandisk/backlight-c200_e200.c
===================================================================
--- firmware/target/arm/sandisk/backlight-c200_e200.c  (Revision 19818)
+++ firmware/target/arm/sandisk/backlight-c200_e200.c  (Arbeitskopie)
@@ -39,15 +39,16 @@
 #ifdef HAVE_LCD_ENABLE
     lcd_enable(true); /* power on lcd + visible display */
 #endif
-#ifndef USE_BACKLIGHT_SW_FADING
-    /* that part ain't useful when fading */
+#if (CONFIG_BACKLIGHT_FADING != BACKLIGHT_FADING_SW_SETTING) /* in bootloader/sim */
+    /* if we set the brightness to the settings value, then fading up
+     * is glitchy */
     _backlight_set_brightness(backlight_brightness);
 #endif
 }

 void _backlight_off(void)
 {
-    ascodec_write(AS3514_DCDC15, 0x0);
+    _backlight_set_brightness(0);
 #ifdef HAVE_LCD_ENABLE
     lcd_enable(false); /* power off visible display */
 #endif
Index: firmware/target/arm/philips/sa9200/backlight-sa9200.c
===================================================================
--- firmware/target/arm/philips/sa9200/backlight-sa9200.c  (Revision 19818)
+++ firmware/target/arm/philips/sa9200/backlight-sa9200.c  (Arbeitskopie)
@@ -39,15 +39,16 @@
 #ifdef HAVE_LCD_ENABLE
     lcd_enable(true); /* power on lcd + visible display */
 #endif
-#ifndef USE_BACKLIGHT_SW_FADING
-    /* that part ain't useful when fading */
+#if (CONFIG_BACKLIGHT_FADING != BACKLIGHT_FADING_SW_SETTING) /* in bootloader/sim */
+    /* if we set the brightness to the settings value, then fading up
+     * is glitchy */
     _backlight_set_brightness(backlight_brightness);
 #endif
 }
 
 void _backlight_off(void)
 {
-    ascodec_write(AS3514_DCDC15, 0x0);
+    _backlight_set_brightness(0);
 #ifdef HAVE_LCD_ENABLE
     lcd_enable(false); /* power off visible display */
 #endif
Index: manual/configure_rockbox/display_options.tex
===================================================================
--- manual/configure_rockbox/display_options.tex  (Revision 19818)
+++ manual/configure_rockbox/display_options.tex  (Arbeitskopie)
@@ -28,7 +28,7 @@
       beginning so that the display can be read to see song information. The
       amount of time is determined by the value of the backlight timeout
       setting, but is no less than 5 seconds.
-      \opt{backlight_fade_pwm}{
+      \opt{backlight_fade_int}{
         \item[Backlight Fade In:]
         The amount of time that the backlight will take to fade from off to on
         after a button is pressed. If set to \setting{Off} the backlight will
@@ -41,14 +41,14 @@
         fade out. Other valid values: \setting{500ms}, \setting{1s},
         \setting{2s}, \setting{3s}, \setting{4s}, \setting{5s} or \setting{10s}.
       }
-      \opt{backlight_fade_sw}{
+      \opt{backlight_fade_bool}{
         \item[Backlight Fade In:]
         This options turns on smooth backlight fading when the backlight is
-        activated. The fading time is dependent on the brightness level you
+        turning on. The fading time may dependent on the brightness level you
         have chosen. If it is turned off, the backlight will turn on immediately.
         \item[Backlight Fade Out:]
         This options turns on smooth backlight fading when the backlight is
-        deactivated. The fading time is dependent on the brightness level you
+        turning off. The fading time may dependent on the brightness level you
         have chosen. If it is turned off, the backlight will turn off immediately.
       }
       \item[First Keypress Enables Backlight Only:]