aboutsummaryrefslogtreecommitdiff
path: root/Demos/MouseHost
diff options
context:
space:
mode:
Diffstat (limited to 'Demos/MouseHost')
-rw-r--r--Demos/MouseHost/ConfigDescriptor.c8
-rw-r--r--Demos/MouseHost/MouseHost.c111
-rw-r--r--Demos/MouseHost/MouseHost.h2
-rw-r--r--Demos/MouseHost/MouseHost.txt13
-rw-r--r--Demos/MouseHost/makefile1
5 files changed, 96 insertions, 39 deletions
diff --git a/Demos/MouseHost/ConfigDescriptor.c b/Demos/MouseHost/ConfigDescriptor.c
index 645f6c80..b45cc645 100644
--- a/Demos/MouseHost/ConfigDescriptor.c
+++ b/Demos/MouseHost/ConfigDescriptor.c
@@ -91,6 +91,14 @@ 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 */
diff --git a/Demos/MouseHost/MouseHost.c b/Demos/MouseHost/MouseHost.c
index ee7aec9d..44f20b43 100644
--- a/Demos/MouseHost/MouseHost.c
+++ b/Demos/MouseHost/MouseHost.c
@@ -176,6 +176,51 @@ 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_MouseReport_Data_t MouseReport;
+ uint8_t LEDMask = LEDS_NO_LEDS;
+
+ /* Select the mouse report data in pipe */
+ Pipe_SelectPipe(MOUSE_DATAPIPE);
+
+ /* Ensure pipe contains data and is ready to be read before continuing */
+ if (!(Pipe_ReadWriteAllowed()))
+ return;
+
+ /* Read in mouse report data */
+ Pipe_Read_Stream_LE(&MouseReport, sizeof(MouseReport));
+
+ /* Clear the IN endpoint, ready for next data packet */
+ Pipe_ClearCurrentBank();
+
+ /* Alter status LEDs according to mouse X movement */
+ if (MouseReport.X > 0)
+ LEDMask |= LEDS_LED1;
+ else if (MouseReport.X < 0)
+ LEDMask |= LEDS_LED2;
+
+ /* Alter status LEDs according to mouse Y movement */
+ if (MouseReport.Y > 0)
+ LEDMask |= LEDS_LED3;
+ else if (MouseReport.Y < 0)
+ LEDMask |= LEDS_LED4;
+
+ /* Alter status LEDs according to mouse button position */
+ if (MouseReport.Button)
+ LEDMask = LEDS_ALL_LEDS;
+
+ LEDs_SetAllLEDs(LEDMask);
+
+ /* Print mouse report data through the serial port */
+ printf_P(PSTR("dX:%2d dY:%2d Button:%d\r\n"), MouseReport.X,
+ MouseReport.Y,
+ MouseReport.Button);
+}
+
/** 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.
*/
@@ -262,49 +307,45 @@ TASK(USB_Mouse_Host)
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_SelectPipe(MOUSE_DATAPIPE);
Pipe_Unfreeze();
- /* Check if data has been received from the attached mouse */
+ /* If a report has been received, read and process it */
if (Pipe_ReadWriteAllowed())
- {
- USB_MouseReport_Data_t MouseReport;
- uint8_t LEDMask = LEDS_NO_LEDS;
-
- /* Read in mouse report data */
- Pipe_Read_Stream_LE(&MouseReport, sizeof(MouseReport));
-
- /* Clear the IN endpoint, ready for next data packet */
- Pipe_ClearCurrentBank();
-
- /* Alter status LEDs according to mouse X movement */
- if (MouseReport.X > 0)
- LEDMask |= LEDS_LED1;
- else if (MouseReport.X < 0)
- LEDMask |= LEDS_LED2;
-
- /* Alter status LEDs according to mouse Y movement */
- if (MouseReport.Y > 0)
- LEDMask |= LEDS_LED3;
- else if (MouseReport.Y < 0)
- LEDMask |= LEDS_LED4;
-
- /* Alter status LEDs according to mouse button position */
- if (MouseReport.Button)
- LEDMask = LEDS_ALL_LEDS;
-
- LEDs_SetAllLEDs(LEDMask);
-
- /* Print mouse report data through the serial port */
- printf_P(PSTR("dX:%2d dY:%2d Button:%d\r\n"), MouseReport.X,
- MouseReport.Y,
- MouseReport.Button);
- }
+ ReadNextReport();
/* Freeze mouse 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 mouse data pipe has caused the interrupt */
+ if (Pipe_HasPipeInterrupted(MOUSE_DATAPIPE))
+ {
+ /* Clear the pipe interrupt, and select the mouse pipe */
+ Pipe_ClearPipeInterrupt(MOUSE_DATAPIPE);
+ Pipe_SelectPipe(MOUSE_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/MouseHost/MouseHost.h b/Demos/MouseHost/MouseHost.h
index 1bd52ebe..b72e09cd 100644
--- a/Demos/MouseHost/MouseHost.h
+++ b/Demos/MouseHost/MouseHost.h
@@ -40,6 +40,7 @@
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/pgmspace.h>
+ #include <avr/interrupt.h>
#include <avr/power.h>
#include <stdio.h>
@@ -92,5 +93,6 @@
/* Function Prototypes: */
void UpdateStatus(uint8_t CurrentStatus);
+ void ReadNextReport(void);
#endif
diff --git a/Demos/MouseHost/MouseHost.txt b/Demos/MouseHost/MouseHost.txt
index a6d1ba82..d36c7313 100644
--- a/Demos/MouseHost/MouseHost.txt
+++ b/Demos/MouseHost/MouseHost.txt
@@ -57,9 +57,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
diff --git a/Demos/MouseHost/makefile b/Demos/MouseHost/makefile
index bdec6fa1..bbdb548f 100644
--- a/Demos/MouseHost/makefile
+++ b/Demos/MouseHost/makefile
@@ -180,7 +180,6 @@ CDEFS = -DF_CPU=$(F_CPU)UL -DF_CLOCK=$(F_CLOCK)UL -DBOARD=BOARD_$(BOARD)
CDEFS += -DUSE_NONSTANDARD_DESCRIPTOR_NAMES -DNO_STREAM_CALLBACKS -DUSB_HOST_ONLY
CDEFS += -DUSE_STATIC_OPTIONS="(USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
-
# Place -D or -U options here for ASM sources
ADEFS = -DF_CPU=$(F_CPU)