Implementation of several key core USB driver functions for the new USB XMEGA devices.
[pub/lufa.git] / LUFA / Drivers / USB / Core / XMEGA / USBController_XMEGA.c
index 52d44fe..2556ee8 100644 (file)
@@ -56,22 +56,88 @@ void USB_Init(
                #endif\r
                )\r
 {\r
-       // TODO\r
+       #if !defined(USE_STATIC_OPTIONS)\r
+       USB_Options = Options;\r
+       #endif\r
+       \r
+       USB_IsInitialized = true;\r
+\r
+       USB_ResetInterface();   \r
 }\r
 \r
 void USB_Disable(void)\r
 {\r
-       // TODO\r
+       USB_INT_DisableAllInterrupts();\r
+       USB_INT_ClearAllInterrupts();\r
+\r
+       USB_Detach();\r
+       USB_Controller_Disable();\r
+\r
+       USB_IsInitialized = false;      \r
 }\r
 \r
 void USB_ResetInterface(void)\r
 {\r
-       // TODO\r
+       USB_INT_DisableAllInterrupts();\r
+       USB_INT_ClearAllInterrupts();\r
+\r
+       USB_Controller_Reset();\r
+       USB_Init_Device();\r
 }\r
 \r
 #if defined(USB_CAN_BE_DEVICE)\r
 static void USB_Init_Device(void)\r
 {\r
-       // TODO\r
+       USB_DeviceState                 = DEVICE_STATE_Unattached;\r
+       USB_Device_ConfigurationNumber  = 0;\r
+\r
+       #if !defined(NO_DEVICE_REMOTE_WAKEUP)\r
+       USB_Device_RemoteWakeupEnabled  = false;\r
+       #endif\r
+\r
+       #if !defined(NO_DEVICE_SELF_POWER)\r
+       USB_Device_CurrentlySelfPowered = false;\r
+       #endif\r
+\r
+       #if !defined(FIXED_CONTROL_ENDPOINT_SIZE)\r
+       USB_Descriptor_Device_t* DeviceDescriptorPtr;\r
+       \r
+       #if defined(ARCH_HAS_MULTI_ADDRESS_SPACE) && \\r
+           !(defined(USE_FLASH_DESCRIPTORS) || defined(USE_EEPROM_DESCRIPTORS) || defined(USE_RAM_DESCRIPTORS))\r
+       uint8_t DescriptorAddressSpace;\r
+\r
+       if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr, &DescriptorAddressSpace) != NO_DESCRIPTOR)\r
+       {\r
+               if (DescriptorAddressSpace == MEMSPACE_FLASH)\r
+                 USB_Device_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size);\r
+               else if (DescriptorAddressSpace == MEMSPACE_EEPROM)\r
+                 USB_Device_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size);\r
+               else\r
+                 USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;\r
+       }\r
+       #else\r
+       if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR)\r
+       {\r
+               #if defined(USE_RAM_DESCRIPTORS)\r
+               USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;\r
+               #elif defined(USE_EEPROM_DESCRIPTORS)\r
+               USB_Device_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size);\r
+               #else\r
+               USB_Device_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size);\r
+               #endif\r
+       }       \r
+       #endif\r
+       #endif\r
+\r
+       if (USB_Options & USB_DEVICE_OPT_LOWSPEED)\r
+         USB_Device_SetLowSpeed();\r
+       else\r
+         USB_Device_SetFullSpeed();\r
+\r
+       Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,\r
+                                                          ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,\r
+                                                          ENDPOINT_BANK_SINGLE);\r
+\r
+       USB_Attach();\r
 }\r
 #endif\r