Advertisement
Guest User

Untitled

a guest
Dec 5th, 2020
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.54 KB | None | 0 0
  1. // ------------------------ INCLUDES --------------//
  2.  
  3. #include "supportFunctions.h"
  4. #include "Constants.h"
  5. #include "I2S.h"
  6. #include "Clock.h"
  7. #include "Interrupt.h"
  8. #include "UART.h"
  9.  
  10. // ------------------------ GLOBAL VARIABLES ----------//
  11.  
  12. int RxBuff_inline[4]; // incoming Audio Signal (inline)
  13. int TxBuff_inline[4]; // Outgoing Audio Signal (inline)
  14. int RxBuff_bluetooth[1024];
  15. int TxBuff_bluetooth[1024];
  16.  
  17. float * IIR_Coeffs;
  18. float * IIR_State;
  19. float inSample_inline_L[2]; // Goes to RxBuff -> inSample
  20. float inSample_inline_R[2];
  21. float outSample_inline_L[2]; // Goes to RxBuff -> inSample
  22. float outSample_inline_R[2];
  23.  
  24. float inSample_bluetooth_L[2]; // Goes to RxBuff -> inSample
  25. float inSample_bluetooth_R[2];
  26. float outSample_bluetooth_L[2]; // Goes to outSamples -> TxBuff
  27. float outSample_bluetooth_R[2];
  28. float inputcompensator = 1.0;
  29.  
  30. uint8_t inLine_Rx_Complete_Callback = 0; // When half the audio samples arrive
  31. uint8_t inLine_Rx_Half_Callback = 0; // When the full audio samples arrive
  32. uint8_t bluetooth_Rx_Complete_Callback = 0; // When half the audio samples arrive
  33. uint8_t bluetooth_Rx_Half_Callback = 0; // When the full audio samples arrive
  34. uint8_t UART_Rx_Callback = 0; // When STM32 Receives a UART command
  35. uint8_t highShelfEnable = 0; // High Shelf Filters are in use
  36. uint8_t lowShelfEnable = 0; //  Low Shelf Filters are in use
  37. uint8_t ESP_to_STM32[1]; // Buffer to store UART commands from ESP to STM32
  38. uint8_t volumePacket = 0; // Volume Packet is being received
  39. uint8_t volumeCurrent = 50; //Current Volume
  40. uint8_t sourceMode = 0;
  41.  
  42. arm_biquad_casd_df1_inst_f32 audioStream_L; // Creates a ARM strut
  43. arm_biquad_casd_df1_inst_f32 audioStream_R;
  44. IIR Filters; // Creates a structure holding all EQ Filters
  45. pState stateVariables;
  46.  
  47. int main(void) {
  48.  
  49.   // ----------------------------------------------- INIT ------------------------------- //
  50.  
  51.   init_Clock();
  52.   //init_I2S_Inline(RxBuff_inline, TxBuff_inline);
  53.   init_I2S_Bluetooth(RxBuff_bluetooth, TxBuff_bluetooth);
  54.   init_UART(ESP_to_STM32);
  55.   init_IIRFilter(IIR_Coeffs, IIR_State, &Filters);
  56.   init_Interrupt();
  57.  
  58.  
  59.  
  60.   while (1) {
  61.  
  62.     // -------------------------------------------- SOURCE SELECTOR ---------------------- //
  63.  
  64.     if (inLine_Rx_Half_Callback == OK) {
  65.  
  66.       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);
  67.       inLine_Rx_Half_Callback = RESET;
  68.  
  69.     } else if (inLine_Rx_Complete_Callback == OK) {
  70.  
  71.       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);
  72.       inLine_Rx_Complete_Callback = RESET;
  73.  
  74.   }  else if (bluetooth_Rx_Half_Callback == OK) {
  75.  
  76.       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);
  77.       bluetooth_Rx_Half_Callback = RESET;
  78.  
  79.     } else if (bluetooth_Rx_Complete_Callback) {
  80.  
  81.       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);
  82.       bluetooth_Rx_Complete_Callback = RESET;
  83.  
  84.     } else if (UART_Rx_Callback == OK) {
  85.  
  86.       processUartPacket(ESP_to_STM32, &volumePacket, &volumeCurrent, &audioStream_L, &audioStream_R, Filters, &inputcompensator, &sourceMode, stateVariables);
  87.       UART_Rx_Callback = RESET;
  88.  
  89.     }
  90.  
  91.   }
  92.  
  93. }
  94.  
  95. void DMA1_Stream3_IRQHandler(void) {
  96.  
  97.   if (((DMA1 -> LISR) & (DMA_LISR_TCIF3)) != 0) {
  98.     DMA1 -> LIFCR |= DMA_LIFCR_CTCIF3;
  99.     UART_Rx_Callback = 1;
  100.   }
  101. }
  102.  
  103. void DMA1_Stream0_IRQHandler(void) {
  104.  
  105.   if (((DMA1 -> LISR) & (DMA_LISR_TCIF0)) != 0) {
  106.       DMA1 -> LIFCR |= DMA_LIFCR_CTCIF0;
  107.       inLine_Rx_Complete_Callback = 1;
  108.  
  109.   } else if (((DMA1 -> LISR) & (DMA_LISR_HTIF0)) != 0) {
  110.     DMA1 -> LIFCR |= DMA_LIFCR_CHTIF0;
  111.     inLine_Rx_Half_Callback = 1;
  112.  
  113.   }
  114. }
  115.  
  116. void DMA1_Stream4_IRQHandler(void) {
  117.  
  118.   if (((DMA1 -> HISR) & (DMA_HISR_TCIF4)) != 0) {
  119.       DMA1 -> HIFCR |= DMA_HIFCR_CTCIF4;
  120.       bluetooth_Rx_Complete_Callback = 1;
  121.  
  122.   } else if (((DMA1 -> HISR) & (DMA_HISR_HTIF4)) != 0) {
  123.     DMA1 -> HIFCR |= DMA_HIFCR_CHTIF4;
  124.     bluetooth_Rx_Half_Callback = 1;
  125.  
  126.   }
  127. }
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement