Finished basic documentation of all device mode class drivers.
[pub/lufa.git] / Bootloaders / DFU / BootloaderDFU.c
index 00c1ea5..6da741e 100644 (file)
@@ -139,7 +139,7 @@ int main (void)
 /** Event handler for the USB_Disconnect event. This indicates that the bootloader should exit and the user\r
  *  application started.\r
  */\r
-EVENT_HANDLER(USB_Disconnect)\r
+void EVENT_USB_Disconnect(void)\r
 {\r
        /* Upon disconnection, run user application */\r
        RunBootloader = false;\r
@@ -149,21 +149,15 @@ EVENT_HANDLER(USB_Disconnect)
  *  control requests that are not handled internally by the USB library (including the DFU commands, which are\r
  *  all issued via the control endpoint), so that they can be handled appropriately for the application.\r
  */\r
-EVENT_HANDLER(USB_UnhandledControlPacket)\r
+void EVENT_USB_UnhandledControlPacket(void)\r
 {\r
-       /* Discard unused wIndex value */\r
-       Endpoint_Discard_Word();\r
-       \r
-       /* Discard unused wValue value */\r
-       Endpoint_Discard_Word();\r
-\r
        /* Get the size of the command and data from the wLength value */\r
-       SentCommand.DataSize = Endpoint_Read_Word_LE();\r
+       SentCommand.DataSize = USB_ControlRequest.wLength;\r
 \r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case DFU_DNLOAD:\r
-                       Endpoint_ClearControlSETUP();\r
+                       Endpoint_ClearSETUP();\r
                        \r
                        /* Check if bootloader is waiting to terminate */\r
                        if (WaitForExit)\r
@@ -235,7 +229,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                                        /* Check if endpoint is empty - if so clear it and wait until ready for next packet */\r
                                                        if (!(Endpoint_BytesInEndpoint()))\r
                                                        {\r
-                                                               Endpoint_ClearControlOUT();\r
+                                                               Endpoint_ClearOUT();\r
                                                                while (!(Endpoint_IsOUTReceived()));\r
                                                        }\r
 \r
@@ -279,7 +273,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                                        /* Check if endpoint is empty - if so clear it and wait until ready for next packet */\r
                                                        if (!(Endpoint_BytesInEndpoint()))\r
                                                        {\r
-                                                               Endpoint_ClearControlOUT();\r
+                                                               Endpoint_ClearOUT();\r
                                                                while (!(Endpoint_IsOUTReceived()));\r
                                                        }\r
 \r
@@ -296,15 +290,15 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                }\r
                        }\r
 \r
-                       Endpoint_ClearControlOUT();\r
+                       Endpoint_ClearOUT();\r
 \r
                        /* Acknowledge status stage */\r
                        while (!(Endpoint_IsINReady()));\r
-                       Endpoint_ClearControlIN();\r
+                       Endpoint_ClearIN();\r
                                \r
                        break;\r
                case DFU_UPLOAD:\r
-                       Endpoint_ClearControlSETUP();\r
+                       Endpoint_ClearSETUP();\r
 \r
                        while (!(Endpoint_IsINReady()));\r
 \r
@@ -343,12 +337,12 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                                /* Check if endpoint is full - if so clear it and wait until ready for next packet */\r
                                                if (Endpoint_BytesInEndpoint() == FIXED_CONTROL_ENDPOINT_SIZE)\r
                                                {\r
-                                                       Endpoint_ClearControlIN();\r
+                                                       Endpoint_ClearIN();\r
                                                        while (!(Endpoint_IsINReady()));\r
                                                }\r
 \r
                                                /* Read the flash word and send it via USB to the host */\r
-                                               #if defined(RAMPZ)\r
+                                               #if (FLASHEND > 0xFFFF)\r
                                                        Endpoint_Write_Word_LE(pgm_read_word_far(CurrFlashAddress.Long));\r
                                                #else\r
                                                        Endpoint_Write_Word_LE(pgm_read_word(CurrFlashAddress.Long));                                                   \r
@@ -368,7 +362,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                                /* Check if endpoint is full - if so clear it and wait until ready for next packet */\r
                                                if (Endpoint_BytesInEndpoint() == FIXED_CONTROL_ENDPOINT_SIZE)\r
                                                {\r
-                                                       Endpoint_ClearControlIN();\r
+                                                       Endpoint_ClearIN();\r
                                                        while (!(Endpoint_IsINReady()));\r
                                                }\r
 \r
@@ -384,15 +378,15 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                DFU_State = dfuIDLE;\r
                        }\r
 \r
-                       Endpoint_ClearControlIN();\r
+                       Endpoint_ClearIN();\r
 \r
                        /* Acknowledge status stage */\r
                        while (!(Endpoint_IsOUTReceived()));\r
-                       Endpoint_ClearControlOUT();\r
+                       Endpoint_ClearOUT();\r
 \r
                        break;\r
                case DFU_GETSTATUS:\r
-                       Endpoint_ClearControlSETUP();\r
+                       Endpoint_ClearSETUP();\r
                        \r
                        /* Write 8-bit status value */\r
                        Endpoint_Write_Byte(DFU_Status);\r
@@ -407,46 +401,46 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        /* Write 8-bit state string ID number */\r
                        Endpoint_Write_Byte(0);\r
 \r
-                       Endpoint_ClearControlIN();\r
+                       Endpoint_ClearIN();\r
                        \r
                        /* Acknowledge status stage */\r
                        while (!(Endpoint_IsOUTReceived()));\r
-                       Endpoint_ClearControlOUT();\r
+                       Endpoint_ClearOUT();\r
        \r
                        break;          \r
                case DFU_CLRSTATUS:\r
-                       Endpoint_ClearControlSETUP();\r
+                       Endpoint_ClearSETUP();\r
                        \r
                        /* Reset the status value variable to the default OK status */\r
                        DFU_Status = OK;\r
 \r
                        /* Acknowledge status stage */\r
                        while (!(Endpoint_IsINReady()));\r
-                       Endpoint_ClearControlIN();\r
+                       Endpoint_ClearIN();\r
                        \r
                        break;\r
                case DFU_GETSTATE:\r
-                       Endpoint_ClearControlSETUP();\r
+                       Endpoint_ClearSETUP();\r
                        \r
                        /* Write the current device state to the endpoint */\r
                        Endpoint_Write_Byte(DFU_State);\r
                \r
-                       Endpoint_ClearControlIN();\r
+                       Endpoint_ClearIN();\r
                        \r
                        /* Acknowledge status stage */\r
                        while (!(Endpoint_IsOUTReceived()));\r
-                       Endpoint_ClearControlOUT();\r
+                       Endpoint_ClearOUT();\r
 \r
                        break;\r
                case DFU_ABORT:\r
-                       Endpoint_ClearControlSETUP();\r
+                       Endpoint_ClearSETUP();\r
                        \r
                        /* Reset the current state variable to the default idle state */\r
                        DFU_State = dfuIDLE;\r
                        \r
                        /* Acknowledge status stage */\r
                        while (!(Endpoint_IsINReady()));\r
-                       Endpoint_ClearControlIN();\r
+                       Endpoint_ClearIN();\r
 \r
                        break;\r
        }\r
@@ -463,13 +457,15 @@ static void DiscardFillerBytes(uint8_t NumberOfBytes)
        {\r
                if (!(Endpoint_BytesInEndpoint()))\r
                {\r
-                       Endpoint_ClearControlOUT();\r
+                       Endpoint_ClearOUT();\r
 \r
                        /* Wait until next data packet received */\r
                        while (!(Endpoint_IsOUTReceived()));\r
                }\r
-\r
-               Endpoint_Discard_Byte();                                                \r
+               else\r
+               {\r
+                       Endpoint_Discard_Byte();\r
+               }\r
        }\r
 }\r
 \r
@@ -591,7 +587,7 @@ static void ProcessMemReadCommand(void)
                while (CurrFlashAddress < BOOT_START_ADDR)\r
                {\r
                        /* Check if the current byte is not blank */\r
-                       #if defined(RAMPZ)\r
+                       #if (FLASHEND > 0xFFFF)\r
                        if (pgm_read_byte_far(CurrFlashAddress) != 0xFF)\r
                        #else\r
                        if (pgm_read_byte(CurrFlashAddress) != 0xFF)\r