This is early stages of my project, the idea of this project is to be able to mix a guitar with windows sounds in reverse such as instrumental background music or trance music perhaps or maybe another fellow guitarist you may have downloaded from the internet. Microphone or guitar pin is p19 I would use a microphone for drums:) and that it for the moment, the code makes the mbed act as usb speaker that excepts a guitar or microphone input, but with a twist it all in reverse like a guitar reverse effects pedal but only you can mix anything you can get from the internet or any windows sound.

Dependencies:   mbed

Committer:
mbed2f
Date:
Sun Jan 08 17:28:24 2012 +0000
Revision:
0:7610d342c76e

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed2f 0:7610d342c76e 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
mbed2f 0:7610d342c76e 2 *
mbed2f 0:7610d342c76e 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
mbed2f 0:7610d342c76e 4 * and associated documentation files (the "Software"), to deal in the Software without
mbed2f 0:7610d342c76e 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
mbed2f 0:7610d342c76e 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
mbed2f 0:7610d342c76e 7 * Software is furnished to do so, subject to the following conditions:
mbed2f 0:7610d342c76e 8 *
mbed2f 0:7610d342c76e 9 * The above copyright notice and this permission notice shall be included in all copies or
mbed2f 0:7610d342c76e 10 * substantial portions of the Software.
mbed2f 0:7610d342c76e 11 *
mbed2f 0:7610d342c76e 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
mbed2f 0:7610d342c76e 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
mbed2f 0:7610d342c76e 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
mbed2f 0:7610d342c76e 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed2f 0:7610d342c76e 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
mbed2f 0:7610d342c76e 17 */
mbed2f 0:7610d342c76e 18
mbed2f 0:7610d342c76e 19 #include "stdint.h"
mbed2f 0:7610d342c76e 20 #include "USBCDC.h"
mbed2f 0:7610d342c76e 21 #include "USBBusInterface.h"
mbed2f 0:7610d342c76e 22
mbed2f 0:7610d342c76e 23 static uint8_t cdc_line_coding[7]= {0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x08};
mbed2f 0:7610d342c76e 24
mbed2f 0:7610d342c76e 25 #define DEFAULT_CONFIGURATION (1)
mbed2f 0:7610d342c76e 26
mbed2f 0:7610d342c76e 27 #define CDC_SET_LINE_CODING 0x20
mbed2f 0:7610d342c76e 28 #define CDC_GET_LINE_CODING 0x21
mbed2f 0:7610d342c76e 29 #define CDC_SET_CONTROL_LINE_STATE 0x22
mbed2f 0:7610d342c76e 30
mbed2f 0:7610d342c76e 31 #define MAX_CDC_REPORT_SIZE MAX_PACKET_SIZE_EPBULK
mbed2f 0:7610d342c76e 32
mbed2f 0:7610d342c76e 33 USBCDC::USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release) {
mbed2f 0:7610d342c76e 34 USBDevice::connect();
mbed2f 0:7610d342c76e 35 }
mbed2f 0:7610d342c76e 36
mbed2f 0:7610d342c76e 37 bool USBCDC::USBCallback_request(void) {
mbed2f 0:7610d342c76e 38 /* Called in ISR context */
mbed2f 0:7610d342c76e 39
mbed2f 0:7610d342c76e 40 bool success = false;
mbed2f 0:7610d342c76e 41 CONTROL_TRANSFER * transfer = getTransferPtr();
mbed2f 0:7610d342c76e 42
mbed2f 0:7610d342c76e 43 /* Process class-specific requests */
mbed2f 0:7610d342c76e 44
mbed2f 0:7610d342c76e 45 if (transfer->setup.bmRequestType.Type == CLASS_TYPE) {
mbed2f 0:7610d342c76e 46 switch (transfer->setup.bRequest) {
mbed2f 0:7610d342c76e 47 case CDC_GET_LINE_CODING:
mbed2f 0:7610d342c76e 48 transfer->remaining = 7;
mbed2f 0:7610d342c76e 49 transfer->ptr = cdc_line_coding;
mbed2f 0:7610d342c76e 50 transfer->direction = DEVICE_TO_HOST;
mbed2f 0:7610d342c76e 51 success = true;
mbed2f 0:7610d342c76e 52 break;
mbed2f 0:7610d342c76e 53 case CDC_SET_LINE_CODING:
mbed2f 0:7610d342c76e 54 transfer->remaining = 7;
mbed2f 0:7610d342c76e 55 success = true;
mbed2f 0:7610d342c76e 56 break;
mbed2f 0:7610d342c76e 57 case CDC_SET_CONTROL_LINE_STATE:
mbed2f 0:7610d342c76e 58 success = true;
mbed2f 0:7610d342c76e 59 break;
mbed2f 0:7610d342c76e 60 default:
mbed2f 0:7610d342c76e 61 break;
mbed2f 0:7610d342c76e 62 }
mbed2f 0:7610d342c76e 63 }
mbed2f 0:7610d342c76e 64
mbed2f 0:7610d342c76e 65 return success;
mbed2f 0:7610d342c76e 66 }
mbed2f 0:7610d342c76e 67
mbed2f 0:7610d342c76e 68
mbed2f 0:7610d342c76e 69 // Called in ISR context
mbed2f 0:7610d342c76e 70 // Set configuration. Return false if the
mbed2f 0:7610d342c76e 71 // configuration is not supported.
mbed2f 0:7610d342c76e 72 bool USBCDC::USBCallback_setConfiguration(uint8_t configuration) {
mbed2f 0:7610d342c76e 73 if (configuration != DEFAULT_CONFIGURATION) {
mbed2f 0:7610d342c76e 74 return false;
mbed2f 0:7610d342c76e 75 }
mbed2f 0:7610d342c76e 76
mbed2f 0:7610d342c76e 77 // Configure endpoints > 0
mbed2f 0:7610d342c76e 78 addEndpoint(EPINT_IN, MAX_PACKET_SIZE_EPINT);
mbed2f 0:7610d342c76e 79 addEndpoint(EPBULK_IN, MAX_PACKET_SIZE_EPBULK);
mbed2f 0:7610d342c76e 80 addEndpoint(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
mbed2f 0:7610d342c76e 81
mbed2f 0:7610d342c76e 82 // We activate the endpoint to be able to recceive data
mbed2f 0:7610d342c76e 83 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
mbed2f 0:7610d342c76e 84 return true;
mbed2f 0:7610d342c76e 85 }
mbed2f 0:7610d342c76e 86
mbed2f 0:7610d342c76e 87 bool USBCDC::send(uint8_t * buffer, uint16_t size) {
mbed2f 0:7610d342c76e 88 return USBDevice::write(EPBULK_IN, buffer, size, MAX_CDC_REPORT_SIZE);
mbed2f 0:7610d342c76e 89 }
mbed2f 0:7610d342c76e 90
mbed2f 0:7610d342c76e 91 bool USBCDC::readEP(uint8_t * buffer, uint16_t * size) {
mbed2f 0:7610d342c76e 92 if (!USBDevice::readEP(EPBULK_OUT, buffer, size, MAX_CDC_REPORT_SIZE))
mbed2f 0:7610d342c76e 93 return false;
mbed2f 0:7610d342c76e 94 if (!readStart(EPBULK_OUT, MAX_CDC_REPORT_SIZE))
mbed2f 0:7610d342c76e 95 return false;
mbed2f 0:7610d342c76e 96 return true;
mbed2f 0:7610d342c76e 97 }
mbed2f 0:7610d342c76e 98
mbed2f 0:7610d342c76e 99 bool USBCDC::readEP_NB(uint8_t * buffer, uint16_t * size) {
mbed2f 0:7610d342c76e 100 if (!USBDevice::readEP_NB(EPBULK_OUT, buffer, size, MAX_CDC_REPORT_SIZE))
mbed2f 0:7610d342c76e 101 return false;
mbed2f 0:7610d342c76e 102 if (!readStart(EPBULK_OUT, MAX_CDC_REPORT_SIZE))
mbed2f 0:7610d342c76e 103 return false;
mbed2f 0:7610d342c76e 104 return true;
mbed2f 0:7610d342c76e 105 }
mbed2f 0:7610d342c76e 106
mbed2f 0:7610d342c76e 107
mbed2f 0:7610d342c76e 108 uint8_t * USBCDC::deviceDesc() {
mbed2f 0:7610d342c76e 109 static uint8_t deviceDescriptor[] = {
mbed2f 0:7610d342c76e 110 18, // bLength
mbed2f 0:7610d342c76e 111 1, // bDescriptorType
mbed2f 0:7610d342c76e 112 0x10, 0x01, // bcdUSB
mbed2f 0:7610d342c76e 113 2, // bDeviceClass
mbed2f 0:7610d342c76e 114 0, // bDeviceSubClass
mbed2f 0:7610d342c76e 115 0, // bDeviceProtocol
mbed2f 0:7610d342c76e 116 MAX_PACKET_SIZE_EP0, // bMaxPacketSize0
mbed2f 0:7610d342c76e 117 LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor
mbed2f 0:7610d342c76e 118 LSB(PRODUCT_ID), MSB(PRODUCT_ID),// idProduct
mbed2f 0:7610d342c76e 119 0x00, 0x01, // bcdDevice
mbed2f 0:7610d342c76e 120 1, // iManufacturer
mbed2f 0:7610d342c76e 121 2, // iProduct
mbed2f 0:7610d342c76e 122 3, // iSerialNumber
mbed2f 0:7610d342c76e 123 1 // bNumConfigurations
mbed2f 0:7610d342c76e 124 };
mbed2f 0:7610d342c76e 125 return deviceDescriptor;
mbed2f 0:7610d342c76e 126 }
mbed2f 0:7610d342c76e 127
mbed2f 0:7610d342c76e 128 uint8_t * USBCDC::stringIinterfaceDesc() {
mbed2f 0:7610d342c76e 129 static uint8_t stringIinterfaceDescriptor[] = {
mbed2f 0:7610d342c76e 130 0x08,
mbed2f 0:7610d342c76e 131 STRING_DESCRIPTOR,
mbed2f 0:7610d342c76e 132 'C',0,'D',0,'C',0,
mbed2f 0:7610d342c76e 133 };
mbed2f 0:7610d342c76e 134 return stringIinterfaceDescriptor;
mbed2f 0:7610d342c76e 135 }
mbed2f 0:7610d342c76e 136
mbed2f 0:7610d342c76e 137 uint8_t * USBCDC::stringIproductDesc() {
mbed2f 0:7610d342c76e 138 static uint8_t stringIproductDescriptor[] = {
mbed2f 0:7610d342c76e 139 0x16,
mbed2f 0:7610d342c76e 140 STRING_DESCRIPTOR,
mbed2f 0:7610d342c76e 141 'C',0,'D',0,'C',0,' ',0,'D',0,'E',0,'V',0,'I',0,'C',0,'E',0
mbed2f 0:7610d342c76e 142 };
mbed2f 0:7610d342c76e 143 return stringIproductDescriptor;
mbed2f 0:7610d342c76e 144 }
mbed2f 0:7610d342c76e 145
mbed2f 0:7610d342c76e 146
mbed2f 0:7610d342c76e 147 #define CONFIG1_DESC_SIZE (9+9+5+5+4+5+7+9+7+7)
mbed2f 0:7610d342c76e 148
mbed2f 0:7610d342c76e 149 uint8_t * USBCDC::configurationDesc() {
mbed2f 0:7610d342c76e 150 static uint8_t configDescriptor[] = {
mbed2f 0:7610d342c76e 151 9, // bLength;
mbed2f 0:7610d342c76e 152 2, // bDescriptorType;
mbed2f 0:7610d342c76e 153 LSB(CONFIG1_DESC_SIZE), // wTotalLength
mbed2f 0:7610d342c76e 154 MSB(CONFIG1_DESC_SIZE),
mbed2f 0:7610d342c76e 155 2, // bNumInterfaces
mbed2f 0:7610d342c76e 156 1, // bConfigurationValue
mbed2f 0:7610d342c76e 157 0, // iConfiguration
mbed2f 0:7610d342c76e 158 0x80, // bmAttributes
mbed2f 0:7610d342c76e 159 50, // bMaxPower
mbed2f 0:7610d342c76e 160
mbed2f 0:7610d342c76e 161 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
mbed2f 0:7610d342c76e 162 9, // bLength
mbed2f 0:7610d342c76e 163 4, // bDescriptorType
mbed2f 0:7610d342c76e 164 0, // bInterfaceNumber
mbed2f 0:7610d342c76e 165 0, // bAlternateSetting
mbed2f 0:7610d342c76e 166 1, // bNumEndpoints
mbed2f 0:7610d342c76e 167 0x02, // bInterfaceClass
mbed2f 0:7610d342c76e 168 0x02, // bInterfaceSubClass
mbed2f 0:7610d342c76e 169 0x01, // bInterfaceProtocol
mbed2f 0:7610d342c76e 170 0, // iInterface
mbed2f 0:7610d342c76e 171
mbed2f 0:7610d342c76e 172 // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
mbed2f 0:7610d342c76e 173 5, // bFunctionLength
mbed2f 0:7610d342c76e 174 0x24, // bDescriptorType
mbed2f 0:7610d342c76e 175 0x00, // bDescriptorSubtype
mbed2f 0:7610d342c76e 176 0x10, 0x01, // bcdCDC
mbed2f 0:7610d342c76e 177
mbed2f 0:7610d342c76e 178 // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
mbed2f 0:7610d342c76e 179 5, // bFunctionLength
mbed2f 0:7610d342c76e 180 0x24, // bDescriptorType
mbed2f 0:7610d342c76e 181 0x01, // bDescriptorSubtype
mbed2f 0:7610d342c76e 182 0x03, // bmCapabilities
mbed2f 0:7610d342c76e 183 1, // bDataInterface
mbed2f 0:7610d342c76e 184
mbed2f 0:7610d342c76e 185 // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
mbed2f 0:7610d342c76e 186 4, // bFunctionLength
mbed2f 0:7610d342c76e 187 0x24, // bDescriptorType
mbed2f 0:7610d342c76e 188 0x02, // bDescriptorSubtype
mbed2f 0:7610d342c76e 189 0x06, // bmCapabilities
mbed2f 0:7610d342c76e 190
mbed2f 0:7610d342c76e 191 // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
mbed2f 0:7610d342c76e 192 5, // bFunctionLength
mbed2f 0:7610d342c76e 193 0x24, // bDescriptorType
mbed2f 0:7610d342c76e 194 0x06, // bDescriptorSubtype
mbed2f 0:7610d342c76e 195 0, // bMasterInterface
mbed2f 0:7610d342c76e 196 1, // bSlaveInterface0
mbed2f 0:7610d342c76e 197
mbed2f 0:7610d342c76e 198 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
mbed2f 0:7610d342c76e 199 ENDPOINT_DESCRIPTOR_LENGTH, // bLength
mbed2f 0:7610d342c76e 200 ENDPOINT_DESCRIPTOR, // bDescriptorType
mbed2f 0:7610d342c76e 201 PHY_TO_DESC(EPINT_IN), // bEndpointAddress
mbed2f 0:7610d342c76e 202 E_INTERRUPT, // bmAttributes (0x03=intr)
mbed2f 0:7610d342c76e 203 LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
mbed2f 0:7610d342c76e 204 MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
mbed2f 0:7610d342c76e 205 16, // bInterval
mbed2f 0:7610d342c76e 206
mbed2f 0:7610d342c76e 207
mbed2f 0:7610d342c76e 208
mbed2f 0:7610d342c76e 209
mbed2f 0:7610d342c76e 210 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
mbed2f 0:7610d342c76e 211 9, // bLength
mbed2f 0:7610d342c76e 212 4, // bDescriptorType
mbed2f 0:7610d342c76e 213 1, // bInterfaceNumber
mbed2f 0:7610d342c76e 214 0, // bAlternateSetting
mbed2f 0:7610d342c76e 215 2, // bNumEndpoints
mbed2f 0:7610d342c76e 216 0x0A, // bInterfaceClass
mbed2f 0:7610d342c76e 217 0x00, // bInterfaceSubClass
mbed2f 0:7610d342c76e 218 0x00, // bInterfaceProtocol
mbed2f 0:7610d342c76e 219 0, // iInterface
mbed2f 0:7610d342c76e 220
mbed2f 0:7610d342c76e 221 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
mbed2f 0:7610d342c76e 222 7, // bLength
mbed2f 0:7610d342c76e 223 5, // bDescriptorType
mbed2f 0:7610d342c76e 224 PHY_TO_DESC(EPBULK_IN), // bEndpointAddress
mbed2f 0:7610d342c76e 225 0x02, // bmAttributes (0x02=bulk)
mbed2f 0:7610d342c76e 226 LSB(MAX_PACKET_SIZE_EPBULK), // wMaxPacketSize (LSB)
mbed2f 0:7610d342c76e 227 MSB(MAX_PACKET_SIZE_EPBULK), // wMaxPacketSize (MSB)
mbed2f 0:7610d342c76e 228 0, // bInterval
mbed2f 0:7610d342c76e 229
mbed2f 0:7610d342c76e 230 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
mbed2f 0:7610d342c76e 231 7, // bLength
mbed2f 0:7610d342c76e 232 5, // bDescriptorType
mbed2f 0:7610d342c76e 233 PHY_TO_DESC(EPBULK_OUT),// bEndpointAddress
mbed2f 0:7610d342c76e 234 0x02, // bmAttributes (0x02=bulk)
mbed2f 0:7610d342c76e 235 LSB(MAX_PACKET_SIZE_EPBULK), // wMaxPacketSize (LSB)
mbed2f 0:7610d342c76e 236 MSB(MAX_PACKET_SIZE_EPBULK), // wMaxPacketSize (MSB)
mbed2f 0:7610d342c76e 237 0 // bInterval
mbed2f 0:7610d342c76e 238 };
mbed2f 0:7610d342c76e 239 return configDescriptor;
mbed2f 0:7610d342c76e 240 }