fix(el18): Audio output should be OFF if no audio playing (#3670)

* Added audio on/off depends whether audio content is present.

* Aligned the mute control with the implementation in the DAC driver.

* Mute Pin should be inverted.

* Removed PCB specific dependencies.

* chore: Formatting and cleanup
This commit is contained in:
richardclli
2023-06-15 10:07:30 +10:00
committed by GitHub
parent 285de8a08e
commit 5288441a82
4 changed files with 74 additions and 28 deletions
-2
View File
@@ -525,8 +525,6 @@ void audioTask(void * pdata)
#if defined(PCBX12S) || defined(RADIO_TX16S) #if defined(PCBX12S) || defined(RADIO_TX16S)
// The audio amp needs ~2s to start // The audio amp needs ~2s to start
RTOS_WAIT_MS(1000); // 1s RTOS_WAIT_MS(1000); // 1s
#elif defined(PCBNV14)
audioOn();
#endif #endif
while (true) { while (true) {
+68 -13
View File
@@ -357,36 +357,83 @@ void audioSendRiffHeader()
audioSpiWriteBuffer(RiffHeader, sizeof(RiffHeader)); audioSpiWriteBuffer(RiffHeader, sizeof(RiffHeader));
} }
#if defined(PCBX12S) || defined(PCBNV14) #if defined(AUDIO_MUTE_GPIO_PIN)
static inline void setMutePin(bool enabled)
void audioOn()
{ {
GPIO_SetBits(AUDIO_SHUTDOWN_GPIO, AUDIO_SHUTDOWN_GPIO_PIN); if (enabled) {
#if defined(INVERTED_MUTE_PIN)
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
#else
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
#endif
} else {
#if defined(INVERTED_MUTE_PIN)
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
#else
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
#endif
}
} }
void audioOff() static inline bool getMutePin(void)
{ {
GPIO_ResetBits(AUDIO_SHUTDOWN_GPIO, AUDIO_SHUTDOWN_GPIO_PIN); #if defined(INVERTED_MUTE_PIN)
return !GPIO_ReadOutputDataBit(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
#else
return GPIO_ReadOutputDataBit(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
#endif
} }
void audioShutdownInit() 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
setMutePin(true);
}
#else
// mute
setMutePin(true);
#endif
}
void audioUnmute()
{
#if defined(AUDIO_UNMUTE_DELAY)
// if muted
if (getMutePin()) {
// ..un-mute
setMutePin(false);
RTOS_WAIT_MS(AUDIO_UNMUTE_DELAY);
}
// reset the mute delay
audioQueue.lastAudioPlayTime = 0;
#else
setMutePin(false);
#endif
}
void audioMuteInit()
{ {
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = AUDIO_SHUTDOWN_GPIO_PIN; GPIO_InitStructure.GPIO_Pin = AUDIO_MUTE_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(AUDIO_SHUTDOWN_GPIO, &GPIO_InitStructure); GPIO_Init(AUDIO_MUTE_GPIO, &GPIO_InitStructure);
GPIO_ResetBits(AUDIO_SHUTDOWN_GPIO, AUDIO_SHUTDOWN_GPIO_PIN); GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
} }
#endif #endif
void audioInit() void audioInit()
{ {
#if defined(PCBX12S) || defined(PCBNV14) #if defined(AUDIO_MUTE_GPIO_PIN)
audioShutdownInit(); audioMuteInit();
// TODO X10 code missing
#endif #endif
audioSpiInit(); audioSpiInit();
@@ -427,6 +474,9 @@ void audioConsumeCurrentBuffer()
} }
if (currentBuffer) { if (currentBuffer) {
#if defined(AUDIO_MUTE_GPIO_PIN)
audioUnmute();
#endif
uint32_t written = audioSpiWriteData(currentBuffer, currentSize); uint32_t written = audioSpiWriteData(currentBuffer, currentSize);
currentBuffer += written; currentBuffer += written;
currentSize -= written; currentSize -= written;
@@ -436,6 +486,11 @@ void audioConsumeCurrentBuffer()
currentSize = 0; currentSize = 0;
} }
} }
#if defined(AUDIO_MUTE_GPIO_PIN)
else {
audioMute();
}
#endif
} }
// adjust this value for a volume level just above the silence // adjust this value for a volume level just above the silence
-10
View File
@@ -262,16 +262,6 @@ void boardOff()
SysTick->CTRL = 0; // turn off systick SysTick->CTRL = 0; // turn off systick
// Shutdown the Audio amp
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = AUDIO_SHUTDOWN_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(AUDIO_SHUTDOWN_GPIO, &GPIO_InitStructure);
GPIO_ResetBits(AUDIO_SHUTDOWN_GPIO, AUDIO_SHUTDOWN_GPIO_PIN);
// Shutdown the Haptic // Shutdown the Haptic
hapticDone(); hapticDone();
+5 -2
View File
@@ -322,8 +322,6 @@
// Audio // Audio
#define AUDIO_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOH) #define AUDIO_RCC_AHB1Periph (RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOH)
#define AUDIO_RCC_APB2Periph RCC_APB2Periph_SPI1 #define AUDIO_RCC_APB2Periph RCC_APB2Periph_SPI1
#define AUDIO_SHUTDOWN_GPIO GPIOH
#define AUDIO_SHUTDOWN_GPIO_PIN GPIO_Pin_8 // PH.08 audio amp control pin
#define AUDIO_XDCS_GPIO GPIOH #define AUDIO_XDCS_GPIO GPIOH
#define AUDIO_XDCS_GPIO_PIN GPIO_Pin_14 // PH.14 #define AUDIO_XDCS_GPIO_PIN GPIO_Pin_14 // PH.14
#define AUDIO_CS_GPIO GPIOH #define AUDIO_CS_GPIO GPIOH
@@ -343,6 +341,11 @@
#define AUDIO_SPI_MOSI_GPIO GPIOB #define AUDIO_SPI_MOSI_GPIO GPIOB
#define AUDIO_SPI_MOSI_GPIO_PIN GPIO_Pin_5 // PB.05 #define AUDIO_SPI_MOSI_GPIO_PIN GPIO_Pin_5 // PB.05
#define AUDIO_SPI_MOSI_GPIO_PinSource GPIO_PinSource5 #define AUDIO_SPI_MOSI_GPIO_PinSource GPIO_PinSource5
#define AUDIO_MUTE_GPIO GPIOH
#define AUDIO_MUTE_GPIO_PIN GPIO_Pin_8 // PH.08 audio amp control pin
#define AUDIO_UNMUTE_DELAY 120 // ms
#define AUDIO_MUTE_DELAY 500 // ms
#define INVERTED_MUTE_PIN
// I2C Bus // I2C Bus
#define I2C_B1 I2C1 #define I2C_B1 I2C1