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/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,45 @@ { GPIOG_OUTPUT_VAL &=~ 0x80; } +static bool turning_off = false; +static bool task_running = false; +static void backlight_dimmer_ticktask(void) +{ + bool end = false; + if (turning_off) + { + if (current_brightness <= 0) + { + end = true; + } + else current_brightness--; + if (current_brightness < 0) + current_brightness = 0; + } + else + { + lcd_enable(true); + if (current_brightness >= backlight_brightness) + end = true; + else current_brightness++; + } + if (end) + { + // if (turning_off) + // lcd_enable(false); + tick_remove_task(backlight_dimmer_ticktask); + task_running = false; + } + else + pp_i2c_send( 0x46, 0x23, current_brightness); +} + +void __backlight_dim(bool dim_now) +{ + turning_off = dim_now; + if (!task_running) + { + task_running = true; + tick_add_task(backlight_dimmer_ticktask); + } +}