USBAudio example using a microphone

Dependencies:   USBDevice mbed

Revision:
8:caede7b4c444
Parent:
0:539ec61e1fbb
--- a/USBDevice/USBDevice/USBDevice.cpp	Tue Dec 20 11:41:31 2011 +0000
+++ b/USBDevice/USBDevice/USBDevice.cpp	Wed Dec 21 10:43:57 2011 +0000
@@ -12,6 +12,8 @@
 #include "USBDescriptor.h"
 #include "USBHID_Types.h"
 
+//#define DEBUG
+
 
 /* Device status */
 #define DEVICE_STATUS_SELF_POWERED  (1U<<0)
@@ -32,7 +34,9 @@
 bool USBDevice::requestGetDescriptor(void)
 {
     bool success = false;
-
+#ifdef DEBUG
+    printf("get descr: type: %d\r\n", DESCRIPTOR_TYPE(transfer.setup.wValue));
+#endif
     switch (DESCRIPTOR_TYPE(transfer.setup.wValue))
     {
         case DEVICE_DESCRIPTOR:
@@ -41,6 +45,9 @@
                 if ((deviceDesc()[0] == DEVICE_DESCRIPTOR_LENGTH) \
                     && (deviceDesc()[1] == DEVICE_DESCRIPTOR))
                 {
+#ifdef DEBUG
+                    printf("device descr\r\n");
+#endif
                     transfer.remaining = DEVICE_DESCRIPTOR_LENGTH;
                     transfer.ptr = deviceDesc();
                     transfer.direction = DEVICE_TO_HOST;
@@ -54,6 +61,9 @@
                 if ((configurationDesc()[0] == CONFIGURATION_DESCRIPTOR_LENGTH) \
                     && (configurationDesc()[1] == CONFIGURATION_DESCRIPTOR))
                 {
+#ifdef DEBUG
+                    printf("conf descr request\r\n");
+#endif
                     /* Get wTotalLength */
                     transfer.remaining = configurationDesc()[2] \
                         | (configurationDesc()[3] << 8);
@@ -65,39 +75,60 @@
             }
             break;
         case STRING_DESCRIPTOR:
+#ifdef DEBUG
+            printf("str descriptor\r\n");
+#endif
             switch (DESCRIPTOR_INDEX(transfer.setup.wValue))
             {
                             case STRING_OFFSET_LANGID:
+#ifdef DEBUG
+                                printf("1\r\n");
+#endif
                                 transfer.remaining = stringLangidDesc()[0];
                                 transfer.ptr = stringLangidDesc();
                                 transfer.direction = DEVICE_TO_HOST;
                                 success = true;
                                 break;
                             case STRING_OFFSET_IMANUFACTURER:
+#ifdef DEBUG
+                                printf("2\r\n");
+#endif
                                 transfer.remaining =  stringImanufacturerDesc()[0];
                                 transfer.ptr = stringImanufacturerDesc();
                                 transfer.direction = DEVICE_TO_HOST;
                                 success = true;
                                 break;       
                             case STRING_OFFSET_IPRODUCT:
+#ifdef DEBUG
+                                printf("3\r\n");
+#endif
                                 transfer.remaining = stringIproductDesc()[0];
                                 transfer.ptr = stringIproductDesc();
                                 transfer.direction = DEVICE_TO_HOST;
                                 success = true;
                                 break;            
                             case STRING_OFFSET_ISERIAL:
+#ifdef DEBUG
+                                printf("4\r\n");
+#endif
                                 transfer.remaining = stringIserialDesc()[0];
                                 transfer.ptr = stringIserialDesc();
                                 transfer.direction = DEVICE_TO_HOST;
                                 success = true;
                                 break;        
                             case STRING_OFFSET_ICONFIGURATION:
+#ifdef DEBUG
+                                printf("5\r\n");
+#endif
                                 transfer.remaining = stringIConfigurationDesc()[0];
                                 transfer.ptr = stringIConfigurationDesc();
                                 transfer.direction = DEVICE_TO_HOST;
                                 success = true;
                                 break; 
                             case STRING_OFFSET_IINTERFACE:
+#ifdef DEBUG
+                                printf("6\r\n");
+#endif
                                 transfer.remaining = stringIinterfaceDesc()[0];
                                 transfer.ptr = stringIinterfaceDesc();
                                 transfer.direction = DEVICE_TO_HOST;
@@ -106,10 +137,19 @@
             }
             break;
         case INTERFACE_DESCRIPTOR:
+#ifdef DEBUG
+            printf("interface descr\r\n");
+#endif
         case ENDPOINT_DESCRIPTOR:
+#ifdef DEBUG
+            printf("endpoint descr\r\n");
+#endif
             /* TODO: Support is optional, not implemented here */
             break;
         default:
+#ifdef DEBUG
+            printf("ERROR\r\n");
+#endif
             break;
     }
 
@@ -496,6 +536,16 @@
     transfer.direction = 0;
     transfer.zlp = false;
     transfer.notify = false;
+    
+#ifdef DEBUG
+    printf("dataTransferDirection: %d\r\nType: %d\r\nRecipient: %d\r\nbRequest: %d\r\nwValue: %d\r\nwIndex: %d\r\nwLength: %d\r\n",transfer.setup.bmRequestType.dataTransferDirection,
+                                                                                                                                   transfer.setup.bmRequestType.Type,
+                                                                                                                                   transfer.setup.bmRequestType.Recipient,
+                                                                                                                                   transfer.setup.bRequest,
+                                                                                                                                   transfer.setup.wValue,
+                                                                                                                                   transfer.setup.wIndex,
+                                                                                                                                   transfer.setup.wLength);
+#endif
 
     /* Class / vendor specific */
     success = USBCallback_request();
@@ -505,6 +555,9 @@
         /* Standard requests */
         if (!requestSetup())
         {
+#ifdef DEBUG
+            printf("fail!!!!\r\n");
+#endif
             return false;
         }
     }
@@ -623,6 +676,7 @@
 
 void USBDevice::EP0in(void)
 {
+    printf("EP0IN\r\n");
     /* Endpoint 0 IN data event */
     if (!controlIn())
     {