summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Gotthardt <gotthardt@rockbox.org>2007-01-08 08:53:36 +0000
committerSteve Gotthardt <gotthardt@rockbox.org>2007-01-08 08:53:36 +0000
commit93b047fffec9b6d3b5ef1697c3034caa83944182 (patch)
tree430b4482bd77c6d860a14048b25310db5aa8943d
parent2446b22db971668f8d6ba5cb2361aabbda286da1 (diff)
downloadrockbox-93b047fffec9b6d3b5ef1697c3034caa83944182.tar.gz
rockbox-93b047fffec9b6d3b5ef1697c3034caa83944182.zip
Updated buttonlights for the Gigabeat port. Added LCD controller off and on for extra power savings - thanks to Greg White. Incorporated feedback from Gary Allen. Added 'battery charging' mode: shows leds during charging. Added 'follow' mode that turns off leds when backlight goes off. Flicker mode and new solid mode only show during disk access. Access settings from Info/debug menu for now.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11945 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/debug_menu.c41
-rw-r--r--firmware/backlight.c2
-rw-r--r--firmware/export/config-gigabeat.h2
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/ata-meg-fx.c2
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/backlight-meg-fx.c335
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/backlight-target.h32
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/button-meg-fx.c2
7 files changed, 291 insertions, 125 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index 3785374338..083dddbd74 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -2094,14 +2094,14 @@ static bool dbg_lcd_power_off(void)
2094static bool dbg_buttonlights(void) 2094static bool dbg_buttonlights(void)
2095{ 2095{
2096 unsigned short mode_changed = 1, mode = 0; 2096 unsigned short mode_changed = 1, mode = 0;
2097 unsigned short which_led = BUTTONLIGHT_LED_ALL; 2097 enum buttonlight_selection which_led = BUTTONLIGHT_LED_ALL;
2098 unsigned short brightness = DEFAULT_BRIGHTNESS_SETTING;
2098 2099
2099 lcd_setmargins(0, 0); 2100 lcd_setmargins(0, 0);
2100 for (;;) 2101 for (;;)
2101 { 2102 {
2102 int button; 2103 int button;
2103 2104
2104
2105 if (mode_changed) 2105 if (mode_changed)
2106 { 2106 {
2107 lcd_clear_display(); 2107 lcd_clear_display();
@@ -2113,22 +2113,37 @@ static bool dbg_buttonlights(void)
2113 { 2113 {
2114 case 0: 2114 case 0:
2115 lcd_puts(1, 3, "Off"); 2115 lcd_puts(1, 3, "Off");
2116 __buttonlight_mode(BUTTONLIGHT_OFF); 2116 __buttonlight_mode(BUTTONLIGHT_OFF, which_led, brightness);
2117 break; 2117 break;
2118 2118
2119 case 1: 2119 case 1:
2120 lcd_puts(1, 3, "On"); 2120 lcd_puts(1, 3, "On - Set to brightness");
2121 __buttonlight_mode(BUTTONLIGHT_ON); 2121 __buttonlight_mode(BUTTONLIGHT_ON, which_led, brightness);
2122 break; 2122 break;
2123 2123
2124 case 2: 2124 case 2:
2125 lcd_puts(1, 3, "Faint"); 2125 lcd_puts(1, 3, "Faint - Always on at lowest brightness");
2126 __buttonlight_mode(BUTTONLIGHT_FAINT); 2126 __buttonlight_mode(BUTTONLIGHT_FAINT, which_led, brightness);
2127 break; 2127 break;
2128 2128
2129 case 3: 2129 case 3:
2130 lcd_puts(1, 3, "Flicker"); 2130 lcd_puts(1, 3, "Flicker on disk access");
2131 __buttonlight_mode(BUTTONLIGHT_FLICKER); 2131 __buttonlight_mode(BUTTONLIGHT_FLICKER, which_led, brightness);
2132 break;
2133
2134 case 4:
2135 lcd_puts(1, 3, "Solid on disk access");
2136 __buttonlight_mode(BUTTONLIGHT_SIGNAL, which_led, brightness);
2137 break;
2138
2139 case 5:
2140 lcd_puts(1, 3, "Follows backlight");
2141 __buttonlight_mode(BUTTONLIGHT_FOLLOW, which_led, brightness);
2142 break;
2143
2144 case 6:
2145 lcd_puts(1, 3, "Shows 'battery charging'");
2146 __buttonlight_mode(BUTTONLIGHT_CHARGING, which_led, brightness);
2132 break; 2147 break;
2133 2148
2134 } 2149 }
@@ -2140,13 +2155,12 @@ static bool dbg_buttonlights(void)
2140 2155
2141 /* does nothing unless in flicker mode */ 2156 /* does nothing unless in flicker mode */
2142 /* the parameter sets the brightness */ 2157 /* the parameter sets the brightness */
2143 __buttonlight_flicker(20); 2158 __buttonlight_trigger();
2144 button = get_action(CONTEXT_STD,HZ/5); 2159 button = get_action(CONTEXT_STD,HZ/5);
2145 switch(button) 2160 switch(button)
2146 { 2161 {
2147 case ACTION_STD_PREV: 2162 case ACTION_STD_PREV:
2148 mode++; 2163 if (++mode > 6) mode = 0;
2149 if (mode > 3) mode = 0;
2150 mode_changed = 1; 2164 mode_changed = 1;
2151 break; 2165 break;
2152 2166
@@ -2159,8 +2173,7 @@ static bool dbg_buttonlights(void)
2159 { 2173 {
2160 which_led = BUTTONLIGHT_LED_ALL; 2174 which_led = BUTTONLIGHT_LED_ALL;
2161 } 2175 }
2162 2176 mode_changed = 1;
2163 __buttonlight_select(which_led);
2164 2177
2165 break; 2178 break;
2166 2179
diff --git a/firmware/backlight.c b/firmware/backlight.c
index 9494be107b..63bde6a868 100644
--- a/firmware/backlight.c
+++ b/firmware/backlight.c
@@ -291,6 +291,8 @@ static void _backlight_on(void)
291 __backlight_on(); 291 __backlight_on();
292 } 292 }
293#elif defined(HAVE_BACKLIGHT_SET_FADING) && !defined(SIMULATOR) 293#elif defined(HAVE_BACKLIGHT_SET_FADING) && !defined(SIMULATOR)
294 /* call the enable from here - it takes longer than the disable */
295 lcd_enable(true);
294 __backlight_dim(false); 296 __backlight_dim(false);
295#else 297#else
296 __backlight_on(); 298 __backlight_on();
diff --git a/firmware/export/config-gigabeat.h b/firmware/export/config-gigabeat.h
index 3672bdfdb5..4a1d11d43a 100644
--- a/firmware/export/config-gigabeat.h
+++ b/firmware/export/config-gigabeat.h
@@ -41,6 +41,8 @@
41/* Define this for LCD backlight available */ 41/* Define this for LCD backlight available */
42#define CONFIG_BACKLIGHT BL_GIGABEAT /* port controlled PWM */ 42#define CONFIG_BACKLIGHT BL_GIGABEAT /* port controlled PWM */
43 43
44#define HAVE_LCD_ENABLE
45
44#define HAVE_BACKLIGHT_BRIGHTNESS 46#define HAVE_BACKLIGHT_BRIGHTNESS
45 47
46/* Main LCD backlight brightness range and defaults */ 48/* Main LCD backlight brightness range and defaults */
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 5e0fd8429c..8e246045e6 100644
--- a/firmware/target/arm/gigabeat/meg-fx/ata-meg-fx.c
+++ b/firmware/target/arm/gigabeat/meg-fx/ata-meg-fx.c
@@ -55,7 +55,7 @@ void ata_device_init(void)
55 55
56void copy_read_sectors(unsigned char* buf, int wordcount) 56void copy_read_sectors(unsigned char* buf, int wordcount)
57{ 57{
58 __buttonlight_flicker(DEFAULT_BRIGHTNESS_SETTING); 58 __buttonlight_trigger();
59 59
60 /* Unaligned transfer - slow copy */ 60 /* Unaligned transfer - slow copy */
61 if ( (unsigned long)buf & 1) 61 if ( (unsigned long)buf & 1)
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 173d2ce38b..b97e1430b2 100644
--- a/firmware/target/arm/gigabeat/meg-fx/backlight-meg-fx.c
+++ b/firmware/target/arm/gigabeat/meg-fx/backlight-meg-fx.c
@@ -23,6 +23,8 @@
23#include "backlight.h" 23#include "backlight.h"
24#include "lcd.h" 24#include "lcd.h"
25#include "sc606-meg-fx.h" 25#include "sc606-meg-fx.h"
26#include "power.h"
27
26 28
27#define FLICKER_PERIOD 15 29#define FLICKER_PERIOD 15
28#define BUTTONLIGHT_MENU (SC606_LED_B1) 30#define BUTTONLIGHT_MENU (SC606_LED_B1)
@@ -56,7 +58,7 @@ enum buttonlight_states
56 BUTTONLIGHT_MODE_OFF_ENTRY, 58 BUTTONLIGHT_MODE_OFF_ENTRY,
57 BUTTONLIGHT_MODE_OFF, 59 BUTTONLIGHT_MODE_OFF,
58 60
59 /* turns button lights on to same brightness as backlight */ 61 /* turns button lights on to setting */
60 BUTTONLIGHT_MODE_ON_ENTRY, 62 BUTTONLIGHT_MODE_ON_ENTRY,
61 BUTTONLIGHT_MODE_ON, 63 BUTTONLIGHT_MODE_ON,
62 64
@@ -69,13 +71,23 @@ enum buttonlight_states
69 BUTTONLIGHT_MODE_FLICKER, 71 BUTTONLIGHT_MODE_FLICKER,
70 BUTTONLIGHT_MODE_FLICKERING, 72 BUTTONLIGHT_MODE_FLICKERING,
71 73
72 /* button lights glow */ 74 /* button lights solid */
73 BUTTONLIGHT_MODE_GLOW_ENTRY, 75 BUTTONLIGHT_MODE_SOLID_ENTRY,
74 BUTTONLIGHT_MODE_GLOW, 76 BUTTONLIGHT_MODE_SOLID,
75 77
78 /* button light charing */
79 BUTTONLIGHT_MODE_CHARGING_ENTRY,
80 BUTTONLIGHT_MODE_CHARGING,
81 BUTTONLIGHT_MODE_CHARGING_WAIT,
82
76 /* internal use only */ 83 /* internal use only */
77 BUTTONLIGHT_HELPER_SET, 84 BUTTONLIGHT_HELPER_SET,
78 BUTTONLIGHT_HELPER_SET_FINAL, 85 BUTTONLIGHT_HELPER_SET_FINAL,
86 BUTTONLIGHT_MODE_STOP,
87
88 /* buttonlights follow the backlight settings */
89 BUTTONLIGHT_MODE_FOLLOW_ENTRY,
90 BUTTONLIGHT_MODE_FOLLOW,
79}; 91};
80 92
81 93
@@ -87,10 +99,18 @@ static unsigned char buttonlight_selected;
87static enum buttonlight_states buttonlight_state; 99static enum buttonlight_states buttonlight_state;
88static enum buttonlight_states buttonlight_saved_state; 100static enum buttonlight_states buttonlight_saved_state;
89static unsigned short buttonlight_flickering; 101static unsigned short buttonlight_flickering;
90static unsigned short buttonlight_flicker_now; 102
91static unsigned short buttonlight_flicker_brightness; 103static unsigned short buttonlight_trigger_now;
104static unsigned short buttonlight_trigger_brightness;
105
92 106
93 107
108static unsigned short charging_led_index;
109static unsigned short buttonlight_charging_counter;
110
111#define CHARGING_LED_COUNT 60
112unsigned char charging_leds[] = { 0x00, 0x20, 0x38, 0x3C };
113
94 114
95 115
96void __backlight_init(void) 116void __backlight_init(void)
@@ -111,10 +131,12 @@ void __backlight_init(void)
111 131
112void __backlight_on(void) 132void __backlight_on(void)
113{ 133{
134 /* now go turn the backlight on */
114 backlight_control = BACKLIGHT_CONTROL_ON; 135 backlight_control = BACKLIGHT_CONTROL_ON;
115} 136}
116 137
117 138
139
118void __backlight_off(void) 140void __backlight_off(void)
119{ 141{
120 backlight_control = BACKLIGHT_CONTROL_OFF; 142 backlight_control = BACKLIGHT_CONTROL_OFF;
@@ -139,45 +161,45 @@ void __backlight_set_brightness(int brightness)
139 161
140 162
141 163
142/* only works if the buttonlight mode is set to flicker */ 164/* only works if the buttonlight mode is set to triggered mode */
143void __buttonlight_flicker(unsigned short brightness) 165void __buttonlight_trigger(void)
144{ 166{
145 /* clip the setting */ 167 buttonlight_trigger_now = 1;
146 if (brightness > MAX_BRIGHTNESS_SETTING)
147 {
148 brightness = MAX_BRIGHTNESS_SETTING;
149 }
150
151 /* add one because we subtract later for full range */
152 buttonlight_flicker_brightness = brightness + 1;
153 buttonlight_flicker_now = 1;
154} 168}
155 169
170
156 171
157 172
158/* select which LEDs light up 173/* map the mode from the command into the state machine entries */
159 * The only pleasing combinations are: only menu/power or all LEDs 174void __buttonlight_mode(enum buttonlight_mode mode,
160 */ 175 enum buttonlight_selection selection,
161void __buttonlight_select(enum buttonlight_selection selection) 176 unsigned short brightness)
162{ 177{
178 /* choose stop to setup mode */
179 buttonlight_state = BUTTONLIGHT_MODE_STOP;
180
181
182 /* clip brightness */
183 if (brightness > MAX_BRIGHTNESS_SETTING)
184 {
185 brightness = MAX_BRIGHTNESS_SETTING;
186 }
187
188 brightness++;
189
190 /* Select which LEDs to use */
163 switch (selection) 191 switch (selection)
164 { 192 {
165 default:
166 case BUTTONLIGHT_LED_MENU:
167 buttonlight_selected = BUTTONLIGHT_MENU;
168 break;
169
170 case BUTTONLIGHT_LED_ALL: 193 case BUTTONLIGHT_LED_ALL:
171 buttonlight_selected = BUTTONLIGHT_ALL; 194 buttonlight_selected = BUTTONLIGHT_ALL;
172 break; 195 break;
173 }
174}
175 196
197 case BUTTONLIGHT_LED_MENU:
198 buttonlight_selected = BUTTONLIGHT_MENU;
199 break;
200 }
176 201
177 202 /* which mode to use */
178/* map the mode from the command into the state machine entries */
179void __buttonlight_mode(enum buttonlight_mode mode)
180{
181 switch (mode) 203 switch (mode)
182 { 204 {
183 case BUTTONLIGHT_OFF: 205 case BUTTONLIGHT_OFF:
@@ -185,22 +207,39 @@ void __buttonlight_mode(enum buttonlight_mode mode)
185 break; 207 break;
186 208
187 case BUTTONLIGHT_ON: 209 case BUTTONLIGHT_ON:
210 buttonlight_trigger_brightness = brightness;
188 buttonlight_state = BUTTONLIGHT_MODE_ON_ENTRY; 211 buttonlight_state = BUTTONLIGHT_MODE_ON_ENTRY;
189 break; 212 break;
190 213
214 /* faint is just a quick way to set ON to 1 */
191 case BUTTONLIGHT_FAINT: 215 case BUTTONLIGHT_FAINT:
192 buttonlight_state = BUTTONLIGHT_MODE_FAINT_ENTRY; 216 buttonlight_trigger_brightness = 1;
217 buttonlight_state = BUTTONLIGHT_MODE_ON_ENTRY;
193 break; 218 break;
194 219
195 case BUTTONLIGHT_FLICKER: 220 case BUTTONLIGHT_FLICKER:
221 buttonlight_trigger_brightness = brightness;
196 buttonlight_state = BUTTONLIGHT_MODE_FLICKER_ENTRY; 222 buttonlight_state = BUTTONLIGHT_MODE_FLICKER_ENTRY;
197 break; 223 break;
198 224
225 case BUTTONLIGHT_SIGNAL:
226 buttonlight_trigger_brightness = brightness;
227 buttonlight_state = BUTTONLIGHT_MODE_SOLID_ENTRY;
228 break;
229
230 case BUTTONLIGHT_FOLLOW:
231 buttonlight_state = BUTTONLIGHT_MODE_FOLLOW_ENTRY;
232 break;
233
234 case BUTTONLIGHT_CHARGING:
235 buttonlight_state = BUTTONLIGHT_MODE_CHARGING_ENTRY;
236 break;
237
199 default: 238 default:
200 return; /* unknown mode */ 239 return; /* unknown mode */
201 } 240 }
202 241
203 242
204} 243}
205 244
206 245
@@ -234,6 +273,8 @@ static void led_control_service(void)
234 case BACKLIGHT_CONTROL_IDLE: 273 case BACKLIGHT_CONTROL_IDLE:
235 switch (buttonlight_state) 274 switch (buttonlight_state)
236 { 275 {
276 case BUTTONLIGHT_MODE_STOP: break;
277
237 /* Buttonlight mode: OFF */ 278 /* Buttonlight mode: OFF */
238 case BUTTONLIGHT_MODE_OFF_ENTRY: 279 case BUTTONLIGHT_MODE_OFF_ENTRY:
239 if (buttonlight_current) 280 if (buttonlight_current)
@@ -248,52 +289,127 @@ static void led_control_service(void)
248 case BUTTONLIGHT_MODE_OFF: 289 case BUTTONLIGHT_MODE_OFF:
249 break; 290 break;
250 291
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 292
261 /* temporary save for the next mode - then to do settings */ 293 /* button mode: CHARGING - show charging sequence */
262 buttonlight_setting = backlight_brightness; 294 case BUTTONLIGHT_MODE_CHARGING_ENTRY:
263 buttonlight_saved_state = BUTTONLIGHT_MODE_ON; 295 /* start turned off */
264 buttonlight_state = BUTTONLIGHT_HELPER_SET; 296 buttonlight_leds = 0x00;
265 } 297 sc606_write(SC606_REG_CONF, backlight_leds);
266 break; 298 buttonlight_current = 0;
267 299
300 /* temporary save for the next mode - then to do settings */
301 buttonlight_setting = DEFAULT_BRIGHTNESS_SETTING;
302 buttonlight_saved_state = BUTTONLIGHT_MODE_CHARGING_WAIT;
303 buttonlight_state = BUTTONLIGHT_HELPER_SET;
304 break;
305
268 306
269 /* Buttonlight mode: Faint */ 307 case BUTTONLIGHT_MODE_CHARGING:
270 case BUTTONLIGHT_MODE_FAINT_ENTRY: 308 if (--buttonlight_charging_counter == 0)
271 if (buttonlight_current != 1)
272 { 309 {
273 /* need to turn on the backlight? */ 310 /* change led */
274 if (buttonlight_current == 0) 311 if (charging_state())
275 { 312 {
276 buttonlight_leds = buttonlight_selected; 313 buttonlight_leds = charging_leds[charging_led_index];
314 if (++charging_led_index >= sizeof(charging_leds))
315 {
316 charging_led_index = 0;
317 }
277 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds); 318 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
319 buttonlight_charging_counter = CHARGING_LED_COUNT;
320 }
321 else
322 {
323 buttonlight_state = BUTTONLIGHT_MODE_CHARGING_ENTRY;
278 } 324 }
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 } 325 }
285 break; 326 break;
286 327
287 case BUTTONLIGHT_MODE_FAINT: 328 /* wait for the charget to be plugged in */
288 /* watch for change in led selction */ 329 case BUTTONLIGHT_MODE_CHARGING_WAIT:
289 if (buttonlight_leds != buttonlight_selected) 330 if (charging_state())
290 { 331 {
332 charging_led_index = 0;
333 buttonlight_charging_counter = CHARGING_LED_COUNT;
334 buttonlight_state = BUTTONLIGHT_MODE_CHARGING;
335 }
336 break;
337
338
339 /* Buttonlight mode: FOLLOW - try to stay current with backlight
340 * since this runs in the idle of the backlight it will not really
341 * follow in real time
342 */
343 case BUTTONLIGHT_MODE_FOLLOW_ENTRY:
344 /* case 1 - backlight on, but buttonlight is off */
345 if (backlight_current)
346 {
347 /* Turn the buttonlights on */
291 buttonlight_leds = buttonlight_selected; 348 buttonlight_leds = buttonlight_selected;
292 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds); 349 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
350
351 /* temporary save for the next mode - then to do settings */
352 buttonlight_setting = backlight_current;
353 buttonlight_saved_state = BUTTONLIGHT_MODE_FOLLOW;
354 buttonlight_state = BUTTONLIGHT_HELPER_SET;
293 } 355 }
356 /* case 2 - backlight off, but buttonlight is on */
357 else
358 {
359 buttonlight_current = 0;
360 buttonlight_leds = 0x00;
361 sc606_write(SC606_REG_CONF, backlight_leds);
362 buttonlight_state = BUTTONLIGHT_MODE_FOLLOW;
363 }
364 break;
365
366 case BUTTONLIGHT_MODE_FOLLOW:
367 if (buttonlight_current != backlight_current)
368 {
369 /* case 1 - backlight on, but buttonlight is off */
370 if (backlight_current)
371 {
372 if (0 == buttonlight_current)
373 {
374 /* Turn the buttonlights on */
375 buttonlight_leds = buttonlight_selected;
376 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
377 }
378
379 /* temporary save for the next mode - then to do settings */
380 buttonlight_setting = backlight_current;
381 buttonlight_saved_state = BUTTONLIGHT_MODE_FOLLOW;
382 buttonlight_state = BUTTONLIGHT_HELPER_SET;
383 }
384
385 /* case 2 - backlight off, but buttonlight is on */
386 else
387 {
388 buttonlight_current = 0;
389 buttonlight_leds = 0x00;
390 sc606_write(SC606_REG_CONF, backlight_leds);
391 }
392
393 }
394 break;
395
294 396
397
398 /* Buttonlight mode: ON - stays at the set brightness */
399 case BUTTONLIGHT_MODE_ON_ENTRY:
400 buttonlight_leds = buttonlight_selected;
401 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
402
403 /* temporary save for the next mode - then to do settings */
404 buttonlight_setting = buttonlight_trigger_brightness;
405 buttonlight_saved_state = BUTTONLIGHT_MODE_ON;
406 buttonlight_state = BUTTONLIGHT_HELPER_SET;
295 break; 407 break;
296 408
409 case BUTTONLIGHT_MODE_ON:
410 break;
411
412
297 413
298 /* Buttonlight mode: FLICKER */ 414 /* Buttonlight mode: FLICKER */
299 case BUTTONLIGHT_MODE_FLICKER_ENTRY: 415 case BUTTONLIGHT_MODE_FLICKER_ENTRY:
@@ -306,19 +422,20 @@ static void led_control_service(void)
306 } 422 }
307 423
308 /* set the brightness if not already set */ 424 /* set the brightness if not already set */
309 if (buttonlight_current != buttonlight_flicker_brightness) 425 if (buttonlight_current != buttonlight_trigger_brightness)
310 { 426 {
311 /* temporary save for the next mode - then to do settings */ 427 /* temporary save for the next mode - then to do settings */
312 buttonlight_setting = buttonlight_flicker_brightness; 428 buttonlight_setting = buttonlight_trigger_brightness;
313 buttonlight_saved_state = BUTTONLIGHT_MODE_FLICKER; 429 buttonlight_saved_state = BUTTONLIGHT_MODE_FLICKER;
314 buttonlight_state = BUTTONLIGHT_HELPER_SET; 430 buttonlight_state = BUTTONLIGHT_HELPER_SET;
315 } 431 }
432 else buttonlight_state = BUTTONLIGHT_MODE_FLICKER;
316 break; 433 break;
317 434
318 435
319 case BUTTONLIGHT_MODE_FLICKER: 436 case BUTTONLIGHT_MODE_FLICKER:
320 /* wait for the foreground to trigger flickering */ 437 /* wait for the foreground to trigger flickering */
321 if (buttonlight_flicker_now) 438 if (buttonlight_trigger_now)
322 { 439 {
323 /* turn them on */ 440 /* turn them on */
324 buttonlight_leds = buttonlight_selected; 441 buttonlight_leds = buttonlight_selected;
@@ -326,7 +443,7 @@ static void led_control_service(void)
326 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds); 443 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
327 444
328 /* reset the trigger and go flicker the LEDs */ 445 /* reset the trigger and go flicker the LEDs */
329 buttonlight_flicker_now = 0; 446 buttonlight_trigger_now = 0;
330 buttonlight_flickering = FLICKER_PERIOD; 447 buttonlight_flickering = FLICKER_PERIOD;
331 buttonlight_state = BUTTONLIGHT_MODE_FLICKERING; 448 buttonlight_state = BUTTONLIGHT_MODE_FLICKERING;
332 } 449 }
@@ -350,7 +467,7 @@ static void led_control_service(void)
350 else 467 else
351 { 468 {
352 /* is flickering triggered again? */ 469 /* is flickering triggered again? */
353 if (!buttonlight_flicker_now) 470 if (!buttonlight_trigger_now)
354 { 471 {
355 /* completed a cycle - no new triggers - go back and wait */ 472 /* completed a cycle - no new triggers - go back and wait */
356 buttonlight_state = BUTTONLIGHT_MODE_FLICKER; 473 buttonlight_state = BUTTONLIGHT_MODE_FLICKER;
@@ -358,7 +475,7 @@ static void led_control_service(void)
358 else 475 else
359 { 476 {
360 /* reset flickering */ 477 /* reset flickering */
361 buttonlight_flicker_now = 0; 478 buttonlight_trigger_now = 0;
362 buttonlight_flickering = FLICKER_PERIOD; 479 buttonlight_flickering = FLICKER_PERIOD;
363 480
364 /* turn buttonlights on */ 481 /* turn buttonlights on */
@@ -369,6 +486,52 @@ static void led_control_service(void)
369 } 486 }
370 break; 487 break;
371 488
489
490 /* Buttonlight mode: SIGNAL / SOLID */
491 case BUTTONLIGHT_MODE_SOLID_ENTRY:
492 /* already on? turn it off */
493 if (buttonlight_current)
494 {
495 buttonlight_leds = 0x00;
496 sc606_write(SC606_REG_CONF, backlight_leds);
497 buttonlight_current = 0;
498 }
499
500 /* set the brightness if not already set */
501 /* temporary save for the next mode - then to do settings */
502 buttonlight_setting = buttonlight_trigger_brightness;
503 buttonlight_saved_state = BUTTONLIGHT_MODE_SOLID;
504 buttonlight_state = BUTTONLIGHT_HELPER_SET;
505 break;
506
507
508 case BUTTONLIGHT_MODE_SOLID:
509 /* wait for the foreground to trigger */
510 if (buttonlight_trigger_now)
511 {
512 /* turn them on if not already on */
513 if (0 == buttonlight_current)
514 {
515 buttonlight_leds = buttonlight_selected;
516 buttonlight_current = buttonlight_setting;
517 sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
518 }
519
520 /* reset the trigger */
521 buttonlight_trigger_now = 0;
522 }
523 else
524 {
525 if (buttonlight_current)
526 {
527 buttonlight_leds = 0x00;
528 sc606_write(SC606_REG_CONF, backlight_leds);
529 buttonlight_current = 0;
530 }
531 }
532 break;
533
534
372 /* set the brightness for the buttonlights - takes 2 passes */ 535 /* set the brightness for the buttonlights - takes 2 passes */
373 case BUTTONLIGHT_HELPER_SET: 536 case BUTTONLIGHT_HELPER_SET:
374 sc606_write(SC606_REG_B, buttonlight_setting-1); 537 sc606_write(SC606_REG_B, buttonlight_setting-1);
@@ -400,6 +563,9 @@ static void led_control_service(void)
400 backlight_leds = 0x00; 563 backlight_leds = 0x00;
401 sc606_write(SC606_REG_CONF, buttonlight_leds); 564 sc606_write(SC606_REG_CONF, buttonlight_leds);
402 backlight_control = BACKLIGHT_CONTROL_IDLE; 565 backlight_control = BACKLIGHT_CONTROL_IDLE;
566
567 /* turn the lcd completely off after the fade or off command */
568 lcd_enable(false);
403 break; 569 break;
404 570
405 571
@@ -514,32 +680,3 @@ void __backlight_dim(bool dim_now)
514} 680}
515 681
516 682
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 67a055449c..781fb9647b 100644
--- a/firmware/target/arm/gigabeat/meg-fx/backlight-target.h
+++ b/firmware/target/arm/gigabeat/meg-fx/backlight-target.h
@@ -34,7 +34,7 @@ enum buttonlight_selection
34/* Use these to set the buttonlight mode */ 34/* Use these to set the buttonlight mode */
35enum buttonlight_mode 35enum buttonlight_mode
36{ 36{
37 /* ON follows the setting of the backlight - same brightness */ 37 /* ON follows the setting */
38 BUTTONLIGHT_ON, 38 BUTTONLIGHT_ON,
39 39
40 /* buttonlights always off */ 40 /* buttonlights always off */
@@ -43,23 +43,37 @@ enum buttonlight_mode
43 /* buttonlights always on but set at lowest brightness */ 43 /* buttonlights always on but set at lowest brightness */
44 BUTTONLIGHT_FAINT, 44 BUTTONLIGHT_FAINT,
45 45
46 /* buttonlights flicker when triggered */ 46 /* buttonlights flicker when triggered - continues to flicker
47 * even if the flicker is still asserted.
48 */
47 BUTTONLIGHT_FLICKER, 49 BUTTONLIGHT_FLICKER,
48};
49
50 50
51/* call to flicker the button lights */ 51 /* buttonlights solid for as long as triggered */
52void __buttonlight_flicker(unsigned short brightness); 52 BUTTONLIGHT_SIGNAL,
53
54 /* buttonlights follow backlight */
55 BUTTONLIGHT_FOLLOW,
56
57 /* buttonlights show battery charging */
58 BUTTONLIGHT_CHARGING,
59};
53 60
54 61
55/* only use the XX__ENTRY when setting the mode */ 62/* Call this to flicker or signal the button lights. Only is effective for
56void __buttonlight_mode(enum buttonlight_mode mode); 63 * modes that take a trigger input.
64 */
65void __buttonlight_trigger(void);
57 66
58 67
59/* select which led to use on the button lights. Other combinations are 68/* select which led to use on the button lights. Other combinations are
60 * possible, but don't look very good. 69 * possible, but don't look very good.
61 */ 70 */
62void __buttonlight_select(enum buttonlight_selection selection); 71
72/* map the mode from the command into the state machine entries */
73/* See enum buttonlight_mode for available functions */
74void __buttonlight_mode(enum buttonlight_mode mode,
75 enum buttonlight_selection selection,
76 unsigned short brightness);
63 77
64 78
65void __backlight_init(void); 79void __backlight_init(void);
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 c5d0251323..117e1114af 100644
--- a/firmware/target/arm/gigabeat/meg-fx/button-meg-fx.c
+++ b/firmware/target/arm/gigabeat/meg-fx/button-meg-fx.c
@@ -123,8 +123,6 @@ int button_read_device(void)
123 123
124 if (touchpad & (1 << 3)) 124 if (touchpad & (1 << 3))
125 btn |= BUTTON_SELECT; 125 btn |= BUTTON_SELECT;
126
127 __buttonlight_flicker(DEFAULT_BRIGHTNESS_SETTING/2);
128 } 126 }
129 127
130 return btn; 128 return btn;