Skip to content

Commit

Permalink
Media : Change max volume level as 15 (#6421)
Browse files Browse the repository at this point in the history
* audio/driver : Update audio driver to support volume level 0~15
1. Change Max Volume level from 10 to 15
2. Apply coding rule of syu645b
3. Remove delay of init_script of syu645b

* framework/media : Change max volume level as 15
Because of some requirement, change max volume level to 15 from 10
  • Loading branch information
Taejun-Kwon authored Oct 2, 2024
1 parent 4c0da9d commit 1fc8fb3
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 135 deletions.
2 changes: 1 addition & 1 deletion framework/src/media/audio/audio_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

#define AUDIO_STREAM_RETRY_COUNT 2

#define AUDIO_DEVICE_MAX_VOLUME 10
#define AUDIO_DEVICE_MAX_VOLUME 15

#ifndef CONFIG_AUDIO_MAX_INPUT_CARD_NUM
#define CONFIG_AUDIO_MAX_INPUT_CARD_NUM 2
Expand Down
2 changes: 1 addition & 1 deletion os/drivers/audio/alc1019.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#define alc1019_givesem(s) sem_post(s)

#define ALC1019_SPK_VOL_MIN 0
#define ALC1019_SPK_VOL_MAX 10
#define ALC1019_SPK_VOL_MAX 15
#define ALC1019_SPK_VOL_DEF 7

/*
Expand Down
199 changes: 96 additions & 103 deletions os/drivers/audio/syu645b.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,26 @@
****************************************************************************/

static const struct audio_ops_s g_audioops = {
.getcaps = syu645b_getcaps, /* getcaps */
.configure = syu645b_configure, /* configure */
.shutdown = syu645b_shutdown, /* shutdown */
.start = syu645b_start, /* start */
.getcaps = syu645b_getcaps, /* getcaps */
.configure = syu645b_configure, /* configure */
.shutdown = syu645b_shutdown, /* shutdown */
.start = syu645b_start, /* start */
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
.stop = syu645b_stop, /* stop */
.stop = syu645b_stop, /* stop */
#endif
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
.pause = syu645b_pause, /* pause */
.resume = syu645b_resume, /* resume */
.pause = syu645b_pause, /* pause */
.resume = syu645b_resume, /* resume */
#endif
.allocbuffer = NULL, /* allocbuffer */
.freebuffer = NULL, /* freebuffer */
.enqueuebuffer = syu645b_enqueuebuffer, /* enqueue_buffer */
.cancelbuffer = syu645b_cancelbuffer, /* cancel_buffer */
.ioctl = syu645b_ioctl, /* ioctl */
.read = NULL, /* read */
.write = NULL, /* write */
.reserve = syu645b_reserve, /* reserve */
.release = syu645b_release, /* release */
.allocbuffer = NULL, /* allocbuffer */
.freebuffer = NULL, /* freebuffer */
.enqueuebuffer = syu645b_enqueuebuffer, /* enqueue_buffer */
.cancelbuffer = syu645b_cancelbuffer, /* cancel_buffer */
.ioctl = syu645b_ioctl, /* ioctl */
.read = NULL, /* read */
.write = NULL, /* write */
.reserve = syu645b_reserve, /* reserve */
.release = syu645b_release, /* release */
};

/************************************************************************************
Expand All @@ -97,38 +97,38 @@ static const struct audio_ops_s g_audioops = {

static int syu645b_exec_i2c_script(FAR struct syu645b_dev_s *priv, t_codec_init_script_entry *script, uint32_t size)
{
uint32_t i;
uint16_t ret = 0;
uint8_t reg[5];
FAR struct i2c_dev_s *dev = priv->i2c;
FAR struct i2c_config_s *syu645b_i2c_config = &(priv->lower->i2c_config);

for (i = 0; i < size; i++) {
reg[0] = script[i].addr;
if (script[i].type == SYU645B_REG_D_2BYTE) {
reg[1] = script[i].val[0];
} else if (script[i].type == SYU645B_REG_D_3BYTE) {
reg[1] = script[i].val[0];
reg[2] = script[i].val[1];
} else if (script[i].type == SYU645B_REG_D_5BYTE) {
reg[1] = script[i].val[0];
reg[2] = script[i].val[1];
reg[3] = script[i].val[2];
reg[4] = script[i].val[3];
} else {
auddbg("Error, script type is not supported\n");
}

ret = i2c_write(dev, syu645b_i2c_config, (uint8_t *)reg, script[i].type);
if (ret < script[i].type) {
auddbg("Error, cannot write to reg addr 0x%x, ret = %d\n", script[i].addr, ret);
break;
}
if (script[i].delay > 0) {
up_mdelay(script[i].delay);
}
}
return ret;
uint32_t i;
uint16_t ret = 0;
uint8_t reg[5];
FAR struct i2c_dev_s *dev = priv->i2c;
FAR struct i2c_config_s *syu645b_i2c_config = &(priv->lower->i2c_config);

for (i = 0; i < size; i++) {
reg[0] = script[i].addr;
if (script[i].type == SYU645B_REG_D_2BYTE) {
reg[1] = script[i].val[0];
} else if (script[i].type == SYU645B_REG_D_3BYTE) {
reg[1] = script[i].val[0];
reg[2] = script[i].val[1];
} else if (script[i].type == SYU645B_REG_D_5BYTE) {
reg[1] = script[i].val[0];
reg[2] = script[i].val[1];
reg[3] = script[i].val[2];
reg[4] = script[i].val[3];
} else {
auddbg("Error, script type is not supported\n");
}

ret = i2c_write(dev, syu645b_i2c_config, (uint8_t *)reg, script[i].type);
if (ret < script[i].type) {
auddbg("Error, cannot write to reg addr 0x%x, ret = %d\n", script[i].addr, ret);
break;
}
if (script[i].delay > 0) {
up_mdelay(script[i].delay);
}
}
return ret;
}

/************************************************************************************
Expand All @@ -141,12 +141,12 @@ static int syu645b_exec_i2c_script(FAR struct syu645b_dev_s *priv, t_codec_init_
************************************************************************************/
static void syu645b_takesem(sem_t *sem)
{
int ret;
int ret;

do {
ret = sem_wait(sem);
DEBUGASSERT(ret == 0 || errno == EINTR);
} while (ret < 0);
do {
ret = sem_wait(sem);
DEBUGASSERT(ret == 0 || errno == EINTR);
} while (ret < 0);
}

/************************************************************************************
Expand All @@ -160,28 +160,30 @@ static void syu645b_takesem(sem_t *sem)
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
static void syu645b_setvolume(FAR struct syu645b_dev_s *priv)
{
/* if no audio device object return */
if (!priv) {
auddbg("Error, Device's private data Not available\n");
return;
}

if (priv->running) {
audvdbg("volume=%u mute=%u\n", priv->volume, priv->mute);
if (priv->mute) {
syu645b_exec_i2c_script(priv, codec_init_mute_on_script, sizeof(codec_init_mute_on_script) / sizeof(t_codec_init_script_entry));
} else {
if (priv->volume == 0) {
codec_set_master_volume_script[0].val[0] = 0;
} else {
/* Linear approximation is done to convert media volume to hardware volume */
codec_set_master_volume_script[0].val[0] = SYU645B_HW_VOL_MIN_BOUND + SYU645B_HW_VOL_SLOPE * priv->volume;
}
syu645b_exec_i2c_script(priv, codec_set_master_volume_script, sizeof(codec_set_master_volume_script) / sizeof(t_codec_init_script_entry));
}
} else {
audvdbg("not running[volume=%u mute=%u]\n", priv->volume, priv->mute);
}
/* if no audio device object return */
if (!priv) {
auddbg("Error, Device's private data Not available\n");
return;
}

if (!priv->running) {
auddbg("not running[volume=%u mute=%u]\n", priv->volume, priv->mute);
return;
}

audvdbg("volume=%u mute=%u\n", priv->volume, priv->mute);
if (priv->mute) {
syu645b_exec_i2c_script(priv, codec_init_mute_on_script, sizeof(codec_init_mute_on_script) / sizeof(t_codec_init_script_entry));
return;
}

if (priv->volume == 0) {
codec_set_master_volume_script[0].val[0] = 0;
} else {
/* Linear approximation is done to convert media volume to hardware volume */
codec_set_master_volume_script[0].val[0] = SYU645B_HW_VOL_MIN_BOUND + SYU645B_HW_VOL_SLOPE * priv->volume;
}
syu645b_exec_i2c_script(priv, codec_set_master_volume_script, sizeof(codec_set_master_volume_script) / sizeof(t_codec_init_script_entry));
}
#endif /* CONFIG_AUDIO_EXCLUDE_VOLUME */

Expand All @@ -197,9 +199,9 @@ static void syu645b_setvolume(FAR struct syu645b_dev_s *priv)
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
static void syu645b_setbass(FAR struct syu645b_dev_s *priv, uint8_t bass)
{
audvdbg("bass=%u\n", bass);
audvdbg("bass=%u\n", bass);
}
#endif /* CONFIG_AUDIO_EXCLUDE_TONE */
#endif

/************************************************************************************
* Name: syu645b_settreble
Expand All @@ -213,7 +215,7 @@ static void syu645b_setbass(FAR struct syu645b_dev_s *priv, uint8_t bass)
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
static void syu645b_settreble(FAR struct syu645b_dev_s *priv, uint8_t treble)
{
audvdbg("treble=%u\n", treble);
audvdbg("treble=%u\n", treble);
}
#endif

Expand All @@ -226,17 +228,13 @@ static void syu645b_settreble(FAR struct syu645b_dev_s *priv, uint8_t treble)
****************************************************************************/
static void syu645b_set_i2s_datawidth(FAR struct syu645b_dev_s *priv)
{
/* if no audio device object return */
if (!priv) {
auddbg("Error, Device's private data Not available\n");
return;
}

if (priv->inout) {
I2S_RXDATAWIDTH(priv->i2s, priv->bpsamp);
} else {
I2S_TXDATAWIDTH(priv->i2s, priv->bpsamp);
}
/* if no audio device object return */
if (!priv) {
auddbg("Error, Device's private data Not available\n");
return;
}

I2S_TXDATAWIDTH(priv->i2s, priv->bpsamp);
}

/****************************************************************************
Expand All @@ -247,17 +245,12 @@ static void syu645b_set_i2s_datawidth(FAR struct syu645b_dev_s *priv)
****************************************************************************/
static void syu645b_set_i2s_samplerate(FAR struct syu645b_dev_s *priv)
{
/* if no audio device object return */
if (!priv) {
auddbg("Error, Device's private data Not available\n");
return;
}

if (priv->inout) {
I2S_RXSAMPLERATE(priv->i2s, priv->samprate);
} else {
I2S_TXSAMPLERATE(priv->i2s, priv->samprate);
}
/* if no audio device object return */
if (!priv) {
auddbg("Error, Device's private data Not available\n");
return;
}
I2S_TXSAMPLERATE(priv->i2s, priv->samprate);
}

/****************************************************************************
Expand Down Expand Up @@ -444,6 +437,8 @@ static int syu645b_configure(FAR struct audio_lowerhalf_s *dev, FAR const struct
audvdbg(" Sample rate: 0x%x\n", priv->samprate);
audvdbg(" Sample width: 0x%x\n", priv->bpsamp);

/* Below is actually not good s/w structure but amp is tightly related to ndp120 due to AEC...*/
#ifndef CONFIG_AUDIO_NDP120
/* Reconfigure the FLL to support the resulting number or channels,
* bits per sample, and bitrate.
*/
Expand All @@ -461,9 +456,8 @@ static int syu645b_configure(FAR struct audio_lowerhalf_s *dev, FAR const struct
} else {
auddbg("ERROR: Unsupported sample rate: %d\n", priv->samprate);
}

#endif
ret = OK;
priv->inout = false;
break;

case AUDIO_TYPE_PROCESSING:
Expand Down Expand Up @@ -944,7 +938,6 @@ static int syu645b_release(FAR struct audio_lowerhalf_s *dev)
****************************************************************************/
static void syu645b_reset_config(FAR struct syu645b_dev_s *priv)
{
priv->inout = false;
/* Put audio output back to its initial configuration */
priv->samprate = SYU645B_DEFAULT_SAMPRATE;
priv->nchannels = SYU645B_DEFAULT_NCHANNELS;
Expand Down
3 changes: 1 addition & 2 deletions os/drivers/audio/syu645b.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#define syu645b_givesem(s) sem_post(s)

#define SYU645B_SPK_VOL_MIN 0
#define SYU645B_SPK_VOL_MAX 10
#define SYU645B_SPK_VOL_MAX 15
#define SYU645B_SPK_VOL_DEF 7
/* TODO : Check if bass and treble present or not */
#define SYU645B_BASS_MAX 100
Expand Down Expand Up @@ -127,7 +127,6 @@ struct syu645b_dev_s {
#endif
bool reserved; /* True: Device is reserved */
volatile int result; /* The result of the last transfer */
bool inout; /* True: IN device */
};

/****************************************************************************
Expand Down
56 changes: 28 additions & 28 deletions os/drivers/audio/syu645bscripts.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,35 @@ t_codec_init_script_entry codec_stop_script[] = {

t_codec_init_script_entry codec_initial_script[] = {
/* Initialize AMP sequence */
{ 0x0F, {0x01,}, 30, SYU645B_REG_D_2BYTE},
{ 0x00, {0x1A,}, 30, SYU645B_REG_D_2BYTE},
{ 0x06, {0x08,}, 29, SYU645B_REG_D_2BYTE},
{ 0x1B, {0xBD,}, 30, SYU645B_REG_D_2BYTE},
{ 0x23, {0x1a,}, 30, SYU645B_REG_D_2BYTE},
{ 0x05, {0x02,}, 30, SYU645B_REG_D_2BYTE},
{ 0x76, {0x0F,}, 30, SYU645B_REG_D_2BYTE},
{ 0x85, {0x00, 0x00, 0x00, 0x06,}, 30, SYU645B_REG_D_5BYTE},
{ 0x86, {0x00, 0x00, 0x30, 0x10,}, 30, SYU645B_REG_D_5BYTE},
{ 0x94, {0x00, 0x00, 0x00, 0x11,}, 30, SYU645B_REG_D_5BYTE},
{ 0x95, {0x10, 0x00, 0x32, 0x10,}, 30, SYU645B_REG_D_5BYTE},
{ 0x96, {0x10, 0x00, 0x5C, 0xAA,}, 30, SYU645B_REG_D_5BYTE},
{ 0xB0, {0x00, 0x00, 0x07, 0xFF,}, 30, SYU645B_REG_D_5BYTE},
{ 0x10, {0x77,}, 30, SYU645B_REG_D_2BYTE},
{ 0x11, {0x00,}, 30, SYU645B_REG_D_2BYTE},
{ 0x12, {0x00,}, 30, SYU645B_REG_D_2BYTE},
{ 0x13, {0x06,}, 30, SYU645B_REG_D_2BYTE},
{ 0x14, {0x06,}, 30, SYU645B_REG_D_2BYTE},
{ 0x1E, {0x05,}, 30, SYU645B_REG_D_2BYTE},
{ 0x0F, {0x01,}, 0, SYU645B_REG_D_2BYTE},
{ 0x00, {0x1A,}, 0, SYU645B_REG_D_2BYTE},
{ 0x06, {0x08,}, 0, SYU645B_REG_D_2BYTE},
{ 0x1B, {0xBD,}, 0, SYU645B_REG_D_2BYTE},
{ 0x23, {0x1a,}, 0, SYU645B_REG_D_2BYTE},
{ 0x05, {0x02,}, 0, SYU645B_REG_D_2BYTE},
{ 0x76, {0x0F,}, 0, SYU645B_REG_D_2BYTE},
{ 0x85, {0x00, 0x00, 0x00, 0x06,}, 0, SYU645B_REG_D_5BYTE},
{ 0x86, {0x00, 0x00, 0x30, 0x10,}, 0, SYU645B_REG_D_5BYTE},
{ 0x94, {0x00, 0x00, 0x00, 0x11,}, 0, SYU645B_REG_D_5BYTE},
{ 0x95, {0x10, 0x00, 0x32, 0x10,}, 0, SYU645B_REG_D_5BYTE},
{ 0x96, {0x10, 0x00, 0x5C, 0xAA,}, 0, SYU645B_REG_D_5BYTE},
{ 0xB0, {0x00, 0x00, 0x07, 0xFF,}, 0, SYU645B_REG_D_5BYTE},
{ 0x10, {0x77,}, 0, SYU645B_REG_D_2BYTE},
{ 0x11, {0x00,}, 0, SYU645B_REG_D_2BYTE},
{ 0x12, {0x00,}, 0, SYU645B_REG_D_2BYTE},
{ 0x13, {0x06,}, 0, SYU645B_REG_D_2BYTE},
{ 0x14, {0x06,}, 0, SYU645B_REG_D_2BYTE},
{ 0x1E, {0x05,}, 0, SYU645B_REG_D_2BYTE},
/* setting to default volume */
{ 0x07, {SYU645B_HW_VOL_DEF,}, 30, SYU645B_REG_D_2BYTE},
{ 0x08, {0xBD,}, 30, SYU645B_REG_D_2BYTE},
{ 0x09, {0xBD,}, 30, SYU645B_REG_D_2BYTE},
{ 0x1F, {0x03,}, 30, SYU645B_REG_D_2BYTE},
{ 0x2C, {0x7F, 0xFF,}, 30, SYU645B_REG_D_3BYTE},
{ 0x2D, {0x7B, 0xAF,}, 30, SYU645B_REG_D_3BYTE},
{ 0x22, {0x00,}, 30, SYU645B_REG_D_2BYTE},
{ 0x06, {0x08,}, 30, SYU645B_REG_D_2BYTE},
{ 0x06, {0x00,}, 30, SYU645B_REG_D_2BYTE},
{ 0x07, {SYU645B_HW_VOL_DEF,}, 0, SYU645B_REG_D_2BYTE},
{ 0x08, {0xBD,}, 0, SYU645B_REG_D_2BYTE},
{ 0x09, {0xBD,}, 0, SYU645B_REG_D_2BYTE},
{ 0x1F, {0x03,}, 0, SYU645B_REG_D_2BYTE},
{ 0x2C, {0x7F, 0xFF,}, 0, SYU645B_REG_D_3BYTE},
{ 0x2D, {0x7B, 0xAF,}, 0, SYU645B_REG_D_3BYTE},
{ 0x22, {0x00,}, 0, SYU645B_REG_D_2BYTE},
{ 0x06, {0x08,}, 0, SYU645B_REG_D_2BYTE},
{ 0x06, {0x00,}, 0, SYU645B_REG_D_2BYTE},
};

t_codec_init_script_entry codec_init_mute_on_script[] = {
Expand Down

0 comments on commit 1fc8fb3

Please sign in to comment.