Add Doxygen documentation to the completed portions of the PDI programming protocol...
[pub/USBasp.git] / Bootloaders / TeensyHID / TeensyHID.c
index bb5a0c7..84ec7aa 100644 (file)
  \r
 #include "TeensyHID.h"\r
 \r
-/* Global Variables: */\r
 /** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run\r
  *  via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application\r
  *  started via a forced watchdog reset.\r
  */\r
 bool RunBootloader = true;\r
 \r
-\r
 /** Main program entry point. This routine configures the hardware required by the bootloader, then continuously \r
  *  runs the bootloader processing routine until instructed to soft-exit.\r
  */\r
@@ -53,9 +51,9 @@ int main(void)
        \r
        while (RunBootloader)\r
          USB_USBTask();\r
-\r
-       /* Wait 100ms to give the host time to register the disconnection */\r
-       _delay_ms(100);\r
+       \r
+       /* Turn off the USB interface, disconnect from the host */\r
+       USB_ShutDown();\r
 \r
        /* Enable the watchdog and force a timeout to reset the AVR */\r
        wdt_enable(WDTO_250MS);\r
@@ -106,7 +104,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                        {\r
                                Endpoint_ClearSETUP();\r
                                \r
-                               /* Wait until the command (report) has been sent by the host */\r
+                               /* Wait until the command has been sent by the host */\r
                                while (!(Endpoint_IsOUTReceived()));\r
                        \r
                                /* Read in the write destination address */\r
@@ -124,7 +122,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                                        boot_spm_busy_wait();\r
                                        \r
                                        /* Write each of the FLASH page's bytes in sequence */\r
-                                       for (uint8_t PageByte = 0; PageByte < 128; PageByte += 2)\r
+                                       for (uint8_t PageByte = 0; PageByte < SPM_PAGESIZE; PageByte += 2)\r
                                        {\r
                                                /* Check if endpoint is empty - if so clear it and wait until ready for next packet */\r
                                                if (!(Endpoint_BytesInEndpoint()))\r