diff options
Diffstat (limited to 'LUFA/Drivers/USB/LowLevel')
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Device.c | 13 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Device.h | 39 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Endpoint.c | 23 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Endpoint.h | 125 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Host.c | 67 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Host.h | 73 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/OTG.h | 37 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Pipe.c | 29 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Pipe.h | 141 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/USBController.c | 41 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/USBController.h | 75 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/USBInterrupt.c | 67 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/USBInterrupt.h | 23 |
13 files changed, 383 insertions, 370 deletions
diff --git a/LUFA/Drivers/USB/LowLevel/Device.c b/LUFA/Drivers/USB/LowLevel/Device.c index 5355ca27c..29dca81cf 100644 --- a/LUFA/Drivers/USB/LowLevel/Device.c +++ b/LUFA/Drivers/USB/LowLevel/Device.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -50,3 +50,4 @@ void USB_Device_SendRemoteWakeup(void) } #endif + diff --git a/LUFA/Drivers/USB/LowLevel/Device.h b/LUFA/Drivers/USB/LowLevel/Device.h index 03440d28f..20c915783 100644 --- a/LUFA/Drivers/USB/LowLevel/Device.h +++ b/LUFA/Drivers/USB/LowLevel/Device.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -54,7 +54,7 @@ #include <avr/pgmspace.h> #include <avr/eeprom.h> - #include "../../../Common/Common.h" + #include "../../../Common/Common.h" #include "../HighLevel/StdDescriptors.h" #include "USBInterrupt.h" #include "Endpoint.h" @@ -67,7 +67,7 @@ #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(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__) @@ -82,7 +82,7 @@ */ #define USB_DEVICE_OPT_LOWSPEED (1 << 0) #endif - + /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the * USB interface should be initialized in full speed (12Mb/s) mode. */ @@ -109,7 +109,7 @@ * \see \ref Group_Descriptors for more information on the RMWAKEUP feature and device descriptors. */ void USB_Device_SendRemoteWakeup(void); - + /* Type Defines: */ enum USB_Device_States_t { @@ -138,7 +138,7 @@ * resumed. */ }; - + /* Inline Functions: */ /** Returns the current USB frame number, when in device mode. Every millisecond the USB bus is active (i.e. enumerated to a host) * the frame number is incremented by one. @@ -147,7 +147,7 @@ { return UDFNUM; } - + #if !defined(NO_SOF_EVENTS) /** Enables the device mode Start Of Frame events. When enabled, this causes the * \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus, @@ -160,7 +160,7 @@ { USB_INT_Enable(USB_INT_SOFI); } - + /** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the * \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode. * @@ -172,13 +172,13 @@ USB_INT_Disable(USB_INT_SOFI); } #endif - + /* Function Prototypes: */ /** Function to retrieve a given descriptor's size and memory location from the given descriptor type value, - * index and language ID. This function MUST be overridden in the user application (added with full, identical + * index and language ID. This function MUST be overridden in the user application (added with full, identical * prototype and name so that the library can call it to retrieve descriptor data. * - * \param[in] wValue The type of the descriptor to retrieve in the upper byte, and the index in the + * \param[in] wValue The type of the descriptor to retrieve in the upper byte, and the index in the * lower byte (when more than one descriptor of the given type exists, such as the * case of string descriptors). The type may be one of the standard types defined * in the DescriptorTypes_t enum, or may be a class-specific descriptor type value. @@ -193,7 +193,7 @@ * * \note By default, the library expects all descriptors to be located in flash memory via the PROGMEM attribute. * If descriptors should be located in RAM or EEPROM instead (to speed up access in the case of RAM, or to - * allow the descriptors to be changed dynamically at runtime) either the USE_RAM_DESCRIPTORS or the + * allow the descriptors to be changed dynamically at runtime) either the USE_RAM_DESCRIPTORS or the * USE_EEPROM_DESCRIPTORS tokens may be defined in the project makefile and passed to the compiler by the -D * switch. * @@ -216,14 +216,14 @@ { UDCON |= (1 << LSM); } - + static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE; static inline void USB_Device_SetFullSpeed(void) { UDCON &= ~(1 << LSM); } #endif - + static inline void USB_Device_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE; static inline void USB_Device_SetDeviceAddress(const uint8_t Address) { @@ -241,3 +241,4 @@ #endif /** @} */ + diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.c b/LUFA/Drivers/USB/LowLevel/Endpoint.c index fc2bff154..c0e639209 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.c +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -59,7 +59,7 @@ void Endpoint_ClearEndpoints(void) for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++) { - Endpoint_SelectEndpoint(EPNum); + Endpoint_SelectEndpoint(EPNum); UEIENX = 0; UEINTX = 0; UECFG1X = 0; @@ -86,7 +86,7 @@ void Endpoint_ClearStatusStage(void) if (USB_DeviceState == DEVICE_STATE_Unattached) return; } - + Endpoint_ClearIN(); } } @@ -95,7 +95,7 @@ void Endpoint_ClearStatusStage(void) uint8_t Endpoint_WaitUntilReady(void) { #if (USB_STREAM_TIMEOUT_MS < 0xFF) - uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; + uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; #else uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; #endif @@ -114,13 +114,13 @@ uint8_t Endpoint_WaitUntilReady(void) if (Endpoint_IsOUTReceived()) return ENDPOINT_READYWAIT_NoError; } - + uint8_t USB_DeviceState_LCL = USB_DeviceState; if (USB_DeviceState_LCL == DEVICE_STATE_Unattached) return ENDPOINT_READYWAIT_DeviceDisconnected; else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended) - return ENDPOINT_READYWAIT_BusSuspended; + return ENDPOINT_READYWAIT_BusSuspended; else if (Endpoint_IsStalled()) return ENDPOINT_READYWAIT_EndpointStalled; @@ -138,3 +138,4 @@ uint8_t Endpoint_WaitUntilReady(void) #endif #endif + diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.h b/LUFA/Drivers/USB/LowLevel/Endpoint.h index 66f5591f0..25ed9bad9 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.h +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -43,13 +43,13 @@ * * Functions, macros, variables, enums and types related to data reading and writing from and to endpoints. */ - + /** \ingroup Group_EndpointRW * @defgroup Group_EndpointPrimitiveRW Read/Write of Primitive Data Types * * Functions, macros, variables, enums and types related to data reading and writing of primitive data types * from and to endpoints. - */ + */ /** \ingroup Group_EndpointManagement * @defgroup Group_EndpointPacketManagement Endpoint Packet Management @@ -77,7 +77,7 @@ #include "../../../Common/Common.h" #include "../HighLevel/USBTask.h" #include "USBInterrupt.h" - + /* Enable C linkage for C++ Compilers: */ #if defined(__cplusplus) extern "C" { @@ -98,10 +98,10 @@ #define _ENDPOINT_GET_DOUBLEBANK(EPIndex) _ENDPOINT_GET_DOUBLEBANK2(ENDPOINT_DETAILS_EP ## EPIndex) #define _ENDPOINT_GET_DOUBLEBANK2(EPDetails) _ENDPOINT_GET_DOUBLEBANK3(EPDetails) #define _ENDPOINT_GET_DOUBLEBANK3(MaxSize, DB) (DB) - + #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) #define ENDPOINT_DETAILS_MAXEP 7 - + #define ENDPOINT_DETAILS_EP0 64, true #define ENDPOINT_DETAILS_EP1 256, true #define ENDPOINT_DETAILS_EP2 64, true @@ -116,7 +116,7 @@ #define ENDPOINT_DETAILS_EP1 64, false #define ENDPOINT_DETAILS_EP2 64, false #define ENDPOINT_DETAILS_EP3 64, true - #define ENDPOINT_DETAILS_EP4 64, true + #define ENDPOINT_DETAILS_EP4 64, true #endif /* Inline Functions: */ @@ -126,13 +126,13 @@ { uint8_t MaskVal = 0; uint16_t CheckBytes = 8; - + while (CheckBytes < Bytes) { MaskVal++; CheckBytes <<= 1; } - + return (MaskVal << EPSIZE0); } @@ -143,7 +143,7 @@ const uint8_t UECFG1XData); #endif - + /* Public Interface - May be used in end-application: */ /* Macros: */ /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint @@ -169,19 +169,19 @@ * accesses the second bank. */ #define ENDPOINT_BANK_DOUBLE (1 << EPBK0) - + /** Endpoint address for the default control endpoint, which always resides in address 0. This is * defined for convenience to give more readable code when used with the endpoint macros. */ #define ENDPOINT_CONTROLEP 0 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__)) - /** Default size of the default control endpoint's bank, until altered by the control endpoint bank size + /** Default size of the default control endpoint's bank, until altered by the control endpoint bank size * value in the device descriptor. Not available if the FIXED_CONTROL_ENDPOINT_SIZE token is defined. */ #define ENDPOINT_CONTROLEP_DEFAULT_SIZE 8 #endif - + /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's * numerical address in the device. */ @@ -196,17 +196,17 @@ * bank size in the device. */ #define ENDPOINT_EPSIZE_MASK 0x7F - + /** Maximum size in bytes of a given endpoint. * * \param[in] EPIndex Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1) - */ + */ #define ENDPOINT_MAX_SIZE(EPIndex) _ENDPOINT_GET_MAXSIZE(EPIndex) /** Indicates if the given endpoint supports double banking. * * \param[in] EPIndex Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1) - */ + */ #define ENDPOINT_DOUBLEBANK_SUPPORTED(EPIndex) _ENDPOINT_GET_DOUBLEBANK(EPIndex) #if !defined(CONTROL_ONLY_DEVICE) || defined(__DOXYGEN__) @@ -243,7 +243,7 @@ */ }; - /* Inline Functions: */ + /* Inline Functions: */ /** Configures the specified endpoint number with the given endpoint type, direction, bank size * and banking mode. Once configured, the endpoint may be read from or written to, depending * on its direction. @@ -274,7 +274,7 @@ * index - refer to the chosen USB AVR's datasheet to determine the maximum bank size for each endpoint. * \n\n * - * \note The default control endpoint should not be manually configured by the user application, as + * \note The default control endpoint should not be manually configured by the user application, as * it is automatically configured by the library internally. * \n\n * @@ -318,7 +318,7 @@ return UEBCLX; #endif } - + /** Get the endpoint address of the currently selected endpoint. This is typically used to save * the currently selected endpoint number so that it can be restored after another endpoint has * been manipulated. @@ -334,7 +334,7 @@ return ENDPOINT_CONTROLEP; #endif } - + /** Selects the given endpoint number. If the address from the device descriptors is used, the * value should be masked with the \ref ENDPOINT_EPNUM_MASK constant to extract only the endpoint * number (and discarding the endpoint direction bit). @@ -349,9 +349,9 @@ { #if !defined(CONTROL_ONLY_DEVICE) UENUM = EndpointNumber; - #endif + #endif } - + /** Resets the endpoint bank FIFO. This clears all the endpoint banks and resets the USB controller's * In and Out pointers to the bank's contents. * @@ -363,7 +363,7 @@ UERST = (1 << EndpointNumber); UERST = 0; } - + /** Enables the currently selected endpoint so that data can be sent and received through it to * and from a host. * @@ -383,7 +383,7 @@ { UECONX &= ~(1 << EPEN); } - + /** Determines if the currently selected endpoint is enabled, but not necessarily configured. * * \return Boolean True if the currently selected endpoint is enabled, false otherwise. @@ -393,7 +393,7 @@ { return ((UECONX & (1 << EPEN)) ? true : false); } - + /** Determines if the currently selected endpoint may be read from (if data is waiting in the endpoint * bank and the endpoint is an OUT direction, or if the bank is not yet full if the endpoint is an IN * direction). This function will return false if an error has occurred in the endpoint, if the endpoint @@ -409,7 +409,7 @@ { return ((UEINTX & (1 << RWAL)) ? true : false); } - + /** Determines if the currently selected endpoint is configured. * * \return Boolean true if the currently selected endpoint has been configured, false otherwise. @@ -419,7 +419,7 @@ { return ((UESTA0X & (1 << CFGOK)) ? true : false); } - + /** Returns a mask indicating which INTERRUPT type endpoints have interrupted - i.e. their * interrupt duration has elapsed. Which endpoints have interrupted can be determined by * masking the return value against (1 << {Endpoint Number}). @@ -431,7 +431,7 @@ { return UEINT; } - + /** Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type * endpoints). * @@ -444,7 +444,7 @@ { return ((UEINT & (1 << EndpointNumber)) ? true : false); } - + /** Determines if the selected IN endpoint is ready for a new packet to be sent to the host. * * \ingroup Group_EndpointPacketManagement @@ -456,7 +456,7 @@ { return ((UEINTX & (1 << TXINI)) ? true : false); } - + /** Determines if the selected OUT endpoint has received new packet from the host. * * \ingroup Group_EndpointPacketManagement @@ -468,7 +468,7 @@ { return ((UEINTX & (1 << RXOUTI)) ? true : false); } - + /** Determines if the current CONTROL type endpoint has received a SETUP packet. * * \ingroup Group_EndpointPacketManagement @@ -480,20 +480,20 @@ { return ((UEINTX & (1 << RXSTPI)) ? true : false); } - + /** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the * endpoint for the next packet. * * \ingroup Group_EndpointPacketManagement * - * \note This is not applicable for non CONTROL type endpoints. + * \note This is not applicable for non CONTROL type endpoints. */ static inline void Endpoint_ClearSETUP(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_ClearSETUP(void) { UEINTX &= ~(1 << RXSTPI); } - + /** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the * next packet and switching to the alternative endpoint bank if double banked. * @@ -508,7 +508,7 @@ UEINTX &= ~(1 << TXINI); #endif } - + /** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint * for the next packet and switching to the alternative endpoint bank if double banked. * @@ -520,10 +520,10 @@ #if !defined(CONTROL_ONLY_DEVICE) UEINTX &= ~((1 << RXOUTI) | (1 << FIFOCON)); #else - UEINTX &= ~(1 << RXOUTI); + UEINTX &= ~(1 << RXOUTI); #endif } - + /** Stalls the current endpoint, indicating to the host that a logical problem occurred with the * indicated endpoint and that the current transfer sequence should be aborted. This provides a * way for devices to indicate invalid commands to the host so that the current transfer can be @@ -540,7 +540,7 @@ { UECONX |= (1 << STALLRQ); } - + /** Clears the STALL condition on the currently selected endpoint. * * \ingroup Group_EndpointPacketManagement @@ -550,7 +550,7 @@ { UECONX |= (1 << STALLRQC); } - + /** Determines if the currently selected endpoint is stalled, false otherwise. * * \ingroup Group_EndpointPacketManagement @@ -562,14 +562,14 @@ { return ((UECONX & (1 << STALLRQ)) ? true : false); } - + /** Resets the data toggle of the currently selected endpoint. */ static inline void Endpoint_ResetDataToggle(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_ResetDataToggle(void) { UECONX |= (1 << RSTDT); } - + /** Determines the currently selected endpoint's direction. * * \return The currently selected endpoint's direction, as a ENDPOINT_DIR_* mask. @@ -622,10 +622,10 @@ static inline void Endpoint_Discard_Byte(void) { uint8_t Dummy; - + Dummy = UEDATX; } - + /** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT * direction endpoints. * @@ -641,10 +641,10 @@ uint16_t Word; uint8_t Bytes[2]; } Data; - + Data.Bytes[0] = UEDATX; Data.Bytes[1] = UEDATX; - + return Data.Word; } @@ -663,10 +663,10 @@ uint16_t Word; uint8_t Bytes[2]; } Data; - + Data.Bytes[1] = UEDATX; Data.Bytes[0] = UEDATX; - + return Data.Word; } @@ -683,7 +683,7 @@ UEDATX = (Word & 0xFF); UEDATX = (Word >> 8); } - + /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN * direction endpoints. * @@ -706,7 +706,7 @@ static inline void Endpoint_Discard_Word(void) { uint8_t Dummy; - + Dummy = UEDATX; Dummy = UEDATX; } @@ -726,12 +726,12 @@ uint32_t DWord; uint8_t Bytes[4]; } Data; - + Data.Bytes[0] = UEDATX; Data.Bytes[1] = UEDATX; Data.Bytes[2] = UEDATX; Data.Bytes[3] = UEDATX; - + return Data.DWord; } @@ -750,12 +750,12 @@ uint32_t DWord; uint8_t Bytes[4]; } Data; - + Data.Bytes[3] = UEDATX; Data.Bytes[2] = UEDATX; Data.Bytes[1] = UEDATX; Data.Bytes[0] = UEDATX; - + return Data.DWord; } @@ -774,7 +774,7 @@ UEDATX = (DWord >> 16); UEDATX = (DWord >> 24); } - + /** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN * direction endpoints. * @@ -791,7 +791,7 @@ UEDATX = (DWord & 0xFF); } - /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints. + /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints. * * \ingroup Group_EndpointPrimitiveRW */ @@ -799,7 +799,7 @@ static inline void Endpoint_Discard_DWord(void) { uint8_t Dummy; - + Dummy = UEDATX; Dummy = UEDATX; Dummy = UEDATX; @@ -850,7 +850,8 @@ #if defined(__cplusplus) } #endif - + #endif /** @} */ + diff --git a/LUFA/Drivers/USB/LowLevel/Host.c b/LUFA/Drivers/USB/LowLevel/Host.c index 1fa5290fc..25b08b73b 100644 --- a/LUFA/Drivers/USB/LowLevel/Host.c +++ b/LUFA/Drivers/USB/LowLevel/Host.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -55,15 +55,15 @@ void USB_Host_ProcessNextHostState(void) ErrorCode = HOST_ENUMERROR_WaitStage; break; } - + if (!(--WaitMSRemaining)) USB_HostState = PostWaitState; } - + break; case HOST_STATE_Powered: WaitMSRemaining = HOST_DEVICE_SETTLE_DELAY_MS; - + USB_HostState = HOST_STATE_Powered_WaitForDeviceSettle; break; case HOST_STATE_Powered_WaitForDeviceSettle: @@ -79,23 +79,23 @@ void USB_Host_ProcessNextHostState(void) USB_OTGPAD_On(); USB_Host_VBUS_Auto_Enable(); USB_Host_VBUS_Auto_On(); - + USB_HostState = HOST_STATE_Powered_WaitForConnect; } - + break; - case HOST_STATE_Powered_WaitForConnect: + case HOST_STATE_Powered_WaitForConnect: if (USB_INT_HasOccurred(USB_INT_DCONNI)) - { + { USB_INT_Clear(USB_INT_DCONNI); USB_INT_Clear(USB_INT_DDISCI); USB_INT_Clear(USB_INT_VBERRI); USB_INT_Enable(USB_INT_VBERRI); - + USB_Host_ResumeBus(); Pipe_ClearPipes(); - + HOST_TASK_NONBLOCK_WAIT(100, HOST_STATE_Powered_DoReset); } @@ -108,8 +108,8 @@ void USB_Host_ProcessNextHostState(void) case HOST_STATE_Powered_ConfigPipe: Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL, PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP, - PIPE_CONTROLPIPE_DEFAULT_SIZE, PIPE_BANK_SINGLE); - + PIPE_CONTROLPIPE_DEFAULT_SIZE, PIPE_BANK_SINGLE); + if (!(Pipe_IsConfigured())) { ErrorCode = HOST_ENUMERROR_PipeConfigError; @@ -138,9 +138,9 @@ void USB_Host_ProcessNextHostState(void) } USB_ControlPipeSize = DataBuffer[offsetof(USB_Descriptor_Device_t, Endpoint0Size)]; - + USB_Host_ResetDevice(); - + HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Default_PostReset); break; case HOST_STATE_Default_PostReset: @@ -197,7 +197,7 @@ uint8_t USB_Host_WaitMS(uint8_t MS) bool BusSuspended = USB_Host_IsBusSuspended(); uint8_t ErrorCode = HOST_WAITERROR_Successful; bool HSOFIEnabled = USB_INT_IsEnabled(USB_INT_HSOFI); - + USB_INT_Disable(USB_INT_HSOFI); USB_INT_Clear(USB_INT_HSOFI); @@ -210,11 +210,11 @@ uint8_t USB_Host_WaitMS(uint8_t MS) USB_INT_Clear(USB_INT_HSOFI); MS--; } - + if ((USB_HostState == HOST_STATE_Unattached) || (USB_CurrentMode != USB_MODE_Host)) { ErrorCode = HOST_WAITERROR_DeviceDisconnect; - + break; } @@ -222,16 +222,16 @@ uint8_t USB_Host_WaitMS(uint8_t MS) { Pipe_ClearError(); ErrorCode = HOST_WAITERROR_PipeError; - + break; } - + if (Pipe_IsStalled() == true) { Pipe_ClearStall(); ErrorCode = HOST_WAITERROR_SetupStalled; - - break; + + break; } } @@ -249,7 +249,7 @@ static void USB_Host_ResetDevice(void) bool BusSuspended = USB_Host_IsBusSuspended(); USB_INT_Disable(USB_INT_DDISCI); - + USB_Host_ResetBus(); while (!(USB_Host_IsBusResetComplete())); USB_Host_ResumeBus(); @@ -258,7 +258,7 @@ static void USB_Host_ResetDevice(void) USB_INT_Disable(USB_INT_HSOFI); USB_INT_Clear(USB_INT_HSOFI); - + for (uint8_t MSRem = 10; MSRem != 0; MSRem--) { /* Workaround for powerless-pull-up devices. After a USB bus reset, @@ -272,7 +272,7 @@ static void USB_Host_ResetDevice(void) USB_INT_Clear(USB_INT_DDISCI); break; } - + _delay_ms(1); } @@ -297,7 +297,7 @@ uint8_t USB_Host_SetDeviceConfiguration(const uint8_t ConfigNumber) }; Pipe_SelectPipe(PIPE_CONTROLPIPE); - + return USB_Host_SendControlRequest(NULL); } @@ -313,7 +313,7 @@ uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr) }; Pipe_SelectPipe(PIPE_CONTROLPIPE); - + return USB_Host_SendControlRequest(DeviceDescriptorPtr); } @@ -331,7 +331,7 @@ uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index, }; Pipe_SelectPipe(PIPE_CONTROLPIPE); - + return USB_Host_SendControlRequest(Buffer); } @@ -347,8 +347,9 @@ uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointNum) }; Pipe_SelectPipe(PIPE_CONTROLPIPE); - + return USB_Host_SendControlRequest(NULL); } #endif + diff --git a/LUFA/Drivers/USB/LowLevel/Host.h b/LUFA/Drivers/USB/LowLevel/Host.h index 2da2e4ce6..f29ab1b3b 100644 --- a/LUFA/Drivers/USB/LowLevel/Host.h +++ b/LUFA/Drivers/USB/LowLevel/Host.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -45,7 +45,7 @@ * * @{ */ - + #ifndef __USBHOST_H__ #define __USBHOST_H__ @@ -68,7 +68,7 @@ #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: */ /** Indicates the fixed USB device address which any attached device is enumerated to when in @@ -83,12 +83,12 @@ * device. If a device fails to respond to a sent control request within this period, the * library will return a timeout error code. * - * This value may be overridden in the user project makefile as the value of the + * This value may be overridden in the user project makefile as the value of the * \ref USB_HOST_TIMEOUT_MS token, and passed to the compiler using the -D switch. */ #define USB_HOST_TIMEOUT_MS 1000 #endif - + #if !defined(HOST_DEVICE_SETTLE_DELAY_MS) || defined(__DOXYGEN__) /** Constant for the delay in milliseconds after a device is connected before the library * will start the enumeration process. Some devices require a delay of up to 5 seconds @@ -131,52 +131,52 @@ HOST_STATE_Unattached = 2, /**< Internally implemented by the library. This state indicates * that the host state machine is waiting for a device to be * attached so that it can start the enumeration process. - * + * * \note Do not manually change to this state in the user code. */ HOST_STATE_Powered = 3, /**< Internally implemented by the library. This state indicates * that a device has been attached, and the library's internals * are being configured to begin the enumeration process. - * + * * \note Do not manually change to this state in the user code. */ HOST_STATE_Powered_WaitForDeviceSettle = 4, /**< Internally implemented by the library. This state indicates * that the stack is waiting for the initial settling period to * elapse before beginning the enumeration process. - * + * * \note Do not manually change to this state in the user code. */ HOST_STATE_Powered_WaitForConnect = 5, /**< Internally implemented by the library. This state indicates * that the stack is waiting for a connection event from the USB * controller to indicate a valid USB device has been attached to * the bus and is ready to be enumerated. - * + * * \note Do not manually change to this state in the user code. */ HOST_STATE_Powered_DoReset = 6, /**< Internally implemented by the library. This state indicates * that a valid USB device has been attached, and that it is * will now be reset to ensure it is ready for enumeration. - * + * * \note Do not manually change to this state in the user code. */ HOST_STATE_Powered_ConfigPipe = 7, /**< Internally implemented by the library. This state indicates * that the attached device is currently powered and reset, and * that the control pipe is now being configured by the stack. - * + * * \note Do not manually change to this state in the user code. */ HOST_STATE_Default = 8, /**< Internally implemented by the library. This state indicates * that the stack is currently retrieving the control endpoint's * size from the device, so that the control pipe can be altered * to match. - * + * * \note Do not manually change to this state in the user code. */ HOST_STATE_Default_PostReset = 9, /**< Internally implemented by the library. This state indicates that * the control pipe is being reconfigured to match the retrieved * control endpoint size from the device, and the device's USB bus * address is being set. - * + * * \note Do not manually change to this state in the user code. */ HOST_STATE_Default_PostAddressSet = 10, /**< Internally implemented by the library. This state indicates that @@ -185,7 +185,7 @@ * stack to change the current USB device address to that set for * the connected device, before progressing to the user-implemented * \ref HOST_STATE_Addressed state for further communications. - * + * * \note Do not manually change to this state in the user code. */ HOST_STATE_Addressed = 11, /**< May be implemented by the user project. This state should @@ -204,7 +204,7 @@ * \ref HOST_STATE_WaitForDeviceRemoval states as needed. */ }; - + /** Enum for the error codes for the \ref EVENT_USB_Host_HostError() event. * * \see \ref Group_Events for more information on this event. @@ -218,7 +218,7 @@ * current. */ }; - + /** Enum for the error codes for the \ref EVENT_USB_Host_DeviceEnumerationFailed() event. * * \see \ref Group_Events for more information on this event. @@ -252,7 +252,7 @@ { return UHFNUM; } - + #if !defined(NO_SOF_EVENTS) /** Enables the host mode Start Of Frame events. When enabled, this causes the * \ref EVENT_USB_Host_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus, @@ -265,7 +265,7 @@ { USB_INT_Enable(USB_INT_HSOFI); } - + /** Disables the host mode Start Of Frame events. When disabled, this stops the firing of the * \ref EVENT_USB_Host_StartOfFrame() event when enumerated in host mode. * @@ -277,7 +277,7 @@ USB_INT_Disable(USB_INT_HSOFI); } #endif - + /** Resets the USB bus, including the endpoints in any attached device and pipes on the AVR host. * USB bus resets leave the default control pipe configured (if already configured). * @@ -320,7 +320,7 @@ { UHCON &= ~(1 << SOFEN); } - + /** Determines if the USB bus has been suspended via the use of the \ref USB_Host_SuspendBus() macro, * false otherwise. While suspended, no USB communications can occur until the bus is resumed, * except for the Remote Wakeup event from the device if supported. @@ -332,7 +332,7 @@ { return ((UHCON & (1 << SOFEN)) ? false : true); } - + /** Determines if the attached device is currently enumerated in Full Speed mode (12Mb/s), or * false if the attached device is enumerated in Low Speed mode (1.5Mb/s). * @@ -371,7 +371,7 @@ { UHCON |= (1 << RESUME); } - + /** Determines if a resume from Remote Wakeup request is currently being sent to an attached * device. * @@ -395,7 +395,7 @@ * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. */ uint8_t USB_Host_SetDeviceConfiguration(const uint8_t ConfigNumber); - + /** Convenience function. This routine sends a GetDescriptor standard request to the attached * device, requesting the device descriptor. This can be used to easily retrieve information * about the device such as its VID, PID and power requirements. @@ -408,7 +408,7 @@ * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. */ uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr); - + /** Convenience function. This routine sends a GetDescriptor standard request to the attached * device, requesting the string descriptor of the specified index. This can be used to easily * retrieve string descriptors from the device by index, after the index is obtained from the @@ -426,7 +426,7 @@ uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index, void* const Buffer, const uint8_t BufferLength); - + /** Clears a stall condition on the given pipe, via a ClearFeature request to the attached device. * * \note After this routine returns, the control pipe will be selected. @@ -458,13 +458,13 @@ OTGCON &= ~(1 << VBUSHWC); UHWCON |= (1 << UVCONE); } - + static inline void USB_Host_VBUS_Manual_Enable(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_VBUS_Manual_Enable(void) { OTGCON |= (1 << VBUSHWC); UHWCON &= ~(1 << UVCONE); - + DDRE |= (1 << 7); } @@ -479,7 +479,7 @@ { PORTE |= (1 << 7); } - + static inline void USB_Host_VBUS_Auto_Off(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_VBUS_Auto_Off(void) { @@ -490,7 +490,7 @@ static inline void USB_Host_VBUS_Manual_Off(void) { PORTE &= ~(1 << 7); - } + } static inline void USB_Host_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE; static inline void USB_Host_SetDeviceAddress(const uint8_t Address) @@ -510,7 +510,7 @@ /* Function Prototypes: */ void USB_Host_ProcessNextHostState(void); uint8_t USB_Host_WaitMS(uint8_t MS); - + #if defined(__INCLUDE_FROM_HOST_C) static void USB_Host_ResetDevice(void); #endif @@ -520,7 +520,8 @@ #if defined(__cplusplus) } #endif - + #endif /** @} */ + diff --git a/LUFA/Drivers/USB/LowLevel/OTG.h b/LUFA/Drivers/USB/LowLevel/OTG.h index 5afa8b3a2..d77b41b49 100644 --- a/LUFA/Drivers/USB/LowLevel/OTG.h +++ b/LUFA/Drivers/USB/LowLevel/OTG.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -27,7 +27,7 @@ arising out of or in connection with the use or performance of this software. */ - + /** \file * \brief USB OTG mode definitions. * @@ -54,26 +54,26 @@ /* Includes: */ #include <avr/io.h> #include <stdbool.h> - + #include "../../../Common/Common.h" /* 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: */ /** Mask for the VBUS pulsing method of SRP, supported by some OTG devices. * * \see \ref USB_OTG_Device_InitiateSRP(). - */ + */ #define USB_OTG_SRP_VBUS (1 << SRPSEL) /** Mask for the Data + pulsing method of SRP, supported by some OTG devices. * * \see \ref USB_OTG_Device_InitiateSRP(). - */ + */ #define USB_OTG_STP_DATA 0 /* Inline Functions: */ @@ -85,7 +85,7 @@ { OTGCON |= (1 << HNPREQ); } - + /** Cancel a Host Negotiation Protocol request. This stops a pending HNP request to the other * connected device. */ @@ -94,7 +94,7 @@ { OTGCON &= ~(1 << HNPREQ); } - + /** Determines if the device is currently sending a HNP to an attached host. * * \return Boolean true if currently sending a HNP to the other connected device, false otherwise @@ -104,7 +104,7 @@ { return ((OTGCON & (1 << HNPREQ)) ? true : false); } - + /** Initiates a Session Request Protocol request. Most OTG devices turn off VBUS when the USB * interface is not in use, to conserve power. Sending a SRP to a USB OTG device running in * host mode indicates that VBUS should be applied and a session started. @@ -129,7 +129,7 @@ { OTGCON |= (1 << HNPREQ); } - + /** Rejects a HNP from a connected device, indicating that both devices should remain in their * current device/host roles. */ @@ -138,7 +138,7 @@ { OTGCON &= ~(1 << HNPREQ); } - + /** Indicates if the connected device is not currently sending a HNP request. * * \return Boolean true if a HNP is currently being issued by the connected device, false otherwise. @@ -148,7 +148,8 @@ { return ((OTGCON & (1 << HNPREQ)) ? true : false); } - + #endif - + /** @} */ + diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.c b/LUFA/Drivers/USB/LowLevel/Pipe.c index e5c30e4b5..74a8f51e4 100644 --- a/LUFA/Drivers/USB/LowLevel/Pipe.c +++ b/LUFA/Drivers/USB/LowLevel/Pipe.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -48,7 +48,7 @@ bool Pipe_ConfigurePipe(const uint8_t Number, Pipe_EnablePipe(); UPCFG1X = 0; - + UPCFG0X = ((Type << EPTYPE0) | Token | ((EndpointNumber & PIPE_EPNUM_MASK) << PEPNUM0)); UPCFG1X = ((1 << ALLOC) | Banks | Pipe_BytesToEPSizeMask(Size)); @@ -78,20 +78,20 @@ bool Pipe_IsEndpointBound(const uint8_t EndpointAddress) for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++) { Pipe_SelectPipe(PNum); - + if (!(Pipe_IsConfigured())) continue; - + uint8_t PipeToken = Pipe_GetPipeToken(); bool PipeTokenCorrect = true; if (PipeToken != PIPE_TOKEN_SETUP) PipeTokenCorrect = (PipeToken == ((EndpointAddress & PIPE_EPDIR_MASK) ? PIPE_TOKEN_IN : PIPE_TOKEN_OUT)); - + if (PipeTokenCorrect && (Pipe_BoundEndpointNumber() == (EndpointAddress & PIPE_EPNUM_MASK))) return true; } - + Pipe_SelectPipe(PrevPipeNumber); return false; } @@ -99,13 +99,13 @@ bool Pipe_IsEndpointBound(const uint8_t EndpointAddress) uint8_t Pipe_WaitUntilReady(void) { #if (USB_STREAM_TIMEOUT_MS < 0xFF) - uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; + uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; #else uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; #endif uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber(); - + for (;;) { if (Pipe_GetPipeToken() == PIPE_TOKEN_IN) @@ -116,7 +116,7 @@ uint8_t Pipe_WaitUntilReady(void) else { if (Pipe_IsOUTReady()) - return PIPE_READYWAIT_NoError; + return PIPE_READYWAIT_NoError; } if (Pipe_IsStalled()) @@ -137,3 +137,4 @@ uint8_t Pipe_WaitUntilReady(void) } #endif + diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.h b/LUFA/Drivers/USB/LowLevel/Pipe.h index 58a5c9464..d8ba1bb02 100644 --- a/LUFA/Drivers/USB/LowLevel/Pipe.h +++ b/LUFA/Drivers/USB/LowLevel/Pipe.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -27,7 +27,7 @@ arising out of or in connection with the use or performance of this software. */ - + /** \file * \brief USB host pipe management definitions. * @@ -36,27 +36,27 @@ * * \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_PipeManagement * @defgroup Group_PipeRW Pipe Data Reading and Writing * * Functions, macros, variables, enums and types related to data reading and writing from and to pipes. */ - -/** \ingroup Group_PipeRW + +/** \ingroup Group_PipeRW * @defgroup Group_PipePrimitiveRW Read/Write of Primitive Data Types * * Functions, macros, variables, enums and types related to data reading and writing of primitive data types * from and to pipes. */ - + /** \ingroup Group_PipeManagement * @defgroup Group_PipePacketManagement Pipe Packet Management * * Functions, macros, variables, enums and types related to packet management of pipes. */ - + /** \ingroup Group_PipeManagement * @defgroup Group_PipeControlReq Pipe Control Request Management * @@ -64,7 +64,7 @@ * vendor control requests to the default control endpoint of an attached device while in host mode. * * \see Chapter 9 of the USB 2.0 specification. - */ + */ /** \ingroup Group_USB * @defgroup Group_PipeManagement Pipe Management @@ -85,7 +85,7 @@ #include "../../../Common/Common.h" #include "../HighLevel/USBTask.h" - + /* Enable C linkage for C++ Compilers: */ #if defined(__cplusplus) extern "C" { @@ -95,7 +95,7 @@ #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: */ /** Mask for \ref Pipe_GetErrorFlags(), indicating that an overflow error occurred in the pipe on the received data. */ @@ -146,17 +146,17 @@ * bank. */ #define PIPE_BANK_DOUBLE (1 << EPBK0) - + /** Pipe address for the default control pipe, which always resides in address 0. This is * defined for convenience to give more readable code when used with the pipe macros. */ #define PIPE_CONTROLPIPE 0 - /** Default size of the default control pipe's bank, until altered by the Endpoint0Size value + /** Default size of the default control pipe's bank, until altered by the Endpoint0Size value * in the device descriptor of the attached device. */ #define PIPE_CONTROLPIPE_DEFAULT_SIZE 64 - + /** Pipe number mask, for masking against pipe addresses to retrieve the pipe's numerical address * in the device. */ @@ -193,7 +193,7 @@ enum Pipe_WaitUntilReady_ErrorCodes_t { PIPE_READYWAIT_NoError = 0, /**< Pipe ready for next packet, no error. */ - PIPE_READYWAIT_PipeStalled = 1, /**< The device stalled the pipe while waiting. */ + PIPE_READYWAIT_PipeStalled = 1, /**< The device stalled the pipe while waiting. */ PIPE_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while waiting. */ PIPE_READYWAIT_Timeout = 3, /**< The device failed to accept or send the next packet * within the software timeout period set by the @@ -216,7 +216,7 @@ { return UPBCX; } - + /** Returns the pipe address of the currently selected pipe. This is typically used to save the * currently selected pipe number so that it can be restored after another pipe has been manipulated. * @@ -238,7 +238,7 @@ { UPNUM = PipeNumber; } - + /** Resets the desired pipe, including the pipe banks and flags. * * \param[in] PipeNumber Index of the pipe to reset. @@ -249,7 +249,7 @@ UPRST = (1 << PipeNumber); UPRST = 0; } - + /** Enables the currently selected pipe so that data can be sent and received through it to and from * an attached device. * @@ -279,7 +279,7 @@ { return ((UPCONX & (1 << PEN)) ? true : false); } - + /** Gets the current pipe token, indicating the pipe's data direction and type. * * \return The current pipe token, as a PIPE_TOKEN_* mask. @@ -289,7 +289,7 @@ { return (UPCFG0X & (0x03 << PTOKEN0)); } - + /** Sets the token for the currently selected pipe to one of the tokens specified by the PIPE_TOKEN_* * masks. This can be used on CONTROL type pipes, to allow for bidirectional transfer of data during * control requests, or on regular pipes to allow for half-duplex bidirectional data transfer to devices @@ -302,14 +302,14 @@ { UPCFG0X = ((UPCFG0X & ~(0x03 << PTOKEN0)) | Token); } - + /** Configures the currently selected pipe to allow for an unlimited number of IN requests. */ static inline void Pipe_SetInfiniteINRequests(void) ATTR_ALWAYS_INLINE; static inline void Pipe_SetInfiniteINRequests(void) { UPCONX |= (1 << INMODE); } - + /** Configures the currently selected pipe to only allow the specified number of IN requests to be * accepted by the pipe before it is automatically frozen. * @@ -331,7 +331,7 @@ { return ((UPSTAX & (1 << CFGOK)) ? true : false); } - + /** Retrieves the endpoint number of the endpoint within the attached device that the currently selected * pipe is bound to. * @@ -352,7 +352,7 @@ { UPCFG2X = Milliseconds; } - + /** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should * be serviced. * @@ -363,7 +363,7 @@ { return UPINT; } - + /** Determines if the specified pipe number has interrupted (valid only for INTERRUPT type * pipes). * @@ -376,14 +376,14 @@ { return ((UPINT & (1 << PipeNumber)) ? true : false); } - + /** Unfreezes the selected pipe, allowing it to communicate with an attached device. */ static inline void Pipe_Unfreeze(void) ATTR_ALWAYS_INLINE; static inline void Pipe_Unfreeze(void) { UPCONX &= ~(1 << PFREEZE); } - + /** Freezes the selected pipe, preventing it from communicating with an attached device. */ static inline void Pipe_Freeze(void) ATTR_ALWAYS_INLINE; static inline void Pipe_Freeze(void) @@ -400,14 +400,14 @@ { return ((UPCONX & (1 << PFREEZE)) ? true : false); } - + /** Clears the master pipe error flag. */ static inline void Pipe_ClearError(void) ATTR_ALWAYS_INLINE; static inline void Pipe_ClearError(void) { UPINTX &= ~(1 << PERRI); } - + /** Determines if the master pipe error flag is set for the currently selected pipe, indicating that * some sort of hardware error has occurred on the pipe. * @@ -420,7 +420,7 @@ { return ((UPINTX & (1 << PERRI)) ? true : false); } - + /** Clears all the currently selected pipe's hardware error flags, but does not clear the master error * flag for the pipe. */ @@ -429,7 +429,7 @@ { UPERRX = 0; } - + /** Gets a mask of the hardware error flags which have occurred on the currently selected pipe. This * value can then be masked against the PIPE_ERRORFLAG_* masks to determine what error has occurred. * @@ -443,7 +443,7 @@ PIPE_ERRORFLAG_DATATGL)) | (UPSTAX & (PIPE_ERRORFLAG_OVERFLOW | PIPE_ERRORFLAG_UNDERFLOW))); } - + /** Determines if the currently selected pipe may be read from (if data is waiting in the pipe * bank and the pipe is an IN direction, or if the bank is not yet full if the pipe is an OUT * direction). This function will return false if an error has occurred in the pipe, or if the pipe @@ -453,7 +453,7 @@ * \note This function is not valid on CONTROL type pipes. * * \ingroup Group_PipePacketManagement - * + * * \return Boolean true if the currently selected pipe may be read from or written to, depending on its direction. */ static inline bool Pipe_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; @@ -461,7 +461,7 @@ { return ((UPINTX & (1 << RWAL)) ? true : false); } - + /** Determines if a packet has been received on the currently selected IN pipe from the attached device. * * \ingroup Group_PipePacketManagement @@ -473,7 +473,7 @@ { return ((UPINTX & (1 << RXINI)) ? true : false); } - + /** Determines if the currently selected OUT pipe is ready to send an OUT packet to the attached device. * * \ingroup Group_PipePacketManagement @@ -498,10 +498,10 @@ { return ((UPINTX & (1 << TXSTPI)) ? true : false); } - + /** Sends the currently selected CONTROL type pipe's contents to the device as a SETUP packet. * - * \ingroup Group_PipePacketManagement + * \ingroup Group_PipePacketManagement */ static inline void Pipe_ClearSETUP(void) ATTR_ALWAYS_INLINE; static inline void Pipe_ClearSETUP(void) @@ -558,7 +558,7 @@ { UPINTX &= ~(1 << NAKEDI); } - + /** Determines if the currently selected pipe has had the STALL condition set by the attached device. * * \ingroup Group_PipePacketManagement @@ -570,7 +570,7 @@ { return ((UPINTX & (1 << RXSTALLI)) ? true : false); } - + /** Clears the STALL condition detection flag on the currently selected pipe, but does not clear the * STALL condition itself (this must be done via a ClearFeature control request to the device). * @@ -614,10 +614,10 @@ static inline void Pipe_Discard_Byte(void) { uint8_t Dummy; - + Dummy = UPDATX; } - + /** Reads two bytes from the currently selected pipe's bank in little endian format, for OUT * direction pipes. * @@ -633,10 +633,10 @@ uint16_t Word; uint8_t Bytes[2]; } Data; - + Data.Bytes[0] = UPDATX; Data.Bytes[1] = UPDATX; - + return Data.Word; } @@ -655,13 +655,13 @@ uint16_t Word; uint8_t Bytes[2]; } Data; - + Data.Bytes[1] = UPDATX; Data.Bytes[0] = UPDATX; - + return Data.Word; } - + /** Writes two bytes to the currently selected pipe's bank in little endian format, for IN * direction pipes. * @@ -675,7 +675,7 @@ UPDATX = (Word & 0xFF); UPDATX = (Word >> 8); } - + /** Writes two bytes to the currently selected pipe's bank in big endian format, for IN * direction pipes. * @@ -698,7 +698,7 @@ static inline void Pipe_Discard_Word(void) { uint8_t Dummy; - + Dummy = UPDATX; Dummy = UPDATX; } @@ -718,12 +718,12 @@ uint32_t DWord; uint8_t Bytes[4]; } Data; - + Data.Bytes[0] = UPDATX; Data.Bytes[1] = UPDATX; Data.Bytes[2] = UPDATX; Data.Bytes[3] = UPDATX; - + return Data.DWord; } @@ -742,12 +742,12 @@ uint32_t DWord; uint8_t Bytes[4]; } Data; - + Data.Bytes[3] = UPDATX; Data.Bytes[2] = UPDATX; Data.Bytes[1] = UPDATX; Data.Bytes[0] = UPDATX; - + return Data.DWord; } @@ -766,7 +766,7 @@ UPDATX = (DWord >> 16); UPDATX = (DWord >> 24); } - + /** Writes four bytes to the currently selected pipe's bank in big endian format, for IN * direction pipes. * @@ -781,9 +781,9 @@ UPDATX = (DWord >> 16); UPDATX = (DWord >> 8); UPDATX = (DWord & 0xFF); - } - - /** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes. + } + + /** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes. * * \ingroup Group_PipePrimitiveRW */ @@ -791,7 +791,7 @@ static inline void Pipe_Discard_DWord(void) { uint8_t Dummy; - + Dummy = UPDATX; Dummy = UPDATX; Dummy = UPDATX; @@ -825,14 +825,14 @@ * Speed USB devices - refer to the USB 2.0 specification. * * \param[in] Token Pipe data token, either \ref PIPE_TOKEN_SETUP, \ref PIPE_TOKEN_OUT or \ref PIPE_TOKEN_IN. - * All pipes (except Control type) are unidirectional - data may only be read from or + * All pipes (except Control type) are unidirectional - data may only be read from or * written to the pipe bank based on its direction, not both. * * \param[in] EndpointNumber Endpoint index within the attached device that the pipe should interface to. * * \param[in] Size Size of the pipe's bank, where packets are stored before they are transmitted to - * the USB device, or after they have been received from the USB device (depending on - * the pipe's data direction). The bank size must indicate the maximum packet size that + * the USB device, or after they have been received from the USB device (depending on + * the pipe's data direction). The bank size must indicate the maximum packet size that * the pipe can handle. * * \param[in] Banks Number of banks to use for the pipe being configured, a PIPE_BANK_* mask. More banks @@ -862,7 +862,7 @@ const uint16_t Size, const uint8_t Banks); - /** Spin-loops until the currently selected non-control pipe is ready for the next packed of data to be read + /** Spin-loops until the currently selected non-control pipe is ready for the next packed of data to be read * or written to it, aborting in the case of an error condition (such as a timeout or device disconnect). * * \ingroup Group_PipeRW @@ -870,7 +870,7 @@ * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum. */ uint8_t Pipe_WaitUntilReady(void); - + /** Determines if a pipe has been bound to the given device endpoint address. If a pipe which is bound to the given * endpoint is found, it is automatically selected. * @@ -887,20 +887,20 @@ #if !defined(ENDPOINT_CONTROLEP) #define ENDPOINT_CONTROLEP 0 #endif - + /* Inline Functions: */ static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE; static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes) { uint8_t MaskVal = 0; uint16_t CheckBytes = 8; - + while ((CheckBytes < Bytes) && (CheckBytes < PIPE_MAX_SIZE)) { MaskVal++; CheckBytes <<= 1; } - + return (MaskVal << EPSIZE0); } @@ -912,7 +912,8 @@ #if defined(__cplusplus) } #endif - + #endif /** @} */ + diff --git a/LUFA/Drivers/USB/LowLevel/USBController.c b/LUFA/Drivers/USB/LowLevel/USBController.c index 6d4a89dd0..b409582a0 100644 --- a/LUFA/Drivers/USB/LowLevel/USBController.c +++ b/LUFA/Drivers/USB/LowLevel/USBController.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -50,7 +50,7 @@ void USB_Init( #elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS)) void #endif - + #if !defined(USE_STATIC_OPTIONS) const uint8_t Options #endif @@ -59,7 +59,7 @@ void USB_Init( #if !defined(USE_STATIC_OPTIONS) USB_Options = Options; #endif - + if (!(USB_Options & USB_OPT_REG_DISABLED)) USB_REG_On(); else @@ -69,7 +69,7 @@ void USB_Init( if (Mode == USB_MODE_UID) { UHWCON |= (1 << UIDE); - USB_INT_Enable(USB_INT_IDTI); + USB_INT_Enable(USB_INT_IDTI); USB_CurrentMode = USB_GetUSBModeFromUID(); } else @@ -90,10 +90,10 @@ void USB_ShutDown(void) USB_Detach(); USB_Controller_Disable(); - + 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) @@ -115,9 +115,9 @@ void USB_ResetInterface(void) USB_INT_DisableAllInterrupts(); USB_INT_ClearAllInterrupts(); - + USB_Controller_Reset(); - + if (!(USB_Options & USB_OPT_MANUAL_PLL)) { #if defined(USB_SERIES_4_AVR) @@ -137,14 +137,14 @@ void USB_ResetInterface(void) #endif USB_CLK_Unfreeze(); - + if (USB_CurrentMode == USB_MODE_Device) { #if defined(USB_CAN_BE_DEVICE) #if (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) UHWCON |= (1 << UIMOD); #endif - + USB_Init_Device(); #endif } @@ -155,7 +155,7 @@ void USB_ResetInterface(void) USB_Init_Host(); #endif } - + #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) USB_OTGPAD_On(); #endif @@ -170,7 +170,7 @@ static void USB_Init_Device(void) #if !defined(NO_DEVICE_REMOTE_WAKEUP) USB_RemoteWakeupEnabled = false; #endif - + #if !defined(NO_DEVICE_SELF_POWER) USB_CurrentlySelfPowered = false; #endif @@ -179,7 +179,7 @@ static void USB_Init_Device(void) 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) @@ -201,7 +201,7 @@ static void USB_Init_Device(void) Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL, ENDPOINT_DIR_OUT, USB_ControlEndpointSize, - ENDPOINT_BANK_SINGLE); + ENDPOINT_BANK_SINGLE); USB_INT_Clear(USB_INT_SUSPI); USB_INT_Enable(USB_INT_SUSPI); @@ -218,7 +218,7 @@ static void USB_Init_Host(void) USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE; USB_Host_HostMode_On(); - + USB_Host_VBUS_Auto_Off(); USB_Host_VBUS_Manual_Enable(); USB_Host_VBUS_Manual_On(); @@ -229,3 +229,4 @@ static void USB_Init_Host(void) USB_Attach(); } #endif + diff --git a/LUFA/Drivers/USB/LowLevel/USBController.h b/LUFA/Drivers/USB/LowLevel/USBController.h index 8a2fec788..fb71eb504 100644 --- a/LUFA/Drivers/USB/LowLevel/USBController.h +++ b/LUFA/Drivers/USB/LowLevel/USBController.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -37,7 +37,7 @@ * \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 * @@ -53,7 +53,7 @@ #include <avr/io.h> #include <avr/interrupt.h> #include <stdbool.h> - + #include "../HighLevel/USBMode.h" #include "../../../Common/Common.h" @@ -61,7 +61,7 @@ #include "../HighLevel/Events.h" #include "../HighLevel/USBTask.h" #include "USBInterrupt.h" - + #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__) #include "Host.h" #include "OTG.h" @@ -69,7 +69,7 @@ #include "../HighLevel/HostStandardReq.h" #include "../HighLevel/PipeStream.h" #endif - + #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__) #include "Device.h" #include "Endpoint.h" @@ -90,7 +90,7 @@ #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__) || \ @@ -116,13 +116,13 @@ #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: */ + /* Macros: */ /** 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. * @@ -136,7 +136,7 @@ * \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. @@ -178,12 +178,12 @@ * (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 + * 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 - + /* Inline Functions: */ #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), @@ -246,21 +246,21 @@ * 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, + * \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 + * (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 + * 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 + * + * \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. @@ -280,7 +280,7 @@ 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. @@ -314,7 +314,7 @@ #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. @@ -348,12 +348,12 @@ #if defined(USB_CAN_BE_DEVICE) static void USB_Init_Device(void); #endif - + #if defined(USB_CAN_BE_HOST) static void USB_Init_Host(void); #endif #endif - + /* Inline Functions: */ static inline void USB_PLL_On(void) ATTR_ALWAYS_INLINE; static inline void USB_PLL_On(void) @@ -361,13 +361,13 @@ PLLCSR = USB_PLL_PSC; PLLCSR |= (1 << PLLE); } - + static inline void USB_PLL_Off(void) ATTR_ALWAYS_INLINE; static inline void USB_PLL_Off(void) { PLLCSR = 0; } - + static inline bool USB_PLL_IsReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool USB_PLL_IsReady(void) { @@ -381,7 +381,7 @@ UHWCON |= (1 << UVREGE); #else REGCR &= ~(1 << REGDIS); - #endif + #endif } static inline void USB_REG_Off(void) ATTR_ALWAYS_INLINE; @@ -391,9 +391,9 @@ UHWCON &= ~(1 << UVREGE); #else REGCR |= (1 << REGDIS); - #endif + #endif } - + #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) static inline void USB_OTGPAD_On(void) ATTR_ALWAYS_INLINE; static inline void USB_OTGPAD_On(void) @@ -413,13 +413,13 @@ { USBCON |= (1 << FRZCLK); } - + static inline void USB_CLK_Unfreeze(void) ATTR_ALWAYS_INLINE; static inline void USB_CLK_Unfreeze(void) { USBCON &= ~(1 << FRZCLK); } - + static inline void USB_Controller_Enable(void) ATTR_ALWAYS_INLINE; static inline void USB_Controller_Enable(void) { @@ -436,11 +436,11 @@ static inline void USB_Controller_Reset(void) { const uint8_t Temp = USBCON; - + USBCON = (Temp & ~(1 << USBE)); USBCON = (Temp | (1 << USBE)); } - + #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) @@ -453,12 +453,13 @@ #endif #endif - + /* Disable C linkage for C++ Compilers: */ #if defined(__cplusplus) } #endif - + #endif /** @} */ + diff --git a/LUFA/Drivers/USB/LowLevel/USBInterrupt.c b/LUFA/Drivers/USB/LowLevel/USBInterrupt.c index 54983c09e..92723ef0e 100644 --- a/LUFA/Drivers/USB/LowLevel/USBInterrupt.c +++ b/LUFA/Drivers/USB/LowLevel/USBInterrupt.c @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -34,19 +34,19 @@ void USB_INT_DisableAllInterrupts(void) { #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) - USBCON &= ~((1 << VBUSTE) | (1 << IDTE)); + USBCON &= ~((1 << VBUSTE) | (1 << IDTE)); #elif defined(USB_SERIES_4_AVR) USBCON &= ~(1 << VBUSTE); #endif - + #if defined(USB_CAN_BE_BOTH) OTGIEN = 0; #endif - + #if defined(USB_CAN_BE_HOST) UHIEN = 0; #endif - + #if defined(USB_CAN_BE_DEVICE) UDIEN = 0; #endif @@ -57,15 +57,15 @@ void USB_INT_ClearAllInterrupts(void) #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) USBINT = 0; #endif - + #if defined(USB_CAN_BE_BOTH) OTGINT = 0; #endif - + #if defined(USB_CAN_BE_HOST) UHINT = 0; #endif - + #if defined(USB_CAN_BE_DEVICE) UDINT = 0; #endif @@ -86,7 +86,7 @@ ISR(USB_GEN_vect, ISR_BLOCK) } else { - USB_DeviceState = DEVICE_STATE_Unattached; + USB_DeviceState = DEVICE_STATE_Unattached; EVENT_USB_Device_Disconnect(); } } @@ -98,9 +98,9 @@ ISR(USB_GEN_vect, ISR_BLOCK) USB_INT_Disable(USB_INT_SUSPI); USB_INT_Enable(USB_INT_WAKEUPI); - + USB_CLK_Freeze(); - + if (!(USB_Options & USB_OPT_MANUAL_PLL)) USB_PLL_Off(); @@ -127,19 +127,19 @@ ISR(USB_GEN_vect, ISR_BLOCK) USB_INT_Disable(USB_INT_WAKEUPI); USB_INT_Enable(USB_INT_SUSPI); - + if (USB_ConfigurationNumber) USB_DeviceState = DEVICE_STATE_Configured; else USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered; - + #if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT) EVENT_USB_Device_Connect(); #else - EVENT_USB_Device_WakeUp(); + EVENT_USB_Device_WakeUp(); #endif } - + if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI)) { USB_INT_Clear(USB_INT_EORSTI); @@ -161,29 +161,29 @@ ISR(USB_GEN_vect, ISR_BLOCK) EVENT_USB_Device_Reset(); } - + #if !defined(NO_SOF_EVENTS) if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI)) { USB_INT_Clear(USB_INT_SOFI); - + EVENT_USB_Device_StartOfFrame(); } - #endif #endif - + #endif + #if defined(USB_CAN_BE_HOST) if (USB_INT_HasOccurred(USB_INT_DDISCI) && USB_INT_IsEnabled(USB_INT_DDISCI)) { USB_INT_Clear(USB_INT_DDISCI); USB_INT_Clear(USB_INT_DCONNI); USB_INT_Disable(USB_INT_DDISCI); - + EVENT_USB_Host_DeviceUnattached(); USB_ResetInterface(); } - + if (USB_INT_HasOccurred(USB_INT_VBERRI) && USB_INT_IsEnabled(USB_INT_VBERRI)) { USB_INT_Clear(USB_INT_VBERRI); @@ -201,18 +201,18 @@ ISR(USB_GEN_vect, ISR_BLOCK) { USB_INT_Clear(USB_INT_SRPI); USB_INT_Disable(USB_INT_SRPI); - + EVENT_USB_Host_DeviceAttached(); USB_INT_Enable(USB_INT_DDISCI); - + USB_HostState = HOST_STATE_Powered; } if (USB_INT_HasOccurred(USB_INT_BCERRI) && USB_INT_IsEnabled(USB_INT_BCERRI)) { USB_INT_Clear(USB_INT_BCERRI); - + EVENT_USB_Host_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected, 0); EVENT_USB_Host_DeviceUnattached(); @@ -223,7 +223,7 @@ ISR(USB_GEN_vect, ISR_BLOCK) if (USB_INT_HasOccurred(USB_INT_HSOFI) && USB_INT_IsEnabled(USB_INT_HSOFI)) { USB_INT_Clear(USB_INT_HSOFI); - + EVENT_USB_Host_StartOfFrame(); } #endif @@ -231,7 +231,7 @@ ISR(USB_GEN_vect, ISR_BLOCK) #if defined(USB_CAN_BE_BOTH) if (USB_INT_HasOccurred(USB_INT_IDTI) && USB_INT_IsEnabled(USB_INT_IDTI)) - { + { USB_INT_Clear(USB_INT_IDTI); if (USB_DeviceState != DEVICE_STATE_Unattached) @@ -239,7 +239,7 @@ ISR(USB_GEN_vect, ISR_BLOCK) if (USB_HostState != HOST_STATE_Unattached) EVENT_USB_Host_DeviceUnattached(); - + USB_CurrentMode = USB_GetUSBModeFromUID(); USB_ResetInterface(); @@ -251,7 +251,7 @@ ISR(USB_GEN_vect, ISR_BLOCK) #if defined(INTERRUPT_CONTROL_ENDPOINT) && defined(USB_CAN_BE_DEVICE) ISR(USB_COM_vect, ISR_BLOCK) { - uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint(); + uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint(); Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); USB_INT_Disable(USB_INT_RXSTPI); @@ -266,3 +266,4 @@ ISR(USB_COM_vect, ISR_BLOCK) Endpoint_SelectEndpoint(PrevSelectedEndpoint); } #endif + diff --git a/LUFA/Drivers/USB/LowLevel/USBInterrupt.h b/LUFA/Drivers/USB/LowLevel/USBInterrupt.h index 8c9b2db1d..51e7a803e 100644 --- a/LUFA/Drivers/USB/LowLevel/USBInterrupt.h +++ b/LUFA/Drivers/USB/LowLevel/USBInterrupt.h @@ -1,7 +1,7 @@ /* LUFA Library Copyright (C) Dean Camera, 2010. - + dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ @@ -9,13 +9,13 @@ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) - Permission to use, copy, modify, distribute, and sell this + Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted - without fee, provided that the above copyright notice appear in + without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -37,7 +37,7 @@ * \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 __USBINTERRUPT_H__ #define __USBINTERRUPT_H__ @@ -46,7 +46,7 @@ #include <avr/interrupt.h> #include <util/atomic.h> #include <stdbool.h> - + /* Enable C linkage for C++ Compilers: */ #if defined(__cplusplus) extern "C" { @@ -56,7 +56,7 @@ #if !defined(__INCLUDE_FROM_USB_DRIVER) #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif - + /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Macros: */ @@ -91,15 +91,16 @@ #include "../HighLevel/USBMode.h" #include "../HighLevel/Events.h" #include "USBController.h" - + /* Function Prototypes: */ void USB_INT_ClearAllInterrupts(void); void USB_INT_DisableAllInterrupts(void); #endif - + /* Disable C linkage for C++ Compilers: */ #if defined(__cplusplus) } #endif #endif + |