aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/KeyboardHost
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-03-20 05:39:15 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-03-20 05:39:15 +0000
commitecf7538430c01b95104682f0f7493e57b9168125 (patch)
tree5243014d8735f14a0841f793738c8ca51f46f783 /Demos/KeyboardHost
parentee7bd5685e000b3a128069fd75d436c653ab54b2 (diff)
downloadlufa-ecf7538430c01b95104682f0f7493e57b9168125.tar.gz
lufa-ecf7538430c01b95104682f0f7493e57b9168125.tar.bz2
lufa-ecf7538430c01b95104682f0f7493e57b9168125.zip
Combined Keyboad and Mouse normal and interrupt driven host demos into unified Keyboard and Mouse host demos.
Diffstat (limited to 'Demos/KeyboardHost')
-rw-r--r--Demos/KeyboardHost/ConfigDescriptor.c11
-rw-r--r--Demos/KeyboardHost/KeyboardHost.c118
-rw-r--r--Demos/KeyboardHost/KeyboardHost.h2
-rw-r--r--Demos/KeyboardHost/KeyboardHost.txt13
4 files changed, 101 insertions, 43 deletions
diff --git a/Demos/KeyboardHost/ConfigDescriptor.c b/Demos/KeyboardHost/ConfigDescriptor.c
index 7a704cfc8..9d1a630ad 100644
--- a/Demos/KeyboardHost/ConfigDescriptor.c
+++ b/Demos/KeyboardHost/ConfigDescriptor.c
@@ -77,7 +77,7 @@ uint8_t ProcessConfigurationDescriptor(void)
/* Get the keyboard interface's data endpoint descriptor */
if (USB_Host_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,
- NextInterfaceKeyboardDataEndpoint))
+ NextInterfaceKeyboardDataEndpoint))
{
/* Descriptor not found, error out */
return NoEndpointFound;
@@ -91,6 +91,15 @@ uint8_t ProcessConfigurationDescriptor(void)
EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE);
Pipe_SetInfiniteINRequests();
+
+ #if defined(INTERRUPT_DATA_PIPE)
+ Pipe_SetInterruptPeriod(EndpointData->PollingIntervalMS);
+
+ /* Enable the pipe IN interrupt for the data pipe */
+ USB_INT_Enable(PIPE_INT_IN);
+ #endif
+
+ Pipe_Unfreeze();
/* Valid data found, return success */
return SuccessfulConfigRead;
diff --git a/Demos/KeyboardHost/KeyboardHost.c b/Demos/KeyboardHost/KeyboardHost.c
index 74d65550e..6249e5291 100644
--- a/Demos/KeyboardHost/KeyboardHost.c
+++ b/Demos/KeyboardHost/KeyboardHost.c
@@ -176,6 +176,56 @@ void UpdateStatus(uint8_t CurrentStatus)
LEDs_SetAllLEDs(LEDMask);
}
+/** Reads in and processes the next report from the attached device, displaying the report
+ * contents on the board LEDs and via the serial port.
+ */
+void ReadNextReport(void)
+{
+ USB_KeyboardReport_Data_t KeyboardReport;
+
+ /* Select the keyboard report data in pipe */
+ Pipe_SelectPipe(KEYBOARD_DATAPIPE);
+
+ /* Ensure pipe contains data and is ready to be read before continuing */
+ if (!(Pipe_ReadWriteAllowed()))
+ return;
+
+ /* Read in keyboard report data */
+ Pipe_Read_Stream_LE(&KeyboardReport, sizeof(KeyboardReport));
+
+ /* Clear the IN endpoint, ready for next data packet */
+ Pipe_ClearCurrentBank();
+
+ /* Indicate if the modifier byte is non-zero (special key such as shift is being pressed) */
+ LEDs_ChangeLEDs(LEDS_LED1, (KeyboardReport.Modifier) ? LEDS_LED1 : 0);
+
+ /* Check if a key has been pressed */
+ if (KeyboardReport.KeyCode)
+ {
+ /* Toggle status LED to indicate keypress */
+ if (LEDs_GetLEDs() & LEDS_LED2)
+ LEDs_TurnOffLEDs(LEDS_LED2);
+ else
+ LEDs_TurnOnLEDs(LEDS_LED2);
+
+ char PressedKey = 0;
+
+ /* Retrieve pressed key character if alphanumeric */
+ if ((KeyboardReport.KeyCode >= 0x04) && (KeyboardReport.KeyCode <= 0x1D))
+ PressedKey = (KeyboardReport.KeyCode - 0x04) + 'A';
+ else if ((KeyboardReport.KeyCode >= 0x1E) && (KeyboardReport.KeyCode <= 0x27))
+ PressedKey = (KeyboardReport.KeyCode - 0x1E) + '0';
+ else if (KeyboardReport.KeyCode == 0x2C)
+ PressedKey = ' ';
+ else if (KeyboardReport.KeyCode == 0x28)
+ PressedKey = '\n';
+
+ /* Print the pressed key character out through the serial port if valid */
+ if (PressedKey)
+ putchar(PressedKey);
+ }
+}
+
/** Task to set the configuration of the attached device after it has been enumerated, and to read and process
* HID reports from the device and display the results onto the board LEDs.
*/
@@ -261,54 +311,44 @@ TASK(USB_Keyboard_Host)
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();
- /* Check if data has been received from the attached keyboard */
+ /* If a report has been received, read and process it */
if (Pipe_ReadWriteAllowed())
- {
- USB_KeyboardReport_Data_t KeyboardReport;
-
- /* Read in keyboard report data */
- Pipe_Read_Stream_LE(&KeyboardReport, sizeof(KeyboardReport));
-
- /* Clear the IN endpoint, ready for next data packet */
- Pipe_ClearCurrentBank();
-
- /* Indicate if the modifier byte is non-zero */
- LEDs_ChangeLEDs(LEDS_LED1, (KeyboardReport.Modifier) ? LEDS_LED1 : 0);
-
- /* Check if a key has been pressed */
- if (KeyboardReport.KeyCode)
- {
- /* Toggle status LED to indicate keypress */
- if (LEDs_GetLEDs() & LEDS_LED2)
- LEDs_TurnOffLEDs(LEDS_LED2);
- else
- LEDs_TurnOnLEDs(LEDS_LED2);
-
- char PressedKey = 0;
-
- /* Retrieve pressed key character if alphanumeric */
- if ((KeyboardReport.KeyCode >= 0x04) && (KeyboardReport.KeyCode <= 0x1D))
- PressedKey = (KeyboardReport.KeyCode - 0x04) + 'A';
- else if ((KeyboardReport.KeyCode >= 0x1E) && (KeyboardReport.KeyCode <= 0x27))
- PressedKey = (KeyboardReport.KeyCode - 0x1E) + '0';
- else if (KeyboardReport.KeyCode == 0x2C)
- PressedKey = ' ';
- else if (KeyboardReport.KeyCode == 0x28)
- PressedKey = '\n';
-
- /* Print the pressed key character out through the serial port if valid */
- if (PressedKey)
- putchar(PressedKey);
- }
- }
+ ReadNextReport();
/* Freeze keyboard data pipe */
Pipe_Freeze();
break;
+ #endif
+ }
+}
+
+#if defined(INTERRUPT_DATA_PIPE)
+/** Interrupt handler for the Endpoint/Pipe interrupt vector. This interrupt fires each time an enabled
+ * pipe interrupt occurs on a pipe which has had that interrupt enabled.
+ */
+ISR(ENDPOINT_PIPE_vect, ISR_BLOCK)
+{
+ /* Check to see if the keyboard data pipe has caused the interrupt */
+ if (Pipe_HasPipeInterrupted(KEYBOARD_DATAPIPE))
+ {
+ /* Clear the pipe interrupt, and select the keyboard pipe */
+ Pipe_ClearPipeInterrupt(KEYBOARD_DATAPIPE);
+ Pipe_SelectPipe(KEYBOARD_DATAPIPE);
+
+ /* Check to see if the pipe IN interrupt has fired */
+ if (USB_INT_HasOccurred(PIPE_INT_IN) && USB_INT_IsEnabled(PIPE_INT_IN))
+ {
+ /* Clear interrupt flag */
+ USB_INT_Clear(PIPE_INT_IN);
+
+ /* Read and process the next report from the device */
+ ReadNextReport();
}
}
+#endif
diff --git a/Demos/KeyboardHost/KeyboardHost.h b/Demos/KeyboardHost/KeyboardHost.h
index 388e50f52..8c1a70915 100644
--- a/Demos/KeyboardHost/KeyboardHost.h
+++ b/Demos/KeyboardHost/KeyboardHost.h
@@ -41,6 +41,7 @@
#include <avr/wdt.h>
#include <avr/pgmspace.h>
#include <avr/power.h>
+ #include <avr/interrupt.h>
#include <stdio.h>
#include <LUFA/Version.h> // Library Version Information
@@ -92,5 +93,6 @@
/* Function Prototypes: */
void UpdateStatus(uint8_t CurrentStatus);
+ void ReadNextReport(void);
#endif
diff --git a/Demos/KeyboardHost/KeyboardHost.txt b/Demos/KeyboardHost/KeyboardHost.txt
index db0e14ad6..6d536fb86 100644
--- a/Demos/KeyboardHost/KeyboardHost.txt
+++ b/Demos/KeyboardHost/KeyboardHost.txt
@@ -56,9 +56,16 @@
*
* <table>
* <tr>
- * <td>
- * None
- * </td>
+ * <td><b>Define Name:</b></td>
+ * <td><b>Location:</b></td>
+ * <td><b>Description:</b></td>
+ * </tr>
+ * <tr>
+ * <td>INTERRUPT_DATA_ENDPOINT</td>
+ * <td>Makefile CDEFS</td>
+ * <td>When defined, this causes the demo to enable interrupts for the data pipe,
+ * which services reports from the device. If not defined, the data pipe is
+ * serviced via polling using the task scheduler.</td>
* </tr>
* </table>
*/ \ No newline at end of file