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