Moved speaker code to its own driver

It appears it will take some work to feed PWM with DMA.
chibios
Marshal Horn 2020-07-16 21:27:07 -07:00
rodzic 45b914dbb8
commit 98a508629a
5 zmienionych plików z 73 dodań i 31 usunięć

Wyświetl plik

@ -166,6 +166,7 @@
#define STM32_PWM_TIM1_IRQ_PRIORITY 3
#define STM32_PWM_TIM2_IRQ_PRIORITY 3
#define STM32_PWM_TIM3_IRQ_PRIORITY 3
#define STM32_PWM_TIM3_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
/*
* SERIAL driver system settings.

Wyświetl plik

@ -0,0 +1,53 @@
#include "speaker.h"
static const DMAConfig spkr_dma = {
.stream = STM32_ICU1_CH1_DMA_STREAM,
.channel = STM32_ICU1_CH1_DMA_CHANNEL,
.dma_priority = STM32_ICU1_CH1_DMA_PRIORITY,
.irq_priority = STM32_ICU1_CH1_DMA_IRQ_PRIORITY,
.periph_addr = &TIM3->DMAR,
.direction = DMA_DIR_P2M,
.psize = 2,
.msize = 2,
.inc_peripheral_addr = false,
.inc_memory_addr = true,
.circular = true,
.error_cb = &error_cb,
.end_cb = &end_cb,
.mburst = 8,
.fifo = 4
};
//DMA channels is STM32_PWM_TIM3_DMA_STREAM
void speakerUpdate(int16_t data, int len);
/** Copies audio data to PWM
*
*/
void speaker_callback(PWMDriver * pwmp){
//FIXME: Copy data into DMA buffer. Or interrupt every period.
}
static PWMConfig spkr = {
.frequency = 4096000, /* 4MHz PWM clock frequency. */
.period = 4096, /* Initial PWM period 1ms. */
.callback = speaker_callback,
.channels = {
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL}
},
.cr2 = 0,
.dier = STM32_TIM_DIER_CC1DE, // DMA request on channel 1 compare match
};
void speakerStart(void){
pwmStart(&PWMD3, &spkr);
}
void speakerStop(void){
pwmStop(&PWMD3);
}

Wyświetl plik

@ -0,0 +1,6 @@
#include "hal.h"
void speakerStart(void);
void speakerStop(void);
void speakerUpdate(int16_t data, int len);

Wyświetl plik

@ -7,6 +7,7 @@
#include "rx.h"
#include "ssb.h"
#include "../drivers/speaker.h"
/** Mailbox for received data */
mailbox_t new_sample;
@ -116,28 +117,3 @@ void adc_rx_init(void){
adcStartConversion(&ADCD1, &qsd_in, samples, len);
}
/** Copies audio data to PWM
*
*/
void speaker_callback(PWMDriver * pwmp){
//FIXME: Copy data into DMA buffer. Or interrupt every period.
}
static PWMConfig spkr = {
4096000, /* 4MHz PWM clock frequency. */
4096, /* Initial PWM period 1ms. */
speaker_callback,
{
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL}
},
0,
0
};
void speaker_init(void){
}

Wyświetl plik

@ -11,12 +11,22 @@
#include "hal.h"
#include "ch.h"
/** List of radio modes.
*
* This list will be expanded as more modes are supported
*/
enum radio_mode {
CW, //< Continuous wave, also known as morse code
USB,//< Upper Sideband, for frequencies above 10MHz
LSB,//< Lower sideband, for frequencies below 10MHz
};
/** Starts radio reception and demodulation
*
*/
void rxStart(uint8_t mode);
void rxStart(enum radio_mode mode, float frequency);
/* Pauses radio reception and demodulation
/* Stops radio reception and demodulation
*
*/
void rxStop(void);
@ -58,8 +68,4 @@ static void adccallback(ADCDriver *adcp);
*/
void adc_rx_init(void);
void speaker_init(void);
void speaker_update(int16_t data, int len);
#endif /* RX_H_ */