aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers/USB/LowLevel
diff options
context:
space:
mode:
Diffstat (limited to 'LUFA/Drivers/USB/LowLevel')
-rw-r--r--LUFA/Drivers/USB/LowLevel/DevChapter9.c796
-rw-r--r--LUFA/Drivers/USB/LowLevel/DevChapter9.h328
-rw-r--r--LUFA/Drivers/USB/LowLevel/Device.h452
-rw-r--r--LUFA/Drivers/USB/LowLevel/Endpoint.c676
-rw-r--r--LUFA/Drivers/USB/LowLevel/Endpoint.h2528
-rw-r--r--LUFA/Drivers/USB/LowLevel/Host.c694
-rw-r--r--LUFA/Drivers/USB/LowLevel/Host.h856
-rw-r--r--LUFA/Drivers/USB/LowLevel/HostChapter9.c358
-rw-r--r--LUFA/Drivers/USB/LowLevel/HostChapter9.h234
-rw-r--r--LUFA/Drivers/USB/LowLevel/LowLevel.c542
-rw-r--r--LUFA/Drivers/USB/LowLevel/LowLevel.h778
-rw-r--r--LUFA/Drivers/USB/LowLevel/OTG.h282
-rw-r--r--LUFA/Drivers/USB/LowLevel/Pipe.c584
-rw-r--r--LUFA/Drivers/USB/LowLevel/Pipe.h2130
-rw-r--r--LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c86
-rw-r--r--LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c104
-rw-r--r--LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_RW.c152
-rw-r--r--LUFA/Drivers/USB/LowLevel/Template/Template_Pipe_RW.c160
-rw-r--r--LUFA/Drivers/USB/LowLevel/USBInterrupt.c494
-rw-r--r--LUFA/Drivers/USB/LowLevel/USBInterrupt.h206
20 files changed, 6220 insertions, 6220 deletions
diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.c b/LUFA/Drivers/USB/LowLevel/DevChapter9.c
index b7f811b5e..f44cf0ba4 100644
--- a/LUFA/Drivers/USB/LowLevel/DevChapter9.c
+++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.c
@@ -1,398 +1,398 @@
-/*
- 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 (USB_DeviceState != DEVICE_STATE_Addressed)
- return;
-
-#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) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
-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) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
- 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
+/*
+ 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 (USB_DeviceState != DEVICE_STATE_Addressed)
+ return;
+
+#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) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
+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) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
+ 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
index 868c3fab2..7bafcbfb3 100644
--- a/LUFA/Drivers/USB/LowLevel/DevChapter9.h
+++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.h
@@ -1,164 +1,164 @@
-/*
- 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 neccesary for the processing of incomming 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 <avr/io.h>
- #include <avr/pgmspace.h>
- #include <avr/eeprom.h>
- #include <avr/boot.h>
- #include <util/atomic.h>
-
- #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) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
- 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
+/*
+ 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 neccesary for the processing of incomming 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 <avr/io.h>
+ #include <avr/pgmspace.h>
+ #include <avr/eeprom.h>
+ #include <avr/boot.h>
+ #include <util/atomic.h>
+
+ #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) && (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
+ 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 5ef4fc08a..d8e7739b3 100644
--- a/LUFA/Drivers/USB/LowLevel/Device.h
+++ b/LUFA/Drivers/USB/LowLevel/Device.h
@@ -1,226 +1,226 @@
-/*
- 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 mode definitions.
- *
- * This file contains structures, function prototypes and macros related to 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.
- */
-
-/** \ingroup Group_USB
- * @defgroup Group_Device Device Management
- *
- * USB Device mode related macros and enums. This module contains macros and enums which are used when
- * the USB controller is initialized in device mode.
- *
- * @{
- */
-
-#ifndef __USBDEVICE_H__
-#define __USBDEVICE_H__
-
- /* Includes: */
- #include <avr/pgmspace.h>
- #include <avr/eeprom.h>
-
- #include "../../../Common/Common.h"
- #include "../HighLevel/StdDescriptors.h"
- #include "Endpoint.h"
-
- /* Preprocessor Checks: */
- #if (defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS))
- #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
- #endif
-
- #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__)
- /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
- * USB interface should be initialized in low speed (1.5Mb/s) mode.
- *
- * \note Low Speed mode is not available on all USB AVR models.
- * \n\n
- *
- * \note Restrictions apply on the number, size and type of endpoints which can be used
- * when running in low speed mode -- refer to the USB 2.0 standard.
- */
- #define USB_DEVICE_OPT_LOWSPEED (1 << 0)
- #endif
-
- /** Mask for the Options parameter of the USB_Init() function. This indicates that the
- * USB interface should be initialized in full speed (12Mb/s) mode.
- */
- #define USB_DEVICE_OPT_FULLSPEED (0 << 0)
-
- /* Pseudo-Function Macros: */
- #if defined(__DOXYGEN__)
- /** Sends a Remote Wakeup request to the host. This signals to the host that the device should
- * be taken out of suspended mode, and communications should resume.
- *
- * Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
- * host computer when the host has suspended all USB devices to enter a low power state.
- *
- * \note This macro should only be used if the device has indicated to the host that it
- * supports the Remote Wakeup feature in the device descriptors, and should only be
- * issued if the host is currently allowing remote wakeup events from the device (i.e.,
- * the \ref USB_RemoteWakeupEnabled flag is set). When the NO_DEVICE_REMOTE_WAKEUP compile
- * time option is used, this macro is unavailable.
- *
- * \see \ref Group_Descriptors for more information on the RMWAKEUP feature and device descriptors.
- */
- static inline void USB_Device_SendRemoteWakeup(void);
-
- /** Indicates if a Remote Wakeup request is being sent to the host. This returns true if a
- * remote wakeup is currently being sent, false otherwise.
- *
- * This can be used in conjunction with the \ref USB_Device_IsUSBSuspended() macro to determine if
- * a sent RMWAKEUP request was accepted or rejected by the host.
- *
- * \note This macro should only be used if the device has indicated to the host that it
- * supports the Remote Wakeup feature in the device descriptors. When the NO_DEVICE_REMOTE_WAKEUP
- * compile time option is used, this macro is unavailable.
- *
- * \see \ref Group_Descriptors for more information on the RMWAKEUP feature and device descriptors.
- *
- * \return Boolean true if no Remote Wakeup request is currently being sent, false otherwise
- */
- static inline bool USB_Device_IsRemoteWakeupSent(void);
-
- /** Indicates if the device is currently suspended by the host. Whilst suspended, the device is
- * to enter a low power state until resumed by the host. No USB traffic to or from the device
- * can occur (except for Remote Wakeup requests) during suspension by the host.
- *
- * \return Boolean true if the USB communications have been suspended by the host, false otherwise.
- */
- static inline bool USB_Device_IsUSBSuspended(void);
-
- /** 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,
- * at the start of each USB frame when enumerated in device mode.
- */
- static inline bool USB_Device_EnableSOFEvents(void);
-
- /** Disables the device mode Start Of Frame events. When disabled, this stop the firing of the
- * \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.
- */
- static inline bool USB_Device_DisableSOFEvents(void);
- #else
- #if !defined(NO_DEVICE_REMOTE_WAKEUP)
- #define USB_Device_SendRemoteWakeup() MACROS{ UDCON |= (1 << RMWKUP); }MACROE
-
- #define USB_Device_IsRemoteWakeupSent() ((UDCON & (1 << RMWKUP)) ? false : true)
- #endif
-
- #define USB_Device_IsUSBSuspended() ((UDINT & (1 << SUSPI)) ? true : false)
-
- #define USB_Device_EnableSOFEvents() MACROS{ USB_INT_Enable(USB_INT_SOFI); }MACROE
-
- #define USB_Device_DisableSOFEvents() MACROS{ USB_INT_Disable(USB_INT_SOFI); }MACROE
- #endif
-
- /* Type Defines: */
- enum USB_Device_States_t
- {
- DEVICE_STATE_Unattached = 0, /**< Internally implemented by the library. This state indicates
- * that the device is not currently connected to a host.
- */
- DEVICE_STATE_Powered = 1, /**< Internally implemented by the library. This state indicates
- * that the device is connected to a host, but enumeration has not
- * yet begun.
- */
- DEVICE_STATE_Default = 2, /**< Internally implemented by the library. This state indicates
- * that the device's USB bus has been reset by the host and it is
- * now waiting for the host to begin the enumeration process.
- */
- DEVICE_STATE_Addressed = 3, /**< Internally implemented by the library. This state indicates
- * that the device has been addressed by the USB Host, but is not
- * yet configured.
- */
- DEVICE_STATE_Configured = 4, /**< May be implemented by the user project. This state indicates
- * that the device has been enumerated by the host and is ready
- * for USB communications to begin.
- */
- DEVICE_STATE_Suspended = 5, /**< May be implemented by the user project. This state indicates
- * that the USB bus has been suspended by the host, and the device
- * should power down to a minimal power level until the bus is
- * resumed.
- */
- };
-
- /* 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
- * 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
- * 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.
- * \param[in] wIndex The language ID of the string to return if the wValue type indicates DTYPE_String,
- * otherwise zero for standard descriptors, or as defined in a class-specific
- * standards.
- * \param[out] DescriptorAddress Pointer to the descriptor in memory. This should be set by the routine to
- * the address of the descriptor.
- * \param[out] MemoryAddressSpace A value from the \ref USB_DescriptorMemorySpaces_t enum to indicate the memory
- * space in which the descriptor is stored. This parameter does not exist when one
- * of the USE_*_DESCRIPTORS compile time options is used.
- *
- * \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
- * USE_EEPROM_DESCRIPTORS tokens may be defined in the project makefile and passed to the compiler by the -D
- * switch.
- *
- * \return Size in bytes of the descriptor if it exists, zero or \ref NO_DESCRIPTOR otherwise
- */
- uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress
- #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS)
- , uint8_t* MemoryAddressSpace
- #endif
- )
- ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
-
- /* 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
- #endif
-
-#endif
-
-/** @} */
+/*
+ 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 mode definitions.
+ *
+ * This file contains structures, function prototypes and macros related to 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.
+ */
+
+/** \ingroup Group_USB
+ * @defgroup Group_Device Device Management
+ *
+ * USB Device mode related macros and enums. This module contains macros and enums which are used when
+ * the USB controller is initialized in device mode.
+ *
+ * @{
+ */
+
+#ifndef __USBDEVICE_H__
+#define __USBDEVICE_H__
+
+ /* Includes: */
+ #include <avr/pgmspace.h>
+ #include <avr/eeprom.h>
+
+ #include "../../../Common/Common.h"
+ #include "../HighLevel/StdDescriptors.h"
+ #include "Endpoint.h"
+
+ /* Preprocessor Checks: */
+ #if (defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS))
+ #error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
+ #endif
+
+ #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__)
+ /** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
+ * USB interface should be initialized in low speed (1.5Mb/s) mode.
+ *
+ * \note Low Speed mode is not available on all USB AVR models.
+ * \n\n
+ *
+ * \note Restrictions apply on the number, size and type of endpoints which can be used
+ * when running in low speed mode -- refer to the USB 2.0 standard.
+ */
+ #define USB_DEVICE_OPT_LOWSPEED (1 << 0)
+ #endif
+
+ /** Mask for the Options parameter of the USB_Init() function. This indicates that the
+ * USB interface should be initialized in full speed (12Mb/s) mode.
+ */
+ #define USB_DEVICE_OPT_FULLSPEED (0 << 0)
+
+ /* Pseudo-Function Macros: */
+ #if defined(__DOXYGEN__)
+ /** Sends a Remote Wakeup request to the host. This signals to the host that the device should
+ * be taken out of suspended mode, and communications should resume.
+ *
+ * Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
+ * host computer when the host has suspended all USB devices to enter a low power state.
+ *
+ * \note This macro should only be used if the device has indicated to the host that it
+ * supports the Remote Wakeup feature in the device descriptors, and should only be
+ * issued if the host is currently allowing remote wakeup events from the device (i.e.,
+ * the \ref USB_RemoteWakeupEnabled flag is set). When the NO_DEVICE_REMOTE_WAKEUP compile
+ * time option is used, this macro is unavailable.
+ *
+ * \see \ref Group_Descriptors for more information on the RMWAKEUP feature and device descriptors.
+ */
+ static inline void USB_Device_SendRemoteWakeup(void);
+
+ /** Indicates if a Remote Wakeup request is being sent to the host. This returns true if a
+ * remote wakeup is currently being sent, false otherwise.
+ *
+ * This can be used in conjunction with the \ref USB_Device_IsUSBSuspended() macro to determine if
+ * a sent RMWAKEUP request was accepted or rejected by the host.
+ *
+ * \note This macro should only be used if the device has indicated to the host that it
+ * supports the Remote Wakeup feature in the device descriptors. When the NO_DEVICE_REMOTE_WAKEUP
+ * compile time option is used, this macro is unavailable.
+ *
+ * \see \ref Group_Descriptors for more information on the RMWAKEUP feature and device descriptors.
+ *
+ * \return Boolean true if no Remote Wakeup request is currently being sent, false otherwise
+ */
+ static inline bool USB_Device_IsRemoteWakeupSent(void);
+
+ /** Indicates if the device is currently suspended by the host. Whilst suspended, the device is
+ * to enter a low power state until resumed by the host. No USB traffic to or from the device
+ * can occur (except for Remote Wakeup requests) during suspension by the host.
+ *
+ * \return Boolean true if the USB communications have been suspended by the host, false otherwise.
+ */
+ static inline bool USB_Device_IsUSBSuspended(void);
+
+ /** 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,
+ * at the start of each USB frame when enumerated in device mode.
+ */
+ static inline bool USB_Device_EnableSOFEvents(void);
+
+ /** Disables the device mode Start Of Frame events. When disabled, this stop the firing of the
+ * \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.
+ */
+ static inline bool USB_Device_DisableSOFEvents(void);
+ #else
+ #if !defined(NO_DEVICE_REMOTE_WAKEUP)
+ #define USB_Device_SendRemoteWakeup() MACROS{ UDCON |= (1 << RMWKUP); }MACROE
+
+ #define USB_Device_IsRemoteWakeupSent() ((UDCON & (1 << RMWKUP)) ? false : true)
+ #endif
+
+ #define USB_Device_IsUSBSuspended() ((UDINT & (1 << SUSPI)) ? true : false)
+
+ #define USB_Device_EnableSOFEvents() MACROS{ USB_INT_Enable(USB_INT_SOFI); }MACROE
+
+ #define USB_Device_DisableSOFEvents() MACROS{ USB_INT_Disable(USB_INT_SOFI); }MACROE
+ #endif
+
+ /* Type Defines: */
+ enum USB_Device_States_t
+ {
+ DEVICE_STATE_Unattached = 0, /**< Internally implemented by the library. This state indicates
+ * that the device is not currently connected to a host.
+ */
+ DEVICE_STATE_Powered = 1, /**< Internally implemented by the library. This state indicates
+ * that the device is connected to a host, but enumeration has not
+ * yet begun.
+ */
+ DEVICE_STATE_Default = 2, /**< Internally implemented by the library. This state indicates
+ * that the device's USB bus has been reset by the host and it is
+ * now waiting for the host to begin the enumeration process.
+ */
+ DEVICE_STATE_Addressed = 3, /**< Internally implemented by the library. This state indicates
+ * that the device has been addressed by the USB Host, but is not
+ * yet configured.
+ */
+ DEVICE_STATE_Configured = 4, /**< May be implemented by the user project. This state indicates
+ * that the device has been enumerated by the host and is ready
+ * for USB communications to begin.
+ */
+ DEVICE_STATE_Suspended = 5, /**< May be implemented by the user project. This state indicates
+ * that the USB bus has been suspended by the host, and the device
+ * should power down to a minimal power level until the bus is
+ * resumed.
+ */
+ };
+
+ /* 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
+ * 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
+ * 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.
+ * \param[in] wIndex The language ID of the string to return if the wValue type indicates DTYPE_String,
+ * otherwise zero for standard descriptors, or as defined in a class-specific
+ * standards.
+ * \param[out] DescriptorAddress Pointer to the descriptor in memory. This should be set by the routine to
+ * the address of the descriptor.
+ * \param[out] MemoryAddressSpace A value from the \ref USB_DescriptorMemorySpaces_t enum to indicate the memory
+ * space in which the descriptor is stored. This parameter does not exist when one
+ * of the USE_*_DESCRIPTORS compile time options is used.
+ *
+ * \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
+ * USE_EEPROM_DESCRIPTORS tokens may be defined in the project makefile and passed to the compiler by the -D
+ * switch.
+ *
+ * \return Size in bytes of the descriptor if it exists, zero or \ref NO_DESCRIPTOR otherwise
+ */
+ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress
+ #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS)
+ , uint8_t* MemoryAddressSpace
+ #endif
+ )
+ ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
+
+ /* 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
+ #endif
+
+#endif
+
+/** @} */
diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.c b/LUFA/Drivers/USB/LowLevel/Endpoint.c
index 5560c8092..c704ac7c5 100644
--- a/LUFA/Drivers/USB/LowLevel/Endpoint.c
+++ b/LUFA/Drivers/USB/LowLevel/Endpoint.c
@@ -1,338 +1,338 @@
-/*
- 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_ENDPOINT_C
-#include "Endpoint.h"
-
-#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
-uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
-#endif
-
-uint8_t Endpoint_BytesToEPSizeMaskDynamic(const uint16_t Size)
-{
- return Endpoint_BytesToEPSizeMask(Size);
-}
-
-bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number, const uint8_t UECFG0XData, const uint8_t UECFG1XData)
-{
- Endpoint_SelectEndpoint(Number);
- Endpoint_EnableEndpoint();
-
- UECFG1X = 0;
-
- UECFG0X = UECFG0XData;
- UECFG1X = UECFG1XData;
-
- return Endpoint_IsConfigured();
-}
-
-void Endpoint_ClearEndpoints(void)
-{
- UEINT = 0;
-
- for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++)
- {
- Endpoint_SelectEndpoint(EPNum);
- UEIENX = 0;
- UEINTX = 0;
- Endpoint_DeallocateMemory();
- Endpoint_DisableEndpoint();
- }
-}
-
-void Endpoint_ClearStatusStage(void)
-{
- if (USB_ControlRequest.bmRequestType & REQDIR_DEVICETOHOST)
- {
- while (!(Endpoint_IsOUTReceived()))
- {
- if (USB_DeviceState == DEVICE_STATE_Unattached)
- return;
- }
-
- Endpoint_ClearOUT();
- }
- else
- {
- while (!(Endpoint_IsINReady()))
- {
- if (USB_DeviceState == DEVICE_STATE_Unattached)
- return;
- }
-
- Endpoint_ClearIN();
- }
-}
-
-#if !defined(CONTROL_ONLY_DEVICE)
-uint8_t Endpoint_WaitUntilReady(void)
-{
- #if (USB_STREAM_TIMEOUT_MS < 0xFF)
- uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
- #else
- uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
- #endif
-
- for (;;)
- {
- if (Endpoint_GetEndpointDirection() == ENDPOINT_DIR_IN)
- {
- if (Endpoint_IsINReady())
- return ENDPOINT_READYWAIT_NoError;
- }
- else
- {
- if (Endpoint_IsOUTReceived())
- return ENDPOINT_READYWAIT_NoError;
- }
-
- if (USB_DeviceState == DEVICE_STATE_Unattached)
- return ENDPOINT_READYWAIT_DeviceDisconnected;
- else if (USB_DeviceState == DEVICE_STATE_Suspended)
- return ENDPOINT_READYWAIT_BusSuspended;
- else if (Endpoint_IsStalled())
- return ENDPOINT_READYWAIT_EndpointStalled;
-
- if (USB_INT_HasOccurred(USB_INT_SOFI))
- {
- USB_INT_Clear(USB_INT_SOFI);
-
- if (!(TimeoutMSRem--))
- return ENDPOINT_READYWAIT_Timeout;
- }
- }
-}
-
-uint8_t Endpoint_Discard_Stream(uint16_t Length
-#if !defined(NO_STREAM_CALLBACKS)
- , StreamCallbackPtr_t Callback
-#endif
- )
-{
- uint8_t ErrorCode;
-
- if ((ErrorCode = Endpoint_WaitUntilReady()))
- return ErrorCode;
-
- #if defined(FAST_STREAM_TRANSFERS)
- uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07);
-
- if (Length >= 8)
- {
- Length -= BytesRemToAlignment;
-
- switch (BytesRemToAlignment)
- {
- default:
- do
- {
- if (!(Endpoint_IsReadWriteAllowed()))
- {
- Endpoint_ClearOUT();
-
- #if !defined(NO_STREAM_CALLBACKS)
- if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
- return ENDPOINT_RWSTREAM_CallbackAborted;
- #endif
-
- if ((ErrorCode = Endpoint_WaitUntilReady()))
- return ErrorCode;
- }
-
- Length -= 8;
-
- Endpoint_Discard_Byte();
- case 7: Endpoint_Discard_Byte();
- case 6: Endpoint_Discard_Byte();
- case 5: Endpoint_Discard_Byte();
- case 4: Endpoint_Discard_Byte();
- case 3: Endpoint_Discard_Byte();
- case 2: Endpoint_Discard_Byte();
- case 1: Endpoint_Discard_Byte();
- } while (Length >= 8);
- }
- }
- #endif
-
- while (Length)
- {
- if (!(Endpoint_IsReadWriteAllowed()))
- {
- Endpoint_ClearOUT();
-
- #if !defined(NO_STREAM_CALLBACKS)
- if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
- return ENDPOINT_RWSTREAM_CallbackAborted;
- #endif
-
- if ((ErrorCode = Endpoint_WaitUntilReady()))
- return ErrorCode;
- }
- else
- {
- Endpoint_Discard_Byte();
- Length--;
- }
- }
-
- return ENDPOINT_RWSTREAM_NoError;
-}
-
-/* The following abuses the C preprocessor in order to copy-past common code with slight alterations,
- * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */
-
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE
-#define TEMPLATE_BUFFER_TYPE const void*
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr++))
-#include "Template/Template_Endpoint_RW.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE
-#define TEMPLATE_BUFFER_TYPE const void*
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
-#include "Template/Template_Endpoint_RW.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE
-#define TEMPLATE_BUFFER_TYPE const void*
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
-#include "Template/Template_Endpoint_RW.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE
-#define TEMPLATE_BUFFER_TYPE const void*
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr--))
-#include "Template/Template_Endpoint_RW.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE
-#define TEMPLATE_BUFFER_TYPE const void*
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
-#include "Template/Template_Endpoint_RW.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE
-#define TEMPLATE_BUFFER_TYPE const void*
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
-#include "Template/Template_Endpoint_RW.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE
-#define TEMPLATE_BUFFER_TYPE void*
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte()
-#include "Template/Template_Endpoint_RW.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE
-#define TEMPLATE_BUFFER_TYPE void*
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte())
-#include "Template/Template_Endpoint_RW.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE
-#define TEMPLATE_BUFFER_TYPE void*
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte()
-#include "Template/Template_Endpoint_RW.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE
-#define TEMPLATE_BUFFER_TYPE void*
-#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte())
-#include "Template/Template_Endpoint_RW.c"
-
-#endif
-
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr++))
-#include "Template/Template_Endpoint_Control_W.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
-#include "Template/Template_Endpoint_Control_W.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
-#include "Template/Template_Endpoint_Control_W.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr--))
-#include "Template/Template_Endpoint_Control_W.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
-#include "Template/Template_Endpoint_Control_W.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
-#include "Template/Template_Endpoint_Control_W.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte()
-#include "Template/Template_Endpoint_Control_R.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte())
-#include "Template/Template_Endpoint_Control_R.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte()
-#include "Template/Template_Endpoint_Control_R.c"
-
-#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte())
-#include "Template/Template_Endpoint_Control_R.c"
-
-#endif
+/*
+ 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_ENDPOINT_C
+#include "Endpoint.h"
+
+#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
+uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
+#endif
+
+uint8_t Endpoint_BytesToEPSizeMaskDynamic(const uint16_t Size)
+{
+ return Endpoint_BytesToEPSizeMask(Size);
+}
+
+bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number, const uint8_t UECFG0XData, const uint8_t UECFG1XData)
+{
+ Endpoint_SelectEndpoint(Number);
+ Endpoint_EnableEndpoint();
+
+ UECFG1X = 0;
+
+ UECFG0X = UECFG0XData;
+ UECFG1X = UECFG1XData;
+
+ return Endpoint_IsConfigured();
+}
+
+void Endpoint_ClearEndpoints(void)
+{
+ UEINT = 0;
+
+ for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++)
+ {
+ Endpoint_SelectEndpoint(EPNum);
+ UEIENX = 0;
+ UEINTX = 0;
+ Endpoint_DeallocateMemory();
+ Endpoint_DisableEndpoint();
+ }
+}
+
+void Endpoint_ClearStatusStage(void)
+{
+ if (USB_ControlRequest.bmRequestType & REQDIR_DEVICETOHOST)
+ {
+ while (!(Endpoint_IsOUTReceived()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
+
+ Endpoint_ClearOUT();
+ }
+ else
+ {
+ while (!(Endpoint_IsINReady()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return;
+ }
+
+ Endpoint_ClearIN();
+ }
+}
+
+#if !defined(CONTROL_ONLY_DEVICE)
+uint8_t Endpoint_WaitUntilReady(void)
+{
+ #if (USB_STREAM_TIMEOUT_MS < 0xFF)
+ uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
+ #else
+ uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
+ #endif
+
+ for (;;)
+ {
+ if (Endpoint_GetEndpointDirection() == ENDPOINT_DIR_IN)
+ {
+ if (Endpoint_IsINReady())
+ return ENDPOINT_READYWAIT_NoError;
+ }
+ else
+ {
+ if (Endpoint_IsOUTReceived())
+ return ENDPOINT_READYWAIT_NoError;
+ }
+
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return ENDPOINT_READYWAIT_DeviceDisconnected;
+ else if (USB_DeviceState == DEVICE_STATE_Suspended)
+ return ENDPOINT_READYWAIT_BusSuspended;
+ else if (Endpoint_IsStalled())
+ return ENDPOINT_READYWAIT_EndpointStalled;
+
+ if (USB_INT_HasOccurred(USB_INT_SOFI))
+ {
+ USB_INT_Clear(USB_INT_SOFI);
+
+ if (!(TimeoutMSRem--))
+ return ENDPOINT_READYWAIT_Timeout;
+ }
+ }
+}
+
+uint8_t Endpoint_Discard_Stream(uint16_t Length
+#if !defined(NO_STREAM_CALLBACKS)
+ , StreamCallbackPtr_t Callback
+#endif
+ )
+{
+ uint8_t ErrorCode;
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+
+ #if defined(FAST_STREAM_TRANSFERS)
+ uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07);
+
+ if (Length >= 8)
+ {
+ Length -= BytesRemToAlignment;
+
+ switch (BytesRemToAlignment)
+ {
+ default:
+ do
+ {
+ if (!(Endpoint_IsReadWriteAllowed()))
+ {
+ Endpoint_ClearOUT();
+
+ #if !defined(NO_STREAM_CALLBACKS)
+ if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
+ return ENDPOINT_RWSTREAM_CallbackAborted;
+ #endif
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+ }
+
+ Length -= 8;
+
+ Endpoint_Discard_Byte();
+ case 7: Endpoint_Discard_Byte();
+ case 6: Endpoint_Discard_Byte();
+ case 5: Endpoint_Discard_Byte();
+ case 4: Endpoint_Discard_Byte();
+ case 3: Endpoint_Discard_Byte();
+ case 2: Endpoint_Discard_Byte();
+ case 1: Endpoint_Discard_Byte();
+ } while (Length >= 8);
+ }
+ }
+ #endif
+
+ while (Length)
+ {
+ if (!(Endpoint_IsReadWriteAllowed()))
+ {
+ Endpoint_ClearOUT();
+
+ #if !defined(NO_STREAM_CALLBACKS)
+ if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
+ return ENDPOINT_RWSTREAM_CallbackAborted;
+ #endif
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+ }
+ else
+ {
+ Endpoint_Discard_Byte();
+ Length--;
+ }
+ }
+
+ return ENDPOINT_RWSTREAM_NoError;
+}
+
+/* The following abuses the C preprocessor in order to copy-past common code with slight alterations,
+ * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr++))
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr--))
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte()
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte())
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte()
+#include "Template/Template_Endpoint_RW.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte())
+#include "Template/Template_Endpoint_RW.c"
+
+#endif
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr++))
+#include "Template/Template_Endpoint_Control_W.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
+#include "Template/Template_Endpoint_Control_W.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
+#include "Template/Template_Endpoint_Control_W.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr--))
+#include "Template/Template_Endpoint_Control_W.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
+#include "Template/Template_Endpoint_Control_W.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
+#include "Template/Template_Endpoint_Control_W.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte()
+#include "Template/Template_Endpoint_Control_R.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte())
+#include "Template/Template_Endpoint_Control_R.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte()
+#include "Template/Template_Endpoint_Control_R.c"
+
+#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte())
+#include "Template/Template_Endpoint_Control_R.c"
+
+#endif
diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.h b/LUFA/Drivers/USB/LowLevel/Endpoint.h
index 93412f500..68413b819 100644
--- a/LUFA/Drivers/USB/LowLevel/Endpoint.h
+++ b/LUFA/Drivers/USB/LowLevel/Endpoint.h
@@ -1,1264 +1,1264 @@
-/*
- 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 endpoint management definitions.
- *
- * This file contains structures, function prototypes and macros related to the management of the device's
- * data endpoints when the library is initialized 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.
- */
-
-/** \ingroup Group_USB
- * @defgroup Group_EndpointManagement Endpoint Management
- *
- * Functions, macros and enums related to endpoint management when in USB Device mode. This
- * module contains the endpoint management macros, as well as endpoint interrupt and data
- * send/receive functions for various data types.
- *
- * @{
- */
-
-/** @defgroup Group_EndpointRW Endpoint Data Reading and Writing
- *
- * 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_EndpointRW
- * @defgroup Group_EndpointStreamRW Read/Write of Multi-Byte Streams
- *
- * Functions, macros, variables, enums and types related to data reading and writing of data streams from
- * and to endpoints.
- */
-
-/** @defgroup Group_EndpointPacketManagement Endpoint Packet Management
- *
- * Functions, macros, variables, enums and types related to packet management of endpoints.
- */
-
-#ifndef __ENDPOINT_H__
-#define __ENDPOINT_H__
-
- /* Includes: */
- #include <avr/io.h>
- #include <avr/pgmspace.h>
- #include <avr/eeprom.h>
- #include <stdbool.h>
-
- #include "../../../Common/Common.h"
- #include "../HighLevel/USBTask.h"
-
- #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
- #include "../HighLevel/StreamCallbacks.h"
- #endif
-
- /* 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: */
- /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
- * should be initialized in the OUT direction - i.e. data flows from host to device.
- */
- #define ENDPOINT_DIR_OUT (0 << EPDIR)
-
- /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
- * should be initialized in the IN direction - i.e. data flows from device to host.
- */
- #define ENDPOINT_DIR_IN (1 << EPDIR)
-
- /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
- * that the endpoint should have one single bank, which requires less USB FIFO memory but results
- * in slower transfers as only one USB device (the AVR or the host) can access the endpoint's
- * bank at the one time.
- */
- #define ENDPOINT_BANK_SINGLE (0 << EPBK0)
-
- /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
- * that the endpoint should have two banks, which requires more USB FIFO memory but results
- * in faster transfers as one USB device (the AVR or the host) can access one bank while the other
- * 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 Endpoint0Size 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.
- */
- #define ENDPOINT_EPNUM_MASK 0x07
-
- /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
- * direction for comparing with the ENDPOINT_DESCRIPTOR_DIR_* masks.
- */
- #define ENDPOINT_EPDIR_MASK 0x80
-
- /** Endpoint bank size mask, for masking against endpoint addresses to retrieve the endpoint's
- * bank size in the device.
- */
- #define ENDPOINT_EPSIZE_MASK 0x7FF
-
- /** Maximum size in bytes of a given endpoint.
- *
- * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1)
- */
- #define ENDPOINT_MAX_SIZE(n) _ENDPOINT_GET_MAXSIZE(n)
-
- /** Indicates if the given endpoint supports double banking.
- *
- * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1)
- */
- #define ENDPOINT_DOUBLEBANK_SUPPORTED(n) _ENDPOINT_GET_DOUBLEBANK(n)
-
- #if !defined(CONTROL_ONLY_DEVICE)
- #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
- /** Total number of endpoints (including the default control endpoint at address 0) which may
- * be used in the device. Different USB AVR models support different amounts of endpoints,
- * this value reflects the maximum number of endpoints for the currently selected AVR model.
- */
- #define ENDPOINT_TOTAL_ENDPOINTS 7
- #else
- #define ENDPOINT_TOTAL_ENDPOINTS 5
- #endif
- #else
- #define ENDPOINT_TOTAL_ENDPOINTS 1
- #endif
-
- /* Pseudo-Function Macros: */
- #if defined(__DOXYGEN__)
- /** Indicates the number of bytes currently stored in the current endpoint's selected bank.
- *
- * \note The return width of this function may differ, depending on the maximum endpoint bank size
- * of the selected AVR model.
- *
- * \ingroup Group_EndpointRW
- *
- * \return Total number of bytes in the currently selected Endpoint's FIFO buffer
- */
- static inline uint16_t Endpoint_BytesInEndpoint(void);
-
- /** 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.
- *
- * \return Index of the currently selected endpoint
- */
- static inline uint8_t Endpoint_GetCurrentEndpoint(void);
-
- /** 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).
- *
- * Any endpoint operations which do not require the endpoint number to be indicated will operate on
- * the currently selected endpoint.
- *
- * \param[in] EndpointNumber Endpoint number to select
- */
- static inline void Endpoint_SelectEndpoint(uint8_t EndpointNumber);
-
- /** 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.
- *
- * \param[in] EndpointNumber Endpoint number whose FIFO buffers are to be reset
- */
- static inline void Endpoint_ResetFIFO(uint8_t EndpointNumber);
-
- /** Enables the currently selected endpoint so that data can be sent and received through it to
- * and from a host.
- *
- * \note Endpoints must first be configured properly via \ref Endpoint_ConfigureEndpoint().
- */
- static inline void Endpoint_EnableEndpoint(void);
-
- /** Disables the currently selected endpoint so that data cannot be sent and received through it
- * to and from a host.
- */
- static inline void Endpoint_DisableEndpoint(void);
-
- /** Determines if the currently selected endpoint is enabled, but not necessarily configured.
- *
- * \return Boolean True if the currently selected endpoint is enabled, false otherwise
- */
- static inline bool Endpoint_IsEnabled(void);
-
- /** 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
- * is an OUT direction and no packet (or an empty packet) has been received, or if the endpoint is an IN
- * direction and the endpoint bank is full.
- *
- * \ingroup Group_EndpointPacketManagement
- *
- * \return Boolean true if the currently selected endpoint may be read from or written to, depending on its direction
- */
- static inline bool Endpoint_IsReadWriteAllowed(void);
-
- /** Determines if the currently selected endpoint is configured.
- *
- * \return Boolean true if the currently selected endpoint has been configured, false otherwise
- */
- static inline bool Endpoint_IsConfigured(void);
-
- /** 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}).
- *
- * \return Mask whose bits indicate which endpoints have interrupted
- */
- static inline uint8_t Endpoint_GetEndpointInterrupts(void);
-
- /** Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type
- * endpoints).
- *
- * \param[in] EndpointNumber Index of the endpoint whose interrupt flag should be tested
- *
- * \return Boolean true if the specified endpoint has interrupted, false otherwise
- */
- static inline bool Endpoint_HasEndpointInterrupted(uint8_t EndpointNumber);
-
- /** Determines if the selected IN endpoint is ready for a new packet.
- *
- * \ingroup Group_EndpointPacketManagement
- *
- * \return Boolean true if the current endpoint is ready for an IN packet, false otherwise.
- */
- static inline bool Endpoint_IsINReady(void);
-
- /** Determines if the selected OUT endpoint has received new packet.
- *
- * \ingroup Group_EndpointPacketManagement
- *
- * \return Boolean true if current endpoint is has received an OUT packet, false otherwise.
- */
- static inline bool Endpoint_IsOUTReceived(void);
-
- /** Determines if the current CONTROL type endpoint has received a SETUP packet.
- *
- * \ingroup Group_EndpointPacketManagement
- *
- * \return Boolean true if the selected endpoint has received a SETUP packet, false otherwise.
- */
- static inline bool Endpoint_IsSETUPReceived(void);
-
- /** 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.
- */
- static inline void Endpoint_ClearSETUP(void);
-
- /** 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.
- *
- * \ingroup Group_EndpointPacketManagement
- */
- static inline void Endpoint_ClearIN(void);
-
- /** 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.
- *
- * \ingroup Group_EndpointPacketManagement
- */
- static inline void Endpoint_ClearOUT(void);
-
- /** 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
- * aborted and the host can begin its own recovery sequence.
- *
- * The currently selected endpoint remains stalled until either the \ref Endpoint_ClearStall() macro
- * is called, or the host issues a CLEAR FEATURE request to the device for the currently selected
- * endpoint.
- *
- * \ingroup Group_EndpointPacketManagement
- */
- static inline void Endpoint_StallTransaction(void);
-
- /** Clears the STALL condition on the currently selected endpoint.
- *
- * \ingroup Group_EndpointPacketManagement
- */
- static inline void Endpoint_ClearStall(void);
-
- /** Determines if the currently selected endpoint is stalled, false otherwise.
- *
- * \ingroup Group_EndpointPacketManagement
- *
- * \return Boolean true if the currently selected endpoint is stalled, false otherwise
- */
- static inline bool Endpoint_IsStalled(void);
-
- /** Resets the data toggle of the currently selected endpoint. */
- static inline void Endpoint_ResetDataToggle(void);
-
- /** Determines the currently selected endpoint's direction.
- *
- * \return The currently selected endpoint's direction, as a ENDPOINT_DIR_* mask.
- */
- static inline uint8_t Endpoint_GetEndpointDirection(void);
-
- /** Sets the direction of the currently selected endpoint.
- *
- * \param[in] DirectionMask New endpoint direction, as a ENDPOINT_DIR_* mask.
- */
- static inline void Endpoint_SetEndpointDirection(uint8_t DirectionMask);
- #else
- #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
- #define Endpoint_BytesInEndpoint() UEBCX
- #elif defined(USB_SERIES_4_AVR)
- #define Endpoint_BytesInEndpoint() (((uint16_t)UEBCHX << 8) | UEBCLX)
- #elif defined(USB_SERIES_2_AVR)
- #define Endpoint_BytesInEndpoint() UEBCLX
- #endif
-
- #if !defined(CONTROL_ONLY_DEVICE)
- #define Endpoint_GetCurrentEndpoint() (UENUM & ENDPOINT_EPNUM_MASK)
- #else
- #define Endpoint_GetCurrentEndpoint() ENDPOINT_CONTROLEP
- #endif
-
- #if !defined(CONTROL_ONLY_DEVICE)
- #define Endpoint_SelectEndpoint(epnum) MACROS{ UENUM = (epnum); }MACROE
- #else
- #define Endpoint_SelectEndpoint(epnum) (void)(epnum)
- #endif
-
- #define Endpoint_ResetFIFO(epnum) MACROS{ UERST = (1 << (epnum)); UERST = 0; }MACROE
-
- #define Endpoint_EnableEndpoint() MACROS{ UECONX |= (1 << EPEN); }MACROE
-
- #define Endpoint_DisableEndpoint() MACROS{ UECONX &= ~(1 << EPEN); }MACROE
-
- #define Endpoint_IsEnabled() ((UECONX & (1 << EPEN)) ? true : false)
-
- #if !defined(CONTROL_ONLY_DEVICE)
- #define Endpoint_IsReadWriteAllowed() ((UEINTX & (1 << RWAL)) ? true : false)
- #endif
-
- #define Endpoint_IsConfigured() ((UESTA0X & (1 << CFGOK)) ? true : false)
-
- #define Endpoint_GetEndpointInterrupts() UEINT
-
- #define Endpoint_HasEndpointInterrupted(n) ((UEINT & (1 << (n))) ? true : false)
-
- #define Endpoint_IsINReady() ((UEINTX & (1 << TXINI)) ? true : false)
-
- #define Endpoint_IsOUTReceived() ((UEINTX & (1 << RXOUTI)) ? true : false)
-
- #define Endpoint_IsSETUPReceived() ((UEINTX & (1 << RXSTPI)) ? true : false)
-
- #define Endpoint_ClearSETUP() MACROS{ UEINTX &= ~(1 << RXSTPI); }MACROE
-
- #if !defined(CONTROL_ONLY_DEVICE)
- #define Endpoint_ClearIN() MACROS{ UEINTX &= ~((1 << TXINI) | (1 << FIFOCON)); }MACROE
- #else
- #define Endpoint_ClearIN() MACROS{ UEINTX &= ~(1 << TXINI); }MACROE
- #endif
-
- #if !defined(CONTROL_ONLY_DEVICE)
- #define Endpoint_ClearOUT() MACROS{ UEINTX &= ~((1 << RXOUTI) | (1 << FIFOCON)); }MACROE
- #else
- #define Endpoint_ClearOUT() MACROS{ UEINTX &= ~(1 << RXOUTI); }MACROE
- #endif
-
- #define Endpoint_StallTransaction() MACROS{ UECONX |= (1 << STALLRQ); }MACROE
-
- #define Endpoint_ClearStall() MACROS{ UECONX |= (1 << STALLRQC); }MACROE
-
- #define Endpoint_IsStalled() ((UECONX & (1 << STALLRQ)) ? true : false)
-
- #define Endpoint_ResetDataToggle() MACROS{ UECONX |= (1 << RSTDT); }MACROE
-
- #define Endpoint_GetEndpointDirection() (UECFG0X & ENDPOINT_DIR_IN)
-
- #define Endpoint_SetEndpointDirection(dir) MACROS{ UECFG0X = ((UECFG0X & ~ENDPOINT_DIR_IN) | (dir)); }MACROE
- #endif
-
- /* Enums: */
- /** Enum for the possible error return codes of the \ref Endpoint_WaitUntilReady() function.
- *
- * \ingroup Group_EndpointRW
- */
- enum Endpoint_WaitUntilReady_ErrorCodes_t
- {
- ENDPOINT_READYWAIT_NoError = 0, /**< Endpoint is ready for next packet, no error. */
- ENDPOINT_READYWAIT_EndpointStalled = 1, /**< The endpoint was stalled during the stream
- * transfer by the host or device.
- */
- ENDPOINT_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while
- * waiting for the endpoint to become ready.
- */
- ENDPOINT_READYWAIT_BusSuspended = 3, /**< The USB bus has been suspended by the host and
- * no USB endpoint traffic can occur until the bus
- * has resumed.
- */
- ENDPOINT_READYWAIT_Timeout = 4, /**< The host failed to accept or send the next packet
- * within the software timeout period set by the
- * \ref USB_STREAM_TIMEOUT_MS macro.
- */
- };
-
- /** Enum for the possible error return codes of the Endpoint_*_Stream_* functions.
- *
- * \ingroup Group_EndpointStreamRW
- */
- enum Endpoint_Stream_RW_ErrorCodes_t
- {
- ENDPOINT_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
- ENDPOINT_RWSTREAM_EndpointStalled = 1, /**< The endpoint was stalled during the stream
- * transfer by the host or device.
- */
- ENDPOINT_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
- * the transfer.
- */
- ENDPOINT_RWSTREAM_BusSuspended = 3, /**< The USB bus has been suspended by the host and
- * no USB endpoint traffic can occur until the bus
- * has resumed.
- */
- ENDPOINT_RWSTREAM_Timeout = 4, /**< The host failed to accept or send the next packet
- * within the software timeout period set by the
- * \ref USB_STREAM_TIMEOUT_MS macro.
- */
- ENDPOINT_RWSTREAM_CallbackAborted = 5, /**< Indicates that the stream's callback function
- * aborted the transfer early.
- */
- };
-
- /** Enum for the possible error return codes of the Endpoint_*_Control_Stream_* functions..
- *
- * \ingroup Group_EndpointStreamRW
- */
- enum Endpoint_ControlStream_RW_ErrorCodes_t
- {
- ENDPOINT_RWCSTREAM_NoError = 0, /**< Command completed successfully, no error. */
- ENDPOINT_RWCSTREAM_HostAborted = 1, /**< The aborted the transfer prematurely. */
- ENDPOINT_RWCSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
- * the transfer.
- */
- ENDPOINT_RWCSTREAM_BusSuspended = 3, /**< The USB bus has been suspended by the host and
- * no USB endpoint traffic can occur until the bus
- * has resumed.
- */
- };
-
- /* Inline Functions: */
- /** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints.
- *
- * \ingroup Group_EndpointPrimitiveRW
- *
- * \return Next byte in the currently selected endpoint's FIFO buffer
- */
- static inline uint8_t Endpoint_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
- static inline uint8_t Endpoint_Read_Byte(void)
- {
- return UEDATX;
- }
-
- /** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints.
- *
- * \ingroup Group_EndpointPrimitiveRW
- *
- * \param[in] Byte Next byte to write into the the currently selected endpoint's FIFO buffer
- */
- static inline void Endpoint_Write_Byte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
- static inline void Endpoint_Write_Byte(const uint8_t Byte)
- {
- UEDATX = Byte;
- }
-
- /** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints.
- *
- * \ingroup Group_EndpointPrimitiveRW
- */
- static inline void Endpoint_Discard_Byte(void) ATTR_ALWAYS_INLINE;
- 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.
- *
- * \ingroup Group_EndpointPrimitiveRW
- *
- * \return Next word in the currently selected endpoint's FIFO buffer
- */
- static inline uint16_t Endpoint_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
- static inline uint16_t Endpoint_Read_Word_LE(void)
- {
- union
- {
- uint16_t Word;
- uint8_t Bytes[2];
- } Data;
-
- Data.Bytes[0] = UEDATX;
- Data.Bytes[1] = UEDATX;
-
- return Data.Word;
- }
-
- /** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT
- * direction endpoints.
- *
- * \ingroup Group_EndpointPrimitiveRW
- *
- * \return Next word in the currently selected endpoint's FIFO buffer
- */
- static inline uint16_t Endpoint_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
- static inline uint16_t Endpoint_Read_Word_BE(void)
- {
- union
- {
- uint16_t Word;
- uint8_t Bytes[2];
- } Data;
-
- Data.Bytes[1] = UEDATX;
- Data.Bytes[0] = UEDATX;
-
- return Data.Word;
- }
-
- /** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN
- * direction endpoints.
- *
- * \ingroup Group_EndpointPrimitiveRW
- *
- * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer
- */
- static inline void Endpoint_Write_Word_LE(const uint16_t Word) ATTR_ALWAYS_INLINE;
- static inline void Endpoint_Write_Word_LE(const uint16_t Word)
- {
- UEDATX = (Word & 0xFF);
- UEDATX = (Word >> 8);
- }
-
- /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN
- * direction endpoints.
- *
- * \ingroup Group_EndpointPrimitiveRW
- *
- * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer
- */
- static inline void Endpoint_Write_Word_BE(const uint16_t Word) ATTR_ALWAYS_INLINE;
- static inline void Endpoint_Write_Word_BE(const uint16_t Word)
- {
- UEDATX = (Word >> 8);
- UEDATX = (Word & 0xFF);
- }
-
- /** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints.
- *
- * \ingroup Group_EndpointPrimitiveRW
- */
- static inline void Endpoint_Discard_Word(void) ATTR_ALWAYS_INLINE;
- static inline void Endpoint_Discard_Word(void)
- {
- uint8_t Dummy;
-
- Dummy = UEDATX;
- Dummy = UEDATX;
- }
-
- /** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT
- * direction endpoints.
- *
- * \ingroup Group_EndpointPrimitiveRW
- *
- * \return Next double word in the currently selected endpoint's FIFO buffer
- */
- static inline uint32_t Endpoint_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
- static inline uint32_t Endpoint_Read_DWord_LE(void)
- {
- union
- {
- 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;
- }
-
- /** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT
- * direction endpoints.
- *
- * \ingroup Group_EndpointPrimitiveRW
- *
- * \return Next double word in the currently selected endpoint's FIFO buffer
- */
- static inline uint32_t Endpoint_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
- static inline uint32_t Endpoint_Read_DWord_BE(void)
- {
- union
- {
- 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;
- }
-
- /** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN
- * direction endpoints.
- *
- * \ingroup Group_EndpointPrimitiveRW
- *
- * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer
- */
- static inline void Endpoint_Write_DWord_LE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
- static inline void Endpoint_Write_DWord_LE(const uint32_t DWord)
- {
- UEDATX = (DWord & 0xFF);
- UEDATX = (DWord >> 8);
- UEDATX = (DWord >> 16);
- UEDATX = (DWord >> 24);
- }
-
- /** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN
- * direction endpoints.
- *
- * \ingroup Group_EndpointPrimitiveRW
- *
- * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer
- */
- static inline void Endpoint_Write_DWord_BE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
- static inline void Endpoint_Write_DWord_BE(const uint32_t DWord)
- {
- UEDATX = (DWord >> 24);
- UEDATX = (DWord >> 16);
- UEDATX = (DWord >> 8);
- UEDATX = (DWord & 0xFF);
- }
-
- /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints.
- *
- * \ingroup Group_EndpointPrimitiveRW
- */
- static inline void Endpoint_Discard_DWord(void) ATTR_ALWAYS_INLINE;
- static inline void Endpoint_Discard_DWord(void)
- {
- uint8_t Dummy;
-
- Dummy = UEDATX;
- Dummy = UEDATX;
- Dummy = UEDATX;
- Dummy = UEDATX;
- }
-
- /* External Variables: */
- /** Global indicating the maximum packet size of the default control endpoint located at address
- * 0 in the device. This value is set to the value indicated in the device descriptor in the user
- * project once the USB interface is initialized into device mode.
- *
- * If space is an issue, it is possible to fix this to a static value by defining the control
- * endpoint size in the FIXED_CONTROL_ENDPOINT_SIZE token passed to the compiler in the makefile
- * via the -D switch. When a fixed control endpoint size is used, the size is no longer dynamically
- * read from the descriptors at runtime and instead fixed to the given value. When used, it is
- * important that the descriptor control endpoint size value matches the size given as the
- * FIXED_CONTROL_ENDPOINT_SIZE token - it is recommended that the FIXED_CONTROL_ENDPOINT_SIZE token
- * be used in the descriptors to ensure this.
- *
- * \note This variable should be treated as read-only in the user application, and never manually
- * changed in value.
- */
- #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
- extern uint8_t USB_ControlEndpointSize;
- #else
- #define USB_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
- #endif
-
- /* Function Prototypes: */
- #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
- #define __CALLBACK_PARAM , StreamCallbackPtr_t Callback
- #else
- #define __CALLBACK_PARAM
- #endif
-
- /** Configures the specified endpoint number with the given endpoint type, direction, bank size
- * and banking mode. Endpoints should be allocated in ascending order by their address in the
- * device (i.e. endpoint 1 should be configured before endpoint 2 and so on) to prevent fragmentation
- * of the USB FIFO memory.
- *
- * The endpoint type may be one of the EP_TYPE_* macros listed in LowLevel.h and the direction
- * may be either \ref ENDPOINT_DIR_OUT or \ref ENDPOINT_DIR_IN.
- *
- * The bank size must indicate the maximum packet size that the endpoint can handle. Different
- * endpoint numbers can handle different maximum packet sizes - refer to the chosen USB AVR's
- * datasheet to determine the maximum bank size for each endpoint.
- *
- * The banking mode may be either \ref ENDPOINT_BANK_SINGLE or \ref ENDPOINT_BANK_DOUBLE.
- *
- * \note The default control endpoint does not have to be manually configured, as it is automatically
- * configured by the library internally.
- * \n\n
- *
- * \note This routine will select the specified endpoint, and the endpoint will remain selected
- * once the routine completes regardless of if the endpoint configuration succeeds.
- *
- * \return Boolean true if the configuration succeeded, false otherwise
- */
- bool Endpoint_ConfigureEndpoint(const uint8_t Number, const uint8_t Type, const uint8_t Direction,
- const uint16_t Size, const uint8_t Banks);
-
- /** Spin-loops until the currently selected non-control endpoint is ready for the next packet of data
- * to be read or written to it.
- *
- * \note This routine should not be called on CONTROL type endpoints.
- *
- * \ingroup Group_EndpointRW
- *
- * \return A value from the \ref Endpoint_WaitUntilReady_ErrorCodes_t enum.
- */
- uint8_t Endpoint_WaitUntilReady(void);
-
- /** Completes the status stage of a control transfer on a CONTROL type endpoint automatically,
- * with respect to the data direction. This is a convenience function which can be used to
- * simplify user control request handling.
- */
- void Endpoint_ClearStatusStage(void);
-
- /** Reads and discards the given number of bytes from the endpoint from the given buffer,
- * discarding fully read packets from the host as needed. The last packet is not automatically
- * discarded once the remaining bytes has been read; the user is responsible for manually
- * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
- * each USB packet, the given stream callback function is executed repeatedly until the next
- * packet is ready, allowing for early aborts of stream transfers.
- *
- * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
- * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
- * disabled and this function has the Callback parameter omitted.
- *
- * \note This routine should not be used on CONTROL type endpoints.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[in] Length Number of bytes to send via the currently selected endpoint.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Discard_Stream(uint16_t Length __CALLBACK_PARAM);
-
- /** Writes the given number of bytes to the endpoint from the given buffer in little endian,
- * sending full packets to the host as needed. The last packet filled is not automatically sent;
- * the user is responsible for manually sending the last written packet to the host via the
- * \ref Endpoint_ClearIN() macro. Between each USB packet, the given stream callback function
- * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early
- * aborts of stream transfers.
- *
- * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
- * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
- * disabled and this function has the Callback parameter omitted.
- *
- * \note This routine should not be used on CONTROL type endpoints.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE().
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Write_EStream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE().
- *
- * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Write_PStream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** Writes the given number of bytes to the endpoint from the given buffer in big endian,
- * sending full packets to the host as needed. The last packet filled is not automatically sent;
- * the user is responsible for manually sending the last written packet to the host via the
- * \ref Endpoint_ClearIN() macro. Between each USB packet, the given stream callback function
- * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early
- * aborts of stream transfers.
- *
- * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
- * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
- * disabled and this function has the Callback parameter omitted.
- *
- * \note This routine should not be used on CONTROL type endpoints.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE().
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Write_EStream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE().
- *
- * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Write_PStream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** Reads the given number of bytes from the endpoint from the given buffer in little endian,
- * discarding fully read packets from the host as needed. The last packet is not automatically
- * discarded once the remaining bytes has been read; the user is responsible for manually
- * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
- * each USB packet, the given stream callback function is executed repeatedly until the endpoint
- * is ready to accept the next packet, allowing for early aborts of stream transfers.
- *
- * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
- * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
- * disabled and this function has the Callback parameter omitted.
- *
- * \note This routine should not be used on CONTROL type endpoints.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[out] Buffer Pointer to the destination data buffer to write to.
- * \param[in] Length Number of bytes to send via the currently selected endpoint.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** EEPROM buffer source version of \ref Endpoint_Read_Stream_LE().
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
- * \param[in] Length Number of bytes to send via the currently selected endpoint.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Read_EStream_LE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** Reads the given number of bytes from the endpoint from the given buffer in big endian,
- * discarding fully read packets from the host as needed. The last packet is not automatically
- * discarded once the remaining bytes has been read; the user is responsible for manually
- * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
- * each USB packet, the given stream callback function is executed repeatedly until the endpoint
- * is ready to accept the next packet, allowing for early aborts of stream transfers.
- *
- * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
- * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
- * disabled and this function has the Callback parameter omitted.
- *
- * \note This routine should not be used on CONTROL type endpoints.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[out] Buffer Pointer to the destination data buffer to write to.
- * \param[in] Length Number of bytes to send via the currently selected endpoint.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** EEPROM buffer source version of \ref Endpoint_Read_Stream_BE().
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
- * \param[in] Length Number of bytes to send via the currently selected endpoint.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Read_EStream_BE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,
- * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
- * in both failure and success states; the user is responsible for manually clearing the setup OUT to
- * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
- *
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt
- * to clear the status stage when using this routine in a control transaction.
- * \n\n
- *
- * \note This routine should only be used on CONTROL type endpoints.
- *
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
- * together; i.e. the entire stream data must be read or written at the one time.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
- *
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
-
- /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE.
- *
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt
- * to clear the status stage when using this routine in a control transaction.
- * \n\n
- *
- * \note This routine should only be used on CONTROL type endpoints.
- *
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
- * together; i.e. the entire stream data must be read or written at the one time.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
- *
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Write_Control_EStream_LE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
-
- /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE().
- *
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt
- * to clear the status stage when using this routine in a control transaction.
- * \n\n
- *
- * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
- * \n\n
- *
- * \note This routine should only be used on CONTROL type endpoints.
- *
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
- * together; i.e. the entire stream data must be read or written at the one time.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
- *
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Write_Control_PStream_LE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
-
- /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,
- * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
- * in both failure and success states; the user is responsible for manually clearing the setup OUT to
- * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
- *
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt
- * to clear the status stage when using this routine in a control transaction.
- * \n\n
- *
- * \note This routine should only be used on CONTROL type endpoints.
- *
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
- * together; i.e. the entire stream data must be read or written at the one time.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
- *
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
-
- /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE().
- *
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt
- * to clear the status stage when using this routine in a control transaction.
- * \n\n
- *
- * \note This routine should only be used on CONTROL type endpoints.
- *
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
- * together; i.e. the entire stream data must be read or written at the one time.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
- *
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Write_Control_EStream_BE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
-
- /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE().
- *
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt
- * to clear the status stage when using this routine in a control transaction.
- * \n\n
- *
- * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
- * \n\n
- *
- * \note This routine should only be used on CONTROL type endpoints.
- *
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
- * together; i.e. the entire stream data must be read or written at the one time.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
- *
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Write_Control_PStream_BE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
-
- /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,
- * discarding fully read packets from the host as needed. The device IN acknowledgement is not
- * automatically sent after success or failure states; the user is responsible for manually sending the
- * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
- *
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt
- * to clear the status stage when using this routine in a control transaction.
- * \n\n
- *
- * \note This routine should only be used on CONTROL type endpoints.
- *
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
- * together; i.e. the entire stream data must be read or written at the one time.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[out] Buffer Pointer to the destination data buffer to write to.
- * \param[in] Length Number of bytes to send via the currently selected endpoint.
- *
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
-
- /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE().
- *
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt
- * to clear the status stage when using this routine in a control transaction.
- * \n\n
- *
- * \note This routine should only be used on CONTROL type endpoints.
- *
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
- * together; i.e. the entire stream data must be read or written at the one time.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[out] Buffer Pointer to the destination data buffer to write to.
- * \param[in] Length Number of bytes to send via the currently selected endpoint.
- *
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Read_Control_EStream_LE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
-
- /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,
- * discarding fully read packets from the host as needed. The device IN acknowledgement is not
- * automatically sent after success or failure states; the user is responsible for manually sending the
- * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
- *
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt
- * to clear the status stage when using this routine in a control transaction.
- * \n\n
- *
- * \note This routine should only be used on CONTROL type endpoints.
- *
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
- * together; i.e. the entire stream data must be read or written at the one time.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[out] Buffer Pointer to the destination data buffer to write to.
- * \param[in] Length Number of bytes to send via the currently selected endpoint.
- *
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
-
- /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE().
- *
- * \note This function automatically clears the control transfer's status stage. Do not manually attempt
- * to clear the status stage when using this routine in a control transaction.
- * \n\n
- *
- * \note This routine should only be used on CONTROL type endpoints.
- *
- * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
- * together; i.e. the entire stream data must be read or written at the one time.
- *
- * \ingroup Group_EndpointStreamRW
- *
- * \param[out] Buffer Pointer to the destination data buffer to write to.
- * \param[in] Length Number of bytes to send via the currently selected endpoint.
- *
- * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
- */
- uint8_t Endpoint_Read_Control_EStream_BE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
-
- /* Private Interface - For use in library only: */
- #if !defined(__DOXYGEN__)
- /* Macros: */
- #define Endpoint_AllocateMemory() MACROS{ UECFG1X |= (1 << ALLOC); }MACROE
- #define Endpoint_DeallocateMemory() MACROS{ UECFG1X &= ~(1 << ALLOC); }MACROE
-
- #define _ENDPOINT_GET_MAXSIZE(n) _ENDPOINT_GET_MAXSIZE2(ENDPOINT_DETAILS_EP ## n)
- #define _ENDPOINT_GET_MAXSIZE2(details) _ENDPOINT_GET_MAXSIZE3(details)
- #define _ENDPOINT_GET_MAXSIZE3(maxsize, db) maxsize
-
- #define _ENDPOINT_GET_DOUBLEBANK(n) _ENDPOINT_GET_DOUBLEBANK2(ENDPOINT_DETAILS_EP ## n)
- #define _ENDPOINT_GET_DOUBLEBANK2(details) _ENDPOINT_GET_DOUBLEBANK3(details)
- #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_EP0 64, true
- #define ENDPOINT_DETAILS_EP1 256, true
- #define ENDPOINT_DETAILS_EP2 64, true
- #define ENDPOINT_DETAILS_EP3 64, true
- #define ENDPOINT_DETAILS_EP4 64, true
- #define ENDPOINT_DETAILS_EP5 64, true
- #define ENDPOINT_DETAILS_EP6 64, true
- #else
- #define ENDPOINT_DETAILS_EP0 64, true
- #define ENDPOINT_DETAILS_EP1 64, false
- #define ENDPOINT_DETAILS_EP2 64, false
- #define ENDPOINT_DETAILS_EP3 64, true
- #define ENDPOINT_DETAILS_EP4 64, true
- #endif
-
- #define Endpoint_ConfigureEndpoint(Number, Type, Direction, Size, Banks) \
- Endpoint_ConfigureEndpoint_Prv((Number), \
- (((Type) << EPTYPE0) | (Direction)), \
- ((1 << ALLOC) | (Banks) | \
- (__builtin_constant_p(Size) ? \
- Endpoint_BytesToEPSizeMask(Size) : \
- Endpoint_BytesToEPSizeMaskDynamic(Size))))
-
- /* Function Prototypes: */
- void Endpoint_ClearEndpoints(void);
- uint8_t Endpoint_BytesToEPSizeMaskDynamic(const uint16_t Size);
- bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number, const uint8_t UECFG0XData, const uint8_t UECFG1XData);
-
- /* Inline Functions: */
- static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;
- static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes)
- {
- uint8_t MaskVal = 0;
- uint16_t CheckBytes = 8;
-
- while (CheckBytes < Bytes)
- {
- MaskVal++;
- CheckBytes <<= 1;
- }
-
- return (MaskVal << EPSIZE0);
- }
-
- #endif
-
- /* Disable C linkage for C++ Compilers: */
- #if defined(__cplusplus)
- }
- #endif
-
-#endif
-
-/** @} */
+/*
+ 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 endpoint management definitions.
+ *
+ * This file contains structures, function prototypes and macros related to the management of the device's
+ * data endpoints when the library is initialized 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.
+ */
+
+/** \ingroup Group_USB
+ * @defgroup Group_EndpointManagement Endpoint Management
+ *
+ * Functions, macros and enums related to endpoint management when in USB Device mode. This
+ * module contains the endpoint management macros, as well as endpoint interrupt and data
+ * send/receive functions for various data types.
+ *
+ * @{
+ */
+
+/** @defgroup Group_EndpointRW Endpoint Data Reading and Writing
+ *
+ * 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_EndpointRW
+ * @defgroup Group_EndpointStreamRW Read/Write of Multi-Byte Streams
+ *
+ * Functions, macros, variables, enums and types related to data reading and writing of data streams from
+ * and to endpoints.
+ */
+
+/** @defgroup Group_EndpointPacketManagement Endpoint Packet Management
+ *
+ * Functions, macros, variables, enums and types related to packet management of endpoints.
+ */
+
+#ifndef __ENDPOINT_H__
+#define __ENDPOINT_H__
+
+ /* Includes: */
+ #include <avr/io.h>
+ #include <avr/pgmspace.h>
+ #include <avr/eeprom.h>
+ #include <stdbool.h>
+
+ #include "../../../Common/Common.h"
+ #include "../HighLevel/USBTask.h"
+
+ #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
+ #include "../HighLevel/StreamCallbacks.h"
+ #endif
+
+ /* 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: */
+ /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
+ * should be initialized in the OUT direction - i.e. data flows from host to device.
+ */
+ #define ENDPOINT_DIR_OUT (0 << EPDIR)
+
+ /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
+ * should be initialized in the IN direction - i.e. data flows from device to host.
+ */
+ #define ENDPOINT_DIR_IN (1 << EPDIR)
+
+ /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
+ * that the endpoint should have one single bank, which requires less USB FIFO memory but results
+ * in slower transfers as only one USB device (the AVR or the host) can access the endpoint's
+ * bank at the one time.
+ */
+ #define ENDPOINT_BANK_SINGLE (0 << EPBK0)
+
+ /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
+ * that the endpoint should have two banks, which requires more USB FIFO memory but results
+ * in faster transfers as one USB device (the AVR or the host) can access one bank while the other
+ * 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 Endpoint0Size 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.
+ */
+ #define ENDPOINT_EPNUM_MASK 0x07
+
+ /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
+ * direction for comparing with the ENDPOINT_DESCRIPTOR_DIR_* masks.
+ */
+ #define ENDPOINT_EPDIR_MASK 0x80
+
+ /** Endpoint bank size mask, for masking against endpoint addresses to retrieve the endpoint's
+ * bank size in the device.
+ */
+ #define ENDPOINT_EPSIZE_MASK 0x7FF
+
+ /** Maximum size in bytes of a given endpoint.
+ *
+ * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1)
+ */
+ #define ENDPOINT_MAX_SIZE(n) _ENDPOINT_GET_MAXSIZE(n)
+
+ /** Indicates if the given endpoint supports double banking.
+ *
+ * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1)
+ */
+ #define ENDPOINT_DOUBLEBANK_SUPPORTED(n) _ENDPOINT_GET_DOUBLEBANK(n)
+
+ #if !defined(CONTROL_ONLY_DEVICE)
+ #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
+ /** Total number of endpoints (including the default control endpoint at address 0) which may
+ * be used in the device. Different USB AVR models support different amounts of endpoints,
+ * this value reflects the maximum number of endpoints for the currently selected AVR model.
+ */
+ #define ENDPOINT_TOTAL_ENDPOINTS 7
+ #else
+ #define ENDPOINT_TOTAL_ENDPOINTS 5
+ #endif
+ #else
+ #define ENDPOINT_TOTAL_ENDPOINTS 1
+ #endif
+
+ /* Pseudo-Function Macros: */
+ #if defined(__DOXYGEN__)
+ /** Indicates the number of bytes currently stored in the current endpoint's selected bank.
+ *
+ * \note The return width of this function may differ, depending on the maximum endpoint bank size
+ * of the selected AVR model.
+ *
+ * \ingroup Group_EndpointRW
+ *
+ * \return Total number of bytes in the currently selected Endpoint's FIFO buffer
+ */
+ static inline uint16_t Endpoint_BytesInEndpoint(void);
+
+ /** 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.
+ *
+ * \return Index of the currently selected endpoint
+ */
+ static inline uint8_t Endpoint_GetCurrentEndpoint(void);
+
+ /** 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).
+ *
+ * Any endpoint operations which do not require the endpoint number to be indicated will operate on
+ * the currently selected endpoint.
+ *
+ * \param[in] EndpointNumber Endpoint number to select
+ */
+ static inline void Endpoint_SelectEndpoint(uint8_t EndpointNumber);
+
+ /** 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.
+ *
+ * \param[in] EndpointNumber Endpoint number whose FIFO buffers are to be reset
+ */
+ static inline void Endpoint_ResetFIFO(uint8_t EndpointNumber);
+
+ /** Enables the currently selected endpoint so that data can be sent and received through it to
+ * and from a host.
+ *
+ * \note Endpoints must first be configured properly via \ref Endpoint_ConfigureEndpoint().
+ */
+ static inline void Endpoint_EnableEndpoint(void);
+
+ /** Disables the currently selected endpoint so that data cannot be sent and received through it
+ * to and from a host.
+ */
+ static inline void Endpoint_DisableEndpoint(void);
+
+ /** Determines if the currently selected endpoint is enabled, but not necessarily configured.
+ *
+ * \return Boolean True if the currently selected endpoint is enabled, false otherwise
+ */
+ static inline bool Endpoint_IsEnabled(void);
+
+ /** 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
+ * is an OUT direction and no packet (or an empty packet) has been received, or if the endpoint is an IN
+ * direction and the endpoint bank is full.
+ *
+ * \ingroup Group_EndpointPacketManagement
+ *
+ * \return Boolean true if the currently selected endpoint may be read from or written to, depending on its direction
+ */
+ static inline bool Endpoint_IsReadWriteAllowed(void);
+
+ /** Determines if the currently selected endpoint is configured.
+ *
+ * \return Boolean true if the currently selected endpoint has been configured, false otherwise
+ */
+ static inline bool Endpoint_IsConfigured(void);
+
+ /** 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}).
+ *
+ * \return Mask whose bits indicate which endpoints have interrupted
+ */
+ static inline uint8_t Endpoint_GetEndpointInterrupts(void);
+
+ /** Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type
+ * endpoints).
+ *
+ * \param[in] EndpointNumber Index of the endpoint whose interrupt flag should be tested
+ *
+ * \return Boolean true if the specified endpoint has interrupted, false otherwise
+ */
+ static inline bool Endpoint_HasEndpointInterrupted(uint8_t EndpointNumber);
+
+ /** Determines if the selected IN endpoint is ready for a new packet.
+ *
+ * \ingroup Group_EndpointPacketManagement
+ *
+ * \return Boolean true if the current endpoint is ready for an IN packet, false otherwise.
+ */
+ static inline bool Endpoint_IsINReady(void);
+
+ /** Determines if the selected OUT endpoint has received new packet.
+ *
+ * \ingroup Group_EndpointPacketManagement
+ *
+ * \return Boolean true if current endpoint is has received an OUT packet, false otherwise.
+ */
+ static inline bool Endpoint_IsOUTReceived(void);
+
+ /** Determines if the current CONTROL type endpoint has received a SETUP packet.
+ *
+ * \ingroup Group_EndpointPacketManagement
+ *
+ * \return Boolean true if the selected endpoint has received a SETUP packet, false otherwise.
+ */
+ static inline bool Endpoint_IsSETUPReceived(void);
+
+ /** 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.
+ */
+ static inline void Endpoint_ClearSETUP(void);
+
+ /** 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.
+ *
+ * \ingroup Group_EndpointPacketManagement
+ */
+ static inline void Endpoint_ClearIN(void);
+
+ /** 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.
+ *
+ * \ingroup Group_EndpointPacketManagement
+ */
+ static inline void Endpoint_ClearOUT(void);
+
+ /** 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
+ * aborted and the host can begin its own recovery sequence.
+ *
+ * The currently selected endpoint remains stalled until either the \ref Endpoint_ClearStall() macro
+ * is called, or the host issues a CLEAR FEATURE request to the device for the currently selected
+ * endpoint.
+ *
+ * \ingroup Group_EndpointPacketManagement
+ */
+ static inline void Endpoint_StallTransaction(void);
+
+ /** Clears the STALL condition on the currently selected endpoint.
+ *
+ * \ingroup Group_EndpointPacketManagement
+ */
+ static inline void Endpoint_ClearStall(void);
+
+ /** Determines if the currently selected endpoint is stalled, false otherwise.
+ *
+ * \ingroup Group_EndpointPacketManagement
+ *
+ * \return Boolean true if the currently selected endpoint is stalled, false otherwise
+ */
+ static inline bool Endpoint_IsStalled(void);
+
+ /** Resets the data toggle of the currently selected endpoint. */
+ static inline void Endpoint_ResetDataToggle(void);
+
+ /** Determines the currently selected endpoint's direction.
+ *
+ * \return The currently selected endpoint's direction, as a ENDPOINT_DIR_* mask.
+ */
+ static inline uint8_t Endpoint_GetEndpointDirection(void);
+
+ /** Sets the direction of the currently selected endpoint.
+ *
+ * \param[in] DirectionMask New endpoint direction, as a ENDPOINT_DIR_* mask.
+ */
+ static inline void Endpoint_SetEndpointDirection(uint8_t DirectionMask);
+ #else
+ #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
+ #define Endpoint_BytesInEndpoint() UEBCX
+ #elif defined(USB_SERIES_4_AVR)
+ #define Endpoint_BytesInEndpoint() (((uint16_t)UEBCHX << 8) | UEBCLX)
+ #elif defined(USB_SERIES_2_AVR)
+ #define Endpoint_BytesInEndpoint() UEBCLX
+ #endif
+
+ #if !defined(CONTROL_ONLY_DEVICE)
+ #define Endpoint_GetCurrentEndpoint() (UENUM & ENDPOINT_EPNUM_MASK)
+ #else
+ #define Endpoint_GetCurrentEndpoint() ENDPOINT_CONTROLEP
+ #endif
+
+ #if !defined(CONTROL_ONLY_DEVICE)
+ #define Endpoint_SelectEndpoint(epnum) MACROS{ UENUM = (epnum); }MACROE
+ #else
+ #define Endpoint_SelectEndpoint(epnum) (void)(epnum)
+ #endif
+
+ #define Endpoint_ResetFIFO(epnum) MACROS{ UERST = (1 << (epnum)); UERST = 0; }MACROE
+
+ #define Endpoint_EnableEndpoint() MACROS{ UECONX |= (1 << EPEN); }MACROE
+
+ #define Endpoint_DisableEndpoint() MACROS{ UECONX &= ~(1 << EPEN); }MACROE
+
+ #define Endpoint_IsEnabled() ((UECONX & (1 << EPEN)) ? true : false)
+
+ #if !defined(CONTROL_ONLY_DEVICE)
+ #define Endpoint_IsReadWriteAllowed() ((UEINTX & (1 << RWAL)) ? true : false)
+ #endif
+
+ #define Endpoint_IsConfigured() ((UESTA0X & (1 << CFGOK)) ? true : false)
+
+ #define Endpoint_GetEndpointInterrupts() UEINT
+
+ #define Endpoint_HasEndpointInterrupted(n) ((UEINT & (1 << (n))) ? true : false)
+
+ #define Endpoint_IsINReady() ((UEINTX & (1 << TXINI)) ? true : false)
+
+ #define Endpoint_IsOUTReceived() ((UEINTX & (1 << RXOUTI)) ? true : false)
+
+ #define Endpoint_IsSETUPReceived() ((UEINTX & (1 << RXSTPI)) ? true : false)
+
+ #define Endpoint_ClearSETUP() MACROS{ UEINTX &= ~(1 << RXSTPI); }MACROE
+
+ #if !defined(CONTROL_ONLY_DEVICE)
+ #define Endpoint_ClearIN() MACROS{ UEINTX &= ~((1 << TXINI) | (1 << FIFOCON)); }MACROE
+ #else
+ #define Endpoint_ClearIN() MACROS{ UEINTX &= ~(1 << TXINI); }MACROE
+ #endif
+
+ #if !defined(CONTROL_ONLY_DEVICE)
+ #define Endpoint_ClearOUT() MACROS{ UEINTX &= ~((1 << RXOUTI) | (1 << FIFOCON)); }MACROE
+ #else
+ #define Endpoint_ClearOUT() MACROS{ UEINTX &= ~(1 << RXOUTI); }MACROE
+ #endif
+
+ #define Endpoint_StallTransaction() MACROS{ UECONX |= (1 << STALLRQ); }MACROE
+
+ #define Endpoint_ClearStall() MACROS{ UECONX |= (1 << STALLRQC); }MACROE
+
+ #define Endpoint_IsStalled() ((UECONX & (1 << STALLRQ)) ? true : false)
+
+ #define Endpoint_ResetDataToggle() MACROS{ UECONX |= (1 << RSTDT); }MACROE
+
+ #define Endpoint_GetEndpointDirection() (UECFG0X & ENDPOINT_DIR_IN)
+
+ #define Endpoint_SetEndpointDirection(dir) MACROS{ UECFG0X = ((UECFG0X & ~ENDPOINT_DIR_IN) | (dir)); }MACROE
+ #endif
+
+ /* Enums: */
+ /** Enum for the possible error return codes of the \ref Endpoint_WaitUntilReady() function.
+ *
+ * \ingroup Group_EndpointRW
+ */
+ enum Endpoint_WaitUntilReady_ErrorCodes_t
+ {
+ ENDPOINT_READYWAIT_NoError = 0, /**< Endpoint is ready for next packet, no error. */
+ ENDPOINT_READYWAIT_EndpointStalled = 1, /**< The endpoint was stalled during the stream
+ * transfer by the host or device.
+ */
+ ENDPOINT_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while
+ * waiting for the endpoint to become ready.
+ */
+ ENDPOINT_READYWAIT_BusSuspended = 3, /**< The USB bus has been suspended by the host and
+ * no USB endpoint traffic can occur until the bus
+ * has resumed.
+ */
+ ENDPOINT_READYWAIT_Timeout = 4, /**< The host failed to accept or send the next packet
+ * within the software timeout period set by the
+ * \ref USB_STREAM_TIMEOUT_MS macro.
+ */
+ };
+
+ /** Enum for the possible error return codes of the Endpoint_*_Stream_* functions.
+ *
+ * \ingroup Group_EndpointStreamRW
+ */
+ enum Endpoint_Stream_RW_ErrorCodes_t
+ {
+ ENDPOINT_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
+ ENDPOINT_RWSTREAM_EndpointStalled = 1, /**< The endpoint was stalled during the stream
+ * transfer by the host or device.
+ */
+ ENDPOINT_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
+ * the transfer.
+ */
+ ENDPOINT_RWSTREAM_BusSuspended = 3, /**< The USB bus has been suspended by the host and
+ * no USB endpoint traffic can occur until the bus
+ * has resumed.
+ */
+ ENDPOINT_RWSTREAM_Timeout = 4, /**< The host failed to accept or send the next packet
+ * within the software timeout period set by the
+ * \ref USB_STREAM_TIMEOUT_MS macro.
+ */
+ ENDPOINT_RWSTREAM_CallbackAborted = 5, /**< Indicates that the stream's callback function
+ * aborted the transfer early.
+ */
+ };
+
+ /** Enum for the possible error return codes of the Endpoint_*_Control_Stream_* functions..
+ *
+ * \ingroup Group_EndpointStreamRW
+ */
+ enum Endpoint_ControlStream_RW_ErrorCodes_t
+ {
+ ENDPOINT_RWCSTREAM_NoError = 0, /**< Command completed successfully, no error. */
+ ENDPOINT_RWCSTREAM_HostAborted = 1, /**< The aborted the transfer prematurely. */
+ ENDPOINT_RWCSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
+ * the transfer.
+ */
+ ENDPOINT_RWCSTREAM_BusSuspended = 3, /**< The USB bus has been suspended by the host and
+ * no USB endpoint traffic can occur until the bus
+ * has resumed.
+ */
+ };
+
+ /* Inline Functions: */
+ /** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW
+ *
+ * \return Next byte in the currently selected endpoint's FIFO buffer
+ */
+ static inline uint8_t Endpoint_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint8_t Endpoint_Read_Byte(void)
+ {
+ return UEDATX;
+ }
+
+ /** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW
+ *
+ * \param[in] Byte Next byte to write into the the currently selected endpoint's FIFO buffer
+ */
+ static inline void Endpoint_Write_Byte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Write_Byte(const uint8_t Byte)
+ {
+ UEDATX = Byte;
+ }
+
+ /** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW
+ */
+ static inline void Endpoint_Discard_Byte(void) ATTR_ALWAYS_INLINE;
+ 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.
+ *
+ * \ingroup Group_EndpointPrimitiveRW
+ *
+ * \return Next word in the currently selected endpoint's FIFO buffer
+ */
+ static inline uint16_t Endpoint_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint16_t Endpoint_Read_Word_LE(void)
+ {
+ union
+ {
+ uint16_t Word;
+ uint8_t Bytes[2];
+ } Data;
+
+ Data.Bytes[0] = UEDATX;
+ Data.Bytes[1] = UEDATX;
+
+ return Data.Word;
+ }
+
+ /** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW
+ *
+ * \return Next word in the currently selected endpoint's FIFO buffer
+ */
+ static inline uint16_t Endpoint_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint16_t Endpoint_Read_Word_BE(void)
+ {
+ union
+ {
+ uint16_t Word;
+ uint8_t Bytes[2];
+ } Data;
+
+ Data.Bytes[1] = UEDATX;
+ Data.Bytes[0] = UEDATX;
+
+ return Data.Word;
+ }
+
+ /** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW
+ *
+ * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer
+ */
+ static inline void Endpoint_Write_Word_LE(const uint16_t Word) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Write_Word_LE(const uint16_t Word)
+ {
+ UEDATX = (Word & 0xFF);
+ UEDATX = (Word >> 8);
+ }
+
+ /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW
+ *
+ * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer
+ */
+ static inline void Endpoint_Write_Word_BE(const uint16_t Word) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Write_Word_BE(const uint16_t Word)
+ {
+ UEDATX = (Word >> 8);
+ UEDATX = (Word & 0xFF);
+ }
+
+ /** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW
+ */
+ static inline void Endpoint_Discard_Word(void) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Discard_Word(void)
+ {
+ uint8_t Dummy;
+
+ Dummy = UEDATX;
+ Dummy = UEDATX;
+ }
+
+ /** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW
+ *
+ * \return Next double word in the currently selected endpoint's FIFO buffer
+ */
+ static inline uint32_t Endpoint_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint32_t Endpoint_Read_DWord_LE(void)
+ {
+ union
+ {
+ 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;
+ }
+
+ /** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW
+ *
+ * \return Next double word in the currently selected endpoint's FIFO buffer
+ */
+ static inline uint32_t Endpoint_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint32_t Endpoint_Read_DWord_BE(void)
+ {
+ union
+ {
+ 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;
+ }
+
+ /** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW
+ *
+ * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer
+ */
+ static inline void Endpoint_Write_DWord_LE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Write_DWord_LE(const uint32_t DWord)
+ {
+ UEDATX = (DWord & 0xFF);
+ UEDATX = (DWord >> 8);
+ UEDATX = (DWord >> 16);
+ UEDATX = (DWord >> 24);
+ }
+
+ /** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN
+ * direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW
+ *
+ * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer
+ */
+ static inline void Endpoint_Write_DWord_BE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Write_DWord_BE(const uint32_t DWord)
+ {
+ UEDATX = (DWord >> 24);
+ UEDATX = (DWord >> 16);
+ UEDATX = (DWord >> 8);
+ UEDATX = (DWord & 0xFF);
+ }
+
+ /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints.
+ *
+ * \ingroup Group_EndpointPrimitiveRW
+ */
+ static inline void Endpoint_Discard_DWord(void) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_Discard_DWord(void)
+ {
+ uint8_t Dummy;
+
+ Dummy = UEDATX;
+ Dummy = UEDATX;
+ Dummy = UEDATX;
+ Dummy = UEDATX;
+ }
+
+ /* External Variables: */
+ /** Global indicating the maximum packet size of the default control endpoint located at address
+ * 0 in the device. This value is set to the value indicated in the device descriptor in the user
+ * project once the USB interface is initialized into device mode.
+ *
+ * If space is an issue, it is possible to fix this to a static value by defining the control
+ * endpoint size in the FIXED_CONTROL_ENDPOINT_SIZE token passed to the compiler in the makefile
+ * via the -D switch. When a fixed control endpoint size is used, the size is no longer dynamically
+ * read from the descriptors at runtime and instead fixed to the given value. When used, it is
+ * important that the descriptor control endpoint size value matches the size given as the
+ * FIXED_CONTROL_ENDPOINT_SIZE token - it is recommended that the FIXED_CONTROL_ENDPOINT_SIZE token
+ * be used in the descriptors to ensure this.
+ *
+ * \note This variable should be treated as read-only in the user application, and never manually
+ * changed in value.
+ */
+ #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
+ extern uint8_t USB_ControlEndpointSize;
+ #else
+ #define USB_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
+ #endif
+
+ /* Function Prototypes: */
+ #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
+ #define __CALLBACK_PARAM , StreamCallbackPtr_t Callback
+ #else
+ #define __CALLBACK_PARAM
+ #endif
+
+ /** Configures the specified endpoint number with the given endpoint type, direction, bank size
+ * and banking mode. Endpoints should be allocated in ascending order by their address in the
+ * device (i.e. endpoint 1 should be configured before endpoint 2 and so on) to prevent fragmentation
+ * of the USB FIFO memory.
+ *
+ * The endpoint type may be one of the EP_TYPE_* macros listed in LowLevel.h and the direction
+ * may be either \ref ENDPOINT_DIR_OUT or \ref ENDPOINT_DIR_IN.
+ *
+ * The bank size must indicate the maximum packet size that the endpoint can handle. Different
+ * endpoint numbers can handle different maximum packet sizes - refer to the chosen USB AVR's
+ * datasheet to determine the maximum bank size for each endpoint.
+ *
+ * The banking mode may be either \ref ENDPOINT_BANK_SINGLE or \ref ENDPOINT_BANK_DOUBLE.
+ *
+ * \note The default control endpoint does not have to be manually configured, as it is automatically
+ * configured by the library internally.
+ * \n\n
+ *
+ * \note This routine will select the specified endpoint, and the endpoint will remain selected
+ * once the routine completes regardless of if the endpoint configuration succeeds.
+ *
+ * \return Boolean true if the configuration succeeded, false otherwise
+ */
+ bool Endpoint_ConfigureEndpoint(const uint8_t Number, const uint8_t Type, const uint8_t Direction,
+ const uint16_t Size, const uint8_t Banks);
+
+ /** Spin-loops until the currently selected non-control endpoint is ready for the next packet of data
+ * to be read or written to it.
+ *
+ * \note This routine should not be called on CONTROL type endpoints.
+ *
+ * \ingroup Group_EndpointRW
+ *
+ * \return A value from the \ref Endpoint_WaitUntilReady_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_WaitUntilReady(void);
+
+ /** Completes the status stage of a control transfer on a CONTROL type endpoint automatically,
+ * with respect to the data direction. This is a convenience function which can be used to
+ * simplify user control request handling.
+ */
+ void Endpoint_ClearStatusStage(void);
+
+ /** Reads and discards the given number of bytes from the endpoint from the given buffer,
+ * discarding fully read packets from the host as needed. The last packet is not automatically
+ * discarded once the remaining bytes has been read; the user is responsible for manually
+ * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
+ * each USB packet, the given stream callback function is executed repeatedly until the next
+ * packet is ready, allowing for early aborts of stream transfers.
+ *
+ * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
+ * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
+ * disabled and this function has the Callback parameter omitted.
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Discard_Stream(uint16_t Length __CALLBACK_PARAM);
+
+ /** Writes the given number of bytes to the endpoint from the given buffer in little endian,
+ * sending full packets to the host as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Endpoint_ClearIN() macro. Between each USB packet, the given stream callback function
+ * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early
+ * aborts of stream transfers.
+ *
+ * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
+ * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
+ * disabled and this function has the Callback parameter omitted.
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE().
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_EStream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE().
+ *
+ * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_PStream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the endpoint from the given buffer in big endian,
+ * sending full packets to the host as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Endpoint_ClearIN() macro. Between each USB packet, the given stream callback function
+ * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early
+ * aborts of stream transfers.
+ *
+ * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
+ * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
+ * disabled and this function has the Callback parameter omitted.
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE().
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_EStream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE().
+ *
+ * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_PStream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the endpoint from the given buffer in little endian,
+ * discarding fully read packets from the host as needed. The last packet is not automatically
+ * discarded once the remaining bytes has been read; the user is responsible for manually
+ * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
+ * each USB packet, the given stream callback function is executed repeatedly until the endpoint
+ * is ready to accept the next packet, allowing for early aborts of stream transfers.
+ *
+ * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
+ * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
+ * disabled and this function has the Callback parameter omitted.
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Read_Stream_LE().
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_EStream_LE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the endpoint from the given buffer in big endian,
+ * discarding fully read packets from the host as needed. The last packet is not automatically
+ * discarded once the remaining bytes has been read; the user is responsible for manually
+ * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
+ * each USB packet, the given stream callback function is executed repeatedly until the endpoint
+ * is ready to accept the next packet, allowing for early aborts of stream transfers.
+ *
+ * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
+ * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
+ * disabled and this function has the Callback parameter omitted.
+ *
+ * \note This routine should not be used on CONTROL type endpoints.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Read_Stream_BE().
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_EStream_BE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,
+ * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
+ * in both failure and success states; the user is responsible for manually clearing the setup OUT to
+ * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_EStream_LE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE().
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_PStream_LE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,
+ * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
+ * in both failure and success states; the user is responsible for manually clearing the setup OUT to
+ * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE().
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_EStream_BE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE().
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Write_Control_PStream_BE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,
+ * discarding fully read packets from the host as needed. The device IN acknowledgement is not
+ * automatically sent after success or failure states; the user is responsible for manually sending the
+ * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE().
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_EStream_LE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,
+ * discarding fully read packets from the host as needed. The device IN acknowledgement is not
+ * automatically sent after success or failure states; the user is responsible for manually sending the
+ * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE().
+ *
+ * \note This function automatically clears the control transfer's status stage. Do not manually attempt
+ * to clear the status stage when using this routine in a control transaction.
+ * \n\n
+ *
+ * \note This routine should only be used on CONTROL type endpoints.
+ *
+ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
+ * together; i.e. the entire stream data must be read or written at the one time.
+ *
+ * \ingroup Group_EndpointStreamRW
+ *
+ * \param[out] Buffer Pointer to the destination data buffer to write to.
+ * \param[in] Length Number of bytes to send via the currently selected endpoint.
+ *
+ * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Endpoint_Read_Control_EStream_BE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
+
+ /* Private Interface - For use in library only: */
+ #if !defined(__DOXYGEN__)
+ /* Macros: */
+ #define Endpoint_AllocateMemory() MACROS{ UECFG1X |= (1 << ALLOC); }MACROE
+ #define Endpoint_DeallocateMemory() MACROS{ UECFG1X &= ~(1 << ALLOC); }MACROE
+
+ #define _ENDPOINT_GET_MAXSIZE(n) _ENDPOINT_GET_MAXSIZE2(ENDPOINT_DETAILS_EP ## n)
+ #define _ENDPOINT_GET_MAXSIZE2(details) _ENDPOINT_GET_MAXSIZE3(details)
+ #define _ENDPOINT_GET_MAXSIZE3(maxsize, db) maxsize
+
+ #define _ENDPOINT_GET_DOUBLEBANK(n) _ENDPOINT_GET_DOUBLEBANK2(ENDPOINT_DETAILS_EP ## n)
+ #define _ENDPOINT_GET_DOUBLEBANK2(details) _ENDPOINT_GET_DOUBLEBANK3(details)
+ #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_EP0 64, true
+ #define ENDPOINT_DETAILS_EP1 256, true
+ #define ENDPOINT_DETAILS_EP2 64, true
+ #define ENDPOINT_DETAILS_EP3 64, true
+ #define ENDPOINT_DETAILS_EP4 64, true
+ #define ENDPOINT_DETAILS_EP5 64, true
+ #define ENDPOINT_DETAILS_EP6 64, true
+ #else
+ #define ENDPOINT_DETAILS_EP0 64, true
+ #define ENDPOINT_DETAILS_EP1 64, false
+ #define ENDPOINT_DETAILS_EP2 64, false
+ #define ENDPOINT_DETAILS_EP3 64, true
+ #define ENDPOINT_DETAILS_EP4 64, true
+ #endif
+
+ #define Endpoint_ConfigureEndpoint(Number, Type, Direction, Size, Banks) \
+ Endpoint_ConfigureEndpoint_Prv((Number), \
+ (((Type) << EPTYPE0) | (Direction)), \
+ ((1 << ALLOC) | (Banks) | \
+ (__builtin_constant_p(Size) ? \
+ Endpoint_BytesToEPSizeMask(Size) : \
+ Endpoint_BytesToEPSizeMaskDynamic(Size))))
+
+ /* Function Prototypes: */
+ void Endpoint_ClearEndpoints(void);
+ uint8_t Endpoint_BytesToEPSizeMaskDynamic(const uint16_t Size);
+ bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number, const uint8_t UECFG0XData, const uint8_t UECFG1XData);
+
+ /* Inline Functions: */
+ static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;
+ static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes)
+ {
+ uint8_t MaskVal = 0;
+ uint16_t CheckBytes = 8;
+
+ while (CheckBytes < Bytes)
+ {
+ MaskVal++;
+ CheckBytes <<= 1;
+ }
+
+ return (MaskVal << EPSIZE0);
+ }
+
+ #endif
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
diff --git a/LUFA/Drivers/USB/LowLevel/Host.c b/LUFA/Drivers/USB/LowLevel/Host.c
index e43972ac9..37ad0adc5 100644
--- a/LUFA/Drivers/USB/LowLevel/Host.c
+++ b/LUFA/Drivers/USB/LowLevel/Host.c
@@ -1,347 +1,347 @@
-/*
- 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_HOST_C
-#include "Host.h"
-
-void USB_Host_ProcessNextHostState(void)
-{
- uint8_t ErrorCode = HOST_ENUMERROR_NoError;
- uint8_t SubErrorCode = HOST_ENUMERROR_NoError;
-
- static uint16_t WaitMSRemaining;
- static uint8_t PostWaitState;
-
- switch (USB_HostState)
- {
- case HOST_STATE_WaitForDevice:
- if (WaitMSRemaining)
- {
- if ((SubErrorCode = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful)
- {
- USB_HostState = PostWaitState;
- 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:
- if (WaitMSRemaining--)
- {
- _delay_ms(1);
- break;
- }
- else
- {
- USB_Host_VBUS_Manual_Off();
-
- 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:
- 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);
- }
-
- break;
- case HOST_STATE_Powered_DoReset:
- USB_Host_ResetDevice();
-
- HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Powered_ConfigPipe);
- break;
- case HOST_STATE_Powered_ConfigPipe:
- Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL,
- PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP,
- PIPE_CONTROLPIPE_DEFAULT_SIZE, PIPE_BANK_SINGLE);
-
- if (!(Pipe_IsConfigured()))
- {
- ErrorCode = HOST_ENUMERROR_PipeConfigError;
- SubErrorCode = 0;
- break;
- }
-
- USB_HostState = HOST_STATE_Default;
- break;
- case HOST_STATE_Default:
- USB_ControlRequest = (USB_Request_Header_t)
- {
- .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
- .bRequest = REQ_GetDescriptor,
- .wValue = (DTYPE_Device << 8),
- .wIndex = 0,
- .wLength = 8,
- };
-
- uint8_t DataBuffer[8];
-
- if ((SubErrorCode = USB_Host_SendControlRequest(DataBuffer)) != HOST_SENDCONTROL_Successful)
- {
- ErrorCode = HOST_ENUMERROR_ControlError;
- break;
- }
-
- 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:
- Pipe_DisablePipe();
- Pipe_DeallocateMemory();
- Pipe_ResetPipe(PIPE_CONTROLPIPE);
-
- Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL,
- PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP,
- USB_ControlPipeSize, PIPE_BANK_SINGLE);
-
- if (!(Pipe_IsConfigured()))
- {
- ErrorCode = HOST_ENUMERROR_PipeConfigError;
- SubErrorCode = 0;
- break;
- }
-
- USB_ControlRequest = (USB_Request_Header_t)
- {
- .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
- .bRequest = REQ_SetAddress,
- .wValue = USB_HOST_DEVICEADDRESS,
- .wIndex = 0,
- .wLength = 0,
- };
-
- if ((SubErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
- {
- ErrorCode = HOST_ENUMERROR_ControlError;
- break;
- }
-
- HOST_TASK_NONBLOCK_WAIT(100, HOST_STATE_Default_PostAddressSet);
- break;
- case HOST_STATE_Default_PostAddressSet:
- USB_Host_SetDeviceAddress(USB_HOST_DEVICEADDRESS);
-
- EVENT_USB_Host_DeviceEnumerationComplete();
- USB_HostState = HOST_STATE_Addressed;
- break;
- }
-
- if ((ErrorCode != HOST_ENUMERROR_NoError) && (USB_HostState != HOST_STATE_Unattached))
- {
- EVENT_USB_Host_DeviceEnumerationFailed(ErrorCode, SubErrorCode);
-
- USB_Host_VBUS_Auto_Off();
-
- EVENT_USB_Host_DeviceUnattached();
-
- USB_ResetInterface();
- }
-}
-
-uint8_t USB_Host_WaitMS(uint8_t MS)
-{
- bool BusSuspended = USB_Host_IsBusSuspended();
- uint8_t ErrorCode = HOST_WAITERROR_Successful;
-
- USB_Host_ResumeBus();
-
- while (MS)
- {
- if (USB_INT_HasOccurred(USB_INT_HSOFI))
- {
- USB_INT_Clear(USB_INT_HSOFI);
- MS--;
- }
-
- if ((USB_HostState == HOST_STATE_Unattached) || (USB_CurrentMode == USB_MODE_DEVICE))
- {
- ErrorCode = HOST_WAITERROR_DeviceDisconnect;
-
- break;
- }
-
- if (Pipe_IsError() == true)
- {
- Pipe_ClearError();
- ErrorCode = HOST_WAITERROR_PipeError;
-
- break;
- }
-
- if (Pipe_IsStalled() == true)
- {
- Pipe_ClearStall();
- ErrorCode = HOST_WAITERROR_SetupStalled;
-
- break;
- }
- }
-
- if (BusSuspended)
- USB_Host_SuspendBus();
-
- return ErrorCode;
-}
-
-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();
-
- 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,
- all disconnection interrupts are suppressed while a USB frame is
- looked for - if it is found within 10ms, the device is still
- present. */
-
- if (USB_INT_HasOccurred(USB_INT_HSOFI))
- {
- USB_INT_Clear(USB_INT_HSOFI);
- USB_INT_Clear(USB_INT_DDISCI);
- break;
- }
-
- _delay_ms(1);
- }
-
- if (BusSuspended)
- USB_Host_SuspendBus();
-
- USB_INT_Enable(USB_INT_DDISCI);
-}
-
-uint8_t USB_Host_SetDeviceConfiguration(const uint8_t ConfigNumber)
-{
- USB_ControlRequest = (USB_Request_Header_t)
- {
- .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
- .bRequest = REQ_SetConfiguration,
- .wValue = ConfigNumber,
- .wIndex = 0,
- .wLength = 0,
- };
-
- Pipe_SelectPipe(PIPE_CONTROLPIPE);
-
- return USB_Host_SendControlRequest(NULL);
-}
-
-uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr)
-{
- USB_ControlRequest = (USB_Request_Header_t)
- {
- .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
- .bRequest = REQ_GetDescriptor,
- .wValue = (DTYPE_Device << 8),
- .wIndex = 0,
- .wLength = sizeof(USB_Descriptor_Device_t),
- };
-
- Pipe_SelectPipe(PIPE_CONTROLPIPE);
-
- return USB_Host_SendControlRequest(DeviceDescriptorPtr);
-}
-
-uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index, void* const Buffer, const uint8_t BufferLength)
-{
- USB_ControlRequest = (USB_Request_Header_t)
- {
- .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
- .bRequest = REQ_GetDescriptor,
- .wValue = (DTYPE_String << 8) | Index,
- .wIndex = 0,
- .wLength = BufferLength,
- };
-
- Pipe_SelectPipe(PIPE_CONTROLPIPE);
-
- return USB_Host_SendControlRequest(Buffer);
-}
-
-uint8_t USB_Host_ClearPipeStall(uint8_t EndpointNum)
-{
- if (Pipe_GetPipeToken() == PIPE_TOKEN_IN)
- EndpointNum |= ENDPOINT_DESCRIPTOR_DIR_IN;
-
- USB_ControlRequest = (USB_Request_Header_t)
- {
- .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT),
- .bRequest = REQ_ClearFeature,
- .wValue = FEATURE_ENDPOINT_HALT,
- .wIndex = EndpointNum,
- .wLength = 0,
- };
-
- Pipe_SelectPipe(PIPE_CONTROLPIPE);
-
- return USB_Host_SendControlRequest(NULL);
-}
-
-#endif
+/*
+ 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_HOST_C
+#include "Host.h"
+
+void USB_Host_ProcessNextHostState(void)
+{
+ uint8_t ErrorCode = HOST_ENUMERROR_NoError;
+ uint8_t SubErrorCode = HOST_ENUMERROR_NoError;
+
+ static uint16_t WaitMSRemaining;
+ static uint8_t PostWaitState;
+
+ switch (USB_HostState)
+ {
+ case HOST_STATE_WaitForDevice:
+ if (WaitMSRemaining)
+ {
+ if ((SubErrorCode = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful)
+ {
+ USB_HostState = PostWaitState;
+ 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:
+ if (WaitMSRemaining--)
+ {
+ _delay_ms(1);
+ break;
+ }
+ else
+ {
+ USB_Host_VBUS_Manual_Off();
+
+ 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:
+ 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);
+ }
+
+ break;
+ case HOST_STATE_Powered_DoReset:
+ USB_Host_ResetDevice();
+
+ HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Powered_ConfigPipe);
+ break;
+ case HOST_STATE_Powered_ConfigPipe:
+ Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL,
+ PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP,
+ PIPE_CONTROLPIPE_DEFAULT_SIZE, PIPE_BANK_SINGLE);
+
+ if (!(Pipe_IsConfigured()))
+ {
+ ErrorCode = HOST_ENUMERROR_PipeConfigError;
+ SubErrorCode = 0;
+ break;
+ }
+
+ USB_HostState = HOST_STATE_Default;
+ break;
+ case HOST_STATE_Default:
+ USB_ControlRequest = (USB_Request_Header_t)
+ {
+ .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
+ .bRequest = REQ_GetDescriptor,
+ .wValue = (DTYPE_Device << 8),
+ .wIndex = 0,
+ .wLength = 8,
+ };
+
+ uint8_t DataBuffer[8];
+
+ if ((SubErrorCode = USB_Host_SendControlRequest(DataBuffer)) != HOST_SENDCONTROL_Successful)
+ {
+ ErrorCode = HOST_ENUMERROR_ControlError;
+ break;
+ }
+
+ 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:
+ Pipe_DisablePipe();
+ Pipe_DeallocateMemory();
+ Pipe_ResetPipe(PIPE_CONTROLPIPE);
+
+ Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL,
+ PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP,
+ USB_ControlPipeSize, PIPE_BANK_SINGLE);
+
+ if (!(Pipe_IsConfigured()))
+ {
+ ErrorCode = HOST_ENUMERROR_PipeConfigError;
+ SubErrorCode = 0;
+ break;
+ }
+
+ USB_ControlRequest = (USB_Request_Header_t)
+ {
+ .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
+ .bRequest = REQ_SetAddress,
+ .wValue = USB_HOST_DEVICEADDRESS,
+ .wIndex = 0,
+ .wLength = 0,
+ };
+
+ if ((SubErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
+ {
+ ErrorCode = HOST_ENUMERROR_ControlError;
+ break;
+ }
+
+ HOST_TASK_NONBLOCK_WAIT(100, HOST_STATE_Default_PostAddressSet);
+ break;
+ case HOST_STATE_Default_PostAddressSet:
+ USB_Host_SetDeviceAddress(USB_HOST_DEVICEADDRESS);
+
+ EVENT_USB_Host_DeviceEnumerationComplete();
+ USB_HostState = HOST_STATE_Addressed;
+ break;
+ }
+
+ if ((ErrorCode != HOST_ENUMERROR_NoError) && (USB_HostState != HOST_STATE_Unattached))
+ {
+ EVENT_USB_Host_DeviceEnumerationFailed(ErrorCode, SubErrorCode);
+
+ USB_Host_VBUS_Auto_Off();
+
+ EVENT_USB_Host_DeviceUnattached();
+
+ USB_ResetInterface();
+ }
+}
+
+uint8_t USB_Host_WaitMS(uint8_t MS)
+{
+ bool BusSuspended = USB_Host_IsBusSuspended();
+ uint8_t ErrorCode = HOST_WAITERROR_Successful;
+
+ USB_Host_ResumeBus();
+
+ while (MS)
+ {
+ if (USB_INT_HasOccurred(USB_INT_HSOFI))
+ {
+ USB_INT_Clear(USB_INT_HSOFI);
+ MS--;
+ }
+
+ if ((USB_HostState == HOST_STATE_Unattached) || (USB_CurrentMode == USB_MODE_DEVICE))
+ {
+ ErrorCode = HOST_WAITERROR_DeviceDisconnect;
+
+ break;
+ }
+
+ if (Pipe_IsError() == true)
+ {
+ Pipe_ClearError();
+ ErrorCode = HOST_WAITERROR_PipeError;
+
+ break;
+ }
+
+ if (Pipe_IsStalled() == true)
+ {
+ Pipe_ClearStall();
+ ErrorCode = HOST_WAITERROR_SetupStalled;
+
+ break;
+ }
+ }
+
+ if (BusSuspended)
+ USB_Host_SuspendBus();
+
+ return ErrorCode;
+}
+
+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();
+
+ 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,
+ all disconnection interrupts are suppressed while a USB frame is
+ looked for - if it is found within 10ms, the device is still
+ present. */
+
+ if (USB_INT_HasOccurred(USB_INT_HSOFI))
+ {
+ USB_INT_Clear(USB_INT_HSOFI);
+ USB_INT_Clear(USB_INT_DDISCI);
+ break;
+ }
+
+ _delay_ms(1);
+ }
+
+ if (BusSuspended)
+ USB_Host_SuspendBus();
+
+ USB_INT_Enable(USB_INT_DDISCI);
+}
+
+uint8_t USB_Host_SetDeviceConfiguration(const uint8_t ConfigNumber)
+{
+ USB_ControlRequest = (USB_Request_Header_t)
+ {
+ .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
+ .bRequest = REQ_SetConfiguration,
+ .wValue = ConfigNumber,
+ .wIndex = 0,
+ .wLength = 0,
+ };
+
+ Pipe_SelectPipe(PIPE_CONTROLPIPE);
+
+ return USB_Host_SendControlRequest(NULL);
+}
+
+uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr)
+{
+ USB_ControlRequest = (USB_Request_Header_t)
+ {
+ .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
+ .bRequest = REQ_GetDescriptor,
+ .wValue = (DTYPE_Device << 8),
+ .wIndex = 0,
+ .wLength = sizeof(USB_Descriptor_Device_t),
+ };
+
+ Pipe_SelectPipe(PIPE_CONTROLPIPE);
+
+ return USB_Host_SendControlRequest(DeviceDescriptorPtr);
+}
+
+uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index, void* const Buffer, const uint8_t BufferLength)
+{
+ USB_ControlRequest = (USB_Request_Header_t)
+ {
+ .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
+ .bRequest = REQ_GetDescriptor,
+ .wValue = (DTYPE_String << 8) | Index,
+ .wIndex = 0,
+ .wLength = BufferLength,
+ };
+
+ Pipe_SelectPipe(PIPE_CONTROLPIPE);
+
+ return USB_Host_SendControlRequest(Buffer);
+}
+
+uint8_t USB_Host_ClearPipeStall(uint8_t EndpointNum)
+{
+ if (Pipe_GetPipeToken() == PIPE_TOKEN_IN)
+ EndpointNum |= ENDPOINT_DESCRIPTOR_DIR_IN;
+
+ USB_ControlRequest = (USB_Request_Header_t)
+ {
+ .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT),
+ .bRequest = REQ_ClearFeature,
+ .wValue = FEATURE_ENDPOINT_HALT,
+ .wIndex = EndpointNum,
+ .wLength = 0,
+ };
+
+ Pipe_SelectPipe(PIPE_CONTROLPIPE);
+
+ return USB_Host_SendControlRequest(NULL);
+}
+
+#endif
diff --git a/LUFA/Drivers/USB/LowLevel/Host.h b/LUFA/Drivers/USB/LowLevel/Host.h
index 97d908dea..1ef023908 100644
--- a/LUFA/Drivers/USB/LowLevel/Host.h
+++ b/LUFA/Drivers/USB/LowLevel/Host.h
@@ -1,428 +1,428 @@
-/*
- 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 mode definitions.
- *
- * This file contains structures, function prototypes and macros related to 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.
- */
-
-/** \ingroup Group_USB
- * @defgroup Group_Host Host Management
- *
- * USB Host mode related macros and enums. This module contains macros and enums which are used when
- * the USB controller is initialized in host mode.
- *
- * @{
- */
-
-#ifndef __USBHOST_H__
-#define __USBHOST_H__
-
- /* Includes: */
- #include <avr/io.h>
- #include <stdbool.h>
- #include <util/delay.h>
-
- #include "../../../Common/Common.h"
- #include "../HighLevel/StdDescriptors.h"
- #include "Pipe.h"
- #include "USBInterrupt.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: */
- /** Indicates the fixed USB device address which any attached device is enumerated to when in
- * host mode. As only one USB device may be attached to the AVR in host mode at any one time
- * and that the address used is not important (other than the fact that it is non-zero), a
- * fixed value is specified by the library.
- */
- #define USB_HOST_DEVICEADDRESS 1
-
- #if !defined(USB_HOST_TIMEOUT_MS) || defined(__DOXYGEN__)
- /** Constant for the maximum software timeout period of sent USB control transactions to an attached
- * 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
- * \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
- * after connection before the enumeration process can start or incorrect operation will
- * occur.
- *
- * This value may be overridden in the user project makefile as the value of the
- * HOST_DEVICE_SETTLE_DELAY_MS token, and passed to the compiler using the -D switch.
- */
- #define HOST_DEVICE_SETTLE_DELAY_MS 1500
- #endif
-
- /* Pseudo-Function Macros: */
- #if defined(__DOXYGEN__)
- /** 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).
- *
- * If the USB bus has been suspended prior to issuing a bus reset, the attached device will be
- * woken up automatically and the bus resumed after the reset has been correctly issued.
- */
- static inline void USB_Host_ResetBus(void);
-
- /** Determines if a previously issued bus reset (via the \ref USB_Host_ResetBus() macro) has
- * completed.
- *
- * \return Boolean true if no bus reset is currently being sent, false otherwise.
- */
- static inline void USB_Host_IsBusResetComplete(void);
-
- /** Resumes USB communications with an attached and enumerated device, by resuming the transmission
- * of the 1MS Start Of Frame messages to the device. When resumed, USB communications between the
- * host and attached device may occur.
- */
- static inline void USB_Host_ResumeBus(void);
-
- /** Suspends the USB bus, preventing any communications from occurring between the host and attached
- * device until the bus has been resumed. This stops the transmission of the 1MS Start Of Frame
- * messages to the device.
- */
- static inline void USB_Host_SuspendBus(void);
-
- /** 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.
- *
- * \return Boolean true if the bus is currently suspended, false otherwise
- */
- static inline bool USB_Host_IsBusSuspended(void);
-
- /** 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).
- *
- * \return Boolean true if the attached device is enumerated in Full Speed mode, false otherwise
- */
- static inline bool USB_Host_IsDeviceFullSpeed(void);
-
- /** Determines if the attached device is currently issuing a Remote Wakeup request, requesting
- * that the host resume the USB bus and wake up the device, false otherwise.
- *
- * \return Boolean true if the attached device has sent a Remote Wakeup request, false otherwise
- */
- static inline bool USB_Host_IsRemoteWakeupSent(void);
-
- /** Clears the flag indicating that a Remote Wakeup request has been issued by an attached device. */
- static inline void USB_Host_ClearRemoteWakeupSent(void);
-
- /** Accepts a Remote Wakeup request from an attached device. This must be issued in response to
- * a device's Remote Wakeup request within 2ms for the request to be accepted and the bus to
- * be resumed.
- */
- static inline void USB_Host_ResumeFromWakeupRequest(void);
-
- /** Determines if a resume from Remote Wakeup request is currently being sent to an attached
- * device.
- *
- * \return Boolean true if no resume request is currently being sent, false otherwise
- */
- static inline bool USB_Host_IsResumeFromWakeupRequestSent(void);
- #else
- #define USB_Host_ResetBus() MACROS{ UHCON |= (1 << RESET); }MACROE
-
- #define USB_Host_IsBusResetComplete() ((UHCON & (1 << RESET)) ? false : true)
-
- #define USB_Host_ResumeBus() MACROS{ UHCON |= (1 << SOFEN); }MACROE
-
- #define USB_Host_SuspendBus() MACROS{ UHCON &= ~(1 << SOFEN); }MACROE
-
- #define USB_Host_IsBusSuspended() ((UHCON & (1 << SOFEN)) ? false : true)
-
- #define USB_Host_IsDeviceFullSpeed() ((USBSTA & (1 << SPEED)) ? true : false)
-
- #define USB_Host_IsRemoteWakeupSent() ((UHINT & (1 << RXRSMI)) ? true : false)
-
- #define USB_Host_ClearRemoteWakeupSent() MACROS{ UHINT &= ~(1 << RXRSMI); }MACROE
-
- #define USB_Host_ResumeFromWakeupRequest() MACROS{ UHCON |= (1 << RESUME); }MACROE
-
- #define USB_Host_IsResumeFromWakeupRequestSent() ((UHCON & (1 << RESUME)) ? false : true)
- #endif
-
- /* Function Prototypes: */
- /** Convenience function. This routine sends a SetConfiguration standard request to the attached
- * device, with the given configuration index. This can be used to easily set the device
- * configuration without creating and sending the request manually.
- *
- * \note After this routine returns, the control pipe will be selected.
- *
- * \param[in] ConfigNumber Configuration index to send to the device
- *
- * \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.
- *
- * \note After this routine returns, the control pipe will be selected.
- *
- * \param[out] DeviceDescriptorPtr Pointer to the destination device descriptor structure where
- * the read data is to be stored
- *
- * \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
- * Device or Configuration descriptors.
- *
- * \note After this routine returns, the control pipe will be selected.
- *
- * \param[in] Index Index of the string index to retrieve
- * \param[out] Buffer Pointer to the destination buffer where the retrieved string decriptor is
- * to be stored
- * \param[in] BufferLength Maximum size of the string descriptor which can be stored into the buffer
- *
- * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
- */
- 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.
- *
- * \param[in] EndpointIndex Index of the endpoint to clear
- *
- * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
- */
- uint8_t USB_Host_ClearPipeStall(uint8_t EndpointIndex);
-
- /* Enums: */
- /** Enum for the various states of the USB Host state machine. Only some states are
- * implemented in the LUFA library - other states are left to the user to implement.
- *
- * For information on each possible USB host state, refer to the USB 2.0 specification.
- * Several of the USB host states are broken up further into multiple smaller sub-states,
- * so that they can be internally implemented inside the library in an efficient manner.
- *
- * \see \ref USB_HostState, which stores the current host state machine state.
- */
- enum USB_Host_States_t
- {
- HOST_STATE_WaitForDeviceRemoval = 0, /**< Internally implemented by the library. This state can be
- * used by the library to wait until the attached device is
- * removed by the user - useful for when an error occurs or
- * further communication with the device is not needed. This
- * allows for other code to run while the state machine is
- * effectively disabled.
- */
- HOST_STATE_WaitForDevice = 1, /**< Internally implemented by the library. This state indicates
- * that the stack is waiting for an interval to elapse before
- * continuing with the next step of the device enumeration
- * process.
- *
- * \note Do not manually change to this state in the user code.
- */
- 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
- * the device's address has now been set, and the stack is has now
- * completed the device enumeration process. This state causes the
- * stack to change the current USB device address to that set for
- * the connected device, before progressing to the user-implemented
- * 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
- * set the device configuration before progressing to the
- * HOST_STATE_Configured state. Other processing (such as the
- * retrieval and processing of the device descriptor) should also
- * be placed in this state.
- */
- HOST_STATE_Configured = 12, /**< May be implemented by the user project. This state should implement the
- * actual work performed on the attached device and changed to the
- * HOST_STATE_Suspended or HOST_STATE_WaitForDeviceRemoval states as needed.
- */
- HOST_STATE_Suspended = 15, /**< May be implemented by the user project. This state should be maintained
- * while the bus is suspended, and changed to either the HOST_STATE_Configured
- * (after resuming the bus with the USB_Host_ResumeBus() macro) or the
- * 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.
- */
- enum USB_Host_ErrorCodes_t
- {
- HOST_ERROR_VBusVoltageDip = 0, /**< VBUS voltage dipped to an unacceptable level. This
- * error may be the result of an attached device drawing
- * too much current from the VBUS line, or due to the
- * AVR's power source being unable to supply sufficient
- * current.
- */
- };
-
- /** Enum for the error codes for the \ref EVENT_USB_Host_DeviceEnumerationFailed() event.
- *
- * \see \ref Group_Events for more information on this event.
- */
- enum USB_Host_EnumerationErrorCodes_t
- {
- HOST_ENUMERROR_NoError = 0, /**< No error occurred. Used internally, this is not a valid
- * ErrorCode parameter value for the \ref EVENT_USB_Host_DeviceEnumerationFailed()
- * event.
- */
- HOST_ENUMERROR_WaitStage = 1, /**< One of the delays between enumeration steps failed
- * to complete successfully, due to a timeout or other
- * error.
- */
- HOST_ENUMERROR_NoDeviceDetected = 2, /**< No device was detected, despite the USB data lines
- * indicating the attachment of a device.
- */
- HOST_ENUMERROR_ControlError = 3, /**< One of the enumeration control requests failed to
- * complete successfully.
- */
- HOST_ENUMERROR_PipeConfigError = 4, /**< The default control pipe (address 0) failed to
- * configure correctly.
- */
- };
-
- /* Private Interface - For use in library only: */
- #if !defined(__DOXYGEN__)
- /* Macros: */
- #define USB_Host_HostMode_On() MACROS{ USBCON |= (1 << HOST); }MACROE
- #define USB_Host_HostMode_Off() MACROS{ USBCON &= ~(1 << HOST); }MACROE
-
- #define USB_Host_VBUS_Auto_Enable() MACROS{ OTGCON &= ~(1 << VBUSHWC); UHWCON |= (1 << UVCONE); }MACROE
- #define USB_Host_VBUS_Manual_Enable() MACROS{ OTGCON |= (1 << VBUSHWC); UHWCON &= ~(1 << UVCONE); DDRE |= (1 << 7); }MACROE
-
- #define USB_Host_VBUS_Auto_On() MACROS{ OTGCON |= (1 << VBUSREQ); }MACROE
- #define USB_Host_VBUS_Manual_On() MACROS{ PORTE |= (1 << 7); }MACROE
-
- #define USB_Host_VBUS_Auto_Off() MACROS{ OTGCON |= (1 << VBUSRQC); }MACROE
- #define USB_Host_VBUS_Manual_Off() MACROS{ PORTE &= ~(1 << 7); }MACROE
-
- #define USB_Host_SetDeviceAddress(addr) MACROS{ UHADDR = ((addr) & 0x7F); }MACROE
-
- /* Enums: */
- enum USB_Host_WaitMSErrorCodes_t
- {
- HOST_WAITERROR_Successful = 0,
- HOST_WAITERROR_DeviceDisconnect = 1,
- HOST_WAITERROR_PipeError = 2,
- HOST_WAITERROR_SetupStalled = 3,
- };
-
- /* 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
- #endif
-
- /* Disable C linkage for C++ Compilers: */
- #if defined(__cplusplus)
- }
- #endif
-
-#endif
-
-/** @} */
+/*
+ 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 mode definitions.
+ *
+ * This file contains structures, function prototypes and macros related to 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.
+ */
+
+/** \ingroup Group_USB
+ * @defgroup Group_Host Host Management
+ *
+ * USB Host mode related macros and enums. This module contains macros and enums which are used when
+ * the USB controller is initialized in host mode.
+ *
+ * @{
+ */
+
+#ifndef __USBHOST_H__
+#define __USBHOST_H__
+
+ /* Includes: */
+ #include <avr/io.h>
+ #include <stdbool.h>
+ #include <util/delay.h>
+
+ #include "../../../Common/Common.h"
+ #include "../HighLevel/StdDescriptors.h"
+ #include "Pipe.h"
+ #include "USBInterrupt.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: */
+ /** Indicates the fixed USB device address which any attached device is enumerated to when in
+ * host mode. As only one USB device may be attached to the AVR in host mode at any one time
+ * and that the address used is not important (other than the fact that it is non-zero), a
+ * fixed value is specified by the library.
+ */
+ #define USB_HOST_DEVICEADDRESS 1
+
+ #if !defined(USB_HOST_TIMEOUT_MS) || defined(__DOXYGEN__)
+ /** Constant for the maximum software timeout period of sent USB control transactions to an attached
+ * 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
+ * \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
+ * after connection before the enumeration process can start or incorrect operation will
+ * occur.
+ *
+ * This value may be overridden in the user project makefile as the value of the
+ * HOST_DEVICE_SETTLE_DELAY_MS token, and passed to the compiler using the -D switch.
+ */
+ #define HOST_DEVICE_SETTLE_DELAY_MS 1500
+ #endif
+
+ /* Pseudo-Function Macros: */
+ #if defined(__DOXYGEN__)
+ /** 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).
+ *
+ * If the USB bus has been suspended prior to issuing a bus reset, the attached device will be
+ * woken up automatically and the bus resumed after the reset has been correctly issued.
+ */
+ static inline void USB_Host_ResetBus(void);
+
+ /** Determines if a previously issued bus reset (via the \ref USB_Host_ResetBus() macro) has
+ * completed.
+ *
+ * \return Boolean true if no bus reset is currently being sent, false otherwise.
+ */
+ static inline void USB_Host_IsBusResetComplete(void);
+
+ /** Resumes USB communications with an attached and enumerated device, by resuming the transmission
+ * of the 1MS Start Of Frame messages to the device. When resumed, USB communications between the
+ * host and attached device may occur.
+ */
+ static inline void USB_Host_ResumeBus(void);
+
+ /** Suspends the USB bus, preventing any communications from occurring between the host and attached
+ * device until the bus has been resumed. This stops the transmission of the 1MS Start Of Frame
+ * messages to the device.
+ */
+ static inline void USB_Host_SuspendBus(void);
+
+ /** 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.
+ *
+ * \return Boolean true if the bus is currently suspended, false otherwise
+ */
+ static inline bool USB_Host_IsBusSuspended(void);
+
+ /** 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).
+ *
+ * \return Boolean true if the attached device is enumerated in Full Speed mode, false otherwise
+ */
+ static inline bool USB_Host_IsDeviceFullSpeed(void);
+
+ /** Determines if the attached device is currently issuing a Remote Wakeup request, requesting
+ * that the host resume the USB bus and wake up the device, false otherwise.
+ *
+ * \return Boolean true if the attached device has sent a Remote Wakeup request, false otherwise
+ */
+ static inline bool USB_Host_IsRemoteWakeupSent(void);
+
+ /** Clears the flag indicating that a Remote Wakeup request has been issued by an attached device. */
+ static inline void USB_Host_ClearRemoteWakeupSent(void);
+
+ /** Accepts a Remote Wakeup request from an attached device. This must be issued in response to
+ * a device's Remote Wakeup request within 2ms for the request to be accepted and the bus to
+ * be resumed.
+ */
+ static inline void USB_Host_ResumeFromWakeupRequest(void);
+
+ /** Determines if a resume from Remote Wakeup request is currently being sent to an attached
+ * device.
+ *
+ * \return Boolean true if no resume request is currently being sent, false otherwise
+ */
+ static inline bool USB_Host_IsResumeFromWakeupRequestSent(void);
+ #else
+ #define USB_Host_ResetBus() MACROS{ UHCON |= (1 << RESET); }MACROE
+
+ #define USB_Host_IsBusResetComplete() ((UHCON & (1 << RESET)) ? false : true)
+
+ #define USB_Host_ResumeBus() MACROS{ UHCON |= (1 << SOFEN); }MACROE
+
+ #define USB_Host_SuspendBus() MACROS{ UHCON &= ~(1 << SOFEN); }MACROE
+
+ #define USB_Host_IsBusSuspended() ((UHCON & (1 << SOFEN)) ? false : true)
+
+ #define USB_Host_IsDeviceFullSpeed() ((USBSTA & (1 << SPEED)) ? true : false)
+
+ #define USB_Host_IsRemoteWakeupSent() ((UHINT & (1 << RXRSMI)) ? true : false)
+
+ #define USB_Host_ClearRemoteWakeupSent() MACROS{ UHINT &= ~(1 << RXRSMI); }MACROE
+
+ #define USB_Host_ResumeFromWakeupRequest() MACROS{ UHCON |= (1 << RESUME); }MACROE
+
+ #define USB_Host_IsResumeFromWakeupRequestSent() ((UHCON & (1 << RESUME)) ? false : true)
+ #endif
+
+ /* Function Prototypes: */
+ /** Convenience function. This routine sends a SetConfiguration standard request to the attached
+ * device, with the given configuration index. This can be used to easily set the device
+ * configuration without creating and sending the request manually.
+ *
+ * \note After this routine returns, the control pipe will be selected.
+ *
+ * \param[in] ConfigNumber Configuration index to send to the device
+ *
+ * \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.
+ *
+ * \note After this routine returns, the control pipe will be selected.
+ *
+ * \param[out] DeviceDescriptorPtr Pointer to the destination device descriptor structure where
+ * the read data is to be stored
+ *
+ * \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
+ * Device or Configuration descriptors.
+ *
+ * \note After this routine returns, the control pipe will be selected.
+ *
+ * \param[in] Index Index of the string index to retrieve
+ * \param[out] Buffer Pointer to the destination buffer where the retrieved string decriptor is
+ * to be stored
+ * \param[in] BufferLength Maximum size of the string descriptor which can be stored into the buffer
+ *
+ * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
+ */
+ 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.
+ *
+ * \param[in] EndpointIndex Index of the endpoint to clear
+ *
+ * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
+ */
+ uint8_t USB_Host_ClearPipeStall(uint8_t EndpointIndex);
+
+ /* Enums: */
+ /** Enum for the various states of the USB Host state machine. Only some states are
+ * implemented in the LUFA library - other states are left to the user to implement.
+ *
+ * For information on each possible USB host state, refer to the USB 2.0 specification.
+ * Several of the USB host states are broken up further into multiple smaller sub-states,
+ * so that they can be internally implemented inside the library in an efficient manner.
+ *
+ * \see \ref USB_HostState, which stores the current host state machine state.
+ */
+ enum USB_Host_States_t
+ {
+ HOST_STATE_WaitForDeviceRemoval = 0, /**< Internally implemented by the library. This state can be
+ * used by the library to wait until the attached device is
+ * removed by the user - useful for when an error occurs or
+ * further communication with the device is not needed. This
+ * allows for other code to run while the state machine is
+ * effectively disabled.
+ */
+ HOST_STATE_WaitForDevice = 1, /**< Internally implemented by the library. This state indicates
+ * that the stack is waiting for an interval to elapse before
+ * continuing with the next step of the device enumeration
+ * process.
+ *
+ * \note Do not manually change to this state in the user code.
+ */
+ 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
+ * the device's address has now been set, and the stack is has now
+ * completed the device enumeration process. This state causes the
+ * stack to change the current USB device address to that set for
+ * the connected device, before progressing to the user-implemented
+ * 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
+ * set the device configuration before progressing to the
+ * HOST_STATE_Configured state. Other processing (such as the
+ * retrieval and processing of the device descriptor) should also
+ * be placed in this state.
+ */
+ HOST_STATE_Configured = 12, /**< May be implemented by the user project. This state should implement the
+ * actual work performed on the attached device and changed to the
+ * HOST_STATE_Suspended or HOST_STATE_WaitForDeviceRemoval states as needed.
+ */
+ HOST_STATE_Suspended = 15, /**< May be implemented by the user project. This state should be maintained
+ * while the bus is suspended, and changed to either the HOST_STATE_Configured
+ * (after resuming the bus with the USB_Host_ResumeBus() macro) or the
+ * 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.
+ */
+ enum USB_Host_ErrorCodes_t
+ {
+ HOST_ERROR_VBusVoltageDip = 0, /**< VBUS voltage dipped to an unacceptable level. This
+ * error may be the result of an attached device drawing
+ * too much current from the VBUS line, or due to the
+ * AVR's power source being unable to supply sufficient
+ * current.
+ */
+ };
+
+ /** Enum for the error codes for the \ref EVENT_USB_Host_DeviceEnumerationFailed() event.
+ *
+ * \see \ref Group_Events for more information on this event.
+ */
+ enum USB_Host_EnumerationErrorCodes_t
+ {
+ HOST_ENUMERROR_NoError = 0, /**< No error occurred. Used internally, this is not a valid
+ * ErrorCode parameter value for the \ref EVENT_USB_Host_DeviceEnumerationFailed()
+ * event.
+ */
+ HOST_ENUMERROR_WaitStage = 1, /**< One of the delays between enumeration steps failed
+ * to complete successfully, due to a timeout or other
+ * error.
+ */
+ HOST_ENUMERROR_NoDeviceDetected = 2, /**< No device was detected, despite the USB data lines
+ * indicating the attachment of a device.
+ */
+ HOST_ENUMERROR_ControlError = 3, /**< One of the enumeration control requests failed to
+ * complete successfully.
+ */
+ HOST_ENUMERROR_PipeConfigError = 4, /**< The default control pipe (address 0) failed to
+ * configure correctly.
+ */
+ };
+
+ /* Private Interface - For use in library only: */
+ #if !defined(__DOXYGEN__)
+ /* Macros: */
+ #define USB_Host_HostMode_On() MACROS{ USBCON |= (1 << HOST); }MACROE
+ #define USB_Host_HostMode_Off() MACROS{ USBCON &= ~(1 << HOST); }MACROE
+
+ #define USB_Host_VBUS_Auto_Enable() MACROS{ OTGCON &= ~(1 << VBUSHWC); UHWCON |= (1 << UVCONE); }MACROE
+ #define USB_Host_VBUS_Manual_Enable() MACROS{ OTGCON |= (1 << VBUSHWC); UHWCON &= ~(1 << UVCONE); DDRE |= (1 << 7); }MACROE
+
+ #define USB_Host_VBUS_Auto_On() MACROS{ OTGCON |= (1 << VBUSREQ); }MACROE
+ #define USB_Host_VBUS_Manual_On() MACROS{ PORTE |= (1 << 7); }MACROE
+
+ #define USB_Host_VBUS_Auto_Off() MACROS{ OTGCON |= (1 << VBUSRQC); }MACROE
+ #define USB_Host_VBUS_Manual_Off() MACROS{ PORTE &= ~(1 << 7); }MACROE
+
+ #define USB_Host_SetDeviceAddress(addr) MACROS{ UHADDR = ((addr) & 0x7F); }MACROE
+
+ /* Enums: */
+ enum USB_Host_WaitMSErrorCodes_t
+ {
+ HOST_WAITERROR_Successful = 0,
+ HOST_WAITERROR_DeviceDisconnect = 1,
+ HOST_WAITERROR_PipeError = 2,
+ HOST_WAITERROR_SetupStalled = 3,
+ };
+
+ /* 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
+ #endif
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
diff --git a/LUFA/Drivers/USB/LowLevel/HostChapter9.c b/LUFA/Drivers/USB/LowLevel/HostChapter9.c
index e5072c8a8..69575f18b 100644
--- a/LUFA/Drivers/USB/LowLevel/HostChapter9.c
+++ b/LUFA/Drivers/USB/LowLevel/HostChapter9.c
@@ -1,179 +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 "../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
+/*
+ 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
index e38c67e6c..ab8348d4c 100644
--- a/LUFA/Drivers/USB/LowLevel/HostChapter9.h
+++ b/LUFA/Drivers/USB/LowLevel/HostChapter9.h
@@ -1,117 +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 neccesary 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 <avr/io.h>
- #include <stdbool.h>
-
- #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
+/*
+ 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 neccesary 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 <avr/io.h>
+ #include <stdbool.h>
+
+ #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
index a088654f7..4c742102b 100644
--- a/LUFA/Drivers/USB/LowLevel/LowLevel.c
+++ b/LUFA/Drivers/USB/LowLevel/LowLevel.c
@@ -1,271 +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 "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
-}
+/*
+ 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
index efa605b72..df9d3bb1c 100644
--- a/LUFA/Drivers/USB/LowLevel/LowLevel.h
+++ b/LUFA/Drivers/USB/LowLevel/LowLevel.h
@@ -1,389 +1,389 @@
-/*
- 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 configutation 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 <avr/io.h>
- #include <avr/interrupt.h>
- #include <stdbool.h>
-
- #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 behaviour. 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
-
-/** @} */
+/*
+ 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 configutation 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 <avr/io.h>
+ #include <avr/interrupt.h>
+ #include <stdbool.h>
+
+ #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 behaviour. 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/OTG.h b/LUFA/Drivers/USB/LowLevel/OTG.h
index ef3ab38d1..944fd72ac 100644
--- a/LUFA/Drivers/USB/LowLevel/OTG.h
+++ b/LUFA/Drivers/USB/LowLevel/OTG.h
@@ -1,141 +1,141 @@
-/*
- 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 OTG mode definitions.
- *
- * This file contains structures, function prototypes and macros related to USB OTG mode, where two USB devices
- * may be linked directly together and exchange host/device roles as needed.
- *
- * \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_OTG USB On The Go (OTG) Management
- *
- * This module contains macros for embedded USB hosts with dual role On The Go capabilities, for managing role
- * exchange. OTG is a way for two USB dual role devices to talk to one another directly without fixed device/host
- * roles.
- *
- * @{
- */
-
-#ifndef __USBOTG_H__
-#define __USBOTG_H__
-
- /* 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 USB_OTG_DEV_Initiate_SRP()
- */
- #define USB_OTG_SRP_VBUS (1 << SRPSEL)
-
- /** Mask for the Data + pulsing method of SRP, supported by some OTG devices.
- *
- * \see USB_OTG_DEV_Initiate_SRP()
- */
- #define USB_OTG_STP_DATA 0
-
- /* Pseudo-Function Macros: */
- #if defined(__DOXYGEN__)
- /** Initiate a Host Negotiation Protocol request. This indicates to the other connected device
- * that the device wishes to change device/host roles.
- */
- static inline void USB_OTG_Device_RequestHNP(void);
-
- /** Cancel a Host Negotiation Protocol request. This stops a pending HNP request to the other
- * connected device.
- */
- static inline void USB_OTG_Device_CancelHNPRequest(void);
-
- /** 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
- */
- static inline bool USB_OTG_Device_IsSendingHNP(void);
-
- /** Accepts a HNP from a connected device, indicating that both devices should exchange
- * device/host roles.
- */
- static inline void USB_OTG_Host_AcceptHNP(void);
-
- /** Rejects a HNP from a connected device, indicating that both devices should remain in their
- * current device/host roles.
- */
- static inline void USB_OTG_Host_RejectHNP(void);
-
- /** 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.
- */
- static inline bool USB_OTG_Host_IsHNPReceived(void);
-
- /** 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.
- *
- * There are two different methods of sending a SRP - either pulses on the VBUS line, or by
- * pulsing the Data + line via the internal pull-up resistor.
- *
- * \param[in] SRPTypeMask Mask indicating the type of SRP to use, either \ref USB_OTG_SRP_VBUS or \ref USB_OTG_STP_DATA.
- */
- static inline void USB_OTG_Dev_InitiateSRP(uint8_t SRPTypeMask);
- #else
- #define USB_OTG_Device_RequestHNP() MACROS{ OTGCON |= (1 << HNPREQ); }MACROE
-
- #define USB_OTG_Device_CancelHNPRequest() MACROS{ OTGCON &= ~(1 << HNPREQ); }MACROE
-
- #define USB_OTG_Device_IsSendingHNP() ((OTGCON & (1 << HNPREQ)) ? true : false)
-
- #define USB_OTG_Host_AcceptHNP() MACROS{ OTGCON |= (1 << HNPREQ); }MACROE
-
- #define USB_OTG_Host_RejectHNP() MACROS{ OTGCON &= ~(1 << HNPREQ); }MACROE
-
- #define USB_OTG_Host_IsHNPReceived() ((OTGCON & (1 << HNPREQ)) ? true : false)
-
- #define USB_OTG_Device_InitiateSRP(type) MACROS{ OTGCON = ((OTGCON & ~(1 << SRPSEL)) | ((type) | (1 << SRPREQ))); }MACROE
- #endif
-
-#endif
-
-/** @} */
+/*
+ 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 OTG mode definitions.
+ *
+ * This file contains structures, function prototypes and macros related to USB OTG mode, where two USB devices
+ * may be linked directly together and exchange host/device roles as needed.
+ *
+ * \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_OTG USB On The Go (OTG) Management
+ *
+ * This module contains macros for embedded USB hosts with dual role On The Go capabilities, for managing role
+ * exchange. OTG is a way for two USB dual role devices to talk to one another directly without fixed device/host
+ * roles.
+ *
+ * @{
+ */
+
+#ifndef __USBOTG_H__
+#define __USBOTG_H__
+
+ /* 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 USB_OTG_DEV_Initiate_SRP()
+ */
+ #define USB_OTG_SRP_VBUS (1 << SRPSEL)
+
+ /** Mask for the Data + pulsing method of SRP, supported by some OTG devices.
+ *
+ * \see USB_OTG_DEV_Initiate_SRP()
+ */
+ #define USB_OTG_STP_DATA 0
+
+ /* Pseudo-Function Macros: */
+ #if defined(__DOXYGEN__)
+ /** Initiate a Host Negotiation Protocol request. This indicates to the other connected device
+ * that the device wishes to change device/host roles.
+ */
+ static inline void USB_OTG_Device_RequestHNP(void);
+
+ /** Cancel a Host Negotiation Protocol request. This stops a pending HNP request to the other
+ * connected device.
+ */
+ static inline void USB_OTG_Device_CancelHNPRequest(void);
+
+ /** 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
+ */
+ static inline bool USB_OTG_Device_IsSendingHNP(void);
+
+ /** Accepts a HNP from a connected device, indicating that both devices should exchange
+ * device/host roles.
+ */
+ static inline void USB_OTG_Host_AcceptHNP(void);
+
+ /** Rejects a HNP from a connected device, indicating that both devices should remain in their
+ * current device/host roles.
+ */
+ static inline void USB_OTG_Host_RejectHNP(void);
+
+ /** 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.
+ */
+ static inline bool USB_OTG_Host_IsHNPReceived(void);
+
+ /** 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.
+ *
+ * There are two different methods of sending a SRP - either pulses on the VBUS line, or by
+ * pulsing the Data + line via the internal pull-up resistor.
+ *
+ * \param[in] SRPTypeMask Mask indicating the type of SRP to use, either \ref USB_OTG_SRP_VBUS or \ref USB_OTG_STP_DATA.
+ */
+ static inline void USB_OTG_Dev_InitiateSRP(uint8_t SRPTypeMask);
+ #else
+ #define USB_OTG_Device_RequestHNP() MACROS{ OTGCON |= (1 << HNPREQ); }MACROE
+
+ #define USB_OTG_Device_CancelHNPRequest() MACROS{ OTGCON &= ~(1 << HNPREQ); }MACROE
+
+ #define USB_OTG_Device_IsSendingHNP() ((OTGCON & (1 << HNPREQ)) ? true : false)
+
+ #define USB_OTG_Host_AcceptHNP() MACROS{ OTGCON |= (1 << HNPREQ); }MACROE
+
+ #define USB_OTG_Host_RejectHNP() MACROS{ OTGCON &= ~(1 << HNPREQ); }MACROE
+
+ #define USB_OTG_Host_IsHNPReceived() ((OTGCON & (1 << HNPREQ)) ? true : false)
+
+ #define USB_OTG_Device_InitiateSRP(type) MACROS{ OTGCON = ((OTGCON & ~(1 << SRPSEL)) | ((type) | (1 << SRPREQ))); }MACROE
+ #endif
+
+#endif
+
+/** @} */
diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.c b/LUFA/Drivers/USB/LowLevel/Pipe.c
index 8784bea0c..013193064 100644
--- a/LUFA/Drivers/USB/LowLevel/Pipe.c
+++ b/LUFA/Drivers/USB/LowLevel/Pipe.c
@@ -1,292 +1,292 @@
-/*
- 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_PIPE_C
-#include "Pipe.h"
-
-uint8_t USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
-
-bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber,
- const uint16_t Size, const uint8_t Banks)
-{
- Pipe_SelectPipe(Number);
- Pipe_EnablePipe();
-
- UPCFG1X = 0;
-
- UPCFG0X = ((Type << EPTYPE0) | Token | ((EndpointNumber & PIPE_EPNUM_MASK) << PEPNUM0));
- UPCFG1X = ((1 << ALLOC) | Banks | Pipe_BytesToEPSizeMask(Size));
-
- Pipe_SetInfiniteINRequests();
-
- return Pipe_IsConfigured();
-}
-
-void Pipe_ClearPipes(void)
-{
- UPINT = 0;
-
- for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)
- {
- Pipe_ResetPipe(PNum);
- Pipe_SelectPipe(PNum);
- UPIENX = 0;
- UPINTX = 0;
- Pipe_ClearError();
- Pipe_ClearErrorFlags();
- Pipe_DeallocateMemory();
- Pipe_DisablePipe();
- }
-}
-
-bool Pipe_IsEndpointBound(const uint8_t EndpointAddress)
-{
- uint8_t PrevPipeNumber = Pipe_GetCurrentPipe();
-
- for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)
- {
- Pipe_SelectPipe(PNum);
-
- 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 (Pipe_IsConfigured() && PipeTokenCorrect && (Pipe_BoundEndpointNumber() == (EndpointAddress & PIPE_EPNUM_MASK)))
- return true;
- }
-
- Pipe_SelectPipe(PrevPipeNumber);
- return false;
-}
-
-uint8_t Pipe_WaitUntilReady(void)
-{
- #if (USB_STREAM_TIMEOUT_MS < 0xFF)
- uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
- #else
- uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
- #endif
-
- for (;;)
- {
- if (Pipe_GetPipeToken() == PIPE_TOKEN_IN)
- {
- if (Pipe_IsINReceived())
- return PIPE_READYWAIT_NoError;
- }
- else
- {
- if (Pipe_IsOUTReady())
- return PIPE_READYWAIT_NoError;
- }
-
- if (Pipe_IsStalled())
- return PIPE_READYWAIT_PipeStalled;
- else if (USB_HostState == HOST_STATE_Unattached)
- return PIPE_READYWAIT_DeviceDisconnected;
-
- if (USB_INT_HasOccurred(USB_INT_HSOFI))
- {
- USB_INT_Clear(USB_INT_HSOFI);
-
- if (!(TimeoutMSRem--))
- return PIPE_READYWAIT_Timeout;
- }
- }
-}
-
-uint8_t Pipe_Discard_Stream(uint16_t Length
-#if !defined(NO_STREAM_CALLBACKS)
- , StreamCallbackPtr_t Callback
-#endif
- )
-{
- uint8_t ErrorCode;
-
- Pipe_SetPipeToken(PIPE_TOKEN_IN);
-
- if ((ErrorCode = Pipe_WaitUntilReady()))
- return ErrorCode;
-
- #if defined(FAST_STREAM_TRANSFERS)
- uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07);
-
- if (Length >= 8)
- {
- Length -= BytesRemToAlignment;
-
- switch (BytesRemToAlignment)
- {
- default:
- do
- {
- if (!(Pipe_IsReadWriteAllowed()))
- {
- Pipe_ClearIN();
-
- #if !defined(NO_STREAM_CALLBACKS)
- if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
- return PIPE_RWSTREAM_CallbackAborted;
- #endif
-
- if ((ErrorCode = Pipe_WaitUntilReady()))
- return ErrorCode;
- }
-
- Length -= 8;
-
- Pipe_Discard_Byte();
- case 7: Pipe_Discard_Byte();
- case 6: Pipe_Discard_Byte();
- case 5: Pipe_Discard_Byte();
- case 4: Pipe_Discard_Byte();
- case 3: Pipe_Discard_Byte();
- case 2: Pipe_Discard_Byte();
- case 1: Pipe_Discard_Byte();
- } while (Length >= 8);
- }
- }
- #endif
-
- while (Length)
- {
- if (!(Pipe_IsReadWriteAllowed()))
- {
- Pipe_ClearIN();
-
- #if !defined(NO_STREAM_CALLBACKS)
- if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
- return PIPE_RWSTREAM_CallbackAborted;
- #endif
-
- if ((ErrorCode = Pipe_WaitUntilReady()))
- return ErrorCode;
- }
- else
- {
- Pipe_Discard_Byte();
- Length--;
- }
- }
-
- return PIPE_RWSTREAM_NoError;
-}
-
-/* The following abuses the C preprocessor in order to copy-past common code with slight alterations,
- * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */
-
-#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_LE
-#define TEMPLATE_BUFFER_TYPE const void*
-#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*((uint8_t*)BufferPtr++))
-#include "Template/Template_Pipe_RW.c"
-
-#define TEMPLATE_FUNC_NAME Pipe_Write_PStream_LE
-#define TEMPLATE_BUFFER_TYPE const void*
-#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
-#include "Template/Template_Pipe_RW.c"
-
-#define TEMPLATE_FUNC_NAME Pipe_Write_EStream_LE
-#define TEMPLATE_BUFFER_TYPE const void*
-#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
-#include "Template/Template_Pipe_RW.c"
-
-#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_BE
-#define TEMPLATE_BUFFER_TYPE const void*
-#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*((uint8_t*)BufferPtr--))
-#include "Template/Template_Pipe_RW.c"
-
-#define TEMPLATE_FUNC_NAME Pipe_Write_PStream_BE
-#define TEMPLATE_BUFFER_TYPE const void*
-#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
-#include "Template/Template_Pipe_RW.c"
-
-#define TEMPLATE_FUNC_NAME Pipe_Write_EStream_BE
-#define TEMPLATE_BUFFER_TYPE const void*
-#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
-#include "Template/Template_Pipe_RW.c"
-
-#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_LE
-#define TEMPLATE_BUFFER_TYPE void*
-#define TEMPLATE_TOKEN PIPE_TOKEN_IN
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Pipe_Read_Byte()
-#include "Template/Template_Pipe_RW.c"
-
-#define TEMPLATE_FUNC_NAME Pipe_Read_EStream_LE
-#define TEMPLATE_BUFFER_TYPE void*
-#define TEMPLATE_TOKEN PIPE_TOKEN_IN
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
-#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte((uint8_t*)BufferPtr++, Pipe_Read_Byte())
-#include "Template/Template_Pipe_RW.c"
-
-#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_BE
-#define TEMPLATE_BUFFER_TYPE void*
-#define TEMPLATE_TOKEN PIPE_TOKEN_IN
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Pipe_Read_Byte()
-#include "Template/Template_Pipe_RW.c"
-
-#define TEMPLATE_FUNC_NAME Pipe_Read_EStream_BE
-#define TEMPLATE_BUFFER_TYPE void*
-#define TEMPLATE_TOKEN PIPE_TOKEN_IN
-#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
-#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte((uint8_t*)BufferPtr--, Pipe_Read_Byte())
-#include "Template/Template_Pipe_RW.c"
-
-#endif
+/*
+ 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_PIPE_C
+#include "Pipe.h"
+
+uint8_t USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
+
+bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber,
+ const uint16_t Size, const uint8_t Banks)
+{
+ Pipe_SelectPipe(Number);
+ Pipe_EnablePipe();
+
+ UPCFG1X = 0;
+
+ UPCFG0X = ((Type << EPTYPE0) | Token | ((EndpointNumber & PIPE_EPNUM_MASK) << PEPNUM0));
+ UPCFG1X = ((1 << ALLOC) | Banks | Pipe_BytesToEPSizeMask(Size));
+
+ Pipe_SetInfiniteINRequests();
+
+ return Pipe_IsConfigured();
+}
+
+void Pipe_ClearPipes(void)
+{
+ UPINT = 0;
+
+ for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)
+ {
+ Pipe_ResetPipe(PNum);
+ Pipe_SelectPipe(PNum);
+ UPIENX = 0;
+ UPINTX = 0;
+ Pipe_ClearError();
+ Pipe_ClearErrorFlags();
+ Pipe_DeallocateMemory();
+ Pipe_DisablePipe();
+ }
+}
+
+bool Pipe_IsEndpointBound(const uint8_t EndpointAddress)
+{
+ uint8_t PrevPipeNumber = Pipe_GetCurrentPipe();
+
+ for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)
+ {
+ Pipe_SelectPipe(PNum);
+
+ 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 (Pipe_IsConfigured() && PipeTokenCorrect && (Pipe_BoundEndpointNumber() == (EndpointAddress & PIPE_EPNUM_MASK)))
+ return true;
+ }
+
+ Pipe_SelectPipe(PrevPipeNumber);
+ return false;
+}
+
+uint8_t Pipe_WaitUntilReady(void)
+{
+ #if (USB_STREAM_TIMEOUT_MS < 0xFF)
+ uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
+ #else
+ uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
+ #endif
+
+ for (;;)
+ {
+ if (Pipe_GetPipeToken() == PIPE_TOKEN_IN)
+ {
+ if (Pipe_IsINReceived())
+ return PIPE_READYWAIT_NoError;
+ }
+ else
+ {
+ if (Pipe_IsOUTReady())
+ return PIPE_READYWAIT_NoError;
+ }
+
+ if (Pipe_IsStalled())
+ return PIPE_READYWAIT_PipeStalled;
+ else if (USB_HostState == HOST_STATE_Unattached)
+ return PIPE_READYWAIT_DeviceDisconnected;
+
+ if (USB_INT_HasOccurred(USB_INT_HSOFI))
+ {
+ USB_INT_Clear(USB_INT_HSOFI);
+
+ if (!(TimeoutMSRem--))
+ return PIPE_READYWAIT_Timeout;
+ }
+ }
+}
+
+uint8_t Pipe_Discard_Stream(uint16_t Length
+#if !defined(NO_STREAM_CALLBACKS)
+ , StreamCallbackPtr_t Callback
+#endif
+ )
+{
+ uint8_t ErrorCode;
+
+ Pipe_SetPipeToken(PIPE_TOKEN_IN);
+
+ if ((ErrorCode = Pipe_WaitUntilReady()))
+ return ErrorCode;
+
+ #if defined(FAST_STREAM_TRANSFERS)
+ uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07);
+
+ if (Length >= 8)
+ {
+ Length -= BytesRemToAlignment;
+
+ switch (BytesRemToAlignment)
+ {
+ default:
+ do
+ {
+ if (!(Pipe_IsReadWriteAllowed()))
+ {
+ Pipe_ClearIN();
+
+ #if !defined(NO_STREAM_CALLBACKS)
+ if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
+ return PIPE_RWSTREAM_CallbackAborted;
+ #endif
+
+ if ((ErrorCode = Pipe_WaitUntilReady()))
+ return ErrorCode;
+ }
+
+ Length -= 8;
+
+ Pipe_Discard_Byte();
+ case 7: Pipe_Discard_Byte();
+ case 6: Pipe_Discard_Byte();
+ case 5: Pipe_Discard_Byte();
+ case 4: Pipe_Discard_Byte();
+ case 3: Pipe_Discard_Byte();
+ case 2: Pipe_Discard_Byte();
+ case 1: Pipe_Discard_Byte();
+ } while (Length >= 8);
+ }
+ }
+ #endif
+
+ while (Length)
+ {
+ if (!(Pipe_IsReadWriteAllowed()))
+ {
+ Pipe_ClearIN();
+
+ #if !defined(NO_STREAM_CALLBACKS)
+ if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
+ return PIPE_RWSTREAM_CallbackAborted;
+ #endif
+
+ if ((ErrorCode = Pipe_WaitUntilReady()))
+ return ErrorCode;
+ }
+ else
+ {
+ Pipe_Discard_Byte();
+ Length--;
+ }
+ }
+
+ return PIPE_RWSTREAM_NoError;
+}
+
+/* The following abuses the C preprocessor in order to copy-past common code with slight alterations,
+ * so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */
+
+#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_LE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*((uint8_t*)BufferPtr++))
+#include "Template/Template_Pipe_RW.c"
+
+#define TEMPLATE_FUNC_NAME Pipe_Write_PStream_LE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
+#include "Template/Template_Pipe_RW.c"
+
+#define TEMPLATE_FUNC_NAME Pipe_Write_EStream_LE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
+#include "Template/Template_Pipe_RW.c"
+
+#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_BE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*((uint8_t*)BufferPtr--))
+#include "Template/Template_Pipe_RW.c"
+
+#define TEMPLATE_FUNC_NAME Pipe_Write_PStream_BE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
+#include "Template/Template_Pipe_RW.c"
+
+#define TEMPLATE_FUNC_NAME Pipe_Write_EStream_BE
+#define TEMPLATE_BUFFER_TYPE const void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
+#include "Template/Template_Pipe_RW.c"
+
+#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_LE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_IN
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Pipe_Read_Byte()
+#include "Template/Template_Pipe_RW.c"
+
+#define TEMPLATE_FUNC_NAME Pipe_Read_EStream_LE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_IN
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) 0
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte((uint8_t*)BufferPtr++, Pipe_Read_Byte())
+#include "Template/Template_Pipe_RW.c"
+
+#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_BE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_IN
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Pipe_Read_Byte()
+#include "Template/Template_Pipe_RW.c"
+
+#define TEMPLATE_FUNC_NAME Pipe_Read_EStream_BE
+#define TEMPLATE_BUFFER_TYPE void*
+#define TEMPLATE_TOKEN PIPE_TOKEN_IN
+#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
+#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte((uint8_t*)BufferPtr--, Pipe_Read_Byte())
+#include "Template/Template_Pipe_RW.c"
+
+#endif
diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.h b/LUFA/Drivers/USB/LowLevel/Pipe.h
index c16822b0d..02f882dc5 100644
--- a/LUFA/Drivers/USB/LowLevel/Pipe.h
+++ b/LUFA/Drivers/USB/LowLevel/Pipe.h
@@ -1,1065 +1,1065 @@
-/*
- 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 pipe management definitions.
- *
- * This file contains structures, function prototypes and macros related to the management of the device's
- * data pipes when the library is initialized 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.
- */
-
-/** \ingroup Group_USB
- * @defgroup Group_PipeManagement Pipe Management
- *
- * This module contains functions, macros and enums related to pipe management when in USB Host mode. This
- * module contains the pipe management macros, as well as pipe interrupt and data send/receive functions
- * for various data types.
- *
- * @{
- */
-
-/** @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
- * @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_PipeRW
- * @defgroup Group_PipeStreamRW Read/Write of Multi-Byte Streams
- *
- * Functions, macros, variables, enums and types related to data reading and writing of data streams from
- * and to pipes.
- */
-
-/** @defgroup Group_PipePacketManagement Pipe Packet Management
- *
- * Functions, macros, variables, enums and types related to packet management of pipes.
- */
-
-/** @defgroup Group_PipeControlReq Pipe Control Request Management
- *
- * Module for host mode request processing. This module allows for the transmission of standard, class and
- * 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.
- */
-
-#ifndef __PIPE_H__
-#define __PIPE_H__
-
- /* Includes: */
- #include <avr/io.h>
- #include <avr/pgmspace.h>
- #include <avr/eeprom.h>
- #include <stdbool.h>
-
- #include "../../../Common/Common.h"
- #include "../HighLevel/USBTask.h"
-
- #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
- #include "../HighLevel/StreamCallbacks.h"
- #endif
-
- /* 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: */
- /** Mask for \ref Pipe_GetErrorFlags(), indicating that an overflow error occurred in the pipe on the received data. */
- #define PIPE_ERRORFLAG_OVERFLOW (1 << 6)
-
- /** Mask for \ref Pipe_GetErrorFlags(), indicating that an underflow error occurred in the pipe on the received data. */
- #define PIPE_ERRORFLAG_UNDERFLOW (1 << 5)
-
- /** Mask for \ref Pipe_GetErrorFlags(), indicating that a CRC error occurred in the pipe on the received data. */
- #define PIPE_ERRORFLAG_CRC16 (1 << 4)
-
- /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware timeout error occurred in the pipe. */
- #define PIPE_ERRORFLAG_TIMEOUT (1 << 3)
-
- /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware PID error occurred in the pipe. */
- #define PIPE_ERRORFLAG_PID (1 << 2)
-
- /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data PID error occurred in the pipe. */
- #define PIPE_ERRORFLAG_DATAPID (1 << 1)
-
- /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data toggle error occurred in the pipe. */
- #define PIPE_ERRORFLAG_DATATGL (1 << 0)
-
- /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a SETUP token (for CONTROL type pipes),
- * which will trigger a control request on the attached device when data is written to the pipe.
- */
- #define PIPE_TOKEN_SETUP (0 << PTOKEN0)
-
- /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a IN token (for non-CONTROL type pipes),
- * indicating that the pipe data will flow from device to host.
- */
- #define PIPE_TOKEN_IN (1 << PTOKEN0)
-
- /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a OUT token (for non-CONTROL type pipes),
- * indicating that the pipe data will flow from host to device.
- */
- #define PIPE_TOKEN_OUT (2 << PTOKEN0)
-
- /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe
- * should have one single bank, which requires less USB FIFO memory but results in slower transfers as
- * only one USB device (the AVR or the attached device) can access the pipe's bank at the one time.
- */
- #define PIPE_BANK_SINGLE (0 << EPBK0)
-
- /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe
- * should have two banks, which requires more USB FIFO memory but results in faster transfers as one
- * USB device (the AVR or the attached device) can access one bank while the other accesses the second
- * 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
- * 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.
- */
- #define PIPE_PIPENUM_MASK 0x07
-
- /** Total number of pipes (including the default control pipe at address 0) which may be used in
- * the device. Different USB AVR models support different amounts of pipes, this value reflects
- * the maximum number of pipes for the currently selected AVR model.
- */
- #define PIPE_TOTAL_PIPES 7
-
- /** Size in bytes of the largest pipe bank size possible in the device. Not all banks on each AVR
- * model supports the largest bank size possible on the device; different pipe numbers support
- * different maximum bank sizes. This value reflects the largest possible bank of any pipe on the
- * currently selected USB AVR model.
- */
- #define PIPE_MAX_SIZE 256
-
- /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
- * numerical address in the attached device.
- */
- #define PIPE_EPNUM_MASK 0x0F
-
- /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
- * direction for comparing with the ENDPOINT_DESCRIPTOR_DIR_* masks.
- */
- #define PIPE_EPDIR_MASK 0x80
-
- /* Pseudo-Function Macros: */
- #if defined(__DOXYGEN__)
- /** Indicates the number of bytes currently stored in the current pipes's selected bank.
- *
- * \note The return width of this function may differ, depending on the maximum pipe bank size
- * of the selected AVR model.
- *
- * \ingroup Group_PipeRW
- *
- * \return Total number of bytes in the currently selected Pipe's FIFO buffer
- */
- static inline uint16_t Pipe_BytesInPipe(void);
-
- /** 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.
- *
- * \return Index of the currently selected pipe
- */
- static inline uint8_t Pipe_GetCurrentPipe(void);
-
- /** Selects the given pipe number. Any pipe operations which do not require the pipe number to be
- * indicated will operate on the currently selected pipe.
- *
- * \param[in] PipeNumber Index of the pipe to select
- */
- static inline void Pipe_SelectPipe(uint8_t PipeNumber);
-
- /** Resets the desired pipe, including the pipe banks and flags.
- *
- * \param[in] PipeNumber Index of the pipe to reset
- */
- static inline void Pipe_ResetPipe(uint8_t PipeNumber);
-
- /** Enables the currently selected pipe so that data can be sent and received through it to and from
- * an attached device.
- *
- * \note Pipes must first be configured properly via \ref Pipe_ConfigurePipe().
- */
- static inline void Pipe_EnablePipe(void);
-
- /** Disables the currently selected pipe so that data cannot be sent and received through it to and
- * from an attached device.
- */
- static inline void Pipe_DisablePipe(void);
-
- /** Determines if the currently selected pipe is enabled, but not necessarily configured.
- *
- * \return Boolean True if the currently selected pipe is enabled, false otherwise
- */
- static inline bool Pipe_IsEnabled(void);
-
- /** Gets the current pipe token, indicating the pipe's data direction and type.
- *
- * \return The current pipe token, as a PIPE_TOKEN_* mask
- */
- static inline uint8_t Pipe_GetPipeToken(void);
-
- /** 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
- * which have two endpoints of opposite direction sharing the same endpoint address within the device.
- *
- * \param[in] Token New pipe token to set the selected pipe to, as a PIPE_TOKEN_* mask
- */
- static inline void Pipe_SetPipeToken(uint8_t Token);
-
- /** Configures the currently selected pipe to allow for an unlimited number of IN requests. */
- static inline void Pipe_SetInfiniteINRequests(void);
-
- /** 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.
- *
- * \param[in] TotalINRequests Total number of IN requests that the pipe may receive before freezing
- */
- static inline void Pipe_SetFiniteINRequests(uint8_t TotalINRequests);
-
- /** Determines if the currently selected pipe is configured.
- *
- * \return Boolean true if the selected pipe is configured, false otherwise
- */
- static inline bool Pipe_IsConfigured(void);
-
- /** Retrieves the endpoint number of the endpoint within the attached device that the currently selected
- * pipe is bound to.
- *
- * \return Endpoint number the currently selected pipe is bound to
- */
- static inline uint8_t Pipe_BoundEndpointNumber(void);
-
- /** Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds.
- *
- * \param[in] Milliseconds Number of milliseconds between each pipe poll
- */
- static inline void Pipe_SetInterruptPeriod(uint8_t Milliseconds);
-
- /** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should
- * be serviced.
- *
- * \return Mask whose bits indicate which pipes have interrupted
- */
- static inline uint8_t Pipe_GetPipeInterrupts(void);
-
- /** Determines if the specified pipe number has interrupted (valid only for INTERRUPT type
- * pipes).
- *
- * \param[in] PipeNumber Index of the pipe whose interrupt flag should be tested
- *
- * \return Boolean true if the specified pipe has interrupted, false otherwise
- */
- static inline bool Pipe_HasPipeInterrupted(uint8_t PipeNumber);
-
- /** Unfreezes the selected pipe, allowing it to communicate with an attached device. */
- static inline void Pipe_Unfreeze(void);
-
- /** Freezes the selected pipe, preventing it from communicating with an attached device. */
- static inline void Pipe_Freeze(void);
-
- /** Determines if the currently selected pipe is frozen, and not able to accept data.
- *
- * \return Boolean true if the currently selected pipe is frozen, false otherwise
- */
- static inline bool Pipe_IsFrozen(void);
-
- /** Clears the master pipe error flag. */
- static inline void Pipe_ClearError(void);
-
- /** 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.
- *
- * \see \ref Pipe_GetErrorFlags() macro for information on retrieving the exact error flag.
- *
- * \return Boolean true if an error has occurred on the selected pipe, false otherwise
- */
- static inline bool Pipe_IsError(void);
-
- /** Clears all the currently selected pipe's hardware error flags, but does not clear the master error
- * flag for the pipe.
- */
- static inline void Pipe_ClearErrorFlags(void);
-
- /** 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.
- *
- * \return Mask comprising of PIPE_ERRORFLAG_* bits indicating what error has occurred on the selected pipe
- */
- static inline uint8_t Pipe_GetErrorFlags(void);
-
- /** 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
- * is an IN direction and no packet (or an empty packet) has been received, or if the pipe is an OUT
- * direction and the pipe bank is full.
- *
- * \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);
-
- /** Determines if an IN request has been received on the currently selected pipe.
- *
- * \ingroup Group_PipePacketManagement
- *
- * \return Boolean true if the current pipe has received an IN packet, false otherwise.
- */
- static inline bool Pipe_IsINReceived(void);
-
- /** Determines if the currently selected pipe is ready to send an OUT request.
- *
- * \ingroup Group_PipePacketManagement
- *
- * \return Boolean true if the current pipe is ready for an OUT packet, false otherwise.
- */
- static inline bool Pipe_IsOUTReady(void);
-
- /** Determines if no SETUP request is currently being sent to the attached device on the selected
- * CONTROL type pipe.
- *
- * \ingroup Group_PipePacketManagement
- *
- * \return Boolean true if the current pipe is ready for a SETUP packet, false otherwise.
- */
- static inline bool Pipe_IsSETUPSent(void);
-
- /** Sends the currently selected CONTROL type pipe's contents to the device as a SETUP packet.
- *
- * \ingroup Group_PipePacketManagement
- */
- static inline void Pipe_ClearSETUP(void);
-
- /** Acknowledges the reception of a setup IN request from the attached device on the currently selected
- * pipe, freeing the bank ready for the next packet.
- *
- * \ingroup Group_PipePacketManagement
- */
- static inline void Pipe_ClearIN(void);
-
- /** Sends the currently selected pipe's contents to the device as an OUT packet on the selected pipe, freeing
- * the bank ready for the next packet.
- *
- * \ingroup Group_PipePacketManagement
- */
- static inline void Pipe_ClearOUT(void);
-
- /** Determines if the device sent a NAK (Negative Acknowledge) in response to the last sent packet on
- * the currently selected pipe. This occurs when the host sends a packet to the device, but the device
- * is not currently ready to handle the packet (i.e. its endpoint banks are full). Once a NAK has been
- * received, it must be cleared using \ref Pipe_ClearNAKReceived() before the previous (or any other) packet
- * can be re-sent.
- *
- * \ingroup Group_PipePacketManagement
- *
- * \return Boolean true if an NAK has been received on the current pipe, false otherwise
- */
- static inline bool Pipe_IsNAKReceived(void);
-
- /** Clears the NAK condition on the currently selected pipe.
- *
- * \ingroup Group_PipePacketManagement
- *
- * \see \ref Pipe_IsNAKReceived() for more details.
- */
- static inline void Pipe_ClearNAKReceived(void);
-
- /** Determines if the currently selected pipe has had the STALL condition set by the attached device.
- *
- * \ingroup Group_PipePacketManagement
- *
- * \return Boolean true if the current pipe has been stalled by the attached device, false otherwise
- */
- static inline bool Pipe_IsStalled(void);
-
- /** 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).
- *
- * \ingroup Group_PipePacketManagement
- */
- static inline void Pipe_ClearStall(void);
- #else
- #define Pipe_BytesInPipe() UPBCX
-
- #define Pipe_GetCurrentPipe() (UPNUM & PIPE_PIPENUM_MASK)
-
- #define Pipe_SelectPipe(pipenum) MACROS{ UPNUM = (pipenum); }MACROE
-
- #define Pipe_ResetPipe(pipenum) MACROS{ UPRST = (1 << (pipenum)); UPRST = 0; }MACROE
-
- #define Pipe_EnablePipe() MACROS{ UPCONX |= (1 << PEN); }MACROE
-
- #define Pipe_DisablePipe() MACROS{ UPCONX &= ~(1 << PEN); }MACROE
-
- #define Pipe_IsEnabled() ((UPCONX & (1 << PEN)) ? true : false)
-
- #define Pipe_GetPipeToken() (UPCFG0X & PIPE_TOKEN_MASK)
-
- #define Pipe_SetPipeToken(token) MACROS{ UPCFG0X = ((UPCFG0X & ~PIPE_TOKEN_MASK) | (token)); }MACROE
-
- #define Pipe_SetInfiniteINRequests() MACROS{ UPCONX |= (1 << INMODE); }MACROE
-
- #define Pipe_SetFiniteINRequests(n) MACROS{ UPCONX &= ~(1 << INMODE); UPINRQX = (n); }MACROE
-
- #define Pipe_IsConfigured() ((UPSTAX & (1 << CFGOK)) ? true : false)
-
- #define Pipe_BoundEndpointNumber() ((UPCFG0X >> PEPNUM0) & PIPE_EPNUM_MASK)
-
- #define Pipe_SetInterruptPeriod(ms) MACROS{ UPCFG2X = (ms); }MACROE
-
- #define Pipe_GetPipeInterrupts() UPINT
-
- #define Pipe_HasPipeInterrupted(n) ((UPINT & (1 << (n))) ? true : false)
-
- #define Pipe_Unfreeze() MACROS{ UPCONX &= ~(1 << PFREEZE); }MACROE
-
- #define Pipe_Freeze() MACROS{ UPCONX |= (1 << PFREEZE); }MACROE
-
- #define Pipe_IsFrozen() ((UPCONX & (1 << PFREEZE)) ? true : false)
-
- #define Pipe_ClearError() MACROS{ UPINTX &= ~(1 << PERRI); }MACROE
-
- #define Pipe_IsError() ((UPINTX & (1 << PERRI)) ? true : false)
-
- #define Pipe_ClearErrorFlags() MACROS{ UPERRX = 0; }MACROE
-
- #define Pipe_GetErrorFlags() ((UPERRX & (PIPE_ERRORFLAG_CRC16 | PIPE_ERRORFLAG_TIMEOUT | \
- PIPE_ERRORFLAG_PID | PIPE_ERRORFLAG_DATAPID | \
- PIPE_ERRORFLAG_DATATGL)) | \
- (UPSTAX & PIPE_ERRORFLAG_OVERFLOW | PIPE_ERRORFLAG_UNDERFLOW))
-
- #define Pipe_IsReadWriteAllowed() ((UPINTX & (1 << RWAL)) ? true : false)
-
- #define Pipe_IsINReceived() ((UPINTX & (1 << RXINI)) ? true : false)
-
- #define Pipe_IsOUTReady() ((UPINTX & (1 << TXOUTI)) ? true : false)
-
- #define Pipe_IsSETUPSent() ((UPINTX & (1 << TXSTPI)) ? true : false)
-
- #define Pipe_ClearIN() MACROS{ UPINTX &= ~((1 << RXINI) | (1 << FIFOCON)); }MACROE
-
- #define Pipe_ClearOUT() MACROS{ UPINTX &= ~((1 << TXOUTI) | (1 << FIFOCON)); }MACROE
-
- #define Pipe_ClearSETUP() MACROS{ UPINTX &= ~((1 << TXSTPI) | (1 << FIFOCON)); }MACROE
-
- #define Pipe_IsNAKReceived() ((UPINTX & (1 << NAKEDI)) ? true : false)
-
- #define Pipe_ClearNAKReceived() MACROS{ UPINTX &= ~(1 << NAKEDI); }MACROE
-
- #define Pipe_IsStalled() ((UPINTX & (1 << RXSTALLI)) ? true : false)
-
- #define Pipe_ClearStall() MACROS{ UPINTX &= ~(1 << RXSTALLI); }MACROE
- #endif
-
- /* Enums: */
- /** Enum for the possible error return codes of the Pipe_WaitUntilReady function
- *
- * \ingroup Group_PipeRW
- */
- 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_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
- * \ref USB_STREAM_TIMEOUT_MS macro.
- */
- };
-
- /** Enum for the possible error return codes of the Pipe_*_Stream_* functions.
- *
- * \ingroup Group_PipeRW
- */
- enum Pipe_Stream_RW_ErrorCodes_t
- {
- PIPE_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
- PIPE_RWSTREAM_PipeStalled = 1, /**< The device stalled the pipe during the transfer. */
- PIPE_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
- * the transfer.
- */
- PIPE_RWSTREAM_Timeout = 3, /**< The device failed to accept or send the next packet
- * within the software timeout period set by the
- * \ref USB_STREAM_TIMEOUT_MS macro.
- */
- PIPE_RWSTREAM_CallbackAborted = 4, /**< Indicates that the stream's callback function aborted
- * the transfer early.
- */
- };
-
- /* Inline Functions: */
- /** Reads one byte from the currently selected pipe's bank, for OUT direction pipes.
- *
- * \ingroup Group_PipePrimitiveRW
- *
- * \return Next byte in the currently selected pipe's FIFO buffer
- */
- static inline uint8_t Pipe_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
- static inline uint8_t Pipe_Read_Byte(void)
- {
- return UPDATX;
- }
-
- /** Writes one byte from the currently selected pipe's bank, for IN direction pipes.
- *
- * \ingroup Group_PipePrimitiveRW
- *
- * \param[in] Byte Next byte to write into the the currently selected pipe's FIFO buffer
- */
- static inline void Pipe_Write_Byte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
- static inline void Pipe_Write_Byte(const uint8_t Byte)
- {
- UPDATX = Byte;
- }
-
- /** Discards one byte from the currently selected pipe's bank, for OUT direction pipes.
- *
- * \ingroup Group_PipePrimitiveRW
- */
- static inline void Pipe_Discard_Byte(void) ATTR_ALWAYS_INLINE;
- 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.
- *
- * \ingroup Group_PipePrimitiveRW
- *
- * \return Next word in the currently selected pipe's FIFO buffer
- */
- static inline uint16_t Pipe_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
- static inline uint16_t Pipe_Read_Word_LE(void)
- {
- union
- {
- uint16_t Word;
- uint8_t Bytes[2];
- } Data;
-
- Data.Bytes[0] = UPDATX;
- Data.Bytes[1] = UPDATX;
-
- return Data.Word;
- }
-
- /** Reads two bytes from the currently selected pipe's bank in big endian format, for OUT
- * direction pipes.
- *
- * \ingroup Group_PipePrimitiveRW
- *
- * \return Next word in the currently selected pipe's FIFO buffer
- */
- static inline uint16_t Pipe_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
- static inline uint16_t Pipe_Read_Word_BE(void)
- {
- union
- {
- 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.
- *
- * \ingroup Group_PipePrimitiveRW
- *
- * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer
- */
- static inline void Pipe_Write_Word_LE(const uint16_t Word) ATTR_ALWAYS_INLINE;
- static inline void Pipe_Write_Word_LE(const uint16_t Word)
- {
- UPDATX = (Word & 0xFF);
- UPDATX = (Word >> 8);
- }
-
- /** Writes two bytes to the currently selected pipe's bank in big endian format, for IN
- * direction pipes.
- *
- * \ingroup Group_PipePrimitiveRW
- *
- * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer
- */
- static inline void Pipe_Write_Word_BE(const uint16_t Word) ATTR_ALWAYS_INLINE;
- static inline void Pipe_Write_Word_BE(const uint16_t Word)
- {
- UPDATX = (Word >> 8);
- UPDATX = (Word & 0xFF);
- }
-
- /** Discards two bytes from the currently selected pipe's bank, for OUT direction pipes.
- *
- * \ingroup Group_PipePrimitiveRW
- */
- static inline void Pipe_Discard_Word(void) ATTR_ALWAYS_INLINE;
- static inline void Pipe_Discard_Word(void)
- {
- uint8_t Dummy;
-
- Dummy = UPDATX;
- Dummy = UPDATX;
- }
-
- /** Reads four bytes from the currently selected pipe's bank in little endian format, for OUT
- * direction pipes.
- *
- * \ingroup Group_PipePrimitiveRW
- *
- * \return Next double word in the currently selected pipe's FIFO buffer
- */
- static inline uint32_t Pipe_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
- static inline uint32_t Pipe_Read_DWord_LE(void)
- {
- union
- {
- 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;
- }
-
- /** Reads four bytes from the currently selected pipe's bank in big endian format, for OUT
- * direction pipes.
- *
- * \ingroup Group_PipePrimitiveRW
- *
- * \return Next double word in the currently selected pipe's FIFO buffer
- */
- static inline uint32_t Pipe_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
- static inline uint32_t Pipe_Read_DWord_BE(void)
- {
- union
- {
- 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;
- }
-
- /** Writes four bytes to the currently selected pipe's bank in little endian format, for IN
- * direction pipes.
- *
- * \ingroup Group_PipePrimitiveRW
- *
- * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer
- */
- static inline void Pipe_Write_DWord_LE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
- static inline void Pipe_Write_DWord_LE(const uint32_t DWord)
- {
- UPDATX = (DWord & 0xFF);
- UPDATX = (DWord >> 8);
- UPDATX = (DWord >> 16);
- UPDATX = (DWord >> 24);
- }
-
- /** Writes four bytes to the currently selected pipe's bank in big endian format, for IN
- * direction pipes.
- *
- * \ingroup Group_PipePrimitiveRW
- *
- * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer
- */
- static inline void Pipe_Write_DWord_BE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
- static inline void Pipe_Write_DWord_BE(const uint32_t DWord)
- {
- UPDATX = (DWord >> 24);
- UPDATX = (DWord >> 16);
- UPDATX = (DWord >> 8);
- UPDATX = (DWord & 0xFF);
- }
-
- /** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes.
- *
- * \ingroup Group_PipePrimitiveRW
- */
- static inline void Pipe_Discard_DWord(void) ATTR_ALWAYS_INLINE;
- static inline void Pipe_Discard_DWord(void)
- {
- uint8_t Dummy;
-
- Dummy = UPDATX;
- Dummy = UPDATX;
- Dummy = UPDATX;
- Dummy = UPDATX;
- }
-
- /* External Variables: */
- /** Global indicating the maximum packet size of the default control pipe located at address
- * 0 in the device. This value is set to the value indicated in the attached device's device
- * descriptor once the USB interface is initialized into host mode and a device is attached
- * to the USB bus.
- *
- * \note This variable should be treated as read-only in the user application, and never manually
- * changed in value.
- */
- extern uint8_t USB_ControlPipeSize;
-
- /* Function Prototypes: */
- #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
- #define __CALLBACK_PARAM , StreamCallbackPtr_t Callback
- #else
- #define __CALLBACK_PARAM
- #endif
-
- /** Configures the specified pipe number with the given pipe type, token, target endpoint number in the
- * attached device, bank size and banking mode. Pipes should be allocated in ascending order by their
- * address in the device (i.e. pipe 1 should be configured before pipe 2 and so on) to prevent fragmentation
- * of the USB FIFO memory.
- *
- * The pipe type may be one of the EP_TYPE_* macros listed in LowLevel.h, the token may be one of the
- * PIPE_TOKEN_* masks.
- *
- * The bank size must indicate the maximum packet size that the pipe can handle. Different pipe
- * numbers can handle different maximum packet sizes - refer to the chosen USB AVR's datasheet to
- * determine the maximum bank size for each pipe.
- *
- * The banking mode may be either \ref PIPE_BANK_SINGLE or \ref PIPE_BANK_DOUBLE.
- *
- * A newly configured pipe is frozen by default, and must be unfrozen before use via the \ref Pipe_Unfreeze()
- * before being used. Pipes should be kept frozen unless waiting for data from a device while in IN mode, or
- * sending data to the device in OUT mode. IN type pipes are also automatically configured to accept infinite
- * numbers of IN requests without automatic freezing - this can be overridden by a call to
- * \ref Pipe_SetFiniteINRequests().
- *
- * \note The default control pipe does not have to be manually configured, as it is automatically
- * configured by the library internally.
- * \n\n
- *
- * \note This routine will select the specified pipe, and the pipe will remain selected once the
- * routine completes regardless of if the pipe configuration succeeds.
- *
- * \return Boolean true if the configuration is successful, false otherwise
- */
- bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber,
- 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
- * or written to it, aborting in the case of an error condition (such as a timeout or device disconnect).
- *
- * \ingroup Group_PipeRW
- *
- * \return A value from the 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.
- *
- * \param[in] EndpointAddress Address and direction mask of the endpoint within the attached device to check
- *
- * \return Boolean true if a pipe bound to the given endpoint address of the specified direction is found, false
- * otherwise
- */
- bool Pipe_IsEndpointBound(const uint8_t EndpointAddress);
-
- /** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host
- * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the
- * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearIN() macro.
- * Between each USB packet, the given stream callback function is executed repeatedly until the next packet is ready,
- * allowing for early aborts of stream transfers.
- *
- * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
- * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
- * disabled and this function has the Callback parameter omitted.
- *
- * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
- *
- * \ingroup Group_PipeStreamRW
- *
- * \param[in] Length Number of bytes to send via the currently selected pipe.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Pipe_Discard_Stream(uint16_t Length __CALLBACK_PARAM);
-
- /** Writes the given number of bytes to the pipe from the given buffer in little endian,
- * sending full packets to the device as needed. The last packet filled is not automatically sent;
- * the user is responsible for manually sending the last written packet to the host via the
- * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
- * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
- *
- * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
- * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
- * disabled and this function has the Callback parameter omitted.
- *
- * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
- *
- * \ingroup Group_PipeStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Pipe_Write_Stream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** EEPROM buffer source version of \ref Pipe_Write_Stream_LE().
- *
- * \ingroup Group_PipeStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Pipe_Write_EStream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** FLASH buffer source version of \ref Pipe_Write_Stream_LE().
- *
- * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
- *
- * \ingroup Group_PipeStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Pipe_Write_PStream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** Writes the given number of bytes to the pipe from the given buffer in big endian,
- * sending full packets to the device as needed. The last packet filled is not automatically sent;
- * the user is responsible for manually sending the last written packet to the host via the
- * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
- * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
- *
- * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
- * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
- * disabled and this function has the Callback parameter omitted.
- *
- * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
- *
- * \ingroup Group_PipeStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Pipe_Write_Stream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** EEPROM buffer source version of \ref Pipe_Write_Stream_BE().
- *
- * \ingroup Group_PipeStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Pipe_Write_EStream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** FLASH buffer source version of \ref Pipe_Write_Stream_BE().
- *
- * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
- *
- * \ingroup Group_PipeStreamRW
- *
- * \param[in] Buffer Pointer to the source data buffer to read from.
- * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Pipe_Write_PStream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** Reads the given number of bytes from the pipe into the given buffer in little endian,
- * sending full packets to the device as needed. The last packet filled is not automatically sent;
- * the user is responsible for manually sending the last written packet to the host via the
- * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
- * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
- *
- * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
- * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
- * disabled and this function has the Callback parameter omitted.
- *
- * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
- *
- * \ingroup Group_PipeStreamRW
- *
- * \param[out] Buffer Pointer to the source data buffer to write to.
- * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** EEPROM buffer source version of \ref Pipe_Read_Stream_LE().
- *
- * \ingroup Group_PipeStreamRW
- *
- * \param[out] Buffer Pointer to the source data buffer to write to.
- * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Pipe_Read_EStream_LE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** Reads the given number of bytes from the pipe into the given buffer in big endian,
- * sending full packets to the device as needed. The last packet filled is not automatically sent;
- * the user is responsible for manually sending the last written packet to the host via the
- * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
- * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
- *
- * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
- * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
- * disabled and this function has the Callback parameter omitted.
- *
- * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
- * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
- *
- * \ingroup Group_PipeStreamRW
- *
- * \param[out] Buffer Pointer to the source data buffer to write to.
- * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /** EEPROM buffer source version of \ref Pipe_Read_Stream_BE().
- *
- * \ingroup Group_PipeStreamRW
- *
- * \param[out] Buffer Pointer to the source data buffer to write to.
- * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
- * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
- *
- * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
- */
- uint8_t Pipe_Read_EStream_BE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
-
- /* Private Interface - For use in library only: */
- #if !defined(__DOXYGEN__)
- /* Macros: */
- #define PIPE_TOKEN_MASK (0x03 << PTOKEN0)
-
- #if !defined(ENDPOINT_CONTROLEP)
- #define ENDPOINT_CONTROLEP 0
- #endif
-
- #define Pipe_AllocateMemory() MACROS{ UPCFG1X |= (1 << ALLOC); }MACROE
- #define Pipe_DeallocateMemory() MACROS{ UPCFG1X &= ~(1 << ALLOC); }MACROE
-
- /* Function Prototypes: */
- void Pipe_ClearPipes(void);
-
- /* Inline Functions: */
- static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;
- static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes)
- {
- if (Bytes <= 8)
- return (0 << EPSIZE0);
- else if (Bytes <= 16)
- return (1 << EPSIZE0);
- else if (Bytes <= 32)
- return (2 << EPSIZE0);
- else if (Bytes <= 64)
- return (3 << EPSIZE0);
- else if (Bytes <= 128)
- return (4 << EPSIZE0);
- else
- return (5 << EPSIZE0);
- }
-
- #endif
-
- /* Disable C linkage for C++ Compilers: */
- #if defined(__cplusplus)
- }
- #endif
-
-#endif
-
-/** @} */
+/*
+ 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 pipe management definitions.
+ *
+ * This file contains structures, function prototypes and macros related to the management of the device's
+ * data pipes when the library is initialized 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.
+ */
+
+/** \ingroup Group_USB
+ * @defgroup Group_PipeManagement Pipe Management
+ *
+ * This module contains functions, macros and enums related to pipe management when in USB Host mode. This
+ * module contains the pipe management macros, as well as pipe interrupt and data send/receive functions
+ * for various data types.
+ *
+ * @{
+ */
+
+/** @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
+ * @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_PipeRW
+ * @defgroup Group_PipeStreamRW Read/Write of Multi-Byte Streams
+ *
+ * Functions, macros, variables, enums and types related to data reading and writing of data streams from
+ * and to pipes.
+ */
+
+/** @defgroup Group_PipePacketManagement Pipe Packet Management
+ *
+ * Functions, macros, variables, enums and types related to packet management of pipes.
+ */
+
+/** @defgroup Group_PipeControlReq Pipe Control Request Management
+ *
+ * Module for host mode request processing. This module allows for the transmission of standard, class and
+ * 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.
+ */
+
+#ifndef __PIPE_H__
+#define __PIPE_H__
+
+ /* Includes: */
+ #include <avr/io.h>
+ #include <avr/pgmspace.h>
+ #include <avr/eeprom.h>
+ #include <stdbool.h>
+
+ #include "../../../Common/Common.h"
+ #include "../HighLevel/USBTask.h"
+
+ #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
+ #include "../HighLevel/StreamCallbacks.h"
+ #endif
+
+ /* 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: */
+ /** Mask for \ref Pipe_GetErrorFlags(), indicating that an overflow error occurred in the pipe on the received data. */
+ #define PIPE_ERRORFLAG_OVERFLOW (1 << 6)
+
+ /** Mask for \ref Pipe_GetErrorFlags(), indicating that an underflow error occurred in the pipe on the received data. */
+ #define PIPE_ERRORFLAG_UNDERFLOW (1 << 5)
+
+ /** Mask for \ref Pipe_GetErrorFlags(), indicating that a CRC error occurred in the pipe on the received data. */
+ #define PIPE_ERRORFLAG_CRC16 (1 << 4)
+
+ /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware timeout error occurred in the pipe. */
+ #define PIPE_ERRORFLAG_TIMEOUT (1 << 3)
+
+ /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware PID error occurred in the pipe. */
+ #define PIPE_ERRORFLAG_PID (1 << 2)
+
+ /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data PID error occurred in the pipe. */
+ #define PIPE_ERRORFLAG_DATAPID (1 << 1)
+
+ /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data toggle error occurred in the pipe. */
+ #define PIPE_ERRORFLAG_DATATGL (1 << 0)
+
+ /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a SETUP token (for CONTROL type pipes),
+ * which will trigger a control request on the attached device when data is written to the pipe.
+ */
+ #define PIPE_TOKEN_SETUP (0 << PTOKEN0)
+
+ /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a IN token (for non-CONTROL type pipes),
+ * indicating that the pipe data will flow from device to host.
+ */
+ #define PIPE_TOKEN_IN (1 << PTOKEN0)
+
+ /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a OUT token (for non-CONTROL type pipes),
+ * indicating that the pipe data will flow from host to device.
+ */
+ #define PIPE_TOKEN_OUT (2 << PTOKEN0)
+
+ /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe
+ * should have one single bank, which requires less USB FIFO memory but results in slower transfers as
+ * only one USB device (the AVR or the attached device) can access the pipe's bank at the one time.
+ */
+ #define PIPE_BANK_SINGLE (0 << EPBK0)
+
+ /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe
+ * should have two banks, which requires more USB FIFO memory but results in faster transfers as one
+ * USB device (the AVR or the attached device) can access one bank while the other accesses the second
+ * 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
+ * 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.
+ */
+ #define PIPE_PIPENUM_MASK 0x07
+
+ /** Total number of pipes (including the default control pipe at address 0) which may be used in
+ * the device. Different USB AVR models support different amounts of pipes, this value reflects
+ * the maximum number of pipes for the currently selected AVR model.
+ */
+ #define PIPE_TOTAL_PIPES 7
+
+ /** Size in bytes of the largest pipe bank size possible in the device. Not all banks on each AVR
+ * model supports the largest bank size possible on the device; different pipe numbers support
+ * different maximum bank sizes. This value reflects the largest possible bank of any pipe on the
+ * currently selected USB AVR model.
+ */
+ #define PIPE_MAX_SIZE 256
+
+ /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
+ * numerical address in the attached device.
+ */
+ #define PIPE_EPNUM_MASK 0x0F
+
+ /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
+ * direction for comparing with the ENDPOINT_DESCRIPTOR_DIR_* masks.
+ */
+ #define PIPE_EPDIR_MASK 0x80
+
+ /* Pseudo-Function Macros: */
+ #if defined(__DOXYGEN__)
+ /** Indicates the number of bytes currently stored in the current pipes's selected bank.
+ *
+ * \note The return width of this function may differ, depending on the maximum pipe bank size
+ * of the selected AVR model.
+ *
+ * \ingroup Group_PipeRW
+ *
+ * \return Total number of bytes in the currently selected Pipe's FIFO buffer
+ */
+ static inline uint16_t Pipe_BytesInPipe(void);
+
+ /** 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.
+ *
+ * \return Index of the currently selected pipe
+ */
+ static inline uint8_t Pipe_GetCurrentPipe(void);
+
+ /** Selects the given pipe number. Any pipe operations which do not require the pipe number to be
+ * indicated will operate on the currently selected pipe.
+ *
+ * \param[in] PipeNumber Index of the pipe to select
+ */
+ static inline void Pipe_SelectPipe(uint8_t PipeNumber);
+
+ /** Resets the desired pipe, including the pipe banks and flags.
+ *
+ * \param[in] PipeNumber Index of the pipe to reset
+ */
+ static inline void Pipe_ResetPipe(uint8_t PipeNumber);
+
+ /** Enables the currently selected pipe so that data can be sent and received through it to and from
+ * an attached device.
+ *
+ * \note Pipes must first be configured properly via \ref Pipe_ConfigurePipe().
+ */
+ static inline void Pipe_EnablePipe(void);
+
+ /** Disables the currently selected pipe so that data cannot be sent and received through it to and
+ * from an attached device.
+ */
+ static inline void Pipe_DisablePipe(void);
+
+ /** Determines if the currently selected pipe is enabled, but not necessarily configured.
+ *
+ * \return Boolean True if the currently selected pipe is enabled, false otherwise
+ */
+ static inline bool Pipe_IsEnabled(void);
+
+ /** Gets the current pipe token, indicating the pipe's data direction and type.
+ *
+ * \return The current pipe token, as a PIPE_TOKEN_* mask
+ */
+ static inline uint8_t Pipe_GetPipeToken(void);
+
+ /** 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
+ * which have two endpoints of opposite direction sharing the same endpoint address within the device.
+ *
+ * \param[in] Token New pipe token to set the selected pipe to, as a PIPE_TOKEN_* mask
+ */
+ static inline void Pipe_SetPipeToken(uint8_t Token);
+
+ /** Configures the currently selected pipe to allow for an unlimited number of IN requests. */
+ static inline void Pipe_SetInfiniteINRequests(void);
+
+ /** 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.
+ *
+ * \param[in] TotalINRequests Total number of IN requests that the pipe may receive before freezing
+ */
+ static inline void Pipe_SetFiniteINRequests(uint8_t TotalINRequests);
+
+ /** Determines if the currently selected pipe is configured.
+ *
+ * \return Boolean true if the selected pipe is configured, false otherwise
+ */
+ static inline bool Pipe_IsConfigured(void);
+
+ /** Retrieves the endpoint number of the endpoint within the attached device that the currently selected
+ * pipe is bound to.
+ *
+ * \return Endpoint number the currently selected pipe is bound to
+ */
+ static inline uint8_t Pipe_BoundEndpointNumber(void);
+
+ /** Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds.
+ *
+ * \param[in] Milliseconds Number of milliseconds between each pipe poll
+ */
+ static inline void Pipe_SetInterruptPeriod(uint8_t Milliseconds);
+
+ /** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should
+ * be serviced.
+ *
+ * \return Mask whose bits indicate which pipes have interrupted
+ */
+ static inline uint8_t Pipe_GetPipeInterrupts(void);
+
+ /** Determines if the specified pipe number has interrupted (valid only for INTERRUPT type
+ * pipes).
+ *
+ * \param[in] PipeNumber Index of the pipe whose interrupt flag should be tested
+ *
+ * \return Boolean true if the specified pipe has interrupted, false otherwise
+ */
+ static inline bool Pipe_HasPipeInterrupted(uint8_t PipeNumber);
+
+ /** Unfreezes the selected pipe, allowing it to communicate with an attached device. */
+ static inline void Pipe_Unfreeze(void);
+
+ /** Freezes the selected pipe, preventing it from communicating with an attached device. */
+ static inline void Pipe_Freeze(void);
+
+ /** Determines if the currently selected pipe is frozen, and not able to accept data.
+ *
+ * \return Boolean true if the currently selected pipe is frozen, false otherwise
+ */
+ static inline bool Pipe_IsFrozen(void);
+
+ /** Clears the master pipe error flag. */
+ static inline void Pipe_ClearError(void);
+
+ /** 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.
+ *
+ * \see \ref Pipe_GetErrorFlags() macro for information on retrieving the exact error flag.
+ *
+ * \return Boolean true if an error has occurred on the selected pipe, false otherwise
+ */
+ static inline bool Pipe_IsError(void);
+
+ /** Clears all the currently selected pipe's hardware error flags, but does not clear the master error
+ * flag for the pipe.
+ */
+ static inline void Pipe_ClearErrorFlags(void);
+
+ /** 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.
+ *
+ * \return Mask comprising of PIPE_ERRORFLAG_* bits indicating what error has occurred on the selected pipe
+ */
+ static inline uint8_t Pipe_GetErrorFlags(void);
+
+ /** 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
+ * is an IN direction and no packet (or an empty packet) has been received, or if the pipe is an OUT
+ * direction and the pipe bank is full.
+ *
+ * \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);
+
+ /** Determines if an IN request has been received on the currently selected pipe.
+ *
+ * \ingroup Group_PipePacketManagement
+ *
+ * \return Boolean true if the current pipe has received an IN packet, false otherwise.
+ */
+ static inline bool Pipe_IsINReceived(void);
+
+ /** Determines if the currently selected pipe is ready to send an OUT request.
+ *
+ * \ingroup Group_PipePacketManagement
+ *
+ * \return Boolean true if the current pipe is ready for an OUT packet, false otherwise.
+ */
+ static inline bool Pipe_IsOUTReady(void);
+
+ /** Determines if no SETUP request is currently being sent to the attached device on the selected
+ * CONTROL type pipe.
+ *
+ * \ingroup Group_PipePacketManagement
+ *
+ * \return Boolean true if the current pipe is ready for a SETUP packet, false otherwise.
+ */
+ static inline bool Pipe_IsSETUPSent(void);
+
+ /** Sends the currently selected CONTROL type pipe's contents to the device as a SETUP packet.
+ *
+ * \ingroup Group_PipePacketManagement
+ */
+ static inline void Pipe_ClearSETUP(void);
+
+ /** Acknowledges the reception of a setup IN request from the attached device on the currently selected
+ * pipe, freeing the bank ready for the next packet.
+ *
+ * \ingroup Group_PipePacketManagement
+ */
+ static inline void Pipe_ClearIN(void);
+
+ /** Sends the currently selected pipe's contents to the device as an OUT packet on the selected pipe, freeing
+ * the bank ready for the next packet.
+ *
+ * \ingroup Group_PipePacketManagement
+ */
+ static inline void Pipe_ClearOUT(void);
+
+ /** Determines if the device sent a NAK (Negative Acknowledge) in response to the last sent packet on
+ * the currently selected pipe. This occurs when the host sends a packet to the device, but the device
+ * is not currently ready to handle the packet (i.e. its endpoint banks are full). Once a NAK has been
+ * received, it must be cleared using \ref Pipe_ClearNAKReceived() before the previous (or any other) packet
+ * can be re-sent.
+ *
+ * \ingroup Group_PipePacketManagement
+ *
+ * \return Boolean true if an NAK has been received on the current pipe, false otherwise
+ */
+ static inline bool Pipe_IsNAKReceived(void);
+
+ /** Clears the NAK condition on the currently selected pipe.
+ *
+ * \ingroup Group_PipePacketManagement
+ *
+ * \see \ref Pipe_IsNAKReceived() for more details.
+ */
+ static inline void Pipe_ClearNAKReceived(void);
+
+ /** Determines if the currently selected pipe has had the STALL condition set by the attached device.
+ *
+ * \ingroup Group_PipePacketManagement
+ *
+ * \return Boolean true if the current pipe has been stalled by the attached device, false otherwise
+ */
+ static inline bool Pipe_IsStalled(void);
+
+ /** 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).
+ *
+ * \ingroup Group_PipePacketManagement
+ */
+ static inline void Pipe_ClearStall(void);
+ #else
+ #define Pipe_BytesInPipe() UPBCX
+
+ #define Pipe_GetCurrentPipe() (UPNUM & PIPE_PIPENUM_MASK)
+
+ #define Pipe_SelectPipe(pipenum) MACROS{ UPNUM = (pipenum); }MACROE
+
+ #define Pipe_ResetPipe(pipenum) MACROS{ UPRST = (1 << (pipenum)); UPRST = 0; }MACROE
+
+ #define Pipe_EnablePipe() MACROS{ UPCONX |= (1 << PEN); }MACROE
+
+ #define Pipe_DisablePipe() MACROS{ UPCONX &= ~(1 << PEN); }MACROE
+
+ #define Pipe_IsEnabled() ((UPCONX & (1 << PEN)) ? true : false)
+
+ #define Pipe_GetPipeToken() (UPCFG0X & PIPE_TOKEN_MASK)
+
+ #define Pipe_SetPipeToken(token) MACROS{ UPCFG0X = ((UPCFG0X & ~PIPE_TOKEN_MASK) | (token)); }MACROE
+
+ #define Pipe_SetInfiniteINRequests() MACROS{ UPCONX |= (1 << INMODE); }MACROE
+
+ #define Pipe_SetFiniteINRequests(n) MACROS{ UPCONX &= ~(1 << INMODE); UPINRQX = (n); }MACROE
+
+ #define Pipe_IsConfigured() ((UPSTAX & (1 << CFGOK)) ? true : false)
+
+ #define Pipe_BoundEndpointNumber() ((UPCFG0X >> PEPNUM0) & PIPE_EPNUM_MASK)
+
+ #define Pipe_SetInterruptPeriod(ms) MACROS{ UPCFG2X = (ms); }MACROE
+
+ #define Pipe_GetPipeInterrupts() UPINT
+
+ #define Pipe_HasPipeInterrupted(n) ((UPINT & (1 << (n))) ? true : false)
+
+ #define Pipe_Unfreeze() MACROS{ UPCONX &= ~(1 << PFREEZE); }MACROE
+
+ #define Pipe_Freeze() MACROS{ UPCONX |= (1 << PFREEZE); }MACROE
+
+ #define Pipe_IsFrozen() ((UPCONX & (1 << PFREEZE)) ? true : false)
+
+ #define Pipe_ClearError() MACROS{ UPINTX &= ~(1 << PERRI); }MACROE
+
+ #define Pipe_IsError() ((UPINTX & (1 << PERRI)) ? true : false)
+
+ #define Pipe_ClearErrorFlags() MACROS{ UPERRX = 0; }MACROE
+
+ #define Pipe_GetErrorFlags() ((UPERRX & (PIPE_ERRORFLAG_CRC16 | PIPE_ERRORFLAG_TIMEOUT | \
+ PIPE_ERRORFLAG_PID | PIPE_ERRORFLAG_DATAPID | \
+ PIPE_ERRORFLAG_DATATGL)) | \
+ (UPSTAX & PIPE_ERRORFLAG_OVERFLOW | PIPE_ERRORFLAG_UNDERFLOW))
+
+ #define Pipe_IsReadWriteAllowed() ((UPINTX & (1 << RWAL)) ? true : false)
+
+ #define Pipe_IsINReceived() ((UPINTX & (1 << RXINI)) ? true : false)
+
+ #define Pipe_IsOUTReady() ((UPINTX & (1 << TXOUTI)) ? true : false)
+
+ #define Pipe_IsSETUPSent() ((UPINTX & (1 << TXSTPI)) ? true : false)
+
+ #define Pipe_ClearIN() MACROS{ UPINTX &= ~((1 << RXINI) | (1 << FIFOCON)); }MACROE
+
+ #define Pipe_ClearOUT() MACROS{ UPINTX &= ~((1 << TXOUTI) | (1 << FIFOCON)); }MACROE
+
+ #define Pipe_ClearSETUP() MACROS{ UPINTX &= ~((1 << TXSTPI) | (1 << FIFOCON)); }MACROE
+
+ #define Pipe_IsNAKReceived() ((UPINTX & (1 << NAKEDI)) ? true : false)
+
+ #define Pipe_ClearNAKReceived() MACROS{ UPINTX &= ~(1 << NAKEDI); }MACROE
+
+ #define Pipe_IsStalled() ((UPINTX & (1 << RXSTALLI)) ? true : false)
+
+ #define Pipe_ClearStall() MACROS{ UPINTX &= ~(1 << RXSTALLI); }MACROE
+ #endif
+
+ /* Enums: */
+ /** Enum for the possible error return codes of the Pipe_WaitUntilReady function
+ *
+ * \ingroup Group_PipeRW
+ */
+ 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_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
+ * \ref USB_STREAM_TIMEOUT_MS macro.
+ */
+ };
+
+ /** Enum for the possible error return codes of the Pipe_*_Stream_* functions.
+ *
+ * \ingroup Group_PipeRW
+ */
+ enum Pipe_Stream_RW_ErrorCodes_t
+ {
+ PIPE_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
+ PIPE_RWSTREAM_PipeStalled = 1, /**< The device stalled the pipe during the transfer. */
+ PIPE_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
+ * the transfer.
+ */
+ PIPE_RWSTREAM_Timeout = 3, /**< The device failed to accept or send the next packet
+ * within the software timeout period set by the
+ * \ref USB_STREAM_TIMEOUT_MS macro.
+ */
+ PIPE_RWSTREAM_CallbackAborted = 4, /**< Indicates that the stream's callback function aborted
+ * the transfer early.
+ */
+ };
+
+ /* Inline Functions: */
+ /** Reads one byte from the currently selected pipe's bank, for OUT direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW
+ *
+ * \return Next byte in the currently selected pipe's FIFO buffer
+ */
+ static inline uint8_t Pipe_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint8_t Pipe_Read_Byte(void)
+ {
+ return UPDATX;
+ }
+
+ /** Writes one byte from the currently selected pipe's bank, for IN direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW
+ *
+ * \param[in] Byte Next byte to write into the the currently selected pipe's FIFO buffer
+ */
+ static inline void Pipe_Write_Byte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Write_Byte(const uint8_t Byte)
+ {
+ UPDATX = Byte;
+ }
+
+ /** Discards one byte from the currently selected pipe's bank, for OUT direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW
+ */
+ static inline void Pipe_Discard_Byte(void) ATTR_ALWAYS_INLINE;
+ 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.
+ *
+ * \ingroup Group_PipePrimitiveRW
+ *
+ * \return Next word in the currently selected pipe's FIFO buffer
+ */
+ static inline uint16_t Pipe_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint16_t Pipe_Read_Word_LE(void)
+ {
+ union
+ {
+ uint16_t Word;
+ uint8_t Bytes[2];
+ } Data;
+
+ Data.Bytes[0] = UPDATX;
+ Data.Bytes[1] = UPDATX;
+
+ return Data.Word;
+ }
+
+ /** Reads two bytes from the currently selected pipe's bank in big endian format, for OUT
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW
+ *
+ * \return Next word in the currently selected pipe's FIFO buffer
+ */
+ static inline uint16_t Pipe_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint16_t Pipe_Read_Word_BE(void)
+ {
+ union
+ {
+ 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.
+ *
+ * \ingroup Group_PipePrimitiveRW
+ *
+ * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer
+ */
+ static inline void Pipe_Write_Word_LE(const uint16_t Word) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Write_Word_LE(const uint16_t Word)
+ {
+ UPDATX = (Word & 0xFF);
+ UPDATX = (Word >> 8);
+ }
+
+ /** Writes two bytes to the currently selected pipe's bank in big endian format, for IN
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW
+ *
+ * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer
+ */
+ static inline void Pipe_Write_Word_BE(const uint16_t Word) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Write_Word_BE(const uint16_t Word)
+ {
+ UPDATX = (Word >> 8);
+ UPDATX = (Word & 0xFF);
+ }
+
+ /** Discards two bytes from the currently selected pipe's bank, for OUT direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW
+ */
+ static inline void Pipe_Discard_Word(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Discard_Word(void)
+ {
+ uint8_t Dummy;
+
+ Dummy = UPDATX;
+ Dummy = UPDATX;
+ }
+
+ /** Reads four bytes from the currently selected pipe's bank in little endian format, for OUT
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW
+ *
+ * \return Next double word in the currently selected pipe's FIFO buffer
+ */
+ static inline uint32_t Pipe_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint32_t Pipe_Read_DWord_LE(void)
+ {
+ union
+ {
+ 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;
+ }
+
+ /** Reads four bytes from the currently selected pipe's bank in big endian format, for OUT
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW
+ *
+ * \return Next double word in the currently selected pipe's FIFO buffer
+ */
+ static inline uint32_t Pipe_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
+ static inline uint32_t Pipe_Read_DWord_BE(void)
+ {
+ union
+ {
+ 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;
+ }
+
+ /** Writes four bytes to the currently selected pipe's bank in little endian format, for IN
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW
+ *
+ * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer
+ */
+ static inline void Pipe_Write_DWord_LE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Write_DWord_LE(const uint32_t DWord)
+ {
+ UPDATX = (DWord & 0xFF);
+ UPDATX = (DWord >> 8);
+ UPDATX = (DWord >> 16);
+ UPDATX = (DWord >> 24);
+ }
+
+ /** Writes four bytes to the currently selected pipe's bank in big endian format, for IN
+ * direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW
+ *
+ * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer
+ */
+ static inline void Pipe_Write_DWord_BE(const uint32_t DWord) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Write_DWord_BE(const uint32_t DWord)
+ {
+ UPDATX = (DWord >> 24);
+ UPDATX = (DWord >> 16);
+ UPDATX = (DWord >> 8);
+ UPDATX = (DWord & 0xFF);
+ }
+
+ /** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes.
+ *
+ * \ingroup Group_PipePrimitiveRW
+ */
+ static inline void Pipe_Discard_DWord(void) ATTR_ALWAYS_INLINE;
+ static inline void Pipe_Discard_DWord(void)
+ {
+ uint8_t Dummy;
+
+ Dummy = UPDATX;
+ Dummy = UPDATX;
+ Dummy = UPDATX;
+ Dummy = UPDATX;
+ }
+
+ /* External Variables: */
+ /** Global indicating the maximum packet size of the default control pipe located at address
+ * 0 in the device. This value is set to the value indicated in the attached device's device
+ * descriptor once the USB interface is initialized into host mode and a device is attached
+ * to the USB bus.
+ *
+ * \note This variable should be treated as read-only in the user application, and never manually
+ * changed in value.
+ */
+ extern uint8_t USB_ControlPipeSize;
+
+ /* Function Prototypes: */
+ #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
+ #define __CALLBACK_PARAM , StreamCallbackPtr_t Callback
+ #else
+ #define __CALLBACK_PARAM
+ #endif
+
+ /** Configures the specified pipe number with the given pipe type, token, target endpoint number in the
+ * attached device, bank size and banking mode. Pipes should be allocated in ascending order by their
+ * address in the device (i.e. pipe 1 should be configured before pipe 2 and so on) to prevent fragmentation
+ * of the USB FIFO memory.
+ *
+ * The pipe type may be one of the EP_TYPE_* macros listed in LowLevel.h, the token may be one of the
+ * PIPE_TOKEN_* masks.
+ *
+ * The bank size must indicate the maximum packet size that the pipe can handle. Different pipe
+ * numbers can handle different maximum packet sizes - refer to the chosen USB AVR's datasheet to
+ * determine the maximum bank size for each pipe.
+ *
+ * The banking mode may be either \ref PIPE_BANK_SINGLE or \ref PIPE_BANK_DOUBLE.
+ *
+ * A newly configured pipe is frozen by default, and must be unfrozen before use via the \ref Pipe_Unfreeze()
+ * before being used. Pipes should be kept frozen unless waiting for data from a device while in IN mode, or
+ * sending data to the device in OUT mode. IN type pipes are also automatically configured to accept infinite
+ * numbers of IN requests without automatic freezing - this can be overridden by a call to
+ * \ref Pipe_SetFiniteINRequests().
+ *
+ * \note The default control pipe does not have to be manually configured, as it is automatically
+ * configured by the library internally.
+ * \n\n
+ *
+ * \note This routine will select the specified pipe, and the pipe will remain selected once the
+ * routine completes regardless of if the pipe configuration succeeds.
+ *
+ * \return Boolean true if the configuration is successful, false otherwise
+ */
+ bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber,
+ 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
+ * or written to it, aborting in the case of an error condition (such as a timeout or device disconnect).
+ *
+ * \ingroup Group_PipeRW
+ *
+ * \return A value from the 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.
+ *
+ * \param[in] EndpointAddress Address and direction mask of the endpoint within the attached device to check
+ *
+ * \return Boolean true if a pipe bound to the given endpoint address of the specified direction is found, false
+ * otherwise
+ */
+ bool Pipe_IsEndpointBound(const uint8_t EndpointAddress);
+
+ /** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host
+ * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the
+ * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearIN() macro.
+ * Between each USB packet, the given stream callback function is executed repeatedly until the next packet is ready,
+ * allowing for early aborts of stream transfers.
+ *
+ * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
+ * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
+ * disabled and this function has the Callback parameter omitted.
+ *
+ * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \ingroup Group_PipeStreamRW
+ *
+ * \param[in] Length Number of bytes to send via the currently selected pipe.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Discard_Stream(uint16_t Length __CALLBACK_PARAM);
+
+ /** Writes the given number of bytes to the pipe from the given buffer in little endian,
+ * sending full packets to the device as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
+ * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
+ *
+ * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
+ * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
+ * disabled and this function has the Callback parameter omitted.
+ *
+ * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \ingroup Group_PipeStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_Stream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Pipe_Write_Stream_LE().
+ *
+ * \ingroup Group_PipeStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_EStream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** FLASH buffer source version of \ref Pipe_Write_Stream_LE().
+ *
+ * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \ingroup Group_PipeStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_PStream_LE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Writes the given number of bytes to the pipe from the given buffer in big endian,
+ * sending full packets to the device as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
+ * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
+ *
+ * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
+ * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
+ * disabled and this function has the Callback parameter omitted.
+ *
+ * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \ingroup Group_PipeStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_Stream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Pipe_Write_Stream_BE().
+ *
+ * \ingroup Group_PipeStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_EStream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** FLASH buffer source version of \ref Pipe_Write_Stream_BE().
+ *
+ * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
+ *
+ * \ingroup Group_PipeStreamRW
+ *
+ * \param[in] Buffer Pointer to the source data buffer to read from.
+ * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Write_PStream_BE(const void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the pipe into the given buffer in little endian,
+ * sending full packets to the device as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
+ * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
+ *
+ * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
+ * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
+ * disabled and this function has the Callback parameter omitted.
+ *
+ * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \ingroup Group_PipeStreamRW
+ *
+ * \param[out] Buffer Pointer to the source data buffer to write to.
+ * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Pipe_Read_Stream_LE().
+ *
+ * \ingroup Group_PipeStreamRW
+ *
+ * \param[out] Buffer Pointer to the source data buffer to write to.
+ * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Read_EStream_LE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** Reads the given number of bytes from the pipe into the given buffer in big endian,
+ * sending full packets to the device as needed. The last packet filled is not automatically sent;
+ * the user is responsible for manually sending the last written packet to the host via the
+ * \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
+ * executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
+ *
+ * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
+ * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
+ * disabled and this function has the Callback parameter omitted.
+ *
+ * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
+ * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
+ *
+ * \ingroup Group_PipeStreamRW
+ *
+ * \param[out] Buffer Pointer to the source data buffer to write to.
+ * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /** EEPROM buffer source version of \ref Pipe_Read_Stream_BE().
+ *
+ * \ingroup Group_PipeStreamRW
+ *
+ * \param[out] Buffer Pointer to the source data buffer to write to.
+ * \param[in] Length Number of bytes to read for the currently selected pipe to read from.
+ * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
+ */
+ uint8_t Pipe_Read_EStream_BE(void* Buffer, uint16_t Length __CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1);
+
+ /* Private Interface - For use in library only: */
+ #if !defined(__DOXYGEN__)
+ /* Macros: */
+ #define PIPE_TOKEN_MASK (0x03 << PTOKEN0)
+
+ #if !defined(ENDPOINT_CONTROLEP)
+ #define ENDPOINT_CONTROLEP 0
+ #endif
+
+ #define Pipe_AllocateMemory() MACROS{ UPCFG1X |= (1 << ALLOC); }MACROE
+ #define Pipe_DeallocateMemory() MACROS{ UPCFG1X &= ~(1 << ALLOC); }MACROE
+
+ /* Function Prototypes: */
+ void Pipe_ClearPipes(void);
+
+ /* Inline Functions: */
+ static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;
+ static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes)
+ {
+ if (Bytes <= 8)
+ return (0 << EPSIZE0);
+ else if (Bytes <= 16)
+ return (1 << EPSIZE0);
+ else if (Bytes <= 32)
+ return (2 << EPSIZE0);
+ else if (Bytes <= 64)
+ return (3 << EPSIZE0);
+ else if (Bytes <= 128)
+ return (4 << EPSIZE0);
+ else
+ return (5 << EPSIZE0);
+ }
+
+ #endif
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif
+
+/** @} */
diff --git a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c
index 92b5396d7..db976440a 100644
--- a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c
+++ b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c
@@ -1,44 +1,44 @@
-uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length)
-{
- uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
-
- if (!(Length))
- Endpoint_ClearOUT();
-
- while (Length)
- {
- if (Endpoint_IsSETUPReceived())
- return ENDPOINT_RWCSTREAM_HostAborted;
-
- if (USB_DeviceState == DEVICE_STATE_Unattached)
- return ENDPOINT_RWCSTREAM_DeviceDisconnected;
- else if (USB_DeviceState == DEVICE_STATE_Suspended)
- return ENDPOINT_RWCSTREAM_BusSuspended;
-
- if (Endpoint_IsOUTReceived())
- {
- while (Length && Endpoint_BytesInEndpoint())
- {
- TEMPLATE_TRANSFER_BYTE(DataStream);
- Length--;
- }
-
- Endpoint_ClearOUT();
- }
- }
-
- while (!(Endpoint_IsINReady()))
- {
- if (USB_DeviceState == DEVICE_STATE_Unattached)
- return ENDPOINT_RWCSTREAM_DeviceDisconnected;
- else if (USB_DeviceState == DEVICE_STATE_Suspended)
- return ENDPOINT_RWCSTREAM_BusSuspended;
- }
-
- return ENDPOINT_RWCSTREAM_NoError;
-}
-
-
-#undef TEMPLATE_BUFFER_OFFSET
-#undef TEMPLATE_FUNC_NAME
+uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length)
+{
+ uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
+
+ if (!(Length))
+ Endpoint_ClearOUT();
+
+ while (Length)
+ {
+ if (Endpoint_IsSETUPReceived())
+ return ENDPOINT_RWCSTREAM_HostAborted;
+
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return ENDPOINT_RWCSTREAM_DeviceDisconnected;
+ else if (USB_DeviceState == DEVICE_STATE_Suspended)
+ return ENDPOINT_RWCSTREAM_BusSuspended;
+
+ if (Endpoint_IsOUTReceived())
+ {
+ while (Length && Endpoint_BytesInEndpoint())
+ {
+ TEMPLATE_TRANSFER_BYTE(DataStream);
+ Length--;
+ }
+
+ Endpoint_ClearOUT();
+ }
+ }
+
+ while (!(Endpoint_IsINReady()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return ENDPOINT_RWCSTREAM_DeviceDisconnected;
+ else if (USB_DeviceState == DEVICE_STATE_Suspended)
+ return ENDPOINT_RWCSTREAM_BusSuspended;
+ }
+
+ return ENDPOINT_RWCSTREAM_NoError;
+}
+
+
+#undef TEMPLATE_BUFFER_OFFSET
+#undef TEMPLATE_FUNC_NAME
#undef TEMPLATE_TRANSFER_BYTE \ No newline at end of file
diff --git a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c
index 8a5be11f1..91f4e963b 100644
--- a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c
+++ b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c
@@ -1,53 +1,53 @@
-uint8_t TEMPLATE_FUNC_NAME (const void* Buffer, uint16_t Length)
-{
- uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
- bool LastPacketFull = false;
-
- if (Length > USB_ControlRequest.wLength)
- Length = USB_ControlRequest.wLength;
- else if (!(Length))
- Endpoint_ClearIN();
-
- while (Length || LastPacketFull)
- {
- if (Endpoint_IsSETUPReceived())
- return ENDPOINT_RWCSTREAM_HostAborted;
-
- if (Endpoint_IsOUTReceived())
- break;
-
- if (USB_DeviceState == DEVICE_STATE_Unattached)
- return ENDPOINT_RWCSTREAM_DeviceDisconnected;
- else if (USB_DeviceState == DEVICE_STATE_Suspended)
- return ENDPOINT_RWCSTREAM_BusSuspended;
-
- if (Endpoint_IsINReady())
- {
- uint8_t BytesInEndpoint = Endpoint_BytesInEndpoint();
-
- while (Length && (BytesInEndpoint < USB_ControlEndpointSize))
- {
- TEMPLATE_TRANSFER_BYTE(DataStream);
- Length--;
- BytesInEndpoint++;
- }
-
- LastPacketFull = (BytesInEndpoint == USB_ControlEndpointSize);
- Endpoint_ClearIN();
- }
- }
-
- while (!(Endpoint_IsOUTReceived()))
- {
- if (USB_DeviceState == DEVICE_STATE_Unattached)
- return ENDPOINT_RWCSTREAM_DeviceDisconnected;
- else if (USB_DeviceState == DEVICE_STATE_Suspended)
- return ENDPOINT_RWCSTREAM_BusSuspended;
- }
-
- return ENDPOINT_RWCSTREAM_NoError;
-}
-
-#undef TEMPLATE_BUFFER_OFFSET
-#undef TEMPLATE_FUNC_NAME
+uint8_t TEMPLATE_FUNC_NAME (const void* Buffer, uint16_t Length)
+{
+ uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
+ bool LastPacketFull = false;
+
+ if (Length > USB_ControlRequest.wLength)
+ Length = USB_ControlRequest.wLength;
+ else if (!(Length))
+ Endpoint_ClearIN();
+
+ while (Length || LastPacketFull)
+ {
+ if (Endpoint_IsSETUPReceived())
+ return ENDPOINT_RWCSTREAM_HostAborted;
+
+ if (Endpoint_IsOUTReceived())
+ break;
+
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return ENDPOINT_RWCSTREAM_DeviceDisconnected;
+ else if (USB_DeviceState == DEVICE_STATE_Suspended)
+ return ENDPOINT_RWCSTREAM_BusSuspended;
+
+ if (Endpoint_IsINReady())
+ {
+ uint8_t BytesInEndpoint = Endpoint_BytesInEndpoint();
+
+ while (Length && (BytesInEndpoint < USB_ControlEndpointSize))
+ {
+ TEMPLATE_TRANSFER_BYTE(DataStream);
+ Length--;
+ BytesInEndpoint++;
+ }
+
+ LastPacketFull = (BytesInEndpoint == USB_ControlEndpointSize);
+ Endpoint_ClearIN();
+ }
+ }
+
+ while (!(Endpoint_IsOUTReceived()))
+ {
+ if (USB_DeviceState == DEVICE_STATE_Unattached)
+ return ENDPOINT_RWCSTREAM_DeviceDisconnected;
+ else if (USB_DeviceState == DEVICE_STATE_Suspended)
+ return ENDPOINT_RWCSTREAM_BusSuspended;
+ }
+
+ return ENDPOINT_RWCSTREAM_NoError;
+}
+
+#undef TEMPLATE_BUFFER_OFFSET
+#undef TEMPLATE_FUNC_NAME
#undef TEMPLATE_TRANSFER_BYTE \ No newline at end of file
diff --git a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_RW.c b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_RW.c
index 9e86eed3a..4e9c32407 100644
--- a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_RW.c
+++ b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_RW.c
@@ -1,77 +1,77 @@
-uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE Buffer, uint16_t Length __CALLBACK_PARAM)
-{
- uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
- uint8_t ErrorCode;
-
- if ((ErrorCode = Endpoint_WaitUntilReady()))
- return ErrorCode;
-
- #if defined(FAST_STREAM_TRANSFERS)
- uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07);
-
- if (Length >= 8)
- {
- Length -= BytesRemToAlignment;
-
- switch (BytesRemToAlignment)
- {
- default:
- do
- {
- if (!(Endpoint_IsReadWriteAllowed()))
- {
- TEMPLATE_CLEAR_ENDPOINT();
-
- #if !defined(NO_STREAM_CALLBACKS)
- if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
- return ENDPOINT_RWSTREAM_CallbackAborted;
- #endif
-
- if ((ErrorCode = Endpoint_WaitUntilReady()))
- return ErrorCode;
- }
-
- Length -= 8;
-
- TEMPLATE_TRANSFER_BYTE(DataStream);
- case 7: TEMPLATE_TRANSFER_BYTE(DataStream);
- case 6: TEMPLATE_TRANSFER_BYTE(DataStream);
- case 5: TEMPLATE_TRANSFER_BYTE(DataStream);
- case 4: TEMPLATE_TRANSFER_BYTE(DataStream);
- case 3: TEMPLATE_TRANSFER_BYTE(DataStream);
- case 2: TEMPLATE_TRANSFER_BYTE(DataStream);
- case 1: TEMPLATE_TRANSFER_BYTE(DataStream);
- } while (Length >= 8);
- }
- }
- #endif
-
- while (Length)
- {
- if (!(Endpoint_IsReadWriteAllowed()))
- {
- TEMPLATE_CLEAR_ENDPOINT();
-
- #if !defined(NO_STREAM_CALLBACKS)
- if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
- return ENDPOINT_RWSTREAM_CallbackAborted;
- #endif
-
- if ((ErrorCode = Endpoint_WaitUntilReady()))
- return ErrorCode;
- }
- else
- {
- TEMPLATE_TRANSFER_BYTE(DataStream);
- Length--;
- }
- }
-
- return ENDPOINT_RWSTREAM_NoError;
-}
-
-#undef TEMPLATE_FUNC_NAME
-#undef TEMPLATE_BUFFER_TYPE
-#undef TEMPLATE_TRANSFER_BYTE
-#undef TEMPLATE_CLEAR_ENDPOINT
+uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE Buffer, uint16_t Length __CALLBACK_PARAM)
+{
+ uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
+ uint8_t ErrorCode;
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+
+ #if defined(FAST_STREAM_TRANSFERS)
+ uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07);
+
+ if (Length >= 8)
+ {
+ Length -= BytesRemToAlignment;
+
+ switch (BytesRemToAlignment)
+ {
+ default:
+ do
+ {
+ if (!(Endpoint_IsReadWriteAllowed()))
+ {
+ TEMPLATE_CLEAR_ENDPOINT();
+
+ #if !defined(NO_STREAM_CALLBACKS)
+ if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
+ return ENDPOINT_RWSTREAM_CallbackAborted;
+ #endif
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+ }
+
+ Length -= 8;
+
+ TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 7: TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 6: TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 5: TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 4: TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 3: TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 2: TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 1: TEMPLATE_TRANSFER_BYTE(DataStream);
+ } while (Length >= 8);
+ }
+ }
+ #endif
+
+ while (Length)
+ {
+ if (!(Endpoint_IsReadWriteAllowed()))
+ {
+ TEMPLATE_CLEAR_ENDPOINT();
+
+ #if !defined(NO_STREAM_CALLBACKS)
+ if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
+ return ENDPOINT_RWSTREAM_CallbackAborted;
+ #endif
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+ }
+ else
+ {
+ TEMPLATE_TRANSFER_BYTE(DataStream);
+ Length--;
+ }
+ }
+
+ return ENDPOINT_RWSTREAM_NoError;
+}
+
+#undef TEMPLATE_FUNC_NAME
+#undef TEMPLATE_BUFFER_TYPE
+#undef TEMPLATE_TRANSFER_BYTE
+#undef TEMPLATE_CLEAR_ENDPOINT
#undef TEMPLATE_BUFFER_OFFSET \ No newline at end of file
diff --git a/LUFA/Drivers/USB/LowLevel/Template/Template_Pipe_RW.c b/LUFA/Drivers/USB/LowLevel/Template/Template_Pipe_RW.c
index ef8035d50..4fa83f5c5 100644
--- a/LUFA/Drivers/USB/LowLevel/Template/Template_Pipe_RW.c
+++ b/LUFA/Drivers/USB/LowLevel/Template/Template_Pipe_RW.c
@@ -1,80 +1,80 @@
-uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE Buffer, uint16_t Length __CALLBACK_PARAM)
-{
- uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
- uint8_t ErrorCode;
-
- Pipe_SetPipeToken(TEMPLATE_TOKEN);
-
- if ((ErrorCode = Pipe_WaitUntilReady()))
- return ErrorCode;
-
- #if defined(FAST_STREAM_TRANSFERS)
- uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07);
-
- if (Length >= 8)
- {
- Length -= BytesRemToAlignment;
-
- switch (BytesRemToAlignment)
- {
- default:
- do
- {
- if (!(Pipe_IsReadWriteAllowed()))
- {
- TEMPLATE_CLEAR_PIPE();
-
- #if !defined(NO_STREAM_CALLBACKS)
- if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
- return PIPE_RWSTREAM_CallbackAborted;
- #endif
-
- if ((ErrorCode = Pipe_WaitUntilReady()))
- return ErrorCode;
- }
-
- Length -= 8;
-
- TEMPLATE_TRANSFER_BYTE(DataStream);
- case 7: TEMPLATE_TRANSFER_BYTE(DataStream);
- case 6: TEMPLATE_TRANSFER_BYTE(DataStream);
- case 5: TEMPLATE_TRANSFER_BYTE(DataStream);
- case 4: TEMPLATE_TRANSFER_BYTE(DataStream);
- case 3: TEMPLATE_TRANSFER_BYTE(DataStream);
- case 2: TEMPLATE_TRANSFER_BYTE(DataStream);
- case 1: TEMPLATE_TRANSFER_BYTE(DataStream);
- } while (Length >= 8);
- }
- }
- #endif
-
- while (Length)
- {
- if (!(Pipe_IsReadWriteAllowed()))
- {
- TEMPLATE_CLEAR_PIPE();
-
- #if !defined(NO_STREAM_CALLBACKS)
- if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
- return PIPE_RWSTREAM_CallbackAborted;
- #endif
-
- if ((ErrorCode = Pipe_WaitUntilReady()))
- return ErrorCode;
- }
- else
- {
- TEMPLATE_TRANSFER_BYTE(DataStream);
- Length--;
- }
- }
-
- return PIPE_RWSTREAM_NoError;
-}
-
-#undef TEMPLATE_FUNC_NAME
-#undef TEMPLATE_BUFFER_TYPE
-#undef TEMPLATE_TOKEN
-#undef TEMPLATE_TRANSFER_BYTE
-#undef TEMPLATE_CLEAR_PIPE
-#undef TEMPLATE_BUFFER_OFFSET
+uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE Buffer, uint16_t Length __CALLBACK_PARAM)
+{
+ uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
+ uint8_t ErrorCode;
+
+ Pipe_SetPipeToken(TEMPLATE_TOKEN);
+
+ if ((ErrorCode = Pipe_WaitUntilReady()))
+ return ErrorCode;
+
+ #if defined(FAST_STREAM_TRANSFERS)
+ uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07);
+
+ if (Length >= 8)
+ {
+ Length -= BytesRemToAlignment;
+
+ switch (BytesRemToAlignment)
+ {
+ default:
+ do
+ {
+ if (!(Pipe_IsReadWriteAllowed()))
+ {
+ TEMPLATE_CLEAR_PIPE();
+
+ #if !defined(NO_STREAM_CALLBACKS)
+ if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
+ return PIPE_RWSTREAM_CallbackAborted;
+ #endif
+
+ if ((ErrorCode = Pipe_WaitUntilReady()))
+ return ErrorCode;
+ }
+
+ Length -= 8;
+
+ TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 7: TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 6: TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 5: TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 4: TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 3: TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 2: TEMPLATE_TRANSFER_BYTE(DataStream);
+ case 1: TEMPLATE_TRANSFER_BYTE(DataStream);
+ } while (Length >= 8);
+ }
+ }
+ #endif
+
+ while (Length)
+ {
+ if (!(Pipe_IsReadWriteAllowed()))
+ {
+ TEMPLATE_CLEAR_PIPE();
+
+ #if !defined(NO_STREAM_CALLBACKS)
+ if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
+ return PIPE_RWSTREAM_CallbackAborted;
+ #endif
+
+ if ((ErrorCode = Pipe_WaitUntilReady()))
+ return ErrorCode;
+ }
+ else
+ {
+ TEMPLATE_TRANSFER_BYTE(DataStream);
+ Length--;
+ }
+ }
+
+ return PIPE_RWSTREAM_NoError;
+}
+
+#undef TEMPLATE_FUNC_NAME
+#undef TEMPLATE_BUFFER_TYPE
+#undef TEMPLATE_TOKEN
+#undef TEMPLATE_TRANSFER_BYTE
+#undef TEMPLATE_CLEAR_PIPE
+#undef TEMPLATE_BUFFER_OFFSET
diff --git a/LUFA/Drivers/USB/LowLevel/USBInterrupt.c b/LUFA/Drivers/USB/LowLevel/USBInterrupt.c
index 2d9e35b72..7edd3ce6a 100644
--- a/LUFA/Drivers/USB/LowLevel/USBInterrupt.c
+++ b/LUFA/Drivers/USB/LowLevel/USBInterrupt.c
@@ -1,247 +1,247 @@
-/*
- 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 "USBInterrupt.h"
-
-void USB_INT_DisableAllInterrupts(void)
-{
- #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
- USBCON &= ~((1 << VBUSTE) | (1 << IDTE));
- #elif defined(USB_SERIES_4_AVR)
- USBCON &= ~(1 << VBUSTE);
- #endif
-
- #if defined(USB_CAN_BE_HOST)
- UHIEN = 0;
- OTGIEN = 0;
- #endif
-
- #if defined(USB_CAN_BE_DEVICE)
- UDIEN = 0;
- #endif
-}
-
-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_HOST)
- UHINT = 0;
- OTGINT = 0;
- #endif
-
- #if defined(USB_CAN_BE_DEVICE)
- UDINT = 0;
- #endif
-}
-
-ISR(USB_GEN_vect, ISR_BLOCK)
-{
- #if defined(USB_CAN_BE_DEVICE)
- #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
- if (USB_INT_HasOccurred(USB_INT_VBUS) && USB_INT_IsEnabled(USB_INT_VBUS))
- {
- USB_INT_Clear(USB_INT_VBUS);
-
- if (USB_VBUS_GetStatus())
- {
- USB_DeviceState = DEVICE_STATE_Powered;
- EVENT_USB_Device_Connect();
- }
- else
- {
- USB_DeviceState = DEVICE_STATE_Unattached;
- EVENT_USB_Device_Disconnect();
- }
- }
- #endif
-
- if (USB_INT_HasOccurred(USB_INT_SUSPEND) && USB_INT_IsEnabled(USB_INT_SUSPEND))
- {
- USB_INT_Clear(USB_INT_SUSPEND);
-
- USB_INT_Disable(USB_INT_SUSPEND);
- USB_INT_Enable(USB_INT_WAKEUP);
-
- USB_CLK_Freeze();
-
- if (!(USB_Options & USB_OPT_MANUAL_PLL))
- USB_PLL_Off();
-
- #if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
- USB_DeviceState = DEVICE_STATE_Unattached;
- EVENT_USB_Device_Disconnect();
- #else
- USB_DeviceState = DEVICE_STATE_Suspended;
- EVENT_USB_Device_Suspend();
- #endif
- }
-
- if (USB_INT_HasOccurred(USB_INT_WAKEUP) && USB_INT_IsEnabled(USB_INT_WAKEUP))
- {
- if (!(USB_Options & USB_OPT_MANUAL_PLL))
- {
- USB_PLL_On();
- while (!(USB_PLL_IsReady()));
- }
-
- USB_CLK_Unfreeze();
-
- USB_INT_Clear(USB_INT_WAKEUP);
-
- USB_INT_Disable(USB_INT_WAKEUP);
- USB_INT_Enable(USB_INT_SUSPEND);
-
- #if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
- USB_DeviceState = (USB_ConfigurationNumber) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
- EVENT_USB_Device_Connect();
- #else
- USB_DeviceState = (USB_ConfigurationNumber) ? DEVICE_STATE_Configured : DEVICE_STATE_Addressed;
- EVENT_USB_Device_WakeUp();
- #endif
- }
-
- if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))
- {
- USB_INT_Clear(USB_INT_EORSTI);
-
- USB_DeviceState = DEVICE_STATE_Default;
- USB_ConfigurationNumber = 0;
-
- USB_INT_Clear(USB_INT_SUSPEND);
- USB_INT_Disable(USB_INT_SUSPEND);
- USB_INT_Enable(USB_INT_WAKEUP);
-
- Endpoint_ClearEndpoints();
-
- Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
- ENDPOINT_DIR_OUT, USB_ControlEndpointSize,
- ENDPOINT_BANK_SINGLE);
-
- #if defined(INTERRUPT_CONTROL_ENDPOINT)
- USB_INT_Enable(USB_INT_RXSTPI);
- #endif
-
- EVENT_USB_Device_Reset();
- }
-
- if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))
- {
- USB_INT_Clear(USB_INT_SOFI);
-
- EVENT_USB_Device_StartOfFrame();
- }
- #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);
-
- USB_Host_VBUS_Manual_Off();
- USB_Host_VBUS_Auto_Off();
-
- EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip);
- EVENT_USB_Host_DeviceUnattached();
-
- USB_HostState = HOST_STATE_Unattached;
- }
-
- if (USB_INT_HasOccurred(USB_INT_SRPI) && USB_INT_IsEnabled(USB_INT_SRPI))
- {
- 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();
-
- USB_ResetInterface();
- }
- #endif
-
- #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)
- EVENT_USB_Device_Disconnect();
-
- if (USB_HostState != HOST_STATE_Unattached)
- EVENT_USB_Host_DeviceUnattached();
-
- USB_CurrentMode = USB_GetUSBModeFromUID();
- EVENT_USB_UIDChange();
-
- USB_ResetInterface();
- }
- #endif
-}
-
-#if defined(INTERRUPT_CONTROL_ENDPOINT) && defined(USB_CAN_BE_DEVICE)
-ISR(USB_COM_vect, ISR_BLOCK)
-{
- uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint();
-
- USB_INT_Disable(USB_INT_RXSTPI);
- sei();
- USB_USBTask();
- USB_INT_Enable(USB_INT_RXSTPI);
-
- USB_INT_Clear(USB_INT_RXSTPI);
-
- Endpoint_SelectEndpoint(PrevSelectedEndpoint);
-}
-#endif
+/*
+ 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 "USBInterrupt.h"
+
+void USB_INT_DisableAllInterrupts(void)
+{
+ #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
+ USBCON &= ~((1 << VBUSTE) | (1 << IDTE));
+ #elif defined(USB_SERIES_4_AVR)
+ USBCON &= ~(1 << VBUSTE);
+ #endif
+
+ #if defined(USB_CAN_BE_HOST)
+ UHIEN = 0;
+ OTGIEN = 0;
+ #endif
+
+ #if defined(USB_CAN_BE_DEVICE)
+ UDIEN = 0;
+ #endif
+}
+
+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_HOST)
+ UHINT = 0;
+ OTGINT = 0;
+ #endif
+
+ #if defined(USB_CAN_BE_DEVICE)
+ UDINT = 0;
+ #endif
+}
+
+ISR(USB_GEN_vect, ISR_BLOCK)
+{
+ #if defined(USB_CAN_BE_DEVICE)
+ #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
+ if (USB_INT_HasOccurred(USB_INT_VBUS) && USB_INT_IsEnabled(USB_INT_VBUS))
+ {
+ USB_INT_Clear(USB_INT_VBUS);
+
+ if (USB_VBUS_GetStatus())
+ {
+ USB_DeviceState = DEVICE_STATE_Powered;
+ EVENT_USB_Device_Connect();
+ }
+ else
+ {
+ USB_DeviceState = DEVICE_STATE_Unattached;
+ EVENT_USB_Device_Disconnect();
+ }
+ }
+ #endif
+
+ if (USB_INT_HasOccurred(USB_INT_SUSPEND) && USB_INT_IsEnabled(USB_INT_SUSPEND))
+ {
+ USB_INT_Clear(USB_INT_SUSPEND);
+
+ USB_INT_Disable(USB_INT_SUSPEND);
+ USB_INT_Enable(USB_INT_WAKEUP);
+
+ USB_CLK_Freeze();
+
+ if (!(USB_Options & USB_OPT_MANUAL_PLL))
+ USB_PLL_Off();
+
+ #if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
+ USB_DeviceState = DEVICE_STATE_Unattached;
+ EVENT_USB_Device_Disconnect();
+ #else
+ USB_DeviceState = DEVICE_STATE_Suspended;
+ EVENT_USB_Device_Suspend();
+ #endif
+ }
+
+ if (USB_INT_HasOccurred(USB_INT_WAKEUP) && USB_INT_IsEnabled(USB_INT_WAKEUP))
+ {
+ if (!(USB_Options & USB_OPT_MANUAL_PLL))
+ {
+ USB_PLL_On();
+ while (!(USB_PLL_IsReady()));
+ }
+
+ USB_CLK_Unfreeze();
+
+ USB_INT_Clear(USB_INT_WAKEUP);
+
+ USB_INT_Disable(USB_INT_WAKEUP);
+ USB_INT_Enable(USB_INT_SUSPEND);
+
+ #if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
+ USB_DeviceState = (USB_ConfigurationNumber) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
+ EVENT_USB_Device_Connect();
+ #else
+ USB_DeviceState = (USB_ConfigurationNumber) ? DEVICE_STATE_Configured : DEVICE_STATE_Addressed;
+ EVENT_USB_Device_WakeUp();
+ #endif
+ }
+
+ if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))
+ {
+ USB_INT_Clear(USB_INT_EORSTI);
+
+ USB_DeviceState = DEVICE_STATE_Default;
+ USB_ConfigurationNumber = 0;
+
+ USB_INT_Clear(USB_INT_SUSPEND);
+ USB_INT_Disable(USB_INT_SUSPEND);
+ USB_INT_Enable(USB_INT_WAKEUP);
+
+ Endpoint_ClearEndpoints();
+
+ Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
+ ENDPOINT_DIR_OUT, USB_ControlEndpointSize,
+ ENDPOINT_BANK_SINGLE);
+
+ #if defined(INTERRUPT_CONTROL_ENDPOINT)
+ USB_INT_Enable(USB_INT_RXSTPI);
+ #endif
+
+ EVENT_USB_Device_Reset();
+ }
+
+ if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))
+ {
+ USB_INT_Clear(USB_INT_SOFI);
+
+ EVENT_USB_Device_StartOfFrame();
+ }
+ #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);
+
+ USB_Host_VBUS_Manual_Off();
+ USB_Host_VBUS_Auto_Off();
+
+ EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip);
+ EVENT_USB_Host_DeviceUnattached();
+
+ USB_HostState = HOST_STATE_Unattached;
+ }
+
+ if (USB_INT_HasOccurred(USB_INT_SRPI) && USB_INT_IsEnabled(USB_INT_SRPI))
+ {
+ 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();
+
+ USB_ResetInterface();
+ }
+ #endif
+
+ #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)
+ EVENT_USB_Device_Disconnect();
+
+ if (USB_HostState != HOST_STATE_Unattached)
+ EVENT_USB_Host_DeviceUnattached();
+
+ USB_CurrentMode = USB_GetUSBModeFromUID();
+ EVENT_USB_UIDChange();
+
+ USB_ResetInterface();
+ }
+ #endif
+}
+
+#if defined(INTERRUPT_CONTROL_ENDPOINT) && defined(USB_CAN_BE_DEVICE)
+ISR(USB_COM_vect, ISR_BLOCK)
+{
+ uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint();
+
+ USB_INT_Disable(USB_INT_RXSTPI);
+ sei();
+ USB_USBTask();
+ USB_INT_Enable(USB_INT_RXSTPI);
+
+ USB_INT_Clear(USB_INT_RXSTPI);
+
+ Endpoint_SelectEndpoint(PrevSelectedEndpoint);
+}
+#endif
diff --git a/LUFA/Drivers/USB/LowLevel/USBInterrupt.h b/LUFA/Drivers/USB/LowLevel/USBInterrupt.h
index e46e7597b..a191a2994 100644
--- a/LUFA/Drivers/USB/LowLevel/USBInterrupt.h
+++ b/LUFA/Drivers/USB/LowLevel/USBInterrupt.h
@@ -1,103 +1,103 @@
-/*
- 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 controller interrupt service routine management.
- *
- * This file contains definitions required for the correct handling of low level USB service routine interrupts
- * from the USB controller.
- *
- * \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__
-
- /* Includes: */
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <stdbool.h>
-
- #include "../../../Common/Common.h"
- #include "../HighLevel/USBMode.h"
- #include "../HighLevel/Events.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
-
- /* Private Interface - For use in library only: */
- #if !defined(__DOXYGEN__)
- /* Macros: */
- #define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE
- #define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE
- #define USB_INT_Clear(int) MACROS{ USB_INT_GET_INT_REG(int) &= ~(USB_INT_GET_INT_MASK(int)); }MACROE
- #define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false)
- #define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false)
-
- #define USB_INT_GET_EN_REG(a, b, c, d) a
- #define USB_INT_GET_EN_MASK(a, b, c, d) b
- #define USB_INT_GET_INT_REG(a, b, c, d) c
- #define USB_INT_GET_INT_MASK(a, b, c, d) d
-
- #define USB_INT_VBUS USBCON, (1 << VBUSTE) , USBINT, (1 << VBUSTI)
- #define USB_INT_IDTI USBCON, (1 << IDTE) , USBINT, (1 << IDTI)
- #define USB_INT_WAKEUP UDIEN , (1 << WAKEUPE), UDINT , (1 << WAKEUPI)
- #define USB_INT_SUSPEND UDIEN , (1 << SUSPE) , UDINT , (1 << SUSPI)
- #define USB_INT_EORSTI UDIEN , (1 << EORSTE) , UDINT , (1 << EORSTI)
- #define USB_INT_DCONNI UHIEN , (1 << DCONNE) , UHINT , (1 << DCONNI)
- #define USB_INT_DDISCI UHIEN , (1 << DDISCE) , UHINT , (1 << DDISCI)
- #define USB_INT_BCERRI OTGIEN, (1 << BCERRE) , OTGINT, (1 << BCERRI)
- #define USB_INT_VBERRI OTGIEN, (1 << VBERRE) , OTGINT, (1 << VBERRI)
- #define USB_INT_SOFI UDIEN, (1 << SOFE) , UDINT , (1 << SOFI)
- #define USB_INT_HSOFI UHIEN, (1 << HSOFE) , UHINT , (1 << HSOFI)
- #define USB_INT_RSTI UHIEN , (1 << RSTE) , UHINT , (1 << RSTI)
- #define USB_INT_SRPI OTGIEN, (1 << SRPE) , OTGINT, (1 << SRPI)
- #define USB_INT_RXSTPI UEIENX, (1 << RXSTPE) , UEINTX, (1 << RXSTPI)
-
- /* Function Prototypes: */
- void USB_INT_ClearAllInterrupts(void);
- void USB_INT_DisableAllInterrupts(void);
- #endif
-
- /* Disable C linkage for C++ Compilers: */
- #if defined(__cplusplus)
- }
- #endif
-
-#endif
+/*
+ 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 controller interrupt service routine management.
+ *
+ * This file contains definitions required for the correct handling of low level USB service routine interrupts
+ * from the USB controller.
+ *
+ * \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__
+
+ /* Includes: */
+ #include <avr/io.h>
+ #include <avr/interrupt.h>
+ #include <stdbool.h>
+
+ #include "../../../Common/Common.h"
+ #include "../HighLevel/USBMode.h"
+ #include "../HighLevel/Events.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
+
+ /* Private Interface - For use in library only: */
+ #if !defined(__DOXYGEN__)
+ /* Macros: */
+ #define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE
+ #define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE
+ #define USB_INT_Clear(int) MACROS{ USB_INT_GET_INT_REG(int) &= ~(USB_INT_GET_INT_MASK(int)); }MACROE
+ #define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false)
+ #define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false)
+
+ #define USB_INT_GET_EN_REG(a, b, c, d) a
+ #define USB_INT_GET_EN_MASK(a, b, c, d) b
+ #define USB_INT_GET_INT_REG(a, b, c, d) c
+ #define USB_INT_GET_INT_MASK(a, b, c, d) d
+
+ #define USB_INT_VBUS USBCON, (1 << VBUSTE) , USBINT, (1 << VBUSTI)
+ #define USB_INT_IDTI USBCON, (1 << IDTE) , USBINT, (1 << IDTI)
+ #define USB_INT_WAKEUP UDIEN , (1 << WAKEUPE), UDINT , (1 << WAKEUPI)
+ #define USB_INT_SUSPEND UDIEN , (1 << SUSPE) , UDINT , (1 << SUSPI)
+ #define USB_INT_EORSTI UDIEN , (1 << EORSTE) , UDINT , (1 << EORSTI)
+ #define USB_INT_DCONNI UHIEN , (1 << DCONNE) , UHINT , (1 << DCONNI)
+ #define USB_INT_DDISCI UHIEN , (1 << DDISCE) , UHINT , (1 << DDISCI)
+ #define USB_INT_BCERRI OTGIEN, (1 << BCERRE) , OTGINT, (1 << BCERRI)
+ #define USB_INT_VBERRI OTGIEN, (1 << VBERRE) , OTGINT, (1 << VBERRI)
+ #define USB_INT_SOFI UDIEN, (1 << SOFE) , UDINT , (1 << SOFI)
+ #define USB_INT_HSOFI UHIEN, (1 << HSOFE) , UHINT , (1 << HSOFI)
+ #define USB_INT_RSTI UHIEN , (1 << RSTE) , UHINT , (1 << RSTI)
+ #define USB_INT_SRPI OTGIEN, (1 << SRPE) , OTGINT, (1 << SRPI)
+ #define USB_INT_RXSTPI UEIENX, (1 << RXSTPE) , UEINTX, (1 << RXSTPI)
+
+ /* Function Prototypes: */
+ void USB_INT_ClearAllInterrupts(void);
+ void USB_INT_DisableAllInterrupts(void);
+ #endif
+
+ /* Disable C linkage for C++ Compilers: */
+ #if defined(__cplusplus)
+ }
+ #endif
+
+#endif