/*
LUFA Library
Copyright (C) Dean Camera, 2010.
-
+
dean [at] fourwalledcubicle [dot] com
- www.fourwalledcubicle.com
+ www.lufa-lib.org
*/
/*
Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
- Permission to use, copy, modify, distribute, and sell this
+ Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
- without fee, provided that the above copyright notice appear in
+ without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
- permission notice and warranty disclaimer appear in supporting
- documentation, and that the name of the author not be used in
- advertising or publicity pertaining to distribution of the
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
ErrorCode = HOST_ENUMERROR_WaitStage;
break;
}
-
+
if (!(--WaitMSRemaining))
USB_HostState = PostWaitState;
}
-
+
break;
case HOST_STATE_Powered:
WaitMSRemaining = HOST_DEVICE_SETTLE_DELAY_MS;
-
+
USB_HostState = HOST_STATE_Powered_WaitForDeviceSettle;
break;
case HOST_STATE_Powered_WaitForDeviceSettle:
USB_OTGPAD_On();
USB_Host_VBUS_Auto_Enable();
USB_Host_VBUS_Auto_On();
-
+
USB_HostState = HOST_STATE_Powered_WaitForConnect;
}
-
+
break;
- case HOST_STATE_Powered_WaitForConnect:
+ case HOST_STATE_Powered_WaitForConnect:
if (USB_INT_HasOccurred(USB_INT_DCONNI))
- {
+ {
USB_INT_Clear(USB_INT_DCONNI);
USB_INT_Clear(USB_INT_DDISCI);
USB_INT_Clear(USB_INT_VBERRI);
USB_INT_Enable(USB_INT_VBERRI);
-
+
USB_Host_ResumeBus();
Pipe_ClearPipes();
-
+
HOST_TASK_NONBLOCK_WAIT(100, HOST_STATE_Powered_DoReset);
}
case HOST_STATE_Powered_ConfigPipe:
Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL,
PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP,
- PIPE_CONTROLPIPE_DEFAULT_SIZE, PIPE_BANK_SINGLE);
-
+ PIPE_CONTROLPIPE_DEFAULT_SIZE, PIPE_BANK_SINGLE);
+
if (!(Pipe_IsConfigured()))
{
ErrorCode = HOST_ENUMERROR_PipeConfigError;
}
USB_ControlPipeSize = DataBuffer[offsetof(USB_Descriptor_Device_t, Endpoint0Size)];
-
+
USB_Host_ResetDevice();
-
+
HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Default_PostReset);
break;
case HOST_STATE_Default_PostReset:
- Pipe_DisablePipe();
- Pipe_DeallocateMemory();
- Pipe_ResetPipe(PIPE_CONTROLPIPE);
-
Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL,
PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP,
USB_ControlPipeSize, PIPE_BANK_SINGLE);
{
bool BusSuspended = USB_Host_IsBusSuspended();
uint8_t ErrorCode = HOST_WAITERROR_Successful;
-
+ bool HSOFIEnabled = USB_INT_IsEnabled(USB_INT_HSOFI);
+
+ USB_INT_Disable(USB_INT_HSOFI);
+ USB_INT_Clear(USB_INT_HSOFI);
+
USB_Host_ResumeBus();
while (MS)
USB_INT_Clear(USB_INT_HSOFI);
MS--;
}
-
- if ((USB_HostState == HOST_STATE_Unattached) || (USB_CurrentMode == USB_MODE_DEVICE))
+
+ if ((USB_HostState == HOST_STATE_Unattached) || (USB_CurrentMode != USB_MODE_Host))
{
ErrorCode = HOST_WAITERROR_DeviceDisconnect;
-
+
break;
}
{
Pipe_ClearError();
ErrorCode = HOST_WAITERROR_PipeError;
-
+
break;
}
-
+
if (Pipe_IsStalled() == true)
{
Pipe_ClearStall();
ErrorCode = HOST_WAITERROR_SetupStalled;
-
- break;
+
+ break;
}
}
if (BusSuspended)
USB_Host_SuspendBus();
+ if (HSOFIEnabled)
+ USB_INT_Enable(USB_INT_HSOFI);
+
return ErrorCode;
}
bool BusSuspended = USB_Host_IsBusSuspended();
USB_INT_Disable(USB_INT_DDISCI);
-
+
USB_Host_ResetBus();
while (!(USB_Host_IsBusResetComplete()));
-
USB_Host_ResumeBus();
+ bool HSOFIEnabled = USB_INT_IsEnabled(USB_INT_HSOFI);
+
+ USB_INT_Disable(USB_INT_HSOFI);
USB_INT_Clear(USB_INT_HSOFI);
for (uint8_t MSRem = 10; MSRem != 0; MSRem--)
USB_INT_Clear(USB_INT_DDISCI);
break;
}
-
+
_delay_ms(1);
}
+ if (HSOFIEnabled)
+ USB_INT_Enable(USB_INT_HSOFI);
+
if (BusSuspended)
USB_Host_SuspendBus();
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
-
+
return USB_Host_SendControlRequest(NULL);
}
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
-
+
return USB_Host_SendControlRequest(DeviceDescriptorPtr);
}
-uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index, void* const Buffer, const uint8_t BufferLength)
+uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index,
+ void* const Buffer,
+ const uint8_t BufferLength)
{
USB_ControlRequest = (USB_Request_Header_t)
{
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
-
+
return USB_Host_SendControlRequest(Buffer);
}
-uint8_t USB_Host_ClearPipeStall(uint8_t EndpointNum)
+uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointNum)
{
- if (Pipe_GetPipeToken() == PIPE_TOKEN_IN)
- EndpointNum |= ENDPOINT_DESCRIPTOR_DIR_IN;
-
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT),
.bRequest = REQ_ClearFeature,
- .wValue = FEATURE_ENDPOINT_HALT,
+ .wValue = FEATURE_SEL_EndpointHalt,
.wIndex = EndpointNum,
.wLength = 0,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
-
+
return USB_Host_SendControlRequest(NULL);
}
#endif
+