1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016, 2020 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef __USB_HOST_AUDIO_H__ 10 #define __USB_HOST_AUDIO_H__ 11 12 /******************************************************************************* 13 * Audio class private structure, enumerations, macros 14 ******************************************************************************/ 15 /******************************************************************************* 16 * Definitions 17 ******************************************************************************/ 18 /* Structure for an AUDIO class descriptor according to the 6.2.1 in Audio 1.0 specification*/ 19 20 /* Audio 1.0 class codes */ 21 #define SET_COMMAND (0x00) 22 #define GET_COMMAND (0x80) 23 #define CUR_REQUEST (0x01) 24 #define MIN_REQUEST (0x02) 25 #define MAX_REQUEST (0x03) 26 #define RES_REQUEST (0x04) 27 #define MEM_REQUEST (0x05) 28 #define GET_STATUS (0xFF) 29 30 #define ITF_REQUEST (0x21) 31 #define EP_REQUEST (0x22) 32 33 #define AUDIO_FU_MUTE_MASK 0x01 34 #define AUDIO_FU_VOLUME_MASK 0x02 35 #define AUDIO_FU_BASS_MASK 0x04 36 #define AUDIO_FU_MID_MASK 0x08 37 #define AUDIO_FU_TREBLE_MASK 0x10 38 #define AUDIO_FU_GRAPHIC_EQ_MASK 0x20 39 #define AUDIO_FU_AGC_MASK 0x40 40 #define AUDIO_FU_DELAY_MASK 0x80 41 #define AUDIO_FU_BASS_BOOST_MASK 0x01 42 43 /* USB audio1.0 Endpoint Control Selectors */ 44 #define AUDIO_EP_CONTROL_UNDEFINED (0x00) 45 #define AUDIO_SAMPLING_FREQ_CONTROL (0x01) 46 #define AUDIO_PITCH_CONTROL (0x02) 47 /* USB audio2.0 Endpoint Control Selectors */ 48 #define AUDIO_EP_CONTROL_UNDEFINED_20 (0x00) 49 #define AUDIO_EP_PITCH_CONTROL_20 (0x01) 50 #define AUDIO_EP_DATA_OVERRUN_CONTRO_20 (0x02) 51 #define AUDIO_EP_DATA_UNDERRUN_CONTROL_20 (0x03) 52 53 /* USB audio1.0 MASK*/ 54 #define AUDIO_SAMPLING_FREQ_MASK (0x01) 55 #define AUDIO_PITCH_MASK (0x02) 56 57 /*! @brief Audio device Format Type Codes */ 58 #define USB_AUDIO_FORMAT_TYPE_UNDEFINED (0x00) 59 #define USB_AUDIO_FORMAT_TYPE_I (0x01) 60 #define USB_AUDIO_FORMAT_TYPE_II (0x02) 61 #define USB_AUDIO_FORMAT_TYPE_III (0x03) 62 /* USB audio2.0 format type */ 63 #define USB_AUDIO_FORMAT_TYPE_IV (0x04) 64 #define USB_AUDIO_FORMAT_EXT_FORMAT_TYPE_I (0x81) 65 #define USB_AUDIO_FORMAT_EXT_FORMAT_TYPE_II (0x82) 66 #define USB_AUDIO_FORMAT_EXT_FORMAT_TYPE_III (0x83) 67 68 typedef enum _fu_request_code 69 { 70 kUSB_AudioCurMute = 0, 71 kUSB_AudioCurVolume, 72 kUSB_AudioMinVolume, 73 kUSB_AudioMaxVolume, 74 kUSB_AudioResVolume, 75 NUMBER_OF_FEATURE_COMMANDS, 76 } fu_request_code_t; 77 78 typedef enum _ep_request_code 79 { 80 kUSB_AudioCurPitch = 0, 81 kUSB_AudioCurSamplingFreq, 82 kUSB_AudioMinSamplingFreq, 83 kUSB_AudioMaxSamplingFreq, 84 kUSB_AudioResSamplingFreq, 85 NUMBER_OF_ENDPOINT_COMMANDS, 86 } ep_request_code_t; 87 88 typedef union _audio_descriptor_union 89 { 90 uint8_t *bufr; 91 usb_descriptor_common_t *common; 92 usb_descriptor_device_t *device; 93 usb_descriptor_configuration_t *configuration; 94 usb_descriptor_interface_t *interface; 95 usb_descriptor_endpoint_t *endpoint; 96 } audio_descriptor_union_t; 97 98 /* Audio command structure */ 99 typedef struct _usb_audio_request 100 { 101 uint8_t controlMask; 102 uint8_t typeRequest; 103 uint8_t codeRequest; 104 uint8_t requestValue; 105 uint8_t length; 106 } usb_audio_request_t; 107 108 /******************************************************************************* 109 * Audio class public structure, enumeration, macros, functions 110 ******************************************************************************/ 111 /*! 112 * @addtogroup usb_host_audio_drv 113 * @{ 114 */ 115 /*! @brief Audio class code */ 116 #define USB_AUDIO_CLASS_CODE 1 117 /*! @brief Audio class control interface code*/ 118 #define USB_AUDIO_SUBCLASS_CODE_CONTROL 1 119 /*! @brief Audio class stream interface code*/ 120 #define USB_AUDIO_SUBCLASS_CODE_AUDIOSTREAMING 2 121 122 /* Audio Device Class Specification Release Number in Binary-Coded Decimal.*/ 123 #define AUDIO_DEVICE_VERSION_01 0x0100U 124 #define AUDIO_DEVICE_VERSION_02 0x0200U 125 126 /*! @brief AUDIO class-specific feature unit get current mute command*/ 127 #define USB_AUDIO_GET_CUR_MUTE 0x80 128 /*! @brief AUDIO class-specific feature unit set current mute command*/ 129 #define USB_AUDIO_SET_CUR_MUTE 0x00 130 /*! @brief AUDIO class-specific feature unit get current volume command*/ 131 #define USB_AUDIO_GET_CUR_VOLUME 0x81 132 /*! @brief AUDIO class-specific feature unit set current volume command*/ 133 #define USB_AUDIO_SET_CUR_VOLUME 0x01 134 /*! @brief AUDIO class-specific feature unit get minimum volume command*/ 135 #define USB_AUDIO_GET_MIN_VOLUME 0x82 136 /*! @brief AUDIO class-specific feature unit set minimum volume command*/ 137 #define USB_AUDIO_SET_MIN_VOLUME 0x02 138 /*! @brief AUDIO class-specific feature unit get maximum volume command*/ 139 #define USB_AUDIO_GET_MAX_VOLUME 0x83 140 /*! @brief AUDIO class-specific feature unit set maximum volume command*/ 141 #define USB_AUDIO_SET_MAX_VOLUME 0x03 142 /*! @brief AUDIO class-specific feature unit get resolution volume command*/ 143 #define USB_AUDIO_GET_RES_VOLUME 0x84 144 /*! @brief AUDIO class-specific feature unit set resolution volume command*/ 145 #define USB_AUDIO_SET_RES_VOLUME 0x04 146 147 /*! @brief AUDIO class-specific endpoint get current pitch control command*/ 148 #define USB_AUDIO_GET_CUR_PITCH 0x80 149 /*! @brief AUDIO class-specific endpoint set current pitch control command*/ 150 #define USB_AUDIO_SET_CUR_PITCH 0x00 151 /*! @brief AUDIO class-specific endpoint get current sampling frequency command*/ 152 #define USB_AUDIO_GET_CUR_SAMPLING_FREQ 0x81 153 /*! @brief AUDIO class-specific endpoint set current sampling frequency command*/ 154 #define USB_AUDIO_SET_CUR_SAMPLING_FREQ 0x01 155 /*! @brief AUDIO class-specific endpoint get minimum sampling frequency command*/ 156 #define USB_AUDIO_GET_MIN_SAMPLING_FREQ 0x82 157 /*! @brief AUDIO class-specific endpoint set minimum sampling frequency command*/ 158 #define USB_AUDIO_SET_MIN_SAMPLING_FREQ 0x02 159 /*! @brief AUDIO class-specific endpoint get maximum sampling frequency command*/ 160 #define USB_AUDIO_GET_MAX_SAMPLING_FREQ 0x83 161 /*! @brief AUDIO class-specific endpoint set maximum sampling frequency command*/ 162 #define USB_AUDIO_SET_MAX_SAMPLING_FREQ 0x03 163 /*! @brief AUDIO class-specific endpoint get resolution sampling frequency command*/ 164 #define USB_AUDIO_GET_RES_SAMPLING_FREQ 0x84 165 /*! @brief AUDIO class-specific endpoint set resolution sampling frequency command*/ 166 #define USB_AUDIO_SET_RES_SAMPLING_FREQ 0x04 167 168 /*Audio Class-Specific AC Interface Descriptor Subtypes*/ 169 #define USB_AUDIO_DESC_SUBTYPE_AUDIO_UNDEFINED 0x00U /*undefined Descriptor*/ 170 /*remain two input terminal descriptor macro for compatibility, please use the latter one*/ 171 #define USB_DESC_SUBTYPE_AUDIO_CS_HEADER 0x01U 172 #define USB_AUDIO_DESC_SUBTYPE_CS_HEADER 0x01U /*Header Descriptor*/ 173 /*remain two input terminal descriptor macro for compatibility, please use the latter one*/ 174 #define USB_DESC_SUBTYPE_AUDIO_CS_IT 0x02U /*Input Terminal Descriptor*/ 175 #define USB_AUDIO_DESC_SUBTYPE_CS_INPUT 0x02U /*Input Terminal Descriptor*/ 176 177 /*remain two output terminal descriptor macro for compatibility, please use the latter one*/ 178 #define USB_DESC_SUBTYPE_AUDIO_CS_OT 0x03U /*Output Terminal Descriptor*/ 179 #define USB_AUDIO_DESC_SUBTYPE_CS_OUTPUT 0x03U /*Output Terminal Descriptor*/ 180 181 #define USB_AUDIO_DESC_SUBTYPE_CS_MIXER 0x04U /*Mixer Unit Descriptor*/ 182 #define USB_AUDIO_DESC_SUBTYPE_CS_SELECTOR 0x05U /*Selector Unit Descriptor*/ 183 /*remain two feature uint descriptor macro for compatibility, please use the latter one*/ 184 #define USB_DESC_SUBTYPE_AUDIO_CS_FU 0x06U 185 #define USB_AUDIO_DESC_SUBTYPE_CS_FEATURE 0x06U /*Feature Unit Descriptor*/ 186 187 #define USB_AUDIO_DESC_SUBTYPE_CS_EFEET 0x07U /*Effect Unit Descriptor*/ 188 #define USB_AUDIO_DESC_SUBTYPE_CS_PROCESSING 0x08U /*Processing Unit Descriptor*/ 189 /*the following descriptor is not support by Audio version 01*/ 190 #define USB_AUDIO_DESC_SUBTYPE_CS_EXTENSION 0x09U /*Extension Unit Descriptor*/ 191 #define USB_AUDIO_DESC_SUBTYPE_CS_CLOCK_SOURE 0x0AU /*Clock Source Descriptor*/ 192 #define USB_AUDIO_DESC_SUBTYPE_CS_CLCOK_SELECTOR 0x0BU /*Clock Selector Descriptor*/ 193 #define USB_AUDIO_DESC_SUBTYPE_CS_CLOCK_MULTIPLE 0x0CU /*Clock Multiple Descriptor*/ 194 195 /*remain two endpoint macro for compatibility, please use the latter one*/ 196 #define USB_DESC_CLASS_ENDPOINT_GENERAL 0x01U 197 #define USB_AUDIO_DESC_CLASS_ENDPOINT_GENERAL 0x01U 198 199 /*! @brief Audio device class-specific descriptor type */ 200 #define USB_AUDIO_DESCRIPTOR_TYPE_CS_DEVICE (0x21U) 201 #define USB_AUDIO_DESCRIPTOR_TYPE_CS_CONFIGURATION (0x22U) 202 #define USB_AUDIO_DESCRIPTOR_TYPE_CS_STRING (0x23U) 203 #define USB_AUDIO_DESCRIPTOR_TYPE_CS_INTERFACE (0x24U) 204 #define USB_AUDIO_DESCRIPTOR_TYPE_CS_ENDPOINT (0x25U) 205 206 /*Feature Unit Control Selectors, audio1.0 and audio2.0 can share same featre unit control selector code*/ 207 #define AUDIO_FU_MUTE 0x01U 208 #define AUDIO_FU_VOLUME 0x02U 209 #define AUDIO_FU_BASS 0x03U 210 #define AUDIO_FU_MID 0x04U 211 #define AUDIO_FU_TREBLE 0x05U 212 #define AUDIO_FU_GRAPHIC_EQ 0x06U 213 #define AUDIO_FU_AGC 0x07U 214 #define AUDIO_FU_DELAY 0x08U 215 #define AUDIO_FU_BASS_BOOST 0x09U 216 217 /*Audio Class-Specific AS Interface Descriptor Subtypes*/ 218 /*audio 1.0*/ 219 /*remain two subtype macro for compatibility, please use the latter one*/ 220 #define USB_DESC_SUBTYPE_AS_CS_GENERAL 0X01U 221 #define USB_DESC_SUBTYPE_AS_CS_FORMAT_TYPE 0X02U 222 223 #define USB_AUDIO_DESC_SUBTYPE_AS_GENERAL 0x01U 224 #define USB_AUDIO_DESC_SUBTYPE_AS_FORMAT_TYPE 0x02U 225 #define USB_AUDIO_DESC_SUBTYPE_AS_FORMAT_SEPCIFIC_TYPE 0x03U 226 227 /*audio 2.0*/ 228 #define USB_AUDIO_DESC_SUBTYPE_AS_GENERAL_20 0x01U 229 #define USB_AUDIO_DESC_SUBTYPE_AS_FORMAT_TYPE_20 0x02U 230 #define USB_AUDIO_DESC_SUBTYPE_AS_FORMAT_ENCODER_20 0x03U 231 #define USB_AUDIO_DESC_SUBTYPE_AS_FORMAT_DECODER_20 0x04U 232 233 /*Audio1.0 Class-Specific Request Codes*/ 234 #define USB_AUDIO_CS_REQUEST_CODE_SET_CUR 0x01U 235 #define USB_AUDIO_CS_REQUEST_CODE_GET_CUR 0x81U 236 #define USB_AUDIO_CS_REQUEST_CODE_SET_MIN 0x02U 237 #define USB_AUDIO_CS_REQUEST_CODE_GET_MIN 0x82U 238 #define USB_AUDIO_CS_REQUEST_CODE_SET_MAX 0x03U 239 #define USB_AUDIO_CS_REQUEST_CODE_GET_MAX 0x83U 240 #define USB_AUDIO_CS_REQUEST_CODE_SET_RES 0x04U 241 #define USB_AUDIO_CS_REQUEST_CODE_GET_RES 0x84U 242 #define USB_AUDIO_CS_REQUEST_CODE_SET_MEM 0x05U 243 #define USB_AUDIO_CS_REQUEST_CODE_GET_MEN 0x85U 244 #define USB_AUDIO_CS_REQUEST_CODE_GET_STAT 0xFFU 245 246 /*Audio2.0 Class-Specific Request Codes*/ 247 #define USB_AUDIO_CS_REQUEST_CODE_CUR_20 0x01U 248 #define USB_AUDIO_CS_REQUEST_CODE_RANGE_20 0x02U 249 250 /*Audio2.0 Clock Source Control Selectors Codes*/ 251 #define USB_AUDIO_CS_SAM_FREQ_CONTROL_20 0x01U 252 #define USB_AUDIO_CS_CLOCK_VALID_CONTROL_20 0x02U 253 254 /*common audio endpoint type code 255 00 = Data endpoint 256 01 = Feedback endpoint 257 10 = Implicit feedback Data endpoit, usb Spec 9.6*/ 258 #define USB_AUDIO_EP_TYPE_DATA 0x00U 259 #define USB_AUDIO_EP_TYPE_FEEDBACK 0x01U 260 #define USB_AUDIO_EP_TYPE_IMPLICIT 0x02U 261 262 /*endpoint control selectors*/ 263 /*audio 1.0*/ 264 #define USB_AUDIO_EP_CS_SAMPING_FREQ_CONTROL 0x01U 265 #define USB_AUDIO_EP_CS_PINTCH_CONTROL 0x02U 266 /*audio 2.0*/ 267 #define USB_AUDIO_EP_CS_PINTCH_CONTROL_20 0x01U 268 #define USB_AUDIO_EP_CS_OVERRUN_CONTROL_20 0x02U 269 #define USB_AUDIO_EP_CS_UNDERRUN_CONTROL_20 0x03U 270 271 struct _usb_audio_2_0_control_range_layout3_struct 272 { 273 uint8_t wNumSubRanges[2]; 274 uint8_t wMIN[4]; 275 uint8_t wMAX[4]; 276 uint8_t wRES[4]; 277 }; 278 typedef struct _usb_audio_2_0_control_range_layout3_struct usb_audio_2_0_control_range_layout3_struct_t; 279 280 struct _usb_audio_2_0_control_range_layout2_struct 281 { 282 uint8_t wNumSubRanges[2]; 283 uint8_t wMIN[2]; 284 uint8_t wMAX[2]; 285 uint8_t wRES[2]; 286 }; 287 typedef struct _usb_audio_2_0_control_range_layout2_struct usb_audio_2_0_control_range_layout2_struct_t; 288 289 /*! @brief Audio control interface header descriptor structure */ 290 typedef struct _usb_audio_2_0_ctrl_header_desc 291 { 292 uint8_t blength; /*!< Total size of the header descriptor*/ 293 uint8_t bdescriptortype; /*!< Descriptor type of audio header descriptor*/ 294 uint8_t bdescriptorsubtype; /*!< Subtype of an audio header descriptor*/ 295 uint8_t bcdcdc[2]; /*!< Audio Device Class Specification Release Number in Binary-Coded Decimal*/ 296 uint8_t bCategory; /*!< Constant, indicating the primary use of this audio function, as intended by the 297 manufacturer. See Appendix A.7, Audio Function Category Codes.*/ 298 uint8_t wtotallength[2]; /*!< Total number of bytes returned for the class-specific AudioControl interface 299 descriptor. Includes the combined length of this descriptor header and all unit and 300 terminal descriptors.*/ 301 uint8_t bmControls; /*!< D1..0: Latency Control 302 D7..2: Reserved. Must be set to 0.*/ 303 } usb_audio_2_0_ctrl_header_desc_t; 304 305 /*! @brief Audio control interface clock source descriptor structure */ 306 typedef struct _usb_audio_2_0_ctrl_clock_source_desc 307 { 308 uint8_t blength; /*!< Total size of the header descriptor*/ 309 uint8_t bdescriptortype; /*!< Descriptor type of audio header descriptor*/ 310 uint8_t bdescriptorsubtype; /*!< Subtype of an audio header descriptor*/ 311 uint8_t bClockID; /*!<Constant uniquely identifying the Clock Source Entity within the audio function. This value is 312 used in all requests to address this Entity.*/ 313 uint8_t bmAttributes; /*!< D1..0: Clock Type, D2: Clock synchronized to SOF*/ 314 uint8_t bmControls; /*!< D1..0: Clock Frequency D3..2: Clock Validity Control.*/ 315 uint8_t bAssocTerminal; /*!< Terminal ID of the Terminal that is associated with this Clock Source.*/ 316 uint8_t iClockSource; /*!<Index of a string descriptor, describing the Clock Source Entity.*/ 317 318 } usb_audio_2_0_ctrl_clock_source_desc_t; 319 320 /*! @brief Audio control interface input terminal descriptor structure */ 321 typedef struct _usb_audio_2_0_ctrl_it_desc 322 { 323 uint8_t blength; /*!< Total size of the input terminal descriptor*/ 324 uint8_t bdescriptortype; /*!< Descriptor type of audio input terminal descriptor*/ 325 uint8_t bdescriptorsubtype; /*!< Subtype of audio input terminal descriptor*/ 326 uint8_t bterminalid; /*!< Constant uniquely identifying the Terminal within the audio function. This value is used 327 in all requests to address this Terminal*/ 328 uint8_t wterminaltype[2]; /*!< Constant characterizing the type of Terminal*/ 329 uint8_t bassocterminal; /*!< ID of the Output Terminal to which this Input Terminal is associated*/ 330 uint8_t bCSourceID; /*!< ID of the Clock Entity to which this Input Terminal is connected.*/ 331 uint8_t bNrChannels; /*!< Describes the spatial location of the logical channels.*/ 332 uint8_t bmChannelConfig[4]; /*!< Describes the spatial location of the logical channels.*/ 333 uint8_t iChannelNames; /*!< Index of a string descriptor, describing the Input Terminal*/ 334 uint8_t bmControls[2]; /*!<D1..0: Copy Protect Control 335 D3..2: Connector Control 336 D5..4: Overload Control 337 D7..6: Cluster Control 338 D9..8: Underflow Control 339 D11..10: Overflow Control 340 D15..12: Reserved. Must be set to 0.*/ 341 uint8_t iTerminal; /*!< Index of a string descriptor, describing the Input Terminal.*/ 342 } usb_audio_2_0_ctrl_it_desc_t; 343 344 /*! @brief Audio control interface output terminal descriptor structure */ 345 typedef struct _usb_audio_2_0_ctrl_ot_desc 346 { 347 uint8_t blength; /*!< Total size of the output terminal descriptor*/ 348 uint8_t bdescriptortype; /*!< Descriptor type of audio output terminal descriptor*/ 349 uint8_t bdescriptorsubtype; /*!< Subtype of audio output terminal descriptor*/ 350 uint8_t bterminalid; /*!< Constant uniquely identifying the Terminal within the audio function. This value is used 351 in all requests to address this Terminal*/ 352 uint8_t wterminaltype[2]; /*!< Constant characterizing the type of Terminal*/ 353 uint8_t 354 bassocterminal; /*!< IConstant, identifying the Input Terminal to which this Output Terminal is associated.*/ 355 uint8_t bSourceID; /*!< ID of the Unit or Terminal to which this Terminal is connected.*/ 356 uint8_t bCSourceID; /*!< ID of the Clock Entity to which this Output Terminal is connected.*/ 357 uint8_t bmControls[2]; /*!<D1..0: Copy Protect Control 358 D3..2: Connector Control 359 D5..4: Overload Control 360 D7..6: Underflow Control 361 D9..8: Overflow Control 362 D15..10: Reserved. Must be set to 0.*/ 363 uint8_t iTerminal; /*!< Index of a string descriptor, describing the Input Terminal.*/ 364 } usb_audio_2_0_ctrl_ot_desc_t; 365 366 /*! @brief Audio control interface feature unit descriptor structure */ 367 typedef struct _usb_audio_2_0_ctrl_fu_desc 368 { 369 uint8_t blength; /*!< Total size of the output terminal descriptor*/ 370 uint8_t bdescriptortype; /*!< Descriptor type of audio output terminal descriptor*/ 371 uint8_t bdescriptorsubtype; /*!< Subtype of audio output terminal descriptor*/ 372 uint8_t bunitid; /*!< Constant uniquely identifying the unit within the audio function. This value is used in all 373 requests to address this unit*/ 374 uint8_t bsourceid; /*!< ID of the Unit or Terminal to which this Feature Unit is connected*/ 375 uint8_t bmaControls0[4]; /*!< The Controls bitmap for master channel 0:*/ 376 } usb_audio_2_0_ctrl_fu_desc_t; 377 378 379 /*! @brief Audio control interface feature unit descriptor structure */ 380 typedef struct _usb_audio_2_0_ctrl_mu_desc 381 { 382 uint8_t blength; /*!< Total size of the output terminal descriptor*/ 383 uint8_t bdescriptortype; /*!< Descriptor type of audio output terminal descriptor*/ 384 uint8_t bdescriptorsubtype; /*!< Subtype of audio output terminal descriptor*/ 385 uint8_t bunitid; /*!< Constant uniquely identifying the unit within the audio function. This value is used in all 386 requests to address this unit*/ 387 uint8_t bNrInPins; /*!< Number of Input Pins of this Unit: p*/ 388 uint8_t baSourceID[4]; 389 } usb_audio_2_0_ctrl_mu_desc_t; 390 391 /*! @brief Audio as isochronous audio data endpoint descriptor structure */ 392 typedef struct _usb_audio_2_0_stream_specific_iso_endp_desc 393 { 394 uint8_t blength; /*!< Total size of the descriptor*/ 395 uint8_t bdescriptortype; /*!< Descriptor type of the descriptor*/ 396 uint8_t bdescriptorsubtype; /*!< Subtype of the descriptor*/ 397 uint8_t bmattributes; /*!< A bit in the range D6..0 set to 1 indicates that the mentioned Control is supported by 398 this endpoint*/ 399 uint8_t bmControls; /*!< D1..0: Pitch Control 400 D3..2: Data Overrun Control 401 D5..4: Data Underrun Control 402 D7..6: Reserved. Must be set to 0. */ 403 uint8_t blockdlayunits; /*!< Indicates the units used for the wLockDelay field*/ 404 uint8_t wlockdelay[2]; /*!< Indicates the time it takes this endpoint to reliably lock its internal clock recovery 405 circuitry. Units used depend on the value of the bLockDelayUnits field.*/ 406 } usb_audio_2_0_stream_specific_iso_endp_desc_t; 407 408 typedef struct _usb_audio_ctrl_common_header_desc 409 { 410 uint8_t blength; /*!< Total size of the header descriptor*/ 411 uint8_t bdescriptortype; /*!< Descriptor type of audio header descriptor*/ 412 uint8_t bdescriptorsubtype; /*!< Subtype of an audio header descriptor*/ 413 uint8_t bcdcdc[2]; /*!< Audio Device Class Specification Release Number in Binary-Coded Decimal*/ 414 } usb_audio_ctrl_common_header_desc_t; 415 /*! @brief Audio control interface header descriptor structure */ 416 typedef struct _usb_audio_ctrl_header_desc 417 { 418 uint8_t blength; /*!< Total size of the header descriptor*/ 419 uint8_t bdescriptortype; /*!< Descriptor type of audio header descriptor*/ 420 uint8_t bdescriptorsubtype; /*!< Subtype of an audio header descriptor*/ 421 uint8_t bcdcdc[2]; /*!< Audio Device Class Specification Release Number in Binary-Coded Decimal*/ 422 uint8_t wtotallength[2]; /*!< Total number of bytes returned for the class-specific AudioControl interface 423 descriptor. Includes the combined length of this descriptor header and all unit and 424 terminal descriptors.*/ 425 uint8_t bincollection; /*!< The number of AudioStreaming and MIDIStreaming interfaces in the Audio Interface 426 Collection to which this AudioControl interface belongs to*/ 427 } usb_audio_ctrl_header_desc_t; 428 429 /*! @brief Audio control interface input terminal descriptor structure */ 430 typedef struct _usb_audio_ctrl_it_desc 431 { 432 uint8_t blength; /*!< Total size of the input terminal descriptor*/ 433 uint8_t bdescriptortype; /*!< Descriptor type of audio input terminal descriptor*/ 434 uint8_t bdescriptorsubtype; /*!< Subtype of audio input terminal descriptor*/ 435 uint8_t bterminalid; /*!< Constant uniquely identifying the Terminal within the audio function. This value is used 436 in all requests to address this Terminal*/ 437 uint8_t wterminaltype[2]; /*!< Constant characterizing the type of Terminal*/ 438 uint8_t bassocterminal; /*!< ID of the Output Terminal to which this Input Terminal is associated*/ 439 uint8_t bnrchannels; /*!< Number of logical output channels in the Terminal's output audio channel cluster*/ 440 uint8_t wchannelconfig[2]; /*!< Describes the spatial location of the logical channels.*/ 441 uint8_t ichannelnames; /*!< Index of a string descriptor, describing the name of the first logical channel*/ 442 uint8_t iterminal; /*!<Index of a string descriptor, describing the Input Terminal*/ 443 } usb_audio_ctrl_it_desc_t; 444 445 /*! @brief Audio control interface output terminal descriptor structure */ 446 typedef struct _usb_audio_ctrl_ot_desc 447 { 448 uint8_t blength; /*!< Total size of the output terminal descriptor*/ 449 uint8_t bdescriptortype; /*!< Descriptor type of audio output terminal descriptor*/ 450 uint8_t bdescriptorsubtype; /*!< Subtype of audio output terminal descriptor*/ 451 uint8_t bterminalid; /*!< Constant uniquely identifying the Terminal within the audio function. This value is used 452 in all requests to address this Terminal*/ 453 uint8_t wterminaltype[2]; /*!< Constant characterizing the type of Terminal*/ 454 uint8_t bassocterminal; /*!< Constant, identifying the Input Terminal to which this Output Terminal is associated*/ 455 uint8_t bsourceid; /*!< ID of the Unit or Terminal to which this Terminal is connected*/ 456 uint8_t iterminal; /*!< Index of a string descriptor, describing the Output Terminal*/ 457 } usb_audio_ctrl_ot_desc_t; 458 459 /*! @brief Audio control interface feature unit descriptor structure */ 460 typedef struct _usb_audio_ctrl_fu_desc 461 { 462 uint8_t blength; /*!< Total size of the output terminal descriptor*/ 463 uint8_t bdescriptortype; /*!< Descriptor type of audio output terminal descriptor*/ 464 uint8_t bdescriptorsubtype; /*!< Subtype of audio output terminal descriptor*/ 465 uint8_t bunitid; /*!< Constant uniquely identifying the unit within the audio function. This value is used in all 466 requests to address this unit*/ 467 uint8_t bsourceid; /*!< ID of the Unit or Terminal to which this Feature Unit is connected*/ 468 uint8_t bcontrolsize; /*!< Size in bytes of an element of the bmaControls*/ 469 } usb_audio_ctrl_fu_desc_t; 470 471 /*! @brief Audio as isochronous audio data endpoint descriptor structure */ 472 typedef struct _usb_audio_stream_specific_iso_endp_desc 473 { 474 uint8_t blength; /*!< Total size of the descriptor*/ 475 uint8_t bdescriptortype; /*!< Descriptor type of the descriptor*/ 476 uint8_t bdescriptorsubtype; /*!< Subtype of the descriptor*/ 477 uint8_t bmattributes; /*!< A bit in the range D6..0 set to 1 indicates that the mentioned Control is supported by 478 this endpoint*/ 479 uint8_t blockdlayunits; /*!< Indicates the units used for the wLockDelay field*/ 480 uint8_t wlockdelay[2]; /*!< Indicates the time it takes this endpoint to reliably lock its internal clock recovery 481 circuitry. Units used depend on the value of the bLockDelayUnits field.*/ 482 } usb_audio_stream_specific_iso_endp_desc_t; 483 484 /*! @brief Audio standard as isochronous synch endpoint descriptor structure */ 485 typedef struct _usb_audio_stream_synch_endp_desc 486 { 487 uint8_t blength; /*!< Total size of the descriptor*/ 488 uint8_t bdescriptortype; /*!< Descriptor type of the endpoint descriptor*/ 489 uint8_t bendpointaddress; /*!< The address of the endpoint on the USB device described by this descriptor*/ 490 uint8_t bmattributes; /*!< D3..2: Synchronization type, D1..0: Transfer type*/ 491 uint8_t wmaxpacketsize[2]; /*!< Maximum packet size this endpoint is capable of sending or receiving when this 492 configuration is selected*/ 493 uint8_t binterval; /*!< Interval for polling endpoint for data transfers expressed in milliseconds*/ 494 uint8_t brefresh; /*!< This field indicates the rate at which an isochronous synchronization pipe provides new 495 synchronization feedback data*/ 496 uint8_t bsynchaddress; /*!< Must be reset to zero*/ 497 } usb_audio_stream_synch_endp_desc_t; 498 499 /*! @brief Audio class-specific as interface descriptor structure */ 500 typedef struct _usb_audio_stream_spepific_as_intf_desc 501 { 502 uint8_t blength; /*!< Total size of the descriptor*/ 503 uint8_t bdescriptortype; /*!< Descriptor type of the descriptor*/ 504 uint8_t bdescriptorsubtype; /*!< Subtype of the descriptor*/ 505 uint8_t bterminallink; /*!< The Terminal ID of the Terminal to which the endpoint of this interface is connected*/ 506 uint8_t bdelay; /*!< Expressed in number of frames*/ 507 uint8_t wformattag[2]; /*!< The Audio Data Format that has to be used to communicate with this interface*/ 508 } usb_audio_stream_spepific_as_intf_desc_t; 509 510 /*! @brief Audio class-specific as interface descriptor structure */ 511 typedef struct _usb_audio_2_0_stream_spepific_as_intf_desc 512 { 513 uint8_t blength; /*!< Total size of the descriptor*/ 514 uint8_t bdescriptortype; /*!< Descriptor type of the descriptor*/ 515 uint8_t bdescriptorsubtype; /*!< Subtype of the descriptor*/ 516 uint8_t bterminallink; /*!< The Terminal ID of the Terminal to which the endpoint of this interface is connected*/ 517 uint8_t bmControls; /*!< D1..0: Active Alternate Setting Control 518 D3..2: Valid Alternate Settings Control 519 D7..4: Reserved. Must be set to 0.*/ 520 uint8_t bFormatType; /*!< Constant identifying the Format Type the AudioStreaming interface is using.*/ 521 uint8_t bmFormats[4]; /*!< The Audio Data Format(s) that can be used to communicate with this interface. See the USB 522 Audio Data Formats document for further details*/ 523 uint8_t bNrChannels; /*!< Number of physical channels in the AS Interface audio channel cluster.*/ 524 uint8_t bmChannelConfig[4]; /*!< Describes the spatial location of the physical channels.*/ 525 uint8_t biChannelNames; /*!< Index of a string descriptor, describing the name of the first physical channel.*/ 526 } usb_audio_2_0_stream_spepific_as_intf_desc_t; 527 528 /* Format type descriptor */ 529 /*! @brief audio Format type descriptor structure */ 530 typedef struct _usb_audio_stream_format_type_desc 531 { 532 uint8_t blength; /*!< Total size of the descriptor*/ 533 uint8_t bdescriptortype; /*!< Descriptor type of the descriptor*/ 534 uint8_t bdescriptorsubtype; /*!< Subtype of the descriptor*/ 535 uint8_t bformattype; /*!< Constant identifying the Format Type the AudioStreaming interface is using*/ 536 uint8_t bnrchannels; /*!< Number of channels of device*/ 537 uint8_t bsubframesize; /*!< Bytes per audio subframe*/ 538 uint8_t bbitresolution; /*!< Bits per sample*/ 539 uint8_t bsamfreqtype; /*!< Frequency supported*/ 540 uint8_t tsamfreq[1][3]; /*!< Sample frequency*/ 541 } usb_audio_stream_format_type_desc_t; 542 543 /*! @brief audio Format type descriptor structure */ 544 typedef struct _usb_audio_2_0_stream_format_type_desc 545 { 546 uint8_t blength; /*!< Total size of the descriptor*/ 547 uint8_t bdescriptortype; /*!< Descriptor type of the descriptor*/ 548 uint8_t bdescriptorsubtype; /*!< Subtype of the descriptor*/ 549 uint8_t bformattype; /*!< Constant identifying the Format Type the AudioStreaming interface is using*/ 550 uint8_t bSubslotSize; /*!< The number of bytes occupied by one audio subslot. Can be 1, 2, 3 or 4.*/ 551 uint8_t bBitResolution; /*!< The number of effectively used bits from the available bits in an audio subslot*/ 552 } usb_audio_2_0_stream_format_type_desc_t; 553 554 /*! @brief Audio instance structure and audio usb_host_class_handle pointer to this structure */ 555 typedef struct _audio_instance 556 { 557 usb_host_handle hostHandle; /*!< This instance's related host handle*/ 558 usb_device_handle deviceHandle; /*!< This instance's related device handle*/ 559 usb_host_interface_handle streamIntfHandle; /*!< This instance's audio stream interface handle*/ 560 usb_host_interface_handle controlIntfHandle; /*!< This instance's control stream interface handle*/ 561 void *asIntfDesc; /*!< Audio class class-specific as interface descriptor pointer*/ 562 void *formatTypeDesc; /*!< Audio class class-specific format type descriptor pointer*/ 563 usb_descriptor_endpoint_t *isoEndpDesc; /*!< Audio class class-specific ISO audio data endpoint descriptor pointer*/ 564 usb_host_pipe_handle isoInPipe; /*!< Audio class ISO in pipe*/ 565 usb_host_pipe_handle isoOutPipe; /*!< Audio class ISO out pipe*/ 566 transfer_callback_t inCallbackFn; /*!< Audio class ISO in transfer callback function*/ 567 void *inCallbackParam; /*!< Audio class ISO in transfer callback parameter*/ 568 transfer_callback_t outCallbackFn; /*!< Audio class ISO out transfer callback function*/ 569 void *outCallbackParam; /*!< Audio class ISO out transfer callback function*/ 570 void *headerDesc; /*!< Audio class header descriptor pointer*/ 571 void *itDesc; /*!< Audio class input terminal descriptor pointer*/ 572 void *otDesc; /*!< Audio class output terminal descriptor pointer*/ 573 void *fuDesc; /*!< Audio class feature unit descriptor pointer*/ 574 void *clockSource; /*!< Audio class clock source descriptor pointer*/ 575 usb_host_pipe_handle controlPipe; /*!< Audio class device control pipe*/ 576 transfer_callback_t controlCallbackFn; /*!< Audio control transfer callback function*/ 577 void *controlCallbackParam; /*!< Audio control transfer callback function*/ 578 usb_host_transfer_t *controlTransfer; /*!< On-going control transfer*/ 579 uint16_t inPacketSize; /*!< Audio ISO in maximum packet size*/ 580 uint16_t outPacketSize; /*!< Audio ISO out maximum packet size*/ 581 uint16_t deviceAudioVersion; /*!< device's current Audio version, 16bit to aligned with Spec*/ 582 uint8_t isSetup; /*!< Whether the audio setup transfer is transmitting*/ 583 uint8_t isoEpNum; /*!< Audio stream ISO endpoint number*/ 584 uint8_t streamIfnum; /*!< Audio stream ISO interface number*/ 585 586 } audio_instance_t; 587 588 /******************************************************************************* 589 * API 590 ******************************************************************************/ 591 #ifdef __cplusplus 592 extern "C" { 593 #endif 594 595 /*! 596 * @name USB host audio class APIs 597 * @{ 598 */ 599 600 /*! 601 * @brief Initializes the audio instance. 602 * 603 * This function allocates the resource for the audio instance. 604 * 605 * @param deviceHandle The device handle. 606 * @param classHandlePtr Return class handle. 607 * 608 * @retval kStatus_USB_Success The device is initialized successfully. 609 * @retval kStatus_USB_AllocFail Allocate memory fail. 610 */ 611 extern usb_status_t USB_HostAudioInit(usb_device_handle deviceHandle, usb_host_class_handle *classHandlePtr); 612 613 /*! 614 * @brief Deinitializes the Audio instance. 615 * 616 * This function release the resource for audio instance. 617 * 618 * @param deviceHandle The device handle. 619 * @param classHandle The class handle. 620 * 621 * @retval kStatus_USB_Success The device is deinitialized successfully. 622 */ 623 extern usb_status_t USB_HostAudioDeinit(usb_device_handle deviceHandle, usb_host_class_handle classHandle); 624 625 /*! 626 * @brief Sets the audio class stream interface. 627 * 628 * This function binds the interface with the audio instance. 629 * 630 * @param classHandle The class handle. 631 * @param interfaceHandle The interface handle. 632 * @param alternateSetting The alternate setting value. 633 * @param callbackFn This callback is called after this function completes. 634 * @param callbackParam The first parameter in the callback function. 635 * 636 * @retval kStatus_USB_Success The device is initialized successfully. 637 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 638 * @retval kStatus_USB_Busy There is no idle transfer. 639 * @retval kStatus_USB_Error Send transfer fail. See the USB_HostSendSetup. 640 * @retval kStatus_USB_Busy Callback return status, there is no idle pipe. 641 * @retval kStatus_USB_TransferStall Callback return status, the transfer is stalled by the device. 642 * @retval kStatus_USB_Error Callback return status, open pipe fail. See the USB_HostOpenPipe. 643 */ 644 extern usb_status_t USB_HostAudioStreamSetInterface(usb_host_class_handle classHandle, 645 usb_host_interface_handle interfaceHandle, 646 uint8_t alternateSetting, 647 transfer_callback_t callbackFn, 648 void *callbackParam); 649 650 /*! 651 * @brief Sets the audio class control interface. 652 * 653 * This function binds the interface with the audio instance. 654 * 655 * @param classHandle The class handle. 656 * @param interfaceHandle The interface handle. 657 * @param alternateSetting The alternate setting value. 658 * @param callbackFn This callback is called after this function completes. 659 * @param callbackParam The first parameter in the callback function. 660 * 661 * @retval kStatus_USB_Success The device is initialized successfully. 662 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 663 * @retval kStatus_USB_Busy There is no idle transfer. 664 * @retval kStatus_USB_Error Send transfer fail. See the USB_HostSendSetup. 665 * @retval kStatus_USB_Busy Callback return status, there is no idle pipe. 666 * @retval kStatus_USB_TransferStall Callback return status, the transfer is stalled by the device. 667 * @retval kStatus_USB_Error Callback return status, open pipe fail. See USB_HostOpenPipe. 668 */ 669 extern usb_status_t USB_HostAudioControlSetInterface(usb_host_class_handle classHandle, 670 usb_host_interface_handle interfaceHandle, 671 uint8_t alternateSetting, 672 transfer_callback_t callbackFn, 673 void *callbackParam); 674 675 /*! 676 * @brief Gets the pipe maximum packet size. 677 * 678 * @param classHandle The class handle. 679 * @param pipeType Its value is USB_ENDPOINT_CONTROL, USB_ENDPOINT_ISOCHRONOUS, USB_ENDPOINT_BULK or 680 * USB_ENDPOINT_INTERRUPT. 681 * See the usb_spec.h 682 * @param direction Pipe direction. 683 * 684 * @retval 0 The classHandle is NULL. 685 * @retval max Packet size. 686 */ 687 extern uint16_t USB_HostAudioPacketSize(usb_host_class_handle classHandle, uint8_t pipeType, uint8_t direction); 688 689 /*! 690 * @brief Audio stream receive data. 691 * 692 * This function implements the audio receiving data. 693 * 694 * @param classHandle The class handle. 695 * @param buffer The buffer pointer. 696 * @param bufferLen The buffer length. 697 * @param callbackFn This callback is called after this function completes. 698 * @param callbackParam The first parameter in the callback function. 699 * 700 * @retval kStatus_USB_Success Receive request successfully. 701 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 702 * @retval kStatus_USB_Busy There is no idle transfer. 703 * @retval kStatus_USB_Error Pipe is not initialized. 704 * Or, send transfer fail. See the USB_HostRecv. 705 */ 706 extern usb_status_t USB_HostAudioStreamRecv(usb_host_class_handle classHandle, 707 uint8_t *buffer, 708 uint32_t bufferLen, 709 transfer_callback_t callbackFn, 710 void *callbackParam); 711 712 /*! 713 * @brief Audio stream send data. 714 * 715 * This function implements the audio sending data. 716 * 717 * @param classHandle The class handle. 718 * @param buffer The buffer pointer. 719 * @param bufferLen The buffer length. 720 * @param callbackFn This callback is called after this function completes. 721 * @param callbackParam The first parameter in the callback function. 722 * 723 * @retval kStatus_USB_Success Receive request successfully. 724 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 725 * @retval kStatus_USB_Busy There is no idle transfer. 726 * @retval kStatus_USB_Error pipe is not initialized. 727 * Or, send transfer fail. See the USB_HostSend. 728 */ 729 extern usb_status_t USB_HostAudioStreamSend(usb_host_class_handle classHandle, 730 uint8_t *buffer, 731 uint32_t bufferLen, 732 transfer_callback_t callbackFn, 733 void *callbackParam); 734 735 /*! 736 * @brief Gets the audio stream current altsetting descriptor. 737 * @deprecated Do not use this function. It has been superceded by @ref 738 * USB_HostAudioStreamGetCurrentAltsettingSpecificDescriptors. 739 * 740 * This function implements the get audio stream current altsetting descriptor. 741 * 742 * @param classHandle The class handle. 743 * @param asIntfDesc The pointer of class-specific AS interface descriptor. 744 * @param formatTypeDesc The pointer of format type descriptor. 745 * @param isoEndpDesc The pointer of specific ISO endp descriptor. 746 * 747 * @retval kStatus_USB_Success Get the audio stream current altsetting descriptor request successfully. 748 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 749 * 750 */ 751 extern usb_status_t USB_HostAudioStreamGetCurrentAltsettingDescriptors( 752 usb_host_class_handle classHandle, 753 usb_audio_stream_spepific_as_intf_desc_t **asIntfDesc, 754 usb_audio_stream_format_type_desc_t **formatTypeDesc, 755 usb_descriptor_endpoint_t **isoEndpDesc); 756 757 /*! 758 * @brief The USB audio feature unit request. 759 * @deprecated Do not use this function. It has been superceded by @ref USB_HostAudioGetSetFeatureUnitRequest. 760 * 761 * This function implements the USB audio feature unit request. 762 * 763 * @param classHandle The class handle. 764 * @param channelNo The channel number of audio feature unit. 765 * @param buf The feature unit request buffer pointer. 766 * @param cmdCode The feature unit command code, for example USB_AUDIO_GET_CUR_MUTE, and so on. 767 * @param callbackFn This callback is called after this function completes. 768 * @param callbackParam The first parameter in the callback function. 769 * 770 * @retval kStatus_USB_Success Feature unit request successfully. 771 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 772 * @retval kStatus_USB_Busy There is no idle transfer. 773 * @retval kStatus_USB_Error Send transfer fail. See the USB_HostSendSetup. 774 * 775 */ 776 extern usb_status_t USB_HostAudioFeatureUnitRequest(usb_host_class_handle classHandle, 777 uint8_t channelNo, 778 void *buf, 779 uint32_t cmdCode, 780 transfer_callback_t callbackFn, 781 void *callbackParam); 782 783 /*! 784 * @brief The USB audio endpoint request. 785 * @deprecated Do not use this function. It has been superceded by @ref USB_HostAudioGetSetEndpointRequest. 786 787 * 788 * This function implements the USB audio endpoint request. 789 * 790 * @param classHandle The class handle. 791 * @param buf The feature unit buffer pointer. 792 * @param cmdCode The feature unit command code, for example USB_AUDIO_GET_CUR_PITCH, and so on. 793 * @param callbackFn This callback is called after this function completes. 794 * @param callbackParam The first parameter in the callback function. 795 * 796 * @retval kStatus_USB_Success Endpoint request successfully. 797 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 798 * @retval kStatus_USB_Busy There is no idle transfer. 799 * @retval kStatus_USB_Error Send transfer fail. See the USB_HostSendSetup. 800 * 801 */ 802 extern usb_status_t USB_HostAudioEndpointRequest(usb_host_class_handle classHandle, 803 void *buf, 804 uint32_t cmdCode, 805 transfer_callback_t callbackFn, 806 void *callbackParam); 807 /*! 808 * @brief get audio control current altsetting descriptor. 809 * 810 * This function implements get audio stream current altsetting descriptor. 811 * 812 * @param classHandle The class handle. 813 * @param DescriptorType The descriptor type. 814 * @param DescriptorSubType The descriptor subtype, 0 for no subtype, for standard endpoint , 0 stand for data 815 * endpoint. 816 * @param Descriptor The pointer of descriptor pointer. 817 * 818 * @retval kStatus_USB_Success Get audio stream current altsetting descriptor request successfully. 819 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 820 * 821 */ 822 usb_status_t USB_HostAudioControlGetCurrentAltsettingSpecificDescriptors( 823 824 usb_host_class_handle classHandle, uint32_t DescriptorType, uint32_t DescriptorSubType, void **Descriptor); 825 826 /*! 827 * @brief get audio control current altsetting descriptor. 828 * 829 * This function implements get audio stream current altsetting descriptor. 830 * 831 * @param classHandle The class handle. 832 * @param DescriptorType The descriptor type. 833 * @param DescriptorSubType The descriptor subtype, 0 for no subtype. 834 * @param Descriptor The pointer of descriptor pointer. 835 * 836 * @retval kStatus_USB_Success Get audio stream current altsetting descriptor request successfully. 837 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 838 * 839 */ 840 usb_status_t USB_HostAudioStreamGetCurrentAltsettingSpecificDescriptors( 841 842 usb_host_class_handle classHandle, uint32_t DescriptorType, uint32_t DescriptorSubType, void **Descriptor); 843 /*! 844 * @brief usb audio set/get feature unit request. 845 * 846 * This function implements usb audio feature unit request. 847 * 848 * @param classHandle The class handle. 849 * @param csAndCn The CS and CN or MCN for wValue field in setup Request. 850 * @param cmdCode The bRequest code in lower 8bit of lower word and get feature(1)/set feature(0) flag in 851 * higher 8bit of lower word. 852 * @param buf The feature unit request buffer pointer. 853 * @param callbackFn This callback is called after this function completes. 854 * @param callbackParam The first parameter in the callback function. 855 * 856 * @retval kStatus_USB_Success Feature unit request successfully. 857 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 858 * @retval kStatus_USB_Busy There is no idle transfer. 859 * @retval kStatus_USB_Error Send transfer fail, please reference to USB_HostSendSetup. 860 * 861 */ 862 usb_status_t USB_HostAudioGetSetFeatureUnitRequest(usb_host_class_handle classHandle, 863 uint32_t csAndCn, 864 uint32_t cmdCode, 865 void *buf, 866 uint32_t bufLen, 867 transfer_callback_t callbackFn, 868 void *callbackParam); 869 870 /*! 871 * @brief usb audio set/get feature unit request. 872 * 873 * This function implements usb audio feature unit request. 874 * 875 * @param classHandle The class handle. 876 * @param csAndCn The CS and CN or MCN for wValue field in setup Request. 877 * @param cmdCode The bRequest code in lower 8bit of lower word and get clock(1)/set clock(0) flag in higher 878 * 8bit of lower word. 879 * @param buf The feature unit request buffer pointer. 880 * @param callbackFn This callback is called after this function completes. 881 * @param callbackParam The first parameter in the callback function. 882 * 883 * @retval kStatus_USB_Success Feature unit request successfully. 884 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 885 * @retval kStatus_USB_Busy There is no idle transfer. 886 * @retval kStatus_USB_Error Send transfer fail, please reference to USB_HostSendSetup. 887 * 888 */ 889 usb_status_t USB_HostAudioGetSetClockSourceRequest(usb_host_class_handle classHandle, 890 uint32_t csAndCn, 891 uint32_t cmdCode, 892 void *buf, 893 uint32_t bufLen, 894 transfer_callback_t callbackFn, 895 void *callbackParam); 896 /*! 897 * @brief usb audio set/get endp unit request. 898 * 899 * This function implements usb audio feature unit request. 900 * 901 * @param classHandle The class handle. 902 * @param csAndCn The CS for wValue field in setup Request. 903 * @param cmdCode The bRequest code in lower 8bit of lower word and get(1)/set(0) flag in higher 8bit of lower 904 word. 905 * @param buf The feature unit request buffer pointer. 906 907 * @param callbackFn This callback is called after this function completes. 908 * @param callbackParam The first parameter in the callback function. 909 * 910 * @retval kStatus_USB_Success Feature unit request successfully. 911 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 912 * @retval kStatus_USB_Busy There is no idle transfer. 913 * @retval kStatus_USB_Error Send transfer fail, please reference to USB_HostSendSetup. 914 * 915 */ 916 usb_status_t USB_HostAudioGetSetEndpointRequest(usb_host_class_handle classHandle, 917 uint32_t csAndCn, 918 uint32_t cmdCode, 919 void *buf, 920 uint32_t bufLen, 921 transfer_callback_t callbackFn, 922 void *callbackParam); 923 924 /*! 925 * @brief change the ISO out data interval 926 * 927 * when the low interval can satisfy the device's data bandwidth requirement, the interval can be increased to decrease 928 * the MCU loading. for example: the audio speaker device is 48K/2channels/2Bytes and the original interval is 125us, 929 * mps is 256Bytes. If using the 125us interval, the USB interrupt will trigger every 125us, it need much MCU loading 930 * (in FreeRTOS environment especially because there is task switch time). 931 * Change the interval as 1ms, it sill can satisfy the device's data bandwidth requirement as follow: 932 * the data lenght is 48 * 2 * 2 = 192Bytes every ms, and the 256Bytes (mps) is bigger than 192Bytes, so 933 * the inteval can be changed to 1ms. Then host sends 192Bytes in one micro-frame of the 8 micro-frames (1ms), and there 934 * are no data transfers in the other 7 micro-frames. 935 * 936 * @param classHandle The class handle. 937 * @param intervalValue The new interval value according to the interval descriptor. 938 * 939 * @retval kStatus_USB_Success the change request successfully. 940 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 941 * @retval kStatus_USB_Busy There is no idle transfer. 942 * @retval kStatus_USB_Error Send transfer fail, please reference to USB_HostSendSetup. 943 * 944 */ 945 usb_status_t USB_HostAudioSetStreamOutDataInterval(usb_host_class_handle classHandle, uint8_t intervalValue); 946 947 /*! @}*/ 948 #ifdef __cplusplus 949 } 950 #endif 951 /*! @}*/ 952 #endif /* __USB_HOST_AUDIO_H__ */ 953