aboutsummaryrefslogtreecommitdiff
path: root/Demos
diff options
context:
space:
mode:
authorDean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28>2009-07-13 05:34:43 +0000
committerDean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28>2009-07-13 05:34:43 +0000
commitbef20db2b251b7aee94e7cfed6d3186fcd94339d (patch)
tree3c9c1613def7ed9c299d197c9a97fe7622eb987d /Demos
parent3760ccaba93daf8902dfbde05f56ec8e0eeaa539 (diff)
Added new HOST_STATE_WaitForDeviceRemoval host state machine state for non-blocking disabling of device communications until the device has been removed (for use when an error occurs or communications with the device have completed). Changed over all host mode demos to use the new state.
Added verbose documentation for each of the USB Host state machine states. git-svn-id: http://lufa-lib.googlecode.com/svn/trunk@642 d5102386-fcda-11dd-9fdb-3debd5008f28
Diffstat (limited to 'Demos')
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c13
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/DeviceDescriptor.c17
-rw-r--r--Demos/Host/Incomplete/PrinterHost/PrinterHost.c12
-rw-r--r--Demos/Host/LowLevel/CDCHost/CDCHost.c4
-rw-r--r--Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c4
-rw-r--r--Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c6
-rw-r--r--Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c6
-rw-r--r--Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c28
-rw-r--r--Demos/Host/LowLevel/MouseHost/MouseHost.c6
-rw-r--r--Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c6
-rw-r--r--Demos/Host/LowLevel/StillImageHost/StillImageHost.c21
11 files changed, 62 insertions, 61 deletions
diff --git a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
index b8e87cb6..3222b770 100644
--- a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
+++ b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
@@ -139,14 +139,11 @@ void Bluetooth_Management_Task(void)
LEDs_SetAllLEDs(LEDS_LED1);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
puts_P(PSTR("Bluetooth Dongle Detected.\r\n"));
-
- /* Select the control pipe for the request transfer */
- Pipe_SelectPipe(PIPE_CONTROLPIPE);
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
@@ -158,7 +155,7 @@ void Bluetooth_Management_Task(void)
LEDs_SetAllLEDs(LEDS_LED1);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -181,7 +178,7 @@ void Bluetooth_Management_Task(void)
LEDs_SetAllLEDs(LEDS_LED1);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -189,9 +186,5 @@ void Bluetooth_Management_Task(void)
USB_HostState = HOST_STATE_Ready;
break;
- case HOST_STATE_Ready:
- /* Do nothing, Bluetooth stack will take care of enumeration */
-
- break;
}
}
diff --git a/Demos/Host/Incomplete/BluetoothHost/DeviceDescriptor.c b/Demos/Host/Incomplete/BluetoothHost/DeviceDescriptor.c
index e9f575c5..f68f957c 100644
--- a/Demos/Host/Incomplete/BluetoothHost/DeviceDescriptor.c
+++ b/Demos/Host/Incomplete/BluetoothHost/DeviceDescriptor.c
@@ -34,28 +34,15 @@ uint8_t ProcessDeviceDescriptor(void)
{
USB_Descriptor_Device_t DeviceDescriptor;
- /* Standard request to get the device descriptor */
- USB_ControlRequest = (USB_Request_Header_t)
- {
- bmRequestType: (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
- bRequest: REQ_GetDescriptor,
- wValue: (DTYPE_Device << 8),
- wIndex: 0,
- wLength: sizeof(USB_Descriptor_Device_t),
- };
-
- /* Select the control pipe for the request transfer */
- Pipe_SelectPipe(PIPE_CONTROLPIPE);
-
/* Send the request to retrieve the device descriptor */
- if (USB_Host_SendControlRequest((void*)&DeviceDescriptor) != HOST_SENDCONTROL_Successful)
+ if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful)
return ControlErrorDuringDeviceRead;
/* Validate returned data - ensure the returned data is a device descriptor */
if (DeviceDescriptor.Header.Type != DTYPE_Device)
return InvalidDeviceDataReturned;
- if ((DeviceDescriptor.Class != BLUETOOTH_DEVICE_CLASS) ||
+ if ((DeviceDescriptor.Class != BLUETOOTH_DEVICE_CLASS) ||
(DeviceDescriptor.SubClass != BLUETOOTH_DEVICE_SUBCLASS) ||
(DeviceDescriptor.Protocol != BLUETOOTH_DEVICE_PROTOCOL))
{
diff --git a/Demos/Host/Incomplete/PrinterHost/PrinterHost.c b/Demos/Host/Incomplete/PrinterHost/PrinterHost.c
index df80789d..7b98542d 100644
--- a/Demos/Host/Incomplete/PrinterHost/PrinterHost.c
+++ b/Demos/Host/Incomplete/PrinterHost/PrinterHost.c
@@ -133,7 +133,7 @@ void USB_Printer_Host(void)
LEDs_SetAllLEDs(LEDS_LED1);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -147,7 +147,7 @@ void USB_Printer_Host(void)
LEDs_SetAllLEDs(LEDS_LED1);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -173,7 +173,7 @@ void USB_Printer_Host(void)
LEDs_SetAllLEDs(LEDS_LED1);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -181,10 +181,8 @@ void USB_Printer_Host(void)
/* Indicate device no longer busy */
LEDs_SetAllLEDs(LEDS_LED4);
-
- /* Wait until USB device disconnected */
- while (USB_IsConnected);
-
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
}
diff --git a/Demos/Host/LowLevel/CDCHost/CDCHost.c b/Demos/Host/LowLevel/CDCHost/CDCHost.c
index b3e06741..de7ab88c 100644
--- a/Demos/Host/LowLevel/CDCHost/CDCHost.c
+++ b/Demos/Host/LowLevel/CDCHost/CDCHost.c
@@ -148,7 +148,7 @@ void CDC_Host_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -162,7 +162,7 @@ void CDC_Host_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
diff --git a/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c b/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c
index 9f7da599..a1b62ac6 100644
--- a/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c
+++ b/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c
@@ -249,7 +249,7 @@ void HID_Host_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -263,7 +263,7 @@ void HID_Host_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
diff --git a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c
index 734ef2a5..2517848b 100644
--- a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c
+++ b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c
@@ -213,7 +213,7 @@ void Keyboard_HID_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -227,7 +227,7 @@ void Keyboard_HID_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -257,7 +257,7 @@ void Keyboard_HID_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
diff --git a/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c b/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c
index 4e78b0de..2ef15e7b 100644
--- a/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c
+++ b/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c
@@ -148,7 +148,7 @@ void Keyboard_HID_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -163,7 +163,7 @@ void Keyboard_HID_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -182,7 +182,7 @@ void Keyboard_HID_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
diff --git a/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c b/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c
index 2f84d0fb..1bb94f6c 100644
--- a/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c
+++ b/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c
@@ -154,7 +154,7 @@ void MassStorage_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -168,7 +168,7 @@ void MassStorage_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -187,6 +187,8 @@ void MassStorage_Task(void)
if ((ErrorCode = MassStore_GetMaxLUN(&MassStore_MaxLUNIndex)) != HOST_SENDCONTROL_Successful)
{
ShowDiskReadError(PSTR("Get Max LUN"), false, ErrorCode);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -197,6 +199,8 @@ void MassStorage_Task(void)
if ((ErrorCode = MassStore_MassStorageReset()) != HOST_SENDCONTROL_Successful)
{
ShowDiskReadError(PSTR("Mass Storage Reset"), false, ErrorCode);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -213,6 +217,8 @@ void MassStorage_Task(void)
if (((ErrorCode = MassStore_PreventAllowMediumRemoval(0, true)) != 0) || (SCSICommandStatus.Status != Command_Pass))
{
ShowDiskReadError(PSTR("Prevent/Allow Medium Removal"), (SCSICommandStatus.Status != Command_Pass), ErrorCode);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -221,6 +227,8 @@ void MassStorage_Task(void)
if (((ErrorCode = MassStore_Inquiry(0, &InquiryData)) != 0) || (SCSICommandStatus.Status != Command_Pass))
{
ShowDiskReadError(PSTR("Inquiry"), (SCSICommandStatus.Status != Command_Pass), ErrorCode);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -237,7 +245,9 @@ void MassStorage_Task(void)
if ((ErrorCode = MassStore_TestUnitReady(0)) != 0)
{
ShowDiskReadError(PSTR("Test Unit Ready"), false, ErrorCode);
- break;
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
+ break;
}
}
while ((SCSICommandStatus.Status != Command_Pass) && USB_IsConnected);
@@ -255,6 +265,8 @@ void MassStorage_Task(void)
if (((ErrorCode = MassStore_ReadCapacity(0, &DiskCapacity)) != 0) || (SCSICommandStatus.Status != Command_Pass))
{
ShowDiskReadError(PSTR("Read Capacity"), (SCSICommandStatus.Status != Command_Pass), ErrorCode);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -269,6 +281,8 @@ void MassStorage_Task(void)
(SCSICommandStatus.Status != Command_Pass))
{
ShowDiskReadError(PSTR("Read Device Block"), (SCSICommandStatus.Status != Command_Pass), ErrorCode);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -319,6 +333,8 @@ void MassStorage_Task(void)
(SCSICommandStatus.Status != Command_Pass))
{
ShowDiskReadError(PSTR("Read Device Block"), (SCSICommandStatus.Status != Command_Pass), ErrorCode);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -339,8 +355,7 @@ void MassStorage_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_READY);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
-
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
}
@@ -372,7 +387,4 @@ void ShowDiskReadError(char* CommandString, bool FailedAtSCSILayer, uint8_t Erro
/* Indicate device error via the status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
-
- /* Wait until USB device disconnected */
- while (USB_IsConnected);
}
diff --git a/Demos/Host/LowLevel/MouseHost/MouseHost.c b/Demos/Host/LowLevel/MouseHost/MouseHost.c
index 2a2e1b99..d5c4bf94 100644
--- a/Demos/Host/LowLevel/MouseHost/MouseHost.c
+++ b/Demos/Host/LowLevel/MouseHost/MouseHost.c
@@ -209,7 +209,7 @@ void Mouse_HID_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -223,7 +223,7 @@ void Mouse_HID_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -253,7 +253,7 @@ void Mouse_HID_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
diff --git a/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c b/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c
index d7a94710..1e931232 100644
--- a/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c
+++ b/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c
@@ -149,7 +149,7 @@ void Mouse_HID_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -163,7 +163,7 @@ void Mouse_HID_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -182,7 +182,7 @@ void Mouse_HID_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
diff --git a/Demos/Host/LowLevel/StillImageHost/StillImageHost.c b/Demos/Host/LowLevel/StillImageHost/StillImageHost.c
index 52438712..0f511ad7 100644
--- a/Demos/Host/LowLevel/StillImageHost/StillImageHost.c
+++ b/Demos/Host/LowLevel/StillImageHost/StillImageHost.c
@@ -149,7 +149,7 @@ void StillImage_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -162,7 +162,7 @@ void StillImage_Task(void)
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
- while (USB_IsConnected);
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -195,6 +195,8 @@ void StillImage_Task(void)
if ((ErrorCode = SImage_RecieveBlockHeader()) != PIPE_RWSTREAM_NoError)
{
ShowCommandError(ErrorCode, false);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -246,6 +248,8 @@ void StillImage_Task(void)
if ((ErrorCode = SImage_RecieveBlockHeader()) != PIPE_RWSTREAM_NoError)
{
ShowCommandError(ErrorCode, false);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -253,6 +257,8 @@ void StillImage_Task(void)
if ((PIMA_ReceivedBlock.Type != CType_ResponseBlock) || (PIMA_ReceivedBlock.Code != PIMA_RESPONSE_OK))
{
ShowCommandError(PIMA_ReceivedBlock.Code, true);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -274,6 +280,8 @@ void StillImage_Task(void)
if ((ErrorCode = SImage_RecieveBlockHeader()) != PIPE_RWSTREAM_NoError)
{
ShowCommandError(ErrorCode, false);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -281,6 +289,8 @@ void StillImage_Task(void)
if ((PIMA_ReceivedBlock.Type != CType_ResponseBlock) || (PIMA_ReceivedBlock.Code != PIMA_RESPONSE_OK))
{
ShowCommandError(PIMA_ReceivedBlock.Code, true);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -302,6 +312,8 @@ void StillImage_Task(void)
if ((ErrorCode = SImage_RecieveBlockHeader()) != PIPE_RWSTREAM_NoError)
{
ShowCommandError(ErrorCode, false);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -309,6 +321,8 @@ void StillImage_Task(void)
if ((PIMA_ReceivedBlock.Type != CType_ResponseBlock) || (PIMA_ReceivedBlock.Code != PIMA_RESPONSE_OK))
{
ShowCommandError(PIMA_ReceivedBlock.Code, true);
+
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
@@ -363,7 +377,4 @@ void ShowCommandError(uint8_t ErrorCode, bool ResponseCodeError)
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
-
- /* Wait until USB device disconnected */
- while (USB_IsConnected);
}