diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2009-07-21 13:31:21 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2009-07-21 13:31:21 +0000 |
commit | e071f3897a0946c6be1e1b5e1f78eda8dcbf6fc7 (patch) | |
tree | 51ac5c80564fd76c93a357ee4d52a347384ac84b /Demos | |
parent | 44179abcf85acb14fb3aff72ce50ae84281c0f2e (diff) | |
download | lufa-e071f3897a0946c6be1e1b5e1f78eda8dcbf6fc7.tar.gz lufa-e071f3897a0946c6be1e1b5e1f78eda8dcbf6fc7.tar.bz2 lufa-e071f3897a0946c6be1e1b5e1f78eda8dcbf6fc7.zip |
Added new USB_DeviceState variable to keep track of the current Device mode USB state.
Added new Endpoint_ClearStatusStage() convenience function to assist with the status stages of control transfers.
Removed vague USB_IsConnected global - test USB_DeviceState or USB_HostState explicitly to gain previous functionality.
Removed USB_IsSuspended global - test USB_DeviceState against DEVICE_STATE_Suspended instead.
Fixed possible enumeration errors from spinloops which may fail to exit if the USB connection is severed before the exit condition becomes true.
Diffstat (limited to 'Demos')
31 files changed, 290 insertions, 246 deletions
diff --git a/Demos/Device/ClassDriver/MassStorage/Lib/DataflashManager.c b/Demos/Device/ClassDriver/MassStorage/Lib/DataflashManager.c index 1c584e71c..5f12d02b4 100644 --- a/Demos/Device/ClassDriver/MassStorage/Lib/DataflashManager.c +++ b/Demos/Device/ClassDriver/MassStorage/Lib/DataflashManager.c @@ -69,7 +69,11 @@ void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, co Dataflash_SendAddressBytes(0, CurrDFPageByte);
/* Wait until endpoint is ready before continuing */
- while (!(Endpoint_IsReadWriteAllowed()));
+ while (!(Endpoint_IsReadWriteAllowed()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
while (TotalBlocks)
{
@@ -85,7 +89,11 @@ void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, co Endpoint_ClearOUT();
/* Wait until the host has sent another packet */
- while (!(Endpoint_IsReadWriteAllowed()));
+ while (!(Endpoint_IsReadWriteAllowed()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
}
/* Check if end of dataflash page reached */
@@ -197,7 +205,11 @@ void DataflashManager_ReadBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, con Dataflash_SendByte(0x00);
/* Wait until endpoint is ready before continuing */
- while (!(Endpoint_IsReadWriteAllowed()));
+ while (!(Endpoint_IsReadWriteAllowed()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
while (TotalBlocks)
{
@@ -213,7 +225,11 @@ void DataflashManager_ReadBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, con Endpoint_ClearIN();
/* Wait until the endpoint is ready for more data */
- while (!(Endpoint_IsReadWriteAllowed()));
+ while (!(Endpoint_IsReadWriteAllowed()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
}
/* Check if end of dataflash page reached */
diff --git a/Demos/Device/ClassDriver/USBtoSerial/USBtoSerial.c b/Demos/Device/ClassDriver/USBtoSerial/USBtoSerial.c index ac63f0f9f..89537066c 100644 --- a/Demos/Device/ClassDriver/USBtoSerial/USBtoSerial.c +++ b/Demos/Device/ClassDriver/USBtoSerial/USBtoSerial.c @@ -152,7 +152,7 @@ void EVENT_USB_UnhandledControlPacket(void) */
ISR(USART1_RX_vect, ISR_BLOCK)
{
- if (USB_IsConnected)
+ if (USB_DeviceState == DEVICE_STATE_Configured)
Buffer_StoreElement(&Tx_Buffer, UDR1);
}
diff --git a/Demos/Device/Incomplete/Sideshow/Sideshow.c b/Demos/Device/Incomplete/Sideshow/Sideshow.c index cc8bd51c3..d67fae03f 100644 --- a/Demos/Device/Incomplete/Sideshow/Sideshow.c +++ b/Demos/Device/Incomplete/Sideshow/Sideshow.c @@ -142,7 +142,7 @@ void EVENT_USB_UnhandledControlPacket(void) void SideShow_Task(void)
{
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
/* Select the SideShow data out endpoint */
diff --git a/Demos/Device/LowLevel/AudioInput/AudioInput.c b/Demos/Device/LowLevel/AudioInput/AudioInput.c index 5656b05d1..bf790169d 100644 --- a/Demos/Device/LowLevel/AudioInput/AudioInput.c +++ b/Demos/Device/LowLevel/AudioInput/AudioInput.c @@ -139,9 +139,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */
StreamingAudioInterfaceSelected = ((USB_ControlRequest.wValue) != 0);
- /* Acknowledge status stage */
- while (!(Endpoint_IsINReady()));
- Endpoint_ClearIN();
+ Endpoint_ClearStatusStage();
}
break;
@@ -152,7 +150,7 @@ void EVENT_USB_UnhandledControlPacket(void) void USB_Audio_Task(void)
{
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
/* Check to see if the streaming interface is selected, if not the host is not receiving audio */
diff --git a/Demos/Device/LowLevel/AudioOutput/AudioOutput.c b/Demos/Device/LowLevel/AudioOutput/AudioOutput.c index 6d22009dc..89c4446bc 100644 --- a/Demos/Device/LowLevel/AudioOutput/AudioOutput.c +++ b/Demos/Device/LowLevel/AudioOutput/AudioOutput.c @@ -166,9 +166,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */
StreamingAudioInterfaceSelected = ((USB_ControlRequest.wValue) != 0);
- /* Acknowledge status stage */
- while (!(Endpoint_IsINReady()));
- Endpoint_ClearIN();
+ Endpoint_ClearStatusStage();
}
break;
@@ -181,7 +179,7 @@ void EVENT_USB_UnhandledControlPacket(void) void USB_Audio_Task(void)
{
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
/* Check to see if the streaming interface is selected, if not the host is not receiving audio */
diff --git a/Demos/Device/LowLevel/CDC/CDC.c b/Demos/Device/LowLevel/CDC/CDC.c index d8263b11f..e63257dbd 100644 --- a/Demos/Device/LowLevel/CDC/CDC.c +++ b/Demos/Device/LowLevel/CDC/CDC.c @@ -56,12 +56,15 @@ CDC_Line_Coding_t LineCoding = { .BaudRateBPS = 9600, */
static int CDC_putchar (char c, FILE *stream)
-{
- if (!(USB_IsConnected))
- return -1;
-
+{
Endpoint_SelectEndpoint(CDC_TX_EPNUM);
- while (!(Endpoint_IsReadWriteAllowed()));
+
+ while (!(Endpoint_IsReadWriteAllowed()))
+ {
+ if (USB_DeviceState != DEVICE_STATE_Configured)
+ return -1;
+ }
+
Endpoint_Write_Byte(c);
Endpoint_ClearIN();
@@ -76,10 +79,11 @@ static int CDC_getchar (FILE *stream) for (;;)
{
- if (!(USB_IsConnected))
- return -1;
-
- while (!(Endpoint_IsReadWriteAllowed()));
+ while (!(Endpoint_IsReadWriteAllowed()))
+ {
+ if (USB_DeviceState != DEVICE_STATE_Configured)
+ return -1;
+ }
if (!(Endpoint_BytesInEndpoint()))
{
@@ -229,9 +233,7 @@ void EVENT_USB_UnhandledControlPacket(void) CONTROL_LINE_OUT_* masks to determine the RTS and DTR line states using the following code:
*/
- /* Acknowledge status stage */
- while (!(Endpoint_IsINReady()));
- Endpoint_ClearIN();
+ Endpoint_ClearStatusStage();
}
break;
@@ -244,18 +246,17 @@ void CDC_Task(void) char* ReportString = NULL;
uint8_t JoyStatus_LCL = Joystick_GetStatus();
static bool ActionSent = false;
-
- char* JoystickStrings[] =
- {
- "Joystick Up\r\n",
- "Joystick Down\r\n",
- "Joystick Left\r\n",
- "Joystick Right\r\n",
- "Joystick Pressed\r\n",
- };
+ char* JoystickStrings[] =
+ {
+ "Joystick Up\r\n",
+ "Joystick Down\r\n",
+ "Joystick Left\r\n",
+ "Joystick Right\r\n",
+ "Joystick Pressed\r\n",
+ };
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
#if 0
@@ -319,7 +320,11 @@ void CDC_Task(void) if (IsFull)
{
/* Wait until the endpoint is ready for another packet */
- while (!(Endpoint_IsINReady()));
+ while (!(Endpoint_IsINReady()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
/* Send an empty packet to ensure that the host does not buffer data sent to it */
Endpoint_ClearIN();
diff --git a/Demos/Device/LowLevel/DualCDC/DualCDC.c b/Demos/Device/LowLevel/DualCDC/DualCDC.c index 862945e63..dd278d535 100644 --- a/Demos/Device/LowLevel/DualCDC/DualCDC.c +++ b/Demos/Device/LowLevel/DualCDC/DualCDC.c @@ -211,9 +211,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Acknowledge the SETUP packet, ready for data transfer */
Endpoint_ClearSETUP();
- /* Acknowledge status stage */
- while (!(Endpoint_IsINReady()));
- Endpoint_ClearIN();
+ Endpoint_ClearStatusStage();
}
break;
@@ -228,20 +226,19 @@ void CDC1_Task(void) char* ReportString = NULL;
uint8_t JoyStatus_LCL = Joystick_GetStatus();
static bool ActionSent = false;
-
+ char* JoystickStrings[] =
+ {
+ "Joystick Up\r\n",
+ "Joystick Down\r\n",
+ "Joystick Left\r\n",
+ "Joystick Right\r\n",
+ "Joystick Pressed\r\n",
+ };
+
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
- char* JoystickStrings[] =
- {
- "Joystick Up\r\n",
- "Joystick Down\r\n",
- "Joystick Left\r\n",
- "Joystick Right\r\n",
- "Joystick Pressed\r\n",
- };
-
/* Determine if a joystick action has occurred */
if (JoyStatus_LCL & JOY_UP)
ReportString = JoystickStrings[0];
@@ -273,7 +270,11 @@ void CDC1_Task(void) Endpoint_ClearIN();
/* Wait until the endpoint is ready for another packet */
- while (!(Endpoint_IsINReady()));
+ while (!(Endpoint_IsINReady()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
/* Send an empty packet to ensure that the host does not buffer data sent to it */
Endpoint_ClearIN();
@@ -293,7 +294,7 @@ void CDC1_Task(void) void CDC2_Task(void)
{
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
/* Select the Serial Rx Endpoint */
@@ -324,7 +325,11 @@ void CDC2_Task(void) Endpoint_ClearIN();
/* Wait until the endpoint is ready for the next packet */
- while (!(Endpoint_IsINReady()));
+ while (!(Endpoint_IsINReady()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
/* Send an empty packet to prevent host buffering */
Endpoint_ClearIN();
diff --git a/Demos/Device/LowLevel/GenericHID/GenericHID.c b/Demos/Device/LowLevel/GenericHID/GenericHID.c index 5c6d1ee47..34c991f12 100644 --- a/Demos/Device/LowLevel/GenericHID/GenericHID.c +++ b/Demos/Device/LowLevel/GenericHID/GenericHID.c @@ -148,7 +148,11 @@ void EVENT_USB_UnhandledControlPacket(void) Endpoint_ClearSETUP();
/* Wait until the generic report has been sent by the host */
- while (!(Endpoint_IsOUTReceived()));
+ while (!(Endpoint_IsOUTReceived()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
Endpoint_Read_Control_Stream_LE(&GenericData, sizeof(GenericData));
@@ -158,7 +162,11 @@ void EVENT_USB_UnhandledControlPacket(void) Endpoint_ClearOUT();
/* Wait until the host is ready to receive the request confirmation */
- while (!(Endpoint_IsINReady()));
+ while (!(Endpoint_IsINReady()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
/* Handshake the request by sending an empty IN packet */
Endpoint_ClearIN();
@@ -203,7 +211,7 @@ void CreateGenericHIDReport(uint8_t* DataArray) void HID_Task(void)
{
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
Endpoint_SelectEndpoint(GENERIC_OUT_EPNUM);
diff --git a/Demos/Device/LowLevel/Joystick/Joystick.c b/Demos/Device/LowLevel/Joystick/Joystick.c index e11747537..db2415e4b 100644 --- a/Demos/Device/LowLevel/Joystick/Joystick.c +++ b/Demos/Device/LowLevel/Joystick/Joystick.c @@ -182,7 +182,7 @@ bool GetNextReport(USB_JoystickReport_Data_t* ReportData) void HID_Task(void)
{
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
/* Select the Joystick Report Endpoint */
diff --git a/Demos/Device/LowLevel/Keyboard/Keyboard.c b/Demos/Device/LowLevel/Keyboard/Keyboard.c index 9950484ba..e27b22827 100644 --- a/Demos/Device/LowLevel/Keyboard/Keyboard.c +++ b/Demos/Device/LowLevel/Keyboard/Keyboard.c @@ -172,7 +172,11 @@ void EVENT_USB_UnhandledControlPacket(void) Endpoint_ClearSETUP();
/* Wait until the LED report has been sent by the host */
- while (!(Endpoint_IsOUTReceived()));
+ while (!(Endpoint_IsOUTReceived()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
/* Read in the LED report from the host */
uint8_t LEDStatus = Endpoint_Read_Byte();
@@ -183,9 +187,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Clear the endpoint data */
Endpoint_ClearOUT();
- /* Acknowledge status stage */
- while (!(Endpoint_IsINReady()));
- Endpoint_ClearIN();
+ Endpoint_ClearStatusStage();
}
break;
@@ -200,9 +202,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Send the flag to the host */
Endpoint_ClearIN();
- /* Acknowledge status stage */
- while (!(Endpoint_IsOUTReceived()));
- Endpoint_ClearOUT();
+ Endpoint_ClearStatusStage();
}
break;
@@ -214,9 +214,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Set or clear the flag depending on what the host indicates that the current Protocol should be */
UsingReportProtocol = (USB_ControlRequest.wValue != 0);
- /* Acknowledge status stage */
- while (!(Endpoint_IsINReady()));
- Endpoint_ClearIN();
+ Endpoint_ClearStatusStage();
}
break;
@@ -228,9 +226,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Get idle period in MSB, IdleCount must be multiplied by 4 to get number of milliseconds */
IdleCount = ((USB_ControlRequest.wValue & 0xFF00) >> 6);
- /* Acknowledge status stage */
- while (!(Endpoint_IsINReady()));
- Endpoint_ClearIN();
+ Endpoint_ClearStatusStage();
}
break;
@@ -245,9 +241,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Send the flag to the host */
Endpoint_ClearIN();
- /* Acknowledge status stage */
- while (!(Endpoint_IsOUTReceived()));
- Endpoint_ClearOUT();
+ Endpoint_ClearStatusStage();
}
break;
@@ -378,7 +372,7 @@ void ReceiveNextReport(void) void HID_Task(void)
{
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
/* Send the next keypress report to the host */
diff --git a/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c b/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c index c60f08f9c..7d486e16e 100644 --- a/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c +++ b/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c @@ -174,7 +174,11 @@ void EVENT_USB_UnhandledControlPacket(void) Endpoint_ClearSETUP();
/* Wait until the LED report has been sent by the host */
- while (!(Endpoint_IsOUTReceived()));
+ while (!(Endpoint_IsOUTReceived()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
/* Read in the LED report from the host */
uint8_t LEDStatus = Endpoint_Read_Byte();
@@ -195,9 +199,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Clear the endpoint data */
Endpoint_ClearOUT();
- /* Acknowledge status stage */
- while (!(Endpoint_IsINReady()));
- Endpoint_ClearIN();
+ Endpoint_ClearStatusStage();
}
break;
@@ -213,7 +215,7 @@ void Keyboard_HID_Task(void) uint8_t JoyStatus_LCL = Joystick_GetStatus();
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
/* Check if board button is not pressed, if so mouse mode enabled */
@@ -284,7 +286,7 @@ void Mouse_HID_Task(void) uint8_t JoyStatus_LCL = Joystick_GetStatus();
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
/* Check if board button is pressed, if so mouse mode enabled */
diff --git a/Demos/Device/LowLevel/MIDI/MIDI.c b/Demos/Device/LowLevel/MIDI/MIDI.c index 954cbcbf6..8aed527db 100644 --- a/Demos/Device/LowLevel/MIDI/MIDI.c +++ b/Demos/Device/LowLevel/MIDI/MIDI.c @@ -117,7 +117,7 @@ void MIDI_Task(void) static uint8_t PrevJoystickStatus;
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
Endpoint_SelectEndpoint(MIDI_STREAM_IN_EPNUM);
diff --git a/Demos/Device/LowLevel/MassStorage/Lib/DataflashManager.c b/Demos/Device/LowLevel/MassStorage/Lib/DataflashManager.c index fdc91dd5d..2bd03c98d 100644 --- a/Demos/Device/LowLevel/MassStorage/Lib/DataflashManager.c +++ b/Demos/Device/LowLevel/MassStorage/Lib/DataflashManager.c @@ -68,8 +68,12 @@ void DataflashManager_WriteBlocks(const uint32_t BlockAddress, uint16_t TotalBlo Dataflash_SendAddressBytes(0, CurrDFPageByte);
/* Wait until endpoint is ready before continuing */
- while (!(Endpoint_IsReadWriteAllowed()));
-
+ while (!(Endpoint_IsReadWriteAllowed()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
+
while (TotalBlocks)
{
uint8_t BytesInBlockDiv16 = 0;
@@ -84,7 +88,11 @@ void DataflashManager_WriteBlocks(const uint32_t BlockAddress, uint16_t TotalBlo Endpoint_ClearOUT();
/* Wait until the host has sent another packet */
- while (!(Endpoint_IsReadWriteAllowed()));
+ while (!(Endpoint_IsReadWriteAllowed()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
}
/* Check if end of dataflash page reached */
@@ -195,7 +203,11 @@ void DataflashManager_ReadBlocks(const uint32_t BlockAddress, uint16_t TotalBloc Dataflash_SendByte(0x00);
/* Wait until endpoint is ready before continuing */
- while (!(Endpoint_IsReadWriteAllowed()));
+ while (!(Endpoint_IsReadWriteAllowed()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
while (TotalBlocks)
{
@@ -211,7 +223,11 @@ void DataflashManager_ReadBlocks(const uint32_t BlockAddress, uint16_t TotalBloc Endpoint_ClearIN();
/* Wait until the endpoint is ready for more data */
- while (!(Endpoint_IsReadWriteAllowed()));
+ while (!(Endpoint_IsReadWriteAllowed()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
}
/* Check if end of dataflash page reached */
diff --git a/Demos/Device/LowLevel/MassStorage/MassStorage.c b/Demos/Device/LowLevel/MassStorage/MassStorage.c index 2c80fc595..01d27f043 100644 --- a/Demos/Device/LowLevel/MassStorage/MassStorage.c +++ b/Demos/Device/LowLevel/MassStorage/MassStorage.c @@ -142,9 +142,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Indicate that the current transfer should be aborted */
IsMassStoreReset = true;
- /* Acknowledge status stage */
- while (!(Endpoint_IsINReady()));
- Endpoint_ClearIN();
+ Endpoint_ClearStatusStage();
}
break;
@@ -158,9 +156,7 @@ void EVENT_USB_UnhandledControlPacket(void) Endpoint_ClearIN();
- /* Acknowledge status stage */
- while (!(Endpoint_IsOUTReceived()));
- Endpoint_ClearOUT();
+ Endpoint_ClearStatusStage();
}
break;
@@ -172,67 +168,67 @@ void EVENT_USB_UnhandledControlPacket(void) */
void MassStorage_Task(void)
{
- /* Check if the USB System is connected to a Host */
- if (USB_IsConnected)
+ /* Device must be connected and configured for the task to run */
+ if (USB_DeviceState != DEVICE_STATE_Configured)
+ return;
+
+ /* Select the Data Out Endpoint */
+ Endpoint_SelectEndpoint(MASS_STORAGE_OUT_EPNUM);
+
+ /* Check to see if a command from the host has been issued */
+ if (Endpoint_IsReadWriteAllowed())
{
- /* Select the Data Out Endpoint */
- Endpoint_SelectEndpoint(MASS_STORAGE_OUT_EPNUM);
-
- /* Check to see if a command from the host has been issued */
- if (Endpoint_IsReadWriteAllowed())
- {
- /* Indicate busy */
- LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
+ /* Indicate busy */
+ LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
- /* Process sent command block from the host */
- if (ReadInCommandBlock())
- {
- /* Check direction of command, select Data IN endpoint if data is from the device */
- if (CommandBlock.Flags & COMMAND_DIRECTION_DATA_IN)
- Endpoint_SelectEndpoint(MASS_STORAGE_IN_EPNUM);
+ /* Process sent command block from the host */
+ if (ReadInCommandBlock())
+ {
+ /* Check direction of command, select Data IN endpoint if data is from the device */
+ if (CommandBlock.Flags & COMMAND_DIRECTION_DATA_IN)
+ Endpoint_SelectEndpoint(MASS_STORAGE_IN_EPNUM);
- /* Decode the received SCSI command */
- SCSI_DecodeSCSICommand();
+ /* Decode the received SCSI command */
+ SCSI_DecodeSCSICommand();
- /* Load in the CBW tag into the CSW to link them together */
- CommandStatus.Tag = CommandBlock.Tag;
+ /* Load in the CBW tag into the CSW to link them together */
+ CommandStatus.Tag = CommandBlock.Tag;
- /* Load in the data residue counter into the CSW */
- CommandStatus.DataTransferResidue = CommandBlock.DataTransferLength;
+ /* Load in the data residue counter into the CSW */
+ CommandStatus.DataTransferResidue = CommandBlock.DataTransferLength;
- /* Stall the selected data pipe if command failed (if data is still to be transferred) */
- if ((CommandStatus.Status == Command_Fail) && (CommandStatus.DataTransferResidue))
- Endpoint_StallTransaction();
+ /* Stall the selected data pipe if command failed (if data is still to be transferred) */
+ if ((CommandStatus.Status == Command_Fail) && (CommandStatus.DataTransferResidue))
+ Endpoint_StallTransaction();
- /* Return command status block to the host */
- ReturnCommandStatus();
-
- /* Check if a Mass Storage Reset occurred */
- if (IsMassStoreReset)
- {
- /* Reset the data endpoint banks */
- Endpoint_ResetFIFO(MASS_STORAGE_OUT_EPNUM);
- Endpoint_ResetFIFO(MASS_STORAGE_IN_EPNUM);
-
- Endpoint_SelectEndpoint(MASS_STORAGE_OUT_EPNUM);
- Endpoint_ClearStall();
- Endpoint_SelectEndpoint(MASS_STORAGE_IN_EPNUM);
- Endpoint_ClearStall();
- }
-
- /* Indicate ready */
- LEDs_SetAllLEDs(LEDMASK_USB_READY);
- }
- else
+ /* Return command status block to the host */
+ ReturnCommandStatus();
+
+ /* Check if a Mass Storage Reset occurred */
+ if (IsMassStoreReset)
{
- /* Indicate error reading in the command block from the host */
- LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+ /* Reset the data endpoint banks */
+ Endpoint_ResetFIFO(MASS_STORAGE_OUT_EPNUM);
+ Endpoint_ResetFIFO(MASS_STORAGE_IN_EPNUM);
+
+ Endpoint_SelectEndpoint(MASS_STORAGE_OUT_EPNUM);
+ Endpoint_ClearStall();
+ Endpoint_SelectEndpoint(MASS_STORAGE_IN_EPNUM);
+ Endpoint_ClearStall();
}
- }
- /* Clear the abort transfer flag */
- IsMassStoreReset = false;
+ /* Indicate ready */
+ LEDs_SetAllLEDs(LEDMASK_USB_READY);
+ }
+ else
+ {
+ /* Indicate error reading in the command block from the host */
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
+ }
}
+
+ /* Clear the abort transfer flag */
+ IsMassStoreReset = false;
}
/** Function to read in a command block from the host, via the bulk data OUT endpoint. This function reads in the next command block
diff --git a/Demos/Device/LowLevel/Mouse/Mouse.c b/Demos/Device/LowLevel/Mouse/Mouse.c index febb36450..d15f688d6 100644 --- a/Demos/Device/LowLevel/Mouse/Mouse.c +++ b/Demos/Device/LowLevel/Mouse/Mouse.c @@ -172,9 +172,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Send the flag to the host */
Endpoint_ClearIN();
- /* Acknowledge status stage */
- while (!(Endpoint_IsOUTReceived()));
- Endpoint_ClearOUT();
+ Endpoint_ClearStatusStage();
}
break;
@@ -186,9 +184,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Set or clear the flag depending on what the host indicates that the current Protocol should be */
UsingReportProtocol = (USB_ControlRequest.wValue != 0);
- /* Acknowledge status stage */
- while (!(Endpoint_IsINReady()));
- Endpoint_ClearIN();
+ Endpoint_ClearStatusStage();
}
break;
@@ -200,9 +196,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Get idle period in MSB, must multiply by 4 to get the duration in milliseconds */
IdleCount = ((USB_ControlRequest.wValue & 0xFF00) >> 6);
- /* Acknowledge status stage */
- while (!(Endpoint_IsINReady()));
- Endpoint_ClearIN();
+ Endpoint_ClearStatusStage();
}
break;
@@ -217,9 +211,7 @@ void EVENT_USB_UnhandledControlPacket(void) /* Send the flag to the host */
Endpoint_ClearIN();
- /* Acknowledge status stage */
- while (!(Endpoint_IsOUTReceived()));
- Endpoint_ClearOUT();
+ Endpoint_ClearStatusStage();
}
break;
@@ -314,7 +306,7 @@ void SendNextReport(void) void Mouse_Task(void)
{
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
/* Send the next mouse report to the host */
diff --git a/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c b/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c index 1c0e0304c..ca38c24d6 100644 --- a/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c +++ b/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c @@ -285,7 +285,7 @@ void Ethernet_Task(void) Ethernet frame at a time, so the FrameInBuffer bool is used to indicate when the buffers contain data. */
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
/* Check if a frame has been written to the IN frame buffer */
diff --git a/Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c b/Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c index 9160dd107..af963b1fc 100644 --- a/Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c +++ b/Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c @@ -192,9 +192,7 @@ void EVENT_USB_UnhandledControlPacket(void) CONTROL_LINE_OUT_* masks to determine the RTS and DTR line states using the following code:
*/
- /* Acknowledge status stage */
- while (!(Endpoint_IsINReady()));
- Endpoint_ClearIN();
+ Endpoint_ClearStatusStage();
}
break;
@@ -205,7 +203,7 @@ void EVENT_USB_UnhandledControlPacket(void) void CDC_Task(void)
{
/* Device must be connected and configured for the task to run */
- if (!(USB_IsConnected) || !(USB_ConfigurationNumber))
+ if (USB_DeviceState != DEVICE_STATE_Configured)
return;
#if 0
@@ -264,7 +262,11 @@ void CDC_Task(void) if (Tx_Buffer.Elements)
{
/* Wait until Serial Tx Endpoint Ready for Read/Write */
- while (!(Endpoint_IsReadWriteAllowed()));
+ while (!(Endpoint_IsReadWriteAllowed()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
/* Write the bytes from the buffer to the endpoint while space is available */
while (Tx_Buffer.Elements && Endpoint_IsReadWriteAllowed())
@@ -284,8 +286,12 @@ void CDC_Task(void) if (IsFull && !(Tx_Buffer.Elements))
{
/* Wait until Serial Tx Endpoint Ready for Read/Write */
- while (!(Endpoint_IsReadWriteAllowed()));
-
+ while (!(Endpoint_IsReadWriteAllowed()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
+
/* Send an empty packet to terminate the transfer */
Endpoint_ClearIN();
}
@@ -298,11 +304,8 @@ void CDC_Task(void) ISR(USART1_RX_vect, ISR_BLOCK)
{
/* Only store received characters if the USB interface is connected */
- if (USB_IsConnected)
- {
- /* Character received, store it into the buffer */
- Buffer_StoreElement(&Tx_Buffer, UDR1);
- }
+ if (USB_DeviceState != DEVICE_STATE_Configured)
+ Buffer_StoreElement(&Tx_Buffer, UDR1);
}
/** Reconfigures the USART to match the current serial port settings issued by the host as closely as possible. */
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c index ddd159ef7..54291bf75 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothHCICommands.c @@ -114,7 +114,12 @@ void Bluetooth_ProcessHCICommands(void) do
{
- while (!(Bluetooth_GetNextHCIEventHeader()));
+ while (!(Bluetooth_GetNextHCIEventHeader()))
+ {
+ if (USB_HostState == HOST_STATE_Unattached)
+ return;
+ }
+
Bluetooth_DiscardRemainingHCIEventParameters();
} while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);
@@ -133,7 +138,12 @@ void Bluetooth_ProcessHCICommands(void) do
{
- while (!(Bluetooth_GetNextHCIEventHeader()));
+ while (!(Bluetooth_GetNextHCIEventHeader()))
+ {
+ if (USB_HostState == HOST_STATE_Unattached)
+ return;
+ }
+
Bluetooth_DiscardRemainingHCIEventParameters();
} while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);
@@ -155,7 +165,12 @@ void Bluetooth_ProcessHCICommands(void) EventMask[3], EventMask[2], EventMask[1], EventMask[0]);
do
{
- while (!(Bluetooth_GetNextHCIEventHeader()));
+ while (!(Bluetooth_GetNextHCIEventHeader()))
+ {
+ if (USB_HostState == HOST_STATE_Unattached)
+ return;
+ }
+
Bluetooth_DiscardRemainingHCIEventParameters();
} while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);
@@ -176,7 +191,12 @@ void Bluetooth_ProcessHCICommands(void) do
{
- while (!(Bluetooth_GetNextHCIEventHeader()));
+ while (!(Bluetooth_GetNextHCIEventHeader()))
+ {
+ if (USB_HostState == HOST_STATE_Unattached)
+ return;
+ }
+
Bluetooth_DiscardRemainingHCIEventParameters();
} while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);
@@ -195,7 +215,12 @@ void Bluetooth_ProcessHCICommands(void) do
{
- while (!(Bluetooth_GetNextHCIEventHeader()));
+ while (!(Bluetooth_GetNextHCIEventHeader()))
+ {
+ if (USB_HostState == HOST_STATE_Unattached)
+ return;
+ }
+
Bluetooth_DiscardRemainingHCIEventParameters();
} while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);
@@ -215,7 +240,12 @@ void Bluetooth_ProcessHCICommands(void) do
{
- while (!(Bluetooth_GetNextHCIEventHeader()));
+ while (!(Bluetooth_GetNextHCIEventHeader()))
+ {
+ if (USB_HostState == HOST_STATE_Unattached)
+ return;
+ }
+
Bluetooth_DiscardRemainingHCIEventParameters();
} while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);
@@ -366,7 +396,12 @@ void Bluetooth_ProcessHCICommands(void) do
{
- while (!(Bluetooth_GetNextHCIEventHeader()));
+ while (!(Bluetooth_GetNextHCIEventHeader()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
+
Bluetooth_DiscardRemainingHCIEventParameters();
} while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c index e2659102e..628fa217c 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.c @@ -41,7 +41,7 @@ Bluetooth_Device_t Bluetooth_DeviceConfiguration ATTR_WEAK = void Bluetooth_Stack_Task(void)
{
- if (!(USB_IsConnected) || (USB_HostState != HOST_STATE_Ready))
+ if (USB_HostState != HOST_STATE_Configured)
Bluetooth_HCIProcessingState = Bluetooth_Init;
Bluetooth_ProcessHCICommands();
diff --git a/Demos/Host/LowLevel/CDCHost/CDCHost.c b/Demos/Host/LowLevel/CDCHost/CDCHost.c index a3cde7826..e20fa2cfc 100644 --- a/Demos/Host/LowLevel/CDCHost/CDCHost.c +++ b/Demos/Host/LowLevel/CDCHost/CDCHost.c @@ -164,15 +164,12 @@ void CDC_Host_Task(void) USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
-
+
+ puts_P(PSTR("CDC Device Enumerated.\r\n"));
+
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
- puts_P(PSTR("CDC Device Enumerated.\r\n"));
-
- USB_HostState = HOST_STATE_Ready;
- break;
- case HOST_STATE_Ready:
/* Select and the data IN pipe */
Pipe_SelectPipe(CDC_DATAPIPE_IN);
Pipe_Unfreeze();
diff --git a/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c b/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c index 3a055c820..d36064333 100644 --- a/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c +++ b/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c @@ -266,14 +266,11 @@ void HID_Host_Task(void) break;
}
+ puts_P(PSTR("HID Device Enumerated.\r\n"));
+
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
- puts_P(PSTR("HID Device Enumerated.\r\n"));
-
- USB_HostState = HOST_STATE_Ready;
- break;
- case HOST_STATE_Ready:
ReadNextReport();
break;
diff --git a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c index c2d8dd4a6..273cd7175 100644 --- a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c +++ b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c @@ -230,9 +230,6 @@ void Keyboard_HID_Task(void) break;
}
- USB_HostState = HOST_STATE_Configured;
- break;
- case HOST_STATE_Configured:
/* HID class request to set the keyboard protocol to the Boot Protocol */
USB_ControlRequest = (USB_Request_Header_t)
{
@@ -262,9 +259,9 @@ void Keyboard_HID_Task(void) puts_P(PSTR("Keyboard Enumerated.\r\n"));
- USB_HostState = HOST_STATE_Ready;
+ USB_HostState = HOST_STATE_Configured;
break;
- case HOST_STATE_Ready:
+ case HOST_STATE_Configured:
/* If a report has been received, read and process it */
ReadNextReport();
diff --git a/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c b/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c index dc1707bd0..eee1755bf 100644 --- a/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c +++ b/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c @@ -166,9 +166,6 @@ void Keyboard_HID_Task(void) break;
}
- USB_HostState = HOST_STATE_Configured;
- break;
- case HOST_STATE_Configured:
puts_P(PSTR("Processing HID Report.\r\n"));
/* Get and process the device's first HID report descriptor */
@@ -187,9 +184,9 @@ void Keyboard_HID_Task(void) puts_P(PSTR("Keyboard Enumerated.\r\n"));
- USB_HostState = HOST_STATE_Ready;
+ USB_HostState = HOST_STATE_Configured;
break;
- case HOST_STATE_Ready:
+ case HOST_STATE_Configured:
/* Select and unfreeze keyboard data pipe */
Pipe_SelectPipe(KEYBOARD_DATAPIPE);
Pipe_Unfreeze();
diff --git a/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c b/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c index 7ee7de138..d0518df1f 100644 --- a/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c +++ b/Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c @@ -154,7 +154,7 @@ static uint8_t MassStore_WaitForDataReceived(void) }
/* Check to see if the device was disconnected, if so exit function */
- if (!(USB_IsConnected))
+ if (USB_HostState == HOST_STATE_Unattached)
return PIPE_RWSTREAM_DeviceDisconnected;
};
@@ -206,7 +206,11 @@ static uint8_t MassStore_SendReceiveData(void* BufferPtr) /* Acknowledge the packet */
Pipe_ClearOUT();
- while (!(Pipe_IsOUTReady()));
+ while (!(Pipe_IsOUTReady()))
+ {
+ if (USB_HostState == HOST_STATE_Unattached)
+ return PIPE_RWSTREAM_DeviceDisconnected;
+ }
}
/* Freeze used pipe after use */
diff --git a/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c b/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c index 1adec5bcf..6cfe669f6 100644 --- a/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c +++ b/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c @@ -171,14 +171,11 @@ void MassStorage_Task(void) break;
}
+ puts_P(PSTR("Mass Storage Disk Enumerated.\r\n"));
+
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
- puts_P(PSTR("Mass Storage Disk Enumerated.\r\n"));
-
- USB_HostState = HOST_STATE_Ready;
- break;
- case HOST_STATE_Ready:
/* Indicate device busy via the status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
@@ -241,7 +238,11 @@ void MassStorage_Task(void) {
Serial_TxByte('.');
- if ((ErrorCode = MassStore_TestUnitReady(0)) != 0)
+ /* Abort if device removed */
+ if (USB_HostState == HOST_STATE_Unattached)
+ break;
+
+ if ((ErrorCode = MassStore_TestUnitReady(0)) != PIPE_RWSTREAM_NoError)
{
ShowDiskReadError(PSTR("Test Unit Ready"), false, ErrorCode);
@@ -249,11 +250,7 @@ void MassStorage_Task(void) break;
}
}
- while ((SCSICommandStatus.Status != Command_Pass) && USB_IsConnected);
-
- /* Abort if device removed */
- if (!(USB_IsConnected))
- break;
+ while (SCSICommandStatus.Status != Command_Pass);
puts_P(PSTR("\r\nRetrieving Capacity... "));
@@ -320,7 +317,7 @@ void MassStorage_Task(void) while (!(Buttons_GetStatus() & BUTTONS_BUTTON1))
{
/* Abort if device removed */
- if (!(USB_IsConnected))
+ if (USB_HostState == HOST_STATE_Unattached)
break;
}
@@ -346,7 +343,7 @@ void MassStorage_Task(void) }
/* Abort if device removed */
- if (!(USB_IsConnected))
+ if (USB_HostState == HOST_STATE_Unattached)
break;
}
diff --git a/Demos/Host/LowLevel/MouseHost/MouseHost.c b/Demos/Host/LowLevel/MouseHost/MouseHost.c index 5340aa11f..b98f4bf96 100644 --- a/Demos/Host/LowLevel/MouseHost/MouseHost.c +++ b/Demos/Host/LowLevel/MouseHost/MouseHost.c @@ -226,9 +226,6 @@ void Mouse_HID_Task(void) break;
}
- USB_HostState = HOST_STATE_Configured;
- break;
- case HOST_STATE_Configured:
/* HID class request to set the mouse protocol to the Boot Protocol */
USB_ControlRequest = (USB_Request_Header_t)
{
@@ -257,10 +254,10 @@ void Mouse_HID_Task(void) }
puts_P(PSTR("Mouse Enumerated.\r\n"));
-
- USB_HostState = HOST_STATE_Ready;
+
+ USB_HostState = HOST_STATE_Configured;
break;
- case HOST_STATE_Ready:
+ case HOST_STATE_Configured:
/* If a report has been received, read and process it */
ReadNextReport();
diff --git a/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c b/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c index 42865e515..63fce0dcb 100644 --- a/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c +++ b/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c @@ -166,9 +166,6 @@ void Mouse_HID_Task(void) break;
}
- USB_HostState = HOST_STATE_Configured;
- break;
- case HOST_STATE_Configured:
puts_P(PSTR("Processing HID Report.\r\n"));
/* Get and process the device's first HID report descriptor */
@@ -186,10 +183,10 @@ void Mouse_HID_Task(void) }
puts_P(PSTR("Mouse Enumerated.\r\n"));
-
- USB_HostState = HOST_STATE_Ready;
+
+ USB_HostState = HOST_STATE_Configured;
break;
- case HOST_STATE_Ready:
+ case HOST_STATE_Configured:
/* Select and unfreeze mouse data pipe */
Pipe_SelectPipe(MOUSE_DATAPIPE);
Pipe_Unfreeze();
diff --git a/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.c b/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.c index 4c88bb4f2..cb051cdf1 100644 --- a/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.c +++ b/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.c @@ -54,7 +54,11 @@ uint8_t Printer_SendData(Printer_Data_t* PrinterCommands) return ErrorCode;
Pipe_ClearOUT();
- while (!(Pipe_IsOUTReady()));
+ while (!(Pipe_IsOUTReady()))
+ {
+ if (USB_HostState == HOST_STATE_Unattached)
+ return PIPE_RWSTREAM_DeviceDisconnected;
+ }
Pipe_Freeze();
diff --git a/Demos/Host/LowLevel/PrinterHost/PrinterHost.c b/Demos/Host/LowLevel/PrinterHost/PrinterHost.c index 3b145a63d..bbda0c24b 100644 --- a/Demos/Host/LowLevel/PrinterHost/PrinterHost.c +++ b/Demos/Host/LowLevel/PrinterHost/PrinterHost.c @@ -195,9 +195,6 @@ void USB_Printer_Host(void) }
}
- USB_HostState = HOST_STATE_Configured;
- break;
- case HOST_STATE_Configured:
puts_P(PSTR("Retrieving Device ID...\r\n"));
char DeviceIDString[256];
@@ -217,10 +214,10 @@ void USB_Printer_Host(void) printf_P(PSTR("Printer Device ID: %s\r\n"), DeviceIDString);
puts_P(PSTR("Printer Enumerated.\r\n"));
-
- USB_HostState = HOST_STATE_Ready;
+
+ USB_HostState = HOST_STATE_Configured;
break;
- case HOST_STATE_Ready:
+ case HOST_STATE_Configured:
/* Indicate device busy via the status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
diff --git a/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c b/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c index e0d71a059..970df4f87 100644 --- a/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c +++ b/Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c @@ -152,12 +152,9 @@ uint8_t SImage_RecieveBlockHeader(void) }
/* Check to see if the device was disconnected, if so exit function */
- if (!(USB_IsConnected))
- {
- /* Return error code */
- return PIPE_RWSTREAM_DeviceDisconnected;
- }
- };
+ if (USB_HostState == HOST_STATE_Unattached)
+ return PIPE_RWSTREAM_DeviceDisconnected;
+ }
/* Freeze OUT pipe after use */
Pipe_SelectPipe(SIMAGE_DATA_OUT_PIPE);
diff --git a/Demos/Host/LowLevel/StillImageHost/StillImageHost.c b/Demos/Host/LowLevel/StillImageHost/StillImageHost.c index 5cfaf46be..ca0771a94 100644 --- a/Demos/Host/LowLevel/StillImageHost/StillImageHost.c +++ b/Demos/Host/LowLevel/StillImageHost/StillImageHost.c @@ -166,14 +166,11 @@ void StillImage_Task(void) break;
}
+ puts_P(PSTR("Still Image Device Enumerated.\r\n"));
+
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
- puts_P(PSTR("Still Image Device Enumerated.\r\n"));
-
- USB_HostState = HOST_STATE_Ready;
- break;
- case HOST_STATE_Ready:
/* Indicate device busy via the status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
@@ -331,9 +328,7 @@ void StillImage_Task(void) /* Indicate device no longer busy */
LEDs_SetAllLEDs(LEDMASK_USB_READY);
- /* Wait until USB device disconnected */
- while (USB_IsConnected);
-
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;
break;
}
}
|