X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/18cbd31605dae070f00900161090a72d3eb0f8ab..82fa9149d705b70fc6d0e53e3d164fe138ce9a8b:/LUFA/Drivers/USB/LowLevel/Host.c?ds=inline diff --git a/LUFA/Drivers/USB/LowLevel/Host.c b/LUFA/Drivers/USB/LowLevel/Host.c index 2b66e28b4..ac7898ad9 100644 --- a/LUFA/Drivers/USB/LowLevel/Host.c +++ b/LUFA/Drivers/USB/LowLevel/Host.c @@ -1,21 +1,21 @@ /* 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 @@ -55,15 +55,15 @@ void USB_Host_ProcessNextHostState(void) 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: @@ -79,23 +79,23 @@ void USB_Host_ProcessNextHostState(void) 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); } @@ -108,8 +108,8 @@ void USB_Host_ProcessNextHostState(void) 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; @@ -138,9 +138,9 @@ void USB_Host_ProcessNextHostState(void) } 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: @@ -194,26 +194,27 @@ void USB_Host_ProcessNextHostState(void) uint8_t USB_Host_WaitMS(uint8_t MS) { - bool BusSuspended = USB_Host_IsBusSuspended(); - uint8_t ErrorCode = HOST_WAITERROR_Successful; - uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber(); - + 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) { - uint16_t CurrentFrameNumber = USB_Host_GetFrameNumber(); - - if (CurrentFrameNumber != PreviousFrameNumber) + if (USB_INT_HasOccurred(USB_INT_HSOFI)) { - PreviousFrameNumber = CurrentFrameNumber; + 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; } @@ -221,22 +222,25 @@ uint8_t USB_Host_WaitMS(uint8_t MS) { 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; } @@ -245,7 +249,7 @@ static void USB_Host_ResetDevice(void) bool BusSuspended = USB_Host_IsBusSuspended(); USB_INT_Disable(USB_INT_DDISCI); - + USB_Host_ResetBus(); while (!(USB_Host_IsBusResetComplete())); USB_Host_ResumeBus(); @@ -254,7 +258,7 @@ static void USB_Host_ResetDevice(void) USB_INT_Disable(USB_INT_HSOFI); USB_INT_Clear(USB_INT_HSOFI); - + for (uint8_t MSRem = 10; MSRem != 0; MSRem--) { /* Workaround for powerless-pull-up devices. After a USB bus reset, @@ -268,7 +272,7 @@ static void USB_Host_ResetDevice(void) USB_INT_Clear(USB_INT_DDISCI); break; } - + _delay_ms(1); } @@ -293,7 +297,7 @@ uint8_t USB_Host_SetDeviceConfiguration(const uint8_t ConfigNumber) }; Pipe_SelectPipe(PIPE_CONTROLPIPE); - + return USB_Host_SendControlRequest(NULL); } @@ -309,7 +313,7 @@ uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr) }; Pipe_SelectPipe(PIPE_CONTROLPIPE); - + return USB_Host_SendControlRequest(DeviceDescriptorPtr); } @@ -327,27 +331,25 @@ uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index, }; 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 +