Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ------------------------ INCLUDES --------------//
- #include "supportFunctions.h"
- #include "Constants.h"
- #include "I2S.h"
- #include "Clock.h"
- #include "Interrupt.h"
- #include "UART.h"
- // ------------------------ GLOBAL VARIABLES ----------//
- int RxBuff_inline[4]; // incoming Audio Signal (inline)
- int TxBuff_inline[4]; // Outgoing Audio Signal (inline)
- int RxBuff_bluetooth[1024];
- int TxBuff_bluetooth[1024];
- float * IIR_Coeffs;
- float * IIR_State;
- float inSample_inline_L[2]; // Goes to RxBuff -> inSample
- float inSample_inline_R[2];
- float outSample_inline_L[2]; // Goes to RxBuff -> inSample
- float outSample_inline_R[2];
- float inSample_bluetooth_L[2]; // Goes to RxBuff -> inSample
- float inSample_bluetooth_R[2];
- float outSample_bluetooth_L[2]; // Goes to outSamples -> TxBuff
- float outSample_bluetooth_R[2];
- float inputcompensator = 1.0;
- uint8_t inLine_Rx_Complete_Callback = 0; // When half the audio samples arrive
- uint8_t inLine_Rx_Half_Callback = 0; // When the full audio samples arrive
- uint8_t bluetooth_Rx_Complete_Callback = 0; // When half the audio samples arrive
- uint8_t bluetooth_Rx_Half_Callback = 0; // When the full audio samples arrive
- uint8_t UART_Rx_Callback = 0; // When STM32 Receives a UART command
- uint8_t highShelfEnable = 0; // High Shelf Filters are in use
- uint8_t lowShelfEnable = 0; // Low Shelf Filters are in use
- uint8_t ESP_to_STM32[1]; // Buffer to store UART commands from ESP to STM32
- uint8_t volumePacket = 0; // Volume Packet is being received
- uint8_t volumeCurrent = 50; //Current Volume
- uint8_t sourceMode = 0;
- arm_biquad_casd_df1_inst_f32 audioStream_L; // Creates a ARM strut
- arm_biquad_casd_df1_inst_f32 audioStream_R;
- IIR Filters; // Creates a structure holding all EQ Filters
- pState stateVariables;
- int main(void) {
- // ----------------------------------------------- INIT ------------------------------- //
- init_Clock();
- //init_I2S_Inline(RxBuff_inline, TxBuff_inline);
- init_I2S_Bluetooth(RxBuff_bluetooth, TxBuff_bluetooth);
- init_UART(ESP_to_STM32);
- init_IIRFilter(IIR_Coeffs, IIR_State, &Filters);
- init_Interrupt();
- while (1) {
- // -------------------------------------------- SOURCE SELECTOR ---------------------- //
- if (inLine_Rx_Half_Callback == OK) {
- prcoess_inline_halfSample(RxBuff_inline, TxBuff_inline, inSample_inline_L, inSample_inline_R, outSample_inline_L, outSample_inline_R, volumeScale, volumeCurrent, &audioStream_L, &audioStream_R, inputcompensator);
- inLine_Rx_Half_Callback = RESET;
- } else if (inLine_Rx_Complete_Callback == OK) {
- process_inline_CompleteSample(RxBuff_inline, TxBuff_inline, inSample_inline_L, inSample_inline_R, outSample_inline_L, outSample_inline_R, volumeScale, volumeCurrent, &audioStream_L, &audioStream_R, inputcompensator);
- inLine_Rx_Complete_Callback = RESET;
- } else if (bluetooth_Rx_Half_Callback == OK) {
- prcoess_bluetooth_halfSample(RxBuff_bluetooth, TxBuff_bluetooth, inSample_bluetooth_L, inSample_bluetooth_R, outSample_bluetooth_L, outSample_bluetooth_R, volumeScale, volumeCurrent, &audioStream_L, &audioStream_R, inputcompensator);
- bluetooth_Rx_Half_Callback = RESET;
- } else if (bluetooth_Rx_Complete_Callback) {
- prcoess_bluetooth_CompleteSample(RxBuff_bluetooth, TxBuff_bluetooth, inSample_bluetooth_L, inSample_bluetooth_R, outSample_bluetooth_L, outSample_bluetooth_R, volumeScale, volumeCurrent, &audioStream_L, &audioStream_R, inputcompensator);
- bluetooth_Rx_Complete_Callback = RESET;
- } else if (UART_Rx_Callback == OK) {
- processUartPacket(ESP_to_STM32, &volumePacket, &volumeCurrent, &audioStream_L, &audioStream_R, Filters, &inputcompensator, &sourceMode, stateVariables);
- UART_Rx_Callback = RESET;
- }
- }
- }
- void DMA1_Stream3_IRQHandler(void) {
- if (((DMA1 -> LISR) & (DMA_LISR_TCIF3)) != 0) {
- DMA1 -> LIFCR |= DMA_LIFCR_CTCIF3;
- UART_Rx_Callback = 1;
- }
- }
- void DMA1_Stream0_IRQHandler(void) {
- if (((DMA1 -> LISR) & (DMA_LISR_TCIF0)) != 0) {
- DMA1 -> LIFCR |= DMA_LIFCR_CTCIF0;
- inLine_Rx_Complete_Callback = 1;
- } else if (((DMA1 -> LISR) & (DMA_LISR_HTIF0)) != 0) {
- DMA1 -> LIFCR |= DMA_LIFCR_CHTIF0;
- inLine_Rx_Half_Callback = 1;
- }
- }
- void DMA1_Stream4_IRQHandler(void) {
- if (((DMA1 -> HISR) & (DMA_HISR_TCIF4)) != 0) {
- DMA1 -> HIFCR |= DMA_HIFCR_CTCIF4;
- bluetooth_Rx_Complete_Callback = 1;
- } else if (((DMA1 -> HISR) & (DMA_HISR_HTIF4)) != 0) {
- DMA1 -> HIFCR |= DMA_HIFCR_CHTIF4;
- bluetooth_Rx_Half_Callback = 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement