esp32s3/i2s: Add interface to stop the I2S streams

In order to gracefully stop the I2S stream, add an interface to set
a `streaming` status variable that sets the `AUDIO_APB_FINAL` flag
that will be handled by the upper layers of the audio subsystem.
This commit is contained in:
Tiago Medicci Serrano 2023-08-30 10:49:22 -03:00 committed by Xiang Xiao
parent 5065849ab6
commit f1b459347b

View file

@ -315,6 +315,8 @@ struct esp32s3_i2s_s
bool rx_started; /* RX channel started */
#endif /* I2S_HAVE_RX */
bool streaming; /* Is I2S peripheral active? */
/* Pre-allocated pool of buffer containers */
sem_t bufsem; /* Buffer wait semaphore */
@ -1303,7 +1305,10 @@ static void i2s_rx_worker(void *arg)
DEBUGASSERT(bfcontainer && bfcontainer->callback);
/* Release the internal buffer used by the DMA inlink */
if (priv->streaming == false)
{
bfcontainer->apb->flags |= AUDIO_APB_FINAL;
}
bfcontainer->callback(&priv->dev, bfcontainer->apb,
bfcontainer->arg, bfcontainer->result);
@ -2902,10 +2907,29 @@ static int i2s_ioctl(struct i2s_dev_s *dev, int cmd, unsigned long arg)
{
i2sinfo("AUDIOIOC_START\n");
priv->streaming = true;
ret = OK;
}
break;
/* AUDIOIOC_STOP - Stop the audio stream.
*
* ioctl argument: Audio session
*/
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
case AUDIOIOC_STOP:
{
i2sinfo("AUDIOIOC_STOP\n");
priv->streaming = false;
ret = OK;
}
break;
#endif /* CONFIG_AUDIO_EXCLUDE_STOP */
/* AUDIOIOC_ALLOCBUFFER - Allocate an audio buffer
*
* ioctl argument: pointer to an audio_buf_desc_s structure