summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Gotthardt <gotthardt@rockbox.org>2007-01-07 06:38:57 +0000
committerSteve Gotthardt <gotthardt@rockbox.org>2007-01-07 06:38:57 +0000
commitc07814fce15b8c48d38bcbf0d55b6800d9a91fd2 (patch)
tree3fe95402d3cb181750bc58675acb133c07a236ec
parent11cdfc6abe733c3288d3d99bce78983ef91f6964 (diff)
downloadrockbox-c07814fce15b8c48d38bcbf0d55b6800d9a91fd2.tar.gz
rockbox-c07814fce15b8c48d38bcbf0d55b6800d9a91fd2.zip
Revamped the backlight state machine and added buttonlight controls. Go to the Info/debug menu and test out the new modes for buttonlights on the Gigabeat - ON, OFF, Faint, and flicker - flickers on touchpad and disk reads.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11935 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/debug_menu.c94
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/ata-meg-fx.c3
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/backlight-meg-fx.c474
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/backlight-target.h44
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/button-meg-fx.c2
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.c4
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.h14
7 files changed, 586 insertions, 49 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index 4f2266ff47..3785374338 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -2089,6 +2089,98 @@ static bool dbg_lcd_power_off(void)
2089 return false; 2089 return false;
2090} 2090}
2091 2091
2092#include "backlight-target.h"
2093
2094static bool dbg_buttonlights(void)
2095{
2096 unsigned short mode_changed = 1, mode = 0;
2097 unsigned short which_led = BUTTONLIGHT_LED_ALL;
2098
2099 lcd_setmargins(0, 0);
2100 for (;;)
2101 {
2102 int button;
2103
2104
2105 if (mode_changed)
2106 {
2107 lcd_clear_display();
2108 lcd_puts(0, 0, "Button light support");
2109 lcd_puts(0, 1, "Press UP for mode change");
2110 lcd_puts(0, 2, "Press DOWN for buttonlight selection");
2111
2112 switch (mode)
2113 {
2114 case 0:
2115 lcd_puts(1, 3, "Off");
2116 __buttonlight_mode(BUTTONLIGHT_OFF);
2117 break;
2118
2119 case 1:
2120 lcd_puts(1, 3, "On");
2121 __buttonlight_mode(BUTTONLIGHT_ON);
2122 break;
2123
2124 case 2:
2125 lcd_puts(1, 3, "Faint");
2126 __buttonlight_mode(BUTTONLIGHT_FAINT);
2127 break;
2128
2129 case 3:
2130 lcd_puts(1, 3, "Flicker");
2131 __buttonlight_mode(BUTTONLIGHT_FLICKER);
2132 break;
2133
2134 }
2135 mode_changed = 0;
2136 lcd_update();
2137 }
2138
2139
2140
2141 /* does nothing unless in flicker mode */
2142 /* the parameter sets the brightness */
2143 __buttonlight_flicker(20);
2144 button = get_action(CONTEXT_STD,HZ/5);
2145 switch(button)
2146 {
2147 case ACTION_STD_PREV:
2148 mode++;
2149 if (mode > 3) mode = 0;
2150 mode_changed = 1;
2151 break;
2152
2153 case ACTION_STD_NEXT:
2154 if (which_led == BUTTONLIGHT_LED_ALL)
2155 {
2156 which_led = BUTTONLIGHT_LED_MENU;
2157 }
2158 else
2159 {
2160 which_led = BUTTONLIGHT_LED_ALL;
2161 }
2162
2163 __buttonlight_select(which_led);
2164
2165 break;
2166
2167
2168 case ACTION_STD_OK:
2169 case ACTION_STD_CANCEL:
2170 action_signalscreenchange();
2171 return false;
2172
2173 default:
2174 sleep(HZ/10);
2175 break;
2176 }
2177 }
2178 return false;
2179}
2180
2181
2182
2183
2092#endif 2184#endif
2093 2185
2094#if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) 2186#if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
@@ -2141,6 +2233,8 @@ bool debug_menu(void)
2141 static const struct menu_item items[] = { 2233 static const struct menu_item items[] = {
2142#if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR) 2234#if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2143 { "LCD Power Off", dbg_lcd_power_off }, 2235 { "LCD Power Off", dbg_lcd_power_off },
2236 { "Button Light modes", dbg_buttonlights },
2237
2144#endif 2238#endif
2145#if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) 2239#if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2146 { "Dump ROM contents", dbg_save_roms }, 2240 { "Dump ROM contents", dbg_save_roms },
diff --git a/firmware/target/arm/gigabeat/meg-fx/ata-meg-fx.c b/firmware/target/arm/gigabeat/meg-fx/ata-meg-fx.c
index d098d83de0..5e0fd8429c 100644
--- a/firmware/target/arm/gigabeat/meg-fx/ata-meg-fx.c
+++ b/firmware/target/arm/gigabeat/meg-fx/ata-meg-fx.c
@@ -26,6 +26,7 @@
26#include "pcf50606.h" 26#include "pcf50606.h"
27#include "ata-target.h" 27#include "ata-target.h"
28#include "mmu-meg-fx.h" 28#include "mmu-meg-fx.h"
29#include "backlight-target.h"
29 30
30void ata_reset(void) 31void ata_reset(void)
31{ 32{
@@ -54,6 +55,8 @@ void ata_device_init(void)
54 55
55void copy_read_sectors(unsigned char* buf, int wordcount) 56void copy_read_sectors(unsigned char* buf, int wordcount)
56{ 57{
58 __buttonlight_flicker(DEFAULT_BRIGHTNESS_SETTING);
59
57 /* Unaligned transfer - slow copy */ 60 /* Unaligned transfer - slow copy */
58 if ( (unsigned long)buf & 1) 61 if ( (unsigned long)buf & 1)
59 { /* not 16-bit aligned, copy byte by byte */ 62 { /* not 16-bit aligned, copy byte by byte */
diff --git a/firmware/target/arm/gigabeat/meg-fx/backlight-meg-fx.c b/firmware/target/arm/gigabeat/meg-fx/backlight-meg-fx.c
index 12a5b55a3c..173d2ce38b 100644
--- a/firmware/target/arm/gigabeat/meg-fx/backlight-meg-fx.c
+++ b/firmware/target/arm/gigabeat/meg-fx/backlight-meg-fx.c
@@ -24,45 +24,100 @@
24#include "lcd.h" 24#include "lcd.h"
25#include "sc606-meg-fx.h" 25#include "sc606-meg-fx.h"
26 26
27#define FLICKER_PERIOD 15
28#define BUTTONLIGHT_MENU (SC606_LED_B1)
29#define BUTTONLIGHT_ALL (SC606_LED_B1 | SC606_LED_B2 | SC606_LED_C1 | SC606_LED_C2)
27 30
28static void backlight_fade_service(void); 31static void led_control_service(void);
29static unsigned short backlight_brightness; 32static unsigned short backlight_brightness;
30static unsigned short backlight_fading;
31static unsigned short backlight_current; 33static unsigned short backlight_current;
32static unsigned short backlight_target; 34static unsigned short backlight_target;
33static unsigned short time_til_fade; 35static unsigned short time_til_fade;
34static unsigned short fade_interval; 36static unsigned short fade_interval;
37static unsigned char backlight_leds;
38
39
40static enum backlight_states
41{
42 BACKLIGHT_CONTROL_IDLE,
43 BACKLIGHT_CONTROL_OFF,
44 BACKLIGHT_CONTROL_ON,
45 BACKLIGHT_CONTROL_SET,
46 BACKLIGHT_CONTROL_FADE_OFF,
47 BACKLIGHT_CONTROL_FADE_ON,
48 BACKLIGHT_CONTROL_FADE_ON_FROM_OFF
49} backlight_control;
50
51
52
53enum buttonlight_states
54{
55 /* turn button lights off */
56 BUTTONLIGHT_MODE_OFF_ENTRY,
57 BUTTONLIGHT_MODE_OFF,
58
59 /* turns button lights on to same brightness as backlight */
60 BUTTONLIGHT_MODE_ON_ENTRY,
61 BUTTONLIGHT_MODE_ON,
62
63 /* turns button lights on to minimum */
64 BUTTONLIGHT_MODE_FAINT_ENTRY,
65 BUTTONLIGHT_MODE_FAINT,
66
67 /* allows button lights to flicker when triggered */
68 BUTTONLIGHT_MODE_FLICKER_ENTRY,
69 BUTTONLIGHT_MODE_FLICKER,
70 BUTTONLIGHT_MODE_FLICKERING,
71
72 /* button lights glow */
73 BUTTONLIGHT_MODE_GLOW_ENTRY,
74 BUTTONLIGHT_MODE_GLOW,
75
76 /* internal use only */
77 BUTTONLIGHT_HELPER_SET,
78 BUTTONLIGHT_HELPER_SET_FINAL,
79};
35 80
36 81
37static int confval = SC606_LOW_FREQ; 82
83static char buttonlight_leds;
84static unsigned short buttonlight_setting;
85static unsigned short buttonlight_current;
86static unsigned char buttonlight_selected;
87static enum buttonlight_states buttonlight_state;
88static enum buttonlight_states buttonlight_saved_state;
89static unsigned short buttonlight_flickering;
90static unsigned short buttonlight_flicker_now;
91static unsigned short buttonlight_flicker_brightness;
92
38 93
39 94
40 95
41void __backlight_init(void) 96void __backlight_init(void)
42{ 97{
43 backlight_fading = false; 98 backlight_control = BACKLIGHT_CONTROL_IDLE;
99
100 backlight_current = DEFAULT_BRIGHTNESS_SETTING;
44 101
45 /* current is from settings */ 102 buttonlight_state = BUTTONLIGHT_MODE_OFF;
46 backlight_current = 50; 103
104 buttonlight_selected = 0x04;
47 105
48 /* put the fade tick on the list */ 106 /* put the led control on the tick list */
49 tick_add_task(backlight_fade_service); 107 tick_add_task(led_control_service);
50} 108}
51 109
52 110
53 111
54void __backlight_on(void) 112void __backlight_on(void)
55{ 113{
56 confval |= (SC606_LED_A1 | SC606_LED_A2); 114 backlight_control = BACKLIGHT_CONTROL_ON;
57 sc606_write(SC606_REG_CONF, confval);
58} 115}
59 116
60 117
61
62void __backlight_off(void) 118void __backlight_off(void)
63{ 119{
64 confval &= ~(SC606_LED_A1 | SC606_LED_A2); 120 backlight_control = BACKLIGHT_CONTROL_OFF;
65 sc606_write(SC606_REG_CONF, confval);
66} 121}
67 122
68 123
@@ -71,46 +126,350 @@ void __backlight_off(void)
71void __backlight_set_brightness(int brightness) 126void __backlight_set_brightness(int brightness)
72{ 127{
73 /* stop the interrupt from messing us up */ 128 /* stop the interrupt from messing us up */
74 backlight_fading = false; 129 backlight_control = BACKLIGHT_CONTROL_IDLE;
75 130
76 backlight_brightness = brightness; 131 backlight_brightness = brightness + 1;
77 132
78 /* only set the brightness if it is different from the current */ 133 /* only set the brightness if it is different from the current */
79 if (backlight_brightness != backlight_current) 134 if (backlight_brightness != backlight_current)
80 { 135 {
81 backlight_target = brightness; 136 backlight_control = BACKLIGHT_CONTROL_SET;
82 fade_interval = time_til_fade = 1;
83 backlight_fading = true;
84 } 137 }
85} 138}
86 139
87 140
88 141
89static void backlight_fade_service(void) 142/* only works if the buttonlight mode is set to flicker */
143void __buttonlight_flicker(unsigned short brightness)
90{ 144{
91 if (!backlight_fading || --time_til_fade) return; 145 /* clip the setting */
92 146 if (brightness > MAX_BRIGHTNESS_SETTING)
93 if (backlight_target > backlight_current)
94 { 147 {
95 backlight_current++; 148 brightness = MAX_BRIGHTNESS_SETTING;
96 } 149 }
97 else 150
151 /* add one because we subtract later for full range */
152 buttonlight_flicker_brightness = brightness + 1;
153 buttonlight_flicker_now = 1;
154}
155
156
157
158/* select which LEDs light up
159 * The only pleasing combinations are: only menu/power or all LEDs
160 */
161void __buttonlight_select(enum buttonlight_selection selection)
162{
163 switch (selection)
98 { 164 {
99 backlight_current--; 165 default:
166 case BUTTONLIGHT_LED_MENU:
167 buttonlight_selected = BUTTONLIGHT_MENU;
168 break;
169
170 case BUTTONLIGHT_LED_ALL:
171 buttonlight_selected = BUTTONLIGHT_ALL;
172 break;
100 } 173 }
174}
101 175
102 /* The SC606 LED driver can set the brightness in 64 steps */
103 sc606_write(SC606_REG_A, backlight_current);
104 176
105 177
106 /* have we hit the target? */ 178/* map the mode from the command into the state machine entries */
107 if (backlight_current == backlight_target) 179void __buttonlight_mode(enum buttonlight_mode mode)
180{
181 switch (mode)
108 { 182 {
109 backlight_fading = false; 183 case BUTTONLIGHT_OFF:
184 buttonlight_state = BUTTONLIGHT_MODE_OFF_ENTRY;
185 break;
186
187 case BUTTONLIGHT_ON:
188 buttonlight_state = BUTTONLIGHT_MODE_ON_ENTRY;
189 break;
190
191 case BUTTONLIGHT_FAINT:
192 buttonlight_state = BUTTONLIGHT_MODE_FAINT_ENTRY;
193 break;
194
195 case BUTTONLIGHT_FLICKER:
196 buttonlight_state = BUTTONLIGHT_MODE_FLICKER_ENTRY;
197 break;
198
199 default:
200 return; /* unknown mode */
110 } 201 }
111 else 202
203
204}
205
206
207
208/*
209 * The button lights have 'modes' of operation. Each mode must setup and
210 * execute its own operation - taking care that this is all done in an ISR.
211 *
212 */
213
214
215
216/* led_control_service runs in interrupt context - be brief!
217 * This service is called once per interrupt timer tick - 100 times a second.
218 *
219 * There should be at most only one i2c operation per call - if more are need
220 * the calls should be spread across calls.
221 *
222 * Putting all led servicing in one thread means that we wont step on any
223 * i2c operations - they are all serialized here in the ISR tick. It also
224 * insures that we get called at equal timing for good visual effect.
225 *
226 * The buttonlight service runs only after all backlight services have finished.
227 * Fading the buttonlights is possible, but not recommended because of the
228 * additional calls needed during the ISR
229 */
230static void led_control_service(void)
231{
232 switch (backlight_control)
112 { 233 {
113 time_til_fade = fade_interval; 234 case BACKLIGHT_CONTROL_IDLE:
235 switch (buttonlight_state)
236 {
237 /* Buttonlight mode: OFF */
238 case BUTTONLIGHT_MODE_OFF_ENTRY:
239 if (buttonlight_current)
240 {
241 buttonlight_leds = 0x00;
242 sc606_write(SC606_REG_CONF, backlight_leds);
243 buttonlight_current = 0;
244 }
245 buttonlight_state = BUTTONLIGHT_MODE_OFF;
246 break;
247
248 case BUTTONLIGHT_MODE_OFF:
249 break;
250
251
252 /* Buttonlight mode: ON */
253 case BUTTONLIGHT_MODE_ON_ENTRY:
254 case BUTTONLIGHT_MODE_ON:
255 if (buttonlight_current != backlight_brightness ||
256 (buttonlight_leds != buttonlight_selected))
257 {
258 buttonlight_leds = buttonlight_selected;
259 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
260
261 /* temporary save for the next mode - then to do settings */
262 buttonlight_setting = backlight_brightness;
263 buttonlight_saved_state = BUTTONLIGHT_MODE_ON;
264 buttonlight_state = BUTTONLIGHT_HELPER_SET;
265 }
266 break;
267
268
269 /* Buttonlight mode: Faint */
270 case BUTTONLIGHT_MODE_FAINT_ENTRY:
271 if (buttonlight_current != 1)
272 {
273 /* need to turn on the backlight? */
274 if (buttonlight_current == 0)
275 {
276 buttonlight_leds = buttonlight_selected;
277 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
278 }
279
280 /* temporary save for the next mode - then to do settings */
281 buttonlight_setting = 1;
282 buttonlight_saved_state = BUTTONLIGHT_MODE_FAINT;
283 buttonlight_state = BUTTONLIGHT_HELPER_SET;
284 }
285 break;
286
287 case BUTTONLIGHT_MODE_FAINT:
288 /* watch for change in led selction */
289 if (buttonlight_leds != buttonlight_selected)
290 {
291 buttonlight_leds = buttonlight_selected;
292 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
293 }
294
295 break;
296
297
298 /* Buttonlight mode: FLICKER */
299 case BUTTONLIGHT_MODE_FLICKER_ENTRY:
300 /* already on? turn it off */
301 if (buttonlight_current)
302 {
303 buttonlight_leds = 0x00;
304 sc606_write(SC606_REG_CONF, backlight_leds);
305 buttonlight_current = 0;
306 }
307
308 /* set the brightness if not already set */
309 if (buttonlight_current != buttonlight_flicker_brightness)
310 {
311 /* temporary save for the next mode - then to do settings */
312 buttonlight_setting = buttonlight_flicker_brightness;
313 buttonlight_saved_state = BUTTONLIGHT_MODE_FLICKER;
314 buttonlight_state = BUTTONLIGHT_HELPER_SET;
315 }
316 break;
317
318
319 case BUTTONLIGHT_MODE_FLICKER:
320 /* wait for the foreground to trigger flickering */
321 if (buttonlight_flicker_now)
322 {
323 /* turn them on */
324 buttonlight_leds = buttonlight_selected;
325 buttonlight_current = buttonlight_setting;
326 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
327
328 /* reset the trigger and go flicker the LEDs */
329 buttonlight_flicker_now = 0;
330 buttonlight_flickering = FLICKER_PERIOD;
331 buttonlight_state = BUTTONLIGHT_MODE_FLICKERING;
332 }
333 break;
334
335
336 case BUTTONLIGHT_MODE_FLICKERING:
337 /* flicker the LEDs for as long as we get triggered */
338 if (buttonlight_flickering)
339 {
340 /* turn the leds off if they are on */
341 if (buttonlight_current)
342 {
343 buttonlight_leds = 0x00;
344 sc606_write(SC606_REG_CONF, backlight_leds);
345 buttonlight_current = 0;
346 }
347
348 buttonlight_flickering--;
349 }
350 else
351 {
352 /* is flickering triggered again? */
353 if (!buttonlight_flicker_now)
354 {
355 /* completed a cycle - no new triggers - go back and wait */
356 buttonlight_state = BUTTONLIGHT_MODE_FLICKER;
357 }
358 else
359 {
360 /* reset flickering */
361 buttonlight_flicker_now = 0;
362 buttonlight_flickering = FLICKER_PERIOD;
363
364 /* turn buttonlights on */
365 buttonlight_leds = buttonlight_selected;
366 buttonlight_current = buttonlight_setting;
367 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
368 }
369 }
370 break;
371
372 /* set the brightness for the buttonlights - takes 2 passes */
373 case BUTTONLIGHT_HELPER_SET:
374 sc606_write(SC606_REG_B, buttonlight_setting-1);
375 buttonlight_state = BUTTONLIGHT_HELPER_SET_FINAL;
376 break;
377
378 case BUTTONLIGHT_HELPER_SET_FINAL:
379 sc606_write(SC606_REG_C, buttonlight_setting-1);
380 buttonlight_current = buttonlight_setting;
381 buttonlight_state = buttonlight_saved_state;
382 break;
383
384 default:
385 break;
386
387 }
388 break;
389
390
391 case BACKLIGHT_CONTROL_FADE_ON_FROM_OFF:
392 backlight_leds = 0x03;
393 sc606_write(SC606_REG_CONF, 0x03 | buttonlight_leds);
394 backlight_control = BACKLIGHT_CONTROL_FADE_ON;
395 break;
396
397
398 case BACKLIGHT_CONTROL_OFF:
399 backlight_current = 0;
400 backlight_leds = 0x00;
401 sc606_write(SC606_REG_CONF, buttonlight_leds);
402 backlight_control = BACKLIGHT_CONTROL_IDLE;
403 break;
404
405
406 case BACKLIGHT_CONTROL_ON:
407 backlight_leds = 0x03;
408 sc606_write(SC606_REG_CONF, 0x03 | buttonlight_leds);
409 backlight_current = backlight_brightness;
410 backlight_control = BACKLIGHT_CONTROL_IDLE;
411 break;
412
413
414 case BACKLIGHT_CONTROL_SET:
415 /* The SC606 LED driver can set the brightness in 64 steps */
416 sc606_write(SC606_REG_A, backlight_brightness-1);
417
418 /* if we were turned off - turn the backlight on */
419 if (backlight_current)
420 {
421 backlight_current = backlight_brightness;
422 backlight_control = BACKLIGHT_CONTROL_IDLE;
423 }
424 else
425 {
426 backlight_control = BACKLIGHT_CONTROL_ON;
427 }
428 break;
429
430
431 case BACKLIGHT_CONTROL_FADE_ON:
432 if (--time_til_fade) return;
433
434 /* The SC606 LED driver can set the brightness in 64 steps */
435 sc606_write(SC606_REG_A, backlight_current++);
436
437 /* have we hit the target? */
438 if (backlight_current == backlight_target)
439 {
440 backlight_control = BACKLIGHT_CONTROL_IDLE;
441 }
442 else
443 {
444 time_til_fade = fade_interval;
445 }
446 break;
447
448
449 case BACKLIGHT_CONTROL_FADE_OFF:
450 if (--time_til_fade) return;
451
452 /* The SC606 LED driver can set the brightness in 64 steps */
453 sc606_write(SC606_REG_A, --backlight_current);
454
455 /* have we hit the target? */
456 if (backlight_current == backlight_target)
457 {
458 if (backlight_current)
459 {
460 backlight_control = BACKLIGHT_CONTROL_IDLE;
461 }
462 else
463 {
464 backlight_control = BACKLIGHT_CONTROL_OFF;
465 }
466
467 }
468 else
469 {
470 time_til_fade = fade_interval;
471 }
472 break;
114 } 473 }
115 474
116} 475}
@@ -121,10 +480,10 @@ static void backlight_fade_service(void)
121 480
122void __backlight_dim(bool dim_now) 481void __backlight_dim(bool dim_now)
123{ 482{
124 int target; 483 unsigned short target;
125 484
126 /* dont let the interrupt tick happen */ 485 /* dont let the interrupt tick happen */
127 backlight_fading = false; 486 backlight_control = BACKLIGHT_CONTROL_IDLE;
128 487
129 target = (dim_now == true) ? 0 : backlight_brightness; 488 target = (dim_now == true) ? 0 : backlight_brightness;
130 489
@@ -135,17 +494,52 @@ void __backlight_dim(bool dim_now)
135 494
136 if (backlight_current > backlight_target) 495 if (backlight_current > backlight_target)
137 { 496 {
138 fade_interval = 4; 497 time_til_fade = fade_interval = 4;
498 backlight_control = BACKLIGHT_CONTROL_FADE_OFF;
139 } 499 }
140 else 500 else
141 { 501 {
142 fade_interval = 1; 502 time_til_fade = fade_interval = 1;
503 if (backlight_current)
504 {
505 backlight_control = BACKLIGHT_CONTROL_FADE_ON;
506 }
507 else
508 {
509 backlight_control = BACKLIGHT_CONTROL_FADE_ON_FROM_OFF;
510 }
143 } 511 }
144
145 /* let the tick work */
146 time_til_fade = fade_interval;
147 backlight_fading = true;
148 } 512 }
149 513
150} 514}
151 515
516
517
518
519#define BACKLIGHT_BUTTONS_OFF 0
520#define BACKLIGHT_BUTTONS_ON 1
521#define BACKLIGHT_BUTTONS_FAINT 2
522#define BACKLIGHT_BUTTONS_FOLLOW 3
523
524
525void __backlight_buttons(int value)
526{
527 switch (value)
528 {
529 default:
530 case BACKLIGHT_BUTTONS_OFF:
531 break;
532
533 case BACKLIGHT_BUTTONS_ON:
534 break;
535
536 case BACKLIGHT_BUTTONS_FAINT:
537 break;
538
539 case BACKLIGHT_BUTTONS_FOLLOW:
540 break;
541
542 }
543
544}
545
diff --git a/firmware/target/arm/gigabeat/meg-fx/backlight-target.h b/firmware/target/arm/gigabeat/meg-fx/backlight-target.h
index c53d00d8de..67a055449c 100644
--- a/firmware/target/arm/gigabeat/meg-fx/backlight-target.h
+++ b/firmware/target/arm/gigabeat/meg-fx/backlight-target.h
@@ -19,11 +19,55 @@
19#ifndef BACKLIGHT_TARGET_H 19#ifndef BACKLIGHT_TARGET_H
20#define BACKLIGHT_TARGET_H 20#define BACKLIGHT_TARGET_H
21 21
22
23/* select the led */
24enum buttonlight_selection
25{
26 /* all leds */
27 BUTTONLIGHT_LED_ALL,
28
29 /* only the menu/power led (two buttons for one LED) */
30 BUTTONLIGHT_LED_MENU
31};
32
33
34/* Use these to set the buttonlight mode */
35enum buttonlight_mode
36{
37 /* ON follows the setting of the backlight - same brightness */
38 BUTTONLIGHT_ON,
39
40 /* buttonlights always off */
41 BUTTONLIGHT_OFF,
42
43 /* buttonlights always on but set at lowest brightness */
44 BUTTONLIGHT_FAINT,
45
46 /* buttonlights flicker when triggered */
47 BUTTONLIGHT_FLICKER,
48};
49
50
51/* call to flicker the button lights */
52void __buttonlight_flicker(unsigned short brightness);
53
54
55/* only use the XX__ENTRY when setting the mode */
56void __buttonlight_mode(enum buttonlight_mode mode);
57
58
59/* select which led to use on the button lights. Other combinations are
60 * possible, but don't look very good.
61 */
62void __buttonlight_select(enum buttonlight_selection selection);
63
64
22void __backlight_init(void); 65void __backlight_init(void);
23void __backlight_on(void); 66void __backlight_on(void);
24void __backlight_off(void); 67void __backlight_off(void);
25void __backlight_set_brightness(int val); 68void __backlight_set_brightness(int val);
26 69
70/* true: backlight fades off - false: backlight fades on */
27void __backlight_dim(bool dim); 71void __backlight_dim(bool dim);
28 72
29#endif 73#endif
diff --git a/firmware/target/arm/gigabeat/meg-fx/button-meg-fx.c b/firmware/target/arm/gigabeat/meg-fx/button-meg-fx.c
index b5f18a264b..4ba6ce23f7 100644
--- a/firmware/target/arm/gigabeat/meg-fx/button-meg-fx.c
+++ b/firmware/target/arm/gigabeat/meg-fx/button-meg-fx.c
@@ -122,6 +122,8 @@ int button_read_device(void)
122 122
123 if (touchpad & (1 << 3)) 123 if (touchpad & (1 << 3))
124 btn |= BUTTON_SELECT; 124 btn |= BUTTON_SELECT;
125
126 __buttonlight_flicker(DEFAULT_BRIGHTNESS_SETTING/2);
125 } 127 }
126 128
127 return btn; 129 return btn;
diff --git a/firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.c b/firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.c
index 654095c2f5..6ca64a0437 100644
--- a/firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.c
+++ b/firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.c
@@ -151,7 +151,7 @@ static unsigned char sc606_i2c_inb(void)
151/* returns number of acks that were bad */ 151/* returns number of acks that were bad */
152int sc606_write(unsigned char reg, unsigned char data) 152int sc606_write(unsigned char reg, unsigned char data)
153{ 153{
154 int x = 0; 154 int x;
155 155
156 sc606_i2c_start(); 156 sc606_i2c_start();
157 157
@@ -178,7 +178,7 @@ int sc606_write(unsigned char reg, unsigned char data)
178 178
179int sc606_read(unsigned char reg, unsigned char* data) 179int sc606_read(unsigned char reg, unsigned char* data)
180{ 180{
181 int x = 0; 181 int x;
182 182
183 sc606_i2c_start(); 183 sc606_i2c_start();
184 sc606_i2c_outb(SLAVE_ADDRESS); 184 sc606_i2c_outb(SLAVE_ADDRESS);
diff --git a/firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.h b/firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.h
index 2637c067e0..df7a654b36 100644
--- a/firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.h
+++ b/firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.h
@@ -13,14 +13,14 @@
13#define SC606_REG_C 2 13#define SC606_REG_C 2
14#define SC606_REG_CONF 3 14#define SC606_REG_CONF 3
15 15
16#define SC606_LED_A1 1 << 0 16#define SC606_LED_A1 (1 << 0)
17#define SC606_LED_A2 1 << 1 17#define SC606_LED_A2 (1 << 1)
18#define SC606_LED_B1 1 << 2 18#define SC606_LED_B1 (1 << 2)
19#define SC606_LED_B2 1 << 3 19#define SC606_LED_B2 (1 << 3)
20#define SC606_LED_C1 1 << 4 20#define SC606_LED_C1 (1 << 4)
21#define SC606_LED_C2 1 << 5 21#define SC606_LED_C2 (1 << 5)
22 22
23#define SC606_LOW_FREQ 1 << 6 23#define SC606_LOW_FREQ (1 << 6)
24 24
25int sc606_write(unsigned char reg, unsigned char data); 25int sc606_write(unsigned char reg, unsigned char data);
26 26