drivers/audio/es8311: Fix setting sample rate and bits per sample

When setting the sample rate (`es8311_setsamplerate`) and the bits
per sample (`es8311_setbitspersample`), check their return value in
`es8311_configure`. Also, this commit ensures that these functions
are called after `es8311_reset` to avoid these values to be set to
the default values.
This commit is contained in:
Tiago Medicci 2024-07-29 17:01:44 -03:00 committed by Xiang Xiao
parent 24954800a7
commit c755218295

View File

@ -1033,19 +1033,25 @@ static int es8311_configure(FAR struct audio_lowerhalf_s *dev,
break;
}
es8311_audio_output(priv);
es8311_reset(priv);
/* Save the current stream configuration */
priv->samprate = caps->ac_controls.hw[0];
priv->bpsamp = caps->ac_controls.b[2];
es8311_audio_output(priv);
es8311_reset(priv);
es8311_setsamplerate(priv);
es8311_setbitspersample(priv);
ret = es8311_setsamplerate(priv) == -ENOTTY ? OK : ret;
if (ret < 0)
{
break;
}
ret = es8311_setbitspersample(priv) == -ENOTTY ? OK : ret;
}
break;
case AUDIO_TYPE_INPUT:
case AUDIO_TYPE_INPUT:
{
audinfo(" AUDIO_TYPE_INPUT:\n");
audinfo(" Number of channels: %u\n", caps->ac_channels);
@ -1074,15 +1080,21 @@ static int es8311_configure(FAR struct audio_lowerhalf_s *dev,
break;
}
es8311_audio_input(priv);
es8311_reset(priv);
/* Save the current stream configuration */
priv->samprate = caps->ac_controls.hw[0];
priv->bpsamp = caps->ac_controls.b[2];
es8311_audio_input(priv);
es8311_reset(priv);
es8311_setsamplerate(priv);
es8311_setbitspersample(priv);
ret = es8311_setsamplerate(priv) == -ENOTTY ? OK : ret;
if (ret != OK)
{
break;
}
ret = es8311_setbitspersample(priv) == -ENOTTY ? OK : ret;
}
break;