diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 813955d3b0..a3d8a03858 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -1762,3 +1762,8 @@ id: LANG_CAR_ADAPTER_MODE desc: Displayed for setting car adapter mode to on/off eng: "Car Adapter Mode" new: + +id: LANG_LINE_IN +desc: in settings_menu +eng: "Line In" +new: diff --git a/apps/settings.c b/apps/settings.c index 9b8f1b35e1..429366d8ed 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -58,11 +58,13 @@ #include "sprintf.h" #include "keyboard.h" #include "version.h" - +#ifdef HAVE_MAS3507D +#include "dac.h" +#endif struct user_settings global_settings; char rockboxdir[] = ROCKBOX_DIR; /* config/font/data file directory */ -#define CONFIG_BLOCK_VERSION 7 +#define CONFIG_BLOCK_VERSION 8 #define CONFIG_BLOCK_SIZE 512 #define RTC_BLOCK_SIZE 44 @@ -134,6 +136,7 @@ Rest of config block, only saved to disk: 0xAE fade on pause/unpause/stop setting (bit 0) caption backlight (bit 1) car adapter mode (bit 2) + line_in (Player only) (bit 3) 0xAF [available/unused] 0xB0 peak meter clip hold timeout (bit 0-4), peak meter performance (bit 7) 0xB1 peak meter release step size, peak_meter_dbfs (bit 7) @@ -405,7 +408,8 @@ int settings_save( void ) config_block[0xae] = (unsigned char) ((global_settings.fade_on_stop & 1) | ((global_settings.caption_backlight & 1) << 1) | - ((global_settings.car_adapter_mode & 1) << 2)); + ((global_settings.car_adapter_mode & 1) << 2) | + ((global_settings.line_in & 1) << 3)); config_block[0xb0] = (unsigned char)global_settings.peak_meter_clip_hold | (global_settings.peak_meter_performance ? 0x80 : 0); config_block[0xb1] = global_settings.peak_meter_release | @@ -490,7 +494,9 @@ void settings_apply(void) backlight_set_timeout(global_settings.backlight_timeout); backlight_set_on_when_charging(global_settings.backlight_on_when_charging); ata_spindown(global_settings.disk_spindown); - +#ifdef HAVE_MAS3507D + dac_line_in(global_settings.line_in); +#endif #ifdef HAVE_ATA_POWER_OFF ata_poweroff(global_settings.disk_poweroff); #endif @@ -690,6 +696,7 @@ void settings_load(void) global_settings.fade_on_stop = config_block[0xae] & 1; global_settings.caption_backlight = (config_block[0xae] >> 1) & 1; global_settings.car_adapter_mode = (config_block[0xae] >> 2) & 1; + global_settings.line_in = (config_block[0xae] >> 3) & 1; } if(config_block[0xb0] != 0xff) { @@ -1059,6 +1066,12 @@ bool settings_load_config(char* file) "9","10","15","30","45","60"}; set_cfg_option(&global_settings.poweroff, value, options, 15); } +#ifdef HAVE_MAS3507D + else if (!strcasecmp(name, "line in")){ + set_cfg_bool(&global_settings.line_in, value); + dac_line_in(global_settings.line_in); + } +#endif else if (!strcasecmp(name, "battery capacity")) set_cfg_int(&global_settings.battery_capacity, value, 1500, BATTERY_CAPACITY_MAX); @@ -1341,6 +1354,10 @@ bool settings_save_config(void) fprintf(fd, "car adapter mode: %s\r\n", boolopt[global_settings.car_adapter_mode]); +#ifdef HAVE_MAS3507D + fprintf(fd, "line in: %s\r\n", boolopt[global_settings.line_in]); +#endif + #ifdef HAVE_MAS3587F fprintf(fd, "#\r\n# Recording\r\n#\r\n"); fprintf(fd, "rec quality: %d\r\n", global_settings.rec_quality); @@ -1472,6 +1489,7 @@ void settings_reset(void) { global_settings.max_files_in_playlist = 10000; global_settings.show_icons = true; global_settings.recursive_dir_insert = RECURSE_OFF; + global_settings.line_in = false; } bool set_bool(char* string, bool* variable ) diff --git a/apps/settings.h b/apps/settings.h index 635834cac0..93516d86cf 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -171,6 +171,8 @@ struct user_settings int max_files_in_playlist; /* Max entries in playlist */ bool show_icons; /* 0=hide 1=show */ int recursive_dir_insert; /* should directories be inserted recursively */ + + bool line_in; /* false=off, true=active */ }; enum optiontype { INT, BOOL }; diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 7af267389a..d6fe1c6316 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c @@ -43,6 +43,9 @@ #include "peakmeter.h" #endif #include "lang.h" +#ifdef HAVE_MAS3507D +#include "dac.h" +#endif static bool car_adapter_mode(void) { @@ -630,6 +633,15 @@ static bool spindown(void) ata_spindown, 1, 3, 254 ); } +#ifdef HAVE_MAS3507D +static bool line_in(void) +{ + bool rc = set_bool(str(LANG_LINE_IN), &global_settings.line_in); + dac_line_in(global_settings.line_in); + return rc; +} +#endif + #ifdef HAVE_ATA_POWER_OFF static bool poweroff(void) { @@ -893,6 +905,9 @@ static bool system_settings_menu(void) struct menu_items items[] = { { str(LANG_SPINDOWN), spindown }, +#ifdef HAVE_MAS3507D + { str(LANG_LINE_IN), line_in }, +#endif #ifdef HAVE_ATA_POWER_OFF { str(LANG_POWEROFF), poweroff }, #endif diff --git a/firmware/drivers/dac.c b/firmware/drivers/dac.c index c8a5414611..4212b322f0 100644 --- a/firmware/drivers/dac.c +++ b/firmware/drivers/dac.c @@ -24,6 +24,10 @@ #ifdef HAVE_DAC3550A +static bool line_in_enabled = false; +static bool dac_enabled = false; + + int dac_volume(unsigned int left, unsigned int right, bool deemph) { int ret = 0; @@ -54,12 +58,16 @@ int dac_volume(unsigned int left, unsigned int right, bool deemph) ** Bit6: 0 = 3V 1 = 5V ** Bit5: 0 = normal 1 = low power ** Bit4: 0 = AUX2 off 1 = AUX2 on -** Bit3: 0 = AUX1 off 1 = AUX2 on +** Bit3: 0 = AUX1 off 1 = AUX1 on ** Bit2: 0 = DAC off 1 = DAC on ** Bit1: 0 = stereo 1 = mono ** Bit0: 0 = normal right amp 1 = inverted right amp ******************************************************************/ -int dac_config(int value) +/* dac_config is called once to initialize it. we will apply + our static settings because of the init flow. + dac_init -> dac_line_in -> mpeg_init -> dac_config +*/ +static int dac_config(void) { int ret = 0; unsigned char buf[2]; @@ -67,7 +75,8 @@ int dac_config(int value) i2c_begin(); buf[0] = DAC_REG_WRITE | DAC_GCFG; - buf[1] = value; + buf[1] = (dac_enabled ? 0x04 : 0) | + (line_in_enabled ? 0x08 : 0); /* send write command */ if (i2c_write(DAC_DEV_WRITE,buf,2)) @@ -79,6 +88,18 @@ int dac_config(int value) return ret; } +void dac_enable(bool enable) +{ + dac_enabled = enable; + dac_config(); +} + +void dac_line_in(bool enable) +{ + line_in_enabled = enable; + dac_config(); +} + void dac_init(void) { unsigned char buf[2]; diff --git a/firmware/drivers/dac.h b/firmware/drivers/dac.h index ef5e4e992d..dc953c1420 100644 --- a/firmware/drivers/dac.h +++ b/firmware/drivers/dac.h @@ -36,8 +36,9 @@ #define DAC_AVOL 2 #define DAC_GCFG 3 -extern int dac_volume(unsigned int left, unsigned int right, bool deemph); -extern int dac_config(int value); +extern int dac_volume(unsigned int left, unsigned int right, bool deemph); +extern void dac_enable(bool enable); +extern void dac_line_in(bool enable); extern void dac_init(void); #endif diff --git a/firmware/mpeg.c b/firmware/mpeg.c index 24b3a68008..ef6972f3e4 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c @@ -3212,7 +3212,7 @@ void mpeg_init(int volume, int bass, int treble, int balance, int loudness, mas_poll_start(1); mas_writereg(MAS_REG_KPRESCALE, 0xe9400); - dac_config(0x04); /* DAC on, all else off */ + dac_enable(true); mpeg_sound_channel_config(channel_config); #endif