diff --git a/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h b/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h index 1168fa2a1d..f911fbdd3e 100644 --- a/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h +++ b/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.h @@ -65,7 +65,7 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif /* Public Interface - May be used in end-application: */ diff --git a/LUFA/Drivers/USB/HighLevel/Events.h b/LUFA/Drivers/USB/HighLevel/Events.h index f6d8aaca8b..2c310f4601 100644 --- a/LUFA/Drivers/USB/HighLevel/Events.h +++ b/LUFA/Drivers/USB/HighLevel/Events.h @@ -66,7 +66,7 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif /* Public Interface - May be used in end-application: */ diff --git a/LUFA/Drivers/USB/HighLevel/StdDescriptors.h b/LUFA/Drivers/USB/HighLevel/StdDescriptors.h index f94673d2e1..363d26281c 100644 --- a/LUFA/Drivers/USB/HighLevel/StdDescriptors.h +++ b/LUFA/Drivers/USB/HighLevel/StdDescriptors.h @@ -67,7 +67,7 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif /* Public Interface - May be used in end-application: */ diff --git a/LUFA/Drivers/USB/HighLevel/StdRequestType.h b/LUFA/Drivers/USB/HighLevel/StdRequestType.h index 4fad0378b8..0db765d282 100644 --- a/LUFA/Drivers/USB/HighLevel/StdRequestType.h +++ b/LUFA/Drivers/USB/HighLevel/StdRequestType.h @@ -42,7 +42,7 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif /* Public Interface - May be used in end-application: */ diff --git a/LUFA/Drivers/USB/HighLevel/StreamCallbacks.h b/LUFA/Drivers/USB/HighLevel/StreamCallbacks.h index 3d30655ec6..777b588fb2 100644 --- a/LUFA/Drivers/USB/HighLevel/StreamCallbacks.h +++ b/LUFA/Drivers/USB/HighLevel/StreamCallbacks.h @@ -43,7 +43,7 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif /* Public Interface - May be used in end-application: */ diff --git a/LUFA/Drivers/USB/HighLevel/USBInterrupt.h b/LUFA/Drivers/USB/HighLevel/USBInterrupt.h index 94f88e278e..8fb152dd57 100644 --- a/LUFA/Drivers/USB/HighLevel/USBInterrupt.h +++ b/LUFA/Drivers/USB/HighLevel/USBInterrupt.h @@ -53,37 +53,65 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #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) + #if defined(__AVR32__) + #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) ## CLR |= USB_INT_GET_INT_MASK(int) ## C; }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_GET_EN_REG(a, b, c, d) *((volatile uint32_t*)AVR32_USBB_ ## a) + #define USB_INT_GET_EN_MASK(a, b, c, d) AVR32_USBB_ ## b + #define USB_INT_GET_INT_REG(a, b, c, d) *((volatile uint32_t*)AVR32_USBB_ ## c) + #define USB_INT_GET_INT_MASK(a, b, c, d) AVR32_USBB_ ## 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) + #define USB_INT_VBUS USBCON, USBCON_VBUSTE_MASK, USBSTA, USBSTA_VBUSTI_MASK + #define USB_INT_IDTI USBCON, USBCON_IDTE_MASK , USBINT, USBCON_IDTI_MASK + #define USB_INT_WAKEUP UDIEN , UDIEN_WAKEUPE_MASK, UDINT , UDIEN_WAKEUPI_MASK + #define USB_INT_SUSPEND UDIEN , UDIEN_SUSPE_MASK , UDINT , UDIEN_SUSPI_MASK + #define USB_INT_EORSTI UDIEN , UDIEN_EORSTE_MASK , UDINT , UDIEN_EORSTI_MASK + #define USB_INT_SOFI UDIEN, UDIEN_SOFE_MASK , UDINT , UDIEN_SOFI_MASK + #define USB_INT_DCONNI UHIEN , UDIEN_DCONNE_MASK , UHINT , UHIEN_DCONNI_MASK + #define USB_INT_DDISCI UHIEN , UDIEN_DDISCE_MASK , UHINT , UHIEN_DDISCI_MASK + #define USB_INT_HSOFI UHIEN, UHIEN_HSOFE_MASK , UHINT , UHIEN_HSOFI_MASK + #define USB_INT_RSTI UHIEN , UHIEN_RSTE_MASK , UHINT , UHIEN_RSTI_MASK + #define USB_INT_RXSTPI UEIENX, UEIENX_RXSTPE_MASK, UEINTX, UEIENX_RXSTPI_MASK + #define USB_INT_BCERRI OTGIEN, OTGIEN_BCERRE_MASK, OTGINT, OTGIEN_BCERRI_MASK + #define USB_INT_VBERRI OTGIEN, OTGIEN_VBERRE_MASK, OTGINT, OTGIEN_VBERRI_MASK + #define USB_INT_SRPI OTGIEN, OTGIEN_SRPE_MASK , OTGINT, OTGIEN_SRPI_MASK + #elif defined(__AVR__) + #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_SOFI UDIEN, (1 << SOFE) , UDINT , (1 << SOFI) + #define USB_INT_DCONNI UHIEN , (1 << DCONNE) , UHINT , (1 << DCONNI) + #define USB_INT_DDISCI UHIEN , (1 << DDISCE) , UHINT , (1 << DDISCI) + #define USB_INT_HSOFI UHIEN, (1 << HSOFE) , UHINT , (1 << HSOFI) + #define USB_INT_RSTI UHIEN , (1 << RSTE) , UHINT , (1 << RSTI) + #define USB_INT_BCERRI OTGIEN, (1 << BCERRE) , OTGINT, (1 << BCERRI) + #define USB_INT_VBERRI OTGIEN, (1 << VBERRE) , OTGINT, (1 << VBERRI) + #define USB_INT_SRPI OTGIEN, (1 << SRPE) , OTGINT, (1 << SRPI) + #define USB_INT_RXSTPI UEIENX, (1 << RXSTPE) , UEINTX, (1 << RXSTPI) + #endif /* Function Prototypes: */ void USB_INT_ClearAllInterrupts(void); diff --git a/LUFA/Drivers/USB/HighLevel/USBMode.h b/LUFA/Drivers/USB/HighLevel/USBMode.h index 1ceb981aed..ee10dea5ce 100644 --- a/LUFA/Drivers/USB/HighLevel/USBMode.h +++ b/LUFA/Drivers/USB/HighLevel/USBMode.h @@ -45,7 +45,7 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif /* Public Interface - May be used in end-application: */ diff --git a/LUFA/Drivers/USB/HighLevel/USBTask.h b/LUFA/Drivers/USB/HighLevel/USBTask.h index 350ad5dc54..e65a5dfc9f 100644 --- a/LUFA/Drivers/USB/HighLevel/USBTask.h +++ b/LUFA/Drivers/USB/HighLevel/USBTask.h @@ -63,7 +63,7 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif /* Public Interface - May be used in end-application: */ @@ -87,7 +87,7 @@ extern USB_Request_Header_t USB_ControlRequest; #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__) - #if !defined(HOST_STATE_AS_GPIOR) || defined(__DOXYGEN__) + #if (!defined(__AVR32__) && !defined(HOST_STATE_AS_GPIOR)) || defined(__DOXYGEN__) /** Indicates the current host state machine state. When in host mode, this indicates the state * via one of the values of the \ref USB_Host_States_t enum values. * @@ -116,7 +116,7 @@ #endif #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__) - #if !defined(DEVICE_STATE_AS_GPIOR) || defined(__DOXYGEN__) + #if (!defined(__AVR32__) && !defined(DEVICE_STATE_AS_GPIOR)) || defined(__DOXYGEN__) /** Indicates the current device state machine state. When in device mode, this indicates the state * via one of the values of the \ref USB_Device_States_t enum values. * diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.h b/LUFA/Drivers/USB/LowLevel/DevChapter9.h index cb1b44ac5a..c20b0760f9 100644 --- a/LUFA/Drivers/USB/LowLevel/DevChapter9.h +++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.h @@ -55,7 +55,7 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif /* Public Interface - May be used in end-application: */ diff --git a/LUFA/Drivers/USB/LowLevel/Device.h b/LUFA/Drivers/USB/LowLevel/Device.h index 9dff3f9171..11fb33a97c 100644 --- a/LUFA/Drivers/USB/LowLevel/Device.h +++ b/LUFA/Drivers/USB/LowLevel/Device.h @@ -56,7 +56,7 @@ #endif #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif /* Public Interface - May be used in end-application: */ diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.c b/LUFA/Drivers/USB/LowLevel/Endpoint.c index 819e3f8125..89fd39ff63 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.c +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.c @@ -40,12 +40,12 @@ uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE; #endif -uint8_t Endpoint_BytesToEPSizeMaskDynamic(const uint16_t Size) +uintN_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) +bool Endpoint_ConfigureEndpoint_Prv(const uintN_t Number, const uintN_t UECFG0XData, const uintN_t UECFG1XData) { Endpoint_SelectEndpoint(Number); Endpoint_EnableEndpoint(); diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.h b/LUFA/Drivers/USB/LowLevel/Endpoint.h index cf6fbc6320..6b16fd7ac7 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.h +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.h @@ -78,6 +78,7 @@ #endif #include "../../../Common/Common.h" + #include "LowLevel.h" #include "../HighLevel/USBTask.h" #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) @@ -91,34 +92,41 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #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) + #if defined(__AVR32__) || defined(__DOXYGEN__) + /** 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 - /** 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) + /** 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 AVR32_USBB_EPDIR_IN - /** 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) + /** 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 AVR32_USBB_EPBK_SINGLE + + /** 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 AVR32_USBB_EPBK_DOUBLE + #elif defined(__AVR__) + #define ENDPOINT_DIR_OUT (0 << EPDIR) + #define ENDPOINT_DIR_IN (1 << EPDIR) + #define ENDPOINT_BANK_SINGLE (0 << EPBK0) + #define ENDPOINT_BANK_DOUBLE (1 << EPBK0) + #endif /** 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. @@ -160,17 +168,18 @@ #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__) + #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || \ + defined(USB_SERIES_UC3B_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 + #define ENDPOINT_TOTAL_ENDPOINTS 7 #else - #define ENDPOINT_TOTAL_ENDPOINTS 5 + #define ENDPOINT_TOTAL_ENDPOINTS 5 #endif #else - #define ENDPOINT_TOTAL_ENDPOINTS 1 + #define ENDPOINT_TOTAL_ENDPOINTS 1 #endif /* Pseudo-Function Macros: */ @@ -360,71 +369,84 @@ #define Endpoint_BytesInEndpoint() (((uint16_t)UEBCHX << 8) | UEBCLX) #elif defined(USB_SERIES_2_AVR) #define Endpoint_BytesInEndpoint() UEBCLX + #elif defined(USB_SERIES_UC3B_AVR) + #define Endpoint_BytesInEndpoint() ((__AVR32_EPREG_X(UESTA0) & AVR32_USBB_BYCT_MASK) >> AVR32_USBB_BYCT) #endif - #if !defined(CONTROL_ONLY_DEVICE) - #define Endpoint_GetCurrentEndpoint() (UENUM & ENDPOINT_EPNUM_MASK) - #else - #define Endpoint_GetCurrentEndpoint() ENDPOINT_CONTROLEP + #if defined(__AVR32__) + #if !defined(CONTROL_ONLY_DEVICE) + #define Endpoint_GetCurrentEndpoint() USB_SelectedEPNumber + #define Endpoint_SelectEndpoint(epnum) MACROS{ USB_SelectedEPNumber = (epnum); }MACROE + #define Endpoint_IsReadWriteAllowed() (__AVR32_EPREG_X(UESTA0) & AVR32_USBB_RWAL_MASK) + #else + #define Endpoint_GetCurrentEndpoint() ENDPOINT_CONTROLEP + #define Endpoint_SelectEndpoint(epnum) (void)(epnum) + #endif + + #define Endpoint_ResetFIFO(epnum) MACROS{ AVR32_USBB.UERST |= (AVR32_USBB_EPRST0_MASK << (epnum)); \ + AVR32_USBB.UERST &= ~(AVR32_USBB_EPRST0_MASK << (epnum)); }MACROE + #define Endpoint_EnableEndpoint() MACROS{ AVR32_USBB.UERST |= (AVR32_USBB_UERST_EPEN0_MASK << (epen)); }MACROE + #define Endpoint_DisableEndpoint() MACROS{ AVR32_USBB.UERST &= ~(AVR32_USBB_UERST_EPEN0_MASK << (epen)); }MACROE + #define Endpoint_IsEnabled() ((AVR32_USBB.UERST & (AVR32_USBB_UERST_EPEN0_MASK << (epen))) ? true : false) + + #define Endpoint_IsConfigured() ((__AVR32_EPREG_X(UESTA0) & AVR32_USBB_UESTA0_CFGOK_MASK) ? true : false) + #define Endpoint_GetEndpointInterrupts() (AVR32_USBB.UDINT >> AVR32_USBB_EP0INT) + #define Endpoint_HasEndpointInterrupted(n) ((AVR32_USBB.UDINT & (AVR32_USBB_EP0INT << (n))) ? true : false) + #define Endpoint_IsINReady() ((__AVR32_EPREG_X(UESTA0) & AVR32_USBB_TXINI) ? true : false) + #define Endpoint_IsOUTReceived() ((__AVR32_EPREG_X(UESTA0) & AVR32_USBB_RXOUTI) ? true : false) + #define Endpoint_IsSETUPReceived() ((__AVR32_EPREG_X(UESTA0) & AVR32_USBB_RXSTPI) ? true : false) + #define Endpoint_ClearSETUP() MACROS{ __AVR32_EPREG_X(UESTA0CLR) = AVR32_USBB_RXSTPIC; }MACROE + #define Endpoint_ClearIN() MACROS{ __AVR32_EPREG_X(UESTA0CLR) = AVR32_USBB_TXINIC; \ + __AVR32_EPREG_X(UECON0CLR) = AVR32_USBB_FIFOCONC; }MACROE + #define Endpoint_ClearOUT() MACROS{ __AVR32_EPREG_X(UESTA0CLR) = AVR32_USBB_RXOUTI; \ + __AVR32_EPREG_X(UECON0CLR) = AVR32_USBB_FIFOCONC; }MACROE + #define Endpoint_StallTransaction() MACROS{ __AVR32_EPREG_X(UECON0SET) = AVR32_USBB_STALLRQS; }MACROE + #define Endpoint_ClearStall() MACROS{ __AVR32_EPREG_X(UECON0CLR) = AVR32_USBB_STALLRQC; }MACROE + #define Endpoint_IsStalled() ((__AVR32_EPREG_X(UECON0) & AVR32_USBB_STALLRQ) ? true : false) + #define Endpoint_ResetDataToggle() MACROS{ __AVR32_EPREG_X(UECON0CLR) = AVR32_USBB_RSTDTS; }MACROE + #define Endpoint_GetEndpointDirection() ((__AVR32_EPREG_X(UECFG0) & ENDPOINT_DIR_IN) ? true : false) + #define Endpoint_SetEndpointDirection(dir) MACROS{ __AVR32_EPREG_X(UECFG0) = \ + ((__AVR32_EPREG_X(UECFG0) & ENDPOINT_DIR_IN) | (dir)); }MACROE + #elif defined(__AVR__) + #if !defined(CONTROL_ONLY_DEVICE) + #define Endpoint_GetCurrentEndpoint() (UENUM & ENDPOINT_EPNUM_MASK) + #define Endpoint_SelectEndpoint(epnum) MACROS{ UENUM = (epnum); }MACROE + #define Endpoint_IsReadWriteAllowed() ((UEINTX & (1 << RWAL)) ? true : false) + #else + #define Endpoint_GetCurrentEndpoint() ENDPOINT_CONTROLEP + #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) + + #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{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << TXINI)); \ + UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE + #define Endpoint_ClearOUT() MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << RXOUTI)); \ + UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE + #else + #define Endpoint_ClearIN() MACROS{ UEINTX &= ~(1 << TXINI); }MACROE + #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 - - #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{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << TXINI)); \ - UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE - #else - #define Endpoint_ClearIN() MACROS{ UEINTX &= ~(1 << TXINI); }MACROE - #endif - - #if !defined(CONTROL_ONLY_DEVICE) - #define Endpoint_ClearOUT() MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << RXOUTI)); \ - UEINTX = (Temp & ~(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: */ @@ -493,7 +515,7 @@ static inline uint8_t Endpoint_Read_Byte(void) { #if defined(__AVR32__) - return 0; // TODO + return __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) return UEDATX; #endif @@ -509,7 +531,7 @@ static inline void Endpoint_Write_Byte(const uint8_t Byte) { #if defined(__AVR32__) - // TODO + __AVR32_EPREG_X(UEDAT0) = Byte; #elif defined(__AVR__) UEDATX = Byte; #endif @@ -525,7 +547,7 @@ uint8_t Dummy; #if defined(__AVR32__) - // TODO + Dummy = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Dummy = UEDATX; #endif @@ -548,7 +570,8 @@ } Data; #if defined(__AVR32__) - // TODO + Data.Bytes[0] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[1] = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Data.Bytes[0] = UEDATX; Data.Bytes[1] = UEDATX; @@ -574,7 +597,8 @@ } Data; #if defined(__AVR32__) - // TODO + Data.Bytes[1] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[0] = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Data.Bytes[1] = UEDATX; Data.Bytes[0] = UEDATX; @@ -594,7 +618,8 @@ static inline void Endpoint_Write_Word_LE(const uint16_t Word) { #if defined(__AVR32__) - // TODO + __AVR32_EPREG_X(UEDAT0) = (Word & 0xFF); + __AVR32_EPREG_X(UEDAT0) = (Word >> 8); #elif defined(__AVR__) UEDATX = (Word & 0xFF); UEDATX = (Word >> 8); @@ -612,7 +637,8 @@ static inline void Endpoint_Write_Word_BE(const uint16_t Word) { #if defined(__AVR32__) - // TODO + __AVR32_EPREG_X(UEDAT0) = (Word >> 8); + __AVR32_EPREG_X(UEDAT0) = (Word & 0xFF); #elif defined(__AVR__) UEDATX = (Word >> 8); UEDATX = (Word & 0xFF); @@ -629,7 +655,8 @@ uint8_t Dummy; #if defined(__AVR32__) - // TODO + Dummy = __AVR32_EPREG_X(UEDAT0); + Dummy = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Dummy = UEDATX; Dummy = UEDATX; @@ -653,7 +680,10 @@ } Data; #if defined(__AVR32__) - // TODO + Data.Bytes[0] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[1] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[2] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[3] = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Data.Bytes[0] = UEDATX; Data.Bytes[1] = UEDATX; @@ -681,7 +711,10 @@ } Data; #if defined(__AVR32__) - // TODO + Data.Bytes[3] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[2] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[1] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[0] = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Data.Bytes[3] = UEDATX; Data.Bytes[2] = UEDATX; @@ -703,7 +736,10 @@ static inline void Endpoint_Write_DWord_LE(const uint32_t DWord) { #if defined(__AVR32__) - // TODO + __AVR32_EPREG_X(UEDAT0) = (DWord & 0xFF); + __AVR32_EPREG_X(UEDAT0) = (DWord >> 8); + __AVR32_EPREG_X(UEDAT0) = (DWord >> 16); + __AVR32_EPREG_X(UEDAT0) = (DWord >> 24); #elif defined(__AVR__) UEDATX = (DWord & 0xFF); UEDATX = (DWord >> 8); @@ -723,7 +759,10 @@ static inline void Endpoint_Write_DWord_BE(const uint32_t DWord) { #if defined(__AVR32__) - // TODO + __AVR32_EPREG_X(UEDAT0) = (DWord >> 24); + __AVR32_EPREG_X(UEDAT0) = (DWord >> 16); + __AVR32_EPREG_X(UEDAT0) = (DWord >> 8); + __AVR32_EPREG_X(UEDAT0) = (DWord & 0xFF); #elif defined(__AVR__) UEDATX = (DWord >> 24); UEDATX = (DWord >> 16); @@ -742,7 +781,10 @@ uint8_t Dummy; #if defined(__AVR32__) - // TODO + Dummy = __AVR32_EPREG_X(UEDAT0); + Dummy = __AVR32_EPREG_X(UEDAT0); + Dummy = __AVR32_EPREG_X(UEDAT0); + Dummy = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Dummy = UEDATX; Dummy = UEDATX; @@ -792,7 +834,7 @@ * 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. + * The banking mode must be a ENDPOINT_BANK_* mask. * * \note The default control endpoint does not have to be manually configured, as it is automatically * configured by the library internally. @@ -802,8 +844,8 @@ * * \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); + bool Endpoint_ConfigureEndpoint(const uintN_t Number, const uintN_t Type, const uintN_t Direction, + const uint16_t Size, const uintN_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. @@ -875,6 +917,8 @@ * \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 * + * \note Not available on AVR32 UC3B targets. + * * \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); @@ -924,6 +968,8 @@ * \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 * + * \note Not available on AVR32 UC3B targets. + * * \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); @@ -973,6 +1019,8 @@ * \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 * + * \note Not available on AVR32 UC3B targets. + * * \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); @@ -1008,6 +1056,8 @@ * \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 * + * \note Not available on AVR32 UC3B targets. + * * \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); @@ -1049,6 +1099,8 @@ * \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. * + * \note Not available on AVR32 UC3B targets. + * * \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); @@ -1111,6 +1163,8 @@ * \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. * + * \note Not available on AVR32 UC3B targets. + * * \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); @@ -1173,6 +1227,8 @@ * \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. * + * \note Not available on AVR32 UC3B targets. + * * \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); @@ -1214,6 +1270,8 @@ * \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. * + * \note Not available on AVR32 UC3B targets. + * * \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); @@ -1221,8 +1279,29 @@ /* 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 + #if defined(__AVR32__) + #define Endpoint_AllocateMemory() MACROS{ __AVR32_EPREG_X(UECFG10) |= AVR32_USBB_UECFG0_ALLOC_MASK; }MACROE + #define Endpoint_DeallocateMemory() MACROS{ __AVR32_EPREG_X(UECFG10) &= ~AVR32_USBB_UECFG0_ALLOC_MASK; }MACROE + + #define Endpoint_ConfigureEndpoint(Number, Type, Direction, Size, Banks) \ + Endpoint_ConfigureEndpoint_Prv((Number), \ + (((Type) << AVR32_USBB_UECFG0_EPTYPE) | (Direction)), \ + (AVR32_USBB_UECFG0_ALLOC_MASK | (Banks) | \ + (__builtin_constant_p(Size) ? \ + Endpoint_BytesToEPSizeMask(Size) : \ + Endpoint_BytesToEPSizeMaskDynamic(Size)))) + #elif defined(__AVR__) + #define Endpoint_AllocateMemory() MACROS{ UECFG1X |= (1 << ALLOC); }MACROE + #define Endpoint_DeallocateMemory() MACROS{ UECFG1X &= ~(1 << ALLOC); }MACROE + + #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)))) + #endif #define _ENDPOINT_GET_MAXSIZE(n) _ENDPOINT_GET_MAXSIZE2(ENDPOINT_DETAILS_EP ## n) #define _ENDPOINT_GET_MAXSIZE2(details) _ENDPOINT_GET_MAXSIZE3(details) @@ -1240,7 +1319,15 @@ #define ENDPOINT_DETAILS_EP4 64, true #define ENDPOINT_DETAILS_EP5 64, true #define ENDPOINT_DETAILS_EP6 64, true - #else + #elif defined(USB_SERIES_UC3B_AVR) + #define ENDPOINT_DETAILS_EP0 64, false + #define ENDPOINT_DETAILS_EP1 64, true + #define ENDPOINT_DETAILS_EP2 64, true + #define ENDPOINT_DETAILS_EP3 64, true + #define ENDPOINT_DETAILS_EP4 64, true + #define ENDPOINT_DETAILS_EP5 256, true + #define ENDPOINT_DETAILS_EP6 256, true + #elif defined(USB_SERIES_2_AVR) #define ENDPOINT_DETAILS_EP0 64, true #define ENDPOINT_DETAILS_EP1 64, false #define ENDPOINT_DETAILS_EP2 64, false @@ -1248,23 +1335,27 @@ #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); + uintN_t Endpoint_BytesToEPSizeMaskDynamic(const uint16_t Size); + bool Endpoint_ConfigureEndpoint_Prv(const uintN_t Number, const uintN_t UECFG0XData, const uintN_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) + static inline uintN_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE; + static inline uintN_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) { + #if defined(__AVR32__) + uint8_t MaskVal = 0; + uint16_t CheckBytes = 8; + + while (CheckBytes < Bytes) + { + MaskVal++; + CheckBytes <<= 1; + } + + return (MaskVal << AVR32_USBB_EPSIZE); + #else uint8_t MaskVal = 0; uint16_t CheckBytes = 8; @@ -1275,6 +1366,7 @@ } return (MaskVal << EPSIZE0); + #endif } #endif diff --git a/LUFA/Drivers/USB/LowLevel/Host.h b/LUFA/Drivers/USB/LowLevel/Host.h index 1e4d3c96d1..82a90d2dfc 100644 --- a/LUFA/Drivers/USB/LowLevel/Host.h +++ b/LUFA/Drivers/USB/LowLevel/Host.h @@ -63,7 +63,7 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif /* Public Interface - May be used in end-application: */ @@ -165,25 +165,29 @@ */ 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) + #if defined(__AVR32__) + #define USB_Host_ResetBus() MACROS{ AVR32_USBB.UHCON.reset = true; }MACROE + #define USB_Host_IsBusResetComplete() AVR32_USBB.UHCON.reset + #define USB_Host_ResumeBus() MACROS{ AVR32_USBB.UHCON.sofen = true; }MACROE + #define USB_Host_SuspendBus() MACROS{ AVR32_USBB.UHCON.sofen = false; }MACROE + #define USB_Host_IsBusSuspended() AVR32_USBB.UHCON.sofen + #define USB_Host_IsDeviceFullSpeed() (AVR32_USBB.USBSTA.speed == 0) + #define USB_Host_IsRemoteWakeupSent() AVR32_USBB.UHINT.rxrsmi + #define USB_Host_ClearRemoteWakeupSent() MACROS{ AVR32_USBB.UHINTCLR.rxrsmic = true; }MACROE + #define USB_Host_ResumeFromWakeupRequest() MACROS{ AVR32_USBB.UHCON.resume = true; }MACROE + #define USB_Host_IsResumeFromWakeupRequestSent() AVR32_USBB.UHCON.resume + #elif defined(__AVR__) + #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 #endif /* Function Prototypes: */ @@ -381,20 +385,36 @@ /* 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 + #if defined(__AVR32__) + #define USB_Host_HostMode_On() MACROS{ AVR32_USBB.USBCON.uimod = false; }MACROE + #define USB_Host_HostMode_Off() MACROS{ AVR32_USBB.USBCON.uimod = true; }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_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_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_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 + #define USB_Host_SetDeviceAddress(addr) MACROS{ UHADDR = ((addr) & 0x7F); }MACROE + #elif defined(__AVR__) + #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 + #endif + /* Enums: */ enum USB_Host_WaitMSErrorCodes_t { diff --git a/LUFA/Drivers/USB/LowLevel/HostChapter9.h b/LUFA/Drivers/USB/LowLevel/HostChapter9.h index 1bd8b6f971..5bf228ee20 100644 --- a/LUFA/Drivers/USB/LowLevel/HostChapter9.h +++ b/LUFA/Drivers/USB/LowLevel/HostChapter9.h @@ -52,7 +52,7 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif /* Public Interface - May be used in end-application: */ diff --git a/LUFA/Drivers/USB/LowLevel/LowLevel.c b/LUFA/Drivers/USB/LowLevel/LowLevel.c index f4f277ccb7..0d220cedca 100644 --- a/LUFA/Drivers/USB/LowLevel/LowLevel.c +++ b/LUFA/Drivers/USB/LowLevel/LowLevel.c @@ -39,6 +39,10 @@ volatile uint8_t USB_CurrentMode = USB_MODE_NONE; volatile uint8_t USB_Options; #endif +#if defined(__AVR32__) && !defined(CONTROL_ONLY_DEVICE) +uint8_t USB_SelectedEPNumber; +#endif + void USB_Init( #if defined(USB_CAN_BE_BOTH) const uint8_t Mode @@ -55,6 +59,10 @@ void USB_Init( #endif ) { + #if defined(__AVR32__) + USB_SelectedEPNumber = 0; + #endif + #if defined(USB_CAN_BE_BOTH) USB_CurrentMode = Mode; #endif diff --git a/LUFA/Drivers/USB/LowLevel/LowLevel.h b/LUFA/Drivers/USB/LowLevel/LowLevel.h index 581dfd1136..2c8ade7b3b 100644 --- a/LUFA/Drivers/USB/LowLevel/LowLevel.h +++ b/LUFA/Drivers/USB/LowLevel/LowLevel.h @@ -39,6 +39,15 @@ #ifndef __USBLOWLEVEL_H__ #define __USBLOWLEVEL_H__ + /* External Variables: */ + #if defined(__AVR32__) + #if !defined(CONTROL_ONLY_DEVICE) + extern uint8_t USB_SelectedEPNumber; + #else + #define USB_SelectedEPNumber 0 + #endif + #endif + /* Includes: */ #if defined(__AVR32__) #include @@ -77,7 +86,7 @@ /* Preprocessor Checks and Defines: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif #if !defined(F_CLOCK) @@ -354,16 +363,22 @@ #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 defined(__AVR32__) + if (AVR32_USBB.USBSTA.id) + return USB_MODE_DEVICE; + else + return USB_MODE_HOST; + #elif defined(__AVR__) if (USBSTA & (1 << ID)) return USB_MODE_DEVICE; else return USB_MODE_HOST; + #endif } #endif diff --git a/LUFA/Drivers/USB/LowLevel/OTG.h b/LUFA/Drivers/USB/LowLevel/OTG.h index acbd47937a..717b040075 100644 --- a/LUFA/Drivers/USB/LowLevel/OTG.h +++ b/LUFA/Drivers/USB/LowLevel/OTG.h @@ -55,7 +55,7 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif /* Public Interface - May be used in end-application: */ diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.h b/LUFA/Drivers/USB/LowLevel/Pipe.h index 08935e1f11..fca44d8665 100644 --- a/LUFA/Drivers/USB/LowLevel/Pipe.h +++ b/LUFA/Drivers/USB/LowLevel/Pipe.h @@ -86,6 +86,7 @@ #endif #include "../../../Common/Common.h" + #include "LowLevel.h" #include "../HighLevel/USBTask.h" #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) @@ -99,7 +100,7 @@ /* Preprocessor Checks: */ #if !defined(__INCLUDE_FROM_USB_DRIVER) - #error Do not include this file directly. Include LUFA/Drivers/USB.h instead. + #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #endif /* Public Interface - May be used in end-application: */ @@ -554,7 +555,7 @@ static inline uint8_t Pipe_Read_Byte(void) { #if defined(__AVR32__) - return 0; // TODO + return __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) return UPDATX; #endif @@ -570,7 +571,7 @@ static inline void Pipe_Write_Byte(const uint8_t Byte) { #if defined(__AVR32__) - // TODO + __AVR32_EPREG_X(UEDAT0) = Byte; #elif defined(__AVR__) UPDATX = Byte; #endif @@ -586,7 +587,7 @@ uint8_t Dummy; #if defined(__AVR32__) - // TODO + Dummy = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Dummy = UPDATX; #endif @@ -609,7 +610,8 @@ } Data; #if defined(__AVR32__) - // TODO + Data.Bytes[0] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[1] = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Data.Bytes[0] = UPDATX; Data.Bytes[1] = UPDATX; @@ -635,7 +637,8 @@ } Data; #if defined(__AVR32__) - // TODO + Data.Bytes[1] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[0] = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Data.Bytes[1] = UPDATX; Data.Bytes[0] = UPDATX; @@ -655,7 +658,8 @@ static inline void Pipe_Write_Word_LE(const uint16_t Word) { #if defined(__AVR32__) - // TODO + __AVR32_EPREG_X(UEDAT0) = (Word & 0xFF); + __AVR32_EPREG_X(UEDAT0) = (Word >> 8); #elif defined(__AVR__) UPDATX = (Word & 0xFF); UPDATX = (Word >> 8); @@ -673,7 +677,8 @@ static inline void Pipe_Write_Word_BE(const uint16_t Word) { #if defined(__AVR32__) - // TODO + __AVR32_EPREG_X(UEDAT0) = (Word >> 8); + __AVR32_EPREG_X(UEDAT0) = (Word & 0xFF); #elif defined(__AVR__) UPDATX = (Word >> 8); UPDATX = (Word & 0xFF); @@ -690,7 +695,8 @@ uint8_t Dummy; #if defined(__AVR32__) - // TODO + Dummy = __AVR32_EPREG_X(UEDAT0); + Dummy = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Dummy = UPDATX; Dummy = UPDATX; @@ -714,7 +720,10 @@ } Data; #if defined(__AVR32__) - // TODO + Data.Bytes[0] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[1] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[2] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[3] = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Data.Bytes[0] = UPDATX; Data.Bytes[1] = UPDATX; @@ -742,12 +751,16 @@ } Data; #if defined(__AVR32__) - // TODO + Data.Bytes[3] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[2] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[1] = __AVR32_EPREG_X(UEDAT0); + Data.Bytes[0] = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Data.Bytes[3] = UPDATX; Data.Bytes[2] = UPDATX; Data.Bytes[1] = UPDATX; Data.Bytes[0] = UPDATX; + #endif return Data.DWord; } @@ -763,7 +776,10 @@ static inline void Pipe_Write_DWord_LE(const uint32_t DWord) { #if defined(__AVR32__) - // TODO + __AVR32_EPREG_X(UEDAT0) = (DWord & 0xFF); + __AVR32_EPREG_X(UEDAT0) = (DWord >> 8); + __AVR32_EPREG_X(UEDAT0) = (DWord >> 16); + __AVR32_EPREG_X(UEDAT0) = (DWord >> 24); #elif defined(__AVR__) UPDATX = (DWord & 0xFF); UPDATX = (DWord >> 8); @@ -783,7 +799,10 @@ static inline void Pipe_Write_DWord_BE(const uint32_t DWord) { #if defined(__AVR32__) - // TODO + __AVR32_EPREG_X(UEDAT0) = (DWord >> 24); + __AVR32_EPREG_X(UEDAT0) = (DWord >> 16); + __AVR32_EPREG_X(UEDAT0) = (DWord >> 8); + __AVR32_EPREG_X(UEDAT0) = (DWord & 0xFF); #elif defined(__AVR__) UPDATX = (DWord >> 24); UPDATX = (DWord >> 16); @@ -802,7 +821,10 @@ uint8_t Dummy; #if defined(__AVR32__) - // TODO + Dummy = __AVR32_EPREG_X(UEDAT0); + Dummy = __AVR32_EPREG_X(UEDAT0); + Dummy = __AVR32_EPREG_X(UEDAT0); + Dummy = __AVR32_EPREG_X(UEDAT0); #elif defined(__AVR__) Dummy = UPDATX; Dummy = UPDATX; @@ -932,6 +954,8 @@ * \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 * + * \note Not available on AVR32 UC3B targets. + * * \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); @@ -981,6 +1005,8 @@ * \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 * + * \note Not available on AVR32 UC3B targets. + * * \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); @@ -1030,6 +1056,8 @@ * \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 * + * \note Not available on AVR32 UC3B targets. + * * \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); @@ -1065,6 +1093,8 @@ * \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 * + * \note Not available on AVR32 UC3B targets. + * * \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); @@ -1085,9 +1115,13 @@ 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) + static inline uintN_t Pipe_BytesToEPSizeMask(uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE; + static inline uintN_t Pipe_BytesToEPSizeMask(uint16_t Bytes) { + #if defined(__AVR32__) + // TODO + return 0; + #elif defined(__AVR__) if (Bytes <= 8) return (0 << EPSIZE0); else if (Bytes <= 16) @@ -1100,6 +1134,7 @@ return (4 << EPSIZE0); else return (5 << EPSIZE0); + #endif } #endif diff --git a/LUFA/Drivers/USB/USB.h b/LUFA/Drivers/USB/USB.h index 484978bede..d648ebe518 100644 --- a/LUFA/Drivers/USB/USB.h +++ b/LUFA/Drivers/USB/USB.h @@ -354,6 +354,10 @@ #if !defined(__DOXYGEN__) #define __INCLUDE_FROM_USB_DRIVER #endif + + #if defined(__AVR32__) + #define __AVR32_EPREG_X(x) ((volatile uint32_t*)AVR32_USBB_ ## x)[USB_SelectedEPNumber] + #endif /* Includes: */ #include "HighLevel/USBMode.h" diff --git a/LUFA/ManPages/CompileTimeTokens.txt b/LUFA/ManPages/CompileTimeTokens.txt index 9beeecebe5..5700c3aabe 100644 --- a/LUFA/ManPages/CompileTimeTokens.txt +++ b/LUFA/ManPages/CompileTimeTokens.txt @@ -148,6 +148,7 @@ * may be defined to a value between 0 and 2 to fix the state variable into one of the three general purpose IO registers inside the AVR * reserved for application use. When defined, the corresponding GPIOR register should not be used within the user application except * implicitly via the library APIs. + * \note This compile time option is ignored for the AVR32 UC3B architecture. * * FIXED_NUM_CONFIGURATIONS=x - ( \ref Group_Device ) \n * By default, the library determines the number of configurations a USB device supports by reading the device descriptor. This reduces @@ -186,6 +187,7 @@ * may be defined to a value between 0 and 2 to fix the state variable into one of the three general purpose IO registers inside the AVR * reserved for application use. When defined, the corresponding GPIOR register should not be used within the user application except * implicitly via the library APIs. + * \note This compile time option is ignored for the AVR32 UC3B architecture. * * USB_HOST_TIMEOUT_MS=x - ( \ref Group_Host ) \n * When a control transfer is initiated in host mode to an attached device, a timeout is used to abort the transfer if the attached