Remove serial driver use from the AVRISP project now that it is no longer needed.
[pub/USBasp.git] / Bootloaders / TeensyHID / TeensyHID.c
index 84ec7aa..585cffd 100644 (file)
@@ -52,12 +52,12 @@ int main(void)
        while (RunBootloader)\r
          USB_USBTask();\r
        \r
-       /* Turn off the USB interface, disconnect from the host */\r
-       USB_ShutDown();\r
+       /* Disconnect from the host - USB interface will be reset later along with the AVR */\r
+       USB_Detach();\r
 \r
        /* Enable the watchdog and force a timeout to reset the AVR */\r
        wdt_enable(WDTO_250MS);\r
-                                       \r
+\r
        for (;;);\r
 }\r
 \r
@@ -100,53 +100,50 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
        switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_SetReport:\r
-                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
-                       {\r
-                               Endpoint_ClearSETUP();\r
-                               \r
-                               /* Wait until the command has been sent by the host */\r
-                               while (!(Endpoint_IsOUTReceived()));\r
+                       Endpoint_ClearSETUP();\r
                        \r
-                               /* Read in the write destination address */\r
-                               uint16_t PageAddress = Endpoint_Read_Word_LE();\r
+                       /* Wait until the command has been sent by the host */\r
+                       while (!(Endpoint_IsOUTReceived()));\r
+               \r
+                       /* Read in the write destination address */\r
+                       uint16_t PageAddress = Endpoint_Read_Word_LE();\r
+                       \r
+                       /* Check if the command is a program page command, or a start application command */\r
+                       if (PageAddress == TEENSY_STARTAPPLICATION)\r
+                       {\r
+                               RunBootloader = false;\r
+                       }\r
+                       else\r
+                       {\r
+                               /* Erase the given FLASH page, ready to be programmed */\r
+                               boot_page_erase(PageAddress);\r
+                               boot_spm_busy_wait();\r
                                \r
-                               /* Check if the command is a program page command, or a start application command */\r
-                               if (PageAddress == TEENSY_STARTAPPLICATION)\r
-                               {\r
-                                       RunBootloader = false;\r
-                               }\r
-                               else\r
+                               /* Write each of the FLASH page's bytes in sequence */\r
+                               for (uint8_t PageByte = 0; PageByte < SPM_PAGESIZE; PageByte += 2)\r
                                {\r
-                                       /* Erase the given FLASH page, ready to be programmed */\r
-                                       boot_page_erase(PageAddress);\r
-                                       boot_spm_busy_wait();\r
-                                       \r
-                                       /* Write each of the FLASH page's bytes in sequence */\r
-                                       for (uint8_t PageByte = 0; PageByte < SPM_PAGESIZE; PageByte += 2)\r
+                                       /* Check if endpoint is empty - if so clear it and wait until ready for next packet */\r
+                                       if (!(Endpoint_BytesInEndpoint()))\r
                                        {\r
-                                               /* Check if endpoint is empty - if so clear it and wait until ready for next packet */\r
-                                               if (!(Endpoint_BytesInEndpoint()))\r
-                                               {\r
-                                                       Endpoint_ClearOUT();\r
-                                                       while (!(Endpoint_IsOUTReceived()));\r
-                                               }\r
-\r
-                                               /* Write the next data word to the FLASH page */\r
-                                               boot_page_fill(PageAddress + PageByte, Endpoint_Read_Word_LE());\r
+                                               Endpoint_ClearOUT();\r
+                                               while (!(Endpoint_IsOUTReceived()));\r
                                        }\r
 \r
-                                       /* Write the filled FLASH page to memory */\r
-                                       boot_page_write(PageAddress);\r
-                                       boot_spm_busy_wait();\r
-\r
-                                       /* Re-enable RWW section */\r
-                                       boot_rww_enable();\r
+                                       /* Write the next data word to the FLASH page */\r
+                                       boot_page_fill(PageAddress + PageByte, Endpoint_Read_Word_LE());\r
                                }\r
 \r
-                               Endpoint_ClearOUT();\r
+                               /* Write the filled FLASH page to memory */\r
+                               boot_page_write(PageAddress);\r
+                               boot_spm_busy_wait();\r
 \r
-                               Endpoint_ClearStatusStage();\r
+                               /* Re-enable RWW section */\r
+                               boot_rww_enable();\r
                        }\r
+\r
+                       Endpoint_ClearOUT();\r
+\r
+                       Endpoint_ClearStatusStage();\r
                        \r
                        break;\r
        }\r