From be2a7d45989f5f57b326589350a6ce5bbc835b5c Mon Sep 17 00:00:00 2001
From: Dean Camera <dean@fourwalledcubicle.com>
Date: Tue, 27 Jul 2010 11:26:47 +0000
Subject: [PATCH] Move over message ID specific header data to unions inside
 the standard TMC header structure, so that all header data is read in one
 chunk in the incomplete TMC demo.

---
 .../TestAndMeasurement/TestAndMeasurement.c   |  8 +++--
 .../TestAndMeasurement/TestAndMeasurement.h   | 35 ++++++++++++++++---
 LUFA/Drivers/USB/LowLevel/Endpoint.h          |  4 +--
 Projects/TempDataLogger/TempDataLogger.c      |  4 +--
 4 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c b/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c
index e00254211..ab98411b7 100644
--- a/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c
+++ b/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.c
@@ -218,7 +218,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
 				else
 				{
 					/* Indicate that all in-progress/pending data IN requests should be aborted */
-					IsTMCBulkINReset  = true;
+					IsTMCBulkINReset = true;
 					
 					/* Save the split request for later checking when a new request is received */
 					RequestInProgess = Req_InitiateAbortBulkIn;
@@ -338,7 +338,7 @@ void TMC_Task(void)
 		
 		Endpoint_Read_Stream_LE(&MessageHeader, sizeof(MessageHeader), StreamCallback_AbortOUTOnRequest);
 		CurrentTransferTag = MessageHeader.Tag;
-
+		
 		switch (MessageHeader.MessageID)
 		{
 			case TMC_MESSAGEID_DEV_DEP_MSG_OUT:
@@ -351,6 +351,10 @@ void TMC_Task(void)
 
 				break;
 			case TMC_MESSAGEID_DEV_VENDOR_IN:
+
+				break;
+			default:
+				Endpoint_StallTransaction();
 				break;
 		}
 		
diff --git a/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h b/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h
index 2d5f82f46..191eb40a6 100644
--- a/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h
+++ b/Demos/Device/Incomplete/TestAndMeasurement/TestAndMeasurement.h
@@ -102,15 +102,40 @@
 			uint8_t Reserved2[6];
 			uint8_t Reserved3[12];			
 		} TMC_Capabilities_t;
+		
+		typedef struct
+		{
+			unsigned char LastMessageTransaction : 1;
+			unsigned char Reserved               : 7;
+
+			uint8_t Reserved2[3];
+		} TMC_DevOUTMessageHeader_t;
 
 		typedef struct
 		{
-			uint8_t MessageID;
-			uint8_t Tag;
-			uint8_t InverseTag;
-			uint8_t Reserved;
+			unsigned char TermCharEnabled        : 1;
+			unsigned char Reserved               : 7;
+
+			uint8_t TermChar;
+			uint8_t Reserved2[2];
+		} TMC_DevINMessageHeader_t;
+
+		typedef struct
+		{
+			uint8_t  MessageID;
+			uint8_t  Tag;
+			uint8_t  InverseTag;
+			uint8_t  Reserved;
+			uint32_t TransferSize;
+			
+			union
+			{
+				TMC_DevOUTMessageHeader_t DeviceOUT;
+				TMC_DevINMessageHeader_t  DeviceIN;
+				uint32_t                  VendorSpecific;
+			} MessageIDSpecific;
 		} TMC_MessageHeader_t;
-		
+
 	/* Function Prototypes: */
 		void SetupHardware(void);
 		void TMC_Task(void);
diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.h b/LUFA/Drivers/USB/LowLevel/Endpoint.h
index dd74d5263..dd49b8092 100644
--- a/LUFA/Drivers/USB/LowLevel/Endpoint.h
+++ b/LUFA/Drivers/USB/LowLevel/Endpoint.h
@@ -131,8 +131,8 @@
 			#define ENDPOINT_CONTROLEP                    0
 
 			#if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
-				/** Default size of the default control endpoint's bank, until altered by the Endpoint0Size value 
-				 *  in the device descriptor. Not available if the FIXED_CONTROL_ENDPOINT_SIZE token is defined.
+				/** Default size of the default control endpoint's bank, until altered by the control endpoint bank size 
+				 *  value in the device descriptor. Not available if the FIXED_CONTROL_ENDPOINT_SIZE token is defined.
 				 */
 				#define ENDPOINT_CONTROLEP_DEFAULT_SIZE   8
 			#endif
diff --git a/Projects/TempDataLogger/TempDataLogger.c b/Projects/TempDataLogger/TempDataLogger.c
index dd707bc08..7d88ba7bf 100644
--- a/Projects/TempDataLogger/TempDataLogger.c
+++ b/Projects/TempDataLogger/TempDataLogger.c
@@ -105,10 +105,10 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK)
 	if (CurrentLoggingTicks++ < LoggingInterval500MS_SRAM)
 	  return;
 	    
-	LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
-
 	/* Reset log tick counter to prepare for next logging interval */
 	CurrentLoggingTicks = 0;
+
+	LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
 	
 	/* Only log when not connected to a USB host */
 	if (USB_DeviceState == DEVICE_STATE_Unattached)
-- 
GitLab