Commit 944e0d20 authored by Dean Camera's avatar Dean Camera

Rename UC3B driver files to UC3, as they are generic to all AVR32 UC3 models.

parent 6005a421
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -64,8 +64,8 @@ ...@@ -64,8 +64,8 @@
/** Selects the Atmel 8-bit AVR (AT90USB* and ATMEGA*U* chips) architecture. */ /** Selects the Atmel 8-bit AVR (AT90USB* and ATMEGA*U* chips) architecture. */
#define ARCH_AVR8 0 #define ARCH_AVR8 0
/** Selects the Atmel 32-bit UC3B AVR (AT32UC3B* chips) architecture. */ /** Selects the Atmel 32-bit UC3 AVR (AT32UC3* chips) architecture. */
#define ARCH_UC3B 1 #define ARCH_UC3 1
#if !defined(__DOXYGEN__) #if !defined(__DOXYGEN__)
#define ARCH_ ARCH_AVR8 #define ARCH_ ARCH_AVR8
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
#define ARCH_LITTLE_ENDIAN #define ARCH_LITTLE_ENDIAN
#include "Endianness.h" #include "Endianness.h"
#elif (ARCH == ARCH_UC3B) #elif (ARCH == ARCH_UC3)
#include <avr32/io.h> #include <avr32/io.h>
// === TODO: Find abstracted way to handle these === // === TODO: Find abstracted way to handle these ===
......
...@@ -128,8 +128,8 @@ ...@@ -128,8 +128,8 @@
/* Architecture Includes: */ /* Architecture Includes: */
#if (ARCH == ARCH_AVR8) #if (ARCH == ARCH_AVR8)
#include "AVR8/Device_AVR8.h" #include "AVR8/Device_AVR8.h"
#elif (ARCH == ARCH_UC3B) #elif (ARCH == ARCH_UC3)
#include "UC3B/Device_UC3B.h" #include "UC3/Device_UC3.h"
#endif #endif
#endif #endif
......
...@@ -101,8 +101,8 @@ ...@@ -101,8 +101,8 @@
/* Architecture Includes: */ /* Architecture Includes: */
#if (ARCH == ARCH_AVR8) #if (ARCH == ARCH_AVR8)
#include "AVR8/Endpoint_AVR8.h" #include "AVR8/Endpoint_AVR8.h"
#elif (ARCH == ARCH_UC3B) #elif (ARCH == ARCH_UC3)
#include "UC3B/Endpoint_UC3B.h" #include "UC3/Endpoint_UC3.h"
#endif #endif
#endif #endif
......
...@@ -165,8 +165,8 @@ ...@@ -165,8 +165,8 @@
/* Architecture Includes: */ /* Architecture Includes: */
#if (ARCH == ARCH_AVR8) #if (ARCH == ARCH_AVR8)
#include "AVR8/Host_AVR8.h" #include "AVR8/Host_AVR8.h"
#elif (ARCH == ARCH_UC3B) #elif (ARCH == ARCH_UC3)
#include "UC3B/Host_UC3B.h" #include "UC3/Host_UC3.h"
#endif #endif
#endif #endif
......
...@@ -116,8 +116,8 @@ ...@@ -116,8 +116,8 @@
/* Architecture Includes: */ /* Architecture Includes: */
#if (ARCH == ARCH_AVR8) #if (ARCH == ARCH_AVR8)
#include "AVR8/Pipe_AVR8.h" #include "AVR8/Pipe_AVR8.h"
#elif (ARCH == ARCH_UC3B) #elif (ARCH == ARCH_UC3)
#include "UC3B/Pipe_UC3B.h" #include "UC3/Pipe_UC3.h"
#endif #endif
#endif #endif
......
...@@ -29,24 +29,24 @@ ...@@ -29,24 +29,24 @@
*/ */
/** \file /** \file
* \brief USB Device definitions for the AVR32 UC3B microcontrollers. * \brief USB Device definitions for the AVR32 UC3 microcontrollers.
* \copydetails Group_Device_UC3B * \copydetails Group_Device_UC3
* *
* \note This file should not be included directly. It is automatically included as needed by the USB driver * \note This file should not be included directly. It is automatically included as needed by the USB driver
* dispatch header located in LUFA/Drivers/USB/USB.h. * dispatch header located in LUFA/Drivers/USB/USB.h.
*/ */
/** \ingroup Group_Device /** \ingroup Group_Device
* \defgroup Group_Device_UC3B Device Management (UC3B) * \defgroup Group_Device_UC3 Device Management (UC3)
* \brief USB Device definitions for the AVR32 UC3B microcontrollers. * \brief USB Device definitions for the AVR32 UC3 microcontrollers.
* *
* Architecture specific USB Device definitions for the Atmel 32-bit UC3B AVR microcontrollers. * Architecture specific USB Device definitions for the Atmel 32-bit UC3 AVR microcontrollers.
* *
* @{ * @{
*/ */
#ifndef __USBDEVICE_UC3B_H__ #ifndef __USBDEVICE_UC3_H__
#define __USBDEVICE_UC3B_H__ #define __USBDEVICE_UC3_H__
/* Includes: */ /* Includes: */
#include "../../../../Common/Common.h" #include "../../../../Common/Common.h"
......
...@@ -29,24 +29,24 @@ ...@@ -29,24 +29,24 @@
*/ */
/** \file /** \file
* \brief USB Controller definitions for the AVR32 UC3B microcontrollers. * \brief USB Controller definitions for the AVR32 UC3 microcontrollers.
* \copydetails Group_USBManagement_UC3B * \copydetails Group_USBManagement_UC3
* *
* \note This file should not be included directly. It is automatically included as needed by the USB driver * \note This file should not be included directly. It is automatically included as needed by the USB driver
* dispatch header located in LUFA/Drivers/USB/USB.h. * dispatch header located in LUFA/Drivers/USB/USB.h.
*/ */
/** \ingroup Group_USBManagement /** \ingroup Group_USBManagement
* \defgroup Group_USBManagement_UC3B USB Interface Management (UC3B) * \defgroup Group_USBManagement_UC3 USB Interface Management (UC3)
* \brief USB Controller definitions for the AVR32 UC3B microcontrollers. * \brief USB Controller definitions for the AVR32 UC3 microcontrollers.
* *
* Functions, macros, variables, enums and types related to the setup and management of the USB interface. * Functions, macros, variables, enums and types related to the setup and management of the USB interface.
* *
* @{ * @{
*/ */
#ifndef __USBCONTROLLER_UC3B_H__ #ifndef __USBCONTROLLER_UC3_H__
#define __USBCONTROLLER_UC3B_H__ #define __USBCONTROLLER_UC3_H__
/* Includes: */ /* Includes: */
#include "../../../../Common/Common.h" #include "../../../../Common/Common.h"
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
*/ */
/** \file /** \file
* \brief USB Controller Interrupt definitions for the AVR32 UC3B microcontrollers. * \brief USB Controller Interrupt definitions for the AVR32 UC3 microcontrollers.
* *
* This file contains definitions required for the correct handling of low level USB service routine interrupts * This file contains definitions required for the correct handling of low level USB service routine interrupts
* from the USB controller. * from the USB controller.
...@@ -38,8 +38,8 @@ ...@@ -38,8 +38,8 @@
* dispatch header located in LUFA/Drivers/USB/USB.h. * dispatch header located in LUFA/Drivers/USB/USB.h.
*/ */
#ifndef __USBINTERRUPT_UC3B_H__ #ifndef __USBINTERRUPT_UC3_H__
#define __USBINTERRUPT_UC3B_H__ #define __USBINTERRUPT_UC3_H__
/* Includes: */ /* Includes: */
#include "../../../../Common/Common.h" #include "../../../../Common/Common.h"
......
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
#define __INCLUDE_FROM_USB_DRIVER
#include "../USBMode.h"
#if defined(USB_CAN_BE_HOST)
#define __INCLUDE_FROM_HOST_C
#include "../Host.h"
void USB_Host_ProcessNextHostState(void)
{
uint8_t ErrorCode = HOST_ENUMERROR_NoError;
uint8_t SubErrorCode = HOST_ENUMERROR_NoError;
static uint16_t WaitMSRemaining;
static uint8_t PostWaitState;
switch (USB_HostState)
{
case HOST_STATE_WaitForDevice:
if (WaitMSRemaining)
{
if ((SubErrorCode = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful)
{
USB_HostState = PostWaitState;
ErrorCode = HOST_ENUMERROR_WaitStage;
break;
}
if (!(--WaitMSRemaining))
USB_HostState = PostWaitState;
}
break;
case HOST_STATE_Powered:
WaitMSRemaining = HOST_DEVICE_SETTLE_DELAY_MS;
USB_HostState = HOST_STATE_Powered_WaitForDeviceSettle;
break;
case HOST_STATE_Powered_WaitForDeviceSettle:
if (WaitMSRemaining--)
{
_delay_ms(1);
break;
}
else
{
USB_Host_VBUS_Manual_Off();
USB_OTGPAD_On();
USB_Host_VBUS_Auto_Enable();
USB_Host_VBUS_Auto_On();
USB_HostState = HOST_STATE_Powered_WaitForConnect;
}
break;
case HOST_STATE_Powered_WaitForConnect:
if (USB_INT_HasOccurred(USB_INT_DCONNI))
{
USB_INT_Clear(USB_INT_DCONNI);
USB_INT_Clear(USB_INT_DDISCI);
USB_INT_Clear(USB_INT_VBERRI);
USB_INT_Enable(USB_INT_VBERRI);
USB_Host_ResumeBus();
Pipe_ClearPipes();
HOST_TASK_NONBLOCK_WAIT(100, HOST_STATE_Powered_DoReset);
}
break;
case HOST_STATE_Powered_DoReset:
USB_Host_ResetDevice();
HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Powered_ConfigPipe);
break;
case HOST_STATE_Powered_ConfigPipe:
Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL,
PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP,
PIPE_CONTROLPIPE_DEFAULT_SIZE, PIPE_BANK_SINGLE);
if (!(Pipe_IsConfigured()))
{
ErrorCode = HOST_ENUMERROR_PipeConfigError;
SubErrorCode = 0;
break;
}
USB_HostState = HOST_STATE_Default;
break;
case HOST_STATE_Default:
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_GetDescriptor,
.wValue = (DTYPE_Device << 8),
.wIndex = 0,
.wLength = 8,
};
uint8_t DataBuffer[8];
if ((SubErrorCode = USB_Host_SendControlRequest(DataBuffer)) != HOST_SENDCONTROL_Successful)
{
ErrorCode = HOST_ENUMERROR_ControlError;
break;
}
USB_ControlPipeSize = DataBuffer[offsetof(USB_Descriptor_Device_t, Endpoint0Size)];
USB_Host_ResetDevice();
HOST_TASK_NONBLOCK_WAIT(200, HOST_STATE_Default_PostReset);
break;
case HOST_STATE_Default_PostReset:
Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL,
PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP,
USB_ControlPipeSize, PIPE_BANK_SINGLE);
if (!(Pipe_IsConfigured()))
{
ErrorCode = HOST_ENUMERROR_PipeConfigError;
SubErrorCode = 0;
break;
}
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_SetAddress,
.wValue = USB_HOST_DEVICEADDRESS,
.wIndex = 0,
.wLength = 0,
};
if ((SubErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
{
ErrorCode = HOST_ENUMERROR_ControlError;
break;
}
HOST_TASK_NONBLOCK_WAIT(100, HOST_STATE_Default_PostAddressSet);
break;
case HOST_STATE_Default_PostAddressSet:
USB_Host_SetDeviceAddress(USB_HOST_DEVICEADDRESS);
EVENT_USB_Host_DeviceEnumerationComplete();
USB_HostState = HOST_STATE_Addressed;
break;
}
if ((ErrorCode != HOST_ENUMERROR_NoError) && (USB_HostState != HOST_STATE_Unattached))
{
EVENT_USB_Host_DeviceEnumerationFailed(ErrorCode, SubErrorCode);
USB_Host_VBUS_Auto_Off();
EVENT_USB_Host_DeviceUnattached();
USB_ResetInterface();
}
}
uint8_t USB_Host_WaitMS(uint8_t MS)
{
bool BusSuspended = USB_Host_IsBusSuspended();
uint8_t ErrorCode = HOST_WAITERROR_Successful;
bool HSOFIEnabled = USB_INT_IsEnabled(USB_INT_HSOFI);
USB_INT_Disable(USB_INT_HSOFI);
USB_INT_Clear(USB_INT_HSOFI);
USB_Host_ResumeBus();
while (MS)
{
if (USB_INT_HasOccurred(USB_INT_HSOFI))
{
USB_INT_Clear(USB_INT_HSOFI);
MS--;
}
if ((USB_HostState == HOST_STATE_Unattached) || (USB_CurrentMode != USB_MODE_Host))
{
ErrorCode = HOST_WAITERROR_DeviceDisconnect;
break;
}
if (Pipe_IsError() == true)
{
Pipe_ClearError();
ErrorCode = HOST_WAITERROR_PipeError;
break;
}
if (Pipe_IsStalled() == true)
{
Pipe_ClearStall();
ErrorCode = HOST_WAITERROR_SetupStalled;
break;
}
}
if (BusSuspended)
USB_Host_SuspendBus();
if (HSOFIEnabled)
USB_INT_Enable(USB_INT_HSOFI);
return ErrorCode;
}
static void USB_Host_ResetDevice(void)
{
bool BusSuspended = USB_Host_IsBusSuspended();
USB_INT_Disable(USB_INT_DDISCI);
USB_Host_ResetBus();
while (!(USB_Host_IsBusResetComplete()));
USB_Host_ResumeBus();
bool HSOFIEnabled = USB_INT_IsEnabled(USB_INT_HSOFI);
USB_INT_Disable(USB_INT_HSOFI);
USB_INT_Clear(USB_INT_HSOFI);
for (uint8_t MSRem = 10; MSRem != 0; MSRem--)
{
/* Workaround for powerless-pull-up devices. After a USB bus reset,
all disconnection interrupts are suppressed while a USB frame is
looked for - if it is found within 10ms, the device is still
present. */
if (USB_INT_HasOccurred(USB_INT_HSOFI))
{
USB_INT_Clear(USB_INT_HSOFI);
USB_INT_Clear(USB_INT_DDISCI);
break;
}
_delay_ms(1);
}
if (HSOFIEnabled)
USB_INT_Enable(USB_INT_HSOFI);
if (BusSuspended)
USB_Host_SuspendBus();
USB_INT_Enable(USB_INT_DDISCI);
}
uint8_t USB_Host_SetDeviceConfiguration(const uint8_t ConfigNumber)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_SetConfiguration,
.wValue = ConfigNumber,
.wIndex = 0,
.wLength = 0,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(NULL);
}
uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_GetDescriptor,
.wValue = (DTYPE_Device << 8),
.wIndex = 0,
.wLength = sizeof(USB_Descriptor_Device_t),
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(DeviceDescriptorPtr);
}
uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index,
void* const Buffer,
const uint8_t BufferLength)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_GetDescriptor,
.wValue = (DTYPE_String << 8) | Index,
.wIndex = 0,
.wLength = BufferLength,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(Buffer);
}
uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointNum)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT),
.bRequest = REQ_ClearFeature,
.wValue = FEATURE_SEL_EndpointHalt,
.wIndex = EndpointNum,
.wLength = 0,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(NULL);
}
#endif
This diff is collapsed.
...@@ -60,8 +60,8 @@ ...@@ -60,8 +60,8 @@
/* Architecture Includes: */ /* Architecture Includes: */
#if (ARCH == ARCH_AVR8) #if (ARCH == ARCH_AVR8)
#include "AVR8/USBController_AVR8.h" #include "AVR8/USBController_AVR8.h"
#elif (ARCH == ARCH_UC3B) #elif (ARCH == ARCH_UC3)
#include "UC3B/USBController_UC3B.h" #include "UC3/USBController_UC3.h"
#endif #endif
#endif #endif
......
...@@ -53,8 +53,8 @@ ...@@ -53,8 +53,8 @@
/* Architecture Includes: */ /* Architecture Includes: */
#if (ARCH == ARCH_AVR8) #if (ARCH == ARCH_AVR8)
#include "AVR8/USBInterrupt_AVR8.h" #include "AVR8/USBInterrupt_AVR8.h"
#elif (ARCH == ARCH_UC3B) #elif (ARCH == ARCH_UC3)
#include "UC3B/USBInterrupt_UC3B.h" #include "UC3/USBInterrupt_UC3.h"
#endif #endif
#endif #endif
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* in exchange for a smaller compiled program binary size * in exchange for a smaller compiled program binary size
* - Added a new general RingBuff.h miscellaneous ring buffer library driver header * - Added a new general RingBuff.h miscellaneous ring buffer library driver header
* - Added new GCC_FORCE_POINTER_ACCESS() macro to correct GCC's mishandling of struct pointer accesses * - Added new GCC_FORCE_POINTER_ACCESS() macro to correct GCC's mishandling of struct pointer accesses
* - Added new GCC_MEMORY_BARRIER() macro to prevent instruction reordering across boundaries
* - Added basic driver example use code to the library documentation * - Added basic driver example use code to the library documentation
* - Added new Endpoint_Null_Stream() and Pipe_Null_Stream() functions * - Added new Endpoint_Null_Stream() and Pipe_Null_Stream() functions
* - Added new ADC_GET_CHANNEL_MASK() convenience macro * - Added new ADC_GET_CHANNEL_MASK() convenience macro
...@@ -24,7 +25,7 @@ ...@@ -24,7 +25,7 @@
* - Added board driver support for the Sparkfun ATMEGA8U2 breakout board * - Added board driver support for the Sparkfun ATMEGA8U2 breakout board
* - Added TWI baud rate prescaler and bit length parameters to the TWI_Init() function (thanks to Thomas Herlinghaus) * - Added TWI baud rate prescaler and bit length parameters to the TWI_Init() function (thanks to Thomas Herlinghaus)
* - Internal restructuring for eventual multiple architecture ports * - Internal restructuring for eventual multiple architecture ports
* - Added start of an AVR32 UC3B architecture port (currently incomplete/experimental) * - Added start of an AVR32 UC3 architecture port (currently incomplete/experimental)
* - Library Applications: * - Library Applications:
* - Added ability to write protect Mass Storage disk write operations from the host OS * - Added ability to write protect Mass Storage disk write operations from the host OS
* - Added new MIDIToneGenerator project * - Added new MIDIToneGenerator project
......
...@@ -7,16 +7,30 @@ ...@@ -7,16 +7,30 @@
/** /**
* \page Page_DeviceSupport Device and Hardware Support * \page Page_DeviceSupport Device and Hardware Support
* *
* \section Sec_AVR8_Support Atmel 32-Bit UC3B AVR (UC3B) * \section Sec_AVR8_Support Atmel 32-Bit UC3 AVR (UC3)
* <i>The AVR32 UC3B device support is currently <b>experimental</b>, and is included for preview purposes only.</i> * <i>The AVR32 UC3 device support is currently <b>experimental</b>, and is included for preview purposes only.</i>
* *
* Currently su