T16 mute improve (#7193)

Introduce mute time  on T16
This commit is contained in:
3djc
2019-12-16 07:02:17 +01:00
committed by GitHub
parent bc8d39adbf
commit 9abcee430a
3 changed files with 48 additions and 16 deletions
+3
View File
@@ -512,6 +512,9 @@ class AudioQueue {
bool isEmpty() const { return fragmentsFifo.empty(); };
void wakeup();
bool started() const { return _started; };
#if defined(AUDIO_UNMUTE_DELAY)
tmr10ms_t lastAudioPlayTime = 0;
#endif
AudioBufferFifo buffersFifo;
@@ -88,33 +88,61 @@ void dacInit()
NVIC_SetPriority(AUDIO_DMA_Stream_IRQn, 7);
}
#if defined(AUDIO_MUTE_GPIO_PIN)
void audioMute()
{
#if defined(AUDIO_UNMUTE_DELAY)
tmr10ms_t now = get_tmr10ms();
if (!audioQueue.lastAudioPlayTime) {
// we start the mute delay now
audioQueue.lastAudioPlayTime = now;
}
else if (now - audioQueue.lastAudioPlayTime > AUDIO_MUTE_DELAY / 10) {
// delay expired, we may mute
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
}
#else
// mute
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
#endif
}
void audioUnmute()
{
#if defined(AUDIO_UNMUTE_DELAY)
// if muted
if (GPIO_ReadOutputDataBit(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN)) {
// ..un-mute
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
RTOS_WAIT_MS(AUDIO_UNMUTE_DELAY);
}
// reset the mute delay
audioQueue.lastAudioPlayTime = 0;
#else
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
#endif
}
#endif
void audioConsumeCurrentBuffer()
{
if (!nextBuffer) {
nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
if (nextBuffer) {
#if defined(AUDIO_MUTE_GPIO_PIN)
// if muted
if (GPIO_ReadOutputDataBit(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN)) {
// ..un-mute
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
#if defined(AUDIO_UNMUTE_DELAY)
RTOS_WAIT_MS(AUDIO_UNMUTE_DELAY);
audioUnmute();
#endif
}
#endif
AUDIO_DMA_Stream->CR &= ~DMA_SxCR_EN ; // Disable DMA channel
AUDIO_DMA->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear bits
AUDIO_DMA_Stream->CR &= ~DMA_SxCR_EN; // Disable DMA channel
AUDIO_DMA->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5; // Write ones to clear bits
AUDIO_DMA_Stream->M0AR = CONVERT_PTR_UINT(nextBuffer->data);
AUDIO_DMA_Stream->NDTR = nextBuffer->size;
AUDIO_DMA_Stream->CR |= DMA_SxCR_EN | DMA_SxCR_TCIE ; // Enable DMA channel and interrupt
DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag
DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1 ; // Enable DAC
AUDIO_DMA_Stream->CR |= DMA_SxCR_EN | DMA_SxCR_TCIE; // Enable DMA channel and interrupt
DAC->SR = DAC_SR_DMAUDR1; // Write 1 to clear flag
DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1; // Enable DAC
}
#if defined(AUDIO_MUTE_GPIO_PIN)
else {
// mute
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
audioMute();
}
#endif
}
+2 -1
View File
@@ -547,7 +547,8 @@
#endif
#if defined(RADIO_T16)
#define AUDIO_UNMUTE_DELAY 150
#define AUDIO_UNMUTE_DELAY 120 // ms
#define AUDIO_MUTE_DELAY 500 // ms
#endif
// I2C Bus