Add new MIDIHost LowLevel demo application.
[pub/USBasp.git] / Bootloaders / TeensyHID / TeensyHID.c
index ee6c91a..bb5a0c7 100644 (file)
@@ -33,7 +33,6 @@
  *  Main source file for the TeensyHID bootloader. This file contains the complete bootloader logic.\r
  */\r
  \r
-#define  INCLUDE_FROM_TEENSYHID_C\r
 #include "TeensyHID.h"\r
 \r
 /* Global Variables: */\r
@@ -49,6 +48,24 @@ bool RunBootloader = true;
  */\r
 int main(void)\r
 {\r
+       /* Setup hardware required for the bootloader */\r
+       SetupHardware();\r
+       \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
+       /* Enable the watchdog and force a timeout to reset the AVR */\r
+       wdt_enable(WDTO_250MS);\r
+                                       \r
+       for (;;);\r
+}\r
+\r
+/** Configures all hardware required for the bootloader. */\r
+void SetupHardware(void)\r
+{\r
        /* Disable watchdog if enabled by bootloader/fuses */\r
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
@@ -62,26 +79,12 @@ int main(void)
 \r
        /* Initialize USB subsystem */\r
        USB_Init();\r
-       \r
-       while (RunBootloader)\r
-         USB_USBTask();\r
-         \r
-       /* Shut down the USB interface, so that the host will register the disconnection */\r
-       USB_ShutDown();\r
-\r
-       /* Wait 100ms to give the host time to register the disconnection */\r
-       _delay_ms(100);\r
-\r
-       /* Enable the watchdog and force a timeout to reset the AVR */\r
-       wdt_enable(WDTO_250MS);\r
-                                       \r
-       for (;;);\r
 }\r
 \r
 /** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready\r
  *  to relay data to and from the attached USB host.\r
  */\r
-void EVENT_USB_ConfigurationChanged(void)\r
+void EVENT_USB_Device_ConfigurationChanged(void)\r
 {\r
        /* Setup HID Report Endpoint */\r
        Endpoint_ConfigureEndpoint(HID_EPNUM, EP_TYPE_INTERRUPT,\r
@@ -89,11 +92,11 @@ void EVENT_USB_ConfigurationChanged(void)
                                   ENDPOINT_BANK_SINGLE);\r
 }\r
 \r
-/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific\r
+/** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific\r
  *  control requests that are not handled internally by the USB library (including the HID commands, which are\r
  *  all issued via the control endpoint), so that they can be handled appropriately for the application.\r
  */\r
-void EVENT_USB_UnhandledControlPacket(void)\r
+void EVENT_USB_Device_UnhandledControlRequest(void)\r
 {\r
        /* Handle HID Class specific requests */\r
        switch (USB_ControlRequest.bRequest)\r
@@ -105,7 +108,7 @@ void EVENT_USB_UnhandledControlPacket(void)
                                \r
                                /* Wait until the command (report) has been sent by the host */\r
                                while (!(Endpoint_IsOUTReceived()));\r
-\r
+                       \r
                                /* Read in the write destination address */\r
                                uint16_t PageAddress = Endpoint_Read_Word_LE();\r
                                \r
@@ -144,9 +147,7 @@ void EVENT_USB_UnhandledControlPacket(void)
 \r
                                Endpoint_ClearOUT();\r
 \r
-                               /* Acknowledge status stage */\r
-                               while (!(Endpoint_IsINReady()));\r
-                               Endpoint_ClearIN();\r
+                               Endpoint_ClearStatusStage();\r
                        }\r
                        \r
                        break;\r