Renamed NO_CLEARSET_FEATURE_REQUEST compile time token to NO_FEATURELESS_CONTROL_ONLY...
[pub/USBasp.git] / Demos / KeyboardViaInt / KeyboardViaInt.c
index 7f6fcd8..1e724e6 100644 (file)
@@ -76,8 +76,8 @@ int main(void)
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
 \r
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
 \r
-       /* Disable Clock Division */\r
-       SetSystemClockPrescaler(0);\r
+       /* Disable clock division */\r
+       clock_prescale_set(clock_div_1);\r
 \r
        /* Hardware Initialization */\r
        Joystick_Init();\r
 \r
        /* Hardware Initialization */\r
        Joystick_Init();\r
@@ -211,10 +211,8 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                /* Clear the endpoint data */\r
                                Endpoint_ClearSetupOUT();\r
 \r
                                /* Clear the endpoint data */\r
                                Endpoint_ClearSetupOUT();\r
 \r
-                               /* Wait until the host is ready to receive the request confirmation */\r
+                               /* Acknowledge status stage */\r
                                while (!(Endpoint_IsSetupINReady()));\r
                                while (!(Endpoint_IsSetupINReady()));\r
-                               \r
-                               /* Handshake the request by sending an empty IN packet */\r
                                Endpoint_ClearSetupIN();\r
                        }\r
                        \r
                                Endpoint_ClearSetupIN();\r
                        }\r
                        \r
@@ -229,6 +227,10 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                \r
                                /* Send the flag to the host */\r
                                Endpoint_ClearSetupIN();\r
                                \r
                                /* Send the flag to the host */\r
                                Endpoint_ClearSetupIN();\r
+\r
+                               /* Acknowledge status stage */\r
+                               while (!(Endpoint_IsSetupOUTReceived()));\r
+                               Endpoint_ClearSetupOUT();\r
                        }\r
                        \r
                        break;\r
                        }\r
                        \r
                        break;\r
@@ -243,7 +245,8 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                /* Set or clear the flag depending on what the host indicates that the current Protocol should be */\r
                                UsingReportProtocol = (wValue != 0x0000);\r
                                \r
                                /* Set or clear the flag depending on what the host indicates that the current Protocol should be */\r
                                UsingReportProtocol = (wValue != 0x0000);\r
                                \r
-                               /* Send an empty packet to acknowedge the command */\r
+                               /* Acknowledge status stage */\r
+                               while (!(Endpoint_IsSetupINReady()));\r
                                Endpoint_ClearSetupIN();\r
                        }\r
                        \r
                                Endpoint_ClearSetupIN();\r
                        }\r
                        \r
@@ -259,7 +262,8 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                /* Get idle period in MSB */\r
                                IdleCount = (wValue >> 8);\r
                                \r
                                /* Get idle period in MSB */\r
                                IdleCount = (wValue >> 8);\r
                                \r
-                               /* Send an empty packet to acknowedge the command */\r
+                               /* Acknowledge status stage */\r
+                               while (!(Endpoint_IsSetupINReady()));\r
                                Endpoint_ClearSetupIN();\r
                        }\r
                        \r
                                Endpoint_ClearSetupIN();\r
                        }\r
                        \r
@@ -274,6 +278,10 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                \r
                                /* Send the flag to the host */\r
                                Endpoint_ClearSetupIN();\r
                                \r
                                /* Send the flag to the host */\r
                                Endpoint_ClearSetupIN();\r
+\r
+                               /* Acknowledge status stage */\r
+                               while (!(Endpoint_IsSetupOUTReceived()));\r
+                               Endpoint_ClearSetupOUT();\r
                        }\r
 \r
                        break;\r
                        }\r
 \r
                        break;\r
@@ -391,7 +399,16 @@ ISR(ENDPOINT_PIPE_vect, ISR_BLOCK)
        {\r
                USB_KeyboardReport_Data_t KeyboardReportData;\r
                bool                      SendReport;\r
        {\r
                USB_KeyboardReport_Data_t KeyboardReportData;\r
                bool                      SendReport;\r
-       \r
+\r
+               /* Select the Keyboard Report Endpoint */\r
+               Endpoint_SelectEndpoint(KEYBOARD_EPNUM);\r
+\r
+               /* Clear the endpoint IN interrupt flag */\r
+               USB_INT_Clear(ENDPOINT_INT_IN);\r
+\r
+               /* Clear the Keyboard Report endpoint interrupt */\r
+               Endpoint_ClearEndpointInterrupt(KEYBOARD_EPNUM);\r
+\r
                /* Create the next keyboard report for transmission to the host */\r
                SendReport = GetNextReport(&KeyboardReportData);\r
        \r
                /* Create the next keyboard report for transmission to the host */\r
                SendReport = GetNextReport(&KeyboardReportData);\r
        \r
@@ -408,15 +425,6 @@ ISR(ENDPOINT_PIPE_vect, ISR_BLOCK)
                /* Check to see if a report should be issued */\r
                if (SendReport)\r
                {\r
                /* Check to see if a report should be issued */\r
                if (SendReport)\r
                {\r
-                       /* Select the Keyboard Report Endpoint */\r
-                       Endpoint_SelectEndpoint(KEYBOARD_EPNUM);\r
-\r
-                       /* Clear the endpoint IN interrupt flag */\r
-                       USB_INT_Clear(ENDPOINT_INT_IN);\r
-\r
-                       /* Clear the Keyboard Report endpoint interrupt */\r
-                       Endpoint_ClearEndpointInterrupt(KEYBOARD_EPNUM);\r
-\r
                        /* Write Keyboard Report Data */\r
                        Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));\r
                }\r
                        /* Write Keyboard Report Data */\r
                        Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));\r
                }\r