Skip to content

Commit

Permalink
refactor(vs1053b): make most functions private
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic committed Jan 16, 2025
1 parent fdbb09a commit 202805b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 63 deletions.
1 change: 1 addition & 0 deletions radio/src/hal/audio_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@


void audioSetVolume(uint8_t volume);
void audioConsumeCurrentBuffer();

44 changes: 20 additions & 24 deletions radio/src/targets/common/arm/stm32/vs1053b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#include "board.h"
#include "edgetx.h"

#if !defined(SIMU)

#define VS_WRITE_COMMAND 0x02
#define VS_READ_COMMAND 0x03

Expand Down Expand Up @@ -96,7 +94,7 @@ static const stm32_spi_t _audio_spi = {
.CS_Pin = AUDIO_CS_GPIO_PIN,
};

void audioSpiInit(void)
static void audioSpiInit(void)
{
stm32_gpio_enable_clock(AUDIO_XDCS_GPIO);
stm32_gpio_enable_clock(AUDIO_RST_GPIO);
Expand All @@ -119,13 +117,13 @@ void audioSpiInit(void)
stm32_spi_init(&_audio_spi, LL_SPI_DATAWIDTH_8BIT);
}

void audioWaitReady()
{
// The audio amp needs ~2s to start
RTOS_WAIT_MS(2000); // 2s
}
// static void audioWaitReady()
// {
// // The audio amp needs ~2s to start
// RTOS_WAIT_MS(2000); // 2s
// }

void audioSpiSetSpeed(uint8_t speed)
static void audioSpiSetSpeed(uint8_t speed)
{
AUDIO_SPI->CR1 &= 0xFFC7; // Fsck=Fcpu/256
switch (speed) {
Expand Down Expand Up @@ -157,12 +155,12 @@ void audioSpiSetSpeed(uint8_t speed)
AUDIO_SPI->CR1 |= 0x01 << 6;
}

uint8_t audioSpiReadWriteByte(uint8_t value)
static uint8_t audioSpiReadWriteByte(uint8_t value)
{
return stm32_spi_transfer_byte(&_audio_spi, value);
}

uint8_t audioWaitDreq(int32_t delay_us)
static uint8_t audioWaitDreq(int32_t delay_us)
{
while (READ_DREQ() == 0) {
if (delay_us-- == 0) return 0;
Expand All @@ -171,7 +169,7 @@ uint8_t audioWaitDreq(int32_t delay_us)
return 1;
}

uint16_t audioSpiReadReg(uint8_t address)
static uint16_t audioSpiReadReg(uint8_t address)
{
if (!audioWaitDreq(100))
return 0;
Expand Down Expand Up @@ -207,13 +205,13 @@ static uint8_t audioSpiWriteCmd(uint8_t address, uint16_t data)
return 1;
}

void audioResetDecodeTime(void)
static void audioResetDecodeTime(void)
{
audioSpiWriteCmd(SPI_DECODE_TIME, 0x0000);
audioSpiWriteCmd(SPI_DECODE_TIME, 0x0000);
}

uint8_t audioHardReset(void)
static uint8_t audioHardReset(void)
{
XDCS_HIGH();
CS_HIGH();
Expand All @@ -228,7 +226,7 @@ uint8_t audioHardReset(void)
return 1;
}

uint8_t audioSoftReset(void)
static uint8_t audioSoftReset(void)
{
audioSpiSetSpeed(SPI_SPEED_64);
if (!audioWaitDreq(100))
Expand Down Expand Up @@ -262,7 +260,7 @@ uint8_t audioSoftReset(void)
return 1;
}

uint32_t audioSpiWriteData(const uint8_t * buffer, uint32_t size)
static uint32_t audioSpiWriteData(const uint8_t * buffer, uint32_t size)
{
XDCS_LOW();

Expand All @@ -275,7 +273,7 @@ uint32_t audioSpiWriteData(const uint8_t * buffer, uint32_t size)
return index;
}

void audioSpiWriteBuffer(const uint8_t * buffer, uint32_t size)
static void audioSpiWriteBuffer(const uint8_t * buffer, uint32_t size)
{
const uint8_t * p = buffer;
while (size > 0) {
Expand Down Expand Up @@ -306,7 +304,7 @@ const uint8_t RiffHeader[] = {
0x00, 0x00, 0x00, 0x00, // data
};

void audioSendRiffHeader()
static void audioSendRiffHeader()
{
audioSpiWriteBuffer(RiffHeader, sizeof(RiffHeader));
}
Expand All @@ -329,7 +327,7 @@ static inline bool getMutePin(void)
return muted;
}

void audioMute()
static void audioMute()
{
#if defined(AUDIO_UNMUTE_DELAY)
tmr10ms_t now = get_tmr10ms();
Expand All @@ -346,7 +344,7 @@ void audioMute()
#endif
}

void audioUnmute()
static void audioUnmute()
{
if(isFunctionActive(FUNCTION_DISABLE_AUDIO_AMP)) {
setMutePin(true);
Expand All @@ -369,7 +367,7 @@ void audioUnmute()
#endif

#if defined(PCBX12S)
void audioShutdownInit()
static void audioShutdownInit()
{
gpio_init(AUDIO_SHUTDOWN_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);

Expand Down Expand Up @@ -412,7 +410,7 @@ static int32_t get_volume()
return -1; // TODO
}

void audioSetCurrentBuffer(const AudioBuffer * buffer)
static void audioSetCurrentBuffer(const AudioBuffer * buffer)
{
if (buffer) {
currentBuffer = (uint8_t *)buffer->data;
Expand Down Expand Up @@ -476,5 +474,3 @@ void audioSetVolume(uint8_t volume)
set_volume(vol);
}
}

#endif
1 change: 0 additions & 1 deletion radio/src/targets/horus/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ bool isBacklightEnabled();

// Audio driver
void audioInit();
void audioConsumeCurrentBuffer();

// Telemetry driver
#define INTMODULE_FIFO_SIZE 512
Expand Down
19 changes: 0 additions & 19 deletions radio/src/targets/nv14/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,6 @@ bool isBacklightEnabled();

// Audio driver
void audioInit();
void audioConsumeCurrentBuffer();
void audioSpiWriteBuffer(const uint8_t * buffer, uint32_t size);
void audioSpiSetSpeed(uint8_t speed);
uint8_t audioHardReset();
uint8_t audioSoftReset();
void audioSendRiffHeader();
void audioOn();
void audioOff();
bool isAudioReady();
bool audioChipReset();

#define SPI_SPEED_2 0
#define SPI_SPEED_4 1
#define SPI_SPEED_8 2
#define SPI_SPEED_16 3
#define SPI_SPEED_32 4
#define SPI_SPEED_64 5
#define SPI_SPEED_128 6
#define SPI_SPEED_256 7

// Telemetry driver
#define INTMODULE_FIFO_SIZE 512
Expand Down
19 changes: 0 additions & 19 deletions radio/src/targets/pl18/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,6 @@ bool isBacklightEnabled();

// Audio driver
void audioInit();
void audioConsumeCurrentBuffer();
void audioSpiWriteBuffer(const uint8_t * buffer, uint32_t size);
void audioSpiSetSpeed(uint8_t speed);
uint8_t audioHardReset();
uint8_t audioSoftReset();
void audioSendRiffHeader();
void audioOn();
void audioOff();
bool isAudioReady();
bool audioChipReset();

#define SPI_SPEED_2 0
#define SPI_SPEED_4 1
#define SPI_SPEED_8 2
#define SPI_SPEED_16 3
#define SPI_SPEED_32 4
#define SPI_SPEED_64 5
#define SPI_SPEED_128 6
#define SPI_SPEED_256 7

// Telemetry driver
#define INTMODULE_FIFO_SIZE 512
Expand Down

0 comments on commit 202805b

Please sign in to comment.