usb device library

Fork of USBDevice by mbed official

Committer:
samux
Date:
Tue Jul 17 14:30:29 2012 +0000
Revision:
1:80ab0d068708
Update USBDevice lib

Who changed what in which revision?

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