Index: firmware/export/config/sansafuze.h =================================================================== --- firmware/export/config/sansafuze.h (revision 27202) +++ firmware/export/config/sansafuze.h (working copy) @@ -209,3 +209,6 @@ /* Define this if a programmable hotkey is mapped */ #define HAVE_HOTKEY + +/* Define this to enable dock detection and line out support */ +#define HAVE_SANSA_DOCK Index: firmware/export/config/sansae200v2.h =================================================================== --- firmware/export/config/sansae200v2.h (revision 27202) +++ firmware/export/config/sansae200v2.h (working copy) @@ -211,3 +211,6 @@ /* Define this if a programmable hotkey is mapped */ #define HAVE_HOTKEY + +/* Define this to enable dock detection and line out support */ +#define HAVE_SANSA_DOCK Index: firmware/export/as3514.h =================================================================== --- firmware/export/as3514.h (revision 27202) +++ firmware/export/as3514.h (working copy) @@ -29,6 +29,9 @@ extern void audiohw_set_master_vol(int vol_l, int vol_r); extern void audiohw_set_lineout_vol(int vol_l, int vol_r); extern void audiohw_set_sampr_dividers(int fsel); +#ifdef HAVE_SANSA_DOCK +extern void lineout_enable(int enable); +#endif /* HAVE_SANSA_DOCK */ /* Register Descriptions */ Index: firmware/target/arm/as3525/sansa-e200v2/button-target.h =================================================================== --- firmware/target/arm/as3525/sansa-e200v2/button-target.h (revision 27202) +++ firmware/target/arm/as3525/sansa-e200v2/button-target.h (working copy) @@ -28,6 +28,9 @@ #define HAS_BUTTON_HOLD bool button_hold(void); +#ifdef HAVE_SANSA_DOCK +int dock_connect(void); +#endif /* HAVE_SANSA_DOCK */ void button_init_device(void); int button_read_device(void); unsigned short button_read_dbop(void); Index: firmware/target/arm/as3525/button-e200v2-fuze.c =================================================================== --- firmware/target/arm/as3525/button-e200v2-fuze.c (revision 27202) +++ firmware/target/arm/as3525/button-e200v2-fuze.c (working copy) @@ -43,6 +43,12 @@ static bool hold_button_old = false; #endif +#ifdef HAVE_SANSA_DOCK +/* Dock detect */ +static bool dock_detect = false; +static bool dock_detect_old = false; +#endif /* HAVE_SANSA_DOCK */ + void button_init_device(void) { GPIOA_DIR |= (1<<1); @@ -54,6 +60,36 @@ return hold_button; } +#ifdef HAVE_SANSA_DOCK +int dock_connect(void) +{ + static unsigned dock_counter = 0; + if (dock_detect != dock_detect_old) + { + if (dock_counter) + { + dock_counter--; + if (!dock_counter) + { + dock_detect_old = dock_detect; + if (dock_detect) + return 1; + else + return 2; + } + else + return 0; + } + else + { + dock_counter = HZ*2; + return 0; + } + } + return 0; +} +#endif /* HAVE_SANSA_DOCK */ + unsigned short button_read_dbop(void) { unsigned dbop_din = dbop_read_input(); @@ -77,6 +113,11 @@ dbop_din = button_read_dbop(); +#ifdef HAVE_SANSA_DOCK + /* Dock detect handling */ + dock_detect = ((dbop_din & (1 << 9)) != 0); +#endif /* HAVE_SANSA_DOCK */ + /* hold button handling */ hold_button = ((dbop_din & (1<<12)) != 0); #ifndef BOOTLOADER Index: firmware/target/arm/as3525/sansa-fuze/button-target.h =================================================================== --- firmware/target/arm/as3525/sansa-fuze/button-target.h (revision 27202) +++ firmware/target/arm/as3525/sansa-fuze/button-target.h (working copy) @@ -29,6 +29,9 @@ void button_init_device(void); bool button_hold(void); +#ifdef HAVE_SANSA_DOCK +int dock_connect(void); +#endif /* HAVE_SANSA_DOCK */ int button_read_device(void); unsigned short button_read_dbop(void); #define get_scrollwheel button_read_dbop Index: firmware/drivers/button.c =================================================================== --- firmware/drivers/button.c (revision 27202) +++ firmware/drivers/button.c (working copy) @@ -43,6 +43,10 @@ #include "lcd-remote.h" #endif +#ifdef HAVE_SANSA_DOCK +#include "as3514.h" +#endif /* HAVE_SANSA_DOCK */ + #if 0 /* Older than MAX_EVENT_AGE button events are going to be ignored. * Used to prevent for example volume going up uncontrollable when events @@ -123,6 +127,17 @@ const int data = 0; #endif +#ifdef HAVE_SANSA_DOCK + int chk_dock_connect = dock_connect(); + if (chk_dock_connect) + { + if (chk_dock_connect == 1) + lineout_enable(true); + else + lineout_enable(false); + } +#endif /* HAVE_SANSA_DOCK */ + #if defined(HAS_SERIAL_REMOTE) && !defined(SIMULATOR) /* Post events for the remote control */ btn = remote_control_rx(); Index: firmware/drivers/audio/as3514.c =================================================================== --- firmware/drivers/audio/as3514.c (revision 27202) +++ firmware/drivers/audio/as3514.c (working copy) @@ -164,16 +164,9 @@ #else /* as3514/as3515 */ -#if defined(SANSA_E200V2) || defined(SANSA_FUZE) - /* Set ADC off, mixer on, DAC on, line out on, line in off, mic off */ - /* Turn on SUM, DAC */ - as3514_write(AS3514_AUDIOSET1, AUDIOSET1_DAC_on | AUDIOSET1_LOUT_on | - AUDIOSET1_SUM_on); -#else /* Set ADC off, mixer on, DAC on, line out off, line in off, mic off */ /* Turn on SUM, DAC */ as3514_write(AS3514_AUDIOSET1, AUDIOSET1_DAC_on | AUDIOSET1_SUM_on); -#endif /* SANSA_E200V2 || SANSA_FUZE */ /* Set BIAS on, DITH off, AGC off, IBR_DAC max reduction, LSP_LP on, IBR_LSP max reduction (50%), taken from c200v2 OF @@ -222,12 +215,6 @@ /* Headphone ON, MUTE, Min volume */ as3514_write(AS3514_HPH_OUT_L, HPH_OUT_L_HP_ON | HPH_OUT_L_HP_MUTE | 0x00); -#if defined(SANSA_E200V2) || defined(SANSA_FUZE) - /* Line Out Stereo, MUTE, Min volume */ - as3514_write(AS3514_LINE_OUT_L, LINE_OUT_L_LO_SES_DM_SE_ST | - LINE_OUT_L_LO_SES_DM_MUTE | 0x00); -#endif /* SANSA_E200V2 || SANSA_FUZE */ - /* DAC_Mute_off */ as3514_set(AS3514_DAC_L, DAC_L_DAC_MUTE_off); } @@ -236,17 +223,48 @@ { if (mute) { as3514_set(AS3514_HPH_OUT_L, HPH_OUT_L_HP_MUTE); -#if defined(SANSA_E200V2) || defined(SANSA_FUZE) +#if defined HAVE_SANSA_DOCK && !defined HAVE_AS3543 as3514_set(AS3514_LINE_OUT_L, LINE_OUT_L_LO_SES_DM_MUTE); -#endif /* SANSA_E200V2 || SANSA_FUZE */ +#endif /* HAVE_SANSA_DOCK && !HAVE_AS3543 */ } else { as3514_clear(AS3514_HPH_OUT_L, HPH_OUT_L_HP_MUTE); -#if defined(SANSA_E200V2) || defined(SANSA_FUZE) +#if defined HAVE_SANSA_DOCK && !defined HAVE_AS3543 as3514_clear(AS3514_LINE_OUT_L, LINE_OUT_L_LO_SES_DM_MUTE); -#endif /* SANSA_E200V2 || SANSA_FUZE */ +#endif /* HAVE_SANSA_DOCK && !HAVE_AS3543 */ } } +#ifdef HAVE_SANSA_DOCK +void lineout_enable(int enable) +{ + if (enable) + { + audiohw_mute(true); + /* Set ADC off, mixer on, DAC on, line out on, line in off, mic off */ + /* Turn on SUM, DAC */ + as3514_write(AS3514_AUDIOSET1, AUDIOSET1_DAC_on | AUDIOSET1_LOUT_on | + AUDIOSET1_SUM_on); + /* Line Out enabled, Stereo, MUTE, Min volume */ + as3514_write(AS3514_LINE_OUT_L, LINE_OUT_L_LO_SES_DM_SE_ST | + LINE_OUT_L_LO_SES_DM_MUTE | 0x00); + /* Set line out volume to 0dB */ + as3514_write_masked(AS3514_LINE_OUT_R, 0x1b, AS3514_VOL_MASK); + as3514_write_masked(AS3514_LINE_OUT_L, 0x1b, AS3514_VOL_MASK); + audiohw_mute(false); + } + else + { + audiohw_mute(true); + /* Line Out disabled, MUTE, Min volume */ + as3514_write(AS3514_LINE_OUT_L, LINE_OUT_L_LO_SES_DM_MUTE | 0x00); + /* Set ADC off, mixer on, DAC on, line out off, line in off, mic off */ + /* Turn on SUM, DAC */ + as3514_write(AS3514_AUDIOSET1, AUDIOSET1_DAC_on | AUDIOSET1_SUM_on); + audiohw_mute(false); + } +} +#endif /* HAVE_SANSA_DOCK */ + void audiohw_postinit(void) { /* wait until outputs have stabilized */ @@ -256,12 +274,6 @@ ascodec_suppressor_on(false); #endif -#if defined(SANSA_E200V2) || defined(SANSA_FUZE) - /* Set line out volume to 0dB */ - as3514_write_masked(AS3514_LINE_OUT_R, 0x1b, AS3514_VOL_MASK); - as3514_write_masked(AS3514_LINE_OUT_L, 0x1b, AS3514_VOL_MASK); -#endif /* SANSA_E200V2 || SANSA_FUZE */ - audiohw_mute(false); }