diff --git a/firmware/drivers/audio/mas35xx.c b/firmware/drivers/audio/mas35xx.c index 983818bf61..403ce07068 100644 --- a/firmware/drivers/audio/mas35xx.c +++ b/firmware/drivers/audio/mas35xx.c @@ -170,3 +170,15 @@ void audiohw_set_treble(int val) mas_writereg(MAS_REG_KTREBLE, treble_table[val+15]); #endif } + +#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) +void audiohw_set_volume(int val) { + unsigned tmp = ((unsigned)(val + 115) & 0xff) << 8; + mas_codec_writereg(0x10, tmp); +} + +void audiohw_set_balance(int val) { + unsigned tmp = ((unsigned)(val * 127 / 100) & 0xff) << 8; + mas_codec_writereg(0x11, tmp); +} +#endif diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h index d450613aff..d11a3b5181 100644 --- a/firmware/export/audiohw.h +++ b/firmware/export/audiohw.h @@ -26,6 +26,8 @@ /* define some audiohw caps */ #define TREBLE_CAP (1 << 0) #define BASS_CAP (1 << 1) +#define BALANCE_CAP (1 << 2) +#define CLIPPING_CAP (1 << 3) #ifdef HAVE_UDA1380 #include "uda1380.h" @@ -62,6 +64,14 @@ #if (AUDIOHW_CAPS & BASS_CAP) #define AUDIOHW_HAVE_BASS #endif + +#if (AUDIOHW_CAPS & BALANCE_CAP) +#define AUDIOHW_HAVE_BALANCE +#endif + +#if (AUDIOHW_CAPS & CLIPPING_CAP) +#define AUDIOHW_HAVE_CLIPPING +#endif #endif /* AUDIOHW_CAPS */ enum { @@ -144,6 +154,26 @@ void audiohw_postinit(void); */ void audiohw_close(void); +#ifdef AUDIOHW_HAVE_CLIPPING + /** + * Set new volume value + * @param val to set. + * NOTE: AUDIOHW_CAPS need to contain + * CLIPPING_CAP + */ +void audiohw_set_volume(int val); +#endif + +#ifdef AUDIOHW_HAVE_BALANCE +/** + * Set new balance value + * @param val to set. + * NOTE: AUDIOHW_CAPS need to contain + * BALANCE_CAP + */ +void audiohw_set_balance(int val); +#endif + /** * Mute or enable sound. * @param mute true or false. diff --git a/firmware/export/mas35xx.h b/firmware/export/mas35xx.h index dbe9d38a37..d28db0fb33 100644 --- a/firmware/export/mas35xx.h +++ b/firmware/export/mas35xx.h @@ -24,14 +24,22 @@ #include "config.h" -#define AUDIOHW_CAPS (BASS_CAP | TREBLE_CAP) - #if CONFIG_CODEC == MAS3507D + #define VOLUME_MIN -780 #define VOLUME_MAX 180 -#else +#define AUDIOHW_CAPS (BASS_CAP | TREBLE_CAP) + +#else /* CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F */ + +/* MAS3587F and MAS3539F handle clipping prevention internally so we do not need + * the prescaler -> CLIPPING_CAP + */ + #define VOLUME_MIN -400 #define VOLUME_MAX 600 +#define AUDIOHW_CAPS (BASS_CAP | TREBLE_CAP | BALANCE_CAP | CLIPPING_CAP) + #endif diff --git a/firmware/sound.c b/firmware/sound.c index 45d3e4b1b6..1e8f9e2b24 100644 --- a/firmware/sound.c +++ b/firmware/sound.c @@ -227,11 +227,7 @@ static int tenthdb2reg(int db) #endif -/* MAS3587F and MAS3539F handle clipping prevention internally so we do not need - * the prescaler. - */ -#if (CONFIG_CODEC != MAS3587F) && (CONFIG_CODEC != MAS3539F) - +#if !defined(AUDIOHW_HAVE_CLIPPING) /* * The prescaler compensates for any kind of boosts, to prevent clipping. * @@ -327,41 +323,29 @@ void sound_set_volume(int value) { if(!audio_is_initialized) return; -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - unsigned tmp = ((unsigned)(value + 115) & 0xff) << 8; - mas_codec_writereg(0x10, tmp); -#elif (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 \ - || defined HAVE_WM8975 || defined HAVE_WM8758 || defined HAVE_WM8731 \ - || defined(HAVE_WM8721) || defined(HAVE_TLV320) || defined(HAVE_WM8751) \ - || defined(HAVE_AS3514) || defined(HAVE_WM8985) || defined(HAVE_TSC2100) \ - || defined(HAVE_WM8978) - current_volume = value * 10; /* tenth of dB */ - set_prescaled_volume(); + +#if defined(AUDIOHW_HAVE_CLIPPING) + audiohw_set_volume(value); #elif CONFIG_CPU == PNX0101 int tmp = (60 - value * 4) & 0xff; CODECVOL = tmp | (tmp << 8); +#else + current_volume = value * 10; /* tenth of dB */ + set_prescaled_volume(); #endif - (void)value; } void sound_set_balance(int value) { if(!audio_is_initialized) return; -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - unsigned tmp = ((unsigned)(value * 127 / 100) & 0xff) << 8; - mas_codec_writereg(0x11, tmp); -#elif CONFIG_CODEC == MAS3507D || defined HAVE_UDA1380 \ - || defined HAVE_WM8975 || defined HAVE_WM8758 || defined HAVE_WM8731 \ - || defined(HAVE_WM8721) || defined(HAVE_TLV320) || defined(HAVE_WM8751) \ - || defined(HAVE_AS3514) || defined(HAVE_WM8985) || defined(HAVE_TSC2100) \ - || defined(HAVE_WM8978) + +#ifdef AUDIOHW_HAVE_BALANCE + audiohw_set_balance(value); +#else current_balance = value * VOLUME_RANGE / 100; /* tenth of dB */ set_prescaled_volume(); -#elif CONFIG_CPU == PNX0101 - /* TODO: implement for iFP */ #endif - (void)value; } void sound_set_bass(int value) @@ -375,7 +359,7 @@ void sound_set_bass(int value) dsp_callback(DSP_CALLBACK_SET_BASS, current_bass); #endif -#if (CONFIG_CODEC != MAS3587F) && (CONFIG_CODEC != MAS3539F) +#if !defined(AUDIOHW_HAVE_CLIPPING) #if defined(HAVE_WM8751) current_bass = value; #else @@ -396,7 +380,7 @@ void sound_set_treble(int value) dsp_callback(DSP_CALLBACK_SET_TREBLE, current_treble); #endif -#if (CONFIG_CODEC != MAS3587F) && (CONFIG_CODEC != MAS3539F) +#if !defined(AUDIOHW_HAVE_CLIPPING) #if defined(HAVE_WM8751) current_treble = value; #else