X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/d1e52660368d34d693131f6aff3c8fd8584162e5..d11ed10c5314c44dc01c06954d1d73d4894cbff8:/LUFA/Drivers/USB/LowLevel/Host.c diff --git a/LUFA/Drivers/USB/LowLevel/Host.c b/LUFA/Drivers/USB/LowLevel/Host.c index 02a1c2171..a5452fdb6 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, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, 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 + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + 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 + 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 software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -60,15 +60,18 @@ void USB_Host_ProcessNextHostState(void) } break; - case HOST_STATE_Attached: + case HOST_STATE_Powered: WaitMSRemaining = HOST_DEVICE_SETTLE_DELAY_MS; - USB_HostState = HOST_STATE_Attached_WaitForDeviceSettle; + USB_HostState = HOST_STATE_Powered_WaitForDeviceSettle; break; - case HOST_STATE_Attached_WaitForDeviceSettle: - _delay_ms(1); - - if (!(WaitMSRemaining--)) + case HOST_STATE_Powered_WaitForDeviceSettle: + if (WaitMSRemaining--) + { + _delay_ms(1); + break; + } + else { USB_Host_VBUS_Manual_Off(); @@ -76,11 +79,11 @@ void USB_Host_ProcessNextHostState(void) USB_Host_VBUS_Auto_Enable(); USB_Host_VBUS_Auto_On(); - USB_HostState = HOST_STATE_Attached_WaitForConnect; + USB_HostState = HOST_STATE_Powered_WaitForConnect; } break; - case HOST_STATE_Attached_WaitForConnect: + case HOST_STATE_Powered_WaitForConnect: if (USB_INT_HasOccurred(USB_INT_DCONNI)) { USB_INT_Clear(USB_INT_DCONNI); @@ -88,23 +91,20 @@ void USB_Host_ProcessNextHostState(void) USB_INT_Clear(USB_INT_VBERRI); USB_INT_Enable(USB_INT_VBERRI); - - USB_IsConnected = true; - EVENT_USB_Connect(); USB_Host_ResumeBus(); Pipe_ClearPipes(); - HOST_TASK_NONBLOCK_WAIT(100, HOST_STATE_Attached_DoReset); + HOST_TASK_NONBLOCK_WAIT(100, HOST_STATE_Powered_DoReset); } break; - case HOST_STATE_Attached_DoReset: + case HOST_STATE_Powered_DoReset: USB_Host_ResetDevice(); - HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Powered); + HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Powered_ConfigPipe); break; - case HOST_STATE_Powered: + case HOST_STATE_Powered_ConfigPipe: Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL, PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP, PIPE_CONTROLPIPE_DEFAULT_SIZE, PIPE_BANK_SINGLE); @@ -136,11 +136,7 @@ void USB_Host_ProcessNextHostState(void) break; } - #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES) USB_ControlPipeSize = DataBuffer[offsetof(USB_Descriptor_Device_t, Endpoint0Size)]; - #else - USB_ControlPipeSize = DataBuffer[offsetof(USB_Descriptor_Device_t, bMaxPacketSize0)]; - #endif USB_Host_ResetDevice(); @@ -162,8 +158,6 @@ void USB_Host_ProcessNextHostState(void) break; } - Pipe_SetInfiniteINRequests(); - USB_ControlRequest = (USB_Request_Header_t) { .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE), @@ -184,22 +178,18 @@ void USB_Host_ProcessNextHostState(void) case HOST_STATE_Default_PostAddressSet: USB_Host_SetDeviceAddress(USB_HOST_DEVICEADDRESS); - EVENT_USB_DeviceEnumerationComplete(); + EVENT_USB_Host_DeviceEnumerationComplete(); USB_HostState = HOST_STATE_Addressed; - break; } if ((ErrorCode != HOST_ENUMERROR_NoError) && (USB_HostState != HOST_STATE_Unattached)) { - EVENT_USB_DeviceEnumerationFailed(ErrorCode, SubErrorCode); + EVENT_USB_Host_DeviceEnumerationFailed(ErrorCode, SubErrorCode); USB_Host_VBUS_Auto_Off(); - EVENT_USB_DeviceUnattached(); - - if (USB_IsConnected) - EVENT_USB_Disconnect(); + EVENT_USB_Host_DeviceUnattached(); USB_ResetInterface(); } @@ -214,13 +204,13 @@ 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--; } - if ((USB_IsConnected == false) || (USB_CurrentMode == USB_MODE_DEVICE)) + if ((USB_HostState == HOST_STATE_Unattached) || (USB_CurrentMode == USB_MODE_DEVICE)) { ErrorCode = HOST_WAITERROR_DeviceDisconnect; @@ -259,9 +249,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 +260,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 +275,72 @@ 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_GetDeviceStringDescriptor(uint8_t Index, void* const Buffer, uint8_t BufferLength) +{ + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE), + .bRequest = REQ_GetDescriptor, + .wValue = (DTYPE_String << 8) | Index, + .wIndex = 0, + .wLength = BufferLength, + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + return USB_Host_SendControlRequest(Buffer); +} + +uint8_t USB_Host_ClearPipeStall(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, + .wIndex = EndpointNum, + .wLength = 0, + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + return USB_Host_SendControlRequest(NULL); +} + #endif