usbd_audio_out_if.c
Go to the documentation of this file.
1 
28 /* Includes ------------------------------------------------------------------*/
29 #include "usbd_audio_core.h"
30 #include "usbd_audio_out_if.h"
31 
69 static uint8_t Init (uint32_t AudioFreq, uint32_t Volume, uint32_t options);
70 static uint8_t DeInit (uint32_t options);
71 static uint8_t AudioCmd (uint8_t* pbuf, uint32_t size, uint8_t cmd);
72 static uint8_t VolumeCtl (uint8_t vol);
73 static uint8_t MuteCtl (uint8_t cmd);
74 static uint8_t PeriodicTC (uint8_t cmd);
75 static uint8_t GetState (void);
76 
85 {
86  Init,
87  DeInit,
88  AudioCmd,
89  VolumeCtl,
90  MuteCtl,
91  PeriodicTC,
92  GetState
93 };
94 
96 
113 static uint8_t Init (uint32_t AudioFreq,
114  uint32_t Volume,
115  uint32_t options)
116 {
117  static uint32_t Initialized = 0;
118 
119  /* Check if the low layer has already been initialized */
120  if (Initialized == 0)
121  {
122  /* Call low layer function */
123  if (EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, Volume, AudioFreq) != 0)
124  {
126  return AUDIO_FAIL;
127  }
128 
129  /* Set the Initialization flag to prevent reinitializing the interface again */
130  Initialized = 1;
131  }
132 
133  /* Update the Audio state machine */
135 
136  return AUDIO_OK;
137 }
138 
145 static uint8_t DeInit (uint32_t options)
146 {
147  /* Update the Audio state machine */
149 
150  return AUDIO_OK;
151 }
152 
162 static uint8_t AudioCmd(uint8_t* pbuf,
163  uint32_t size,
164  uint8_t cmd)
165 {
166  /* Check the current state */
168  {
170  return AUDIO_FAIL;
171  }
172 
173  switch (cmd)
174  {
175  /* Process the PLAY command ----------------------------*/
176  case AUDIO_CMD_PLAY:
177  /* If current state is Active or Stopped */
178  if ((AudioState == AUDIO_STATE_ACTIVE) || \
181  {
182  Audio_MAL_Play((uint32_t)pbuf, (size/2));
184  return AUDIO_OK;
185  }
186  /* If current state is Paused */
187  else if (AudioState == AUDIO_STATE_PAUSED)
188  {
189  if (EVAL_AUDIO_PauseResume(AUDIO_RESUME, (uint32_t)pbuf, (size/2)) != 0)
190  {
192  return AUDIO_FAIL;
193  }
194  else
195  {
197  return AUDIO_OK;
198  }
199  }
200  else /* Not allowed command */
201  {
202  return AUDIO_FAIL;
203  }
204 
205  /* Process the STOP command ----------------------------*/
206  case AUDIO_CMD_STOP:
208  {
209  /* Unsupported command */
210  return AUDIO_FAIL;
211  }
212  else if (EVAL_AUDIO_Stop(CODEC_PDWN_SW) != 0)
213  {
215  return AUDIO_FAIL;
216  }
217  else
218  {
220  return AUDIO_OK;
221  }
222 
223  /* Process the PAUSE command ---------------------------*/
224  case AUDIO_CMD_PAUSE:
226  {
227  /* Unsupported command */
228  return AUDIO_FAIL;
229  }
230  else if (EVAL_AUDIO_PauseResume(AUDIO_PAUSE, (uint32_t)pbuf, (size/2)) != 0)
231  {
233  return AUDIO_FAIL;
234  }
235  else
236  {
238  return AUDIO_OK;
239  }
240 
241  /* Unsupported command ---------------------------------*/
242  default:
243  return AUDIO_FAIL;
244  }
245 }
246 
253 static uint8_t VolumeCtl (uint8_t vol)
254 {
255  /* Call low layer volume setting function */
256  if (EVAL_AUDIO_VolumeCtl(vol) != 0)
257  {
259  return AUDIO_FAIL;
260  }
261 
262  return AUDIO_OK;
263 }
264 
271 static uint8_t MuteCtl (uint8_t cmd)
272 {
273  /* Call low layer mute setting function */
274  if (EVAL_AUDIO_Mute(cmd) != 0)
275  {
277  return AUDIO_FAIL;
278  }
279 
280  return AUDIO_OK;
281 }
282 
290 static uint8_t PeriodicTC (uint8_t cmd)
291 {
292 
293 
294  return AUDIO_OK;
295 }
296 
297 
304 static uint8_t GetState (void)
305 {
306  return AudioState;
307 }
308 
321 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define AUDIO_STATE_ACTIVE
#define AUDIO_STATE_ERROR
static uint8_t DeInit(uint32_t options)
DeInit Free all resources used by low layer and stops audio-play function.
#define AUDIO_OK
static uint8_t Init(uint32_t AudioFreq, uint32_t Volume, uint32_t options)
Init Initialize and configures all required resources for audio play function.
static uint8_t cmd
Definition: drv_hmc5883l.c:79
#define AUDIO_STATE_PAUSED
static uint8_t MuteCtl(uint8_t cmd)
MuteCtl Mute or Unmute the audio current output.
#define AUDIO_FAIL
static uint8_t PeriodicTC(uint8_t cmd)
static uint8_t VolumeCtl(uint8_t vol)
VolumeCtl Set the volume level in %.
static uint8_t AudioState
static uint8_t GetState(void)
GetState Return the current state of the audio machine.
#define AUDIO_STATE_STOPPED
#define AUDIO_STATE_INACTIVE
#define AUDIO_STATE_PLAYING
AUDIO_FOPS_TypeDef AUDIO_OUT_fops
header file for the usbd_audio_out_if.c file.
header file for the usbd_audio_core.c file.
static uint8_t AudioCmd(uint8_t *pbuf, uint32_t size, uint8_t cmd)
AudioCmd Play, Stop, Pause or Resume current file.


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:26