From d9c16402b9059628a9c45a129a99cae86b48aa5d Mon Sep 17 00:00:00 2001
From: Dean Camera <dean@fourwalledcubicle.com>
Date: Fri, 8 Jul 2011 07:56:40 +0000
Subject: [PATCH] Add missing device deconfiguration-on-error statements to the
 host mode demos and projects.

---
 Demos/Host/ClassDriver/AudioInputHost/AudioInputHost.c         | 2 ++
 Demos/Host/ClassDriver/AudioOutputHost/AudioOutputHost.c       | 2 ++
 .../JoystickHostWithParser/JoystickHostWithParser.c            | 1 +
 Demos/Host/ClassDriver/KeyboardHost/KeyboardHost.c             | 1 +
 .../KeyboardHostWithParser/KeyboardHostWithParser.c            | 1 +
 Demos/Host/ClassDriver/MouseHost/MouseHost.c                   | 1 +
 .../Host/ClassDriver/MouseHostWithParser/MouseHostWithParser.c | 1 +
 Demos/Host/LowLevel/AudioOutputHost/AudioOutputHost.c          | 1 +
 Projects/Webserver/USBHostMode.c                               | 3 +++
 9 files changed, 13 insertions(+)

diff --git a/Demos/Host/ClassDriver/AudioInputHost/AudioInputHost.c b/Demos/Host/ClassDriver/AudioInputHost/AudioInputHost.c
index ab93721ae..f789f6318 100644
--- a/Demos/Host/ClassDriver/AudioInputHost/AudioInputHost.c
+++ b/Demos/Host/ClassDriver/AudioInputHost/AudioInputHost.c
@@ -174,6 +174,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 	{
 		puts_P(PSTR("Error Enabling Audio Stream.\r\n"));
 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		USB_Host_SetDeviceConfiguration(0);
 		return;
 	}
 
@@ -184,6 +185,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 	{
 		puts_P(PSTR("Error Setting Audio Sampling Frequency.\r\n"));
 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		USB_Host_SetDeviceConfiguration(0);
 		return;
 	}
 
diff --git a/Demos/Host/ClassDriver/AudioOutputHost/AudioOutputHost.c b/Demos/Host/ClassDriver/AudioOutputHost/AudioOutputHost.c
index c43b3ab3a..c8dc3a35d 100644
--- a/Demos/Host/ClassDriver/AudioOutputHost/AudioOutputHost.c
+++ b/Demos/Host/ClassDriver/AudioOutputHost/AudioOutputHost.c
@@ -182,6 +182,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 	{
 		puts_P(PSTR("Error Enabling Audio Stream.\r\n"));
 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		USB_Host_SetDeviceConfiguration(0);
 		return;
 	}
 	
@@ -192,6 +193,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 	{
 		puts_P(PSTR("Error Setting Audio Sampling Frequency.\r\n"));
 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		USB_Host_SetDeviceConfiguration(0);
 		return;
 	}
 
diff --git a/Demos/Host/ClassDriver/JoystickHostWithParser/JoystickHostWithParser.c b/Demos/Host/ClassDriver/JoystickHostWithParser/JoystickHostWithParser.c
index e74dfe06f..d118c850b 100644
--- a/Demos/Host/ClassDriver/JoystickHostWithParser/JoystickHostWithParser.c
+++ b/Demos/Host/ClassDriver/JoystickHostWithParser/JoystickHostWithParser.c
@@ -206,6 +206,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 	{
 		puts_P(PSTR("Error Setting Report Protocol Mode or Not a Valid Joystick.\r\n"));
 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		USB_Host_SetDeviceConfiguration(0);
 		return;
 	}
 
diff --git a/Demos/Host/ClassDriver/KeyboardHost/KeyboardHost.c b/Demos/Host/ClassDriver/KeyboardHost/KeyboardHost.c
index abc038e22..81c877afa 100644
--- a/Demos/Host/ClassDriver/KeyboardHost/KeyboardHost.c
+++ b/Demos/Host/ClassDriver/KeyboardHost/KeyboardHost.c
@@ -202,6 +202,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 	{
 		puts_P(PSTR("Could not Set Boot Protocol Mode.\r\n"));
 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		USB_Host_SetDeviceConfiguration(0);
 		return;
 	}
 
diff --git a/Demos/Host/ClassDriver/KeyboardHostWithParser/KeyboardHostWithParser.c b/Demos/Host/ClassDriver/KeyboardHostWithParser/KeyboardHostWithParser.c
index 273cdde67..3bf5dd254 100644
--- a/Demos/Host/ClassDriver/KeyboardHostWithParser/KeyboardHostWithParser.c
+++ b/Demos/Host/ClassDriver/KeyboardHostWithParser/KeyboardHostWithParser.c
@@ -228,6 +228,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 	{
 		puts_P(PSTR("Error Setting Report Protocol Mode or Not a Valid Keyboard.\r\n"));
 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		USB_Host_SetDeviceConfiguration(0);
 		return;
 	}
 
diff --git a/Demos/Host/ClassDriver/MouseHost/MouseHost.c b/Demos/Host/ClassDriver/MouseHost/MouseHost.c
index 5c94ecda1..ebdc4e28c 100644
--- a/Demos/Host/ClassDriver/MouseHost/MouseHost.c
+++ b/Demos/Host/ClassDriver/MouseHost/MouseHost.c
@@ -185,6 +185,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 	{
 		puts_P(PSTR("Could not Set Boot Protocol Mode.\r\n"));
 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		USB_Host_SetDeviceConfiguration(0);
 		return;
 	}
 
diff --git a/Demos/Host/ClassDriver/MouseHostWithParser/MouseHostWithParser.c b/Demos/Host/ClassDriver/MouseHostWithParser/MouseHostWithParser.c
index b71554f48..d8a6b74e6 100644
--- a/Demos/Host/ClassDriver/MouseHostWithParser/MouseHostWithParser.c
+++ b/Demos/Host/ClassDriver/MouseHostWithParser/MouseHostWithParser.c
@@ -215,6 +215,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 	{
 		puts_P(PSTR("Error Setting Report Protocol Mode or Not a Valid Mouse.\r\n"));
 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		USB_Host_SetDeviceConfiguration(0);
 		return;
 	}
 
diff --git a/Demos/Host/LowLevel/AudioOutputHost/AudioOutputHost.c b/Demos/Host/LowLevel/AudioOutputHost/AudioOutputHost.c
index 4fdb661fa..704ddea98 100644
--- a/Demos/Host/LowLevel/AudioOutputHost/AudioOutputHost.c
+++ b/Demos/Host/LowLevel/AudioOutputHost/AudioOutputHost.c
@@ -134,6 +134,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 		                         " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
 
 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		USB_Host_SetDeviceConfiguration(0);
 		return;
 	}
 
diff --git a/Projects/Webserver/USBHostMode.c b/Projects/Webserver/USBHostMode.c
index 98467a1bb..1620cb5d8 100644
--- a/Projects/Webserver/USBHostMode.c
+++ b/Projects/Webserver/USBHostMode.c
@@ -120,6 +120,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 	if (RNDIS_Host_InitializeDevice(&Ethernet_RNDIS_Interface_Host) != HOST_SENDCONTROL_Successful)
 	{
 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		USB_Host_SetDeviceConfiguration(0);
 		return;
 	}
 
@@ -128,6 +129,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 	                                &PacketFilter, sizeof(PacketFilter)) != HOST_SENDCONTROL_Successful)
 	{
 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		USB_Host_SetDeviceConfiguration(0);
 		return;
 	}
 
@@ -135,6 +137,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
 	                                  &MACAddress, sizeof(MACAddress)) != HOST_SENDCONTROL_Successful)
 	{
 		LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+		USB_Host_SetDeviceConfiguration(0);
 		return;
 	}
 
-- 
GitLab