SD card interface

Committer:
lharoon
Date:
Mon Oct 08 11:14:07 2012 +0000
Revision:
0:22612ae617a0
1st edition

Who changed what in which revision?

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