Keyboard firmwares for Atmel AVR and Cortex-M
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

USBAudio.cpp 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /* Copyright (c) 2010-2011 mbed.org, MIT License
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  4. * and associated documentation files (the "Software"), to deal in the Software without
  5. * restriction, including without limitation the rights to use, copy, modify, merge, publish,
  6. * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
  7. * Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or
  10. * substantial portions of the Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  13. * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  14. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  15. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. */
  18. #include "stdint.h"
  19. #include "USBAudio.h"
  20. #include "USBAudio_Types.h"
  21. 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) {
  22. mute = 0;
  23. volCur = 0x0080;
  24. volMin = 0x0000;
  25. volMax = 0x0100;
  26. volRes = 0x0004;
  27. available = false;
  28. FREQ_IN = frequency_in;
  29. FREQ_OUT = frequency_out;
  30. this->channel_nb_in = channel_nb_in;
  31. this->channel_nb_out = channel_nb_out;
  32. // stereo -> *2, mono -> *1
  33. PACKET_SIZE_ISO_IN = (FREQ_IN / 500) * channel_nb_in;
  34. PACKET_SIZE_ISO_OUT = (FREQ_OUT / 500) * channel_nb_out;
  35. // STEREO -> left and right
  36. channel_config_in = (channel_nb_in == 1) ? CHANNEL_M : CHANNEL_L + CHANNEL_R;
  37. channel_config_out = (channel_nb_out == 1) ? CHANNEL_M : CHANNEL_L + CHANNEL_R;
  38. SOF_handler = false;
  39. buf_stream_out = NULL;
  40. buf_stream_in = NULL;
  41. interruptOUT = false;
  42. writeIN = false;
  43. interruptIN = false;
  44. available = false;
  45. volume = 0;
  46. // connect the device
  47. USBDevice::connect();
  48. }
  49. bool USBAudio::read(uint8_t * buf) {
  50. buf_stream_in = buf;
  51. SOF_handler = false;
  52. while (!available || !SOF_handler);
  53. available = false;
  54. return true;
  55. }
  56. bool USBAudio::readNB(uint8_t * buf) {
  57. buf_stream_in = buf;
  58. SOF_handler = false;
  59. while (!SOF_handler);
  60. if (available) {
  61. available = false;
  62. buf_stream_in = NULL;
  63. return true;
  64. }
  65. return false;
  66. }
  67. bool USBAudio::readWrite(uint8_t * buf_read, uint8_t * buf_write) {
  68. buf_stream_in = buf_read;
  69. SOF_handler = false;
  70. writeIN = false;
  71. if (interruptIN) {
  72. USBDevice::writeNB(EP3IN, buf_write, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
  73. } else {
  74. buf_stream_out = buf_write;
  75. }
  76. while (!available);
  77. if (interruptIN) {
  78. while (!writeIN);
  79. }
  80. while (!SOF_handler);
  81. return true;
  82. }
  83. bool USBAudio::write(uint8_t * buf) {
  84. writeIN = false;
  85. SOF_handler = false;
  86. if (interruptIN) {
  87. USBDevice::writeNB(EP3IN, buf, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
  88. } else {
  89. buf_stream_out = buf;
  90. }
  91. while (!SOF_handler);
  92. if (interruptIN) {
  93. while (!writeIN);
  94. }
  95. return true;
  96. }
  97. float USBAudio::getVolume() {
  98. return (mute) ? 0.0 : volume;
  99. }
  100. bool USBAudio::EPISO_OUT_callback() {
  101. uint32_t size = 0;
  102. interruptOUT = true;
  103. if (buf_stream_in != NULL) {
  104. readEP(EP3OUT, (uint8_t *)buf_stream_in, &size, PACKET_SIZE_ISO_IN);
  105. available = true;
  106. buf_stream_in = NULL;
  107. }
  108. readStart(EP3OUT, PACKET_SIZE_ISO_IN);
  109. return false;
  110. }
  111. bool USBAudio::EPISO_IN_callback() {
  112. interruptIN = true;
  113. writeIN = true;
  114. return true;
  115. }
  116. // Called in ISR context on each start of frame
  117. void USBAudio::SOF(int frameNumber) {
  118. uint32_t size = 0;
  119. if (!interruptOUT) {
  120. // read the isochronous endpoint
  121. if (buf_stream_in != NULL) {
  122. if (USBDevice::readEP_NB(EP3OUT, (uint8_t *)buf_stream_in, &size, PACKET_SIZE_ISO_IN)) {
  123. if (size) {
  124. available = true;
  125. readStart(EP3OUT, PACKET_SIZE_ISO_IN);
  126. buf_stream_in = NULL;
  127. }
  128. }
  129. }
  130. }
  131. if (!interruptIN) {
  132. // write if needed
  133. if (buf_stream_out != NULL) {
  134. USBDevice::writeNB(EP3IN, (uint8_t *)buf_stream_out, PACKET_SIZE_ISO_OUT, PACKET_SIZE_ISO_OUT);
  135. buf_stream_out = NULL;
  136. }
  137. }
  138. SOF_handler = true;
  139. }
  140. // Called in ISR context
  141. // Set configuration. Return false if the configuration is not supported.
  142. bool USBAudio::USBCallback_setConfiguration(uint8_t configuration) {
  143. if (configuration != DEFAULT_CONFIGURATION) {
  144. return false;
  145. }
  146. // Configure isochronous endpoint
  147. realiseEndpoint(EP3OUT, PACKET_SIZE_ISO_IN, ISOCHRONOUS);
  148. realiseEndpoint(EP3IN, PACKET_SIZE_ISO_OUT, ISOCHRONOUS);
  149. // activate readings on this endpoint
  150. readStart(EP3OUT, PACKET_SIZE_ISO_IN);
  151. return true;
  152. }
  153. // Called in ISR context
  154. // Set alternate setting. Return false if the alternate setting is not supported
  155. bool USBAudio::USBCallback_setInterface(uint16_t interface, uint8_t alternate) {
  156. if (interface == 0 && alternate == 0) {
  157. return true;
  158. }
  159. if (interface == 1 && (alternate == 0 || alternate == 1)) {
  160. return true;
  161. }
  162. if (interface == 2 && (alternate == 0 || alternate == 1)) {
  163. return true;
  164. }
  165. return false;
  166. }
  167. // Called in ISR context
  168. // Called by USBDevice on Endpoint0 request
  169. // This is used to handle extensions to standard requests and class specific requests.
  170. // Return true if class handles this request
  171. bool USBAudio::USBCallback_request() {
  172. bool success = false;
  173. CONTROL_TRANSFER * transfer = getTransferPtr();
  174. // Process class-specific requests
  175. if (transfer->setup.bmRequestType.Type == CLASS_TYPE) {
  176. // Feature Unit: Interface = 0, ID = 2
  177. if (transfer->setup.wIndex == 0x0200) {
  178. // Master Channel
  179. if ((transfer->setup.wValue & 0xff) == 0) {
  180. switch (transfer->setup.wValue >> 8) {
  181. case MUTE_CONTROL:
  182. switch (transfer->setup.bRequest) {
  183. case REQUEST_GET_CUR:
  184. transfer->remaining = 1;
  185. transfer->ptr = &mute;
  186. transfer->direction = DEVICE_TO_HOST;
  187. success = true;
  188. break;
  189. case REQUEST_SET_CUR:
  190. transfer->remaining = 1;
  191. transfer->notify = true;
  192. transfer->direction = HOST_TO_DEVICE;
  193. success = true;
  194. break;
  195. default:
  196. break;
  197. }
  198. break;
  199. case VOLUME_CONTROL:
  200. switch (transfer->setup.bRequest) {
  201. case REQUEST_GET_CUR:
  202. transfer->remaining = 2;
  203. transfer->ptr = (uint8_t *)&volCur;
  204. transfer->direction = DEVICE_TO_HOST;
  205. success = true;
  206. break;
  207. case REQUEST_GET_MIN:
  208. transfer->remaining = 2;
  209. transfer->ptr = (uint8_t *)&volMin;
  210. transfer->direction = DEVICE_TO_HOST;
  211. success = true;
  212. break;
  213. case REQUEST_GET_MAX:
  214. transfer->remaining = 2;
  215. transfer->ptr = (uint8_t *)&volMax;
  216. transfer->direction = DEVICE_TO_HOST;
  217. success = true;
  218. break;
  219. case REQUEST_GET_RES:
  220. transfer->remaining = 2;
  221. transfer->ptr = (uint8_t *)&volRes;
  222. transfer->direction = DEVICE_TO_HOST;
  223. success = true;
  224. break;
  225. case REQUEST_SET_CUR:
  226. transfer->remaining = 2;
  227. transfer->notify = true;
  228. transfer->direction = HOST_TO_DEVICE;
  229. success = true;
  230. break;
  231. case REQUEST_SET_MIN:
  232. transfer->remaining = 2;
  233. transfer->notify = true;
  234. transfer->direction = HOST_TO_DEVICE;
  235. success = true;
  236. break;
  237. case REQUEST_SET_MAX:
  238. transfer->remaining = 2;
  239. transfer->notify = true;
  240. transfer->direction = HOST_TO_DEVICE;
  241. success = true;
  242. break;
  243. case REQUEST_SET_RES:
  244. transfer->remaining = 2;
  245. transfer->notify = true;
  246. transfer->direction = HOST_TO_DEVICE;
  247. success = true;
  248. break;
  249. }
  250. break;
  251. default:
  252. break;
  253. }
  254. }
  255. }
  256. }
  257. return success;
  258. }
  259. // Called in ISR context when a data OUT stage has been performed
  260. void USBAudio::USBCallback_requestCompleted(uint8_t * buf, uint32_t length) {
  261. if ((length == 1) || (length == 2)) {
  262. uint16_t data = (length == 1) ? *buf : *((uint16_t *)buf);
  263. CONTROL_TRANSFER * transfer = getTransferPtr();
  264. switch (transfer->setup.wValue >> 8) {
  265. case MUTE_CONTROL:
  266. switch (transfer->setup.bRequest) {
  267. case REQUEST_SET_CUR:
  268. mute = data & 0xff;
  269. updateVol.call();
  270. break;
  271. default:
  272. break;
  273. }
  274. break;
  275. case VOLUME_CONTROL:
  276. switch (transfer->setup.bRequest) {
  277. case REQUEST_SET_CUR:
  278. volCur = data;
  279. volume = (float)volCur/(float)volMax;
  280. updateVol.call();
  281. break;
  282. default:
  283. break;
  284. }
  285. break;
  286. default:
  287. break;
  288. }
  289. }
  290. }
  291. #define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \
  292. + (5 * INTERFACE_DESCRIPTOR_LENGTH) \
  293. + (1 * CONTROL_INTERFACE_DESCRIPTOR_LENGTH + 1) \
  294. + (2 * INPUT_TERMINAL_DESCRIPTOR_LENGTH) \
  295. + (1 * FEATURE_UNIT_DESCRIPTOR_LENGTH) \
  296. + (2 * OUTPUT_TERMINAL_DESCRIPTOR_LENGTH) \
  297. + (2 * STREAMING_INTERFACE_DESCRIPTOR_LENGTH) \
  298. + (2 * FORMAT_TYPE_I_DESCRIPTOR_LENGTH) \
  299. + (2 * (ENDPOINT_DESCRIPTOR_LENGTH + 2)) \
  300. + (2 * STREAMING_ENDPOINT_DESCRIPTOR_LENGTH) )
  301. #define TOTAL_CONTROL_INTF_LENGTH (CONTROL_INTERFACE_DESCRIPTOR_LENGTH + 1 + \
  302. 2*INPUT_TERMINAL_DESCRIPTOR_LENGTH + \
  303. FEATURE_UNIT_DESCRIPTOR_LENGTH + \
  304. 2*OUTPUT_TERMINAL_DESCRIPTOR_LENGTH)
  305. uint8_t * USBAudio::configurationDesc() {
  306. static uint8_t configDescriptor[] = {
  307. // Configuration 1
  308. CONFIGURATION_DESCRIPTOR_LENGTH, // bLength
  309. CONFIGURATION_DESCRIPTOR, // bDescriptorType
  310. LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
  311. MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
  312. 0x03, // bNumInterfaces
  313. DEFAULT_CONFIGURATION, // bConfigurationValue
  314. 0x00, // iConfiguration
  315. 0x80, // bmAttributes
  316. 50, // bMaxPower
  317. // Interface 0, Alternate Setting 0, Audio Control
  318. INTERFACE_DESCRIPTOR_LENGTH, // bLength
  319. INTERFACE_DESCRIPTOR, // bDescriptorType
  320. 0x00, // bInterfaceNumber
  321. 0x00, // bAlternateSetting
  322. 0x00, // bNumEndpoints
  323. AUDIO_CLASS, // bInterfaceClass
  324. SUBCLASS_AUDIOCONTROL, // bInterfaceSubClass
  325. 0x00, // bInterfaceProtocol
  326. 0x00, // iInterface
  327. // Audio Control Interface
  328. CONTROL_INTERFACE_DESCRIPTOR_LENGTH + 1,// bLength
  329. INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType
  330. CONTROL_HEADER, // bDescriptorSubtype
  331. LSB(0x0100), // bcdADC (LSB)
  332. MSB(0x0100), // bcdADC (MSB)
  333. LSB(TOTAL_CONTROL_INTF_LENGTH), // wTotalLength
  334. MSB(TOTAL_CONTROL_INTF_LENGTH), // wTotalLength
  335. 0x02, // bInCollection
  336. 0x01, // baInterfaceNr
  337. 0x02, // baInterfaceNr
  338. // Audio Input Terminal (Speaker)
  339. INPUT_TERMINAL_DESCRIPTOR_LENGTH, // bLength
  340. INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType
  341. CONTROL_INPUT_TERMINAL, // bDescriptorSubtype
  342. 0x01, // bTerminalID
  343. LSB(TERMINAL_USB_STREAMING), // wTerminalType
  344. MSB(TERMINAL_USB_STREAMING), // wTerminalType
  345. 0x00, // bAssocTerminal
  346. channel_nb_in, // bNrChannels
  347. (uint8_t)(LSB(channel_config_in)), // wChannelConfig
  348. (uint8_t)(MSB(channel_config_in)), // wChannelConfig
  349. 0x00, // iChannelNames
  350. 0x00, // iTerminal
  351. // Audio Feature Unit (Speaker)
  352. FEATURE_UNIT_DESCRIPTOR_LENGTH, // bLength
  353. INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType
  354. CONTROL_FEATURE_UNIT, // bDescriptorSubtype
  355. 0x02, // bUnitID
  356. 0x01, // bSourceID
  357. 0x01, // bControlSize
  358. CONTROL_MUTE |
  359. CONTROL_VOLUME, // bmaControls(0)
  360. 0x00, // bmaControls(1)
  361. 0x00, // iTerminal
  362. // Audio Output Terminal (Speaker)
  363. OUTPUT_TERMINAL_DESCRIPTOR_LENGTH, // bLength
  364. INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType
  365. CONTROL_OUTPUT_TERMINAL, // bDescriptorSubtype
  366. 0x03, // bTerminalID
  367. LSB(TERMINAL_SPEAKER), // wTerminalType
  368. MSB(TERMINAL_SPEAKER), // wTerminalType
  369. 0x00, // bAssocTerminal
  370. 0x02, // bSourceID
  371. 0x00, // iTerminal
  372. // Audio Input Terminal (Microphone)
  373. INPUT_TERMINAL_DESCRIPTOR_LENGTH, // bLength
  374. INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType
  375. CONTROL_INPUT_TERMINAL, // bDescriptorSubtype
  376. 0x04, // bTerminalID
  377. LSB(TERMINAL_MICROPHONE), // wTerminalType
  378. MSB(TERMINAL_MICROPHONE), // wTerminalType
  379. 0x00, // bAssocTerminal
  380. channel_nb_out, // bNrChannels
  381. (uint8_t)(LSB(channel_config_out)), // wChannelConfig
  382. (uint8_t)(MSB(channel_config_out)), // wChannelConfig
  383. 0x00, // iChannelNames
  384. 0x00, // iTerminal
  385. // Audio Output Terminal (Microphone)
  386. OUTPUT_TERMINAL_DESCRIPTOR_LENGTH, // bLength
  387. INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType
  388. CONTROL_OUTPUT_TERMINAL, // bDescriptorSubtype
  389. 0x05, // bTerminalID
  390. LSB(TERMINAL_USB_STREAMING), // wTerminalType
  391. MSB(TERMINAL_USB_STREAMING), // wTerminalType
  392. 0x00, // bAssocTerminal
  393. 0x04, // bSourceID
  394. 0x00, // iTerminal
  395. // Interface 1, Alternate Setting 0, Audio Streaming - Zero Bandwith
  396. INTERFACE_DESCRIPTOR_LENGTH, // bLength
  397. INTERFACE_DESCRIPTOR, // bDescriptorType
  398. 0x01, // bInterfaceNumber
  399. 0x00, // bAlternateSetting
  400. 0x00, // bNumEndpoints
  401. AUDIO_CLASS, // bInterfaceClass
  402. SUBCLASS_AUDIOSTREAMING, // bInterfaceSubClass
  403. 0x00, // bInterfaceProtocol
  404. 0x00, // iInterface
  405. // Interface 1, Alternate Setting 1, Audio Streaming - Operational
  406. INTERFACE_DESCRIPTOR_LENGTH, // bLength
  407. INTERFACE_DESCRIPTOR, // bDescriptorType
  408. 0x01, // bInterfaceNumber
  409. 0x01, // bAlternateSetting
  410. 0x01, // bNumEndpoints
  411. AUDIO_CLASS, // bInterfaceClass
  412. SUBCLASS_AUDIOSTREAMING, // bInterfaceSubClass
  413. 0x00, // bInterfaceProtocol
  414. 0x00, // iInterface
  415. // Audio Streaming Interface
  416. STREAMING_INTERFACE_DESCRIPTOR_LENGTH, // bLength
  417. INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType
  418. STREAMING_GENERAL, // bDescriptorSubtype
  419. 0x01, // bTerminalLink
  420. 0x00, // bDelay
  421. LSB(FORMAT_PCM), // wFormatTag
  422. MSB(FORMAT_PCM), // wFormatTag
  423. // Audio Type I Format
  424. FORMAT_TYPE_I_DESCRIPTOR_LENGTH, // bLength
  425. INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType
  426. STREAMING_FORMAT_TYPE, // bDescriptorSubtype
  427. FORMAT_TYPE_I, // bFormatType
  428. channel_nb_in, // bNrChannels
  429. 0x02, // bSubFrameSize
  430. 16, // bBitResolution
  431. 0x01, // bSamFreqType
  432. (uint8_t)(LSB(FREQ_IN)), // tSamFreq
  433. (uint8_t)((FREQ_IN >> 8) & 0xff), // tSamFreq
  434. (uint8_t)((FREQ_IN >> 16) & 0xff), // tSamFreq
  435. // Endpoint - Standard Descriptor
  436. ENDPOINT_DESCRIPTOR_LENGTH + 2, // bLength
  437. ENDPOINT_DESCRIPTOR, // bDescriptorType
  438. PHY_TO_DESC(EPISO_OUT), // bEndpointAddress
  439. E_ISOCHRONOUS, // bmAttributes
  440. (uint8_t)(LSB(PACKET_SIZE_ISO_IN)), // wMaxPacketSize
  441. (uint8_t)(MSB(PACKET_SIZE_ISO_IN)), // wMaxPacketSize
  442. 0x01, // bInterval
  443. 0x00, // bRefresh
  444. 0x00, // bSynchAddress
  445. // Endpoint - Audio Streaming
  446. STREAMING_ENDPOINT_DESCRIPTOR_LENGTH, // bLength
  447. ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType
  448. ENDPOINT_GENERAL, // bDescriptor
  449. 0x00, // bmAttributes
  450. 0x00, // bLockDelayUnits
  451. LSB(0x0000), // wLockDelay
  452. MSB(0x0000), // wLockDelay
  453. // Interface 1, Alternate Setting 0, Audio Streaming - Zero Bandwith
  454. INTERFACE_DESCRIPTOR_LENGTH, // bLength
  455. INTERFACE_DESCRIPTOR, // bDescriptorType
  456. 0x02, // bInterfaceNumber
  457. 0x00, // bAlternateSetting
  458. 0x00, // bNumEndpoints
  459. AUDIO_CLASS, // bInterfaceClass
  460. SUBCLASS_AUDIOSTREAMING, // bInterfaceSubClass
  461. 0x00, // bInterfaceProtocol
  462. 0x00, // iInterface
  463. // Interface 1, Alternate Setting 1, Audio Streaming - Operational
  464. INTERFACE_DESCRIPTOR_LENGTH, // bLength
  465. INTERFACE_DESCRIPTOR, // bDescriptorType
  466. 0x02, // bInterfaceNumber
  467. 0x01, // bAlternateSetting
  468. 0x01, // bNumEndpoints
  469. AUDIO_CLASS, // bInterfaceClass
  470. SUBCLASS_AUDIOSTREAMING, // bInterfaceSubClass
  471. 0x00, // bInterfaceProtocol
  472. 0x00, // iInterface
  473. // Audio Streaming Interface
  474. STREAMING_INTERFACE_DESCRIPTOR_LENGTH, // bLength
  475. INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType
  476. SUBCLASS_AUDIOCONTROL, // bDescriptorSubtype
  477. 0x05, // bTerminalLink (output terminal microphone)
  478. 0x01, // bDelay
  479. 0x01, // wFormatTag
  480. 0x00, // wFormatTag
  481. // Audio Type I Format
  482. FORMAT_TYPE_I_DESCRIPTOR_LENGTH, // bLength
  483. INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType
  484. SUBCLASS_AUDIOSTREAMING, // bDescriptorSubtype
  485. FORMAT_TYPE_I, // bFormatType
  486. channel_nb_out, // bNrChannels
  487. 0x02, // bSubFrameSize
  488. 0x10, // bBitResolution
  489. 0x01, // bSamFreqType
  490. (uint8_t)(LSB(FREQ_OUT)), // tSamFreq
  491. (uint8_t)((FREQ_OUT >> 8) & 0xff), // tSamFreq
  492. (uint8_t)((FREQ_OUT >> 16) & 0xff), // tSamFreq
  493. // Endpoint - Standard Descriptor
  494. ENDPOINT_DESCRIPTOR_LENGTH + 2, // bLength
  495. ENDPOINT_DESCRIPTOR, // bDescriptorType
  496. PHY_TO_DESC(EPISO_IN), // bEndpointAddress
  497. E_ISOCHRONOUS, // bmAttributes
  498. (uint8_t)(LSB(PACKET_SIZE_ISO_OUT)), // wMaxPacketSize
  499. (uint8_t)(MSB(PACKET_SIZE_ISO_OUT)), // wMaxPacketSize
  500. 0x01, // bInterval
  501. 0x00, // bRefresh
  502. 0x00, // bSynchAddress
  503. // Endpoint - Audio Streaming
  504. STREAMING_ENDPOINT_DESCRIPTOR_LENGTH, // bLength
  505. ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType
  506. ENDPOINT_GENERAL, // bDescriptor
  507. 0x00, // bmAttributes
  508. 0x00, // bLockDelayUnits
  509. LSB(0x0000), // wLockDelay
  510. MSB(0x0000), // wLockDelay
  511. // Terminator
  512. 0 // bLength
  513. };
  514. return configDescriptor;
  515. }
  516. uint8_t * USBAudio::stringIinterfaceDesc() {
  517. static uint8_t stringIinterfaceDescriptor[] = {
  518. 0x0c, //bLength
  519. STRING_DESCRIPTOR, //bDescriptorType 0x03
  520. 'A',0,'u',0,'d',0,'i',0,'o',0 //bString iInterface - Audio
  521. };
  522. return stringIinterfaceDescriptor;
  523. }
  524. uint8_t * USBAudio::stringIproductDesc() {
  525. static uint8_t stringIproductDescriptor[] = {
  526. 0x16, //bLength
  527. STRING_DESCRIPTOR, //bDescriptorType 0x03
  528. 'M',0,'b',0,'e',0,'d',0,' ',0,'A',0,'u',0,'d',0,'i',0,'o',0 //bString iProduct - Mbed Audio
  529. };
  530. return stringIproductDescriptor;
  531. }