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