stm322xg_eval_audio.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. ******************************************************************************
  3. * @file stm322xg_eval_audio.h
  4. * @author MCD Application Team
  5. * @brief This file contains the common defines and functions prototypes for
  6. * the stm322xg_eval_audio.c driver.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  11. *
  12. * Redistribution and use in source and binary forms, with or without modification,
  13. * are permitted provided that the following conditions are met:
  14. * 1. Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  20. * may be used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  29. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  30. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  31. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ******************************************************************************
  35. */
  36. /* Define to prevent recursive inclusion -------------------------------------*/
  37. #ifndef __STM322xG_EVAL_AUDIO_H
  38. #define __STM322xG_EVAL_AUDIO_H
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /* Includes ------------------------------------------------------------------*/
  43. #include "../Components/cs43l22/cs43l22.h"
  44. #include "stm322xg_eval.h"
  45. /** @addtogroup BSP
  46. * @{
  47. */
  48. /** @addtogroup STM322xG_EVAL
  49. * @{
  50. */
  51. /** @addtogroup STM322xG_EVAL_AUDIO
  52. * @{
  53. */
  54. /** @defgroup STM322xG_EVAL_AUDIO_Exported_Constants STM322xG EVAL AUDIO Exported Constants
  55. * @{
  56. */
  57. /* Audio Reset Pin definition */
  58. #define AUDIO_RESET_PIN IO_PIN_2
  59. /* I2S peripheral configuration defines */
  60. #define AUDIO_I2Sx SPI2
  61. #define AUDIO_I2Sx_CLK_ENABLE() __HAL_RCC_SPI2_CLK_ENABLE()
  62. #define AUDIO_I2Sx_CLK_DISABLE() __HAL_RCC_SPI2_CLK_DISABLE()
  63. #define AUDIO_I2Sx_SCK_SD_WS_AF GPIO_AF5_SPI2
  64. #define AUDIO_I2Sx_SCK_SD_WS_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
  65. #define AUDIO_I2Sx_MCK_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
  66. #define AUDIO_I2Sx_WS_PIN GPIO_PIN_0
  67. #define AUDIO_I2Sx_SCK_PIN GPIO_PIN_1
  68. #define AUDIO_I2Sx_SD_PIN GPIO_PIN_3
  69. #define AUDIO_I2Sx_MCK_PIN GPIO_PIN_6
  70. #define AUDIO_I2Sx_SCK_SD_WS_GPIO_PORT GPIOI
  71. #define AUDIO_I2Sx_MCK_GPIO_PORT GPIOC
  72. /* I2S DMA Stream definitions */
  73. #define AUDIO_I2Sx_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE()
  74. #define AUDIO_I2Sx_DMAx_STREAM DMA1_Stream4
  75. #define AUDIO_I2Sx_DMAx_CHANNEL DMA_CHANNEL_0
  76. #define AUDIO_I2Sx_DMAx_IRQ DMA1_Stream4_IRQn
  77. #define AUDIO_I2Sx_DMAx_PERIPH_DATA_SIZE DMA_PDATAALIGN_HALFWORD
  78. #define AUDIO_I2Sx_DMAx_MEM_DATA_SIZE DMA_MDATAALIGN_HALFWORD
  79. #define DMA_MAX_SZE 0xFFFF
  80. #define AUDIO_I2Sx_DMAx_IRQHandler DMA1_Stream4_IRQHandler
  81. /*------------------------------------------------------------------------------
  82. CONFIGURATION: Audio Driver Configuration parameters
  83. ------------------------------------------------------------------------------*/
  84. /* Select the interrupt preemption priority for the DMA interrupt */
  85. #define AUDIO_IRQ_PREPRIO 0x0F /* Select the preemption priority level(0 is the highest) */
  86. #define AUDIODATA_SIZE 2 /* 16-bits audio data size */
  87. /* Audio status definition */
  88. #define AUDIO_OK 0x00
  89. #define AUDIO_ERROR 0x01
  90. #define AUDIO_TIMEOUT 0x02
  91. /*------------------------------------------------------------------------------
  92. OPTIONAL Configuration defines parameters
  93. ------------------------------------------------------------------------------*/
  94. /* Delay for the Codec to be correctly reset */
  95. #define CODEC_RESET_DELAY 5
  96. /**
  97. * @}
  98. */
  99. /** @defgroup STM322xG_EVAL_AUDIO_Exported_Macros STM322xG EVAL AUDIO Exported Macros
  100. * @{
  101. */
  102. #define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE)
  103. /**
  104. * @}
  105. */
  106. /** @defgroup STM322xG_EVAL_AUDIO_Exported_Functions STM322xG EVAL AUDIO Exported Functions
  107. * @{
  108. */
  109. uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq);
  110. void BSP_AUDIO_OUT_DeInit(void);
  111. uint8_t BSP_AUDIO_OUT_Play(uint16_t *pBuffer, uint32_t Size);
  112. void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size);
  113. uint8_t BSP_AUDIO_OUT_Pause(void);
  114. uint8_t BSP_AUDIO_OUT_Resume(void);
  115. uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option);
  116. uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume);
  117. void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq);
  118. uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd);
  119. uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output);
  120. /* User Callbacks: user has to implement these functions in his code if they are needed. */
  121. /* This function is called when the requested data has been completely transferred.*/
  122. void BSP_AUDIO_OUT_TransferComplete_CallBack(void);
  123. /* This function is called when half of the requested buffer has been transferred. */
  124. void BSP_AUDIO_OUT_HalfTransfer_CallBack(void);
  125. /* This function is called when an Interrupt due to transfer error on or peripheral
  126. error occurs. */
  127. void BSP_AUDIO_OUT_Error_CallBack(void);
  128. /* These function can be modified in case the current settings (e.g. DMA stream)
  129. need to be changed for specific application needs */
  130. void BSP_AUDIO_OUT_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params);
  131. void BSP_AUDIO_OUT_MspInit(I2S_HandleTypeDef *hi2s, void *Params);
  132. void BSP_AUDIO_OUT_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params);
  133. /**
  134. * @}
  135. */
  136. /**
  137. * @}
  138. */
  139. /**
  140. * @}
  141. */
  142. /**
  143. * @}
  144. */
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif /* __STM322xG_EVAL_AUDIO_H */
  149. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/