Added module file dependancy information to the USB class drivers.
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / DevChapter9.c
index f02bb56..f49f5b3 100644 (file)
@@ -62,7 +62,8 @@ void USB_Device_ProcessControlPacket(void)
                        break;\r
                case REQ_ClearFeature:\r
                case REQ_SetFeature:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT))\r
+                       if ((bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE)) ||\r
+                           (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT)))\r
                        {\r
                                USB_Device_ClearSetFeature();\r
                                RequestHandled = true;\r
@@ -105,7 +106,7 @@ void USB_Device_ProcessControlPacket(void)
        }\r
 \r
        if (!(RequestHandled))\r
-         RAISE_EVENT(USB_UnhandledControlPacket);\r
+         EVENT_USB_UnhandledControlPacket();\r
          \r
        if (Endpoint_IsSETUPReceived())\r
        {\r
@@ -118,8 +119,6 @@ static void USB_Device_SetAddress(void)
 {\r
        Endpoint_ClearSETUP();\r
        \r
-       while (!(Endpoint_IsINReady()));\r
-       \r
        Endpoint_ClearIN();\r
        \r
        while (!(Endpoint_IsINReady()));\r
@@ -138,7 +137,7 @@ static void USB_Device_SetConfiguration(void)
 #else\r
        USB_Descriptor_Device_t* DevDescriptorPtr;\r
 \r
-       if ((USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DevDescriptorPtr) == NO_DESCRIPTOR) ||\r
+       if ((CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DevDescriptorPtr) == NO_DESCRIPTOR) ||\r
        #if defined(USE_RAM_DESCRIPTORS)\r
            ((uint8_t)USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations))\r
        #elif defined (USE_EEPROM_DESCRIPTORS)\r
@@ -158,9 +157,9 @@ static void USB_Device_SetConfiguration(void)
        Endpoint_ClearIN();\r
 \r
        if (!(AlreadyConfigured) && USB_ConfigurationNumber)\r
-         RAISE_EVENT(USB_DeviceEnumerationComplete);\r
+         EVENT_USB_DeviceEnumerationComplete();\r
 \r
-       RAISE_EVENT(USB_ConfigurationChanged);\r
+       EVENT_USB_ConfigurationChanged();\r
 }\r
 \r
 void USB_Device_GetConfiguration(void)\r
@@ -180,54 +179,74 @@ static void USB_Device_GetDescriptor(void)
        void*    DescriptorPointer;\r
        uint16_t DescriptorSize;\r
        \r
-       if ((DescriptorSize = USB_GetDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex, &DescriptorPointer)) == NO_DESCRIPTOR)\r
-         return;\r
-       \r
-       Endpoint_ClearSETUP();\r
-       \r
-       #if defined(USE_RAM_DESCRIPTORS)\r
-       Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize);\r
-       #else\r
-       bool SendZLP;\r
-       \r
-       if (USB_ControlRequest.wLength > DescriptorSize)\r
-         USB_ControlRequest.wLength = DescriptorSize;\r
-       \r
-       while (USB_ControlRequest.wLength)\r
+       #if !defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))\r
+       if (USB_ControlRequest.wValue == ((DTYPE_String << 8) | USE_INTERNAL_SERIAL))\r
        {\r
-               while (!(Endpoint_IsINReady()))\r
+               struct\r
                {\r
-                       if (Endpoint_IsOUTReceived())\r
-                       {\r
-                               Endpoint_ClearOUT();\r
-                               return;\r
-                       }               \r
-               }\r
+                       USB_Descriptor_Header_t Header;\r
+                       int16_t                 UnicodeString[12];\r
+               } SignatureDescriptor;\r
+\r
+               #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES)\r
+                       SignatureDescriptor.Header.Size            = sizeof(SignatureDescriptor);\r
+                       SignatureDescriptor.Header.Type            = DTYPE_String;\r
+               #else\r
+                       SignatureDescriptor.Header.bLength         = sizeof(SignatureDescriptor);\r
+                       SignatureDescriptor.Header.bDescriptorType = DTYPE_String;\r
+               #endif\r
                \r
-               while (USB_ControlRequest.wLength && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
+               uint8_t  SigReadAddress  = 0x0E;                \r
+               bool     OddRead         = false;\r
+\r
+               for (uint8_t SerialCharNum = 0; SerialCharNum < 12; SerialCharNum++)\r
                {\r
-                       #if defined (USE_EEPROM_DESCRIPTORS)\r
-                       Endpoint_Write_Byte(eeprom_read_byte(DescriptorPointer++));                     \r
-                       #else\r
-                       Endpoint_Write_Byte(pgm_read_byte(DescriptorPointer++));\r
-                       #endif\r
+                       uint8_t SerialByte = boot_signature_byte_get(SigReadAddress);\r
+                       \r
+                       if (OddRead)\r
+                       {\r
+                               SerialByte >>= 4;\r
+                               SigReadAddress++;\r
+                       }\r
+                       else\r
+                       {\r
+                               SerialByte &= 0x0F;\r
+                       }\r
                        \r
-                       USB_ControlRequest.wLength--;\r
+                       OddRead = !(OddRead);\r
+\r
+                       if (SerialByte < 0x0A)\r
+                         SerialByte += '0';\r
+                       else\r
+                         SerialByte += ('A' - 0x0A);\r
+\r
+                       SignatureDescriptor.UnicodeString[SerialCharNum] = SerialByte;\r
                }\r
                \r
-               SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
-               Endpoint_ClearIN();\r
+               Endpoint_ClearSETUP();\r
+               Endpoint_Write_Control_Stream_LE(&SignatureDescriptor, sizeof(SignatureDescriptor));\r
+               Endpoint_ClearOUT();\r
+\r
+               return;\r
        }\r
+       #endif\r
        \r
-       if (SendZLP)\r
+       if ((DescriptorSize = CALLBACK_USB_GetDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex,\r
+                                                        &DescriptorPointer)) == NO_DESCRIPTOR)\r
        {\r
-               while (!(Endpoint_IsINReady()));\r
-               Endpoint_ClearIN();\r
+               return;\r
        }\r
+       \r
+       Endpoint_ClearSETUP();\r
 \r
-       while (!(Endpoint_IsOUTReceived()));\r
+       #if defined(USE_RAM_DESCRIPTORS)\r
+       Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize);\r
+       #elif defined(USE_EEPROM_DESCRIPTORS)\r
+       Endpoint_Write_Control_EStream_LE(DescriptorPointer, DescriptorSize);\r
+       #else\r
+       Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize);   \r
        #endif\r
-       \r
+\r
        Endpoint_ClearOUT();\r
 }\r
 \r
@@ -299,7 +318,7 @@ static void USB_Device_ClearSetFeature(void)
                                        }\r
                                        else\r
                                        {\r
-                                               Endpoint_StallTransaction();                                            \r
+                                               Endpoint_StallTransaction();\r
                                        }\r
                                }\r
                        }\r
@@ -313,9 +332,6 @@ static void USB_Device_ClearSetFeature(void)
        Endpoint_ClearSETUP();\r
 \r
        Endpoint_ClearIN();\r
-\r
-       while (!(Endpoint_IsOUTReceived()));\r
-       Endpoint_ClearOUT();\r
 }\r
 \r
 #endif\r