diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2011-10-31 02:26:21 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2011-10-31 02:26:21 +0000 |
commit | 0304916356ea83bb17783df157c79cbfdef0d45b (patch) | |
tree | 5a4671825b203897c7c43146b578716cb10e74bc /LUFA/Drivers | |
parent | eb5b8a32e4d254479b14c82d36de8e17218640c4 (diff) | |
download | lufa-0304916356ea83bb17783df157c79cbfdef0d45b.tar.gz lufa-0304916356ea83bb17783df157c79cbfdef0d45b.tar.bz2 lufa-0304916356ea83bb17783df157c79cbfdef0d45b.zip |
Fix XMEGA core USB driver so that device mode enumerates correctly on the host PC.
Diffstat (limited to 'LUFA/Drivers')
-rw-r--r-- | LUFA/Drivers/USB/Core/XMEGA/Device_XMEGA.h | 1 | ||||
-rw-r--r-- | LUFA/Drivers/USB/Core/XMEGA/Endpoint_XMEGA.c | 23 | ||||
-rw-r--r-- | LUFA/Drivers/USB/Core/XMEGA/Endpoint_XMEGA.h | 21 | ||||
-rw-r--r-- | LUFA/Drivers/USB/Core/XMEGA/USBController_XMEGA.c | 2 |
4 files changed, 37 insertions, 10 deletions
diff --git a/LUFA/Drivers/USB/Core/XMEGA/Device_XMEGA.h b/LUFA/Drivers/USB/Core/XMEGA/Device_XMEGA.h index df6823a9c..1c128dc10 100644 --- a/LUFA/Drivers/USB/Core/XMEGA/Device_XMEGA.h +++ b/LUFA/Drivers/USB/Core/XMEGA/Device_XMEGA.h @@ -211,6 +211,7 @@ NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc; SerialByte = pgm_read_byte(SigReadAddress); + NVM.CMD = 0; if (SerialCharNum & 0x01) { diff --git a/LUFA/Drivers/USB/Core/XMEGA/Endpoint_XMEGA.c b/LUFA/Drivers/USB/Core/XMEGA/Endpoint_XMEGA.c index 3c9ba27ea..604427fca 100644 --- a/LUFA/Drivers/USB/Core/XMEGA/Endpoint_XMEGA.c +++ b/LUFA/Drivers/USB/Core/XMEGA/Endpoint_XMEGA.c @@ -53,7 +53,7 @@ bool Endpoint_ConfigureEndpoint_PRV(const uint8_t Number, Endpoint_SelectEndpoint(Number | Direction); USB_Endpoint_SelectedHandle->CTRL = 0; - USB_Endpoint_SelectedHandle->STATUS = (Direction == ENDPOINT_DIR_IN) ? (USB_EP_BUSNACK0_bm | USB_EP_TRNCOMPL0_bm) : USB_EP_BUSNACK0_bm; + USB_Endpoint_SelectedHandle->STATUS = (Direction == ENDPOINT_DIR_IN) ? USB_EP_BUSNACK0_bm : 0; USB_Endpoint_SelectedHandle->CTRL = Config; USB_Endpoint_SelectedHandle->CNT = 0; USB_Endpoint_SelectedHandle->DATAPTR = (intptr_t)&USB_Endpoint_SelectedFIFO->Data[0]; @@ -72,13 +72,26 @@ void Endpoint_ClearEndpoints(void) void Endpoint_ClearStatusStage(void) { - while (!(Endpoint_IsOUTReceived())) + if (USB_ControlRequest.bmRequestType & REQDIR_DEVICETOHOST) { - if (USB_DeviceState == DEVICE_STATE_Unattached) - return; + while (!(Endpoint_IsOUTReceived())) + { + if (USB_DeviceState == DEVICE_STATE_Unattached) + return; + } + + Endpoint_ClearOUT(); } + else + { + while (!(Endpoint_IsINReady())) + { + if (USB_DeviceState == DEVICE_STATE_Unattached) + return; + } - Endpoint_ClearOUT(); + Endpoint_ClearIN(); + } } #if !defined(CONTROL_ONLY_DEVICE) diff --git a/LUFA/Drivers/USB/Core/XMEGA/Endpoint_XMEGA.h b/LUFA/Drivers/USB/Core/XMEGA/Endpoint_XMEGA.h index c26f7e5b4..2ba135619 100644 --- a/LUFA/Drivers/USB/Core/XMEGA/Endpoint_XMEGA.h +++ b/LUFA/Drivers/USB/Core/XMEGA/Endpoint_XMEGA.h @@ -433,7 +433,7 @@ { Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); - return ((USB_Endpoint_SelectedHandle->STATUS & USB_EP_TRNCOMPL0_bm) ? true : false); + return ((USB_Endpoint_SelectedHandle->STATUS & USB_EP_BUSNACK0_bm) ? true : false); } /** Determines if the selected OUT endpoint has received new packet from the host. @@ -486,7 +486,13 @@ static inline void Endpoint_ClearSETUP(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_ClearSETUP(void) { - USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_SETUP_bm | USB_EP_BUSNACK0_bm); + USB_Endpoint_SelectedHandle->STATUS &= ~(USB_EP_SETUP_bm | USB_EP_TRNCOMPL0_bm | USB_EP_BUSNACK0_bm | USB_EP_OVF_bm); + + USB_Endpoint_SelectedHandle->STATUS |= USB_EP_TOGGLE_bm; + USB_Endpoint_SelectedFIFO->Position = 0; + + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); + USB_Endpoint_SelectedHandle->STATUS |= USB_EP_TOGGLE_bm; USB_Endpoint_SelectedFIFO->Position = 0; } @@ -529,7 +535,14 @@ static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_StallTransaction(void) { - USB_Endpoint_SelectedHandle->CTRL |= USB_EP_STALL_bm; + USB_Endpoint_SelectedHandle->CTRL |= USB_EP_STALL_bm; + + if ((USB_Endpoint_SelectedHandle->CTRL & USB_EP_TYPE_gm) == USB_EP_TYPE_CONTROL_gc) + { + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN); + USB_Endpoint_SelectedHandle->STATUS |= USB_EP_STALL_bm; + Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint & ~ENDPOINT_DIR_IN); + } } /** Clears the STALL condition on the currently selected endpoint. @@ -551,7 +564,7 @@ static inline bool Endpoint_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsStalled(void) { - return ((USB_Endpoint_SelectedHandle->CTRL & USB_EP_STALL_bm) ? true : false); + return ((USB_Endpoint_SelectedHandle->CTRL & USB_EP_STALLF_bm) ? true : false); } /** Resets the data toggle of the currently selected endpoint. */ diff --git a/LUFA/Drivers/USB/Core/XMEGA/USBController_XMEGA.c b/LUFA/Drivers/USB/Core/XMEGA/USBController_XMEGA.c index 58d1b768b..3b7793020 100644 --- a/LUFA/Drivers/USB/Core/XMEGA/USBController_XMEGA.c +++ b/LUFA/Drivers/USB/Core/XMEGA/USBController_XMEGA.c @@ -69,8 +69,8 @@ void USB_Init( NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc; USB.CAL0 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL0)); - NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc; USB.CAL1 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL1)); + NVM.CMD = 0; USB.EPPTR = (intptr_t)&USB_EndpointTable; USB.CTRLA = (USB_STFRNUM_bm | USB_MAXEP_gm); |