From 6198289b388e4122afe4913f899b37a8e7cd8af4 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Wed, 1 Apr 2009 07:21:45 +0000 Subject: Added new GenericHIDHost demo. Corrections to the KeyboardHost and MouseHost demos' pipe handling to freeze and unfreeze the data pipes at the point of use. --- Demos/Host/KeyboardHost/KeyboardHost.c | 38 ++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'Demos/Host/KeyboardHost/KeyboardHost.c') diff --git a/Demos/Host/KeyboardHost/KeyboardHost.c b/Demos/Host/KeyboardHost/KeyboardHost.c index 6249e5291..fe95c3493 100644 --- a/Demos/Host/KeyboardHost/KeyboardHost.c +++ b/Demos/Host/KeyboardHost/KeyboardHost.c @@ -183,13 +183,25 @@ void ReadNextReport(void) { USB_KeyboardReport_Data_t KeyboardReport; - /* Select the keyboard report data in pipe */ + /* Select keyboard data pipe */ Pipe_SelectPipe(KEYBOARD_DATAPIPE); + #if !defined(INTERRUPT_DATA_PIPE) + /* Unfreeze keyboard 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 keyboard data pipe */ + Pipe_Freeze(); + #endif + return; + } + /* Read in keyboard report data */ Pipe_Read_Stream_LE(&KeyboardReport, sizeof(KeyboardReport)); @@ -224,6 +236,11 @@ void ReadNextReport(void) if (PressedKey) putchar(PressedKey); } + + #if !defined(INTERRUPT_DATA_PIPE) + /* Refreeze keyboard data pipe */ + Pipe_Freeze(); + #endif } /** Task to set the configuration of the attached device after it has been enumerated, and to read and process @@ -307,22 +324,21 @@ TASK(USB_Keyboard_Host) break; } + #if defined(INTERRUPT_DATA_PIPE) + /* Select and unfreeze keyboard data pipe */ + Pipe_SelectPipe(KEYBOARD_DATAPIPE); + Pipe_Unfreeze(); + #endif + puts_P(PSTR("Keyboard Enumerated.\r\n")); - + USB_HostState = HOST_STATE_Ready; break; #if !defined(INTERRUPT_DATA_PIPE) case HOST_STATE_Ready: - /* Select and unfreeze keyboard data pipe */ - Pipe_SelectPipe(KEYBOARD_DATAPIPE); - Pipe_Unfreeze(); - /* If a report has been received, read and process it */ - if (Pipe_ReadWriteAllowed()) - ReadNextReport(); + ReadNextReport(); - /* Freeze keyboard data pipe */ - Pipe_Freeze(); break; #endif } -- cgit v1.2.3