Skip to content

Commit

Permalink
Fixed audio after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
richardclli committed Jan 20, 2025
1 parent 6c25433 commit b19e840
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 27 deletions.
47 changes: 37 additions & 10 deletions radio/src/targets/pl18/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "stm32_adc.h"
#include "stm32_gpio.h"
#include "stm32_ws2812.h"
#include "stm32_spi.h"

#include "hal/adc_driver.h"
#include "hal/trainer_driver.h"
Expand All @@ -41,6 +42,10 @@
#include "touch.h"
#include "debug.h"

#if defined(AUDIO_SPI)
#include "vs1053b.h"
#endif

#if defined(FLYSKY_GIMBAL)
#include "flysky_gimbal_driver.h"
#endif
Expand Down Expand Up @@ -84,6 +89,29 @@ extern "C" void flushFTL();
}
#endif

#if defined(AUDIO_SPI)
stm32_spi_t audioSpi =
{
.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 =
{
.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,
};
#endif

void delay_self(int count)
{
for (int i = 50000; i > 0; i--)
Expand Down Expand Up @@ -160,6 +188,11 @@ void boardInit()
pwrInit();
boardInitModulePorts();

#if defined(AUDIO_SPI)
gpio_init(AUDIO_RST_GPIO, GPIO_OUT, GPIO_PIN_SPEED_MEDIUM);
gpio_init(AUDIO_MUTE_GPIO, GPIO_OUT, GPIO_PIN_SPEED_MEDIUM);
#endif

board_trainer_init();
battery_charge_init();

Expand Down Expand Up @@ -215,7 +248,11 @@ void boardInit()
#if defined(RADIO_NB4P)
disableVoiceChip();
#endif
#if defined(AUDIO_SPI)
vs1053b_init(&audioConfig);
#else
audioInit();
#endif
monitorInit();
adcInit(&_adc_driver);
hapticInit();
Expand All @@ -226,16 +263,6 @@ void boardInit()
#endif

lcdSetInitalFrameBuffer(lcdFront->getData());

#if defined(DEBUG)
/* DBGMCU_APB1PeriphConfig(
DBGMCU_IWDG_STOP | DBGMCU_TIM1_STOP | DBGMCU_TIM2_STOP |
DBGMCU_TIM3_STOP | DBGMCU_TIM4_STOP | DBGMCU_TIM5_STOP |
DBGMCU_TIM6_STOP | DBGMCU_TIM7_STOP | DBGMCU_TIM8_STOP |
DBGMCU_TIM9_STOP | DBGMCU_TIM10_STOP | DBGMCU_TIM11_STOP |
DBGMCU_TIM12_STOP | DBGMCU_TIM13_STOP | DBGMCU_TIM14_STOP,
ENABLE);*/
#endif
}

extern void rtcDisableBackupReg();
Expand Down
8 changes: 6 additions & 2 deletions radio/src/targets/pl18/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ void getCPUUniqueID(char * s);
PCBREV_EL18 = 1,
};

#define HAS_HARDWARE_OPTIONS

typedef struct {
uint8_t pcbrev;
} HardwareOptions;
Expand Down Expand Up @@ -250,8 +252,10 @@ bool isBacklightEnabled();
#define DISABLE_UCHARGER()
#endif

// Audio driver
void audioInit();
#if !defined(AUDIO_SPI)
// DAC Audio driver
void audioInit();
#endif

// Telemetry driver
#define INTMODULE_FIFO_SIZE 512
Expand Down
23 changes: 8 additions & 15 deletions radio/src/targets/pl18/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,22 +672,15 @@

// Audio
#if defined(RADIO_NV14_FAMILY)
#define AUDIO_XDCS_GPIO GPIOH
#define AUDIO_XDCS_GPIO_PIN LL_GPIO_PIN_14 // PH.14
#define AUDIO_CS_GPIO GPIOH
#define AUDIO_CS_GPIO_PIN LL_GPIO_PIN_13 // PH.13
#define AUDIO_DREQ_GPIO GPIOH
#define AUDIO_DREQ_GPIO_PIN LL_GPIO_PIN_15 // PH.15
#define AUDIO_RST_GPIO GPIOD
#define AUDIO_RST_GPIO_PIN LL_GPIO_PIN_4 // PD.04
#define AUDIO_XDCS_GPIO GPIO_PIN(GPIOH, 14) // PH.14
#define AUDIO_CS_GPIO GPIO_PIN(GPIOH, 13) // PH.13
#define AUDIO_DREQ_GPIO GPIO_PIN(GPIOH, 15) // PH.15
#define AUDIO_RST_GPIO GPIO_PIN(GPIOD, 4) // PD.04
#define AUDIO_SPI SPI1
#define AUDIO_SPI_GPIO_AF LL_GPIO_AF_5
#define AUDIO_SPI_SCK_GPIO GPIOB
#define AUDIO_SPI_SCK_GPIO_PIN LL_GPIO_PIN_3 // PB.03
#define AUDIO_SPI_MISO_GPIO GPIOB
#define AUDIO_SPI_MISO_GPIO_PIN LL_GPIO_PIN_4 // PB.04
#define AUDIO_SPI_MOSI_GPIO GPIOB
#define AUDIO_SPI_MOSI_GPIO_PIN LL_GPIO_PIN_5 // PB.05
#define AUDIO_SPI_SCK_GPIO GPIO_PIN(GPIOB, 3) // PB.03
#define AUDIO_SPI_MISO_GPIO GPIO_PIN(GPIOB, 4) // PB.04
#define AUDIO_SPI_MOSI_GPIO GPIO_PIN(GPIOB, 5) // PB.05
#else
#define AUDIO_RCC_APB1Periph (RCC_APB1Periph_TIM6 | RCC_APB1Periph_DAC)
#define AUDIO_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_DMA1)
Expand All @@ -705,7 +698,7 @@
#define AUDIO_MUTE_GPIO GPIO_PIN(GPIOH, 8) // PH.08 audio amp control pin
#define AUDIO_UNMUTE_DELAY 120 // ms
#define AUDIO_MUTE_DELAY 500 // ms
#define INVERTED_MUTE_PIN
#define AUDIO_MUTE_POL VS1053B_MUTE_INVERTED
#elif defined(RADIO_NB4P)
#define AUDIO_MUTE_GPIO GPIO_PIN(GPIOH, 9) // PH.09 audio amp control pin
#define AUDIO_UNMUTE_DELAY 120 // ms
Expand Down

0 comments on commit b19e840

Please sign in to comment.