Add branch for the conversion of demos to use standard C header files for configurati...
[pub/USBasp.git] / LUFA / Drivers / USB / Core / XMEGA / USBController_XMEGA.c
index 387e8e4..844ef65 100644 (file)
@@ -43,7 +43,8 @@ volatile uint8_t USB_CurrentMode = USB_MODE_None;
 volatile uint8_t USB_Options;
 #endif
 
-USB_EndpointTable_t USB_EndpointTable ATTR_ALIGNED(4);
+/* Ugly workaround to ensure an aligned table, since __BIGGEST_ALIGNMENT__ == 1 for 8-bit AVR-GCC */
+uint8_t USB_EndpointTable[sizeof(USB_EndpointTable_t) + 1];
 
 void USB_Init(
                #if defined(USB_CAN_BE_BOTH)
@@ -75,8 +76,9 @@ void USB_Init(
        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);
+       /* Ugly workaround to ensure an aligned table, since __BIGGEST_ALIGNMENT__ == 1 for 8-bit AVR-GCC */
+       USB.EPPTR = ((intptr_t)&USB_EndpointTable[1] & ~(1 << 0));
+       USB.CTRLA = (USB_STFRNUM_bm | ((ENDPOINT_TOTAL_ENDPOINTS - 1) << USB_MAXEP_gp));
 
        if ((USB_Options & USB_OPT_BUSEVENT_PRIHIGH) == USB_OPT_BUSEVENT_PRIHIGH)
          USB.INTCTRLA = (3 << USB_INTLVL_gp);
@@ -103,13 +105,17 @@ void USB_Disable(void)
 
 void USB_ResetInterface(void)
 {
+       #if defined(USB_DEVICE_OPT_FULLSPEED)
        if (USB_Options & USB_DEVICE_OPT_LOWSPEED)
          CLK.USBCTRL = (((F_USB / 6000000) - 1) << CLK_USBPSDIV_gp);
        else
          CLK.USBCTRL = (((F_USB / 48000000) - 1) << CLK_USBPSDIV_gp);
-
+       #else
+       CLK.USBCTRL = (((F_USB / 6000000) - 1) << CLK_USBPSDIV_gp);
+       #endif
+       
        if (USB_Options & USB_OPT_PLLCLKSRC)
-         CLK.USBCTRL |= (CLK_USBSRC_PLL_gc | CLK_USBSEN_bm);
+         CLK.USBCTRL |= (CLK_USBSRC_PLL_gc   | CLK_USBSEN_bm);
        else
          CLK.USBCTRL |= (CLK_USBSRC_RC32M_gc | CLK_USBSEN_bm);
 
@@ -172,8 +178,7 @@ static void USB_Init_Device(void)
          USB_Device_SetFullSpeed();
 
        Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
-                                                          ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
-                                                          ENDPOINT_BANK_SINGLE);
+                                                          USB_Device_ControlEndpointSize, 1);
 
        USB_INT_Enable(USB_INT_BUSEVENTI);