From 09a786138c051a07c4eb16b2689faa020a9a5f34 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Mon, 26 Nov 2007 23:10:20 +0000 Subject: Allow (almost) arbitrary backlight fade in and fade out times (on targets with software PWM fading), and comvert the associated settings to table settings. * Settings system: Unify a bunch of formatters and getlang helpers. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15817 a1c6a512-1295-4272-9138-f99709370657 --- firmware/backlight.c | 85 +++++++++++++++++++++++---------------------- firmware/export/backlight.h | 4 +-- 2 files changed, 45 insertions(+), 44 deletions(-) (limited to 'firmware') diff --git a/firmware/backlight.c b/firmware/backlight.c index f3bba5b8c7..fcb7159cce 100644 --- a/firmware/backlight.c +++ b/firmware/backlight.c @@ -185,37 +185,35 @@ int _lcd_sleep_timeout = 10*HZ; #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) /* backlight fading */ -#define BL_PWM_INTERVAL 5000 /* Cycle interval in us */ -#define BL_PWM_COUNT 100 -static const char backlight_fade_value[8] = { 0, 1, 2, 4, 6, 8, 10, 20 }; -static int fade_in_count = 1; -static int fade_out_count = 4; +#define BL_PWM_INTERVAL 5 /* Cycle interval in ms */ +#define BL_PWM_BITS 8 +#define BL_PWM_COUNT (1<> 16; if (bl_dim_current > 0 && bl_dim_current < BL_PWM_COUNT) { _backlight_on_isr(); - bl_pwm_counter = bl_dim_current; - timer_period = timer_period * bl_pwm_counter / BL_PWM_COUNT; + timer_period = (timer_period * bl_dim_current) >> BL_PWM_BITS; bl_dim_state = DIM_STATE_MAIN; } else @@ -227,29 +225,25 @@ static void backlight_isr(void) if (bl_dim_current == bl_dim_target) idle = true; } - - break ; + if (bl_dim_current < bl_dim_target) + { + bl_dim_fraction = MIN(bl_dim_fraction + bl_fade_in_step, + (BL_PWM_COUNT<<16)); + } + else if (bl_dim_current > bl_dim_target) + { + bl_dim_fraction = MAX(bl_dim_fraction - bl_fade_out_step, 0); + } + break; /* Dim main screen */ case DIM_STATE_MAIN: _backlight_off_isr(); + timer_period = (timer_period * (BL_PWM_COUNT - bl_dim_current)) + >> BL_PWM_BITS; bl_dim_state = DIM_STATE_START; - timer_period = timer_period * (BL_PWM_COUNT - bl_pwm_counter) / BL_PWM_COUNT; break ; } - - if ((bl_dim_target > bl_dim_current) && (bl_cycle_counter >= fade_in_count)) - { - bl_dim_current++; - bl_cycle_counter = 0; - } - - if ((bl_dim_target < bl_dim_current) && (bl_cycle_counter >= fade_out_count)) - { - bl_dim_current--; - bl_cycle_counter = 0; - } - if (idle) { #if defined(_BACKLIGHT_FADE_BOOST) || defined(_BACKLIGHT_FADE_ENABLE) @@ -267,12 +261,12 @@ static void backlight_switch(void) if (bl_dim_target > (BL_PWM_COUNT/2)) { _backlight_on_normal(); - bl_dim_current = BL_PWM_COUNT; + bl_dim_fraction = (BL_PWM_COUNT<<16); } else { _backlight_off_normal(); - bl_dim_current = 0; + bl_dim_fraction = 0; } } @@ -311,7 +305,7 @@ static void backlight_dim(int value) static void _backlight_on(void) { - if (fade_in_count > 0) + if (bl_fade_in_step > 0) { #ifdef _BACKLIGHT_FADE_ENABLE _backlight_hw_enable(true); @@ -320,7 +314,8 @@ static void _backlight_on(void) } else { - bl_dim_target = bl_dim_current = BL_PWM_COUNT; + bl_dim_target = BL_PWM_COUNT; + bl_dim_fraction = (BL_PWM_COUNT<<16); _backlight_on_normal(); } #ifdef HAVE_LCD_SLEEP @@ -330,13 +325,13 @@ static void _backlight_on(void) static void _backlight_off(void) { - if (fade_out_count > 0) + if (bl_fade_out_step > 0) { backlight_dim(0); } else { - bl_dim_target = bl_dim_current = 0; + bl_dim_target = bl_dim_fraction = 0; _backlight_off_normal(); } #ifdef HAVE_LCD_SLEEP @@ -351,14 +346,20 @@ static void _backlight_off(void) #endif } -void backlight_set_fade_in(int index) +void backlight_set_fade_in(int value) { - fade_in_count = backlight_fade_value[index]; + if (value > 0) + bl_fade_in_step = ((BL_PWM_INTERVAL*BL_PWM_COUNT)<<16) / value; + else + bl_fade_in_step = 0; } -void backlight_set_fade_out(int index) +void backlight_set_fade_out(int value) { - fade_out_count = backlight_fade_value[index]; + if (value > 0) + bl_fade_out_step = ((BL_PWM_INTERVAL*BL_PWM_COUNT)<<16) / value; + else + bl_fade_out_step = 0; } #endif /* defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) */ @@ -588,8 +589,8 @@ void backlight_init(void) { # ifdef HAVE_BACKLIGHT_PWM_FADING /* If backlight is already on, don't fade in. */ - bl_dim_current = BL_PWM_COUNT; bl_dim_target = BL_PWM_COUNT; + bl_dim_fraction = (BL_PWM_COUNT<<16); # endif } #endif diff --git a/firmware/export/backlight.h b/firmware/export/backlight.h index 058f7960f9..3ee46c1485 100644 --- a/firmware/export/backlight.h +++ b/firmware/export/backlight.h @@ -32,8 +32,8 @@ void backlight_init(void); int backlight_get_current_timeout(void); #ifdef HAVE_BACKLIGHT_PWM_FADING -void backlight_set_fade_in(int index); -void backlight_set_fade_out(int index); +void backlight_set_fade_in(int value); +void backlight_set_fade_out(int value); #endif void backlight_set_timeout_plugged(int value); -- cgit v1.2.3