mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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