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;
121 int fd
= open(NVRAM_FILE
, O_RDONLY
);
125 memset(buf
,0,max_len
);
126 bytes
= read(fd
,buf
,max_len
);
128 if (bytes
< 8) /* min is 8 bytes,magic, ver, vars, crc32 */
131 memset(buf
,0,max_len
);
133 for (i
=0; i
< max_len
; i
++ )
134 buf
[i
] = rtc_read(0x14+i
);
136 /* check magic, version */
137 if ((buf
[0] != 'R') || (buf
[1] != 'b')
138 || (buf
[2] != NVRAM_CONFIG_VERSION
))
141 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
142 max_len
-NVRAM_DATA_START
-1,0xffffffff);
143 if (memcmp(&crc32
,&buf
[4],4))
145 /* all good, so read in the settings */
147 buf_pos
= NVRAM_DATA_START
;
148 for(i
=0; i
<nb_settings
; i
++)
150 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
151 >>F_NVRAM_MASK_SHIFT
;
154 if ((var_count
>0) && (buf_pos
<max_len
))
156 memcpy(settings
[i
].setting
,&buf
[buf_pos
],nvram_bytes
);
157 buf_pos
+= nvram_bytes
;
160 else /* should only happen when new items are added to the end */
162 memcpy(settings
[i
].setting
, &settings
[i
].default_val
, nvram_bytes
);
168 static bool write_nvram_data(char* buf
, int max_len
)
170 unsigned crc32
= 0xffffffff;
171 int i
= 0, buf_pos
= 0;
176 memset(buf
,0,max_len
);
178 buf
[0] = 'R'; buf
[1] = 'b';
179 buf
[2] = NVRAM_CONFIG_VERSION
;
180 buf_pos
= NVRAM_DATA_START
;
181 for(i
=0; (i
<nb_settings
) && (buf_pos
<max_len
); i
++)
183 int nvram_bytes
= (settings
[i
].flags
&F_NVRAM_BYTES_MASK
)
184 >>F_NVRAM_MASK_SHIFT
;
187 memcpy(&buf
[buf_pos
],settings
[i
].setting
,nvram_bytes
);
188 buf_pos
+= nvram_bytes
;
192 /* count and crc32 */
194 crc32
= crc_32(&buf
[NVRAM_DATA_START
],
195 max_len
-NVRAM_DATA_START
-1,0xffffffff);
196 memcpy(&buf
[4],&crc32
,4);
198 fd
= open(NVRAM_FILE
,O_CREAT
|O_TRUNC
|O_WRONLY
, 0666);
201 int len
= write(fd
,buf
,max_len
);
207 /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so
208 that it would write a number of bytes at a time since the RTC chip
209 supports that, but this will have to do for now 8-) */
210 for (i
=0; i
< NVRAM_BLOCK_SIZE
; i
++ ) {
211 int r
= rtc_write(0x14+i
, buf
[i
]);
219 /** Reading from a config file **/
221 * load settings from disk or RTC RAM
223 void settings_load(int which
)
225 if (which
&SETTINGS_RTC
)
226 read_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
227 if (which
&SETTINGS_HD
)
229 settings_load_config(CONFIGFILE
, false);
230 settings_load_config(FIXEDSETTINGSFILE
, false);
234 bool cfg_string_to_int(int setting_id
, int* out
, const char* str
)
236 const char* start
= settings
[setting_id
].cfg_vals
;
242 end
= strchr(start
, ',');
245 if (!strcmp(str
, start
))
252 strlcpy(temp
, start
, end
-start
+1);
253 if (!strcmp(str
, temp
))
264 bool settings_load_config(const char* file
, bool apply
)
271 fd
= open_utf8(file
, O_RDONLY
);
275 while (read_line(fd
, line
, sizeof line
) > 0)
277 if (!settings_parseline(line
, &name
, &value
))
279 for(i
=0; i
<nb_settings
; i
++)
281 if (settings
[i
].cfg_name
== NULL
)
283 if (!strcasecmp(name
,settings
[i
].cfg_name
))
285 switch (settings
[i
].flags
&F_T_MASK
)
288 settings
[i
].custom_setting
->load_from_cfg(settings
[i
].setting
, value
);
292 #ifdef HAVE_LCD_COLOR
293 if (settings
[i
].flags
&F_RGB
)
294 hex_to_rgb(value
, (int*)settings
[i
].setting
);
297 if (settings
[i
].cfg_vals
== NULL
)
299 *(int*)settings
[i
].setting
= atoi(value
);
303 int temp
, *v
= (int*)settings
[i
].setting
;
304 bool found
= cfg_string_to_int(i
, &temp
, value
);
307 if (settings
[i
].flags
&F_TABLE_SETTING
)
308 *v
= settings
[i
].table_setting
->values
[temp
];
313 { /* atoi breaks choice settings because they
314 * don't have int-like values, and would
315 * fall back to the first value (i.e. 0)
317 if (!(settings
[i
].flags
&F_CHOICE_SETTING
))
325 if (cfg_string_to_int(i
,&temp
,value
))
326 *(bool*)settings
[i
].setting
= (temp
!=0);
327 if (settings
[i
].bool_setting
->option_callback
)
328 settings
[i
].bool_setting
->option_callback(temp
!=0);
334 char storage
[MAX_PATH
];
335 if (settings
[i
].filename_setting
->prefix
)
337 const char *dir
= settings
[i
].filename_setting
->prefix
;
338 size_t len
= strlen(dir
);
339 if (!strncasecmp(value
, dir
, len
))
341 strlcpy(storage
, &value
[len
], MAX_PATH
);
343 else strlcpy(storage
, value
, MAX_PATH
);
345 else strlcpy(storage
, value
, MAX_PATH
);
346 if (settings
[i
].filename_setting
->suffix
)
348 char *s
= strcasestr(storage
,settings
[i
].filename_setting
->suffix
);
351 strlcpy((char*)settings
[i
].setting
, storage
,
352 settings
[i
].filename_setting
->max_len
);
357 } /* if (!strcmp(name,settings[i].cfg_name)) */
365 settings_apply(true);
366 settings_apply_skins();
371 /** Writing to a config file and saving settings **/
373 bool cfg_int_to_string(int setting_id
, int val
, char* buf
, int buf_len
)
375 int flags
= settings
[setting_id
].flags
;
376 const char* start
= settings
[setting_id
].cfg_vals
;
380 if ((flags
&F_T_MASK
)==F_T_INT
&&
381 flags
&F_TABLE_SETTING
)
383 const int *value
= settings
[setting_id
].table_setting
->values
;
386 end
= strchr(start
,',');
387 if (value
[count
] == val
)
390 strlcpy(buf
, start
, buf_len
);
393 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
394 strlcpy(buf
, start
, len
+1);
410 start
= strchr(start
,',');
416 end
= strchr(start
,',');
418 strlcpy(buf
, start
, buf_len
);
421 int len
= (buf_len
> (end
-start
))? end
-start
: buf_len
;
422 strlcpy(buf
, start
, len
+1);
427 bool cfg_to_string(int i
/*setting_id*/, char* buf
, int buf_len
)
429 switch (settings
[i
].flags
&F_T_MASK
)
432 settings
[i
].custom_setting
->write_to_cfg(settings
[i
].setting
,
437 #ifdef HAVE_LCD_COLOR
438 if (settings
[i
].flags
&F_RGB
)
440 int colour
= *(int*)settings
[i
].setting
;
441 snprintf(buf
,buf_len
,"%02x%02x%02x",
442 (int)RGB_UNPACK_RED(colour
),
443 (int)RGB_UNPACK_GREEN(colour
),
444 (int)RGB_UNPACK_BLUE(colour
));
448 if (settings
[i
].cfg_vals
== NULL
)
450 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
454 if (cfg_int_to_string(i
, *(int*)settings
[i
].setting
,
455 buf
, buf_len
) == false)
457 snprintf(buf
,buf_len
,"%d",*(int*)settings
[i
].setting
);
465 *(bool*)settings
[i
].setting
==false?0:1, buf
, buf_len
);
469 if (((char*)settings
[i
].setting
)[0]
470 && settings
[i
].filename_setting
->prefix
)
472 if (((char*)settings
[i
].setting
)[0] == '-')
479 snprintf(buf
,buf_len
,"%s%s%s",
480 settings
[i
].filename_setting
->prefix
,
481 (char*)settings
[i
].setting
,
482 settings
[i
].filename_setting
->suffix
);
485 else strlcpy(buf
,(char*)settings
[i
].setting
,
486 settings
[i
].filename_setting
->max_len
);
493 static bool is_changed(int setting_id
)
495 const struct settings_list
*setting
= &settings
[setting_id
];
496 switch (setting
->flags
&F_T_MASK
)
499 return setting
->custom_setting
->is_changed(setting
->setting
,
500 setting
->default_val
.custom
);
504 if (setting
->flags
&F_DEF_ISFUNC
)
506 if (*(int*)setting
->setting
== setting
->default_val
.func())
509 else if (setting
->flags
&F_T_SOUND
)
511 if (*(int*)setting
->setting
==
512 sound_default(setting
->sound_setting
->setting
))
515 else if (*(int*)setting
->setting
== setting
->default_val
.int_
)
519 if (*(bool*)setting
->setting
== setting
->default_val
.bool_
)
524 if (!strcmp((char*)setting
->setting
, setting
->default_val
.charptr
))
531 static bool settings_write_config(const char* filename
, int options
)
535 char value
[MAX_PATH
];
536 fd
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
, 0666);
539 fdprintf(fd
, "# .cfg file created by rockbox %s - "
540 "http://www.rockbox.org\r\n\r\n", rbversion
);
541 for(i
=0; i
<nb_settings
; i
++)
543 if (settings
[i
].cfg_name
== NULL
)
549 case SETTINGS_SAVE_CHANGED
:
553 case SETTINGS_SAVE_SOUND
:
554 if ((settings
[i
].flags
&F_SOUNDSETTING
) == 0)
557 case SETTINGS_SAVE_THEME
:
558 if ((settings
[i
].flags
&F_THEMESETTING
) == 0)
561 #ifdef HAVE_RECORDING
562 case SETTINGS_SAVE_RECPRESETS
:
563 if ((settings
[i
].flags
&F_RECSETTING
) == 0)
567 #if CONFIG_CODEC == SWCODEC
568 case SETTINGS_SAVE_EQPRESET
:
569 if ((settings
[i
].flags
&F_EQSETTING
) == 0)
575 cfg_to_string(i
, value
, MAX_PATH
);
576 fdprintf(fd
,"%s: %s\r\n",settings
[i
].cfg_name
,value
);
582 static void flush_global_status_callback(void *data
)
585 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
588 static void flush_config_block_callback(void *data
)
591 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
592 settings_write_config(CONFIGFILE
, SETTINGS_SAVE_CHANGED
);
596 * persist all runtime user settings to disk or RTC RAM
598 static void update_runtime(void)
602 elapsed_secs
= (current_tick
- lasttime
) / HZ
;
603 global_status
.runtime
+= elapsed_secs
;
604 lasttime
+= (elapsed_secs
* HZ
);
606 if ( global_status
.runtime
> global_status
.topruntime
)
607 global_status
.topruntime
= global_status
.runtime
;
610 void status_save(void)
614 /* this will be done in the storage_callback if
615 target doesnt have rtc ram */
616 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
618 register_storage_idle_func(flush_global_status_callback
);
622 int settings_save(void)
626 /* this will be done in the storage_callback if
627 target doesnt have rtc ram */
628 write_nvram_data(nvram_buffer
,NVRAM_BLOCK_SIZE
);
630 register_storage_idle_func(flush_config_block_callback
);
634 bool settings_save_config(int options
)
636 char filename
[MAX_PATH
];
637 const char *folder
, *namebase
;
640 case SETTINGS_SAVE_THEME
:
644 #ifdef HAVE_RECORDING
645 case SETTINGS_SAVE_RECPRESETS
:
646 folder
= RECPRESETS_DIR
;
647 namebase
= "recording";
650 #if CONFIG_CODEC == SWCODEC
651 case SETTINGS_SAVE_EQPRESET
:
656 case SETTINGS_SAVE_SOUND
:
657 folder
= ROCKBOX_DIR
;
661 folder
= ROCKBOX_DIR
;
665 create_numbered_filename(filename
, folder
, namebase
, ".cfg", 2
666 IF_CNFN_NUM_(, NULL
));
668 /* allow user to modify filename */
670 if (!kbd_input(filename
, sizeof filename
)) {
678 if (settings_write_config(filename
, options
))
679 splash(HZ
, ID2P(LANG_SETTINGS_SAVED
));
681 splash(HZ
, ID2P(LANG_FAILED
));
685 /** Apply and Reset settings **/
688 #ifdef HAVE_LCD_BITMAP
690 * Applies the range infos stored in global_settings to
693 void settings_apply_pm_range(void)
697 /* depending on the scale mode (dBfs or percent) the values
698 of global_settings.peak_meter_dbfs have different meanings */
699 if (global_settings
.peak_meter_dbfs
)
701 /* convert to dBfs * 100 */
702 pm_min
= -(((int)global_settings
.peak_meter_min
) * 100);
703 pm_max
= -(((int)global_settings
.peak_meter_max
) * 100);
707 /* percent is stored directly -> no conversion */
708 pm_min
= global_settings
.peak_meter_min
;
709 pm_max
= global_settings
.peak_meter_max
;
712 /* apply the range */
713 peak_meter_init_range(global_settings
.peak_meter_dbfs
, pm_min
, pm_max
);
715 #endif /* HAVE_LCD_BITMAP */
717 void sound_settings_apply(void)
719 #if CONFIG_CODEC == SWCODEC
720 sound_set_dsp_callback(dsp_callback
);
722 #ifdef AUDIOHW_HAVE_BASS
723 sound_set(SOUND_BASS
, global_settings
.bass
);
725 #ifdef AUDIOHW_HAVE_TREBLE
726 sound_set(SOUND_TREBLE
, global_settings
.treble
);
728 sound_set(SOUND_BALANCE
, global_settings
.balance
);
729 #ifndef PLATFORM_HAS_VOLUME_CHANGE
730 sound_set(SOUND_VOLUME
, global_settings
.volume
);
732 sound_set(SOUND_CHANNELS
, global_settings
.channel_config
);
733 sound_set(SOUND_STEREO_WIDTH
, global_settings
.stereo_width
);
734 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
735 sound_set(SOUND_LOUDNESS
, global_settings
.loudness
);
736 sound_set(SOUND_AVC
, global_settings
.avc
);
737 sound_set(SOUND_MDB_STRENGTH
, global_settings
.mdb_strength
);
738 sound_set(SOUND_MDB_HARMONICS
, global_settings
.mdb_harmonics
);
739 sound_set(SOUND_MDB_CENTER
, global_settings
.mdb_center
);
740 sound_set(SOUND_MDB_SHAPE
, global_settings
.mdb_shape
);
741 sound_set(SOUND_MDB_ENABLE
, global_settings
.mdb_enable
);
742 sound_set(SOUND_SUPERBASS
, global_settings
.superbass
);
744 #ifdef AUDIOHW_HAVE_BASS_CUTOFF
745 sound_set(SOUND_BASS_CUTOFF
, global_settings
.bass_cutoff
);
747 #ifdef AUDIOHW_HAVE_TREBLE_CUTOFF
748 sound_set(SOUND_TREBLE_CUTOFF
, global_settings
.treble_cutoff
);
750 #ifdef AUDIOHW_HAVE_DEPTH_3D
751 sound_set(SOUND_DEPTH_3D
, global_settings
.depth_3d
);
753 #ifdef AUDIOHW_HAVE_EQ
756 for (b
= 0; b
< AUDIOHW_EQ_BAND_NUM
; b
++)
758 int setting
= sound_enum_hw_eq_band_setting(b
, AUDIOHW_EQ_GAIN
);
759 sound_set(setting
, global_settings
.hw_eq_bands
[b
].gain
);
761 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
762 setting
= sound_enum_hw_eq_band_setting(b
, AUDIOHW_EQ_FREQUENCY
);
764 sound_set(setting
, global_settings
.hw_eq_bands
[b
].frequency
);
765 #endif /* AUDIOHW_HAVE_EQ_FREQUENCY */
766 #ifdef AUDIOHW_HAVE_EQ_WIDTH
767 setting
= sound_enum_hw_eq_band_setting(b
, AUDIOHW_EQ_WIDTH
);
769 sound_set(setting
, global_settings
.hw_eq_bands
[b
].width
);
770 #endif /* AUDIOHW_HAVE_EQ_WIDTH */
775 void settings_apply(bool read_disk
)
777 #ifdef HAVE_LCD_BITMAP
780 #if CONFIG_CODEC == SWCODEC
783 sound_settings_apply();
785 #ifdef HAVE_DISK_STORAGE
786 audio_set_buffer_margin(global_settings
.buffer_margin
);
789 #ifdef HAVE_LCD_CONTRAST
790 lcd_set_contrast(global_settings
.contrast
);
792 lcd_scroll_speed(global_settings
.scroll_speed
);
793 #ifdef HAVE_REMOTE_LCD
794 lcd_remote_set_contrast(global_settings
.remote_contrast
);
795 lcd_remote_set_invert_display(global_settings
.remote_invert
);
798 lcd_remote_set_flip(global_settings
.remote_flip_display
);
801 lcd_remote_scroll_speed(global_settings
.remote_scroll_speed
);
802 lcd_remote_scroll_step(global_settings
.remote_scroll_step
);
803 lcd_remote_scroll_delay(global_settings
.remote_scroll_delay
);
804 lcd_remote_bidir_scroll(global_settings
.remote_bidir_limit
);
805 #ifdef HAVE_REMOTE_LCD_TICKING
806 lcd_remote_emireduce(global_settings
.remote_reduce_ticking
);
808 remote_backlight_set_timeout(global_settings
.remote_backlight_timeout
);
810 remote_backlight_set_timeout_plugged(global_settings
.remote_backlight_timeout_plugged
);
812 #ifdef HAS_REMOTE_BUTTON_HOLD
813 remote_backlight_set_on_button_hold(global_settings
.remote_backlight_on_button_hold
);
815 #endif /* HAVE_REMOTE_LCD */
816 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
817 backlight_set_brightness(global_settings
.brightness
);
819 #ifdef HAVE_BACKLIGHT
820 backlight_set_timeout(global_settings
.backlight_timeout
);
822 backlight_set_timeout_plugged(global_settings
.backlight_timeout_plugged
);
824 #if defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
825 || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
826 backlight_set_fade_in(global_settings
.backlight_fade_in
);
827 backlight_set_fade_out(global_settings
.backlight_fade_out
);
830 #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
831 buttonlight_set_brightness(global_settings
.buttonlight_brightness
);
833 #ifdef HAVE_BUTTON_LIGHT
834 buttonlight_set_timeout(global_settings
.buttonlight_timeout
);
836 #ifdef HAVE_DISK_STORAGE
837 storage_spindown(global_settings
.disk_spindown
);
839 #if (CONFIG_CODEC == MAS3507D) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
840 dac_line_in(global_settings
.line_in
);
842 set_poweroff_timeout(global_settings
.poweroff
);
844 #if defined(BATTERY_CAPACITY_INC) && BATTERY_CAPACITY_INC > 0
845 /* only call if it's really exchangable */
846 set_battery_capacity(global_settings
.battery_capacity
);
849 #if BATTERY_TYPES_COUNT > 1
850 set_battery_type(global_settings
.battery_type
);
853 #ifdef HAVE_LCD_BITMAP
854 #ifdef HAVE_LCD_INVERT
855 lcd_set_invert_display(global_settings
.invert
);
858 lcd_set_flip(global_settings
.flip_display
);
859 button_set_flip(global_settings
.flip_display
);
861 lcd_update(); /* refresh after flipping the screen */
862 settings_apply_pm_range();
863 peak_meter_init_times(
864 global_settings
.peak_meter_release
, global_settings
.peak_meter_hold
,
865 global_settings
.peak_meter_clip_hold
);
869 audiohw_enable_speaker(global_settings
.speaker_enabled
);
875 #ifdef HAVE_LCD_BITMAP
876 /* fonts need to be loaded before the WPS */
877 if (global_settings
.font_file
[0]
878 && global_settings
.font_file
[0] != '-') {
880 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
881 global_settings
.font_file
);
882 CHART2(">font_load ", global_settings
.font_file
);
883 rc
= font_load(NULL
, buf
);
884 CHART2("<font_load ", global_settings
.font_file
);
890 #ifdef HAVE_REMOTE_LCD
891 if ( global_settings
.remote_font_file
[0]
892 && global_settings
.remote_font_file
[0] != '-') {
893 snprintf(buf
, sizeof buf
, FONT_DIR
"/%s.fnt",
894 global_settings
.remote_font_file
);
895 CHART2(">font_load_remoteui ", global_settings
.remote_font_file
);
896 rc
= font_load_remoteui(buf
);
897 CHART2("<font_load_remoteui ", global_settings
.remote_font_file
);
899 font_load_remoteui(NULL
);
902 font_load_remoteui(NULL
);
904 if ( global_settings
.kbd_file
[0]
905 && global_settings
.kbd_file
[0] != '-') {
906 snprintf(buf
, sizeof buf
, ROCKBOX_DIR
"/%s.kbd",
907 global_settings
.kbd_file
);
914 #endif /* HAVE_LCD_BITMAP */
915 if ( global_settings
.lang_file
[0]) {
916 snprintf(buf
, sizeof buf
, LANG_DIR
"/%s.lng",
917 global_settings
.lang_file
);
918 CHART(">lang_core_load");
920 CHART("<lang_core_load");
922 talk_init(); /* use voice of same language */
926 /* load the icon set */
927 CHART(">icons_init");
929 CHART("<icons_init");
931 #ifdef HAVE_LCD_COLOR
932 if (global_settings
.colors_file
[0]
933 && global_settings
.colors_file
[0] != '-')
935 CHART(">read_color_theme_file");
936 read_color_theme_file();
937 CHART("<read_color_theme_file");
941 #ifdef HAVE_LCD_COLOR
942 screens
[SCREEN_MAIN
].set_foreground(global_settings
.fg_color
);
943 screens
[SCREEN_MAIN
].set_background(global_settings
.bg_color
);
944 screens
[SCREEN_MAIN
].set_selector_start(global_settings
.lss_color
);
945 screens
[SCREEN_MAIN
].set_selector_end(global_settings
.lse_color
);
946 screens
[SCREEN_MAIN
].set_selector_text(global_settings
.lst_color
);
949 #ifdef HAVE_LCD_BITMAP
950 lcd_scroll_step(global_settings
.scroll_step
);
951 gui_list_screen_scroll_step(global_settings
.screen_scroll_step
);
952 gui_list_screen_scroll_out_of_view(global_settings
.offset_out_of_view
);
954 lcd_bidir_scroll(global_settings
.bidir_limit
);
955 lcd_scroll_delay(global_settings
.scroll_delay
);
958 CHART(">set_codepage");
959 set_codepage(global_settings
.default_codepage
);
960 CHART("<set_codepage");
962 #if CONFIG_CODEC == SWCODEC
963 #ifdef HAVE_CROSSFADE
964 audio_set_crossfade(global_settings
.crossfade
);
966 dsp_set_replaygain();
967 dsp_set_crossfeed(global_settings
.crossfeed
);
968 dsp_set_crossfeed_direct_gain(global_settings
.crossfeed_direct_gain
);
969 dsp_set_crossfeed_cross_params(global_settings
.crossfeed_cross_gain
,
970 global_settings
.crossfeed_hf_attenuation
,
971 global_settings
.crossfeed_hf_cutoff
);
973 /* Configure software equalizer, hardware eq is handled in audio_init() */
974 dsp_set_eq(global_settings
.eq_enabled
);
975 dsp_set_eq_precut(global_settings
.eq_precut
);
976 for(i
= 0; i
< 5; i
++) {
980 dsp_dither_enable(global_settings
.dithering_enabled
);
981 #ifdef HAVE_PITCHSCREEN
982 dsp_timestretch_enable(global_settings
.timestretch_enabled
);
984 dsp_set_compressor(global_settings
.compressor_threshold
,
985 global_settings
.compressor_makeup_gain
,
986 global_settings
.compressor_ratio
,
987 global_settings
.compressor_knee
,
988 global_settings
.compressor_release_time
);
991 #ifdef HAVE_SPDIF_POWER
992 spdif_power_enable(global_settings
.spdif_enable
);
995 #ifdef HAVE_BACKLIGHT
996 set_backlight_filter_keypress(global_settings
.bl_filter_first_keypress
);
997 #ifdef HAVE_REMOTE_LCD
998 set_remote_backlight_filter_keypress(global_settings
.remote_bl_filter_first_keypress
);
1000 #ifdef HAS_BUTTON_HOLD
1001 backlight_set_on_button_hold(global_settings
.backlight_on_button_hold
);
1003 #ifdef HAVE_LCD_SLEEP_SETTING
1004 lcd_set_sleep_after_backlight_off(global_settings
.lcd_sleep_after_backlight_off
);
1006 #endif /* HAVE_BACKLIGHT */
1008 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
1009 touchpad_set_sensitivity(global_settings
.touchpad_sensitivity
);
1012 #ifdef HAVE_USB_CHARGING_ENABLE
1013 usb_charging_enable(global_settings
.usb_charging
);
1016 #ifdef HAVE_TOUCHSCREEN
1017 touchscreen_set_mode(global_settings
.touch_mode
);
1018 memcpy(&calibration_parameters
, &global_settings
.ts_calibration_data
, sizeof(struct touchscreen_parameter
));
1021 /* This should stay last */
1022 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1023 enc_global_settings_apply();
1025 #ifdef HAVE_LCD_BITMAP
1026 /* already called with THEME_STATUSBAR in settings_apply_skins() */
1027 CHART(">viewportmanager_theme_changed");
1028 viewportmanager_theme_changed(THEME_UI_VIEWPORT
|THEME_LANGUAGE
|THEME_BUTTONBAR
);
1029 CHART("<viewportmanager_theme_changed");
1035 * reset all settings to their default value
1037 void reset_setting(const struct settings_list
*setting
, void *var
)
1039 switch (setting
->flags
&F_T_MASK
)
1042 setting
->custom_setting
->set_default(setting
->setting
,
1043 setting
->default_val
.custom
);
1047 if (setting
->flags
&F_DEF_ISFUNC
)
1048 *(int*)var
= setting
->default_val
.func();
1049 else if (setting
->flags
&F_T_SOUND
)
1050 *(int*)var
= sound_default(setting
->sound_setting
->setting
);
1051 else *(int*)var
= setting
->default_val
.int_
;
1054 *(bool*)var
= setting
->default_val
.bool_
;
1058 strlcpy((char*)var
, setting
->default_val
.charptr
,
1059 setting
->filename_setting
->max_len
);
1064 void settings_reset(void)
1068 for(i
=0; i
<nb_settings
; i
++)
1069 reset_setting(&settings
[i
], settings
[i
].setting
);
1070 #if defined (HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
1071 enc_global_settings_reset();
1075 /** Changing setting values **/
1076 const struct settings_list
* find_setting(const void* variable
, int *id
)
1079 for(i
=0;i
<nb_settings
;i
++)
1081 if (settings
[i
].setting
== variable
)
1085 return &settings
[i
];
1091 bool set_bool(const char* string
, const bool* variable
)
1093 return set_bool_options(string
, variable
,
1094 (char *)STR(LANG_SET_BOOL_YES
),
1095 (char *)STR(LANG_SET_BOOL_NO
),
1100 bool set_bool_options(const char* string
, const bool* variable
,
1101 const char* yes_str
, int yes_voice
,
1102 const char* no_str
, int no_voice
,
1103 void (*function
)(bool))
1105 struct opt_items names
[] = {
1106 {(unsigned const char *)no_str
, no_voice
},
1107 {(unsigned const char *)yes_str
, yes_voice
}
1111 result
= set_option(string
, variable
, BOOL
, names
, 2,
1112 (void (*)(int))function
);
1116 bool set_int(const unsigned char* string
,
1119 const int* variable
,
1120 void (*function
)(int),
1124 const char* (*formatter
)(char*, size_t, int, const char*) )
1126 return set_int_ex(string
, unit
, voice_unit
, variable
, function
,
1127 step
, min
, max
, formatter
, NULL
);
1130 bool set_int_ex(const unsigned char* string
,
1133 const int* variable
,
1134 void (*function
)(int),
1138 const char* (*formatter
)(char*, size_t, int, const char*),
1139 int32_t (*get_talk_id
)(int, int))
1142 struct settings_list item
;
1143 struct int_setting data
= {
1144 function
, voice_unit
, min
, max
, step
,
1145 formatter
, get_talk_id
1147 item
.int_setting
= &data
;
1148 item
.flags
= F_INT_SETTING
|F_T_INT
;
1150 item
.cfg_vals
= (char*)string
;
1151 item
.setting
= (void *)variable
;
1152 return option_screen(&item
, NULL
, false, NULL
);
1156 static const struct opt_items
*set_option_options
;
1157 static const char* set_option_formatter(char* buf
, size_t size
, int item
, const char* unit
)
1159 (void)buf
, (void)unit
, (void)size
;
1160 return P2STR(set_option_options
[item
].string
);
1163 static int32_t set_option_get_talk_id(int value
, int unit
)
1166 return set_option_options
[value
].voice_id
;
1169 bool set_option(const char* string
, const void* variable
, enum optiontype type
,
1170 const struct opt_items
* options
,
1171 int numoptions
, void (*function
)(int))
1174 struct settings_list item
;
1175 struct int_setting data
= {
1176 function
, UNIT_INT
, 0, numoptions
-1, 1,
1177 set_option_formatter
, set_option_get_talk_id
1179 set_option_options
= options
;
1180 item
.int_setting
= &data
;
1181 item
.flags
= F_INT_SETTING
|F_T_INT
;
1183 item
.cfg_vals
= (char*)string
;
1184 item
.setting
= &temp
;
1186 temp
= *(bool*)variable
? 1: 0;
1188 temp
= *(int*)variable
;
1189 if (!option_screen(&item
, NULL
, false, NULL
))
1193 *(bool*)variable
= (temp
== 1);
1195 *(int*)variable
= temp
;
1202 * Takes filename, removes the directory and the extension,
1203 * and then copies the basename into setting, unless the basename exceeds maxlen
1205 void set_file(const char* filename
, char* setting
, const int maxlen
)
1207 const char* fptr
= strrchr(filename
,'/');
1217 extptr
= strrchr(fptr
, '.');
1219 if (!extptr
|| extptr
< fptr
)
1222 extlen
= strlen(extptr
);
1224 len
= strlen(fptr
) - extlen
+ 1;
1226 /* error if filename isn't in ROCKBOX_DIR */
1230 strlcpy(setting
, fptr
, len
);