Minor corrections to the library Doxygen documentation.
[pub/lufa.git] / Demos / Host / MouseHost / MouseHost.c
index 44f20b4..dd7ff73 100644 (file)
@@ -184,12 +184,24 @@ void ReadNextReport(void)
        USB_MouseReport_Data_t MouseReport;\r
        uint8_t                LEDMask = LEDS_NO_LEDS;\r
 \r
-       /* Select the mouse report data in pipe */\r
-       Pipe_SelectPipe(MOUSE_DATAPIPE);\r
+       /* Select mouse data pipe */\r
+       Pipe_SelectPipe(MOUSE_DATAPIPE);        \r
+\r
+       #if !defined(INTERRUPT_DATA_PIPE)\r
+       /* Unfreeze mouse data pipe */\r
+       Pipe_Unfreeze();\r
+       #endif\r
 \r
        /* Ensure pipe contains data and is ready to be read before continuing */\r
        if (!(Pipe_ReadWriteAllowed()))\r
-         return;\r
+       {\r
+               #if !defined(INTERRUPT_DATA_PIPE)\r
+               /* Refreeze mouse data pipe */\r
+               Pipe_Freeze();\r
+               #endif\r
+\r
+               return;\r
+       }\r
 \r
        /* Read in mouse report data */\r
        Pipe_Read_Stream_LE(&MouseReport, sizeof(MouseReport));                         \r
@@ -219,6 +231,11 @@ void ReadNextReport(void)
        printf_P(PSTR("dX:%2d dY:%2d Button:%d\r\n"), MouseReport.X,\r
                                                                                                  MouseReport.Y,\r
                                                                                                  MouseReport.Button);\r
+\r
+       #if !defined(INTERRUPT_DATA_PIPE)\r
+       /* Refreeze mouse data pipe */\r
+       Pipe_Freeze();\r
+       #endif\r
 }\r
 \r
 /** Task to set the configuration of the attached device after it has been enumerated, and to read and process\r
@@ -303,22 +320,21 @@ TASK(USB_Mouse_Host)
                                break;\r
                        }\r
 \r
+                       #if defined(INTERRUPT_DATA_PIPE)                        \r
+                       /* Select and unfreeze mouse data pipe */\r
+                       Pipe_SelectPipe(MOUSE_DATAPIPE);        \r
+                       Pipe_Unfreeze();\r
+                       #endif\r
+\r
                        puts_P(PSTR("Mouse Enumerated.\r\n"));\r
                        \r
                        USB_HostState = HOST_STATE_Ready;\r
                        break;\r
                #if !defined(INTERRUPT_DATA_PIPE)\r
                case HOST_STATE_Ready:\r
-                       /* Select and unfreeze mouse data pipe */\r
-                       Pipe_SelectPipe(MOUSE_DATAPIPE);\r
-                       Pipe_Unfreeze();\r
-\r
                        /* If a report has been received, read and process it */\r
-                       if (Pipe_ReadWriteAllowed())\r
-                         ReadNextReport();\r
+                       ReadNextReport();\r
 \r
-                       /* Freeze mouse data pipe */\r
-                       Pipe_Freeze();\r
                        break;\r
                #endif\r
        }\r
@@ -330,6 +346,9 @@ TASK(USB_Mouse_Host)
  */\r
 ISR(ENDPOINT_PIPE_vect, ISR_BLOCK)\r
 {\r
+       /* Save previously selected pipe before selecting a new pipe */\r
+       uint8_t PrevSelectedPipe = Pipe_GetCurrentPipe();\r
+\r
        /* Check to see if the mouse data pipe has caused the interrupt */\r
        if (Pipe_HasPipeInterrupted(MOUSE_DATAPIPE))\r
        {\r
@@ -347,5 +366,8 @@ ISR(ENDPOINT_PIPE_vect, ISR_BLOCK)
                        ReadNextReport();\r
                }\r
        }\r
+\r
+       /* Restore previously selected pipe */\r
+       Pipe_SelectPipe(PrevSelectedPipe);\r
 }\r
 #endif\r