X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/0fcbe22c9eb68f5769bf57469e1bcf9b340d0ae3..d11ed10c5314c44dc01c06954d1d73d4894cbff8:/LUFA/Drivers/USB/LowLevel/Host.c?ds=sidebyside diff --git a/LUFA/Drivers/USB/LowLevel/Host.c b/LUFA/Drivers/USB/LowLevel/Host.c index 78a9ca8fb..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,16 +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: - #if HOST_DEVICE_SETTLE_DELAY_MS > 0 - _delay_ms(1); - - if (!(WaitMSRemaining--)) + case HOST_STATE_Powered_WaitForDeviceSettle: + if (WaitMSRemaining--) + { + _delay_ms(1); + break; + } + else { USB_Host_VBUS_Manual_Off(); @@ -77,14 +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; } - #else - USB_HostState = HOST_STATE_Attached_WaitForConnect; - #endif break; - case HOST_STATE_Attached_WaitForConnect: + case HOST_STATE_Powered_WaitForConnect: if (USB_INT_HasOccurred(USB_INT_DCONNI)) { USB_INT_Clear(USB_INT_DCONNI); @@ -92,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); @@ -140,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(); @@ -186,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(); } @@ -222,7 +210,7 @@ uint8_t USB_Host_WaitMS(uint8_t MS) 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; @@ -288,7 +276,7 @@ static void USB_Host_ResetDevice(void) USB_INT_Enable(USB_INT_DDISCI); } -uint8_t USB_Host_SetDeviceConfiguration(uint8_t ConfigNumber) +uint8_t USB_Host_SetDeviceConfiguration(const uint8_t ConfigNumber) { USB_ControlRequest = (USB_Request_Header_t) { @@ -304,15 +292,15 @@ uint8_t USB_Host_SetDeviceConfiguration(uint8_t ConfigNumber) return USB_Host_SendControlRequest(NULL); } -uint8_t USB_Host_GetDeviceDescriptor(void* DeviceDescriptorPtr) +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), + .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); @@ -320,10 +308,26 @@ uint8_t USB_Host_GetDeviceDescriptor(void* DeviceDescriptorPtr) 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 |= (1 << 7); + EndpointNum |= ENDPOINT_DESCRIPTOR_DIR_IN; USB_ControlRequest = (USB_Request_Header_t) {