Skip to content

Commit

Permalink
feat(vs1053b): use callbacks for RST & MUTE pins (#5836)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic authored Jan 30, 2025
1 parent 8256688 commit 21012d3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 40 deletions.
22 changes: 7 additions & 15 deletions radio/src/targets/common/arm/stm32/vs1053b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,23 @@ static inline uint32_t _read_dreq() { return gpio_read(_instance->DREQ); }

static inline void _reset_high()
{
if (_instance->RST != GPIO_UNDEF) {
gpio_set(_instance->RST);
if (_instance->set_rst_pin) {
_instance->set_rst_pin(true);
}
}

static inline void _reset_low()
{
if (_instance->RST != GPIO_UNDEF) {
gpio_clear(_instance->RST);
if (_instance->set_rst_pin) {
_instance->set_rst_pin(false);
}
}

static inline void _set_mute_pin(bool muted)
{
if (_instance->MUTE != GPIO_UNDEF) {
if (_instance->set_mute_pin) {
_is_muted = muted;
bool inv = _instance->flags & VS1053B_MUTE_INVERTED;
gpio_write(_instance->MUTE, inv ? !muted : muted);
_instance->set_mute_pin(muted);
}
}

Expand All @@ -124,14 +123,7 @@ static void vs1053b_gpio_init(void)
gpio_init(_instance->XDCS, GPIO_OUT, GPIO_PIN_SPEED_HIGH);
gpio_init(_instance->DREQ, GPIO_IN, GPIO_PIN_SPEED_HIGH);

if (_instance->RST != GPIO_UNDEF) {
gpio_init(_instance->RST, GPIO_OUT, GPIO_PIN_SPEED_HIGH);
}

if (_instance->MUTE != GPIO_UNDEF) {
gpio_init(_instance->MUTE, GPIO_OUT, GPIO_PIN_SPEED_HIGH);
_set_mute_pin(true);
}
_set_mute_pin(true);

stm32_spi_init(_instance->spi, LL_SPI_DATAWIDTH_8BIT);
}
Expand Down
8 changes: 3 additions & 5 deletions radio/src/targets/common/arm/stm32/vs1053b.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@
#include "hal/gpio.h"
#include "stm32_spi.h"

#define VS1053B_MUTE_INVERTED (1 << 0)

typedef struct {
stm32_spi_t* spi;

gpio_t XDCS;
gpio_t DREQ;
gpio_t RST;
gpio_t MUTE;

uint32_t flags;
void (*set_rst_pin)(bool set);
void (*set_mute_pin)(bool set);

uint32_t mute_delay_ms;
uint32_t unmute_delay_ms;
} vs1053b_t;
Expand Down
9 changes: 8 additions & 1 deletion radio/src/targets/horus/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ void boardBLEarlyInit()
#include "edgetx.h"

#if defined(PCBX12S)
static void audio_set_rst_pin(bool set)
{
gpio_write(AUDIO_RST_GPIO, set);
}

void audioInit()
{
static stm32_spi_t spi_dev = {
Expand All @@ -101,11 +106,13 @@ void audioInit()
.spi = &spi_dev,
.XDCS = AUDIO_XDCS_GPIO,
.DREQ = AUDIO_DREQ_GPIO,
.RST = AUDIO_RST_GPIO,
.set_rst_pin = audio_set_rst_pin,
};

gpio_init(AUDIO_RST_GPIO, GPIO_OUT, 0);
gpio_init(AUDIO_SHUTDOWN_GPIO, GPIO_OUT, 0);
gpio_set(AUDIO_SHUTDOWN_GPIO);

vs1053b_init(&vs1053);
}
#endif
Expand Down
53 changes: 34 additions & 19 deletions radio/src/targets/nv14/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,41 @@ static uint8_t boardGetPcbRev()
}
}

stm32_spi_t audioSpi =
static void audio_set_rst_pin(bool set)
{
.SPIx = AUDIO_SPI,
.SCK = AUDIO_SPI_SCK_GPIO,
.MISO = AUDIO_SPI_MISO_GPIO,
.MOSI = AUDIO_SPI_MOSI_GPIO,
.CS = AUDIO_CS_GPIO,
};

vs1053b_t audioConfig =
gpio_write(AUDIO_RST_GPIO, set);
}

static void audio_set_mute_pin(bool set)
{
gpio_write(AUDIO_MUTE_GPIO, !set);
}

static void audioInit()
{
.spi = &audioSpi,
.XDCS = AUDIO_XDCS_GPIO,
.DREQ = AUDIO_DREQ_GPIO,
.RST = AUDIO_RST_GPIO,
.MUTE = AUDIO_MUTE_GPIO,
.flags = AUDIO_MUTE_POL,
.mute_delay_ms = AUDIO_MUTE_DELAY,
.unmute_delay_ms = AUDIO_UNMUTE_DELAY,
};
static stm32_spi_t spi_dev = {
.SPIx = AUDIO_SPI,
.SCK = AUDIO_SPI_SCK_GPIO,
.MISO = AUDIO_SPI_MISO_GPIO,
.MOSI = AUDIO_SPI_MOSI_GPIO,
.CS = AUDIO_CS_GPIO,
};

static vs1053b_t vs1053 = {
.spi = &spi_dev,
.XDCS = AUDIO_XDCS_GPIO,
.DREQ = AUDIO_DREQ_GPIO,
.set_rst_pin = audio_set_rst_pin,
.set_mute_pin = audio_set_mute_pin,
.mute_delay_ms = AUDIO_MUTE_DELAY,
.unmute_delay_ms = AUDIO_UNMUTE_DELAY,
};

gpio_init(AUDIO_RST_GPIO, GPIO_OUT, 0);
gpio_init(AUDIO_MUTE_GPIO, GPIO_OUT, 0);

vs1053b_init(&vs1053);
}

void boardBLEarlyInit()
{
Expand Down Expand Up @@ -194,7 +209,7 @@ void boardInit()

keysInit();
switchInit();
vs1053b_init(&audioConfig);
audioInit();
monitorInit();
adcInit(&_adc_driver);
hapticInit();
Expand Down

0 comments on commit 21012d3

Please sign in to comment.