From f1b459347b7553614e87a340f7ea594deebbe4d1 Mon Sep 17 00:00:00 2001 From: Tiago Medicci Serrano Date: Wed, 30 Aug 2023 10:49:22 -0300 Subject: [PATCH] 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. --- arch/xtensa/src/esp32s3/esp32s3_i2s.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/arch/xtensa/src/esp32s3/esp32s3_i2s.c b/arch/xtensa/src/esp32s3/esp32s3_i2s.c index 94ed92acdbd..2a9e681a451 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_i2s.c +++ b/arch/xtensa/src/esp32s3/esp32s3_i2s.c @@ -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