STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
usbh_audio.h
Go to the documentation of this file.
1 
28 /* Define to prevent recursive ----------------------------------------------*/
29 #ifndef __USBH_AUDIO_H
30 #define __USBH_AUDIO_H
31 
32 #ifdef __cplusplus
33  extern "C" {
34 #endif
35 
36 /* Includes ------------------------------------------------------------------*/
37 #include "usbh_core.h"
38 
61 /* States for AUDIO State Machine */
62 typedef enum
63 {
64  AUDIO_INIT = 0,
85 }
87 
88 typedef enum
89 {
97 }
99 
100 typedef enum
101 {
110 }
112 
113 typedef enum
114 {
120 }
122 
123 typedef enum
124 {
127 }
129 
130 typedef enum
131 {
137 }
139 
140 
141 typedef enum
142 {
145 }
147 
148 /* Structure for AUDIO process */
149 typedef struct
150 {
151  uint8_t Channels;
152  uint8_t Bits;
153  uint32_t SampleRate;
154 }
156 
157 typedef struct
158 {
159  uint8_t Ep;
160  uint16_t EpSize;
161  uint8_t AltSettings;
162  uint8_t interface;
163  uint8_t valid;
164  uint16_t Poll;
165 }
167 
168 typedef struct
169 {
170  uint8_t Ep;
171  uint16_t EpSize;
172  uint8_t AltSettings;
173  uint8_t interface;
174  uint8_t valid;
175  uint16_t Poll;
176 }
178 
179 
180 typedef struct
181 {
182  uint8_t mute;
183  uint32_t volumeMin;
184  uint32_t volumeMax;
185  uint32_t volume;
186  uint32_t resolution;
187 }
189 
190 typedef struct
191 {
192 
193  uint8_t Ep;
194  uint16_t EpSize;
195  uint8_t interface;
196  uint8_t AltSettings;
197  uint8_t supported;
198 
199  uint8_t Pipe;
200  uint8_t Poll;
201  uint32_t timer ;
202 
203  uint8_t asociated_as;
204  uint8_t asociated_mixer;
209 
210  uint32_t frequency;
211  uint8_t *buf;
212  uint8_t *cbuf;
213  uint32_t partial_ptr;
214 
215  uint32_t global_ptr;
216  uint16_t frame_length;
217  uint32_t total_length;
218 
220 }
222 
223 typedef struct
224 {
225 
226  uint8_t Ep;
227  uint16_t EpSize;
228  uint8_t interface;
229  uint8_t supported;
230 
231  uint8_t Pipe;
232  uint8_t Poll;
233  uint32_t timer ;
234 }
236 
237 
238 #define AUDIO_MAX_AUDIO_STD_INTERFACE 0x05
239 #define AUDIO_MAX_FREQ_SUPPORTED 0x05
240 #define AUDIO_MAX_STREAMING_INTERFACE 0x05
241 #define AUDIO_MAX_NUM_IN_TERMINAL 0x04
242 #define AUDIO_MAX_NUM_OUT_TERMINAL 0x04
243 #define AUDIO_MAX_NUM_FEATURE_UNIT 0x04
244 #define AUDIO_MAX_NUM_MIXER_UNIT 0x04
245 #define AUDIO_MAX_NUM_SELECTOR_UNIT 0x04
246 
247 #define HEADPHONE_SUPPORTED 0x01
248 #define MICROPHONE_SUPPORTED 0x02
249 #define HEADSET_SUPPORTED 0x03
250 
251 #define AUDIO_MAX_SAMFREQ_NBR 5
252 #define AUDIO_MAX_INTERFACE_NBR 5
253 #define AUDIO_MAX_CONTROLS_NBR 5
254 
255 /*Class-Specific AS(Audio Streaming) Interface Descriptor*/
256 typedef struct
257 {
258  uint8_t bLength;
261  uint8_t bTerminalLink;
262  uint8_t bDelay;
263  uint8_t wFormatTag[2];
264 }
266 
267 /*Class-Specific AS(Audio Streaming) Format Type Descriptor*/
268 typedef struct
269 {
270  uint8_t bLength;
273  uint8_t bFormatType;
274  uint8_t bNrChannels;
275  uint8_t bSubframeSize;
276  uint8_t bBitResolution;
277  uint8_t bSamFreqType;
278  uint8_t tSamFreq[AUDIO_MAX_SAMFREQ_NBR][3];
279 }
281 
282 /*Class-Specific AS(Audio Streaming) Interface Descriptor*/
283 typedef struct
284 {
287 }
289 
290 /* 4.3.2 Class-Specific AC Interface Descriptor */
291 
292 typedef struct
293 {
294  uint8_t bLength;
295  uint8_t bDescriptorType;
297  uint8_t bcdADC[2];
298  uint8_t wTotalLength[2];
299  uint8_t bInCollection;
300  uint8_t baInterfaceNr[AUDIO_MAX_INTERFACE_NBR];
301 }
303 
304 /* 4.3.2.1 Input Terminal Descriptor */
305 typedef struct
306 {
307  uint8_t bLength;
308  uint8_t bDescriptorType;
310  uint8_t bTerminalID;
311  uint8_t wTerminalType[2];
312  uint8_t bAssocTerminal;
313  uint8_t bNrChannels;
314  uint8_t wChannelConfig[2];
315  uint8_t iChannelNames;
316  uint8_t iTerminal;
317 }
319 
320 /* 4.3.2.2 Output Terminal Descriptor */
321 typedef struct
322 {
323  uint8_t bLength;
324  uint8_t bDescriptorType;
326  uint8_t bTerminalID;
327  uint8_t wTerminalType[2];
328  uint8_t bAssocTerminal;
329  uint8_t bSourceID;
330  uint8_t iTerminal;
331 }
333 
334 /* 4.3.2.3 Feature Descriptor */
335 typedef struct
336 {
337  uint8_t bLength;
338  uint8_t bDescriptorType;
340  uint8_t bUnitID;
341  uint8_t bSourceID;
342  uint8_t bControlSize;
343  uint8_t bmaControls[AUDIO_MAX_CONTROLS_NBR][2];
344 }
346 
347 
348 /* 4.3.2.3 Feature Descriptor */
349 typedef struct
350 {
351  uint8_t bLength;
352  uint8_t bDescriptorType;
354  uint8_t bUnitID;
355  uint8_t bNrInPins;
356  uint8_t bSourceID0;
357  uint8_t bSourceID1;
358  uint8_t bNrChannels;
359  uint8_t bmChannelsConfig[2];
360  uint8_t iChannelsNames;
361  uint8_t bmaControls;
362  uint8_t iMixer;
363 }
365 
366 
367 
368 /* 4.3.2.3 Feature Descriptor */
369 typedef struct
370 {
371  uint8_t bLength;
372  uint8_t bDescriptorType;
374  uint8_t bUnitID;
375  uint8_t bNrInPins;
376  uint8_t bSourceID0;
377  uint8_t iSelector;
378 }
380 
381 /*Class-Specific AC(Audio Control) Interface Descriptor*/
382 typedef struct
383 {
390 }
392 
393 /*Class-Specific AC : Global descriptor*/
394 
395 typedef struct
396 {
397  AUDIO_ACDescTypeDef cs_desc; /* Only one control descriptor*/
399 
400  uint16_t ASNum;
401  uint16_t InputTerminalNum;
402  uint16_t OutputTerminalNum;
403  uint16_t FeatureUnitNum;
404  uint16_t SelectorUnitNum;
405  uint16_t MixerUnitNum;
406 }
408 
409 
410 typedef struct _AUDIO_Process
411 {
412  AUDIO_ReqStateTypeDef req_state;
413  AUDIO_CSReqStateTypeDef cs_req_state;
414  AUDIO_PlayStateTypeDef play_state;
415  AUDIO_ControlStateTypeDef control_state;
416  AUDIO_ProcessingTypeDef processing_state;
417 
421 
425  uint16_t mem [8];
426  uint8_t temp_feature;
427  uint8_t temp_channels;
428 }
430 
440 /*Audio Interface Subclass Codes*/
441 #define AC_CLASS 0x01
442 
443 /* A.2 Audio Interface Subclass Codes */
444 #define USB_SUBCLASS_AUDIOCONTROL 0x01
445 #define USB_SUBCLASS_AUDIOSTREAMING 0x02
446 #define USB_SUBCLASS_MIDISTREAMING 0x03
447 
448 #define USB_DESC_TYPE_CS_INTERFACE 0x24
449 #define USB_DESC_TYPE_CS_ENDPOINT 0x25
450 
451 /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
452 #define UAC_HEADER 0x01
453 #define UAC_INPUT_TERMINAL 0x02
454 #define UAC_OUTPUT_TERMINAL 0x03
455 #define UAC_MIXER_UNIT 0x04
456 #define UAC_SELECTOR_UNIT 0x05
457 #define UAC_FEATURE_UNIT 0x06
458 #define UAC_PROCESSING_UNIT 0x07
459 #define UAC_EXTENSION_UNIT 0x08
460 
461 /*Audio Class-Specific Endpoint Descriptor Subtypes*/
462 #define EP_CONTROL_UNDEFINED 0x00
463 #define SAMPLING_FREQ_CONTROL 0x01
464 #define PITCH_CONTROL 0x02
465 
466 /*Feature unit control selector*/
467 #define FU_CONTROL_UNDEFINED 0x00
468 #define MUTE_CONTROL 0x01
469 #define VOLUME_CONTROL 0x02
470 #define BASS_CONTROL 0x03
471 #define MID_CONTROL 0x04
472 #define TREBLE_CONTROL 0x05
473 #define GRAPHIC_EQUALIZER_CONTROL 0x06
474 #define AUTOMATIC_GAIN_CONTROL 0x07
475 #define DELAY_CONTROL 0x08
476 #define BASS_BOOST_CONTROL 0x09
477 #define LOUDNESS_CONTROL 0x0A
478 
479 /*Terminal control selector*/
480 #define TE_CONTROL_UNDEFINED 0x00
481 #define COPY_PROTECT_CONTROL 0x01
482 
483 
484 /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
485 #define UAC_AS_GENERAL 0x01
486 #define UAC_FORMAT_TYPE 0x02
487 #define UAC_FORMAT_SPECIFIC 0x03
488 
489 /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
490 #define UAC_EP_GENERAL 0x01
491 
492 /* A.9 Audio Class-Specific Request Codes */
493 #define UAC_SET_ 0x00
494 #define UAC_GET_ 0x80
495 
496 #define UAC__CUR 0x1
497 #define UAC__MIN 0x2
498 #define UAC__MAX 0x3
499 #define UAC__RES 0x4
500 #define UAC__MEM 0x5
501 
502 #define UAC_SET_CUR (UAC_SET_ | UAC__CUR)
503 #define UAC_GET_CUR (UAC_GET_ | UAC__CUR)
504 #define UAC_SET_MIN (UAC_SET_ | UAC__MIN)
505 #define UAC_GET_MIN (UAC_GET_ | UAC__MIN)
506 #define UAC_SET_MAX (UAC_SET_ | UAC__MAX)
507 #define UAC_GET_MAX (UAC_GET_ | UAC__MAX)
508 #define UAC_SET_RES (UAC_SET_ | UAC__RES)
509 #define UAC_GET_RES (UAC_GET_ | UAC__RES)
510 #define UAC_SET_MEM (UAC_SET_ | UAC__MEM)
511 #define UAC_GET_MEM (UAC_GET_ | UAC__MEM)
512 
513 #define UAC_GET_STAT 0xff
514 
515 /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
516 #define UAC_MS_HEADER 0x01
517 #define UAC_MIDI_IN_JACK 0x02
518 #define UAC_MIDI_OUT_JACK 0x03
519 
520 /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
521 #define UAC_MS_GENERAL 0x01
522 
523 /* Terminals - 2.1 USB Terminal Types */
524 #define UAC_TERMINAL_UNDEFINED 0x100
525 #define UAC_TERMINAL_STREAMING 0x101
526 #define UAC_TERMINAL_VENDOR_SPEC 0x1FF
527 
543 #define USBH_AUDIO_CLASS &AUDIO_Class
544 
552  uint16_t sample_rate,
553  uint8_t channel_num,
554  uint8_t data_width);
555 
556 USBH_StatusTypeDef USBH_AUDIO_Play (USBH_HandleTypeDef *phost, uint8_t *buf, uint32_t length);
563 
565 
566 #define USBH_AUDIO_FrequencySetCallback USBH_AUDIO_FrequencySet
572 #ifdef __cplusplus
573 }
574 #endif
575 
576 #endif /* __USBH_AUDIO_H */
577 
593 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
594 
#define AUDIO_MAX_INTERFACE_NBR
Definition: usbh_audio.h:252
Header file for usbh_core.c.
AUDIO_ControlStateTypeDef
Definition: usbh_audio.h:130
AUDIO_PlayStateTypeDef play_state
Definition: usbh_audio.h:414
#define AUDIO_MAX_NUM_IN_TERMINAL
Definition: usbh_audio.h:241
uint8_t temp_feature
Definition: usbh_audio.h:426
AUDIO_VolumeCtrlTypeDef
Definition: usbh_audio.h:123
uint8_t bDescriptorType
Definition: usbh_audio.h:324
uint8_t bDescriptorType
Definition: usbh_audio.h:308
#define AUDIO_MAX_NUM_FEATURE_UNIT
Definition: usbh_audio.h:243
AUDIO_ControlStateTypeDef control_state
Definition: usbh_audio.h:415
USBH_StatusTypeDef USBH_AUDIO_Stop(USBH_HandleTypeDef *phost)
USBH_AUDIO_Pause Stop the playback process.
Definition: usbh_audio.c:1764
uint8_t bAssocTerminal
Definition: usbh_audio.h:312
uint8_t bAssocTerminal
Definition: usbh_audio.h:328
USBH_StatusTypeDef USBH_AUDIO_Play(USBH_HandleTypeDef *phost, uint8_t *buf, uint32_t length)
USBH_AUDIO_Play Start playback process.
Definition: usbh_audio.c:1734
void USBH_AUDIO_BufferEmptyCallback(USBH_HandleTypeDef *phost)
The function informs user that User data are processed.
Definition: usbh_audio.c:1998
#define AUDIO_MAX_SAMFREQ_NBR
Definition: usbh_audio.h:251
AUDIO_ControlAttributeTypeDef attribute
Definition: usbh_audio.h:219
struct _AUDIO_Process AUDIO_HandleTypeDef
AUDIO_PlayStateTypeDef
Definition: usbh_audio.h:113
void USBH_AUDIO_FrequencySet(USBH_HandleTypeDef *phost)
The function informs user that Settings have been changed.
Definition: usbh_audio.c:1988
AUDIO_ClassSpecificDescTypedef class_desc
Definition: usbh_audio.h:420
#define AUDIO_MAX_NUM_SELECTOR_UNIT
Definition: usbh_audio.h:245
AUDIO_StateTypeDef
Definition: usbh_audio.h:62
AUDIO_InterfaceStreamPropTypeDef microphone
Definition: usbh_audio.h:423
AUDIO_STREAMING_OUT_HandleTypeDef stream_out[AUDIO_MAX_AUDIO_STD_INTERFACE]
Definition: usbh_audio.h:419
USBH_StatusTypeDef USBH_AUDIO_ChangeOutBuffer(USBH_HandleTypeDef *phost, uint8_t *buf)
USBH_AUDIO_ChangeOutBuffer Change audio data buffer address.
Definition: usbh_audio.c:1844
AUDIO_InterfaceStreamPropTypeDef headphone
Definition: usbh_audio.h:422
uint8_t temp_channels
Definition: usbh_audio.h:427
#define AUDIO_MAX_NUM_MIXER_UNIT
Definition: usbh_audio.h:244
#define AUDIO_MAX_AUDIO_STD_INTERFACE
Definition: usbh_audio.h:238
AUDIO_InterfaceControlPropTypeDef control
Definition: usbh_audio.h:424
USBH_StatusTypeDef USBH_AUDIO_SetFrequency(USBH_HandleTypeDef *phost, uint16_t sample_rate, uint8_t channel_num, uint8_t data_width)
USBH_AUDIO_SetFrequency Set Audio sampling parameters.
Definition: usbh_audio.c:1669
int32_t USBH_AUDIO_GetOutOffset(USBH_HandleTypeDef *phost)
USBH_AUDIO_GetOutOffset return the current buffer pointer for OUT process.
Definition: usbh_audio.c:1822
USBH_StatusTypeDef USBH_AUDIO_Suspend(USBH_HandleTypeDef *phost)
USBH_AUDIO_Suspend Suspend the playback process.
Definition: usbh_audio.c:1777
AUDIO_CSReqStateTypeDef cs_req_state
Definition: usbh_audio.h:413
AUDIO_ProcessingTypeDef processing_state
Definition: usbh_audio.h:416
AUDIO_ProcessingTypeDef
Definition: usbh_audio.h:141
AUDIO_STREAMING_IN_HandleTypeDef stream_in[AUDIO_MAX_AUDIO_STD_INTERFACE]
Definition: usbh_audio.h:418
#define AUDIO_MAX_CONTROLS_NBR
Definition: usbh_audio.h:253
AUDIO_HeaderDescTypeDef * HeaderDesc
Definition: usbh_audio.h:384
USBH_StatusTypeDef
Definition: usbh_def.h:302
AUDIO_ReqStateTypeDef
Definition: usbh_audio.h:88
AUDIO_ACDescTypeDef cs_desc
Definition: usbh_audio.h:397
AUDIO_ASGeneralDescTypeDef * GeneralDesc
Definition: usbh_audio.h:285
USBH_ClassTypeDef AUDIO_Class
Definition: usbh_audio.c:175
USBH_StatusTypeDef USBH_AUDIO_SetVolume(USBH_HandleTypeDef *phost, AUDIO_VolumeCtrlTypeDef volume_ctl)
USBH_AUDIO_SetVolume Set Volume.
Definition: usbh_audio.c:1936
Definition: mem.c:179
uint8_t bDescriptorSubtype
Definition: usbh_audio.h:325
AUDIO_CSReqStateTypeDef
Definition: usbh_audio.h:100
uint8_t bDescriptorSubtype
Definition: usbh_audio.h:309
AUDIO_ReqStateTypeDef req_state
Definition: usbh_audio.h:412
#define AUDIO_MAX_STREAMING_INTERFACE
Definition: usbh_audio.h:240
USBH_StatusTypeDef USBH_AUDIO_Resume(USBH_HandleTypeDef *phost)
USBH_AUDIO_Resume Resume the playback process.
Definition: usbh_audio.c:1800
#define AUDIO_MAX_NUM_OUT_TERMINAL
Definition: usbh_audio.h:242
AUDIO_ASFormatTypeDescTypeDef * FormatTypeDesc
Definition: usbh_audio.h:286