X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/d1e52660368d34d693131f6aff3c8fd8584162e5..d0db78432fc02bacbd57cc9f15eb05b4e56981cb:/LUFA/Drivers/USB/LowLevel/Host.c diff --git a/LUFA/Drivers/USB/LowLevel/Host.c b/LUFA/Drivers/USB/LowLevel/Host.c index 02a1c2171..efe4baeeb 100644 --- a/LUFA/Drivers/USB/LowLevel/Host.c +++ b/LUFA/Drivers/USB/LowLevel/Host.c @@ -66,6 +66,7 @@ void USB_Host_ProcessNextHostState(void) USB_HostState = HOST_STATE_Attached_WaitForDeviceSettle; break; case HOST_STATE_Attached_WaitForDeviceSettle: + #if HOST_DEVICE_SETTLE_DELAY_MS > 0 _delay_ms(1); if (!(WaitMSRemaining--)) @@ -78,6 +79,9 @@ void USB_Host_ProcessNextHostState(void) USB_HostState = HOST_STATE_Attached_WaitForConnect; } + #else + USB_HostState = HOST_STATE_Attached_WaitForConnect; + #endif break; case HOST_STATE_Attached_WaitForConnect: @@ -162,8 +166,6 @@ void USB_Host_ProcessNextHostState(void) break; } - Pipe_SetInfiniteINRequests(); - USB_ControlRequest = (USB_Request_Header_t) { .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE), @@ -214,9 +216,9 @@ uint8_t USB_Host_WaitMS(uint8_t MS) while (MS) { - if (FrameElapsed) + if (USB_INT_HasOccurred(USB_INT_HSOFI)) { - FrameElapsed = false; + USB_INT_Clear(USB_INT_HSOFI); MS--; } @@ -259,9 +261,9 @@ static void USB_Host_ResetDevice(void) USB_Host_ResetBus(); while (!(USB_Host_IsBusResetComplete())); - USB_Host_ResumeBus(); - - FrameElapsed = false; + USB_Host_ResumeBus(); + + USB_INT_Clear(USB_INT_HSOFI); for (uint8_t MSRem = 10; MSRem != 0; MSRem--) { @@ -270,10 +272,9 @@ static void USB_Host_ResetDevice(void) looked for - if it is found within 10ms, the device is still present. */ - if (FrameElapsed) + if (USB_INT_HasOccurred(USB_INT_HSOFI)) { - FrameElapsed = false; - + USB_INT_Clear(USB_INT_HSOFI); USB_INT_Clear(USB_INT_DDISCI); break; } @@ -286,4 +287,56 @@ static void USB_Host_ResetDevice(void) USB_INT_Enable(USB_INT_DDISCI); } + +uint8_t USB_Host_SetDeviceConfiguration(const uint8_t ConfigNumber) +{ + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE), + .bRequest = REQ_SetConfiguration, + .wValue = ConfigNumber, + .wIndex = 0, + .wLength = 0, + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + return USB_Host_SendControlRequest(NULL); +} + +uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr) +{ + 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), + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + return USB_Host_SendControlRequest(DeviceDescriptorPtr); +} + +uint8_t USB_Host_ClearPipeStall(uint8_t EndpointNum) +{ + if (Pipe_GetPipeToken() == PIPE_TOKEN_IN) + EndpointNum |= (1 << 7); + + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT), + .bRequest = REQ_ClearFeature, + .wValue = FEATURE_ENDPOINT_HALT, + .wIndex = EndpointNum, + .wLength = 0, + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + return USB_Host_SendControlRequest(NULL); +} + #endif