diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2014-07-22 19:08:25 +1000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2014-07-22 19:08:25 +1000 |
commit | 89df1efcf3ecb625c172a47def21e18912fc46f3 (patch) | |
tree | 4a8e5ca4fe3a6214981e4beda8617aa0086d369d /LUFA/Drivers/USB/Core | |
parent | 526091fba4e1b86d14c8fcff5d32953c15ed0802 (diff) | |
parent | c499a0b7550ba26e4b26e11ae13935f094f22ddc (diff) | |
download | lufa-89df1efcf3ecb625c172a47def21e18912fc46f3.tar.gz lufa-89df1efcf3ecb625c172a47def21e18912fc46f3.tar.bz2 lufa-89df1efcf3ecb625c172a47def21e18912fc46f3.zip |
Merge pull request #32 from The-42/fix-xmega-usb-prescaler
Fix XMEGA USB prescaler calculation (thanks to Bert van Hall).
Diffstat (limited to 'LUFA/Drivers/USB/Core')
-rw-r--r-- | LUFA/Drivers/USB/Core/XMEGA/USBController_XMEGA.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/LUFA/Drivers/USB/Core/XMEGA/USBController_XMEGA.c b/LUFA/Drivers/USB/Core/XMEGA/USBController_XMEGA.c index f8b0fc6af..b5de862f1 100644 --- a/LUFA/Drivers/USB/Core/XMEGA/USBController_XMEGA.c +++ b/LUFA/Drivers/USB/Core/XMEGA/USBController_XMEGA.c @@ -109,15 +109,25 @@ void USB_Disable(void) void USB_ResetInterface(void) { + uint8_t PrescalerNeeded; + uint8_t nbit = 0; + #if defined(USB_DEVICE_OPT_FULLSPEED) if (USB_Options & USB_DEVICE_OPT_LOWSPEED) - CLK.USBCTRL = (((F_USB / 6000000) - 1) << CLK_USBPSDIV_gp); + PrescalerNeeded = F_USB / 6000000; else - CLK.USBCTRL = (((F_USB / 48000000) - 1) << CLK_USBPSDIV_gp); + PrescalerNeeded = F_USB / 48000000; #else - CLK.USBCTRL = (((F_USB / 6000000) - 1) << CLK_USBPSDIV_gp); + PrescalerNeeded = F_USB / 6000000; #endif + while (PrescalerNeeded && nbit < 7) { + PrescalerNeeded >>= 1; + nbit++; + } + + CLK.USBCTRL = (nbit - 1) << CLK_USBPSDIV_gp; + if (USB_Options & USB_OPT_PLLCLKSRC) CLK.USBCTRL |= (CLK_USBSRC_PLL_gc | CLK_USBSEN_bm); else |