audiohw: avoid magic numbers for DAC power mode

Define proper symbolic constants for power mode. Also allow
targets to define the default power mode setting.

Change-Id: Ia07cf854dce47d0a6aa88e067471f1ff9fbc45fb
This commit is contained in:
Aidan MacDonald 2022-01-10 21:50:32 +00:00
parent 18b3e91707
commit dac3175445
6 changed files with 20 additions and 7 deletions

View file

@ -351,6 +351,12 @@ static const char graphic_numeric[] = "graphic,numeric";
# endif # endif
#endif #endif
#ifdef AUDIOHW_HAVE_POWER_MODE
# ifndef TARGET_DEFAULT_DAC_POWER_MODE
# define TARGET_DEFAULT_DAC_POWER_MODE SOUND_HIGH_POWER
# endif
#endif
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1
static const char* list_pad_formatter(char *buffer, size_t buffer_size, static const char* list_pad_formatter(char *buffer, size_t buffer_size,
int val, const char *unit) int val, const char *unit)
@ -877,7 +883,8 @@ const struct settings_list settings[] = {
#endif #endif
#ifdef AUDIOHW_HAVE_POWER_MODE #ifdef AUDIOHW_HAVE_POWER_MODE
CHOICE_SETTING(F_SOUNDSETTING, power_mode, LANG_DAC_POWER_MODE, 0, CHOICE_SETTING(F_SOUNDSETTING, power_mode, LANG_DAC_POWER_MODE,
TARGET_DEFAULT_DAC_POWER_MODE,
"dac_power_mode", "high,low", sound_set_power_mode, "dac_power_mode", "high,low", sound_set_power_mode,
2, ID2P(LANG_DAC_POWER_HIGH), ID2P(LANG_DAC_POWER_LOW)), 2, ID2P(LANG_DAC_POWER_HIGH), ID2P(LANG_DAC_POWER_LOW)),
#endif #endif

View file

@ -242,11 +242,11 @@ void ak4376_set_freqmode(int fsel, int mult, int power_mode)
/* Handle the DSMLP bit in the MODE_CTRL register */ /* Handle the DSMLP bit in the MODE_CTRL register */
int mode_ctrl = 0x00; int mode_ctrl = 0x00;
if(power_mode || hw_freq_sampr[fsel] <= SAMPR_12) if(power_mode == SOUND_LOW_POWER || hw_freq_sampr[fsel] <= SAMPR_12)
mode_ctrl |= 0x40; mode_ctrl |= 0x40;
/* Program the new settings */ /* Program the new settings */
ak4376_write(AK4376_REG_CLOCK_MODE, clock_mode); ak4376_write(AK4376_REG_CLOCK_MODE, clock_mode);
ak4376_write(AK4376_REG_MODE_CTRL, mode_ctrl); ak4376_write(AK4376_REG_MODE_CTRL, mode_ctrl);
ak4376_write(AK4376_REG_PWR3, power_mode ? 0x11 : 0x01); ak4376_write(AK4376_REG_PWR3, power_mode == SOUND_LOW_POWER ? 0x11 : 0x01);
} }

View file

@ -144,8 +144,8 @@ extern void ak4376_set_filter_roll_off(int val);
* and power-up / power-down sequences as a frequency switch, so both settings * and power-up / power-down sequences as a frequency switch, so both settings
* are controlled by this function. * are controlled by this function.
* *
* high power mode -- use power_mode=0 * high power mode -- use power_mode=SOUND_HIGH_POWER
* low power mode -- use power_mode=1 * low power mode -- use power_mode=SOUND_LOW_POWER
*/ */
extern void ak4376_set_freqmode(int fsel, int mult, int power_mode); extern void ak4376_set_freqmode(int fsel, int mult, int power_mode);

View file

@ -605,6 +605,12 @@ void audiohw_set_filter_roll_off(int val);
#endif #endif
#ifdef AUDIOHW_HAVE_POWER_MODE #ifdef AUDIOHW_HAVE_POWER_MODE
enum audiohw_power_mode
{
SOUND_HIGH_POWER = 0,
SOUND_LOW_POWER,
};
/** /**
* Set DAC's power saving mode. * Set DAC's power saving mode.
* @param enable 0 - highest performance, 1 - battery saving * @param enable 0 - highest performance, 1 - battery saving

View file

@ -28,7 +28,7 @@
#include "logf.h" #include "logf.h"
static int cur_fsel = HW_FREQ_48; static int cur_fsel = HW_FREQ_48;
static int cur_power_mode = 0; static int cur_power_mode = SOUND_HIGH_POWER;
static void set_ak_freqmode(void) static void set_ak_freqmode(void)
{ {

View file

@ -154,7 +154,7 @@ void audiohw_set_filter_roll_off(int value)
void audiohw_set_power_mode(int mode) void audiohw_set_power_mode(int mode)
{ {
enum es9218_amp_mode new_amp_mode; enum es9218_amp_mode new_amp_mode;
if(mode == 0) if(mode == SOUND_HIGH_POWER)
new_amp_mode = ES9218_AMP_MODE_2VRMS; new_amp_mode = ES9218_AMP_MODE_2VRMS;
else else
new_amp_mode = ES9218_AMP_MODE_1VRMS; new_amp_mode = ES9218_AMP_MODE_1VRMS;