STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
stm32f769i_discovery_audio.c
Go to the documentation of this file.
1 
129 /* Includes ------------------------------------------------------------------*/
131 
149 typedef struct
150 {
151  uint16_t *pRecBuf; /* Pointer to record user buffer */
152  uint32_t RecSize; /* Size to record in mono, double size to record in stereo */
154 
169 /*### RECORD ###*/
170 #define DFSDM_OVER_SAMPLING(__FREQUENCY__) \
171  (__FREQUENCY__ == AUDIO_FREQUENCY_8K) ? 256 \
172  : (__FREQUENCY__ == AUDIO_FREQUENCY_11K) ? 256 \
173  : (__FREQUENCY__ == AUDIO_FREQUENCY_16K) ? 128 \
174  : (__FREQUENCY__ == AUDIO_FREQUENCY_22K) ? 128 \
175  : (__FREQUENCY__ == AUDIO_FREQUENCY_32K) ? 64 \
176  : (__FREQUENCY__ == AUDIO_FREQUENCY_44K) ? 64 \
177  : (__FREQUENCY__ == AUDIO_FREQUENCY_48K) ? 40 : 20 \
178 
179 #define DFSDM_CLOCK_DIVIDER(__FREQUENCY__) \
180  (__FREQUENCY__ == AUDIO_FREQUENCY_8K) ? 24 \
181  : (__FREQUENCY__ == AUDIO_FREQUENCY_11K) ? 4 \
182  : (__FREQUENCY__ == AUDIO_FREQUENCY_16K) ? 24 \
183  : (__FREQUENCY__ == AUDIO_FREQUENCY_22K) ? 4 \
184  : (__FREQUENCY__ == AUDIO_FREQUENCY_32K) ? 24 \
185  : (__FREQUENCY__ == AUDIO_FREQUENCY_44K) ? 4 \
186  : (__FREQUENCY__ == AUDIO_FREQUENCY_48K) ? 25 : 25 \
187 
188 #define DFSDM_FILTER_ORDER(__FREQUENCY__) \
189  (__FREQUENCY__ == AUDIO_FREQUENCY_8K) ? DFSDM_FILTER_SINC3_ORDER \
190  : (__FREQUENCY__ == AUDIO_FREQUENCY_11K) ? DFSDM_FILTER_SINC3_ORDER \
191  : (__FREQUENCY__ == AUDIO_FREQUENCY_16K) ? DFSDM_FILTER_SINC3_ORDER \
192  : (__FREQUENCY__ == AUDIO_FREQUENCY_22K) ? DFSDM_FILTER_SINC3_ORDER \
193  : (__FREQUENCY__ == AUDIO_FREQUENCY_32K) ? DFSDM_FILTER_SINC4_ORDER \
194  : (__FREQUENCY__ == AUDIO_FREQUENCY_44K) ? DFSDM_FILTER_SINC3_ORDER \
195  : (__FREQUENCY__ == AUDIO_FREQUENCY_48K) ? DFSDM_FILTER_SINC3_ORDER : DFSDM_FILTER_SINC5_ORDER \
196 
197 #define DFSDM_RIGHT_BIT_SHIFT(__FREQUENCY__) \
198  (__FREQUENCY__ == AUDIO_FREQUENCY_8K) ? 8 \
199  : (__FREQUENCY__ == AUDIO_FREQUENCY_11K) ? 8 \
200  : (__FREQUENCY__ == AUDIO_FREQUENCY_16K) ? 3 \
201  : (__FREQUENCY__ == AUDIO_FREQUENCY_22K) ? 4 \
202  : (__FREQUENCY__ == AUDIO_FREQUENCY_32K) ? 7 \
203  : (__FREQUENCY__ == AUDIO_FREQUENCY_44K) ? 0 \
204  : (__FREQUENCY__ == AUDIO_FREQUENCY_48K) ? 0 : 4 \
205 
206 /* Saturate the record PCM sample */
207 #define SaturaLH(N, L, H) (((N)<(L))?(L):(((N)>(H))?(H):(N)))
208 
215 /* PLAY */
219 
220 /* RECORD */
222 
223 DFSDM_Channel_HandleTypeDef hAudioInTopLeftChannel;
224 DFSDM_Channel_HandleTypeDef hAudioInTopRightChannel;
225 DFSDM_Filter_HandleTypeDef hAudioInTopLeftFilter;
226 DFSDM_Filter_HandleTypeDef hAudioInTopRightFilter;
229 
230 DFSDM_Channel_HandleTypeDef hAudioInButtomLeftChannel;
231 DFSDM_Channel_HandleTypeDef hAudioInButtomRightChannel;
232 DFSDM_Filter_HandleTypeDef hAudioInButtomLeftFilter;
233 DFSDM_Filter_HandleTypeDef hAudioInButtomRightFilter;
236 
237 /* Buffers for right and left samples */
238 static int32_t *pScratchBuff[2*DEFAULT_AUDIO_IN_CHANNEL_NBR];
239 static __IO int32_t ScratchSize;
240 /* Cannel number to be used: 2 channels by default */
241 static uint8_t AudioIn_ChannelNumber = DEFAULT_AUDIO_IN_CHANNEL_NBR;
242 /* Input device to be used: digital microphones by default */
243 static uint16_t AudioIn_Device = INPUT_DEVICE_DIGITAL_MIC;
244 
245 /* Buffers status flags */
246 static uint32_t DmaTopLeftRecHalfCplt = 0;
247 static uint32_t DmaTopLeftRecCplt = 0;
248 static uint32_t DmaTopRightRecHalfCplt = 0;
249 static uint32_t DmaTopRightRecCplt = 0;
250 static uint32_t DmaButtomLeftRecHalfCplt = 0;
251 static uint32_t DmaButtomLeftRecCplt = 0;
252 static uint32_t DmaButtomRightRecHalfCplt = 0;
253 static uint32_t DmaButtomRightRecCplt = 0;
254 
255 /* Application Buffer Trigger */
256 static __IO uint32_t AppBuffTrigger = 0;
257 static __IO uint32_t AppBuffHalf = 0;
258 
266 static void SAIx_Out_Init(uint32_t AudioFreq);
267 static void SAIx_Out_DeInit(void);
268 static void SAI_AUDIO_IN_MspInit(SAI_HandleTypeDef *hsai, void *Params);
269 static void SAI_AUDIO_IN_MspDeInit(SAI_HandleTypeDef *hsai, void *Params);
270 static void SAIx_In_Init(uint32_t AudioFreq);
271 static void SAIx_In_DeInit(void);
272 static void DFSDMx_ChannelMspInit(void);
273 static void DFSDMx_FilterMspInit(void);
274 static void DFSDMx_ChannelMspDeInit(void);
275 static void DFSDMx_FilterMspDeInit(void);
276 static uint8_t DFSDMx_Init(uint32_t AudioFreq);
277 static uint8_t DFSDMx_DeInit(void);
294 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
295 {
296  uint8_t ret = AUDIO_ERROR;
297  uint32_t deviceid = 0x00;
298 
299  /* Disable SAI */
300  SAIx_Out_DeInit();
301 
302  /* PLL clock is set depending by the AudioFreq (44.1khz vs 48khz groups) */
303  BSP_AUDIO_OUT_ClockConfig(&haudio_out_sai, AudioFreq, NULL);
304 
305  /* SAI data transfer preparation:
306  Prepare the Media to be used for the audio transfer from memory to SAI peripheral */
307  haudio_out_sai.Instance = AUDIO_OUT_SAIx;
308  if(HAL_SAI_GetState(&haudio_out_sai) == HAL_SAI_STATE_RESET)
309  {
310  /* Init the SAI MSP: this __weak function can be redefined by the application*/
311  BSP_AUDIO_OUT_MspInit(&haudio_out_sai, NULL);
312  }
313  SAIx_Out_Init(AudioFreq);
314 
315  /* wm8994 codec initialization */
316  deviceid = wm8994_drv.ReadID(AUDIO_I2C_ADDRESS);
317 
318  if((deviceid) == WM8994_ID)
319  {
320  /* Reset the Codec Registers */
322  /* Initialize the audio driver structure */
323  audio_drv = &wm8994_drv;
324  ret = AUDIO_OK;
325  }
326  else
327  {
328  ret = AUDIO_ERROR;
329  }
330 
331  if(ret == AUDIO_OK)
332  {
333  /* Initialize the codec internal registers */
334  audio_drv->Init(AUDIO_I2C_ADDRESS, OutputDevice, Volume, AudioFreq);
335  }
336 
337  return ret;
338 }
339 
346 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size)
347 {
348  /* Call the audio Codec Play function */
349  if(audio_drv->Play(AUDIO_I2C_ADDRESS, (uint16_t *)pBuffer, Size) != 0)
350  {
351  return AUDIO_ERROR;
352  }
353  else
354  {
355  /* Update the Media layer and enable it for play */
356  HAL_SAI_Transmit_DMA(&haudio_out_sai, (uint8_t*) pBuffer, DMA_MAX(Size / AUDIODATA_SIZE));
357 
358  return AUDIO_OK;
359  }
360 }
361 
362 void BSP_AUDIO_OUT_Restart(uint16_t* pBuffer, uint32_t Size)
363 {
364  HAL_SAI_Transmit_DMA(&haudio_out_sai, (uint8_t*) pBuffer, DMA_MAX(Size / AUDIODATA_SIZE));
365 }
366 
373 void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size)
374 {
375  HAL_SAI_Transmit_DMA(&haudio_out_sai, (uint8_t*) pData, Size);
376 }
377 
386 uint8_t BSP_AUDIO_OUT_Pause(void)
387 {
388  /* Call the Audio Codec Pause/Resume function */
389  if(audio_drv->Pause(AUDIO_I2C_ADDRESS) != 0)
390  {
391  return AUDIO_ERROR;
392  }
393  else
394  {
395  /* Call the Media layer pause function */
396  HAL_SAI_DMAPause(&haudio_out_sai);
397 
398  /* Return AUDIO_OK when all operations are correctly done */
399  return AUDIO_OK;
400  }
401 }
402 
410 uint8_t BSP_AUDIO_OUT_Resume(void)
411 {
412  /* Call the Audio Codec Pause/Resume function */
413  if(audio_drv->Resume(AUDIO_I2C_ADDRESS) != 0)
414  {
415  return AUDIO_ERROR;
416  }
417  else
418  {
419  /* Call the Media layer pause/resume function */
420  HAL_SAI_DMAResume(&haudio_out_sai);
421 
422  /* Return AUDIO_OK when all operations are correctly done */
423  return AUDIO_OK;
424  }
425 }
426 
436 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option)
437 {
438  /* Call the Media layer stop function */
439  HAL_SAI_DMAStop(&haudio_out_sai);
440 
441  /* Call Audio Codec Stop function */
442  if(audio_drv->Stop(AUDIO_I2C_ADDRESS, Option) != 0)
443  {
444  return AUDIO_ERROR;
445  }
446  else
447  {
448  if(Option == CODEC_PDWN_HW)
449  {
450  /* Wait at least 100us */
451  HAL_Delay(1);
452  }
453  /* Return AUDIO_OK when all operations are correctly done */
454  return AUDIO_OK;
455  }
456 }
457 
464 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume)
465 {
466  /* Call the codec volume control function with converted volume value */
467  if(audio_drv->SetVolume(AUDIO_I2C_ADDRESS, Volume) != 0)
468  {
469  return AUDIO_ERROR;
470  }
471  else
472  {
473  /* Return AUDIO_OK when all operations are correctly done */
474  return AUDIO_OK;
475  }
476 }
477 
484 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd)
485 {
486  /* Call the Codec Mute function */
487  if(audio_drv->SetMute(AUDIO_I2C_ADDRESS, Cmd) != 0)
488  {
489  return AUDIO_ERROR;
490  }
491  else
492  {
493  /* Return AUDIO_OK when all operations are correctly done */
494  return AUDIO_OK;
495  }
496 }
497 
505 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output)
506 {
507  /* Call the Codec output device function */
508  if(audio_drv->SetOutputMode(AUDIO_I2C_ADDRESS, Output) != 0)
509  {
510  return AUDIO_ERROR;
511  }
512  else
513  {
514  /* Return AUDIO_OK when all operations are correctly done */
515  return AUDIO_OK;
516  }
517 }
518 
526 void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq)
527 {
528  /* PLL clock is set depending by the AudioFreq (44.1khz vs 48khz groups) */
529  BSP_AUDIO_OUT_ClockConfig(&haudio_out_sai, AudioFreq, NULL);
530 
531  /* Disable SAI peripheral to allow access to SAI internal registers */
532  __HAL_SAI_DISABLE(&haudio_out_sai);
533 
534  /* Update the SAI audio frequency configuration */
535  haudio_out_sai.Init.AudioFrequency = AudioFreq;
536  HAL_SAI_Init(&haudio_out_sai);
537 
538  /* Enable SAI peripheral to generate MCLK */
539  __HAL_SAI_ENABLE(&haudio_out_sai);
540 }
541 
550 void BSP_AUDIO_OUT_SetAudioFrameSlot(uint32_t AudioFrameSlot)
551 {
552  /* Disable SAI peripheral to allow access to SAI internal registers */
553  __HAL_SAI_DISABLE(&haudio_out_sai);
554 
555  /* Update the SAI audio frame slot configuration */
556  haudio_out_sai.SlotInit.SlotActive = AudioFrameSlot;
557  HAL_SAI_Init(&haudio_out_sai);
558 
559  /* Enable SAI peripheral to generate MCLK */
560  __HAL_SAI_ENABLE(&haudio_out_sai);
561 }
562 
568 {
569  SAIx_Out_DeInit();
570  /* DeInit the SAI MSP : this __weak function can be rewritten by the application */
571  BSP_AUDIO_OUT_MspDeInit(&haudio_out_sai, NULL);
572 }
573 
580 {
582  /* Manage the remaining file size and new address offset: This function
583  should be coded by user (its prototype is already declared in stm32f769i_discovery_audio.h) */
584  if (hsai == &haudio_out_sai)
586  else
588 }
589 
596 {
597  extern void SPDIF_TX_HalfTransfer_CallBack();
598  /* Manage the remaining file size and new address offset: This function
599  should be coded by user (its prototype is already declared in stm32f769i_discovery_audio.h) */
600  if (hsai == &haudio_out_sai)
602  else
604 }
605 
612 {
613  if(hsai->Instance == AUDIO_OUT_SAIx)
614  {
616  }
617  else
618  {
620  }
621 }
622 
628 {
629 }
630 
636 {
637 }
638 
644 {
645 }
646 
652 __weak void BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params)
653 {
654  static DMA_HandleTypeDef hdma_sai_tx;
655  GPIO_InitTypeDef gpio_init_structure;
656 
657  /* Enable SAI clock */
659 
660  /* Enable GPIO clock */
663 
664  /* CODEC_SAI pins configuration: FS, SCK, MCK and SD pins ------------------*/
666  gpio_init_structure.Mode = GPIO_MODE_AF_PP;
667  gpio_init_structure.Pull = GPIO_NOPULL;
668  gpio_init_structure.Speed = GPIO_SPEED_HIGH;
669  gpio_init_structure.Alternate = AUDIO_OUT_SAIx_AF;
670  HAL_GPIO_Init(AUDIO_OUT_SAIx_SD_FS_SCK_GPIO_PORT, &gpio_init_structure);
671 
672  gpio_init_structure.Pin = AUDIO_OUT_SAIx_MCLK_PIN;
673  HAL_GPIO_Init(AUDIO_OUT_SAIx_MCLK_GPIO_PORT, &gpio_init_structure);
674 
675  /* Enable the DMA clock */
677 
678  if(hsai->Instance == AUDIO_OUT_SAIx)
679  {
680  /* Configure the hdma_saiTx handle parameters */
682  hdma_sai_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
683  hdma_sai_tx.Init.PeriphInc = DMA_PINC_DISABLE;
684  hdma_sai_tx.Init.MemInc = DMA_MINC_ENABLE;
687  hdma_sai_tx.Init.Mode = DMA_CIRCULAR;
688  hdma_sai_tx.Init.Priority = DMA_PRIORITY_HIGH;
689  hdma_sai_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
691  hdma_sai_tx.Init.MemBurst = DMA_MBURST_SINGLE;
692  hdma_sai_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
693 
694  hdma_sai_tx.Instance = AUDIO_OUT_SAIx_DMAx_STREAM;
695 
696  /* Associate the DMA handle */
697  __HAL_LINKDMA(hsai, hdmatx, hdma_sai_tx);
698 
699  /* Deinitialize the Stream for new transfer */
700  HAL_DMA_DeInit(&hdma_sai_tx);
701 
702  /* Configure the DMA Stream */
703  HAL_DMA_Init(&hdma_sai_tx);
704  }
705 
706  /* SAI DMA IRQ Channel configuration */
709 }
710 
716 static void SAI_AUDIO_IN_MspInit(SAI_HandleTypeDef *hsai, void *Params)
717 {
718  static DMA_HandleTypeDef hdma_sai_rx;
719  GPIO_InitTypeDef gpio_init_structure;
720 
721  /* Enable SAI clock */
723 
724  /* Enable SD GPIO clock */
726  /* CODEC_SAI pin configuration: SD pin */
727  gpio_init_structure.Pin = AUDIO_IN_SAIx_SD_PIN;
728  gpio_init_structure.Mode = GPIO_MODE_AF_PP;
729  gpio_init_structure.Pull = GPIO_NOPULL;
730  gpio_init_structure.Speed = GPIO_SPEED_FAST;
731  gpio_init_structure.Alternate = AUDIO_IN_SAIx_AF;
732  HAL_GPIO_Init(AUDIO_IN_SAIx_SD_GPIO_PORT, &gpio_init_structure);
733 
734  /* Enable Audio INT GPIO clock */
736  /* Audio INT pin configuration: input */
737  gpio_init_structure.Pin = AUDIO_IN_INT_GPIO_PIN;
738  gpio_init_structure.Mode = GPIO_MODE_INPUT;
739  gpio_init_structure.Pull = GPIO_NOPULL;
740  gpio_init_structure.Speed = GPIO_SPEED_FAST;
741  HAL_GPIO_Init(AUDIO_IN_INT_GPIO_PORT, &gpio_init_structure);
742 
743  /* Enable the DMA clock */
745 
746  if(hsai->Instance == AUDIO_IN_SAIx)
747  {
748  /* Configure the hdma_sai_rx handle parameters */
750  hdma_sai_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
751  hdma_sai_rx.Init.PeriphInc = DMA_PINC_DISABLE;
752  hdma_sai_rx.Init.MemInc = DMA_MINC_ENABLE;
755  hdma_sai_rx.Init.Mode = DMA_CIRCULAR;
756  hdma_sai_rx.Init.Priority = DMA_PRIORITY_HIGH;
757  hdma_sai_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
759  hdma_sai_rx.Init.MemBurst = DMA_MBURST_SINGLE;
760  hdma_sai_rx.Init.PeriphBurst = DMA_MBURST_SINGLE;
761 
762  hdma_sai_rx.Instance = AUDIO_IN_SAIx_DMAx_STREAM;
763 
764  /* Associate the DMA handle */
765  __HAL_LINKDMA(hsai, hdmarx, hdma_sai_rx);
766 
767  /* Deinitialize the Stream for new transfer */
768  HAL_DMA_DeInit(&hdma_sai_rx);
769 
770  /* Configure the DMA Stream */
771  HAL_DMA_Init(&hdma_sai_rx);
772  }
773 
774  /* SAI DMA IRQ Channel configuration */
777 
778 #if 0
779  /* Audio INT IRQ Channel configuration */
782 #endif
783 }
784 
790 static void SAI_AUDIO_IN_MspDeInit(SAI_HandleTypeDef *hsai, void *Params)
791 {
792  GPIO_InitTypeDef gpio_init_structure;
793 
794  /* SAI DMA IRQ Channel deactivation */
796 
797  if(hsai->Instance == AUDIO_IN_SAIx)
798  {
799  /* Deinitialize the DMA stream */
800  HAL_DMA_DeInit(hsai->hdmatx);
801  }
802 
803  /* Disable SAI peripheral */
804  __HAL_SAI_DISABLE(hsai);
805 
806  /* Deactivates CODEC_SAI pin SD by putting them in input mode */
807  gpio_init_structure.Pin = AUDIO_IN_SAIx_SD_PIN;
808  HAL_GPIO_DeInit(AUDIO_IN_SAIx_SD_GPIO_PORT, gpio_init_structure.Pin);
809 
810  gpio_init_structure.Pin = AUDIO_IN_INT_GPIO_PIN;
811  HAL_GPIO_DeInit(AUDIO_IN_INT_GPIO_PORT, gpio_init_structure.Pin);
812 
813  /* Disable SAI clock */
815 }
816 
822 __weak void BSP_AUDIO_OUT_MspDeInit(SAI_HandleTypeDef *hsai, void *Params)
823 {
824  GPIO_InitTypeDef gpio_init_structure;
825 
826  /* SAI DMA IRQ Channel deactivation */
828 
829  if(hsai->Instance == AUDIO_OUT_SAIx)
830  {
831  /* Deinitialize the DMA stream */
832  HAL_DMA_DeInit(hsai->hdmatx);
833  }
834 
835  /* Disable SAI peripheral */
836  __HAL_SAI_DISABLE(hsai);
837 
838  /* Deactivates CODEC_SAI pins FS, SCK, MCK and SD by putting them in input mode */
841 
842  gpio_init_structure.Pin = AUDIO_OUT_SAIx_MCLK_PIN;
843  HAL_GPIO_DeInit(AUDIO_OUT_SAIx_MCLK_GPIO_PORT, gpio_init_structure.Pin);
844 
845  /* Disable SAI clock */
847 
848  /* GPIO pins clock and DMA clock can be shut down in the applic
849  by surcharging this __weak function */
850 }
851 
860 __weak void BSP_AUDIO_OUT_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t AudioFreq, void *Params)
861 {
862  RCC_PeriphCLKInitTypeDef rcc_ex_clk_init_struct;
863 
864  HAL_RCCEx_GetPeriphCLKConfig(&rcc_ex_clk_init_struct);
865 
866  /* Set the PLL configuration according to the audio frequency */
867  if((AudioFreq == AUDIO_FREQUENCY_11K) || (AudioFreq == AUDIO_FREQUENCY_22K) || (AudioFreq == AUDIO_FREQUENCY_44K))
868  {
869  /* Configure PLLSAI prescalers */
870  /* PLLSAI_VCO: VCO_429M
871  SAI_CLK(first level) = PLLSAI_VCO/PLLSAIQ = 429/2 = 214.5 Mhz
872  SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ = 214.5/19 = 11.289 Mhz */
873  rcc_ex_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_SAI1;
874  rcc_ex_clk_init_struct.Sai1ClockSelection = RCC_SAI1CLKSOURCE_PLLI2S;
875  rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 429;
876  rcc_ex_clk_init_struct.PLLI2S.PLLI2SQ = 2;
877  rcc_ex_clk_init_struct.PLLI2SDivQ = 19;
878 
879  HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct);
880 
881  }
882  else /* AUDIO_FREQUENCY_8K, AUDIO_FREQUENCY_16K, AUDIO_FREQUENCY_48K, AUDIO_FREQUENCY_96K */
883  {
884  /* SAI clock config
885  PLLSAI_VCO: VCO_344M
886  SAI_CLK(first level) = PLLSAI_VCO/PLLSAIQ = 344/7 = 49.142 Mhz
887  SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ = 49.142/1 = 49.142 Mhz */
888  rcc_ex_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_SAI1;
889  rcc_ex_clk_init_struct.Sai1ClockSelection = RCC_SAI1CLKSOURCE_PLLI2S;
890  rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 344;
891  rcc_ex_clk_init_struct.PLLI2S.PLLI2SQ = 7;
892  rcc_ex_clk_init_struct.PLLI2SDivQ = 1;
893 
894  HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct);
895  }
896 }
897 
898 /*******************************************************************************
899  Static Functions
900 *******************************************************************************/
901 
909 static void SAIx_Out_Init(uint32_t AudioFreq)
910 {
911  /* Initialize the haudio_out_sai Instance parameter */
912  haudio_out_sai.Instance = AUDIO_OUT_SAIx;
913 
914  /* Disable SAI peripheral to allow access to SAI internal registers */
915  __HAL_SAI_DISABLE(&haudio_out_sai);
916 
917  /* Configure SAI_Block_x
918  LSBFirst: Disabled
919  DataSize: 16 */
920  haudio_out_sai.Init.MonoStereoMode = SAI_STEREOMODE;
921  haudio_out_sai.Init.AudioFrequency = AudioFreq;
922  haudio_out_sai.Init.AudioMode = SAI_MODEMASTER_TX;
923  haudio_out_sai.Init.NoDivider = SAI_MASTERDIVIDER_ENABLED;
924  haudio_out_sai.Init.Protocol = SAI_FREE_PROTOCOL;
925  haudio_out_sai.Init.DataSize = SAI_DATASIZE_16;
926  haudio_out_sai.Init.FirstBit = SAI_FIRSTBIT_MSB;
928  haudio_out_sai.Init.Synchro = SAI_ASYNCHRONOUS;
929  haudio_out_sai.Init.OutputDrive = SAI_OUTPUTDRIVE_ENABLED;
930  haudio_out_sai.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;
931  haudio_out_sai.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
932  haudio_out_sai.Init.CompandingMode = SAI_NOCOMPANDING;
933  haudio_out_sai.Init.TriState = SAI_OUTPUT_NOTRELEASED;
934  haudio_out_sai.Init.Mckdiv = 0;
935 
936  /* Configure SAI_Block_x Frame
937  Frame Length: 64
938  Frame active Length: 32
939  FS Definition: Start frame + Channel Side identification
940  FS Polarity: FS active Low
941  FS Offset: FS asserted one bit before the first bit of slot 0 */
942  haudio_out_sai.FrameInit.FrameLength = 128;
943  haudio_out_sai.FrameInit.ActiveFrameLength = 64;
945  haudio_out_sai.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
946  haudio_out_sai.FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;
947 
948  /* Configure SAI Block_x Slot
949  Slot First Bit Offset: 0
950  Slot Size : 16
951  Slot Number: 4
952  Slot Active: All slot actives */
953  haudio_out_sai.SlotInit.FirstBitOffset = 0;
954  haudio_out_sai.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
955  haudio_out_sai.SlotInit.SlotNumber = 4;
957 
958  HAL_SAI_Init(&haudio_out_sai);
959 
960  /* Enable SAI peripheral to generate MCLK */
961  __HAL_SAI_ENABLE(&haudio_out_sai);
962 }
963 
968 static void SAIx_Out_DeInit(void)
969 {
970  /* Initialize the haudio_out_sai Instance parameter */
971  haudio_out_sai.Instance = AUDIO_OUT_SAIx;
972 
973  /* Disable SAI peripheral */
974  __HAL_SAI_DISABLE(&haudio_out_sai);
975 
976  HAL_SAI_DeInit(&haudio_out_sai);
977 }
978 
986 static void SAIx_In_Init(uint32_t AudioFreq)
987 {
988  /* Initialize SAI1 block A in MASTER TX */
989  /* Initialize the haudio_out_sai Instance parameter */
990  haudio_out_sai.Instance = AUDIO_OUT_SAIx;
991 
992  /* Disable SAI peripheral to allow access to SAI internal registers */
993  __HAL_SAI_DISABLE(&haudio_out_sai);
994 
995  /* Configure SAI_Block_x
996  LSBFirst: Disabled
997  DataSize: 16 */
998  haudio_out_sai.Init.MonoStereoMode = SAI_STEREOMODE;
999  haudio_out_sai.Init.AudioFrequency = AudioFreq;
1000  haudio_out_sai.Init.AudioMode = SAI_MODEMASTER_TX; //SAI_MODEMASTER_RX;
1001  haudio_out_sai.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
1002  haudio_out_sai.Init.Protocol = SAI_FREE_PROTOCOL;
1003  haudio_out_sai.Init.DataSize = SAI_DATASIZE_16;
1004  haudio_out_sai.Init.FirstBit = SAI_FIRSTBIT_MSB;
1006  haudio_out_sai.Init.Synchro = SAI_ASYNCHRONOUS;
1007  haudio_out_sai.Init.OutputDrive = SAI_OUTPUTDRIVE_ENABLE;
1008  haudio_out_sai.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;
1009  haudio_out_sai.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
1010  haudio_out_sai.Init.CompandingMode = SAI_NOCOMPANDING;
1011  haudio_out_sai.Init.TriState = SAI_OUTPUT_NOTRELEASED;
1012  haudio_out_sai.Init.Mckdiv = 0;
1013 
1014  /* Configure SAI_Block_x Frame
1015  Frame Length: 64
1016  Frame active Length: 32
1017  FS Definition: Start frame + Channel Side identification
1018  FS Polarity: FS active Low
1019  FS Offset: FS asserted one bit before the first bit of slot 0 */
1020  haudio_out_sai.FrameInit.FrameLength = 64;
1021  haudio_out_sai.FrameInit.ActiveFrameLength = 32;
1023  haudio_out_sai.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
1024  haudio_out_sai.FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;
1025 
1026  /* Configure SAI Block_x Slot
1027  Slot First Bit Offset: 0
1028  Slot Size : 16
1029  Slot Number: 4
1030  Slot Active: All slot active */
1031  haudio_out_sai.SlotInit.FirstBitOffset = 0;
1032  haudio_out_sai.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
1033  haudio_out_sai.SlotInit.SlotNumber = 4;
1034  haudio_out_sai.SlotInit.SlotActive = CODEC_AUDIOFRAME_SLOT_02;
1035 
1036  HAL_SAI_Init(&haudio_out_sai);
1037 
1038  /* Initialize SAI1 block B in SLAVE RX synchronous from SAI1 block A */
1039  /* Initialize the haudio_in_sai Instance parameter */
1040  haudio_in_sai.Instance = AUDIO_IN_SAIx;
1041 
1042  /* Disable SAI peripheral to allow access to SAI internal registers */
1043  __HAL_SAI_DISABLE(&haudio_in_sai);
1044 
1045  /* Configure SAI_Block_x
1046  LSBFirst: Disabled
1047  DataSize: 16 */
1048  haudio_in_sai.Init.MonoStereoMode = SAI_STEREOMODE;
1049  haudio_in_sai.Init.AudioFrequency = AudioFreq;
1050  haudio_in_sai.Init.AudioMode = SAI_MODESLAVE_RX;
1051  haudio_in_sai.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
1052  haudio_in_sai.Init.Protocol = SAI_FREE_PROTOCOL;
1053  haudio_in_sai.Init.DataSize = SAI_DATASIZE_16;
1054  haudio_in_sai.Init.FirstBit = SAI_FIRSTBIT_MSB;
1056  haudio_in_sai.Init.Synchro = SAI_SYNCHRONOUS;
1057  haudio_in_sai.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
1058  haudio_in_sai.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;
1059  haudio_in_sai.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
1060  haudio_in_sai.Init.CompandingMode = SAI_NOCOMPANDING;
1061  haudio_in_sai.Init.TriState = SAI_OUTPUT_RELEASED;
1062  haudio_in_sai.Init.Mckdiv = 0;
1063 
1064  /* Configure SAI_Block_x Frame
1065  Frame Length: 64
1066  Frame active Length: 32
1067  FS Definition: Start frame + Channel Side identification
1068  FS Polarity: FS active Low
1069  FS Offset: FS asserted one bit before the first bit of slot 0 */
1070  haudio_in_sai.FrameInit.FrameLength = 64;
1071  haudio_in_sai.FrameInit.ActiveFrameLength = 32;
1073  haudio_in_sai.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
1074  haudio_in_sai.FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;
1075 
1076  /* Configure SAI Block_x Slot
1077  Slot First Bit Offset: 0
1078  Slot Size : 16
1079  Slot Number: 4
1080  Slot Active: All slot active */
1081  haudio_in_sai.SlotInit.FirstBitOffset = 0;
1082  haudio_in_sai.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
1083  haudio_in_sai.SlotInit.SlotNumber = 4;
1085 
1086  HAL_SAI_Init(&haudio_in_sai);
1087 
1088  /* Enable SAI peripheral */
1089  __HAL_SAI_ENABLE(&haudio_in_sai);
1090 
1091  /* Enable SAI peripheral to generate MCLK */
1092  __HAL_SAI_ENABLE(&haudio_out_sai);
1093 }
1094 
1099 static void SAIx_In_DeInit(void)
1100 {
1101  /* Initialize the haudio_in_sai Instance parameter */
1102  haudio_in_sai.Instance = AUDIO_IN_SAIx;
1103  haudio_out_sai.Instance = AUDIO_OUT_SAIx;
1104  /* Disable SAI peripheral */
1105  __HAL_SAI_DISABLE(&haudio_in_sai);
1106 
1107  HAL_SAI_DeInit(&haudio_in_sai);
1108  HAL_SAI_DeInit(&haudio_out_sai);
1109 }
1110 
1126 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr)
1127 {
1128  return BSP_AUDIO_IN_InitEx(INPUT_DEVICE_DIGITAL_MIC, AudioFreq, BitRes, ChnlNbr);
1129 }
1130 
1139 uint8_t BSP_AUDIO_IN_InitEx(uint16_t InputDevice, uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr)
1140 {
1141  uint8_t ret = AUDIO_ERROR;
1142  AudioIn_Device = InputDevice;
1143 
1144  if(InputDevice == INPUT_DEVICE_DIGITAL_MIC)
1145  {
1146  AudioIn_ChannelNumber = ChnlNbr;
1147  /* PLL clock is set depending by the AudioFreq (44.1khz vs 48khz groups) */
1149 
1150  /* Init the SAI MSP: this __weak function can be redefined by the application*/
1152 
1153  /* Initializes DFSDM peripheral */
1154  DFSDMx_Init(AudioFreq);
1155  ret = AUDIO_OK;
1156  }
1157  else
1158  {
1159  /* Disable SAI */
1160  SAIx_In_DeInit();
1161 
1162  /* PLL clock is set depending by the AudioFreq (44.1khz vs 48khz groups) */
1163  BSP_AUDIO_OUT_ClockConfig(&haudio_in_sai, AudioFreq, NULL);
1164 
1165  haudio_in_sai.Instance = AUDIO_IN_SAIx;
1166  if(HAL_SAI_GetState(&haudio_in_sai) == HAL_SAI_STATE_RESET)
1167  {
1168  BSP_AUDIO_OUT_MspInit(&haudio_in_sai, NULL);
1170  }
1171 
1172  SAIx_In_Init(AudioFreq);
1173 
1175  {
1176  /* Reset the Codec Registers */
1178  /* Initialize the audio driver structure */
1179  audio_drv = &wm8994_drv;
1180  ret = AUDIO_OK;
1181  }
1182  else
1183  {
1184  ret = AUDIO_ERROR;
1185  }
1186 
1187  if(ret == AUDIO_OK)
1188  {
1189  /* Initialize the codec internal registers */
1190  audio_drv->Init(AUDIO_I2C_ADDRESS, InputDevice | OUTPUT_DEVICE_HEADPHONE, 90, AudioFreq);
1191  }
1192  }
1193 
1194  /* Return AUDIO_OK when all operations are correctly done */
1195  return ret;
1196 }
1197 
1203 uint8_t BSP_AUDIO_IN_AllocScratch (int32_t *pScratch, uint32_t size)
1204 {
1205  uint32_t idx;
1206 
1207  ScratchSize = (size / AudioIn_ChannelNumber);
1208 
1209  /* copy scratch pointers */
1210  for (idx = 0; idx < AudioIn_ChannelNumber; idx++)
1211  {
1212  pScratchBuff[idx] = (int32_t *)(pScratch + (idx * ScratchSize));
1213  }
1214  /* Return AUDIO_OK */
1215  return AUDIO_OK;
1216 }
1217 
1224 {
1225  return AudioIn_ChannelNumber;
1226 }
1227 
1234 uint8_t BSP_AUDIO_IN_Record(uint16_t* pbuf, uint32_t size)
1235 {
1236  if (AudioIn_Device == INPUT_DEVICE_DIGITAL_MIC)
1237  {
1238  hAudioIn.pRecBuf = pbuf;
1239  hAudioIn.RecSize = size;
1240  /* Reset Application Buffer Trigger */
1241  AppBuffTrigger = 0;
1242  AppBuffHalf = 0;
1243 
1244  if(AudioIn_ChannelNumber > 2)
1245  {
1246  /* Call the Media layer start function for buttom right channel */
1247  if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInButtomRightFilter, pScratchBuff[2], ScratchSize))
1248  {
1249  return AUDIO_ERROR;
1250  }
1251 
1252  /* Call the Media layer start function for buttom left channel */
1253  if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInButtomLeftFilter, pScratchBuff[3], ScratchSize))
1254  {
1255  return AUDIO_ERROR;
1256  }
1257  }
1258 
1259  /* Call the Media layer start function for top right channel */
1260  if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInTopRightFilter, pScratchBuff[0], ScratchSize))
1261  {
1262  return AUDIO_ERROR;
1263  }
1264 
1265  /* Call the Media layer start function for top left channel */
1266  if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInTopLeftFilter, pScratchBuff[1], ScratchSize))
1267  {
1268  return AUDIO_ERROR;
1269  }
1270  }
1271  else
1272  {
1273  /* Start the process receive DMA */
1274  if(HAL_OK != HAL_SAI_Receive_DMA(&haudio_in_sai, (uint8_t*)pbuf, size))
1275  {
1276  return AUDIO_ERROR;
1277  }
1278  }
1279  /* Return AUDIO_OK when all operations are correctly done */
1280  return AUDIO_OK;
1281 }
1282 
1287 uint8_t BSP_AUDIO_IN_Stop(void)
1288 {
1289  if (AudioIn_Device == INPUT_DEVICE_DIGITAL_MIC)
1290  {
1291  AppBuffTrigger = 0;
1292  AppBuffHalf = 0;
1293 
1294  if(AudioIn_ChannelNumber > 2)
1295  {
1296  /* Call the Media layer stop function for buttom right channel */
1297  if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInButtomRightFilter))
1298  {
1299  return AUDIO_ERROR;
1300  }
1301 
1302  /* Call the Media layer stop function for buttom left channel */
1303  if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInButtomLeftFilter))
1304  {
1305  return AUDIO_ERROR;
1306  }
1307  }
1308 
1309  /* Call the Media layer stop function for top right channel */
1310  if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInTopRightFilter))
1311  {
1312  return AUDIO_ERROR;
1313  }
1314 
1315  /* Call the Media layer stop function for top left channel */
1316  if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInTopLeftFilter))
1317  {
1318  return AUDIO_ERROR;
1319  }
1320  }
1321  else
1322  {
1323  /* Call the Media layer stop function */
1324  HAL_SAI_DMAStop(&haudio_in_sai);
1325 
1326  /* Call Audio Codec Stop function */
1327  if(audio_drv->Stop(AUDIO_I2C_ADDRESS, CODEC_PDWN_HW) != 0)
1328  {
1329  return AUDIO_ERROR;
1330  }
1331  else
1332  {
1333  /* Wait at least 100us */
1334  HAL_Delay(1);
1335 
1336  /* Return AUDIO_OK when all operations are correctly done */
1337  return AUDIO_OK;
1338  }
1339  }
1340  /* Return AUDIO_OK when all operations are correctly done */
1341  return AUDIO_OK;
1342 }
1343 
1348 uint8_t BSP_AUDIO_IN_Pause(void)
1349 {
1350  if(AudioIn_ChannelNumber > 2)
1351  {
1352  /* Call the Media layer stop function */
1353  if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInButtomRightFilter))
1354  {
1355  return AUDIO_ERROR;
1356  }
1357 
1358  /* Call the Media layer stop function */
1359  if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInButtomLeftFilter))
1360  {
1361  return AUDIO_ERROR;
1362  }
1363  }
1364  /* Call the Media layer stop function */
1365  if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInTopRightFilter))
1366  {
1367  return AUDIO_ERROR;
1368  }
1369 
1370  /* Call the Media layer stop function */
1371  if(HAL_OK != HAL_DFSDM_FilterRegularStop_DMA(&hAudioInTopLeftFilter))
1372  {
1373  return AUDIO_ERROR;
1374  }
1375 
1376  /* Return AUDIO_OK when all operations are correctly done */
1377  return AUDIO_OK;
1378 }
1379 
1384 uint8_t BSP_AUDIO_IN_Resume(void)
1385 {
1386  if(AudioIn_ChannelNumber > 2)
1387  {
1388  /* Call the Media layer start function for buttom right channel */
1389  if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInButtomRightFilter, pScratchBuff[2], ScratchSize))
1390  {
1391  return AUDIO_ERROR;
1392  }
1393 
1394  /* Call the Media layer start function for buttom left channel */
1395  if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInButtomLeftFilter, pScratchBuff[3], ScratchSize))
1396  {
1397  return AUDIO_ERROR;
1398  }
1399  }
1400  /* Call the Media layer start function for top right channel */
1401  if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInTopRightFilter, pScratchBuff[0], ScratchSize))
1402  {
1403  return AUDIO_ERROR;
1404  }
1405 
1406  /* Call the Media layer start function for top left channel */
1407  if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&hAudioInTopLeftFilter, pScratchBuff[1], ScratchSize))
1408  {
1409  return AUDIO_ERROR;
1410  }
1411 
1412  /* Return AUDIO_OK when all operations are correctly done */
1413  return AUDIO_OK;
1414 }
1415 
1421 {
1423 
1424  if(AudioIn_Device == INPUT_DEVICE_DIGITAL_MIC)
1425  {
1426  DFSDMx_DeInit();
1427  }
1428  else
1429  {
1430  SAIx_In_DeInit();
1431  }
1432 }
1433 
1441 void HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
1442 {
1443  uint32_t index = 0;
1444 
1445  if(hdfsdm_filter == &hAudioInTopLeftFilter)
1446  {
1447  DmaTopLeftRecCplt = 1;
1448  }
1449  else if(hdfsdm_filter == &hAudioInTopRightFilter)
1450  {
1451  DmaTopRightRecCplt = 1;
1452  }
1453  else if(hdfsdm_filter == &hAudioInButtomLeftFilter)
1454  {
1455  DmaButtomLeftRecCplt = 1;
1456  }
1457  else
1458  {
1459  DmaButtomRightRecCplt = 1;
1460  }
1461 
1462  if(AudioIn_ChannelNumber > 2)
1463  {
1464  if((DmaTopLeftRecCplt == 1) && (DmaTopRightRecCplt == 1) && (DmaButtomLeftRecCplt == 1) && (DmaButtomRightRecCplt == 1))
1465  {
1466  for(index = (ScratchSize/2) ; index < ScratchSize; index++)
1467  {
1468  hAudioIn.pRecBuf[AppBuffTrigger] = (uint16_t)(SaturaLH((pScratchBuff[1][index] >> 8), -32760, 32760));
1469  hAudioIn.pRecBuf[AppBuffTrigger + 1] = (uint16_t)(SaturaLH((pScratchBuff[0][index] >> 8), -32760, 32760));
1470  hAudioIn.pRecBuf[AppBuffTrigger + 2] = (uint16_t)(SaturaLH((pScratchBuff[3][index] >> 8), -32760, 32760));
1471  hAudioIn.pRecBuf[AppBuffTrigger + 3] = (uint16_t)(SaturaLH((pScratchBuff[2][index] >> 8), -32760, 32760));
1472  AppBuffTrigger +=4;
1473  }
1474  DmaTopLeftRecCplt = 0;
1475  DmaTopRightRecCplt = 0;
1476  DmaButtomLeftRecCplt = 0;
1477  DmaButtomRightRecCplt = 0;
1478  }
1479  }
1480  else
1481  {
1482  if((DmaTopLeftRecCplt == 1) && (DmaTopRightRecCplt == 1))
1483  {
1484  for(index = (ScratchSize/2) ; index < ScratchSize; index++)
1485  {
1486  hAudioIn.pRecBuf[AppBuffTrigger] = (uint16_t)(SaturaLH((pScratchBuff[1][index] >> 8), -32760, 32760));
1487  hAudioIn.pRecBuf[AppBuffTrigger + 1] = (uint16_t)(SaturaLH((pScratchBuff[0][index] >> 8), -32760, 32760));
1488  AppBuffTrigger +=2;
1489  }
1490  DmaTopLeftRecCplt = 0;
1491  DmaTopRightRecCplt = 0;
1492  }
1493  }
1494 
1495  /* Call Half Transfer Complete callback */
1496  if((AppBuffTrigger == hAudioIn.RecSize/2) && (AppBuffHalf == 0))
1497  {
1498  AppBuffHalf = 1;
1500  }
1501  /* Call Transfer Complete callback */
1502  if(AppBuffTrigger == hAudioIn.RecSize)
1503  {
1504  /* Reset Application Buffer Trigger */
1505  AppBuffTrigger = 0;
1506  AppBuffHalf = 0;
1507  /* Call the record update function to get the next buffer to fill and its size (size is ignored) */
1509  }
1510 }
1511 
1517 void HAL_DFSDM_FilterRegConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
1518 {
1519  uint32_t index = 0;
1520 
1521  if(hdfsdm_filter == &hAudioInTopLeftFilter)
1522  {
1523  DmaTopLeftRecHalfCplt = 1;
1524  }
1525  else if(hdfsdm_filter == &hAudioInTopRightFilter)
1526  {
1527  DmaTopRightRecHalfCplt = 1;
1528  }
1529  else if(hdfsdm_filter == &hAudioInButtomLeftFilter)
1530  {
1531  DmaButtomLeftRecHalfCplt = 1;
1532  }
1533  else
1534  {
1535  DmaButtomRightRecHalfCplt = 1;
1536  }
1537 
1538  if(AudioIn_ChannelNumber > 2)
1539  {
1540  if((DmaTopLeftRecHalfCplt == 1) && (DmaTopRightRecHalfCplt == 1) && (DmaButtomLeftRecHalfCplt == 1) && (DmaButtomRightRecHalfCplt == 1))
1541  {
1542  for(index = 0 ; index < ScratchSize/2; index++)
1543  {
1544  hAudioIn.pRecBuf[AppBuffTrigger] = (uint16_t)(SaturaLH((pScratchBuff[1][index] >> 8), -32760, 32760));
1545  hAudioIn.pRecBuf[AppBuffTrigger + 1] = (uint16_t)(SaturaLH((pScratchBuff[0][index] >> 8), -32760, 32760));
1546  hAudioIn.pRecBuf[AppBuffTrigger + 2] = (uint16_t)(SaturaLH((pScratchBuff[3][index] >> 8), -32760, 32760));
1547  hAudioIn.pRecBuf[AppBuffTrigger + 3] = (uint16_t)(SaturaLH((pScratchBuff[2][index] >> 8), -32760, 32760));
1548  AppBuffTrigger +=4;
1549  }
1550  DmaTopLeftRecHalfCplt = 0;
1551  DmaTopRightRecHalfCplt = 0;
1552  DmaButtomLeftRecHalfCplt = 0;
1553  DmaButtomRightRecHalfCplt = 0;
1554  }
1555  }
1556  else
1557  {
1558  if((DmaTopLeftRecHalfCplt == 1) && (DmaTopRightRecHalfCplt == 1))
1559  {
1560  for(index = 0 ; index < ScratchSize/2; index++)
1561  {
1562  hAudioIn.pRecBuf[AppBuffTrigger] = (uint16_t)(SaturaLH((pScratchBuff[1][index] >> 8), -32760, 32760));
1563  hAudioIn.pRecBuf[AppBuffTrigger + 1] = (uint16_t)(SaturaLH((pScratchBuff[0][index] >> 8), -32760, 32760));
1564  AppBuffTrigger +=2;
1565  }
1566  DmaTopLeftRecHalfCplt = 0;
1567  DmaTopRightRecHalfCplt = 0;
1568  }
1569  }
1570 
1571  /* Call Half Transfer Complete callback */
1572  if((AppBuffTrigger == hAudioIn.RecSize/2) && (AppBuffHalf == 0))
1573  {
1574  AppBuffHalf = 1;
1576  }
1577  /* Call Transfer Complete callback */
1578  if(AppBuffTrigger == hAudioIn.RecSize)
1579  {
1580  /* Reset Application Buffer Trigger */
1581  AppBuffTrigger = 0;
1582  AppBuffHalf = 0;
1583  /* Call the record update function to get the next buffer to fill and its size (size is ignored) */
1585  }
1586 }
1587 
1594 {
1595  /* Manage the remaining file size and new address offset: This function
1596  should be coded by user (its prototype is already declared in stm32746g_discovery_audio.h) */
1598 
1600 }
1601 
1608 {
1609  /* Call the record update function to get the next buffer to fill and its size (size is ignored) */
1611 
1613 }
1614 
1620 {
1621  /* This function should be implemented by the user application.
1622  It is called into this driver when the current buffer is filled
1623  to prepare the next buffer pointer and its size. */
1624 }
1625 
1631 {
1632  /* This function should be implemented by the user application.
1633  It is called into this driver when the current buffer is filled
1634  to prepare the next buffer pointer and its size. */
1635 }
1636 
1642 {
1643  /* This function is called when an Interrupt due to transfer error on or peripheral
1644  error occurs. */
1645 }
1646 
1652 __weak void BSP_AUDIO_IN_MspInit(void)
1653 {
1654  if (AudioIn_Device == INPUT_DEVICE_DIGITAL_MIC)
1655  {
1656  /* MSP channels initialization */
1657  DFSDMx_ChannelMspInit();
1658  /* MSP filters initialization */
1659  DFSDMx_FilterMspInit();
1660  }
1661  else
1662  {
1663  SAI_AUDIO_IN_MspInit(&haudio_in_sai, NULL);
1664  }
1665 }
1666 
1672 __weak void BSP_AUDIO_IN_MspDeInit(void)
1673 {
1674  if (AudioIn_Device == INPUT_DEVICE_DIGITAL_MIC)
1675  {
1676  /* MSP channels initialization */
1677  DFSDMx_ChannelMspDeInit();
1678  /* MSP filters initialization */
1679  DFSDMx_FilterMspDeInit();
1680  }
1681  else
1682  {
1683  SAI_AUDIO_IN_MspDeInit(&haudio_in_sai, NULL);
1684  }
1685 }
1686 
1695 __weak void BSP_AUDIO_IN_ClockConfig(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, uint32_t AudioFreq, void *Params)
1696 {
1697  RCC_PeriphCLKInitTypeDef rcc_ex_clk_init_struct;
1698 
1699  HAL_RCCEx_GetPeriphCLKConfig(&rcc_ex_clk_init_struct);
1700 
1701  /* Set the PLL configuration according to the audio frequency */
1702  if((AudioFreq == AUDIO_FREQUENCY_11K) || (AudioFreq == AUDIO_FREQUENCY_22K) || (AudioFreq == AUDIO_FREQUENCY_44K))
1703  {
1704  /* Configure PLLSAI prescalers */
1705  /* PLLI2S_VCO: VCO_429M
1706  SAI_CLK(first level) = PLLI2S_VCO/PLLI2SQ = 429/2 = 214.5 Mhz
1707  SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ = 214.5/19 = 11.289 Mhz */
1708  rcc_ex_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_SAI2;
1709  rcc_ex_clk_init_struct.Sai2ClockSelection = RCC_SAI2CLKSOURCE_PLLI2S;
1710  rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 429;
1711  rcc_ex_clk_init_struct.PLLI2S.PLLI2SQ = 2;
1712  rcc_ex_clk_init_struct.PLLI2SDivQ = 19;
1713 
1714  HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct);
1715 
1716  }
1717  else /* AUDIO_FREQUENCY_8K, AUDIO_FREQUENCY_16K, AUDIO_FREQUENCY_32K, AUDIO_FREQUENCY_48K, AUDIO_FREQUENCY_96K */
1718  {
1719  /* SAI clock config
1720  PLLI2S_VCO: VCO_344M
1721  SAI_CLK(first level) = PLLI2S_VCO/PLLI2SQ = 344/7 = 49.142 Mhz
1722  SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ = 49.142/1 = 49.142 Mhz */
1723  rcc_ex_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_SAI2;
1724  rcc_ex_clk_init_struct.Sai2ClockSelection = RCC_SAI2CLKSOURCE_PLLI2S;
1725  rcc_ex_clk_init_struct.PLLI2S.PLLI2SN = 344;
1726  rcc_ex_clk_init_struct.PLLI2S.PLLI2SQ = 7;
1727  rcc_ex_clk_init_struct.PLLI2SDivQ = 1;
1728  HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct);
1729  }
1730 
1731  rcc_ex_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_DFSDM1_AUDIO;
1732  rcc_ex_clk_init_struct.Dfsdm1AudioClockSelection = RCC_DFSDM1AUDIOCLKSOURCE_SAI2;
1733  HAL_RCCEx_PeriphCLKConfig(&rcc_ex_clk_init_struct);
1734 }
1735 
1736 /*******************************************************************************
1737  Static Functions
1738 *******************************************************************************/
1748 static uint8_t DFSDMx_Init(uint32_t AudioFreq)
1749 {
1750  /****************************************************************************/
1751  /********************** Channels configuration *****************************/
1752  /****************************************************************************/
1753  /* CHANNEL 1 configuration */
1754  __HAL_DFSDM_CHANNEL_RESET_HANDLE_STATE(&hAudioInTopLeftChannel);
1756  hAudioInTopLeftChannel.Init.OutputClock.Activation = ENABLE;
1757  hAudioInTopLeftChannel.Init.OutputClock.Selection = DFSDM_CHANNEL_OUTPUT_CLOCK_AUDIO;
1758  /* Set the DFSDM clock OUT audio frequency configuration */
1759  hAudioInTopLeftChannel.Init.OutputClock.Divider = DFSDM_CLOCK_DIVIDER(AudioFreq);
1760  hAudioInTopLeftChannel.Init.Input.Multiplexer = DFSDM_CHANNEL_EXTERNAL_INPUTS;
1761  hAudioInTopLeftChannel.Init.Input.DataPacking = DFSDM_CHANNEL_STANDARD_MODE;
1762  hAudioInTopLeftChannel.Init.Input.Pins = DFSDM_CHANNEL_SAME_CHANNEL_PINS;
1763  /* Request to sample stable data for LEFT micro on Rising edge */
1764  hAudioInTopLeftChannel.Init.SerialInterface.Type = DFSDM_CHANNEL_SPI_RISING;
1765  hAudioInTopLeftChannel.Init.SerialInterface.SpiClock = DFSDM_CHANNEL_SPI_CLOCK_INTERNAL;
1766  hAudioInTopLeftChannel.Init.Awd.FilterOrder = DFSDM_CHANNEL_FASTSINC_ORDER;
1767  hAudioInTopLeftChannel.Init.Awd.Oversampling = 10;
1768  hAudioInTopLeftChannel.Init.Offset = 0;
1769  hAudioInTopLeftChannel.Init.RightBitShift = DFSDM_RIGHT_BIT_SHIFT(AudioFreq);
1770  if(HAL_OK != HAL_DFSDM_ChannelInit(&hAudioInTopLeftChannel))
1771  {
1772  return AUDIO_ERROR;
1773  }
1774 
1775  /* CHANNEL 0 configuration */
1776  __HAL_DFSDM_CHANNEL_RESET_HANDLE_STATE(&hAudioInTopRightChannel);
1778  hAudioInTopRightChannel.Init.OutputClock.Activation = ENABLE;
1779  hAudioInTopRightChannel.Init.OutputClock.Selection = DFSDM_CHANNEL_OUTPUT_CLOCK_AUDIO;
1780  /* Set the DFSDM clock OUT audio frequency configuration */
1781  hAudioInTopRightChannel.Init.OutputClock.Divider = DFSDM_CLOCK_DIVIDER(AudioFreq);
1782  hAudioInTopRightChannel.Init.Input.Multiplexer = DFSDM_CHANNEL_EXTERNAL_INPUTS;
1783  hAudioInTopRightChannel.Init.Input.DataPacking = DFSDM_CHANNEL_STANDARD_MODE;
1784  hAudioInTopRightChannel.Init.Input.Pins = DFSDM_CHANNEL_FOLLOWING_CHANNEL_PINS;
1785  /* Request to sample stable data for RIGHT micro on Falling edge */
1786  hAudioInTopRightChannel.Init.SerialInterface.Type = DFSDM_CHANNEL_SPI_FALLING;
1787  hAudioInTopRightChannel.Init.SerialInterface.SpiClock = DFSDM_CHANNEL_SPI_CLOCK_INTERNAL;
1788  hAudioInTopRightChannel.Init.Awd.FilterOrder = DFSDM_CHANNEL_FASTSINC_ORDER;
1789  hAudioInTopRightChannel.Init.Awd.Oversampling = 10;
1790  hAudioInTopRightChannel.Init.Offset = 0;
1791  hAudioInTopRightChannel.Init.RightBitShift = DFSDM_RIGHT_BIT_SHIFT(AudioFreq);
1792  if(HAL_OK != HAL_DFSDM_ChannelInit(&hAudioInTopRightChannel))
1793  {
1794  return AUDIO_ERROR;
1795  }
1796 
1797  if(AudioIn_ChannelNumber > 2)
1798  {
1799  /* CHANNEL 5 configuration */
1800  __HAL_DFSDM_CHANNEL_RESET_HANDLE_STATE(&hAudioInButtomLeftChannel);
1802  hAudioInButtomLeftChannel.Init.OutputClock.Activation = ENABLE;
1803  hAudioInButtomLeftChannel.Init.OutputClock.Selection = DFSDM_CHANNEL_OUTPUT_CLOCK_AUDIO;
1804  /* Set the DFSDM clock OUT audio frequency configuration */
1805  hAudioInButtomLeftChannel.Init.OutputClock.Divider = DFSDM_CLOCK_DIVIDER(AudioFreq);
1806  hAudioInButtomLeftChannel.Init.Input.Multiplexer = DFSDM_CHANNEL_EXTERNAL_INPUTS;
1807  hAudioInButtomLeftChannel.Init.Input.DataPacking = DFSDM_CHANNEL_STANDARD_MODE;
1808  hAudioInButtomLeftChannel.Init.Input.Pins = DFSDM_CHANNEL_SAME_CHANNEL_PINS;
1809  /* Request to sample stable data for LEFT micro on Rising edge */
1810  hAudioInButtomLeftChannel.Init.SerialInterface.Type = DFSDM_CHANNEL_SPI_RISING;
1811  hAudioInButtomLeftChannel.Init.SerialInterface.SpiClock = DFSDM_CHANNEL_SPI_CLOCK_INTERNAL;
1812  hAudioInButtomLeftChannel.Init.Awd.FilterOrder = DFSDM_CHANNEL_FASTSINC_ORDER;
1813  hAudioInButtomLeftChannel.Init.Awd.Oversampling = 10;
1814  hAudioInButtomLeftChannel.Init.Offset = 0;
1815  hAudioInButtomLeftChannel.Init.RightBitShift = DFSDM_RIGHT_BIT_SHIFT(AudioFreq);
1816  if(HAL_OK != HAL_DFSDM_ChannelInit(&hAudioInButtomLeftChannel))
1817  {
1818  return AUDIO_ERROR;
1819  }
1820 
1821  /* CHANNEL 4 configuration */
1822  __HAL_DFSDM_CHANNEL_RESET_HANDLE_STATE(&hAudioInButtomRightChannel);
1824  hAudioInButtomRightChannel.Init.OutputClock.Activation = ENABLE;
1825  hAudioInButtomRightChannel.Init.OutputClock.Selection = DFSDM_CHANNEL_OUTPUT_CLOCK_AUDIO;
1826  /* Set the DFSDM clock OUT audio frequency configuration */
1827  hAudioInButtomRightChannel.Init.OutputClock.Divider = DFSDM_CLOCK_DIVIDER(AudioFreq);
1828  hAudioInButtomRightChannel.Init.Input.Multiplexer = DFSDM_CHANNEL_EXTERNAL_INPUTS;
1829  hAudioInButtomRightChannel.Init.Input.DataPacking = DFSDM_CHANNEL_STANDARD_MODE;
1830  hAudioInButtomRightChannel.Init.Input.Pins = DFSDM_CHANNEL_FOLLOWING_CHANNEL_PINS;
1831  /* Request to sample stable data for RIGHT micro on Falling edge */
1832  hAudioInButtomRightChannel.Init.SerialInterface.Type = DFSDM_CHANNEL_SPI_FALLING;
1833  hAudioInButtomRightChannel.Init.SerialInterface.SpiClock = DFSDM_CHANNEL_SPI_CLOCK_INTERNAL;
1834  hAudioInButtomRightChannel.Init.Awd.FilterOrder = DFSDM_CHANNEL_FASTSINC_ORDER;
1835  hAudioInButtomRightChannel.Init.Awd.Oversampling = 10;
1836  hAudioInButtomRightChannel.Init.Offset = 0;
1837  hAudioInButtomRightChannel.Init.RightBitShift = DFSDM_RIGHT_BIT_SHIFT(AudioFreq);
1838  if(HAL_OK != HAL_DFSDM_ChannelInit(&hAudioInButtomRightChannel))
1839  {
1840  return AUDIO_ERROR;
1841  }
1842  }
1843  /****************************************************************************/
1844  /********************** Filters configuration ******************************/
1845  /****************************************************************************/
1846 
1847  /* FILTER 0 configuration */
1848  __HAL_DFSDM_FILTER_RESET_HANDLE_STATE(&hAudioInTopLeftFilter);
1850  hAudioInTopLeftFilter.Init.RegularParam.Trigger = DFSDM_FILTER_SW_TRIGGER;
1851  hAudioInTopLeftFilter.Init.RegularParam.FastMode = ENABLE;
1852  hAudioInTopLeftFilter.Init.RegularParam.DmaMode = ENABLE;
1853  hAudioInTopLeftFilter.Init.InjectedParam.Trigger = DFSDM_FILTER_SW_TRIGGER;
1854  hAudioInTopLeftFilter.Init.InjectedParam.ScanMode = ENABLE;
1855  hAudioInTopLeftFilter.Init.InjectedParam.DmaMode = DISABLE;
1856  hAudioInTopLeftFilter.Init.InjectedParam.ExtTrigger = DFSDM_FILTER_EXT_TRIG_TIM1_TRGO;
1857  hAudioInTopLeftFilter.Init.InjectedParam.ExtTriggerEdge = DFSDM_FILTER_EXT_TRIG_RISING_EDGE;
1858  hAudioInTopLeftFilter.Init.FilterParam.SincOrder = DFSDM_FILTER_ORDER(AudioFreq);
1859  /* Set the DFSDM Filters Oversampling to have correct sample rate */
1860  hAudioInTopLeftFilter.Init.FilterParam.Oversampling = DFSDM_OVER_SAMPLING(AudioFreq);
1861  hAudioInTopLeftFilter.Init.FilterParam.IntOversampling = 1;
1862  if(HAL_OK != HAL_DFSDM_FilterInit(&hAudioInTopLeftFilter))
1863  {
1864  return AUDIO_ERROR;
1865  }
1866 
1867  /* Configure injected channel */
1868  if(HAL_OK != HAL_DFSDM_FilterConfigRegChannel(&hAudioInTopLeftFilter, AUDIO_DFSDMx_TOP_LEFT_CHANNEL, DFSDM_CONTINUOUS_CONV_ON))
1869  {
1870  return AUDIO_ERROR;
1871  }
1872 
1873  /* FILTER 1 configuration */
1874  __HAL_DFSDM_FILTER_RESET_HANDLE_STATE(&hAudioInTopRightFilter);
1876  hAudioInTopRightFilter.Init.RegularParam.Trigger = DFSDM_FILTER_SYNC_TRIGGER;
1877  hAudioInTopRightFilter.Init.RegularParam.FastMode = ENABLE;
1878  hAudioInTopRightFilter.Init.RegularParam.DmaMode = ENABLE;
1879  hAudioInTopRightFilter.Init.InjectedParam.Trigger = DFSDM_FILTER_SW_TRIGGER;
1880  hAudioInTopRightFilter.Init.InjectedParam.ScanMode = DISABLE;
1881  hAudioInTopRightFilter.Init.InjectedParam.DmaMode = DISABLE;
1882  hAudioInTopRightFilter.Init.InjectedParam.ExtTrigger = DFSDM_FILTER_EXT_TRIG_TIM1_TRGO;
1883  hAudioInTopRightFilter.Init.InjectedParam.ExtTriggerEdge = DFSDM_FILTER_EXT_TRIG_RISING_EDGE;
1884  hAudioInTopRightFilter.Init.FilterParam.SincOrder = DFSDM_FILTER_ORDER(AudioFreq);
1885  /* Set the DFSDM Filters Oversampling to have correct sample rate */
1886  hAudioInTopRightFilter.Init.FilterParam.Oversampling = DFSDM_OVER_SAMPLING(AudioFreq);
1887  hAudioInTopRightFilter.Init.FilterParam.IntOversampling = 1;
1888  if(HAL_OK != HAL_DFSDM_FilterInit(&hAudioInTopRightFilter))
1889  {
1890  return AUDIO_ERROR;
1891  }
1892  /* Configure injected channel */
1893  if(HAL_OK != HAL_DFSDM_FilterConfigRegChannel(&hAudioInTopRightFilter, AUDIO_DFSDMx_TOP_RIGHT_CHANNEL, DFSDM_CONTINUOUS_CONV_ON))
1894  {
1895  return AUDIO_ERROR;
1896  }
1897 
1898  if(AudioIn_ChannelNumber > 2)
1899  {
1900  /* FILTER 2 configuration */
1901  __HAL_DFSDM_FILTER_RESET_HANDLE_STATE(&hAudioInButtomLeftFilter);
1903  hAudioInButtomLeftFilter.Init.RegularParam.Trigger = DFSDM_FILTER_SYNC_TRIGGER;
1904  hAudioInButtomLeftFilter.Init.RegularParam.FastMode = ENABLE;
1905  hAudioInButtomLeftFilter.Init.RegularParam.DmaMode = ENABLE;
1906  hAudioInButtomLeftFilter.Init.InjectedParam.Trigger = DFSDM_FILTER_SW_TRIGGER;
1907  hAudioInButtomLeftFilter.Init.InjectedParam.ScanMode = ENABLE;
1908  hAudioInButtomLeftFilter.Init.InjectedParam.DmaMode = DISABLE;
1909  hAudioInButtomLeftFilter.Init.InjectedParam.ExtTrigger = DFSDM_FILTER_EXT_TRIG_TIM1_TRGO;
1910  hAudioInButtomLeftFilter.Init.InjectedParam.ExtTriggerEdge = DFSDM_FILTER_EXT_TRIG_RISING_EDGE;
1911  hAudioInButtomLeftFilter.Init.FilterParam.SincOrder = DFSDM_FILTER_ORDER(AudioFreq);
1912  /* Set the DFSDM Filters Oversampling to have correct sample rate */
1913  hAudioInButtomLeftFilter.Init.FilterParam.Oversampling = DFSDM_OVER_SAMPLING(AudioFreq);
1914  hAudioInButtomLeftFilter.Init.FilterParam.IntOversampling = 1;
1915  if(HAL_OK != HAL_DFSDM_FilterInit(&hAudioInButtomLeftFilter))
1916  {
1917  return AUDIO_ERROR;
1918  }
1919 
1920  /* Configure injected channel */
1921  if(HAL_OK != HAL_DFSDM_FilterConfigRegChannel(&hAudioInButtomLeftFilter, AUDIO_DFSDMx_BUTTOM_LEFT_CHANNEL, DFSDM_CONTINUOUS_CONV_ON))
1922  {
1923  return AUDIO_ERROR;
1924  }
1925 
1926  /* FILTER 3 configuration */
1927  __HAL_DFSDM_FILTER_RESET_HANDLE_STATE(&hAudioInButtomRightFilter);
1929  hAudioInButtomRightFilter.Init.RegularParam.Trigger = DFSDM_FILTER_SYNC_TRIGGER;
1930  hAudioInButtomRightFilter.Init.RegularParam.FastMode = ENABLE;
1931  hAudioInButtomRightFilter.Init.RegularParam.DmaMode = ENABLE;
1932  hAudioInButtomRightFilter.Init.InjectedParam.Trigger = DFSDM_FILTER_SW_TRIGGER;
1933  hAudioInButtomRightFilter.Init.InjectedParam.ScanMode = DISABLE;
1934  hAudioInButtomRightFilter.Init.InjectedParam.DmaMode = DISABLE;
1935  hAudioInButtomRightFilter.Init.InjectedParam.ExtTrigger = DFSDM_FILTER_EXT_TRIG_TIM1_TRGO;
1936  hAudioInButtomRightFilter.Init.InjectedParam.ExtTriggerEdge = DFSDM_FILTER_EXT_TRIG_RISING_EDGE;
1937  hAudioInButtomRightFilter.Init.FilterParam.SincOrder = DFSDM_FILTER_ORDER(AudioFreq);
1938  /* Set the DFSDM Filters Oversampling to have correct sample rate */
1939  hAudioInButtomRightFilter.Init.FilterParam.Oversampling = DFSDM_OVER_SAMPLING(AudioFreq);
1940  hAudioInButtomRightFilter.Init.FilterParam.IntOversampling = 1;
1941  if(HAL_OK != HAL_DFSDM_FilterInit(&hAudioInButtomRightFilter))
1942  {
1943  return AUDIO_ERROR;
1944  }
1945  /* Configure injected channel */
1946  if(HAL_OK != HAL_DFSDM_FilterConfigRegChannel(&hAudioInButtomRightFilter, AUDIO_DFSDMx_BUTTOM_RIGHT_CHANNEL, DFSDM_CONTINUOUS_CONV_ON))
1947  {
1948  return AUDIO_ERROR;
1949  }
1950  }
1951  return AUDIO_OK;
1952 }
1953 
1958 static uint8_t DFSDMx_DeInit(void)
1959 {
1960  /* De-initializes the DFSDM filters to allow access to DFSDM internal registers */
1961  if(HAL_OK != HAL_DFSDM_FilterDeInit(&hAudioInTopLeftFilter))
1962  {
1963  return AUDIO_ERROR;
1964  }
1965 
1966  if(HAL_OK != HAL_DFSDM_FilterDeInit(&hAudioInTopRightFilter))
1967  {
1968  return AUDIO_ERROR;
1969  }
1970 
1971  /* De-initializes the DFSDM channels to allow access to DFSDM internal registers */
1972  if(HAL_OK != HAL_DFSDM_ChannelDeInit(&hAudioInTopLeftChannel))
1973  {
1974  return AUDIO_ERROR;
1975  }
1976 
1977  if(HAL_OK != HAL_DFSDM_ChannelDeInit(&hAudioInTopRightChannel))
1978  {
1979  return AUDIO_ERROR;
1980  }
1981 
1982  if(AudioIn_ChannelNumber > 2)
1983  {
1984  /* De-initializes the DFSDM filters to allow access to DFSDM internal registers */
1985  if(HAL_OK != HAL_DFSDM_FilterDeInit(&hAudioInButtomLeftFilter))
1986  {
1987  return AUDIO_ERROR;
1988  }
1989 
1990  if(HAL_OK != HAL_DFSDM_FilterDeInit(&hAudioInButtomRightFilter))
1991  {
1992  return AUDIO_ERROR;
1993  }
1994 
1995  /* De-initializes the DFSDM channels to allow access to DFSDM internal registers */
1996  if(HAL_OK != HAL_DFSDM_ChannelDeInit(&hAudioInButtomLeftChannel))
1997  {
1998  return AUDIO_ERROR;
1999  }
2000 
2001  if(HAL_OK != HAL_DFSDM_ChannelDeInit(&hAudioInButtomRightChannel))
2002  {
2003  return AUDIO_ERROR;
2004  }
2005  }
2006 
2007  return AUDIO_OK;
2008 }
2009 
2015 static void DFSDMx_ChannelMspInit(void)
2016 {
2017  GPIO_InitTypeDef GPIO_InitStruct;
2018 
2019  /* Enable DFSDM clock */
2021 
2022  /* Enable GPIO clock */
2025 
2026  /* DFSDM pins configuration: DFSDM_CKOUT, DMIC_DATIN1 pins ------------------*/
2027  GPIO_InitStruct.Pin = AUDIO_DFSDMx_CKOUT_PIN;
2028  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
2029  GPIO_InitStruct.Pull = GPIO_NOPULL;
2030  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
2031  GPIO_InitStruct.Alternate = AUDIO_DFSDMx_CKOUT_AF;
2033 
2034  /* DFSDM pin configuration: DMIC_DATIN1 pin --------------------------------*/
2035  GPIO_InitStruct.Pin = AUDIO_DFSDMx_DMIC_DATIN1_PIN;
2036  GPIO_InitStruct.Alternate = AUDIO_DFSDMx_DMIC_DATIN_AF;
2038 
2039  if(AudioIn_ChannelNumber > 2)
2040  {
2041  /* DFSDM pin configuration: DMIC_DATIN5 pin --------------------------------*/
2042  GPIO_InitStruct.Pin = AUDIO_DFSDMx_DMIC_DATIN5_PIN;
2043  GPIO_InitStruct.Alternate = AUDIO_DFSDMx_DMIC_DATIN_AF;
2045  }
2046 }
2047 
2053 static void DFSDMx_ChannelMspDeInit(void)
2054 {
2055  GPIO_InitTypeDef GPIO_InitStruct;
2056 
2057  /* DFSDM pin configuration: DMIC_DATIN1 pin --------------------------------*/
2058  GPIO_InitStruct.Pin = AUDIO_DFSDMx_CKOUT_PIN;
2060  GPIO_InitStruct.Pin = AUDIO_DFSDMx_DMIC_DATIN1_PIN;
2062 
2063  if(AudioIn_ChannelNumber > 2)
2064  {
2065  /* DFSDM pin configuration: DMIC_DATIN5 pin ------------------------------*/
2066  GPIO_InitStruct.Pin = AUDIO_DFSDMx_CKOUT_PIN;
2068  GPIO_InitStruct.Pin = AUDIO_DFSDMx_DMIC_DATIN5_PIN;
2070  }
2071 }
2072 
2078 static void DFSDMx_FilterMspInit(void)
2079 {
2080  /* Enable DFSDM clock */
2082 
2083  /* Enable the DMA clock */
2085 
2086  /*********** Configure DMA stream for TOP LEFT microphone *******************/
2087  hDmaTopLeft.Init.Direction = DMA_PERIPH_TO_MEMORY;
2088  hDmaTopLeft.Init.PeriphInc = DMA_PINC_DISABLE;
2089  hDmaTopLeft.Init.MemInc = DMA_MINC_ENABLE;
2092  hDmaTopLeft.Init.Mode = DMA_CIRCULAR;
2093  hDmaTopLeft.Init.Priority = DMA_PRIORITY_HIGH;
2095  hDmaTopLeft.Init.Channel = AUDIO_DFSDMx_DMAx_CHANNEL;
2096 
2097  /* Associate the DMA handle */
2098  __HAL_LINKDMA(&hAudioInTopLeftFilter, hdmaReg, hDmaTopLeft);
2099 
2100  /* Reset DMA handle state */
2101  __HAL_DMA_RESET_HANDLE_STATE(&hDmaTopLeft);
2102 
2103  /* Configure the DMA Channel */
2104  HAL_DMA_Init(&hDmaTopLeft);
2105 
2106  /* DMA IRQ Channel configuration */
2109 
2110 
2111  /*********** Configure DMA stream for TOP RIGHT microphone ******************/
2112  hDmaTopRight.Init.Direction = DMA_PERIPH_TO_MEMORY;
2113  hDmaTopRight.Init.PeriphInc = DMA_PINC_DISABLE;
2114  hDmaTopRight.Init.MemInc = DMA_MINC_ENABLE;
2117  hDmaTopRight.Init.Mode = DMA_CIRCULAR;
2118  hDmaTopRight.Init.Priority = DMA_PRIORITY_HIGH;
2120  hDmaTopRight.Init.Channel = AUDIO_DFSDMx_DMAx_CHANNEL;
2121 
2122  /* Associate the DMA handle */
2123  __HAL_LINKDMA(&hAudioInTopRightFilter, hdmaReg, hDmaTopRight);
2124 
2125  /* Reset DMA handle state */
2126  __HAL_DMA_RESET_HANDLE_STATE(&hDmaTopRight);
2127 
2128  /* Configure the DMA Channel */
2129  HAL_DMA_Init(&hDmaTopRight);
2130 
2131  /* DMA IRQ Channel configuration */
2134 
2135  if(AudioIn_ChannelNumber > 2)
2136  {
2137  /*********** Configure DMA stream for BUTTOM LEFT microphone ****************/
2138  hDmaButtomLeft.Init.Direction = DMA_PERIPH_TO_MEMORY;
2139  hDmaButtomLeft.Init.PeriphInc = DMA_PINC_DISABLE;
2140  hDmaButtomLeft.Init.MemInc = DMA_MINC_ENABLE;
2143  hDmaButtomLeft.Init.Mode = DMA_CIRCULAR;
2144  hDmaButtomLeft.Init.Priority = DMA_PRIORITY_HIGH;
2146  hDmaButtomLeft.Init.Channel = AUDIO_DFSDMx_DMAx_CHANNEL;
2147 
2148  /* Associate the DMA handle */
2149  __HAL_LINKDMA(&hAudioInButtomLeftFilter, hdmaReg, hDmaButtomLeft);
2150 
2151  /* Reset DMA handle state */
2152  __HAL_DMA_RESET_HANDLE_STATE(&hDmaButtomLeft);
2153 
2154  /* Configure the DMA Channel */
2155  HAL_DMA_Init(&hDmaButtomLeft);
2156 
2157  /* DMA IRQ Channel configuration */
2160 
2161 
2162  /*********** Configure DMA stream for BUTTOM RIGHT microphone ***************/
2163  hDmaButtomRight.Init.Direction = DMA_PERIPH_TO_MEMORY;
2164  hDmaButtomRight.Init.PeriphInc = DMA_PINC_DISABLE;
2165  hDmaButtomRight.Init.MemInc = DMA_MINC_ENABLE;
2168  hDmaButtomRight.Init.Mode = DMA_CIRCULAR;
2169  hDmaButtomRight.Init.Priority = DMA_PRIORITY_HIGH;
2171  hDmaButtomRight.Init.Channel = AUDIO_DFSDMx_DMAx_CHANNEL;
2172 
2173  /* Associate the DMA handle */
2174  __HAL_LINKDMA(&hAudioInButtomRightFilter, hdmaReg, hDmaButtomRight);
2175 
2176  /* Reset DMA handle state */
2177  __HAL_DMA_RESET_HANDLE_STATE(&hDmaButtomRight);
2178 
2179  /* Configure the DMA Channel */
2180  HAL_DMA_Init(&hDmaButtomRight);
2181 
2182  /* DMA IRQ Channel configuration */
2185  }
2186 }
2187 
2193 static void DFSDMx_FilterMspDeInit(void)
2194 {
2195  /* Configure the DMA Channel */
2196  HAL_DMA_DeInit(&hDmaTopLeft);
2197  HAL_DMA_DeInit(&hDmaTopRight);
2198  if(AudioIn_ChannelNumber > 2)
2199  {
2200  HAL_DMA_DeInit(&hDmaButtomLeft);
2201  HAL_DMA_DeInit(&hDmaButtomRight);
2202  }
2203 }
2204 
2221 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define AUDIO_DFSDMx_TOP_LEFT_CHANNEL
__weak void BSP_AUDIO_IN_ClockConfig(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, uint32_t AudioFreq, void *Params)
Clock Config.
#define AUDIO_DFSDMx_TOP_LEFT_FILTER
SAI_SlotInitTypeDef SlotInit
#define SAI_FIFOTHRESHOLD_1QF
#define AUDIO_I2C_ADDRESS
Audio I2C Slave address.
RCC_PLLI2SInitTypeDef PLLI2S
#define AUDIO_IN_SAIx
HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size)
void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size)
Sends n-Bytes on the SAI interface.
#define AUDIO_IN_SAIx_SD_PIN
uint8_t BSP_AUDIO_IN_GetChannelNumber(void)
Return audio in channel number.
__weak void BSP_AUDIO_OUT_MspDeInit(SAI_HandleTypeDef *hsai, void *Params)
Deinitializes SAI MSP.
#define AUDIO_DFSDMx_CKOUT_PIN
void AUDIO_Player_IncHeartbeat(void)
Increment the audio reception counter (heartbeat)
Definition: AudioPlayer.c:371
#define GPIO_NOPULL
#define SAI_STEREOMODE
#define SAI_CLOCKSTROBING_FALLINGEDGE
#define AUDIO_OK
#define AUDIO_IN_SAIx_CLK_DISABLE()
__weak void BSP_AUDIO_IN_MspInit(void)
Initialize BSP_AUDIO_IN MSP.
void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai)
Tx Half Transfer completed callbacks.
#define AUDIO_DFSDMx_TOP_RIGHT_FILTER
#define SAI_DATASIZE_16
#define AUDIO_DFSDMx_DMAx_TOP_LEFT_IRQ
__weak void BSP_AUDIO_IN_TransferComplete_CallBack(void)
User callback when record buffer is filled.
void HAL_Delay(__IO uint32_t Delay)
This function provides accurate delay (in milliseconds) based on variable incremented.
#define DMA_FIFOMODE_DISABLE
__weak void BSP_AUDIO_IN_Error_CallBack(void)
Audio IN Error callback function.
#define AUDIO_OUT_SAIx_FS_PIN
#define DMA_MBURST_SINGLE
uint32_t idx
Definition: lcd_log.c:247
DMA_HandleTypeDef hDmaTopRight
#define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__)
#define DFSDM1_Channel4
Definition: stm32f765xx.h:1506
uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option)
Stops audio playing and Power down the Audio Codec.
#define AUDIO_OUT_SAIx_DMAx_CLK_ENABLE()
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai)
void BSP_AUDIO_OUT_SetAudioFrameSlot(uint32_t AudioFrameSlot)
Updates the Audio frame slot configuration.
HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size)
#define WM8994_ID
WM8994 ID.
Definition: wm8994.h:120
#define AUDIO_IN_INT_GPIO_PIN
void SPDIF_TX_HalfTransfer_CallBack(void)
ISR Handler for the SPDIF Tx (first buffer full)
Definition: SPDIF_Tx.c:109
uint32_t(* Stop)(uint16_t, uint32_t)
Definition: audio.h:89
#define SAI_MASTERDIVIDER_ENABLE
#define AUDIO_DFSDMx_DMIC_DATIN5_PIN
void BSP_AUDIO_OUT_DeInit(void)
De-initializes the audio out peripheral.
DFSDM_Channel_HandleTypeDef hAudioInButtomRightChannel
uint8_t BSP_AUDIO_IN_AllocScratch(int32_t *pScratch, uint32_t size)
Allocate channel buffer scratch.
DMA_InitTypeDef Init
uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume)
Controls the current audio volume level.
#define SAI_OUTPUT_RELEASED
#define SAI_FIRSTBIT_MSB
#define AUDIO_OUT_SAIx_SCK_PIN
#define DMA_PINC_DISABLE
#define AUDIO_DFSDMx_CKOUT_DMIC_GPIO_CLK_ENABLE()
DFSDM_Channel_HandleTypeDef hAudioInTopRightChannel
uint8_t BSP_AUDIO_IN_Stop(void)
Stop audio recording.
#define DFSDM1_Channel0
Definition: stm32f765xx.h:1502
#define AUDIO_DFSDMx_DMAx_BUTTOM_LEFT_IRQ
DMA_HandleTypeDef hDmaTopLeft
#define AUDIO_DFSDMx_TOP_RIGHT_CHANNEL
#define __HAL_DMA_RESET_HANDLE_STATE(__HANDLE__)
Reset DMA handle state.
SAI_Block_TypeDef * Instance
#define SAI_ASYNCHRONOUS
HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai)
uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
Configures the audio peripherals.
#define DEFAULT_AUDIO_IN_CHANNEL_NBR
#define AUDIO_IN_SAIx_SD_GPIO_PORT
#define OUTPUT_DEVICE_HEADPHONE
Definition: wm8994.h:75
#define AUDIO_IN_SAIx_DMAx_CLK_ENABLE()
uint32_t(* ReadID)(uint16_t)
Definition: audio.h:85
void BSP_AUDIO_IN_DeInit(void)
Deinit the audio IN peripherals.
#define AUDIO_DFSDMx_DMAx_CHANNEL
AUDIO_DrvTypeDef * audio_drv
#define GPIO_MODE_INPUT
#define AUDIO_OUT_SAIx_DMAx_MEM_DATA_SIZE
uint32_t(* Init)(uint16_t, uint16_t, uint8_t, uint32_t)
Definition: audio.h:83
#define __HAL_SAI_ENABLE(__HANDLE__)
#define DMA_FIFO_THRESHOLD_FULL
#define AUDIO_OUT_SAIx_CLK_DISABLE()
#define AUDIO_DFSDMx_DMAx_TOP_RIGHT_IRQ
#define SAI_OUTPUTDRIVE_ENABLE
__weak void BSP_AUDIO_OUT_ClockConfig(SAI_HandleTypeDef *hsai, uint32_t AudioFreq, void *Params)
Clock Config.
#define DFSDM1_Channel5
Definition: stm32f765xx.h:1507
#define SaturaLH(N, L, H)
#define AUDIO_OUT_SAIx
uint32_t(* Reset)(uint16_t)
Definition: audio.h:94
#define AUDIO_DFSDMx_BUTTOM_RIGHT_FILTER
HAL_SAI_StateTypeDef HAL_SAI_GetState(SAI_HandleTypeDef *hsai)
#define DFSDM1_Channel1
Definition: stm32f765xx.h:1503
#define AUDIO_IN_INT_IRQ
#define AUDIO_FREQUENCY_22K
Definition: wm8994.h:106
#define AUDIO_DFSDMx_DMAx_BUTTOM_LEFT_STREAM
void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq)
Updates the audio frequency.
uint8_t BSP_AUDIO_OUT_Resume(void)
Resumes the audio file stream. When calling BSP_AUDIO_OUT_Pause() function for pause, only BSP_AUDIO_OUT_Resume() function should be called for resume (use of BSP_AUDIO_OUT_Play() function for resume could lead to unexpected behaviour).
#define NULL
Definition: usbd_def.h:53
#define GPIO_SPEED_FREQ_VERY_HIGH
#define SAI_MODESLAVE_RX
#define SAI_OUTPUTDRIVE_DISABLE
#define AUDIO_IN_SAIx_DMAx_PERIPH_DATA_SIZE
#define __IO
Definition: core_cm0.h:213
DMA_HandleTypeDef * hdmatx
#define AUDIO_DFSDMx_DMAx_MEM_DATA_SIZE
RCC extended clocks structure definition.
uint32_t(* Pause)(uint16_t)
Definition: audio.h:87
#define SAI_SYNCEXT_DISABLE
#define SAI_FS_ACTIVE_LOW
#define DFSDM_RIGHT_BIT_SHIFT(__FREQUENCY__)
#define CODEC_AUDIOFRAME_SLOT_0123
HAL_StatusTypeDef HAL_SAI_DeInit(SAI_HandleTypeDef *hsai)
#define AUDIO_DFSDMx_DMIC_DATIN_GPIO_PORT
uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output)
Switch dynamically (while audio file is played) the output target (speaker or headphone).
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
Reception complete callback.
#define AUDIO_OUT_SAIx_AF
#define SAI_OUTPUT_NOTRELEASED
#define AUDIO_OUT_SAIx_CLK_ENABLE()
DMA_HandleTypeDef hDmaButtomLeft
#define AUDIO_FREQUENCY_11K
Definition: wm8994.h:108
#define RCC_SAI2CLKSOURCE_PLLI2S
#define SAI_FREE_PROTOCOL
Definition: pbuf.h:108
#define SAI_NOCOMPANDING
DMA_HandleTypeDef hDmaButtomRight
DMA_Stream_TypeDef * Instance
#define SAI_MASTERDIVIDER_ENABLED
#define AUDIO_IN_INT_GPIO_ENABLE()
#define AUDIO_IN_IRQ_PREPRIO
#define AUDIO_IN_INT_GPIO_PORT
void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai)
Tx Transfer completed callbacks.
#define AUDIODATA_SIZE
void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
#define AUDIO_IN_SAIx_DMAx_STREAM
#define AUDIO_DFSDMx_DMAx_BUTTOM_RIGHT_STREAM
uint32_t(* Play)(uint16_t, uint16_t *, uint16_t)
Definition: audio.h:86
#define AUDIO_OUT_IRQ_PREPRIO
#define AUDIO_IN_SAIx_DMAx_IRQ
SAI_FrameInitTypeDef FrameInit
uint8_t BSP_AUDIO_IN_Resume(void)
Resume the audio file stream.
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
#define DFSDM_OVER_SAMPLING(__FREQUENCY__)
void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai)
Half reception complete callback.
#define AUDIO_OUT_SAIx_MCLK_PIN
#define SAI_MODEMASTER_TX
#define AUDIO_DFSDMx_DMAx_TOP_RIGHT_STREAM
#define SAI_CLOCKSTROBING_RISINGEDGE
uint8_t BSP_AUDIO_IN_InitEx(uint16_t InputDevice, uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr)
Initialize wave recording.
#define DFSDM_FILTER_ORDER(__FREQUENCY__)
GPIO Init structure definition.
DFSDM_Filter_HandleTypeDef hAudioInTopLeftFilter
uint32_t PeriphDataAlignment
uint8_t BSP_AUDIO_OUT_Play(uint16_t *pBuffer, uint32_t Size)
Starts playing audio stream from a data buffer for a determined size.
AUDIO_DrvTypeDef wm8994_drv
Definition: wm8994.c:88
uint8_t BSP_AUDIO_OUT_Pause(void)
This function Pauses the audio file stream. In case of using DMA, the DMA Pause feature is used...
uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd)
Enables or disables the MUTE mode by software.
#define AUDIO_IN_SAIx_CLK_ENABLE()
__weak void BSP_AUDIO_OUT_Error_CallBack(void)
Manages the DMA FIFO error event.
#define AUDIO_DFSDMx_CKOUT_DMIC_GPIO_PORT
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
#define AUDIO_FREQUENCY_44K
Definition: wm8994.h:104
#define AUDIO_OUT_SAIx_SD_FS_SCK_GPIO_PORT
__weak void BSP_AUDIO_IN_MspDeInit(void)
DeInitialize BSP_AUDIO_IN MSP.
#define AUDIO_OUT_SAIx_MCLK_GPIO_PORT
DFSDM_Filter_HandleTypeDef hAudioInTopRightFilter
#define RCC_PERIPHCLK_SAI2
#define DMA_PBURST_SINGLE
#define CODEC_AUDIOFRAME_SLOT_02
#define AUDIO_DFSDMx_DMAx_CLK_ENABLE()
#define AUDIO_OUT_SAIx_SD_FS_CLK_ENABLE()
void SPDIF_TX_TransferComplete_CallBack(void)
ISR Handler for the SPDIF Tx (second buffer full)
Definition: SPDIF_Tx.c:89
DFSDM_Filter_HandleTypeDef hAudioInButtomLeftFilter
#define DMA_MINC_ENABLE
#define AUDIO_OUT_SAIx_MCLK_ENABLE()
#define AUDIO_DFSDMx_DMAx_PERIPH_DATA_SIZE
#define CODEC_PDWN_HW
Definition: wm8994.h:93
uint8_t BSP_AUDIO_IN_Record(uint16_t *pbuf, uint32_t size)
Start audio recording.
#define AUDIO_DFSDMx_CKOUT_AF
HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai)
#define INPUT_DEVICE_DIGITAL_MIC
void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai)
SAI error callbacks.
SAI_InitTypeDef Init
#define __HAL_SAI_DISABLE(__HANDLE__)
#define SAI_OUTPUTDRIVE_ENABLED
#define AUDIO_DFSDMx_BUTTOM_LEFT_FILTER
DMA handle Structure definition.
#define AUDIO_DFSDMx_DMIC_DATIN1_PIN
DFSDM_Channel_HandleTypeDef hAudioInButtomLeftChannel
#define SAI_FS_BEFOREFIRSTBIT
#define AUDIO_IN_SAIx_SD_ENABLE()
#define SAI_FS_CHANNEL_IDENTIFICATION
#define AUDIO_DFSDMx_BUTTOM_RIGHT_CHANNEL
#define AUDIO_OUT_SAIx_DMAx_STREAM
#define AUDIO_IN_SAIx_DMAx_CHANNEL
void HAL_DFSDM_FilterRegConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
Half regular conversion complete callback.
#define DMA_MAX(x)
uint32_t(* Resume)(uint16_t)
Definition: audio.h:88
DFSDM_Filter_HandleTypeDef hAudioInButtomRightFilter
#define AUDIO_OUT_SAIx_SD_PIN
HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
__weak void BSP_AUDIO_OUT_HalfTransfer_CallBack(void)
Manages the DMA Half Transfer complete event.
#define AUDIO_OUT_SAIx_DMAx_PERIPH_DATA_SIZE
#define AUDIO_DFSDMx_CLK_ENABLE()
#define DMA_FIFOMODE_ENABLE
#define SAI_SYNCHRONOUS
#define AUDIO_DFSDMx_DMAx_TOP_LEFT_STREAM
AUDIOIN_TypeDef hAudioIn
uint32_t(* SetVolume)(uint16_t, uint8_t)
Definition: audio.h:91
uint32_t(* SetOutputMode)(uint16_t, uint8_t)
Definition: audio.h:93
#define AUDIO_OUT_SAIx_DMAx_CHANNEL
#define DFSDM_CLOCK_DIVIDER(__FREQUENCY__)
#define RCC_PERIPHCLK_SAI1
#define AUDIO_DFSDMx_BUTTOM_LEFT_CHANNEL
This file contains the common defines and functions prototypes for the stm32f769i_discovery_audio.c driver.
#define SAI_SLOTSIZE_DATASIZE
#define AUDIO_IN_SAIx_DMAx_MEM_DATA_SIZE
uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr)
Initialize wave recording.
#define GPIO_MODE_AF_PP
__weak void BSP_AUDIO_IN_HalfTransfer_CallBack(void)
Manages the DMA Half Transfer complete event.
uint32_t MemDataAlignment
#define RCC_SAI1CLKSOURCE_PLLI2S
HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
SAI_HandleTypeDef haudio_out_sai
#define DMA_PERIPH_TO_MEMORY
#define AUDIO_DFSDMx_DMIC_DATIN_AF
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
void BSP_AUDIO_OUT_Restart(uint16_t *pBuffer, uint32_t Size)
#define AUDIO_DFSDMx_DMIC_DATIN_GPIO_CLK_ENABLE()
#define DMA_CIRCULAR
void HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
Regular conversion complete callback.
uint8_t BSP_AUDIO_IN_Pause(void)
Pause the audio file stream.
__weak void BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params)
Initializes BSP_AUDIO_OUT MSP.
#define DMA_PRIORITY_HIGH
uint32_t(* SetMute)(uint16_t, uint32_t)
Definition: audio.h:92
#define AUDIO_OUT_SAIx_DMAx_IRQ
DFSDM_Channel_HandleTypeDef hAudioInTopLeftChannel
HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai)
SAI_HandleTypeDef haudio_in_sai
#define AUDIO_DFSDMx_DMAx_BUTTOM_RIGHT_IRQ
#define DMA_MEMORY_TO_PERIPH
__weak void BSP_AUDIO_OUT_TransferComplete_CallBack(void)
Manages the DMA full Transfer complete event.
#define AUDIO_IN_SAIx_AF