Index: firmware/export/config-e200.h =================================================================== --- firmware/export/config-e200.h (revision 13956) +++ firmware/export/config-e200.h (working copy) @@ -54,6 +54,9 @@ #define MAX_BRIGHTNESS_SETTING 12 #define DEFAULT_BRIGHTNESS_SETTING 6 +/* define this if the backlight can be set to a brightness */ +#define HAVE_BACKLIGHT_SET_FADING + /* define this if you have a light associated with the buttons */ #define HAVE_BUTTON_LIGHT Index: firmware/backlight.c =================================================================== --- firmware/backlight.c (revision 13956) +++ firmware/backlight.c (working copy) @@ -341,7 +341,11 @@ #elif defined(HAVE_BACKLIGHT_SET_FADING) && !defined(SIMULATOR) /* call the enable from here - it takes longer than the disable */ lcd_enable(true); +#ifdef HAVE_LCD_SLEEP + __backlight_dim(false, false); +#else __backlight_dim(false); +#endif #else __backlight_on(); #endif @@ -361,7 +365,11 @@ __backlight_off(); } #elif defined(HAVE_BACKLIGHT_SET_FADING) && !defined(SIMULATOR) +#ifdef HAVE_LCD_SLEEP + __backlight_dim(true, lcd_sleep_timeout < 0); +#else __backlight_dim(true); +#endif #else __backlight_off(); #endif @@ -370,8 +378,11 @@ /* Start LCD sleep countdown */ if (lcd_sleep_timeout < 0) { +#ifndef HAVE_BACKLIGHT_SET_FADING /* these targets will lcd_sleep() + when fade is finished */ lcd_sleep_timer = 0; /* Setting == Always */ lcd_sleep(); +#endif } else lcd_sleep_timer = lcd_sleep_timeout; Index: firmware/target/arm/sandisk/sansa-e200/backlight-target.h =================================================================== --- firmware/target/arm/sandisk/sansa-e200/backlight-target.h (revision 13956) +++ firmware/target/arm/sandisk/sansa-e200/backlight-target.h (working copy) @@ -18,12 +18,13 @@ ****************************************************************************/ #ifndef BACKLIGHT_TARGET_H #define BACKLIGHT_TARGET_H +#include "stdbool.h" #define __backlight_init() true void __backlight_on(void); void __backlight_off(void); +void __backlight_dim(bool dim_now, bool sleep_now); void __backlight_set_brightness(int brightness); -int __backlight_is_on(void); void __button_backlight_on(void); void __button_backlight_off(void); Index: firmware/target/arm/sandisk/sansa-e200/backlight-e200.c =================================================================== --- firmware/target/arm/sandisk/sansa-e200/backlight-e200.c (revision 13956) +++ firmware/target/arm/sandisk/sansa-e200/backlight-e200.c (working copy) @@ -23,6 +23,7 @@ #include "i2c-pp.h" static unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; +static short current_brightness = DEFAULT_BRIGHTNESS_SETTING; void __backlight_set_brightness(int brightness) { @@ -38,11 +39,13 @@ { lcd_enable(true); /* power on lcd */ pp_i2c_send( 0x46, 0x23, backlight_brightness); + current_brightness = backlight_brightness; } void __backlight_off(void) { pp_i2c_send( 0x46, 0x23, 0x0); + current_brightness = 0; lcd_enable(false); /* power off lcd */ } @@ -56,3 +59,53 @@ { GPIOG_OUTPUT_VAL &=~ 0x80; } +static bool turning_off = false; +static bool task_running = false; +static unsigned int count; +static void backlight_dimmer_ticktask(void) +{ + bool end = false; + if (++count%(HZ/25)) + return; + if (turning_off) + { + if (current_brightness <= 0) + { + end = true; + backlight_off(); + } + else current_brightness--; + } + else + { + if (current_brightness >= backlight_brightness) + end = true; + else current_brightness++; + } + if (end) + { + tick_remove_task(backlight_dimmer_ticktask); + task_running = false; + } + else + pp_i2c_send( 0x46, 0x23, current_brightness); +} + +void __backlight_dim(bool dim_now, bool sleep_now) +{ + if ((dim_now == true) && !task_running + && current_brightness<=0) + { + lcd_enable(false); + if (sleep_now) + lcd_sleep(); + return; + } + turning_off = dim_now; + count = 0; + if (!task_running) + { + task_running = true; + tick_add_task(backlight_dimmer_ticktask); + } +}