Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions radio/src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,19 @@ class AudioBufferFifo {
private:
volatile uint8_t readIdx;
volatile uint8_t writeIdx;
volatile bool bufferFull;

inline uint8_t nextBufferIdx(uint8_t idx) const
{
return (idx >= AUDIO_BUFFER_COUNT - 1 ? 0 : idx + 1);
}

bool full() const { return readIdx == nextBufferIdx(writeIdx); }
bool full() const { return bufferFull; }
bool empty() const { return readIdx == writeIdx; }
uint8_t used() const { return (writeIdx - readIdx) % AUDIO_BUFFER_COUNT; }

public:
AudioBufferFifo() : readIdx(0), writeIdx(0)
AudioBufferFifo() : readIdx(0), writeIdx(0), bufferFull(false)
{
memset(audioBuffers, 0, sizeof(audioBuffers));
}
Expand All @@ -326,10 +327,17 @@ class AudioBufferFifo {
}

// puts filled buffer into FIFO
void audioPushBuffer() { writeIdx = nextBufferIdx(writeIdx); }
void audioPushBuffer()
{
writeIdx = nextBufferIdx(writeIdx);
if (writeIdx == readIdx) bufferFull = true;
}

// frees the last played buffer
void freeNextFilledBuffer() { readIdx = nextBufferIdx(readIdx); }
void freeNextFilledBuffer()
{
readIdx = nextBufferIdx(readIdx);
bufferFull = false;
}

// returns a pointer to the audio buffer to be played
const AudioBuffer *getNextFilledBuffer()
Expand Down
15 changes: 13 additions & 2 deletions radio/src/targets/common/arm/stm32/audio_dac_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,12 @@ void dacInit()

// use TIM6 TRGO as trigger (TSEL1 = TSEL2 = 000)
// enable DAC & channel 1 trigger
AUDIO_DAC->CR = DAC_CR_TEN1 | DAC_CR_EN1;
AUDIO_DAC->CR = DAC_CR_TEN1 | DAC_CR_EN1 | DAC_CR_DMAUDRIE1;
#endif
NVIC_EnableIRQ(AUDIO_DMA_Stream_IRQn);
NVIC_SetPriority(AUDIO_DMA_Stream_IRQn, 7);
NVIC_EnableIRQ(AUDIO_TIM_IRQn);
NVIC_SetPriority(AUDIO_TIM_IRQn, 7);
}

#if defined(AUDIO_MUTE_GPIO)
Expand Down Expand Up @@ -299,7 +301,7 @@ void audioConsumeCurrentBuffer()
AUDIO_DAC->SR = DAC_SR_DMAUDR1;

// enable DAC
AUDIO_DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1;
AUDIO_DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1 | DAC_CR_DMAUDRIE1;
#endif
} else {
#if defined(AUDIO_MUTE_GPIO)
Expand All @@ -325,6 +327,15 @@ void audioEnd()
NVIC_DisableIRQ(AUDIO_DMA_Stream_IRQn);
}

extern "C" void AUDIO_TIM_IRQHandler()
{
DEBUG_INTERRUPT(INT_AUDIO);
if (AUDIO_DAC->SR & DAC_SR_DMAUDR1) {
AUDIO_DAC->CR &= ~(DAC_CR_DMAEN1 | DAC_CR_DMAUDRIE1);
AUDIO_DAC->SR = DAC_SR_DMAUDR1;
}
}

extern "C" void AUDIO_DMA_Stream_IRQHandler()
{
#if defined(STM32H5) || defined(STM32H7) || defined(STM32H7RS)
Expand Down
10 changes: 10 additions & 0 deletions radio/src/targets/common/arm/stm32/spi_flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include "stm32_gpio.h"

#include "hal.h"
#if !defined(BOOT)
#include "rtos.h"
#endif

#define CS_HIGH() stm32_spi_unselect(&_flash_spi)
#define CS_LOW() stm32_spi_select(&_flash_spi)
Expand Down Expand Up @@ -147,6 +150,13 @@ static void flash_wait_for_not_busy()
uint8_t status;
do {
flash_do_cmd(FLASH_CMD_STATUS, 0, &status, 1);
if (status & 0x01) {
#if !defined(BOOT)
RTOS_WAIT_MS(1);
#else
delay_ms(1);
#endif
}
} while (status & 0x01);
}

Expand Down
Loading