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 set_battery_capacity(global_settings
.battery_capacity
);
856 #if BATTERY_TYPES_COUNT > 1
857 set_battery_type(global_settings
.battery_type
);
860 #ifdef HAVE_LCD_BITMAP
861 #ifdef HAVE_LCD_INVERT
862 lcd_set_invert_display(global_settings
.invert
);
865 lcd_set_flip(global_settings
.flip_display
);
866 button_set_flip(global_settings
.flip_display
);
868 lcd_update(); /* refresh after flipping the screen */
869 settings_apply_pm_range();
870 peak_meter_init_times(
871 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
872 global_settings
.peak_meter_clip_hold
);
876 audiohw_enable_speaker(global_settings
.speaker_enabled
);
882 #ifdef HAVE_LCD_BITMAP
884 const char *font_path
= get_user_file_path(FONT_DIR
, 0, dir
, sizeof(dir
));
885 /* fonts need to be loaded before the WPS */
886 if (global_settings
.font_file
[0]
887 && global_settings
.font_file
[0] != '-') {
889 snprintf(buf
, sizeof buf
, "%s/%s.fnt", font_path
,
890 global_settings
.font_file
);
891 CHART2(">font_load ", global_settings
.font_file
);
892 rc
= font_load(NULL
, buf
);
893 CHART2("<font_load ", global_settings
.font_file
);
899 #ifdef HAVE_REMOTE_LCD
900 if ( global_settings
.remote_font_file
[0]
901 && global_settings
.remote_font_file
[0] != '-') {
902 snprintf(buf
, sizeof buf
, "%s/%s.fnt", font_path
,
903 global_settings
.remote_font_file
);
904 CHART2(">font_load_remoteui ", global_settings
.remote_font_file
);
905 rc
= font_load_remoteui(buf
);
906 CHART2("<font_load_remoteui ", global_settings
.remote_font_file
);
908 font_load_remoteui(NULL
);
911 font_load_remoteui(NULL
);
913 if ( global_settings
.kbd_file
[0]) {
914 snprintf(buf
, sizeof buf
, "%s/%s.kbd",
915 get_user_file_path(ROCKBOX_DIR
, 0, dir
, sizeof(dir
)),
916 global_settings
.kbd_file
);
923 #endif /* HAVE_LCD_BITMAP */
924 /* no get_user_file_path() here because we don't really support
925 * langs that don't come with rockbox */
926 if ( global_settings
.lang_file
[0]) {
927 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
928 global_settings
.lang_file
);
929 CHART(">lang_core_load");
931 CHART("<lang_core_load");
933 talk_init(); /* use voice of same language */
937 /* load the icon set */
938 CHART(">icons_init");
940 CHART("<icons_init");
942 #ifdef HAVE_LCD_COLOR
943 if (global_settings
.colors_file
[0])
945 CHART(">read_color_theme_file");
946 read_color_theme_file();
947 CHART("<read_color_theme_file");
951 #ifdef HAVE_LCD_COLOR
952 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
953 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
954 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
955 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
956 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
959 #ifdef HAVE_LCD_BITMAP
960 lcd_scroll_step(global_settings
.scroll_step
);
961 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
962 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
964 lcd_bidir_scroll(global_settings
.bidir_limit
);
965 lcd_scroll_delay(global_settings
.scroll_delay
);
968 CHART(">set_codepage");
969 set_codepage(global_settings
.default_codepage
);
970 CHART("<set_codepage");
972 #if CONFIG_CODEC == SWCODEC
973 #ifdef HAVE_CROSSFADE
974 audio_set_crossfade(global_settings
.crossfade
);
976 dsp_set_replaygain();
977 dsp_set_crossfeed(global_settings
.crossfeed
);
978 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
979 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
980 global_settings
.crossfeed_hf_attenuation
,
981 global_settings
.crossfeed_hf_cutoff
);
983 /* Configure software equalizer, hardware eq is handled in audio_init() */
984 dsp_set_eq(global_settings
.eq_enabled
);
985 dsp_set_eq_precut(global_settings
.eq_precut
);
986 for(i
= 0; i
< 5; i
++) {
990 dsp_dither_enable(global_settings
.dithering_enabled
);
991 dsp_timestretch_enable(global_settings
.timestretch_enabled
);
992 dsp_set_compressor(global_settings
.compressor_threshold
,
993 global_settings
.compressor_makeup_gain
,
994 global_settings
.compressor_ratio
,
995 global_settings
.compressor_knee
,
996 global_settings
.compressor_release_time
);
999 #ifdef HAVE_SPDIF_POWER
1000 spdif_power_enable(global_settings
.spdif_enable
);
1003 #ifdef HAVE_BACKLIGHT
1004 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
1005 #ifdef HAVE_REMOTE_LCD
1006 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
1008 #ifdef HAS_BUTTON_HOLD
1009 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
1011 #ifdef HAVE_LCD_SLEEP_SETTING
1012 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
1014 #endif /* HAVE_BACKLIGHT */
1016 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
1017 touchpad_set_sensitivity(global_settings
.touchpad_sensitivity
);
1020 #ifdef HAVE_USB_CHARGING_ENABLE
1021 usb_charging_enable(global_settings
.usb_charging
);
1024 #ifdef HAVE_TOUCHSCREEN
1025 touchscreen_set_mode(global_settings
.touch_mode
);
1026 memcpy(&calibration_parameters
, &global_settings
.ts_calibration_data
, sizeof(struct touchscreen_parameter
));
1029 /* This should stay last */
1030 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1031 enc_global_settings_apply();
1033 #ifdef HAVE_LCD_BITMAP
1034 /* already called with THEME_STATUSBAR in settings_apply_skins() */
1035 CHART(">viewportmanager_theme_changed");
1036 viewportmanager_theme_changed(THEME_UI_VIEWPORT
|THEME_LANGUAGE
|THEME_BUTTONBAR
);
1037 CHART("<viewportmanager_theme_changed");
1043 * reset all settings to their default value
1045 void reset_setting(const struct settings_list
*setting
, void *var
)
1047 switch (setting
->flags
&F_T_MASK
)
1050 setting
->custom_setting
->set_default(setting
->setting
,
1051 setting
->default_val
.custom
);
1055 if (setting
->flags
&F_DEF_ISFUNC
)
1056 *(int*)var
= setting
->default_val
.func();
1057 else if (setting
->flags
&F_T_SOUND
)
1058 *(int*)var
= sound_default(setting
->sound_setting
->setting
);
1059 else *(int*)var
= setting
->default_val
.int_
;
1062 *(bool*)var
= setting
->default_val
.bool_
;
1066 strlcpy((char*)var
, setting
->default_val
.charptr
,
1067 setting
->filename_setting
->max_len
);
1072 void settings_reset(void)
1076 for(i
=0; i
<nb_settings
; i
++)
1077 reset_setting(&settings
[i
], settings
[i
].setting
);
1078 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1079 enc_global_settings_reset();
1083 /** Changing setting values **/
1084 const struct settings_list
* find_setting(const void* variable
, int *id
)
1087 for(i
=0;i
<nb_settings
;i
++)
1089 if (settings
[i
].setting
== variable
)
1093 return &settings
[i
];
1099 bool set_bool(const char* string
, const bool* variable
)
1101 return set_bool_options(string
, variable
,
1102 (char *)STR(LANG_SET_BOOL_YES
),
1103 (char *)STR(LANG_SET_BOOL_NO
),
1108 bool set_bool_options(const char* string
, const bool* variable
,
1109 const char* yes_str
, int yes_voice
,
1110 const char* no_str
, int no_voice
,
1111 void (*function
)(bool))
1113 struct opt_items names
[] = {
1114 {(unsigned const char *)no_str
, no_voice
},
1115 {(unsigned const char *)yes_str
, yes_voice
}
1119 result
= set_option(string
, variable
, BOOL
, names
, 2,
1120 (void (*)(int))function
);
1124 bool set_int(const unsigned char* string
,
1127 const int* variable
,
1128 void (*function
)(int),
1132 const char* (*formatter
)(char*, size_t, int, const char*) )
1134 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
1135 step
, min
, max
, formatter
, NULL
);
1138 bool set_int_ex(const unsigned char* string
,
1141 const int* variable
,
1142 void (*function
)(int),
1146 const char* (*formatter
)(char*, size_t, int, const char*),
1147 int32_t (*get_talk_id
)(int, int))
1150 struct settings_list item
;
1151 struct int_setting data
= {
1152 function
, voice_unit
, min
, max
, step
,
1153 formatter
, get_talk_id
1155 item
.int_setting
= &data
;
1156 item
.flags
= F_INT_SETTING
|F_T_INT
;
1158 item
.cfg_vals
= (char*)string
;
1159 item
.setting
= (void *)variable
;
1160 return option_screen(&item
, NULL
, false, NULL
);
1164 static const struct opt_items
*set_option_options
;
1165 static const char* set_option_formatter(char* buf
, size_t size
, int item
, const char* unit
)
1167 (void)buf
, (void)unit
, (void)size
;
1168 return P2STR(set_option_options
[item
].string
);
1171 static int32_t set_option_get_talk_id(int value
, int unit
)
1174 return set_option_options
[value
].voice_id
;
1177 bool set_option(const char* string
, const void* variable
, enum optiontype type
,
1178 const struct opt_items
* options
,
1179 int numoptions
, void (*function
)(int))
1182 struct settings_list item
;
1183 struct int_setting data
= {
1184 function
, UNIT_INT
, 0, numoptions
-1, 1,
1185 set_option_formatter
, set_option_get_talk_id
1187 set_option_options
= options
;
1188 item
.int_setting
= &data
;
1189 item
.flags
= F_INT_SETTING
|F_T_INT
;
1191 item
.cfg_vals
= (char*)string
;
1192 item
.setting
= &temp
;
1194 temp
= *(bool*)variable
? 1: 0;
1196 temp
= *(int*)variable
;
1197 if (!option_screen(&item
, NULL
, false, NULL
))
1201 *(bool*)variable
= (temp
== 1);
1203 *(int*)variable
= temp
;
1210 * Takes filename, removes the directory and the extension,
1211 * and then copies the basename into setting, unless the basename exceeds maxlen
1213 void set_file(const char* filename
, char* setting
, const int maxlen
)
1215 const char* fptr
= strrchr(filename
,'/');
1225 extptr
= strrchr(fptr
, '.');
1227 if (!extptr
|| extptr
< fptr
)
1230 extlen
= strlen(extptr
);
1232 len
= strlen(fptr
) - extlen
+ 1;
1234 /* error if filename isn't in ROCKBOX_DIR */
1238 strlcpy(setting
, fptr
, len
);