From 99d8a3936384d1e9286dfecfb6f7896294cd6c11 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Wed, 21 Jul 2010 12:20:34 +0000 Subject: Move and rename DevChaper9.c/.h and HostChapter9.c/.h to the HighLevel directory, new named DeviceStandardReq.c/.h and HostStandardReq.c/.h. Rename LowLevel.c/.h to USBController.c/.h. Remove dependancies on the complete header in the HighLevel USB driver directory, to ensure less work is required in later (possible) ports. --- LUFA/Common/Common.h | 3 +- LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h | 8 +- LUFA/Drivers/USB/HighLevel/DeviceStandardReq.c | 395 +++++++++++++++++++++++++ LUFA/Drivers/USB/HighLevel/DeviceStandardReq.h | 165 +++++++++++ LUFA/Drivers/USB/HighLevel/Events.h | 2 +- LUFA/Drivers/USB/HighLevel/HostStandardReq.c | 179 +++++++++++ LUFA/Drivers/USB/HighLevel/HostStandardReq.h | 117 ++++++++ LUFA/Drivers/USB/HighLevel/StdDescriptors.h | 1 + LUFA/Drivers/USB/HighLevel/StdRequestType.h | 3 + LUFA/Drivers/USB/HighLevel/StreamCallbacks.h | 3 + LUFA/Drivers/USB/HighLevel/USBTask.h | 8 +- LUFA/Drivers/USB/LowLevel/DevChapter9.c | 395 ------------------------- LUFA/Drivers/USB/LowLevel/DevChapter9.h | 164 ---------- LUFA/Drivers/USB/LowLevel/Device.h | 7 +- LUFA/Drivers/USB/LowLevel/HostChapter9.c | 179 ----------- LUFA/Drivers/USB/LowLevel/HostChapter9.h | 117 -------- LUFA/Drivers/USB/LowLevel/LowLevel.c | 271 ----------------- LUFA/Drivers/USB/LowLevel/LowLevel.h | 389 ------------------------ LUFA/Drivers/USB/LowLevel/USBController.c | 271 +++++++++++++++++ LUFA/Drivers/USB/LowLevel/USBController.h | 390 ++++++++++++++++++++++++ LUFA/Drivers/USB/LowLevel/USBInterrupt.h | 2 +- LUFA/Drivers/USB/USB.h | 12 +- LUFA/ManPages/MigrationInformation.txt | 6 + LUFA/Scheduler/Scheduler.h | 2 +- LUFA/makefile | 8 +- 25 files changed, 1558 insertions(+), 1539 deletions(-) create mode 100644 LUFA/Drivers/USB/HighLevel/DeviceStandardReq.c create mode 100644 LUFA/Drivers/USB/HighLevel/DeviceStandardReq.h create mode 100644 LUFA/Drivers/USB/HighLevel/HostStandardReq.c create mode 100644 LUFA/Drivers/USB/HighLevel/HostStandardReq.h delete mode 100644 LUFA/Drivers/USB/LowLevel/DevChapter9.c delete mode 100644 LUFA/Drivers/USB/LowLevel/DevChapter9.h delete mode 100644 LUFA/Drivers/USB/LowLevel/HostChapter9.c delete mode 100644 LUFA/Drivers/USB/LowLevel/HostChapter9.h delete mode 100644 LUFA/Drivers/USB/LowLevel/LowLevel.c delete mode 100644 LUFA/Drivers/USB/LowLevel/LowLevel.h create mode 100644 LUFA/Drivers/USB/LowLevel/USBController.c create mode 100644 LUFA/Drivers/USB/LowLevel/USBController.h (limited to 'LUFA') diff --git a/LUFA/Common/Common.h b/LUFA/Common/Common.h index 76144f94b..e52aae8e0 100644 --- a/LUFA/Common/Common.h +++ b/LUFA/Common/Common.h @@ -57,7 +57,8 @@ #define __COMMON_H__ /* Includes: */ - #include + #include + #include #include "Attributes.h" #include "BoardTypes.h" diff --git a/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h b/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h index 76b734bd7..9d4a2b3b1 100644 --- a/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h +++ b/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h @@ -51,12 +51,12 @@ #define __CONFIGDESCRIPTOR_H__ /* Includes: */ - #include + #include #include "../../../Common/Common.h" - #include "../HighLevel/USBMode.h" - #include "../LowLevel/HostChapter9.h" - #include "../HighLevel/StdDescriptors.h" + #include "HostStandardReq.h" + #include "USBMode.h" + #include "StdDescriptors.h" /* Enable C linkage for C++ Compilers: */ #if defined(__cplusplus) diff --git a/LUFA/Drivers/USB/HighLevel/DeviceStandardReq.c b/LUFA/Drivers/USB/HighLevel/DeviceStandardReq.c new file mode 100644 index 000000000..64af1406b --- /dev/null +++ b/LUFA/Drivers/USB/HighLevel/DeviceStandardReq.c @@ -0,0 +1,395 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2010. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + 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 + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#define __INCLUDE_FROM_USB_DRIVER +#include "USBMode.h" + +#if defined(USB_CAN_BE_DEVICE) + +#define __INCLUDE_FROM_DEVICESTDREQ_C +#include "DeviceStandardReq.h" + +uint8_t USB_ConfigurationNumber; + +#if !defined(NO_DEVICE_SELF_POWER) +bool USB_CurrentlySelfPowered; +#endif + +#if !defined(NO_DEVICE_REMOTE_WAKEUP) +bool USB_RemoteWakeupEnabled; +#endif + +void USB_Device_ProcessControlRequest(void) +{ + bool RequestHandled = false; + uint8_t* RequestHeader = (uint8_t*)&USB_ControlRequest; + + for (uint8_t RequestHeaderByte = 0; RequestHeaderByte < sizeof(USB_Request_Header_t); RequestHeaderByte++) + *(RequestHeader++) = Endpoint_Read_Byte(); + + uint8_t bmRequestType = USB_ControlRequest.bmRequestType; + + switch (USB_ControlRequest.bRequest) + { + case REQ_GetStatus: + if ((bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) || + (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT))) + { + USB_Device_GetStatus(); + RequestHandled = true; + } + + break; + case REQ_ClearFeature: + case REQ_SetFeature: + if ((bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE)) || + (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT))) + { + USB_Device_ClearSetFeature(); + RequestHandled = true; + } + + break; + case REQ_SetAddress: + if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE)) + { + USB_Device_SetAddress(); + RequestHandled = true; + } + + break; + case REQ_GetDescriptor: + if ((bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) || + (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE))) + { + USB_Device_GetDescriptor(); + RequestHandled = true; + } + + break; + case REQ_GetConfiguration: + if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) + { + USB_Device_GetConfiguration(); + RequestHandled = true; + } + + break; + case REQ_SetConfiguration: + if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE)) + { + USB_Device_SetConfiguration(); + RequestHandled = true; + } + + break; + } + + if (!(RequestHandled)) + EVENT_USB_Device_UnhandledControlRequest(); + + if (Endpoint_IsSETUPReceived()) + { + Endpoint_StallTransaction(); + Endpoint_ClearSETUP(); + } +} + +static void USB_Device_SetAddress(void) +{ + uint8_t DeviceAddress = (USB_ControlRequest.wValue & 0x7F); + + Endpoint_ClearSETUP(); + + Endpoint_ClearStatusStage(); + + while (!(Endpoint_IsINReady())) + { + if (USB_DeviceState == DEVICE_STATE_Unattached) + return; + } + + USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default; + + USB_Device_SetDeviceAddress(DeviceAddress); + + return; +} + +static void USB_Device_SetConfiguration(void) +{ +#if defined(FIXED_NUM_CONFIGURATIONS) + if ((uint8_t)USB_ControlRequest.wValue > FIXED_NUM_CONFIGURATIONS) + return; +#else + #if defined(USE_FLASH_DESCRIPTORS) + #define MemoryAddressSpace MEMSPACE_FLASH + #elif defined(USE_EEPROM_DESCRIPTORS) + #define MemoryAddressSpace MEMSPACE_EEPROM + #elif defined(USE_SRAM_DESCRIPTORS) + #define MemoryAddressSpace MEMSPACE_SRAM + #else + uint8_t MemoryAddressSpace; + #endif + + USB_Descriptor_Device_t* DevDescriptorPtr; + + if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DevDescriptorPtr + #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS) + , &MemoryAddressSpace + #endif + ) == NO_DESCRIPTOR) + { + return; + } + + if (MemoryAddressSpace == MEMSPACE_FLASH) + { + if (((uint8_t)USB_ControlRequest.wValue > pgm_read_byte(&DevDescriptorPtr->NumberOfConfigurations))) + return; + } + else if (MemoryAddressSpace == MEMSPACE_EEPROM) + { + if (((uint8_t)USB_ControlRequest.wValue > eeprom_read_byte(&DevDescriptorPtr->NumberOfConfigurations))) + return; + } + else + { + if ((uint8_t)USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations) + return; + } +#endif + + Endpoint_ClearSETUP(); + + USB_ConfigurationNumber = (uint8_t)USB_ControlRequest.wValue; + + Endpoint_ClearStatusStage(); + + USB_DeviceState = (USB_ConfigurationNumber) ? DEVICE_STATE_Configured : DEVICE_STATE_Addressed; + + EVENT_USB_Device_ConfigurationChanged(); +} + +void USB_Device_GetConfiguration(void) +{ + Endpoint_ClearSETUP(); + + Endpoint_Write_Byte(USB_ConfigurationNumber); + Endpoint_ClearIN(); + + Endpoint_ClearStatusStage(); +} + +#if !defined(NO_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL != NO_DESCRIPTOR) +static char USB_Device_NibbleToASCII(uint8_t Nibble) +{ + Nibble = ((Nibble & 0x0F) + '0'); + return (Nibble > '9') ? (Nibble + ('A' - '9' - 1)) : Nibble; +} + +static void USB_Device_GetInternalSerialDescriptor(void) +{ + struct + { + USB_Descriptor_Header_t Header; + int16_t UnicodeString[20]; + } SignatureDescriptor; + + SignatureDescriptor.Header.Type = DTYPE_String; + SignatureDescriptor.Header.Size = sizeof(SignatureDescriptor); + + uint8_t SigReadAddress = 0x0E; + + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) + { + for (uint8_t SerialCharNum = 0; SerialCharNum < 20; SerialCharNum++) + { + uint8_t SerialByte = boot_signature_byte_get(SigReadAddress); + + if (SerialCharNum & 0x01) + { + SerialByte >>= 4; + SigReadAddress++; + } + + SignatureDescriptor.UnicodeString[SerialCharNum] = USB_Device_NibbleToASCII(SerialByte); + } + } + + Endpoint_ClearSETUP(); + + Endpoint_Write_Control_Stream_LE(&SignatureDescriptor, sizeof(SignatureDescriptor)); + + Endpoint_ClearOUT(); +} +#endif + +static void USB_Device_GetDescriptor(void) +{ + void* DescriptorPointer; + uint16_t DescriptorSize; + + #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS) + uint8_t DescriptorAddressSpace; + #endif + + #if !defined(NO_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL != NO_DESCRIPTOR) + if (USB_ControlRequest.wValue == ((DTYPE_String << 8) | USE_INTERNAL_SERIAL)) + { + USB_Device_GetInternalSerialDescriptor(); + return; + } + #endif + + if ((DescriptorSize = CALLBACK_USB_GetDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex, + &DescriptorPointer + #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS) + , &DescriptorAddressSpace + #endif + )) == NO_DESCRIPTOR) + { + return; + } + + Endpoint_ClearSETUP(); + + #if defined(USE_RAM_DESCRIPTORS) + Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize); + #elif defined(USE_EEPROM_DESCRIPTORS) + Endpoint_Write_Control_EStream_LE(DescriptorPointer, DescriptorSize); + #elif defined(USE_FLASH_DESCRIPTORS) + Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize); + #else + if (DescriptorAddressSpace == MEMSPACE_FLASH) + Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize); + else if (DescriptorAddressSpace == MEMSPACE_EEPROM) + Endpoint_Write_Control_EStream_LE(DescriptorPointer, DescriptorSize); + else + Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize); + #endif + + Endpoint_ClearOUT(); +} + +static void USB_Device_GetStatus(void) +{ + uint8_t CurrentStatus = 0; + + switch (USB_ControlRequest.bmRequestType) + { +#if !defined(NO_DEVICE_SELF_POWER) || !defined(NO_DEVICE_REMOTE_WAKEUP) + case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE): + #if !defined(NO_DEVICE_SELF_POWER) + if (USB_CurrentlySelfPowered) + CurrentStatus |= FEATURE_SELFPOWERED_ENABLED; + #endif + + #if !defined(NO_DEVICE_REMOTE_WAKEUP) + if (USB_RemoteWakeupEnabled) + CurrentStatus |= FEATURE_REMOTE_WAKEUP_ENABLED; + #endif + break; +#endif +#if !defined(CONTROL_ONLY_DEVICE) + case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT): + Endpoint_SelectEndpoint((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK); + + CurrentStatus = Endpoint_IsStalled(); + + Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); + + break; +#endif + default: + return; + } + + Endpoint_ClearSETUP(); + + Endpoint_Write_Word_LE(CurrentStatus); + Endpoint_ClearIN(); + + Endpoint_ClearStatusStage(); +} + +static void USB_Device_ClearSetFeature(void) +{ + switch (USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) + { +#if !defined(NO_DEVICE_REMOTE_WAKEUP) + case REQREC_DEVICE: + if ((uint8_t)USB_ControlRequest.wValue == FEATURE_REMOTE_WAKEUP) + USB_RemoteWakeupEnabled = (USB_ControlRequest.bRequest == REQ_SetFeature); + else + return; + + break; +#endif +#if !defined(CONTROL_ONLY_DEVICE) + case REQREC_ENDPOINT: + if ((uint8_t)USB_ControlRequest.wValue == FEATURE_ENDPOINT_HALT) + { + uint8_t EndpointIndex = ((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK); + + if (EndpointIndex == ENDPOINT_CONTROLEP) + return; + + Endpoint_SelectEndpoint(EndpointIndex); + + if (!(Endpoint_IsEnabled())) + return; + + if (USB_ControlRequest.bRequest == REQ_SetFeature) + { + Endpoint_StallTransaction(); + } + else + { + Endpoint_ClearStall(); + Endpoint_ResetFIFO(EndpointIndex); + Endpoint_ResetDataToggle(); + } + } + + break; +#endif + default: + return; + } + + Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); + + Endpoint_ClearSETUP(); + + Endpoint_ClearStatusStage(); +} + +#endif diff --git a/LUFA/Drivers/USB/HighLevel/DeviceStandardReq.h b/LUFA/Drivers/USB/HighLevel/DeviceStandardReq.h new file mode 100644 index 000000000..a65b93b62 --- /dev/null +++ b/LUFA/Drivers/USB/HighLevel/DeviceStandardReq.h @@ -0,0 +1,165 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2010. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + 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 + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief USB device standard request management. + * + * This file contains the function prototypes necessary for the processing of incoming standard control requests + * when the library is in USB device mode. + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +#ifndef __DEVICESTDREQ_H__ +#define __DEVICESTDREQ_H__ + + /* Includes: */ + #include + #include + #include + #include + #include + #include + + #include "StdDescriptors.h" + #include "Events.h" + #include "StdRequestType.h" + #include "USBTask.h" + #include "../LowLevel/USBController.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + #if defined(USE_SINGLE_DEVICE_CONFIGURATION) + #define FIXED_NUM_CONFIGURATIONS 1 + #endif + + /* Enums: */ + #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS) + /** Enum for the possible descriptor memory spaces, for the MemoryAddressSpace of the + * \ref CALLBACK_USB_GetDescriptor() function. This can be used when none of the USE_*_DESCRIPTORS + * compile time options are used, to indicate in which memory space the descriptor is stored. + * + * \ingroup Group_Device + */ + enum USB_DescriptorMemorySpaces_t + { + MEMSPACE_FLASH = 0, /**< Indicates the requested descriptor is located in FLASH memory. */ + MEMSPACE_EEPROM = 1, /**< Indicates the requested descriptor is located in EEPROM memory. */ + MEMSPACE_RAM = 2, /**< Indicates the requested descriptor is located in RAM memory. */ + }; + #endif + + /* Global Variables: */ + /** Indicates the currently set configuration number of the device. USB devices may have several + * different configurations which the host can select between; this indicates the currently selected + * value, or 0 if no configuration has been selected. + * + * \note This variable should be treated as read-only in the user application, and never manually + * changed in value. + * + * \ingroup Group_Device + */ + extern uint8_t USB_ConfigurationNumber; + + #if !defined(NO_DEVICE_REMOTE_WAKEUP) + /** Indicates if the host is currently allowing the device to issue remote wakeup events. If this + * flag is cleared, the device should not issue remote wakeup events to the host. + * + * \note This variable should be treated as read-only in the user application, and never manually + * changed in value. + * \n\n + * + * \note To reduce FLASH usage of the compiled applications where Remote Wakeup is not supported, + * this global and the underlying management code can be disabled by defining the + * NO_DEVICE_REMOTE_WAKEUP token in the project makefile and passing it to the compiler via + * the -D switch. + * + * \ingroup Group_Device + */ + extern bool USB_RemoteWakeupEnabled; + #endif + + #if !defined(NO_DEVICE_SELF_POWER) + /** Indicates if the device is currently being powered by its own power supply, rather than being + * powered by the host's USB supply. This flag should remain cleared if the device does not + * support self powered mode, as indicated in the device descriptors. + * + * \ingroup Group_Device + */ + extern bool USB_CurrentlySelfPowered; + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + #if defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) + #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive. + #elif defined(USE_RAM_DESCRIPTORS) && defined(USE_FLASH_DESCRIPTORS) + #error USE_RAM_DESCRIPTORS and USE_FLASH_DESCRIPTORS are mutually exclusive. + #elif defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) + #error USE_FLASH_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive. + #elif defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) && defined(USE_RAM_DESCRIPTORS) + #error Only one of the USE_*_DESCRIPTORS modes should be selected. + #endif + + /* Function Prototypes: */ + void USB_Device_ProcessControlRequest(void); + + #if defined(__INCLUDE_FROM_DEVICESTDREQ_C) + static void USB_Device_SetAddress(void); + static void USB_Device_SetConfiguration(void); + static void USB_Device_GetConfiguration(void); + static void USB_Device_GetDescriptor(void); + static void USB_Device_GetStatus(void); + static void USB_Device_ClearSetFeature(void); + + #if !defined(NO_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL != NO_DESCRIPTOR) + static char USB_Device_NibbleToASCII(uint8_t Nibble) ATTR_ALWAYS_INLINE; + static void USB_Device_GetInternalSerialDescriptor(void); + #endif + #endif + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/HighLevel/Events.h b/LUFA/Drivers/USB/HighLevel/Events.h index d88c47123..ab63c7bfe 100644 --- a/LUFA/Drivers/USB/HighLevel/Events.h +++ b/LUFA/Drivers/USB/HighLevel/Events.h @@ -69,7 +69,7 @@ #define __USBEVENTS_H__ /* Includes: */ - #include + #include #include "../../../Common/Common.h" #include "USBMode.h" diff --git a/LUFA/Drivers/USB/HighLevel/HostStandardReq.c b/LUFA/Drivers/USB/HighLevel/HostStandardReq.c new file mode 100644 index 000000000..cc6dc41e6 --- /dev/null +++ b/LUFA/Drivers/USB/HighLevel/HostStandardReq.c @@ -0,0 +1,179 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2010. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + 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 + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#define __INCLUDE_FROM_USB_DRIVER +#include "USBMode.h" + +#if defined(USB_CAN_BE_HOST) + +#define __INCLUDE_FROM_HOSTSTDREQ_C +#include "HostStandardReq.h" + +uint8_t USB_Host_SendControlRequest(void* BufferPtr) +{ + uint8_t* HeaderStream = (uint8_t*)&USB_ControlRequest; + uint8_t* DataStream = (uint8_t*)BufferPtr; + bool BusSuspended = USB_Host_IsBusSuspended(); + uint8_t ReturnStatus = HOST_SENDCONTROL_Successful; + uint16_t DataLen = USB_ControlRequest.wLength; + + USB_Host_ResumeBus(); + + if ((ReturnStatus = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful) + goto End_Of_Control_Send; + + Pipe_SetPipeToken(PIPE_TOKEN_SETUP); + Pipe_ClearErrorFlags(); + + Pipe_Unfreeze(); + + for (uint8_t HeaderByte = 0; HeaderByte < sizeof(USB_Request_Header_t); HeaderByte++) + Pipe_Write_Byte(*(HeaderStream++)); + + Pipe_ClearSETUP(); + + if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_SetupSent)) != HOST_SENDCONTROL_Successful) + goto End_Of_Control_Send; + + Pipe_Freeze(); + + if ((ReturnStatus = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful) + goto End_Of_Control_Send; + + if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_DIRECTION) == REQDIR_DEVICETOHOST) + { + Pipe_SetPipeToken(PIPE_TOKEN_IN); + + if (DataStream != NULL) + { + while (DataLen) + { + Pipe_Unfreeze(); + + if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_InReceived)) != HOST_SENDCONTROL_Successful) + goto End_Of_Control_Send; + + if (!(Pipe_BytesInPipe())) + DataLen = 0; + + while (Pipe_BytesInPipe() && DataLen) + { + *(DataStream++) = Pipe_Read_Byte(); + DataLen--; + } + + Pipe_Freeze(); + Pipe_ClearIN(); + } + } + + Pipe_SetPipeToken(PIPE_TOKEN_OUT); + Pipe_Unfreeze(); + + if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_OutReady)) != HOST_SENDCONTROL_Successful) + goto End_Of_Control_Send; + + Pipe_ClearOUT(); + + if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_OutReady)) != HOST_SENDCONTROL_Successful) + goto End_Of_Control_Send; + } + else + { + if (DataStream != NULL) + { + Pipe_SetPipeToken(PIPE_TOKEN_OUT); + Pipe_Unfreeze(); + + while (DataLen) + { + if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_OutReady)) != HOST_SENDCONTROL_Successful) + goto End_Of_Control_Send; + + while (DataLen && (Pipe_BytesInPipe() < USB_ControlPipeSize)) + { + Pipe_Write_Byte(*(DataStream++)); + DataLen--; + } + + Pipe_ClearOUT(); + } + + if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_OutReady)) != HOST_SENDCONTROL_Successful) + goto End_Of_Control_Send; + + Pipe_Freeze(); + } + + Pipe_SetPipeToken(PIPE_TOKEN_IN); + Pipe_Unfreeze(); + + if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_InReceived)) != HOST_SENDCONTROL_Successful) + goto End_Of_Control_Send; + + Pipe_ClearIN(); + } + +End_Of_Control_Send: + Pipe_Freeze(); + + if (BusSuspended) + USB_Host_SuspendBus(); + + Pipe_ResetPipe(PIPE_CONTROLPIPE); + + return ReturnStatus; +} + +static uint8_t USB_Host_WaitForIOS(const uint8_t WaitType) +{ + #if (USB_HOST_TIMEOUT_MS < 0xFF) + uint8_t TimeoutCounter = USB_HOST_TIMEOUT_MS; + #else + uint16_t TimeoutCounter = USB_HOST_TIMEOUT_MS; + #endif + + while (!(((WaitType == USB_HOST_WAITFOR_SetupSent) && Pipe_IsSETUPSent()) || + ((WaitType == USB_HOST_WAITFOR_InReceived) && Pipe_IsINReceived()) || + ((WaitType == USB_HOST_WAITFOR_OutReady) && Pipe_IsOUTReady()))) + { + uint8_t ErrorCode; + + if ((ErrorCode = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful) + return ErrorCode; + + if (!(TimeoutCounter--)) + return HOST_SENDCONTROL_SoftwareTimeOut; + } + + return HOST_SENDCONTROL_Successful; +} + +#endif diff --git a/LUFA/Drivers/USB/HighLevel/HostStandardReq.h b/LUFA/Drivers/USB/HighLevel/HostStandardReq.h new file mode 100644 index 000000000..4a527faee --- /dev/null +++ b/LUFA/Drivers/USB/HighLevel/HostStandardReq.h @@ -0,0 +1,117 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2010. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + 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 + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief USB host standard request management. + * + * This file contains the function prototypes necessary for the issuing of outgoing standard control requests + * when the library is in USB host mode. + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +#ifndef __HOSTSTDREQ_H__ +#define __HOSTSTDREQ_H__ + + /* Includes: */ + #include + #include + + #include "USBMode.h" + #include "StdRequestType.h" + #include "../LowLevel/USBController.h" + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + /* Public Interface - May be used in end-application: */ + /* Enums: */ + /** Enum for the \ref USB_Host_SendControlRequest() return code, indicating the reason for the error + * if the transfer of the request is unsuccessful. + * + * \ingroup Group_PipeControlReq + */ + enum USB_Host_SendControlErrorCodes_t + { + HOST_SENDCONTROL_Successful = 0, /**< No error occurred in the request transfer. */ + HOST_SENDCONTROL_DeviceDisconnected = 1, /**< The attached device was disconnected during the + * request transfer. + */ + HOST_SENDCONTROL_PipeError = 2, /**< An error occurred in the pipe while sending the request. */ + HOST_SENDCONTROL_SetupStalled = 3, /**< The attached device stalled the request, usually + * indicating that the request is unsupported on the device. + */ + HOST_SENDCONTROL_SoftwareTimeOut = 4, /**< The request or data transfer timed out. */ + }; + + /* Function Prototypes: */ + /** Sends the request stored in the \ref USB_ControlRequest global structure to the attached device, + * and transfers the data stored in the buffer to the device, or from the device to the buffer + * as requested. The transfer is made on the currently selected pipe. + * + * \ingroup Group_PipeControlReq + * + * \param[in] BufferPtr Pointer to the start of the data buffer if the request has a data stage, or + * NULL if the request transfers no data to or from the device. + * + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. + */ + uint8_t USB_Host_SendControlRequest(void* BufferPtr); + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Enums: */ + enum USB_WaitForTypes_t + { + USB_HOST_WAITFOR_SetupSent, + USB_HOST_WAITFOR_InReceived, + USB_HOST_WAITFOR_OutReady, + }; + + /* Function Prototypes: */ + #if defined(__INCLUDE_FROM_HOSTSTDREQ_C) + static uint8_t USB_Host_WaitForIOS(const uint8_t WaitType); + #endif + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif diff --git a/LUFA/Drivers/USB/HighLevel/StdDescriptors.h b/LUFA/Drivers/USB/HighLevel/StdDescriptors.h index 1798365c5..6768b59f0 100644 --- a/LUFA/Drivers/USB/HighLevel/StdDescriptors.h +++ b/LUFA/Drivers/USB/HighLevel/StdDescriptors.h @@ -52,6 +52,7 @@ /* Includes: */ #include #include + #include #include #include "../../../Common/Common.h" diff --git a/LUFA/Drivers/USB/HighLevel/StdRequestType.h b/LUFA/Drivers/USB/HighLevel/StdRequestType.h index 505ccd3c2..f8e4f45f4 100644 --- a/LUFA/Drivers/USB/HighLevel/StdRequestType.h +++ b/LUFA/Drivers/USB/HighLevel/StdRequestType.h @@ -49,6 +49,9 @@ #ifndef __STDREQTYPE_H__ #define __STDREQTYPE_H__ + /* Includes: */ + #include + /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. diff --git a/LUFA/Drivers/USB/HighLevel/StreamCallbacks.h b/LUFA/Drivers/USB/HighLevel/StreamCallbacks.h index d3334e72f..dc3495285 100644 --- a/LUFA/Drivers/USB/HighLevel/StreamCallbacks.h +++ b/LUFA/Drivers/USB/HighLevel/StreamCallbacks.h @@ -51,6 +51,9 @@ #ifndef __STREAMCALLBACK_H__ #define __STREAMCALLBACK_H__ + /* Includes: */ + #include + /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. diff --git a/LUFA/Drivers/USB/HighLevel/USBTask.h b/LUFA/Drivers/USB/HighLevel/USBTask.h index cce7bb29e..faff2a3bb 100644 --- a/LUFA/Drivers/USB/HighLevel/USBTask.h +++ b/LUFA/Drivers/USB/HighLevel/USBTask.h @@ -42,22 +42,22 @@ #define __USBTASK_H__ /* Includes: */ - #include #include + #include #include - #include "../LowLevel/LowLevel.h" + #include "../LowLevel/USBController.h" #include "Events.h" #include "StdRequestType.h" #include "StdDescriptors.h" #include "USBMode.h" #if defined(USB_CAN_BE_DEVICE) - #include "../LowLevel/DevChapter9.h" + #include "DeviceStandardReq.h" #endif #if defined(USB_CAN_BE_HOST) - #include "../LowLevel/HostChapter9.h" + #include "HostStandardReq.h" #endif /* Enable C linkage for C++ Compilers: */ diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.c b/LUFA/Drivers/USB/LowLevel/DevChapter9.c deleted file mode 100644 index 544531b8d..000000000 --- a/LUFA/Drivers/USB/LowLevel/DevChapter9.c +++ /dev/null @@ -1,395 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2010. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - 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 - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#define __INCLUDE_FROM_USB_DRIVER -#include "../HighLevel/USBMode.h" - -#if defined(USB_CAN_BE_DEVICE) - -#define __INCLUDE_FROM_DEVCHAPTER9_C -#include "DevChapter9.h" - -uint8_t USB_ConfigurationNumber; - -#if !defined(NO_DEVICE_SELF_POWER) -bool USB_CurrentlySelfPowered; -#endif - -#if !defined(NO_DEVICE_REMOTE_WAKEUP) -bool USB_RemoteWakeupEnabled; -#endif - -void USB_Device_ProcessControlRequest(void) -{ - bool RequestHandled = false; - uint8_t* RequestHeader = (uint8_t*)&USB_ControlRequest; - - for (uint8_t RequestHeaderByte = 0; RequestHeaderByte < sizeof(USB_Request_Header_t); RequestHeaderByte++) - *(RequestHeader++) = Endpoint_Read_Byte(); - - uint8_t bmRequestType = USB_ControlRequest.bmRequestType; - - switch (USB_ControlRequest.bRequest) - { - case REQ_GetStatus: - if ((bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) || - (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT))) - { - USB_Device_GetStatus(); - RequestHandled = true; - } - - break; - case REQ_ClearFeature: - case REQ_SetFeature: - if ((bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE)) || - (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT))) - { - USB_Device_ClearSetFeature(); - RequestHandled = true; - } - - break; - case REQ_SetAddress: - if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE)) - { - USB_Device_SetAddress(); - RequestHandled = true; - } - - break; - case REQ_GetDescriptor: - if ((bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) || - (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE))) - { - USB_Device_GetDescriptor(); - RequestHandled = true; - } - - break; - case REQ_GetConfiguration: - if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) - { - USB_Device_GetConfiguration(); - RequestHandled = true; - } - - break; - case REQ_SetConfiguration: - if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE)) - { - USB_Device_SetConfiguration(); - RequestHandled = true; - } - - break; - } - - if (!(RequestHandled)) - EVENT_USB_Device_UnhandledControlRequest(); - - if (Endpoint_IsSETUPReceived()) - { - Endpoint_StallTransaction(); - Endpoint_ClearSETUP(); - } -} - -static void USB_Device_SetAddress(void) -{ - uint8_t DeviceAddress = (USB_ControlRequest.wValue & 0x7F); - - Endpoint_ClearSETUP(); - - Endpoint_ClearStatusStage(); - - while (!(Endpoint_IsINReady())) - { - if (USB_DeviceState == DEVICE_STATE_Unattached) - return; - } - - USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default; - - UDADDR = ((1 << ADDEN) | DeviceAddress); - - return; -} - -static void USB_Device_SetConfiguration(void) -{ -#if defined(FIXED_NUM_CONFIGURATIONS) - if ((uint8_t)USB_ControlRequest.wValue > FIXED_NUM_CONFIGURATIONS) - return; -#else - #if defined(USE_FLASH_DESCRIPTORS) - #define MemoryAddressSpace MEMSPACE_FLASH - #elif defined(USE_EEPROM_DESCRIPTORS) - #define MemoryAddressSpace MEMSPACE_EEPROM - #elif defined(USE_SRAM_DESCRIPTORS) - #define MemoryAddressSpace MEMSPACE_SRAM - #else - uint8_t MemoryAddressSpace; - #endif - - USB_Descriptor_Device_t* DevDescriptorPtr; - - if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DevDescriptorPtr - #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS) - , &MemoryAddressSpace - #endif - ) == NO_DESCRIPTOR) - { - return; - } - - if (MemoryAddressSpace == MEMSPACE_FLASH) - { - if (((uint8_t)USB_ControlRequest.wValue > pgm_read_byte(&DevDescriptorPtr->NumberOfConfigurations))) - return; - } - else if (MemoryAddressSpace == MEMSPACE_EEPROM) - { - if (((uint8_t)USB_ControlRequest.wValue > eeprom_read_byte(&DevDescriptorPtr->NumberOfConfigurations))) - return; - } - else - { - if ((uint8_t)USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations) - return; - } -#endif - - Endpoint_ClearSETUP(); - - USB_ConfigurationNumber = (uint8_t)USB_ControlRequest.wValue; - - Endpoint_ClearStatusStage(); - - USB_DeviceState = (USB_ConfigurationNumber) ? DEVICE_STATE_Configured : DEVICE_STATE_Addressed; - - EVENT_USB_Device_ConfigurationChanged(); -} - -void USB_Device_GetConfiguration(void) -{ - Endpoint_ClearSETUP(); - - Endpoint_Write_Byte(USB_ConfigurationNumber); - Endpoint_ClearIN(); - - Endpoint_ClearStatusStage(); -} - -#if !defined(NO_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL != NO_DESCRIPTOR) -static char USB_Device_NibbleToASCII(uint8_t Nibble) -{ - Nibble = ((Nibble & 0x0F) + '0'); - return (Nibble > '9') ? (Nibble + ('A' - '9' - 1)) : Nibble; -} - -static void USB_Device_GetInternalSerialDescriptor(void) -{ - struct - { - USB_Descriptor_Header_t Header; - int16_t UnicodeString[20]; - } SignatureDescriptor; - - SignatureDescriptor.Header.Type = DTYPE_String; - SignatureDescriptor.Header.Size = sizeof(SignatureDescriptor); - - uint8_t SigReadAddress = 0x0E; - - ATOMIC_BLOCK(ATOMIC_RESTORESTATE) - { - for (uint8_t SerialCharNum = 0; SerialCharNum < 20; SerialCharNum++) - { - uint8_t SerialByte = boot_signature_byte_get(SigReadAddress); - - if (SerialCharNum & 0x01) - { - SerialByte >>= 4; - SigReadAddress++; - } - - SignatureDescriptor.UnicodeString[SerialCharNum] = USB_Device_NibbleToASCII(SerialByte); - } - } - - Endpoint_ClearSETUP(); - - Endpoint_Write_Control_Stream_LE(&SignatureDescriptor, sizeof(SignatureDescriptor)); - - Endpoint_ClearOUT(); -} -#endif - -static void USB_Device_GetDescriptor(void) -{ - void* DescriptorPointer; - uint16_t DescriptorSize; - - #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS) - uint8_t DescriptorAddressSpace; - #endif - - #if !defined(NO_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL != NO_DESCRIPTOR) - if (USB_ControlRequest.wValue == ((DTYPE_String << 8) | USE_INTERNAL_SERIAL)) - { - USB_Device_GetInternalSerialDescriptor(); - return; - } - #endif - - if ((DescriptorSize = CALLBACK_USB_GetDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex, - &DescriptorPointer - #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS) - , &DescriptorAddressSpace - #endif - )) == NO_DESCRIPTOR) - { - return; - } - - Endpoint_ClearSETUP(); - - #if defined(USE_RAM_DESCRIPTORS) - Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize); - #elif defined(USE_EEPROM_DESCRIPTORS) - Endpoint_Write_Control_EStream_LE(DescriptorPointer, DescriptorSize); - #elif defined(USE_FLASH_DESCRIPTORS) - Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize); - #else - if (DescriptorAddressSpace == MEMSPACE_FLASH) - Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize); - else if (DescriptorAddressSpace == MEMSPACE_EEPROM) - Endpoint_Write_Control_EStream_LE(DescriptorPointer, DescriptorSize); - else - Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize); - #endif - - Endpoint_ClearOUT(); -} - -static void USB_Device_GetStatus(void) -{ - uint8_t CurrentStatus = 0; - - switch (USB_ControlRequest.bmRequestType) - { -#if !defined(NO_DEVICE_SELF_POWER) || !defined(NO_DEVICE_REMOTE_WAKEUP) - case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE): - #if !defined(NO_DEVICE_SELF_POWER) - if (USB_CurrentlySelfPowered) - CurrentStatus |= FEATURE_SELFPOWERED_ENABLED; - #endif - - #if !defined(NO_DEVICE_REMOTE_WAKEUP) - if (USB_RemoteWakeupEnabled) - CurrentStatus |= FEATURE_REMOTE_WAKEUP_ENABLED; - #endif - break; -#endif -#if !defined(CONTROL_ONLY_DEVICE) - case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT): - Endpoint_SelectEndpoint((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK); - - CurrentStatus = Endpoint_IsStalled(); - - Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); - - break; -#endif - default: - return; - } - - Endpoint_ClearSETUP(); - - Endpoint_Write_Word_LE(CurrentStatus); - Endpoint_ClearIN(); - - Endpoint_ClearStatusStage(); -} - -static void USB_Device_ClearSetFeature(void) -{ - switch (USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) - { -#if !defined(NO_DEVICE_REMOTE_WAKEUP) - case REQREC_DEVICE: - if ((uint8_t)USB_ControlRequest.wValue == FEATURE_REMOTE_WAKEUP) - USB_RemoteWakeupEnabled = (USB_ControlRequest.bRequest == REQ_SetFeature); - else - return; - - break; -#endif -#if !defined(CONTROL_ONLY_DEVICE) - case REQREC_ENDPOINT: - if ((uint8_t)USB_ControlRequest.wValue == FEATURE_ENDPOINT_HALT) - { - uint8_t EndpointIndex = ((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK); - - if (EndpointIndex == ENDPOINT_CONTROLEP) - return; - - Endpoint_SelectEndpoint(EndpointIndex); - - if (!(Endpoint_IsEnabled())) - return; - - if (USB_ControlRequest.bRequest == REQ_SetFeature) - { - Endpoint_StallTransaction(); - } - else - { - Endpoint_ClearStall(); - Endpoint_ResetFIFO(EndpointIndex); - Endpoint_ResetDataToggle(); - } - } - - break; -#endif - default: - return; - } - - Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); - - Endpoint_ClearSETUP(); - - Endpoint_ClearStatusStage(); -} - -#endif diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.h b/LUFA/Drivers/USB/LowLevel/DevChapter9.h deleted file mode 100644 index ab62c535a..000000000 --- a/LUFA/Drivers/USB/LowLevel/DevChapter9.h +++ /dev/null @@ -1,164 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2010. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - 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 - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief USB device standard request management. - * - * This file contains the function prototypes necessary for the processing of incoming standard control requests - * when the library is in USB device mode. - * - * \note This file should not be included directly. It is automatically included as needed by the USB driver - * dispatch header located in LUFA/Drivers/USB/USB.h. - */ - -#ifndef __DEVCHAPTER9_H__ -#define __DEVCHAPTER9_H__ - - /* Includes: */ - #include - #include - #include - #include - #include - - #include "../HighLevel/StdDescriptors.h" - #include "../HighLevel/Events.h" - #include "../HighLevel/StdRequestType.h" - #include "../HighLevel/USBTask.h" - #include "LowLevel.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Macros: */ - #if defined(USE_SINGLE_DEVICE_CONFIGURATION) - #define FIXED_NUM_CONFIGURATIONS 1 - #endif - - /* Enums: */ - #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS) - /** Enum for the possible descriptor memory spaces, for the MemoryAddressSpace of the - * \ref CALLBACK_USB_GetDescriptor() function. This can be used when none of the USE_*_DESCRIPTORS - * compile time options are used, to indicate in which memory space the descriptor is stored. - * - * \ingroup Group_Device - */ - enum USB_DescriptorMemorySpaces_t - { - MEMSPACE_FLASH = 0, /**< Indicates the requested descriptor is located in FLASH memory. */ - MEMSPACE_EEPROM = 1, /**< Indicates the requested descriptor is located in EEPROM memory. */ - MEMSPACE_RAM = 2, /**< Indicates the requested descriptor is located in RAM memory. */ - }; - #endif - - /* Global Variables: */ - /** Indicates the currently set configuration number of the device. USB devices may have several - * different configurations which the host can select between; this indicates the currently selected - * value, or 0 if no configuration has been selected. - * - * \note This variable should be treated as read-only in the user application, and never manually - * changed in value. - * - * \ingroup Group_Device - */ - extern uint8_t USB_ConfigurationNumber; - - #if !defined(NO_DEVICE_REMOTE_WAKEUP) - /** Indicates if the host is currently allowing the device to issue remote wakeup events. If this - * flag is cleared, the device should not issue remote wakeup events to the host. - * - * \note This variable should be treated as read-only in the user application, and never manually - * changed in value. - * \n\n - * - * \note To reduce FLASH usage of the compiled applications where Remote Wakeup is not supported, - * this global and the underlying management code can be disabled by defining the - * NO_DEVICE_REMOTE_WAKEUP token in the project makefile and passing it to the compiler via - * the -D switch. - * - * \ingroup Group_Device - */ - extern bool USB_RemoteWakeupEnabled; - #endif - - #if !defined(NO_DEVICE_SELF_POWER) - /** Indicates if the device is currently being powered by its own power supply, rather than being - * powered by the host's USB supply. This flag should remain cleared if the device does not - * support self powered mode, as indicated in the device descriptors. - * - * \ingroup Group_Device - */ - extern bool USB_CurrentlySelfPowered; - #endif - - /* Private Interface - For use in library only: */ - #if !defined(__DOXYGEN__) - #if defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) - #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive. - #elif defined(USE_RAM_DESCRIPTORS) && defined(USE_FLASH_DESCRIPTORS) - #error USE_RAM_DESCRIPTORS and USE_FLASH_DESCRIPTORS are mutually exclusive. - #elif defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) - #error USE_FLASH_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive. - #elif defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) && defined(USE_RAM_DESCRIPTORS) - #error Only one of the USE_*_DESCRIPTORS modes should be selected. - #endif - - /* Function Prototypes: */ - void USB_Device_ProcessControlRequest(void); - - #if defined(__INCLUDE_FROM_DEVCHAPTER9_C) - static void USB_Device_SetAddress(void); - static void USB_Device_SetConfiguration(void); - static void USB_Device_GetConfiguration(void); - static void USB_Device_GetDescriptor(void); - static void USB_Device_GetStatus(void); - static void USB_Device_ClearSetFeature(void); - - #if !defined(NO_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL != NO_DESCRIPTOR) - static char USB_Device_NibbleToASCII(uint8_t Nibble) ATTR_ALWAYS_INLINE; - static void USB_Device_GetInternalSerialDescriptor(void); - #endif - #endif - #endif - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif diff --git a/LUFA/Drivers/USB/LowLevel/Device.h b/LUFA/Drivers/USB/LowLevel/Device.h index 27bc42828..02dd8cf0d 100644 --- a/LUFA/Drivers/USB/LowLevel/Device.h +++ b/LUFA/Drivers/USB/LowLevel/Device.h @@ -191,8 +191,11 @@ /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Macros: */ - #define USB_Device_SetLowSpeed() MACROS{ UDCON |= (1 << LSM); }MACROE - #define USB_Device_SetFullSpeed() MACROS{ UDCON &= ~(1 << LSM); }MACROE + #define USB_Device_SetLowSpeed() MACROS{ UDCON |= (1 << LSM); }MACROE + #define USB_Device_SetFullSpeed() MACROS{ UDCON &= ~(1 << LSM); }MACROE + + #define USB_Device_SetDeviceAddress(addr) MACROS{ UDADDR = ((1 << ADDEN) | (addr & 0x7F)); }MACROE + #endif #endif diff --git a/LUFA/Drivers/USB/LowLevel/HostChapter9.c b/LUFA/Drivers/USB/LowLevel/HostChapter9.c deleted file mode 100644 index 69575f18b..000000000 --- a/LUFA/Drivers/USB/LowLevel/HostChapter9.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2010. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - 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 - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#define __INCLUDE_FROM_USB_DRIVER -#include "../HighLevel/USBMode.h" - -#if defined(USB_CAN_BE_HOST) - -#define __INCLUDE_FROM_HOSTCHAPTER9_C -#include "HostChapter9.h" - -uint8_t USB_Host_SendControlRequest(void* BufferPtr) -{ - uint8_t* HeaderStream = (uint8_t*)&USB_ControlRequest; - uint8_t* DataStream = (uint8_t*)BufferPtr; - bool BusSuspended = USB_Host_IsBusSuspended(); - uint8_t ReturnStatus = HOST_SENDCONTROL_Successful; - uint16_t DataLen = USB_ControlRequest.wLength; - - USB_Host_ResumeBus(); - - if ((ReturnStatus = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful) - goto End_Of_Control_Send; - - Pipe_SetPipeToken(PIPE_TOKEN_SETUP); - Pipe_ClearErrorFlags(); - - Pipe_Unfreeze(); - - for (uint8_t HeaderByte = 0; HeaderByte < sizeof(USB_Request_Header_t); HeaderByte++) - Pipe_Write_Byte(*(HeaderStream++)); - - Pipe_ClearSETUP(); - - if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_SetupSent)) != HOST_SENDCONTROL_Successful) - goto End_Of_Control_Send; - - Pipe_Freeze(); - - if ((ReturnStatus = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful) - goto End_Of_Control_Send; - - if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_DIRECTION) == REQDIR_DEVICETOHOST) - { - Pipe_SetPipeToken(PIPE_TOKEN_IN); - - if (DataStream != NULL) - { - while (DataLen) - { - Pipe_Unfreeze(); - - if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_InReceived)) != HOST_SENDCONTROL_Successful) - goto End_Of_Control_Send; - - if (!(Pipe_BytesInPipe())) - DataLen = 0; - - while (Pipe_BytesInPipe() && DataLen) - { - *(DataStream++) = Pipe_Read_Byte(); - DataLen--; - } - - Pipe_Freeze(); - Pipe_ClearIN(); - } - } - - Pipe_SetPipeToken(PIPE_TOKEN_OUT); - Pipe_Unfreeze(); - - if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_OutReady)) != HOST_SENDCONTROL_Successful) - goto End_Of_Control_Send; - - Pipe_ClearOUT(); - - if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_OutReady)) != HOST_SENDCONTROL_Successful) - goto End_Of_Control_Send; - } - else - { - if (DataStream != NULL) - { - Pipe_SetPipeToken(PIPE_TOKEN_OUT); - Pipe_Unfreeze(); - - while (DataLen) - { - if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_OutReady)) != HOST_SENDCONTROL_Successful) - goto End_Of_Control_Send; - - while (DataLen && (Pipe_BytesInPipe() < USB_ControlPipeSize)) - { - Pipe_Write_Byte(*(DataStream++)); - DataLen--; - } - - Pipe_ClearOUT(); - } - - if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_OutReady)) != HOST_SENDCONTROL_Successful) - goto End_Of_Control_Send; - - Pipe_Freeze(); - } - - Pipe_SetPipeToken(PIPE_TOKEN_IN); - Pipe_Unfreeze(); - - if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_InReceived)) != HOST_SENDCONTROL_Successful) - goto End_Of_Control_Send; - - Pipe_ClearIN(); - } - -End_Of_Control_Send: - Pipe_Freeze(); - - if (BusSuspended) - USB_Host_SuspendBus(); - - Pipe_ResetPipe(PIPE_CONTROLPIPE); - - return ReturnStatus; -} - -static uint8_t USB_Host_WaitForIOS(const uint8_t WaitType) -{ - #if (USB_HOST_TIMEOUT_MS < 0xFF) - uint8_t TimeoutCounter = USB_HOST_TIMEOUT_MS; - #else - uint16_t TimeoutCounter = USB_HOST_TIMEOUT_MS; - #endif - - while (!(((WaitType == USB_HOST_WAITFOR_SetupSent) && Pipe_IsSETUPSent()) || - ((WaitType == USB_HOST_WAITFOR_InReceived) && Pipe_IsINReceived()) || - ((WaitType == USB_HOST_WAITFOR_OutReady) && Pipe_IsOUTReady()))) - { - uint8_t ErrorCode; - - if ((ErrorCode = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful) - return ErrorCode; - - if (!(TimeoutCounter--)) - return HOST_SENDCONTROL_SoftwareTimeOut; - } - - return HOST_SENDCONTROL_Successful; -} - -#endif diff --git a/LUFA/Drivers/USB/LowLevel/HostChapter9.h b/LUFA/Drivers/USB/LowLevel/HostChapter9.h deleted file mode 100644 index 0518855ad..000000000 --- a/LUFA/Drivers/USB/LowLevel/HostChapter9.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2010. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - 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 - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief USB host standard request management. - * - * This file contains the function prototypes necessary for the issuing of outgoing standard control requests - * when the library is in USB host mode. - * - * \note This file should not be included directly. It is automatically included as needed by the USB driver - * dispatch header located in LUFA/Drivers/USB/USB.h. - */ - -#ifndef __HOSTCHAPTER9_H__ -#define __HOSTCHAPTER9_H__ - - /* Includes: */ - #include - #include - - #include "LowLevel.h" - #include "../HighLevel/USBMode.h" - #include "../HighLevel/StdRequestType.h" - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks: */ - #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. - #endif - - /* Public Interface - May be used in end-application: */ - /* Enums: */ - /** Enum for the \ref USB_Host_SendControlRequest() return code, indicating the reason for the error - * if the transfer of the request is unsuccessful. - * - * \ingroup Group_PipeControlReq - */ - enum USB_Host_SendControlErrorCodes_t - { - HOST_SENDCONTROL_Successful = 0, /**< No error occurred in the request transfer. */ - HOST_SENDCONTROL_DeviceDisconnected = 1, /**< The attached device was disconnected during the - * request transfer. - */ - HOST_SENDCONTROL_PipeError = 2, /**< An error occurred in the pipe while sending the request. */ - HOST_SENDCONTROL_SetupStalled = 3, /**< The attached device stalled the request, usually - * indicating that the request is unsupported on the device. - */ - HOST_SENDCONTROL_SoftwareTimeOut = 4, /**< The request or data transfer timed out. */ - }; - - /* Function Prototypes: */ - /** Sends the request stored in the \ref USB_ControlRequest global structure to the attached device, - * and transfers the data stored in the buffer to the device, or from the device to the buffer - * as requested. The transfer is made on the currently selected pipe. - * - * \ingroup Group_PipeControlReq - * - * \param[in] BufferPtr Pointer to the start of the data buffer if the request has a data stage, or - * NULL if the request transfers no data to or from the device. - * - * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. - */ - uint8_t USB_Host_SendControlRequest(void* BufferPtr); - - /* Private Interface - For use in library only: */ - #if !defined(__DOXYGEN__) - /* Enums: */ - enum USB_WaitForTypes_t - { - USB_HOST_WAITFOR_SetupSent, - USB_HOST_WAITFOR_InReceived, - USB_HOST_WAITFOR_OutReady, - }; - - /* Function Prototypes: */ - #if defined(__INCLUDE_FROM_HOSTCHAPTER9_C) - static uint8_t USB_Host_WaitForIOS(const uint8_t WaitType); - #endif - #endif - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif diff --git a/LUFA/Drivers/USB/LowLevel/LowLevel.c b/LUFA/Drivers/USB/LowLevel/LowLevel.c deleted file mode 100644 index 4c742102b..000000000 --- a/LUFA/Drivers/USB/LowLevel/LowLevel.c +++ /dev/null @@ -1,271 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2010. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - 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 - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -#define __INCLUDE_FROM_USB_DRIVER -#include "LowLevel.h" - -#if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) -volatile uint8_t USB_CurrentMode = USB_MODE_NONE; -#endif - -#if !defined(USE_STATIC_OPTIONS) -volatile uint8_t USB_Options; -#endif - -void USB_Init( - #if defined(USB_CAN_BE_BOTH) - const uint8_t Mode - #endif - - #if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS)) - , - #elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS)) - void - #endif - - #if !defined(USE_STATIC_OPTIONS) - const uint8_t Options - #endif - ) -{ - #if defined(USB_CAN_BE_BOTH) - USB_CurrentMode = Mode; - #endif - - #if !defined(USE_STATIC_OPTIONS) - USB_Options = Options; - #endif - - #if defined(USB_CAN_BE_HOST) - USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE; - #endif - - #if defined(USB_DEVICE_ONLY) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) - UHWCON |= (1 << UIMOD); - #elif defined(USB_HOST_ONLY) - UHWCON &= ~(1 << UIMOD); - #elif defined(USB_CAN_BE_BOTH) - if (Mode == USB_MODE_UID) - { - UHWCON |= (1 << UIDE); - - USB_INT_Clear(USB_INT_IDTI); - USB_INT_Enable(USB_INT_IDTI); - - USB_CurrentMode = USB_GetUSBModeFromUID(); - } - else if (Mode == USB_MODE_DEVICE) - { - UHWCON |= (1 << UIMOD); - } - else if (Mode == USB_MODE_HOST) - { - UHWCON &= ~(1 << UIMOD); - } - else - { - EVENT_USB_InitFailure(USB_INITERROR_NoUSBModeSpecified); - return; - } - #endif - - USB_ResetInterface(); - - #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) - USB_OTGPAD_On(); - #endif - - USB_IsInitialized = true; -} - -void USB_ShutDown(void) -{ - USB_ResetInterface(); - USB_Detach(); - USB_Controller_Disable(); - - USB_INT_DisableAllInterrupts(); - USB_INT_ClearAllInterrupts(); - - #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) - UHWCON &= ~(1 << UIMOD); - #endif - - if (!(USB_Options & USB_OPT_MANUAL_PLL)) - USB_PLL_Off(); - - USB_REG_Off(); - - #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) - USB_OTGPAD_Off(); - #endif - - #if defined(USB_CAN_BE_BOTH) - UHWCON &= ~(1 << UIDE); - #endif - - USB_IsInitialized = false; - - #if defined(USB_CAN_BE_BOTH) - USB_CurrentMode = USB_MODE_NONE; - #endif -} - -void USB_ResetInterface(void) -{ - USB_INT_DisableAllInterrupts(); - USB_INT_ClearAllInterrupts(); - - #if defined(USB_CAN_BE_HOST) - USB_HostState = HOST_STATE_Unattached; - #endif - - #if defined(USB_CAN_BE_DEVICE) - USB_DeviceState = DEVICE_STATE_Unattached; - USB_ConfigurationNumber = 0; - - #if !defined(NO_DEVICE_REMOTE_WAKEUP) - USB_RemoteWakeupEnabled = false; - #endif - - #if !defined(NO_DEVICE_SELF_POWER) - USB_CurrentlySelfPowered = false; - #endif - #endif - - if (!(USB_Options & USB_OPT_MANUAL_PLL)) - { - #if defined(USB_SERIES_4_AVR) - PLLFRQ = ((1 << PLLUSB) | (1 << PDIV3) | (1 << PDIV1)); - #endif - - USB_PLL_On(); - while (!(USB_PLL_IsReady())); - } - - USB_Controller_Reset(); - - #if defined(USB_CAN_BE_BOTH) - if (UHWCON & (1 << UIDE)) - { - USB_INT_Clear(USB_INT_IDTI); - USB_INT_Enable(USB_INT_IDTI); - USB_CurrentMode = USB_GetUSBModeFromUID(); - } - #endif - - if (!(USB_Options & USB_OPT_REG_DISABLED)) - USB_REG_On(); - else - USB_REG_Off(); - - USB_CLK_Unfreeze(); - - #if (defined(USB_CAN_BE_DEVICE) && (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))) - if (USB_CurrentMode == USB_MODE_DEVICE) - { - if (USB_Options & USB_DEVICE_OPT_LOWSPEED) - USB_Device_SetLowSpeed(); - else - USB_Device_SetFullSpeed(); - } - #endif - - #if (defined(USB_CAN_BE_DEVICE) && !defined(FIXED_CONTROL_ENDPOINT_SIZE)) - if (USB_CurrentMode == USB_MODE_DEVICE) - { - USB_Descriptor_Device_t* DeviceDescriptorPtr; - - if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR) - { - #if defined(USE_RAM_DESCRIPTORS) - USB_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size; - #elif defined(USE_EEPROM_DESCRIPTORS) - USB_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size); - #else - USB_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size); - #endif - } - } - #endif - - USB_Attach(); - - #if defined(USB_DEVICE_ONLY) - USB_INT_Clear(USB_INT_SUSPEND); - USB_INT_Enable(USB_INT_SUSPEND); - USB_INT_Clear(USB_INT_EORSTI); - USB_INT_Enable(USB_INT_EORSTI); - - #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) - USB_INT_Enable(USB_INT_VBUS); - #endif - #elif defined(USB_HOST_ONLY) - USB_Host_HostMode_On(); - - USB_Host_VBUS_Auto_Off(); - USB_OTGPAD_Off(); - - USB_Host_VBUS_Manual_Enable(); - USB_Host_VBUS_Manual_On(); - - USB_INT_Enable(USB_INT_SRPI); - USB_INT_Enable(USB_INT_BCERRI); - #else - if (USB_CurrentMode == USB_MODE_DEVICE) - { - USB_INT_Clear(USB_INT_SUSPEND); - USB_INT_Enable(USB_INT_SUSPEND); - USB_INT_Clear(USB_INT_EORSTI); - USB_INT_Enable(USB_INT_EORSTI); - - #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) - USB_INT_Enable(USB_INT_VBUS); - #endif - - #if defined(CONTROL_ONLY_DEVICE) - UENUM = ENDPOINT_CONTROLEP; - #endif - } - else if (USB_CurrentMode == USB_MODE_HOST) - { - USB_Host_HostMode_On(); - - USB_Host_VBUS_Auto_Off(); - USB_OTGPAD_Off(); - - USB_Host_VBUS_Manual_Enable(); - USB_Host_VBUS_Manual_On(); - - USB_INT_Enable(USB_INT_SRPI); - USB_INT_Enable(USB_INT_BCERRI); - } - #endif -} diff --git a/LUFA/Drivers/USB/LowLevel/LowLevel.h b/LUFA/Drivers/USB/LowLevel/LowLevel.h deleted file mode 100644 index 4f27216b1..000000000 --- a/LUFA/Drivers/USB/LowLevel/LowLevel.h +++ /dev/null @@ -1,389 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2010. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - 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 - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * \brief USB low level USB controller definitions. - * - * This file contains structures, function prototypes and macros related to the low level configuration of the - * USB controller, to start, stop and reset the USB library core. - * - * \note This file should not be included directly. It is automatically included as needed by the USB driver - * dispatch header located in LUFA/Drivers/USB/USB.h. - */ - -/** \ingroup Group_USB - * @defgroup Group_USBManagement USB Interface Management - * - * Functions, macros, variables, enums and types related to the setup and management of the USB interface. - * - * @{ - */ - -#ifndef __USBLOWLEVEL_H__ -#define __USBLOWLEVEL_H__ - - /* Includes: */ - #include - #include - #include - - #include "../HighLevel/USBMode.h" - - #include "../../../Common/Common.h" - #include "../HighLevel/USBMode.h" - #include "../HighLevel/Events.h" - #include "../HighLevel/USBTask.h" - #include "USBInterrupt.h" - - #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__) - #include "Host.h" - #include "Pipe.h" - #include "OTG.h" - #endif - - #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__) - #include "Device.h" - #include "Endpoint.h" - #include "DevChapter9.h" - #endif - - /* Enable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - extern "C" { - #endif - - /* Preprocessor Checks and Defines: */ - #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. - #endif - - #if !defined(F_CLOCK) - #error F_CLOCK is not defined. You must define F_CLOCK to the frequency of the unprescaled input clock in your project makefile. - #endif - - #if (F_CLOCK == 8000000) - #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \ - defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \ - defined(__AVR_ATmega32U2__)) - #define USB_PLL_PSC 0 - #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) - #define USB_PLL_PSC 0 - #elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) || defined(__AVR_ATmega32U6__)) - #define USB_PLL_PSC ((1 << PLLP1) | (1 << PLLP0)) - #elif (defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__)) - #define USB_PLL_PSC ((1 << PLLP1) | (1 << PLLP0)) - #endif - #elif (F_CLOCK == 16000000) - #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \ - defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \ - defined(__AVR_ATmega32U2__)) - #define USB_PLL_PSC (1 << PLLP0) - #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) - #define USB_PLL_PSC (1 << PINDIV) - #elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_ATmega32U6__)) - #define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP1)) - #elif (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)) - #define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP0)) - #endif - #endif - - #if !defined(USB_PLL_PSC) - #error No PLL prescale value available for chosen F_CPU value and AVR model. - #endif - - /* Public Interface - May be used in end-application: */ - /* Macros: */ - /** Mode mask for the \ref USB_CurrentMode global. This indicates that the USB interface is currently not - * initialized into any mode. - */ - #define USB_MODE_NONE 0 - - /** Mode mask for the \ref USB_CurrentMode global and the \ref USB_Init() function. This indicates that the - * USB interface is or should be initialized in the USB device mode. - */ - #define USB_MODE_DEVICE 1 - - /** Mode mask for the \ref USB_CurrentMode global and the \ref USB_Init() function. This indicates that the - * USB interface is or should be initialized in the USB host mode. - */ - #define USB_MODE_HOST 2 - - #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__) - /** Mode mask for the the \ref USB_Init() function. This indicates that the USB interface should be - * initialized into whatever mode the UID pin of the USB AVR indicates, and that the device - * should swap over its mode when the level of the UID pin changes during operation. - * - * \note This token is not available on AVR models which do not support both host and device modes. - */ - #define USB_MODE_UID 3 - #endif - - /** Regulator disable option mask for \ref USB_Init(). This indicates that the internal 3.3V USB data pad - * regulator should be enabled to regulate the data pin voltages to within the USB standard. - * - * \note See USB AVR data sheet for more information on the internal pad regulator. - */ - #define USB_OPT_REG_DISABLED (1 << 1) - - /** Regulator enable option mask for \ref USB_Init(). This indicates that the internal 3.3V USB data pad - * regulator should be disabled and the AVR's VCC level used for the data pads. - * - * \note See USB AVR data sheet for more information on the internal pad regulator. - */ - #define USB_OPT_REG_ENABLED (0 << 1) - - /** Manual PLL control option mask for \ref USB_Init(). This indicates to the library that the user application - * will take full responsibility for controlling the AVR's PLL (used to generate the high frequency clock - * that the USB controller requires) and ensuring that it is locked at the correct frequency for USB operations. - */ - #define USB_OPT_MANUAL_PLL (1 << 2) - - /** Automatic PLL control option mask for \ref USB_Init(). This indicates to the library that the library should - * take full responsibility for controlling the AVR's PLL (used to generate the high frequency clock - * that the USB controller requires) and ensuring that it is locked at the correct frequency for USB operations. - */ - #define USB_OPT_AUTO_PLL (0 << 2) - - /** Mask for a CONTROL type endpoint or pipe. - * - * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions. - */ - #define EP_TYPE_CONTROL 0x00 - - /** Mask for an ISOCHRONOUS type endpoint or pipe. - * - * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions. - */ - #define EP_TYPE_ISOCHRONOUS 0x01 - - /** Mask for a BULK type endpoint or pipe. - * - * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions. - */ - #define EP_TYPE_BULK 0x02 - - /** Mask for an INTERRUPT type endpoint or pipe. - * - * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions. - */ - #define EP_TYPE_INTERRUPT 0x03 - - #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__) - /** Returns boolean true if the VBUS line is currently high (i.e. the USB host is supplying power), - * otherwise returns false. - * - * \note This token is not available on some AVR models which do not support hardware VBUS monitoring. - */ - #define USB_VBUS_GetStatus() ((USBSTA & (1 << VBUS)) ? true : false) - #endif - - /** Detaches the device from the USB bus. This has the effect of removing the device from any - * attached host, ceasing USB communications. If no host is present, this prevents any host from - * enumerating the device once attached until \ref USB_Attach() is called. - */ - #define USB_Detach() MACROS{ UDCON |= (1 << DETACH); }MACROE - - /** Attaches the device to the USB bus. This announces the device's presence to any attached - * USB host, starting the enumeration process. If no host is present, attaching the device - * will allow for enumeration once a host is connected to the device. - * - * This is inexplicably also required for proper operation while in host mode, to enable the - * attachment of a device to the host. This is despite the bit being located in the device-mode - * register and despite the datasheet making no mention of its requirement in host mode. - */ - #define USB_Attach() MACROS{ UDCON &= ~(1 << DETACH); }MACROE - - #if !defined(USB_STREAM_TIMEOUT_MS) || defined(__DOXYGEN__) - /** Constant for the maximum software timeout period of the USB data stream transfer functions - * (both control and standard) when in either device or host mode. If the next packet of a stream - * is not received or acknowledged within this time period, the stream function will fail. - * - * This value may be overridden in the user project makefile as the value of the - * \ref USB_STREAM_TIMEOUT_MS token, and passed to the compiler using the -D switch. - */ - #define USB_STREAM_TIMEOUT_MS 100 - #endif - - /* Function Prototypes: */ - /** Main function to initialize and start the USB interface. Once active, the USB interface will - * allow for device connection to a host when in device mode, or for device enumeration while in - * host mode. - * - * As the USB library relies on interrupts for the device and host mode enumeration processes, - * the user must enable global interrupts before or shortly after this function is called. In - * device mode, interrupts must be enabled within 500ms of this function being called to ensure - * that the host does not time out whilst enumerating the device. In host mode, interrupts may be - * enabled at the application's leisure however enumeration will not begin of an attached device - * until after this has occurred. - * - * Calling this function when the USB interface is already initialized will cause a complete USB - * interface reset and re-enumeration. - * - * \param[in] Mode This is a mask indicating what mode the USB interface is to be initialized to. - * Valid mode masks are \ref USB_MODE_DEVICE, \ref USB_MODE_HOST or \ref USB_MODE_UID. - * - * \param[in] Options Mask indicating the options which should be used when initializing the USB - * interface to control the USB interface's behavior. This should be comprised of - * a USB_OPT_REG_* mask to control the regulator, a USB_OPT_*_PLL mask to control the - * PLL, and a USB_DEVICE_OPT_* mask (when the device mode is enabled) to set the device - * mode speed. - * - * \note To reduce the FLASH requirements of the library if only device or host mode is required, - * the mode can be statically set in the project makefile by defining the token USB_DEVICE_ONLY - * (for device mode) or USB_HOST_ONLY (for host mode), passing the token to the compiler - * via the -D switch. If the mode is statically set, this parameter does not exist in the - * function prototype. - * \n\n - * - * \note To reduce the FLASH requirements of the library if only fixed settings are are required, - * the options may be set statically in the same manner as the mode (see the Mode parameter of - * this function). To statically set the USB options, pass in the USE_STATIC_OPTIONS token, - * defined to the appropriate options masks. When the options are statically set, this - * parameter does not exist in the function prototype. - * \n\n - * - * \note The mode parameter does not exist on devices where only one mode is possible, such as USB - * AVR models which only implement the USB device mode in hardware. - * - * \see Device.h for the USB_DEVICE_OPT_* masks. - */ - void USB_Init( - #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__) - const uint8_t Mode - #endif - - #if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS)) || defined(__DOXYGEN__) - , - #elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS)) - void - #endif - - #if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__) - const uint8_t Options - #endif - ); - - /** Shuts down the USB interface. This turns off the USB interface after deallocating all USB FIFO - * memory, endpoints and pipes. When turned off, no USB functionality can be used until the interface - * is restarted with the \ref USB_Init() function. - */ - void USB_ShutDown(void); - - /** Resets the interface, when already initialized. This will re-enumerate the device if already connected - * to a host, or re-enumerate an already attached device when in host mode. - */ - void USB_ResetInterface(void); - - /* Enums: */ - /** Enum for error codes relating to the powering on of the USB interface. These error codes are - * used in the ErrorCode parameter value of the \ref EVENT_USB_InitFailure() event. - */ - enum USB_InitErrorCodes_t - { - USB_INITERROR_NoUSBModeSpecified = 0, /**< Indicates that \ref USB_Init() was called with an - * invalid or missing Mode parameter. - */ - }; - - /* Global Variables: */ - #if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) || defined(__DOXYGEN__) - /** Indicates the mode that the USB interface is currently initialized to. This value will be - * one of the USB_MODE_* masks defined elsewhere in this module. - * - * \note This variable should be treated as read-only in the user application, and never manually - * changed in value. - */ - extern volatile uint8_t USB_CurrentMode; - #elif defined(USB_HOST_ONLY) - #define USB_CurrentMode USB_MODE_HOST - #elif defined(USB_DEVICE_ONLY) - #define USB_CurrentMode USB_MODE_DEVICE - #endif - - #if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__) - /** Indicates the current USB options that the USB interface was initialized with when \ref USB_Init() - * was called. This value will be one of the USB_MODE_* masks defined elsewhere in this module. - * - * \note This variable should be treated as read-only in the user application, and never manually - * changed in value. - */ - extern volatile uint8_t USB_Options; - #elif defined(USE_STATIC_OPTIONS) - #define USB_Options USE_STATIC_OPTIONS - #endif - - /* Private Interface - For use in library only: */ - #if !defined(__DOXYGEN__) - /* Macros: */ - #define USB_PLL_On() MACROS{ PLLCSR = USB_PLL_PSC; PLLCSR |= (1 << PLLE); }MACROE - #define USB_PLL_Off() MACROS{ PLLCSR = 0; }MACROE - #define USB_PLL_IsReady() ((PLLCSR & (1 << PLOCK)) ? true : false) - - #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) - #define USB_REG_On() MACROS{ UHWCON |= (1 << UVREGE); }MACROE - #define USB_REG_Off() MACROS{ UHWCON &= ~(1 << UVREGE); }MACROE - #else - #define USB_REG_On() MACROS{ REGCR &= ~(1 << REGDIS); }MACROE - #define USB_REG_Off() MACROS{ REGCR |= (1 << REGDIS); }MACROE - #endif - - #define USB_OTGPAD_On() MACROS{ USBCON |= (1 << OTGPADE); }MACROE - #define USB_OTGPAD_Off() MACROS{ USBCON &= ~(1 << OTGPADE); }MACROE - - #define USB_CLK_Freeze() MACROS{ USBCON |= (1 << FRZCLK); }MACROE - #define USB_CLK_Unfreeze() MACROS{ USBCON &= ~(1 << FRZCLK); }MACROE - - #define USB_Controller_Enable() MACROS{ USBCON |= (1 << USBE); }MACROE - #define USB_Controller_Disable() MACROS{ USBCON &= ~(1 << USBE); }MACROE - #define USB_Controller_Reset() MACROS{ const uint8_t Temp = USBCON; USBCON = (Temp & ~(1 << USBE)); \ - USBCON = (Temp | (1 << USBE)); }MACROE - - /* Inline Functions: */ - #if defined(USB_CAN_BE_BOTH) - static inline uint8_t USB_GetUSBModeFromUID(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; - static inline uint8_t USB_GetUSBModeFromUID(void) - { - if (USBSTA & (1 << ID)) - return USB_MODE_DEVICE; - else - return USB_MODE_HOST; - } - #endif - - #endif - - /* Disable C linkage for C++ Compilers: */ - #if defined(__cplusplus) - } - #endif - -#endif - -/** @} */ diff --git a/LUFA/Drivers/USB/LowLevel/USBController.c b/LUFA/Drivers/USB/LowLevel/USBController.c new file mode 100644 index 000000000..907e2bab0 --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/USBController.c @@ -0,0 +1,271 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2010. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + 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 + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +#define __INCLUDE_FROM_USB_DRIVER +#include "USBController.h" + +#if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) +volatile uint8_t USB_CurrentMode = USB_MODE_NONE; +#endif + +#if !defined(USE_STATIC_OPTIONS) +volatile uint8_t USB_Options; +#endif + +void USB_Init( + #if defined(USB_CAN_BE_BOTH) + const uint8_t Mode + #endif + + #if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS)) + , + #elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS)) + void + #endif + + #if !defined(USE_STATIC_OPTIONS) + const uint8_t Options + #endif + ) +{ + #if defined(USB_CAN_BE_BOTH) + USB_CurrentMode = Mode; + #endif + + #if !defined(USE_STATIC_OPTIONS) + USB_Options = Options; + #endif + + #if defined(USB_CAN_BE_HOST) + USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE; + #endif + + #if defined(USB_DEVICE_ONLY) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) + UHWCON |= (1 << UIMOD); + #elif defined(USB_HOST_ONLY) + UHWCON &= ~(1 << UIMOD); + #elif defined(USB_CAN_BE_BOTH) + if (Mode == USB_MODE_UID) + { + UHWCON |= (1 << UIDE); + + USB_INT_Clear(USB_INT_IDTI); + USB_INT_Enable(USB_INT_IDTI); + + USB_CurrentMode = USB_GetUSBModeFromUID(); + } + else if (Mode == USB_MODE_DEVICE) + { + UHWCON |= (1 << UIMOD); + } + else if (Mode == USB_MODE_HOST) + { + UHWCON &= ~(1 << UIMOD); + } + else + { + EVENT_USB_InitFailure(USB_INITERROR_NoUSBModeSpecified); + return; + } + #endif + + USB_ResetInterface(); + + #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) + USB_OTGPAD_On(); + #endif + + USB_IsInitialized = true; +} + +void USB_ShutDown(void) +{ + USB_ResetInterface(); + USB_Detach(); + USB_Controller_Disable(); + + USB_INT_DisableAllInterrupts(); + USB_INT_ClearAllInterrupts(); + + #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) + UHWCON &= ~(1 << UIMOD); + #endif + + if (!(USB_Options & USB_OPT_MANUAL_PLL)) + USB_PLL_Off(); + + USB_REG_Off(); + + #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) + USB_OTGPAD_Off(); + #endif + + #if defined(USB_CAN_BE_BOTH) + UHWCON &= ~(1 << UIDE); + #endif + + USB_IsInitialized = false; + + #if defined(USB_CAN_BE_BOTH) + USB_CurrentMode = USB_MODE_NONE; + #endif +} + +void USB_ResetInterface(void) +{ + USB_INT_DisableAllInterrupts(); + USB_INT_ClearAllInterrupts(); + + #if defined(USB_CAN_BE_HOST) + USB_HostState = HOST_STATE_Unattached; + #endif + + #if defined(USB_CAN_BE_DEVICE) + USB_DeviceState = DEVICE_STATE_Unattached; + USB_ConfigurationNumber = 0; + + #if !defined(NO_DEVICE_REMOTE_WAKEUP) + USB_RemoteWakeupEnabled = false; + #endif + + #if !defined(NO_DEVICE_SELF_POWER) + USB_CurrentlySelfPowered = false; + #endif + #endif + + if (!(USB_Options & USB_OPT_MANUAL_PLL)) + { + #if defined(USB_SERIES_4_AVR) + PLLFRQ = ((1 << PLLUSB) | (1 << PDIV3) | (1 << PDIV1)); + #endif + + USB_PLL_On(); + while (!(USB_PLL_IsReady())); + } + + USB_Controller_Reset(); + + #if defined(USB_CAN_BE_BOTH) + if (UHWCON & (1 << UIDE)) + { + USB_INT_Clear(USB_INT_IDTI); + USB_INT_Enable(USB_INT_IDTI); + USB_CurrentMode = USB_GetUSBModeFromUID(); + } + #endif + + if (!(USB_Options & USB_OPT_REG_DISABLED)) + USB_REG_On(); + else + USB_REG_Off(); + + USB_CLK_Unfreeze(); + + #if (defined(USB_CAN_BE_DEVICE) && (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))) + if (USB_CurrentMode == USB_MODE_DEVICE) + { + if (USB_Options & USB_DEVICE_OPT_LOWSPEED) + USB_Device_SetLowSpeed(); + else + USB_Device_SetFullSpeed(); + } + #endif + + #if (defined(USB_CAN_BE_DEVICE) && !defined(FIXED_CONTROL_ENDPOINT_SIZE)) + if (USB_CurrentMode == USB_MODE_DEVICE) + { + USB_Descriptor_Device_t* DeviceDescriptorPtr; + + if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR) + { + #if defined(USE_RAM_DESCRIPTORS) + USB_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size; + #elif defined(USE_EEPROM_DESCRIPTORS) + USB_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size); + #else + USB_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size); + #endif + } + } + #endif + + USB_Attach(); + + #if defined(USB_DEVICE_ONLY) + USB_INT_Clear(USB_INT_SUSPEND); + USB_INT_Enable(USB_INT_SUSPEND); + USB_INT_Clear(USB_INT_EORSTI); + USB_INT_Enable(USB_INT_EORSTI); + + #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) + USB_INT_Enable(USB_INT_VBUS); + #endif + #elif defined(USB_HOST_ONLY) + USB_Host_HostMode_On(); + + USB_Host_VBUS_Auto_Off(); + USB_OTGPAD_Off(); + + USB_Host_VBUS_Manual_Enable(); + USB_Host_VBUS_Manual_On(); + + USB_INT_Enable(USB_INT_SRPI); + USB_INT_Enable(USB_INT_BCERRI); + #else + if (USB_CurrentMode == USB_MODE_DEVICE) + { + USB_INT_Clear(USB_INT_SUSPEND); + USB_INT_Enable(USB_INT_SUSPEND); + USB_INT_Clear(USB_INT_EORSTI); + USB_INT_Enable(USB_INT_EORSTI); + + #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) + USB_INT_Enable(USB_INT_VBUS); + #endif + + #if defined(CONTROL_ONLY_DEVICE) + UENUM = ENDPOINT_CONTROLEP; + #endif + } + else if (USB_CurrentMode == USB_MODE_HOST) + { + USB_Host_HostMode_On(); + + USB_Host_VBUS_Auto_Off(); + USB_OTGPAD_Off(); + + USB_Host_VBUS_Manual_Enable(); + USB_Host_VBUS_Manual_On(); + + USB_INT_Enable(USB_INT_SRPI); + USB_INT_Enable(USB_INT_BCERRI); + } + #endif +} diff --git a/LUFA/Drivers/USB/LowLevel/USBController.h b/LUFA/Drivers/USB/LowLevel/USBController.h new file mode 100644 index 000000000..ef670a456 --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/USBController.h @@ -0,0 +1,390 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2010. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + 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 + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief USB low level USB controller definitions. + * + * This file contains structures, function prototypes and macros related to the low level configuration of the + * USB controller, to start, stop and reset the USB library core. + * + * \note This file should not be included directly. It is automatically included as needed by the USB driver + * dispatch header located in LUFA/Drivers/USB/USB.h. + */ + +/** \ingroup Group_USB + * @defgroup Group_USBManagement USB Interface Management + * + * Functions, macros, variables, enums and types related to the setup and management of the USB interface. + * + * @{ + */ + +#ifndef __USBCONTROLLER_H__ +#define __USBCONTROLLER_H__ + + /* Includes: */ + #include + #include + #include + + #include "../HighLevel/USBMode.h" + + #include "../../../Common/Common.h" + #include "../HighLevel/USBMode.h" + #include "../HighLevel/Events.h" + #include "../HighLevel/USBTask.h" + #include "USBInterrupt.h" + + #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__) + #include "Host.h" + #include "Pipe.h" + #include "OTG.h" + #include "../HighLevel/HostStandardReq.h" + #endif + + #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__) + #include "Device.h" + #include "Endpoint.h" + #include "../HighLevel/DeviceStandardReq.h" + #endif + + /* Enable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + extern "C" { + #endif + + /* Preprocessor Checks and Defines: */ + #if !defined(__INCLUDE_FROM_USB_DRIVER) + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. + #endif + + #if !defined(F_CLOCK) + #error F_CLOCK is not defined. You must define F_CLOCK to the frequency of the unprescaled input clock in your project makefile. + #endif + + #if (F_CLOCK == 8000000) + #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \ + defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \ + defined(__AVR_ATmega32U2__)) + #define USB_PLL_PSC 0 + #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) + #define USB_PLL_PSC 0 + #elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) || defined(__AVR_ATmega32U6__)) + #define USB_PLL_PSC ((1 << PLLP1) | (1 << PLLP0)) + #elif (defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__)) + #define USB_PLL_PSC ((1 << PLLP1) | (1 << PLLP0)) + #endif + #elif (F_CLOCK == 16000000) + #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \ + defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \ + defined(__AVR_ATmega32U2__)) + #define USB_PLL_PSC (1 << PLLP0) + #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)) + #define USB_PLL_PSC (1 << PINDIV) + #elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_ATmega32U6__)) + #define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP1)) + #elif (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)) + #define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP0)) + #endif + #endif + + #if !defined(USB_PLL_PSC) + #error No PLL prescale value available for chosen F_CPU value and AVR model. + #endif + + /* Public Interface - May be used in end-application: */ + /* Macros: */ + /** Mode mask for the \ref USB_CurrentMode global. This indicates that the USB interface is currently not + * initialized into any mode. + */ + #define USB_MODE_NONE 0 + + /** Mode mask for the \ref USB_CurrentMode global and the \ref USB_Init() function. This indicates that the + * USB interface is or should be initialized in the USB device mode. + */ + #define USB_MODE_DEVICE 1 + + /** Mode mask for the \ref USB_CurrentMode global and the \ref USB_Init() function. This indicates that the + * USB interface is or should be initialized in the USB host mode. + */ + #define USB_MODE_HOST 2 + + #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__) + /** Mode mask for the the \ref USB_Init() function. This indicates that the USB interface should be + * initialized into whatever mode the UID pin of the USB AVR indicates, and that the device + * should swap over its mode when the level of the UID pin changes during operation. + * + * \note This token is not available on AVR models which do not support both host and device modes. + */ + #define USB_MODE_UID 3 + #endif + + /** Regulator disable option mask for \ref USB_Init(). This indicates that the internal 3.3V USB data pad + * regulator should be enabled to regulate the data pin voltages to within the USB standard. + * + * \note See USB AVR data sheet for more information on the internal pad regulator. + */ + #define USB_OPT_REG_DISABLED (1 << 1) + + /** Regulator enable option mask for \ref USB_Init(). This indicates that the internal 3.3V USB data pad + * regulator should be disabled and the AVR's VCC level used for the data pads. + * + * \note See USB AVR data sheet for more information on the internal pad regulator. + */ + #define USB_OPT_REG_ENABLED (0 << 1) + + /** Manual PLL control option mask for \ref USB_Init(). This indicates to the library that the user application + * will take full responsibility for controlling the AVR's PLL (used to generate the high frequency clock + * that the USB controller requires) and ensuring that it is locked at the correct frequency for USB operations. + */ + #define USB_OPT_MANUAL_PLL (1 << 2) + + /** Automatic PLL control option mask for \ref USB_Init(). This indicates to the library that the library should + * take full responsibility for controlling the AVR's PLL (used to generate the high frequency clock + * that the USB controller requires) and ensuring that it is locked at the correct frequency for USB operations. + */ + #define USB_OPT_AUTO_PLL (0 << 2) + + /** Mask for a CONTROL type endpoint or pipe. + * + * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions. + */ + #define EP_TYPE_CONTROL 0x00 + + /** Mask for an ISOCHRONOUS type endpoint or pipe. + * + * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions. + */ + #define EP_TYPE_ISOCHRONOUS 0x01 + + /** Mask for a BULK type endpoint or pipe. + * + * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions. + */ + #define EP_TYPE_BULK 0x02 + + /** Mask for an INTERRUPT type endpoint or pipe. + * + * \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions. + */ + #define EP_TYPE_INTERRUPT 0x03 + + #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__) + /** Returns boolean true if the VBUS line is currently high (i.e. the USB host is supplying power), + * otherwise returns false. + * + * \note This token is not available on some AVR models which do not support hardware VBUS monitoring. + */ + #define USB_VBUS_GetStatus() ((USBSTA & (1 << VBUS)) ? true : false) + #endif + + /** Detaches the device from the USB bus. This has the effect of removing the device from any + * attached host, ceasing USB communications. If no host is present, this prevents any host from + * enumerating the device once attached until \ref USB_Attach() is called. + */ + #define USB_Detach() MACROS{ UDCON |= (1 << DETACH); }MACROE + + /** Attaches the device to the USB bus. This announces the device's presence to any attached + * USB host, starting the enumeration process. If no host is present, attaching the device + * will allow for enumeration once a host is connected to the device. + * + * This is inexplicably also required for proper operation while in host mode, to enable the + * attachment of a device to the host. This is despite the bit being located in the device-mode + * register and despite the datasheet making no mention of its requirement in host mode. + */ + #define USB_Attach() MACROS{ UDCON &= ~(1 << DETACH); }MACROE + + #if !defined(USB_STREAM_TIMEOUT_MS) || defined(__DOXYGEN__) + /** Constant for the maximum software timeout period of the USB data stream transfer functions + * (both control and standard) when in either device or host mode. If the next packet of a stream + * is not received or acknowledged within this time period, the stream function will fail. + * + * This value may be overridden in the user project makefile as the value of the + * \ref USB_STREAM_TIMEOUT_MS token, and passed to the compiler using the -D switch. + */ + #define USB_STREAM_TIMEOUT_MS 100 + #endif + + /* Function Prototypes: */ + /** Main function to initialize and start the USB interface. Once active, the USB interface will + * allow for device connection to a host when in device mode, or for device enumeration while in + * host mode. + * + * As the USB library relies on interrupts for the device and host mode enumeration processes, + * the user must enable global interrupts before or shortly after this function is called. In + * device mode, interrupts must be enabled within 500ms of this function being called to ensure + * that the host does not time out whilst enumerating the device. In host mode, interrupts may be + * enabled at the application's leisure however enumeration will not begin of an attached device + * until after this has occurred. + * + * Calling this function when the USB interface is already initialized will cause a complete USB + * interface reset and re-enumeration. + * + * \param[in] Mode This is a mask indicating what mode the USB interface is to be initialized to. + * Valid mode masks are \ref USB_MODE_DEVICE, \ref USB_MODE_HOST or \ref USB_MODE_UID. + * + * \param[in] Options Mask indicating the options which should be used when initializing the USB + * interface to control the USB interface's behavior. This should be comprised of + * a USB_OPT_REG_* mask to control the regulator, a USB_OPT_*_PLL mask to control the + * PLL, and a USB_DEVICE_OPT_* mask (when the device mode is enabled) to set the device + * mode speed. + * + * \note To reduce the FLASH requirements of the library if only device or host mode is required, + * the mode can be statically set in the project makefile by defining the token USB_DEVICE_ONLY + * (for device mode) or USB_HOST_ONLY (for host mode), passing the token to the compiler + * via the -D switch. If the mode is statically set, this parameter does not exist in the + * function prototype. + * \n\n + * + * \note To reduce the FLASH requirements of the library if only fixed settings are are required, + * the options may be set statically in the same manner as the mode (see the Mode parameter of + * this function). To statically set the USB options, pass in the USE_STATIC_OPTIONS token, + * defined to the appropriate options masks. When the options are statically set, this + * parameter does not exist in the function prototype. + * \n\n + * + * \note The mode parameter does not exist on devices where only one mode is possible, such as USB + * AVR models which only implement the USB device mode in hardware. + * + * \see Device.h for the USB_DEVICE_OPT_* masks. + */ + void USB_Init( + #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__) + const uint8_t Mode + #endif + + #if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS)) || defined(__DOXYGEN__) + , + #elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS)) + void + #endif + + #if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__) + const uint8_t Options + #endif + ); + + /** Shuts down the USB interface. This turns off the USB interface after deallocating all USB FIFO + * memory, endpoints and pipes. When turned off, no USB functionality can be used until the interface + * is restarted with the \ref USB_Init() function. + */ + void USB_ShutDown(void); + + /** Resets the interface, when already initialized. This will re-enumerate the device if already connected + * to a host, or re-enumerate an already attached device when in host mode. + */ + void USB_ResetInterface(void); + + /* Enums: */ + /** Enum for error codes relating to the powering on of the USB interface. These error codes are + * used in the ErrorCode parameter value of the \ref EVENT_USB_InitFailure() event. + */ + enum USB_InitErrorCodes_t + { + USB_INITERROR_NoUSBModeSpecified = 0, /**< Indicates that \ref USB_Init() was called with an + * invalid or missing Mode parameter. + */ + }; + + /* Global Variables: */ + #if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) || defined(__DOXYGEN__) + /** Indicates the mode that the USB interface is currently initialized to. This value will be + * one of the USB_MODE_* masks defined elsewhere in this module. + * + * \note This variable should be treated as read-only in the user application, and never manually + * changed in value. + */ + extern volatile uint8_t USB_CurrentMode; + #elif defined(USB_HOST_ONLY) + #define USB_CurrentMode USB_MODE_HOST + #elif defined(USB_DEVICE_ONLY) + #define USB_CurrentMode USB_MODE_DEVICE + #endif + + #if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__) + /** Indicates the current USB options that the USB interface was initialized with when \ref USB_Init() + * was called. This value will be one of the USB_MODE_* masks defined elsewhere in this module. + * + * \note This variable should be treated as read-only in the user application, and never manually + * changed in value. + */ + extern volatile uint8_t USB_Options; + #elif defined(USE_STATIC_OPTIONS) + #define USB_Options USE_STATIC_OPTIONS + #endif + + /* Private Interface - For use in library only: */ + #if !defined(__DOXYGEN__) + /* Macros: */ + #define USB_PLL_On() MACROS{ PLLCSR = USB_PLL_PSC; PLLCSR |= (1 << PLLE); }MACROE + #define USB_PLL_Off() MACROS{ PLLCSR = 0; }MACROE + #define USB_PLL_IsReady() ((PLLCSR & (1 << PLOCK)) ? true : false) + + #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) + #define USB_REG_On() MACROS{ UHWCON |= (1 << UVREGE); }MACROE + #define USB_REG_Off() MACROS{ UHWCON &= ~(1 << UVREGE); }MACROE + #else + #define USB_REG_On() MACROS{ REGCR &= ~(1 << REGDIS); }MACROE + #define USB_REG_Off() MACROS{ REGCR |= (1 << REGDIS); }MACROE + #endif + + #define USB_OTGPAD_On() MACROS{ USBCON |= (1 << OTGPADE); }MACROE + #define USB_OTGPAD_Off() MACROS{ USBCON &= ~(1 << OTGPADE); }MACROE + + #define USB_CLK_Freeze() MACROS{ USBCON |= (1 << FRZCLK); }MACROE + #define USB_CLK_Unfreeze() MACROS{ USBCON &= ~(1 << FRZCLK); }MACROE + + #define USB_Controller_Enable() MACROS{ USBCON |= (1 << USBE); }MACROE + #define USB_Controller_Disable() MACROS{ USBCON &= ~(1 << USBE); }MACROE + #define USB_Controller_Reset() MACROS{ const uint8_t Temp = USBCON; USBCON = (Temp & ~(1 << USBE)); \ + USBCON = (Temp | (1 << USBE)); }MACROE + + /* Inline Functions: */ + #if defined(USB_CAN_BE_BOTH) + static inline uint8_t USB_GetUSBModeFromUID(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; + static inline uint8_t USB_GetUSBModeFromUID(void) + { + if (USBSTA & (1 << ID)) + return USB_MODE_DEVICE; + else + return USB_MODE_HOST; + } + #endif + + #endif + + /* Disable C linkage for C++ Compilers: */ + #if defined(__cplusplus) + } + #endif + +#endif + +/** @} */ diff --git a/LUFA/Drivers/USB/LowLevel/USBInterrupt.h b/LUFA/Drivers/USB/LowLevel/USBInterrupt.h index 6f8bf7cea..f954468be 100644 --- a/LUFA/Drivers/USB/LowLevel/USBInterrupt.h +++ b/LUFA/Drivers/USB/LowLevel/USBInterrupt.h @@ -50,7 +50,7 @@ #include "../../../Common/Common.h" #include "../HighLevel/USBMode.h" #include "../HighLevel/Events.h" - #include "LowLevel.h" + #include "USBController.h" /* Enable C linkage for C++ Compilers: */ #if defined(__cplusplus) diff --git a/LUFA/Drivers/USB/USB.h b/LUFA/Drivers/USB/USB.h index 3cc1593fc..c63582bad 100644 --- a/LUFA/Drivers/USB/USB.h +++ b/LUFA/Drivers/USB/USB.h @@ -41,16 +41,16 @@ * * \section Sec_Dependencies Module Source Dependencies * The following files must be built with any user project that uses this module: - * - LUFA/Drivers/USB/LowLevel/DevChapter9.c (Makefile source module name: LUFA_SRC_USB) * - LUFA/Drivers/USB/LowLevel/Device.c (Makefile source module name: LUFA_SRC_USB) * - LUFA/Drivers/USB/LowLevel/Endpoint.c (Makefile source module name: LUFA_SRC_USB) * - LUFA/Drivers/USB/LowLevel/Host.c (Makefile source module name: LUFA_SRC_USB) - * - LUFA/Drivers/USB/LowLevel/HostChapter9.c (Makefile source module name: LUFA_SRC_USB) - * - LUFA/Drivers/USB/LowLevel/LowLevel.c (Makefile source module name: LUFA_SRC_USB) * - LUFA/Drivers/USB/LowLevel/Pipe.c (Makefile source module name: LUFA_SRC_USB) + * - LUFA/Drivers/USB/LowLevel/USBController.c (Makefile source module name: LUFA_SRC_USB) * - LUFA/Drivers/USB/LowLevel/USBInterrupt.c (Makefile source module name: LUFA_SRC_USB) * - LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c (Makefile source module name: LUFA_SRC_USB) + * - LUFA/Drivers/USB/HighLevel/DeviceStandardReq.c (Makefile source module name: LUFA_SRC_USB) * - LUFA/Drivers/USB/HighLevel/Events.c (Makefile source module name: LUFA_SRC_USB) + * - LUFA/Drivers/USB/HighLevel/HostStandardReq.c (Makefile source module name: LUFA_SRC_USB) * - LUFA/Drivers/USB/HighLevel/USBTask.c (Makefile source module name: LUFA_SRC_USB) * * \section Module Description @@ -372,19 +372,19 @@ #include "HighLevel/StdDescriptors.h" #include "HighLevel/ConfigDescriptor.h" - #include "LowLevel/LowLevel.h" + #include "LowLevel/USBController.h" #include "LowLevel/USBInterrupt.h" #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__) #include "LowLevel/Host.h" - #include "LowLevel/HostChapter9.h" #include "LowLevel/Pipe.h" + #include "HighLevel/HostStandardReq.h" #endif #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__) #include "LowLevel/Device.h" - #include "LowLevel/DevChapter9.h" #include "LowLevel/Endpoint.h" + #include "HighLevel/DeviceStandardReq.h" #endif #if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__) diff --git a/LUFA/ManPages/MigrationInformation.txt b/LUFA/ManPages/MigrationInformation.txt index b0739ee8c..ae05c8bdb 100644 --- a/LUFA/ManPages/MigrationInformation.txt +++ b/LUFA/ManPages/MigrationInformation.txt @@ -15,6 +15,12 @@ * USB Core * - A new USB driver source file, Drivers/USB/LowLevel/Device.c now exists. This source file should be added to all project * makefiles using the USB driver of LUFA, or the makefile should be updated to use the new module source variables. + * - The Drivers/USB/LowLevel/DevChapter9.c source file has moved to Drivers/USB/HighLevel/DeviceStandardReq.c - this should + * be updated in all project makefiles, or the makefile should be updated to use the new module source variables. + * - The Drivers/USB/LowLevel/HostChapter9.h source file has moved to Drivers/USB/HighLevel/HostStandardReq.c - this should + * be updated in all project makefiles, or the makefile should be updated to use the new module source variables. + * - The Drivers/USB/LowLevel/LowLevel.c source file has moved to Drivers/LowLevel/USBController.c - this should be updated + * in all project makefiles, or the makefile should be updated to use the new module source variables. * * Device Mode * - The USB_Device_IsRemoteWakeupSent() macro has been removed, as the remote wakeup request is now fully handled by the diff --git a/LUFA/Scheduler/Scheduler.h b/LUFA/Scheduler/Scheduler.h index ce2cbb191..4b6ffa9af 100644 --- a/LUFA/Scheduler/Scheduler.h +++ b/LUFA/Scheduler/Scheduler.h @@ -87,7 +87,7 @@ #define __SCHEDULER_H__ /* Includes: */ - #include + #include #include #include diff --git a/LUFA/makefile b/LUFA/makefile index 845de4e49..2ecfde177 100644 --- a/LUFA/makefile +++ b/LUFA/makefile @@ -17,16 +17,16 @@ else endif # Define module source file lists -LUFA_SRC_USB = $(LUFA_ROOT_PATH)/Drivers/USB/LowLevel/DevChapter9.c \ - $(LUFA_ROOT_PATH)/Drivers/USB/LowLevel/Device.c \ +LUFA_SRC_USB = $(LUFA_ROOT_PATH)/Drivers/USB/LowLevel/Device.c \ $(LUFA_ROOT_PATH)/Drivers/USB/LowLevel/Endpoint.c \ $(LUFA_ROOT_PATH)/Drivers/USB/LowLevel/Host.c \ - $(LUFA_ROOT_PATH)/Drivers/USB/LowLevel/HostChapter9.c \ - $(LUFA_ROOT_PATH)/Drivers/USB/LowLevel/LowLevel.c \ $(LUFA_ROOT_PATH)/Drivers/USB/LowLevel/Pipe.c \ + $(LUFA_ROOT_PATH)/Drivers/USB/LowLevel/USBController.c \ $(LUFA_ROOT_PATH)/Drivers/USB/LowLevel/USBInterrupt.c \ $(LUFA_ROOT_PATH)/Drivers/USB/HighLevel/ConfigDescriptor.c \ + $(LUFA_ROOT_PATH)/Drivers/USB/HighLevel/DeviceStandardReq.c \ $(LUFA_ROOT_PATH)/Drivers/USB/HighLevel/Events.c \ + $(LUFA_ROOT_PATH)/Drivers/USB/HighLevel/HostStandardReq.c \ $(LUFA_ROOT_PATH)/Drivers/USB/HighLevel/USBTask.c \ $(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/HIDParser.c LUFA_SRC_USBCLASS = $(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/Audio.c \ -- cgit v1.2.3