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