From f93f73210892cec94a6ca446776879dee64484ed Mon Sep 17 00:00:00 2001
From: Dean Camera <dean@fourwalledcubicle.com>
Date: Wed, 4 Nov 2009 04:17:11 +0000
Subject: [PATCH] Update DevChapter9.c - use the Endpoint_ClearStatusStage()
 function where possible to reduce code size and (potentially) allow for
 centralized status stage timeouts.

Fix Joystick device demo HID descriptors - buttons should be placed outside the Pointer collection.
---
 .../Device/ClassDriver/Joystick/Descriptors.c | 22 ++++++++--------
 Demos/Device/LowLevel/Joystick/Descriptors.c  | 22 ++++++++--------
 LUFA/Drivers/USB/LowLevel/DevChapter9.c       | 26 +++++--------------
 LUFA/ManPages/ChangeLog.txt                   |  2 ++
 LUFA/ManPages/LUFAPoweredProjects.txt         |  1 +
 5 files changed, 32 insertions(+), 41 deletions(-)

diff --git a/Demos/Device/ClassDriver/Joystick/Descriptors.c b/Demos/Device/ClassDriver/Joystick/Descriptors.c
index 8f4177e07..266710e66 100644
--- a/Demos/Device/ClassDriver/Joystick/Descriptors.c
+++ b/Demos/Device/ClassDriver/Joystick/Descriptors.c
@@ -58,18 +58,18 @@ USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] =
 	0x75, 0x08,          /*     Report Size (8)                                */
 	0x95, 0x02,          /*     Report Count (2)                               */
 	0x81, 0x82,          /*     Input (Data, Variable, Absolute, Volatile)     */
-	0x05, 0x09,          /*     Usage Page (Button)                            */
-	0x09, 0x02,          /*     Usage (Button 2)                               */
-	0x09, 0x01,          /*     Usage (Button 1)                               */
-	0x15, 0x00,          /*     Logical Minimum (0)                            */
-	0x25, 0x01,          /*     Logical Maximum (1)                            */
-	0x75, 0x01,          /*     Report Size (1)                                */
-	0x95, 0x02,          /*     Report Count (2)                               */
-	0x81, 0x02,          /*     Input (Data, Variable, Absolute)               */
-	0x75, 0x06,          /*     Report Size (6)                                */
-	0x95, 0x01,          /*     Report Count (1)                               */
-	0x81, 0x01,          /*     Input (Constant)                               */
 	0xc0,                /*   End Collection                                   */
+	0x05, 0x09,          /*   Usage Page (Button)                              */
+	0x09, 0x02,          /*   Usage (Button 2)                                 */
+	0x09, 0x01,          /*   Usage (Button 1)                                 */
+	0x15, 0x00,          /*   Logical Minimum (0)                              */
+	0x25, 0x01,          /*   Logical Maximum (1)                              */
+	0x75, 0x01,          /*   Report Size (1)                                  */
+	0x95, 0x02,          /*   Report Count (2)                                 */
+	0x81, 0x02,          /*   Input (Data, Variable, Absolute)                 */
+	0x75, 0x06,          /*   Report Size (6)                                  */
+	0x95, 0x01,          /*   Report Count (1)                                 */
+	0x81, 0x01,          /*   Input (Constant)                                 */
 	0xc0                 /* End Collection                                     */
 };
 
diff --git a/Demos/Device/LowLevel/Joystick/Descriptors.c b/Demos/Device/LowLevel/Joystick/Descriptors.c
index 63f3adce2..911d7dbf4 100644
--- a/Demos/Device/LowLevel/Joystick/Descriptors.c
+++ b/Demos/Device/LowLevel/Joystick/Descriptors.c
@@ -58,18 +58,18 @@ USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] =
 	0x75, 0x08,          /*     Report Size (8)                                */
 	0x95, 0x02,          /*     Report Count (2)                               */
 	0x81, 0x82,          /*     Input (Data, Variable, Absolute, Volatile)     */
-	0x05, 0x09,          /*     Usage Page (Button)                            */
-	0x09, 0x02,          /*     Usage (Button 2)                               */
-	0x09, 0x01,          /*     Usage (Button 1)                               */
-	0x15, 0x00,          /*     Logical Minimum (0)                            */
-	0x25, 0x01,          /*     Logical Maximum (1)                            */
-	0x75, 0x01,          /*     Report Size (1)                                */
-	0x95, 0x02,          /*     Report Count (2)                               */
-	0x81, 0x02,          /*     Input (Data, Variable, Absolute)               */
-	0x75, 0x06,          /*     Report Size (6)                                */
-	0x95, 0x01,          /*     Report Count (1)                               */
-	0x81, 0x01,          /*     Input (Constant)                               */
 	0xc0,                /*   End Collection                                   */
+	0x05, 0x09,          /*   Usage Page (Button)                              */
+	0x09, 0x02,          /*   Usage (Button 2)                                 */
+	0x09, 0x01,          /*   Usage (Button 1)                                 */
+	0x15, 0x00,          /*   Logical Minimum (0)                              */
+	0x25, 0x01,          /*   Logical Maximum (1)                              */
+	0x75, 0x01,          /*   Report Size (1)                                  */
+	0x95, 0x02,          /*   Report Count (2)                                 */
+	0x81, 0x02,          /*   Input (Data, Variable, Absolute)                 */
+	0x75, 0x06,          /*   Report Size (6)                                  */
+	0x95, 0x01,          /*   Report Count (1)                                 */
+	0x81, 0x01,          /*   Input (Constant)                                 */
 	0xc0                 /* End Collection                                     */
 };
 
diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.c b/LUFA/Drivers/USB/LowLevel/DevChapter9.c
index 50afb61be..89c4e2998 100644
--- a/LUFA/Drivers/USB/LowLevel/DevChapter9.c
+++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.c
@@ -121,7 +121,7 @@ static void USB_Device_SetAddress(void)
 
 	Endpoint_ClearSETUP();
 	
-	Endpoint_ClearIN();
+	Endpoint_ClearStatusStage();
 	
 	while (!(Endpoint_IsINReady()))
 	{
@@ -190,7 +190,7 @@ static void USB_Device_SetConfiguration(void)
 
 	USB_ConfigurationNumber = (uint8_t)USB_ControlRequest.wValue;
 
-	Endpoint_ClearIN();
+	Endpoint_ClearStatusStage();
 
 	if (USB_ConfigurationNumber)
 	  USB_DeviceState = DEVICE_STATE_Configured;
@@ -205,16 +205,9 @@ void USB_Device_GetConfiguration(void)
 	Endpoint_ClearSETUP();
 
 	Endpoint_Write_Byte(USB_ConfigurationNumber);
-	
 	Endpoint_ClearIN();
 
-	while (!(Endpoint_IsOUTReceived()))
-	{
-		if (USB_DeviceState == DEVICE_STATE_Unattached)
-		  return;	
-	}
-
-	Endpoint_ClearOUT();
+	Endpoint_ClearStatusStage();
 }
 
 #if !defined(NO_INTERNAL_SERIAL) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
@@ -251,7 +244,9 @@ static void USB_Device_GetInternalSerialDescriptor(void)
 	}
 	
 	Endpoint_ClearSETUP();
+
 	Endpoint_Write_Control_Stream_LE(&SignatureDescriptor, sizeof(SignatureDescriptor));
+
 	Endpoint_ClearOUT();
 }
 #endif
@@ -334,16 +329,9 @@ static void USB_Device_GetStatus(void)
 	Endpoint_ClearSETUP();
 
 	Endpoint_Write_Word_LE(CurrentStatus);
-
 	Endpoint_ClearIN();
 	
-	while (!(Endpoint_IsOUTReceived()))
-	{
-		if (USB_DeviceState == DEVICE_STATE_Unattached)
-		  return;	
-	}
-	
-	Endpoint_ClearOUT();
+	Endpoint_ClearStatusStage();
 }
 
 static void USB_Device_ClearSetFeature(void)
@@ -391,7 +379,7 @@ static void USB_Device_ClearSetFeature(void)
 
 	Endpoint_ClearSETUP();
 
-	Endpoint_ClearIN();
+	Endpoint_ClearStatusStage();
 }
 
 #endif
diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt
index 6c25c584a..aa76c4451 100644
--- a/LUFA/ManPages/ChangeLog.txt
+++ b/LUFA/ManPages/ChangeLog.txt
@@ -14,6 +14,7 @@
   *    Report protocol is not needed
   *  - Added new MIDI LowLevel and ClassDriver Host demo, add new MIDI Host Class driver
   *  - Added stdio.h stream examples for the virtual CDC UART in the CDC host demos
+  *  - Added new CDC/Mouse ClassDriver device demo
   *
   *  <b>Changed:</b>
   *  - Removed mostly useless "TestApp" demo, as it was mainly useful only for checking for sytax errors in the library
@@ -39,6 +40,7 @@
   *  - Fixed incorrect SampleFrequencyType value in the AudioInput and AudioOutput ClassDriver demos' descriptors
   *  - Fixed incorrect event name rule in demo/project/bootloader makefiles
   *  - Fixed HID device class driver not reselecting the correct endpoint once the user callback routines have been called
+  *  - Corrected HID descriptor in the Joystick Device demos - buttons should be placed outside the pointer collection
   *
   *  \section Sec_ChangeLog090924 Version 090924
   *
diff --git a/LUFA/ManPages/LUFAPoweredProjects.txt b/LUFA/ManPages/LUFAPoweredProjects.txt
index 002328465..4c5a69447 100644
--- a/LUFA/ManPages/LUFAPoweredProjects.txt
+++ b/LUFA/ManPages/LUFAPoweredProjects.txt
@@ -35,6 +35,7 @@
  *  - "Fingerlicking Wingdinger" (WARNING: Bad Language if no Javascript), a MIDI controller - http://noisybox.net/electronics/wingdinger/
  *  - Garmin GPS USB to NMEA standard serial sentence translator: http://github.com/nall/garmin-transmogrifier/tree/master
  *  - Generic HID Device Creator : http://generichid.sourceforge.net/
+ *  - Mobo 4.3, some sort of Audio related device: http://sites.google.com/site/lofturj/mobo4_3
  *  - NES Controller USB modification: http://projects.peterpolidoro.net/video/NESUSB.htm
  *  - MakeTV Episode Dispenser: http://www.youtube.com/watch?v=BkWUi18hl3g
  *  - Opendous-JTAG, an open source JTAG device: http://code.google.com/p/opendous-jtag/
-- 
GitLab