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.
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(EPISO_IN, 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(EPISO_IN, 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, AudioSampleCorrectType jitter_nb) 00117 { 00118 if ((jitter_nb != RemoveOneSample) && (jitter_nb != AddOneSample)) { 00119 jitter_nb = NoCorrection; 00120 } 00121 /* each sample is 2 bytes */ 00122 USBDevice::writeNB(EPISO_IN, buf, PACKET_SIZE_ISO_OUT + jitter_nb *(this->channel_nb_out*2), PACKET_SIZE_ISO_OUT+this->channel_nb_out*2); 00123 } 00124 00125 uint32_t USBAudio::readSync(uint8_t *buf) 00126 { 00127 uint32_t size = 0; 00128 USBDevice::readEP(EPISO_OUT, (uint8_t *)buf, &size, PACKET_SIZE_ISO_IN); 00129 return size; 00130 } 00131 00132 float USBAudio::getVolume() { 00133 return (mute) ? 0.0 : volume; 00134 } 00135 00136 00137 bool USBAudio::EPISO_OUT_callback() { 00138 uint32_t size = 0; 00139 interruptOUT = true; 00140 if (buf_stream_in != NULL) { 00141 readEP(EPISO_OUT, (uint8_t *)buf_stream_in, &size, PACKET_SIZE_ISO_IN); 00142 available = true; 00143 buf_stream_in = NULL; 00144 } 00145 else { 00146 if (rxDone) 00147 rxDone.call(); 00148 } 00149 readStart(EPISO_OUT, PACKET_SIZE_ISO_IN); 00150 return false; 00151 } 00152 00153 00154 bool USBAudio::EPISO_IN_callback() { 00155 interruptIN = true; 00156 writeIN = true; 00157 if (txDone) 00158 txDone.call(); 00159 return true; 00160 } 00161 00162 00163 00164 // Called in ISR context on each start of frame 00165 void USBAudio::SOF(int frameNumber) { 00166 uint32_t size = 0; 00167 00168 if (!interruptOUT) { 00169 // read the isochronous endpoint 00170 if (buf_stream_in != NULL) { 00171 if (USBDevice::readEP_NB(EPISO_OUT, (uint8_t *)buf_stream_in, &size, PACKET_SIZE_ISO_IN)) { 00172 if (size) { 00173 available = true; 00174 readStart(EPISO_OUT, PACKET_SIZE_ISO_IN); 00175 buf_stream_in = NULL; 00176 } 00177 } 00178 } 00179 } 00180 00181 if (!interruptIN) { 00182 // write if needed 00183 if (buf_stream_out != NULL) { 00184 USBDevice::writeNB(EPISO_IN, (uint8_t *)buf_stream_out, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT); 00185 buf_stream_out = NULL; 00186 } 00187 } 00188 00189 SOF_handler = true; 00190 } 00191 00192 00193 // Called in ISR context 00194 // Set configuration. Return false if the configuration is not supported. 00195 bool USBAudio::USBCallback_setConfiguration(uint8_t configuration) { 00196 if (configuration != DEFAULT_CONFIGURATION) { 00197 return false; 00198 } 00199 00200 // Configure isochronous endpoint 00201 realiseEndpoint(EPISO_OUT, PACKET_SIZE_ISO_IN, ISOCHRONOUS); 00202 realiseEndpoint(EPISO_IN, PACKET_SIZE_ISO_OUT+this->channel_nb_out*2, ISOCHRONOUS); 00203 00204 // activate readings on this endpoint 00205 readStart(EPISO_OUT, PACKET_SIZE_ISO_IN); 00206 return true; 00207 } 00208 00209 00210 // Called in ISR context 00211 // Set alternate setting. Return false if the alternate setting is not supported 00212 bool USBAudio::USBCallback_setInterface(uint16_t interface, uint8_t alternate) { 00213 if (interface == 0 && alternate == 0) { 00214 return true; 00215 } 00216 if (interface == 1 && (alternate == 0 || alternate == 1)) { 00217 return true; 00218 } 00219 if (interface == 2 && (alternate == 0 || alternate == 1)) { 00220 return true; 00221 } 00222 return false; 00223 } 00224 00225 00226 00227 // Called in ISR context 00228 // Called by USBDevice on Endpoint0 request 00229 // This is used to handle extensions to standard requests and class specific requests. 00230 // Return true if class handles this request 00231 bool USBAudio::USBCallback_request() { 00232 bool success = false; 00233 CONTROL_TRANSFER * transfer = getTransferPtr(); 00234 00235 // Process class-specific requests 00236 if (transfer->setup.bmRequestType.Type == CLASS_TYPE) { 00237 00238 // Feature Unit: Interface = 0, ID = 2 00239 if (transfer->setup.wIndex == 0x0200) { 00240 00241 // Master Channel 00242 if ((transfer->setup.wValue & 0xff) == 0) { 00243 00244 switch (transfer->setup.wValue >> 8) { 00245 case MUTE_CONTROL: 00246 switch (transfer->setup.bRequest) { 00247 case REQUEST_GET_CUR: 00248 transfer->remaining = 1; 00249 transfer->ptr = &mute; 00250 transfer->direction = DEVICE_TO_HOST; 00251 success = true; 00252 break; 00253 00254 case REQUEST_SET_CUR: 00255 transfer->remaining = 1; 00256 transfer->notify = true; 00257 transfer->direction = HOST_TO_DEVICE; 00258 success = true; 00259 break; 00260 default: 00261 break; 00262 } 00263 break; 00264 case VOLUME_CONTROL: 00265 switch (transfer->setup.bRequest) { 00266 case REQUEST_GET_CUR: 00267 transfer->remaining = 2; 00268 transfer->ptr = (uint8_t *)&volCur; 00269 transfer->direction = DEVICE_TO_HOST; 00270 success = true; 00271 break; 00272 case REQUEST_GET_MIN: 00273 transfer->remaining = 2; 00274 transfer->ptr = (uint8_t *)&volMin; 00275 transfer->direction = DEVICE_TO_HOST; 00276 success = true; 00277 break; 00278 case REQUEST_GET_MAX: 00279 transfer->remaining = 2; 00280 transfer->ptr = (uint8_t *)&volMax; 00281 transfer->direction = DEVICE_TO_HOST; 00282 success = true; 00283 break; 00284 case REQUEST_GET_RES: 00285 transfer->remaining = 2; 00286 transfer->ptr = (uint8_t *)&volRes; 00287 transfer->direction = DEVICE_TO_HOST; 00288 success = true; 00289 break; 00290 00291 case REQUEST_SET_CUR: 00292 transfer->remaining = 2; 00293 transfer->notify = true; 00294 transfer->direction = HOST_TO_DEVICE; 00295 success = true; 00296 break; 00297 case REQUEST_SET_MIN: 00298 transfer->remaining = 2; 00299 transfer->notify = true; 00300 transfer->direction = HOST_TO_DEVICE; 00301 success = true; 00302 break; 00303 case REQUEST_SET_MAX: 00304 transfer->remaining = 2; 00305 transfer->notify = true; 00306 transfer->direction = HOST_TO_DEVICE; 00307 success = true; 00308 break; 00309 case REQUEST_SET_RES: 00310 transfer->remaining = 2; 00311 transfer->notify = true; 00312 transfer->direction = HOST_TO_DEVICE; 00313 success = true; 00314 break; 00315 } 00316 break; 00317 default: 00318 break; 00319 } 00320 } 00321 } 00322 } 00323 return success; 00324 } 00325 00326 00327 // Called in ISR context when a data OUT stage has been performed 00328 void USBAudio::USBCallback_requestCompleted(uint8_t * buf, uint32_t length) { 00329 if ((length == 1) || (length == 2)) { 00330 uint16_t data = (length == 1) ? *buf : *((uint16_t *)buf); 00331 CONTROL_TRANSFER * transfer = getTransferPtr(); 00332 switch (transfer->setup.wValue >> 8) { 00333 case MUTE_CONTROL: 00334 switch (transfer->setup.bRequest) { 00335 case REQUEST_SET_CUR: 00336 mute = data & 0xff; 00337 if (updateVol) 00338 updateVol.call(); 00339 break; 00340 default: 00341 break; 00342 } 00343 break; 00344 case VOLUME_CONTROL: 00345 switch (transfer->setup.bRequest) { 00346 case REQUEST_SET_CUR: 00347 volCur = data; 00348 volume = (float)volCur/(float)volMax; 00349 if (updateVol) 00350 updateVol.call(); 00351 break; 00352 default: 00353 break; 00354 } 00355 break; 00356 default: 00357 break; 00358 } 00359 } 00360 } 00361 00362 00363 00364 #define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \ 00365 + (5 * INTERFACE_DESCRIPTOR_LENGTH) \ 00366 + (1 * CONTROL_INTERFACE_DESCRIPTOR_LENGTH + 1) \ 00367 + (2 * INPUT_TERMINAL_DESCRIPTOR_LENGTH) \ 00368 + (1 * FEATURE_UNIT_DESCRIPTOR_LENGTH) \ 00369 + (2 * OUTPUT_TERMINAL_DESCRIPTOR_LENGTH) \ 00370 + (2 * STREAMING_INTERFACE_DESCRIPTOR_LENGTH) \ 00371 + (2 * FORMAT_TYPE_I_DESCRIPTOR_LENGTH) \ 00372 + (2 * (ENDPOINT_DESCRIPTOR_LENGTH + 2)) \ 00373 + (2 * STREAMING_ENDPOINT_DESCRIPTOR_LENGTH) ) 00374 00375 #define TOTAL_CONTROL_INTF_LENGTH (CONTROL_INTERFACE_DESCRIPTOR_LENGTH + 1 + \ 00376 2*INPUT_TERMINAL_DESCRIPTOR_LENGTH + \ 00377 FEATURE_UNIT_DESCRIPTOR_LENGTH + \ 00378 2*OUTPUT_TERMINAL_DESCRIPTOR_LENGTH) 00379 00380 uint8_t * USBAudio::configurationDesc() { 00381 static uint8_t configDescriptor[] = { 00382 // Configuration 1 00383 CONFIGURATION_DESCRIPTOR_LENGTH, // bLength 00384 CONFIGURATION_DESCRIPTOR, // bDescriptorType 00385 LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB) 00386 MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB) 00387 0x03, // bNumInterfaces 00388 DEFAULT_CONFIGURATION, // bConfigurationValue 00389 0x00, // iConfiguration 00390 0x80, // bmAttributes 00391 50, // bMaxPower 00392 00393 // Interface 0, Alternate Setting 0, Audio Control 00394 INTERFACE_DESCRIPTOR_LENGTH, // bLength 00395 INTERFACE_DESCRIPTOR, // bDescriptorType 00396 0x00, // bInterfaceNumber 00397 0x00, // bAlternateSetting 00398 0x00, // bNumEndpoints 00399 AUDIO_CLASS, // bInterfaceClass 00400 SUBCLASS_AUDIOCONTROL, // bInterfaceSubClass 00401 0x00, // bInterfaceProtocol 00402 0x00, // iInterface 00403 00404 00405 // Audio Control Interface 00406 CONTROL_INTERFACE_DESCRIPTOR_LENGTH + 1,// bLength 00407 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00408 CONTROL_HEADER, // bDescriptorSubtype 00409 LSB(0x0100), // bcdADC (LSB) 00410 MSB(0x0100), // bcdADC (MSB) 00411 LSB(TOTAL_CONTROL_INTF_LENGTH), // wTotalLength 00412 MSB(TOTAL_CONTROL_INTF_LENGTH), // wTotalLength 00413 0x02, // bInCollection 00414 0x01, // baInterfaceNr 00415 0x02, // baInterfaceNr 00416 00417 // Audio Input Terminal (Speaker) 00418 INPUT_TERMINAL_DESCRIPTOR_LENGTH, // bLength 00419 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00420 CONTROL_INPUT_TERMINAL, // bDescriptorSubtype 00421 0x01, // bTerminalID 00422 LSB(TERMINAL_USB_STREAMING), // wTerminalType 00423 MSB(TERMINAL_USB_STREAMING), // wTerminalType 00424 0x00, // bAssocTerminal 00425 channel_nb_in, // bNrChannels 00426 (uint8_t)(LSB(channel_config_in)), // wChannelConfig 00427 (uint8_t)(MSB(channel_config_in)), // wChannelConfig 00428 0x00, // iChannelNames 00429 0x00, // iTerminal 00430 00431 // Audio Feature Unit (Speaker) 00432 FEATURE_UNIT_DESCRIPTOR_LENGTH, // bLength 00433 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00434 CONTROL_FEATURE_UNIT, // bDescriptorSubtype 00435 0x02, // bUnitID 00436 0x01, // bSourceID 00437 0x01, // bControlSize 00438 CONTROL_MUTE | 00439 CONTROL_VOLUME, // bmaControls(0) 00440 0x00, // bmaControls(1) 00441 0x00, // iTerminal 00442 00443 // Audio Output Terminal (Speaker) 00444 OUTPUT_TERMINAL_DESCRIPTOR_LENGTH, // bLength 00445 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00446 CONTROL_OUTPUT_TERMINAL, // bDescriptorSubtype 00447 0x03, // bTerminalID 00448 LSB(TERMINAL_SPEAKER), // wTerminalType 00449 MSB(TERMINAL_SPEAKER), // wTerminalType 00450 0x00, // bAssocTerminal 00451 0x02, // bSourceID 00452 0x00, // iTerminal 00453 00454 00455 // Audio Input Terminal (Microphone) 00456 INPUT_TERMINAL_DESCRIPTOR_LENGTH, // bLength 00457 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00458 CONTROL_INPUT_TERMINAL, // bDescriptorSubtype 00459 0x04, // bTerminalID 00460 LSB(TERMINAL_MICROPHONE), // wTerminalType 00461 MSB(TERMINAL_MICROPHONE), // wTerminalType 00462 0x00, // bAssocTerminal 00463 channel_nb_out, // bNrChannels 00464 (uint8_t)(LSB(channel_config_out)), // wChannelConfig 00465 (uint8_t)(MSB(channel_config_out)), // wChannelConfig 00466 0x00, // iChannelNames 00467 0x00, // iTerminal 00468 00469 // Audio Output Terminal (Microphone) 00470 OUTPUT_TERMINAL_DESCRIPTOR_LENGTH, // bLength 00471 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00472 CONTROL_OUTPUT_TERMINAL, // bDescriptorSubtype 00473 0x05, // bTerminalID 00474 LSB(TERMINAL_USB_STREAMING), // wTerminalType 00475 MSB(TERMINAL_USB_STREAMING), // wTerminalType 00476 0x00, // bAssocTerminal 00477 0x04, // bSourceID 00478 0x00, // iTerminal 00479 00480 00481 00482 00483 00484 00485 // Interface 1, Alternate Setting 0, Audio Streaming - Zero Bandwith 00486 INTERFACE_DESCRIPTOR_LENGTH, // bLength 00487 INTERFACE_DESCRIPTOR, // bDescriptorType 00488 0x01, // bInterfaceNumber 00489 0x00, // bAlternateSetting 00490 0x00, // bNumEndpoints 00491 AUDIO_CLASS, // bInterfaceClass 00492 SUBCLASS_AUDIOSTREAMING, // bInterfaceSubClass 00493 0x00, // bInterfaceProtocol 00494 0x00, // iInterface 00495 00496 // Interface 1, Alternate Setting 1, Audio Streaming - Operational 00497 INTERFACE_DESCRIPTOR_LENGTH, // bLength 00498 INTERFACE_DESCRIPTOR, // bDescriptorType 00499 0x01, // bInterfaceNumber 00500 0x01, // bAlternateSetting 00501 0x01, // bNumEndpoints 00502 AUDIO_CLASS, // bInterfaceClass 00503 SUBCLASS_AUDIOSTREAMING, // bInterfaceSubClass 00504 0x00, // bInterfaceProtocol 00505 0x00, // iInterface 00506 00507 // Audio Streaming Interface 00508 STREAMING_INTERFACE_DESCRIPTOR_LENGTH, // bLength 00509 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00510 STREAMING_GENERAL, // bDescriptorSubtype 00511 0x01, // bTerminalLink 00512 0x00, // bDelay 00513 LSB(FORMAT_PCM), // wFormatTag 00514 MSB(FORMAT_PCM), // wFormatTag 00515 00516 // Audio Type I Format 00517 FORMAT_TYPE_I_DESCRIPTOR_LENGTH, // bLength 00518 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00519 STREAMING_FORMAT_TYPE, // bDescriptorSubtype 00520 FORMAT_TYPE_I, // bFormatType 00521 channel_nb_in, // bNrChannels 00522 0x02, // bSubFrameSize 00523 16, // bBitResolution 00524 0x01, // bSamFreqType 00525 (uint8_t)(LSB(FREQ_IN)), // tSamFreq 00526 (uint8_t)((FREQ_IN >> 8) & 0xff), // tSamFreq 00527 (uint8_t)((FREQ_IN >> 16) & 0xff), // tSamFreq 00528 00529 // Endpoint - Standard Descriptor 00530 ENDPOINT_DESCRIPTOR_LENGTH + 2, // bLength 00531 ENDPOINT_DESCRIPTOR, // bDescriptorType 00532 PHY_TO_DESC(EPISO_OUT), // bEndpointAddress 00533 E_ISOCHRONOUS, // bmAttributes 00534 (uint8_t)(LSB(PACKET_SIZE_ISO_IN)), // wMaxPacketSize 00535 (uint8_t)(MSB(PACKET_SIZE_ISO_IN)), // wMaxPacketSize 00536 0x01, // bInterval 00537 0x00, // bRefresh 00538 0x00, // bSynchAddress 00539 00540 // Endpoint - Audio Streaming 00541 STREAMING_ENDPOINT_DESCRIPTOR_LENGTH, // bLength 00542 ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType 00543 ENDPOINT_GENERAL, // bDescriptor 00544 0x00, // bmAttributes 00545 0x00, // bLockDelayUnits 00546 LSB(0x0000), // wLockDelay 00547 MSB(0x0000), // wLockDelay 00548 00549 00550 00551 00552 00553 00554 00555 // Interface 1, Alternate Setting 0, Audio Streaming - Zero Bandwith 00556 INTERFACE_DESCRIPTOR_LENGTH, // bLength 00557 INTERFACE_DESCRIPTOR, // bDescriptorType 00558 0x02, // bInterfaceNumber 00559 0x00, // bAlternateSetting 00560 0x00, // bNumEndpoints 00561 AUDIO_CLASS, // bInterfaceClass 00562 SUBCLASS_AUDIOSTREAMING, // bInterfaceSubClass 00563 0x00, // bInterfaceProtocol 00564 0x00, // iInterface 00565 00566 // Interface 1, Alternate Setting 1, Audio Streaming - Operational 00567 INTERFACE_DESCRIPTOR_LENGTH, // bLength 00568 INTERFACE_DESCRIPTOR, // bDescriptorType 00569 0x02, // bInterfaceNumber 00570 0x01, // bAlternateSetting 00571 0x01, // bNumEndpoints 00572 AUDIO_CLASS, // bInterfaceClass 00573 SUBCLASS_AUDIOSTREAMING, // bInterfaceSubClass 00574 0x00, // bInterfaceProtocol 00575 0x00, // iInterface 00576 00577 // Audio Streaming Interface 00578 STREAMING_INTERFACE_DESCRIPTOR_LENGTH, // bLength 00579 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00580 SUBCLASS_AUDIOCONTROL, // bDescriptorSubtype 00581 0x05, // bTerminalLink (output terminal microphone) 00582 0x01, // bDelay 00583 0x01, // wFormatTag 00584 0x00, // wFormatTag 00585 00586 // Audio Type I Format 00587 FORMAT_TYPE_I_DESCRIPTOR_LENGTH, // bLength 00588 INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType 00589 SUBCLASS_AUDIOSTREAMING, // bDescriptorSubtype 00590 FORMAT_TYPE_I, // bFormatType 00591 channel_nb_out, // bNrChannels 00592 0x02, // bSubFrameSize 00593 0x10, // bBitResolution 00594 0x01, // bSamFreqType 00595 (uint8_t)(LSB(FREQ_OUT)), // tSamFreq 00596 (uint8_t)((FREQ_OUT >> 8) & 0xff), // tSamFreq 00597 (uint8_t)((FREQ_OUT >> 16) & 0xff), // tSamFreq 00598 00599 // Endpoint - Standard Descriptor 00600 ENDPOINT_DESCRIPTOR_LENGTH + 2, // bLength 00601 ENDPOINT_DESCRIPTOR, // bDescriptorType 00602 PHY_TO_DESC(EPISO_IN), // bEndpointAddress 00603 E_ISOCHRONOUS, // bmAttributes 00604 (uint8_t)(LSB(PACKET_SIZE_ISO_OUT+channel_nb_out*2)), // wMaxPacketSize 00605 (uint8_t)(MSB(PACKET_SIZE_ISO_OUT+channel_nb_out*2)), // wMaxPacketSize 00606 0x01, // bInterval 00607 0x00, // bRefresh 00608 0x00, // bSynchAddress 00609 00610 // Endpoint - Audio Streaming 00611 STREAMING_ENDPOINT_DESCRIPTOR_LENGTH, // bLength 00612 ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType 00613 ENDPOINT_GENERAL, // bDescriptor 00614 0x00, // bmAttributes 00615 0x00, // bLockDelayUnits 00616 LSB(0x0000), // wLockDelay 00617 MSB(0x0000), // wLockDelay 00618 00619 // Terminator 00620 0 // bLength 00621 }; 00622 return configDescriptor; 00623 } 00624 00625 uint8_t * USBAudio::stringIinterfaceDesc() { 00626 static uint8_t stringIinterfaceDescriptor[] = { 00627 0x0c, //bLength 00628 STRING_DESCRIPTOR, //bDescriptorType 0x03 00629 'A',0,'u',0,'d',0,'i',0,'o',0 //bString iInterface - Audio 00630 }; 00631 return stringIinterfaceDescriptor; 00632 } 00633 00634 uint8_t * USBAudio::stringIproductDesc() { 00635 static uint8_t stringIproductDescriptor[] = { 00636 0x16, //bLength 00637 STRING_DESCRIPTOR, //bDescriptorType 0x03 00638 'M',0,'b',0,'e',0,'d',0,' ',0,'A',0,'u',0,'d',0,'i',0,'o',0 //bString iProduct - Mbed Audio 00639 }; 00640 return stringIproductDescriptor; 00641 }
Generated on Thu Jul 14 2022 14:36:24 by
