1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Stuart Martin
11 * RTC config saving code (C) 2002 by hessu@hes.iki.fi
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
35 #include "backlight.h"
39 #include "strcasestr.h"
42 #include "ata_idle_notify.h"
50 #ifdef HAVE_LCD_BITMAP
53 #include "peakmeter.h"
57 #include "powermgmt.h"
60 #include "rbunicode.h"
64 #include "settings_list.h"
65 #include "filetypes.h"
66 #include "option_select.h"
71 #include "skin_engine/skin_engine.h"
73 #include "statusbar-skinned.h"
74 #include "bootchart.h"
76 #if CONFIG_CODEC == MAS3507D
77 void dac_line_in(bool enable
);
79 struct user_settings global_settings
;
80 struct system_status global_status
;
82 #if CONFIG_CODEC == SWCODEC
86 #include "enc_config.h"
88 #endif /* CONFIG_CODEC == SWCODEC */
90 #define NVRAM_BLOCK_SIZE 44
92 #ifdef HAVE_LCD_BITMAP
98 #ifdef HAVE_REMOTE_LCD
99 #include "lcd-remote.h"
104 /** NVRAM stuff, if the target doesnt have NVRAM it is saved in ROCKBOX_DIR /nvram.bin **/
105 /* NVRAM is set out as
109 [3] stored variable count
111 [8-NVRAM_BLOCK_SIZE] data
113 #define NVRAM_DATA_START 8
114 static char nvram_buffer
[NVRAM_BLOCK_SIZE
];
116 static bool read_nvram_data(char* buf
, int max_len
)
118 unsigned crc32
= 0xffffffff;
119 int var_count
= 0, i
= 0, buf_pos
= 0;
122 int fd
= open(get_user_file_path(NVRAM_FILE
, IS_FILE
|NEED_WRITE
,
123 path
, sizeof(path
)), O_RDONLY
);
127 memset(buf
,0,max_len
);
128 bytes
= read(fd
,buf
,max_len
);
130 if (bytes
< 8) /* min is 8 bytes,magic, ver, vars, crc32 */
133 memset(buf
,0,max_len
);
135 for (i
=0; i
< max_len
; i
++ )
136 buf
[i
] = rtc_read(0x14+i
);
138 /* check magic, version */
139 if ((buf
[0] != 'R') || (buf
[1] != 'b')
140 || (buf
[2] != NVRAM_CONFIG_VERSION
))
143 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
144 max_len
-NVRAM_DATA_START
-1,0xffffffff);
145 if (memcmp(&crc32
,&buf
[4],4))
147 /* all good, so read in the settings */
149 buf_pos
= NVRAM_DATA_START
;
150 for(i
=0; i
<nb_settings
; i
++)
152 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
153 >>F_NVRAM_MASK_SHIFT
;
156 if ((var_count
>0) && (buf_pos
<max_len
))
158 memcpy(settings
[i
].setting
,&buf
[buf_pos
],nvram_bytes
);
159 buf_pos
+= nvram_bytes
;
162 else /* should only happen when new items are added to the end */
164 memcpy(settings
[i
].setting
, &settings
[i
].default_val
, nvram_bytes
);
170 static bool write_nvram_data(char* buf
, int max_len
)
172 unsigned crc32
= 0xffffffff;
173 int i
= 0, buf_pos
= 0;
179 memset(buf
,0,max_len
);
181 buf
[0] = 'R'; buf
[1] = 'b';
182 buf
[2] = NVRAM_CONFIG_VERSION
;
183 buf_pos
= NVRAM_DATA_START
;
184 for(i
=0; (i
<nb_settings
) && (buf_pos
<max_len
); i
++)
186 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
187 >>F_NVRAM_MASK_SHIFT
;
190 memcpy(&buf
[buf_pos
],settings
[i
].setting
,nvram_bytes
);
191 buf_pos
+= nvram_bytes
;
195 /* count and crc32 */
197 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
198 max_len
-NVRAM_DATA_START
-1,0xffffffff);
199 memcpy(&buf
[4],&crc32
,4);
201 fd
= open(get_user_file_path(NVRAM_FILE
, IS_FILE
|NEED_WRITE
,
202 path
, sizeof(path
)),O_CREAT
|O_TRUNC
|O_WRONLY
, 0666);
205 int len
= write(fd
,buf
,max_len
);
211 /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so
212 that it would write a number of bytes at a time since the RTC chip
213 supports that, but this will have to do for now 8-) */
214 for (i
=0; i
< NVRAM_BLOCK_SIZE
; i
++ ) {
215 int r
= rtc_write(0x14+i
, buf
[i
]);
223 /** Reading from a config file **/
225 * load settings from disk or RTC RAM
227 void settings_load(int which
)
229 if (which
&SETTINGS_RTC
)
230 read_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
231 if (which
&SETTINGS_HD
)
235 file
= get_user_file_path(CONFIGFILE
, IS_FILE
|NEED_WRITE
, path
, sizeof(path
));
236 settings_load_config(file
, false);
237 file
= get_user_file_path(FIXEDSETTINGSFILE
, IS_FILE
, path
, sizeof(path
));
238 settings_load_config(file
, false);
242 static bool cfg_string_to_int(int setting_id
, int* out
, const char* str
)
244 const char* start
= settings
[setting_id
].cfg_vals
;
250 end
= strchr(start
, ',');
253 if (!strcmp(str
, start
))
260 strlcpy(temp
, start
, end
-start
+1);
261 if (!strcmp(str
, temp
))
272 bool settings_load_config(const char* file
, bool apply
)
279 fd
= open_utf8(file
, O_RDONLY
);
283 while (read_line(fd
, line
, sizeof line
) > 0)
285 if (!settings_parseline(line
, &name
, &value
))
287 for(i
=0; i
<nb_settings
; i
++)
289 if (settings
[i
].cfg_name
== NULL
)
291 if (!strcasecmp(name
,settings
[i
].cfg_name
))
293 switch (settings
[i
].flags
&F_T_MASK
)
296 settings
[i
].custom_setting
->load_from_cfg(settings
[i
].setting
, value
);
300 #ifdef HAVE_LCD_COLOR
301 if (settings
[i
].flags
&F_RGB
)
302 hex_to_rgb(value
, (int*)settings
[i
].setting
);
305 if (settings
[i
].cfg_vals
== NULL
)
307 *(int*)settings
[i
].setting
= atoi(value
);
311 int temp
, *v
= (int*)settings
[i
].setting
;
312 bool found
= cfg_string_to_int(i
, &temp
, value
);
315 if (settings
[i
].flags
&F_TABLE_SETTING
)
316 *v
= settings
[i
].table_setting
->values
[temp
];
321 { /* atoi breaks choice settings because they
322 * don't have int-like values, and would
323 * fall back to the first value (i.e. 0)
325 if (!(settings
[i
].flags
&F_CHOICE_SETTING
))
333 if (cfg_string_to_int(i
,&temp
,value
))
334 *(bool*)settings
[i
].setting
= (temp
!=0);
335 if (settings
[i
].bool_setting
->option_callback
)
336 settings
[i
].bool_setting
->option_callback(temp
!=0);
342 char storage
[MAX_PATH
];
343 if (settings
[i
].filename_setting
->prefix
)
345 const char *dir
= settings
[i
].filename_setting
->prefix
;
346 size_t len
= strlen(dir
);
347 if (!strncasecmp(value
, dir
, len
))
349 strlcpy(storage
, &value
[len
], MAX_PATH
);
351 else strlcpy(storage
, value
, MAX_PATH
);
353 else strlcpy(storage
, value
, MAX_PATH
);
354 if (settings
[i
].filename_setting
->suffix
)
356 char *s
= strcasestr(storage
,settings
[i
].filename_setting
->suffix
);
359 strlcpy((char*)settings
[i
].setting
, storage
,
360 settings
[i
].filename_setting
->max_len
);
365 } /* if (!strcmp(name,settings[i].cfg_name)) */
373 settings_apply(true);
374 settings_apply_skins();
379 /** Writing to a config file and saving settings **/
381 bool cfg_int_to_string(int setting_id
, int val
, char* buf
, int buf_len
)
383 int flags
= settings
[setting_id
].flags
;
384 const char* start
= settings
[setting_id
].cfg_vals
;
388 if ((flags
&F_T_MASK
)==F_T_INT
&&
389 flags
&F_TABLE_SETTING
)
391 const int *value
= settings
[setting_id
].table_setting
->values
;
394 end
= strchr(start
,',');
395 if (value
[count
] == val
)
398 strlcpy(buf
, start
, buf_len
);
401 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
402 strlcpy(buf
, start
, len
+1);
418 start
= strchr(start
,',');
424 end
= strchr(start
,',');
426 strlcpy(buf
, start
, buf_len
);
429 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
430 strlcpy(buf
, start
, len
+1);
435 bool cfg_to_string(int i
/*setting_id*/, char* buf
, int buf_len
)
437 switch (settings
[i
].flags
&F_T_MASK
)
440 settings
[i
].custom_setting
->write_to_cfg(settings
[i
].setting
,
445 #ifdef HAVE_LCD_COLOR
446 if (settings
[i
].flags
&F_RGB
)
448 int colour
= *(int*)settings
[i
].setting
;
449 snprintf(buf
,buf_len
,"%02x%02x%02x",
450 (int)RGB_UNPACK_RED(colour
),
451 (int)RGB_UNPACK_GREEN(colour
),
452 (int)RGB_UNPACK_BLUE(colour
));
456 if (settings
[i
].cfg_vals
== NULL
)
458 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
462 if (cfg_int_to_string(i
, *(int*)settings
[i
].setting
,
463 buf
, buf_len
) == false)
465 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
473 *(bool*)settings
[i
].setting
==false?0:1, buf
, buf_len
);
477 if (((char*)settings
[i
].setting
)[0]
478 && settings
[i
].filename_setting
->prefix
)
480 if (((char*)settings
[i
].setting
)[0] == '-')
487 snprintf(buf
,buf_len
,"%s%s%s",
488 settings
[i
].filename_setting
->prefix
,
489 (char*)settings
[i
].setting
,
490 settings
[i
].filename_setting
->suffix
);
493 else strlcpy(buf
,(char*)settings
[i
].setting
,
494 settings
[i
].filename_setting
->max_len
);
501 static bool is_changed(int setting_id
)
503 const struct settings_list
*setting
= &settings
[setting_id
];
504 switch (setting
->flags
&F_T_MASK
)
507 return setting
->custom_setting
->is_changed(setting
->setting
,
508 setting
->default_val
.custom
);
512 if (setting
->flags
&F_DEF_ISFUNC
)
514 if (*(int*)setting
->setting
== setting
->default_val
.func())
517 else if (setting
->flags
&F_T_SOUND
)
519 if (*(int*)setting
->setting
==
520 sound_default(setting
->sound_setting
->setting
))
523 else if (*(int*)setting
->setting
== setting
->default_val
.int_
)
527 if (*(bool*)setting
->setting
== setting
->default_val
.bool_
)
532 if (!strcmp((char*)setting
->setting
, setting
->default_val
.charptr
))
539 static bool settings_write_config(const char* filename
, int options
)
543 char value
[MAX_PATH
];
544 fd
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
, 0666);
547 fdprintf(fd
, "# .cfg file created by rockbox %s - "
548 "http://www.rockbox.org\r\n\r\n", rbversion
);
549 for(i
=0; i
<nb_settings
; i
++)
551 if (settings
[i
].cfg_name
== NULL
)
557 case SETTINGS_SAVE_CHANGED
:
561 case SETTINGS_SAVE_SOUND
:
562 if ((settings
[i
].flags
&F_SOUNDSETTING
) == 0)
565 case SETTINGS_SAVE_THEME
:
566 if ((settings
[i
].flags
&F_THEMESETTING
) == 0)
569 #ifdef HAVE_RECORDING
570 case SETTINGS_SAVE_RECPRESETS
:
571 if ((settings
[i
].flags
&F_RECSETTING
) == 0)
575 #if CONFIG_CODEC == SWCODEC
576 case SETTINGS_SAVE_EQPRESET
:
577 if ((settings
[i
].flags
&F_EQSETTING
) == 0)
583 cfg_to_string(i
, value
, MAX_PATH
);
584 fdprintf(fd
,"%s: %s\r\n",settings
[i
].cfg_name
,value
);
590 static void flush_global_status_callback(void *data
)
593 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
596 static void flush_config_block_callback(void *data
)
600 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
601 settings_write_config(
602 get_user_file_path(CONFIGFILE
, IS_FILE
|NEED_WRITE
, path
, sizeof(path
)),
603 SETTINGS_SAVE_CHANGED
);
607 * persist all runtime user settings to disk or RTC RAM
609 static void update_runtime(void)
613 elapsed_secs
= (current_tick
- lasttime
) / HZ
;
614 global_status
.runtime
+= elapsed_secs
;
615 lasttime
+= (elapsed_secs
* HZ
);
617 if ( global_status
.runtime
> global_status
.topruntime
)
618 global_status
.topruntime
= global_status
.runtime
;
621 void status_save(void)
625 /* this will be done in the storage_callback if
626 target doesnt have rtc ram */
627 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
629 register_storage_idle_func(flush_global_status_callback
);
633 int settings_save(void)
637 /* this will be done in the storage_callback if
638 target doesnt have rtc ram */
639 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
641 register_storage_idle_func(flush_config_block_callback
);
645 bool settings_save_config(int options
)
647 char filename
[MAX_PATH
], path
[MAX_PATH
];
648 const char *folder
, *namebase
;
651 case SETTINGS_SAVE_THEME
:
655 #ifdef HAVE_RECORDING
656 case SETTINGS_SAVE_RECPRESETS
:
657 folder
= RECPRESETS_DIR
;
658 namebase
= "recording";
661 #if CONFIG_CODEC == SWCODEC
662 case SETTINGS_SAVE_EQPRESET
:
667 case SETTINGS_SAVE_SOUND
:
668 folder
= ROCKBOX_DIR
;
672 folder
= ROCKBOX_DIR
;
677 folder
= get_user_file_path(folder
, NEED_WRITE
, path
, sizeof(path
));
678 create_numbered_filename(filename
, folder
, namebase
, ".cfg", 2
679 IF_CNFN_NUM_(, NULL
));
681 /* allow user to modify filename */
683 if (!kbd_input(filename
, sizeof filename
)) {
691 if (settings_write_config(filename
, options
))
692 splash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
694 splash(HZ
, ID2P(LANG_FAILED
));
698 /** Apply and Reset settings **/
701 #ifdef HAVE_LCD_BITMAP
703 * Applies the range infos stored in global_settings to
706 void settings_apply_pm_range(void)
710 /* depending on the scale mode (dBfs or percent) the values
711 of global_settings.peak_meter_dbfs have different meanings */
712 if (global_settings
.peak_meter_dbfs
)
714 /* convert to dBfs * 100 */
715 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
716 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
720 /* percent is stored directly -> no conversion */
721 pm_min
= global_settings
.peak_meter_min
;
722 pm_max
= global_settings
.peak_meter_max
;
725 /* apply the range */
726 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
728 #endif /* HAVE_LCD_BITMAP */
730 void sound_settings_apply(void)
732 #if CONFIG_CODEC == SWCODEC
733 sound_set_dsp_callback(dsp_callback
);
735 #ifdef AUDIOHW_HAVE_BASS
736 sound_set(SOUND_BASS
, global_settings
.bass
);
738 #ifdef AUDIOHW_HAVE_TREBLE
739 sound_set(SOUND_TREBLE
, global_settings
.treble
);
741 sound_set(SOUND_BALANCE
, global_settings
.balance
);
742 sound_set(SOUND_VOLUME
, global_settings
.volume
);
743 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
744 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
745 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
746 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
747 sound_set(SOUND_AVC
, global_settings
.avc
);
748 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
749 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
750 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
751 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
752 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
753 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
755 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
756 sound_set(SOUND_BASS_CUTOFF
, global_settings
.bass_cutoff
);
758 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
759 sound_set(SOUND_TREBLE_CUTOFF
, global_settings
.treble_cutoff
);
761 #ifdef AUDIOHW_HAVE_DEPTH_3D
762 sound_set(SOUND_DEPTH_3D
, global_settings
.depth_3d
);
764 #ifdef AUDIOHW_HAVE_EQ
767 for (b
= 0; b
< AUDIOHW_EQ_BAND_NUM
; b
++)
769 int setting
= sound_enum_hw_eq_band_setting(b
, AUDIOHW_EQ_GAIN
);
770 sound_set(setting
, global_settings
.hw_eq_bands
[b
].gain
);
772 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
773 setting
= sound_enum_hw_eq_band_setting(b
, AUDIOHW_EQ_FREQUENCY
);
775 sound_set(setting
, global_settings
.hw_eq_bands
[b
].frequency
);
776 #endif /* AUDIOHW_HAVE_EQ_FREQUENCY */
777 #ifdef AUDIOHW_HAVE_EQ_WIDTH
778 setting
= sound_enum_hw_eq_band_setting(b
, AUDIOHW_EQ_WIDTH
);
780 sound_set(setting
, global_settings
.hw_eq_bands
[b
].width
);
781 #endif /* AUDIOHW_HAVE_EQ_WIDTH */
786 void settings_apply(bool read_disk
)
788 #ifdef HAVE_LCD_BITMAP
791 #if CONFIG_CODEC == SWCODEC
794 sound_settings_apply();
796 #ifdef HAVE_DISK_STORAGE
797 audio_set_buffer_margin(global_settings
.buffer_margin
);
800 #ifdef HAVE_LCD_CONTRAST
801 lcd_set_contrast(global_settings
.contrast
);
803 lcd_scroll_speed(global_settings
.scroll_speed
);
804 #ifdef HAVE_REMOTE_LCD
805 lcd_remote_set_contrast(global_settings
.remote_contrast
);
806 lcd_remote_set_invert_display(global_settings
.remote_invert
);
809 lcd_remote_set_flip(global_settings
.remote_flip_display
);
812 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
813 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
814 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
815 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
816 #ifdef HAVE_REMOTE_LCD_TICKING
817 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
819 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
821 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
823 #ifdef HAS_REMOTE_BUTTON_HOLD
824 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
826 #endif /* HAVE_REMOTE_LCD */
827 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
828 backlight_set_brightness(global_settings
.brightness
);
830 #ifdef HAVE_BACKLIGHT
831 backlight_set_timeout(global_settings
.backlight_timeout
);
833 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
835 #if defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
836 || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
837 backlight_set_fade_in(global_settings
.backlight_fade_in
);
838 backlight_set_fade_out(global_settings
.backlight_fade_out
);
841 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
842 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
844 #ifdef HAVE_BUTTON_LIGHT
845 buttonlight_set_timeout(global_settings
.buttonlight_timeout
);
847 #ifdef HAVE_DISK_STORAGE
848 storage_spindown(global_settings
.disk_spindown
);
850 #if (CONFIG_CODEC == MAS3507D) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
851 dac_line_in(global_settings
.line_in
);
853 set_poweroff_timeout(global_settings
.poweroff
);
855 #if defined(BATTERY_CAPACITY_INC) && BATTERY_CAPACITY_INC > 0
856 /* only call if it's really exchangable */
857 set_battery_capacity(global_settings
.battery_capacity
);
860 #if BATTERY_TYPES_COUNT > 1
861 set_battery_type(global_settings
.battery_type
);
864 #ifdef HAVE_LCD_BITMAP
865 #ifdef HAVE_LCD_INVERT
866 lcd_set_invert_display(global_settings
.invert
);
869 lcd_set_flip(global_settings
.flip_display
);
870 button_set_flip(global_settings
.flip_display
);
872 lcd_update(); /* refresh after flipping the screen */
873 settings_apply_pm_range();
874 peak_meter_init_times(
875 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
876 global_settings
.peak_meter_clip_hold
);
880 audiohw_enable_speaker(global_settings
.speaker_enabled
);
886 #ifdef HAVE_LCD_BITMAP
888 const char *font_path
= get_user_file_path(FONT_DIR
, 0, dir
, sizeof(dir
));
889 /* fonts need to be loaded before the WPS */
890 if (global_settings
.font_file
[0]
891 && global_settings
.font_file
[0] != '-') {
893 snprintf(buf
, sizeof buf
, "%s/%s.fnt", font_path
,
894 global_settings
.font_file
);
895 CHART2(">font_load ", global_settings
.font_file
);
896 rc
= font_load(NULL
, buf
);
897 CHART2("<font_load ", global_settings
.font_file
);
903 #ifdef HAVE_REMOTE_LCD
904 if ( global_settings
.remote_font_file
[0]
905 && global_settings
.remote_font_file
[0] != '-') {
906 snprintf(buf
, sizeof buf
, "%s/%s.fnt", font_path
,
907 global_settings
.remote_font_file
);
908 CHART2(">font_load_remoteui ", global_settings
.remote_font_file
);
909 rc
= font_load_remoteui(buf
);
910 CHART2("<font_load_remoteui ", global_settings
.remote_font_file
);
912 font_load_remoteui(NULL
);
915 font_load_remoteui(NULL
);
917 if ( global_settings
.kbd_file
[0]) {
918 snprintf(buf
, sizeof buf
, "%s/%s.kbd",
919 get_user_file_path(ROCKBOX_DIR
, 0, dir
, sizeof(dir
)),
920 global_settings
.kbd_file
);
927 #endif /* HAVE_LCD_BITMAP */
928 /* no get_user_file_path() here because we don't really support
929 * langs that don't come with rockbox */
930 if ( global_settings
.lang_file
[0]) {
931 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
932 global_settings
.lang_file
);
933 CHART(">lang_core_load");
935 CHART("<lang_core_load");
937 talk_init(); /* use voice of same language */
941 /* load the icon set */
942 CHART(">icons_init");
944 CHART("<icons_init");
946 #ifdef HAVE_LCD_COLOR
947 if (global_settings
.colors_file
[0])
949 CHART(">read_color_theme_file");
950 read_color_theme_file();
951 CHART("<read_color_theme_file");
955 #ifdef HAVE_LCD_COLOR
956 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
957 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
958 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
959 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
960 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
963 #ifdef HAVE_LCD_BITMAP
964 lcd_scroll_step(global_settings
.scroll_step
);
965 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
966 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
968 lcd_bidir_scroll(global_settings
.bidir_limit
);
969 lcd_scroll_delay(global_settings
.scroll_delay
);
972 CHART(">set_codepage");
973 set_codepage(global_settings
.default_codepage
);
974 CHART("<set_codepage");
976 #if CONFIG_CODEC == SWCODEC
977 #ifdef HAVE_CROSSFADE
978 audio_set_crossfade(global_settings
.crossfade
);
980 dsp_set_replaygain();
981 dsp_set_crossfeed(global_settings
.crossfeed
);
982 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
983 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
984 global_settings
.crossfeed_hf_attenuation
,
985 global_settings
.crossfeed_hf_cutoff
);
987 /* Configure software equalizer, hardware eq is handled in audio_init() */
988 dsp_set_eq(global_settings
.eq_enabled
);
989 dsp_set_eq_precut(global_settings
.eq_precut
);
990 for(i
= 0; i
< 5; i
++) {
994 dsp_dither_enable(global_settings
.dithering_enabled
);
995 #ifdef HAVE_PITCHSCREEN
996 dsp_timestretch_enable(global_settings
.timestretch_enabled
);
998 dsp_set_compressor(global_settings
.compressor_threshold
,
999 global_settings
.compressor_makeup_gain
,
1000 global_settings
.compressor_ratio
,
1001 global_settings
.compressor_knee
,
1002 global_settings
.compressor_release_time
);
1005 #ifdef HAVE_SPDIF_POWER
1006 spdif_power_enable(global_settings
.spdif_enable
);
1009 #ifdef HAVE_BACKLIGHT
1010 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
1011 #ifdef HAVE_REMOTE_LCD
1012 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
1014 #ifdef HAS_BUTTON_HOLD
1015 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
1017 #ifdef HAVE_LCD_SLEEP_SETTING
1018 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
1020 #endif /* HAVE_BACKLIGHT */
1022 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
1023 touchpad_set_sensitivity(global_settings
.touchpad_sensitivity
);
1026 #ifdef HAVE_USB_CHARGING_ENABLE
1027 usb_charging_enable(global_settings
.usb_charging
);
1030 #ifdef HAVE_TOUCHSCREEN
1031 touchscreen_set_mode(global_settings
.touch_mode
);
1032 memcpy(&calibration_parameters
, &global_settings
.ts_calibration_data
, sizeof(struct touchscreen_parameter
));
1035 /* This should stay last */
1036 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1037 enc_global_settings_apply();
1039 #ifdef HAVE_LCD_BITMAP
1040 /* already called with THEME_STATUSBAR in settings_apply_skins() */
1041 CHART(">viewportmanager_theme_changed");
1042 viewportmanager_theme_changed(THEME_UI_VIEWPORT
|THEME_LANGUAGE
|THEME_BUTTONBAR
);
1043 CHART("<viewportmanager_theme_changed");
1049 * reset all settings to their default value
1051 void reset_setting(const struct settings_list
*setting
, void *var
)
1053 switch (setting
->flags
&F_T_MASK
)
1056 setting
->custom_setting
->set_default(setting
->setting
,
1057 setting
->default_val
.custom
);
1061 if (setting
->flags
&F_DEF_ISFUNC
)
1062 *(int*)var
= setting
->default_val
.func();
1063 else if (setting
->flags
&F_T_SOUND
)
1064 *(int*)var
= sound_default(setting
->sound_setting
->setting
);
1065 else *(int*)var
= setting
->default_val
.int_
;
1068 *(bool*)var
= setting
->default_val
.bool_
;
1072 strlcpy((char*)var
, setting
->default_val
.charptr
,
1073 setting
->filename_setting
->max_len
);
1078 void settings_reset(void)
1082 for(i
=0; i
<nb_settings
; i
++)
1083 reset_setting(&settings
[i
], settings
[i
].setting
);
1084 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1085 enc_global_settings_reset();
1089 /** Changing setting values **/
1090 const struct settings_list
* find_setting(const void* variable
, int *id
)
1093 for(i
=0;i
<nb_settings
;i
++)
1095 if (settings
[i
].setting
== variable
)
1099 return &settings
[i
];
1105 bool set_bool(const char* string
, const bool* variable
)
1107 return set_bool_options(string
, variable
,
1108 (char *)STR(LANG_SET_BOOL_YES
),
1109 (char *)STR(LANG_SET_BOOL_NO
),
1114 bool set_bool_options(const char* string
, const bool* variable
,
1115 const char* yes_str
, int yes_voice
,
1116 const char* no_str
, int no_voice
,
1117 void (*function
)(bool))
1119 struct opt_items names
[] = {
1120 {(unsigned const char *)no_str
, no_voice
},
1121 {(unsigned const char *)yes_str
, yes_voice
}
1125 result
= set_option(string
, variable
, BOOL
, names
, 2,
1126 (void (*)(int))function
);
1130 bool set_int(const unsigned char* string
,
1133 const int* variable
,
1134 void (*function
)(int),
1138 const char* (*formatter
)(char*, size_t, int, const char*) )
1140 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
1141 step
, min
, max
, formatter
, NULL
);
1144 bool set_int_ex(const unsigned char* string
,
1147 const int* variable
,
1148 void (*function
)(int),
1152 const char* (*formatter
)(char*, size_t, int, const char*),
1153 int32_t (*get_talk_id
)(int, int))
1156 struct settings_list item
;
1157 struct int_setting data
= {
1158 function
, voice_unit
, min
, max
, step
,
1159 formatter
, get_talk_id
1161 item
.int_setting
= &data
;
1162 item
.flags
= F_INT_SETTING
|F_T_INT
;
1164 item
.cfg_vals
= (char*)string
;
1165 item
.setting
= (void *)variable
;
1166 return option_screen(&item
, NULL
, false, NULL
);
1170 static const struct opt_items
*set_option_options
;
1171 static const char* set_option_formatter(char* buf
, size_t size
, int item
, const char* unit
)
1173 (void)buf
, (void)unit
, (void)size
;
1174 return P2STR(set_option_options
[item
].string
);
1177 static int32_t set_option_get_talk_id(int value
, int unit
)
1180 return set_option_options
[value
].voice_id
;
1183 bool set_option(const char* string
, const void* variable
, enum optiontype type
,
1184 const struct opt_items
* options
,
1185 int numoptions
, void (*function
)(int))
1188 struct settings_list item
;
1189 struct int_setting data
= {
1190 function
, UNIT_INT
, 0, numoptions
-1, 1,
1191 set_option_formatter
, set_option_get_talk_id
1193 set_option_options
= options
;
1194 item
.int_setting
= &data
;
1195 item
.flags
= F_INT_SETTING
|F_T_INT
;
1197 item
.cfg_vals
= (char*)string
;
1198 item
.setting
= &temp
;
1200 temp
= *(bool*)variable
? 1: 0;
1202 temp
= *(int*)variable
;
1203 if (!option_screen(&item
, NULL
, false, NULL
))
1207 *(bool*)variable
= (temp
== 1);
1209 *(int*)variable
= temp
;
1216 * Takes filename, removes the directory and the extension,
1217 * and then copies the basename into setting, unless the basename exceeds maxlen
1219 void set_file(const char* filename
, char* setting
, const int maxlen
)
1221 const char* fptr
= strrchr(filename
,'/');
1231 extptr
= strrchr(fptr
, '.');
1233 if (!extptr
|| extptr
< fptr
)
1236 extlen
= strlen(extptr
);
1238 len
= strlen(fptr
) - extlen
+ 1;
1240 /* error if filename isn't in ROCKBOX_DIR */
1244 strlcpy(setting
, fptr
, len
);