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 /*! @brief Audio as isochronous audio data endpoint descriptor structure */ 379 typedef struct _usb_audio_2_0_stream_specific_iso_endp_desc 380 { 381 uint8_t blength; /*!< Total size of the descriptor*/ 382 uint8_t bdescriptortype; /*!< Descriptor type of the descriptor*/ 383 uint8_t bdescriptorsubtype; /*!< Subtype of the descriptor*/ 384 uint8_t bmattributes; /*!< A bit in the range D6..0 set to 1 indicates that the mentioned Control is supported by 385 this endpoint*/ 386 uint8_t bmControls; /*!< D1..0: Pitch Control 387 D3..2: Data Overrun Control 388 D5..4: Data Underrun Control 389 D7..6: Reserved. Must be set to 0. */ 390 uint8_t blockdlayunits; /*!< Indicates the units used for the wLockDelay field*/ 391 uint8_t wlockdelay[2]; /*!< Indicates the time it takes this endpoint to reliably lock its internal clock recovery 392 circuitry. Units used depend on the value of the bLockDelayUnits field.*/ 393 } usb_audio_2_0_stream_specific_iso_endp_desc_t; 394 395 typedef struct _usb_audio_ctrl_common_header_desc 396 { 397 uint8_t blength; /*!< Total size of the header descriptor*/ 398 uint8_t bdescriptortype; /*!< Descriptor type of audio header descriptor*/ 399 uint8_t bdescriptorsubtype; /*!< Subtype of an audio header descriptor*/ 400 uint8_t bcdcdc[2]; /*!< Audio Device Class Specification Release Number in Binary-Coded Decimal*/ 401 } usb_audio_ctrl_common_header_desc_t; 402 /*! @brief Audio control interface header descriptor structure */ 403 typedef struct _usb_audio_ctrl_header_desc 404 { 405 uint8_t blength; /*!< Total size of the header descriptor*/ 406 uint8_t bdescriptortype; /*!< Descriptor type of audio header descriptor*/ 407 uint8_t bdescriptorsubtype; /*!< Subtype of an audio header descriptor*/ 408 uint8_t bcdcdc[2]; /*!< Audio Device Class Specification Release Number in Binary-Coded Decimal*/ 409 uint8_t wtotallength[2]; /*!< Total number of bytes returned for the class-specific AudioControl interface 410 descriptor. Includes the combined length of this descriptor header and all unit and 411 terminal descriptors.*/ 412 uint8_t bincollection; /*!< The number of AudioStreaming and MIDIStreaming interfaces in the Audio Interface 413 Collection to which this AudioControl interface belongs to*/ 414 } usb_audio_ctrl_header_desc_t; 415 416 /*! @brief Audio control interface input terminal descriptor structure */ 417 typedef struct _usb_audio_ctrl_it_desc 418 { 419 uint8_t blength; /*!< Total size of the input terminal descriptor*/ 420 uint8_t bdescriptortype; /*!< Descriptor type of audio input terminal descriptor*/ 421 uint8_t bdescriptorsubtype; /*!< Subtype of audio input terminal descriptor*/ 422 uint8_t bterminalid; /*!< Constant uniquely identifying the Terminal within the audio function. This value is used 423 in all requests to address this Terminal*/ 424 uint8_t wterminaltype[2]; /*!< Constant characterizing the type of Terminal*/ 425 uint8_t bassocterminal; /*!< ID of the Output Terminal to which this Input Terminal is associated*/ 426 uint8_t bnrchannels; /*!< Number of logical output channels in the Terminal's output audio channel cluster*/ 427 uint8_t wchannelconfig[2]; /*!< Describes the spatial location of the logical channels.*/ 428 uint8_t ichannelnames; /*!< Index of a string descriptor, describing the name of the first logical channel*/ 429 uint8_t iterminal; /*!<Index of a string descriptor, describing the Input Terminal*/ 430 } usb_audio_ctrl_it_desc_t; 431 432 /*! @brief Audio control interface output terminal descriptor structure */ 433 typedef struct _usb_audio_ctrl_ot_desc 434 { 435 uint8_t blength; /*!< Total size of the output terminal descriptor*/ 436 uint8_t bdescriptortype; /*!< Descriptor type of audio output terminal descriptor*/ 437 uint8_t bdescriptorsubtype; /*!< Subtype of audio output terminal descriptor*/ 438 uint8_t bterminalid; /*!< Constant uniquely identifying the Terminal within the audio function. This value is used 439 in all requests to address this Terminal*/ 440 uint8_t wterminaltype[2]; /*!< Constant characterizing the type of Terminal*/ 441 uint8_t bassocterminal; /*!< Constant, identifying the Input Terminal to which this Output Terminal is associated*/ 442 uint8_t bsourceid; /*!< ID of the Unit or Terminal to which this Terminal is connected*/ 443 uint8_t iterminal; /*!< Index of a string descriptor, describing the Output Terminal*/ 444 } usb_audio_ctrl_ot_desc_t; 445 446 /*! @brief Audio control interface feature unit descriptor structure */ 447 typedef struct _usb_audio_ctrl_fu_desc 448 { 449 uint8_t blength; /*!< Total size of the output terminal descriptor*/ 450 uint8_t bdescriptortype; /*!< Descriptor type of audio output terminal descriptor*/ 451 uint8_t bdescriptorsubtype; /*!< Subtype of audio output terminal descriptor*/ 452 uint8_t bunitid; /*!< Constant uniquely identifying the unit within the audio function. This value is used in all 453 requests to address this unit*/ 454 uint8_t bsourceid; /*!< ID of the Unit or Terminal to which this Feature Unit is connected*/ 455 uint8_t bcontrolsize; /*!< Size in bytes of an element of the bmaControls*/ 456 } usb_audio_ctrl_fu_desc_t; 457 458 /*! @brief Audio as isochronous audio data endpoint descriptor structure */ 459 typedef struct _usb_audio_stream_specific_iso_endp_desc 460 { 461 uint8_t blength; /*!< Total size of the descriptor*/ 462 uint8_t bdescriptortype; /*!< Descriptor type of the descriptor*/ 463 uint8_t bdescriptorsubtype; /*!< Subtype of the descriptor*/ 464 uint8_t bmattributes; /*!< A bit in the range D6..0 set to 1 indicates that the mentioned Control is supported by 465 this endpoint*/ 466 uint8_t blockdlayunits; /*!< Indicates the units used for the wLockDelay field*/ 467 uint8_t wlockdelay[2]; /*!< Indicates the time it takes this endpoint to reliably lock its internal clock recovery 468 circuitry. Units used depend on the value of the bLockDelayUnits field.*/ 469 } usb_audio_stream_specific_iso_endp_desc_t; 470 471 /*! @brief Audio standard as isochronous synch endpoint descriptor structure */ 472 typedef struct _usb_audio_stream_synch_endp_desc 473 { 474 uint8_t blength; /*!< Total size of the descriptor*/ 475 uint8_t bdescriptortype; /*!< Descriptor type of the endpoint descriptor*/ 476 uint8_t bendpointaddress; /*!< The address of the endpoint on the USB device described by this descriptor*/ 477 uint8_t bmattributes; /*!< D3..2: Synchronization type, D1..0: Transfer type*/ 478 uint8_t wmaxpacketsize[2]; /*!< Maximum packet size this endpoint is capable of sending or receiving when this 479 configuration is selected*/ 480 uint8_t binterval; /*!< Interval for polling endpoint for data transfers expressed in milliseconds*/ 481 uint8_t brefresh; /*!< This field indicates the rate at which an isochronous synchronization pipe provides new 482 synchronization feedback data*/ 483 uint8_t bsynchaddress; /*!< Must be reset to zero*/ 484 } usb_audio_stream_synch_endp_desc_t; 485 486 /*! @brief Audio class-specific as interface descriptor structure */ 487 typedef struct _usb_audio_stream_spepific_as_intf_desc 488 { 489 uint8_t blength; /*!< Total size of the descriptor*/ 490 uint8_t bdescriptortype; /*!< Descriptor type of the descriptor*/ 491 uint8_t bdescriptorsubtype; /*!< Subtype of the descriptor*/ 492 uint8_t bterminallink; /*!< The Terminal ID of the Terminal to which the endpoint of this interface is connected*/ 493 uint8_t bdelay; /*!< Expressed in number of frames*/ 494 uint8_t wformattag[2]; /*!< The Audio Data Format that has to be used to communicate with this interface*/ 495 } usb_audio_stream_spepific_as_intf_desc_t; 496 497 /*! @brief Audio class-specific as interface descriptor structure */ 498 typedef struct _usb_audio_2_0_stream_spepific_as_intf_desc 499 { 500 uint8_t blength; /*!< Total size of the descriptor*/ 501 uint8_t bdescriptortype; /*!< Descriptor type of the descriptor*/ 502 uint8_t bdescriptorsubtype; /*!< Subtype of the descriptor*/ 503 uint8_t bterminallink; /*!< The Terminal ID of the Terminal to which the endpoint of this interface is connected*/ 504 uint8_t bmControls; /*!< D1..0: Active Alternate Setting Control 505 D3..2: Valid Alternate Settings Control 506 D7..4: Reserved. Must be set to 0.*/ 507 uint8_t bFormatType; /*!< Constant identifying the Format Type the AudioStreaming interface is using.*/ 508 uint8_t bmFormats[4]; /*!< The Audio Data Format(s) that can be used to communicate with this interface. See the USB 509 Audio Data Formats document for further details*/ 510 uint8_t bNrChannels; /*!< Number of physical channels in the AS Interface audio channel cluster.*/ 511 uint8_t bmChannelConfig[4]; /*!< Describes the spatial location of the physical channels.*/ 512 uint8_t biChannelNames; /*!< Index of a string descriptor, describing the name of the first physical channel.*/ 513 } usb_audio_2_0_stream_spepific_as_intf_desc_t; 514 515 /* Format type descriptor */ 516 /*! @brief audio Format type descriptor structure */ 517 typedef struct _usb_audio_stream_format_type_desc 518 { 519 uint8_t blength; /*!< Total size of the descriptor*/ 520 uint8_t bdescriptortype; /*!< Descriptor type of the descriptor*/ 521 uint8_t bdescriptorsubtype; /*!< Subtype of the descriptor*/ 522 uint8_t bformattype; /*!< Constant identifying the Format Type the AudioStreaming interface is using*/ 523 uint8_t bnrchannels; /*!< Number of channels of device*/ 524 uint8_t bsubframesize; /*!< Bytes per audio subframe*/ 525 uint8_t bbitresolution; /*!< Bits per sample*/ 526 uint8_t bsamfreqtype; /*!< Frequency supported*/ 527 uint8_t tsamfreq[1][3]; /*!< Sample frequency*/ 528 } usb_audio_stream_format_type_desc_t; 529 530 /*! @brief audio Format type descriptor structure */ 531 typedef struct _usb_audio_2_0_stream_format_type_desc 532 { 533 uint8_t blength; /*!< Total size of the descriptor*/ 534 uint8_t bdescriptortype; /*!< Descriptor type of the descriptor*/ 535 uint8_t bdescriptorsubtype; /*!< Subtype of the descriptor*/ 536 uint8_t bformattype; /*!< Constant identifying the Format Type the AudioStreaming interface is using*/ 537 uint8_t bSubslotSize; /*!< The number of bytes occupied by one audio subslot. Can be 1, 2, 3 or 4.*/ 538 uint8_t bBitResolution; /*!< The number of effectively used bits from the available bits in an audio subslot*/ 539 } usb_audio_2_0_stream_format_type_desc_t; 540 541 /*! @brief Audio instance structure and audio usb_host_class_handle pointer to this structure */ 542 typedef struct _audio_instance 543 { 544 usb_host_handle hostHandle; /*!< This instance's related host handle*/ 545 usb_device_handle deviceHandle; /*!< This instance's related device handle*/ 546 usb_host_interface_handle streamIntfHandle; /*!< This instance's audio stream interface handle*/ 547 usb_host_interface_handle controlIntfHandle; /*!< This instance's control stream interface handle*/ 548 void *asIntfDesc; /*!< Audio class class-specific as interface descriptor pointer*/ 549 void *formatTypeDesc; /*!< Audio class class-specific format type descriptor pointer*/ 550 usb_descriptor_endpoint_t *isoEndpDesc; /*!< Audio class class-specific ISO audio data endpoint descriptor pointer*/ 551 usb_host_pipe_handle isoInPipe; /*!< Audio class ISO in pipe*/ 552 usb_host_pipe_handle isoOutPipe; /*!< Audio class ISO out pipe*/ 553 transfer_callback_t inCallbackFn; /*!< Audio class ISO in transfer callback function*/ 554 void *inCallbackParam; /*!< Audio class ISO in transfer callback parameter*/ 555 transfer_callback_t outCallbackFn; /*!< Audio class ISO out transfer callback function*/ 556 void *outCallbackParam; /*!< Audio class ISO out transfer callback function*/ 557 void *headerDesc; /*!< Audio class header descriptor pointer*/ 558 void *itDesc; /*!< Audio class input terminal descriptor pointer*/ 559 void *otDesc; /*!< Audio class output terminal descriptor pointer*/ 560 void *fuDesc; /*!< Audio class feature unit descriptor pointer*/ 561 void *clockSource; /*!< Audio class clock source descriptor pointer*/ 562 usb_host_pipe_handle controlPipe; /*!< Audio class device control pipe*/ 563 transfer_callback_t controlCallbackFn; /*!< Audio control transfer callback function*/ 564 void *controlCallbackParam; /*!< Audio control transfer callback function*/ 565 usb_host_transfer_t *controlTransfer; /*!< On-going control transfer*/ 566 uint16_t inPacketSize; /*!< Audio ISO in maximum packet size*/ 567 uint16_t outPacketSize; /*!< Audio ISO out maximum packet size*/ 568 uint16_t deviceAudioVersion; /*!< device's current Audio version, 16bit to aligned with Spec*/ 569 uint8_t isSetup; /*!< Whether the audio setup transfer is transmitting*/ 570 uint8_t isoEpNum; /*!< Audio stream ISO endpoint number*/ 571 uint8_t streamIfnum; /*!< Audio stream ISO interface number*/ 572 573 } audio_instance_t; 574 575 /******************************************************************************* 576 * API 577 ******************************************************************************/ 578 #ifdef __cplusplus 579 extern "C" { 580 #endif 581 582 /*! 583 * @name USB host audio class APIs 584 * @{ 585 */ 586 587 /*! 588 * @brief Initializes the audio instance. 589 * 590 * This function allocates the resource for the audio instance. 591 * 592 * @param deviceHandle The device handle. 593 * @param classHandlePtr Return class handle. 594 * 595 * @retval kStatus_USB_Success The device is initialized successfully. 596 * @retval kStatus_USB_AllocFail Allocate memory fail. 597 */ 598 extern usb_status_t USB_HostAudioInit(usb_device_handle deviceHandle, usb_host_class_handle *classHandlePtr); 599 600 /*! 601 * @brief Deinitializes the Audio instance. 602 * 603 * This function release the resource for audio instance. 604 * 605 * @param deviceHandle The device handle. 606 * @param classHandle The class handle. 607 * 608 * @retval kStatus_USB_Success The device is deinitialized successfully. 609 */ 610 extern usb_status_t USB_HostAudioDeinit(usb_device_handle deviceHandle, usb_host_class_handle classHandle); 611 612 /*! 613 * @brief Sets the audio class stream interface. 614 * 615 * This function binds the interface with the audio instance. 616 * 617 * @param classHandle The class handle. 618 * @param interfaceHandle The interface handle. 619 * @param alternateSetting The alternate setting value. 620 * @param callbackFn This callback is called after this function completes. 621 * @param callbackParam The first parameter in the callback function. 622 * 623 * @retval kStatus_USB_Success The device is initialized successfully. 624 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 625 * @retval kStatus_USB_Busy There is no idle transfer. 626 * @retval kStatus_USB_Error Send transfer fail. See the USB_HostSendSetup. 627 * @retval kStatus_USB_Busy Callback return status, there is no idle pipe. 628 * @retval kStatus_USB_TransferStall Callback return status, the transfer is stalled by the device. 629 * @retval kStatus_USB_Error Callback return status, open pipe fail. See the USB_HostOpenPipe. 630 */ 631 extern usb_status_t USB_HostAudioStreamSetInterface(usb_host_class_handle classHandle, 632 usb_host_interface_handle interfaceHandle, 633 uint8_t alternateSetting, 634 transfer_callback_t callbackFn, 635 void *callbackParam); 636 637 /*! 638 * @brief Sets the audio class control interface. 639 * 640 * This function binds the interface with the audio instance. 641 * 642 * @param classHandle The class handle. 643 * @param interfaceHandle The interface handle. 644 * @param alternateSetting The alternate setting value. 645 * @param callbackFn This callback is called after this function completes. 646 * @param callbackParam The first parameter in the callback function. 647 * 648 * @retval kStatus_USB_Success The device is initialized successfully. 649 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 650 * @retval kStatus_USB_Busy There is no idle transfer. 651 * @retval kStatus_USB_Error Send transfer fail. See the USB_HostSendSetup. 652 * @retval kStatus_USB_Busy Callback return status, there is no idle pipe. 653 * @retval kStatus_USB_TransferStall Callback return status, the transfer is stalled by the device. 654 * @retval kStatus_USB_Error Callback return status, open pipe fail. See USB_HostOpenPipe. 655 */ 656 extern usb_status_t USB_HostAudioControlSetInterface(usb_host_class_handle classHandle, 657 usb_host_interface_handle interfaceHandle, 658 uint8_t alternateSetting, 659 transfer_callback_t callbackFn, 660 void *callbackParam); 661 662 /*! 663 * @brief Gets the pipe maximum packet size. 664 * 665 * @param classHandle The class handle. 666 * @param pipeType Its value is USB_ENDPOINT_CONTROL, USB_ENDPOINT_ISOCHRONOUS, USB_ENDPOINT_BULK or 667 * USB_ENDPOINT_INTERRUPT. 668 * See the usb_spec.h 669 * @param direction Pipe direction. 670 * 671 * @retval 0 The classHandle is NULL. 672 * @retval max Packet size. 673 */ 674 extern uint16_t USB_HostAudioPacketSize(usb_host_class_handle classHandle, uint8_t pipeType, uint8_t direction); 675 676 /*! 677 * @brief Audio stream receive data. 678 * 679 * This function implements the audio receiving data. 680 * 681 * @param classHandle The class handle. 682 * @param buffer The buffer pointer. 683 * @param bufferLen The buffer length. 684 * @param callbackFn This callback is called after this function completes. 685 * @param callbackParam The first parameter in the callback function. 686 * 687 * @retval kStatus_USB_Success Receive request successfully. 688 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 689 * @retval kStatus_USB_Busy There is no idle transfer. 690 * @retval kStatus_USB_Error Pipe is not initialized. 691 * Or, send transfer fail. See the USB_HostRecv. 692 */ 693 extern usb_status_t USB_HostAudioStreamRecv(usb_host_class_handle classHandle, 694 uint8_t *buffer, 695 uint32_t bufferLen, 696 transfer_callback_t callbackFn, 697 void *callbackParam); 698 699 /*! 700 * @brief Audio stream send data. 701 * 702 * This function implements the audio sending data. 703 * 704 * @param classHandle The class handle. 705 * @param buffer The buffer pointer. 706 * @param bufferLen The buffer length. 707 * @param callbackFn This callback is called after this function completes. 708 * @param callbackParam The first parameter in the callback function. 709 * 710 * @retval kStatus_USB_Success Receive request successfully. 711 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 712 * @retval kStatus_USB_Busy There is no idle transfer. 713 * @retval kStatus_USB_Error pipe is not initialized. 714 * Or, send transfer fail. See the USB_HostSend. 715 */ 716 extern usb_status_t USB_HostAudioStreamSend(usb_host_class_handle classHandle, 717 uint8_t *buffer, 718 uint32_t bufferLen, 719 transfer_callback_t callbackFn, 720 void *callbackParam); 721 722 /*! 723 * @brief Gets the audio stream current altsetting descriptor. 724 * @deprecated Do not use this function. It has been superceded by @ref 725 * USB_HostAudioStreamGetCurrentAltsettingSpecificDescriptors. 726 * 727 * This function implements the get audio stream current altsetting descriptor. 728 * 729 * @param classHandle The class handle. 730 * @param asIntfDesc The pointer of class-specific AS interface descriptor. 731 * @param formatTypeDesc The pointer of format type descriptor. 732 * @param isoEndpDesc The pointer of specific ISO endp descriptor. 733 * 734 * @retval kStatus_USB_Success Get the audio stream current altsetting descriptor request successfully. 735 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 736 * 737 */ 738 extern usb_status_t USB_HostAudioStreamGetCurrentAltsettingDescriptors( 739 usb_host_class_handle classHandle, 740 usb_audio_stream_spepific_as_intf_desc_t **asIntfDesc, 741 usb_audio_stream_format_type_desc_t **formatTypeDesc, 742 usb_descriptor_endpoint_t **isoEndpDesc); 743 744 /*! 745 * @brief The USB audio feature unit request. 746 * @deprecated Do not use this function. It has been superceded by @ref USB_HostAudioGetSetFeatureUnitRequest. 747 * 748 * This function implements the USB audio feature unit request. 749 * 750 * @param classHandle The class handle. 751 * @param channelNo The channel number of audio feature unit. 752 * @param buf The feature unit request buffer pointer. 753 * @param cmdCode The feature unit command code, for example USB_AUDIO_GET_CUR_MUTE, and so on. 754 * @param callbackFn This callback is called after this function completes. 755 * @param callbackParam The first parameter in the callback function. 756 * 757 * @retval kStatus_USB_Success Feature unit request successfully. 758 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 759 * @retval kStatus_USB_Busy There is no idle transfer. 760 * @retval kStatus_USB_Error Send transfer fail. See the USB_HostSendSetup. 761 * 762 */ 763 extern usb_status_t USB_HostAudioFeatureUnitRequest(usb_host_class_handle classHandle, 764 uint8_t channelNo, 765 void *buf, 766 uint32_t cmdCode, 767 transfer_callback_t callbackFn, 768 void *callbackParam); 769 770 /*! 771 * @brief The USB audio endpoint request. 772 * @deprecated Do not use this function. It has been superceded by @ref USB_HostAudioGetSetEndpointRequest. 773 774 * 775 * This function implements the USB audio endpoint request. 776 * 777 * @param classHandle The class handle. 778 * @param buf The feature unit buffer pointer. 779 * @param cmdCode The feature unit command code, for example USB_AUDIO_GET_CUR_PITCH, and so on. 780 * @param callbackFn This callback is called after this function completes. 781 * @param callbackParam The first parameter in the callback function. 782 * 783 * @retval kStatus_USB_Success Endpoint request successfully. 784 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 785 * @retval kStatus_USB_Busy There is no idle transfer. 786 * @retval kStatus_USB_Error Send transfer fail. See the USB_HostSendSetup. 787 * 788 */ 789 extern usb_status_t USB_HostAudioEndpointRequest(usb_host_class_handle classHandle, 790 void *buf, 791 uint32_t cmdCode, 792 transfer_callback_t callbackFn, 793 void *callbackParam); 794 /*! 795 * @brief get audio control current altsetting descriptor. 796 * 797 * This function implements get audio stream current altsetting descriptor. 798 * 799 * @param classHandle The class handle. 800 * @param DescriptorType The descriptor type. 801 * @param DescriptorSubType The descriptor subtype, 0 for no subtype, for standard endpoint , 0 stand for data 802 * endpoint. 803 * @param Descriptor The pointer of descriptor pointer. 804 * 805 * @retval kStatus_USB_Success Get audio stream current altsetting descriptor request successfully. 806 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 807 * 808 */ 809 usb_status_t USB_HostAudioControlGetCurrentAltsettingSpecificDescriptors( 810 811 usb_host_class_handle classHandle, uint32_t DescriptorType, uint32_t DescriptorSubType, void **Descriptor); 812 813 /*! 814 * @brief get audio control current altsetting descriptor. 815 * 816 * This function implements get audio stream current altsetting descriptor. 817 * 818 * @param classHandle The class handle. 819 * @param DescriptorType The descriptor type. 820 * @param DescriptorSubType The descriptor subtype, 0 for no subtype. 821 * @param Descriptor The pointer of descriptor pointer. 822 * 823 * @retval kStatus_USB_Success Get audio stream current altsetting descriptor request successfully. 824 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 825 * 826 */ 827 usb_status_t USB_HostAudioStreamGetCurrentAltsettingSpecificDescriptors( 828 829 usb_host_class_handle classHandle, uint32_t DescriptorType, uint32_t DescriptorSubType, void **Descriptor); 830 /*! 831 * @brief usb audio set/get feature unit request. 832 * 833 * This function implements usb audio feature unit request. 834 * 835 * @param classHandle The class handle. 836 * @param csAndCn The CS and CN or MCN for wValue field in setup Request. 837 * @param cmdCode The bRequest code in lower 8bit of lower word and get feature(1)/set feature(0) flag in 838 * higher 8bit of lower word. 839 * @param buf The feature unit request buffer pointer. 840 * @param callbackFn This callback is called after this function completes. 841 * @param callbackParam The first parameter in the callback function. 842 * 843 * @retval kStatus_USB_Success Feature unit request successfully. 844 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 845 * @retval kStatus_USB_Busy There is no idle transfer. 846 * @retval kStatus_USB_Error Send transfer fail, please reference to USB_HostSendSetup. 847 * 848 */ 849 usb_status_t USB_HostAudioGetSetFeatureUnitRequest(usb_host_class_handle classHandle, 850 uint32_t csAndCn, 851 uint32_t cmdCode, 852 void *buf, 853 uint32_t bufLen, 854 transfer_callback_t callbackFn, 855 void *callbackParam); 856 857 /*! 858 * @brief usb audio set/get feature unit request. 859 * 860 * This function implements usb audio feature unit request. 861 * 862 * @param classHandle The class handle. 863 * @param csAndCn The CS and CN or MCN for wValue field in setup Request. 864 * @param cmdCode The bRequest code in lower 8bit of lower word and get clock(1)/set clock(0) flag in higher 865 * 8bit of lower word. 866 * @param buf The feature unit request buffer pointer. 867 * @param callbackFn This callback is called after this function completes. 868 * @param callbackParam The first parameter in the callback function. 869 * 870 * @retval kStatus_USB_Success Feature unit request successfully. 871 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 872 * @retval kStatus_USB_Busy There is no idle transfer. 873 * @retval kStatus_USB_Error Send transfer fail, please reference to USB_HostSendSetup. 874 * 875 */ 876 usb_status_t USB_HostAudioGetSetClockSourceRequest(usb_host_class_handle classHandle, 877 uint32_t csAndCn, 878 uint32_t cmdCode, 879 void *buf, 880 uint32_t bufLen, 881 transfer_callback_t callbackFn, 882 void *callbackParam); 883 /*! 884 * @brief usb audio set/get endp unit request. 885 * 886 * This function implements usb audio feature unit request. 887 * 888 * @param classHandle The class handle. 889 * @param csAndCn The CS for wValue field in setup Request. 890 * @param cmdCode The bRequest code in lower 8bit of lower word and get(1)/set(0) flag in higher 8bit of lower 891 word. 892 * @param buf The feature unit request buffer pointer. 893 894 * @param callbackFn This callback is called after this function completes. 895 * @param callbackParam The first parameter in the callback function. 896 * 897 * @retval kStatus_USB_Success Feature unit request successfully. 898 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 899 * @retval kStatus_USB_Busy There is no idle transfer. 900 * @retval kStatus_USB_Error Send transfer fail, please reference to USB_HostSendSetup. 901 * 902 */ 903 usb_status_t USB_HostAudioGetSetEndpointRequest(usb_host_class_handle classHandle, 904 uint32_t csAndCn, 905 uint32_t cmdCode, 906 void *buf, 907 uint32_t bufLen, 908 transfer_callback_t callbackFn, 909 void *callbackParam); 910 911 /*! 912 * @brief change the ISO out data interval 913 * 914 * when the low interval can satisfy the device's data bandwidth requirement, the interval can be increased to decrease 915 * the MCU loading. for example: the audio speaker device is 48K/2channels/2Bytes and the original interval is 125us, 916 * mps is 256Bytes. If using the 125us interval, the USB interrupt will trigger every 125us, it need much MCU loading 917 * (in FreeRTOS environment especially because there is task switch time). 918 * Change the interval as 1ms, it sill can satisfy the device's data bandwidth requirement as follow: 919 * the data lenght is 48 * 2 * 2 = 192Bytes every ms, and the 256Bytes (mps) is bigger than 192Bytes, so 920 * the inteval can be changed to 1ms. Then host sends 192Bytes in one micro-frame of the 8 micro-frames (1ms), and there 921 * are no data transfers in the other 7 micro-frames. 922 * 923 * @param classHandle The class handle. 924 * @param intervalValue The new interval value according to the interval descriptor. 925 * 926 * @retval kStatus_USB_Success the change request successfully. 927 * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. 928 * @retval kStatus_USB_Busy There is no idle transfer. 929 * @retval kStatus_USB_Error Send transfer fail, please reference to USB_HostSendSetup. 930 * 931 */ 932 usb_status_t USB_HostAudioSetStreamOutDataInterval(usb_host_class_handle classHandle, uint8_t intervalValue); 933 934 /*! @}*/ 935 #ifdef __cplusplus 936 } 937 #endif 938 /*! @}*/ 939 #endif /* __USB_HOST_AUDIO_H__ */ 940