usbd_audio_if.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : usbd_audio_if.c
  5. * @version : v1.0_Cube
  6. * @brief : Generic media access layer.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2024 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "usbd_audio_if.h"
  22. /* USER CODE BEGIN INCLUDE */
  23. /* USER CODE END INCLUDE */
  24. /* Private typedef -----------------------------------------------------------*/
  25. /* Private define ------------------------------------------------------------*/
  26. /* Private macro -------------------------------------------------------------*/
  27. /* USER CODE BEGIN PV */
  28. /* Private variables ---------------------------------------------------------*/
  29. /* USER CODE END PV */
  30. /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
  31. * @brief Usb device library.
  32. * @{
  33. */
  34. /** @addtogroup USBD_AUDIO_IF
  35. * @{
  36. */
  37. /** @defgroup USBD_AUDIO_IF_Private_TypesDefinitions USBD_AUDIO_IF_Private_TypesDefinitions
  38. * @brief Private types.
  39. * @{
  40. */
  41. /* USER CODE BEGIN PRIVATE_TYPES */
  42. /* USER CODE END PRIVATE_TYPES */
  43. /**
  44. * @}
  45. */
  46. /** @defgroup USBD_AUDIO_IF_Private_Defines USBD_AUDIO_IF_Private_Defines
  47. * @brief Private defines.
  48. * @{
  49. */
  50. /* USER CODE BEGIN PRIVATE_DEFINES */
  51. /* USER CODE END PRIVATE_DEFINES */
  52. /**
  53. * @}
  54. */
  55. /** @defgroup USBD_AUDIO_IF_Private_Macros USBD_AUDIO_IF_Private_Macros
  56. * @brief Private macros.
  57. * @{
  58. */
  59. /* USER CODE BEGIN PRIVATE_MACRO */
  60. /* USER CODE END PRIVATE_MACRO */
  61. /**
  62. * @}
  63. */
  64. /** @defgroup USBD_AUDIO_IF_Private_Variables USBD_AUDIO_IF_Private_Variables
  65. * @brief Private variables.
  66. * @{
  67. */
  68. /* USER CODE BEGIN PRIVATE_VARIABLES */
  69. /* USER CODE END PRIVATE_VARIABLES */
  70. /**
  71. * @}
  72. */
  73. /** @defgroup USBD_AUDIO_IF_Exported_Variables USBD_AUDIO_IF_Exported_Variables
  74. * @brief Public variables.
  75. * @{
  76. */
  77. extern USBD_HandleTypeDef hUsbDeviceFS;
  78. /* USER CODE BEGIN EXPORTED_VARIABLES */
  79. /* USER CODE END EXPORTED_VARIABLES */
  80. /**
  81. * @}
  82. */
  83. /** @defgroup USBD_AUDIO_IF_Private_FunctionPrototypes USBD_AUDIO_IF_Private_FunctionPrototypes
  84. * @brief Private functions declaration.
  85. * @{
  86. */
  87. static int8_t AUDIO_Init_FS(uint32_t AudioFreq, uint32_t Volume, uint32_t options);
  88. static int8_t AUDIO_DeInit_FS(uint32_t options);
  89. static int8_t AUDIO_AudioCmd_FS(uint8_t* pbuf, uint32_t size, uint8_t cmd);
  90. static int8_t AUDIO_VolumeCtl_FS(uint8_t vol);
  91. static int8_t AUDIO_MuteCtl_FS(uint8_t cmd);
  92. static int8_t AUDIO_PeriodicTC_FS(uint8_t *pbuf, uint32_t size, uint8_t cmd);
  93. static int8_t AUDIO_GetState_FS(void);
  94. /* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */
  95. /* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */
  96. /**
  97. * @}
  98. */
  99. USBD_AUDIO_ItfTypeDef USBD_AUDIO_fops_FS =
  100. {
  101. AUDIO_Init_FS,
  102. AUDIO_DeInit_FS,
  103. AUDIO_AudioCmd_FS,
  104. AUDIO_VolumeCtl_FS,
  105. AUDIO_MuteCtl_FS,
  106. AUDIO_PeriodicTC_FS,
  107. AUDIO_GetState_FS,
  108. };
  109. /* Private functions ---------------------------------------------------------*/
  110. /**
  111. * @brief Initializes the AUDIO media low layer over USB FS IP
  112. * @param AudioFreq: Audio frequency used to play the audio stream.
  113. * @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
  114. * @param options: Reserved for future use
  115. * @retval USBD_OK if all operations are OK else USBD_FAIL
  116. */
  117. static int8_t AUDIO_Init_FS(uint32_t AudioFreq, uint32_t Volume, uint32_t options)
  118. {
  119. /* USER CODE BEGIN 0 */
  120. UNUSED(AudioFreq);
  121. UNUSED(Volume);
  122. UNUSED(options);
  123. return (USBD_OK);
  124. /* USER CODE END 0 */
  125. }
  126. /**
  127. * @brief De-Initializes the AUDIO media low layer
  128. * @param options: Reserved for future use
  129. * @retval USBD_OK if all operations are OK else USBD_FAIL
  130. */
  131. static int8_t AUDIO_DeInit_FS(uint32_t options)
  132. {
  133. /* USER CODE BEGIN 1 */
  134. UNUSED(options);
  135. return (USBD_OK);
  136. /* USER CODE END 1 */
  137. }
  138. /**
  139. * @brief Handles AUDIO command.
  140. * @param pbuf: Pointer to buffer of data to be sent
  141. * @param size: Number of data to be sent (in bytes)
  142. * @param cmd: Command opcode
  143. * @retval USBD_OK if all operations are OK else USBD_FAIL
  144. */
  145. static int8_t AUDIO_AudioCmd_FS(uint8_t* pbuf, uint32_t size, uint8_t cmd)
  146. {
  147. /* USER CODE BEGIN 2 */
  148. switch(cmd)
  149. {
  150. case AUDIO_CMD_START:
  151. break;
  152. case AUDIO_CMD_PLAY:
  153. break;
  154. }
  155. UNUSED(pbuf);
  156. UNUSED(size);
  157. UNUSED(cmd);
  158. return (USBD_OK);
  159. /* USER CODE END 2 */
  160. }
  161. /**
  162. * @brief Controls AUDIO Volume.
  163. * @param vol: volume level (0..100)
  164. * @retval USBD_OK if all operations are OK else USBD_FAIL
  165. */
  166. static int8_t AUDIO_VolumeCtl_FS(uint8_t vol)
  167. {
  168. /* USER CODE BEGIN 3 */
  169. UNUSED(vol);
  170. return (USBD_OK);
  171. /* USER CODE END 3 */
  172. }
  173. /**
  174. * @brief Controls AUDIO Mute.
  175. * @param cmd: command opcode
  176. * @retval USBD_OK if all operations are OK else USBD_FAIL
  177. */
  178. static int8_t AUDIO_MuteCtl_FS(uint8_t cmd)
  179. {
  180. /* USER CODE BEGIN 4 */
  181. UNUSED(cmd);
  182. return (USBD_OK);
  183. /* USER CODE END 4 */
  184. }
  185. /**
  186. * @brief AUDIO_PeriodicT_FS
  187. * @param cmd: Command opcode
  188. * @retval USBD_OK if all operations are OK else USBD_FAIL
  189. */
  190. static int8_t AUDIO_PeriodicTC_FS(uint8_t *pbuf, uint32_t size, uint8_t cmd)
  191. {
  192. /* USER CODE BEGIN 5 */
  193. UNUSED(pbuf);
  194. UNUSED(size);
  195. UNUSED(cmd);
  196. return (USBD_OK);
  197. /* USER CODE END 5 */
  198. }
  199. /**
  200. * @brief Gets AUDIO State.
  201. * @retval USBD_OK if all operations are OK else USBD_FAIL
  202. */
  203. static int8_t AUDIO_GetState_FS(void)
  204. {
  205. /* USER CODE BEGIN 6 */
  206. return (USBD_OK);
  207. /* USER CODE END 6 */
  208. }
  209. /**
  210. * @brief Manages the DMA full transfer complete event.
  211. * @retval None
  212. */
  213. void TransferComplete_CallBack_FS(void)
  214. {
  215. /* USER CODE BEGIN 7 */
  216. USBD_AUDIO_Sync(&hUsbDeviceFS, AUDIO_OFFSET_FULL);
  217. /* USER CODE END 7 */
  218. }
  219. /**
  220. * @brief Manages the DMA Half transfer complete event.
  221. * @retval None
  222. */
  223. void HalfTransfer_CallBack_FS(void)
  224. {
  225. /* USER CODE BEGIN 8 */
  226. USBD_AUDIO_Sync(&hUsbDeviceFS, AUDIO_OFFSET_HALF);
  227. /* USER CODE END 8 */
  228. }
  229. /* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */
  230. /* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */
  231. /**
  232. * @}
  233. */
  234. /**
  235. * @}
  236. */