Index: firmware/export/config-e200.h =================================================================== --- firmware/export/config-e200.h (Revision 16053) +++ firmware/export/config-e200.h (Arbeitskopie) @@ -29,6 +29,9 @@ /* define this if you want album art for this target */ #define HAVE_ALBUMART +/* 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 16053) +++ firmware/backlight.c (Arbeitskopie) @@ -392,8 +392,18 @@ else { backlight_timer = backlight_timeout; - _backlight_on(); - } +#if 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 + } } #ifdef HAVE_REMOTE_LCD @@ -501,7 +511,15 @@ case BACKLIGHT_OFF: backlight_timer = 0; /* Disable the timeout */ - _backlight_off(); +#if defined(HAVE_BACKLIGHT_SET_FADING) && !defined(SIMULATOR) +#ifdef HAVE_LCD_SLEEP + __backlight_dim(true, backlight_timeout < 0); +#else + __backlight_dim(true); +#endif +#else + _backlight_off(); +#endif break; #ifdef HAVE_LCD_SLEEP Index: firmware/target/arm/sandisk/backlight-c200_e200.c =================================================================== --- firmware/target/arm/sandisk/backlight-c200_e200.c (Revision 16053) +++ firmware/target/arm/sandisk/backlight-c200_e200.c (Arbeitskopie) @@ -25,6 +25,7 @@ #include "as3514.h" static unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; +static short current_brightness = DEFAULT_BRIGHTNESS_SETTING; void _backlight_set_brightness(int brightness) { @@ -45,11 +46,13 @@ _lcd_sleep_timer = 0; /* LCD should be awake already */ #endif pp_i2c_send(AS3514_I2C_ADDR, DCDC15, backlight_brightness); + current_brightness = backlight_brightness; } void _backlight_off(void) { pp_i2c_send(AS3514_I2C_ADDR, DCDC15, 0x0); + current_brightness = 0; #ifdef HAVE_LCD_ENABLE lcd_enable(false); /* power off lcd */ #endif @@ -80,3 +83,54 @@ GPIO_CLEAR_BITWISE(GPIOB_OUTPUT_VAL, 0x10); /* The "menu" backlight */ #endif } + +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); + } +} Index: firmware/target/arm/sandisk/backlight-target.h =================================================================== --- firmware/target/arm/sandisk/backlight-target.h (Revision 16053) +++ firmware/target/arm/sandisk/backlight-target.h (Arbeitskopie) @@ -18,10 +18,12 @@ ****************************************************************************/ #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);