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