Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
USBAudio.cpp
00001 /* Copyright (c) 2010-2011 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #include "stdint.h" 00020 #include "USBAudio.h" 00021 #include "USBAudio_Types.h" 00022 00023 00024 00025 USBAudio::USBAudio(uint32_t frequency_in, uint8_t channel_nb_in, uint32_t frequency_out, uint8_t channel_nb_out, uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release) { 00026 mute = 0; 00027 volCur = 0x0080; 00028 volMin = 0x0000; 00029 volMax = 0x0100; 00030 volRes = 0x0004; 00031 available = false; 00032 00033 FREQ_IN = frequency_in; 00034 FREQ_OUT = frequency_out; 00035 00036 this->channel_nb_in = channel_nb_in; 00037 this->channel_nb_out = channel_nb_out; 00038 00039 // stereo -> *2, mono -> *1 00040 PACKET_SIZE_ISO_IN = (FREQ_IN / 500) * channel_nb_in; 00041 PACKET_SIZE_ISO_OUT = (FREQ_OUT / 500) * channel_nb_out; 00042 00043 // STEREO -> left and right 00044 channel_config_in = (channel_nb_in == 1) ? CHANNEL_M : CHANNEL_L + CHANNEL_R; 00045 channel_config_out = (channel_nb_out == 1) ? CHANNEL_M : CHANNEL_L + CHANNEL_R; 00046 00047 SOF_handler = false; 00048 00049 buf_stream_out = NULL; 00050 buf_stream_in = NULL; 00051 00052 interruptOUT = false; 00053 writeIN = false; 00054 interruptIN = false; 00055 available = false; 00056 00057 volume = 0; 00058 00059 // connect the device 00060 USBDevice::connect(); 00061 } 00062 00063 bool USBAudio::read(uint8_t * buf) { 00064 buf_stream_in = buf; 00065 SOF_handler = false; 00066 while (!available || !SOF_handler); 00067 available = false; 00068 return true; 00069 } 00070 00071 bool USBAudio::readNB(uint8_t * buf) { 00072 buf_stream_in = buf; 00073 SOF_handler = false; 00074 while (!SOF_handler); 00075 if (available) { 00076 available = false; 00077 buf_stream_in = NULL; 00078 return true; 00079 } 00080 return false; 00081 } 00082 00083 bool USBAudio::readWrite(uint8_t * buf_read, uint8_t * buf_write) { 00084 buf_stream_in = buf_read; 00085 SOF_handler = false; 00086 writeIN = false; 00087 if (interruptIN) { 00088 USBDevice::writeNB(EP3IN, buf_write, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT); 00089 } else { 00090 buf_stream_out = buf_write; 00091 } 00092 while (!available); 00093 if (interruptIN) { 00094 while (!writeIN); 00095 } 00096 while (!SOF_handler); 00097 return true; 00098 } 00099 00100 00101 bool USBAudio::write(uint8_t * buf) { 00102 writeIN = false; 00103 SOF_handler = false; 00104 if (interruptIN) { 00105 USBDevice::writeNB(EP3IN, buf, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT); 00106 } else { 00107 buf_stream_out = buf; 00108 } 00109 while (!SOF_handler); 00110 if (interruptIN) { 00111 while (!writeIN); 00112 } 00113 return true; 00114 } 00115 00116 void USBAudio::writeSync(uint8_t *buf) 00117 { 00118 USBDevice::writeNB(EP3IN, buf, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT); 00119 } 00120 00121 uint32_t USBAudio::readSync(uint8_t *buf) 00122 { 00123 uint32_t size = 0; 00124 USBDevice::readEP(EP3OUT, (uint8_t *)buf, &size, PACKET_SIZE_ISO_IN); 00125 return size; 00126 } 00127 00128 float USBAudio::getVolume() { 00129 return (mute) ? 0.0 : volume; 00130 } 00131 00132 00133 bool USBAudio::EPISO_OUT_callback() { 00134 uint32_t size = 0; 00135 interruptOUT = true; 00136 if (buf_stream_in != NULL) { 00137 readEP(EP3OUT, (uint8_t *)buf_stream_in, &size, PACKET_SIZE_ISO_IN); 00138 available = true; 00139 buf_stream_in = NULL; 00140 } 00141 else { 00142 if (rxDone) 00143 rxDone.call(); 00144 } 00145 readStart(EP3OUT, PACKET_SIZE_ISO_IN); 00146 return false; 00147 } 00148 00149 00150 bool USBAudio::EPISO_IN_callback() { 00151 interruptIN = true; 00152 writeIN = true; 00153 if (txDone) 00154 txDone.call(); 00155 return true; 00156 } 00157 00158 00159 00160 // Called in ISR context on each start of frame 00161 void USBAudio::SOF(int frameNumber) { 00162 uint32_t size = 0; 00163 00164 if (!interruptOUT) { 00165 // read the isochronous endpoint 00166 if (buf_stream_in != NULL) { 00167 if (USBDevice::readEP_NB(EP3OUT, (uint8_t *)buf_stream_in, &size, PACKET_SIZE_ISO_IN)) { 00168 if (size) { 00169 available = true; 00170 readStart(EP3OUT, PACKET_SIZE_ISO_IN); 00171 buf_stream_in = NULL; 00172 } 00173 } 00174 } 00175 } 00176 00177 if (!interruptIN) { 00178 // write if needed 00179 if (buf_stream_out != NULL) { 00180 USBDevice::writeNB(EP3IN, (uint8_t *)buf_stream_out, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT); 00181 buf_stream_out = NULL; 00182 } 00183 } 00184 00185 SOF_handler = true; 00186 } 00187 00188 00189 // Called in ISR context 00190 // Set configuration. Return false if the configuration is not supported. 00191 bool USBAudio::USBCallback_setConfiguration(uint8_t configuration) { 00192 if (configuration != DEFAULT_CONFIGURATION) { 00193 return false; 00194 } 00195 00196 // Configure isochronous endpoint 00197 realiseEndpoint(EP3OUT, PACKET_SIZE_ISO_IN, ISOCHRONOUS); 00198 realiseEndpoint(EP3IN, PACKET_SIZE_ISO_OUT, ISOCHRONOUS); 00199 00200 // activate readings on this endpoint 00201 readStart(EP3OUT, PACKET_SIZE_ISO_IN); 00202 return true; 00203 } 00204 00205 00206 // Called in ISR context 00207 // Set alternate setting. Return false if the alternate setting is not supported 00208 bool USBAudio::USBCallback_setInterface(uint16_t interface, uint8_t alternate) { 00209 if (interface == 0 && alternate == 0) { 00210 return true; 00211 } 00212 if (interface == 1 && (alternate == 0 || alternate == 1)) { 00213 return true; 00214 } 00215 if (interface == 2 && (alternate == 0 || alternate == 1)) { 00216 return true; 00217 } 00218 return false; 00219 } 00220 00221 00222 00223 // Called in ISR context 00224 // Called by USBDevice on Endpoint0 request 00225 // This is used to handle extensions to standard requests and class specific requests. 00226 // Return true if class handles this request 00227 bool USBAudio::USBCallback_request() { 00228 bool success = false; 00229 CONTROL_TRANSFER * transfer = getTransferPtr(); 00230 00231 // Process class-specific requests 00232 if (transfer->setup.bmRequestType.Type == CLASS_TYPE) { 00233 00234 // Feature Unit: Interface = 0, ID = 2 00235 if (transfer->setup.wIndex == 0x0200) { 00236 00237 // Master Channel 00238 if ((transfer->setup.wValue & 0xff) == 0) { 00239 00240 switch (transfer->setup.wValue >> 8) { 00241 case MUTE_CONTROL: 00242 switch (transfer->setup.bRequest) { 00243 case REQUEST_GET_CUR: 00244 transfer->remaining = 1; 00245 transfer->ptr = &mute; 00246 transfer->direction = DEVICE_TO_HOST; 00247 success = true; 00248 break; 00249 00250 case REQUEST_SET_CUR: 00251 transfer->remaining = 1; 00252 transfer->notify = true; 00253 transfer->direction = HOST_TO_DEVICE; 00254 success = true; 00255 break; 00256 default: 00257 break; 00258 } 00259 break; 00260 case VOLUME_CONTROL: 00261 switch (transfer->setup.bRequest) { 00262 case REQUEST_GET_CUR: 00263 transfer->remaining = 2; 00264 transfer->ptr = (uint8_t *)&volCur; 00265 transfer->direction = DEVICE_TO_HOST; 00266 success = true; 00267 break; 00268 case REQUEST_GET_MIN: 00269 transfer->remaining = 2; 00270 transfer->ptr = (uint8_t *)&volMin; 00271 transfer->direction = DEVICE_TO_HOST; 00272 success = true; 00273 break; 00274 case REQUEST_GET_MAX: 00275 transfer->remaining = 2; 00276 transfer->ptr = (uint8_t *)&volMax; 00277 transfer->direction = DEVICE_TO_HOST; 00278 success = true; 00279 break; 00280 case REQUEST_GET_RES: 00281 transfer->remaining = 2; 00282 transfer->ptr = (uint8_t *)&volRes; 00283 transfer->direction = DEVICE_TO_HOST; 00284 success = true; 00285 break; 00286 00287 case REQUEST_SET_CUR: 00288 transfer->remaining = 2; 00289 transfer->notify = true; 00290 transfer->direction = HOST_TO_DEVICE; 00291 success = true; 00292 break; 00293 case REQUEST_SET_MIN: 00294 transfer->remaining = 2; 00295 transfer->notify = true; 00296 transfer->direction = HOST_TO_DEVICE; 00297 success = true; 00298 break; 00299 case REQUEST_SET_MAX: 00300 transfer->remaining = 2; 00301 transfer->notify = true; 00302 transfer->direction = HOST_TO_DEVICE; 00303 success = true; 00304 break; 00305 case REQUEST_SET_RES: 00306 transfer->remaining = 2; 00307 transfer->notify = true; 00308 transfer->direction = HOST_TO_DEVICE; 00309 success = true; 00310 break; 00311 } 00312 break; 00313 default: 00314 break; 00315 } 00316 } 00317 } 00318 } 00319 return success; 00320 } 00321 00322 00323 // Called in ISR context when a data OUT stage has been performed 00324 void USBAudio::USBCallback_requestCompleted(uint8_t * buf, uint32_t length) { 00325 if ((length == 1) || (length == 2)) { 00326 uint16_t data = (length == 1) ? *buf : *((uint16_t *)buf); 00327 CONTROL_TRANSFER * transfer = getTransferPtr(); 00328 switch (transfer->setup.wValue >> 8) { 00329 case MUTE_CONTROL: 00330 switch (transfer->setup.bRequest) { 00331 case REQUEST_SET_CUR: 00332 mute = data & 0xff; 00333 if (updateVol) 00334 updateVol.call(); 00335 break; 00336 default: 00337 break; 00338 } 00339 break; 00340 case VOLUME_CONTROL: 00341 switch (transfer->setup.bRequest) { 00342 case REQUEST_SET_CUR: 00343 volCur = data; 00344 volume = (float)volCur/(float)volMax; 00345 if (updateVol) 00346 updateVol.call(); 00347 break; 00348 default: 00349 break; 00350 } 00351 break; 00352 default: 00353 break; 00354 } 00355 } 00356 } 00357 00358 00359 00360 #define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \ 00361 + (5 * INTERFACE_DESCRIPTOR_LENGTH) \ 00362 + (1 * CONTROL_INTERFACE_DESCRIPTOR_LENGTH + 1) \ 00363 + (2 * INPUT_TERMINAL_DESCRIPTOR_LENGTH) \ 00364 + (1 * FEATURE_UNIT_DESCRIPTOR_LENGTH) \ 00365 + (2 * OUTPUT_TERMINAL_DESCRIPTOR_LENGTH) \ 00366 + (2 * STREAMING_INTERFACE_DESCRIPTOR_LENGTH) \ 00367 + (2 * FORMAT_TYPE_I_DESCRIPTOR_LENGTH) \ 00368 + (2 * (ENDPOINT_DESCRIPTOR_LENGTH + 2)) \ 00369 + (2 * STREAMING_ENDPOINT_DESCRIPTOR_LENGTH) ) 00370 00371 #define TOTAL_CONTROL_INTF_LENGTH (CONTROL_INTERFACE_DESCRIPTOR_LENGTH + 1 + \ 00372 2*INPUT_TERMINAL_DESCRIPTOR_LENGTH + \ 00373 FEATURE_UNIT_DESCRIPTOR_LENGTH + \ 00374 2*OUTPUT_TERMINAL_DESCRIPTOR_LENGTH) 00375 00376 uint8_t * USBAudio::configurationDesc() { 00377 static uint8_t configDescriptor[] = { 00378 // Configuration 1 00379 CONFIGURATION_DESCRIPTOR_LENGTH, // bLength 00380 CONFIGURATION_DESCRIPTOR, // bDescriptorType 00381 LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB) 00382 MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB) 00383 0x03, // bNumInterfaces 00384 DEFAULT_CONFIGURATION, // bConfigurationValue 00385 0x00, // iConfiguration 00386 0x80, // bmAttributes 00387 50, // bMaxPower 00388 00389 // Interface 0, Alternate Setting 0, Audio Control 00390 INTERFACE_DESCRIPTOR_LENGTH, // bLength 00391 INTERFACE_DESCRIPTOR, // bDescriptorType 00392 0x00, // bInterfaceNumber 00393 0x00, // bAlternateSetting 00394 0x00, // bNumEndpoints 00395 AUDIO_CLASS, // bInterfaceClass 00396 SUBCLASS_AUDIOCONTROL, // bInterfaceSubClass 00397 0x00, // bInterfaceProtocol 00398 0x00, // iInterface 00399 00400 00401 // Audio Control Interface 00402 CONTROL_INTERFACE_DESCRIPTOR_LENGTH + 1,// bLength 00403 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00404 CONTROL_HEADER, // bDescriptorSubtype 00405 LSB(0x0100), // bcdADC (LSB) 00406 MSB(0x0100), // bcdADC (MSB) 00407 LSB(TOTAL_CONTROL_INTF_LENGTH), // wTotalLength 00408 MSB(TOTAL_CONTROL_INTF_LENGTH), // wTotalLength 00409 0x02, // bInCollection 00410 0x01, // baInterfaceNr 00411 0x02, // baInterfaceNr 00412 00413 // Audio Input Terminal (Speaker) 00414 INPUT_TERMINAL_DESCRIPTOR_LENGTH, // bLength 00415 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00416 CONTROL_INPUT_TERMINAL, // bDescriptorSubtype 00417 0x01, // bTerminalID 00418 LSB(TERMINAL_USB_STREAMING), // wTerminalType 00419 MSB(TERMINAL_USB_STREAMING), // wTerminalType 00420 0x00, // bAssocTerminal 00421 channel_nb_in, // bNrChannels 00422 (uint8_t)(LSB(channel_config_in)), // wChannelConfig 00423 (uint8_t)(MSB(channel_config_in)), // wChannelConfig 00424 0x00, // iChannelNames 00425 0x00, // iTerminal 00426 00427 // Audio Feature Unit (Speaker) 00428 FEATURE_UNIT_DESCRIPTOR_LENGTH, // bLength 00429 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00430 CONTROL_FEATURE_UNIT, // bDescriptorSubtype 00431 0x02, // bUnitID 00432 0x01, // bSourceID 00433 0x01, // bControlSize 00434 CONTROL_MUTE | 00435 CONTROL_VOLUME, // bmaControls(0) 00436 0x00, // bmaControls(1) 00437 0x00, // iTerminal 00438 00439 // Audio Output Terminal (Speaker) 00440 OUTPUT_TERMINAL_DESCRIPTOR_LENGTH, // bLength 00441 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00442 CONTROL_OUTPUT_TERMINAL, // bDescriptorSubtype 00443 0x03, // bTerminalID 00444 LSB(TERMINAL_SPEAKER), // wTerminalType 00445 MSB(TERMINAL_SPEAKER), // wTerminalType 00446 0x00, // bAssocTerminal 00447 0x02, // bSourceID 00448 0x00, // iTerminal 00449 00450 00451 // Audio Input Terminal (Microphone) 00452 INPUT_TERMINAL_DESCRIPTOR_LENGTH, // bLength 00453 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00454 CONTROL_INPUT_TERMINAL, // bDescriptorSubtype 00455 0x04, // bTerminalID 00456 LSB(TERMINAL_MICROPHONE), // wTerminalType 00457 MSB(TERMINAL_MICROPHONE), // wTerminalType 00458 0x00, // bAssocTerminal 00459 channel_nb_out, // bNrChannels 00460 (uint8_t)(LSB(channel_config_out)), // wChannelConfig 00461 (uint8_t)(MSB(channel_config_out)), // wChannelConfig 00462 0x00, // iChannelNames 00463 0x00, // iTerminal 00464 00465 // Audio Output Terminal (Microphone) 00466 OUTPUT_TERMINAL_DESCRIPTOR_LENGTH, // bLength 00467 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00468 CONTROL_OUTPUT_TERMINAL, // bDescriptorSubtype 00469 0x05, // bTerminalID 00470 LSB(TERMINAL_USB_STREAMING), // wTerminalType 00471 MSB(TERMINAL_USB_STREAMING), // wTerminalType 00472 0x00, // bAssocTerminal 00473 0x04, // bSourceID 00474 0x00, // iTerminal 00475 00476 00477 00478 00479 00480 00481 // Interface 1, Alternate Setting 0, Audio Streaming - Zero Bandwith 00482 INTERFACE_DESCRIPTOR_LENGTH, // bLength 00483 INTERFACE_DESCRIPTOR, // bDescriptorType 00484 0x01, // bInterfaceNumber 00485 0x00, // bAlternateSetting 00486 0x00, // bNumEndpoints 00487 AUDIO_CLASS, // bInterfaceClass 00488 SUBCLASS_AUDIOSTREAMING, // bInterfaceSubClass 00489 0x00, // bInterfaceProtocol 00490 0x00, // iInterface 00491 00492 // Interface 1, Alternate Setting 1, Audio Streaming - Operational 00493 INTERFACE_DESCRIPTOR_LENGTH, // bLength 00494 INTERFACE_DESCRIPTOR, // bDescriptorType 00495 0x01, // bInterfaceNumber 00496 0x01, // bAlternateSetting 00497 0x01, // bNumEndpoints 00498 AUDIO_CLASS, // bInterfaceClass 00499 SUBCLASS_AUDIOSTREAMING, // bInterfaceSubClass 00500 0x00, // bInterfaceProtocol 00501 0x00, // iInterface 00502 00503 // Audio Streaming Interface 00504 STREAMING_INTERFACE_DESCRIPTOR_LENGTH, // bLength 00505 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00506 STREAMING_GENERAL, // bDescriptorSubtype 00507 0x01, // bTerminalLink 00508 0x00, // bDelay 00509 LSB(FORMAT_PCM), // wFormatTag 00510 MSB(FORMAT_PCM), // wFormatTag 00511 00512 // Audio Type I Format 00513 FORMAT_TYPE_I_DESCRIPTOR_LENGTH, // bLength 00514 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00515 STREAMING_FORMAT_TYPE, // bDescriptorSubtype 00516 FORMAT_TYPE_I, // bFormatType 00517 channel_nb_in, // bNrChannels 00518 0x02, // bSubFrameSize 00519 16, // bBitResolution 00520 0x01, // bSamFreqType 00521 (uint8_t)(LSB(FREQ_IN)), // tSamFreq 00522 (uint8_t)((FREQ_IN >> 8) & 0xff), // tSamFreq 00523 (uint8_t)((FREQ_IN >> 16) & 0xff), // tSamFreq 00524 00525 // Endpoint - Standard Descriptor 00526 ENDPOINT_DESCRIPTOR_LENGTH + 2, // bLength 00527 ENDPOINT_DESCRIPTOR, // bDescriptorType 00528 PHY_TO_DESC(EPISO_OUT), // bEndpointAddress 00529 E_ISOCHRONOUS, // bmAttributes 00530 (uint8_t)(LSB(PACKET_SIZE_ISO_IN)), // wMaxPacketSize 00531 (uint8_t)(MSB(PACKET_SIZE_ISO_IN)), // wMaxPacketSize 00532 0x01, // bInterval 00533 0x00, // bRefresh 00534 0x00, // bSynchAddress 00535 00536 // Endpoint - Audio Streaming 00537 STREAMING_ENDPOINT_DESCRIPTOR_LENGTH, // bLength 00538 ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType 00539 ENDPOINT_GENERAL, // bDescriptor 00540 0x00, // bmAttributes 00541 0x00, // bLockDelayUnits 00542 LSB(0x0000), // wLockDelay 00543 MSB(0x0000), // wLockDelay 00544 00545 00546 00547 00548 00549 00550 00551 // Interface 1, Alternate Setting 0, Audio Streaming - Zero Bandwith 00552 INTERFACE_DESCRIPTOR_LENGTH, // bLength 00553 INTERFACE_DESCRIPTOR, // bDescriptorType 00554 0x02, // bInterfaceNumber 00555 0x00, // bAlternateSetting 00556 0x00, // bNumEndpoints 00557 AUDIO_CLASS, // bInterfaceClass 00558 SUBCLASS_AUDIOSTREAMING, // bInterfaceSubClass 00559 0x00, // bInterfaceProtocol 00560 0x00, // iInterface 00561 00562 // Interface 1, Alternate Setting 1, Audio Streaming - Operational 00563 INTERFACE_DESCRIPTOR_LENGTH, // bLength 00564 INTERFACE_DESCRIPTOR, // bDescriptorType 00565 0x02, // bInterfaceNumber 00566 0x01, // bAlternateSetting 00567 0x01, // bNumEndpoints 00568 AUDIO_CLASS, // bInterfaceClass 00569 SUBCLASS_AUDIOSTREAMING, // bInterfaceSubClass 00570 0x00, // bInterfaceProtocol 00571 0x00, // iInterface 00572 00573 // Audio Streaming Interface 00574 STREAMING_INTERFACE_DESCRIPTOR_LENGTH, // bLength 00575 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00576 SUBCLASS_AUDIOCONTROL, // bDescriptorSubtype 00577 0x05, // bTerminalLink (output terminal microphone) 00578 0x01, // bDelay 00579 0x01, // wFormatTag 00580 0x00, // wFormatTag 00581 00582 // Audio Type I Format 00583 FORMAT_TYPE_I_DESCRIPTOR_LENGTH, // bLength 00584 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00585 SUBCLASS_AUDIOSTREAMING, // bDescriptorSubtype 00586 FORMAT_TYPE_I, // bFormatType 00587 channel_nb_out, // bNrChannels 00588 0x02, // bSubFrameSize 00589 0x10, // bBitResolution 00590 0x01, // bSamFreqType 00591 (uint8_t)(LSB(FREQ_OUT)), // tSamFreq 00592 (uint8_t)((FREQ_OUT >> 8) & 0xff), // tSamFreq 00593 (uint8_t)((FREQ_OUT >> 16) & 0xff), // tSamFreq 00594 00595 // Endpoint - Standard Descriptor 00596 ENDPOINT_DESCRIPTOR_LENGTH + 2, // bLength 00597 ENDPOINT_DESCRIPTOR, // bDescriptorType 00598 PHY_TO_DESC(EPISO_IN), // bEndpointAddress 00599 E_ISOCHRONOUS, // bmAttributes 00600 (uint8_t)(LSB(PACKET_SIZE_ISO_OUT)), // wMaxPacketSize 00601 (uint8_t)(MSB(PACKET_SIZE_ISO_OUT)), // wMaxPacketSize 00602 0x01, // bInterval 00603 0x00, // bRefresh 00604 0x00, // bSynchAddress 00605 00606 // Endpoint - Audio Streaming 00607 STREAMING_ENDPOINT_DESCRIPTOR_LENGTH, // bLength 00608 ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType 00609 ENDPOINT_GENERAL, // bDescriptor 00610 0x00, // bmAttributes 00611 0x00, // bLockDelayUnits 00612 LSB(0x0000), // wLockDelay 00613 MSB(0x0000), // wLockDelay 00614 00615 // Terminator 00616 0 // bLength 00617 }; 00618 return configDescriptor; 00619 } 00620 00621 uint8_t * USBAudio::stringIinterfaceDesc() { 00622 static uint8_t stringIinterfaceDescriptor[] = { 00623 0x0c, //bLength 00624 STRING_DESCRIPTOR, //bDescriptorType 0x03 00625 'A',0,'u',0,'d',0,'i',0,'o',0 //bString iInterface - Audio 00626 }; 00627 return stringIinterfaceDescriptor; 00628 } 00629 00630 uint8_t * USBAudio::stringIproductDesc() { 00631 static uint8_t stringIproductDescriptor[] = { 00632 0x16, //bLength 00633 STRING_DESCRIPTOR, //bDescriptorType 0x03 00634 'M',0,'b',0,'e',0,'d',0,' ',0,'A',0,'u',0,'d',0,'i',0,'o',0 //bString iProduct - Mbed Audio 00635 }; 00636 return stringIproductDescriptor; 00637 }
Generated on Tue Jul 12 2022 11:02:58 by
1.7.2