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
This commit is contained in:
Jens Arnold 2007-11-26 23:10:20 +00:00
parent e24454f8b3
commit 09a786138c
6 changed files with 88 additions and 124 deletions

View file

@ -49,7 +49,7 @@ static const char *unit_strings[] =
{
[UNIT_INT] = "", [UNIT_MS] = "ms",
[UNIT_SEC] = "s", [UNIT_MIN] = "min",
[UNIT_HOUR]= "hr", [UNIT_KHZ] = "KHz",
[UNIT_HOUR]= "hr", [UNIT_KHZ] = "kHz",
[UNIT_DB] = "dB", [UNIT_PERCENT] = "%",
[UNIT_MAH] = "mAh", [UNIT_PIXEL] = "px",
[UNIT_PER_SEC] = "per sec",
@ -168,7 +168,7 @@ static int option_talk(int selected_item, void * data)
const struct int_setting *int_info = setting->int_setting;
const struct table_setting *tbl_info = setting->table_setting;
int unit;
int32_t (*get_talk_id)(int);
int32_t (*get_talk_id)(int, int);
if ((setting->flags & F_INT_SETTING) == F_INT_SETTING)
{
unit = int_info->unit;
@ -180,7 +180,7 @@ static int option_talk(int selected_item, void * data)
get_talk_id = tbl_info->get_talk_id;
}
if (get_talk_id)
talk_id(get_talk_id((int)temp_var), false);
talk_id(get_talk_id((int)temp_var, unit), false);
else
talk_value((int)temp_var, unit, false);
}
@ -541,8 +541,9 @@ void set_option_formatter(char* buf, size_t size, int item, const char* unit)
const unsigned char *text = set_option_options[item].string;
snprintf(buf, size, "%s", P2STR(text));
}
int32_t set_option_get_talk_id(int value)
int32_t set_option_get_talk_id(int value, int unit)
{
(void)unit;
return set_option_options[value].voice_id;
}
bool set_option(const char* string, void* variable, enum optiontype type,
@ -582,7 +583,7 @@ bool set_int_ex(const unsigned char* string,
int min,
int max,
void (*formatter)(char*, size_t, int, const char*),
int32_t (*get_talk_id)(int))
int32_t (*get_talk_id)(int, int))
{
(void)unit;
struct settings_list item;

View file

@ -240,7 +240,7 @@ bool set_int_ex(const unsigned char* string, const char* unit, int voice_unit,
int* variable,
void (*function)(int), int step, int min, int max,
void (*formatter)(char*, size_t, int, const char*),
int32_t (*get_talk_id)(int));
int32_t (*get_talk_id)(int, int));
/* the following are either not in setting.c or shouldnt be */
bool set_time_screen(const char* string, struct tm *tm);

View file

@ -192,52 +192,48 @@ static const char trig_durations_conf [] =
# endif
#endif
static int32_t rectime_getlang(int value)
#endif /* HAVE_RECORDING */
static void formatter_unit_0_is_off(char *buffer, size_t buffer_size,
int val, const char *unit)
{
if (value == 0)
return LANG_OFF;
return TALK_ID(value, UNIT_SEC);
}
static void rectime_formatter(char *buffer, size_t buffer_size,
int val, const char *unit)
{
(void)unit;
if (val == 0)
strcpy(buffer, str(LANG_OFF));
else
snprintf(buffer, buffer_size, "%d s", val);
snprintf(buffer, buffer_size, "%d %s", val, unit);
}
#endif /* HAVE_RECORDING */
static int32_t getlang_unit_0_is_off(int value, int unit)
{
if (value == 0)
return LANG_OFF;
else
return TALK_ID(value,unit);
}
#ifdef HAVE_BACKLIGHT
static void backlight_formatter(char *buffer, size_t buffer_size,
int val, const char *unit)
{
(void)unit;
if (val == -1)
strcpy(buffer, str(LANG_OFF));
else if (val == 0)
strcpy(buffer, str(LANG_ON));
else
snprintf(buffer, buffer_size, "%d s", val);
snprintf(buffer, buffer_size, "%d %s", val, unit);
}
static int32_t backlight_getlang(int value)
static int32_t backlight_getlang(int value, int unit)
{
if (value == -1)
return LANG_OFF;
else if (value == 0)
return LANG_ON;
return TALK_ID(value, UNIT_SEC);
else
return TALK_ID(value, unit);
}
#endif
static int32_t scanaccel_getlang(int value)
{
if (value == 0)
return LANG_OFF;
return TALK_ID(value, UNIT_SEC);
}
static void scanaccel_formatter(char *buffer, size_t buffer_size,
static void scanaccel_formatter(char *buffer, size_t buffer_size,
int val, const char *unit)
{
(void)unit;
@ -247,40 +243,6 @@ static void scanaccel_formatter(char *buffer, size_t buffer_size,
snprintf(buffer, buffer_size, "2x/%ds", val);
}
static int32_t poweroff_idle_timer_getlang(int value)
{
if (value == 0)
return LANG_OFF;
return TALK_ID(value, UNIT_MIN);
}
static void poweroff_idle_timer_formatter(char *buffer, size_t buffer_size,
int val, const char *unit)
{
(void)unit;
if (val == 0)
strcpy(buffer, str(LANG_OFF));
else
snprintf(buffer, buffer_size, "%dm", val);
}
#ifndef HAVE_SCROLLWHEEL
static int32_t listaccel_getlang(int value)
{
if (value == 0)
return LANG_OFF;
return TALK_ID((HZ/2)*value, UNIT_MS);
}
static void listaccel_formatter(char *buffer, size_t buffer_size,
int val, const char *unit)
{
(void)unit;
if (val == 0)
strcpy(buffer, str(LANG_OFF));
else
snprintf(buffer, buffer_size, "%d ms", 5*HZ*val);
}
#endif /* HAVE_SCROLLWHEEL */
#if CONFIG_CODEC == SWCODEC
static void crossfeed_format(char* buffer, size_t buffer_size, int value,
const char* unit)
@ -469,8 +431,8 @@ const struct settings_list settings[] = {
OFFON_SETTING(0,show_icons, LANG_SHOW_ICONS ,true,"show icons", NULL),
/* system */
TABLE_SETTING(F_ALLOW_ARBITRARY_VALS, poweroff, LANG_POWEROFF_IDLE, 10,
"idle poweroff", "off", UNIT_MIN, poweroff_idle_timer_formatter,
poweroff_idle_timer_getlang, set_poweroff_timeout, 15,
"idle poweroff", "off", UNIT_MIN, formatter_unit_0_is_off,
getlang_unit_0_is_off, set_poweroff_timeout, 15,
0,1,2,3,4,5,6,7,8,9,10,15,30,45,60),
SYSTEM_SETTING(NVRAM(4),runtime,0),
SYSTEM_SETTING(NVRAM(4),topruntime,0),
@ -566,15 +528,15 @@ const struct settings_list settings[] = {
#endif
#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
/* backlight fading */
STRINGCHOICE_SETTING(0,backlight_fade_in, LANG_BACKLIGHT_FADE_IN, 1,
"backlight fade in","off,500ms,1s,2s", backlight_set_fade_in, 4,
LANG_OFF, TALK_ID(500, UNIT_MS),
TALK_ID(1, UNIT_SEC), TALK_ID(2, UNIT_SEC)),
STRINGCHOICE_SETTING(0,backlight_fade_out, LANG_BACKLIGHT_FADE_OUT, 1,
"backlight fade out","off,500ms,1s,2s,3s,5s,10s", backlight_set_fade_out, 7,
LANG_OFF, TALK_ID(500, UNIT_MS),
TALK_ID(1, UNIT_SEC), TALK_ID(2, UNIT_SEC),
TALK_ID(3, UNIT_SEC), TALK_ID(5, UNIT_SEC), TALK_ID(10, UNIT_SEC)),
TABLE_SETTING(F_ALLOW_ARBITRARY_VALS, backlight_fade_in,
LANG_BACKLIGHT_FADE_IN, 300, "backlight fade in", "off",
UNIT_MS, formatter_unit_0_is_off, getlang_unit_0_is_off,
backlight_set_fade_in, 7, 0,100,200,300,500,1000,2000),
TABLE_SETTING(F_ALLOW_ARBITRARY_VALS, backlight_fade_out,
LANG_BACKLIGHT_FADE_OUT, 2000, "backlight fade out", "off",
UNIT_MS, formatter_unit_0_is_off, getlang_unit_0_is_off,
backlight_set_fade_out, 10,
0,100,200,300,500,1000,2000,3000,5000,10000),
#endif
INT_SETTING(F_PADTITLE, scroll_speed, LANG_SCROLL_SPEED, 9,"scroll speed",
UNIT_INT, 0, 15, 1, NULL, NULL, lcd_scroll_speed),
@ -630,7 +592,7 @@ const struct settings_list settings[] = {
LANG_FFRW_STEP, 1, "scan min step", NULL, UNIT_SEC,
NULL, NULL, NULL, 14, 1,2,3,4,5,6,8,10,15,20,25,30,45,60),
INT_SETTING(0, ff_rewind_accel, LANG_FFRW_ACCEL, 3, "scan accel",
UNIT_SEC, 16, 0, -1, scanaccel_formatter, scanaccel_getlang, NULL),
UNIT_SEC, 16, 0, -1, scanaccel_formatter, getlang_unit_0_is_off, NULL),
#if (CONFIG_CODEC == SWCODEC) && !defined(HAVE_FLASH_STORAGE)
STRINGCHOICE_SETTING(0, buffer_margin, LANG_MP3BUFFER_MARGIN, 0,"antiskip",
"5s,15s,30s,1min,2min,3min,5min,10min",NULL, 8,
@ -799,8 +761,8 @@ const struct settings_list settings[] = {
HAVE_FMRADIO_REC_(",fmradio")[1]
,UNUSED},
INT_SETTING(F_RECSETTING, rec_prerecord_time, LANG_RECORD_PRERECORD_TIME,
0, "prerecording time",
UNIT_SEC, 0, 30, 1, rectime_formatter, rectime_getlang, NULL),
0, "prerecording time", UNIT_SEC, 0, 30, 1,
formatter_unit_0_is_off, getlang_unit_0_is_off, NULL),
FILENAME_SETTING(F_RECSETTING, rec_directory, "rec path",
REC_BASE_DIR, NULL, NULL, MAX_FILENAME+1),
@ -1203,10 +1165,10 @@ const struct settings_list settings[] = {
#ifndef HAVE_SCROLLWHEEL
INT_SETTING(0, list_accel_start_delay, LANG_LISTACCEL_START_DELAY,
2, "list_accel_start_delay", UNIT_MS, 0, 10, 1,
listaccel_formatter, listaccel_getlang, NULL),
formatter_unit_0_is_off, getlang_unit_0_is_off, NULL),
INT_SETTING(0, list_accel_wait, LANG_LISTACCEL_ACCEL_SPEED,
3, "list_accel_wait", UNIT_SEC, 1, 10, 1,
scanaccel_formatter, scanaccel_getlang, NULL),
scanaccel_formatter, getlang_unit_0_is_off, NULL),
#endif /* HAVE_SCROLLWHEEL */
};

View file

@ -70,7 +70,7 @@ struct int_setting {
int max;
int step;
void (*formatter)(char*, size_t, int, const char*);
int32_t (*get_talk_id)(int);
int32_t (*get_talk_id)(int, int);
};
#define F_INT_SETTING 0x80
@ -89,7 +89,7 @@ struct choice_setting {
struct table_setting {
void (*option_callback)(int);
void (*formatter)(char*, size_t, int, const char*);
int32_t (*get_talk_id)(int);
int32_t (*get_talk_id)(int, int);
int unit;
int count;
const int * values;

View file

@ -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<<BL_PWM_BITS)
/* s15.16 fixed point variables */
static int32_t bl_fade_in_step = ((BL_PWM_INTERVAL*BL_PWM_COUNT)<<16)/300;
static int32_t bl_fade_out_step = ((BL_PWM_INTERVAL*BL_PWM_COUNT)<<16)/2000;
static int32_t bl_dim_fraction = 0;
static bool bl_timer_active = false;
static int bl_dim_current = 0;
static int bl_dim_target = 0;
static int bl_pwm_counter = 0;
static volatile int bl_cycle_counter = 0;
static int bl_dim_current = 0;
static enum {DIM_STATE_START, DIM_STATE_MAIN} bl_dim_state = DIM_STATE_START;
static bool bl_timer_active = false;
static void backlight_isr(void)
{
int timer_period;
int timer_period = (TIMER_FREQ*BL_PWM_INTERVAL/1000);
bool idle = false;
timer_period = TIMER_FREQ / 1000 * BL_PWM_INTERVAL / 1000;
switch (bl_dim_state)
{
/* New cycle */
case DIM_STATE_START:
bl_pwm_counter = 0;
bl_cycle_counter++;
bl_dim_current = bl_dim_fraction >> 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

View file

@ -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);