LPC11U35 ADC Tick & USBSerial

Dependencies:   mbed

Dependents:   SmallDoseMeter_SingleCH_AE_lpc11u35_V1_00

Committer:
H_Tsunemoto
Date:
Mon Feb 19 08:51:33 2018 +0000
Revision:
0:871ab6846b18
test

Who changed what in which revision?

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