Added LUFA into the project, right now just for some demo stuff.

This commit is contained in:
Doug Brown 2011-12-09 22:11:31 -08:00
parent f5bf5fed36
commit 1db6834da4
103 changed files with 23441 additions and 2 deletions

View File

@ -32,6 +32,18 @@
<tool id="de.innot.avreclipse.tool.compiler.winavr.app.debug.1123922496" name="AVR Compiler" superClass="de.innot.avreclipse.tool.compiler.winavr.app.debug">
<option id="de.innot.avreclipse.compiler.option.debug.level.1719005254" name="Generate Debugging Info" superClass="de.innot.avreclipse.compiler.option.debug.level"/>
<option id="de.innot.avreclipse.compiler.option.optimize.1096379855" name="Optimization Level" superClass="de.innot.avreclipse.compiler.option.optimize"/>
<option id="de.innot.avreclipse.compiler.option.def.212979603" name="Define Syms (-D)" superClass="de.innot.avreclipse.compiler.option.def" valueType="definedSymbols">
<listOptionValue builtIn="false" value="USB_DEVICE_ONLY"/>
<listOptionValue builtIn="false" value="F_USB=16000000"/>
<listOptionValue builtIn="false" value="DEVICE_STATE_AS_GPIOR=0"/>
<listOptionValue builtIn="false" value="ORDERED_EP_CONFIG"/>
<listOptionValue builtIn="false" value="FIXED_CONTROL_ENDPOINT_SIZE=8"/>
<listOptionValue builtIn="false" value="FIXED_NUM_CONFIGURATIONS=1"/>
<listOptionValue builtIn="false" value="USE_FLASH_DESCRIPTORS"/>
<listOptionValue builtIn="false" value="USE_STATIC_OPTIONS=&quot;(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)&quot;"/>
<listOptionValue builtIn="false" value="INTERRUPT_CONTROL_ENDPOINT"/>
</option>
<option id="de.innot.avreclipse.compiler.option.otherflags.1513967861" superClass="de.innot.avreclipse.compiler.option.otherflags" value="-ffunction-sections -fdata-sections" valueType="string"/>
<inputType id="de.innot.avreclipse.compiler.winavr.input.1367172122" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/>
</tool>
<tool id="de.innot.avreclipse.tool.cppcompiler.app.debug.24092953" name="AVR C++ Compiler" superClass="de.innot.avreclipse.tool.cppcompiler.app.debug">
@ -39,6 +51,7 @@
<option id="de.innot.avreclipse.cppcompiler.option.optimize.1022518531" name="Optimization Level" superClass="de.innot.avreclipse.cppcompiler.option.optimize"/>
</tool>
<tool id="de.innot.avreclipse.tool.linker.winavr.app.debug.806884166" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.debug">
<option id="de.innot.avreclipse.linker.option.otherlinkargs.1714687929" superClass="de.innot.avreclipse.linker.option.otherlinkargs" value="-Wl,--relax,--gc-sections" valueType="string"/>
<inputType id="de.innot.avreclipse.tool.linker.input.1020880987" name="OBJ Files" superClass="de.innot.avreclipse.tool.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
@ -369,6 +382,8 @@
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="org.eclipse.cdt.core.language.mapping"/>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
</cconfiguration>
<cconfiguration id="de.innot.avreclipse.configuration.app.release.1163010375">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="de.innot.avreclipse.configuration.app.release.1163010375" moduleId="org.eclipse.cdt.core.settings" name="Release">
@ -399,6 +414,18 @@
<tool id="de.innot.avreclipse.tool.compiler.winavr.app.release.883804772" name="AVR Compiler" superClass="de.innot.avreclipse.tool.compiler.winavr.app.release">
<option id="de.innot.avreclipse.compiler.option.debug.level.369847490" name="Generate Debugging Info" superClass="de.innot.avreclipse.compiler.option.debug.level" value="de.innot.avreclipse.compiler.option.debug.level.none" valueType="enumerated"/>
<option id="de.innot.avreclipse.compiler.option.optimize.471434010" name="Optimization Level" superClass="de.innot.avreclipse.compiler.option.optimize" value="de.innot.avreclipse.compiler.optimize.size" valueType="enumerated"/>
<option id="de.innot.avreclipse.compiler.option.def.1514251723" name="Define Syms (-D)" superClass="de.innot.avreclipse.compiler.option.def" valueType="definedSymbols">
<listOptionValue builtIn="false" value="USB_DEVICE_ONLY"/>
<listOptionValue builtIn="false" value="F_USB=16000000"/>
<listOptionValue builtIn="false" value="DEVICE_STATE_AS_GPIOR=0"/>
<listOptionValue builtIn="false" value="ORDERED_EP_CONFIG"/>
<listOptionValue builtIn="false" value="FIXED_CONTROL_ENDPOINT_SIZE=8"/>
<listOptionValue builtIn="false" value="FIXED_NUM_CONFIGURATIONS=1"/>
<listOptionValue builtIn="false" value="USE_FLASH_DESCRIPTORS"/>
<listOptionValue builtIn="false" value="USE_STATIC_OPTIONS=&quot;(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)&quot;"/>
<listOptionValue builtIn="false" value="INTERRUPT_CONTROL_ENDPOINT"/>
</option>
<option id="de.innot.avreclipse.compiler.option.otherflags.1566165436" superClass="de.innot.avreclipse.compiler.option.otherflags" value="-ffunction-sections -fdata-sections" valueType="string"/>
<inputType id="de.innot.avreclipse.compiler.winavr.input.2084198580" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/>
</tool>
<tool id="de.innot.avreclipse.tool.cppcompiler.app.release.912002244" name="AVR C++ Compiler" superClass="de.innot.avreclipse.tool.cppcompiler.app.release">
@ -406,6 +433,7 @@
<option id="de.innot.avreclipse.cppcompiler.option.optimize.1657124646" name="Optimization Level" superClass="de.innot.avreclipse.cppcompiler.option.optimize" value="de.innot.avreclipse.cppcompiler.optimize.size" valueType="enumerated"/>
</tool>
<tool id="de.innot.avreclipse.tool.linker.winavr.app.release.381852607" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.release">
<option id="de.innot.avreclipse.linker.option.otherlinkargs.270243458" superClass="de.innot.avreclipse.linker.option.otherlinkargs" value="-Wl,--relax,--gc-sections" valueType="string"/>
<inputType id="de.innot.avreclipse.tool.linker.input.567763029" name="OBJ Files" superClass="de.innot.avreclipse.tool.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
@ -736,6 +764,8 @@
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="org.eclipse.cdt.core.language.mapping"/>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">

271
Descriptors.c Normal file
View File

@ -0,0 +1,271 @@
/*
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.
*/
/** \file
*
* USB Device Descriptors, for library use when in USB device mode. Descriptors are special
* computer-readable structures which the host requests upon device enumeration, to determine
* the device's capabilities and functions.
*/
#include "Descriptors.h"
/* On some devices, there is a factory set internal serial number which can be automatically sent to the host as
* the device's serial number when the Device Descriptor's .SerialNumStrIndex entry is set to USE_INTERNAL_SERIAL.
* This allows the host to track a device across insertions on different ports, allowing them to retain allocated
* resources like COM port numbers and drivers. On demos using this feature, give a warning on unsupported devices
* so that the user can supply their own serial number descriptor instead or remove the USE_INTERNAL_SERIAL value
* from the Device Descriptor (forcing the host to generate a serial number for each device from the VID, PID and
* port location).
*/
#if (USE_INTERNAL_SERIAL == NO_DESCRIPTOR)
#warning USE_INTERNAL_SERIAL is not available on this AVR - please manually construct a device serial descriptor.
#endif
/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
* device characteristics, including the supported USB version, control endpoint size and the
* number of device configurations. The descriptor is read out by the USB host when the enumeration
* process begins.
*/
const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
{
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
.USBSpecification = VERSION_BCD(01.10),
.Class = CDC_CSCP_CDCClass,
.SubClass = CDC_CSCP_NoSpecificSubclass,
.Protocol = CDC_CSCP_NoSpecificProtocol,
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
.VendorID = 0x03EB,
.ProductID = 0x204B,
.ReleaseNumber = VERSION_BCD(00.01),
.ManufacturerStrIndex = 0x01,
.ProductStrIndex = 0x02,
.SerialNumStrIndex = USE_INTERNAL_SERIAL,
.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
};
/** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
* of the device in one of its supported configurations, including information about any device interfaces
* and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
* a configuration so that the host may correctly communicate with the USB device.
*/
const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
{
.Config =
{
.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
.TotalInterfaces = 2,
.ConfigurationNumber = 1,
.ConfigurationStrIndex = NO_DESCRIPTOR,
.ConfigAttributes = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
},
.CDC_CCI_Interface =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
.InterfaceNumber = 0,
.AlternateSetting = 0,
.TotalEndpoints = 1,
.Class = CDC_CSCP_CDCClass,
.SubClass = CDC_CSCP_ACMSubclass,
.Protocol = CDC_CSCP_ATCommandProtocol,
.InterfaceStrIndex = NO_DESCRIPTOR
},
.CDC_Functional_Header =
{
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
.Subtype = CDC_DSUBTYPE_CSInterface_Header,
.CDCSpecification = VERSION_BCD(01.10),
},
.CDC_Functional_ACM =
{
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
.Subtype = CDC_DSUBTYPE_CSInterface_ACM,
.Capabilities = 0x06,
},
.CDC_Functional_Union =
{
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
.Subtype = CDC_DSUBTYPE_CSInterface_Union,
.MasterInterfaceNumber = 0,
.SlaveInterfaceNumber = 1,
},
.CDC_NotificationEndpoint =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM),
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_NOTIFICATION_EPSIZE,
.PollingIntervalMS = 0xFF
},
.CDC_DCI_Interface =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
.InterfaceNumber = 1,
.AlternateSetting = 0,
.TotalEndpoints = 2,
.Class = CDC_CSCP_CDCDataClass,
.SubClass = CDC_CSCP_NoDataSubclass,
.Protocol = CDC_CSCP_NoDataProtocol,
.InterfaceStrIndex = NO_DESCRIPTOR
},
.CDC_DataOutEndpoint =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = (ENDPOINT_DIR_OUT | CDC_RX_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_TXRX_EPSIZE,
.PollingIntervalMS = 0x01
},
.CDC_DataInEndpoint =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = (ENDPOINT_DIR_IN | CDC_TX_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_TXRX_EPSIZE,
.PollingIntervalMS = 0x01
}
};
/** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
* the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
* via the language ID table available at USB.org what languages the device supports for its string descriptors.
*/
const USB_Descriptor_String_t PROGMEM LanguageString =
{
.Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
.UnicodeString = {LANGUAGE_ID_ENG}
};
/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
* form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
* Descriptor.
*/
const USB_Descriptor_String_t PROGMEM ManufacturerString =
{
.Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
.UnicodeString = L"Dean Camera"
};
/** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
* and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
* Descriptor.
*/
const USB_Descriptor_String_t PROGMEM ProductString =
{
.Header = {.Size = USB_STRING_LEN(23), .Type = DTYPE_String},
.UnicodeString = L"LUFA USB-RS232 Adapter"
};
/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
* documentation) by the application code so that the address and size of a requested descriptor can be given
* to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
* is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
* USB host.
*/
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex,
const void** const DescriptorAddress)
{
const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF);
const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType)
{
case DTYPE_Device:
Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t);
break;
case DTYPE_Configuration:
Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t);
break;
case DTYPE_String:
switch (DescriptorNumber)
{
case 0x00:
Address = &LanguageString;
Size = pgm_read_byte(&LanguageString.Header.Size);
break;
case 0x01:
Address = &ManufacturerString;
Size = pgm_read_byte(&ManufacturerString.Header.Size);
break;
case 0x02:
Address = &ProductString;
Size = pgm_read_byte(&ProductString.Header.Size);
break;
}
break;
}
*DescriptorAddress = Address;
return Size;
}

89
Descriptors.h Normal file
View File

@ -0,0 +1,89 @@
/*
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.
*/
/** \file
*
* Header file for Descriptors.c.
*/
#ifndef _DESCRIPTORS_H_
#define _DESCRIPTORS_H_
/* Includes: */
#include <avr/pgmspace.h>
#include "LUFA/Drivers/USB/USB.h"
/* Macros: */
/** Endpoint number of the CDC device-to-host notification IN endpoint. */
#define CDC_NOTIFICATION_EPNUM 2
/** Endpoint number of the CDC device-to-host data IN endpoint. */
#define CDC_TX_EPNUM 3
/** Endpoint number of the CDC host-to-device data OUT endpoint. */
#define CDC_RX_EPNUM 4
/** Size in bytes of the CDC device-to-host notification IN endpoint. */
#define CDC_NOTIFICATION_EPSIZE 8
/** Size in bytes of the CDC data IN and OUT endpoints. */
#define CDC_TXRX_EPSIZE 16
/* Type Defines: */
/** Type define for the device configuration descriptor structure. This must be defined in the
* application code, as the configuration descriptor contains several sub-descriptors which
* vary between devices, and which describe the device's usage to the host.
*/
typedef struct
{
USB_Descriptor_Configuration_Header_t Config;
// CDC Command Interface
USB_Descriptor_Interface_t CDC_CCI_Interface;
USB_CDC_Descriptor_FunctionalHeader_t CDC_Functional_Header;
USB_CDC_Descriptor_FunctionalACM_t CDC_Functional_ACM;
USB_CDC_Descriptor_FunctionalUnion_t CDC_Functional_Union;
USB_Descriptor_Endpoint_t CDC_NotificationEndpoint;
// CDC Data Interface
USB_Descriptor_Interface_t CDC_DCI_Interface;
USB_Descriptor_Endpoint_t CDC_DataOutEndpoint;
USB_Descriptor_Endpoint_t CDC_DataInEndpoint;
} USB_Descriptor_Configuration_t;
/* Function Prototypes: */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex,
const void** const DescriptorAddress)
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
#endif

View File

@ -0,0 +1,83 @@
/*
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.
*/
/*
This is a stub driver header file, for implementing custom board
layout hardware with compatible LUFA board specific drivers. If
the library is configured to use the BOARD_USER board mode, this
driver file should be completed and copied into the "/Board/" folder
inside the application's folder.
This stub is for the board-specific component of the LUFA Buttons driver,
for the control of physical board-mounted GPIO pushbuttons.
*/
#ifndef __BUTTONS_USER_H__
#define __BUTTONS_USER_H__
/* Includes: */
// TODO: Add any required includes here
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_BUTTONS_H)
#error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Button mask for the first button on the board. */
#define BUTTONS_BUTTON1 // TODO: Add mask for first board button here
/* Inline Functions: */
#if !defined(__DOXYGEN__)
static inline void Buttons_Init(void)
{
// TODO: Initialize the appropriate port pins as an inputs here, with pull-ups
}
static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
static inline uint8_t Buttons_GetStatus(void)
{
// TODO: Return current button status here, debounced if required
}
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,218 @@
/*
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.
*/
/*
This is a stub driver header file, for implementing custom board
layout hardware with compatible LUFA board specific drivers. If
the library is configured to use the BOARD_USER board mode, this
driver file should be completed and copied into the "/Board/" folder
inside the application's folder.
This stub is for the board-specific component of the LUFA Dataflash
driver.
*/
#ifndef __DATAFLASH_USER_H__
#define __DATAFLASH_USER_H__
/* Includes: */
// TODO: Add any required includes here
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_DATAFLASH_H)
#error Do not include this file directly. Include LUFA/Drivers/Board/Dataflash.h instead.
#endif
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Macros: */
#define DATAFLASH_CHIPCS_MASK // TODO: Replace this with a mask of all the /CS pins of all Dataflashes
#define DATAFLASH_CHIPCS_DDR // TODO: Replace with the DDR register name for the board's Dataflash ICs
#define DATAFLASH_CHIPCS_PORT // TODO: Replace with the PORT register name for the board's Dataflash ICs
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Constant indicating the total number of dataflash ICs mounted on the selected board. */
#define DATAFLASH_TOTALCHIPS 1 // TODO: Replace with the number of Dataflashes on the board, max 2
/** Mask for no dataflash chip selected. */
#define DATAFLASH_NO_CHIP DATAFLASH_CHIPCS_MASK
/** Mask for the first dataflash chip selected. */
#define DATAFLASH_CHIP1 // TODO: Replace with mask to hold /CS of first Dataflash low, and all others high
/** Mask for the second dataflash chip selected. */
#define DATAFLASH_CHIP2 // TODO: Replace with mask to hold /CS of second Dataflash low, and all others high
/** Internal main memory page size for the board's dataflash ICs. */
#define DATAFLASH_PAGE_SIZE // TODO: Replace with the page size for the Dataflash ICs
/** Total number of pages inside each of the board's dataflash ICs. */
#define DATAFLASH_PAGES // TODO: Replace with the total number of pages inside one of the Dataflash ICs
/* Inline Functions: */
/** Initializes the dataflash driver so that commands and data may be sent to an attached dataflash IC.
* The microcontroller's SPI driver MUST be initialized before any of the dataflash commands are used.
*/
static inline void Dataflash_Init(void)
{
DATAFLASH_CHIPCS_DDR |= DATAFLASH_CHIPCS_MASK;
DATAFLASH_CHIPCS_PORT |= DATAFLASH_CHIPCS_MASK;
}
/** Sends a byte to the currently selected dataflash IC, and returns a byte from the dataflash.
*
* \param[in] Byte of data to send to the dataflash
*
* \return Last response byte from the dataflash
*/
static inline uint8_t Dataflash_TransferByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
static inline uint8_t Dataflash_TransferByte(const uint8_t Byte)
{
return SPI_TransferByte(Byte);
}
/** Sends a byte to the currently selected dataflash IC, and ignores the next byte from the dataflash.
*
* \param[in] Byte of data to send to the dataflash
*/
static inline void Dataflash_SendByte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
static inline void Dataflash_SendByte(const uint8_t Byte)
{
SPI_SendByte(Byte);
}
/** Sends a dummy byte to the currently selected dataflash IC, and returns the next byte from the dataflash.
*
* \return Last response byte from the dataflash
*/
static inline uint8_t Dataflash_ReceiveByte(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline uint8_t Dataflash_ReceiveByte(void)
{
return SPI_ReceiveByte();
}
/** Determines the currently selected dataflash chip.
*
* \return Mask of the currently selected Dataflash chip, either \ref DATAFLASH_NO_CHIP if no chip is selected
* or a DATAFLASH_CHIPn mask (where n is the chip number).
*/
static inline uint8_t Dataflash_GetSelectedChip(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline uint8_t Dataflash_GetSelectedChip(void)
{
return (DATAFLASH_CHIPCS_PORT & DATAFLASH_CHIPCS_MASK);
}
/** Selects the given dataflash chip.
*
* \param[in] ChipMask Mask of the Dataflash IC to select, in the form of DATAFLASH_CHIPn mask (where n is
* the chip number).
*/
static inline void Dataflash_SelectChip(const uint8_t ChipMask) ATTR_ALWAYS_INLINE;
static inline void Dataflash_SelectChip(const uint8_t ChipMask)
{
DATAFLASH_CHIPCS_PORT = ((DATAFLASH_CHIPCS_PORT & ~DATAFLASH_CHIPCS_MASK) | ChipMask);
}
/** Deselects the current dataflash chip, so that no dataflash is selected. */
static inline void Dataflash_DeselectChip(void) ATTR_ALWAYS_INLINE;
static inline void Dataflash_DeselectChip(void)
{
Dataflash_SelectChip(DATAFLASH_NO_CHIP);
}
/** Selects a dataflash IC from the given page number, which should range from 0 to
* ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1). For boards containing only one
* dataflash IC, this will select DATAFLASH_CHIP1. If the given page number is outside
* the total number of pages contained in the boards dataflash ICs, all dataflash ICs
* are deselected.
*
* \param[in] PageAddress Address of the page to manipulate, ranging from
* 0 to ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1).
*/
static inline void Dataflash_SelectChipFromPage(const uint16_t PageAddress)
{
Dataflash_DeselectChip();
if (PageAddress >= (DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS))
return;
#if (DATAFLASH_TOTALCHIPS == 2)
if (PageAddress & 0x01)
Dataflash_SelectChip(DATAFLASH_CHIP2);
else
Dataflash_SelectChip(DATAFLASH_CHIP1);
#else
Dataflash_SelectChip(DATAFLASH_CHIP1);
#endif
}
/** Toggles the select line of the currently selected dataflash IC, so that it is ready to receive
* a new command.
*/
static inline void Dataflash_ToggleSelectedChipCS(void)
{
uint8_t SelectedChipMask = Dataflash_GetSelectedChip();
Dataflash_DeselectChip();
Dataflash_SelectChip(SelectedChipMask);
}
/** Spin-loops while the currently selected dataflash is busy executing a command, such as a main
* memory page program or main memory to buffer transfer.
*/
static inline void Dataflash_WaitWhileBusy(void)
{
Dataflash_ToggleSelectedChipCS();
Dataflash_SendByte(DF_CMD_GETSTATUS);
while (!(Dataflash_ReceiveByte() & DF_STATUS_READY));
Dataflash_ToggleSelectedChipCS();
}
/** Sends a set of page and buffer address bytes to the currently selected dataflash IC, for use with
* dataflash commands which require a complete 24-bit address.
*
* \param[in] PageAddress Page address within the selected dataflash IC
* \param[in] BufferByte Address within the dataflash's buffer
*/
static inline void Dataflash_SendAddressBytes(uint16_t PageAddress, const uint16_t BufferByte)
{
#if (DATAFLASH_TOTALCHIPS == 2)
PageAddress >>= 1;
#endif
Dataflash_SendByte(PageAddress >> 5);
Dataflash_SendByte((PageAddress << 3) | (BufferByte >> 8));
Dataflash_SendByte(BufferByte);
}
#endif

View File

@ -0,0 +1,95 @@
/*
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.
*/
/*
This is a stub driver header file, for implementing custom board
layout hardware with compatible LUFA board specific drivers. If
the library is configured to use the BOARD_USER board mode, this
driver file should be completed and copied into the "/Board/" folder
inside the application's folder.
This stub is for the board-specific component of the LUFA Joystick
driver, for a digital four-way (plus button) joystick.
*/
#ifndef __JOYSTICK_USER_H__
#define __JOYSTICK_USER_H__
/* Includes: */
// TODO: Add any required includes here
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_JOYSTICK_H)
#error Do not include this file directly. Include LUFA/Drivers/Board/Joystick.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Mask for the joystick being pushed in the left direction. */
#define JOY_LEFT // TODO: Add mask to indicate joystick left position here
/** Mask for the joystick being pushed in the right direction. */
#define JOY_RIGHT // TODO: Add mask to indicate joystick right position here
/** Mask for the joystick being pushed in the upward direction. */
#define JOY_UP // TODO: Add mask to indicate joystick up position here
/** Mask for the joystick being pushed in the downward direction. */
#define JOY_DOWN // TODO: Add mask to indicate joystick down position here
/** Mask for the joystick being pushed inward. */
#define JOY_PRESS // TODO: Add mask to indicate joystick pressed position here
/* Inline Functions: */
#if !defined(__DOXYGEN__)
static inline void Joystick_Init(void)
{
// TODO: Initialize joystick port pins as inputs with pull-ups
}
static inline uint8_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
static inline uint8_t Joystick_GetStatus(void)
{
// TODO: Return current joystick position data which can be obtained by masking against the JOY_* macros
}
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,123 @@
/*
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.
*/
/*
This is a stub driver header file, for implementing custom board
layout hardware with compatible LUFA board specific drivers. If
the library is configured to use the BOARD_USER board mode, this
driver file should be completed and copied into the "/Board/" folder
inside the application's folder.
This stub is for the board-specific component of the LUFA LEDs driver,
for the LEDs (up to four) mounted on most development boards.
*/
#ifndef __LEDS_USER_H__
#define __LEDS_USER_H__
/* Includes: */
// TODO: Add any required includes here
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_LEDS_H)
#error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** LED mask for the first LED on the board. */
#define LEDS_LED1 // TODO: Add mask for first board LED here
/** LED mask for the second LED on the board. */
#define LEDS_LED2 // TODO: Add mask for second board LED here
/** LED mask for the third LED on the board. */
#define LEDS_LED3 // TODO: Add mask for third board LED here
/** LED mask for the fourth LED on the board. */
#define LEDS_LED4 // TODO: Add mask for fourth board LED here
/** LED mask for all the LEDs on the board. */
#define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2 | LEDS_LED3 | LEDS_LED4)
/** LED mask for none of the board LEDs. */
#define LEDS_NO_LEDS 0
/* Inline Functions: */
#if !defined(__DOXYGEN__)
static inline void LEDs_Init(void)
{
// TODO: Add code to initialize LED port pins as outputs here
}
static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
{
// TODO: Add code to turn on LEDs given in the LEDMask mask here, leave others as-is
}
static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
{
// TODO: Add code to turn off LEDs given in the LEDMask mask here, leave others as-is
}
static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
{
// TODO: Add code to turn on only LEDs given in the LEDMask mask here, all others off
}
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask)
{
// TODO: Add code to set the Leds in the given LEDMask to the status given in ActiveMask here
}
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
{
// TODO: Add code to toggle the Leds in the given LEDMask, ignoring all others
}
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
static inline uint8_t LEDs_GetLEDs(void)
{
// TODO: Add code to return the current LEDs status' here which can be masked against LED_LED* macros
}
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,156 @@
/*
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.
*/
/*
This is a header file which can be used to configure LUFA's
compile time options, as an alternative to the compile time
constants supplied through a makefile. To use this configuration
header, copy this into your project's root directory and supply
the \c USE_LUFA_CONFIG_HEADER token to the compiler so that it is
defined in all compiled source files.
For information on what each token does, refer to the LUFA
manual section "Summary of Compile Tokens".
*/
#ifndef __LUFA_CONFIG_H__
#define __LUFA_CONFIG_H__
#if (ARCH == ARCH_AVR8)
/* Non-USB Related Configuration Tokens: */
// #define DISABLE_TERMINAL_CODES
/* USB Class Driver Related Tokens: */
// #define HID_HOST_BOOT_PROTOCOL_ONLY
// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here}
// #define HID_USAGE_STACK_DEPTH {Insert Value Here}
// #define HID_MAX_COLLECTIONS {Insert Value Here}
// #define HID_MAX_REPORTITEMS {Insert Value Here}
// #define HID_MAX_REPORT_IDS {Insert Value Here}
// #define NO_CLASS_DRIVER_AUTOFLUSH
/* General USB Driver Related Tokens: */
// #define ORDERED_EP_CONFIG
// #define USE_STATIC_OPTIONS {Insert Value Here}
// #define USB_DEVICE_ONLY
// #define USB_HOST_ONLY
// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
// #define NO_LIMITED_CONTROLLER_CONNECT
// #define NO_SOF_EVENTS
/* USB Device Mode Driver Related Tokens: */
// #define USE_RAM_DESCRIPTORS
// #define USE_FLASH_DESCRIPTORS
// #define USE_EEPROM_DESCRIPTORS
// #define NO_INTERNAL_SERIAL
// #define FIXED_CONTROL_ENDPOINT_SIZE {Insert Value Here}
// #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
// #define FIXED_NUM_CONFIGURATION {Insert Value Here}
// #define CONTROL_ONLY_DEVICE
// #define INTERRUPT_CONTROL_ENDPOINT
// #define NO_DEVICE_REMOTE_WAKEUP
// #define NO_DEVICE_SELF_POWER
/* USB Host Mode Driver Related Tokens: */
// #define HOST_STATE_AS_GPIOR {Insert Value Here}
// #define USB_HOST_TIMEOUT_MS {Insert Value Here}
// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here}
#elif (ARCH == ARCH_XMEGA)
/* Non-USB Related Configuration Tokens: */
// #define DISABLE_TERMINAL_CODES
/* USB Class Driver Related Tokens: */
// #define HID_HOST_BOOT_PROTOCOL_ONLY
// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here}
// #define HID_USAGE_STACK_DEPTH {Insert Value Here}
// #define HID_MAX_COLLECTIONS {Insert Value Here}
// #define HID_MAX_REPORTITEMS {Insert Value Here}
// #define HID_MAX_REPORT_IDS {Insert Value Here}
// #define NO_CLASS_DRIVER_AUTOFLUSH
/* General USB Driver Related Tokens: */
// #define USE_STATIC_OPTIONS {Insert Value Here}
// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
// #define NO_LIMITED_CONTROLLER_CONNECT
// #define NO_SOF_EVENTS
/* USB Device Mode Driver Related Tokens: */
// #define USE_RAM_DESCRIPTORS
// #define USE_FLASH_DESCRIPTORS
// #define USE_EEPROM_DESCRIPTORS
// #define NO_INTERNAL_SERIAL
// #define FIXED_CONTROL_ENDPOINT_SIZE {Insert Value Here}
// #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
// #define FIXED_NUM_CONFIGURATION {Insert Value Here}
// #define CONTROL_ONLY_DEVICE
// #define NO_DEVICE_REMOTE_WAKEUP
// #define NO_DEVICE_SELF_POWER
#elif (ARCH == ARCH_UC3)
/* Non-USB Related Configuration Tokens: */
// #define DISABLE_TERMINAL_CODES
/* USB Class Driver Related Tokens: */
// #define HID_HOST_BOOT_PROTOCOL_ONLY
// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here}
// #define HID_USAGE_STACK_DEPTH {Insert Value Here}
// #define HID_MAX_COLLECTIONS {Insert Value Here}
// #define HID_MAX_REPORTITEMS {Insert Value Here}
// #define HID_MAX_REPORT_IDS {Insert Value Here}
// #define NO_CLASS_DRIVER_AUTOFLUSH
/* General USB Driver Related Tokens: */
// #define ORDERED_EP_CONFIG
// #define USE_STATIC_OPTIONS {Insert Value Here}
// #define USB_DEVICE_ONLY
// #define USB_HOST_ONLY
// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
// #define NO_SOF_EVENTS
/* USB Device Mode Driver Related Tokens: */
// #define NO_INTERNAL_SERIAL
// #define FIXED_CONTROL_ENDPOINT_SIZE {Insert Value Here}
// #define FIXED_NUM_CONFIGURATION {Insert Value Here}
// #define CONTROL_ONLY_DEVICE
// #define INTERRUPT_CONTROL_ENDPOINT
// #define NO_DEVICE_REMOTE_WAKEUP
// #define NO_DEVICE_SELF_POWER
/* USB Host Mode Driver Related Tokens: */
// #define USB_HOST_TIMEOUT_MS {Insert Value Here}
// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here}
#endif
#endif

View File

@ -0,0 +1,713 @@
# Hey Emacs, this is a -*- makefile -*-
#----------------------------------------------------------------------------
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
# >> Modified for use with the LUFA project. <<
#
# Released to the Public Domain
#
# Additional material for this makefile was written by:
# Peter Fleury
# Tim Henigan
# Colin O'Flynn
# Reiner Patommel
# Markus Pfaff
# Sander Pool
# Frederik Rouleau
# Carlos Lamas
# Dean Camera
# Opendous Inc.
# Denver Gingerich
#
#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF.
#
# make extcoff = Convert ELF to AVR Extended COFF.
#
# make program = Download the hex file to the device, using avrdude.
# Please customize the avrdude settings below first!
#
# make dfu = Download the hex file to the device, using dfu-programmer (must
# have dfu-programmer installed).
#
# make flip = Download the hex file to the device, using Atmel FLIP (must
# have Atmel FLIP installed).
#
# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
# (must have dfu-programmer installed).
#
# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
# (must have Atmel FLIP installed).
#
# make doxygen = Generate DoxyGen documentation for the project (must have
# DoxyGen installed)
#
# make debug = Start either simulavr or avarice as specified for debugging,
# with avr-gdb or avr-insight as the front end for debugging.
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
# bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------
# MCU name
MCU = ### INSERT NAME OF MICROCONTROLLER MODEL HERE ###
# Targeted chip architecture (see library "Architectures" documentation)
ARCH = AVR8
# Target board (see library "Board Types" documentation, NONE for projects not requiring
# LUFA board drivers). If USER is selected, put custom board drivers in a directory called
# "Board" inside the application directory.
BOARD = ### INSERT NAME OF BOARD HERE, OR NONE IF NO BOARD DRIVERS USED ###
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency in Hz. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
#
# This will be an integer division of F_CLOCK below, as it is sourced by
# F_CLOCK after it has run through any CPU prescalers. Note that this value
# does not *change* the processor frequency - it should merely be updated to
# reflect the processor speed set externally so that the code can use accurate
# software delays.
F_CPU = ### INSERT PRESCALED SYSTEM CLOCK SPEED HERE, IN HZ ###
# Input clock frequency.
# This will define a symbol, F_USB, in all source code files equal to the
# input clock frequency (before any prescaling is performed) in Hz. This value may
# differ from F_CPU if prescaling is used on the latter, and is required as the
# raw input clock is fed directly to the PLL sections of the AVR for high speed
# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
# at the end, this will be done automatically to create a 32-bit value in your
# source code.
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_USB = ### INSERT CLOCK TO USB MODULE HERE, IN HZ ###
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# Target file name (without extension).
TARGET = ### INSERT NAME OF MAIN FILENAME HERE, WITHOUT EXTENSION ###
# Object files directory
# To put object files in current directory, use a dot (.), do NOT make
# this an empty or blank macro!
OBJDIR = .
# Path to the LUFA library
LUFA_PATH = ### INSERT PATH TO LUFA LIBRARY RELATIVE TO PROJECT DIRECTORY HERE ###
# LUFA library compile-time options and predefined tokens (add '-D' before each token)
LUFA_OPTS = ### INSERT LUFA COMPILE TIME TOKENS HERE ###
# Create the LUFA source path variables by including the LUFA root makefile
include $(LUFA_PATH)/LUFA/makefile
# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \
$(LUFA_SRC_USB) \
$(LUFA_SRC_USBCLASS)
### INSERT ADDITIONAL PROJECT SOURCE FILENAMES OR LUFA MODULE NAMES HERE ###
# List C++ source files here. (C dependencies are automatically generated.)
CPPSRC =
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS = $(LUFA_PATH)/
# Compiler flag to set the C Standard level.
# c89 = "ANSI" C
# gnu89 = c89 plus GCC extensions
# c99 = ISO C99 standard (not yet fully implemented)
# gnu99 = c99 plus GCC extensions
CSTANDARD = -std=gnu99
# Place -D or -U options here for C sources
CDEFS = -DF_CPU=$(F_CPU)UL
CDEFS += -DF_USB=$(F_USB)UL
CDEFS += -DBOARD=BOARD_$(BOARD)
CDEFS += -DARCH=ARCH_$(ARCH)
CDEFS += $(LUFA_OPTS)
# Place -D or -U options here for ASM sources
ADEFS = -DF_CPU=$(F_CPU)
ADEFS += -DF_USB=$(F_USB)UL
ADEFS += -DBOARD=BOARD_$(BOARD)
ADEFS += -DARCH=ARCH_$(ARCH)
ADEFS += $(LUFA_OPTS)
# Place -D or -U options here for C++ sources
CPPDEFS = -DF_CPU=$(F_CPU)UL
CPPDEFS += -DF_USB=$(F_USB)UL
CPPDEFS += -DBOARD=BOARD_$(BOARD)
CPPDEFS += -DARCH=ARCH_$(ARCH)
CPPDEFS += $(LUFA_OPTS)
# Debugging format.
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
# AVR Studio 4.10 requires dwarf-2.
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
DEBUG = dwarf-2
#---------------- Compiler Options C ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -ffunction-sections
CFLAGS += -fno-inline-small-functions
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
CFLAGS += -fno-strict-aliasing
CFLAGS += -Wall
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
#---------------- Compiler Options C++ ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CPPFLAGS = -g$(DEBUG)
CPPFLAGS += $(CPPDEFS)
CPPFLAGS += -O$(OPT)
CPPFLAGS += -funsigned-char
CPPFLAGS += -funsigned-bitfields
CPPFLAGS += -fpack-struct
CPPFLAGS += -fshort-enums
CPPFLAGS += -ffunction-sections
CPPFLAGS += -fno-strict-aliasing
CPPFLAGS += -fno-exceptions
CPPFLAGS += -Wall
CPPFLAGS += -Wundef
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
#CPPFLAGS += $(CSTANDARD)
#---------------- Assembler Options ----------------
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
# dump that will be displayed for a given single line of source input.
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
#---------------- Library Options ----------------
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
# If this is left blank, then it will use the Standard printf version.
PRINTF_LIB =
#PRINTF_LIB = $(PRINTF_LIB_MIN)
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
# If this is left blank, then it will use the Standard scanf version.
SCANF_LIB =
#SCANF_LIB = $(SCANF_LIB_MIN)
#SCANF_LIB = $(SCANF_LIB_FLOAT)
MATH_LIB = -lm
# List any extra directories to look for libraries here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRALIBDIRS =
#---------------- External Memory Options ----------------
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
EXTMEMOPTS =
#---------------- Linker Options ----------------
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += -Wl,--relax
LDFLAGS += -Wl,--gc-sections
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
#LDFLAGS += -T linker_script.x
#---------------- Programming Options (avrdude) ----------------
# Programming hardware
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = jtagmkII
# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = usb
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_NO_VERIFY = -V
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_VERBOSE = -v -v
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
#---------------- Debugging Options ----------------
# For simulavr only - target MCU frequency.
DEBUG_MFREQ = $(F_CPU)
# Set the DEBUG_UI to either gdb or insight.
# DEBUG_UI = gdb
DEBUG_UI = insight
# Set the debugging back-end to either avarice, simulavr.
DEBUG_BACKEND = avarice
#DEBUG_BACKEND = simulavr
# GDB Init Filename.
GDBINIT_FILE = __avr_gdbinit
# When using avarice settings for the JTAG
JTAG_DEV = /dev/com1
# Debugging port used to communicate between GDB / avarice / simulavr.
DEBUG_PORT = 4242
# Debugging host used to communicate between GDB / avarice / simulavr, normally
# just set to localhost unless doing some sort of crazy debugging when
# avarice is running on a different computer.
DEBUG_HOST = localhost
#============================================================================
# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
AR = avr-ar rcs
NM = avr-nm
AVRDUDE = avrdude
REMOVE = rm -f
REMOVEDIR = rm -rf
COPY = cp
WINSHELL = cmd
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling C:
MSG_COMPILING_CPP = Compiling C++:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
MSG_CREATING_LIBRARY = Creating library:
# Define all object files.
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
# Define all listing files.
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
# Compiler flags to generate dependency files.
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
all: begin gccversion sizebefore build sizeafter end
# Change the build target to build a HEX file or a library.
build: elf hex eep lss sym
#build: lib
elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym
LIBNAME=lib$(TARGET).a
lib: $(LIBNAME)
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
end:
@echo $(MSG_END)
@echo
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
sizebefore:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
2>/dev/null; echo; fi
sizeafter:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
2>/dev/null; echo; fi
# Display compiler version information.
gccversion :
@$(CC) --version
# Program the device.
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
flip: $(TARGET).hex
batchisp -hardware usb -device $(MCU) -operation erase f
batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
batchisp -hardware usb -device $(MCU) -operation start reset 0
dfu: $(TARGET).hex
dfu-programmer $(MCU) erase
dfu-programmer $(MCU) flash $(TARGET).hex
dfu-programmer $(MCU) reset
flip-ee: $(TARGET).hex $(TARGET).eep
$(COPY) $(TARGET).eep $(TARGET)eep.hex
batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program
batchisp -hardware usb -device $(MCU) -operation start reset 0
$(REMOVE) $(TARGET)eep.hex
dfu-ee: $(TARGET).hex $(TARGET).eep
dfu-programmer $(MCU) eeprom-flash $(TARGET).eep
dfu-programmer $(MCU) reset
# Generate avr-gdb config/init file which does the following:
# define the reset signal, load the target file, connect to target, and set
# a breakpoint at main().
gdb-config:
@$(REMOVE) $(GDBINIT_FILE)
@echo define reset >> $(GDBINIT_FILE)
@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
@echo end >> $(GDBINIT_FILE)
@echo file $(TARGET).elf >> $(GDBINIT_FILE)
@echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
ifeq ($(DEBUG_BACKEND),simulavr)
@echo load >> $(GDBINIT_FILE)
endif
@echo break main >> $(GDBINIT_FILE)
debug: gdb-config $(TARGET).elf
ifeq ($(DEBUG_BACKEND), avarice)
@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
@$(WINSHELL) /c pause
else
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
$(DEBUG_MFREQ) --port $(DEBUG_PORT)
endif
@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT = $(OBJCOPY) --debugging
COFFCONVERT += --change-section-address .data-0x800000
COFFCONVERT += --change-section-address .bss-0x800000
COFFCONVERT += --change-section-address .noinit-0x800000
COFFCONVERT += --change-section-address .eeprom-0x810000
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S -z $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
$(NM) -n $< > $@
# Create library from object files.
.SECONDARY : $(TARGET).a
.PRECIOUS : $(OBJ)
%.a: $(OBJ)
@echo
@echo $(MSG_CREATING_LIBRARY) $@
$(AR) $@ $(OBJ)
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
$(OBJDIR)/%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create object files from C++ source files.
$(OBJDIR)/%.o : %.cpp
@echo
@echo $(MSG_COMPILING_CPP) $<
$(CC) -c $(ALL_CPPFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C++ source files.
%.s : %.cpp
$(CC) -S $(ALL_CPPFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
$(OBJDIR)/%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Create preprocessed source for use in sending a bug report.
%.i : %.c
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list end
clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lss
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
$(REMOVE) $(SRC:.c=.i)
$(REMOVEDIR) .dep
doxygen:
@echo Generating Project Documentation \($(TARGET)\)...
@doxygen Doxygen.conf
@echo Documentation Generation Complete.
clean_doxygen:
rm -rf Documentation
checksource:
@for f in $(SRC) $(CPPSRC) $(ASRC); do \
if [ -f $$f ]; then \
echo "Found Source File: $$f" ; \
else \
echo "Source File Not Found: $$f" ; \
fi; done
# Create object files directory
$(shell mkdir $(OBJDIR) 2>/dev/null)
# Include the dependency files.
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex eep lss sym coff extcoff doxygen clean \
clean_list clean_doxygen program dfu flip flip-ee dfu-ee \
debug gdb-config checksource

View File

@ -0,0 +1,486 @@
# Hey Emacs, this is a -*- makefile -*-
#----------------------------------------------------------------------------
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
# >> Modified for use with the LUFA project. <<
#
# Released to the Public Domain
#
# Additional material for this makefile was written by:
# Peter Fleury
# Tim Henigan
# Colin O'Flynn
# Reiner Patommel
# Markus Pfaff
# Sander Pool
# Frederik Rouleau
# Carlos Lamas
# Dean Camera
# Opendous Inc.
# Denver Gingerich
#
#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make dfu = Download the hex file to the device, using dfu-programmer (must
# have dfu-programmer installed).
#
# make flip = Download the hex file to the device, using Atmel FLIP (must
# have Atmel FLIP installed).
#
# make doxygen = Generate DoxyGen documentation for the project (must have
# DoxyGen installed)
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
# bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------
# MCU name
MCU = ### INSERT NAME OF MICROCONTROLLER MODEL HERE ###
# Targeted chip architecture (see library "Architectures" documentation)
ARCH = UC3
# Target board (see library "Board Types" documentation, NONE for projects not requiring
# LUFA board drivers). If USER is selected, put custom board drivers in a directory called
# "Board" inside the application directory.
BOARD = ### INSERT NAME OF BOARD HERE, OR NONE IF NO BOARD DRIVERS USED ###
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency in Hz. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
#
# This should be the frequency the system core runs at, after the system clock
# has been set up correctly and started.
F_CPU = ### INSERT PRESCALED SYSTEM CLOCK SPEED HERE, IN HZ ###
# USB controller master clock frequency.
# This will define a symbol, F_USB, in all source code files equal to the
# input clock frequency of the USB controller's clock generator in Hz.
#
# For the UC3 chips, this should be equal to 48MHz or 96MHz.
F_USB = ### INSERT CLOCK TO USB MODULE HERE, IN HZ ###
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# Target file name (without extension).
TARGET = ### INSERT NAME OF MAIN FILENAME HERE, WITHOUT EXTENSION ###
# Object files directory
# To put object files in current directory, use a dot (.), do NOT make
# this an empty or blank macro!
OBJDIR = .
# Path to the LUFA library
LUFA_PATH = ### INSERT PATH TO LUFA LIBRARY RELATIVE TO PROJECT DIRECTORY HERE ###
# LUFA library compile-time options and predefined tokens (add '-D' before each token)
LUFA_OPTS = ### INSERT LUFA COMPILE TIME TOKENS HERE ###
# Create the LUFA source path variables by including the LUFA root makefile
include $(LUFA_PATH)/LUFA/makefile
# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \
$(LUFA_SRC_USB) \
$(LUFA_SRC_USBCLASS)
### INSERT ADDITIONAL PROJECT SOURCE FILENAMES OR LUFA MODULE NAMES HERE ###
# List C++ source files here. (C dependencies are automatically generated.)
CPPSRC =
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS = $(LUFA_PATH)/
# Compiler flag to set the C Standard level.
# c89 = "ANSI" C
# gnu89 = c89 plus GCC extensions
# c99 = ISO C99 standard (not yet fully implemented)
# gnu99 = c99 plus GCC extensions
CSTANDARD = -std=gnu99
# Place -D or -U options here for C sources
CDEFS = -DF_CPU=$(F_CPU)UL
CDEFS += -DF_USB=$(F_USB)UL
CDEFS += -DBOARD=BOARD_$(BOARD)
CDEFS += -DARCH=ARCH_$(ARCH)
CDEFS += $(LUFA_OPTS)
# Place -D or -U options here for ASM sources
ADEFS = -DF_CPU=$(F_CPU)
ADEFS += -DF_USB=$(F_USB)UL
ADEFS += -DBOARD=BOARD_$(BOARD)
ADEFS += -DARCH=ARCH_$(ARCH)
ADEFS += $(LUFA_OPTS)
# Place -D or -U options here for C++ sources
CPPDEFS = -DF_CPU=$(F_CPU)UL
CPPDEFS += -DF_USB=$(F_USB)UL
CPPDEFS += -DBOARD=BOARD_$(BOARD)
CPPDEFS += -DARCH=ARCH_$(ARCH)
CPPDEFS += $(LUFA_OPTS)
# Debugging level.
DEBUG = 3
#---------------- Compiler Options C ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -ffunction-sections
CFLAGS += -fno-strict-aliasing
CFLAGS += -Wall
CFLAGS += -Wstrict-prototypes
CFLAGS += -masm-addr-pseudos
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
#---------------- Compiler Options C++ ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CPPFLAGS = -g$(DEBUG)
CPPFLAGS += $(CPPDEFS)
CPPFLAGS += -O$(OPT)
CPPFLAGS += -funsigned-char
CPPFLAGS += -funsigned-bitfields
CPPFLAGS += -ffunction-sections
CPPFLAGS += -fno-strict-aliasing
CPPFLAGS += -fno-exceptions
CPPFLAGS += -masm-addr-pseudos
CPPFLAGS += -Wall
CPPFLAGS += -Wundef
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
#CPPFLAGS += $(CSTANDARD)
#---------------- Assembler Options ----------------
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
# dump that will be displayed for a given single line of source input.
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
#---------------- Linker Options ----------------
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += -Wl,--gc-sections --rodata-writable
LDFLAGS += -Wl,--direct-data
#LDFLAGS += -T linker_script.x
#============================================================================
# Define programs and commands.
SHELL = sh
CC = avr32-gcc
OBJCOPY = avr32-objcopy
OBJDUMP = avr32-objdump
SIZE = avr32-size
AR = avr32-ar rcs
NM = avr32-nm
REMOVE = rm -f
REMOVEDIR = rm -rf
COPY = cp
WINSHELL = cmd
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling C:
MSG_COMPILING_CPP = Compiling C++:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
MSG_CREATING_LIBRARY = Creating library:
# Define all object files.
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
# Define all listing files.
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
# Compiler flags to generate dependency files.
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mpart=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_CPPFLAGS = -mpart=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mpart=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
all: begin gccversion sizebefore build sizeafter end
# Change the build target to build a HEX file or a library.
build: elf hex lss sym
#build: lib
elf: $(TARGET).elf
hex: $(TARGET).hex
lss: $(TARGET).lss
sym: $(TARGET).sym
LIBNAME=lib$(TARGET).a
lib: $(LIBNAME)
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
end:
@echo $(MSG_END)
@echo
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
sizebefore:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
2>/dev/null; echo; fi
sizeafter:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
2>/dev/null; echo; fi
# Display compiler version information.
gccversion :
@$(CC) --version
# Program the device.
flip: $(TARGET).hex
batchisp -hardware usb -device $(MCU) -operation erase f
batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
batchisp -hardware usb -device $(MCU) -operation start reset 0
dfu: $(TARGET).hex
dfu-programmer $(MCU) erase
dfu-programmer $(MCU) flash $(TARGET).hex
dfu-programmer $(MCU) reset
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S -z $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
$(NM) -n $< > $@
# Create library from object files.
.SECONDARY : $(TARGET).a
.PRECIOUS : $(OBJ)
%.a: $(OBJ)
@echo
@echo $(MSG_CREATING_LIBRARY) $@
$(AR) $@ $(OBJ)
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
$(OBJDIR)/%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create object files from C++ source files.
$(OBJDIR)/%.o : %.cpp
@echo
@echo $(MSG_COMPILING_CPP) $<
$(CC) -c $(ALL_CPPFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C++ source files.
%.s : %.cpp
$(CC) -S $(ALL_CPPFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
$(OBJDIR)/%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Create preprocessed source for use in sending a bug report.
%.i : %.c
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list end
clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lss
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
$(REMOVE) $(SRC:.c=.i)
$(REMOVEDIR) .dep
doxygen:
@echo Generating Project Documentation \($(TARGET)\)...
@doxygen Doxygen.conf
@echo Documentation Generation Complete.
clean_doxygen:
rm -rf Documentation
checksource:
@for f in $(SRC) $(CPPSRC) $(ASRC); do \
if [ -f $$f ]; then \
echo "Found Source File: $$f" ; \
else \
echo "Source File Not Found: $$f" ; \
fi; done
# Create object files directory
$(shell mkdir $(OBJDIR) 2>/dev/null)
# Include the dependency files.
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex lss sym doxygen clean clean_list clean_doxygen \
dfu flip checksource

View File

@ -0,0 +1,705 @@
# Hey Emacs, this is a -*- makefile -*-
#----------------------------------------------------------------------------
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
# >> Modified for use with the LUFA project. <<
#
# Released to the Public Domain
#
# Additional material for this makefile was written by:
# Peter Fleury
# Tim Henigan
# Colin O'Flynn
# Reiner Patommel
# Markus Pfaff
# Sander Pool
# Frederik Rouleau
# Carlos Lamas
# Dean Camera
# Opendous Inc.
# Denver Gingerich
#
#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF.
#
# make extcoff = Convert ELF to AVR Extended COFF.
#
# make program = Download the hex file to the device, using avrdude.
# Please customize the avrdude settings below first!
#
# make dfu = Download the hex file to the device, using dfu-programmer (must
# have dfu-programmer installed).
#
# make flip = Download the hex file to the device, using Atmel FLIP (must
# have Atmel FLIP installed).
#
# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
# (must have dfu-programmer installed).
#
# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
# (must have Atmel FLIP installed).
#
# make doxygen = Generate DoxyGen documentation for the project (must have
# DoxyGen installed)
#
# make debug = Start either simulavr or avarice as specified for debugging,
# with avr-gdb or avr-insight as the front end for debugging.
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
# bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------
# MCU name
MCU = ### INSERT NAME OF MICROCONTROLLER MODEL HERE ###
# Targeted chip architecture (see library "Architectures" documentation)
ARCH = XMEGA
# Target board (see library "Board Types" documentation, NONE for projects not requiring
# LUFA board drivers). If USER is selected, put custom board drivers in a directory called
# "Board" inside the application directory.
BOARD = ### INSERT NAME OF BOARD HERE, OR NONE IF NO BOARD DRIVERS USED ###
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency in Hz. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
#
# This should be the frequency the system core runs at, after the system clock
# has been set up correctly and started.
F_CPU = ### INSERT PRESCALED SYSTEM CLOCK SPEED HERE, IN HZ ###
# USB controller master clock frequency.
# This will define a symbol, F_USB, in all source code files equal to the
# input clock frequency of the USB controller's clock generator in Hz.
#
# For the XMEGA chips, this should be equal to a multiple of 6MHz for Low
# Speed USB mode, or a multiple of 48MHz for Full Speed USB mode.
F_USB = ### INSERT CLOCK TO USB MODULE HERE, IN HZ ###
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# Target file name (without extension).
TARGET = ### INSERT NAME OF MAIN FILENAME HERE, WITHOUT EXTENSION ###
# Object files directory
# To put object files in current directory, use a dot (.), do NOT make
# this an empty or blank macro!
OBJDIR = .
# Path to the LUFA library
LUFA_PATH = ### INSERT PATH TO LUFA LIBRARY RELATIVE TO PROJECT DIRECTORY HERE ###
# LUFA library compile-time options and predefined tokens (add '-D' before each token)
LUFA_OPTS = ### INSERT LUFA COMPILE TIME TOKENS HERE ###
# Create the LUFA source path variables by including the LUFA root makefile
include $(LUFA_PATH)/LUFA/makefile
# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \
$(LUFA_SRC_USB) \
$(LUFA_SRC_USBCLASS)
### INSERT ADDITIONAL PROJECT SOURCE FILENAMES OR LUFA MODULE NAMES HERE ###
# List C++ source files here. (C dependencies are automatically generated.)
CPPSRC =
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS = $(LUFA_PATH)/
# Compiler flag to set the C Standard level.
# c89 = "ANSI" C
# gnu89 = c89 plus GCC extensions
# c99 = ISO C99 standard (not yet fully implemented)
# gnu99 = c99 plus GCC extensions
CSTANDARD = -std=gnu99
# Place -D or -U options here for C sources
CDEFS = -DF_CPU=$(F_CPU)UL
CDEFS += -DF_USB=$(F_USB)UL
CDEFS += -DBOARD=BOARD_$(BOARD)
CDEFS += -DARCH=ARCH_$(ARCH)
CDEFS += $(LUFA_OPTS)
# Place -D or -U options here for ASM sources
ADEFS = -DF_CPU=$(F_CPU)
ADEFS += -DF_USB=$(F_USB)UL
ADEFS += -DBOARD=BOARD_$(BOARD)
ADEFS += -DARCH=ARCH_$(ARCH)
ADEFS += $(LUFA_OPTS)
# Place -D or -U options here for C++ sources
CPPDEFS = -DF_CPU=$(F_CPU)UL
CPPDEFS += -DF_USB=$(F_USB)UL
CPPDEFS += -DBOARD=BOARD_$(BOARD)
CPPDEFS += -DARCH=ARCH_$(ARCH)
CPPDEFS += $(LUFA_OPTS)
# Debugging format.
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
# AVR Studio 4.10 requires dwarf-2.
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
DEBUG = dwarf-2
#---------------- Compiler Options C ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -ffunction-sections
CFLAGS += -fno-inline-small-functions
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
CFLAGS += -fno-strict-aliasing
CFLAGS += -Wall
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
#---------------- Compiler Options C++ ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CPPFLAGS = -g$(DEBUG)
CPPFLAGS += $(CPPDEFS)
CPPFLAGS += -O$(OPT)
CPPFLAGS += -funsigned-char
CPPFLAGS += -funsigned-bitfields
CPPFLAGS += -fpack-struct
CPPFLAGS += -fshort-enums
CPPFLAGS += -ffunction-sections
CPPFLAGS += -fno-strict-aliasing
CPPFLAGS += -fno-exceptions
CPPFLAGS += -Wall
CPPFLAGS += -Wundef
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
#CPPFLAGS += $(CSTANDARD)
#---------------- Assembler Options ----------------
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
# dump that will be displayed for a given single line of source input.
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
#---------------- Library Options ----------------
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
# If this is left blank, then it will use the Standard printf version.
PRINTF_LIB =
#PRINTF_LIB = $(PRINTF_LIB_MIN)
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
# If this is left blank, then it will use the Standard scanf version.
SCANF_LIB =
#SCANF_LIB = $(SCANF_LIB_MIN)
#SCANF_LIB = $(SCANF_LIB_FLOAT)
MATH_LIB = -lm
# List any extra directories to look for libraries here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRALIBDIRS =
#---------------- External Memory Options ----------------
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
EXTMEMOPTS =
#---------------- Linker Options ----------------
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += -Wl,--relax
LDFLAGS += -Wl,--gc-sections
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
#LDFLAGS += -T linker_script.x
#---------------- Programming Options (avrdude) ----------------
# Programming hardware
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = jtagmkII
# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = usb
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_NO_VERIFY = -V
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_VERBOSE = -v -v
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
#---------------- Debugging Options ----------------
# For simulavr only - target MCU frequency.
DEBUG_MFREQ = $(F_CPU)
# Set the DEBUG_UI to either gdb or insight.
# DEBUG_UI = gdb
DEBUG_UI = insight
# Set the debugging back-end to either avarice, simulavr.
DEBUG_BACKEND = avarice
#DEBUG_BACKEND = simulavr
# GDB Init Filename.
GDBINIT_FILE = __avr_gdbinit
# When using avarice settings for the JTAG
JTAG_DEV = /dev/com1
# Debugging port used to communicate between GDB / avarice / simulavr.
DEBUG_PORT = 4242
# Debugging host used to communicate between GDB / avarice / simulavr, normally
# just set to localhost unless doing some sort of crazy debugging when
# avarice is running on a different computer.
DEBUG_HOST = localhost
#============================================================================
# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
AR = avr-ar rcs
NM = avr-nm
AVRDUDE = avrdude
REMOVE = rm -f
REMOVEDIR = rm -rf
COPY = cp
WINSHELL = cmd
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling C:
MSG_COMPILING_CPP = Compiling C++:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
MSG_CREATING_LIBRARY = Creating library:
# Define all object files.
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
# Define all listing files.
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
# Compiler flags to generate dependency files.
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
all: begin gccversion sizebefore build sizeafter end
# Change the build target to build a HEX file or a library.
build: elf hex eep lss sym
#build: lib
elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym
LIBNAME=lib$(TARGET).a
lib: $(LIBNAME)
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
end:
@echo $(MSG_END)
@echo
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
sizebefore:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
2>/dev/null; echo; fi
sizeafter:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
2>/dev/null; echo; fi
# Display compiler version information.
gccversion :
@$(CC) --version
# Program the device.
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
flip: $(TARGET).hex
batchisp -hardware usb -device $(MCU) -operation erase f
batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
batchisp -hardware usb -device $(MCU) -operation start reset 0
dfu: $(TARGET).hex
dfu-programmer $(MCU) erase
dfu-programmer $(MCU) flash $(TARGET).hex
dfu-programmer $(MCU) reset
flip-ee: $(TARGET).hex $(TARGET).eep
$(COPY) $(TARGET).eep $(TARGET)eep.hex
batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program
batchisp -hardware usb -device $(MCU) -operation start reset 0
$(REMOVE) $(TARGET)eep.hex
dfu-ee: $(TARGET).hex $(TARGET).eep
dfu-programmer $(MCU) eeprom-flash $(TARGET).eep
dfu-programmer $(MCU) reset
# Generate avr-gdb config/init file which does the following:
# define the reset signal, load the target file, connect to target, and set
# a breakpoint at main().
gdb-config:
@$(REMOVE) $(GDBINIT_FILE)
@echo define reset >> $(GDBINIT_FILE)
@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
@echo end >> $(GDBINIT_FILE)
@echo file $(TARGET).elf >> $(GDBINIT_FILE)
@echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
ifeq ($(DEBUG_BACKEND),simulavr)
@echo load >> $(GDBINIT_FILE)
endif
@echo break main >> $(GDBINIT_FILE)
debug: gdb-config $(TARGET).elf
ifeq ($(DEBUG_BACKEND), avarice)
@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
@$(WINSHELL) /c pause
else
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
$(DEBUG_MFREQ) --port $(DEBUG_PORT)
endif
@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT = $(OBJCOPY) --debugging
COFFCONVERT += --change-section-address .data-0x800000
COFFCONVERT += --change-section-address .bss-0x800000
COFFCONVERT += --change-section-address .noinit-0x800000
COFFCONVERT += --change-section-address .eeprom-0x810000
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S -z $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
$(NM) -n $< > $@
# Create library from object files.
.SECONDARY : $(TARGET).a
.PRECIOUS : $(OBJ)
%.a: $(OBJ)
@echo
@echo $(MSG_CREATING_LIBRARY) $@
$(AR) $@ $(OBJ)
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
$(OBJDIR)/%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create object files from C++ source files.
$(OBJDIR)/%.o : %.cpp
@echo
@echo $(MSG_COMPILING_CPP) $<
$(CC) -c $(ALL_CPPFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C++ source files.
%.s : %.cpp
$(CC) -S $(ALL_CPPFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
$(OBJDIR)/%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Create preprocessed source for use in sending a bug report.
%.i : %.c
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list end
clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lss
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
$(REMOVE) $(SRC:.c=.i)
$(REMOVEDIR) .dep
doxygen:
@echo Generating Project Documentation \($(TARGET)\)...
@doxygen Doxygen.conf
@echo Documentation Generation Complete.
clean_doxygen:
rm -rf Documentation
checksource:
@for f in $(SRC) $(CPPSRC) $(ASRC); do \
if [ -f $$f ]; then \
echo "Found Source File: $$f" ; \
else \
echo "Source File Not Found: $$f" ; \
fi; done
# Create object files directory
$(shell mkdir $(OBJDIR) 2>/dev/null)
# Include the dependency files.
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex eep lss sym coff extcoff doxygen clean \
clean_list clean_doxygen program dfu flip flip-ee dfu-ee \
debug gdb-config checksource

View File

@ -0,0 +1,148 @@
/*
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.
*/
/** \file
* \brief Architecture specific definitions relating to specific processor architectures.
*
* \copydetails Group_ArchitectureSpecific
*
* \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
* functionality.
*/
/** \ingroup Group_Common
* \defgroup Group_ArchitectureSpecific Architecture Specific Definitions
* \brief Architecture specific definitions relating to specific processor architectures.
*
* Architecture specific macros, functions and other definitions, which relate to specific architectures. This
* definitions may or may not be available in some form on other architectures, and thus should be protected by
* preprocessor checks in portable code to prevent compile errors.
*
* @{
*/
#ifndef __LUFA_ARCHSPEC_H__
#define __LUFA_ARCHSPEC_H__
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_COMMON_H)
#error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
#endif
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
#if (ARCH == ARCH_AVR8) || defined(__DOXYGEN__)
/** Disables the AVR's JTAG bus in software, until a system reset. This will override the current JTAG
* status as set by the JTAGEN fuse, disabling JTAG debugging and reverting the JTAG pins back to GPIO
* mode.
*
* \note This macro is not available for all architectures.
*/
#define JTAG_DISABLE() MACROS{ \
__asm__ __volatile__ ( \
"in __tmp_reg__,__SREG__" "\n\t" \
"cli" "\n\t" \
"out %1, %0" "\n\t" \
"out __SREG__, __tmp_reg__" "\n\t" \
"out %1, %0" "\n\t" \
: \
: "r" (1 << JTD), \
"M" (_SFR_IO_ADDR(MCUCR)) \
: "r0"); \
}MACROE
/** Defines a volatile \c NOP statement which cannot be optimized out by the compiler, and thus can always
* be set as a breakpoint in the resulting code. Useful for debugging purposes, where the optimizer
* removes/reorders code to the point where break points cannot reliably be set.
*
* \note This macro is not available for all architectures.
*/
#define JTAG_DEBUG_POINT() __asm__ __volatile__ ("nop" ::)
/** Defines an explicit JTAG break point in the resulting binary via the assembly \c BREAK statement. When
* a JTAG is used, this causes the program execution to halt when reached until manually resumed.
*
* \note This macro is not available for all architectures.
*/
#define JTAG_DEBUG_BREAK() __asm__ __volatile__ ("break" ::)
/** Macro for testing condition "x" and breaking via \ref JTAG_DEBUG_BREAK() if the condition is false.
*
* \note This macro is not available for all architectures.
*
* \param[in] Condition Condition that will be evaluated.
*/
#define JTAG_ASSERT(Condition) MACROS{ if (!(Condition)) { JTAG_DEBUG_BREAK(); } }MACROE
/** Macro for testing condition \c "x" and writing debug data to the stdout stream if \c false. The stdout stream
* must be pre-initialized before this macro is run and linked to an output device, such as the microcontroller's
* USART peripheral.
*
* The output takes the form "{FILENAME}: Function {FUNCTION NAME}, Line {LINE NUMBER}: Assertion {Condition} failed."
*
* \note This macro is not available for all architectures.
*
* \param[in] Condition Condition that will be evaluated,
*/
#define STDOUT_ASSERT(Condition) MACROS{ if (!(x)) { printf_P(PSTR("%s: Function \"%s\", Line %d: " \
"Assertion \"%s\" failed.\r\n"), \
__FILE__, __func__, __LINE__, #Condition); } }MACROE
#if !defined(pgm_read_ptr) || defined(__DOXYGEN__)
/** Reads a pointer out of PROGMEM space on the AVR8 architecture. This is currently a wrapper for the
* avr-libc \c pgm_read_ptr() macro with a \c void* cast, so that its value can be assigned directly
* to a pointer variable or used in pointer arithmetic without further casting in C. In a future
* avr-libc distribution this will be part of the standard API and will be implemented in a more formal
* manner.
*
* \note This macro is not available for all architectures.
*
* \param[in] Address Address of the pointer to read.
*
* \return Pointer retrieved from PROGMEM space.
*/
#define pgm_read_ptr(Address) (void*)pgm_read_word(Address)
#endif
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,84 @@
/*
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.
*/
/** \file
* \brief Supported library architecture defines.
*
* \copydetails Group_Architectures
*
* \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
* functionality.
*/
/** \ingroup Group_Common
* \defgroup Group_Architectures Hardware Architectures
* \brief Supported library architecture defines.
*
* Architecture macros for selecting the desired target microcontroller architecture. One of these values should be
* defined as the value of \c ARCH in the user project makefile via the \c -D compiler switch to GCC, to select the
* target architecture.
*
* The selected architecture should remain consistent with the makefile \c ARCH value, which is used to select the
* underlying driver source files for each architecture.
*
* @{
*/
#ifndef __LUFA_ARCHITECTURES_H__
#define __LUFA_ARCHITECTURES_H__
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_COMMON_H)
#error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Selects the Atmel 8-bit AVR (AT90USB* and ATMEGA*U* chips) architecture. */
#define ARCH_AVR8 0
/** Selects the Atmel 32-bit UC3 AVR (AT32UC3* chips) architecture. */
#define ARCH_UC3 1
/** Selects the Atmel XMEGA AVR (ATXMEGA*U chips) architecture. */
#define ARCH_XMEGA 2
#if !defined(__DOXYGEN__)
#define ARCH_ ARCH_AVR8
#if !defined(ARCH)
#define ARCH ARCH_AVR8
#endif
#endif
#endif
/** @} */

150
LUFA/Common/Attributes.h Normal file
View File

@ -0,0 +1,150 @@
/*
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.
*/
/** \file
* \brief Special function/variable attribute macros.
*
* \copydetails Group_FuncVarAttributes
*
* \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
* functionality.
*/
/** \ingroup Group_Common
* \defgroup Group_FuncVarAttributes Function/Variable Attributes
* \brief Special function/variable attribute macros.
*
* This module contains macros for applying specific attributes to functions and variables to control various
* optimizer and code generation features of the compiler. Attributes may be placed in the function prototype
* or variable declaration in any order, and multiple attributes can be specified for a single item via a space
* separated list.
*
* On incompatible versions of GCC or on other compilers, these macros evaluate to nothing unless they are
* critical to the code's function and thus must throw a compile error when used.
*
* @{
*/
#ifndef __LUFA_FUNCATTR_H__
#define __LUFA_FUNCATTR_H__
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_COMMON_H)
#error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
#if (__GNUC__ >= 3) || defined(__DOXYGEN__)
/** Indicates to the compiler that the function can not ever return, so that any stack restoring or
* return code may be omitted by the compiler in the resulting binary.
*/
#define ATTR_NO_RETURN __attribute__ ((noreturn))
/** Indicates that the function returns a value which should not be ignored by the user code. When
* applied, any ignored return value from calling the function will produce a compiler warning.
*/
#define ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
/** Indicates that the specified parameters of the function are pointers which should never be \c NULL.
* When applied as a 1-based comma separated list the compiler will emit a warning if the specified
* parameters are known at compiler time to be \c NULL at the point of calling the function.
*/
#define ATTR_NON_NULL_PTR_ARG(...) __attribute__ ((nonnull (__VA_ARGS__)))
/** Removes any preamble or postamble from the function. When used, the function will not have any
* register or stack saving code. This should be used with caution, and when used the programmer
* is responsible for maintaining stack and register integrity.
*/
#define ATTR_NAKED __attribute__ ((naked))
/** Prevents the compiler from considering a specified function for in-lining. When applied, the given
* function will not be in-lined under any circumstances.
*/
#define ATTR_NO_INLINE __attribute__ ((noinline))
/** Forces the compiler to inline the specified function. When applied, the given function will be
* in-lined under all circumstances.
*/
#define ATTR_ALWAYS_INLINE __attribute__ ((always_inline))
/** Indicates that the specified function is pure, in that it has no side-effects other than global
* or parameter variable access.
*/
#define ATTR_PURE __attribute__ ((pure))
/** Indicates that the specified function is constant, in that it has no side effects other than
* parameter access.
*/
#define ATTR_CONST __attribute__ ((const))
/** Marks a given function as deprecated, which produces a warning if the function is called. */
#define ATTR_DEPRECATED __attribute__ ((deprecated))
/** Marks a function as a weak reference, which can be overridden by other functions with an
* identical name (in which case the weak reference is discarded at link time).
*/
#define ATTR_WEAK __attribute__ ((weak))
#endif
/** Forces the compiler to not automatically zero the given global variable on startup, so that the
* current RAM contents is retained. Under most conditions this value will be random due to the
* behaviour of volatile memory once power is removed, but may be used in some specific circumstances,
* like the passing of values back after a system watchdog reset.
*/
#define ATTR_NO_INIT __attribute__ ((section (".noinit")))
/** Places the function in one of the initialization sections, which execute before the main function
* of the application. Refer to the avr-libc manual for more information on the initialization sections.
*
* \param[in] SectionIndex Initialization section number where the function should be placed.
*/
#define ATTR_INIT_SECTION(SectionIndex) __attribute__ ((used, naked, section (".init" #SectionIndex )))
/** Marks a function as an alias for another function.
*
* \param[in] Func Name of the function which the given function name should alias.
*/
#define ATTR_ALIAS(Func) __attribute__ ((alias( #Func )))
/** Marks a variable or struct element for packing into the smallest space available, omitting any
* alignment bytes usually added between fields to optimize field accesses.
*/
#define ATTR_PACKED __attribute__ ((packed))
/** Indicates the minimum alignment in bytes for a variable or struct element.
*
* \param[in] Bytes Minimum number of bytes the item should be aligned to.
*/
#define ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
#endif
/** @} */

182
LUFA/Common/BoardTypes.h Normal file
View File

@ -0,0 +1,182 @@
/*
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.
*/
/** \file
* \brief Supported pre-made board hardware defines.
*
* \copydetails Group_BoardTypes
*
* \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
* functionality.
*/
/** \ingroup Group_Common
* \defgroup Group_BoardTypes Board Types
* \brief Supported pre-made board hardware defines.
*
* Board macros for indicating the chosen physical board hardware to the library. These macros should be used when
* defining the \c BOARD token to the chosen hardware via the \c -D switch in the project makefile. If a custom
* board is used, the \ref BOARD_NONE or \ref BOARD_USER values should be selected.
*
* @{
*/
#ifndef __LUFA_BOARDTYPES_H__
#define __LUFA_BOARDTYPES_H__
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_COMMON_H)
#error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Selects the USBKEY specific board drivers, including Temperature, Button, Dataflash, Joystick and LED drivers. */
#define BOARD_USBKEY 0
/** Selects the STK525 specific board drivers, including Temperature, Button, Dataflash, Joystick and LED drivers. */
#define BOARD_STK525 1
/** Selects the STK526 specific board drivers, including Temperature, Button, Dataflash, Joystick and LED drivers. */
#define BOARD_STK526 2
/** Selects the RZUSBSTICK specific board drivers, including the driver for the boards LEDs. */
#define BOARD_RZUSBSTICK 3
/** Selects the ATAVRUSBRF01 specific board drivers, including the driver for the board LEDs. */
#define BOARD_ATAVRUSBRF01 4
/** Selects the user-defined board drivers, which should be placed in the user project's folder
* under a directory named \c /Board/. Each board driver should be named identically to the LUFA
* master board driver (i.e., driver in the \c LUFA/Drivers/Board directory) so that the library
* can correctly identify it.
*/
#define BOARD_USER 5
/** Selects the BUMBLEB specific board drivers, using the officially recommended peripheral layout. */
#define BOARD_BUMBLEB 6
/** Selects the XPLAIN (Revision 2 or newer) specific board drivers, including LED and Dataflash drivers. */
#define BOARD_XPLAIN 7
/** Selects the XPLAIN (Revision 1) specific board drivers, including LED and Dataflash drivers. */
#define BOARD_XPLAIN_REV1 8
/** Selects the EVK527 specific board drivers, including Temperature, Button, Dataflash, Joystick and LED drivers. */
#define BOARD_EVK527 9
/** Disables board drivers when operation will not be adversely affected (e.g. LEDs) - use of board drivers
* such as the Joystick driver, where the removal would adversely affect the code's operation is still disallowed. */
#define BOARD_NONE 10
/** Selects the Teensy version 1.x specific board drivers, including the driver for the board LEDs. */
#define BOARD_TEENSY 11
/** Selects the USBTINY MKII specific board drivers, including the Button and LEDs drivers. */
#define BOARD_USBTINYMKII 12
/** Selects the Benito specific board drivers, including the Button and LEDs drivers. */
#define BOARD_BENITO 13
/** Selects the JM-DB-U2 specific board drivers, including the Button and LEDs drivers. */
#define BOARD_JMDBU2 14
/** Selects the Olimex AVR-USB-162 specific board drivers, including the Button and LEDs drivers. */
#define BOARD_OLIMEX162 15
/** Selects the UDIP specific board drivers, including the Button and LEDs drivers. */
#define BOARD_UDIP 16
/** Selects the BUI specific board drivers, including the driver for the board LEDs. */
#define BOARD_BUI 17
/** Selects the Arduino Uno specific board drivers, including the driver for the board LEDs. */
#define BOARD_UNO 18
/** Selects the Busware CUL V3 specific board drivers, including the Button and LEDs drivers. */
#define BOARD_CULV3 19
/** Selects the Blackcat USB JTAG specific board drivers, including the driver for the board LEDs. */
#define BOARD_BLACKCAT 20
/** Selects the Maximus specific board drivers, including the driver for the board LEDs. */
#define BOARD_MAXIMUS 21
/** Selects the Minimus specific board drivers, including the Button and LEDs drivers. */
#define BOARD_MINIMUS 22
/** Selects the Adafruit U4 specific board drivers, including the Button driver. */
#define BOARD_ADAFRUITU4 23
/** Selects the Microsin AVR-USB162 specific board drivers, including the Button and LEDs drivers. */
#define BOARD_MICROSIN162 24
/** Selects the Kernel Concepts USBFOO specific board drivers, including the Button and LEDs drivers. */
#define BOARD_USBFOO 25
/** Selects the Sparkfun ATMEGA8U2 specific board drivers, including the driver for the board LEDs. */
#define BOARD_SPARKFUN8U2 26
/** Selects the Atmel EVK1101 specific board drivers, including the Button, Joystick and LED drivers. */
#define BOARD_EVK1101 27
/** Selects the Busware TUL specific board drivers, including the Button and LED drivers. */
#define BOARD_TUL 28
/** Selects the Atmel EVK1100 specific board drivers, including the Button, Joystick and LED drivers. */
#define BOARD_EVK1100 29
/** Selects the Atmel EVK1104 specific board drivers, including the Button and LED drivers. */
#define BOARD_EVK1104 30
/** Selects the Atmel XMEGA A3BU Xplained specific board drivers, including Dataflash, Button and LED drivers. */
#define BOARD_A3BU_XPLAINED 31
/** Selects the Teensy version 2.x specific board drivers, including the driver for the board LEDs. */
#define BOARD_TEENSY2 32
/** Selects the USB2AX version 1 and 2 specific board drivers, including the Button and LEDs drivers. */
#define BOARD_USB2AX 33
/** Selects the USB2AX version 3 specific board drivers, including the Button and LEDs drivers. */
#define BOARD_USB2AX_V3 34
#if !defined(__DOXYGEN__)
#define BOARD_ BOARD_NONE
#if !defined(BOARD)
#define BOARD BOARD_NONE
#endif
#endif
#endif
/** @} */

373
LUFA/Common/Common.h Normal file
View File

@ -0,0 +1,373 @@
/*
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.
*/
/** \file
* \brief Common library convenience headers, macros and functions.
*
* \copydetails Group_Common
*/
/** \defgroup Group_Common Common Utility Headers - LUFA/Drivers/Common/Common.h
* \brief Common library convenience headers, macros and functions.
*
* Common utility headers containing macros, functions, enums and types which are common to all
* aspects of the library.
*
* @{
*/
/** \defgroup Group_GlobalInt Global Interrupt Macros
* \brief Convenience macros for the management of interrupts globally within the device.
*
* Macros and functions to create and control global interrupts within the device.
*/
#ifndef __LUFA_COMMON_H__
#define __LUFA_COMMON_H__
/* Macros: */
#define __INCLUDE_FROM_COMMON_H
/* Includes: */
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stddef.h>
#if defined(USE_LUFA_CONFIG_HEADER)
#include "LUFAConfig.h"
#endif
#include "ArchitectureSpecific.h"
#include "CompilerSpecific.h"
#include "Architectures.h"
#include "Attributes.h"
#include "BoardTypes.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Architecture specific utility includes: */
#if defined(__DOXYGEN__)
/** Type define for an unsigned integer the same width as the selected architecture's machine register.
* This is distinct from the non-specific standard int data type, whose width is machine dependant but
* which may not reflect the actual machine register width on some targets (e.g. AVR8).
*/
typedef MACHINE_REG_t uint_reg_t;
#elif (ARCH == ARCH_AVR8)
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <avr/boot.h>
#include <util/delay.h>
typedef uint8_t uint_reg_t;
#define ARCH_HAS_EEPROM_ADDRESS_SPACE
#define ARCH_HAS_FLASH_ADDRESS_SPACE
#define ARCH_HAS_MULTI_ADDRESS_SPACE
#define ARCH_LITTLE_ENDIAN
#include "Endianness.h"
#elif (ARCH == ARCH_UC3)
#include <avr32/io.h>
// === TODO: Find abstracted way to handle these ===
#define PROGMEM const
#define pgm_read_byte(x) *x
#define memcmp_P(...) memcmp(__VA_ARGS__)
#define memcpy_P(...) memcpy(__VA_ARGS__)
// =================================================
typedef uint32_t uint_reg_t;
#define ARCH_BIG_ENDIAN
#include "Endianness.h"
#elif (ARCH == ARCH_XMEGA)
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <util/delay.h>
typedef uint8_t uint_reg_t;
#define ARCH_HAS_EEPROM_ADDRESS_SPACE
#define ARCH_HAS_FLASH_ADDRESS_SPACE
#define ARCH_HAS_MULTI_ADDRESS_SPACE
#define ARCH_LITTLE_ENDIAN
#include "Endianness.h"
#else
#error Unknown device architecture specified.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Macro for encasing other multi-statement macros. This should be used along with an opening brace
* before the start of any multi-statement macro, so that the macros contents as a whole are treated
* as a discrete block and not as a list of separate statements which may cause problems when used as
* a block (such as inline \c if statements).
*/
#define MACROS do
/** Macro for encasing other multi-statement macros. This should be used along with a preceding closing
* brace at the end of any multi-statement macro, so that the macros contents as a whole are treated
* as a discrete block and not as a list of separate statements which may cause problems when used as
* a block (such as inline \c if statements).
*/
#define MACROE while (0)
/** Convenience macro to determine the larger of two values.
*
* \note This macro should only be used with operands that do not have side effects from being evaluated
* multiple times.
*
* \param[in] x First value to compare
* \param[in] y First value to compare
*
* \return The larger of the two input parameters
*/
#if !defined(MAX) || defined(__DOXYGEN__)
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#endif
/** Convenience macro to determine the smaller of two values.
*
* \note This macro should only be used with operands that do not have side effects from being evaluated
* multiple times.
*
* \param[in] x First value to compare
* \param[in] y First value to compare
*
* \return The smaller of the two input parameters
*/
#if !defined(MIN) || defined(__DOXYGEN__)
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#endif
#if !defined(STRINGIFY) || defined(__DOXYGEN__)
/** Converts the given input into a string, via the C Preprocessor. This macro puts literal quotation
* marks around the input, converting the source into a string literal.
*
* \param[in] x Input to convert into a string literal.
*
* \return String version of the input.
*/
#define STRINGIFY(x) #x
/** Converts the given input into a string after macro expansion, via the C Preprocessor. This macro puts
* literal quotation marks around the expanded input, converting the source into a string literal.
*
* \param[in] x Input to expand and convert into a string literal.
*
* \return String version of the expanded input.
*/
#define STRINGIFY_EXPANDED(x) STRINGIFY(x)
#endif
#if !defined(ISR) || defined(__DOXYGEN__)
/** Macro for the definition of interrupt service routines, so that the compiler can insert the required
* prologue and epilogue code to properly manage the interrupt routine without affecting the main thread's
* state with unintentional side-effects.
*
* Interrupt handlers written using this macro may still need to be registered with the microcontroller's
* Interrupt Controller (if present) before they will properly handle incoming interrupt events.
*
* \note This macro is only supplied on some architectures, where the standard library does not include a valid
* definition. If an existing definition exists, the alternative definition here will be ignored.
*
* \ingroup Group_GlobalInt
*
* \param Name Unique name of the interrupt service routine.
*/
#define ISR(Name, ...) void Name (void) __attribute__((__interrupt__)) __VA_ARGS__; void Name (void)
#endif
/* Inline Functions: */
/** Function to reverse the individual bits in a byte - i.e. bit 7 is moved to bit 0, bit 6 to bit 1,
* etc.
*
* \param[in] Byte Byte of data whose bits are to be reversed.
*
* \return Input data with the individual bits reversed (mirrored).
*/
static inline uint8_t BitReverse(uint8_t Byte) ATTR_WARN_UNUSED_RESULT ATTR_CONST;
static inline uint8_t BitReverse(uint8_t Byte)
{
Byte = (((Byte & 0xF0) >> 4) | ((Byte & 0x0F) << 4));
Byte = (((Byte & 0xCC) >> 2) | ((Byte & 0x33) << 2));
Byte = (((Byte & 0xAA) >> 1) | ((Byte & 0x55) << 1));
return Byte;
}
/** Function to perform a blocking delay for a specified number of milliseconds. The actual delay will be
* at a minimum the specified number of milliseconds, however due to loop overhead and internal calculations
* may be slightly higher.
*
* \param[in] Milliseconds Number of milliseconds to delay
*/
static inline void Delay_MS(uint16_t Milliseconds) ATTR_ALWAYS_INLINE;
static inline void Delay_MS(uint16_t Milliseconds)
{
#if (ARCH == ARCH_AVR8)
if (GCC_IS_COMPILE_CONST(Milliseconds))
{
_delay_ms(Milliseconds);
}
else
{
while (Milliseconds--)
_delay_ms(1);
}
#elif (ARCH == ARCH_UC3)
while (Milliseconds--)
{
__builtin_mtsr(AVR32_COUNT, 0);
while (__builtin_mfsr(AVR32_COUNT) < (F_CPU / 1000));
}
#elif (ARCH == ARCH_XMEGA)
if (GCC_IS_COMPILE_CONST(Milliseconds))
{
_delay_ms(Milliseconds);
}
else
{
while (Milliseconds--)
_delay_ms(1);
}
#endif
}
/** Retrieves a mask which contains the current state of the global interrupts for the device. This
* value can be stored before altering the global interrupt enable state, before restoring the
* flag(s) back to their previous values after a critical section using \ref SetGlobalInterruptMask().
*
* \ingroup Group_GlobalInt
*
* \return Mask containing the current Global Interrupt Enable Mask bit(s).
*/
static inline uint_reg_t GetGlobalInterruptMask(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline uint_reg_t GetGlobalInterruptMask(void)
{
GCC_MEMORY_BARRIER();
#if (ARCH == ARCH_AVR8)
return SREG;
#elif (ARCH == ARCH_UC3)
return __builtin_mfsr(AVR32_SR);
#elif (ARCH == ARCH_XMEGA)
return SREG;
#endif
GCC_MEMORY_BARRIER();
}
/** Sets the global interrupt enable state of the microcontroller to the mask passed into the function.
* This can be combined with \ref GetGlobalInterruptMask() to save and restore the Global Interrupt Enable
* Mask bit(s) of the device after a critical section has completed.
*
* \ingroup Group_GlobalInt
*
* \param[in] GlobalIntState Global Interrupt Enable Mask value to use
*/
static inline void SetGlobalInterruptMask(const uint_reg_t GlobalIntState) ATTR_ALWAYS_INLINE;
static inline void SetGlobalInterruptMask(const uint_reg_t GlobalIntState)
{
GCC_MEMORY_BARRIER();
#if (ARCH == ARCH_AVR8)
SREG = GlobalIntState;
#elif (ARCH == ARCH_UC3)
if (GlobalIntState & AVR32_SR_GM)
__builtin_ssrf(AVR32_SR_GM_OFFSET);
else
__builtin_csrf(AVR32_SR_GM_OFFSET);
#elif (ARCH == ARCH_XMEGA)
SREG = GlobalIntState;
#endif
GCC_MEMORY_BARRIER();
}
/** Enables global interrupt handling for the device, allowing interrupts to be handled.
*
* \ingroup Group_GlobalInt
*/
static inline void GlobalInterruptEnable(void) ATTR_ALWAYS_INLINE;
static inline void GlobalInterruptEnable(void)
{
GCC_MEMORY_BARRIER();
#if (ARCH == ARCH_AVR8)
sei();
#elif (ARCH == ARCH_UC3)
__builtin_csrf(AVR32_SR_GM_OFFSET);
#elif (ARCH == ARCH_XMEGA)
sei();
#endif
GCC_MEMORY_BARRIER();
}
/** Disabled global interrupt handling for the device, preventing interrupts from being handled.
*
* \ingroup Group_GlobalInt
*/
static inline void GlobalInterruptDisable(void) ATTR_ALWAYS_INLINE;
static inline void GlobalInterruptDisable(void)
{
GCC_MEMORY_BARRIER();
#if (ARCH == ARCH_AVR8)
cli();
#elif (ARCH == ARCH_UC3)
__builtin_ssrf(AVR32_SR_GM_OFFSET);
#elif (ARCH == ARCH_XMEGA)
cli();
#endif
GCC_MEMORY_BARRIER();
}
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,98 @@
/*
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.
*/
/** \file
* \brief Compiler specific definitions for code optimization and correctness.
*
* \copydetails Group_CompilerSpecific
*
* \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
* functionality.
*/
/** \ingroup Group_Common
* \defgroup Group_CompilerSpecific Compiler Specific Definitions
* \brief Compiler specific definitions for code optimization and correctness.
*
* Compiler specific definitions to expose certain compiler features which may increase the level of code optimization
* for a specific compiler, or correct certain issues that may be present such as memory barriers for use in conjunction
* with atomic variable access.
*
* Where possible, on alternative compilers, these macros will either have no effect, or default to returning a sane value
* so that they can be used in existing code without the need for extra compiler checks in the user application code.
*
* @{
*/
#ifndef __LUFA_COMPILERSPEC_H__
#define __LUFA_COMPILERSPEC_H__
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_COMMON_H)
#error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
#if defined(__GNUC__) || defined(__DOXYGEN__)
/** Forces GCC to use pointer indirection (via the device's pointer register pairs) when accessing the given
* struct pointer. In some cases GCC will emit non-optimal assembly code when accessing a structure through
* a pointer, resulting in a larger binary. When this macro is used on a (non \c const) structure pointer before
* use, it will force GCC to use pointer indirection on the elements rather than direct store and load
* instructions.
*
* \param[in, out] StructPtr Pointer to a structure which is to be forced into indirect access mode.
*/
#define GCC_FORCE_POINTER_ACCESS(StructPtr) __asm__ __volatile__("" : "=b" (StructPtr) : "0" (StructPtr))
/** Forces GCC to create a memory barrier, ensuring that memory accesses are not reordered past the barrier point.
* This can be used before ordering-critical operations, to ensure that the compiler does not re-order the resulting
* assembly output in an unexpected manner on sections of code that are ordering-specific.
*/
#define GCC_MEMORY_BARRIER() __asm__ __volatile__("" ::: "memory");
/** Evaluates to boolean true if the specified value can be determined at compile time to be a constant value
* when compiling under GCC.
*
* \param[in] x Value to check compile time constantness of.
*
* \return Boolean true if the given value is known to be a compile time constant, false otherwise.
*/
#define GCC_IS_COMPILE_CONST(x) __builtin_constant_p(x)
#else
#define GCC_FORCE_POINTER_ACCESS(StructPtr)
#define GCC_MEMORY_BARRIER()
#define GCC_IS_COMPILE_CONST(x) 0
#endif
#endif
/** @} */

488
LUFA/Common/Endianness.h Normal file
View File

@ -0,0 +1,488 @@
/*
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.
*/
/** \file
* \brief Endianness and Byte Ordering macros and functions.
*
* \copydetails Group_Endianness
*/
/** \ingroup Group_Endianness
* \defgroup Group_ByteSwapping Byte Reordering
* \brief Macros and functions for forced byte reordering.
*/
/** \ingroup Group_Endianness
* \defgroup Group_EndianConversion Endianness Conversion
* \brief Macros and functions for automatic endianness conversion.
*/
/** \ingroup Group_Common
* \defgroup Group_Endianness Endianness and Byte Ordering
* \brief Convenience macros and functions relating to byte (re-)ordering
*
* Common library convenience macros and functions relating to byte (re-)ordering.
*
* @{
*/
#ifndef __LUFA_ENDIANNESS_H__
#define __LUFA_ENDIANNESS_H__
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_COMMON_H)
#error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
#endif
#if !(defined(ARCH_BIG_ENDIAN) || defined(ARCH_LITTLE_ENDIAN))
#error ARCH_BIG_ENDIAN or ARCH_LITTLE_ENDIAN not set for the specified architecture.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Swaps the byte ordering of a 16-bit value at compile-time. Do not use this macro for swapping byte orderings
* of dynamic values computed at runtime, use \ref SwapEndian_16() instead. The result of this macro can be used
* inside struct or other variable initializers outside of a function, something that is not possible with the
* inline function variant.
*
* \ingroup Group_ByteSwapping
*
* \param[in] x 16-bit value whose byte ordering is to be swapped.
*
* \return Input value with the byte ordering reversed.
*/
#define SWAPENDIAN_16(x) (uint16_t)((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
/** Swaps the byte ordering of a 32-bit value at compile-time. Do not use this macro for swapping byte orderings
* of dynamic values computed at runtime- use \ref SwapEndian_32() instead. The result of this macro can be used
* inside struct or other variable initializers outside of a function, something that is not possible with the
* inline function variant.
*
* \ingroup Group_ByteSwapping
*
* \param[in] x 32-bit value whose byte ordering is to be swapped.
*
* \return Input value with the byte ordering reversed.
*/
#define SWAPENDIAN_32(x) (uint32_t)((((x) & 0xFF000000UL) >> 24UL) | (((x) & 0x00FF0000UL) >> 8UL) | \
(((x) & 0x0000FF00UL) << 8UL) | (((x) & 0x000000FFUL) << 24UL))
#if defined(ARCH_BIG_ENDIAN) && !defined(le16_to_cpu)
#define le16_to_cpu(x) SwapEndian_16(x)
#define le32_to_cpu(x) SwapEndian_32(x)
#define be16_to_cpu(x) (x)
#define be32_to_cpu(x) (x)
#define cpu_to_le16(x) SwapEndian_16(x)
#define cpu_to_le32(x) SwapEndian_32(x)
#define cpu_to_be16(x) (x)
#define cpu_to_be32(x) (x)
#define LE16_TO_CPU(x) SWAPENDIAN_16(x)
#define LE32_TO_CPU(x) SWAPENDIAN_32(x)
#define BE16_TO_CPU(x) (x)
#define BE32_TO_CPU(x) (x)
#define CPU_TO_LE16(x) SWAPENDIAN_16(x)
#define CPU_TO_LE32(x) SWAPENDIAN_32(x)
#define CPU_TO_BE16(x) (x)
#define CPU_TO_BE32(x) (x)
#elif !defined(le16_to_cpu)
/** \name Run-time endianness conversion */
//@{
/** Performs a conversion between a Little Endian encoded 16-bit piece of data and the
* Endianness of the currently selected CPU architecture.
*
* On little endian architectures, this macro does nothing.
*
* \note This macro is designed for run-time conversion of data - for compile-time endianness
* conversion, use \ref LE16_TO_CPU instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define le16_to_cpu(x) (x)
/** Performs a conversion between a Little Endian encoded 32-bit piece of data and the
* Endianness of the currently selected CPU architecture.
*
* On little endian architectures, this macro does nothing.
*
* \note This macro is designed for run-time conversion of data - for compile-time endianness
* conversion, use \ref LE32_TO_CPU instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define le32_to_cpu(x) (x)
/** Performs a conversion between a Big Endian encoded 16-bit piece of data and the
* Endianness of the currently selected CPU architecture.
*
* On big endian architectures, this macro does nothing.
*
* \note This macro is designed for run-time conversion of data - for compile-time endianness
* conversion, use \ref BE16_TO_CPU instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define be16_to_cpu(x) SwapEndian_16(x)
/** Performs a conversion between a Big Endian encoded 32-bit piece of data and the
* Endianness of the currently selected CPU architecture.
*
* On big endian architectures, this macro does nothing.
*
* \note This macro is designed for run-time conversion of data - for compile-time endianness
* conversion, use \ref BE32_TO_CPU instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define be32_to_cpu(x) SwapEndian_32(x)
/** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
* is in Little Endian format regardless of the currently selected CPU architecture.
*
* On little endian architectures, this macro does nothing.
*
* \note This macro is designed for run-time conversion of data - for compile-time endianness
* conversion, use \ref CPU_TO_LE16 instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define cpu_to_le16(x) (x)
/** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
* is in Little Endian format regardless of the currently selected CPU architecture.
*
* On little endian architectures, this macro does nothing.
*
* \note This macro is designed for run-time conversion of data - for compile-time endianness
* conversion, use \ref CPU_TO_LE32 instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define cpu_to_le32(x) (x)
/** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
* is in Big Endian format regardless of the currently selected CPU architecture.
*
* On big endian architectures, this macro does nothing.
*
* \note This macro is designed for run-time conversion of data - for compile-time endianness
* conversion, use \ref CPU_TO_BE16 instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define cpu_to_be16(x) SwapEndian_16(x)
/** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
* is in Big Endian format regardless of the currently selected CPU architecture.
*
* On big endian architectures, this macro does nothing.
*
* \note This macro is designed for run-time conversion of data - for compile-time endianness
* conversion, use \ref CPU_TO_BE32 instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define cpu_to_be32(x) SwapEndian_32(x)
//@}
/** \name Compile-time endianness conversion */
//@{
/** Performs a conversion between a Little Endian encoded 16-bit piece of data and the
* Endianness of the currently selected CPU architecture.
*
* On little endian architectures, this macro does nothing.
*
* \note This macro is designed for compile-time conversion of data - for run time endianness
* conversion, use \ref le16_to_cpu instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define LE16_TO_CPU(x) (x)
/** Performs a conversion between a Little Endian encoded 32-bit piece of data and the
* Endianness of the currently selected CPU architecture.
*
* On little endian architectures, this macro does nothing.
*
* \note This macro is designed for compile-time conversion of data - for run time endianness
* conversion, use \ref le32_to_cpu instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define LE32_TO_CPU(x) (x)
/** Performs a conversion between a Big Endian encoded 16-bit piece of data and the
* Endianness of the currently selected CPU architecture.
*
* On big endian architectures, this macro does nothing.
*
* \note This macro is designed for compile-time conversion of data - for run-time endianness
* conversion, use \ref be16_to_cpu instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define BE16_TO_CPU(x) SWAPENDIAN_16(x)
/** Performs a conversion between a Big Endian encoded 32-bit piece of data and the
* Endianness of the currently selected CPU architecture.
*
* On big endian architectures, this macro does nothing.
*
* \note This macro is designed for compile-time conversion of data - for run-time endianness
* conversion, use \ref be32_to_cpu instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define BE32_TO_CPU(x) SWAPENDIAN_32(x)
/** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
* is in Little Endian format regardless of the currently selected CPU architecture.
*
* On little endian architectures, this macro does nothing.
*
* \note This macro is designed for compile-time conversion of data - for run-time endianness
* conversion, use \ref cpu_to_le16 instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define CPU_TO_LE16(x) (x)
/** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
* is in Little Endian format regardless of the currently selected CPU architecture.
*
* On little endian architectures, this macro does nothing.
*
* \note This macro is designed for compile-time conversion of data - for run-time endianness
* conversion, use \ref cpu_to_le32 instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define CPU_TO_LE32(x) (x)
/** Performs a conversion on a natively encoded 16-bit piece of data to ensure that it
* is in Big Endian format regardless of the currently selected CPU architecture.
*
* On big endian architectures, this macro does nothing.
*
* \note This macro is designed for compile-time conversion of data - for run-time endianness
* conversion, use \ref cpu_to_be16 instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define CPU_TO_BE16(x) SWAPENDIAN_16(x)
/** Performs a conversion on a natively encoded 32-bit piece of data to ensure that it
* is in Big Endian format regardless of the currently selected CPU architecture.
*
* On big endian architectures, this macro does nothing.
*
* \note This macro is designed for compile-time conversion of data - for run-time endianness
* conversion, use \ref cpu_to_be32 instead.
*
* \ingroup Group_EndianConversion
*
* \param[in] x Data to perform the endianness conversion on.
*
* \return Endian corrected version of the input value.
*/
#define CPU_TO_BE32(x) SWAPENDIAN_32(x)
//! @}
#endif
/* Inline Functions: */
/** Function to reverse the byte ordering of the individual bytes in a 16 bit value.
*
* \ingroup Group_ByteSwapping
*
* \param[in] Word Word of data whose bytes are to be swapped.
*
* \return Input data with the individual bytes reversed.
*/
static inline uint16_t SwapEndian_16(const uint16_t Word) ATTR_WARN_UNUSED_RESULT ATTR_CONST;
static inline uint16_t SwapEndian_16(const uint16_t Word)
{
if (GCC_IS_COMPILE_CONST(Word))
return SWAPENDIAN_16(Word);
uint8_t Temp;
union
{
uint16_t Word;
uint8_t Bytes[2];
} Data;
Data.Word = Word;
Temp = Data.Bytes[0];
Data.Bytes[0] = Data.Bytes[1];
Data.Bytes[1] = Temp;
return Data.Word;
}
/** Function to reverse the byte ordering of the individual bytes in a 32 bit value.
*
* \ingroup Group_ByteSwapping
*
* \param[in] DWord Double word of data whose bytes are to be swapped.
*
* \return Input data with the individual bytes reversed.
*/
static inline uint32_t SwapEndian_32(const uint32_t DWord) ATTR_WARN_UNUSED_RESULT ATTR_CONST;
static inline uint32_t SwapEndian_32(const uint32_t DWord)
{
if (GCC_IS_COMPILE_CONST(DWord))
return SWAPENDIAN_32(DWord);
uint8_t Temp;
union
{
uint32_t DWord;
uint8_t Bytes[4];
} Data;
Data.DWord = DWord;
Temp = Data.Bytes[0];
Data.Bytes[0] = Data.Bytes[3];
Data.Bytes[3] = Temp;
Temp = Data.Bytes[1];
Data.Bytes[1] = Data.Bytes[2];
Data.Bytes[2] = Temp;
return Data.DWord;
}
/** Function to reverse the byte ordering of the individual bytes in a n byte value.
*
* \ingroup Group_ByteSwapping
*
* \param[in,out] Data Pointer to a number containing an even number of bytes to be reversed.
* \param[in] Length Length of the data in bytes.
*
* \return Input data with the individual bytes reversed.
*/
static inline void SwapEndian_n(void* const Data,
uint8_t Length) ATTR_NON_NULL_PTR_ARG(1);
static inline void SwapEndian_n(void* const Data,
uint8_t Length)
{
uint8_t* CurrDataPos = (uint8_t*)Data;
while (Length > 1)
{
uint8_t Temp = *CurrDataPos;
*CurrDataPos = *(CurrDataPos + Length - 1);
*(CurrDataPos + Length - 1) = Temp;
CurrDataPos++;
Length -= 2;
}
}
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

1732
LUFA/Doxygen.conf Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,20 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/**
* \page Page_AboutLUFA About LUFA
*
* This section of the manual contains information about the library as a whole, including its supported targets,
* past and planned changes, and links to other projects incorporating LUFA.
*
* <b>Subsections:</b>
* \li \subpage Page_DeviceSupport - Current Device and Hardware Support
* \li \subpage Page_Resources - LUFA and USB Related Resources
* \li \subpage Page_ChangeLog - Project Changelog
* \li \subpage Page_FutureChanges - Planned Changes to the Library
* \li \subpage Page_LUFAPoweredProjects - Other Projects Using LUFA
*/

View File

@ -0,0 +1,69 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/**
* \page Page_AlternativeStacks Alternative USB AVR Stacks
*
* LUFA is not the only stack available for the USB AVRs, although it is perhaps the best (see \ref Page_WhyUseLUFA).
* In the interests of completeness and user choice, other known USB AVR stacks are listed here.
*
* \section Sec_HardwareStacks Hardware USB AVR Stacks
* These are the known alternative USB stacks which are designed for and run exclusively on the USB AVR series microcontrollers,
* which contain on-chip USB controller hardware for maximum features and speed.
*
* - <b>Name:</b> Atmel USB AVR Stack (<i>Atmel Inc.</i>) \n
* <b>Cost:</b> Free \n
* <b>License:</b> Atmel Limited License (see Atmel download for details) \n
* <b>Website:</b> http://atmel.com/dyn/products/app_notes.asp?family_id=607#USB \n
* <b>Description:</b> This is the official Atmel USB AVR stack, for their 8-bit USB AVR lineup. Each series of
* USB AVR is separated into a separate download stack, which is both AVR-GCC and IAR compatible.
*
* - <b>Name:</b> Dr. Stefan Salewski's AT90USB1287 Stack (<i>Dr. Stefan Salewski</i>) \n
* <b>Cost:</b> Free \n
* <b>License:</b> GPL \n
* <b>Website:</b> http://www.ssalewski.de/AT90USB_firmware.html.en \n
* <b>Description:</b> This is a GPL'd library specifically designed for the AT90USB1287, by Dr. Stefan Salewski, a
* German Physicist. It compiles for AVR-GCC and can potentially be modified to work on other USB
* AVR models.
*
* - <b>Name:</b> FreakUSB Stack (<i>FreakLabs</i>) \n
* <b>Cost:</b> Free \n
* <b>License:</b> Modified BSD \n
* <b>Website:</b> http://freaklabs.org/index.php/FreakUSB-Open-Source-USB-Device-Stack.html \n
* <b>Description:</b> An open source simple USB stack for a selection of the USB AVRs. Contains a sample class driver
* for the CDC-ACM class, however other class driver implementations are also possible.
*
* - <b>Name:</b> PJRC Teensy Stack (<i>Paul Stoffregen</i>) \n
* <b>Cost:</b> Free \n
* <b>License:</b> BSD \n
* <b>Website:</b> http://www.pjrc.com/teensy/usb_debug_only.html \n
* <b>Description:</b> Not so much a complete stack as a collection of USB enabled demos, this library is specifically
* designed for the PJRC Teensy line of USB AVRs, and thus may need to be modified for other USB AVR
* chips. These minimal code samples shows the inner workings of the USB controller, without all the
* abstraction present in most other USB AVR stacks.
*
* \section Sec_SoftwareStacks Software AVR Stacks
* These are the known alternative USB stacks which can run on regular AVR models, lacking dedicated hardware USB controllers
* via a bit-banged (emulated) version of the USB protocol. They are limited in their capabilities due to the cycles required
* to be dedicated to managing the USB bus, but offer a cheap way to implement USB functionality into a design.
*
* - <b>Name:</b> AVR309: Software USB (<i>Atmel</i>) \n
* <b>Cost:</b> Free \n
* <b>License:</b> None Stated \n
* <b>Website:</b> http://www.atmel.com/dyn/Products/app_notes.asp?family_id=607 \n
* <b>Description:</b> Atmel's official software USB implementation, an Application Note containing work by Igor Cesko. This
* is a minimal assembly-only implementation of software USB, providing HID functionality. Less compile
* options than V-USB (see below).
*
* - <b>Name:</b> V-USB (<i>Objective Development</i>) \n
* <b>Cost:</b> Free for some uses, see website for licensing \n
* <b>License:</b> Dual GPL2/Custom \n
* <b>Website:</b> http://www.obdev.at/products/vusb/index.html \n
* <b>Description:</b> Well regarded and complete USB 1.1 software stack for several AVR models, implementing Low Speed HID.
* Used in many commercial and non-commercial designs, with user-submitted projects available for viewing
* on the company's website. Uses C language code mixed with assembly for time-critical sections.
*/

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -0,0 +1,23 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** \page Page_BuildLibrary Building as a Linkable Library
*
* The LUFA library can be built as a proper linkable library (with the extention .a) under AVR-GCC, so that
* the library does not need to be recompiled with each revision of a user project. Instructions for creating
* a library from a given source tree can be found in the AVR-GCC user manual included in the WinAVR install
* /Docs/ directory.
*
* However, building the library is <b>not recommended</b>, as the static (compile-time) options will be
* unable to be changed without a recompilation of the LUFA code. Therefore, if the library is to be built
* from the LUFA source, it should be made to be application-specific and compiled with the static options
* that are required for each project (which should be recorded along with the library).
*
* Normal library use has the library components compiled in at the same point as the application code, as
* demonstrated in the library demos and applications. This is the preferred method, as the library is recompiled
* each time to ensure that all static options for a particular application are applied.
*/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,208 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** \page Page_TokenSummary Summary of Compile Tokens
*
* The following lists all the possible tokens which can be defined in a project makefile, and passed to the
* compiler via the -D switch, to alter the LUFA library code. These tokens may alter the library behaviour,
* or remove features unused by a given application in order to save flash space.
*
* \note If the \c USE_LUFA_CONFIG_HEADER token is defined, the library will include a header file named \c LUFAConfig.h located
* in the user directory where the below compile time tokens may be defined. This allows for an alternative to makefile
* defined tokens for configuring the library.
*
* \section Sec_SummaryNonUSBTokens Non USB Related Tokens
* This section describes compile tokens which affect non-USB sections of the LUFA library.
*
* <b>DISABLE_TERMINAL_CODES</b> - (\ref Group_Terminal) - <i>All Architectures</i> \n
* If an application contains ANSI terminal control codes listed in TerminalCodes.h, it might be desired to remove them
* at compile time for use with a terminal which is non-ANSI control code aware, without modifying the source code. If
* this token is defined, all ANSI control codes in the application code from the TerminalCodes.h header are removed from
* the source code at compile time.
*
*
* \section Sec_SummaryUSBClassTokens USB Class Driver Related Tokens
* This section describes compile tokens which affect USB class-specific drivers in the LUFA library.
*
* <b>HID_HOST_BOOT_PROTOCOL_ONLY</b> - (\ref Group_USBClassHIDHost) - <i>All Architectures</i> \n
* By default, the USB HID Host class driver is designed to work with HID devices using either the Boot or Report HID
* communication protocols. On devices where the Report protocol is not used (i.e. in applications where only basic
* Mouse or Keyboard operation is desired, using boot compatible devices), the code responsible for the Report protocol
* mode can be removed to save space in the compiled application by defining this token. When defined, it is still necessary
* to explicitly put the attached device into Boot protocol mode via a call to \ref HID_Host_SetBootProtocol().
*
* <b>HID_STATETABLE_STACK_DEPTH</b>=<i>x</i> - (\ref Group_HIDParser) - <i>All Architectures</i> \n
* <i>Supported Architectures:</i> All \n
* HID reports may contain PUSH and POP elements, to store and retrieve the current HID state table onto a stack. This
* allows for reports to save the state table before modifying it slightly for a data item, and then restore the previous
* state table in a compact manner. This token may be defined to a non-zero 8-bit value to give the maximum depth of the state
* table stack. If not defined, this defaults to the value indicated in the HID.h file documentation.
*
* <b>HID_USAGE_STACK_DEPTH</b>=<i>x</i> - (\ref Group_HIDParser) - <i>All Architectures</i> \n
* HID reports generally contain many USAGE elements, which are assigned to INPUT, OUTPUT and FEATURE items in succession
* when multiple items are defined at once (via REPORT COUNT elements). This allows for several items to be defined with
* different usages in a compact manner. This token may be defined to a non-zero 8-bit value to set the maximum depth of the
* usage stack, indicating the maximum number of USAGE items which can be stored temporarily until the next INPUT, OUTPUT
* and FEATURE item. If not defined, this defaults to the value indicated in the HID.h file documentation.
*
* <b>HID_MAX_COLLECTIONS</b>=<i>x</i> - (\ref Group_HIDParser) - <i>All Architectures</i> \n
* HID reports generally contain several COLLECTION elements, used to group related data items together. Collection information
* is stored separately in the processed usage structure (and referred to by the data elements in the structure) to save space.
* This token may be defined to a non-zero 8-bit value to set the maximum number of COLLECTION items which can be processed by the
* parser into the resultant processed report structure. If not defined, this defaults to the value indicated in the HID.h file
* documentation.
*
* <b>HID_MAX_REPORTITEMS</b>=<i>x</i> - (\ref Group_HIDParser) - <i>All Architectures</i> \n
* All HID reports contain one or more INPUT, OUTPUT and/or FEATURE items describing the data which can be sent to and from the HID
* device. Each item has associated usages, bit offsets in the item reports and other associated data indicating the manner in which
* the report data should be interpreted by the host. This token may be defined to a non-zero 8-bit value to set the maximum number of
* data elements which can be stored in the processed HID report structure, including INPUT, OUTPUT and (if enabled) FEATURE items.
* If a item has a multiple count (i.e. a REPORT COUNT of more than 1), each item in the report count is placed separately in the
* processed HID report table. If not defined, this defaults to the value indicated in the HID.h file documentation.
*
* <b>HID_MAX_REPORT_IDS</b>=<i>x</i> - (\ref Group_HIDParser) - <i>All Architectures</i> \n
* HID reports may contain several report IDs, to logically distinguish grouped device data from one another - for example, a combination
* keyboard and mouse might use report IDs to separate the keyboard reports from the mouse reports. In order to determine the size of each
* report, and thus know how many bytes must be read or written, the size of each report (IN, OUT and FEATURE) must be calculated and
* stored. This token may be defined to a non-zero 8-bit value to set the maximum number of report IDs in a device which can be processed
* and their sizes calculated/stored into the resultant processed report structure. If not defined, this defaults to the value indicated in
* the HID.h file documentation.
*
* <b>NO_CLASS_DRIVER_AUTOFLUSH</b> - (\ref Group_USBClassDrivers) - <i>All Architectures</i> \n
* Many of the device and host mode class drivers automatically flush any data waiting to be written to an interface, when the corresponding
* USB management task is executed. This is usually desirable to ensure that any queued data is sent as soon as possible once and new data is
* constructed in the main program loop. However, if flushing is to be controlled manually by the user application via the *_Flush() commands,
* the compile time token may be defined in the application's makefile to disable automatic flushing during calls to the class driver USB
* management tasks.
*
* \section Sec_SummaryUSBTokens General USB Driver Related Tokens
* This section describes compile tokens which affect USB driver stack as a whole in the LUFA library.
*
* <b>ORDERED_EP_CONFIG</b> - (\ref Group_EndpointManagement , \ref Group_PipeManagement) - <i>AVR8, UC3</i> \n
* The USB AVRs do not allow for Endpoints and Pipes to be configured out of order; they <i>must</i> be configured in an ascending order to
* prevent data corruption issues. However, by default LUFA employs a workaround to allow for unordered Endpoint/Pipe initialization. This compile
* time token may be used to restrict the initialization order to ascending indexes only in exchange for a smaller compiled binary size. Use
* caution when applied to applications using the library USB Class drivers; the user application must ensure that all endpoints and pipes are
* allocated sequentially.
*
* <b>USE_STATIC_OPTIONS</b>=<i>x</i> - (\ref Group_USBManagement) - <i>All Architectures</i> \n
* By default, the USB_Init() function accepts dynamic options at runtime to alter the library behaviour, including whether the USB pad
* voltage regulator is enabled, and the device speed when in device mode. By defining this token to a mask comprised of the USB options
* mask defines usually passed as the Options parameter to USB_Init(), the resulting compiled binary can be decreased in size by removing
* the dynamic options code, and replacing it with the statically set options. When defined, the USB_Init() function no longer accepts an
* Options parameter.
*
* <b>USB_DEVICE_ONLY</b> - (\ref Group_USBManagement) - <i>All Architectures</i> \n
* For the USB AVR models supporting both device and host USB modes, the USB_Init() function contains a Mode parameter which specifies the
* mode the library should be initialized to. If only device mode is required, the code for USB host mode can be removed from the binary to
* save space. When defined, the USB_Init() function no longer accepts a Mode parameter. This define is irrelevant on smaller USB AVRs which
* do not support host mode.
*
* <b>USB_HOST_ONLY</b> - (\ref Group_USBManagement) - <i>All Architectures</i> \n
* Same as USB_DEVICE_ONLY, except the library is fixed to USB host mode rather than USB device mode. Not available on some USB AVR models.
*
* <b>USB_STREAM_TIMEOUT_MS</b>=<i>x</i> - (\ref Group_USBManagement) - <i>All Architectures</i> \n
* When endpoint and/or pipe stream functions are used, by default there is a timeout between each transfer which the connected device or host
* must satisfy, or the stream function aborts the remaining data transfer. This token may be defined to a non-zero 16-bit value to set the timeout
* period for stream transfers, specified in milliseconds. If not defined, the default value specified in LowLevel.h is used instead.
*
* <b>NO_LIMITED_CONTROLLER_CONNECT</b> - (\ref Group_Events) - <i>AVR8 Only</i> \n
* On the smaller USB AVRs, the USB controller lacks VBUS events to determine the physical connection state of the USB bus to a host. In lieu of
* VBUS events, the library attempts to determine the connection state via the bus suspension and wake up events instead. This however may be
* slightly inaccurate due to the possibility of the host suspending the bus while the device is still connected. If accurate connection status is
* required, the VBUS line of the USB connector should be routed to an AVR pin to detect its level, so that the USB_DeviceState global
* can be accurately set and the \ref EVENT_USB_Device_Connect() and \ref EVENT_USB_Device_Disconnect() events manually raised by the RAISE_EVENT macro.
* When defined, this token disables the library's auto-detection of the connection state by the aforementioned suspension and wake up events.
*
* <b>NO_SOF_EVENTS</b> - (\ref Group_Events) - <i>All Architectures</i> \n
* By default, there exists a LUFA application event for the start of each USB frame while the USB bus is not suspended in either host or device mode.
* This event can be selectively enabled or disabled by calling the appropriate device or host mode function. When this compile time token is defined,
* the ability to receive USB Start of Frame events via the \ref EVENT_USB_Device_StartOfFrame() or \ref EVENT_USB_Host_StartOfFrame() events is removed,
* reducing the compiled program's binary size.
*
* \section Sec_SummaryUSBDeviceTokens USB Device Mode Driver Related Tokens
* This section describes compile tokens which affect USB driver stack of the LUFA library when used in Device mode.
*
* <b>USE_RAM_DESCRIPTORS</b> - (\ref Group_StdDescriptors) - <i>AVR8 Only</i> \n
* Define this token to indicate to the USB driver that all device descriptors are stored in RAM, rather than being located in any one
* of the AVR's memory spaces. RAM descriptors may be desirable in applications where the descriptors need to be modified at runtime.
*
* <b>USE_FLASH_DESCRIPTORS</b> - (\ref Group_StdDescriptors) - <i>AVR8 Only</i> \n
* Similar to USE_RAM_DESCRIPTORS, but all descriptors are stored in the AVR's FLASH memory rather than RAM.
*
* <b>USE_EEPROM_DESCRIPTORS</b> - (\ref Group_StdDescriptors) - <i>AVR8 Only</i> \n
* Similar to USE_RAM_DESCRIPTORS, but all descriptors are stored in the AVR's EEPROM memory rather than RAM.
*
* <b>NO_INTERNAL_SERIAL</b> - (\ref Group_StdDescriptors) - <i>All Architectures</i> \n
* Some AVR models contain a unique serial number which can be used as the device serial number, while in device mode. This allows
* the host to uniquely identify the device regardless of if it is moved between USB ports on the same computer, allowing allocated
* resources (such as drivers, COM Port number allocations) to be preserved. This is not needed in many apps, and so the code that
* performs this task can be disabled by defining this option and passing it to the compiler via the -D switch.
*
* <b>FIXED_CONTROL_ENDPOINT_SIZE</b>=<i>x</i> - (\ref Group_EndpointManagement) - <i>All Architectures</i> \n
* By default, the library determines the size of the control endpoint (when in device mode) by reading the device descriptor.
* Normally this reduces the amount of configuration required for the library, allows the value to change dynamically (if
* descriptors are stored in EEPROM or RAM rather than flash memory) and reduces code maintenance. However, this token can be
* defined to a non-zero value instead to give the size in bytes of the control endpoint, to reduce the size of the compiled
* binary.
*
* <b>DEVICE_STATE_AS_GPIOR</b> - (\ref Group_Device) - <i>AVR8 Only</i> \n
* One of the most frequently used global variables in the stack is the USB_DeviceState global, which indicates the current state of
* the Device State Machine. To reduce the amount of code and time required to access and modify this global in an application, this token
* may be defined to a value between 0 and 2 to fix the state variable into one of the three general purpose IO registers inside the AVR
* reserved for application use. When defined, the corresponding GPIOR register should not be used within the user application except
* implicitly via the library APIs.
*
* <b>FIXED_NUM_CONFIGURATIONS</b>=<i>x</i> - (\ref Group_Device) - <i>All Architectures</i> \n
* By default, the library determines the number of configurations a USB device supports by reading the device descriptor. This reduces
* the amount of configuration required to set up the library, and allows the value to change dynamically (if descriptors are stored in
* EEPROM or RAM rather than flash memory) and reduces code maintenance. However, this value may be fixed via this token in the project
* makefile to reduce the compiled size of the binary at the expense of flexibility.
*
* <b>CONTROL_ONLY_DEVICE</b> - (\ref Group_Device) - <i>All Architectures</i> \n
* In some limited USB device applications, there are no device endpoints other than the control endpoint; i.e. all device communication
* is through control endpoint requests. Defining this token will remove several features related to the selection and control of device
* endpoints internally, saving space. Generally, this is usually only useful in (some) bootloaders and is best avoided.
*
* <b>INTERRUPT_CONTROL_ENDPOINT</b> - (\ref Group_USBManagement) - <i>All Architectures</i> \n
* Some applications prefer to not call the USB_USBTask() management task regularly while in device mode, as it can complicate code significantly.
* Instead, when device mode is used this token can be passed to the library via the -D switch to allow the library to manage the USB control
* endpoint entirely via USB controller interrupts asynchronously to the user application. When defined, USB_USBTask() does not need to be called
* when in USB device mode.
*
* <b>NO_DEVICE_REMOTE_WAKEUP</b> - (\ref Group_Device) - <i>All Architectures</i> \n
* Many devices do not require the use of the Remote Wakeup features of USB, used to wake up the USB host when suspended. On these devices,
* the code required to manage device Remote Wakeup can be disabled by defining this token and passing it to the library via the -D switch.
*
* <b>NO_DEVICE_SELF_POWER</b> - (\ref Group_Device) - <i>All Architectures</i> \n
* USB devices may be bus powered, self powered, or a combination of both. When a device can be both bus powered and self powered, the host may
* query the device to determine the current power source, via \ref USB_Device_CurrentlySelfPowered. For solely bus powered devices, this global
* and the code required to manage it may be disabled by passing this token to the library via the -D switch.
*
*
* \section Sec_SummaryUSBHostTokens USB Host Mode Driver Related Tokens
*
* This section describes compile tokens which affect USB driver stack of the LUFA library when used in Host mode.
*
* <b>HOST_STATE_AS_GPIOR</b> - (\ref Group_Host) - <i>AVR8 Only</i> \n
* One of the most frequently used global variables in the stack is the USB_HostState global, which indicates the current state of
* the Host State Machine. To reduce the amount of code and time required to access and modify this global in an application, this token
* may be defined to a value between 0 and 2 to fix the state variable into one of the three general purpose IO registers inside the AVR
* reserved for application use. When defined, the corresponding GPIOR register should not be used within the user application except
* implicitly via the library APIs.
*
* <b>USB_HOST_TIMEOUT_MS</b>=<i>x</i> - (\ref Group_Host) - <i>All Architectures</i> \n
* When a control transfer is initiated in host mode to an attached device, a timeout is used to abort the transfer if the attached
* device fails to respond within the timeout period. This token may be defined to a non-zero 16-bit value to set the timeout period for
* control transfers, specified in milliseconds. If not defined, the default value specified in Host.h is used instead.
*
* <b>HOST_DEVICE_SETTLE_DELAY_MS</b>=<i>x</i> - (\ref Group_Host) - <i>All Architectures</i> \n
* Some devices require a delay of up to 5 seconds after they are connected to VBUS before the enumeration process can be started, or
* they will fail to enumerate correctly. By placing a delay before the enumeration process, it can be ensured that the bus has settled
* back to a known idle state before communications occur with the device. This token may be defined to a 16-bit value to set the device
* settle period, specified in milliseconds. If not defined, the default value specified in Host.h is used instead.
*/

View File

@ -0,0 +1,30 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** \page Page_CompilingApps Compiling the Demos, Bootloaders and Projects
*
* The following details how to compile the included LUFA demos, applications and bootloaders using AVR-GCC.
*
* \section Sec_Prerequisites Prerequisites
* Before you can compile any of the LUFA library code or demos, you will need a recent distribution of avr-libc (1.6.2+)
* and the AVR-GCC (4.2+) compiler. For Windows users, the best way to obtain these is the WinAVR project
* (<a>http://winavr.sourceforge.net</a>) as this provides a single-file setup for everything required to compile your
* own AVR projects.
*
* \section Sec_Compiling Compiling a LUFA Application
* Compiling the LUFA demos, applications and/or bootloaders is very simple. LUFA comes with makefile scripts for
* each individual demo, bootloader and project folder, as well as scripts in the /Demos/, /Bootloaders/, /Projects/
* and the LUFA root directory. This means that compilation can be started from any of the above directories, with
* a build started from an upper directory in the directory structure executing build of all child directories under it.
* This means that while a build inside a particular demo directory will build only that particular demo, a build stated
* from the /Demos/ directory will build all LUFA demo projects sequentially.
*
* To build a project from the source via the command line, the command <b>"make all"</b> should be executed from the command line in the directory
* of interest. To remove compiled files (including the binary output, all intermediately files and all diagnostic output
* files), execute <b>"make clean"</b>. Once a "make all" has been run and no errors were encountered, the resulting binary will
* be located in the generated ".HEX" file. If your project makes use of pre-initialized EEPROM variables, the generated ".EEP"
* file will contain the project's EEPROM data.
*/

View File

@ -0,0 +1,89 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** \page Page_ConfiguringApps Configuring the Demos, Bootloaders and Projects
*
* If the target microcontroller model, architecture, clock speed, board or other settings are different from the current
* settings, they must be changed and the project recompiled from the source code before being programmed into the microcontroller.
* Most project configuration options are located in the "makefile" build script inside each LUFA application's folder, however
* some demo or application-specific configuration settings (such as the output format in the AudioOut demo) are located in one or
* more of the source files of the project. See each project's individual documentation for application-specific configuration
* values.
*
* Each project "makefile" contains all the script and configuration data required to compile each project. When opened with
* any regular basic text editor such as Notepad or WordPad (ensure that the save format is a pure ASCII text format) the
* build configuration settings may be altered.
*
* Inside each makefile, a number of configuration variables are located, with the format "<VARIABLE NAME> = <VALUE>". For
* each application, the important variables which should be altered are:
*
* - <b>MCU</b>, the target processor model
* - <b>ARCH</b>, the target microcontroller architecture
* - <b>BOARD</b>, the target board hardware
* - <b>F_CPU</b>, the target CPU master clock frequency, after any prescaling
* - <b>F_USB</b>, the target raw input clock to the USB module of the processor
* - <b>CDEFS</b>, the C preprocessor defines which configure options the source code
* - <b>LUFA_PATH</b>, the path to the LUFA library source code
* - <b>LUFA_OPTS</b>, the compile time LUFA options which configure the library features
*
* These values should be changed to reflect the build hardware.
*
* \section Sec_MCU The MCU Parameter
* This parameter indicates the target microcontroller model for the compiled application. This should be set to the model of the target
* microcontroller (such as the AT90USB1287, or the ATMEGA32U4), in all lower-case (e.g. "at90usb1287"). Note that not all demos support all the
* microcontroller models and architectures, as they may make use of peripherals or modes only present in some devices.
*
* For supported processor models, see \ref Page_DeviceSupport.
*
* \section Sec_ARCH The ARCH Parameter
* This parameter indicates the target microcontroller architecture the library is to be compiled for. Different microcontroller
* architectures require different source files to be compiled into the final binary, and so this option must be set to the correct
* architecture for the selected platform.
*
* For supported processor architectures, see \ref Page_DeviceSupport.
*
* \section Sec_BOARD The BOARD Parameter
* This parameter indicates the target board hardware for the compiled application. Some LUFA library drivers are board-specific,
* such as the LED driver, and the library needs to know the layout of the target board. If you are using one of the board models listed
* on the main library page, change this parameter to the board name in all UPPER-case.
*
* If you are not using any board-specific drivers in the LUFA library, or you are using a custom board layout, change this to read
* "USER" (no quotes) instead of a standard board name. If the USER board type is selected and the application makes use of one or more
* board-specific hardware drivers inside the LUFA library, then the appropriate stub drives files should be copied from the \c /CodeTemplates/DriverStubs/
* directory into a /Board/ folder inside the application directory, and the stub driver completed with the appropriate code to drive the
* custom board's hardware.
*
* For boards with built in hardware driver support within the LUFA library, see \ref Page_DeviceSupport.
*
* \section Sec_F_CPU The F_CPU Parameter
* This parameter indicates the target microcontroller's main CPU clock frequency, in Hz. This is used by many libraries (and applications) for
* timing related purposes, and should reflect the actual CPU speed after any prescaling or adjustments are performed.
*
* \section Sec_F_USB The F_USB Parameter
* This parameter indicates the raw input clock frequency to the USB module within the microcontroller in Hz. This may be very different on some platforms
* to the main CPU clock or other peripheral/bus clocks.
*
* \section Sec_CDEFS The CDEFS Parameter
* Many applications have features which can be controlled by the defining of specially named preprocessor tokens at the point of compilation - for example,
* an application might use a compile time token to turn on or off optional or mutually exclusive portions of code. Preprocessor tokens can be
* defined here by listing each one with the -D command line switch, and each token can optionally be defined to a specific value. When defined in the
* project makefile, these behave as if they were defined in every source file via a normal preprocessor define statement.
*
* Most applications will actually have multiple CDEF lines, which are concatenated together with the "+=" operator. This ensures that large
* numbers of configuration options remain readable by splitting up groups of options into separate lines.
*
* \section Sec_LUFA_PATH The LUFA_PATH Parameter
* As each LUFA program requires the LUFA library source code to compile correctly, the application must know where the LUFA library is located. This
* value specifies the path to the LUFA library base relative to the path of the project makefile.
*
* \section Sec_LUFA_OPTS The LUFA_OPTS Parameter
* This value is similar to the CDEFS parameter listed elsewhere -- indeed, it is simply a convenient place to group LUFA related tokens away from the
* application's compile time tokens. Normally, these options do not need to be altered to allow an application to compile and run correctly on a
* different board or microcontroller to the current configuration - if the options are incorrect, then the demo is most likely incompatible with the chosen
* microcontroller model and cannot be made to function through the altering of the makefile settings alone (or at all). Settings such as the USB mode
* (device, host or both), the USB interface speed and other LUFA configuration options can be set here - see \ref Page_TokenSummary documentation for details
* on the available LUFA compile time configuration options.
*/

View File

@ -0,0 +1,21 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/**
* \page Page_DevelopingWithLUFA Developing With LUFA
*
* This section of the manual contains information on LUFA development, such as Getting Started information,
* information on compile-time tuning of the library and other developer-related sections.
*
* <b>Subsections:</b>
* \li \subpage Page_TokenSummary - Summary of Compile Time Tokens
* \li \subpage Page_Migration - Migrating from an Older LUFA Version
* \li \subpage Page_VIDPID - Allocated USB VID and PID Values
* \li \subpage Page_BuildLibrary - Building as a Linkable Library
* \li \subpage Page_WritingBoardDrivers - How to Write Custom Board Drivers
* \li \subpage Page_SoftwareBootloaderStart - How to jump to the bootloader in software
*/

View File

@ -0,0 +1,377 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/**
* \page Page_DeviceSupport Device and Hardware Support
*
* <b>Atmel Microcontrollers:</b>
* \li \subpage Page_AVR8Support - Atmel AVR8 Support
* \li \subpage Page_UC3Support - Atmel AVR32 UC3 Support
* \li \subpage Page_XMEGASupport - Atmel XMEGA Support
*/
/**
* \page Page_AVR8Support Atmel 8-Bit AVR (AVR8) Support
*
* \section Sec_AVR8Support_Devices Supported Microcontroller Models
*
* Currently supported AVR8 models:
*
* <table>
* <tr>
* <th width="150px">Part</th>
* <th width="150px">USB Device Mode</th>
* <th width="150px">USB Host Mode</th>
* </tr>
* <tr>
* <td>AT90USB82</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATMEGA8U2</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>AT90USB162</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATMEGA16U2</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATMEGA16U4</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATMEGA32U2</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATMEGA32U4</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATMEGA32U6</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>AT90USB646</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>AT90USB647</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT90USB1286</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>AT90USB1287</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* </table>
*
* \section Sec_AVR8Support_Boards Supported Atmel Boards
* Currently supported Atmel AVR8 boards (see \ref Group_BoardTypes):
* - AT90USBKEY
* - ATAVRUSBRF01
* - EVK527
* - RZUSBSTICK
* - STK525
* - STK526
* - XPLAIN (Excluding the blue XPLAINED family boards)
*
* \section Sec_AVR8Support_ThirdParty Supported Third Party Models
* Currently supported third-party boards (see \ref Group_BoardTypes for makefile \c BOARD constant names):
* - Adafruit U4 Breakout Board
* - Arduino Uno
* - Busware BUI
* - Busware CUL V3
* - Fletchtronics Bumble-B (using officially recommended peripheral layout)
* - Kernel Concepts USBFOO
* - Linnix UDIP
* - MattairTech JM-DB-U2
* - Maximus USB
* - Microsin AVR-USB162
* - Minimus USB
* - Olimex AVR-USB-162
* - Paranoid Studio's US2AX (V1, V2 and V3 hardware revisions)
* - PJRC Teensy (1.x and 2.x versions)
* - Sparkfun U2 Breakout Board
* - TCNISO Blackcat USB JTAG
* - Tempusdictum Benito
* - Tom's USBTINY-MKII (all revisions and versions)
* - Custom User Boards (with Board Drivers if desired, see \ref Page_WritingBoardDrivers)
*/
/**
* \page Page_UC3Support Atmel 32-Bit UC3 AVR (UC3)
* Note: <i>The AVR32 UC3 device support is currently <b>experimental</b>, and is included for preview purposes only.</i>
*
* \section Sec_UC3Support_Devices Supported Microcontroller Models
*
* Currently supported UC3 models:
*
* <table>
* <tr>
* <th width="150px">Part</th>
* <th width="150px">USB Device Mode</th>
* <th width="150px">USB Host Mode</th>
* </tr>
* <tr>
* <td>AT32UC3A064</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A164</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A364</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A364S</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A464</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A464S</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3B064</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3B164</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A0128</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A1128</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A3128</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A3128S</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A4128</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A4128S</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3B0128</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3B1128</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A0256</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A1256</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A3256</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A3256S</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A4256</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A4256S</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3B0256</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3B1256</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A0512</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3A1512</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3B0512</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>AT32UC3B1512</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* </table>
*
* \section Sec_UC3Support_Boards Supported Atmel Boards
*
* Currently supported Atmel UC3 boards (see \ref Group_BoardTypes):
* - EVK1100
* - EVK1101
* - EVK1104
*
* \section Sec_UC3Support_ThirdParty Supported Third Party Models
*
* Currently supported third-party boards (see \ref Group_BoardTypes for makefile \c BOARD constant names):
* - Custom User Boards (with Board Drivers if desired, see \ref Page_WritingBoardDrivers)
*/
/**
* \page Page_XMEGASupport Atmel USB XMEGA AVR (XMEGA)
* Note: <i>The XMEGA device support is currently <b>experimental</b> (incomplete and/or non-functional), and is included for preview purposes only.</i>
*
* \section Sec_XMEGASupport_Devices Supported Microcontroller Models
*
* Currently supported XMEGA models:
*
* <table>
* <tr>
* <th width="150px">Part</th>
* <th width="150px">USB Device Mode</th>
* <th width="150px">USB Host Mode</th>
* </tr>
* <tr>
* <td>ATXMEGA16A4U</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATXMEGA32A4U</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATXMEGA64A3U</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATXMEGA128A3U</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATXMEGA192A3U</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATXMEGA256A3U</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATXMEGA256A3BU</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATXMEGA128A1U</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATXMEGA64B3</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATXMEGA128B3</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATXMEGA64B1</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* <tr>
* <td>ATXMEGA128B1</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#EE0000">No</td>
* </tr>
* </table>
*
* \section Sec_XMEGASupport_Boards Supported Atmel Boards
* Currently supported Atmel XMEGA boards (see \ref Group_BoardTypes):
* - XMEGA A3BU Xplained
*
* \section Sec_XMEGASupport_ThirdParty Supported Third Party Models
* Currently supported third-party boards (see \ref Group_BoardTypes for makefile \c BOARD constant names):
* - Custom User Boards (with Board Drivers if desired, see \ref Page_WritingBoardDrivers)
*/

View File

@ -0,0 +1,254 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** \dir LUFA/Common
* \brief Common library header files.
*
* This folder contains header files which are common to all parts of the LUFA library. They may be used freely in
* user applications.
*
* \dir LUFA/Drivers
* \brief Library hardware and software drivers.
*
* This folder contains all the library hardware and software drivers for each supported board, architecture and
* microcontroller model.
*
* \dir LUFA/Drivers/Misc
* \brief Miscellaneous driver files.
*
* This folder contains drivers for aspects other than the USB interface, board hardware or microcontroller peripherals.
*
* \dir LUFA/Drivers/Peripheral
* \brief Microcontroller peripheral driver files.
*
* This folder contains drivers for various low level microcontroller peripherals, usually located on the microcontroller
* die within the same physical chip.
*
* \dir LUFA/Drivers/USB
* \brief USB controller peripheral driver files.
*
* This folder contains the complete LUFA USB stack and controller files, including the core driver and stack, as well
* as the USB class driver implementations.
*
* \dir LUFA/Drivers/USB/Core
* \brief Core USB driver files.
*
* This folder contains the core USB stack and controller driver files, to correctly implement USB functionality on the
* target architecture and microcontroller model. This
*
* \dir LUFA/Drivers/USB/Class
* \brief USB Class helper driver files.
*
* This folder contains drivers for implementing functionality of standardized USB classes. These are not used directly by the library,
* but provide a standard and library-maintained way of implementing functionality from some of the defined USB classes without extensive
* development effort. Is is recommended that these drivers be used where possible to reduce maintenance of user applications.
*
* \dir LUFA/Drivers/USB/Class/Device
* \brief USB Device Class helper driver files.
*
* Device mode drivers for the standard USB classes.
*
* \dir LUFA/Drivers/USB/Class/Host
* \brief USB Host Class helper driver files.
*
* Host mode drivers for the standard USB classes.
*
* \dir LUFA/Drivers/Board
* \brief Board hardware driver files.
*
* This folder contains drivers for interfacing with the physical hardware on supported commercial boards, primarily from
* the Atmel corporation. Header files in this folder should be included in user applications requiring the functionality of
* hardware placed on supported boards.
*
* \dir LUFA/Drivers/Board/AVR8/ADAFRUITU4
* \brief ADAFRUITU4 board hardware driver files.
*
* This folder contains drivers for hardware on the Adafruit U4 breakout board (http://ladyada.net/products/atmega32u4breakout).
* The header files in this folder should not be included directly in user applications; the similarly named dispatch header files
* located in the parent Board directory should be included instead.
* \dir LUFA/Drivers/Board/AVR8/ATAVRUSBRF01
* \brief ATAVRUSBRF01 board hardware driver files.
*
* This folder contains drivers for hardware on the Atmel ATAVRUSBRF01 board, as used in several Atmel wireless demo kits. The header
* files in this folder should not be included directly in user applications; the similarly named dispatch header files located in
* the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/BENITO
* \brief BENITO board hardware driver files.
*
* This folder contains drivers for hardware on the Benito boards (http://dorkbotpdx.org/wiki/benito). The header files in this
* folder should not be included directly in user applications; the similarly named dispatch header files located in the parent
* Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/BUMBLEB
* \brief BUMBLEB board hardware driver files.
*
* This folder contains drivers for hardware on the Fletchtronics Bumble-B board (http://fletchtronics.net/bumble-b). The header
* files in this folder should not be included directly in user applications; the similarly named dispatch header files located in
* the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/BUI
* \brief BUI board hardware driver files.
*
* This folder contains drivers for hardware on the Busware BUI (http://www.busware.de/tiki-index.php?page=BUI).
* The header files in this folder should not be included directly in user applications; the similarly named dispatch header files
* located in the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/BLACKCAT
* \brief BLACKCAT board hardware driver files.
*
* This folder contains drivers for hardware on the TCNISO Blackcat USB JTAG (http://www.embeddedcomputers.net/products/BlackcatUSB/.
* The header files in this folder should not be included directly in user applications; the similarly named dispatch header files
* located in the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/CULV3
* \brief CULV3 board hardware driver files.
*
* This folder contains drivers for hardware on the Busware CUL V3 (http://busware.de/tiki-index.php?page=CUL).
* The header files in this folder should not be included directly in user applications; the similarly named dispatch header files
* located in the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/EVK527
* \brief EVK527 board hardware driver files.
*
* This folder contains drivers for hardware on the Atmel EVK527 development board. The header files in this folder should
* not be included directly in user applications; the similarly named dispatch header files located in the parent Board directory
* should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/JMDBU2
* \brief JM-DB-U2 board hardware driver files.
*
* This folder contains drivers for hardware on the JM-DB-U2 boards (http://u2.mattair.net/). The header files in this folder
* should not be included directly in user applications; the similarly named dispatch header files located in the parent Board
* directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/MAXIMUS
* \brief MAXIMUS board hardware driver files.
*
* This folder contains drivers for hardware on the Maximus boards (http://www.avrusb.com/). The header files in this folder
* should not be included directly in user applications; the similarly named dispatch header files located in the parent Board
* directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/MICROSIN162
* \brief MICROSIN162 board hardware driver files.
*
* This folder contains drivers for hardware on the Microsin AVR-USB162 board (http://microsin.ru/content/view/685/44/). The
* header files in this folder should not be included directly in user applications; the similarly named dispatch header files
* located in the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/MINIMUS
* \brief MINIMUS board hardware driver files.
*
* This folder contains drivers for hardware on the Minimus boards (http://www.minimususb.com/). The header files in this folder
* should not be included directly in user applications; the similarly named dispatch header files located in the parent Board
* directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/OLIMEX162
* \brief Olimex USB-STK-162 board hardware driver files.
*
* This folder contains drivers for hardware on the Olimex AVR-USB-162 boards (http://www.olimex.com/dev/avr-usb-162.html).
* The header files in this folder should not be included directly in user applications; the similarly named dispatch header files
* located in the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/RZUSBSTICK
* \brief RZUSBSTICK board hardware driver files.
*
* This folder contains drivers for hardware on the Atmel RZUSBSTICK board, as used in the Atmel "Raven" wireless kits. The header
* files in this folder should not be included directly in user applications; the similarly named dispatch header files located in
* the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/SPARKFUN8U2
* \brief SPARKFUN8U2 board hardware driver files.
*
* This folder contains drivers for hardware on the Sparkfun ATMEGA8U2 breakout board (http://www.sparkfun.com/products/10277). The
* header files in this folder should not be included directly in user applications; the similarly named dispatch header files located
* in the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/STK525
* \brief STK525 board hardware driver files.
*
* This folder contains drivers for hardware on the Atmel STK525 development board. The header files in this folder should
* not be included directly in user applications; the similarly named dispatch header files located in the parent Board directory
* should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/STK526
* \brief STK526 board hardware driver files.
*
* This folder contains drivers for hardware on the Atmel STK526 development board. The header files in this folder should
* not be included directly in user applications; the similarly named dispatch header files located in the parent Board directory
* should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/TEENSY
* \brief TEENSY board hardware driver files.
*
* This folder contains drivers for hardware on all revisions of the PJRC Teensy boards (http://www.pjrc.com/teensy/). The header
* files in this folder should not be included directly in user applications; the similarly named dispatch header files located
* in the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/TUL
* \brief TUL board hardware driver files.
*
* This folder contains drivers for hardware on the Busware TUL (http://busware.de/tiki-index.php?page=TUL).
* The header files in this folder should not be included directly in user applications; the similarly named dispatch header files
* located in the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/UDIP
* \brief UDIP board hardware driver files.
*
* This folder contains drivers for hardware on the Linnix UDIP boards (http://linnix.com/udip/).
* The header files in this folder should not be included directly in user applications; the similarly named dispatch header files
* located in the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/UNO
* \brief UNO board hardware driver files.
*
* This folder contains drivers for hardware on the Arduino Uno boards (http://www.arduino.cc).
* The header files in this folder should not be included directly in user applications; the similarly named dispatch header files
* located in the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/USBFOO
* \brief USBFOO board hardware driver files.
*
* This folder contains drivers for hardware on the USBFOO boards (http://shop.kernelconcepts.de/product_info.php?products_id=102).
* The header files in this folder should not be included directly in user applications; the similarly named dispatch header files
* located in the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/USBKEY
* \brief USBKEY board hardware driver files.
*
* This folder contains drivers for hardware on the Atmel USBKEY demonstration board. The header files in this folder should
* not be included directly in user applications; the similarly named dispatch header files located in the parent Board directory
* should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/USBTINYMKII
* \brief USBTINY-MKII board hardware driver files.
*
* This folder contains drivers for hardware on all revisions of the USBTINY-MKII boards (http://tom-itx.dyndns.org:81/~webpage/).
* The header files in this folder should not be included directly in user applications; the similarly named dispatch header files
* located in the parent Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/AVR8/XPLAIN
* \brief XPLAIN board hardware driver files.
*
* This folder contains drivers for hardware on the Atmel XPLAIN board (all hardware revisions). The header files in this folder
* should not be included directly in user applications; the similarly named dispatch header files located in the parent Board
* directory should be included instead.
*
* \dir LUFA/CodeTemplates
* \brief Code templates for use in LUFA powered applications.
*
* This contains code templates for board drivers, sample LUFA project makefiles and other similar templates that can be copied into
* a LUFA powered application and modified to speed up development.
*
* \dir LUFA/CodeTemplates/DriverStubs
* \brief Driver stub header files for custom boards, to allow the LUFA board drivers to operate.
*
* This contains stub files for the LUFA board drivers. If the LUFA board drivers are used with board hardware other than those
* directly supported by the library, the BOARD parameter of the application's makefile can be set to "USER", and these stub files
* copied to the "/Board/" directory of the application's folder. When fleshed out with working driver code for the custom board,
* the corresponding LUFA board APIs will work correctly with the non-standard board hardware.
*/

View File

@ -0,0 +1,24 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/**
* \page Page_Donating Donating to Support This Project
*
* \image html Author.jpg "Dean Camera, LUFA Developer"
*
* I am a 22 year old University student studying for a double degree in Computer Science and Electronics Engineering.
* The development and support of this library requires much effort from myself, as I am the sole developer, maintainer
* and supporter. Please consider donating a small amount to support this and my future Open Source projects - All
* donations are <i>greatly</i> appreciated.
*
* Note that commercial entities can remove the attribution portion of the LUFA license by a one-time fee - see
* \ref Page_LicenseInfo for more details (<b>Note: Please do NOT pay this in advance through the donation link below -
* contact author for payment details.</b>).
*
* \image html "http://www.pledgie.com/campaigns/6927.png?skin_name=chrome"
* <a href='http://www.lufa-lib.org/donate'>Donate to this project via PayPal</a> - Thanks in Advance!
*/

View File

@ -0,0 +1,48 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** \page Page_FutureChanges Future Changes
*
* Below is a list of future changes which are proposed for the LUFA library, but not yet started/complete.
* This gives an unordered list of future changes which may be available in future releases of the library.
* If you have an item to add to this list, please contact the library author via email, the LUFA mailing list,
* or post your suggestion as an enhancement request to the project bug tracker.
*
* <b>Targeted for Future Releases:</b>
* - Code Features
* -# Add hub support when in Host mode for multiple devices
* -# Investigate virtual hubs when in device mode instead of composite devices
* -# Change makefiles to allow for absolute LUFA location to be used
* -# Re-add interrupt Pipe/Endpoint support
* -# Add makefile includes to reduce boilerplate in user makefiles
* -# Update stream APIs to use DMA transfers on supported architectures
* -# Pull out third party libraries into a separate folder and reference them as required
* -# Add a LUFA_YIELD macro for integration into a third-party RTOS
* -# Abstract out Mass Storage byte send/receive to prevent low level API use in projects
* -# Consider switch from endpoint numbers to full endpoint addresses to ease future architecture expansion
* -# Fix HID report parser usage support for array types
* -# Make HOST_DEVICE_SETTLE_DELAY_MS a global variable that can be changed
* -# Add MANDATORY_EVENT_FUNCTIONS compile time option
* -# Add watchdog support to the library and apps/bootloaders
* -# Re-run USBIF test suite on all classes to formally verify operation
* - Documentation/Support
* -# Add detailed overviews of how each demo works
* -# Add board overviews
* -# Write LUFA tutorials
* - Demos/Projects
* -# Device/Host USB bridge
* -# Finish incomplete demos and projects
* -# Add class driver support for Test and Measurement class
* -# Add class driver support for EEM class
* -# Add class driver support for ECM class
* -# Port all demos to multiple architectures
* - Ports
* -# Finish USB XMEGA port
* -# Add AVR32 UC3C support
* -# Atmel ARM7 series microcontrollers
* -# Other (commercial) C compilers
*/

View File

@ -0,0 +1,27 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** \page Page_GettingStarted Getting Started
*
* Out of the box, LUFA contains a large number of pre-made class demos for you to test, experiment with and
* ultimately build upon for your own projects. All the demos (where possible) come pre-configured to build and
* run correctly on the AT90USB1287 AVR microcontroller, mounted on the Atmel USBKEY board and running at an 8MHz
* master clock. This is due to two reasons; one, it is the hardware the author possesses, and two, it is the most
* popular Atmel USB demonstration board to date. To learn how to reconfigure, recompile and program the included
* LUFA applications using different settings, see the subsections below.
*
* Most of the included demos in the /Demos/ folder come in both ClassDriver and LowLevel varieties. If you are new
* to LUFA, it is highly recommended that you look at the ClassDriver versions first, which use the pre-made USB
* Class Drivers (\ref Group_USBClassDrivers) to simplify the use of the standard USB classes in user applications.
*
* For an overview of the included library applications, bootloaders and demos, see \ref Page_LibraryApps.
*
* <b>Subsections:</b>
* \li \subpage Page_ConfiguringApps - How to Configure the Included Demos, Projects and Bootloaders
* \li \subpage Page_CompilingApps - How to Compile the Included Demos, Projects and Bootloaders
* \li \subpage Page_ProgrammingApps - How to Program an AVR with the Included Demos, Projects and Bootloaders
*/

View File

@ -0,0 +1,25 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** @defgroup Group_BoardDrivers Board Drivers
*
* Functions, macros, variables, enums and types related to the control of physical board hardware.
*/
/** @defgroup Group_PeripheralDrivers On-chip Peripheral Drivers
*
* Functions, macros, variables, enums and types related to the control of AVR subsystems.
*/
/** @defgroup Group_MiscDrivers Miscellaneous Drivers
*
* Miscellaneous driver Functions, macros, variables, enums and types.
*/
/** @defgroup Group_PlatformDrivers System Platform Drivers
*
* Drivers relating to the general architecture platform, such as clock setup and interrupt management.
*/

BIN
LUFA/DoxygenPages/LUFA.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -0,0 +1,151 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** \page Page_LUFAPoweredProjects User Projects Powered by LUFA
*
* LUFA is currently in use all around the world, in many applications both commercial and non-commercial. Below is a
* list of known public LUFA powered projects, which all use the LUFA library in some way. Feel free to visit each project's
* home page for more information on each project.
*
* If you have a project that you would like to add to this list, please contact me via the details on the main page of this
* documentation.
*
* \section Sec_BoardsUsingLUFA AVR-USB Development Boards Using LUFA
*
* The following is a list of known AVR USB development boards, which recommend using LUFA for the USB stack. Some of these
* are open design, and all are available for purchase as completed development boards suitable for project development.
*
* - AVR-USB-162, a USBKEY-like development board for the AT90USB162: http://olimex.com/dev/avr-usb-162.html
* - Benito #7, a no-frills USB board: http://www.dorkbotpdx.org/wiki/benito
* - JM-DB-U2, an ATMEGA32U2 development board: http://u2.mattair.net/index.html
* - Micropendous, an open design/source set of AVR USB development boards: http://micropendous.org/
* - Microsin AVR-USB162 breakout board, a DIY AT90USB162 development board: http://microsin.ru/content/view/685/44/
* - Minimus USB, a board specially designed for PSGroove: http://www.minimususb.com/
* - Nanduino, a do-it-yourself AT90USB162 board: http://www.makestuff.eu/wordpress/?page_id=569
* - Sparkfun ATMEGA8U2 breakout board: http://www.sparkfun.com/products/10277
* - Teensy and Teensy++, two other AVR USB development boards: http://www.pjrc.com/teensy/index.html
* - U2DIL/U4DIL, a set of DIP layout USB AVR boards: http://www.reworld.eu/re/en/products/u2dil/
* - USB2AX, a tiny USB to serial converter board: http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX
* - USBFOO 2, AT90USB162 based development board: http://shop.kernelconcepts.de/product_info.php?products_id=102
*
* \section Sec_LUFAProjects Projects Using LUFA (Hobbyist)
*
* The following are known hobbyist projects using LUFA. Most are open source, and show off interesting ways that the LUFA library
* can be incorporated into many different applications.
*
* - Accelerometer Game Joystick: http://www.crictor.co.il/he/episodes/joystick/
* - Arcade Controller: http://fletchtronics.net/arcade-controller-made-petunia
* - Arcade Joystick: http://jamie.lentin.co.uk/embedded/arcade-joystick/
* - AVR USB Modem, a 3G Wireless Modem host: http://code.google.com/p/avrusbmodem/
* - Bicycle POV: http://www.code.google.com/p/bicycleledpov/
* - Bluetooth Explorerbot: http://code.google.com/p/bluetooth-explorerbot/
* - Bus Ninja, an AVR clone of the popular BusPirate project: http://blog.hodgepig.org/busninja/
* - CAMTRIG, a remote Camera Trigger device: http://code.astraw.com/projects/motmot/camtrig
* - CD Driver Emulator Dongle for ISO Files: http://cdemu.blogspot.com/
* - ClockTamer, a configurable clock generator: http://code.google.com/p/clock-tamer/
* - Collection of alternative Arduino Uno firmwares: http://hunt.net.nz/users/darran/
* - CULFW, a 868MHz RF packet encoder/decoder: http://www.koeniglich.de/culfw/culfw.html
* - Dashkey, a custom PC keyboard controller: http://geekhack.org/showwiki.php?title=Island:19096
* - DIY PS3 controller emulator: https://code.google.com/p/diyps3controller/
* - EMuSer, a USB-RS422 adapter for E-Mu samplers: http://www.emxp.net/EMuSer.htm
* - Estick JTAG, an ARM JTAG debugger: http://code.google.com/p/estick-jtag/
* - "Fingerlicking Wingdinger" (WARNING: Bad language if no Javascript), a MIDI controller: http://noisybox.net/electronics/wingdinger/
* - Flyatar, a real-time fly tracking system: https://github.com/peterpolidoro/Flyatar
* - Gamecube controller to USB adapter: https://www.facebook.com/media/set/?set=a.10150202447076304.310536.688776303&l=df53851c50
* - Garmin GPS USB to NMEA standard serial sentence translator: http://github.com/nall/garmin-transmogrifier/tree/master
* - Generic HID Device Creator: http://generichid.sourceforge.net/
* - Generic HID Open Source Framework: http://www.waitingforfriday.com/index.php/USB_Generic_HID_Open_Source_Framework_for_Atmel_AVR_and_Windows
* - Ghetto Drum, a MIDI drum controller: http://noisybox.net/art/gdrum/
* - Hiduino, a USB-MIDI replacement firmware for the Arduino Uno: http://code.google.com/p/hiduino/
* - Ikea RGB LED USB modification: http://slashhome.se/p/projects/id/ikea_dioder_usb/#project
* - IR Remote to Keyboard decoder: http://netzhansa.blogspot.com/2010/04/our-living-room-hi-fi-setup-needs-mp3.html
* - LED Panel controller: http://projects.peterpolidoro.net/caltech/panelscontroller/panelscontroller.htm
* - Linux Secure Storage Dongle: http://github.com/TomMD/teensy
* - LUFA powered DDR dance mat (French): http://logicien-parfait.fr/dokuwiki/doku.php?id=projet:ddr_repair
* - MakeTV Episode Dispenser: http://www.youtube.com/watch?v=BkWUi18hl3g
* - MidiMonster, a USB-to-MIDI gateway board: http://www.dorkbotpdx.org/wiki/midimonster
* - MIDI Theremin: http://baldwisdom.com/usb-midi-controller-theremin-style-on-arduino-uno/
* - MiniBloq, a graphical Ardunio programming environment : http://minibloq.org/
* - MiXley, a port of the Teacup 3D printer firmware for the USB AVRs: http://codaset.com/michielh/mixley
* - Mobo 4.3, a USB controlled all band (160-10m) HF SDR transceiver: http://sites.google.com/site/lofturj/mobo4_3
* - Moco, a native Arduino Uno MIDI replacement firmware: http://web.mac.com/kuwatay/morecat_lab./MocoLUFA.html
* - Motherboard BIOS flasher: http://www.coreboot.org/InSystemFlasher
* - MRF49XA RF Tranceiver Dongle: http://www.github.com/hpux735/MRF49XA-Dongle
* - Multi-button Joystick (French): http://logicien-parfait.fr/dokuwiki/doku.php?id=projet:joystick
* - Music Playing Alarm Clock (Tutorial): http://www.instructables.com/id/Music-Playing-Alarm-Clock/
* - NeroJTAG, a JTAG dongle: https://github.com/makestuff/neroJtag
* - NES Controller USB modification: http://projects.peterpolidoro.net/video/NESUSB.htm
* - Nikon wireless camera remote control (Norwegian): http://hekta.org/~hpe1119/
* - Opendous-JTAG, an open source ARM JTAG debugger: http://code.google.com/p/opendous-jtag/
* - Openkubus, an open source hardware-based authentication dongle: http://code.google.com/p/openkubus/
* - Orbee, a USB connected RGB Orb for notifications: http://www.franksworkshop.com.au/Electronics/Orbee/Orbee.htm
* - Programmable keyboard controller: http://41j.com/blog/2011/10/a-programmable-keyboard-controller/
* - Programmable XBOX controller: http://richard-burke.dyndns.org/wordpress/pan-galactic-gargantuan-gargle-brain-aka-xbox-360-usb-controller/
* - PSGroove, a Playstation 3 Homebrew dongle: http://github.com/psgroove
* - PS/2 to USB adapter: https://github.com/makestuff/p2ukbd
* - Reprap with LUFA, a LUFA powered 3D printer: http://code.google.com/p/at90usb1287-code-for-arduino-and-eclipse/
* - SD Card reader: http://elasticsheep.com/2010/04/teensy2-usb-mass-storage-with-an-sd-card/
* - SDR1, a Software Defined Radio firmware: https://code.google.com/p/sdr-mk1/
* - SEGA Megadrive/Genesis Development Cartridge: http://www.makestuff.eu/wordpress/?page_id=398
* - Serial Line bus analyser: http://www.pjrc.com/teensy/projects/SerialAnalyzer.html
* - Smartcard Detective: https://code.google.com/p/smartcarddetective/
* - SmartportVHD Apple II Mass Storage adapter: http://pcedric3.free.fr/SmartportVHD/
* - Single LED Matrix Display: http://guysoft.wordpress.com/2009/10/08/bumble-b/
* - Stripe Snoop, a Magnetic Card reader: http://www.ossguy.com/ss_usb/
* - Stylophone, with USB MIDI connectivity: http://www.waitingforfriday.com/index.php/Stylophone_Studio_5
* - Teensy SD Card .WAV file player: http://elasticsheep.com/2010/04/teensy2-usb-wav-player-part-1/
* - Touchscreen Input Device: http://capnstech.blogspot.com/2010/07/touchscreen-update.html
* - Universal USB AVR Module: http://usbavr.bplaced.net/
* - USB2AX, a USB to Dynamixel network adapter: http://paranoidstudio.assembla.com/wiki/show/paranoidstudio/USB2AX
* - USB Interface for Playstation Portable Devices: http://forums.ps2dev.org/viewtopic.php?t=11001
* - USB MIDI to DMX controller: http://github.com/hanshuebner/miDiMX
* - USB powered Geiger Counter: http://uhrheber.wordpress.com/2011/04/28/a-usb-powered-geiger-counter-for-the-z2-and-other-computers/
* - Userial, a USB to Serial converter with SPI, I2C and other protocols: http://www.tty1.net/userial/
* - Wireless MIDI Guitar system: http://www.ise.pw.edu.pl/~wzab/wireless_guitar_system/
* - Xnormidi, a C MIDI library: http://x37v.info/projects/xnormidi
* - XUM1541, a Commodore 64 floppy drive to USB adapter: http://www.root.org/~nate/c64/xum1541/
* - Zeus, a touch screen computer for music manipulation: http://www.benbengler.com/developments_zeus.html
*
* \section Sec_LUFACommercialProjects Projects Using LUFA (Commercial)
*
* The following is a list of known commercial products using LUFA. Some of these are open source, although many are "black-box"
* solutions with no source code given. Those companies which have purchased a Commercial License to LUFA (see \ref Page_LicenseInfo)
* are not listed here unless specifically requested.
*
* - Arduino Uno, the official Arduino board: http://www.arduino.cc
* - ARPS Locator: http://la3t.hamradio.no/lab//?id=tracker_en
* - CFFA3000, a CompactFlash interface for the Apple II: http://www.dreher.net/CFforAppleII
* - Digital Survey Instruments Magnetometer and Pointer: http://www.digitalsurveyinstruments.com/
* - FinchRobot, a robot designed for educational use: http://www.finchrobot.com/
* - Penguino, an Arduino Board With On-Board LUFA Powered Debugger/Programmer: http://wiki.icy.com.au/PenguinoAVR
* - PIR-1, an IR control interface for consumer electronics: http://www.promixis.com/pir-1.php
* - PIR-4, a USB Connected 4 port IR transmitter: http://promixis.com/pir-4.php
* - KeyGlove, an alternative input system: http://www.keyglove.net/
* - Many of Busware's Products: http://www.busware.de/
* - MIDIFighter, a USB-MIDI controller: http://www.midifighter.com/
* - Norduino, a wireless Arduino: http://norduino.robomotic.com/norduino-is-now-usb-hid/
* - Retrode, a USB Games Console Cartridge Reader: http://www.retrode.org
* - SmartCardDetective, a Smart Card analysis tool: http://www.smartcarddetective.com/
* - USBTINY-MKII, an AVRISP-MKII Clone AVR Programmer: http://tom-itx.dyndns.org:81/~webpage/boards/USBTiny_Mkii/USBTiny_Mkii_index.php
* - VMeter, a USB MIDI touch strip controller: http://www.vmeter.net/
* - XMEGA Development Board, using LUFA as an On-Board Programmer: http://xmega.mattair.net/
* - Zeptoprog, a multifunction AVR programmer: http://www.mattairtech.com/index.php/featured/zeptoprog.html
*
* \section Sec_LUFAPublications Publications Mentioning LUFA
* - Elektor Magazine, "My First AVR-USB" by Antoine Authier (feature), January 2010 Issue
* - Elektor Magazine, "USB is Cool/Sucks" by Jerry Jacobs and Chris Vossen (minor mention), January 2010 Issue
* - Elektor Magazine, "20 x Open Source" by Jens Nickel, March 2010 Issue
* - Circuit Cellar Magazine, "Advanced USB Design Debugging" by Collin O'Flynn, August 2010 Issue
*
* \section Sec_PortsAndForks Non-Official LUFA Ports and Forks
* - NXP's official "nxpusblib" LUFA fork, for LPC devices: http://www.lpcware.com/content/project/nxpusblib
* - Kevin Mehall's LUFA port to the NXP LPC13xx: https://github.com/kevinmehall/LUFA-LPC13xx
*
* \section Sec_LUFANotableMentions Other Notable Mentions of LUFA
* - Adafruit "Ask an Engineer", 7th November 2010
* - Arduino 2010 Keynote speech
* - The Amp Hour podcast blog #11
*/

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -0,0 +1,52 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/**
* \page Page_LUFAvsAtmelStack LUFA vs the Atmel 8-bit USB AVR Stack
*
* Atmel offers an official 8-bit USB AVR stack, which may be incorporated into user projects and products. As LUFA and the Atmel
* stack aims to give roughly the same functionality to a design, it is often asked what advantages LUFA carries over the official
* Atmel USB stack for the 8-bit USB AVRs. Below are just some of the advantages to choosing LUFA over the official Atmel stack.
*
* - <b>Licensing:</b>
* LUFA is released under a very permissive MIT license (see \ref Page_LicenseInfo), while the Atmel stack carries several
* restrictions as to how and where it can be used. LUFA's licensing should be suitable for both Commercial and Non-Commercial
* entities alike.
*
* - <b>Demos and Projects:</b>
* Unlike the Atmel stack, LUFA comes with many different Device and Host mode Demos and Projects ready to run out of the box.
* Atmel favors separate downloads for each of their (small set) of USB AVR demos, which requires more time and offers less
* to the end-user. LUFA also contains several open source Bootloaders, which can be modified as the user wishes to suit his or
* her application, instead of being forced to use Atmel's single prebuilt (closed-source) DFU bootloader.
*
* - <b>Central Library Code:</b>
* LUFA is designed to allow the central library core code to be shared amongst several projects, so long as the compiled object
* files are cleaned between different projects. This is in direct contrast to the Atmel library, which is strongly coupled to the
* project it is integrated with. Using LUFA allows for only one copy of the library core to be needed for all applications, and
* makes updating the library used in all projects a trivial copy-and-paste process.
*
* - <b>Clean API:</b>
* One of the main design goals of LUFA is to make the API easy to use. While LUFA is a fluid project which has undergone many
* API improvements, the API is arguably much nicer to use and easier to understand than the equivalent Atmel stack code. LUFA's
* API is also more complete than the Atmel stack, and contains many features to speed up application development.
*
* - <b>Full Hardware Support:</b>
* LUFA supports the full range of Atmel's USB AVR microcontrollers (see \ref Page_DeviceSupport), with porting between chips being
* as simple as a single compile switch in many cases. Atmel's stack requires different libraries to be used based on the USB AVR
* microcontroller series, complicating the process of moving between USB AVR models. In addition, LUFA contains drivers for all the
* hardware contained on Atmel's USB AVR based boards, so you can get started quickly and easily.
*
* - <b>Better Library Support:</b>
* As many people are now using LUFA, there is a community being built around it. You can get answers to your LUFA related questions
* quickly by either emailing the library author (subject to author's schedule) or by posting to the official LUFA support mailing list.
*
* - <b>More Compact Code:</b>
* LUFA is written from the ground up to compile optimally, using clean code and good design. Two demos giving the same functionality -
* the LUFA Low Level API Mouse Demo vs. the Atmel AVR270 HID Mouse application note shows LUFA to be the clear size winner *.
*
* * <i>LUFA Low Level Mouse Demo: 3510 bytes, Atmel AVR270 Mouse Application Note: 4222 bytes, using an identical build environment.</i>
*/

View File

@ -0,0 +1,128 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** \page Page_LibraryApps Included Library Applications
*
* The LUFA library ships with several different host and device demos, located in the /Demos/ subdirectory. Within this
* directory the demos are separated by USB mode (Device, Host, OTG) and further separated by the use or non-use of the
* library USB Class drivers (which abstract out the actual implementation of the USB classes to simplify development even
* further at the expense of a loss of flexibility).
*
* With one or two exceptions (e.g. proprietary classes such as RNDIS) all the included demos will work across all OSes without
* the need for special drivers. On Windows, some demos require the supplied .INF file to be used as the device driver, which
* directs the OS to use its inbuilt class drivers for the device.
*
* Also included with the library are two fully functional bootloaders, located in the /Bootloaders/ subdirectory.
* The DFU class bootloader is compatible with Atmel's FLIP software or the open source dfu-programmer project, while
* the CDC class (AVR109 protocol) is compatible with such open source software as AVRDUDE and AVR-OSP.
*
* User-submitted projects are located in the /Projects/ subdirectory. If you wish to have your LUFA project included,
* please email it to the Library author.
*
* \section Sec_AppOverview Overview of Included Library Applications
* The following shows the folder structure of the included library applications, including demos, bootloaders and user-submitted
* open source projects.
*
* <small>
*
* - <b>Demos</b>
* - <b>Device</b>
* - <b>ClassDriver</b>
* - <b>AudioInput</b> - Audio In (microphone) demo, using the library USB Audio Class driver framework
* - <b>AudioOutput</b> - Audio Out (speaker) demo, using the library USB Audio Class driver framework
* - <b>DualVirtualSerial</b> - Dual Virtual Serial Port demo, using the library USB CDC Class driver framework
* - <b>GenericHID</b> - Generic Human Interface Class demo, using the library USB HID Class driver framework
* - <b>Joystick</b> - USB Joystick demo, using the library USB HID Class driver framework
* - <b>Keyboard</b> - USB Keyboard demo, using the library USB HID Class driver framework
* - <b>KeyboardMouse</b> - Dual Keyboard/Mouse demo, using the library USB HID Class driver framework
* - <b>KeyboardMouseMultiReport</b> - Multi HID report Keyboard/Mouse demo, using the library USB HID Class driver framework
* - <b>MassStorage</b> - Dual Drive Mass Storage demo, using the library USB Mass Storage Class driver framework
* - <b>MassStorageKeyboard</b> - Mass Storage and Keyboard demo, using the library USB Mass Storage/HID Class driver frameworks
* - <b>MIDI</b> - MIDI In demo, using the library USB MIDI-Audio Class driver framework
* - <b>Mouse</b> - USB Mouse demo, using the library USB HID driver framework
* - <b>RNDISEthernet</b> - RNDIS Ethernet Webserver demo, using the library USB RNDIS driver framework
* - <b>VirtualSerial</b> - Virtual Serial Port demo, using the library USB CDC Class driver framework
* - <b>VirtualSerialMassStorage</b> - Virtual Serial Port and Mass Storage demo, using the library USB CDC and Mass Storage Class driver frameworks
* - <b>VirtualSerialMouse</b> - Virtual Serial Port and Mouse demo, using the library USB CDC and HID Class driver frameworks
* - <b>LowLevel</b>
* - <b>AudioInput</b> - Audio In (microphone) demo, using the low level LUFA APIs to implement the USB Audio class
* - <b>AudioOutput</b> - Audio Out (speaker) demo, using the low level LUFA APIs to implement the USB Audio class
* - <b>DualVirtualSerial</b> - Dual Virtual Serial Port demo, using the low level LUFA APIs to implement the USB CDC class
* - <b>GenericHID</b> - Generic Human Interface Class demo, using the low level LUFA APIs to implement the USB HID class
* - <b>Joystick</b> - USB Joystick demo, using the low level LUFA APIs to implement the USB HID class
* - <b>Keyboard</b> - USB Keyboard demo, using the low level LUFA APIs to implement the USB HID class
* - <b>KeyboardMouse</b> - Dual Keyboard/Mouse demo, using the low level LUFA APIs to implement the USB HID class
* - <b>MassStorage</b> - Dual Drive Mass Storage demo, using the low level LUFA APIs to implement the USB Mass Storage class
* - <b>MIDI</b> - MIDI In demo, using the low level LUFA APIs to implement the USB MIDI-Audio class
* - <b>Mouse</b> - USB Mouse demo, using the low level LUFA APIs to implement the USB HID class
* - <b>RNDISEthernet</b> - RNDIS Ethernet Webserver demo, using the low level LUFA APIs to implement the USB RNDIS class
* - <b>VirtualSerial</b> - Virtual Serial Port demo, using the low level LUFA APIs to implement the USB CDC class
* - <b>Incomplete</b>
* - <b>SideShow</b> - Incomplete Windows SideShow demo, using the low level LUFA APIs to implement the USB SideShow class
* - <b>TestAndMeasurement</b> - Incomplete Test and Measurement demo, using the low level LUFA APIs to implement the USB Test and
* Measurement class
* - <b>Host</b>
* - <b>ClassDriver</b>
* - <b>AndroidAccessoryHost</b> - Android Accessory host demo, using the library USB Android Open Accessory Class driver framework
* - <b>AudioInputHost</b> - Audio Input host demo, using the library USB Audio Class driver framework
* - <b>AudioOutputHost</b> - Audio Output host demo, using the library USB Audio Class driver framework
* - <b>JoystickHostWithParser</b> - Joystick host demo with HID Descriptor parser, using the library USB HID Class driver framework
* - <b>KeyboardHost</b> - USB Keyboard host demo, using the library USB HID Class driver framework
* - <b>KeyboardHostWithParser</b> - USB Keyboard host demo with HID Descriptor parser, using the library USB HID Class
* driver framework
* - <b>MassStorageHost</b> - Mass Storage host demo, using the library USB Mass Storage Class driver framework
* - <b>MouseHost</b> - Mouse host demo, using the library USB HID Class driver framework
* - <b>MouseHostWithParser</b> - Mouse host demo with HID Descriptor parser, using the library USB HID Class driver framework
* - <b>RNDISHost</b> - RNDIS Ethernet host demo, using the library USB RNDIS Class driver framework
* - <b>StillImageHost</b> - Still Image Camera host demo, using the library USB Still Image Class driver framework
* - <b>VirtualSerialHost</b> - Virtual Serial Port host demo, using the library USB CDC Class driver framework
* - <b>LowLevel</b>
* - <b>AndroidAccessoryHost</b> - Android Accessory host demo, using the low level LUFA APIs to implement the Android Open Accessory class
* - <b>AudioInputHost</b> - Audio Input host demo, using the low level LUFA APIs to implement the USB Audio class
* - <b>AudioOutputHost</b> - Audio Output host demo, using the low level LUFA APIs to implement the USB Audio class
* - <b>GenericHIDHost</b> - Generic HID host demo, using the low level LUFA APIs to implement the USB HID class
* - <b>JoystickHostWithParser</b> - Joystick host demo with HID Descriptor parser, using the low level LUFA APIs to implement
* the USB HID class
* - <b>KeyboardHost</b> - USB Keyboard host demo, using the low level LUFA APIs to implement the USB HID class
* - <b>KeyboardHostWithParser</b> - USB Keyboard host demo with HID Descriptor parser, using the low level LUFA APIs to
* implement the USB HID class
* - <b>MassStorageHost</b> - Mass Storage host demo, using the low level LUFA APIs to implement the USB Mass Storage class
* - <b>MouseHost</b> - Mouse host demo, using the low level LUFA APIs to implement the USB HID class
* - <b>MouseHostWithParser</b> - Mouse host demo with HID Descriptor parser, using the low level LUFA APIs to implement the
* USB HID class
* - <b>PrinterHost</b> - Printer host demo, using the low level LUFA APIs to implement the USB Printer class
* - <b>RNDISHost</b> - RNDIS Ethernet host demo, using the low level LUFA APIs to implement the RNDIS class
* - <b>StillImageHost</b> - Still Image Camera host demo, using the low level LUFA APIs to implement the USB Still Image class
* - <b>VirtualSerialHost</b> - Virtual Serial Port host demo, using the low level LUFA APIs to implement the USB CDC class
* - <b>Incomplete</b>
* - <b>BluetoothHost</b> - Incomplete Bluetooth host demo, using the low level LUFA APIs to implement the USB Bluetooth class
* - <b>DualRole</b>
* - <b>ClassDriver</b>
* - <b>MouseHostDevice</b> - Dual role Mouse Host and Mouse Device demo, using the library USB CDC Class driver framework
* - <b>Bootloaders</b>
* - <b>CDC</b> - CDC Class USB bootloader, compatible with any AVR910 protocol programming software such as AVRDude
* - <b>DFU</b> - DFU Class USB bootloader, compatible with Atmel's FLIP and the open source dfu-programmer software
* - <b>HID</b> - HID Class USB bootloader, compatible with a modified PJRC TeensyHID protocol loader application software
* - <b>Projects</b>
* - <b>AVRISP-MKII</b> - AVRISP-MKII Programmer Clone project
* - <b>Benito</b> - Benito Board Arduino Programmer project
* - <b>HIDReportViewer</b> - HID Device Report Viewer project
* - <b>LEDNotifier</b> - USB LED Notification project
* - <b>Magstripe</b> - Magnetic Stripe Card Reader project
* - <b>MediaController</b> - Media Playback Controller project
* - <b>MIDIToneGenerator</b> - MIDI Note Tone Generator project
* - <b>MissileLaucher</b> - Toy Missile Launcher Host project
* - <b>RelayBoard</b> - Relay board controller, controllable via the "sismpctl" Linux application
* - <b>TempDataLogger</b> - Temperature Datalogging project, using the FatFS library
* - <b>USBtoSerial</b> - USB to USART Serial Converter project
* - <b>Webserver</b> - RNDIS Host Webserver with DHCP client, powered by uIP TCP/IP stack project and FatFS library
* - <b>XPLAINBridge</b> - XPLAIN alternative PDI Programmer/USB to Serial Bridge firmware project
* - <b>Incomplete</b>
* - <b>StandaloneProgrammer</b> - Incomplete Standalone AVR Programmer application, to program AVRs directly from a Mass Storage disk
*
* </small>
*/

View File

@ -0,0 +1,33 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/**
* \page Page_Resources Library Resources
*
* \section Sec_UnofficialResources Unofficial Resources
* Unofficial Russian LUFA documentation translation: http://microsin.ru/Download.cnt/doc/LUFA/ \n
*
* \section Sec_ProjectPages LUFA Related Webpages
* Project Homepage: http://www.lufa-lib.org \n
* Commercial Licenses: http://www.lufa-lib.org/license \n
* Author's Website: http://www.fourwalledcubicle.com \n
* Development Blog: http://www.fourwalledcubicle.com/blog \n
*
* \section Sec_ProjectHelp Assistance With LUFA
* Discussion Group: http://www.lufa-lib.org/support \n
* Author's Email: dean [at] fourwalledcubicle [dot] com \n
*
* \section Sec_InDevelopment Latest In-Development Source Code
* Issue Tracker: http://www.lufa-lib.org/tracker \n
* SVN Access: http://www.lufa-lib.org/svn \n
* GIT Access: http://www.lufa-lib.org/git \n
* Latest Repository Source Archive: http://www.lufa-lib.org/latest-archive \n
* Commit RSS Feed: http://www.lufa-lib.org/rss \n
*
* \section Sec_USBResources USB Resources
* USB-IF Website: http://www.usb.org \n
*/

View File

@ -0,0 +1,22 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/**
* \page Page_LicenseInfo Source Code License
*
* The LUFA library is currently released under the MIT license, included below.
*
* Commercial entities can opt out of the public disclosure clause in this license
* for a one-time US$1500 payment. This provides a non-exclusive modified MIT licensed which
* allows for the free use of the LUFA library, bootloaders and (where the sole copyright
* is attributed to Dean Camera) demos without public disclosure within an organization, in
* addition to three free hours of consultation with the library author, and priority support.
* Please visit the Commercial License link on \ref Page_Resources for more information on
* ordering a commercial license for your company.
*
* \verbinclude License.txt
*/

View File

@ -0,0 +1,48 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/**
* \mainpage
*
* \image html LUFA.png
* <div align="center"><small><i>Logo design by <a href="http://www.studiomonsoon.com">Studio Monsoon Photography</a></i></small></div>
* \n
* <div align="center"><a href="http://www.lufa-lib.org">http://www.lufa-lib.org</a></div>
* \n
*
* <b>LUFA is donationware. For author and donation information, see \ref Page_Donating.</b>
*
* LUFA is an open-source USB library for the USB-enabled AVR microcontrollers, released under the MIT license (see \ref Page_LicenseInfo).
* It supports a large number of USB AVR models and boards (see \ref Page_DeviceSupport). It is designed to provide an easy to use,
* feature rich framework for the development of USB peripherals and hosts.
*
* LUFA focuses on the microcontroller side of USB development only; it includes no PC host USB driver development facilities - other projects
* such as the Windows Driver Development Kit, Windows USB Device Mode Framework and libusb may be of interest for developing custom OS drivers.
* While custom USB devices can be made with LUFA using such tools, the included demos all use the inbuilt OS drivers for each USB class for
* simplicity.
*
* The library is currently in a stable release, suitable for download and incorporation into user projects for
* both host and device modes. For information about the project progression, see the blog link at \ref Page_Resources.
*
* LUFA is written specifically for the free AVR-GCC compiler, and uses several GCC-only extensions to make the
* library API more streamlined and robust. You can download AVR-GCC for free in a convenient windows package,
* from the the WinAVR website (see \ref Page_Resources).
*
* The only required AVR peripherals for LUFA is the USB controller itself and interrupts - LUFA does not require the use of the
* microcontroller's timers or other hardware, leaving more hardware to the application developer.
*
* Accompanying LUFA in the download package is a set of example demo applications, plus several Bootloaders of different classes
* and open source LUFA powered projects.
*
* <b>Subsections:</b>
* \li \subpage Page_WhyUseLUFA - What are the advantages of using LUFA?
* \li \subpage Page_LUFAvsAtmelStack - How does LUFA compare to the Atmel USB AVR stack?
* \li \subpage Page_AlternativeStacks - Alternative USB AVR Stacks
* \li \subpage Page_LicenseInfo - Project source license and commercial use information
* \li \subpage Page_Donating - Donating to support this project
* \li \subpage Page_LibraryApps - Overview of included Demos, Bootloaders and Projects
*/

View File

@ -0,0 +1,628 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** \page Page_Migration Migrating from Older Versions
*
* Below is migration information for updating existing projects based on previous versions of the LUFA library
* to the next version released. It does not indicate all new additions to the library in each version change, only
* areas relevant to making older projects compatible with the API changes of each new release.
*
* \section Sec_MigrationXXXXXX Migrating from 111009 to XXXXXX
* <b>USB Core</b>
* - The HID_KEYBOARD_MODIFER_* macros in the HID class driver have been corrected to HID_KEYBOARD_MODIFIER_* (note the spelling of "modifier").
* Existing applications should switch over to the correctly spelled macro names.
* - The names of the USB Device and USB Host class driver files have changed; a new "ClassDevice" and "ClassHost" postfix has been added to the
* respective class driver files. Projects referencing the class driver source files by filename rather than the LUFA_SRC_USBCLASS makefile
* variable should append these postfixes to the source file names. Projects including the USB class driver dispatch headers directly should either
* switch to including the main USB driver header instead, or use the updated header filenames.
*
* \section Sec_Migration111009 Migrating from 110528 to 111009
* <b>Non-USB Library Components</b>
* - The \c JTAG_DEBUG_ASSERT() macro has been renamed \ref JTAG_ASSERT() to be consistent with \ref STDOUT_ASSERT().
*
* <b>USB Core</b>
* - By default, unordered Endpoint and Pipe configuration is now allowed once again, via the previous workaround of
* reconfiguring all Endpoints/Pipes in order each time a new Endpoint/Pipe is created. To minimize the compiled program
* size, the new \c ORDERED_EP_CONFIG compile time option may be defined in the project makefile to restrict the ordering
* in exchange for a smaller compiled binary size.
* - The previous \c F_CLOCK symbol, required in the project makefile, has been renamed to \c F_USB. This is due to the previous name
* being far too generic for use in future architecture ports, where multiple clock domains are used.
*
* <b>Device Mode</b>
* - The Endpoint stream functions now all require a \c BytesProcessed parameter instead of the previous callback parameter.
* This should be set to \c NULL to retain previous behaviour of the functions, or point to a location where the number of bytes
* processed in the current transaction can be stored. If the \c BytesProcessed parameter is non \c NULL, each time the endpoint
* bank becomes full and the packet is sent, the routine will exit with the new \ref ENDPOINT_RWSTREAM_IncompleteTransfer
* error code to allow the user application to determine when to send the next chunk of data.
* - The \ref CDC_Device_SendString() function now expects a null terminated string instead of an explicit length. Existing code
* should use the new \ref CDC_Device_SendData() function, or remove the length parameter from the function call.
* - The \c Endpoint_ResetFIFO() function has been renamed to \ref Endpoint_ResetEndpoint(), to make the API function names more
* consistent. Existing applications using the old function name should simply replace it with a call to the new function name.
* - The \c Endpoint_*_Byte() functions have been renamed Endpoint_*_8() to ensure they are correct across all architectures. Existing
* code using these functions should replace the previous function names with the new function names.
* - The \c Endpoint_*_Word() functions have been renamed Endpoint_*_16() to ensure they are correct across all architectures. Existing
* code using these functions should replace the previous function names with the new function names.
* - The \c Endpoint_*_DWord() functions have been renamed Endpoint_*_32() to ensure they are correct across all architectures. Existing
* code using these functions should replace the previous function names with the new function names.
* - The Device mode RNDIS class driver no longer stores the incoming and outgoing packets in the class driver instance; the user is
* now expected to manually define a storage location for the packet data. Packets must now be sent and received manually via a call
* to \ref RNDIS_Device_ReadPacket() and/or \ref RNDIS_Device_SendPacket().
* - The definition of the Audio class \ref USB_Audio_Descriptor_Format_t has been altered, to remove the fixed singular
* audio sample rate in the descriptor definition, and to rename the \c SampleFrequencyType to the more appropriate
* \c TotalDiscreteSampleRates. Existing applications will need to add an array of \ref USB_Audio_SampleFreq_t elements
* immediately following any \ref USB_Audio_Descriptor_Format_t descriptors, and insert the appropriate sampling rates
* supported by the device, as well as rename the descriptor elements to match the updated element names.
* - The device mode Audio class driver now requires a new user application callback, \ref CALLBACK_Audio_Device_GetSetEndpointProperty().
* Existing applications must implement this new callback, however if multiple sample rates or pitch control is not used,
* this function may be hard-coded to always return false for previous behaviour to be retained.
* - The \c USB_ConfigurationNumber, \c USB_RemoteWakeupEnabled and \c USB_CurrentlySelfPowered globals have been renamed to
* \ref USB_Device_ConfigurationNumber, \ref USB_Device_RemoteWakeupEnabled and \ref USB_Device_CurrentlySelfPowered to clearly indicate
* the USB mode they relate to. Existing applications using these variables should rename all references to the previous names.
* - The \c ENDPOINT_DESCRIPTOR_DIR_IN and \c ENDPOINT_DESCRIPTOR_DIR_OUT macros have now been replaced by \ref ENDPOINT_DIR_IN and
* \ref ENDPOINT_DIR_OUT to improve code clarity.
* - The \ref HID_DESCRIPTOR_JOYSTICK() macro now takes an additional (first) parameter indicating the number of axis in the joystick.
*
* <b>Host Mode</b>
* - The Pipe stream functions now all require a \c BytesProcessed parameter instead of the previous callback parameter.
* This should be set to \c NULL to retain previous behaviour of the functions, or point to a location where the number of bytes
* processed in the current transaction can be stored. If the BytesProcessed parameter is non \c NULL, each time the pipe
* bank becomes full and the packet is sent, the routine will exit with the new \ref PIPE_RWSTREAM_IncompleteTransfer
* error code to allow the user application to determine when to send the next chunk of data.
* - The \ref PRNT_Host_SendString() and \ref CDC_Host_SendString() functions now expect a null terminated string instead of an explicit
* length. Existing code should use the new \ref PRNT_Host_SendData() and \ref CDC_Host_SendData() functions, or remove the
* length parameter from the function call.
* - The \c Pipe_ClearErrorFlags() function has been removed, as the pipe error flags are now automatically cleared when the
* \ref Pipe_ClearError() function is called.
* - The \c Pipe_*_Byte() functions have been renamed Pipe_*_8() to ensure they are correct across all architectures. Existing code using
* these functions should replace the previous function names with the new function names.
* - The \c Pipe_*_Word() functions have been renamed Pipe_*_16() to ensure they are correct across all architectures. Existing code using
* these functions should replace the previous function names with the new function names.
* - The \c Pipe_*_DWord() functions have been renamed Pipe_*_32() to ensure they are correct across all architectures. Existing code using
* these functions should replace the previous function names with the new function names.
* - The \c USB_Host_ClearPipeStall() function has been renamed to USB_Host_ClearEndpointStall(), as it operates on a full endpoing address
* within the attached device and not a pipe within the host. Existing code using the old function name should update the function calls and
* check for correct usage.
*
* \section Sec_Migration101122 Migrating from 100807 to 101122
* <b>USB Core</b>
* - A new USB driver source file, \c Drivers/USB/HighLevel/EndpointStream.c now exists. This source file should be added
* to all project makefiles using the USB driver of LUFA, or the makefile should be updated to use the new module source
* variables.
* - A new USB driver source file, \c Drivers/USB/HighLevel/PipeStream.c now exists. This source file should be added to all
* project makefiles using the USB driver of LUFA, or the makefile should be updated to use the new module source variables.
* - The \c EVENT_USB_InitFailure() event has been removed, as the \ref USB_Init() function will no longer fail; if not USB mode is
* specified, the controller will default to UID selection mode.
* - The USB mode specifier constants have been moved into a new enum and renamed. Existing projects should use the equivalent
* value in the new \ref USB_Modes_t enum.
* - All class driver headers are now included as part of the standard \c LUFA/Drivers/USB/USB.h master dispatch header, and should
* no longer be included separately. Class driver module source files must still be added as a separate module in the project's
* makefile if used.
*
* <b>Device Mode</b>
* - Endpoints MUST be allocated in ascending order to ensure that bank corruption does not occur. Ensure that your user application
* allocated endpoints in ascending order - or if your application uses the USB device mode class drivers, ensure that each instance's
* endpoint indexes are not overlapped with other interface's endpoints.
* - The signature for the \ref CALLBACK_USB_GetDescriptor() callback has changed, the \c void** \c const \c DescriptorAddress parameter is
* now \c const \c void** \c const \c DescriptorAddress. Existing applications should update their callback signatures to match this, and
* eliminate any casting of descriptor pointers to a non \c const pointer.
* - The names of the class specific descriptor type defines in the USB Class drivers have changed - refer to the driver documentation
* for each class driver for the new class specific descriptor type names.
* - The \c ENDPOINT_DOUBLEBANK_SUPPORTED() macro is has been renamed \ref ENDPOINT_BANKS_SUPPORTED() and now returns the total number of
* banks supported by the given endpoint. Existing code should switch to the new naming scheme, and test that the return value of the
* macro is equal to or greater than 2 to regain the previous functionality.
* - The \c EVENT_USB_Device_UnhandledControlRequest() event is now named \ref EVENT_USB_Device_ControlRequest() and fires before (not after)
* the internal library event handlers. Existing code should rename the event handlers in the user application to match the new event
* name, and should ensure that the new execution order does not affect the application's operation.
*
* <b>Host Mode</b>
* - Pipes MUST be allocated in ascending order to ensure that bank corruption does not occur. Ensure that your user application
* allocated pipes in ascending order - or if your application uses the USB host mode class drivers, ensure that each instance's
* pipe indexes are not overlapped with other interface's pipes.
* - The \c PRNT_Host_SendData() function has been renamed to \ref PRNT_Host_SendString(). Existing applications should simply
* replace all references to the obsolete function name with the new function name.
* - The names of the class specific descriptor type defines in the USB Class drivers have changed - refer to the driver documentation
* for each class driver for the new class specific descriptor type names.
* - The Still Image Host class' function prefix has been changed from \c SImage_ to \c SI_, to remain consistent with the rest of the
* driver's enums, type defines and constants.
*
* \section Sec_Migration100807 Migrating from 100513 to 100807
*
* <b>Non-USB Library Components</b>
* - The Dataflash board driver stub file has changed, as dataflash functions previously located in the internal
* Dataflash driver of the library have now been moved to the individual board files. Existing drivers can
* copy-paste the new functions from the board Dataflash stub driver.
*
* <b>USB Core</b>
* - A new USB driver source file, \c Drivers/USB/LowLevel/Device.c now exists. This source file should be added to all project
* makefiles using the USB driver of LUFA, or the makefile should be updated to use the new module source variables.
* - The \c Drivers/USB/LowLevel/DevChapter9.c source file has moved to \c Drivers/USB/HighLevel/DeviceStandardReq.c - this should
* be updated in all project makefiles, or the makefile should be updated to use the new module source variables.
* - The \c Drivers/USB/LowLevel/HostChapter9.h source file has moved to \c Drivers/USB/HighLevel/HostStandardReq.c - this should
* be updated in all project makefiles, or the makefile should be updated to use the new module source variables.
* - The \c Drivers/USB/LowLevel/LowLevel.c source file has moved to \c Drivers/LowLevel/USBController.c - this should be updated
* in all project makefiles, or the makefile should be updated to use the new module source variables.
*
* <b>Device Mode</b>
* - The \c USB_Device_IsRemoteWakeupSent() macro has been removed, as the remote wakeup request is now fully handled by the
* enhanced \ref USB_Device_SendRemoteWakeup() function. Existing code may now discard any checks to \c USB_Device_IsRemoteWakeupSent().
* - The \c USB_Device_IsUSBSuspended() macro has been removed, as it is obsolete. Existing code should compare \ref USB_DeviceState
* to see if it the device is in the \ref DEVICE_STATE_Suspended state instead.
* - The \ref CDC_Device_ReceiveByte() function has changed, and now returns a signed 16-bit integer, with -1 indicating no data was
* received. This allows for more efficient coding, as a call to \ref CDC_Device_BytesReceived() is no longer needed if the exact
* number of queued bytes received is not needed.
*
* <b>Host Mode</b>
* - The \ref CDC_Host_ReceiveByte() function has changed, and now returns a signed 16-bit integer, with -1 indicating no data was
* received. This allows for more efficient coding, as a call to \ref CDC_Host_BytesReceived() is no longer needed if the exact
* number of queued bytes received is not needed.
* - The \ref CDC_Host_USBTask() now calls \ref CDC_Host_Flush() automatically, flushing any queued data to the attached device. Manual
* flushing of the interface is no longer needed if the flushes should be in sync with calls to \ref CDC_Host_USBTask().
*
* \section Sec_Migration100513 Migrating from 100219 to 100513
*
* <b>Non-USB Library Components</b>
* - The \ref TWI_StartTransmission() function now takes in a timeout period, expressed in milliseconds, within which the addressed
* device must respond or the function will abort.
*
* <b>Device Mode</b>
* - The \ref USB_Init() function no longer calls \c sei() to enable global interrupts, as the user application may need
* to perform other initialization before it is ready to handle global interrupts. The user application is now responsible
* for enabling global interrupts before or shortly after calling \ref USB_Init() to ensure that the enumeration process
* functions correctly.
* - The \c USBInterrupt.c USB driver source file has been relocated from \c LUFA/Drivers/USB/HighLevel/ to \c LUFA/Drivers/USB/LowLevel.
* Projects must update their makefile SRC values accordingly.
* - The HID Device Class driver's function signature for the \ref CALLBACK_HID_Device_ProcessHIDReport() function has been changed, to
* allow for a new \c ReportType parameter. This new parameter must be added in all user applications using the Device mode HID Class
* Driver, but may be ignored unless Host-to-Device FEATURE HID reports are used.
*
* <b>Host Mode</b>
* - The \ref USB_Init() function no longer calls \c sei() to enable global interrupts, as the user application may need
* to perform other initialization before it is ready to handle global interrupts. The user application is now responsible
* for enabling global interrupts before or shortly after calling \ref USB_Init() to ensure that the enumeration process
* functions correctly.
* - The \c USBInterrupt.c USB driver source file has been relocated from \c LUFA/Drivers/USB/HighLevel/ to \c LUFA/Drivers/USB/LowLevel.
* Projects must update their makefile \c SRC values accordingly.
* - The HID Host Class driver's function signature for the \ref HID_Host_SendReportByID() function has been changed, to allow for a new
* ReportType parameter. Existing calls to this function should substitute \c REPORT_ITEM_TYPE_Out as this parameter's value.
*
* \section Sec_Migration100219 Migrating from 091223 to 100219
*
* <b>Non-USB Library Components</b>
* - Due to some ADC channels not being identical to their ADC MUX selection masks for single-ended conversions on some AVR models,
* the ADC driver now has explicit masks for each of the standard ADC channels (see \ref Group_ADC). These masks should be used
* when calling the ADC functions to ensure proper operation across all AVR models. Note that the \ref ADC_SetupChannel() function
* is an exception, and should always be called with a channel number rather than a channel mask.
*
* <b>Host Mode</b>
* - The MIDI Host Class driver send and receive routines now operate on packed events, where multiple MIDI events may be
* packed into a single USB packet. This means that the sending of MIDI events will now be delayed until the MIDI send
* pipe bank is full. To override this new behaviour and revert to the previous behaviour, the user application may manually
* flush the queued event(s) to the device by calling \ref MIDI_Host_Flush().
* - The \ref Pipe_IsEndpointBound() function now takes the endpoint's direction into account, by checking if the MSB of the endpoint's address
* is set to denote IN endpoints. If the previous functionality where the direction is to be discounted is required, mask the endpoint
* address against the \ref PIPE_EPNUM_MASK token before calling \ref Pipe_IsEndpointBound().
*
* <b>Device Mode</b>
* - The MIDI Device Class driver send and receive routines now operate on packed events, where multiple MIDI events may be
* packed into a single USB packet. This means that the sending of MIDI events will now be delayed until the MIDI send
* endpoint bank is full. To override this new behaviour and revert to the previous behaviour, the user application may manually
* flush the queued event(s) to the host by calling \ref MIDI_Device_Flush().
*
* \section Sec_Migration091223 Migrating from 091122 to 091223
*
* <b>Host Mode</b>
* - The Still Image Host Class driver \ref SI_Host_USBTask() and \ref SI_Host_ConfigurePipes() functions were misnamed, and are
* now named \c SImage_Host_USBTask() and \c SImage_Host_ConfigurePipes() respectively.
* - The \c HOST_SENDCONTROL_DeviceDisconnect enum value has been renamed to \ref HOST_SENDCONTROL_DeviceDisconnected to be in
* line with the rest of the library error codes.
* - The HID Parser item usages no longer contain separate minimum and maximum values, as this was a violation of the HID
* specification. Instead, the values are distributed evenly across each item as its usage value, to ensure that all items
* can be distinguished from one-another.
*
* <b>Device Mode</b>
* - The \ref CALLBACK_HID_Device_CreateHIDReport() HID Device Class driver callback now has a new \c ReportType parameter to
* indicate the report type to generate. Existing applications may simply add and ignore this additional parameter.
*
* \section Sec_Migration091122 Migrating from 090924 to 091122
*
* <b>Host Mode</b>
* - The \c HID_PARSE_UsageStackOverflow HID parser error constant is now named \ref HID_PARSE_UsageListOverflow
* - The \ref CALLBACK_HIDParser_FilterHIDReportItem() HID Parser callback now passes a complete \ref HID_ReportItem_t to the
* user application, instead of just its attributes.
* - The \c USB_GetDeviceConfigDescriptor() function was incorrectly named and is now called \ref USB_Host_GetDeviceConfigDescriptor().
*
* \section Sec_Migration090924 Migrating from 090810 to 090924
*
* <b>Non-USB Library Components</b>
* - The \c ADC_Off() function has been renamed to \c ADC_ShutDown() to be consistent with the rest of the library.
* - The \ref SPI_Init() routine's parameters have changed, so that the clock polarity and data sampling modes can be set. See
* the \ref SPI_Init() function documentation for more details
* - The \ref Dataflash_Init() routine no longer initializes the SPI bus - the SPI bus should be initialized manually via a
* call to \ref SPI_Init() before using the Dataflash driver
*
* <b>Host Mode</b>
* - The \c USB_GetDeviceConfigDescriptor() function's parameters and behaviour has changed; the user is required to
* preallocate the largest allowable buffer, and pass the size of the buffer to the function. This allows for a single
* call to the function to retrieve, size check and validate the Configuration Descriptor rather than having the user
* application perform these intermediary steps.
* - The HID report parser now requires a mandatory callback in the user code, to filter only the items the application
* is interested in into the processed HID report item structure to save RAM. See \ref CALLBACK_HIDParser_FilterHIDReportItem().
* - The HID report parser now always parses FEATURE and always ignores constant-data items - the \c HID_ENABLE_FEATURE_PROCESSING
* and \c HID_INCLUDE_CONSTANT_DATA_ITEMS compile time tokens now have no effect.
* - The \c USE_NONSTANDARD_DESCRIPTOR_NAMES compile time token has been removed - there are now separate \c USB_Descriptor_*
* and \c USB_StdDescriptor_* structures for both the LUFA and standardized element naming conventions so that both may be used in
* the one project. For existing projects using the standardized names, change all code to use the \c USB_StdDescriptor_* variants.
*
* <b>Device Mode</b>
* - The \c USE_NONSTANDARD_DESCRIPTOR_NAMES compile time token has been removed - there are now separate \c USB_Descriptor_*
* and \c USB_StdDescriptor_* structures for both the LUFA and standardized element naming conventions so that both may be used in
* the one project. For existing projects using the standardized names, change all code to use the \c USB_StdDescriptor_* variants.
*
* \section Sec_Migration090810 Migrating from 090605 to 090810
*
* <b>All</b>
* - The "Simple Scheduler" has been <i>deprecated</i>, as it was little more than an abstracted loop and caused much confusion.
* User applications using the scheduler should switch to regular loops instead. The scheduler code will be removed in a future
* release.
* - The "Dynamic Memory Block Allocator" has been removed, as it was unused in (and unrelated to) the LUFA library and never
* used in user applications.
*
* <b>Non-USB Library Components</b>
* - The \c ATTR_NOINLINE function attribute macro has been renamed to \ref ATTR_NO_INLINE to be in line with the rest of the function attribute
* macro names.
*
* <b>Library Demos</b>
* - Most demos now have a corresponding Class Driver implementation, which uses the new internal library class drivers for the standard
* USB classes. This allows for more rapid device and host development, and so should be used in preference to the low level APIs where
* possible so that fixes to the class drivers propagate to all applications which use them automatically with each new LUFA release.
*
* <b>Host Mode</b>
* - The \c HIDParser.c module has moved from \c LUFA/Drivers/USB/Class/ to \c LUFA/Drivers/USB/Class/Host/.
* - The \c USB_GetDeviceConfigDescriptor() function now requires the desired configuration index within the device as its first
* parameter, to add support for multi-configuration devices. Existing code should use a configuration index of 1 to indicate the
* first configuration descriptor within the device.
* - The non-standard "Ready" host state has been removed. Existing \ref HOST_STATE_Configured code should be moved to the end of
* the existing \ref HOST_STATE_Addressed state, and the existing HOST_STATE_Ready state code should be moved to the \ref HOST_STATE_Configured
* state.
* - The \c USB_IsConnected global has been removed, as it is too vague for general use. Test \ref USB_HostState explicitly to ensure the host is
* in the desired state instead.
* - The USB event names have been changed and their firing conditions changed to properly separate out Host mode events from Device mode
* events. See the \ref Group_Events page for details on the new event names and firing conditions.
*
* <b>Device Mode</b>
* - The \ref CALLBACK_USB_GetDescriptor() function now takes an extra parameter to specify the descriptor's memory space so that
* descriptors in mixed memory spaces can be used. The previous functionality can be returned by defining the \c USE_FLASH_DESCRIPTORS
* token in the project makefile to fix all descriptors into FLASH space and remove the extra function parameter.
* - The \c USB_IsSuspended global has been removed - test \ref USB_DeviceState against \ref DEVICE_STATE_Suspended instead.
* - The \c USB_IsConnected global has been removed, as it is too vague for general use. Test \ref USB_DeviceState explicitly to ensure the device
* is in the desired state instead.
* - The VBUS events have been removed, as they are already exposed to the user via the \c USB_Connect and \c USB_Disconnect events.
* - The USB event names have been changed and their firing conditions changed to properly separate out Host mode events from Device mode
* events. See the \ref Group_Events page for details on the new event names and firing conditions.
*
* \section Sec_Migration090605 Migrating from 090510 to 090605
*
* <b>Device Mode</b>
* - Support for non-control data endpoint interrupts has been dropped due to many issues in the implementation. All existing
* projects using interrupts on non-control endpoints should switch to polling. For control interrupts, the library can
* manage the control endpoint via interrupts automatically by compiling with the \c INTERRUPT_CONTROL_ENDPOINT token defined.
* - The \c DESCRIPTOR_ADDRESS() macro has been removed. User applications should use normal casts to obtain a descriptor's memory
* address.
* - The library events system has been rewritten, so that all macros have been removed to allow for clearer user code. See
* \ref Group_Events for new API details.
* - The \c STREAM_CALLBACK() macro has been removed. User applications should replace all instances of the macro with regular
* function signatures of a function accepting no arguments and returning a \c uint8_t value.
* - The \c Event_DeviceError() event no longer exists, as its sole caller (unlinked \c USB_GetDescriptor() function) now produces a
* compilation error rather than a runtime error. The \c StdDescriptors.c file no longer exists as a result, and should be removed
* from project makefiles.
* - The \c USB_GetDescriptor() function has been renamed to \ref CALLBACK_USB_GetDescriptor() to be in line with the new \c CALLBACK_
* function prefixes for functions which <i>must</i> be implemented in the user application.
*
* <b>Host Mode</b>
* - Support for non-control data pipe interrupts has been dropped due to many issues in the implementation. All existing
* projects using interrupts on non-control pipes should switch to polling.
* - The library events system has been rewritten, so that all macros have been removed to allow for clearer user code. See
* \ref Group_Events for new API details.
* - The \c STREAM_CALLBACK() macro has been removed. User applications should replace all instances of the macro with regular
* function signatures of a function accepting no arguments and returning a \c uint8_t value.
* - The \c DESCRIPTOR_COMPARATOR() macro has been removed. User applications should replace all instances of the macro with
* regular function signatures of a function accepting a void pointer to the descriptor to test, and returning a \c uint8_t value.
*
* \section Sec_Migration090510 Migrating from 090401 to 090510
*
* <b>All</b>
* - The \c ButtLoadTag.h header has been removed, as it was never used for its intended purpose. Projects should either remove all
* \c BUTTLOADTAG() elements, or download and extract \c ButtLoadTag.h header from the ButtLoad project.
* - The \c Drivers/AT90USBXXX/ directory has been renamed to \c Drivers/Peripheral/.
* - The \c Serial_Stream driver has been renamed to \c SerialStream to remain consistent with the rest of the library naming scheme.
* - The HWB driver has changed to the \c Buttons driver. See the board Buttons driver documentation for the new API.
*
* <b>Dual Role Mode</b>
* - The \c USB_PowerOnFail event has been renamed to \c USB_InitFailure.
* - The functions in \c OTG.h have been renamed to remain more consistent with the library API. See the functions in \c OTG.h for more
* details.
*
* <b>Device Mode</b>
* - The \c Endpoint_ClearCurrentBank() macro has been removed, and is now replaced with the \ref Endpoint_ClearIN(), \ref Endpoint_ClearOUT()
* macros. See \c Endpoint.h documentation for more details on the new endpoint management macros.
* - The \c Endpoint_ReadWriteAllowed() macro has been renamed to \ref Endpoint_IsReadWriteAllowed() to be more consistent with the rest of
* the API naming scheme.
* - The \c Endpoint_IsSetupINReady() and \c Endpoint_IsSetupOUTReceived() macros have been renamed to \ref Endpoint_IsINReady() and
* \ref Endpoint_IsOUTReceived() respectively.
* - The \c Endpoint_IsSetupReceived() macro has been renamed to \ref Endpoint_IsSETUPReceived().
* - The \c Endpoint_ClearSetupReceived() macro has been renamed to \ref Endpoint_ClearSETUP().
* - All endpoint read/write/discard aliases which did not have an explicitly endianness specifier (such as \c Endpoint_Read_Word()) have
* been removed for clarity. Existing projects should use the \c _LE suffix on such calls to use the explicit Little Endian versions.
* - The \c USB_UnhandledControlPacket event no longer has any parameters. User code should no longer attempt to read in the remainder of
* the Control Request header as all Control Request header data is now preloaded by the library and made available in the
* USB_ControlRequest structure.
* - The \c FEATURELESS_CONTROL_ONLY_DEVICE token has been renamed to \c CONTROL_ONLY_DEVICE.
* - The \c STATIC_ENDPOINT_CONFIGURATION is no longer applicable as the library will apply this optimization when appropriate automatically.
* - The values of the \ref Endpoint_Stream_RW_ErrorCodes_t and \ref Endpoint_ControlStream_RW_ErrorCodes_t enums have had the \c ERROR_ portion
* of their names removed.
*
* <b>Host Mode</b>
* - The \ref USB_Host_SendControlRequest() function no longer automatically selects the Control pipe (pipe 0) to allow it to be used on
* other control type pipes. Care should be taken to ensure that the Control pipe is always selected before the function is called
* in existing projects where the Control pipe is to be operated on.
* - The USB Host management task now saves and restores the currently selected pipe before and after the task runs. Projects no longer
* need to manage this manually when calling the USB management task.
* - The \c Pipe_ClearCurrentBank() macro has been removed, and is now replaced with the Pipe_ClearIN(), Pipe_ClearOUT() macros. See
* Pipe.h documentation for more details on the new pipe management macros.
* - The \c Pipe_ReadWriteAllowed() macro has been renamed to \ref Pipe_IsReadWriteAllowed() to be more consistent with the rest of the API
* naming scheme.
* - The \c Pipe_IsSetupINReceived() and \c Pipe_IsOutReady() macros have been renamed to \ref Pipe_IsINReceived() and \ref Pipe_IsOUTReady()
* respectively.
* - The new \ref Pipe_ClearSETUP() macro should be used to send SETUP transactions, rather than the previous \c Pipe_ClearSetupOUT() macro.
* - The \c Pipe_IsSetupSent() macro has been renamed to \ref Pipe_IsSETUPSent().
* - The \c Pipe_ClearSetupSent() macro is no longer applicable and should be removed.
* - All pipe read/write/discard aliases which did not have an explicitly endianness specifier (such as \c Pipe_Read_Word()) have
* been removed for clarity. Existing projects should use the \c _LE suffix on such calls to use the explicit Little Endian versions.
* - The \c Host_IsResetBusDone() macro has been renamed to \c Host_IsBusResetComplete().
* - The \c Pipe_Ignore_Word() and \c Pipe_Ignore_DWord() functions have been renamed to \c Pipe_Discard_Word() and \c Pipe_Discard_DWord()
* to remain consistent with the rest of the pipe API.
* - It is no longer needed to manually include the headers from \c LUFA/Drivers/USB/Class, as they are now included along with the rest
* of the USB headers when \c LUFA/Drivers/USB/USB.h is included.
* - Functions in the \c ConfigDescriptor.h header file no longer have \c Host_ as part of their names.
* - The \c ProcessHIDReport() has been renamed to \ref USB_ProcessHIDReport(), \c GetReportItemInfo() has been renamed to \ref USB_GetHIDReportItemInfo()
* and \c SetReportItemInfo() has been renamed to \ref USB_GetHIDReportItemInfo().
* - The values of the \ref DSearch_Return_ErrorCodes_t and \ref DSearch_Comp_Return_ErrorCodes_t enums have had their respective \c Descriptor_Search
* and \c Descriptor_Search_Comp prefixes changed to all caps.
* - The \c USB_HostRequest global has been renamed to \ref USB_ControlRequest, and is used in Device mode also. The \c USB_Host_Request_Header_t
* structure type has been renamed to \ref USB_Request_Header_t.
* - The values of the \ref Pipe_Stream_RW_ErrorCodes_t enum have had the \c ERROR_ portion of their names removed.
*
* \section Sec_Migration090401 Migrating from 090209 to 090401
*
* <b>All</b>
* - LUFA projects must now give the raw input clock frequency (before any prescaling) as a compile time constant \c F_USB,
* defined in the project makefile and passed to the compiler via the -D switch.
* - The makefile EEPROM programming targets for FLIP and dfu-programmer no longer program in the FLASH data in addition to the
* EEPROM data into the device. If both are to be programmed, both the EEPROM and FLASH programming targets must be called.
* - As the avr-libc macro has been corrected in recent avr-libc distributions, the \c SetSystemClockPrescaler() macro has been removed.
* Include \c <avr/power.h> and call \c clock_prescale_set(clock_div_1); instead on recent avr-libc distributions.
*
* <b>Library Demos</b>
* - The USBtoSerial demo now discards all data when not connected to a host, rather than buffering it for later transmission.
*
* <b>Non-USB Library Components</b>
* - The \c ATTR_ALWAYSINLINE function attribute macro has been renamed to \ref ATTR_ALWAYS_INLINE.
* - Custom board Dataflash drivers now require the implementation of \ref Dataflash_SelectChipFromPage() and \ref Dataflash_SendAddressBytes().
*
* <b>Device Mode</b>
* - The \c NO_CLEARSET_FEATURE_REQUEST compile time token has been renamed to \c FEATURELESS_CONTROL_ONLY_DEVICE, and its function expanded
* to also remove parts of the Get Status chapter 9 request to further reduce code usage. On all applications currently using the
* \c NO_CLEARSET_FEATURE_REQUEST compile time token, it can be replaced with the \c FEATURELESS_CONTROL_ONLY_DEVICE token with no further
* modifications required.
*
* \section Sec_Migration090209 Migrating from 081217 to 090209
*
* <b>Device Mode</b>
* - The \c ENDPOINT_MAX_ENDPOINTS constant has been renamed to the more appropriate name of \c ENDPOINT_TOTAL_ENDPOINTS.
* - The \c USB_STREAM_TIMEOUT_MS stream timeout default period has been extended to 100ms. This can be overridden in the user
* makefile if desired to restore the previous 50ms timeout.
*
* <b>Host Mode</b>
* - The \c PIPE_MAX_ENDPOINTS constant has been renamed to the more appropriate name of \c PIPE_TOTAL_ENDPOINTS.
* - The \c USB_STREAM_TIMEOUT_MS stream timeout default period has been extended to 100ms. This can be overridden in the user
* makefile if desired to restore the previous 50ms timeout.
* - The \c USB_DeviceEnumerationFailed event now contains a second \c SubErrorCode parameter, giving the error code of the function
* which failed.
* - The \c HID_PARSE_Sucessful enum member constant name has been corrected to \ref HID_PARSE_Successful.
*
* <b>Non-USB Library Components</b>
* - The previous \c SPI_SendByte() functionality is now located in \ref SPI_TransferByte(). \ref SPI_SendByte() now discards the return byte
* for speed, to compliment the new \ref SPI_ReceiveByte() function. If bidirectional SPI transfers are required, calls to \ref SPI_SendByte()
* should be changed to \ref SPI_TransferByte().
* - The serial driver now sets the Tx line as an output explicitly, and enables the pull-up of the Rx line.
* - The \ref Serial_Init() and \c SerialStream_Init() functions now take a second \c DoubleSpeed parameter, which indicates if the USART
* should be initialized in double speed mode - useful in some circumstances for attaining baud rates not usually possible at the given AVR
* clock speed.
*
* \section Sec_Migration171208 Migrating from V1.5.3 to 081217
*
* <b>All</b>
* - The MyUSB project name has been changed to LUFA (Lightweight Framework for USB AVRs). All references to MyUSB, including macro names,
* have been changed to LUFA.
*
* <b>Library Demos</b>
* - The ReconfigureUSART() routine in the USBtoSerial demo was not being called after new line encoding
* parameters were set by the host. Projects built on the USBtoSerial code should update to the latest version.
* - The HID Parser now supports multiple report (on a single endpoint) HID devices. The MouseHostWithParser and
* KeyboardHostWithPaser demos use the updated API functions to function correctly on such devices. Projects
* built on either "WithParser" demo should update to the latest code.
* - The RNDIS demo TCP stack has been modified so that connections can be properly closed. It is still not
* recommended that the MyUSB RNDIS demo TCP/IP stack be used for anything other than demonstration purposes,
* as it is neither a full nor a standards compliant implementation.
*
* <b>Non-USB Library Components</b>
* - The Serial_IsCharReceived() macro has been changed to the correct spelling of Serial_IsCharReceived() in Serial.h.
*
* <b>Device Mode</b>
* - The MANUAL_PLL_CONTROL compile time token has been removed, and replaced with a USB_OPT_MANUAL_PLL mask
* to be used in the Options parameter of the USB_Init() function.
* - Calling USB_Init() now forces a complete USB interface reset and enumeration, even if the USB interface is
* currently initialized.
* - Interrupts are now disabled when processing control requests, to avoid problems with interrupts causing the library
* or user request processing code to exceed the strict USB timing requirements on control transfers.
* - The USB Reset event now resets and disables all device endpoints. If user code depends on endpoints remaining configured
* after a Reset event, it should be altered to explicitly re-initialize all user endpoints.
* - The prototype for the GetDescriptor function has been changed, as the return value was redundant. The function now
* returns the size of the descriptor, rather than passing it back via a parameter, or returns NO_DESCRIPTOR if the specified
* descriptor does not exist.
* - The NO_DESCRIPTOR_STRING macro has been renamed NO_DESCRIPTOR, and is now also used as a possible return value for the
* GetDescriptor function.
*
* <b>Host Mode</b>
* - The MANUAL_PLL_CONTROL compile time token has been removed, and replaced with a USB_OPT_MANUAL_PLL mask
* to be used in the Options parameter of the USB_Init() function.
* - The HID report parser now supports multiple Report IDs. The HID report parser GetReportItemInfo() and
* SetReportItemInfo() routines now return a boolean, set if the requested report item was located in the
* current report. If sending a report to a multi-report device, the first byte of the report is automatically
* set to the report ID of the given report item.
* - Calling USB_Init() now forces a complete USB interface reset and enumeration, even if the USB interface is
* currently initialized.
*
* \section Sec_Migration152 Migrating from V1.5.2 to V1.5.3
*
* <b>Library Demos</b>
* - Previously, all demos contained a serial number string descriptor, filled with all zeros. A serial number
* string is required in Mass Storage devices, or devices which are to retain settings when moved between
* ports on a machine. As people were not changing the serial number value, this was causing conflicts and so
* the serial number descriptor has been removed from all but the Mass Storage demo, which requires it.
* - The AudioOut and AudioIn demos did not previously silence their endpoints when the host has deactivated
* them. Projects built upon either demo should upgrade to the latest code.
* - The FEATURE_ENDPOINT macro has been renamed FEATURE_ENDPOINT_HALT, and is now correctly documented.
* - The MassStoreHost demo contained errors which caused it to lock up randomly on certain devices. Projects built
* on the MassStoreDemo code should update to the latest version.
* - The Interrupt type endpoint in the CDC based demos previously had a polling interval of 0x02, which caused
* problems on some Linux systems. This has been changed to 0xFF, projects built on the CDC demos should upgrade
* to the latest code.
* - The HID keyboard and mouse demos were not previously boot mode compatible. To enable boot mode support, projects
* built on the keyboard or mouse demos (or derivatives) should upgrade to the latest code.
* - The Mass Storage demo was not previously standards compliant. Projects built on the Mass Storage demo should
* upgrade to the latest code.
* - The USART was not being reconfigured after the host sent new encoding settings in the USBtoSerial demo. This was
* previously discovered and fixed, but the change was lost. Projects built on the USBtoSerial demo should update
* to the latest code.
*
* <b>Device Mode</b>
* - The endpoint non-control stream functions now have a default timeout of 50ms between packets in the stream.
* If this timeout is exceeded, the function returns the new ENDPOINT_RWSTREAM_ERROR_Timeout error value. The
* timeout value can be overridden by defining the USB_STREAM_TIMEOUT_MS in the project makefile to the desired
* timeout duration in ms.
* - Rather than returning fixed values, the flags indicating if the device has Remote Wakeup currently enabled
* and/or is self-powered are now accessed and set through the new USB_RemoteWakeupEnabled and
* USB_CurrentlySelfPowered macros. See the DevChapter9.h documentation for more details.
* - All endpoint stream functions now require an extra Callback function parameter. Existing code may be updated
* to either supply NO_STREAM_CALLBACK as the extra parameter, or disable stream callbacks altogether by passing
* the token NO_STREAM_CALLBACKS to the compiler using the -D switch.
*
* <b>Host Mode</b>
* - The pipe non-control stream functions now have a default timeout of 50ms between packets in the stream.
* If this timeout is exceeded, the function returns the new PIPE_RWSTREAM_ERROR_Timeout error value. The
* timeout value can be overridden by defining the USB_STREAM_TIMEOUT_MS in the project makefile to the desired
* timeout duration in ms.
* - CollectionPath_t has been renamed to HID_CollectionPath_t to be more in line with the other HID parser structures.
* - All pipe stream functions now require an extra Callback function parameter. Existing code may be updated
* to either supply NO_STREAM_CALLBACK as the extra parameter, or disable stream callbacks altogether by passing
* the token NO_STREAM_CALLBACKS to the compiler using the -D switch.
*
* \section Sec_Migration151 Migrating from V1.5.1 to V1.5.2
*
* <b>Library Demos</b>
* - The RNDIS demo application has been updated so that it is functional on Linux under earlier implementations
* of the RNDIS specification, which had non-standard behaviour. Projects built upon the demo should upgrade
* to the latest code.
* - The DFU class bootloader has had several bugs corrected in this release. It is recommended that where
* possible any existing devices upgrade to the latest bootloader code.
*
* \section Sec_Migration150 Migrating from V1.5.0 to V1.5.1
*
* <b>Library Demos</b>
* - The USBtoSerial demo was broken in the 1.5.0 release, due to incorrect register polling in place of the
* global "Transmitting" flag. The change has been reverted in this release. Projects built upon the demo
* should upgrade to the latest code.
* - The HID class demos did not implement the mandatory GetReport HID class request. Projects built upon the HID
* demos should upgrade to the latest code.
* - The HID class demos incorrectly reported themselves as boot-protocol enabled HID devices in their descriptors.
* Projects built upon the HID demos should upgrade to the latest code.
* - The MIDI device demo had incorrect AudioStreaming interface descriptors. Projects built upon the MIDI demo
* should upgrade to the latest code.
* - The AudioOut demo did not correctly tristate the speaker pins when USB was disconnected, wasting power.
* Projects built upon the AudioOut demo should upgrade to the latest code.
*
* \section Sec_Migration141 Migrating from V1.4.1 to V1.5.0
*
* <b>Library Demos</b>
* - Previous versions of the library demos had incorrectly encoded BCD version numbers in the descriptors. To
* avoid such mistakes in the future, the VERSION_BCD macro has been added to StdDescriptors.h. Existing
* projects should at least manually correct the BCD version numbers, or preferably update the descriptors to
* encode the version number in BCD format using the new macro.
* - The mandatory GetReport class-specific request was accidentally omitted from previous versions of the demos
* based on the Human Interface Device (HID) class. This has been corrected, and any user projects based on the
* HID demos should also be updated accordingly.
* - The CDC demos now correctly send an empty packet directly after a full packet, to end the transmission.
* Failure to do this on projects which always or frequently send full packets will cause buffering issues on
* the host OS. All CDC user projects are advised to update their transmission routines in the same manner as
* the library CDC demos.
* - The previous interrupt-driven Endpoint/Pipe demos did not properly save and restore the currently selected
* Endpoint/Pipe when the ISR fired. This has been corrected - user projects based on the interrupt driven
* demos should also update to properly save and restore the selected Endpoint/Pipe.
*
* <b>Non-USB Library Components</b>
* - The Atomic.h and ISRMacro.h header files in MyUSB/Common have been removed, as the library is now only
* compatible with avr-libc library versions newer than the time before the functionality of the deleted
* headers was available.
*
* <b>Device Mode</b>
* - The GetDescriptor function (see StdDescriptors.h) now has a new prototype, with altered parameter names and
* functions. Existing projects will need to update the GetDescriptor implementation to reflect the new API.
* The previously split Type and Index parameters are now passed as the original wValue parameter to the
* function, to make way for the USB specification wIndex parameter which is <i>not</i> the same as the
* previous Index parameter.
* - The USB_UnhandledControlPacket event (see Events.h) now has new parameter names, to be in line with the
* official USB specification. Existing code will need to be altered to use the new parameter names.
* - The USB_CreateEndpoints event (see Events.h) has been renamed to USB_ConfigurationChanged, which is more
* appropriate. It fires in an identical manner to the previously named event, thus the only change to be made
* is the event name itself in the user project.
* - The USB_Descriptor_Language_t structure no longer exists in StdDescriptors.h, as this was a
* pseudo-descriptor modeled on the string descriptor. It is replaced by the true USB_Descriptor_String_t type
* descriptor as indicated in the USB specification, thus all device code must be updated accordingly.
* - The names of several Endpoint macros have been changed to be more consistent with the rest of the library,
* with no implementation changes. This means that existing code can be altered to use the new macro names
* with no other considerations required. See Endpoint.h for the new macro names.
* - The previous version of the MassStorage demo had an incorrect value in the SCSI_Request_Sense_Response_t
* structure named SenseData in SCSI.c which caused some problems with some hosts. User projects based on this
* demo should correct the structure value to maintain compatibility across multiple OS platforms.
* - By default, the descriptor structures use the official USB specification names for the elements. Previous
* versions of the library used non-standard (but more verbose) names, which are still usable in the current
* and future releases when the correct compile time option is enabled. See the StdDescriptors.h file
* documentation for more details.
*
* <b>Host Mode</b>
* - The USB_Host_Request_Header_t structure in HostChapter9.h (used for issuing control requests) has had its
* members renamed to the official USB specification names for requests. Existing code will need to be updated
* to use the new names.
* - The names of several Pipe macros have been changed to be more consistent with the rest of the library,
* with no implementation changes. This means that existing code can be altered to use the new macro names
* with no other considerations required. See Pipe.h for the new macro names.
* - By default, the descriptor structures use the official USB specification names for the elements. Previous
* versions of the library used non-standard (but more verbose) names, which are still usable in the current
* and future releases when the correct compile time option is enabled. See the StdDescriptors.h file
* documentation for more details.
* - The names of the macros in Host.h for controlling the SOF generation have been renamed, see the Host.h
* module documentation for the new macro names.
*
* <b>Dual Role Mode</b>
* - The OTG.h header file has been corrected so that the macros now perform their stated functions. Any existing
* projects using custom headers to fix the broken OTG header should now be altered to once again use the OTG
* header inside the library.
* - The USB_DeviceEnumerationComplete event (see Events.h) now also fires in Device mode, when the host has
* finished enumerating the device. Projects relying on the event only firing in Host mode should be updated
* so that the event action only occurs when the USB_Mode global is set to USB_MODE_HOST.
*/

View File

@ -0,0 +1,27 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** \page Page_ProgrammingApps Programming an Application into a USB AVR
*
* Once you have built an application, you will need a way to program in the resulting ".HEX" file (and, if your
* application uses EEPROM variables with initial values, also a ".EEP" file) into your USB AVR. Normally, the
* reprogramming of an AVR device must be performed using a special piece of programming hardware, through one of the
* supported AVR programming protocols - ISP, HVSP, HVPP, JTAG or dW. This can be done through a custom programmer,
* a third party programmer, or an official Atmel AVR tool - for more information, see the Atmel.com website.
*
* Alternatively, you can use the bootloader. From the Atmel factory, each USB AVR comes preloaded with the Atmel
* DFU (Device Firmware Update) class bootloader, a small piece of AVR firmware which allows the remainder of the
* AVR to be programmed through a non-standard interface such as the serial USART port, SPI, or (in this case) USB.
* Bootloaders have the advantage of not requiring any special hardware for programming, and cannot usually be erased
* or broken without an external programming device. They have disadvantages however; they cannot change the fuses of
* the AVR (special configuration settings that control the operation of the chip itself) and a small portion of the
* AVR's FLASH program memory must be reserved to contain the bootloader firmware, and thus cannot be used by the
* loaded application. Atmel's DFU bootloader is either 4KB (for the smaller USB AVRs) or 8KB (for the larger USB AVRs).
*
* If you wish to use the DFU bootloader to program in your application, refer to your DFU programmer's documentation.
* Atmel provides a free utility called FLIP which is USB AVR compatible, and an open source (Linux compatible)
* alternative exists called "dfu-programmer".
*/

View File

@ -0,0 +1,71 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/**
* \page Page_SoftwareBootloaderStart Entering the Bootloader via Software
*
* A common requirement of many applications is the ability to jump to the programmed bootloader of a chip
* on demand, via the code's firmware (i.e. not as a result of any physical user interaction with the
* hardware). This might be required because the device does not have any physical user input, or simply
* just to streamline the device upgrade process on the host PC.
*
* The following C code snippets may be used to enter the bootloader upon request by the user application.
* By using the watchdog to physically reset the controller, it is ensured that all system hardware is
* completely reset to their defaults before the bootloader is run. This is important; since bootloaders
* are written to occupy a very limited space, they usually make assumptions about the register states based
* on the default values after a hard-reset of the chip.
*
* \section Sec_SoftareBootAVR8 AVR8 Architecture
* The following software bootloader jump code is written for the AVR8 architecture.
*
* \code
* #include <avr/wdt.h>
* #include <avr/io.h>
* #include <util/delay.h>
*
* #include <LUFA/Common/Common.h>
* #include <LUFA/Drivers/USB/USB.h>
*
* uint32_t Boot_Key ATTR_NO_INIT;
*
* #define MAGIC_BOOT_KEY 0xDC42ACCA
* #define BOOTLOADER_START_ADDRESS (FLASH_SIZE_BYTES - BOOTLOADER_SEC_SIZE_BYTES)
*
* void Bootloader_Jump_Check(void) ATTR_INIT_SECTION(3);
* void Bootloader_Jump_Check(void)
* {
* // If the reset source was the bootloader and the key is correct, clear it and jump to the bootloader
* if ((MCUSR & (1 << WDRF)) && (Boot_Key == MAGIC_BOOT_KEY))
* {
* Boot_Key = 0;
* ((void (*)(void))BOOTLOADER_START_ADDRESS)();
* }
* }
*
* void Jump_To_Bootloader(void)
* {
* // If USB is used, detach from the bus and reset it
* USB_Disable();
*
* // Disable all interrupts
* cli();
*
* // Wait two seconds for the USB detachment to register on the host
* Delay_MS(2000);
*
* // Set the bootloader key to the magic value and force a reset
* Boot_Key = MAGIC_BOOT_KEY;
* wdt_enable(WDTO_250MS);
* for (;;);
* }
* \endcode
*
* Note that the bootloader magic key can be any arbitrary value. The <em>FLASH_SIZE_BYTES</em> and
* <em>BOOTLOADER_SEC_SIZE_BYTES</em> tokens should be replaced with the total flash size of the AVR
* in bytes, and the allocated size of the bootloader section for the target AVR.
*
*/

View File

@ -0,0 +1,424 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** \page Page_VIDPID VID and PID values
*
* \section Sec_VIDPID_Allocations
* The LUFA library uses VID/PID combinations generously donated by Atmel. The following VID/PID combinations
* are used within the LUFA demos, and thus may be re-used by derivations of each demo. Free PID values may be
* used by future LUFA demo projects.
*
* <b>These VID/PID values should not be used in commercial designs under any circumstances.</b> Private projects
* may use the following values freely, but must accept any collisions due to other LUFA derived private projects
* sharing identical values. It is suggested that private projects using interfaces compatible with existing
* demos share the same VID/PID value.
*
* <table>
*
* <tr>
* <td>
* <b>VID</b>
* </td>
* <td>
* <b>PID</b>
* </td>
* <td>
* <b>Usage</b>
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2040
* </td>
* <td>
* Test VID/PID (See below)
* </td>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2041
* </td>
* <td>
* Mouse Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2042
* </td>
* <td>
* Keyboard Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2043
* </td>
* <td>
* Joystick Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2044
* </td>
* <td>
* CDC Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2045
* </td>
* <td>
* Mass Storage Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2046
* </td>
* <td>
* Audio Output Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2047
* </td>
* <td>
* Audio Input Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2048
* </td>
* <td>
* MIDI Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2049
* </td>
* <td>
* MagStripe Project
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x204A
* </td>
* <td>
* CDC Bootloader
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x204B
* </td>
* <td>
* USB to Serial Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x204C
* </td>
* <td>
* RNDIS Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x204D
* </td>
* <td>
* Combined Keyboard and Mouse Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x204E
* </td>
* <td>
* Dual CDC Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x204F
* </td>
* <td>
* Generic HID Demo Application
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2060
* </td>
* <td>
* Benito Programmer Project
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2061
* </td>
* <td>
* Combined Mass Storage and Keyboard Demo
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2062
* </td>
* <td>
* Combined CDC and Mouse Demo
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2063
* </td>
* <td>
* Mass Storage/HID Interface Datalogger Project
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2064
* </td>
* <td>
* Interfaceless Control-Only LUFA Devices
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2065
* </td>
* <td>
* Test and Measurement Demo
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2066
* </td>
* <td>
* Multiple Report Keyboard/Mouse HID Demo
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2067
* </td>
* <td>
* HID Class Bootloader
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2068
* </td>
* <td>
* Virtual Serial/Mass Storage Demo
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x2069
* </td>
* <td>
* Webserver Project
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x206A
* </td>
* <td>
* Media Control Project
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x206B
* </td>
* <td>
* <i>Currently Unallocated</i>
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x206C
* </td>
* <td>
* <i>Currently Unallocated</i>
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x206D
* </td>
* <td>
* <i>Currently Unallocated</i>
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x206E
* </td>
* <td>
* <i>Currently Unallocated</i>
* </td>
* </tr>
*
* <tr>
* <td>
* 0x03EB
* </td>
* <td>
* 0x206F
* </td>
* <td>
* <i>Currently Unallocated</i>
* </td>
* </tr>
*
* </table>
*
* \section Sec_Test_VIDPID The Test VID/PID Combination:
* For use in testing of LUFA powered devices during development only, by non-commercial entities.
* All devices must accept collisions on this VID/PID range (from other in-development LUFA devices)
* to be resolved by using a unique release number in the Device Descriptor. No devices using this
* VID/PID combination may be released to the general public.
*/

View File

@ -0,0 +1,43 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/**
* \page Page_WhyUseLUFA Why Use LUFA?
*
* The LUFA Library has many advantages over implementing the code required to drive the USB AVRs directly.
* It is much more preferable to incorporate LUFA into your existing projects - or even make a new project
* using LUFA - than it is to start from scratch and use the USB AVR registers directly. Some of these reasons
* are:
*
* - <b>Portability:</b>
* The LUFA stack is designed to run (at some capacity) on the entire Atmel range of USB AVRs, regardless of the
* exact USB controller revision used. If you decide to implement your own USB stack, you will either need to
* code around the differences between each USB AVR controller's implementation between different chip models, or
* require your code to run on only one specific USB AVR model series.
*
* - <b>Speed of Development:</b>
* LUFA ships with a wide range of pre-made demos, bootloaders and projects for you to try, learn and extend. Each
* of these demos are tested (where possible) across as many USB AVRs and Operating Systems as possible, to ensure
* that they work under as many conditions as possible. In addition, there are inbuilt class drivers for several of
* the USB classes which you can make use of in your projects with minimal effort.
*
* - <b>Maintainability:</b>
* As LUFA takes care of much of the USB implementation, you can be left to focusing on your actual project's
* functionality, rather than being held back developing and debugging the USB stack code. Since LUFA uses clear APIs
* for USB development, your code will be more readable than if it had the low level USB stack code integrated into
* it directly. Updating the LUFA library is a simple folder-replacement and gives new features and bug fixes in
* seconds each time a new release is made.
*
* - <b>Size:</b>
* Not just requiring less code to make complex USB devices, LUFA is written to compile down as much as possible into
* optimal code, to occupy only a small space for its feature set.
*
* - <b>Support:</b>
* Since many people are now using LUFA in their own projects, you can take advantage of other's knowledge when you run
* into difficulties or need some advice. In addition, you can also email the library author to receive personalized
* support when you need it (subject to author's schedule).
*/

View File

@ -0,0 +1,27 @@
/** \file
*
* This file contains special DoxyGen information for the generation of the main page and other special
* documentation pages. It is not a project source file.
*/
/** \page Page_WritingBoardDrivers Writing LUFA Board Drivers
*
* LUFA ships with several basic pre-made board drivers, to control hardware present on the supported board
* hardware - such as Dataflash ICs, LEDs, Joysticks, or other hardware peripherals. When compiling an application
* which makes use of one or more board drivers located in LUFA/Drivers/Board, you must also indicate what board
* hardware you are using in your project makefile. This is done by defining the BOARD macro using the -D switch
* passed to the compiler, with a constant of BOARD_{Name}. For example <b>-DBOARD=BOARD_USBKEY</b> instructs the
* compiler to use the USBKEY board hardware drivers.
*
* If your application does not use *any* board level drivers, you can omit the definition of the BOARD macro.
* However, some users may wish to write their own custom board hardware drivers which are to remain compatible
* with the LUFA hardware API. To do this, the BOARD macro should be defined to the value BOARD_USER. This indicates
* that the board level drivers should be located in a folder named "Board" located inside the application's folder.
*
* When used, the driver stub files located in the LUFA/CodeTemplates/DriverStubs folder should be copied to the user
* Board/ directory, and fleshed out to include the values and code needed to control the custom board hardware. Once
* done, the existing LUFA board level APIs (accessed in the regular LUFA/Drivers/Board/ folder) will redirect to the
* user board drivers, maintaining code compatibility and allowing for a different board to be selected through the
* project makefile with no code changes.
*/

View File

@ -0,0 +1 @@
</body><span style="margin-right: 20px; float: right;"><a href="http://www.lufa-lib.org" title="LUFA Project Page">LUFA Project Page</a> | <a href="http://www.lufa-lib.org/support" title="LUFA Support List">Support Mailing List</a> | <a href="http://www.lufa-lib.org/donate" title="Donate to Support LUFA">Donate</a> | <a href="http://www.fourwalledcubicle.com" title="Four Walled Cubicle Website">Four Walled Cubicle</a> - LUFA, the Lightweight USB Framework for AVRs</span></html>

View File

@ -0,0 +1,80 @@
/*
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.
*/
/** \file
* \brief Master include file for the library USB CDC-ACM Class driver.
*
* Master include file for the library USB CDC Class driver, for both host and device modes, where available.
*
* This file should be included in all user projects making use of this optional class driver, instead of
* including any headers in the USB/ClassDriver/Device, USB/ClassDriver/Host or USB/ClassDriver/Common subdirectories.
*/
/** \ingroup Group_USBClassDrivers
* \defgroup Group_USBClassCDC CDC-ACM (Virtual Serial) Class Driver
*
* \section Sec_Dependencies Module Source Dependencies
* The following files must be built with any user project that uses this module:
* - LUFA/Drivers/USB/Class/Device/CDCClassDevice.c <i>(Makefile source module name: LUFA_SRC_USBCLASS)</i>
* - LUFA/Drivers/USB/Class/Host/CDCClassHost.c <i>(Makefile source module name: LUFA_SRC_USBCLASS)</i>
*
* \section Sec_ModDescription Module Description
* CDC Class Driver module. This module contains an internal implementation of the USB CDC-ACM class Virtual Serial
* Ports, for both Device and Host USB modes. User applications can use this class driver instead of implementing the
* CDC class manually via the low-level LUFA APIs.
*
* This module is designed to simplify the user code by exposing only the required interface needed to interface with
* Hosts or Devices using the USB CDC Class.
*
* @{
*/
#ifndef _CDC_CLASS_H_
#define _CDC_CLASS_H_
/* Macros: */
#define __INCLUDE_FROM_USB_DRIVER
#define __INCLUDE_FROM_CDC_DRIVER
/* Includes: */
#include "../Core/USBMode.h"
#if defined(USB_CAN_BE_DEVICE)
#include "Device/CDCClassDevice.h"
#endif
#if defined(USB_CAN_BE_HOST)
#include "Host/CDCClassHost.h"
#endif
#endif
/** @} */

View File

@ -0,0 +1,386 @@
/*
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.
*/
/** \file
* \brief Common definitions and declarations for the library USB CDC Class driver.
*
* Common definitions and declarations for the library USB CDC Class driver.
*
* \note This file should not be included directly. It is automatically included as needed by the USB module driver
* dispatch header located in LUFA/Drivers/USB.h.
*/
/** \ingroup Group_USBClassCDC
* \defgroup Group_USBClassCDCCommon Common Class Definitions
*
* \section Sec_ModDescription Module Description
* Constants, Types and Enum definitions that are common to both Device and Host modes for the USB
* CDC Class.
*
* @{
*/
#ifndef _CDC_CLASS_COMMON_H_
#define _CDC_CLASS_COMMON_H_
/* Includes: */
#include "../../Core/StdDescriptors.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_CDC_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
#endif
/* Macros: */
/** \name Virtual Control Line Masks */
//@{
/** Mask for the DTR handshake line for use with the \ref CDC_REQ_SetControlLineState class-specific request
* from the host, to indicate that the DTR line state should be high.
*/
#define CDC_CONTROL_LINE_OUT_DTR (1 << 0)
/** Mask for the RTS handshake line for use with the \ref CDC_REQ_SetControlLineState class-specific request
* from the host, to indicate that the RTS line state should be high.
*/
#define CDC_CONTROL_LINE_OUT_RTS (1 << 1)
/** Mask for the DCD handshake line for use with the \ref CDC_NOTIF_SerialState class-specific notification
* from the device to the host, to indicate that the DCD line state is currently high.
*/
#define CDC_CONTROL_LINE_IN_DCD (1 << 0)
/** Mask for the DSR handshake line for use with the \ref CDC_NOTIF_SerialState class-specific notification
* from the device to the host, to indicate that the DSR line state is currently high.
*/
#define CDC_CONTROL_LINE_IN_DSR (1 << 1)
/** Mask for the BREAK handshake line for use with the \ref CDC_NOTIF_SerialState class-specific notification
* from the device to the host, to indicate that the BREAK line state is currently high.
*/
#define CDC_CONTROL_LINE_IN_BREAK (1 << 2)
/** Mask for the RING handshake line for use with the \ref CDC_NOTIF_SerialState class-specific notification
* from the device to the host, to indicate that the RING line state is currently high.
*/
#define CDC_CONTROL_LINE_IN_RING (1 << 3)
/** Mask for use with the \ref CDC_NOTIF_SerialState class-specific notification from the device to the host,
* to indicate that a framing error has occurred on the virtual serial port.
*/
#define CDC_CONTROL_LINE_IN_FRAMEERROR (1 << 4)
/** Mask for use with the \ref CDC_NOTIF_SerialState class-specific notification from the device to the host,
* to indicate that a parity error has occurred on the virtual serial port.
*/
#define CDC_CONTROL_LINE_IN_PARITYERROR (1 << 5)
/** Mask for use with the \ref CDC_NOTIF_SerialState class-specific notification from the device to the host,
* to indicate that a data overrun error has occurred on the virtual serial port.
*/
#define CDC_CONTROL_LINE_IN_OVERRUNERROR (1 << 6)
//@}
/** Macro to define a CDC class-specific functional descriptor. CDC functional descriptors have a
* uniform structure but variable sized data payloads, thus cannot be represented accurately by
* a single typedef struct. A macro is used instead so that functional descriptors can be created
* easily by specifying the size of the payload. This allows \c sizeof() to work correctly.
*
* \param[in] DataSize Size in bytes of the CDC functional descriptor's data payload.
*/
#define CDC_FUNCTIONAL_DESCRIPTOR(DataSize) \
struct \
{ \
USB_Descriptor_Header_t Header; \
uint8_t SubType; \
uint8_t Data[DataSize]; \
}
/* Enums: */
/** Enum for possible Class, Subclass and Protocol values of device and interface descriptors relating to the CDC
* device class.
*/
enum CDC_Descriptor_ClassSubclassProtocol_t
{
CDC_CSCP_CDCClass = 0x02, /**< Descriptor Class value indicating that the device or interface
* belongs to the CDC class.
*/
CDC_CSCP_NoSpecificSubclass = 0x00, /**< Descriptor Subclass value indicating that the device or interface
* belongs to no specific subclass of the CDC class.
*/
CDC_CSCP_ACMSubclass = 0x02, /**< Descriptor Subclass value indicating that the device or interface
* belongs to the Abstract Control Model CDC subclass.
*/
CDC_CSCP_ATCommandProtocol = 0x01, /**< Descriptor Protocol value indicating that the device or interface
* belongs to the AT Command protocol of the CDC class.
*/
CDC_CSCP_NoSpecificProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface
* belongs to no specific protocol of the CDC class.
*/
CDC_CSCP_VendorSpecificProtocol = 0xFF, /**< Descriptor Protocol value indicating that the device or interface
* belongs to a vendor-specific protocol of the CDC class.
*/
CDC_CSCP_CDCDataClass = 0x0A, /**< Descriptor Class value indicating that the device or interface
* belongs to the CDC Data class.
*/
CDC_CSCP_NoDataSubclass = 0x00, /**< Descriptor Subclass value indicating that the device or interface
* belongs to no specific subclass of the CDC data class.
*/
CDC_CSCP_NoDataProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface
* belongs to no specific protocol of the CDC data class.
*/
};
/** Enum for the CDC class specific control requests that can be issued by the USB bus host. */
enum CDC_ClassRequests_t
{
CDC_REQ_SendEncapsulatedCommand = 0x00, /**< CDC class-specific request to send an encapsulated command to the device. */
CDC_REQ_GetEncapsulatedResponse = 0x01, /**< CDC class-specific request to retrieve an encapsulated command response from the device. */
CDC_REQ_SetLineEncoding = 0x20, /**< CDC class-specific request to set the current virtual serial port configuration settings. */
CDC_REQ_GetLineEncoding = 0x21, /**< CDC class-specific request to get the current virtual serial port configuration settings. */
CDC_REQ_SetControlLineState = 0x22, /**< CDC class-specific request to set the current virtual serial port handshake line states. */
CDC_REQ_SendBreak = 0x23, /**< CDC class-specific request to send a break to the receiver via the carrier channel. */
};
/** Enum for the CDC class specific notification requests that can be issued by a CDC device to a host. */
enum CDC_ClassNotifications_t
{
CDC_NOTIF_SerialState = 0x20, /**< Notification type constant for a change in the virtual serial port
* handshake line states, for use with a \ref USB_Request_Header_t
* notification structure when sent to the host via the CDC notification
* endpoint.
*/
};
/** Enum for the CDC class specific interface descriptor subtypes. */
enum CDC_DescriptorSubtypes_t
{
CDC_DSUBTYPE_CSInterface_Header = 0x00, /**< CDC class-specific Header functional descriptor. */
CDC_DSUBTYPE_CSInterface_CallManagement = 0x01, /**< CDC class-specific Call Management functional descriptor. */
CDC_DSUBTYPE_CSInterface_ACM = 0x02, /**< CDC class-specific Abstract Control Model functional descriptor. */
CDC_DSUBTYPE_CSInterface_DirectLine = 0x03, /**< CDC class-specific Direct Line functional descriptor. */
CDC_DSUBTYPE_CSInterface_TelephoneRinger = 0x04, /**< CDC class-specific Telephone Ringer functional descriptor. */
CDC_DSUBTYPE_CSInterface_TelephoneCall = 0x05, /**< CDC class-specific Telephone Call functional descriptor. */
CDC_DSUBTYPE_CSInterface_Union = 0x06, /**< CDC class-specific Union functional descriptor. */
CDC_DSUBTYPE_CSInterface_CountrySelection = 0x07, /**< CDC class-specific Country Selection functional descriptor. */
CDC_DSUBTYPE_CSInterface_TelephoneOpModes = 0x08, /**< CDC class-specific Telephone Operation Modes functional descriptor. */
CDC_DSUBTYPE_CSInterface_USBTerminal = 0x09, /**< CDC class-specific USB Terminal functional descriptor. */
CDC_DSUBTYPE_CSInterface_NetworkChannel = 0x0A, /**< CDC class-specific Network Channel functional descriptor. */
CDC_DSUBTYPE_CSInterface_ProtocolUnit = 0x0B, /**< CDC class-specific Protocol Unit functional descriptor. */
CDC_DSUBTYPE_CSInterface_ExtensionUnit = 0x0C, /**< CDC class-specific Extension Unit functional descriptor. */
CDC_DSUBTYPE_CSInterface_MultiChannel = 0x0D, /**< CDC class-specific Multi-Channel Management functional descriptor. */
CDC_DSUBTYPE_CSInterface_CAPI = 0x0E, /**< CDC class-specific Common ISDN API functional descriptor. */
CDC_DSUBTYPE_CSInterface_Ethernet = 0x0F, /**< CDC class-specific Ethernet functional descriptor. */
CDC_DSUBTYPE_CSInterface_ATM = 0x10, /**< CDC class-specific Asynchronous Transfer Mode functional descriptor. */
};
/** Enum for the possible line encoding formats of a virtual serial port. */
enum CDC_LineEncodingFormats_t
{
CDC_LINEENCODING_OneStopBit = 0, /**< Each frame contains one stop bit. */
CDC_LINEENCODING_OneAndAHalfStopBits = 1, /**< Each frame contains one and a half stop bits. */
CDC_LINEENCODING_TwoStopBits = 2, /**< Each frame contains two stop bits. */
};
/** Enum for the possible line encoding parity settings of a virtual serial port. */
enum CDC_LineEncodingParity_t
{
CDC_PARITY_None = 0, /**< No parity bit mode on each frame. */
CDC_PARITY_Odd = 1, /**< Odd parity bit mode on each frame. */
CDC_PARITY_Even = 2, /**< Even parity bit mode on each frame. */
CDC_PARITY_Mark = 3, /**< Mark parity bit mode on each frame. */
CDC_PARITY_Space = 4, /**< Space parity bit mode on each frame. */
};
/* Type Defines: */
/** \brief CDC class-specific Functional Header Descriptor (LUFA naming conventions).
*
* Type define for a CDC class-specific functional header descriptor. This indicates to the host that the device
* contains one or more CDC functional data descriptors, which give the CDC interface's capabilities and configuration.
* See the CDC class specification for more details.
*
* \see \ref USB_CDC_StdDescriptor_FunctionalHeader_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
uint8_t Subtype; /**< Sub type value used to distinguish between CDC class-specific descriptors,
* must be \ref CDC_DSUBTYPE_CSInterface_Header.
*/
uint16_t CDCSpecification; /**< Version number of the CDC specification implemented by the device,
* encoded in BCD format.
*/
} ATTR_PACKED USB_CDC_Descriptor_FunctionalHeader_t;
/** \brief CDC class-specific Functional Header Descriptor (USB-IF naming conventions).
*
* Type define for a CDC class-specific functional header descriptor. This indicates to the host that the device
* contains one or more CDC functional data descriptors, which give the CDC interface's capabilities and configuration.
* See the CDC class specification for more details.
*
* \see \ref USB_CDC_Descriptor_FunctionalHeader_t for the version of this type with non-standard LUFA specific
* element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
uint8_t bFunctionLength; /**< Size of the descriptor, in bytes. */
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
* given by the specific class.
*/
uint8_t bDescriptorSubType; /**< Sub type value used to distinguish between CDC class-specific descriptors,
* must be \ref CDC_DSUBTYPE_CSInterface_Header.
*/
uint16_t bcdCDC; /**< Version number of the CDC specification implemented by the device, encoded in BCD format. */
} ATTR_PACKED USB_CDC_StdDescriptor_FunctionalHeader_t;
/** \brief CDC class-specific Functional ACM Descriptor (LUFA naming conventions).
*
* Type define for a CDC class-specific functional ACM descriptor. This indicates to the host that the CDC interface
* supports the CDC ACM subclass of the CDC specification. See the CDC class specification for more details.
*
* \see \ref USB_CDC_StdDescriptor_FunctionalACM_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
uint8_t Subtype; /**< Sub type value used to distinguish between CDC class-specific descriptors,
* must be \ref CDC_DSUBTYPE_CSInterface_ACM.
*/
uint8_t Capabilities; /**< Capabilities of the ACM interface, given as a bit mask. For most devices,
* this should be set to a fixed value of 0x06 - for other capabilities, refer
* to the CDC ACM specification.
*/
} ATTR_PACKED USB_CDC_Descriptor_FunctionalACM_t;
/** \brief CDC class-specific Functional ACM Descriptor (USB-IF naming conventions).
*
* Type define for a CDC class-specific functional ACM descriptor. This indicates to the host that the CDC interface
* supports the CDC ACM subclass of the CDC specification. See the CDC class specification for more details.
*
* \see \ref USB_CDC_Descriptor_FunctionalACM_t for the version of this type with non-standard LUFA specific
* element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
uint8_t bFunctionLength; /**< Size of the descriptor, in bytes. */
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
* given by the specific class.
*/
uint8_t bDescriptorSubType; /**< Sub type value used to distinguish between CDC class-specific descriptors,
* must be \ref CDC_DSUBTYPE_CSInterface_ACM.
*/
uint8_t bmCapabilities; /**< Capabilities of the ACM interface, given as a bit mask. For most devices,
* this should be set to a fixed value of 0x06 - for other capabilities, refer
* to the CDC ACM specification.
*/
} ATTR_PACKED USB_CDC_StdDescriptor_FunctionalACM_t;
/** \brief CDC class-specific Functional Union Descriptor (LUFA naming conventions).
*
* Type define for a CDC class-specific functional Union descriptor. This indicates to the host that specific
* CDC control and data interfaces are related. See the CDC class specification for more details.
*
* \see \ref USB_CDC_StdDescriptor_FunctionalUnion_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
uint8_t Subtype; /**< Sub type value used to distinguish between CDC class-specific descriptors,
* must be \ref CDC_DSUBTYPE_CSInterface_Union.
*/
uint8_t MasterInterfaceNumber; /**< Interface number of the CDC Control interface. */
uint8_t SlaveInterfaceNumber; /**< Interface number of the CDC Data interface. */
} ATTR_PACKED USB_CDC_Descriptor_FunctionalUnion_t;
/** \brief CDC class-specific Functional Union Descriptor (USB-IF naming conventions).
*
* Type define for a CDC class-specific functional Union descriptor. This indicates to the host that specific
* CDC control and data interfaces are related. See the CDC class specification for more details.
*
* \see \ref USB_CDC_Descriptor_FunctionalUnion_t for the version of this type with non-standard LUFA specific
* element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
uint8_t bFunctionLength; /**< Size of the descriptor, in bytes. */
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
* given by the specific class.
*/
uint8_t bDescriptorSubType; /**< Sub type value used to distinguish between CDC class-specific descriptors,
* must be \ref CDC_DSUBTYPE_CSInterface_Union.
*/
uint8_t bMasterInterface; /**< Interface number of the CDC Control interface. */
uint8_t bSlaveInterface0; /**< Interface number of the CDC Data interface. */
} ATTR_PACKED USB_CDC_StdDescriptor_FunctionalUnion_t;
/** \brief CDC Virtual Serial Port Line Encoding Settings Structure.
*
* Type define for a CDC Line Encoding structure, used to hold the various encoding parameters for a virtual
* serial port.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
uint32_t BaudRateBPS; /**< Baud rate of the virtual serial port, in bits per second. */
uint8_t CharFormat; /**< Character format of the virtual serial port, a value from the
* \ref CDC_LineEncodingFormats_t enum.
*/
uint8_t ParityType; /**< Parity setting of the virtual serial port, a value from the
* \ref CDC_LineEncodingParity_t enum.
*/
uint8_t DataBits; /**< Bits of data per character of the virtual serial port. */
} ATTR_PACKED CDC_LineEncoding_t;
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,361 @@
/*
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 "../../Core/USBMode.h"
#if defined(USB_CAN_BE_DEVICE)
#define __INCLUDE_FROM_CDC_DRIVER
#define __INCLUDE_FROM_CDC_DEVICE_C
#include "CDCClassDevice.h"
void CDC_Device_ProcessControlRequest(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
{
if (!(Endpoint_IsSETUPReceived()))
return;
if (USB_ControlRequest.wIndex != CDCInterfaceInfo->Config.ControlInterfaceNumber)
return;
switch (USB_ControlRequest.bRequest)
{
case CDC_REQ_GetLineEncoding:
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
while (!(Endpoint_IsINReady()));
Endpoint_Write_32_LE(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS);
Endpoint_Write_8(CDCInterfaceInfo->State.LineEncoding.CharFormat);
Endpoint_Write_8(CDCInterfaceInfo->State.LineEncoding.ParityType);
Endpoint_Write_8(CDCInterfaceInfo->State.LineEncoding.DataBits);
Endpoint_ClearIN();
Endpoint_ClearStatusStage();
}
break;
case CDC_REQ_SetLineEncoding:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
while (!(Endpoint_IsOUTReceived()));
CDCInterfaceInfo->State.LineEncoding.BaudRateBPS = Endpoint_Read_32_LE();
CDCInterfaceInfo->State.LineEncoding.CharFormat = Endpoint_Read_8();
CDCInterfaceInfo->State.LineEncoding.ParityType = Endpoint_Read_8();
CDCInterfaceInfo->State.LineEncoding.DataBits = Endpoint_Read_8();
Endpoint_ClearOUT();
Endpoint_ClearStatusStage();
EVENT_CDC_Device_LineEncodingChanged(CDCInterfaceInfo);
}
break;
case CDC_REQ_SetControlLineState:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
Endpoint_ClearStatusStage();
CDCInterfaceInfo->State.ControlLineStates.HostToDevice = USB_ControlRequest.wValue;
EVENT_CDC_Device_ControLineStateChanged(CDCInterfaceInfo);
}
break;
case CDC_REQ_SendBreak:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
Endpoint_ClearStatusStage();
EVENT_CDC_Device_BreakSent(CDCInterfaceInfo, (uint8_t)USB_ControlRequest.wValue);
}
break;
}
}
bool CDC_Device_ConfigureEndpoints(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
{
memset(&CDCInterfaceInfo->State, 0x00, sizeof(CDCInterfaceInfo->State));
for (uint8_t EndpointNum = 1; EndpointNum < ENDPOINT_TOTAL_ENDPOINTS; EndpointNum++)
{
uint16_t Size;
uint8_t Type;
uint8_t Direction;
bool DoubleBanked;
if (EndpointNum == CDCInterfaceInfo->Config.DataINEndpointNumber)
{
Size = CDCInterfaceInfo->Config.DataINEndpointSize;
Direction = ENDPOINT_DIR_IN;
Type = EP_TYPE_BULK;
DoubleBanked = CDCInterfaceInfo->Config.DataINEndpointDoubleBank;
}
else if (EndpointNum == CDCInterfaceInfo->Config.DataOUTEndpointNumber)
{
Size = CDCInterfaceInfo->Config.DataOUTEndpointSize;
Direction = ENDPOINT_DIR_OUT;
Type = EP_TYPE_BULK;
DoubleBanked = CDCInterfaceInfo->Config.DataOUTEndpointDoubleBank;
}
else if (EndpointNum == CDCInterfaceInfo->Config.NotificationEndpointNumber)
{
Size = CDCInterfaceInfo->Config.NotificationEndpointSize;
Direction = ENDPOINT_DIR_IN;
Type = EP_TYPE_INTERRUPT;
DoubleBanked = CDCInterfaceInfo->Config.NotificationEndpointDoubleBank;
}
else
{
continue;
}
if (!(Endpoint_ConfigureEndpoint(EndpointNum, Type, Direction, Size,
DoubleBanked ? ENDPOINT_BANK_DOUBLE : ENDPOINT_BANK_SINGLE)))
{
return false;
}
}
return true;
}
void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
{
if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
return;
#if !defined(NO_CLASS_DRIVER_AUTOFLUSH)
CDC_Device_Flush(CDCInterfaceInfo);
#endif
}
uint8_t CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
const char* const String)
{
if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
return ENDPOINT_RWSTREAM_DeviceDisconnected;
Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);
return Endpoint_Write_Stream_LE(String, strlen(String), NULL);
}
uint8_t CDC_Device_SendData(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
const char* const Buffer,
const uint16_t Length)
{
if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
return ENDPOINT_RWSTREAM_DeviceDisconnected;
Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);
return Endpoint_Write_Stream_LE(Buffer, Length, NULL);
}
uint8_t CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
const uint8_t Data)
{
if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
return ENDPOINT_RWSTREAM_DeviceDisconnected;
Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearIN();
uint8_t ErrorCode;
if ((ErrorCode = Endpoint_WaitUntilReady()) != ENDPOINT_READYWAIT_NoError)
return ErrorCode;
}
Endpoint_Write_8(Data);
return ENDPOINT_READYWAIT_NoError;
}
uint8_t CDC_Device_Flush(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
{
if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
return ENDPOINT_RWSTREAM_DeviceDisconnected;
uint8_t ErrorCode;
Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);
if (!(Endpoint_BytesInEndpoint()))
return ENDPOINT_READYWAIT_NoError;
bool BankFull = !(Endpoint_IsReadWriteAllowed());
Endpoint_ClearIN();
if (BankFull)
{
if ((ErrorCode = Endpoint_WaitUntilReady()) != ENDPOINT_READYWAIT_NoError)
return ErrorCode;
Endpoint_ClearIN();
}
return ENDPOINT_READYWAIT_NoError;
}
uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
{
if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
return 0;
Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber);
if (Endpoint_IsOUTReceived())
{
if (!(Endpoint_BytesInEndpoint()))
{
Endpoint_ClearOUT();
return 0;
}
else
{
return Endpoint_BytesInEndpoint();
}
}
else
{
return 0;
}
}
int16_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
{
if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
return -1;
int16_t ReceivedByte = -1;
Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber);
if (Endpoint_IsOUTReceived())
{
if (Endpoint_BytesInEndpoint())
ReceivedByte = Endpoint_Read_8();
if (!(Endpoint_BytesInEndpoint()))
Endpoint_ClearOUT();
}
return ReceivedByte;
}
void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
{
if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
return;
Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.NotificationEndpointNumber);
USB_Request_Header_t Notification = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),
.bRequest = CDC_NOTIF_SerialState,
.wValue = CPU_TO_LE16(0),
.wIndex = CPU_TO_LE16(0),
.wLength = CPU_TO_LE16(sizeof(CDCInterfaceInfo->State.ControlLineStates.DeviceToHost)),
};
Endpoint_Write_Stream_LE(&Notification, sizeof(USB_Request_Header_t), NULL);
Endpoint_Write_Stream_LE(&CDCInterfaceInfo->State.ControlLineStates.DeviceToHost,
sizeof(CDCInterfaceInfo->State.ControlLineStates.DeviceToHost),
NULL);
Endpoint_ClearIN();
}
#if defined(FDEV_SETUP_STREAM)
void CDC_Device_CreateStream(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
FILE* const Stream)
{
*Stream = (FILE)FDEV_SETUP_STREAM(CDC_Device_putchar, CDC_Device_getchar, _FDEV_SETUP_RW);
fdev_set_udata(Stream, CDCInterfaceInfo);
}
void CDC_Device_CreateBlockingStream(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
FILE* const Stream)
{
*Stream = (FILE)FDEV_SETUP_STREAM(CDC_Device_putchar, CDC_Device_getchar_Blocking, _FDEV_SETUP_RW);
fdev_set_udata(Stream, CDCInterfaceInfo);
}
static int CDC_Device_putchar(char c,
FILE* Stream)
{
return CDC_Device_SendByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream), c) ? _FDEV_ERR : 0;
}
static int CDC_Device_getchar(FILE* Stream)
{
int16_t ReceivedByte = CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));
if (ReceivedByte < 0)
return _FDEV_EOF;
return ReceivedByte;
}
static int CDC_Device_getchar_Blocking(FILE* Stream)
{
int16_t ReceivedByte;
while ((ReceivedByte = CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream))) < 0)
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return _FDEV_EOF;
CDC_Device_USBTask((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));
USB_USBTask();
}
return ReceivedByte;
}
#endif
void CDC_Device_Event_Stub(void)
{
}
#endif

View File

@ -0,0 +1,357 @@
/*
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.
*/
/** \file
* \brief Device mode driver for the library USB CDC Class driver.
*
* Device mode driver for the library USB CDC Class driver.
*
* \note This file should not be included directly. It is automatically included as needed by the USB module driver
* dispatch header located in LUFA/Drivers/USB.h.
*/
/** \ingroup Group_USBClassCDC
* \defgroup Group_USBClassCDCDevice CDC Class Device Mode Driver
*
* \section Sec_Dependencies Module Source Dependencies
* The following files must be built with any user project that uses this module:
* - LUFA/Drivers/USB/Class/Device/CDCClassDevice.c <i>(Makefile source module name: LUFA_SRC_USBCLASS)</i>
*
* \section Sec_ModDescription Module Description
* Device Mode USB Class driver framework interface, for the CDC USB Class driver.
*
* \note There are several major drawbacks to the CDC-ACM standard USB class, however
* it is very standardized and thus usually available as a built-in driver on
* most platforms, and so is a better choice than a proprietary serial class.
*
* One major issue with CDC-ACM is that it requires two Interface descriptors,
* which will upset most hosts when part of a multi-function "Composite" USB
* device, as each interface will be loaded into a separate driver instance. To
* combat this, you should use the "Interface Association Descriptor" addendum to
* the USB standard which is available on most OSes when creating Composite devices.
*
* Another major oversight is that there is no mechanism for the host to notify the
* device that there is a data sink on the host side ready to accept data. This
* means that the device may try to send data while the host isn't listening, causing
* lengthy blocking timeouts in the transmission routines. To combat this, it is
* recommended that the virtual serial line DTR (Data Terminal Ready) be used where
* possible to determine if a host application is ready for data.
*
* @{
*/
#ifndef _CDC_CLASS_DEVICE_H_
#define _CDC_CLASS_DEVICE_H_
/* Includes: */
#include "../../USB.h"
#include "../Common/CDCClassCommon.h"
#include <stdio.h>
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_CDC_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Type Defines: */
/** \brief CDC Class Device Mode Configuration and State Structure.
*
* Class state structure. An instance of this structure should be made for each CDC interface
* within the user application, and passed to each of the CDC class driver functions as the
* CDCInterfaceInfo parameter. This stores each CDC interface's configuration and state information.
*/
typedef struct
{
const struct
{
uint8_t ControlInterfaceNumber; /**< Interface number of the CDC control interface within the device. */
uint8_t DataINEndpointNumber; /**< Endpoint number of the CDC interface's IN data endpoint. */
uint16_t DataINEndpointSize; /**< Size in bytes of the CDC interface's IN data endpoint. */
bool DataINEndpointDoubleBank; /**< Indicates if the CDC interface's IN data endpoint should use double banking. */
uint8_t DataOUTEndpointNumber; /**< Endpoint number of the CDC interface's OUT data endpoint. */
uint16_t DataOUTEndpointSize; /**< Size in bytes of the CDC interface's OUT data endpoint. */
bool DataOUTEndpointDoubleBank; /**< Indicates if the CDC interface's OUT data endpoint should use double banking. */
uint8_t NotificationEndpointNumber; /**< Endpoint number of the CDC interface's IN notification endpoint, if used. */
uint16_t NotificationEndpointSize; /**< Size in bytes of the CDC interface's IN notification endpoint, if used. */
bool NotificationEndpointDoubleBank; /**< Indicates if the CDC interface's notification endpoint should use double banking. */
} Config; /**< Config data for the USB class interface within the device. All elements in this section
* <b>must</b> be set or the interface will fail to enumerate and operate correctly.
*/
struct
{
struct
{
uint16_t HostToDevice; /**< Control line states from the host to device, as a set of \c CDC_CONTROL_LINE_OUT_*
* masks. This value is updated each time \ref CDC_Device_USBTask() is called.
*/
uint16_t DeviceToHost; /**< Control line states from the device to host, as a set of \c CDC_CONTROL_LINE_IN_*
* masks - to notify the host of changes to these values, call the
* \ref CDC_Device_SendControlLineStateChange() function.
*/
} ControlLineStates; /**< Current states of the virtual serial port's control lines between the device and host. */
CDC_LineEncoding_t LineEncoding; /** Line encoding used in the virtual serial port, for the device's information.
* This is generally only used if the virtual serial port data is to be
* reconstructed on a physical UART.
*/
} State; /**< State data for the USB class interface within the device. All elements in this section
* are reset to their defaults when the interface is enumerated.
*/
} USB_ClassInfo_CDC_Device_t;
/* Function Prototypes: */
/** Configures the endpoints of a given CDC interface, ready for use. This should be linked to the library
* \ref EVENT_USB_Device_ConfigurationChanged() event so that the endpoints are configured when the configuration containing
* the given CDC interface is selected.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*
* \return Boolean \c true if the endpoints were successfully configured, \c false otherwise.
*/
bool CDC_Device_ConfigureEndpoints(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
/** Processes incoming control requests from the host, that are directed to the given CDC class interface. This should be
* linked to the library \ref EVENT_USB_Device_ControlRequest() event.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*/
void CDC_Device_ProcessControlRequest(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
/** General management task for a given CDC class interface, required for the correct operation of the interface. This should
* be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*/
void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
/** CDC class driver event for a line encoding change on a CDC interface. This event fires each time the host requests a
* line encoding change (containing the serial parity, baud and other configuration information) and may be hooked in the
* user program by declaring a handler function with the same name and parameters listed here. The new line encoding
* settings are available in the LineEncoding structure inside the CDC interface structure passed as a parameter.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*/
void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
/** CDC class driver event for a control line state change on a CDC interface. This event fires each time the host requests a
* control line state change (containing the virtual serial control line states, such as DTR) and may be hooked in the
* user program by declaring a handler function with the same name and parameters listed here. The new control line states
* are available in the State.ControlLineStates.HostToDevice value inside the CDC interface structure passed as a parameter, set as
* a mask of CDC_CONTROL_LINE_OUT_* masks.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*/
void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
/** CDC class driver event for a send break request sent to the device from the host. This is generally used to separate
* data or to indicate a special condition to the receiving device.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
* \param[in] Duration Duration of the break that has been sent by the host, in milliseconds.
*/
void EVENT_CDC_Device_BreakSent(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
const uint8_t Duration) ATTR_NON_NULL_PTR_ARG(1);
/** Sends a given data buffer to the attached USB host, if connected. If a host is not connected when the function is
* called, the string is discarded. Bytes will be queued for transmission to the host until either the endpoint bank
* becomes full, or the \ref CDC_Device_Flush() function is called to flush the pending data to the host. This allows
* for multiple bytes to be packed into a single endpoint packet, increasing data throughput.
*
* \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or
* the call will fail.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
* \param[in] Buffer Pointer to a buffer containing the data to send to the device.
* \param[in] Length Length of the data to send to the host.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t CDC_Device_SendData(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
const char* const Buffer,
const uint16_t Length) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
/** Sends a given null terminated string to the attached USB host, if connected. If a host is not connected when
* the function is called, the string is discarded. Bytes will be queued for transmission to the host until either
* the endpoint bank becomes full, or the \ref CDC_Device_Flush() function is called to flush the pending data to
* the host. This allows for multiple bytes to be packed into a single endpoint packet, increasing data throughput.
*
* \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or
* the call will fail.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
* \param[in] String Pointer to the null terminated string to send to the host.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
const char* const String) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
/** Sends a given byte to the attached USB host, if connected. If a host is not connected when the function is called, the
* byte is discarded. Bytes will be queued for transmission to the host until either the endpoint bank becomes full, or the
* \ref CDC_Device_Flush() function is called to flush the pending data to the host. This allows for multiple bytes to be
* packed into a single endpoint packet, increasing data throughput.
*
* \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or
* the call will fail.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
* \param[in] Data Byte of data to send to the host.
*
* \return A value from the \ref Endpoint_WaitUntilReady_ErrorCodes_t enum.
*/
uint8_t CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
const uint8_t Data) ATTR_NON_NULL_PTR_ARG(1);
/** Determines the number of bytes received by the CDC interface from the host, waiting to be read. This indicates the number
* of bytes in the OUT endpoint bank only, and thus the number of calls to \ref CDC_Device_ReceiveByte() which are guaranteed to
* succeed immediately. If multiple bytes are to be received, they should be buffered by the user application, as the endpoint
* bank will not be released back to the USB controller until all bytes are read.
*
* \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or
* the call will fail.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*
* \return Total number of buffered bytes received from the host.
*/
uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
/** Reads a byte of data from the host. If no data is waiting to be read of if a USB host is not connected, the function
* returns a negative value. The \ref CDC_Device_BytesReceived() function may be queried in advance to determine how many
* bytes are currently buffered in the CDC interface's data receive endpoint bank, and thus how many repeated calls to this
* function which are guaranteed to succeed.
*
* \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or
* the call will fail.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*
* \return Next received byte from the host, or a negative value if no data received.
*/
int16_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
/** Flushes any data waiting to be sent, ensuring that the send buffer is cleared.
*
* \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or
* the call will fail.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*
* \return A value from the \ref Endpoint_WaitUntilReady_ErrorCodes_t enum.
*/
uint8_t CDC_Device_Flush(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
/** Sends a Serial Control Line State Change notification to the host. This should be called when the virtual serial
* control lines (DCD, DSR, etc.) have changed states, or to give BREAK notifications to the host. Line states persist
* until they are cleared via a second notification. This should be called each time the CDC class driver's
* ControlLineStates.DeviceToHost value is updated to push the new states to the USB host.
*
* \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or
* the call will fail.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
*/
void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
/** Creates a standard character stream for the given CDC Device instance so that it can be used with all the regular
* functions in the standard <stdio.h> library that accept a \c FILE stream as a destination (e.g. \c fprintf). The created
* stream is bidirectional and can be used for both input and output functions.
*
* Reading data from this stream is non-blocking, i.e. in most instances, complete strings cannot be read in by a single
* fetch, as the endpoint will not be ready at some point in the transmission, aborting the transfer. However, this may
* be used when the read data is processed byte-per-bye (via \c getc()) or when the user application will implement its own
* line buffering.
*
* \note The created stream can be given as stdout if desired to direct the standard output from all <stdio.h> functions
* to the given CDC interface.
* \n\n
*
* \note This function is not available on all microcontroller architectures.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
* \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed.
*/
void CDC_Device_CreateStream(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
FILE* const Stream) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
/** Identical to \ref CDC_Device_CreateStream(), except that reads are blocking until the calling stream function terminates
* the transfer. While blocking, the USB and CDC service tasks are called repeatedly to maintain USB communications.
*
* \note This function is not available on all microcontroller architectures.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
* \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed.
*/
void CDC_Device_CreateBlockingStream(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
FILE* const Stream) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Function Prototypes: */
#if defined(__INCLUDE_FROM_CDC_DEVICE_C)
#if defined(FDEV_SETUP_STREAM)
static int CDC_Device_putchar(char c,
FILE* Stream) ATTR_NON_NULL_PTR_ARG(2);
static int CDC_Device_getchar(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1);
static int CDC_Device_getchar_Blocking(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1);
#endif
void CDC_Device_Event_Stub(void) ATTR_CONST;
void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
ATTR_WEAK ATTR_NON_NULL_PTR_ARG(1) ATTR_ALIAS(CDC_Device_Event_Stub);
void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
ATTR_WEAK ATTR_NON_NULL_PTR_ARG(1) ATTR_ALIAS(CDC_Device_Event_Stub);
void EVENT_CDC_Device_BreakSent(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
const uint8_t Duration) ATTR_WEAK ATTR_NON_NULL_PTR_ARG(1)
ATTR_ALIAS(CDC_Device_Event_Stub);
#endif
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,53 @@
/*
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_DEVICE)
#include "../Device.h"
void USB_Device_SendRemoteWakeup(void)
{
if (!(USB_Options & USB_OPT_MANUAL_PLL))
{
USB_PLL_On();
while (!(USB_PLL_IsReady()));
}
USB_CLK_Unfreeze();
UDCON |= (1 << RMWKUP);
while (UDCON & (1 << RMWKUP));
}
#endif

View File

@ -0,0 +1,264 @@
/*
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.
*/
/** \file
* \brief USB Device definitions for the AVR8 microcontrollers.
* \copydetails Group_Device_AVR8
*
* \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.
*/
/** \ingroup Group_Device
* \defgroup Group_Device_AVR8 Device Management (AVR8)
* \brief USB Device definitions for the AVR8 microcontrollers.
*
* Architecture specific USB Device definitions for the Atmel 8-bit AVR microcontrollers.
*
* @{
*/
#ifndef __USBDEVICE_AVR8_H__
#define __USBDEVICE_AVR8_H__
/* Includes: */
#include "../../../../Common/Common.h"
#include "../USBController.h"
#include "../StdDescriptors.h"
#include "../USBInterrupt.h"
#include "../Endpoint.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
#if (defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS))
#error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
#endif
#if (defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS))
#error USE_FLASH_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
#endif
#if (defined(USE_FLASH_DESCRIPTORS) && defined(USE_RAM_DESCRIPTORS))
#error USE_FLASH_DESCRIPTORS and USE_RAM_DESCRIPTORS are mutually exclusive.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** \name USB Device Mode Option Masks */
//@{
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
/** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
* USB interface should be initialized in low speed (1.5Mb/s) mode.
*
* \note Low Speed mode is not available on all USB AVR models.
* \n
*
* \note Restrictions apply on the number, size and type of endpoints which can be used
* when running in low speed mode - refer to the USB 2.0 specification.
*/
#define USB_DEVICE_OPT_LOWSPEED (1 << 0)
#endif
/** Mask for the Options parameter of the \ref USB_Init() function. This indicates that the
* USB interface should be initialized in full speed (12Mb/s) mode.
*/
#define USB_DEVICE_OPT_FULLSPEED (0 << 0)
//@}
#if (!defined(NO_INTERNAL_SERIAL) && \
(defined(USB_SERIES_7_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_4_AVR) || \
(defined(USB_SERIES_2_AVR) && (!defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__))) || \
defined(__DOXYGEN__)))
/** String descriptor index for the device's unique serial number string descriptor within the device.
* This unique serial number is used by the host to associate resources to the device (such as drivers or COM port
* number allocations) to a device regardless of the port it is plugged in to on the host. Some microcontrollers contain
* a unique serial number internally, and setting the device descriptors serial number string index to this value
* will cause it to use the internal serial number.
*
* On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
* number for the device.
*/
#define USE_INTERNAL_SERIAL 0xDC
/** Length of the device's unique internal serial number, in bits, if present on the selected microcontroller
* model.
*/
#define INTERNAL_SERIAL_LENGTH_BITS 80
/** Start address of the internal serial number, in the appropriate address space, if present on the selected microcontroller
* model.
*/
#define INTERNAL_SERIAL_START_ADDRESS 0x0E
#else
#define USE_INTERNAL_SERIAL NO_DESCRIPTOR
#define INTERNAL_SERIAL_LENGTH_BITS 0
#define INTERNAL_SERIAL_START_ADDRESS 0
#endif
/* Function Prototypes: */
/** Sends a Remote Wakeup request to the host. This signals to the host that the device should
* be taken out of suspended mode, and communications should resume.
*
* Typically, this is implemented so that HID devices (mice, keyboards, etc.) can wake up the
* host computer when the host has suspended all USB devices to enter a low power state.
*
* \note This macro should only be used if the device has indicated to the host that it
* supports the Remote Wakeup feature in the device descriptors, and should only be
* issued if the host is currently allowing remote wakeup events from the device (i.e.,
* the \ref USB_Device_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP
* compile time option is used, this macro is unavailable.
* \n\n
*
* \note The USB clock must be running for this function to operate. If the stack is initialized with
* the \ref USB_OPT_MANUAL_PLL option enabled, the user must ensure that the PLL is running
* before attempting to call this function.
*
* \see \ref Group_StdDescriptors for more information on the RMWAKEUP feature and device descriptors.
*/
void USB_Device_SendRemoteWakeup(void);
/* Inline Functions: */
/** Returns the current USB frame number, when in device mode. Every millisecond the USB bus is active (i.e. enumerated to a host)
* the frame number is incremented by one.
*
* \return Current USB frame number from the USB controller.
*/
static inline uint16_t USB_Device_GetFrameNumber(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline uint16_t USB_Device_GetFrameNumber(void)
{
return UDFNUM;
}
#if !defined(NO_SOF_EVENTS)
/** Enables the device mode Start Of Frame events. When enabled, this causes the
* \ref EVENT_USB_Device_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
* at the start of each USB frame when enumerated in device mode.
*
* \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
*/
static inline void USB_Device_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
static inline void USB_Device_EnableSOFEvents(void)
{
USB_INT_Enable(USB_INT_SOFI);
}
/** Disables the device mode Start Of Frame events. When disabled, this stops the firing of the
* \ref EVENT_USB_Device_StartOfFrame() event when enumerated in device mode.
*
* \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
*/
static inline void USB_Device_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
static inline void USB_Device_DisableSOFEvents(void)
{
USB_INT_Disable(USB_INT_SOFI);
}
#endif
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Inline Functions: */
#if defined(USB_DEVICE_OPT_LOWSPEED)
static inline void USB_Device_SetLowSpeed(void) ATTR_ALWAYS_INLINE;
static inline void USB_Device_SetLowSpeed(void)
{
UDCON |= (1 << LSM);
}
static inline void USB_Device_SetFullSpeed(void) ATTR_ALWAYS_INLINE;
static inline void USB_Device_SetFullSpeed(void)
{
UDCON &= ~(1 << LSM);
}
#endif
static inline void USB_Device_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
static inline void USB_Device_SetDeviceAddress(const uint8_t Address)
{
uint8_t Temp = (UDADDR & (1 << ADDEN)) | (Address & 0x7F);
UDADDR = Temp;
UDADDR = Temp | (1 << ADDEN);
}
static inline bool USB_Device_IsAddressSet(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline bool USB_Device_IsAddressSet(void)
{
return (UDADDR & (1 << ADDEN));
}
#if (USE_INTERNAL_SERIAL != NO_DESCRIPTOR)
static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString) ATTR_NON_NULL_PTR_ARG(1);
static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString)
{
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
GlobalInterruptDisable();
uint8_t SigReadAddress = INTERNAL_SERIAL_START_ADDRESS;
for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++)
{
uint8_t SerialByte = boot_signature_byte_get(SigReadAddress);
if (SerialCharNum & 0x01)
{
SerialByte >>= 4;
SigReadAddress++;
}
SerialByte &= 0x0F;
UnicodeString[SerialCharNum] = cpu_to_le16((SerialByte >= 10) ?
(('A' - 10) + SerialByte) : ('0' + SerialByte));
}
SetGlobalInterruptMask(CurrentGlobalInt);
}
#endif
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,270 @@
/*
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_DEVICE)
#include "EndpointStream_AVR8.h"
#if !defined(CONTROL_ONLY_DEVICE)
uint8_t Endpoint_Discard_Stream(uint16_t Length,
uint16_t* const BytesProcessed)
{
uint8_t ErrorCode;
uint16_t BytesInTransfer = 0;
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
if (BytesProcessed != NULL)
Length -= *BytesProcessed;
while (Length)
{
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearOUT();
if (BytesProcessed != NULL)
{
*BytesProcessed += BytesInTransfer;
return ENDPOINT_RWSTREAM_IncompleteTransfer;
}
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
else
{
Endpoint_Discard_8();
Length--;
BytesInTransfer++;
}
}
return ENDPOINT_RWSTREAM_NoError;
}
uint8_t Endpoint_Null_Stream(uint16_t Length,
uint16_t* const BytesProcessed)
{
uint8_t ErrorCode;
uint16_t BytesInTransfer = 0;
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
if (BytesProcessed != NULL)
Length -= *BytesProcessed;
while (Length)
{
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearIN();
if (BytesProcessed != NULL)
{
*BytesProcessed += BytesInTransfer;
return ENDPOINT_RWSTREAM_IncompleteTransfer;
}
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
else
{
Endpoint_Write_8(0);
Length--;
BytesInTransfer++;
}
}
return ENDPOINT_RWSTREAM_NoError;
}
/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations,
* so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */
#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE
#define TEMPLATE_BUFFER_TYPE void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE
#define TEMPLATE_BUFFER_TYPE void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
#include "Template/Template_Endpoint_RW.c"
#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)
#define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
#include "Template/Template_Endpoint_RW.c"
#endif
#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)
#define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE
#define TEMPLATE_BUFFER_TYPE void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE
#define TEMPLATE_BUFFER_TYPE void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
#include "Template/Template_Endpoint_RW.c"
#endif
#endif
#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
#include "Template/Template_Endpoint_Control_W.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(*BufferPtr)
#include "Template/Template_Endpoint_Control_W.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
#include "Template/Template_Endpoint_Control_R.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_8()
#include "Template/Template_Endpoint_Control_R.c"
#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE)
#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
#include "Template/Template_Endpoint_Control_W.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(pgm_read_byte(BufferPtr))
#include "Template/Template_Endpoint_Control_W.c"
#endif
#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE)
#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
#include "Template/Template_Endpoint_Control_W.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_8(eeprom_read_byte(BufferPtr))
#include "Template/Template_Endpoint_Control_W.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
#include "Template/Template_Endpoint_Control_R.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_8())
#include "Template/Template_Endpoint_Control_R.c"
#endif
#endif

View File

@ -0,0 +1,648 @@
/*
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.
*/
/** \file
* \brief Endpoint data stream transmission and reception management for the AVR8 microcontrollers.
* \copydetails Group_EndpointStreamRW_AVR8
*
* \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.
*/
/** \ingroup Group_EndpointStreamRW
* \defgroup Group_EndpointStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8)
* \brief Endpoint data stream transmission and reception management for the Atmel AVR8 architecture.
*
* Functions, macros, variables, enums and types related to data reading and writing of data streams from
* and to endpoints.
*
* @{
*/
#ifndef __ENDPOINT_STREAM_AVR8_H__
#define __ENDPOINT_STREAM_AVR8_H__
/* Includes: */
#include "../../../../Common/Common.h"
#include "../USBMode.h"
#include "../USBTask.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Function Prototypes: */
/** \name Stream functions for null data */
//@{
/** Reads and discards the given number of bytes from the currently selected endpoint's bank,
* discarding fully read packets from the host as needed. The last packet is not automatically
* discarded once the remaining bytes has been read; the user is responsible for manually
* discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
*
* If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
* failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
* storage location, the transfer will instead be performed as a series of chunks. Each time
* the endpoint bank becomes empty while there is still data to process (and after the current
* packet has been acknowledged) the BytesProcessed location will be updated with the total number
* of bytes processed in the stream, and the function will exit with an error code of
* \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
* in the user code - to continue the transfer, call the function again with identical parameters
* and it will resume until the BytesProcessed value reaches the total transfer length.
*
* <b>Single Stream Transfer Example:</b>
* \code
* uint8_t ErrorCode;
*
* if ((ErrorCode = Endpoint_Discard_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* <b>Partial Stream Transfers Example:</b>
* \code
* uint8_t ErrorCode;
* uint16_t BytesProcessed;
*
* BytesProcessed = 0;
* while ((ErrorCode = Endpoint_Discard_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
* {
* // Stream not yet complete - do other actions here, abort if required
* }
*
* if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* \note This routine should not be used on CONTROL type endpoints.
*
* \param[in] Length Number of bytes to discard via the currently selected endpoint.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
* transaction should be updated, \c NULL if the entire stream should be read at once.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Discard_Stream(uint16_t Length,
uint16_t* const BytesProcessed);
/** Writes a given number of zeroed bytes to the currently selected endpoint's bank, sending
* full packets to the host as needed. The last packet is not automatically sent once the
* remaining bytes have been written; the user is responsible for manually sending the last
* packet to the host via the \ref Endpoint_ClearIN() macro.
*
* If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
* failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
* storage location, the transfer will instead be performed as a series of chunks. Each time
* the endpoint bank becomes full while there is still data to process (and after the current
* packet transmission has been initiated) the BytesProcessed location will be updated with the
* total number of bytes processed in the stream, and the function will exit with an error code of
* \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
* in the user code - to continue the transfer, call the function again with identical parameters
* and it will resume until the BytesProcessed value reaches the total transfer length.
*
* <b>Single Stream Transfer Example:</b>
* \code
* uint8_t ErrorCode;
*
* if ((ErrorCode = Endpoint_Null_Stream(512, NULL)) != ENDPOINT_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* <b>Partial Stream Transfers Example:</b>
* \code
* uint8_t ErrorCode;
* uint16_t BytesProcessed;
*
* BytesProcessed = 0;
* while ((ErrorCode = Endpoint_Null_Stream(512, &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
* {
* // Stream not yet complete - do other actions here, abort if required
* }
*
* if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* \note This routine should not be used on CONTROL type endpoints.
*
* \param[in] Length Number of zero bytes to send via the currently selected endpoint.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
* transaction should be updated, \c NULL if the entire stream should be read at once.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Null_Stream(uint16_t Length,
uint16_t* const BytesProcessed);
//@}
/** \name Stream functions for RAM source/destination data */
//@{
/** Writes the given number of bytes to the endpoint from the given buffer in little endian,
* sending full packets to the host as needed. The last packet filled is not automatically sent;
* the user is responsible for manually sending the last written packet to the host via the
* \ref Endpoint_ClearIN() macro.
*
* If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
* failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
* storage location, the transfer will instead be performed as a series of chunks. Each time
* the endpoint bank becomes full while there is still data to process (and after the current
* packet transmission has been initiated) the BytesProcessed location will be updated with the
* total number of bytes processed in the stream, and the function will exit with an error code of
* \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
* in the user code - to continue the transfer, call the function again with identical parameters
* and it will resume until the BytesProcessed value reaches the total transfer length.
*
* <b>Single Stream Transfer Example:</b>
* \code
* uint8_t DataStream[512];
* uint8_t ErrorCode;
*
* if ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),
* NULL)) != ENDPOINT_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* <b>Partial Stream Transfers Example:</b>
* \code
* uint8_t DataStream[512];
* uint8_t ErrorCode;
* uint16_t BytesProcessed;
*
* BytesProcessed = 0;
* while ((ErrorCode = Endpoint_Write_Stream_LE(DataStream, sizeof(DataStream),
* &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
* {
* // Stream not yet complete - do other actions here, abort if required
* }
*
* if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* \note This routine should not be used on CONTROL type endpoints.
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
* transaction should be updated, \c NULL if the entire stream should be written at once.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Write_Stream_LE(const void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** Writes the given number of bytes to the endpoint from the given buffer in big endian,
* sending full packets to the host as needed. The last packet filled is not automatically sent;
* the user is responsible for manually sending the last written packet to the host via the
* \ref Endpoint_ClearIN() macro.
*
* \note This routine should not be used on CONTROL type endpoints.
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
* transaction should be updated, \c NULL if the entire stream should be written at once.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Write_Stream_BE(const void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** Reads the given number of bytes from the endpoint from the given buffer in little endian,
* discarding fully read packets from the host as needed. The last packet is not automatically
* discarded once the remaining bytes has been read; the user is responsible for manually
* discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
*
* If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
* failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
* storage location, the transfer will instead be performed as a series of chunks. Each time
* the endpoint bank becomes empty while there is still data to process (and after the current
* packet has been acknowledged) the BytesProcessed location will be updated with the total number
* of bytes processed in the stream, and the function will exit with an error code of
* \ref ENDPOINT_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
* in the user code - to continue the transfer, call the function again with identical parameters
* and it will resume until the BytesProcessed value reaches the total transfer length.
*
* <b>Single Stream Transfer Example:</b>
* \code
* uint8_t DataStream[512];
* uint8_t ErrorCode;
*
* if ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),
* NULL)) != ENDPOINT_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* <b>Partial Stream Transfers Example:</b>
* \code
* uint8_t DataStream[512];
* uint8_t ErrorCode;
* uint16_t BytesProcessed;
*
* BytesProcessed = 0;
* while ((ErrorCode = Endpoint_Read_Stream_LE(DataStream, sizeof(DataStream),
* &BytesProcessed)) == ENDPOINT_RWSTREAM_IncompleteTransfer)
* {
* // Stream not yet complete - do other actions here, abort if required
* }
*
* if (ErrorCode != ENDPOINT_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* \note This routine should not be used on CONTROL type endpoints.
*
* \param[out] Buffer Pointer to the destination data buffer to write to.
* \param[in] Length Number of bytes to send via the currently selected endpoint.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
* transaction should be updated, \c NULL if the entire stream should be read at once.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Read_Stream_LE(void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** Reads the given number of bytes from the endpoint from the given buffer in big endian,
* discarding fully read packets from the host as needed. The last packet is not automatically
* discarded once the remaining bytes has been read; the user is responsible for manually
* discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro.
*
* \note This routine should not be used on CONTROL type endpoints.
*
* \param[out] Buffer Pointer to the destination data buffer to write to.
* \param[in] Length Number of bytes to send via the currently selected endpoint.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
* transaction should be updated, \c NULL if the entire stream should be read at once.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Read_Stream_BE(void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,
* sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
* in both failure and success states; the user is responsible for manually clearing the setup OUT to
* finalize the transfer via the \ref Endpoint_ClearOUT() macro.
*
* \note This function automatically clears the control transfer's status stage. Do not manually attempt
* to clear the status stage when using this routine in a control transaction.
* \n\n
*
* \note This routine should only be used on CONTROL type endpoints.
*
* \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
* together; i.e. the entire stream data must be read or written at the one time.
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
*
* \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Write_Control_Stream_LE(const void* const Buffer,
uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
/** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,
* sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
* in both failure and success states; the user is responsible for manually clearing the setup OUT to
* finalize the transfer via the \ref Endpoint_ClearOUT() macro.
*
* \note This function automatically clears the control transfer's status stage. Do not manually attempt
* to clear the status stage when using this routine in a control transaction.
* \n\n
*
* \note This routine should only be used on CONTROL type endpoints.
*
* \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
* together; i.e. the entire stream data must be read or written at the one time.
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
*
* \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Write_Control_Stream_BE(const void* const Buffer,
uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
/** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,
* discarding fully read packets from the host as needed. The device IN acknowledgement is not
* automatically sent after success or failure states; the user is responsible for manually sending the
* setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
*
* \note This function automatically clears the control transfer's status stage. Do not manually attempt
* to clear the status stage when using this routine in a control transaction.
* \n\n
*
* \note This routine should only be used on CONTROL type endpoints.
*
* \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
* together; i.e. the entire stream data must be read or written at the one time.
*
* \param[out] Buffer Pointer to the destination data buffer to write to.
* \param[in] Length Number of bytes to send via the currently selected endpoint.
*
* \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Read_Control_Stream_LE(void* const Buffer,
uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
/** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,
* discarding fully read packets from the host as needed. The device IN acknowledgement is not
* automatically sent after success or failure states; the user is responsible for manually sending the
* setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
*
* \note This function automatically clears the control transfer's status stage. Do not manually attempt
* to clear the status stage when using this routine in a control transaction.
* \n\n
*
* \note This routine should only be used on CONTROL type endpoints.
*
* \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
* together; i.e. the entire stream data must be read or written at the one time.
*
* \param[out] Buffer Pointer to the destination data buffer to write to.
* \param[in] Length Number of bytes to send via the currently selected endpoint.
*
* \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Read_Control_Stream_BE(void* const Buffer,
uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
//@}
/** \name Stream functions for EEPROM source/destination data */
//@{
/** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE().
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
* transaction should be updated, \c NULL if the entire stream should be written at once.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Write_EStream_LE(const void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE().
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
* transaction should be updated, \c NULL if the entire stream should be written at once.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Write_EStream_BE(const void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** EEPROM buffer destination version of \ref Endpoint_Read_Stream_LE().
*
* \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
* \param[in] Length Number of bytes to send via the currently selected endpoint.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
* transaction should be updated, \c NULL if the entire stream should be read at once.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Read_EStream_LE(void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** EEPROM buffer destination version of \ref Endpoint_Read_Stream_BE().
*
* \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
* \param[in] Length Number of bytes to send via the currently selected endpoint.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
* transaction should be updated, \c NULL if the entire stream should be read at once.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Read_EStream_BE(void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE.
*
* \note This function automatically clears the control transfer's status stage. Do not manually attempt
* to clear the status stage when using this routine in a control transaction.
* \n\n
*
* \note This routine should only be used on CONTROL type endpoints.
* \n\n
*
* \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
* together; i.e. the entire stream data must be read or written at the one time.
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
*
* \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Write_Control_EStream_LE(const void* const Buffer,
uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
/** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE().
*
* \note This function automatically clears the control transfer's status stage. Do not manually attempt
* to clear the status stage when using this routine in a control transaction.
* \n\n
*
* \note This routine should only be used on CONTROL type endpoints.
* \n\n
*
* \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
* together; i.e. the entire stream data must be read or written at the one time.
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
*
* \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Write_Control_EStream_BE(const void* const Buffer,
uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
/** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE().
*
* \note This function automatically clears the control transfer's status stage. Do not manually attempt
* to clear the status stage when using this routine in a control transaction.
* \n\n
*
* \note This routine should only be used on CONTROL type endpoints.
* \n\n
*
* \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
* together; i.e. the entire stream data must be read or written at the one time.
*
* \param[out] Buffer Pointer to the destination data buffer to write to.
* \param[in] Length Number of bytes to send via the currently selected endpoint.
*
* \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Read_Control_EStream_LE(void* const Buffer,
uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
/** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE().
*
* \note This function automatically clears the control transfer's status stage. Do not manually attempt
* to clear the status stage when using this routine in a control transaction.
* \n\n
*
* \note This routine should only be used on CONTROL type endpoints.
* \n\n
*
* \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
* together; i.e. the entire stream data must be read or written at the one time.
*
* \param[out] Buffer Pointer to the destination data buffer to write to.
* \param[in] Length Number of bytes to send via the currently selected endpoint.
*
* \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Read_Control_EStream_BE(void* const Buffer,
uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
//@}
/** \name Stream functions for PROGMEM source/destination data */
//@{
/** FLASH buffer source version of \ref Endpoint_Write_Stream_LE().
*
* \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
* transaction should be updated, \c NULL if the entire stream should be written at once.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Write_PStream_LE(const void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** FLASH buffer source version of \ref Endpoint_Write_Stream_BE().
*
* \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes processed in the current
* transaction should be updated, \c NULL if the entire stream should be written at once.
*
* \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Write_PStream_BE(const void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE().
*
* \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
*
* \note This function automatically clears the control transfer's status stage. Do not manually attempt
* to clear the status stage when using this routine in a control transaction.
* \n\n
*
* \note This routine should only be used on CONTROL type endpoints.
* \n\n
*
* \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
* together; i.e. the entire stream data must be read or written at the one time.
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
*
* \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Write_Control_PStream_LE(const void* const Buffer,
uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
/** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE().
*
* \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
*
* \note This function automatically clears the control transfer's status stage. Do not manually attempt
* to clear the status stage when using this routine in a control transaction.
* \n\n
*
* \note This routine should only be used on CONTROL type endpoints.
* \n\n
*
* \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
* together; i.e. the entire stream data must be read or written at the one time.
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
*
* \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
*/
uint8_t Endpoint_Write_Control_PStream_BE(const void* const Buffer,
uint16_t Length) ATTR_NON_NULL_PTR_ARG(1);
//@}
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,182 @@
/*
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_DEVICE)
#include "../Endpoint.h"
#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
uint8_t USB_Device_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
#endif
bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
const uint8_t UECFG0XData,
const uint8_t UECFG1XData)
{
#if defined(CONTROL_ONLY_DEVICE) || defined(ORDERED_EP_CONFIG)
Endpoint_SelectEndpoint(Number);
Endpoint_EnableEndpoint();
UECFG1X = 0;
UECFG0X = UECFG0XData;
UECFG1X = UECFG1XData;
return Endpoint_IsConfigured();
#else
for (uint8_t EPNum = Number; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++)
{
uint8_t UECFG0XTemp;
uint8_t UECFG1XTemp;
uint8_t UEIENXTemp;
Endpoint_SelectEndpoint(EPNum);
if (EPNum == Number)
{
UECFG0XTemp = UECFG0XData;
UECFG1XTemp = UECFG1XData;
UEIENXTemp = 0;
}
else
{
UECFG0XTemp = UECFG0X;
UECFG1XTemp = UECFG1X;
UEIENXTemp = UEIENX;
}
if (!(UECFG1XTemp & (1 << ALLOC)))
continue;
Endpoint_DisableEndpoint();
UECFG1X &= ~(1 << ALLOC);
Endpoint_EnableEndpoint();
UECFG0X = UECFG0XTemp;
UECFG1X = UECFG1XTemp;
UEIENX = UEIENXTemp;
if (!(Endpoint_IsConfigured()))
return false;
}
Endpoint_SelectEndpoint(Number);
return true;
#endif
}
void Endpoint_ClearEndpoints(void)
{
UEINT = 0;
for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++)
{
Endpoint_SelectEndpoint(EPNum);
UEIENX = 0;
UEINTX = 0;
UECFG1X = 0;
Endpoint_DisableEndpoint();
}
}
void Endpoint_ClearStatusStage(void)
{
if (USB_ControlRequest.bmRequestType & REQDIR_DEVICETOHOST)
{
while (!(Endpoint_IsOUTReceived()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
Endpoint_ClearOUT();
}
else
{
while (!(Endpoint_IsINReady()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
Endpoint_ClearIN();
}
}
#if !defined(CONTROL_ONLY_DEVICE)
uint8_t Endpoint_WaitUntilReady(void)
{
#if (USB_STREAM_TIMEOUT_MS < 0xFF)
uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
#else
uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
#endif
uint16_t PreviousFrameNumber = USB_Device_GetFrameNumber();
for (;;)
{
if (Endpoint_GetEndpointDirection() == ENDPOINT_DIR_IN)
{
if (Endpoint_IsINReady())
return ENDPOINT_READYWAIT_NoError;
}
else
{
if (Endpoint_IsOUTReceived())
return ENDPOINT_READYWAIT_NoError;
}
uint8_t USB_DeviceState_LCL = USB_DeviceState;
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
return ENDPOINT_READYWAIT_DeviceDisconnected;
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
return ENDPOINT_READYWAIT_BusSuspended;
else if (Endpoint_IsStalled())
return ENDPOINT_READYWAIT_EndpointStalled;
uint16_t CurrentFrameNumber = USB_Device_GetFrameNumber();
if (CurrentFrameNumber != PreviousFrameNumber)
{
PreviousFrameNumber = CurrentFrameNumber;
if (!(TimeoutMSRem--))
return ENDPOINT_READYWAIT_Timeout;
}
}
}
#endif
#endif

View File

@ -0,0 +1,873 @@
/*
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.
*/
/** \file
* \brief USB Endpoint definitions for the AVR8 microcontrollers.
* \copydetails Group_EndpointManagement_AVR8
*
* \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.
*/
/** \ingroup Group_EndpointRW
* \defgroup Group_EndpointRW_AVR8 Endpoint Data Reading and Writing (AVR8)
* \brief Endpoint data read/write definitions for the Atmel AVR8 architecture.
*
* Functions, macros, variables, enums and types related to data reading and writing from and to endpoints.
*/
/** \ingroup Group_EndpointPrimitiveRW
* \defgroup Group_EndpointPrimitiveRW_AVR8 Read/Write of Primitive Data Types (AVR8)
* \brief Endpoint primitive read/write definitions for the Atmel AVR8 architecture.
*
* Functions, macros, variables, enums and types related to data reading and writing of primitive data types
* from and to endpoints.
*/
/** \ingroup Group_EndpointPacketManagement
* \defgroup Group_EndpointPacketManagement_AVR8 Endpoint Packet Management (AVR8)
* \brief Endpoint packet management definitions for the Atmel AVR8 architecture.
*
* Functions, macros, variables, enums and types related to packet management of endpoints.
*/
/** \ingroup Group_EndpointManagement
* \defgroup Group_EndpointManagement_AVR8 Endpoint Management (AVR8)
* \brief Endpoint management definitions for the Atmel AVR8 architecture.
*
* Functions, macros and enums related to endpoint management when in USB Device mode. This
* module contains the endpoint management macros, as well as endpoint interrupt and data
* send/receive functions for various data types.
*
* @{
*/
#ifndef __ENDPOINT_AVR8_H__
#define __ENDPOINT_AVR8_H__
/* Includes: */
#include "../../../../Common/Common.h"
#include "../USBTask.h"
#include "../USBInterrupt.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Macros: */
#define _ENDPOINT_GET_MAXSIZE(EPIndex) _ENDPOINT_GET_MAXSIZE2(ENDPOINT_DETAILS_EP ## EPIndex)
#define _ENDPOINT_GET_MAXSIZE2(EPDetails) _ENDPOINT_GET_MAXSIZE3(EPDetails)
#define _ENDPOINT_GET_MAXSIZE3(MaxSize, Banks) (MaxSize)
#define _ENDPOINT_GET_BANKS(EPIndex) _ENDPOINT_GET_BANKS2(ENDPOINT_DETAILS_EP ## EPIndex)
#define _ENDPOINT_GET_BANKS2(EPDetails) _ENDPOINT_GET_BANKS3(EPDetails)
#define _ENDPOINT_GET_BANKS3(MaxSize, Banks) (Banks)
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
#define ENDPOINT_DETAILS_MAXEP 7
#define ENDPOINT_DETAILS_EP0 64, 1
#define ENDPOINT_DETAILS_EP1 256, 2
#define ENDPOINT_DETAILS_EP2 64, 2
#define ENDPOINT_DETAILS_EP3 64, 2
#define ENDPOINT_DETAILS_EP4 64, 2
#define ENDPOINT_DETAILS_EP5 64, 2
#define ENDPOINT_DETAILS_EP6 64, 2
#else
#define ENDPOINT_DETAILS_MAXEP 5
#define ENDPOINT_DETAILS_EP0 64, 1
#define ENDPOINT_DETAILS_EP1 64, 1
#define ENDPOINT_DETAILS_EP2 64, 1
#define ENDPOINT_DETAILS_EP3 64, 2
#define ENDPOINT_DETAILS_EP4 64, 2
#endif
/* Inline Functions: */
static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST
ATTR_ALWAYS_INLINE;
static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes)
{
uint8_t MaskVal = 0;
uint16_t CheckBytes = 8;
while (CheckBytes < Bytes)
{
MaskVal++;
CheckBytes <<= 1;
}
return (MaskVal << EPSIZE0);
}
/* Function Prototypes: */
void Endpoint_ClearEndpoints(void);
bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
const uint8_t UECFG0XData,
const uint8_t UECFG1XData);
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** \name Endpoint Bank Mode Masks */
//@{
/** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
* that the endpoint should have one single bank, which requires less USB FIFO memory but results
* in slower transfers as only one USB device (the AVR or the host) can access the endpoint's
* bank at the one time.
*/
#define ENDPOINT_BANK_SINGLE (0 << EPBK0)
/** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
* that the endpoint should have two banks, which requires more USB FIFO memory but results
* in faster transfers as one USB device (the AVR or the host) can access one bank while the other
* accesses the second bank.
*/
#define ENDPOINT_BANK_DOUBLE (1 << EPBK0)
//@}
#if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
/** Default size of the default control endpoint's bank, until altered by the control endpoint bank size
* value in the device descriptor. Not available if the \c FIXED_CONTROL_ENDPOINT_SIZE token is defined.
*/
#define ENDPOINT_CONTROLEP_DEFAULT_SIZE 8
#endif
/** Retrieves the maximum bank size in bytes of a given endpoint.
*
* \note This macro will only work correctly on endpoint indexes that are compile-time constants
* defined by the preprocessor.
*
* \param[in] EPIndex Endpoint number, a value between 0 and (\ref ENDPOINT_TOTAL_ENDPOINTS - 1)
*/
#define ENDPOINT_MAX_SIZE(EPIndex) _ENDPOINT_GET_MAXSIZE(EPIndex)
/** Retrieves the total number of banks supported by the given endpoint.
*
* \note This macro will only work correctly on endpoint indexes that are compile-time constants
* defined by the preprocessor.
*
* \param[in] EPIndex Endpoint number, a value between 0 and (\ref ENDPOINT_TOTAL_ENDPOINTS - 1)
*/
#define ENDPOINT_BANKS_SUPPORTED(EPIndex) _ENDPOINT_GET_BANKS(EPIndex)
#if !defined(CONTROL_ONLY_DEVICE) || defined(__DOXYGEN__)
/** Total number of endpoints (including the default control endpoint at address 0) which may
* be used in the device. Different USB AVR models support different amounts of endpoints,
* this value reflects the maximum number of endpoints for the currently selected AVR model.
*/
#define ENDPOINT_TOTAL_ENDPOINTS ENDPOINT_DETAILS_MAXEP
#else
#define ENDPOINT_TOTAL_ENDPOINTS 1
#endif
/* Enums: */
/** Enum for the possible error return codes of the \ref Endpoint_WaitUntilReady() function.
*
* \ingroup Group_EndpointRW_AVR8
*/
enum Endpoint_WaitUntilReady_ErrorCodes_t
{
ENDPOINT_READYWAIT_NoError = 0, /**< Endpoint is ready for next packet, no error. */
ENDPOINT_READYWAIT_EndpointStalled = 1, /**< The endpoint was stalled during the stream
* transfer by the host or device.
*/
ENDPOINT_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while
* waiting for the endpoint to become ready.
*/
ENDPOINT_READYWAIT_BusSuspended = 3, /**< The USB bus has been suspended by the host and
* no USB endpoint traffic can occur until the bus
* has resumed.
*/
ENDPOINT_READYWAIT_Timeout = 4, /**< The host failed to accept or send the next packet
* within the software timeout period set by the
* \ref USB_STREAM_TIMEOUT_MS macro.
*/
};
/* Inline Functions: */
/** Configures the specified endpoint number with the given endpoint type, direction, bank size
* and banking mode. Once configured, the endpoint may be read from or written to, depending
* on its direction.
*
* \param[in] Number Endpoint number to configure. This must be more than 0 and less than
* \ref ENDPOINT_TOTAL_ENDPOINTS.
*
* \param[in] Type Type of endpoint to configure, a \c EP_TYPE_* mask. Not all endpoint types
* are available on Low Speed USB devices - refer to the USB 2.0 specification.
*
* \param[in] Direction Endpoint data direction, either \ref ENDPOINT_DIR_OUT or \ref ENDPOINT_DIR_IN.
* All endpoints (except Control type) are unidirectional - data may only be read
* from or written to the endpoint bank based on its direction, not both.
*
* \param[in] Size Size of the endpoint's bank, where packets are stored before they are transmitted
* to the USB host, or after they have been received from the USB host (depending on
* the endpoint's data direction). The bank size must indicate the maximum packet size
* that the endpoint can handle.
*
* \param[in] Banks Number of banks to use for the endpoint being configured, an \c ENDPOINT_BANK_* mask.
* More banks uses more USB DPRAM, but offers better performance. Isochronous type
* endpoints <b>must</b> have at least two banks.
*
* \note When the \c ORDERED_EP_CONFIG compile time option is used, Endpoints <b>must</b> be configured in
* ascending order, or bank corruption will occur.
* \n\n
*
* \note Different endpoints may have different maximum packet sizes based on the endpoint's index - refer to
* the chosen microcontroller model's datasheet to determine the maximum bank size for each endpoint.
* \n\n
*
* \note The default control endpoint should not be manually configured by the user application, as
* it is automatically configured by the library internally.
* \n\n
*
* \note This routine will automatically select the specified endpoint upon success. Upon failure, the endpoint
* which failed to reconfigure correctly will be selected.
*
* \return Boolean \c true if the configuration succeeded, \c false otherwise.
*/
static inline bool Endpoint_ConfigureEndpoint(const uint8_t Number,
const uint8_t Type,
const uint8_t Direction,
const uint16_t Size,
const uint8_t Banks) ATTR_ALWAYS_INLINE;
static inline bool Endpoint_ConfigureEndpoint(const uint8_t Number,
const uint8_t Type,
const uint8_t Direction,
const uint16_t Size,
const uint8_t Banks)
{
return Endpoint_ConfigureEndpoint_Prv(Number, ((Type << EPTYPE0) | (Direction ? (1 << EPDIR) : 0)),
((1 << ALLOC) | Banks | Endpoint_BytesToEPSizeMask(Size)));
}
/** Indicates the number of bytes currently stored in the current endpoint's selected bank.
*
* \note The return width of this function may differ, depending on the maximum endpoint bank size
* of the selected AVR model.
*
* \ingroup Group_EndpointRW_AVR8
*
* \return Total number of bytes in the currently selected Endpoint's FIFO buffer.
*/
static inline uint16_t Endpoint_BytesInEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint16_t Endpoint_BytesInEndpoint(void)
{
#if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
return UEBCX;
#elif defined(USB_SERIES_4_AVR)
return (((uint16_t)UEBCHX << 8) | UEBCLX);
#elif defined(USB_SERIES_2_AVR)
return UEBCLX;
#endif
}
/** Get the endpoint address of the currently selected endpoint. This is typically used to save
* the currently selected endpoint number so that it can be restored after another endpoint has
* been manipulated.
*
* \return Index of the currently selected endpoint.
*/
static inline uint8_t Endpoint_GetCurrentEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Endpoint_GetCurrentEndpoint(void)
{
#if !defined(CONTROL_ONLY_DEVICE)
return (UENUM & ENDPOINT_EPNUM_MASK);
#else
return ENDPOINT_CONTROLEP;
#endif
}
/** Selects the given endpoint number. If the address from the device descriptors is used, the
* value should be masked with the \ref ENDPOINT_EPNUM_MASK constant to extract only the endpoint
* number (and discarding the endpoint direction bit).
*
* Any endpoint operations which do not require the endpoint number to be indicated will operate on
* the currently selected endpoint.
*
* \param[in] EndpointNumber Endpoint number to select.
*/
static inline void Endpoint_SelectEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
static inline void Endpoint_SelectEndpoint(const uint8_t EndpointNumber)
{
#if !defined(CONTROL_ONLY_DEVICE)
UENUM = EndpointNumber;
#endif
}
/** Resets the endpoint bank FIFO. This clears all the endpoint banks and resets the USB controller's
* data In and Out pointers to the bank's contents.
*
* \param[in] EndpointNumber Endpoint number whose FIFO buffers are to be reset.
*/
static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ResetEndpoint(const uint8_t EndpointNumber)
{
UERST = (1 << EndpointNumber);
UERST = 0;
}
/** Enables the currently selected endpoint so that data can be sent and received through it to
* and from a host.
*
* \note Endpoints must first be configured properly via \ref Endpoint_ConfigureEndpoint().
*/
static inline void Endpoint_EnableEndpoint(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_EnableEndpoint(void)
{
UECONX |= (1 << EPEN);
}
/** Disables the currently selected endpoint so that data cannot be sent and received through it
* to and from a host.
*/
static inline void Endpoint_DisableEndpoint(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_DisableEndpoint(void)
{
UECONX &= ~(1 << EPEN);
}
/** Determines if the currently selected endpoint is enabled, but not necessarily configured.
*
* \return Boolean \c true if the currently selected endpoint is enabled, \c false otherwise.
*/
static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsEnabled(void)
{
return ((UECONX & (1 << EPEN)) ? true : false);
}
/** Retrieves the number of busy banks in the currently selected endpoint, which have been queued for
* transmission via the \ref Endpoint_ClearIN() command, or are awaiting acknowledgement via the
* \ref Endpoint_ClearOUT() command.
*
* \ingroup Group_EndpointPacketManagement_AVR8
*
* \return Total number of busy banks in the selected endpoint.
*/
static inline uint8_t Endpoint_GetBusyBanks(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline uint8_t Endpoint_GetBusyBanks(void)
{
return (UESTA0X & (0x03 << NBUSYBK0));
}
/** Aborts all pending IN transactions on the currently selected endpoint, once the bank
* has been queued for transmission to the host via \ref Endpoint_ClearIN(). This function
* will terminate all queued transactions, resetting the endpoint banks ready for a new
* packet.
*
* \ingroup Group_EndpointPacketManagement_AVR8
*/
static inline void Endpoint_AbortPendingIN(void)
{
while (Endpoint_GetBusyBanks() != 0)
{
UEINTX |= (1 << RXOUTI);
while (UEINTX & (1 << RXOUTI));
}
}
/** Determines if the currently selected endpoint may be read from (if data is waiting in the endpoint
* bank and the endpoint is an OUT direction, or if the bank is not yet full if the endpoint is an IN
* direction). This function will return false if an error has occurred in the endpoint, if the endpoint
* is an OUT direction and no packet (or an empty packet) has been received, or if the endpoint is an IN
* direction and the endpoint bank is full.
*
* \ingroup Group_EndpointPacketManagement_AVR8
*
* \return Boolean \c true if the currently selected endpoint may be read from or written to, depending
* on its direction.
*/
static inline bool Endpoint_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsReadWriteAllowed(void)
{
return ((UEINTX & (1 << RWAL)) ? true : false);
}
/** Determines if the currently selected endpoint is configured.
*
* \return Boolean \c true if the currently selected endpoint has been configured, \c false otherwise.
*/
static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsConfigured(void)
{
return ((UESTA0X & (1 << CFGOK)) ? true : false);
}
/** Returns a mask indicating which INTERRUPT type endpoints have interrupted - i.e. their
* interrupt duration has elapsed. Which endpoints have interrupted can be determined by
* masking the return value against <tt>(1 << <i>{Endpoint Number}</i>)</tt>.
*
* \return Mask whose bits indicate which endpoints have interrupted.
*/
static inline uint8_t Endpoint_GetEndpointInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Endpoint_GetEndpointInterrupts(void)
{
return UEINT;
}
/** Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type
* endpoints).
*
* \param[in] EndpointNumber Index of the endpoint whose interrupt flag should be tested.
*
* \return Boolean \c true if the specified endpoint has interrupted, \c false otherwise.
*/
static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber)
{
return ((Endpoint_GetEndpointInterrupts() & (1 << EndpointNumber)) ? true : false);
}
/** Determines if the selected IN endpoint is ready for a new packet to be sent to the host.
*
* \ingroup Group_EndpointPacketManagement_AVR8
*
* \return Boolean \c true if the current endpoint is ready for an IN packet, \c false otherwise.
*/
static inline bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsINReady(void)
{
return ((UEINTX & (1 << TXINI)) ? true : false);
}
/** Determines if the selected OUT endpoint has received new packet from the host.
*
* \ingroup Group_EndpointPacketManagement_AVR8
*
* \return Boolean \c true if current endpoint is has received an OUT packet, \c false otherwise.
*/
static inline bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsOUTReceived(void)
{
return ((UEINTX & (1 << RXOUTI)) ? true : false);
}
/** Determines if the current CONTROL type endpoint has received a SETUP packet.
*
* \ingroup Group_EndpointPacketManagement_AVR8
*
* \return Boolean \c true if the selected endpoint has received a SETUP packet, \c false otherwise.
*/
static inline bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsSETUPReceived(void)
{
return ((UEINTX & (1 << RXSTPI)) ? true : false);
}
/** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the
* endpoint for the next packet.
*
* \ingroup Group_EndpointPacketManagement_AVR8
*
* \note This is not applicable for non CONTROL type endpoints.
*/
static inline void Endpoint_ClearSETUP(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ClearSETUP(void)
{
UEINTX &= ~(1 << RXSTPI);
}
/** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the
* next packet and switching to the alternative endpoint bank if double banked.
*
* \ingroup Group_EndpointPacketManagement_AVR8
*/
static inline void Endpoint_ClearIN(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ClearIN(void)
{
#if !defined(CONTROL_ONLY_DEVICE)
UEINTX &= ~((1 << TXINI) | (1 << FIFOCON));
#else
UEINTX &= ~(1 << TXINI);
#endif
}
/** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint
* for the next packet and switching to the alternative endpoint bank if double banked.
*
* \ingroup Group_EndpointPacketManagement_AVR8
*/
static inline void Endpoint_ClearOUT(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ClearOUT(void)
{
#if !defined(CONTROL_ONLY_DEVICE)
UEINTX &= ~((1 << RXOUTI) | (1 << FIFOCON));
#else
UEINTX &= ~(1 << RXOUTI);
#endif
}
/** Stalls the current endpoint, indicating to the host that a logical problem occurred with the
* indicated endpoint and that the current transfer sequence should be aborted. This provides a
* way for devices to indicate invalid commands to the host so that the current transfer can be
* aborted and the host can begin its own recovery sequence.
*
* The currently selected endpoint remains stalled until either the \ref Endpoint_ClearStall() macro
* is called, or the host issues a CLEAR FEATURE request to the device for the currently selected
* endpoint.
*
* \ingroup Group_EndpointPacketManagement_AVR8
*/
static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_StallTransaction(void)
{
UECONX |= (1 << STALLRQ);
}
/** Clears the STALL condition on the currently selected endpoint.
*
* \ingroup Group_EndpointPacketManagement_AVR8
*/
static inline void Endpoint_ClearStall(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ClearStall(void)
{
UECONX |= (1 << STALLRQC);
}
/** Determines if the currently selected endpoint is stalled, false otherwise.
*
* \ingroup Group_EndpointPacketManagement_AVR8
*
* \return Boolean \c true if the currently selected endpoint is stalled, \c false otherwise.
*/
static inline bool Endpoint_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsStalled(void)
{
return ((UECONX & (1 << STALLRQ)) ? true : false);
}
/** Resets the data toggle of the currently selected endpoint. */
static inline void Endpoint_ResetDataToggle(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ResetDataToggle(void)
{
UECONX |= (1 << RSTDT);
}
/** Determines the currently selected endpoint's direction.
*
* \return The currently selected endpoint's direction, as a \c ENDPOINT_DIR_* mask.
*/
static inline uint8_t Endpoint_GetEndpointDirection(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Endpoint_GetEndpointDirection(void)
{
return (UECFG0X & (1 << EPDIR)) ? ENDPOINT_DIR_IN : ENDPOINT_DIR_OUT;
}
/** Sets the direction of the currently selected endpoint.
*
* \param[in] DirectionMask New endpoint direction, as a \c ENDPOINT_DIR_* mask.
*/
static inline void Endpoint_SetEndpointDirection(const uint8_t DirectionMask) ATTR_ALWAYS_INLINE;
static inline void Endpoint_SetEndpointDirection(const uint8_t DirectionMask)
{
UECFG0X = ((UECFG0X & ~(1 << EPDIR)) | (DirectionMask ? (1 << EPDIR) : 0));
}
/** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints.
*
* \ingroup Group_EndpointPrimitiveRW_AVR8
*
* \return Next byte in the currently selected endpoint's FIFO buffer.
*/
static inline uint8_t Endpoint_Read_8(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Endpoint_Read_8(void)
{
return UEDATX;
}
/** Writes one byte to the currently selected endpoint's bank, for IN direction endpoints.
*
* \ingroup Group_EndpointPrimitiveRW_AVR8
*
* \param[in] Data Data to write into the the currently selected endpoint's FIFO buffer.
*/
static inline void Endpoint_Write_8(const uint8_t Data) ATTR_ALWAYS_INLINE;
static inline void Endpoint_Write_8(const uint8_t Data)
{
UEDATX = Data;
}
/** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints.
*
* \ingroup Group_EndpointPrimitiveRW_AVR8
*/
static inline void Endpoint_Discard_8(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_Discard_8(void)
{
uint8_t Dummy;
Dummy = UEDATX;
(void)Dummy;
}
/** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT
* direction endpoints.
*
* \ingroup Group_EndpointPrimitiveRW_AVR8
*
* \return Next two bytes in the currently selected endpoint's FIFO buffer.
*/
static inline uint16_t Endpoint_Read_16_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint16_t Endpoint_Read_16_LE(void)
{
union
{
uint16_t Value;
uint8_t Bytes[2];
} Data;
Data.Bytes[0] = UEDATX;
Data.Bytes[1] = UEDATX;
return Data.Value;
}
/** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT
* direction endpoints.
*
* \ingroup Group_EndpointPrimitiveRW_AVR8
*
* \return Next two bytes in the currently selected endpoint's FIFO buffer.
*/
static inline uint16_t Endpoint_Read_16_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint16_t Endpoint_Read_16_BE(void)
{
union
{
uint16_t Value;
uint8_t Bytes[2];
} Data;
Data.Bytes[1] = UEDATX;
Data.Bytes[0] = UEDATX;
return Data.Value;
}
/** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN
* direction endpoints.
*
* \ingroup Group_EndpointPrimitiveRW_AVR8
*
* \param[in] Data Data to write to the currently selected endpoint's FIFO buffer.
*/
static inline void Endpoint_Write_16_LE(const uint16_t Data) ATTR_ALWAYS_INLINE;
static inline void Endpoint_Write_16_LE(const uint16_t Data)
{
UEDATX = (Data & 0xFF);
UEDATX = (Data >> 8);
}
/** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN
* direction endpoints.
*
* \ingroup Group_EndpointPrimitiveRW_AVR8
*
* \param[in] Data Data to write to the currently selected endpoint's FIFO buffer.
*/
static inline void Endpoint_Write_16_BE(const uint16_t Data) ATTR_ALWAYS_INLINE;
static inline void Endpoint_Write_16_BE(const uint16_t Data)
{
UEDATX = (Data >> 8);
UEDATX = (Data & 0xFF);
}
/** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints.
*
* \ingroup Group_EndpointPrimitiveRW_AVR8
*/
static inline void Endpoint_Discard_16(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_Discard_16(void)
{
uint8_t Dummy;
Dummy = UEDATX;
Dummy = UEDATX;
(void)Dummy;
}
/** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT
* direction endpoints.
*
* \ingroup Group_EndpointPrimitiveRW_AVR8
*
* \return Next four bytes in the currently selected endpoint's FIFO buffer.
*/
static inline uint32_t Endpoint_Read_32_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint32_t Endpoint_Read_32_LE(void)
{
union
{
uint32_t Value;
uint8_t Bytes[4];
} Data;
Data.Bytes[0] = UEDATX;
Data.Bytes[1] = UEDATX;
Data.Bytes[2] = UEDATX;
Data.Bytes[3] = UEDATX;
return Data.Value;
}
/** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT
* direction endpoints.
*
* \ingroup Group_EndpointPrimitiveRW_AVR8
*
* \return Next four bytes in the currently selected endpoint's FIFO buffer.
*/
static inline uint32_t Endpoint_Read_32_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint32_t Endpoint_Read_32_BE(void)
{
union
{
uint32_t Value;
uint8_t Bytes[4];
} Data;
Data.Bytes[3] = UEDATX;
Data.Bytes[2] = UEDATX;
Data.Bytes[1] = UEDATX;
Data.Bytes[0] = UEDATX;
return Data.Value;
}
/** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN
* direction endpoints.
*
* \ingroup Group_EndpointPrimitiveRW_AVR8
*
* \param[in] Data Data to write to the currently selected endpoint's FIFO buffer.
*/
static inline void Endpoint_Write_32_LE(const uint32_t Data) ATTR_ALWAYS_INLINE;
static inline void Endpoint_Write_32_LE(const uint32_t Data)
{
UEDATX = (Data & 0xFF);
UEDATX = (Data >> 8);
UEDATX = (Data >> 16);
UEDATX = (Data >> 24);
}
/** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN
* direction endpoints.
*
* \ingroup Group_EndpointPrimitiveRW_AVR8
*
* \param[in] Data Data to write to the currently selected endpoint's FIFO buffer.
*/
static inline void Endpoint_Write_32_BE(const uint32_t Data) ATTR_ALWAYS_INLINE;
static inline void Endpoint_Write_32_BE(const uint32_t Data)
{
UEDATX = (Data >> 24);
UEDATX = (Data >> 16);
UEDATX = (Data >> 8);
UEDATX = (Data & 0xFF);
}
/** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints.
*
* \ingroup Group_EndpointPrimitiveRW_AVR8
*/
static inline void Endpoint_Discard_32(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_Discard_32(void)
{
uint8_t Dummy;
Dummy = UEDATX;
Dummy = UEDATX;
Dummy = UEDATX;
Dummy = UEDATX;
(void)Dummy;
}
/* External Variables: */
/** Global indicating the maximum packet size of the default control endpoint located at address
* 0 in the device. This value is set to the value indicated in the device descriptor in the user
* project once the USB interface is initialized into device mode.
*
* If space is an issue, it is possible to fix this to a static value by defining the control
* endpoint size in the \c FIXED_CONTROL_ENDPOINT_SIZE token passed to the compiler in the makefile
* via the -D switch. When a fixed control endpoint size is used, the size is no longer dynamically
* read from the descriptors at runtime and instead fixed to the given value. When used, it is
* important that the descriptor control endpoint size value matches the size given as the
* \c FIXED_CONTROL_ENDPOINT_SIZE token - it is recommended that the \c FIXED_CONTROL_ENDPOINT_SIZE token
* be used in the device descriptors to ensure this.
*
* \note This variable should be treated as read-only in the user application, and never manually
* changed in value.
*/
#if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
extern uint8_t USB_Device_ControlEndpointSize;
#else
#define USB_Device_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
#endif
/* Function Prototypes: */
/** Completes the status stage of a control transfer on a CONTROL type endpoint automatically,
* with respect to the data direction. This is a convenience function which can be used to
* simplify user control request handling.
*/
void Endpoint_ClearStatusStage(void);
/** Spin-loops until the currently selected non-control endpoint is ready for the next packet of data
* to be read or written to it.
*
* \note This routine should not be called on CONTROL type endpoints.
*
* \ingroup Group_EndpointRW_AVR8
*
* \return A value from the \ref Endpoint_WaitUntilReady_ErrorCodes_t enum.
*/
uint8_t Endpoint_WaitUntilReady(void);
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,292 @@
/*
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_Host_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_Host_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);
USB_HostState = HOST_STATE_Addressed;
EVENT_USB_Host_DeviceEnumerationComplete();
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();
USB_Host_ConfigurationNumber = 0;
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);
}
#endif

View File

@ -0,0 +1,360 @@
/*
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.
*/
/** \file
* \brief USB Host definitions for the AVR8 microcontrollers.
* \copydetails Group_Host_AVR8
*
* \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.
*/
/** \ingroup Group_Host
* \defgroup Group_Host_AVR8 Host Management (AVR8)
* \brief USB Host definitions for the AVR8 microcontrollers.
*
* Architecture specific USB Host definitions for the Atmel 8-bit AVR microcontrollers.
*
* @{
*/
#ifndef __USBHOST_AVR8_H__
#define __USBHOST_AVR8_H__
/* Includes: */
#include "../../../../Common/Common.h"
#include "../StdDescriptors.h"
#include "../Pipe.h"
#include "../USBInterrupt.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Indicates the fixed USB device address which any attached device is enumerated to when in
* host mode. As only one USB device may be attached to the AVR in host mode at any one time
* and that the address used is not important (other than the fact that it is non-zero), a
* fixed value is specified by the library.
*/
#define USB_HOST_DEVICEADDRESS 1
#if !defined(HOST_DEVICE_SETTLE_DELAY_MS) || defined(__DOXYGEN__)
/** Constant for the delay in milliseconds after a device is connected before the library
* will start the enumeration process. Some devices require a delay of up to 5 seconds
* after connection before the enumeration process can start or incorrect operation will
* occur.
*
* The default delay value may be overridden in the user project makefile by defining the
* \c HOST_DEVICE_SETTLE_DELAY_MS token to the required delay in milliseconds, and passed to the
* compiler using the -D switch.
*/
#define HOST_DEVICE_SETTLE_DELAY_MS 1000
#endif
/** Enum for the error codes for the \ref EVENT_USB_Host_HostError() event.
*
* \see \ref Group_Events for more information on this event.
*/
enum USB_Host_ErrorCodes_t
{
HOST_ERROR_VBusVoltageDip = 0, /**< VBUS voltage dipped to an unacceptable level. This
* error may be the result of an attached device drawing
* too much current from the VBUS line, or due to the
* AVR's power source being unable to supply sufficient
* current.
*/
};
/** Enum for the error codes for the \ref EVENT_USB_Host_DeviceEnumerationFailed() event.
*
* \see \ref Group_Events for more information on this event.
*/
enum USB_Host_EnumerationErrorCodes_t
{
HOST_ENUMERROR_NoError = 0, /**< No error occurred. Used internally, this is not a valid
* ErrorCode parameter value for the \ref EVENT_USB_Host_DeviceEnumerationFailed()
* event.
*/
HOST_ENUMERROR_WaitStage = 1, /**< One of the delays between enumeration steps failed
* to complete successfully, due to a timeout or other
* error.
*/
HOST_ENUMERROR_NoDeviceDetected = 2, /**< No device was detected, despite the USB data lines
* indicating the attachment of a device.
*/
HOST_ENUMERROR_ControlError = 3, /**< One of the enumeration control requests failed to
* complete successfully.
*/
HOST_ENUMERROR_PipeConfigError = 4, /**< The default control pipe (address 0) failed to
* configure correctly.
*/
};
/* Inline Functions: */
/** Returns the current USB frame number, when in host mode. Every millisecond the USB bus is active (i.e. not suspended)
* the frame number is incremented by one.
*
* \return Current USB frame number from the USB controller.
*/
static inline uint16_t USB_Host_GetFrameNumber(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint16_t USB_Host_GetFrameNumber(void)
{
return UHFNUM;
}
#if !defined(NO_SOF_EVENTS)
/** Enables the host mode Start Of Frame events. When enabled, this causes the
* \ref EVENT_USB_Host_StartOfFrame() event to fire once per millisecond, synchronized to the USB bus,
* at the start of each USB frame when a device is enumerated while in host mode.
*
* \note Not available when the \c NO_SOF_EVENTS compile time token is defined.
*/
static inline void USB_Host_EnableSOFEvents(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_EnableSOFEvents(void)
{
USB_INT_Enable(USB_INT_HSOFI);
}
/** Disables the host mode Start Of Frame events. When disabled, this stops the firing of the
* \ref EVENT_USB_Host_StartOfFrame() event when enumerated in host mode.
*
* \note Not available when the NO_SOF_EVENTS compile time token is defined.
*/
static inline void USB_Host_DisableSOFEvents(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_DisableSOFEvents(void)
{
USB_INT_Disable(USB_INT_HSOFI);
}
#endif
/** Resets the USB bus, including the endpoints in any attached device and pipes on the AVR host.
* USB bus resets leave the default control pipe configured (if already configured).
*
* If the USB bus has been suspended prior to issuing a bus reset, the attached device will be
* woken up automatically and the bus resumed after the reset has been correctly issued.
*/
static inline void USB_Host_ResetBus(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_ResetBus(void)
{
UHCON |= (1 << RESET);
}
/** Determines if a previously issued bus reset (via the \ref USB_Host_ResetBus() macro) has
* completed.
*
* \return Boolean \c true if no bus reset is currently being sent, \c false otherwise.
*/
static inline bool USB_Host_IsBusResetComplete(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_Host_IsBusResetComplete(void)
{
return ((UHCON & (1 << RESET)) ? false : true);
}
/** Resumes USB communications with an attached and enumerated device, by resuming the transmission
* of the 1MS Start Of Frame messages to the device. When resumed, USB communications between the
* host and attached device may occur.
*/
static inline void USB_Host_ResumeBus(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_ResumeBus(void)
{
UHCON |= (1 << SOFEN);
}
/** Suspends the USB bus, preventing any communications from occurring between the host and attached
* device until the bus has been resumed. This stops the transmission of the 1MS Start Of Frame
* messages to the device.
*
* \note While the USB bus is suspended, all USB interrupt sources are also disabled; this means that
* some events (such as device disconnections) will not fire until the bus is resumed.
*/
static inline void USB_Host_SuspendBus(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_SuspendBus(void)
{
UHCON &= ~(1 << SOFEN);
}
/** Determines if the USB bus has been suspended via the use of the \ref USB_Host_SuspendBus() macro,
* false otherwise. While suspended, no USB communications can occur until the bus is resumed,
* except for the Remote Wakeup event from the device if supported.
*
* \return Boolean \c true if the bus is currently suspended, \c false otherwise.
*/
static inline bool USB_Host_IsBusSuspended(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_Host_IsBusSuspended(void)
{
return ((UHCON & (1 << SOFEN)) ? false : true);
}
/** Determines if the attached device is currently enumerated in Full Speed mode (12Mb/s), or
* false if the attached device is enumerated in Low Speed mode (1.5Mb/s).
*
* \return Boolean \c true if the attached device is enumerated in Full Speed mode, \c false otherwise.
*/
static inline bool USB_Host_IsDeviceFullSpeed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_Host_IsDeviceFullSpeed(void)
{
return ((USBSTA & (1 << SPEED)) ? true : false);
}
/** Determines if the attached device is currently issuing a Remote Wakeup request, requesting
* that the host resume the USB bus and wake up the device, false otherwise.
*
* \return Boolean \c true if the attached device has sent a Remote Wakeup request, \c false otherwise.
*/
static inline bool USB_Host_IsRemoteWakeupSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_Host_IsRemoteWakeupSent(void)
{
return ((UHINT & (1 << RXRSMI)) ? true : false);
}
/** Clears the flag indicating that a Remote Wakeup request has been issued by an attached device. */
static inline void USB_Host_ClearRemoteWakeupSent(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_ClearRemoteWakeupSent(void)
{
UHINT &= ~(1 << RXRSMI);
}
/** Accepts a Remote Wakeup request from an attached device. This must be issued in response to
* a device's Remote Wakeup request within 2ms for the request to be accepted and the bus to
* be resumed.
*/
static inline void USB_Host_ResumeFromWakeupRequest(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_ResumeFromWakeupRequest(void)
{
UHCON |= (1 << RESUME);
}
/** Determines if a resume from Remote Wakeup request is currently being sent to an attached
* device.
*
* \return Boolean \c true if no resume request is currently being sent, \c false otherwise.
*/
static inline bool USB_Host_IsResumeFromWakeupRequestSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_Host_IsResumeFromWakeupRequestSent(void)
{
return ((UHCON & (1 << RESUME)) ? false : true);
}
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Macros: */
static inline void USB_Host_HostMode_On(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_HostMode_On(void)
{
USBCON |= (1 << HOST);
}
static inline void USB_Host_HostMode_Off(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_HostMode_Off(void)
{
USBCON &= ~(1 << HOST);
}
static inline void USB_Host_VBUS_Auto_Enable(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_VBUS_Auto_Enable(void)
{
OTGCON &= ~(1 << VBUSHWC);
UHWCON |= (1 << UVCONE);
}
static inline void USB_Host_VBUS_Manual_Enable(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_VBUS_Manual_Enable(void)
{
OTGCON |= (1 << VBUSHWC);
UHWCON &= ~(1 << UVCONE);
DDRE |= (1 << 7);
}
static inline void USB_Host_VBUS_Auto_On(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_VBUS_Auto_On(void)
{
OTGCON |= (1 << VBUSREQ);
}
static inline void USB_Host_VBUS_Manual_On(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_VBUS_Manual_On(void)
{
PORTE |= (1 << 7);
}
static inline void USB_Host_VBUS_Auto_Off(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_VBUS_Auto_Off(void)
{
OTGCON |= (1 << VBUSRQC);
}
static inline void USB_Host_VBUS_Manual_Off(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_VBUS_Manual_Off(void)
{
PORTE &= ~(1 << 7);
}
static inline void USB_Host_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
static inline void USB_Host_SetDeviceAddress(const uint8_t Address)
{
UHADDR = (Address & 0x7F);
}
/* Enums: */
enum USB_Host_WaitMSErrorCodes_t
{
HOST_WAITERROR_Successful = 0,
HOST_WAITERROR_DeviceDisconnect = 1,
HOST_WAITERROR_PipeError = 2,
HOST_WAITERROR_SetupStalled = 3,
};
/* Function Prototypes: */
void USB_Host_ProcessNextHostState(void);
uint8_t USB_Host_WaitMS(uint8_t MS);
#if defined(__INCLUDE_FROM_HOST_C)
static void USB_Host_ResetDevice(void);
#endif
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,159 @@
/*
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.
*/
/** \file
* \brief USB OTG definitions for the AVR8 microcontrollers.
* \copydetails Group_OTG_AVR8
*
* \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.
*/
/** \ingroup Group_OTG
* \defgroup Group_OTG_AVR8 USB On The Go (OTG) Management (AVR8)
* \brief USB OTG definitions for the AVR8 microcontrollers.
*
* Architecture specific USB OTG definitions for the Atmel 8-bit AVR microcontrollers.
*
* @{
*/
#ifndef __USBOTG_AVR8_H__
#define __USBOTG_AVR8_H__
/* Includes: */
#include "../../../../Common/Common.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Mask for the VBUS pulsing method of SRP, supported by some OTG devices.
*
* \see \ref USB_OTG_Device_InitiateSRP().
*/
#define USB_OTG_SRP_VBUS (1 << SRPSEL)
/** Mask for the Data + pulsing method of SRP, supported by some OTG devices.
*
* \see \ref USB_OTG_Device_InitiateSRP().
*/
#define USB_OTG_STP_DATA 0
/* Inline Functions: */
/** Initiate a Host Negotiation Protocol request. This indicates to the other connected device
* that the device wishes to change device/host roles.
*/
static inline void USB_OTG_Device_RequestHNP(void) ATTR_ALWAYS_INLINE;
static inline void USB_OTG_Device_RequestHNP(void)
{
OTGCON |= (1 << HNPREQ);
}
/** Cancel a Host Negotiation Protocol request. This stops a pending HNP request to the other
* connected device.
*/
static inline void USB_OTG_Device_CancelHNPRequest(void) ATTR_ALWAYS_INLINE;
static inline void USB_OTG_Device_CancelHNPRequest(void)
{
OTGCON &= ~(1 << HNPREQ);
}
/** Determines if the device is currently sending a HNP to an attached host.
*
* \return Boolean \c true if currently sending a HNP to the other connected device, \c false otherwise
*/
static inline bool USB_OTG_Device_IsSendingHNP(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_OTG_Device_IsSendingHNP(void)
{
return ((OTGCON & (1 << HNPREQ)) ? true : false);
}
/** Initiates a Session Request Protocol request. Most OTG devices turn off VBUS when the USB
* interface is not in use, to conserve power. Sending a SRP to a USB OTG device running in
* host mode indicates that VBUS should be applied and a session started.
*
* There are two different methods of sending a SRP - either pulses on the VBUS line, or by
* pulsing the Data + line via the internal pull-up resistor.
*
* \param[in] SRPTypeMask Mask indicating the type of SRP to use, either \ref USB_OTG_SRP_VBUS or
* \ref USB_OTG_STP_DATA.
*/
static inline void USB_OTG_Device_InitiateSRP(const uint8_t SRPTypeMask) ATTR_ALWAYS_INLINE;
static inline void USB_OTG_Device_InitiateSRP(const uint8_t SRPTypeMask)
{
OTGCON = ((OTGCON & ~(1 << SRPSEL)) | (SRPTypeMask | (1 << SRPREQ)));
}
/** Accepts a HNP from a connected device, indicating that both devices should exchange
* device/host roles.
*/
static inline void USB_OTG_Host_AcceptHNP(void) ATTR_ALWAYS_INLINE;
static inline void USB_OTG_Host_AcceptHNP(void)
{
OTGCON |= (1 << HNPREQ);
}
/** Rejects a HNP from a connected device, indicating that both devices should remain in their
* current device/host roles.
*/
static inline void USB_OTG_Host_RejectHNP(void) ATTR_ALWAYS_INLINE;
static inline void USB_OTG_Host_RejectHNP(void)
{
OTGCON &= ~(1 << HNPREQ);
}
/** Indicates if the connected device is currently sending a HNP request.
*
* \return Boolean \c true if a HNP is currently being issued by the connected device, \c false otherwise.
*/
static inline bool USB_OTG_Host_IsHNPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_OTG_Host_IsHNPReceived(void)
{
return ((OTGCON & (1 << HNPREQ)) ? true : false);
}
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,216 @@
/*
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)
#include "PipeStream_AVR8.h"
uint8_t Pipe_Discard_Stream(uint16_t Length,
uint16_t* const BytesProcessed)
{
uint8_t ErrorCode;
uint16_t BytesInTransfer = 0;
Pipe_SetPipeToken(PIPE_TOKEN_IN);
if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
if (BytesProcessed != NULL)
Length -= *BytesProcessed;
while (Length)
{
if (!(Pipe_IsReadWriteAllowed()))
{
Pipe_ClearIN();
if (BytesProcessed != NULL)
{
*BytesProcessed += BytesInTransfer;
return PIPE_RWSTREAM_IncompleteTransfer;
}
if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
}
else
{
Pipe_Discard_8();
Length--;
BytesInTransfer++;
}
}
return PIPE_RWSTREAM_NoError;
}
uint8_t Pipe_Null_Stream(uint16_t Length,
uint16_t* const BytesProcessed)
{
uint8_t ErrorCode;
uint16_t BytesInTransfer = 0;
Pipe_SetPipeToken(PIPE_TOKEN_OUT);
if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
if (BytesProcessed != NULL)
Length -= *BytesProcessed;
while (Length)
{
if (!(Pipe_IsReadWriteAllowed()))
{
Pipe_ClearOUT();
if (BytesProcessed != NULL)
{
*BytesProcessed += BytesInTransfer;
return PIPE_RWSTREAM_IncompleteTransfer;
}
USB_USBTask();
if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
}
else
{
Pipe_Write_8(0);
Length--;
BytesInTransfer++;
}
}
return PIPE_RWSTREAM_NoError;
}
/* The following abuses the C preprocessor in order to copy-paste common code with slight alterations,
* so that the code needs to be written once. It is a crude form of templating to reduce code maintenance. */
#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_LE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr)
#include "Template/Template_Pipe_RW.c"
#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_BE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(*BufferPtr)
#include "Template/Template_Pipe_RW.c"
#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_LE
#define TEMPLATE_BUFFER_TYPE void*
#define TEMPLATE_TOKEN PIPE_TOKEN_IN
#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8()
#include "Template/Template_Pipe_RW.c"
#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_BE
#define TEMPLATE_BUFFER_TYPE void*
#define TEMPLATE_TOKEN PIPE_TOKEN_IN
#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_8()
#include "Template/Template_Pipe_RW.c"
#define TEMPLATE_FUNC_NAME Pipe_Write_PStream_LE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(pgm_read_byte(BufferPtr))
#include "Template/Template_Pipe_RW.c"
#define TEMPLATE_FUNC_NAME Pipe_Write_PStream_BE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(pgm_read_byte(BufferPtr))
#include "Template/Template_Pipe_RW.c"
#define TEMPLATE_FUNC_NAME Pipe_Write_EStream_LE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(eeprom_read_byte(BufferPtr))
#include "Template/Template_Pipe_RW.c"
#define TEMPLATE_FUNC_NAME Pipe_Write_EStream_BE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_TOKEN PIPE_TOKEN_OUT
#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_8(eeprom_read_byte(BufferPtr))
#include "Template/Template_Pipe_RW.c"
#define TEMPLATE_FUNC_NAME Pipe_Read_EStream_LE
#define TEMPLATE_BUFFER_TYPE void*
#define TEMPLATE_TOKEN PIPE_TOKEN_IN
#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Pipe_Read_8())
#include "Template/Template_Pipe_RW.c"
#define TEMPLATE_FUNC_NAME Pipe_Read_EStream_BE
#define TEMPLATE_BUFFER_TYPE void*
#define TEMPLATE_TOKEN PIPE_TOKEN_IN
#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Pipe_Read_8())
#include "Template/Template_Pipe_RW.c"
#endif

View File

@ -0,0 +1,442 @@
/*
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.
*/
/** \file
* \brief Pipe data stream transmission and reception management for the AVR8 microcontrollers
* \copydetails Group_PipeStreamRW_AVR8
*
* \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.
*/
/** \ingroup Group_PipeStreamRW
* \defgroup Group_PipeStreamRW_AVR8 Read/Write of Multi-Byte Streams (AVR8)
* \brief Pipe data stream transmission and reception management for the Atmel AVR8 architecture.
*
* Functions, macros, variables, enums and types related to data reading and writing of data streams from
* and to pipes.
*
* @{
*/
#ifndef __PIPE_STREAM_AVR8_H__
#define __PIPE_STREAM_AVR8_H__
/* Includes: */
#include "../../../../Common/Common.h"
#include "../USBMode.h"
#include "../USBTask.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Function Prototypes: */
/** \name Stream functions for null data */
//@{
/** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host
* as needed. The last packet is not automatically discarded once the remaining bytes has been read; the
* user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearIN() macro.
*
* If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or
* succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer
* will instead be performed as a series of chunks. Each time the pipe bank becomes empty while there is still data
* to process (and after the current packet has been acknowledged) the BytesProcessed location will be updated with
* the total number of bytes processed in the stream, and the function will exit with an error code of
* \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to
* continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed
* value reaches the total transfer length.
*
* <b>Single Stream Transfer Example:</b>
* \code
* uint8_t ErrorCode;
*
* if ((ErrorCode = Pipe_Discard_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* <b>Partial Stream Transfers Example:</b>
* \code
* uint8_t ErrorCode;
* uint16_t BytesProcessed;
*
* BytesProcessed = 0;
* while ((ErrorCode = Pipe_Discard_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
* {
* // Stream not yet complete - do other actions here, abort if required
* }
*
* if (ErrorCode != PIPE_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
* having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
*
* \param[in] Length Number of bytes to discard via the currently selected pipe.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
* updated, \c NULL if the entire stream should be processed at once.
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Pipe_Discard_Stream(uint16_t Length,
uint16_t* const BytesProcessed);
/** Writes a given number of zeroed bytes to the pipe, sending full pipe packets from the host to the device
* as needed. The last packet is not automatically sent once the remaining bytes has been written; the
* user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearOUT() macro.
*
* If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once, failing or
* succeeding as a single unit. If the BytesProcessed parameter points to a valid storage location, the transfer
* will instead be performed as a series of chunks. Each time the pipe bank becomes full while there is still data
* to process (and after the current packet transmission has been initiated) the BytesProcessed location will be
* updated with the total number of bytes processed in the stream, and the function will exit with an error code of
* \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed in the user code - to
* continue the transfer, call the function again with identical parameters and it will resume until the BytesProcessed
* value reaches the total transfer length.
*
* <b>Single Stream Transfer Example:</b>
* \code
* uint8_t ErrorCode;
*
* if ((ErrorCode = Pipe_Null_Stream(512, NULL)) != PIPE_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* <b>Partial Stream Transfers Example:</b>
* \code
* uint8_t ErrorCode;
* uint16_t BytesProcessed;
*
* BytesProcessed = 0;
* while ((ErrorCode = Pipe_Null_Stream(512, &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
* {
* // Stream not yet complete - do other actions here, abort if required
* }
*
* if (ErrorCode != PIPE_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
* having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
*
* \param[in] Length Number of zero bytes to write via the currently selected pipe.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
* updated, \c NULL if the entire stream should be processed at once.
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Pipe_Null_Stream(uint16_t Length,
uint16_t* const BytesProcessed);
//@}
/** \name Stream functions for RAM source/destination data */
//@{
/** Writes the given number of bytes to the pipe from the given buffer in little endian,
* sending full packets to the device as needed. The last packet filled is not automatically sent;
* the user is responsible for manually sending the last written packet to the host via the
* \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
* executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
*
* If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
* failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
* storage location, the transfer will instead be performed as a series of chunks. Each time
* the pipe bank becomes full while there is still data to process (and after the current
* packet transmission has been initiated) the BytesProcessed location will be updated with the
* total number of bytes processed in the stream, and the function will exit with an error code of
* \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
* in the user code - to continue the transfer, call the function again with identical parameters
* and it will resume until the BytesProcessed value reaches the total transfer length.
*
* <b>Single Stream Transfer Example:</b>
* \code
* uint8_t DataStream[512];
* uint8_t ErrorCode;
*
* if ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),
* NULL)) != PIPE_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* <b>Partial Stream Transfers Example:</b>
* \code
* uint8_t DataStream[512];
* uint8_t ErrorCode;
* uint16_t BytesProcessed;
*
* BytesProcessed = 0;
* while ((ErrorCode = Pipe_Write_Stream_LE(DataStream, sizeof(DataStream),
* &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
* {
* // Stream not yet complete - do other actions here, abort if required
* }
*
* if (ErrorCode != PIPE_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
* having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
* updated, \c NULL if the entire stream should be written at once.
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Pipe_Write_Stream_LE(const void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** Writes the given number of bytes to the pipe from the given buffer in big endian,
* sending full packets to the device as needed. The last packet filled is not automatically sent;
* the user is responsible for manually sending the last written packet to the host via the
* \ref Pipe_ClearOUT() macro. Between each USB packet, the given stream callback function is
* executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
*
* \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
* having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
* updated, \c NULL if the entire stream should be written at once.
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Pipe_Write_Stream_BE(const void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** Reads the given number of bytes from the pipe into the given buffer in little endian,
* sending full packets to the device as needed. The last packet filled is not automatically sent;
* the user is responsible for manually sending the last written packet to the host via the
* \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
* executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
*
* If the BytesProcessed parameter is \c NULL, the entire stream transfer is attempted at once,
* failing or succeeding as a single unit. If the BytesProcessed parameter points to a valid
* storage location, the transfer will instead be performed as a series of chunks. Each time
* the pipe bank becomes empty while there is still data to process (and after the current
* packet has been acknowledged) the BytesProcessed location will be updated with the total number
* of bytes processed in the stream, and the function will exit with an error code of
* \ref PIPE_RWSTREAM_IncompleteTransfer. This allows for any abort checking to be performed
* in the user code - to continue the transfer, call the function again with identical parameters
* and it will resume until the BytesProcessed value reaches the total transfer length.
*
* <b>Single Stream Transfer Example:</b>
* \code
* uint8_t DataStream[512];
* uint8_t ErrorCode;
*
* if ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),
* NULL)) != PIPE_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* <b>Partial Stream Transfers Example:</b>
* \code
* uint8_t DataStream[512];
* uint8_t ErrorCode;
* uint16_t BytesProcessed;
*
* BytesProcessed = 0;
* while ((ErrorCode = Pipe_Read_Stream_LE(DataStream, sizeof(DataStream),
* &BytesProcessed)) == PIPE_RWSTREAM_IncompleteTransfer)
* {
* // Stream not yet complete - do other actions here, abort if required
* }
*
* if (ErrorCode != PIPE_RWSTREAM_NoError)
* {
* // Stream failed to complete - check ErrorCode here
* }
* \endcode
*
* \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
* having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
*
* \param[out] Buffer Pointer to the source data buffer to write to.
* \param[in] Length Number of bytes to read for the currently selected pipe to read from.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
* updated, \c NULL if the entire stream should be read at once.
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Pipe_Read_Stream_LE(void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** Reads the given number of bytes from the pipe into the given buffer in big endian,
* sending full packets to the device as needed. The last packet filled is not automatically sent;
* the user is responsible for manually sending the last written packet to the host via the
* \ref Pipe_ClearIN() macro. Between each USB packet, the given stream callback function is
* executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.
*
* \note The pipe token is set automatically, thus this can be used on bi-directional pipes directly without
* having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken().
*
* \param[out] Buffer Pointer to the source data buffer to write to.
* \param[in] Length Number of bytes to read for the currently selected pipe to read from.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
* updated, \c NULL if the entire stream should be read at once.
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Pipe_Read_Stream_BE(void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
//@}
/** \name Stream functions for EEPROM source/destination data */
//@{
/** EEPROM buffer source version of \ref Pipe_Write_Stream_LE().
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
* updated, \c NULL if the entire stream should be written at once.
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Pipe_Write_EStream_LE(const void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** EEPROM buffer source version of \ref Pipe_Write_Stream_BE().
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
* updated, \c NULL if the entire stream should be written at once.
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Pipe_Write_EStream_BE(const void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** EEPROM buffer source version of \ref Pipe_Read_Stream_LE().
*
* \param[out] Buffer Pointer to the source data buffer to write to.
* \param[in] Length Number of bytes to read for the currently selected pipe to read from.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
* updated, \c NULL if the entire stream should be read at once.
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Pipe_Read_EStream_LE(void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** EEPROM buffer source version of \ref Pipe_Read_Stream_BE().
*
* \param[out] Buffer Pointer to the source data buffer to write to.
* \param[in] Length Number of bytes to read for the currently selected pipe to read from.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
* updated, \c NULL if the entire stream should be read at once.
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Pipe_Read_EStream_BE(void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
//@}
/** \name Stream functions for PROGMEM source/destination data */
//@{
/** FLASH buffer source version of \ref Pipe_Write_Stream_LE().
*
* \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
* updated, \c NULL if the entire stream should be written at once.
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Pipe_Write_PStream_LE(const void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
/** FLASH buffer source version of \ref Pipe_Write_Stream_BE().
*
* \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
*
* \param[in] Buffer Pointer to the source data buffer to read from.
* \param[in] Length Number of bytes to read for the currently selected pipe into the buffer.
* \param[in] BytesProcessed Pointer to a location where the total number of bytes already processed should
* updated, \c NULL if the entire stream should be written at once.
*
* \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.
*/
uint8_t Pipe_Write_PStream_BE(const void* const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed) ATTR_NON_NULL_PTR_ARG(1);
//@}
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,181 @@
/*
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)
#include "../Pipe.h"
uint8_t USB_Host_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
bool Pipe_ConfigurePipe(const uint8_t Number,
const uint8_t Type,
const uint8_t Token,
const uint8_t EndpointNumber,
const uint16_t Size,
const uint8_t Banks)
{
#if defined(ORDERED_EP_CONFIG)
Pipe_SelectPipe(Number);
Pipe_EnablePipe();
UPCFG1X = 0;
UPCFG0X = ((Type << EPTYPE0) | Token | ((EndpointNumber & PIPE_EPNUM_MASK) << PEPNUM0));
UPCFG1X = ((1 << ALLOC) | Banks | Pipe_BytesToEPSizeMask(Size));
Pipe_SetInfiniteINRequests();
return Pipe_IsConfigured();
#else
for (uint8_t PNum = Number; PNum < PIPE_TOTAL_PIPES; PNum++)
{
uint8_t UPCFG0XTemp;
uint8_t UPCFG1XTemp;
uint8_t UPCFG2XTemp;
uint8_t UPIENXTemp;
Pipe_SelectPipe(PNum);
if (PNum == Number)
{
UPCFG0XTemp = ((Type << EPTYPE0) | Token | ((EndpointNumber & PIPE_EPNUM_MASK) << PEPNUM0));
UPCFG1XTemp = ((1 << ALLOC) | Banks | Pipe_BytesToEPSizeMask(Size));
UPCFG2XTemp = 0;
UPIENXTemp = 0;
}
else
{
UPCFG0XTemp = UPCFG0X;
UPCFG1XTemp = UPCFG1X;
UPCFG2XTemp = UPCFG2X;
UPIENXTemp = UPIENX;
}
if (!(UPCFG1XTemp & (1 << ALLOC)))
continue;
Pipe_DisablePipe();
UPCFG1X &= ~(1 << ALLOC);
Pipe_EnablePipe();
UPCFG0X = UPCFG0XTemp;
UPCFG1X = UPCFG1XTemp;
UPCFG2X = UPCFG2XTemp;
UPIENX = UPIENXTemp;
Pipe_SetInfiniteINRequests();
if (!(Pipe_IsConfigured()))
return false;
}
Pipe_SelectPipe(Number);
return true;
#endif
}
void Pipe_ClearPipes(void)
{
UPINT = 0;
for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)
{
Pipe_SelectPipe(PNum);
UPIENX = 0;
UPINTX = 0;
UPCFG1X = 0;
Pipe_DisablePipe();
}
}
bool Pipe_IsEndpointBound(const uint8_t EndpointAddress)
{
uint8_t PrevPipeNumber = Pipe_GetCurrentPipe();
for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)
{
Pipe_SelectPipe(PNum);
if (!(Pipe_IsConfigured()))
continue;
if (Pipe_GetBoundEndpointAddress() == EndpointAddress)
return true;
}
Pipe_SelectPipe(PrevPipeNumber);
return false;
}
uint8_t Pipe_WaitUntilReady(void)
{
#if (USB_STREAM_TIMEOUT_MS < 0xFF)
uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
#else
uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;
#endif
uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber();
for (;;)
{
if (Pipe_GetPipeToken() == PIPE_TOKEN_IN)
{
if (Pipe_IsINReceived())
return PIPE_READYWAIT_NoError;
}
else
{
if (Pipe_IsOUTReady())
return PIPE_READYWAIT_NoError;
}
if (Pipe_IsStalled())
return PIPE_READYWAIT_PipeStalled;
else if (USB_HostState == HOST_STATE_Unattached)
return PIPE_READYWAIT_DeviceDisconnected;
uint16_t CurrentFrameNumber = USB_Host_GetFrameNumber();
if (CurrentFrameNumber != PreviousFrameNumber)
{
PreviousFrameNumber = CurrentFrameNumber;
if (!(TimeoutMSRem--))
return PIPE_READYWAIT_Timeout;
}
}
}
#endif

View File

@ -0,0 +1,923 @@
/*
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.
*/
/** \file
* \brief USB Pipe definitions for the AVR8 microcontrollers.
* \copydetails Group_PipeManagement_AVR8
*
* \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.
*/
/** \ingroup Group_PipeRW
* \defgroup Group_PipeRW_AVR8 Pipe Data Reading and Writing (AVR8)
* \brief Pipe data read/write definitions for the Atmel AVR8 architecture.
*
* Functions, macros, variables, enums and types related to data reading and writing from and to pipes.
*/
/** \ingroup Group_PipePrimitiveRW
* \defgroup Group_PipePrimitiveRW_AVR8 Read/Write of Primitive Data Types (AVR8)
* \brief Pipe primitive data read/write definitions for the Atmel AVR8 architecture.
*
* Functions, macros, variables, enums and types related to data reading and writing of primitive data types
* from and to pipes.
*/
/** \ingroup Group_PipePacketManagement
* \defgroup Group_PipePacketManagement_AVR8 Pipe Packet Management (AVR8)
* \brief Pipe packet management definitions for the Atmel AVR8 architecture.
*
* Functions, macros, variables, enums and types related to packet management of pipes.
*/
/** \ingroup Group_PipeControlReq
* \defgroup Group_PipeControlReq_AVR8 Pipe Control Request Management (AVR8)
* \brief Pipe control request management definitions for the Atmel AVR8 architecture.
*
* Module for host mode request processing. This module allows for the transmission of standard, class and
* vendor control requests to the default control endpoint of an attached device while in host mode.
*
* \see Chapter 9 of the USB 2.0 specification.
*/
/** \ingroup Group_PipeManagement
* \defgroup Group_PipeManagement_AVR8 Pipe Management (AVR8)
* \brief Pipe management definitions for the Atmel AVR8 architecture.
*
* This module contains functions, macros and enums related to pipe management when in USB Host mode. This
* module contains the pipe management macros, as well as pipe interrupt and data send/receive functions
* for various data types.
*
* @{
*/
#ifndef __PIPE_AVR8_H__
#define __PIPE_AVR8_H__
/* Includes: */
#include "../../../../Common/Common.h"
#include "../USBTask.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** \name Pipe Error Flag Masks */
//@{
/** Mask for \ref Pipe_GetErrorFlags(), indicating that an overflow error occurred in the pipe on the received data. */
#define PIPE_ERRORFLAG_OVERFLOW (1 << 6)
/** Mask for \ref Pipe_GetErrorFlags(), indicating that an underflow error occurred in the pipe on the received data. */
#define PIPE_ERRORFLAG_UNDERFLOW (1 << 5)
/** Mask for \ref Pipe_GetErrorFlags(), indicating that a CRC error occurred in the pipe on the received data. */
#define PIPE_ERRORFLAG_CRC16 (1 << 4)
/** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware timeout error occurred in the pipe. */
#define PIPE_ERRORFLAG_TIMEOUT (1 << 3)
/** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware PID error occurred in the pipe. */
#define PIPE_ERRORFLAG_PID (1 << 2)
/** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data PID error occurred in the pipe. */
#define PIPE_ERRORFLAG_DATAPID (1 << 1)
/** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data toggle error occurred in the pipe. */
#define PIPE_ERRORFLAG_DATATGL (1 << 0)
//@}
/** \name Pipe Token Masks */
//@{
/** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a SETUP token (for CONTROL type pipes),
* which will trigger a control request on the attached device when data is written to the pipe.
*/
#define PIPE_TOKEN_SETUP (0 << PTOKEN0)
/** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a IN token (for non-CONTROL type pipes),
* indicating that the pipe data will flow from device to host.
*/
#define PIPE_TOKEN_IN (1 << PTOKEN0)
/** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a OUT token (for non-CONTROL type pipes),
* indicating that the pipe data will flow from host to device.
*/
#define PIPE_TOKEN_OUT (2 << PTOKEN0)
//@}
/** \name Pipe Bank Mode Masks */
//@{
/** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe
* should have one single bank, which requires less USB FIFO memory but results in slower transfers as
* only one USB device (the AVR or the attached device) can access the pipe's bank at the one time.
*/
#define PIPE_BANK_SINGLE (0 << EPBK0)
/** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe
* should have two banks, which requires more USB FIFO memory but results in faster transfers as one
* USB device (the AVR or the attached device) can access one bank while the other accesses the second
* bank.
*/
#define PIPE_BANK_DOUBLE (1 << EPBK0)
//@}
/** Default size of the default control pipe's bank, until altered by the Endpoint0Size value
* in the device descriptor of the attached device.
*/
#define PIPE_CONTROLPIPE_DEFAULT_SIZE 64
/** Total number of pipes (including the default control pipe at address 0) which may be used in
* the device. Different USB AVR models support different amounts of pipes, this value reflects
* the maximum number of pipes for the currently selected AVR model.
*/
#define PIPE_TOTAL_PIPES 7
/** Size in bytes of the largest pipe bank size possible in the device. Not all banks on each AVR
* model supports the largest bank size possible on the device; different pipe numbers support
* different maximum bank sizes. This value reflects the largest possible bank of any pipe on the
* currently selected USB AVR model.
*/
#define PIPE_MAX_SIZE 256
/* Enums: */
/** Enum for the possible error return codes of the \ref Pipe_WaitUntilReady() function.
*
* \ingroup Group_PipeRW_AVR8
*/
enum Pipe_WaitUntilReady_ErrorCodes_t
{
PIPE_READYWAIT_NoError = 0, /**< Pipe ready for next packet, no error. */
PIPE_READYWAIT_PipeStalled = 1, /**< The device stalled the pipe while waiting. */
PIPE_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while waiting. */
PIPE_READYWAIT_Timeout = 3, /**< The device failed to accept or send the next packet
* within the software timeout period set by the
* \ref USB_STREAM_TIMEOUT_MS macro.
*/
};
/* Inline Functions: */
/** Indicates the number of bytes currently stored in the current pipes's selected bank.
*
* \note The return width of this function may differ, depending on the maximum pipe bank size
* of the selected AVR model.
*
* \ingroup Group_PipeRW_AVR8
*
* \return Total number of bytes in the currently selected pipe's FIFO buffer.
*/
static inline uint16_t Pipe_BytesInPipe(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint16_t Pipe_BytesInPipe(void)
{
return UPBCX;
}
/** Returns the pipe address of the currently selected pipe. This is typically used to save the
* currently selected pipe number so that it can be restored after another pipe has been manipulated.
*
* \return Index of the currently selected pipe.
*/
static inline uint8_t Pipe_GetCurrentPipe(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Pipe_GetCurrentPipe(void)
{
return (UPNUM & PIPE_PIPENUM_MASK);
}
/** Selects the given pipe number. Any pipe operations which do not require the pipe number to be
* indicated will operate on the currently selected pipe.
*
* \param[in] PipeNumber Index of the pipe to select.
*/
static inline void Pipe_SelectPipe(const uint8_t PipeNumber) ATTR_ALWAYS_INLINE;
static inline void Pipe_SelectPipe(const uint8_t PipeNumber)
{
UPNUM = PipeNumber;
}
/** Resets the desired pipe, including the pipe banks and flags.
*
* \param[in] PipeNumber Index of the pipe to reset.
*/
static inline void Pipe_ResetPipe(const uint8_t PipeNumber) ATTR_ALWAYS_INLINE;
static inline void Pipe_ResetPipe(const uint8_t PipeNumber)
{
UPRST = (1 << PipeNumber);
UPRST = 0;
}
/** Enables the currently selected pipe so that data can be sent and received through it to and from
* an attached device.
*
* \pre The currently selected pipe must first be configured properly via \ref Pipe_ConfigurePipe().
*/
static inline void Pipe_EnablePipe(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_EnablePipe(void)
{
UPCONX |= (1 << PEN);
}
/** Disables the currently selected pipe so that data cannot be sent and received through it to and
* from an attached device.
*/
static inline void Pipe_DisablePipe(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_DisablePipe(void)
{
UPCONX &= ~(1 << PEN);
}
/** Determines if the currently selected pipe is enabled, but not necessarily configured.
*
* \return Boolean \c true if the currently selected pipe is enabled, \c false otherwise.
*/
static inline bool Pipe_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Pipe_IsEnabled(void)
{
return ((UPCONX & (1 << PEN)) ? true : false);
}
/** Gets the current pipe token, indicating the pipe's data direction and type.
*
* \return The current pipe token, as a \c PIPE_TOKEN_* mask.
*/
static inline uint8_t Pipe_GetPipeToken(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Pipe_GetPipeToken(void)
{
return (UPCFG0X & (0x03 << PTOKEN0));
}
/** Sets the token for the currently selected pipe to one of the tokens specified by the \c PIPE_TOKEN_*
* masks. This can be used on CONTROL type pipes, to allow for bidirectional transfer of data during
* control requests, or on regular pipes to allow for half-duplex bidirectional data transfer to devices
* which have two endpoints of opposite direction sharing the same endpoint address within the device.
*
* \param[in] Token New pipe token to set the selected pipe to, as a \c PIPE_TOKEN_* mask.
*/
static inline void Pipe_SetPipeToken(const uint8_t Token) ATTR_ALWAYS_INLINE;
static inline void Pipe_SetPipeToken(const uint8_t Token)
{
UPCFG0X = ((UPCFG0X & ~(0x03 << PTOKEN0)) | Token);
}
/** Configures the currently selected pipe to allow for an unlimited number of IN requests. */
static inline void Pipe_SetInfiniteINRequests(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_SetInfiniteINRequests(void)
{
UPCONX |= (1 << INMODE);
}
/** Configures the currently selected pipe to only allow the specified number of IN requests to be
* accepted by the pipe before it is automatically frozen.
*
* \param[in] TotalINRequests Total number of IN requests that the pipe may receive before freezing.
*/
static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests) ATTR_ALWAYS_INLINE;
static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests)
{
UPCONX &= ~(1 << INMODE);
UPINRQX = TotalINRequests;
}
/** Determines if the currently selected pipe is configured.
*
* \return Boolean \c true if the selected pipe is configured, \c false otherwise.
*/
static inline bool Pipe_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Pipe_IsConfigured(void)
{
return ((UPSTAX & (1 << CFGOK)) ? true : false);
}
/** Retrieves the endpoint address of the endpoint within the attached device that the currently selected
* pipe is bound to.
*
* \return Endpoint address the currently selected pipe is bound to.
*/
static inline uint8_t Pipe_GetBoundEndpointAddress(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Pipe_GetBoundEndpointAddress(void)
{
return (((UPCFG0X >> PEPNUM0) & PIPE_EPNUM_MASK) |
((Pipe_GetPipeToken() == PIPE_TOKEN_IN) ? PIPE_EPDIR_MASK : 0));
}
/** Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds.
*
* \param[in] Milliseconds Number of milliseconds between each pipe poll.
*/
static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds) ATTR_ALWAYS_INLINE;
static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds)
{
UPCFG2X = Milliseconds;
}
/** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should
* be serviced.
*
* \return Mask whose bits indicate which pipes have interrupted.
*/
static inline uint8_t Pipe_GetPipeInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Pipe_GetPipeInterrupts(void)
{
return UPINT;
}
/** Determines if the specified pipe number has interrupted (valid only for INTERRUPT type
* pipes).
*
* \param[in] PipeNumber Index of the pipe whose interrupt flag should be tested.
*
* \return Boolean \c true if the specified pipe has interrupted, \c false otherwise.
*/
static inline bool Pipe_HasPipeInterrupted(const uint8_t PipeNumber) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Pipe_HasPipeInterrupted(const uint8_t PipeNumber)
{
return ((UPINT & (1 << PipeNumber)) ? true : false);
}
/** Unfreezes the selected pipe, allowing it to communicate with an attached device. */
static inline void Pipe_Unfreeze(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_Unfreeze(void)
{
UPCONX &= ~(1 << PFREEZE);
}
/** Freezes the selected pipe, preventing it from communicating with an attached device. */
static inline void Pipe_Freeze(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_Freeze(void)
{
UPCONX |= (1 << PFREEZE);
}
/** Determines if the currently selected pipe is frozen, and not able to accept data.
*
* \return Boolean \c true if the currently selected pipe is frozen, \c false otherwise.
*/
static inline bool Pipe_IsFrozen(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Pipe_IsFrozen(void)
{
return ((UPCONX & (1 << PFREEZE)) ? true : false);
}
/** Clears the error flags for the currently selected pipe. */
static inline void Pipe_ClearError(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_ClearError(void)
{
UPERRX = 0;
UPINTX &= ~(1 << PERRI);
}
/** Determines if the master pipe error flag is set for the currently selected pipe, indicating that
* some sort of hardware error has occurred on the pipe.
*
* \see \ref Pipe_GetErrorFlags() macro for information on retrieving the exact error flag.
*
* \return Boolean \c true if an error has occurred on the selected pipe, \c false otherwise.
*/
static inline bool Pipe_IsError(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Pipe_IsError(void)
{
return ((UPINTX & (1 << PERRI)) ? true : false);
}
/** Gets a mask of the hardware error flags which have occurred on the currently selected pipe. This
* value can then be masked against the \c PIPE_ERRORFLAG_* masks to determine what error has occurred.
*
* \return Mask comprising of \c PIPE_ERRORFLAG_* bits indicating what error has occurred on the selected pipe.
*/
static inline uint8_t Pipe_GetErrorFlags(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Pipe_GetErrorFlags(void)
{
return ((UPERRX & (PIPE_ERRORFLAG_CRC16 | PIPE_ERRORFLAG_TIMEOUT |
PIPE_ERRORFLAG_PID | PIPE_ERRORFLAG_DATAPID |
PIPE_ERRORFLAG_DATATGL)) |
(UPSTAX & (PIPE_ERRORFLAG_OVERFLOW | PIPE_ERRORFLAG_UNDERFLOW)));
}
/** Retrieves the number of busy banks in the currently selected pipe, which have been queued for
* transmission via the \ref Pipe_ClearOUT() command, or are awaiting acknowledgement via the
* \ref Pipe_ClearIN() command.
*
* \ingroup Group_PipePacketManagement_AVR8
*
* \return Total number of busy banks in the selected pipe.
*/
static inline uint8_t Pipe_GetBusyBanks(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Pipe_GetBusyBanks(void)
{
return (UPSTAX & (0x03 << NBUSYBK0));
}
/** Determines if the currently selected pipe may be read from (if data is waiting in the pipe
* bank and the pipe is an IN direction, or if the bank is not yet full if the pipe is an OUT
* direction). This function will return false if an error has occurred in the pipe, or if the pipe
* is an IN direction and no packet (or an empty packet) has been received, or if the pipe is an OUT
* direction and the pipe bank is full.
*
* \note This function is not valid on CONTROL type pipes.
*
* \ingroup Group_PipePacketManagement_AVR8
*
* \return Boolean \c true if the currently selected pipe may be read from or written to, depending
* on its direction.
*/
static inline bool Pipe_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Pipe_IsReadWriteAllowed(void)
{
return ((UPINTX & (1 << RWAL)) ? true : false);
}
/** Determines if a packet has been received on the currently selected IN pipe from the attached device.
*
* \ingroup Group_PipePacketManagement_AVR8
*
* \return Boolean \c true if the current pipe has received an IN packet, \c false otherwise.
*/
static inline bool Pipe_IsINReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Pipe_IsINReceived(void)
{
return ((UPINTX & (1 << RXINI)) ? true : false);
}
/** Determines if the currently selected OUT pipe is ready to send an OUT packet to the attached device.
*
* \ingroup Group_PipePacketManagement_AVR8
*
* \return Boolean \c true if the current pipe is ready for an OUT packet, \c false otherwise.
*/
static inline bool Pipe_IsOUTReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Pipe_IsOUTReady(void)
{
return ((UPINTX & (1 << TXOUTI)) ? true : false);
}
/** Determines if no SETUP request is currently being sent to the attached device on the selected
* CONTROL type pipe.
*
* \ingroup Group_PipePacketManagement_AVR8
*
* \return Boolean \c true if the current pipe is ready for a SETUP packet, \c false otherwise.
*/
static inline bool Pipe_IsSETUPSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Pipe_IsSETUPSent(void)
{
return ((UPINTX & (1 << TXSTPI)) ? true : false);
}
/** Sends the currently selected CONTROL type pipe's contents to the device as a SETUP packet.
*
* \ingroup Group_PipePacketManagement_AVR8
*/
static inline void Pipe_ClearSETUP(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_ClearSETUP(void)
{
UPINTX &= ~((1 << TXSTPI) | (1 << FIFOCON));
}
/** Acknowledges the reception of a setup IN request from the attached device on the currently selected
* pipe, freeing the bank ready for the next packet.
*
* \ingroup Group_PipePacketManagement_AVR8
*/
static inline void Pipe_ClearIN(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_ClearIN(void)
{
UPINTX &= ~((1 << RXINI) | (1 << FIFOCON));
}
/** Sends the currently selected pipe's contents to the device as an OUT packet on the selected pipe, freeing
* the bank ready for the next packet.
*
* \ingroup Group_PipePacketManagement_AVR8
*/
static inline void Pipe_ClearOUT(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_ClearOUT(void)
{
UPINTX &= ~((1 << TXOUTI) | (1 << FIFOCON));
}
/** Determines if the device sent a NAK (Negative Acknowledge) in response to the last sent packet on
* the currently selected pipe. This occurs when the host sends a packet to the device, but the device
* is not currently ready to handle the packet (i.e. its endpoint banks are full). Once a NAK has been
* received, it must be cleared using \ref Pipe_ClearNAKReceived() before the previous (or any other) packet
* can be re-sent.
*
* \ingroup Group_PipePacketManagement_AVR8
*
* \return Boolean \c true if an NAK has been received on the current pipe, \c false otherwise.
*/
static inline bool Pipe_IsNAKReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Pipe_IsNAKReceived(void)
{
return ((UPINTX & (1 << NAKEDI)) ? true : false);
}
/** Clears the NAK condition on the currently selected pipe.
*
* \ingroup Group_PipePacketManagement_AVR8
*
* \see \ref Pipe_IsNAKReceived() for more details.
*/
static inline void Pipe_ClearNAKReceived(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_ClearNAKReceived(void)
{
UPINTX &= ~(1 << NAKEDI);
}
/** Determines if the currently selected pipe has had the STALL condition set by the attached device.
*
* \ingroup Group_PipePacketManagement_AVR8
*
* \return Boolean \c true if the current pipe has been stalled by the attached device, \c false otherwise.
*/
static inline bool Pipe_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Pipe_IsStalled(void)
{
return ((UPINTX & (1 << RXSTALLI)) ? true : false);
}
/** Clears the STALL condition detection flag on the currently selected pipe, but does not clear the
* STALL condition itself (this must be done via a ClearFeature control request to the device).
*
* \ingroup Group_PipePacketManagement_AVR8
*/
static inline void Pipe_ClearStall(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_ClearStall(void)
{
UPINTX &= ~(1 << RXSTALLI);
}
/** Reads one byte from the currently selected pipe's bank, for OUT direction pipes.
*
* \ingroup Group_PipePrimitiveRW_AVR8
*
* \return Next byte in the currently selected pipe's FIFO buffer.
*/
static inline uint8_t Pipe_Read_8(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Pipe_Read_8(void)
{
return UPDATX;
}
/** Writes one byte to the currently selected pipe's bank, for IN direction pipes.
*
* \ingroup Group_PipePrimitiveRW_AVR8
*
* \param[in] Data Data to write into the the currently selected pipe's FIFO buffer.
*/
static inline void Pipe_Write_8(const uint8_t Data) ATTR_ALWAYS_INLINE;
static inline void Pipe_Write_8(const uint8_t Data)
{
UPDATX = Data;
}
/** Discards one byte from the currently selected pipe's bank, for OUT direction pipes.
*
* \ingroup Group_PipePrimitiveRW_AVR8
*/
static inline void Pipe_Discard_8(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_Discard_8(void)
{
uint8_t Dummy;
Dummy = UPDATX;
(void)Dummy;
}
/** Reads two bytes from the currently selected pipe's bank in little endian format, for OUT
* direction pipes.
*
* \ingroup Group_PipePrimitiveRW_AVR8
*
* \return Next two bytes in the currently selected pipe's FIFO buffer.
*/
static inline uint16_t Pipe_Read_16_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint16_t Pipe_Read_16_LE(void)
{
union
{
uint16_t Value;
uint8_t Bytes[2];
} Data;
Data.Bytes[0] = UPDATX;
Data.Bytes[1] = UPDATX;
return Data.Value;
}
/** Reads two bytes from the currently selected pipe's bank in big endian format, for OUT
* direction pipes.
*
* \ingroup Group_PipePrimitiveRW_AVR8
*
* \return Next two bytes in the currently selected pipe's FIFO buffer.
*/
static inline uint16_t Pipe_Read_16_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint16_t Pipe_Read_16_BE(void)
{
union
{
uint16_t Value;
uint8_t Bytes[2];
} Data;
Data.Bytes[1] = UPDATX;
Data.Bytes[0] = UPDATX;
return Data.Value;
}
/** Writes two bytes to the currently selected pipe's bank in little endian format, for IN
* direction pipes.
*
* \ingroup Group_PipePrimitiveRW_AVR8
*
* \param[in] Data Data to write to the currently selected pipe's FIFO buffer.
*/
static inline void Pipe_Write_16_LE(const uint16_t Data) ATTR_ALWAYS_INLINE;
static inline void Pipe_Write_16_LE(const uint16_t Data)
{
UPDATX = (Data & 0xFF);
UPDATX = (Data >> 8);
}
/** Writes two bytes to the currently selected pipe's bank in big endian format, for IN
* direction pipes.
*
* \ingroup Group_PipePrimitiveRW_AVR8
*
* \param[in] Data Data to write to the currently selected pipe's FIFO buffer.
*/
static inline void Pipe_Write_16_BE(const uint16_t Data) ATTR_ALWAYS_INLINE;
static inline void Pipe_Write_16_BE(const uint16_t Data)
{
UPDATX = (Data >> 8);
UPDATX = (Data & 0xFF);
}
/** Discards two bytes from the currently selected pipe's bank, for OUT direction pipes.
*
* \ingroup Group_PipePrimitiveRW_AVR8
*/
static inline void Pipe_Discard_16(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_Discard_16(void)
{
uint8_t Dummy;
Dummy = UPDATX;
Dummy = UPDATX;
(void)Dummy;
}
/** Reads four bytes from the currently selected pipe's bank in little endian format, for OUT
* direction pipes.
*
* \ingroup Group_PipePrimitiveRW_AVR8
*
* \return Next four bytes in the currently selected pipe's FIFO buffer.
*/
static inline uint32_t Pipe_Read_32_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint32_t Pipe_Read_32_LE(void)
{
union
{
uint32_t Value;
uint8_t Bytes[4];
} Data;
Data.Bytes[0] = UPDATX;
Data.Bytes[1] = UPDATX;
Data.Bytes[2] = UPDATX;
Data.Bytes[3] = UPDATX;
return Data.Value;
}
/** Reads four bytes from the currently selected pipe's bank in big endian format, for OUT
* direction pipes.
*
* \ingroup Group_PipePrimitiveRW_AVR8
*
* \return Next four bytes in the currently selected pipe's FIFO buffer.
*/
static inline uint32_t Pipe_Read_32_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint32_t Pipe_Read_32_BE(void)
{
union
{
uint32_t DWord;
uint8_t Bytes[4];
} Data;
Data.Bytes[3] = UPDATX;
Data.Bytes[2] = UPDATX;
Data.Bytes[1] = UPDATX;
Data.Bytes[0] = UPDATX;
return Data.DWord;
}
/** Writes four bytes to the currently selected pipe's bank in little endian format, for IN
* direction pipes.
*
* \ingroup Group_PipePrimitiveRW_AVR8
*
* \param[in] Data Data to write to the currently selected pipe's FIFO buffer.
*/
static inline void Pipe_Write_32_LE(const uint32_t Data) ATTR_ALWAYS_INLINE;
static inline void Pipe_Write_32_LE(const uint32_t Data)
{
UPDATX = (Data & 0xFF);
UPDATX = (Data >> 8);
UPDATX = (Data >> 16);
UPDATX = (Data >> 24);
}
/** Writes four bytes to the currently selected pipe's bank in big endian format, for IN
* direction pipes.
*
* \ingroup Group_PipePrimitiveRW_AVR8
*
* \param[in] Data Data to write to the currently selected pipe's FIFO buffer.
*/
static inline void Pipe_Write_32_BE(const uint32_t Data) ATTR_ALWAYS_INLINE;
static inline void Pipe_Write_32_BE(const uint32_t Data)
{
UPDATX = (Data >> 24);
UPDATX = (Data >> 16);
UPDATX = (Data >> 8);
UPDATX = (Data & 0xFF);
}
/** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes.
*
* \ingroup Group_PipePrimitiveRW_AVR8
*/
static inline void Pipe_Discard_32(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_Discard_32(void)
{
uint8_t Dummy;
Dummy = UPDATX;
Dummy = UPDATX;
Dummy = UPDATX;
Dummy = UPDATX;
(void)Dummy;
}
/* External Variables: */
/** Global indicating the maximum packet size of the default control pipe located at address
* 0 in the device. This value is set to the value indicated in the attached device's device
* descriptor once the USB interface is initialized into host mode and a device is attached
* to the USB bus.
*
* \note This variable should be treated as read-only in the user application, and never manually
* changed in value.
*/
extern uint8_t USB_Host_ControlPipeSize;
/* Function Prototypes: */
/** Configures the specified pipe number with the given pipe type, token, target endpoint number in the
* attached device, bank size and banking mode.
*
* A newly configured pipe is frozen by default, and must be unfrozen before use via the \ref Pipe_Unfreeze()
* before being used. Pipes should be kept frozen unless waiting for data from a device while in IN mode, or
* sending data to the device in OUT mode. IN type pipes are also automatically configured to accept infinite
* numbers of IN requests without automatic freezing - this can be overridden by a call to
* \ref Pipe_SetFiniteINRequests().
*
* \param[in] Number Pipe number to configure. This must be more than 0 and less than \ref PIPE_TOTAL_PIPES.
*
* \param[in] Type Type of pipe to configure, an \c EP_TYPE_* mask. Not all pipe types are available on Low
* Speed USB devices - refer to the USB 2.0 specification.
*
* \param[in] Token Pipe data token, either \ref PIPE_TOKEN_SETUP, \ref PIPE_TOKEN_OUT or \ref PIPE_TOKEN_IN.
* All pipes (except Control type) are unidirectional - data may only be read from or
* written to the pipe bank based on its direction, not both.
*
* \param[in] EndpointNumber Endpoint index within the attached device that the pipe should interface to.
*
* \param[in] Size Size of the pipe's bank, where packets are stored before they are transmitted to
* the USB device, or after they have been received from the USB device (depending on
* the pipe's data direction). The bank size must indicate the maximum packet size that
* the pipe can handle.
*
* \param[in] Banks Number of banks to use for the pipe being configured, a \c PIPE_BANK_* mask. More banks
* uses more USB DPRAM, but offers better performance. Isochronous type pipes <b>must</b>
* have at least two banks.
*
* \note When the \c ORDERED_EP_CONFIG compile time option is used, Pipes <b>must</b> be configured in ascending order,
* or bank corruption will occur.
* \n\n
*
* \note Certain microcontroller model's pipes may have different maximum packet sizes based on the pipe's
* index - refer to the chosen microcontroller's datasheet to determine the maximum bank size for each pipe.
* \n\n
*
* \note The default control pipe should not be manually configured by the user application, as it is
* automatically configured by the library internally.
* \n\n
*
* \note This routine will automatically select the specified pipe upon success. Upon failure, the pipe which
* failed to reconfigure correctly will be selected.
*
* \return Boolean \c true if the configuration succeeded, \c false otherwise.
*/
bool Pipe_ConfigurePipe(const uint8_t Number,
const uint8_t Type,
const uint8_t Token,
const uint8_t EndpointNumber,
const uint16_t Size,
const uint8_t Banks);
/** Spin-loops until the currently selected non-control pipe is ready for the next packet of data to be read
* or written to it, aborting in the case of an error condition (such as a timeout or device disconnect).
*
* \ingroup Group_PipeRW_AVR8
*
* \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum.
*/
uint8_t Pipe_WaitUntilReady(void);
/** Determines if a pipe has been bound to the given device endpoint address. If a pipe which is bound to the given
* endpoint is found, it is automatically selected.
*
* \param[in] EndpointAddress Address and direction mask of the endpoint within the attached device to check.
*
* \return Boolean \c true if a pipe bound to the given endpoint address of the specified direction is found,
* \c false otherwise.
*/
bool Pipe_IsEndpointBound(const uint8_t EndpointAddress) ATTR_WARN_UNUSED_RESULT;
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Macros: */
#if !defined(ENDPOINT_CONTROLEP)
#define ENDPOINT_CONTROLEP 0
#endif
/* Inline Functions: */
static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes)
{
uint8_t MaskVal = 0;
uint16_t CheckBytes = 8;
while ((CheckBytes < Bytes) && (CheckBytes < PIPE_MAX_SIZE))
{
MaskVal++;
CheckBytes <<= 1;
}
return (MaskVal << EPSIZE0);
}
/* Function Prototypes: */
void Pipe_ClearPipes(void);
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,83 @@
/*
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.
*/
#if defined(TEMPLATE_FUNC_NAME)
uint8_t TEMPLATE_FUNC_NAME (void* const Buffer,
uint16_t Length)
{
uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
if (!(Length))
Endpoint_ClearOUT();
while (Length)
{
uint8_t USB_DeviceState_LCL = USB_DeviceState;
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
return ENDPOINT_RWCSTREAM_DeviceDisconnected;
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
return ENDPOINT_RWCSTREAM_BusSuspended;
else if (Endpoint_IsSETUPReceived())
return ENDPOINT_RWCSTREAM_HostAborted;
if (Endpoint_IsOUTReceived())
{
while (Length && Endpoint_BytesInEndpoint())
{
TEMPLATE_TRANSFER_BYTE(DataStream);
TEMPLATE_BUFFER_MOVE(DataStream, 1);
Length--;
}
Endpoint_ClearOUT();
}
}
while (!(Endpoint_IsINReady()))
{
uint8_t USB_DeviceState_LCL = USB_DeviceState;
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
return ENDPOINT_RWCSTREAM_DeviceDisconnected;
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
return ENDPOINT_RWCSTREAM_BusSuspended;
}
return ENDPOINT_RWCSTREAM_NoError;
}
#undef TEMPLATE_BUFFER_OFFSET
#undef TEMPLATE_BUFFER_MOVE
#undef TEMPLATE_FUNC_NAME
#undef TEMPLATE_TRANSFER_BYTE
#endif

View File

@ -0,0 +1,92 @@
/*
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.
*/
#if defined(TEMPLATE_FUNC_NAME)
uint8_t TEMPLATE_FUNC_NAME (const void* const Buffer,
uint16_t Length)
{
uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
bool LastPacketFull = false;
if (Length > USB_ControlRequest.wLength)
Length = USB_ControlRequest.wLength;
else if (!(Length))
Endpoint_ClearIN();
while (Length || LastPacketFull)
{
uint8_t USB_DeviceState_LCL = USB_DeviceState;
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
return ENDPOINT_RWCSTREAM_DeviceDisconnected;
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
return ENDPOINT_RWCSTREAM_BusSuspended;
else if (Endpoint_IsSETUPReceived())
return ENDPOINT_RWCSTREAM_HostAborted;
else if (Endpoint_IsOUTReceived())
break;
if (Endpoint_IsINReady())
{
uint16_t BytesInEndpoint = Endpoint_BytesInEndpoint();
while (Length && (BytesInEndpoint < USB_Device_ControlEndpointSize))
{
TEMPLATE_TRANSFER_BYTE(DataStream);
TEMPLATE_BUFFER_MOVE(DataStream, 1);
Length--;
BytesInEndpoint++;
}
LastPacketFull = (BytesInEndpoint == USB_Device_ControlEndpointSize);
Endpoint_ClearIN();
}
}
while (!(Endpoint_IsOUTReceived()))
{
uint8_t USB_DeviceState_LCL = USB_DeviceState;
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
return ENDPOINT_RWCSTREAM_DeviceDisconnected;
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
return ENDPOINT_RWCSTREAM_BusSuspended;
}
return ENDPOINT_RWCSTREAM_NoError;
}
#undef TEMPLATE_BUFFER_OFFSET
#undef TEMPLATE_BUFFER_MOVE
#undef TEMPLATE_FUNC_NAME
#undef TEMPLATE_TRANSFER_BYTE
#endif

View File

@ -0,0 +1,88 @@
/*
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.
*/
#if defined(TEMPLATE_FUNC_NAME)
uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed)
{
uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
uint16_t BytesInTransfer = 0;
uint8_t ErrorCode;
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
if (BytesProcessed != NULL)
{
Length -= *BytesProcessed;
TEMPLATE_BUFFER_MOVE(DataStream, *BytesProcessed);
}
while (Length)
{
if (!(Endpoint_IsReadWriteAllowed()))
{
TEMPLATE_CLEAR_ENDPOINT();
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
USB_USBTask();
#endif
if (BytesProcessed != NULL)
{
*BytesProcessed += BytesInTransfer;
return ENDPOINT_RWSTREAM_IncompleteTransfer;
}
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
else
{
TEMPLATE_TRANSFER_BYTE(DataStream);
TEMPLATE_BUFFER_MOVE(DataStream, 1);
Length--;
BytesInTransfer++;
}
}
return ENDPOINT_RWSTREAM_NoError;
}
#undef TEMPLATE_FUNC_NAME
#undef TEMPLATE_BUFFER_TYPE
#undef TEMPLATE_TRANSFER_BYTE
#undef TEMPLATE_CLEAR_ENDPOINT
#undef TEMPLATE_BUFFER_OFFSET
#undef TEMPLATE_BUFFER_MOVE
#endif

View File

@ -0,0 +1,87 @@
/*
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.
*/
#if defined(TEMPLATE_FUNC_NAME)
uint8_t TEMPLATE_FUNC_NAME (TEMPLATE_BUFFER_TYPE const Buffer,
uint16_t Length,
uint16_t* const BytesProcessed)
{
uint8_t* DataStream = ((uint8_t*)Buffer + TEMPLATE_BUFFER_OFFSET(Length));
uint16_t BytesInTransfer = 0;
uint8_t ErrorCode;
Pipe_SetPipeToken(TEMPLATE_TOKEN);
if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
if (BytesProcessed != NULL)
{
Length -= *BytesProcessed;
TEMPLATE_BUFFER_MOVE(DataStream, *BytesProcessed);
}
while (Length)
{
if (!(Pipe_IsReadWriteAllowed()))
{
TEMPLATE_CLEAR_PIPE();
if (BytesProcessed != NULL)
{
*BytesProcessed += BytesInTransfer;
return PIPE_RWSTREAM_IncompleteTransfer;
}
if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
}
else
{
TEMPLATE_TRANSFER_BYTE(DataStream);
TEMPLATE_BUFFER_MOVE(DataStream, 1);
Length--;
BytesInTransfer++;
}
}
return PIPE_RWSTREAM_NoError;
}
#undef TEMPLATE_FUNC_NAME
#undef TEMPLATE_BUFFER_TYPE
#undef TEMPLATE_TOKEN
#undef TEMPLATE_TRANSFER_BYTE
#undef TEMPLATE_CLEAR_PIPE
#undef TEMPLATE_BUFFER_OFFSET
#undef TEMPLATE_BUFFER_MOVE
#endif

View File

@ -0,0 +1,262 @@
/*
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
#define __INCLUDE_FROM_USB_CONTROLLER_C
#include "../USBController.h"
#if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY))
volatile uint8_t USB_CurrentMode = USB_MODE_None;
#endif
#if !defined(USE_STATIC_OPTIONS)
volatile uint8_t USB_Options;
#endif
void USB_Init(
#if defined(USB_CAN_BE_BOTH)
const uint8_t Mode
#endif
#if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS))
,
#elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS))
void
#endif
#if !defined(USE_STATIC_OPTIONS)
const uint8_t Options
#endif
)
{
#if !defined(USE_STATIC_OPTIONS)
USB_Options = Options;
#endif
if (!(USB_Options & USB_OPT_REG_DISABLED))
USB_REG_On();
else
USB_REG_Off();
if (!(USB_Options & USB_OPT_MANUAL_PLL))
{
#if defined(USB_SERIES_4_AVR)
PLLFRQ = (1 << PDIV2);
#endif
}
#if defined(USB_CAN_BE_BOTH)
if (Mode == USB_MODE_UID)
{
UHWCON |= (1 << UIDE);
USB_INT_Enable(USB_INT_IDTI);
USB_CurrentMode = USB_GetUSBModeFromUID();
}
else
{
UHWCON &= ~(1 << UIDE);
USB_CurrentMode = Mode;
}
#endif
USB_IsInitialized = true;
USB_ResetInterface();
}
void USB_Disable(void)
{
USB_INT_DisableAllInterrupts();
USB_INT_ClearAllInterrupts();
USB_Detach();
USB_Controller_Disable();
if (!(USB_Options & USB_OPT_MANUAL_PLL))
USB_PLL_Off();
USB_REG_Off();
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
USB_OTGPAD_Off();
#endif
#if defined(USB_CAN_BE_BOTH)
USB_CurrentMode = USB_MODE_None;
#endif
USB_IsInitialized = false;
}
void USB_ResetInterface(void)
{
#if defined(USB_CAN_BE_BOTH)
bool UIDModeSelectEnabled = ((UHWCON & (1 << UIDE)) != 0);
#endif
USB_INT_DisableAllInterrupts();
USB_INT_ClearAllInterrupts();
USB_Controller_Reset();
#if defined(USB_CAN_BE_BOTH)
if (UIDModeSelectEnabled)
USB_INT_Enable(USB_INT_IDTI);
#endif
USB_CLK_Unfreeze();
if (USB_CurrentMode == USB_MODE_Device)
{
#if defined(USB_CAN_BE_DEVICE)
#if (defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
UHWCON |= (1 << UIMOD);
#endif
if (!(USB_Options & USB_OPT_MANUAL_PLL))
{
#if defined(USB_SERIES_2_AVR)
USB_PLL_On();
while (!(USB_PLL_IsReady()));
#else
USB_PLL_Off();
#endif
}
USB_Init_Device();
#endif
}
else if (USB_CurrentMode == USB_MODE_Host)
{
#if defined(USB_CAN_BE_HOST)
UHWCON &= ~(1 << UIMOD);
if (!(USB_Options & USB_OPT_MANUAL_PLL))
{
#if defined(USB_CAN_BE_HOST)
USB_PLL_On();
while (!(USB_PLL_IsReady()));
#endif
}
USB_Init_Host();
#endif
}
#if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
USB_OTGPAD_On();
#endif
}
#if defined(USB_CAN_BE_DEVICE)
static void USB_Init_Device(void)
{
USB_DeviceState = DEVICE_STATE_Unattached;
USB_Device_ConfigurationNumber = 0;
#if !defined(NO_DEVICE_REMOTE_WAKEUP)
USB_Device_RemoteWakeupEnabled = false;
#endif
#if !defined(NO_DEVICE_SELF_POWER)
USB_Device_CurrentlySelfPowered = false;
#endif
#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
USB_Descriptor_Device_t* DeviceDescriptorPtr;
#if defined(ARCH_HAS_MULTI_ADDRESS_SPACE) && \
!(defined(USE_FLASH_DESCRIPTORS) || defined(USE_EEPROM_DESCRIPTORS) || defined(USE_RAM_DESCRIPTORS))
uint8_t DescriptorAddressSpace;
if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr, &DescriptorAddressSpace) != NO_DESCRIPTOR)
{
if (DescriptorAddressSpace == MEMSPACE_FLASH)
USB_Device_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
else if (DescriptorAddressSpace == MEMSPACE_EEPROM)
USB_Device_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
else
USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;
}
#else
if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR)
{
#if defined(USE_RAM_DESCRIPTORS)
USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;
#elif defined(USE_EEPROM_DESCRIPTORS)
USB_Device_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
#else
USB_Device_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
#endif
}
#endif
#endif
#if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
if (USB_Options & USB_DEVICE_OPT_LOWSPEED)
USB_Device_SetLowSpeed();
else
USB_Device_SetFullSpeed();
USB_INT_Enable(USB_INT_VBUSTI);
#endif
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
ENDPOINT_BANK_SINGLE);
USB_INT_Clear(USB_INT_SUSPI);
USB_INT_Enable(USB_INT_SUSPI);
USB_INT_Enable(USB_INT_EORSTI);
USB_Attach();
}
#endif
#if defined(USB_CAN_BE_HOST)
static void USB_Init_Host(void)
{
USB_HostState = HOST_STATE_Unattached;
USB_Host_ConfigurationNumber = 0;
USB_Host_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
USB_Host_HostMode_On();
USB_Host_VBUS_Auto_Off();
USB_Host_VBUS_Manual_Enable();
USB_Host_VBUS_Manual_On();
USB_INT_Enable(USB_INT_SRPI);
USB_INT_Enable(USB_INT_BCERRI);
USB_Attach();
}
#endif

View File

@ -0,0 +1,437 @@
/*
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.
*/
/** \file
* \brief USB Controller definitions for the AVR8 microcontrollers.
* \copydetails Group_USBManagement_AVR8
*
* \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.
*/
/** \ingroup Group_USBManagement
* \defgroup Group_USBManagement_AVR8 USB Interface Management (AVR8)
* \brief USB Controller definitions for the AVR8 microcontrollers.
*
* Functions, macros, variables, enums and types related to the setup and management of the USB interface.
*
* @{
*/
#ifndef __USBCONTROLLER_AVR8_H__
#define __USBCONTROLLER_AVR8_H__
/* Includes: */
#include "../../../../Common/Common.h"
#include "../USBMode.h"
#include "../Events.h"
#include "../USBTask.h"
#include "../USBInterrupt.h"
#if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)
#include "../Host.h"
#include "../OTG.h"
#include "../Pipe.h"
#include "../HostStandardReq.h"
#include "../PipeStream.h"
#endif
#if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
#include "../Device.h"
#include "../Endpoint.h"
#include "../DeviceStandardReq.h"
#include "../EndpointStream.h"
#endif
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks and Defines: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
#if !defined(F_USB)
#error F_USB is not defined. You must define F_USB to the frequency of the unprescaled USB controller clock in your project makefile.
#endif
#if (F_USB == 8000000)
#if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \
defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \
defined(__AVR_ATmega32U2__))
#define USB_PLL_PSC 0
#elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
#define USB_PLL_PSC 0
#elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) || defined(__AVR_ATmega32U6__))
#define USB_PLL_PSC ((1 << PLLP1) | (1 << PLLP0))
#elif (defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__))
#define USB_PLL_PSC ((1 << PLLP1) | (1 << PLLP0))
#endif
#elif (F_USB == 16000000)
#if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \
defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \
defined(__AVR_ATmega32U2__))
#define USB_PLL_PSC (1 << PLLP0)
#elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
#define USB_PLL_PSC (1 << PINDIV)
#elif (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_ATmega32U6__))
#define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP1))
#elif (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__))
#define USB_PLL_PSC ((1 << PLLP2) | (1 << PLLP0))
#endif
#endif
#if !defined(USB_PLL_PSC)
#error No PLL prescale value available for chosen F_USB value and AVR model.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** \name USB Controller Option Masks */
//@{
/** Regulator disable option mask for \ref USB_Init(). This indicates that the internal 3.3V USB data pad
* regulator should be disabled and the AVR's VCC level used for the data pads.
*
* \note See USB AVR data sheet for more information on the internal pad regulator.
*/
#define USB_OPT_REG_DISABLED (1 << 1)
/** Regulator enable option mask for \ref USB_Init(). This indicates that the internal 3.3V USB data pad
* regulator should be enabled to regulate the data pin voltages from the VBUS level down to a level within
* the range allowable by the USB standard.
*
* \note See USB AVR data sheet for more information on the internal pad regulator.
*/
#define USB_OPT_REG_ENABLED (0 << 1)
/** Manual PLL control option mask for \ref USB_Init(). This indicates to the library that the user application
* will take full responsibility for controlling the AVR's PLL (used to generate the high frequency clock
* that the USB controller requires) and ensuring that it is locked at the correct frequency for USB operations.
*/
#define USB_OPT_MANUAL_PLL (1 << 2)
/** Automatic PLL control option mask for \ref USB_Init(). This indicates to the library that the library should
* take full responsibility for controlling the AVR's PLL (used to generate the high frequency clock
* that the USB controller requires) and ensuring that it is locked at the correct frequency for USB operations.
*/
#define USB_OPT_AUTO_PLL (0 << 2)
//@}
#if !defined(USB_STREAM_TIMEOUT_MS) || defined(__DOXYGEN__)
/** Constant for the maximum software timeout period of the USB data stream transfer functions
* (both control and standard) when in either device or host mode. If the next packet of a stream
* is not received or acknowledged within this time period, the stream function will fail.
*
* This value may be overridden in the user project makefile as the value of the
* \ref USB_STREAM_TIMEOUT_MS token, and passed to the compiler using the -D switch.
*/
#define USB_STREAM_TIMEOUT_MS 100
#endif
/* Inline Functions: */
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
/** Determines if the VBUS line is currently high (i.e. the USB host is supplying power).
*
* \note This function is not available on some AVR models which do not support hardware VBUS monitoring.
*
* \return Boolean \c true if the VBUS line is currently detecting power from a host, \c false otherwise.
*/
static inline bool USB_VBUS_GetStatus(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_VBUS_GetStatus(void)
{
return ((USBSTA & (1 << VBUS)) ? true : false);
}
#endif
/** Detaches the device from the USB bus. This has the effect of removing the device from any
* attached host, ceasing USB communications. If no host is present, this prevents any host from
* enumerating the device once attached until \ref USB_Attach() is called.
*/
static inline void USB_Detach(void) ATTR_ALWAYS_INLINE;
static inline void USB_Detach(void)
{
UDCON |= (1 << DETACH);
}
/** Attaches the device to the USB bus. This announces the device's presence to any attached
* USB host, starting the enumeration process. If no host is present, attaching the device
* will allow for enumeration once a host is connected to the device.
*
* This is inexplicably also required for proper operation while in host mode, to enable the
* attachment of a device to the host. This is despite the bit being located in the device-mode
* register and despite the datasheet making no mention of its requirement in host mode.
*/
static inline void USB_Attach(void) ATTR_ALWAYS_INLINE;
static inline void USB_Attach(void)
{
UDCON &= ~(1 << DETACH);
}
/* Function Prototypes: */
/** Main function to initialize and start the USB interface. Once active, the USB interface will
* allow for device connection to a host when in device mode, or for device enumeration while in
* host mode.
*
* As the USB library relies on interrupts for the device and host mode enumeration processes,
* the user must enable global interrupts before or shortly after this function is called. In
* device mode, interrupts must be enabled within 500ms of this function being called to ensure
* that the host does not time out whilst enumerating the device. In host mode, interrupts may be
* enabled at the application's leisure however enumeration will not begin of an attached device
* until after this has occurred.
*
* Calling this function when the USB interface is already initialized will cause a complete USB
* interface reset and re-enumeration.
*
* \param[in] Mode This is a mask indicating what mode the USB interface is to be initialized to, a value
* from the \ref USB_Modes_t enum.
*
* \param[in] Options Mask indicating the options which should be used when initializing the USB
* interface to control the USB interface's behaviour. This should be comprised of
* a \c USB_OPT_REG_* mask to control the regulator, a \c USB_OPT_*_PLL mask to control the
* PLL, and a \c USB_DEVICE_OPT_* mask (when the device mode is enabled) to set the device
* mode speed.
*
* \note To reduce the FLASH requirements of the library if only device or host mode is required,
* the mode can be statically set in the project makefile by defining the token \c USB_DEVICE_ONLY
* (for device mode) or \c USB_HOST_ONLY (for host mode), passing the token to the compiler
* via the -D switch. If the mode is statically set, this parameter does not exist in the
* function prototype.
* \n\n
*
* \note To reduce the FLASH requirements of the library if only fixed settings are are required,
* the options may be set statically in the same manner as the mode (see the Mode parameter of
* this function). To statically set the USB options, pass in the \c USE_STATIC_OPTIONS token,
* defined to the appropriate options masks. When the options are statically set, this
* parameter does not exist in the function prototype.
* \n\n
*
* \note The mode parameter does not exist on devices where only one mode is possible, such as USB
* AVR models which only implement the USB device mode in hardware.
*
* \see \ref Group_Device for the \c USB_DEVICE_OPT_* masks.
*/
void USB_Init(
#if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__)
const uint8_t Mode
#endif
#if (defined(USB_CAN_BE_BOTH) && !defined(USE_STATIC_OPTIONS)) || defined(__DOXYGEN__)
,
#elif (!defined(USB_CAN_BE_BOTH) && defined(USE_STATIC_OPTIONS))
void
#endif
#if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)
const uint8_t Options
#endif
);
/** Shuts down the USB interface. This turns off the USB interface after deallocating all USB FIFO
* memory, endpoints and pipes. When turned off, no USB functionality can be used until the interface
* is restarted with the \ref USB_Init() function.
*/
void USB_Disable(void);
/** Resets the interface, when already initialized. This will re-enumerate the device if already connected
* to a host, or re-enumerate an already attached device when in host mode.
*/
void USB_ResetInterface(void);
/* Global Variables: */
#if (!defined(USB_HOST_ONLY) && !defined(USB_DEVICE_ONLY)) || defined(__DOXYGEN__)
/** Indicates the mode that the USB interface is currently initialized to, a value from the
* \ref USB_Modes_t enum.
*
* \note This variable should be treated as read-only in the user application, and never manually
* changed in value.
* \n\n
*
* \note When the controller is initialized into UID auto-detection mode, this variable will hold the
* currently selected USB mode (i.e. \ref USB_MODE_Device or \ref USB_MODE_Host). If the controller
* is fixed into a specific mode (either through the \c USB_DEVICE_ONLY or \c USB_HOST_ONLY compile time
* options, or a limitation of the USB controller in the chosen device model) this will evaluate to
* a constant of the appropriate value and will never evaluate to \ref USB_MODE_None even when the
* USB interface is not initialized.
*/
extern volatile uint8_t USB_CurrentMode;
#elif defined(USB_HOST_ONLY)
#define USB_CurrentMode USB_MODE_Host
#elif defined(USB_DEVICE_ONLY)
#define USB_CurrentMode USB_MODE_Device
#endif
#if !defined(USE_STATIC_OPTIONS) || defined(__DOXYGEN__)
/** Indicates the current USB options that the USB interface was initialized with when \ref USB_Init()
* was called. This value will be one of the \c USB_MODE_* masks defined elsewhere in this module.
*
* \note This variable should be treated as read-only in the user application, and never manually
* changed in value.
*/
extern volatile uint8_t USB_Options;
#elif defined(USE_STATIC_OPTIONS)
#define USB_Options USE_STATIC_OPTIONS
#endif
/* Enums: */
/** Enum for the possible USB controller modes, for initialization via \ref USB_Init() and indication back to the
* user application via \ref USB_CurrentMode.
*/
enum USB_Modes_t
{
USB_MODE_None = 0, /**< Indicates that the controller is currently not initialized in any specific USB mode. */
USB_MODE_Device = 1, /**< Indicates that the controller is currently initialized in USB Device mode. */
USB_MODE_Host = 2, /**< Indicates that the controller is currently initialized in USB Host mode. */
USB_MODE_UID = 3, /**< Indicates that the controller should determine the USB mode from the UID pin of the
* USB connector.
*/
};
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Function Prototypes: */
#if defined(__INCLUDE_FROM_USB_CONTROLLER_C)
#if defined(USB_CAN_BE_DEVICE)
static void USB_Init_Device(void);
#endif
#if defined(USB_CAN_BE_HOST)
static void USB_Init_Host(void);
#endif
#endif
/* Inline Functions: */
static inline void USB_PLL_On(void) ATTR_ALWAYS_INLINE;
static inline void USB_PLL_On(void)
{
PLLCSR = USB_PLL_PSC;
PLLCSR = (USB_PLL_PSC | (1 << PLLE));
}
static inline void USB_PLL_Off(void) ATTR_ALWAYS_INLINE;
static inline void USB_PLL_Off(void)
{
PLLCSR = 0;
}
static inline bool USB_PLL_IsReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_PLL_IsReady(void)
{
return ((PLLCSR & (1 << PLOCK)) ? true : false);
}
static inline void USB_REG_On(void) ATTR_ALWAYS_INLINE;
static inline void USB_REG_On(void)
{
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
UHWCON |= (1 << UVREGE);
#else
REGCR &= ~(1 << REGDIS);
#endif
}
static inline void USB_REG_Off(void) ATTR_ALWAYS_INLINE;
static inline void USB_REG_Off(void)
{
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
UHWCON &= ~(1 << UVREGE);
#else
REGCR |= (1 << REGDIS);
#endif
}
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
static inline void USB_OTGPAD_On(void) ATTR_ALWAYS_INLINE;
static inline void USB_OTGPAD_On(void)
{
USBCON |= (1 << OTGPADE);
}
static inline void USB_OTGPAD_Off(void) ATTR_ALWAYS_INLINE;
static inline void USB_OTGPAD_Off(void)
{
USBCON &= ~(1 << OTGPADE);
}
#endif
static inline void USB_CLK_Freeze(void) ATTR_ALWAYS_INLINE;
static inline void USB_CLK_Freeze(void)
{
USBCON |= (1 << FRZCLK);
}
static inline void USB_CLK_Unfreeze(void) ATTR_ALWAYS_INLINE;
static inline void USB_CLK_Unfreeze(void)
{
USBCON &= ~(1 << FRZCLK);
}
static inline void USB_Controller_Enable(void) ATTR_ALWAYS_INLINE;
static inline void USB_Controller_Enable(void)
{
USBCON |= (1 << USBE);
}
static inline void USB_Controller_Disable(void) ATTR_ALWAYS_INLINE;
static inline void USB_Controller_Disable(void)
{
USBCON &= ~(1 << USBE);
}
static inline void USB_Controller_Reset(void) ATTR_ALWAYS_INLINE;
static inline void USB_Controller_Reset(void)
{
USBCON &= ~(1 << USBE);
USBCON |= (1 << USBE);
}
#if defined(USB_CAN_BE_BOTH)
static inline uint8_t USB_GetUSBModeFromUID(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t USB_GetUSBModeFromUID(void)
{
if (USBSTA & (1 << ID))
return USB_MODE_Device;
else
return USB_MODE_Host;
}
#endif
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,275 @@
/*
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 "../USBInterrupt.h"
void USB_INT_DisableAllInterrupts(void)
{
#if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
USBCON &= ~((1 << VBUSTE) | (1 << IDTE));
#elif defined(USB_SERIES_4_AVR)
USBCON &= ~(1 << VBUSTE);
#endif
#if defined(USB_CAN_BE_BOTH)
OTGIEN = 0;
#endif
#if defined(USB_CAN_BE_HOST)
UHIEN = 0;
#endif
#if defined(USB_CAN_BE_DEVICE)
UDIEN = 0;
#endif
}
void USB_INT_ClearAllInterrupts(void)
{
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
USBINT = 0;
#endif
#if defined(USB_CAN_BE_BOTH)
OTGINT = 0;
#endif
#if defined(USB_CAN_BE_HOST)
UHINT = 0;
#endif
#if defined(USB_CAN_BE_DEVICE)
UDINT = 0;
#endif
}
ISR(USB_GEN_vect, ISR_BLOCK)
{
#if defined(USB_CAN_BE_DEVICE)
#if !defined(NO_SOF_EVENTS)
if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))
{
USB_INT_Clear(USB_INT_SOFI);
EVENT_USB_Device_StartOfFrame();
}
#endif
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
if (USB_INT_HasOccurred(USB_INT_VBUSTI) && USB_INT_IsEnabled(USB_INT_VBUSTI))
{
USB_INT_Clear(USB_INT_VBUSTI);
if (USB_VBUS_GetStatus())
{
if (!(USB_Options & USB_OPT_MANUAL_PLL))
{
USB_PLL_On();
while (!(USB_PLL_IsReady()));
}
USB_DeviceState = DEVICE_STATE_Powered;
EVENT_USB_Device_Connect();
}
else
{
if (!(USB_Options & USB_OPT_MANUAL_PLL))
USB_PLL_Off();
USB_DeviceState = DEVICE_STATE_Unattached;
EVENT_USB_Device_Disconnect();
}
}
#endif
if (USB_INT_HasOccurred(USB_INT_SUSPI) && USB_INT_IsEnabled(USB_INT_SUSPI))
{
USB_INT_Disable(USB_INT_SUSPI);
USB_INT_Enable(USB_INT_WAKEUPI);
USB_CLK_Freeze();
if (!(USB_Options & USB_OPT_MANUAL_PLL))
USB_PLL_Off();
#if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
USB_DeviceState = DEVICE_STATE_Unattached;
EVENT_USB_Device_Disconnect();
#else
USB_DeviceState = DEVICE_STATE_Suspended;
EVENT_USB_Device_Suspend();
#endif
}
if (USB_INT_HasOccurred(USB_INT_WAKEUPI) && USB_INT_IsEnabled(USB_INT_WAKEUPI))
{
if (!(USB_Options & USB_OPT_MANUAL_PLL))
{
USB_PLL_On();
while (!(USB_PLL_IsReady()));
}
USB_CLK_Unfreeze();
USB_INT_Clear(USB_INT_WAKEUPI);
USB_INT_Disable(USB_INT_WAKEUPI);
USB_INT_Enable(USB_INT_SUSPI);
if (USB_Device_ConfigurationNumber)
USB_DeviceState = DEVICE_STATE_Configured;
else
USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
#if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
EVENT_USB_Device_Connect();
#else
EVENT_USB_Device_WakeUp();
#endif
}
if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))
{
USB_INT_Clear(USB_INT_EORSTI);
USB_DeviceState = DEVICE_STATE_Default;
USB_Device_ConfigurationNumber = 0;
USB_INT_Clear(USB_INT_SUSPI);
USB_INT_Disable(USB_INT_SUSPI);
USB_INT_Enable(USB_INT_WAKEUPI);
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
ENDPOINT_BANK_SINGLE);
#if defined(INTERRUPT_CONTROL_ENDPOINT)
USB_INT_Enable(USB_INT_RXSTPI);
#endif
EVENT_USB_Device_Reset();
}
#endif
#if defined(USB_CAN_BE_HOST)
#if !defined(NO_SOF_EVENTS)
if (USB_INT_HasOccurred(USB_INT_HSOFI) && USB_INT_IsEnabled(USB_INT_HSOFI))
{
USB_INT_Clear(USB_INT_HSOFI);
EVENT_USB_Host_StartOfFrame();
}
#endif
if (USB_INT_HasOccurred(USB_INT_DDISCI) && USB_INT_IsEnabled(USB_INT_DDISCI))
{
USB_INT_Clear(USB_INT_DDISCI);
USB_INT_Clear(USB_INT_DCONNI);
USB_INT_Disable(USB_INT_DDISCI);
EVENT_USB_Host_DeviceUnattached();
USB_ResetInterface();
}
if (USB_INT_HasOccurred(USB_INT_VBERRI) && USB_INT_IsEnabled(USB_INT_VBERRI))
{
USB_INT_Clear(USB_INT_VBERRI);
USB_Host_VBUS_Manual_Off();
USB_Host_VBUS_Auto_Off();
EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip);
EVENT_USB_Host_DeviceUnattached();
USB_HostState = HOST_STATE_Unattached;
}
if (USB_INT_HasOccurred(USB_INT_SRPI) && USB_INT_IsEnabled(USB_INT_SRPI))
{
USB_INT_Clear(USB_INT_SRPI);
USB_INT_Disable(USB_INT_SRPI);
EVENT_USB_Host_DeviceAttached();
USB_INT_Enable(USB_INT_DDISCI);
USB_HostState = HOST_STATE_Powered;
}
if (USB_INT_HasOccurred(USB_INT_BCERRI) && USB_INT_IsEnabled(USB_INT_BCERRI))
{
USB_INT_Clear(USB_INT_BCERRI);
EVENT_USB_Host_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected, 0);
EVENT_USB_Host_DeviceUnattached();
USB_ResetInterface();
}
#endif
#if defined(USB_CAN_BE_BOTH)
if (USB_INT_HasOccurred(USB_INT_IDTI) && USB_INT_IsEnabled(USB_INT_IDTI))
{
USB_INT_Clear(USB_INT_IDTI);
if (USB_DeviceState != DEVICE_STATE_Unattached)
EVENT_USB_Device_Disconnect();
if (USB_HostState != HOST_STATE_Unattached)
EVENT_USB_Host_DeviceUnattached();
USB_CurrentMode = USB_GetUSBModeFromUID();
USB_ResetInterface();
EVENT_USB_UIDChange();
}
#endif
}
#if defined(INTERRUPT_CONTROL_ENDPOINT) && defined(USB_CAN_BE_DEVICE)
ISR(USB_COM_vect, ISR_BLOCK)
{
uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint();
Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
USB_INT_Disable(USB_INT_RXSTPI);
GlobalInterruptEnable();
USB_Device_ProcessControlRequest();
Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
USB_INT_Enable(USB_INT_RXSTPI);
Endpoint_SelectEndpoint(PrevSelectedEndpoint);
}
#endif

View File

@ -0,0 +1,369 @@
/*
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.
*/
/** \file
* \brief USB Controller Interrupt definitions for the AVR8 microcontrollers.
*
* This file contains definitions required for the correct handling of low level USB service routine interrupts
* from the USB controller.
*
* \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.
*/
#ifndef __USBINTERRUPT_AVR8_H__
#define __USBINTERRUPT_AVR8_H__
/* Includes: */
#include "../../../../Common/Common.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Enums: */
enum USB_Interrupts_t
{
#if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__))
USB_INT_VBUSTI = 0,
#endif
#if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
USB_INT_IDTI = 1,
#endif
#if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
USB_INT_WAKEUPI = 2,
USB_INT_SUSPI = 3,
USB_INT_EORSTI = 4,
USB_INT_SOFI = 5,
USB_INT_RXSTPI = 6,
#endif
#if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
USB_INT_HSOFI = 7,
USB_INT_DCONNI = 8,
USB_INT_DDISCI = 9,
USB_INT_RSTI = 10,
USB_INT_BCERRI = 11,
USB_INT_VBERRI = 12,
USB_INT_SRPI = 13,
#endif
};
/* Inline Functions: */
static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
static inline void USB_INT_Enable(const uint8_t Interrupt)
{
switch (Interrupt)
{
#if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
case USB_INT_VBUSTI:
USBCON |= (1 << VBUSTE);
break;
#endif
#if defined(USB_CAN_BE_BOTH)
case USB_INT_IDTI:
USBCON |= (1 << IDTE);
break;
#endif
#if defined(USB_CAN_BE_DEVICE)
case USB_INT_WAKEUPI:
UDIEN |= (1 << WAKEUPE);
break;
case USB_INT_SUSPI:
UDIEN |= (1 << SUSPE);
break;
case USB_INT_EORSTI:
UDIEN |= (1 << EORSTE);
break;
case USB_INT_SOFI:
UDIEN |= (1 << SOFE);
break;
case USB_INT_RXSTPI:
UEIENX |= (1 << RXSTPE);
break;
#endif
#if defined(USB_CAN_BE_HOST)
case USB_INT_HSOFI:
UHIEN |= (1 << HSOFE);
break;
case USB_INT_DCONNI:
UHIEN |= (1 << DCONNE);
break;
case USB_INT_DDISCI:
UHIEN |= (1 << DDISCE);
break;
case USB_INT_RSTI:
UHIEN |= (1 << RSTE);
break;
case USB_INT_BCERRI:
OTGIEN |= (1 << BCERRE);
break;
case USB_INT_VBERRI:
OTGIEN |= (1 << VBERRE);
break;
case USB_INT_SRPI:
OTGIEN |= (1 << SRPE);
break;
#endif
}
}
static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
static inline void USB_INT_Disable(const uint8_t Interrupt)
{
switch (Interrupt)
{
#if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
case USB_INT_VBUSTI:
USBCON &= ~(1 << VBUSTE);
break;
#endif
#if defined(USB_CAN_BE_BOTH)
case USB_INT_IDTI:
USBCON &= ~(1 << IDTE);
break;
#endif
#if defined(USB_CAN_BE_DEVICE)
case USB_INT_WAKEUPI:
UDIEN &= ~(1 << WAKEUPE);
break;
case USB_INT_SUSPI:
UDIEN &= ~(1 << SUSPE);
break;
case USB_INT_EORSTI:
UDIEN &= ~(1 << EORSTE);
break;
case USB_INT_SOFI:
UDIEN &= ~(1 << SOFE);
break;
case USB_INT_RXSTPI:
UEIENX &= ~(1 << RXSTPE);
break;
#endif
#if defined(USB_CAN_BE_HOST)
case USB_INT_HSOFI:
UHIEN &= ~(1 << HSOFE);
break;
case USB_INT_DCONNI:
UHIEN &= ~(1 << DCONNE);
break;
case USB_INT_DDISCI:
UHIEN &= ~(1 << DDISCE);
break;
case USB_INT_RSTI:
UHIEN &= ~(1 << RSTE);
break;
case USB_INT_BCERRI:
OTGIEN &= ~(1 << BCERRE);
break;
case USB_INT_VBERRI:
OTGIEN &= ~(1 << VBERRE);
break;
case USB_INT_SRPI:
OTGIEN &= ~(1 << SRPE);
break;
#endif
}
}
static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
static inline void USB_INT_Clear(const uint8_t Interrupt)
{
switch (Interrupt)
{
#if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
case USB_INT_VBUSTI:
USBINT &= ~(1 << VBUSTI);
break;
#endif
#if defined(USB_CAN_BE_BOTH)
case USB_INT_IDTI:
USBINT &= ~(1 << IDTI);
break;
#endif
#if defined(USB_CAN_BE_DEVICE)
case USB_INT_WAKEUPI:
UDINT &= ~(1 << WAKEUPI);
break;
case USB_INT_SUSPI:
UDINT &= ~(1 << SUSPI);
break;
case USB_INT_EORSTI:
UDINT &= ~(1 << EORSTI);
break;
case USB_INT_SOFI:
UDINT &= ~(1 << SOFI);
break;
case USB_INT_RXSTPI:
UEINTX &= ~(1 << RXSTPI);
break;
#endif
#if defined(USB_CAN_BE_HOST)
case USB_INT_HSOFI:
UHINT &= ~(1 << HSOFI);
break;
case USB_INT_DCONNI:
UHINT &= ~(1 << DCONNI);
break;
case USB_INT_DDISCI:
UHINT &= ~(1 << DDISCI);
break;
case USB_INT_RSTI:
UHINT &= ~(1 << RSTI);
break;
case USB_INT_BCERRI:
OTGINT &= ~(1 << BCERRI);
break;
case USB_INT_VBERRI:
OTGINT &= ~(1 << VBERRI);
break;
case USB_INT_SRPI:
OTGINT &= ~(1 << SRPI);
break;
#endif
}
}
static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
{
switch (Interrupt)
{
#if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
case USB_INT_VBUSTI:
return (USBCON & (1 << VBUSTE));
#endif
#if defined(USB_CAN_BE_BOTH)
case USB_INT_IDTI:
return (USBCON & (1 << IDTE));
#endif
#if defined(USB_CAN_BE_DEVICE)
case USB_INT_WAKEUPI:
return (UDIEN & (1 << WAKEUPE));
case USB_INT_SUSPI:
return (UDIEN & (1 << SUSPE));
case USB_INT_EORSTI:
return (UDIEN & (1 << EORSTE));
case USB_INT_SOFI:
return (UDIEN & (1 << SOFE));
case USB_INT_RXSTPI:
return (UEIENX & (1 << RXSTPE));
#endif
#if defined(USB_CAN_BE_HOST)
case USB_INT_HSOFI:
return (UHIEN & (1 << HSOFE));
case USB_INT_DCONNI:
return (UHIEN & (1 << DCONNE));
case USB_INT_DDISCI:
return (UHIEN & (1 << DDISCE));
case USB_INT_RSTI:
return (UHIEN & (1 << RSTE));
case USB_INT_BCERRI:
return (OTGIEN & (1 << BCERRE));
case USB_INT_VBERRI:
return (OTGIEN & (1 << VBERRE));
case USB_INT_SRPI:
return (OTGIEN & (1 << SRPE));
#endif
}
return false;
}
static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
{
switch (Interrupt)
{
#if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
case USB_INT_VBUSTI:
return (USBINT & (1 << VBUSTI));
#endif
#if defined(USB_CAN_BE_BOTH)
case USB_INT_IDTI:
return (USBINT & (1 << IDTI));
#endif
#if defined(USB_CAN_BE_DEVICE)
case USB_INT_WAKEUPI:
return (UDINT & (1 << WAKEUPI));
case USB_INT_SUSPI:
return (UDINT & (1 << SUSPI));
case USB_INT_EORSTI:
return (UDINT & (1 << EORSTI));
case USB_INT_SOFI:
return (UDINT & (1 << SOFI));
case USB_INT_RXSTPI:
return (UEINTX & (1 << RXSTPI));
#endif
#if defined(USB_CAN_BE_HOST)
case USB_INT_HSOFI:
return (UHINT & (1 << HSOFI));
case USB_INT_DCONNI:
return (UHINT & (1 << DCONNI));
case USB_INT_DDISCI:
return (UHINT & (1 << DDISCI));
case USB_INT_RSTI:
return (UHINT & (1 << RSTI));
case USB_INT_BCERRI:
return (OTGINT & (1 << BCERRI));
case USB_INT_VBERRI:
return (OTGINT & (1 << VBERRI));
case USB_INT_SRPI:
return (OTGINT & (1 << SRPI));
#endif
}
return false;
}
/* Includes: */
#include "../USBMode.h"
#include "../Events.h"
#include "../USBController.h"
/* Function Prototypes: */
void USB_INT_ClearAllInterrupts(void);
void USB_INT_DisableAllInterrupts(void);
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,146 @@
/*
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 "ConfigDescriptor.h"
#if defined(USB_CAN_BE_HOST)
uint8_t USB_Host_GetDeviceConfigDescriptor(const uint8_t ConfigNumber,
uint16_t* const ConfigSizePtr,
void* const BufferPtr,
const uint16_t BufferSize)
{
uint8_t ErrorCode;
uint8_t ConfigHeader[sizeof(USB_Descriptor_Configuration_Header_t)];
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_GetDescriptor,
.wValue = ((DTYPE_Configuration << 8) | (ConfigNumber - 1)),
.wIndex = 0,
.wLength = sizeof(USB_Descriptor_Configuration_Header_t),
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
if ((ErrorCode = USB_Host_SendControlRequest(ConfigHeader)) != HOST_SENDCONTROL_Successful)
return ErrorCode;
*ConfigSizePtr = le16_to_cpu(DESCRIPTOR_PCAST(ConfigHeader, USB_Descriptor_Configuration_Header_t)->TotalConfigurationSize);
if (*ConfigSizePtr > BufferSize)
return HOST_GETCONFIG_BuffOverflow;
USB_ControlRequest.wLength = *ConfigSizePtr;
if ((ErrorCode = USB_Host_SendControlRequest(BufferPtr)) != HOST_SENDCONTROL_Successful)
return ErrorCode;
if (DESCRIPTOR_TYPE(BufferPtr) != DTYPE_Configuration)
return HOST_GETCONFIG_InvalidData;
return HOST_GETCONFIG_Successful;
}
#endif
void USB_GetNextDescriptorOfType(uint16_t* const BytesRem,
void** const CurrConfigLoc,
const uint8_t Type)
{
while (*BytesRem)
{
USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)
return;
}
}
void USB_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem,
void** const CurrConfigLoc,
const uint8_t Type,
const uint8_t BeforeType)
{
while (*BytesRem)
{
USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)
{
return;
}
else if (DESCRIPTOR_TYPE(*CurrConfigLoc) == BeforeType)
{
*BytesRem = 0;
return;
}
}
}
void USB_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem,
void** const CurrConfigLoc,
const uint8_t Type,
const uint8_t AfterType)
{
USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, AfterType);
if (*BytesRem)
USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, Type);
}
uint8_t USB_GetNextDescriptorComp(uint16_t* const BytesRem,
void** const CurrConfigLoc,
ConfigComparatorPtr_t const ComparatorRoutine)
{
uint8_t ErrorCode;
while (*BytesRem)
{
uint8_t* PrevDescLoc = *CurrConfigLoc;
uint16_t PrevBytesRem = *BytesRem;
USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
if ((ErrorCode = ComparatorRoutine(*CurrConfigLoc)) != DESCRIPTOR_SEARCH_NotFound)
{
if (ErrorCode == DESCRIPTOR_SEARCH_Fail)
{
*CurrConfigLoc = PrevDescLoc;
*BytesRem = PrevBytesRem;
}
return ErrorCode;
}
}
return DESCRIPTOR_SEARCH_COMP_EndOfDescriptor;
}

View File

@ -0,0 +1,285 @@
/*
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.
*/
/** \file
* \brief USB Configuration Descriptor definitions.
* \copydetails Group_ConfigDescriptorParser
*
* \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.
*/
/** \ingroup Group_Descriptors
* \defgroup Group_ConfigDescriptorParser Configuration Descriptor Parser
* \brief USB Configuration Descriptor definitions.
*
* This section of the library gives a friendly API which can be used in host applications to easily
* parse an attached device's configuration descriptor so that endpoint, interface and other descriptor
* data can be extracted and used as needed.
*
* @{
*/
#ifndef __CONFIGDESCRIPTOR_H__
#define __CONFIGDESCRIPTOR_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
#include "HostStandardReq.h"
#include "StdDescriptors.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Casts a pointer to a descriptor inside the configuration descriptor into a pointer to the given
* descriptor type.
*
* Usage Example:
* \code
* uint8_t* CurrDescriptor = &ConfigDescriptor[0]; // Pointing to the configuration header
* USB_Descriptor_Configuration_Header_t* ConfigHeaderPtr = DESCRIPTOR_PCAST(CurrDescriptor,
* USB_Descriptor_Configuration_Header_t);
*
* // Can now access elements of the configuration header struct using the -> indirection operator
* \endcode
*/
#define DESCRIPTOR_PCAST(DescriptorPtr, Type) ((Type*)(DescriptorPtr))
/** Casts a pointer to a descriptor inside the configuration descriptor into the given descriptor
* type (as an actual struct instance rather than a pointer to a struct).
*
* Usage Example:
* \code
* uint8_t* CurrDescriptor = &ConfigDescriptor[0]; // Pointing to the configuration header
* USB_Descriptor_Configuration_Header_t ConfigHeader = DESCRIPTOR_CAST(CurrDescriptor,
* USB_Descriptor_Configuration_Header_t);
*
* // Can now access elements of the configuration header struct using the . operator
* \endcode
*/
#define DESCRIPTOR_CAST(DescriptorPtr, Type) (*DESCRIPTOR_PCAST(DescriptorPtr, Type))
/** Returns the descriptor's type, expressed as the 8-bit type value in the header of the descriptor.
* This value's meaning depends on the descriptor's placement in the descriptor, but standard type
* values can be accessed in the \ref USB_DescriptorTypes_t enum.
*/
#define DESCRIPTOR_TYPE(DescriptorPtr) DESCRIPTOR_PCAST(DescriptorPtr, USB_Descriptor_Header_t)->Type
/** Returns the descriptor's size, expressed as the 8-bit value indicating the number of bytes. */
#define DESCRIPTOR_SIZE(DescriptorPtr) DESCRIPTOR_PCAST(DescriptorPtr, USB_Descriptor_Header_t)->Size
/* Type Defines: */
/** Type define for a Configuration Descriptor comparator function (function taking a pointer to an array
* of type void, returning a uint8_t value).
*
* \see \ref USB_GetNextDescriptorComp function for more details.
*/
typedef uint8_t (* ConfigComparatorPtr_t)(void*);
/* Enums: */
/** Enum for the possible return codes of the \ref USB_Host_GetDeviceConfigDescriptor() function. */
enum USB_Host_GetConfigDescriptor_ErrorCodes_t
{
HOST_GETCONFIG_Successful = 0, /**< No error occurred while retrieving the configuration descriptor. */
HOST_GETCONFIG_DeviceDisconnect = 1, /**< The attached device was disconnected while retrieving the configuration
* descriptor.
*/
HOST_GETCONFIG_PipeError = 2, /**< An error occurred in the pipe while sending the request. */
HOST_GETCONFIG_SetupStalled = 3, /**< The attached device stalled the request to retrieve the configuration
* descriptor.
*/
HOST_GETCONFIG_SoftwareTimeOut = 4, /**< The request or data transfer timed out. */
HOST_GETCONFIG_BuffOverflow = 5, /**< The device's configuration descriptor is too large to fit into the allocated
* buffer.
*/
HOST_GETCONFIG_InvalidData = 6, /**< The device returned invalid configuration descriptor data. */
};
/** Enum for return values of a descriptor comparator function. */
enum DSearch_Return_ErrorCodes_t
{
DESCRIPTOR_SEARCH_Found = 0, /**< Current descriptor matches comparator criteria. */
DESCRIPTOR_SEARCH_Fail = 1, /**< No further descriptor could possibly match criteria, fail the search. */
DESCRIPTOR_SEARCH_NotFound = 2, /**< Current descriptor does not match comparator criteria. */
};
/** Enum for return values of \ref USB_GetNextDescriptorComp(). */
enum DSearch_Comp_Return_ErrorCodes_t
{
DESCRIPTOR_SEARCH_COMP_Found = 0, /**< Configuration descriptor now points to descriptor which matches
* search criteria of the given comparator function. */
DESCRIPTOR_SEARCH_COMP_Fail = 1, /**< Comparator function returned \ref DESCRIPTOR_SEARCH_Fail. */
DESCRIPTOR_SEARCH_COMP_EndOfDescriptor = 2, /**< End of configuration descriptor reached before match found. */
};
/* Function Prototypes: */
/** Retrieves the configuration descriptor data from an attached device via a standard request into a buffer,
* including validity and size checking to prevent a buffer overflow.
*
* \param[in] ConfigNumber Device configuration descriptor number to fetch from the device (usually set to 1 for
* single configuration devices).
* \param[in,out] ConfigSizePtr Pointer to a location for storing the retrieved configuration descriptor size.
* \param[out] BufferPtr Pointer to the buffer for storing the configuration descriptor data.
* \param[out] BufferSize Size of the allocated buffer where the configuration descriptor is to be stored.
*
* \return A value from the \ref USB_Host_GetConfigDescriptor_ErrorCodes_t enum.
*/
uint8_t USB_Host_GetDeviceConfigDescriptor(const uint8_t ConfigNumber,
uint16_t* const ConfigSizePtr,
void* const BufferPtr,
const uint16_t BufferSize) ATTR_NON_NULL_PTR_ARG(2) ATTR_NON_NULL_PTR_ARG(3);
/** Skips to the next sub-descriptor inside the configuration descriptor of the specified type value.
* The bytes remaining value is automatically decremented.
*
* \param[in,out] BytesRem Pointer to the number of bytes remaining of the configuration descriptor.
* \param[in,out] CurrConfigLoc Pointer to the current descriptor inside the configuration descriptor.
* \param[in] Type Descriptor type value to search for.
*/
void USB_GetNextDescriptorOfType(uint16_t* const BytesRem,
void** const CurrConfigLoc,
const uint8_t Type)
ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
/** Skips to the next sub-descriptor inside the configuration descriptor of the specified type value,
* which must come before a descriptor of the second given type value. If the BeforeType type
* descriptor is reached first, the number of bytes remaining to process is set to zero and the
* function exits. The bytes remaining value is automatically decremented.
*
* \param[in,out] BytesRem Pointer to the number of bytes remaining of the configuration descriptor.
* \param[in,out] CurrConfigLoc Pointer to the current descriptor inside the configuration descriptor.
* \param[in] Type Descriptor type value to search for.
* \param[in] BeforeType Descriptor type value which must not be reached before the given Type descriptor.
*/
void USB_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem,
void** const CurrConfigLoc,
const uint8_t Type,
const uint8_t BeforeType)
ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
/** Skips to the next sub-descriptor inside the configuration descriptor of the specified type value,
* which must come after a descriptor of the second given type value. The bytes remaining value is
* automatically decremented.
*
* \param[in,out] BytesRem Pointer to the number of bytes remaining of the configuration descriptor.
* \param[in,out] CurrConfigLoc Pointer to the current descriptor inside the configuration descriptor.
* \param[in] Type Descriptor type value to search for.
* \param[in] AfterType Descriptor type value which must be reached before the given Type descriptor.
*/
void USB_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem,
void** const CurrConfigLoc,
const uint8_t Type,
const uint8_t AfterType)
ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
/** Searches for the next descriptor in the given configuration descriptor using a pre-made comparator
* function. The routine updates the position and remaining configuration descriptor bytes values
* automatically. If a comparator routine fails a search, the descriptor pointer is retreated back
* so that the next descriptor search invocation will start from the descriptor which first caused the
* original search to fail. This behaviour allows for one comparator to be used immediately after another
* has failed, starting the second search from the descriptor which failed the first.
*
* Comparator functions should be standard functions which accept a pointer to the header of the current
* descriptor inside the configuration descriptor which is being compared, and should return a value from
* the \ref DSearch_Return_ErrorCodes_t enum as a uint8_t value.
*
* \note This function is available in USB Host mode only.
*
* \param[in,out] BytesRem Pointer to an int storing the remaining bytes in the configuration descriptor.
* \param[in,out] CurrConfigLoc Pointer to the current position in the configuration descriptor.
* \param[in] ComparatorRoutine Name of the comparator search function to use on the configuration descriptor.
*
* \return Value of one of the members of the \ref DSearch_Comp_Return_ErrorCodes_t enum.
*
* Usage Example:
* \code
* uint8_t EndpointSearcher(void* CurrentDescriptor); // Comparator Prototype
*
* uint8_t EndpointSearcher(void* CurrentDescriptor)
* {
* if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint)
* return DESCRIPTOR_SEARCH_Found;
* else
* return DESCRIPTOR_SEARCH_NotFound;
* }
*
* //...
* // After retrieving configuration descriptor:
* if (USB_Host_GetNextDescriptorComp(&BytesRemaining, &CurrentConfigLoc, EndpointSearcher) ==
* Descriptor_Search_Comp_Found)
* {
* // Do something with the endpoint descriptor
* }
* \endcode
*/
uint8_t USB_GetNextDescriptorComp(uint16_t* const BytesRem,
void** const CurrConfigLoc,
ConfigComparatorPtr_t const ComparatorRoutine);
/* Inline Functions: */
/** Skips over the current sub-descriptor inside the configuration descriptor, so that the pointer then
points to the next sub-descriptor. The bytes remaining value is automatically decremented.
*
* \param[in,out] BytesRem Pointer to the number of bytes remaining of the configuration descriptor.
* \param[in,out] CurrConfigLoc Pointer to the current descriptor inside the configuration descriptor.
*/
static inline void USB_GetNextDescriptor(uint16_t* const BytesRem,
void** CurrConfigLoc) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
static inline void USB_GetNextDescriptor(uint16_t* const BytesRem,
void** CurrConfigLoc)
{
uint16_t CurrDescriptorSize = DESCRIPTOR_CAST(*CurrConfigLoc, USB_Descriptor_Header_t).Size;
if (*BytesRem < CurrDescriptorSize)
CurrDescriptorSize = *BytesRem;
*CurrConfigLoc = (void*)((uintptr_t)*CurrConfigLoc + CurrDescriptorSize);
*BytesRem -= CurrDescriptorSize;
}
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,159 @@
/*
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.
*/
/** \file
* \brief Common USB Device definitions for all architectures.
* \copydetails Group_Device
*
* \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.
*/
/** \ingroup Group_USB
* \defgroup Group_Device Device Management
* \brief USB Device management definitions for USB device mode.
*
* USB Device mode related definitions common to all architectures. This module contains definitions which
* are used when the USB controller is initialized in device mode.
*
* @{
*/
#ifndef __USBDEVICE_H__
#define __USBDEVICE_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
#include "StdDescriptors.h"
#include "USBInterrupt.h"
#include "Endpoint.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Enums: */
/** Enum for the various states of the USB Device state machine. Only some states are
* implemented in the LUFA library - other states are left to the user to implement.
*
* For information on each possible USB device state, refer to the USB 2.0 specification.
*
* \see \ref USB_DeviceState, which stores the current device state machine state.
*/
enum USB_Device_States_t
{
DEVICE_STATE_Unattached = 0, /**< Internally implemented by the library. This state indicates
* that the device is not currently connected to a host.
*/
DEVICE_STATE_Powered = 1, /**< Internally implemented by the library. This state indicates
* that the device is connected to a host, but enumeration has not
* yet begun.
*/
DEVICE_STATE_Default = 2, /**< Internally implemented by the library. This state indicates
* that the device's USB bus has been reset by the host and it is
* now waiting for the host to begin the enumeration process.
*/
DEVICE_STATE_Addressed = 3, /**< Internally implemented by the library. This state indicates
* that the device has been addressed by the USB Host, but is not
* yet configured.
*/
DEVICE_STATE_Configured = 4, /**< May be implemented by the user project. This state indicates
* that the device has been enumerated by the host and is ready
* for USB communications to begin.
*/
DEVICE_STATE_Suspended = 5, /**< May be implemented by the user project. This state indicates
* that the USB bus has been suspended by the host, and the device
* should power down to a minimal power level until the bus is
* resumed.
*/
};
/* Function Prototypes: */
/** Function to retrieve a given descriptor's size and memory location from the given descriptor type value,
* index and language ID. This function MUST be overridden in the user application (added with full, identical
* prototype and name so that the library can call it to retrieve descriptor data.
*
* \param[in] wValue The type of the descriptor to retrieve in the upper byte, and the index in the
* lower byte (when more than one descriptor of the given type exists, such as the
* case of string descriptors). The type may be one of the standard types defined
* in the DescriptorTypes_t enum, or may be a class-specific descriptor type value.
* \param[in] wIndex The language ID of the string to return if the \c wValue type indicates
* \ref DTYPE_String, otherwise zero for standard descriptors, or as defined in a
* class-specific standards.
* \param[out] DescriptorAddress Pointer to the descriptor in memory. This should be set by the routine to
* the address of the descriptor.
* \param[out] MemoryAddressSpace A value from the \ref USB_DescriptorMemorySpaces_t enum to indicate the memory
* space in which the descriptor is stored. This parameter does not exist when one
* of the \c USE_*_DESCRIPTORS compile time options is used, or on architectures which
* use a unified address space.
*
* \note By default, the library expects all descriptors to be located in flash memory via the \c PROGMEM attribute.
* If descriptors should be located in RAM or EEPROM instead (to speed up access in the case of RAM, or to
* allow the descriptors to be changed dynamically at runtime) either the \c USE_RAM_DESCRIPTORS or the
* \c USE_EEPROM_DESCRIPTORS tokens may be defined in the project makefile and passed to the compiler by the -D
* switch.
*
* \return Size in bytes of the descriptor if it exists, zero or \ref NO_DESCRIPTOR otherwise.
*/
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex,
const void** const DescriptorAddress
#if (defined(ARCH_HAS_MULTI_ADDRESS_SPACE) || defined(__DOXYGEN__)) && \
!(defined(USE_FLASH_DESCRIPTORS) || defined(USE_EEPROM_DESCRIPTORS) || defined(USE_RAM_DESCRIPTORS))
, uint8_t* MemoryAddressSpace
#endif
) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
/* Architecture Includes: */
#if (ARCH == ARCH_AVR8)
#include "AVR8/Device_AVR8.h"
#elif (ARCH == ARCH_UC3)
#include "UC3/Device_UC3.h"
#elif (ARCH == ARCH_XMEGA)
#include "XMEGA/Device_XMEGA.h"
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,380 @@
/*
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_DEVICE)
#define __INCLUDE_FROM_DEVICESTDREQ_C
#include "DeviceStandardReq.h"
uint8_t USB_Device_ConfigurationNumber;
#if !defined(NO_DEVICE_SELF_POWER)
bool USB_Device_CurrentlySelfPowered;
#endif
#if !defined(NO_DEVICE_REMOTE_WAKEUP)
bool USB_Device_RemoteWakeupEnabled;
#endif
void USB_Device_ProcessControlRequest(void)
{
#if defined(ARCH_BIG_ENDIAN)
USB_ControlRequest.bmRequestType = Endpoint_Read_8();
USB_ControlRequest.bRequest = Endpoint_Read_8();
USB_ControlRequest.wValue = Endpoint_Read_16_LE();
USB_ControlRequest.wIndex = Endpoint_Read_16_LE();
USB_ControlRequest.wLength = Endpoint_Read_16_LE();
#else
uint8_t* RequestHeader = (uint8_t*)&USB_ControlRequest;
for (uint8_t RequestHeaderByte = 0; RequestHeaderByte < sizeof(USB_Request_Header_t); RequestHeaderByte++)
*(RequestHeader++) = Endpoint_Read_8();
#endif
EVENT_USB_Device_ControlRequest();
if (Endpoint_IsSETUPReceived())
{
uint8_t bmRequestType = USB_ControlRequest.bmRequestType;
switch (USB_ControlRequest.bRequest)
{
case REQ_GetStatus:
if ((bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) ||
(bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT)))
{
USB_Device_GetStatus();
}
break;
case REQ_ClearFeature:
case REQ_SetFeature:
if ((bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE)) ||
(bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT)))
{
USB_Device_ClearSetFeature();
}
break;
case REQ_SetAddress:
if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE))
USB_Device_SetAddress();
break;
case REQ_GetDescriptor:
if ((bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) ||
(bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE)))
{
USB_Device_GetDescriptor();
}
break;
case REQ_GetConfiguration:
if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE))
USB_Device_GetConfiguration();
break;
case REQ_SetConfiguration:
if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE))
USB_Device_SetConfiguration();
break;
}
}
if (Endpoint_IsSETUPReceived())
{
Endpoint_StallTransaction();
Endpoint_ClearSETUP();
}
}
static void USB_Device_SetAddress(void)
{
uint8_t DeviceAddress = (USB_ControlRequest.wValue & 0x7F);
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
GlobalInterruptDisable();
Endpoint_ClearSETUP();
Endpoint_ClearStatusStage();
while (!(Endpoint_IsINReady()));
USB_Device_SetDeviceAddress(DeviceAddress);
USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default;
SetGlobalInterruptMask(CurrentGlobalInt);
}
static void USB_Device_SetConfiguration(void)
{
#if defined(FIXED_NUM_CONFIGURATIONS)
if ((uint8_t)USB_ControlRequest.wValue > FIXED_NUM_CONFIGURATIONS)
return;
#else
USB_Descriptor_Device_t* DevDescriptorPtr;
#if defined(ARCH_HAS_MULTI_ADDRESS_SPACE)
#if defined(USE_FLASH_DESCRIPTORS)
#define MemoryAddressSpace MEMSPACE_FLASH
#elif defined(USE_EEPROM_DESCRIPTORS)
#define MemoryAddressSpace MEMSPACE_EEPROM
#elif defined(USE_SRAM_DESCRIPTORS)
#define MemoryAddressSpace MEMSPACE_SRAM
#else
uint8_t MemoryAddressSpace;
#endif
#endif
if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DevDescriptorPtr
#if defined(ARCH_HAS_MULTI_ADDRESS_SPACE) && \
!(defined(USE_FLASH_DESCRIPTORS) || defined(USE_EEPROM_DESCRIPTORS) || defined(USE_RAM_DESCRIPTORS))
, &MemoryAddressSpace
#endif
) == NO_DESCRIPTOR)
{
return;
}
#if defined(ARCH_HAS_MULTI_ADDRESS_SPACE)
if (MemoryAddressSpace == MEMSPACE_FLASH)
{
if (((uint8_t)USB_ControlRequest.wValue > pgm_read_byte(&DevDescriptorPtr->NumberOfConfigurations)))
return;
}
else if (MemoryAddressSpace == MEMSPACE_EEPROM)
{
if (((uint8_t)USB_ControlRequest.wValue > eeprom_read_byte(&DevDescriptorPtr->NumberOfConfigurations)))
return;
}
else
{
if ((uint8_t)USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations)
return;
}
#else
if ((uint8_t)USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations)
return;
#endif
#endif
Endpoint_ClearSETUP();
USB_Device_ConfigurationNumber = (uint8_t)USB_ControlRequest.wValue;
Endpoint_ClearStatusStage();
if (USB_Device_ConfigurationNumber)
USB_DeviceState = DEVICE_STATE_Configured;
else
USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
EVENT_USB_Device_ConfigurationChanged();
}
static void USB_Device_GetConfiguration(void)
{
Endpoint_ClearSETUP();
Endpoint_Write_8(USB_Device_ConfigurationNumber);
Endpoint_ClearIN();
Endpoint_ClearStatusStage();
}
#if !defined(NO_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL != NO_DESCRIPTOR)
static void USB_Device_GetInternalSerialDescriptor(void)
{
struct
{
USB_Descriptor_Header_t Header;
uint16_t UnicodeString[INTERNAL_SERIAL_LENGTH_BITS / 4];
} SignatureDescriptor;
SignatureDescriptor.Header.Type = DTYPE_String;
SignatureDescriptor.Header.Size = USB_STRING_LEN(INTERNAL_SERIAL_LENGTH_BITS / 4);
USB_Device_GetSerialString(SignatureDescriptor.UnicodeString);
Endpoint_ClearSETUP();
Endpoint_Write_Control_Stream_LE(&SignatureDescriptor, sizeof(SignatureDescriptor));
Endpoint_ClearOUT();
}
#endif
static void USB_Device_GetDescriptor(void)
{
const void* DescriptorPointer;
uint16_t DescriptorSize;
#if defined(ARCH_HAS_MULTI_ADDRESS_SPACE) && \
!(defined(USE_FLASH_DESCRIPTORS) || defined(USE_EEPROM_DESCRIPTORS) || defined(USE_RAM_DESCRIPTORS))
uint8_t DescriptorAddressSpace;
#endif
#if !defined(NO_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL != NO_DESCRIPTOR)
if (USB_ControlRequest.wValue == ((DTYPE_String << 8) | USE_INTERNAL_SERIAL))
{
USB_Device_GetInternalSerialDescriptor();
return;
}
#endif
if ((DescriptorSize = CALLBACK_USB_GetDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex,
&DescriptorPointer
#if defined(ARCH_HAS_MULTI_ADDRESS_SPACE) && \
!(defined(USE_FLASH_DESCRIPTORS) || defined(USE_EEPROM_DESCRIPTORS) || defined(USE_RAM_DESCRIPTORS))
, &DescriptorAddressSpace
#endif
)) == NO_DESCRIPTOR)
{
return;
}
Endpoint_ClearSETUP();
#if defined(USE_RAM_DESCRIPTORS) || !defined(ARCH_HAS_MULTI_ADDRESS_SPACE)
Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize);
#elif defined(USE_EEPROM_DESCRIPTORS)
Endpoint_Write_Control_EStream_LE(DescriptorPointer, DescriptorSize);
#elif defined(USE_FLASH_DESCRIPTORS)
Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize);
#else
if (DescriptorAddressSpace == MEMSPACE_FLASH)
Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize);
else if (DescriptorAddressSpace == MEMSPACE_EEPROM)
Endpoint_Write_Control_EStream_LE(DescriptorPointer, DescriptorSize);
else
Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize);
#endif
Endpoint_ClearOUT();
}
static void USB_Device_GetStatus(void)
{
uint8_t CurrentStatus = 0;
switch (USB_ControlRequest.bmRequestType)
{
#if !defined(NO_DEVICE_SELF_POWER) || !defined(NO_DEVICE_REMOTE_WAKEUP)
case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE):
#if !defined(NO_DEVICE_SELF_POWER)
if (USB_Device_CurrentlySelfPowered)
CurrentStatus |= FEATURE_SELFPOWERED_ENABLED;
#endif
#if !defined(NO_DEVICE_REMOTE_WAKEUP)
if (USB_Device_RemoteWakeupEnabled)
CurrentStatus |= FEATURE_REMOTE_WAKEUP_ENABLED;
#endif
break;
#endif
#if !defined(CONTROL_ONLY_DEVICE)
case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT):
Endpoint_SelectEndpoint((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK);
CurrentStatus = Endpoint_IsStalled();
Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
break;
#endif
default:
return;
}
Endpoint_ClearSETUP();
Endpoint_Write_16_LE(CurrentStatus);
Endpoint_ClearIN();
Endpoint_ClearStatusStage();
}
static void USB_Device_ClearSetFeature(void)
{
switch (USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT)
{
#if !defined(NO_DEVICE_REMOTE_WAKEUP)
case REQREC_DEVICE:
if ((uint8_t)USB_ControlRequest.wValue == FEATURE_SEL_DeviceRemoteWakeup)
USB_Device_RemoteWakeupEnabled = (USB_ControlRequest.bRequest == REQ_SetFeature);
else
return;
break;
#endif
#if !defined(CONTROL_ONLY_DEVICE)
case REQREC_ENDPOINT:
if ((uint8_t)USB_ControlRequest.wValue == FEATURE_SEL_EndpointHalt)
{
uint8_t EndpointIndex = ((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK);
if (EndpointIndex == ENDPOINT_CONTROLEP)
return;
Endpoint_SelectEndpoint(EndpointIndex);
if (Endpoint_IsEnabled())
{
if (USB_ControlRequest.bRequest == REQ_SetFeature)
{
Endpoint_StallTransaction();
}
else
{
Endpoint_ClearStall();
Endpoint_ResetEndpoint(EndpointIndex);
Endpoint_ResetDataToggle();
}
}
}
break;
#endif
default:
return;
}
Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
Endpoint_ClearSETUP();
Endpoint_ClearStatusStage();
}
#endif

View File

@ -0,0 +1,159 @@
/*
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.
*/
/** \file
* \brief USB device standard request management.
*
* This file contains the function prototypes necessary for the processing of incoming standard control requests
* when the library is in USB device mode.
*
* \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.
*/
#ifndef __DEVICESTDREQ_H__
#define __DEVICESTDREQ_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
#include "StdDescriptors.h"
#include "Events.h"
#include "StdRequestType.h"
#include "USBTask.h"
#include "USBController.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Enums: */
#if defined(ARCH_HAS_MULTI_ADDRESS_SPACE) || defined(__DOXYGEN__)
/** Enum for the possible descriptor memory spaces, for the \c MemoryAddressSpace parameter of the
* \ref CALLBACK_USB_GetDescriptor() function. This can be used when none of the \c USE_*_DESCRIPTORS
* compile time options are used, to indicate in which memory space the descriptor is stored.
*
* \ingroup Group_Device
*/
enum USB_DescriptorMemorySpaces_t
{
#if defined(ARCH_HAS_FLASH_ADDRESS_SPACE) || defined(__DOXYGEN__)
MEMSPACE_FLASH = 0, /**< Indicates the requested descriptor is located in FLASH memory. */
#endif
#if defined(ARCH_HAS_EEPROM_ADDRESS_SPACE) || defined(__DOXYGEN__)
MEMSPACE_EEPROM = 1, /**< Indicates the requested descriptor is located in EEPROM memory. */
#endif
MEMSPACE_RAM = 2, /**< Indicates the requested descriptor is located in RAM memory. */
};
#endif
/* Global Variables: */
/** Indicates the currently set configuration number of the device. USB devices may have several
* different configurations which the host can select between; this indicates the currently selected
* value, or 0 if no configuration has been selected.
*
* \note This variable should be treated as read-only in the user application, and never manually
* changed in value.
*
* \ingroup Group_Device
*/
extern uint8_t USB_Device_ConfigurationNumber;
#if !defined(NO_DEVICE_REMOTE_WAKEUP)
/** Indicates if the host is currently allowing the device to issue remote wakeup events. If this
* flag is cleared, the device should not issue remote wakeup events to the host.
*
* \note This variable should be treated as read-only in the user application, and never manually
* changed in value.
* \n\n
*
* \note To reduce FLASH usage of the compiled applications where Remote Wakeup is not supported,
* this global and the underlying management code can be disabled by defining the
* \c NO_DEVICE_REMOTE_WAKEUP token in the project makefile and passing it to the compiler via
* the -D switch.
*
* \ingroup Group_Device
*/
extern bool USB_Device_RemoteWakeupEnabled;
#endif
#if !defined(NO_DEVICE_SELF_POWER)
/** Indicates if the device is currently being powered by its own power supply, rather than being
* powered by the host's USB supply. This flag should remain cleared if the device does not
* support self powered mode, as indicated in the device descriptors.
*
* \ingroup Group_Device
*/
extern bool USB_Device_CurrentlySelfPowered;
#endif
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
#if defined(USE_RAM_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS)
#error USE_RAM_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
#elif defined(USE_RAM_DESCRIPTORS) && defined(USE_FLASH_DESCRIPTORS)
#error USE_RAM_DESCRIPTORS and USE_FLASH_DESCRIPTORS are mutually exclusive.
#elif defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS)
#error USE_FLASH_DESCRIPTORS and USE_EEPROM_DESCRIPTORS are mutually exclusive.
#elif defined(USE_FLASH_DESCRIPTORS) && defined(USE_EEPROM_DESCRIPTORS) && defined(USE_RAM_DESCRIPTORS)
#error Only one of the USE_*_DESCRIPTORS modes should be selected.
#endif
/* Function Prototypes: */
void USB_Device_ProcessControlRequest(void);
#if defined(__INCLUDE_FROM_DEVICESTDREQ_C)
static void USB_Device_SetAddress(void);
static void USB_Device_SetConfiguration(void);
static void USB_Device_GetConfiguration(void);
static void USB_Device_GetDescriptor(void);
static void USB_Device_GetStatus(void);
static void USB_Device_ClearSetFeature(void);
#if !defined(NO_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL != NO_DESCRIPTOR)
static void USB_Device_GetInternalSerialDescriptor(void);
#endif
#endif
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,118 @@
/*
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.
*/
/** \file
* \brief USB Endpoint definitions for all architectures.
* \copydetails Group_EndpointManagement
*
* \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.
*/
/** \ingroup Group_EndpointManagement
* \defgroup Group_EndpointRW Endpoint Data Reading and Writing
* \brief Endpoint data read/write definitions.
*
* Functions, macros, variables, enums and types related to data reading and writing from and to endpoints.
*/
/** \ingroup Group_EndpointRW
* \defgroup Group_EndpointPrimitiveRW Read/Write of Primitive Data Types
* \brief Endpoint data primitive read/write definitions.
*
* Functions, macros, variables, enums and types related to data reading and writing of primitive data types
* from and to endpoints.
*/
/** \ingroup Group_EndpointManagement
* \defgroup Group_EndpointPacketManagement Endpoint Packet Management
* \brief USB Endpoint package management definitions.
*
* Functions, macros, variables, enums and types related to packet management of endpoints.
*/
/** \ingroup Group_USB
* \defgroup Group_EndpointManagement Endpoint Management
* \brief Endpoint management definitions.
*
* Functions, macros and enums related to endpoint management when in USB Device mode. This
* module contains the endpoint management macros, as well as endpoint interrupt and data
* send/receive functions for various data types.
*
* @{
*/
#ifndef __ENDPOINT_H__
#define __ENDPOINT_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
* numerical address in the device.
*/
#define ENDPOINT_EPNUM_MASK 0x0F
/** Endpoint address for the default control endpoint, which always resides in address 0. This is
* defined for convenience to give more readable code when used with the endpoint macros.
*/
#define ENDPOINT_CONTROLEP 0
/* Architecture Includes: */
#if (ARCH == ARCH_AVR8)
#include "AVR8/Endpoint_AVR8.h"
#elif (ARCH == ARCH_UC3)
#include "UC3/Endpoint_UC3.h"
#elif (ARCH == ARCH_XMEGA)
#include "XMEGA/Endpoint_XMEGA.h"
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,124 @@
/*
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.
*/
/** \file
* \brief Endpoint data stream transmission and reception management.
* \copydetails Group_EndpointStreamRW
*
* \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.
*/
/** \ingroup Group_EndpointRW
* \defgroup Group_EndpointStreamRW Read/Write of Multi-Byte Streams
* \brief Endpoint data stream transmission and reception management.
*
* Functions, macros, variables, enums and types related to data reading and writing of data streams from
* and to endpoints.
*
* @{
*/
#ifndef __ENDPOINT_STREAM_H__
#define __ENDPOINT_STREAM_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Enums: */
/** Enum for the possible error return codes of the \c Endpoint_*_Stream_* functions. */
enum Endpoint_Stream_RW_ErrorCodes_t
{
ENDPOINT_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
ENDPOINT_RWSTREAM_EndpointStalled = 1, /**< The endpoint was stalled during the stream
* transfer by the host or device.
*/
ENDPOINT_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
* the transfer.
*/
ENDPOINT_RWSTREAM_BusSuspended = 3, /**< The USB bus has been suspended by the host and
* no USB endpoint traffic can occur until the bus
* has resumed.
*/
ENDPOINT_RWSTREAM_Timeout = 4, /**< The host failed to accept or send the next packet
* within the software timeout period set by the
* \ref USB_STREAM_TIMEOUT_MS macro.
*/
ENDPOINT_RWSTREAM_IncompleteTransfer = 5, /**< Indicates that the endpoint bank became full or empty before
* the complete contents of the current stream could be
* transferred. The endpoint stream function should be called
* again to process the next chunk of data in the transfer.
*/
};
/** Enum for the possible error return codes of the \c Endpoint_*_Control_Stream_* functions. */
enum Endpoint_ControlStream_RW_ErrorCodes_t
{
ENDPOINT_RWCSTREAM_NoError = 0, /**< Command completed successfully, no error. */
ENDPOINT_RWCSTREAM_HostAborted = 1, /**< The aborted the transfer prematurely. */
ENDPOINT_RWCSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
* the transfer.
*/
ENDPOINT_RWCSTREAM_BusSuspended = 3, /**< The USB bus has been suspended by the host and
* no USB endpoint traffic can occur until the bus
* has resumed.
*/
};
/* Architecture Includes: */
#if (ARCH == ARCH_AVR8)
#include "AVR8/EndpointStream_AVR8.h"
#elif (ARCH == ARCH_UC3)
#include "UC3/EndpointStream_UC3.h"
#elif (ARCH == ARCH_XMEGA)
#include "XMEGA/EndpointStream_XMEGA.h"
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,39 @@
/*
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_EVENTS_C
#define __INCLUDE_FROM_USB_DRIVER
#include "Events.h"
void USB_Event_Stub(void)
{
}

View File

@ -0,0 +1,366 @@
/*
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.
*/
/** \file
* \brief USB Event management definitions.
* \copydetails Group_Events
*
* \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.
*/
/** \ingroup Group_USB
* \defgroup Group_Events USB Events
* \brief USB Event management definitions.
*
* This module contains macros and functions relating to the management of library events, which are small
* pieces of code similar to ISRs which are run when a given condition is met. Each event can be fired from
* multiple places in the user or library code, which may or may not be inside an ISR, thus each handler
* should be written to be as small and fast as possible to prevent possible problems.
*
* Events can be hooked by the user application by declaring a handler function with the same name and parameters
* listed here. If an event with no user-associated handler is fired within the library, it by default maps to an
* internal empty stub function.
*
* Each event must only have one associated event handler, but can be raised by multiple sources by calling the
* event handler function (with any required event parameters).
*
* @{
*/
#ifndef __USBEVENTS_H__
#define __USBEVENTS_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Pseudo-Functions for Doxygen: */
#if !defined(__INCLUDE_FROM_EVENTS_C) || defined(__DOXYGEN__)
/** Event for USB mode pin level change. This event fires when the USB interface is set to dual role
* mode, and the UID pin level has changed to indicate a new mode (device or host). This event fires
* before the mode is switched to the newly indicated mode but after the \ref EVENT_USB_Device_Disconnect
* event has fired (if disconnected before the role change).
*
* \note This event only exists on microcontrollers that support dual role USB modes.
* \n\n
*
* \note This event does not exist if the \c USB_DEVICE_ONLY or \c USB_HOST_ONLY tokens have been supplied
* to the compiler (see \ref Group_USBManagement documentation).
*/
void EVENT_USB_UIDChange(void);
/** Event for USB host error. This event fires when a hardware fault has occurred whilst the USB
* interface is in host mode.
*
* \param[in] ErrorCode Error code indicating the failure reason, a value in \ref USB_Host_ErrorCodes_t.
*
* \note This event only exists on microcontrollers that supports USB host mode.
* \n\n
*
* \note This event does not exist if the \c USB_DEVICE_ONLY token is supplied to the compiler (see
* \ref Group_USBManagement documentation).
*/
void EVENT_USB_Host_HostError(const uint8_t ErrorCode);
/** Event for USB device attachment. This event fires when a the USB interface is in host mode, and
* a USB device has been connected to the USB interface. This is interrupt driven, thus fires before
* the standard \ref EVENT_USB_Device_Connect() event and so can be used to programmatically start the USB
* management task to reduce CPU consumption.
*
* \note This event only exists on microcontrollers that supports USB host mode.
* \n\n
*
* \note This event does not exist if the \c USB_DEVICE_ONLY token is supplied to the compiler (see
* \ref Group_USBManagement documentation).
*
* \see \ref USB_USBTask() for more information on the USB management task and reducing CPU usage.
*/
void EVENT_USB_Host_DeviceAttached(void);
/** Event for USB device removal. This event fires when a the USB interface is in host mode, and
* a USB device has been removed the USB interface whether or not it has been enumerated. This
* can be used to programmatically stop the USB management task to reduce CPU consumption.
*
* \note This event only exists on microcontrollers that supports USB host mode.
* \n\n
*
* \note This event does not exist if the \c USB_DEVICE_ONLY token is supplied to the compiler (see
* \ref Group_USBManagement documentation).
*
* \see \ref USB_USBTask() for more information on the USB management task and reducing CPU usage.
*/
void EVENT_USB_Host_DeviceUnattached(void);
/** Event for USB device enumeration failure. This event fires when a the USB interface is
* in host mode, and an attached USB device has failed to enumerate completely.
*
* \param[in] ErrorCode Error code indicating the failure reason, a value in
* \ref USB_Host_EnumerationErrorCodes_t.
*
* \param[in] SubErrorCode Sub error code indicating the reason for failure - for example, if the
* ErrorCode parameter indicates a control error, this will give the error
* code returned by the \ref USB_Host_SendControlRequest() function.
*
* \note This event only exists on microcontrollers that supports USB host mode.
* \n\n
*
* \note This event does not exist if the \c USB_DEVICE_ONLY token is supplied to the compiler (see
* \ref Group_USBManagement documentation).
*/
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
const uint8_t SubErrorCode);
/** Event for USB device enumeration completion. This event fires when a the USB interface is
* in host mode and an attached USB device has been completely enumerated and is ready to be
* controlled by the user application.
*
* This event is time-critical; exceeding OS-specific delays within this event handler (typically of around
* 1 second) when a transaction is waiting to be processed by the device will prevent break communications
* and cause the host to reset the USB bus.
*/
void EVENT_USB_Host_DeviceEnumerationComplete(void);
/** Event for USB Start Of Frame detection, when enabled. This event fires at the start of each USB
* frame, once per millisecond, and is synchronized to the USB bus. This can be used as an accurate
* millisecond timer source when the USB bus is not suspended while in host mode.
*
* This event is time-critical; it is run once per millisecond and thus long handlers will significantly
* degrade device performance. This event should only be enabled when needed to reduce device wake-ups.
*
* \note This event is not normally active - it must be manually enabled and disabled via the
* \ref USB_Host_EnableSOFEvents() and \ref USB_Host_DisableSOFEvents() commands after enumeration of
* a USB device.
* \n\n
*
* \note This event does not exist if the \c USB_DEVICE_ONLY token is supplied to the compiler (see
* \ref Group_USBManagement documentation).
*/
void EVENT_USB_Host_StartOfFrame(void);
/** Event for USB device connection. This event fires when the microcontroller is in USB Device mode
* and the device is connected to a USB host, beginning the enumeration process measured by a rising
* level on the microcontroller's VBUS sense pin.
*
* This event is time-critical; exceeding OS-specific delays within this event handler (typically of around
* two seconds) will prevent the device from enumerating correctly.
*
* \note For the microcontrollers with limited USB controller functionality, VBUS sensing is not available.
* this means that the current connection state is derived from the bus suspension and wake up events by default,
* which is not always accurate (host may suspend the bus while still connected). If the actual connection state
* needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by
* passing the \c NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
* and disconnection events may be manually fired, and the \ref USB_DeviceState global changed manually.
* \n\n
*
* \note This event may fire multiple times during device enumeration on the microcontrollers with limited USB controllers
* if \c NO_LIMITED_CONTROLLER_CONNECT is not defined.
*
* \see \ref Group_USBManagement for more information on the USB management task and reducing CPU usage.
*/
void EVENT_USB_Device_Connect(void);
/** Event for USB device disconnection. This event fires when the microcontroller is in USB Device mode and the device is
* disconnected from a host, measured by a falling level on the microcontroller's VBUS sense pin.
*
* \note For the microcontrollers with limited USB controllers, VBUS sense is not available to the USB controller.
* this means that the current connection state is derived from the bus suspension and wake up events by default,
* which is not always accurate (host may suspend the bus while still connected). If the actual connection state
* needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by
* passing the \c NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
* and disconnection events may be manually fired, and the \ref USB_DeviceState global changed manually.
* \n\n
*
* \note This event may fire multiple times during device enumeration on the microcontrollers with limited USB controllers
* if \c NO_LIMITED_CONTROLLER_CONNECT is not defined.
*
* \see \ref Group_USBManagement for more information on the USB management task and reducing CPU usage.
*/
void EVENT_USB_Device_Disconnect(void);
/** Event for control requests. This event fires when a the USB host issues a control request
* to the mandatory device control endpoint (of address 0). This may either be a standard
* request that the library may have a handler code for internally, or a class specific request
* issued to the device which must be handled appropriately. If a request is not processed in the
* user application via this event, it will be passed to the library for processing internally
* if a suitable handler exists.
*
* This event is time-critical; each packet within the request transaction must be acknowledged or
* sent within 50ms or the host will abort the transfer.
*
* The library internally handles all standard control requests with the exceptions of SYNC FRAME,
* SET DESCRIPTOR and SET INTERFACE. These and all other non-standard control requests will be left
* for the user to process via this event if desired. If not handled in the user application or by
* the library internally, unknown requests are automatically STALLed.
*
* \note This event does not exist if the \c USB_HOST_ONLY token is supplied to the compiler (see
* \ref Group_USBManagement documentation).
* \n\n
*
* \note Requests should be handled in the same manner as described in the USB 2.0 Specification,
* or appropriate class specification. In all instances, the library has already read the
* request SETUP parameters into the \ref USB_ControlRequest structure which should then be used
* by the application to determine how to handle the issued request.
*/
void EVENT_USB_Device_ControlRequest(void);
/** Event for USB configuration number changed. This event fires when a the USB host changes the
* selected configuration number while in device mode. This event should be hooked in device
* applications to create the endpoints and configure the device for the selected configuration.
*
* This event is time-critical; exceeding OS-specific delays within this event handler (typically of around
* one second) will prevent the device from enumerating correctly.
*
* This event fires after the value of \ref USB_Device_ConfigurationNumber has been changed.
*
* \note This event does not exist if the \c USB_HOST_ONLY token is supplied to the compiler (see
* \ref Group_USBManagement documentation).
*/
void EVENT_USB_Device_ConfigurationChanged(void);
/** Event for USB suspend. This event fires when a the USB host suspends the device by halting its
* transmission of Start Of Frame pulses to the device. This is generally hooked in order to move
* the device over to a low power state until the host wakes up the device. If the USB interface is
* enumerated with the \ref USB_OPT_AUTO_PLL option set, the library will automatically suspend the
* USB PLL before the event is fired to save power.
*
* \note This event does not exist if the \c USB_HOST_ONLY token is supplied to the compiler (see
* \ref Group_USBManagement documentation).
* \n\n
*
* \note This event does not exist on the microcontrollers with limited USB VBUS sensing abilities
* when the \c NO_LIMITED_CONTROLLER_CONNECT compile time token is not set - see
* \ref EVENT_USB_Device_Disconnect.
*
* \see \ref EVENT_USB_Device_WakeUp() event for accompanying Wake Up event.
*/
void EVENT_USB_Device_Suspend(void);
/** Event for USB wake up. This event fires when a the USB interface is suspended while in device
* mode, and the host wakes up the device by supplying Start Of Frame pulses. This is generally
* hooked to pull the user application out of a low power state and back into normal operating
* mode. If the USB interface is enumerated with the \ref USB_OPT_AUTO_PLL option set, the library
* will automatically restart the USB PLL before the event is fired.
*
* \note This event does not exist if the \c USB_HOST_ONLY token is supplied to the compiler (see
* \ref Group_USBManagement documentation).
* \n\n
*
* \note This event does not exist on the microcontrollers with limited USB VBUS sensing abilities
* when the \c NO_LIMITED_CONTROLLER_CONNECT compile time token is not set - see
* \ref EVENT_USB_Device_Disconnect.
*
* \see \ref EVENT_USB_Device_Suspend() event for accompanying Suspend event.
*/
void EVENT_USB_Device_WakeUp(void);
/** Event for USB interface reset. This event fires when the USB interface is in device mode, and
* a the USB host requests that the device reset its interface. This event fires after the control
* endpoint has been automatically configured by the library.
*
* This event is time-critical; exceeding OS-specific delays within this event handler (typically of around
* two seconds) will prevent the device from enumerating correctly.
*
* \note This event does not exist if the \c USB_HOST_ONLY token is supplied to the compiler (see
* \ref Group_USBManagement documentation).
*/
void EVENT_USB_Device_Reset(void);
/** Event for USB Start Of Frame detection, when enabled. This event fires at the start of each USB
* frame, once per millisecond, and is synchronized to the USB bus. This can be used as an accurate
* millisecond timer source when the USB bus is enumerated in device mode to a USB host.
*
* This event is time-critical; it is run once per millisecond and thus long handlers will significantly
* degrade device performance. This event should only be enabled when needed to reduce device wake-ups.
*
* \pre This event is not normally active - it must be manually enabled and disabled via the
* \ref USB_Device_EnableSOFEvents() and \ref USB_Device_DisableSOFEvents() commands after enumeration.
* \n\n
*
* \note This event does not exist if the \c USB_HOST_ONLY token is supplied to the compiler (see
* \ref Group_USBManagement documentation).
*/
void EVENT_USB_Device_StartOfFrame(void);
#endif
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Function Prototypes: */
#if defined(__INCLUDE_FROM_EVENTS_C)
void USB_Event_Stub(void) ATTR_CONST;
#if defined(USB_CAN_BE_BOTH)
void EVENT_USB_UIDChange(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
#endif
#if defined(USB_CAN_BE_HOST)
void EVENT_USB_Host_HostError(const uint8_t ErrorCode) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_Host_DeviceAttached(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_Host_DeviceUnattached(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_Host_DeviceEnumerationComplete(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
const uint8_t SubErrorCode)
ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_Host_StartOfFrame(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
#endif
#if defined(USB_CAN_BE_DEVICE)
void EVENT_USB_Device_Connect(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_Device_Disconnect(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_Device_ControlRequest(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_Device_ConfigurationChanged(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_Device_Suspend(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_Device_WakeUp(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_Device_Reset(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
void EVENT_USB_Device_StartOfFrame(void) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
#endif
#endif
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,139 @@
/*
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.
*/
/** \file
* \brief Common USB Host definitions for all architectures.
* \copydetails Group_Host
*
* \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.
*/
/** \ingroup Group_USB
* \defgroup Group_Host Host Management
* \brief USB Host management definitions for USB host mode.
*
* USB Host mode related macros and enums. This module contains macros and enums which are used when
* the USB controller is initialized in host mode.
*
* @{
*/
#ifndef __USBHOST_H__
#define __USBHOST_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Enums: */
/** Enum for the various states of the USB Host state machine.
*
* For information on each possible USB host state, refer to the USB 2.0 specification.
* Several of the USB host states are broken up further into multiple smaller sub-states,
* so that they can be internally implemented inside the library in an efficient manner.
*
* \see \ref USB_HostState, which stores the current host state machine state.
*/
enum USB_Host_States_t
{
HOST_STATE_WaitForDevice = 0, /**< This state indicates that the stack is waiting for an interval
* to elapse before continuing with the next step of the device
* enumeration process.
*/
HOST_STATE_Unattached = 1, /**< This state indicates that the host state machine is waiting for
* a device to be attached so that it can start the enumeration process.
*/
HOST_STATE_Powered = 2, /**< This state indicates that a device has been attached, and the
* library's internals are being configured to begin the enumeration
* process.
*/
HOST_STATE_Powered_WaitForDeviceSettle = 3, /**< This state indicates that the stack is waiting for the initial
* settling period to elapse before beginning the enumeration process.
*/
HOST_STATE_Powered_WaitForConnect = 4, /**< This state indicates that the stack is waiting for a connection event
* from the USB controller to indicate a valid USB device has been attached
* to the bus and is ready to be enumerated.
*/
HOST_STATE_Powered_DoReset = 5, /**< This state indicates that a valid USB device has been attached, and that
* it will now be reset to ensure it is ready for enumeration.
*/
HOST_STATE_Powered_ConfigPipe = 6, /**< This state indicates that the attached device is currently powered and
* reset, and that the control pipe is now being configured by the stack.
*/
HOST_STATE_Default = 7, /**< This state indicates that the stack is currently retrieving the control
* endpoint's size from the device, so that the control pipe can be altered
* to match.
*/
HOST_STATE_Default_PostReset = 8, /**< This state indicates that the control pipe is being reconfigured to match
* the retrieved control endpoint size from the device, and the device's USB
* bus address is being set.
*/
HOST_STATE_Default_PostAddressSet = 9, /**< This state indicates that the device's address has now been set, and the
* stack is has now completed the device enumeration process. This state causes
* the stack to change the current USB device address to that set for the
* connected device, before progressing to the \ref HOST_STATE_Addressed state
* ready for use in the user application.
*/
HOST_STATE_Addressed = 10, /**< Indicates that the device has been enumerated and addressed, and is now waiting
* for the user application to configure the device ready for use.
*/
HOST_STATE_Configured = 11, /**< Indicates that the device has been configured into a valid device configuration,
* ready for general use by the user application.
*/
};
/* Architecture Includes: */
#if (ARCH == ARCH_AVR8)
#include "AVR8/Host_AVR8.h"
#elif (ARCH == ARCH_UC3)
#include "UC3/Host_UC3.h"
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,316 @@
/*
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_HOSTSTDREQ_C
#include "HostStandardReq.h"
uint8_t USB_Host_ConfigurationNumber;
uint8_t USB_Host_SendControlRequest(void* const BufferPtr)
{
uint8_t* DataStream = (uint8_t*)BufferPtr;
bool BusSuspended = USB_Host_IsBusSuspended();
uint8_t ReturnStatus = HOST_SENDCONTROL_Successful;
uint16_t DataLen = USB_ControlRequest.wLength;
USB_Host_ResumeBus();
if ((ReturnStatus = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful)
goto End_Of_Control_Send;
Pipe_SetPipeToken(PIPE_TOKEN_SETUP);
Pipe_ClearError();
Pipe_Unfreeze();
#if defined(ARCH_BIG_ENDIAN)
Pipe_Write_8(USB_ControlRequest.bmRequestType);
Pipe_Write_8(USB_ControlRequest.bRequest);
Pipe_Write_16_LE(USB_ControlRequest.wValue);
Pipe_Write_16_LE(USB_ControlRequest.wIndex);
Pipe_Write_16_LE(USB_ControlRequest.wLength);
#else
uint8_t* HeaderStream = (uint8_t*)&USB_ControlRequest;
for (uint8_t HeaderByte = 0; HeaderByte < sizeof(USB_Request_Header_t); HeaderByte++)
Pipe_Write_8(*(HeaderStream++));
#endif
Pipe_ClearSETUP();
if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_SetupSent)) != HOST_SENDCONTROL_Successful)
goto End_Of_Control_Send;
Pipe_Freeze();
if ((ReturnStatus = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful)
goto End_Of_Control_Send;
if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_DIRECTION) == REQDIR_DEVICETOHOST)
{
Pipe_SetPipeToken(PIPE_TOKEN_IN);
if (DataStream != NULL)
{
while (DataLen)
{
Pipe_Unfreeze();
if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_InReceived)) != HOST_SENDCONTROL_Successful)
goto End_Of_Control_Send;
if (!(Pipe_BytesInPipe()))
DataLen = 0;
while (Pipe_BytesInPipe() && DataLen)
{
*(DataStream++) = Pipe_Read_8();
DataLen--;
}
Pipe_Freeze();
Pipe_ClearIN();
}
}
Pipe_SetPipeToken(PIPE_TOKEN_OUT);
Pipe_Unfreeze();
if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_OutReady)) != HOST_SENDCONTROL_Successful)
goto End_Of_Control_Send;
Pipe_ClearOUT();
if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_OutReady)) != HOST_SENDCONTROL_Successful)
goto End_Of_Control_Send;
}
else
{
if (DataStream != NULL)
{
Pipe_SetPipeToken(PIPE_TOKEN_OUT);
Pipe_Unfreeze();
while (DataLen)
{
if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_OutReady)) != HOST_SENDCONTROL_Successful)
goto End_Of_Control_Send;
while (DataLen && (Pipe_BytesInPipe() < USB_Host_ControlPipeSize))
{
Pipe_Write_8(*(DataStream++));
DataLen--;
}
Pipe_ClearOUT();
}
if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_OutReady)) != HOST_SENDCONTROL_Successful)
goto End_Of_Control_Send;
Pipe_Freeze();
}
Pipe_SetPipeToken(PIPE_TOKEN_IN);
Pipe_Unfreeze();
if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_InReceived)) != HOST_SENDCONTROL_Successful)
goto End_Of_Control_Send;
Pipe_ClearIN();
}
End_Of_Control_Send:
Pipe_Freeze();
if (BusSuspended)
USB_Host_SuspendBus();
Pipe_ResetPipe(PIPE_CONTROLPIPE);
return ReturnStatus;
}
static uint8_t USB_Host_WaitForIOS(const uint8_t WaitType)
{
#if (USB_HOST_TIMEOUT_MS < 0xFF)
uint8_t TimeoutCounter = USB_HOST_TIMEOUT_MS;
#else
uint16_t TimeoutCounter = USB_HOST_TIMEOUT_MS;
#endif
while (!(((WaitType == USB_HOST_WAITFOR_SetupSent) && Pipe_IsSETUPSent()) ||
((WaitType == USB_HOST_WAITFOR_InReceived) && Pipe_IsINReceived()) ||
((WaitType == USB_HOST_WAITFOR_OutReady) && Pipe_IsOUTReady())))
{
uint8_t ErrorCode;
if ((ErrorCode = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful)
return ErrorCode;
if (!(TimeoutCounter--))
return HOST_SENDCONTROL_SoftwareTimeOut;
}
return HOST_SENDCONTROL_Successful;
}
uint8_t USB_Host_SetDeviceConfiguration(const uint8_t ConfigNumber)
{
uint8_t ErrorCode;
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);
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) == HOST_SENDCONTROL_Successful)
{
USB_Host_ConfigurationNumber = ConfigNumber;
USB_HostState = (ConfigNumber) ? HOST_STATE_Configured : HOST_STATE_Addressed;
}
return ErrorCode;
}
uint8_t USB_Host_GetDeviceConfiguration(uint8_t* const ConfigNumber)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_GetConfiguration,
.wValue = 0,
.wIndex = 0,
.wLength = sizeof(uint8_t),
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(ConfigNumber);
}
uint8_t USB_Host_GetDescriptor(const uint8_t Type,
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 = (((uint16_t)Type << 8) | Index),
.wIndex = 0,
.wLength = BufferLength,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(Buffer);
}
uint8_t USB_Host_GetDeviceStatus(uint8_t* const FeatureStatus)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_GetStatus,
.wValue = 0,
.wIndex = 0,
.wLength = 0,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(FeatureStatus);
}
uint8_t USB_Host_ClearEndpointStall(const uint8_t EndpointAddress)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT),
.bRequest = REQ_ClearFeature,
.wValue = FEATURE_SEL_EndpointHalt,
.wIndex = EndpointAddress,
.wLength = 0,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(NULL);
}
uint8_t USB_Host_SetInterfaceAltSetting(const uint8_t InterfaceIndex,
const uint8_t AltSetting)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE),
.bRequest = REQ_SetInterface,
.wValue = AltSetting,
.wIndex = InterfaceIndex,
.wLength = 0,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(NULL);
}
uint8_t USB_Host_GetInterfaceAltSetting(const uint8_t InterfaceIndex,
uint8_t* const AltSetting)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE),
.bRequest = REQ_GetInterface,
.wValue = 0,
.wIndex = InterfaceIndex,
.wLength = sizeof(uint8_t),
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(AltSetting);
}
#endif

View File

@ -0,0 +1,291 @@
/*
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.
*/
/** \file
* \brief USB host standard request management.
*
* This file contains the function prototypes necessary for the issuing of outgoing standard control requests
* when the library is in USB host mode.
*
* \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.
*/
#ifndef __HOSTSTDREQ_H__
#define __HOSTSTDREQ_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
#include "StdRequestType.h"
#include "USBController.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
#if !defined(USB_HOST_TIMEOUT_MS) || defined(__DOXYGEN__)
/** Constant for the maximum software timeout period of sent USB control transactions to an attached
* device. If a device fails to respond to a sent control request within this period, the
* library will return a timeout error code.
*
* This value may be overridden in the user project makefile as the value of the
* \ref USB_HOST_TIMEOUT_MS token, and passed to the compiler using the -D switch.
*/
#define USB_HOST_TIMEOUT_MS 1000
#endif
/* Enums: */
/** Enum for the \ref USB_Host_SendControlRequest() return code, indicating the reason for the error
* if the transfer of the request is unsuccessful.
*
* \ingroup Group_PipeControlReq
*/
enum USB_Host_SendControlErrorCodes_t
{
HOST_SENDCONTROL_Successful = 0, /**< No error occurred in the request transfer. */
HOST_SENDCONTROL_DeviceDisconnected = 1, /**< The attached device was disconnected during the
* request transfer.
*/
HOST_SENDCONTROL_PipeError = 2, /**< An error occurred in the pipe while sending the request. */
HOST_SENDCONTROL_SetupStalled = 3, /**< The attached device stalled the request, usually
* indicating that the request is unsupported on the device.
*/
HOST_SENDCONTROL_SoftwareTimeOut = 4, /**< The request or data transfer timed out. */
};
/* Global Variables: */
/** Indicates the currently set configuration number of the attached device. This indicates the currently
* selected configuration value if one has been set sucessfully, or 0 if no configuration has been selected.
*
* To set a device configuration, call the \ref USB_Host_SetDeviceConfiguration() function.
*
* \note This variable should be treated as read-only in the user application, and never manually
* changed in value.
*
* \ingroup Group_Host
*/
extern uint8_t USB_Host_ConfigurationNumber;
/* Function Prototypes: */
/** Sends the request stored in the \ref USB_ControlRequest global structure to the attached device,
* and transfers the data stored in the buffer to the device, or from the device to the buffer
* as requested. The transfer is made on the currently selected pipe.
*
* \ingroup Group_PipeControlReq
*
* \param[in] BufferPtr Pointer to the start of the data buffer if the request has a data stage, or
* \c NULL if the request transfers no data to or from the device.
*
* \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
*/
uint8_t USB_Host_SendControlRequest(void* const BufferPtr);
/** Sends a SET CONFIGURATION standard request to the attached device, with the given configuration index.
*
* This routine will automatically update the \ref USB_HostState and \ref USB_Host_ConfigurationNumber
* state variables according to the given function parameters and the result of the request.
*
* \note After this routine returns, the control pipe will be selected.
*
* \ingroup Group_PipeControlReq
*
* \param[in] ConfigNumber Configuration index to send to the device.
*
* \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
*/
uint8_t USB_Host_SetDeviceConfiguration(const uint8_t ConfigNumber);
/** Sends a GET CONFIGURATION standard request to the attached device, to retrieve the currently selected
* device configuration index.
*
* \note After this routine returns, the control pipe will be selected.
*
* \ingroup Group_PipeControlReq
*
* \param[out] ConfigNumber Pointer to a location where the retrieved configuration index should be stored.
*
* \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
*/
uint8_t USB_Host_GetDeviceConfiguration(uint8_t* const ConfigNumber) ATTR_NON_NULL_PTR_ARG(1);
/** Sends a GET DESCRIPTOR standard request to the attached device, requesting the descriptor of the
* specified type and index.
*
* \note After this routine returns, the control pipe will be selected.
*
* \ingroup Group_PipeControlReq
*
* \param[in] Type Type of descriptor to retrieve, a value from the \ref USB_DescriptorTypes_t enum.
* \param[in] Index Index of the descriptor to retrieve.
* \param[out] Buffer Pointer to the destination buffer where the retrieved string descriptor is to be stored.
* \param[in] BufferLength Maximum size of the string descriptor which can be stored into the buffer.
*
* \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
*/
uint8_t USB_Host_GetDescriptor(const uint8_t Type,
const uint8_t Index,
void* const Buffer,
const uint8_t BufferLength) ATTR_NON_NULL_PTR_ARG(3);
/** Retrieves the current feature status of the attached device, via a GET STATUS standard request. The
* retrieved feature status can then be examined by masking the retrieved value with the various
* FEATURE_* masks for bus/self power information and remote wakeup support.
*
* \note After this routine returns, the control pipe will be selected.
*
* \ingroup Group_PipeControlReq
*
* \param[out] FeatureStatus Location where the retrieved feature status should be stored.
*
* \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
*/
uint8_t USB_Host_GetDeviceStatus(uint8_t* const FeatureStatus) ATTR_NON_NULL_PTR_ARG(1);
/** Clears a stall condition on the given pipe, via a CLEAR FEATURE standard request to the attached device.
*
* \note After this routine returns, the control pipe will be selected.
*
* \ingroup Group_PipeControlReq
*
* \param[in] EndpointAddress Address of the endpoint to clear, including the endpoint's direction.
*
* \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
*/
uint8_t USB_Host_ClearEndpointStall(const uint8_t EndpointAddress);
/** Selects a given alternative setting for the specified interface, via a SET INTERFACE standard request to
* the attached device.
*
* \note After this routine returns, the control pipe will be selected.
*
* \ingroup Group_PipeControlReq
*
* \param[in] InterfaceIndex Index of the interface whose alternative setting is to be altered.
* \param[in] AltSetting Index of the interface's alternative setting which is to be selected.
*
* \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
*/
uint8_t USB_Host_SetInterfaceAltSetting(const uint8_t InterfaceIndex,
const uint8_t AltSetting);
/** Retrieves the current alternative setting for the specified interface, via a GET INTERFACE standard request to
* the attached device.
*
* \note After this routine returns, the control pipe will be selected.
*
* \ingroup Group_PipeControlReq
*
* \param[in] InterfaceIndex Index of the interface whose alternative setting is to be altered.
* \param[out] AltSetting Pointer to a location where the retrieved alternative setting value should be stored.
*
* \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
*/
uint8_t USB_Host_GetInterfaceAltSetting(const uint8_t InterfaceIndex,
uint8_t* const AltSetting) ATTR_NON_NULL_PTR_ARG(2);
/* Inline Functions: */
/** Sends a GET DESCRIPTOR standard request to the attached device, requesting the device descriptor.
* This can be used to easily retrieve information about the device such as its VID, PID and power
* requirements. This is a convenience wrapper for \ref USB_Host_GetDescriptor().
*
* \note After this routine returns, the control pipe will be selected.
*
* \ingroup Group_PipeControlReq
*
* \param[out] DeviceDescriptorPtr Pointer to the destination device descriptor structure where
* the read data is to be stored.
*
* \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
*/
static inline uint8_t USB_Host_GetDeviceDescriptor(USB_Descriptor_Device_t* const DeviceDescriptorPtr) ATTR_NON_NULL_PTR_ARG(1);
static inline uint8_t USB_Host_GetDeviceDescriptor(USB_Descriptor_Device_t* const DeviceDescriptorPtr)
{
return USB_Host_GetDescriptor(DTYPE_Device, 0, DeviceDescriptorPtr, sizeof(USB_Descriptor_Device_t));
}
/** Sends a GET DESCRIPTOR standard request to the attached device, requesting the string descriptor
* of the specified index. This can be used to easily retrieve string descriptors from the device by
* index, after the index is obtained from the Device or Configuration descriptors. This is a convenience
* wrapper for \ref USB_Host_GetDescriptor().
*
* \note After this routine returns, the control pipe will be selected.
*
* \ingroup Group_PipeControlReq
*
* \param[in] Index Index of the string descriptor to retrieve.
* \param[out] Buffer Pointer to the destination buffer where the retrieved string descriptor is
* to be stored.
* \param[in] BufferLength Maximum size of the string descriptor which can be stored into the buffer.
*
* \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
*/
static inline uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index,
void* const Buffer,
const uint8_t BufferLength) ATTR_NON_NULL_PTR_ARG(2);
static inline uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index,
void* const Buffer,
const uint8_t BufferLength)
{
return USB_Host_GetDescriptor(DTYPE_String, Index, Buffer, BufferLength);
}
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Enums: */
enum USB_WaitForTypes_t
{
USB_HOST_WAITFOR_SetupSent,
USB_HOST_WAITFOR_InReceived,
USB_HOST_WAITFOR_OutReady,
};
/* Function Prototypes: */
#if defined(__INCLUDE_FROM_HOSTSTDREQ_C)
static uint8_t USB_Host_WaitForIOS(const uint8_t WaitType);
#endif
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,80 @@
/*
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.
*/
/** \file
* \brief Common USB OTG definitions for all architectures.
* \copydetails Group_OTG
*
* \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.
*/
/** \ingroup Group_USB
* \defgroup Group_OTG USB On The Go (OTG) Management
* \brief USB OTG management definitions.
*
* This module contains macros for embedded USB hosts with dual role On The Go capabilities, for managing role
* exchange. OTG is a way for two USB dual role devices to talk to one another directly without fixed device/host
* roles.
*
* @{
*/
#ifndef __USBOTG_H__
#define __USBOTG_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Architecture Includes: */
#if (ARCH == ARCH_AVR8)
#include "AVR8/OTG_AVR8.h"
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,136 @@
/*
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.
*/
/** \file
* \brief Common USB Pipe definitions for all architectures.
* \copydetails Group_PipeManagement
*
* \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.
*/
/** \ingroup Group_PipeManagement
* \defgroup Group_PipeRW Pipe Data Reading and Writing
* \brief Pipe data read/write definitions.
*
* Functions, macros, variables, enums and types related to data reading and writing from and to pipes.
*/
/** \ingroup Group_PipeRW
* \defgroup Group_PipePrimitiveRW Read/Write of Primitive Data Types
* \brief Pipe data primitive read/write definitions.
*
* Functions, macros, variables, enums and types related to data reading and writing of primitive data types
* from and to pipes.
*/
/** \ingroup Group_PipeManagement
* \defgroup Group_PipePacketManagement Pipe Packet Management
* \brief Pipe packet management definitions.
*
* Functions, macros, variables, enums and types related to packet management of pipes.
*/
/** \ingroup Group_PipeManagement
* \defgroup Group_PipeControlReq Pipe Control Request Management
* \brief Pipe control request definitions.
*
* Module for host mode request processing. This module allows for the transmission of standard, class and
* vendor control requests to the default control endpoint of an attached device while in host mode.
*
* \see Chapter 9 of the USB 2.0 specification.
*/
/** \ingroup Group_USB
* \defgroup Group_PipeManagement Pipe Management
* \brief Pipe management definitions.
*
* This module contains functions, macros and enums related to pipe management when in USB Host mode. This
* module contains the pipe management macros, as well as pipe interrupt and data send/receive functions
* for various data types.
*
* @{
*/
#ifndef __PIPE_H__
#define __PIPE_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Pipe address for the default control pipe, which always resides in address 0. This is
* defined for convenience to give more readable code when used with the pipe macros.
*/
#define PIPE_CONTROLPIPE 0
/** Pipe number mask, for masking against pipe addresses to retrieve the pipe's numerical address
* in the device.
*/
#define PIPE_PIPENUM_MASK 0x07
/** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
* numerical address in the attached device.
*/
#define PIPE_EPNUM_MASK 0x0F
/** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
* direction for comparing with the \c ENDPOINT_DESCRIPTOR_DIR_* masks.
*/
#define PIPE_EPDIR_MASK 0x80
/* Architecture Includes: */
#if (ARCH == ARCH_AVR8)
#include "AVR8/Pipe_AVR8.h"
#elif (ARCH == ARCH_UC3)
#include "UC3/Pipe_UC3.h"
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,100 @@
/*
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.
*/
/** \file
* \brief Pipe data stream transmission and reception management.
* \copydetails Group_PipeStreamRW
*
* \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.
*/
/** \ingroup Group_PipeRW
* \defgroup Group_PipeStreamRW Read/Write of Multi-Byte Streams
* \brief Pipe data stream transmission and reception management.
*
* Functions, macros, variables, enums and types related to data reading and writing of data streams from
* and to pipes.
*
* @{
*/
#ifndef __PIPE_STREAM_H__
#define __PIPE_STREAM_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Enums: */
/** Enum for the possible error return codes of the Pipe_*_Stream_* functions. */
enum Pipe_Stream_RW_ErrorCodes_t
{
PIPE_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
PIPE_RWSTREAM_PipeStalled = 1, /**< The device stalled the pipe during the transfer. */
PIPE_RWSTREAM_DeviceDisconnected = 2, /**< Device was disconnected from the host during
* the transfer.
*/
PIPE_RWSTREAM_Timeout = 3, /**< The device failed to accept or send the next packet
* within the software timeout period set by the
* \ref USB_STREAM_TIMEOUT_MS macro.
*/
PIPE_RWSTREAM_IncompleteTransfer = 4, /**< Indicates that the pipe bank became full/empty before the
* complete contents of the stream could be transferred.
*/
};
/* Architecture Includes: */
#if (ARCH == ARCH_AVR8)
#include "AVR8/PipeStream_AVR8.h"
#elif (ARCH == ARCH_UC3)
#include "UC3/PipeStream_UC3.h"
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,740 @@
/*
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.
*/
/** \file
* \brief Common standard USB Descriptor definitions for all architectures.
* \copydetails Group_StdDescriptors
*
* \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.
*/
/** \ingroup Group_USB
* \defgroup Group_StdDescriptors USB Descriptors
* \brief Standard USB Descriptor definitions.
*
* Standard USB device descriptor defines and retrieval routines, for USB devices. This module contains
* structures and macros for the easy creation of standard USB descriptors in USB device projects.
*
* @{
*/
#ifndef __USBDESCRIPTORS_H__
#define __USBDESCRIPTORS_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
#include "Events.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Indicates that a given descriptor does not exist in the device. This can be used inside descriptors
* for string descriptor indexes, or may be use as a return value for GetDescriptor when the specified
* descriptor does not exist.
*/
#define NO_DESCRIPTOR 0
/** Macro to calculate the power value for the configuration descriptor, from a given number of milliamperes.
*
* \param[in] mA Maximum number of milliamps the device consumes when the given configuration is selected.
*/
#define USB_CONFIG_POWER_MA(mA) ((mA) >> 1)
/** Macro to calculate the Unicode length of a string with a given number of Unicode characters.
* Should be used in string descriptor's headers for giving the string descriptor's byte length.
*
* \param[in] UnicodeChars Number of Unicode characters in the string text.
*/
#define USB_STRING_LEN(UnicodeChars) (sizeof(USB_Descriptor_Header_t) + ((UnicodeChars) << 1))
/** Macro to encode a given four digit floating point version number (e.g. 01.23) into Binary Coded
* Decimal format for descriptor fields requiring BCD encoding, such as the USB version number in the
* standard device descriptor.
*
* \note This value is automatically converted into Little Endian, suitable for direct use inside device
* descriptors on all architectures without endianness conversion macros.
*
* \param[in] x Version number to encode as a 16-bit little-endian number, as a floating point number.
*/
#define VERSION_BCD(x) CPU_TO_LE16((((VERSION_TENS(x) << 4) | VERSION_ONES(x)) << 8) | \
((VERSION_TENTHS(x) << 4) | VERSION_HUNDREDTHS(x)))
/** String language ID for the English language. Should be used in \ref USB_Descriptor_String_t descriptors
* to indicate that the English language is supported by the device in its string descriptors.
*/
#define LANGUAGE_ID_ENG 0x0409
/** \name USB Configuration Descriptor Attribute Masks */
//@{
/** Can be masked with other configuration descriptor attributes for a \ref USB_Descriptor_Configuration_Header_t
* descriptor's ConfigAttributes value to indicate that the specified configuration can draw its power
* from the host's VBUS line.
*/
#define USB_CONFIG_ATTR_BUSPOWERED 0x80
/** Can be masked with other configuration descriptor attributes for a \ref USB_Descriptor_Configuration_Header_t
* descriptor's ConfigAttributes value to indicate that the specified configuration can draw its power
* from the device's own power source.
*/
#define USB_CONFIG_ATTR_SELFPOWERED 0x40
/** Can be masked with other configuration descriptor attributes for a \ref USB_Descriptor_Configuration_Header_t
* descriptor's ConfigAttributes value to indicate that the specified configuration supports the
* remote wakeup feature of the USB standard, allowing a suspended USB device to wake up the host upon
* request.
*/
#define USB_CONFIG_ATTR_REMOTEWAKEUP 0x20
//@}
/** \name Endpoint Descriptor Attribute Masks */
//@{
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
* Attributes value to indicate that the specified endpoint is not synchronized.
*
* \see The USB specification for more details on the possible Endpoint attributes.
*/
#define ENDPOINT_ATTR_NO_SYNC (0 << 2)
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
* Attributes value to indicate that the specified endpoint is asynchronous.
*
* \see The USB specification for more details on the possible Endpoint attributes.
*/
#define ENDPOINT_ATTR_ASYNC (1 << 2)
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
* Attributes value to indicate that the specified endpoint is adaptive.
*
* \see The USB specification for more details on the possible Endpoint attributes.
*/
#define ENDPOINT_ATTR_ADAPTIVE (2 << 2)
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
* Attributes value to indicate that the specified endpoint is synchronized.
*
* \see The USB specification for more details on the possible Endpoint attributes.
*/
#define ENDPOINT_ATTR_SYNC (3 << 2)
//@}
/** \name Endpoint Descriptor Usage Masks */
//@{
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
* Attributes value to indicate that the specified endpoint is used for data transfers.
*
* \see The USB specification for more details on the possible Endpoint usage attributes.
*/
#define ENDPOINT_USAGE_DATA (0 << 4)
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
* Attributes value to indicate that the specified endpoint is used for feedback.
*
* \see The USB specification for more details on the possible Endpoint usage attributes.
*/
#define ENDPOINT_USAGE_FEEDBACK (1 << 4)
/** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
* Attributes value to indicate that the specified endpoint is used for implicit feedback.
*
* \see The USB specification for more details on the possible Endpoint usage attributes.
*/
#define ENDPOINT_USAGE_IMPLICIT_FEEDBACK (2 << 4)
//@}
/* Enums: */
/** Enum for the possible standard descriptor types, as given in each descriptor's header. */
enum USB_DescriptorTypes_t
{
DTYPE_Device = 0x01, /**< Indicates that the descriptor is a device descriptor. */
DTYPE_Configuration = 0x02, /**< Indicates that the descriptor is a configuration descriptor. */
DTYPE_String = 0x03, /**< Indicates that the descriptor is a string descriptor. */
DTYPE_Interface = 0x04, /**< Indicates that the descriptor is an interface descriptor. */
DTYPE_Endpoint = 0x05, /**< Indicates that the descriptor is an endpoint descriptor. */
DTYPE_DeviceQualifier = 0x06, /**< Indicates that the descriptor is a device qualifier descriptor. */
DTYPE_Other = 0x07, /**< Indicates that the descriptor is of other type. */
DTYPE_InterfacePower = 0x08, /**< Indicates that the descriptor is an interface power descriptor. */
DTYPE_InterfaceAssociation = 0x0B, /**< Indicates that the descriptor is an interface association descriptor. */
DTYPE_CSInterface = 0x24, /**< Indicates that the descriptor is a class specific interface descriptor. */
DTYPE_CSEndpoint = 0x25, /**< Indicates that the descriptor is a class specific endpoint descriptor. */
};
/** Enum for possible Class, Subclass and Protocol values of device and interface descriptors. */
enum USB_Descriptor_ClassSubclassProtocol_t
{
USB_CSCP_NoDeviceClass = 0x00, /**< Descriptor Class value indicating that the device does not belong
* to a particular class at the device level.
*/
USB_CSCP_NoDeviceSubclass = 0x00, /**< Descriptor Subclass value indicating that the device does not belong
* to a particular subclass at the device level.
*/
USB_CSCP_NoDeviceProtocol = 0x00, /**< Descriptor Protocol value indicating that the device does not belong
* to a particular protocol at the device level.
*/
USB_CSCP_VendorSpecificClass = 0xFF, /**< Descriptor Class value indicating that the device/interface belongs
* to a vendor specific class.
*/
USB_CSCP_VendorSpecificSubclass = 0xFF, /**< Descriptor Subclass value indicating that the device/interface belongs
* to a vendor specific subclass.
*/
USB_CSCP_VendorSpecificProtocol = 0xFF, /**< Descriptor Protocol value indicating that the device/interface belongs
* to a vendor specific protocol.
*/
USB_CSCP_IADDeviceClass = 0xEF, /**< Descriptor Class value indicating that the device belongs to the
* Interface Association Descriptor class.
*/
USB_CSCP_IADDeviceSubclass = 0x02, /**< Descriptor Subclass value indicating that the device belongs to the
* Interface Association Descriptor subclass.
*/
USB_CSCP_IADDeviceProtocol = 0x01, /**< Descriptor Protocol value indicating that the device belongs to the
* Interface Association Descriptor protocol.
*/
};
/* Type Defines: */
/** \brief Standard USB Descriptor Header (LUFA naming conventions).
*
* Type define for all descriptors' standard header, indicating the descriptor's length and type. This structure
* uses LUFA-specific element names to make each element's purpose clearer.
*
* \see \ref USB_StdDescriptor_Header_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
uint8_t Size; /**< Size of the descriptor, in bytes. */
uint8_t Type; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
* given by the specific class.
*/
} ATTR_PACKED USB_Descriptor_Header_t;
/** \brief Standard USB Descriptor Header (USB-IF naming conventions).
*
* Type define for all descriptors' standard header, indicating the descriptor's length and type. This structure
* uses the relevant standard's given element names to ensure compatibility with the standard.
*
* \see \ref USB_Descriptor_Header_t for the version of this type with non-standard LUFA specific element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
uint8_t bLength; /**< Size of the descriptor, in bytes. */
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
* given by the specific class.
*/
} ATTR_PACKED USB_StdDescriptor_Header_t;
/** \brief Standard USB Device Descriptor (LUFA naming conventions).
*
* Type define for a standard Device Descriptor. This structure uses LUFA-specific element names to make each
* element's purpose clearer.
*
* \see \ref USB_StdDescriptor_Device_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
uint16_t USBSpecification; /**< BCD of the supported USB specification. */
uint8_t Class; /**< USB device class. */
uint8_t SubClass; /**< USB device subclass. */
uint8_t Protocol; /**< USB device protocol. */
uint8_t Endpoint0Size; /**< Size of the control (address 0) endpoint's bank in bytes. */
uint16_t VendorID; /**< Vendor ID for the USB product. */
uint16_t ProductID; /**< Unique product ID for the USB product. */
uint16_t ReleaseNumber; /**< Product release (version) number. */
uint8_t ManufacturerStrIndex; /**< String index for the manufacturer's name. The
* host will request this string via a separate
* control request for the string descriptor.
*
* \note If no string supplied, use \ref NO_DESCRIPTOR.
*/
uint8_t ProductStrIndex; /**< String index for the product name/details.
*
* \see ManufacturerStrIndex structure entry.
*/
uint8_t SerialNumStrIndex; /**< String index for the product's globally unique hexadecimal
* serial number, in uppercase Unicode ASCII.
*
* \note On some microcontroller models, there is an embedded serial number
* in the chip which can be used for the device serial number.
* To use this serial number, set this to USE_INTERNAL_SERIAL.
* On unsupported devices, this will evaluate to 0 and will cause
* the host to generate a pseudo-unique value for the device upon
* insertion.
*
* \see ManufacturerStrIndex structure entry.
*/
uint8_t NumberOfConfigurations; /**< Total number of configurations supported by
* the device.
*/
} ATTR_PACKED USB_Descriptor_Device_t;
/** \brief Standard USB Device Descriptor (USB-IF naming conventions).
*
* Type define for a standard Device Descriptor. This structure uses the relevant standard's given element names
* to ensure compatibility with the standard.
*
* \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
uint8_t bLength; /**< Size of the descriptor, in bytes. */
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
* given by the specific class.
*/
uint16_t bcdUSB; /**< BCD of the supported USB specification. */
uint8_t bDeviceClass; /**< USB device class. */
uint8_t bDeviceSubClass; /**< USB device subclass. */
uint8_t bDeviceProtocol; /**< USB device protocol. */
uint8_t bMaxPacketSize0; /**< Size of the control (address 0) endpoint's bank in bytes. */
uint16_t idVendor; /**< Vendor ID for the USB product. */
uint16_t idProduct; /**< Unique product ID for the USB product. */
uint16_t bcdDevice; /**< Product release (version) number. */
uint8_t iManufacturer; /**< String index for the manufacturer's name. The
* host will request this string via a separate
* control request for the string descriptor.
*
* \note If no string supplied, use \ref NO_DESCRIPTOR.
*/
uint8_t iProduct; /**< String index for the product name/details.
*
* \see ManufacturerStrIndex structure entry.
*/
uint8_t iSerialNumber; /**< String index for the product's globally unique hexadecimal
* serial number, in uppercase Unicode ASCII.
*
* \note On some microcontroller models, there is an embedded serial number
* in the chip which can be used for the device serial number.
* To use this serial number, set this to USE_INTERNAL_SERIAL.
* On unsupported devices, this will evaluate to 0 and will cause
* the host to generate a pseudo-unique value for the device upon
* insertion.
*
* \see ManufacturerStrIndex structure entry.
*/
uint8_t bNumConfigurations; /**< Total number of configurations supported by
* the device.
*/
} ATTR_PACKED USB_StdDescriptor_Device_t;
/** \brief Standard USB Device Qualifier Descriptor (LUFA naming conventions).
*
* Type define for a standard Device Qualifier Descriptor. This structure uses LUFA-specific element names
* to make each element's purpose clearer.
*
* \see \ref USB_StdDescriptor_DeviceQualifier_t for the version of this type with standard element names.
*/
typedef struct
{
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
uint16_t USBSpecification; /**< BCD of the supported USB specification. */
uint8_t Class; /**< USB device class. */
uint8_t SubClass; /**< USB device subclass. */
uint8_t Protocol; /**< USB device protocol. */
uint8_t Endpoint0Size; /**< Size of the control (address 0) endpoint's bank in bytes. */
uint8_t NumberOfConfigurations; /**< Total number of configurations supported by
* the device.
*/
uint8_t Reserved; /**< Reserved for future use, must be 0. */
} ATTR_PACKED USB_Descriptor_DeviceQualifier_t;
/** \brief Standard USB Device Qualifier Descriptor (USB-IF naming conventions).
*
* Type define for a standard Device Qualifier Descriptor. This structure uses the relevant standard's given element names
* to ensure compatibility with the standard.
*
* \see \ref USB_Descriptor_DeviceQualifier_t for the version of this type with non-standard LUFA specific element names.
*/
typedef struct
{
uint8_t bLength; /**< Size of the descriptor, in bytes. */
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
* given by the specific class.
*/
uint16_t bcdUSB; /**< BCD of the supported USB specification. */
uint8_t bDeviceClass; /**< USB device class. */
uint8_t bDeviceSubClass; /**< USB device subclass. */
uint8_t bDeviceProtocol; /**< USB device protocol. */
uint8_t bMaxPacketSize0; /**< Size of the control (address 0) endpoint's bank in bytes. */
uint8_t bNumConfigurations; /**< Total number of configurations supported by
* the device.
*/
uint8_t bReserved; /**< Reserved for future use, must be 0. */
} ATTR_PACKED USB_StdDescriptor_DeviceQualifier_t;
/** \brief Standard USB Configuration Descriptor (LUFA naming conventions).
*
* Type define for a standard Configuration Descriptor header. This structure uses LUFA-specific element names
* to make each element's purpose clearer.
*
* \see \ref USB_StdDescriptor_Configuration_Header_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
uint16_t TotalConfigurationSize; /**< Size of the configuration descriptor header,
* and all sub descriptors inside the configuration.
*/
uint8_t TotalInterfaces; /**< Total number of interfaces in the configuration. */
uint8_t ConfigurationNumber; /**< Configuration index of the current configuration. */
uint8_t ConfigurationStrIndex; /**< Index of a string descriptor describing the configuration. */
uint8_t ConfigAttributes; /**< Configuration attributes, comprised of a mask of zero or
* more USB_CONFIG_ATTR_* masks.
*/
uint8_t MaxPowerConsumption; /**< Maximum power consumption of the device while in the
* current configuration, calculated by the \ref USB_CONFIG_POWER_MA()
* macro.
*/
} ATTR_PACKED USB_Descriptor_Configuration_Header_t;
/** \brief Standard USB Configuration Descriptor (USB-IF naming conventions).
*
* Type define for a standard Configuration Descriptor header. This structure uses the relevant standard's given element names
* to ensure compatibility with the standard.
*
* \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
uint8_t bLength; /**< Size of the descriptor, in bytes. */
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
* given by the specific class.
*/
uint16_t wTotalLength; /**< Size of the configuration descriptor header,
* and all sub descriptors inside the configuration.
*/
uint8_t bNumInterfaces; /**< Total number of interfaces in the configuration. */
uint8_t bConfigurationValue; /**< Configuration index of the current configuration. */
uint8_t iConfiguration; /**< Index of a string descriptor describing the configuration. */
uint8_t bmAttributes; /**< Configuration attributes, comprised of a mask of zero or
* more USB_CONFIG_ATTR_* masks.
*/
uint8_t bMaxPower; /**< Maximum power consumption of the device while in the
* current configuration, calculated by the \ref USB_CONFIG_POWER_MA()
* macro.
*/
} ATTR_PACKED USB_StdDescriptor_Configuration_Header_t;
/** \brief Standard USB Interface Descriptor (LUFA naming conventions).
*
* Type define for a standard Interface Descriptor. This structure uses LUFA-specific element names
* to make each element's purpose clearer.
*
* \see \ref USB_StdDescriptor_Interface_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
uint8_t InterfaceNumber; /**< Index of the interface in the current configuration. */
uint8_t AlternateSetting; /**< Alternate setting for the interface number. The same
* interface number can have multiple alternate settings
* with different endpoint configurations, which can be
* selected by the host.
*/
uint8_t TotalEndpoints; /**< Total number of endpoints in the interface. */
uint8_t Class; /**< Interface class ID. */
uint8_t SubClass; /**< Interface subclass ID. */
uint8_t Protocol; /**< Interface protocol ID. */
uint8_t InterfaceStrIndex; /**< Index of the string descriptor describing the interface. */
} ATTR_PACKED USB_Descriptor_Interface_t;
/** \brief Standard USB Interface Descriptor (USB-IF naming conventions).
*
* Type define for a standard Interface Descriptor. This structure uses the relevant standard's given element names
* to ensure compatibility with the standard.
*
* \see \ref USB_Descriptor_Interface_t for the version of this type with non-standard LUFA specific element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
uint8_t bLength; /**< Size of the descriptor, in bytes. */
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
* given by the specific class.
*/
uint8_t bInterfaceNumber; /**< Index of the interface in the current configuration. */
uint8_t bAlternateSetting; /**< Alternate setting for the interface number. The same
* interface number can have multiple alternate settings
* with different endpoint configurations, which can be
* selected by the host.
*/
uint8_t bNumEndpoints; /**< Total number of endpoints in the interface. */
uint8_t bInterfaceClass; /**< Interface class ID. */
uint8_t bInterfaceSubClass; /**< Interface subclass ID. */
uint8_t bInterfaceProtocol; /**< Interface protocol ID. */
uint8_t iInterface; /**< Index of the string descriptor describing the
* interface.
*/
} ATTR_PACKED USB_StdDescriptor_Interface_t;
/** \brief Standard USB Interface Association Descriptor (LUFA naming conventions).
*
* Type define for a standard Interface Association Descriptor. This structure uses LUFA-specific element names
* to make each element's purpose clearer.
*
* This descriptor has been added as a supplement to the USB2.0 standard, in the ECN located at
* <a>http://www.usb.org/developers/docs/InterfaceAssociationDescriptor_ecn.pdf</a>. It allows composite
* devices with multiple interfaces related to the same function to have the multiple interfaces bound
* together at the point of enumeration, loading one generic driver for all the interfaces in the single
* function. Read the ECN for more information.
*
* \see \ref USB_StdDescriptor_Interface_Association_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
uint8_t FirstInterfaceIndex; /**< Index of the first associated interface. */
uint8_t TotalInterfaces; /**< Total number of associated interfaces. */
uint8_t Class; /**< Interface class ID. */
uint8_t SubClass; /**< Interface subclass ID. */
uint8_t Protocol; /**< Interface protocol ID. */
uint8_t IADStrIndex; /**< Index of the string descriptor describing the
* interface association.
*/
} ATTR_PACKED USB_Descriptor_Interface_Association_t;
/** \brief Standard USB Interface Association Descriptor (USB-IF naming conventions).
*
* Type define for a standard Interface Association Descriptor. This structure uses the relevant standard's given
* element names to ensure compatibility with the standard.
*
* This descriptor has been added as a supplement to the USB2.0 standard, in the ECN located at
* <a>http://www.usb.org/developers/docs/InterfaceAssociationDescriptor_ecn.pdf</a>. It allows composite
* devices with multiple interfaces related to the same function to have the multiple interfaces bound
* together at the point of enumeration, loading one generic driver for all the interfaces in the single
* function. Read the ECN for more information.
*
* \see \ref USB_Descriptor_Interface_Association_t for the version of this type with non-standard LUFA specific
* element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
uint8_t bLength; /**< Size of the descriptor, in bytes. */
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
* given by the specific class.
*/
uint8_t bFirstInterface; /**< Index of the first associated interface. */
uint8_t bInterfaceCount; /**< Total number of associated interfaces. */
uint8_t bFunctionClass; /**< Interface class ID. */
uint8_t bFunctionSubClass; /**< Interface subclass ID. */
uint8_t bFunctionProtocol; /**< Interface protocol ID. */
uint8_t iFunction; /**< Index of the string descriptor describing the
* interface association.
*/
} ATTR_PACKED USB_StdDescriptor_Interface_Association_t;
/** \brief Standard USB Endpoint Descriptor (LUFA naming conventions).
*
* Type define for a standard Endpoint Descriptor. This structure uses LUFA-specific element names
* to make each element's purpose clearer.
*
* \see \ref USB_StdDescriptor_Endpoint_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
uint8_t EndpointAddress; /**< Logical address of the endpoint within the device for the current
* configuration, including direction mask.
*/
uint8_t Attributes; /**< Endpoint attributes, comprised of a mask of the endpoint type (EP_TYPE_*)
* and attributes (ENDPOINT_ATTR_*) masks.
*/
uint16_t EndpointSize; /**< Size of the endpoint bank, in bytes. This indicates the maximum packet
* size that the endpoint can receive at a time.
*/
uint8_t PollingIntervalMS; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT
* or ISOCHRONOUS type.
*/
} ATTR_PACKED USB_Descriptor_Endpoint_t;
/** \brief Standard USB Endpoint Descriptor (USB-IF naming conventions).
*
* Type define for a standard Endpoint Descriptor. This structure uses the relevant standard's given
* element names to ensure compatibility with the standard.
*
* \see \ref USB_Descriptor_Endpoint_t for the version of this type with non-standard LUFA specific
* element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
uint8_t bLength; /**< Size of the descriptor, in bytes. */
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a
* value given by the specific class.
*/
uint8_t bEndpointAddress; /**< Logical address of the endpoint within the device for the current
* configuration, including direction mask.
*/
uint8_t bmAttributes; /**< Endpoint attributes, comprised of a mask of the endpoint type (EP_TYPE_*)
* and attributes (ENDPOINT_ATTR_*) masks.
*/
uint16_t wMaxPacketSize; /**< Size of the endpoint bank, in bytes. This indicates the maximum packet size
* that the endpoint can receive at a time.
*/
uint8_t bInterval; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT or
* ISOCHRONOUS type.
*/
} ATTR_PACKED USB_StdDescriptor_Endpoint_t;
/** \brief Standard USB String Descriptor (LUFA naming conventions).
*
* Type define for a standard string descriptor. Unlike other standard descriptors, the length
* of the descriptor for placement in the descriptor header must be determined by the \ref USB_STRING_LEN()
* macro rather than by the size of the descriptor structure, as the length is not fixed.
*
* This structure should also be used for string index 0, which contains the supported language IDs for
* the device as an array.
*
* This structure uses LUFA-specific element names to make each element's purpose clearer.
*
* \see \ref USB_StdDescriptor_String_t for the version of this type with standard element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
#if (((ARCH == ARCH_AVR8) || (ARCH == ARCH_XMEGA)) && !defined(__DOXYGEN__))
wchar_t UnicodeString[];
#else
uint16_t UnicodeString[]; /**< String data, as unicode characters (alternatively,
* string language IDs). If normal ASCII characters are
* to be used, they must be added as an array of characters
* rather than a normal C string so that they are widened to
* Unicode size.
*
* Under GCC, strings prefixed with the "L" character (before
* the opening string quotation mark) are considered to be
* Unicode strings, and may be used instead of an explicit
* array of ASCII characters on little endian devices with
* UTF-16-LE \c wchar_t encoding.
*/
#endif
} ATTR_PACKED USB_Descriptor_String_t;
/** \brief Standard USB String Descriptor (USB-IF naming conventions).
*
* Type define for a standard string descriptor. Unlike other standard descriptors, the length
* of the descriptor for placement in the descriptor header must be determined by the \ref USB_STRING_LEN()
* macro rather than by the size of the descriptor structure, as the length is not fixed.
*
* This structure should also be used for string index 0, which contains the supported language IDs for
* the device as an array.
*
* This structure uses the relevant standard's given element names to ensure compatibility with the standard.
*
* \see \ref USB_Descriptor_String_t for the version of this type with with non-standard LUFA specific
* element names.
*
* \note Regardless of CPU architecture, these values should be stored as little endian.
*/
typedef struct
{
uint8_t bLength; /**< Size of the descriptor, in bytes. */
uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t
* or a value given by the specific class.
*/
uint16_t bString[]; /**< String data, as unicode characters (alternatively, string language IDs).
* If normal ASCII characters are to be used, they must be added as an array
* of characters rather than a normal C string so that they are widened to
* Unicode size.
*
* Under GCC, strings prefixed with the "L" character (before the opening string
* quotation mark) are considered to be Unicode strings, and may be used instead
* of an explicit array of ASCII characters.
*/
} ATTR_PACKED USB_StdDescriptor_String_t;
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Macros: */
#define VERSION_TENS(x) (int)((x) / 10)
#define VERSION_ONES(x) (int)((x) - (10 * VERSION_TENS(x)))
#define VERSION_TENTHS(x) (int)(((x) - (int)(x)) * 10)
#define VERSION_HUNDREDTHS(x) (int)((((x) - (int)(x)) * 100) - (10 * VERSION_TENTHS(x)))
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,258 @@
/*
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.
*/
/** \file
* \brief USB control endpoint request definitions.
* \copydetails Group_StdRequest
*
* \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.
*/
/** \ingroup Group_USB
* \defgroup Group_StdRequest Standard USB Requests
* \brief USB control endpoint request definitions.
*
* This module contains definitions for the various control request parameters, so that the request
* details (such as data direction, request recipient, etc.) can be extracted via masking.
*
* @{
*/
#ifndef __STDREQTYPE_H__
#define __STDREQTYPE_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Mask for the request type parameter, to indicate the direction of the request data (Host to Device
* or Device to Host). The result of this mask should then be compared to the request direction masks.
*
* \see REQDIR_* macros for masks indicating the request data direction.
*/
#define CONTROL_REQTYPE_DIRECTION 0x80
/** Mask for the request type parameter, to indicate the type of request (Device, Class or Vendor
* Specific). The result of this mask should then be compared to the request type masks.
*
* \see REQTYPE_* macros for masks indicating the request type.
*/
#define CONTROL_REQTYPE_TYPE 0x60
/** Mask for the request type parameter, to indicate the recipient of the request (Device, Interface
* Endpoint or Other). The result of this mask should then be compared to the request recipient
* masks.
*
* \see REQREC_* macros for masks indicating the request recipient.
*/
#define CONTROL_REQTYPE_RECIPIENT 0x1F
/** \name Control Request Data Direction Masks */
//@{
/** Request data direction mask, indicating that the request data will flow from host to device.
*
* \see \ref CONTROL_REQTYPE_DIRECTION macro.
*/
#define REQDIR_HOSTTODEVICE (0 << 7)
/** Request data direction mask, indicating that the request data will flow from device to host.
*
* \see \ref CONTROL_REQTYPE_DIRECTION macro.
*/
#define REQDIR_DEVICETOHOST (1 << 7)
//@}
/** \name Control Request Type Masks */
//@{
/** Request type mask, indicating that the request is a standard request.
*
* \see \ref CONTROL_REQTYPE_TYPE macro.
*/
#define REQTYPE_STANDARD (0 << 5)
/** Request type mask, indicating that the request is a class-specific request.
*
* \see \ref CONTROL_REQTYPE_TYPE macro.
*/
#define REQTYPE_CLASS (1 << 5)
/** Request type mask, indicating that the request is a vendor specific request.
*
* \see \ref CONTROL_REQTYPE_TYPE macro.
*/
#define REQTYPE_VENDOR (2 << 5)
//@}
/** \name Control Request Recipient Masks */
//@{
/** Request recipient mask, indicating that the request is to be issued to the device as a whole.
*
* \see \ref CONTROL_REQTYPE_RECIPIENT macro.
*/
#define REQREC_DEVICE (0 << 0)
/** Request recipient mask, indicating that the request is to be issued to an interface in the
* currently selected configuration.
*
* \see \ref CONTROL_REQTYPE_RECIPIENT macro.
*/
#define REQREC_INTERFACE (1 << 0)
/** Request recipient mask, indicating that the request is to be issued to an endpoint in the
* currently selected configuration.
*
* \see \ref CONTROL_REQTYPE_RECIPIENT macro.
*/
#define REQREC_ENDPOINT (2 << 0)
/** Request recipient mask, indicating that the request is to be issued to an unspecified element
* in the currently selected configuration.
*
* \see \ref CONTROL_REQTYPE_RECIPIENT macro.
*/
#define REQREC_OTHER (3 << 0)
//@}
/* Type Defines: */
/** \brief Standard USB Control Request
*
* Type define for a standard USB control request.
*
* \see The USB 2.0 specification for more information on standard control requests.
*/
typedef struct
{
uint8_t bmRequestType; /**< Type of the request. */
uint8_t bRequest; /**< Request command code. */
uint16_t wValue; /**< wValue parameter of the request. */
uint16_t wIndex; /**< wIndex parameter of the request. */
uint16_t wLength; /**< Length of the data to transfer in bytes. */
} ATTR_PACKED USB_Request_Header_t;
/* Enums: */
/** Enumeration for the various standard request commands. These commands are applicable when the
* request type is \ref REQTYPE_STANDARD (with the exception of \ref REQ_GetDescriptor, which is always
* handled regardless of the request type value).
*
* \see Chapter 9 of the USB 2.0 Specification.
*/
enum USB_Control_Request_t
{
REQ_GetStatus = 0, /**< Implemented in the library for device and endpoint recipients. Passed
* to the user application for other recipients via the
* \ref EVENT_USB_Device_ControlRequest() event when received in
* device mode. */
REQ_ClearFeature = 1, /**< Implemented in the library for device and endpoint recipients. Passed
* to the user application for other recipients via the
* \ref EVENT_USB_Device_ControlRequest() event when received in
* device mode. */
REQ_SetFeature = 3, /**< Implemented in the library for device and endpoint recipients. Passed
* to the user application for other recipients via the
* \ref EVENT_USB_Device_ControlRequest() event when received in
* device mode. */
REQ_SetAddress = 5, /**< Implemented in the library for the device recipient. Passed
* to the user application for other recipients via the
* \ref EVENT_USB_Device_ControlRequest() event when received in
* device mode. */
REQ_GetDescriptor = 6, /**< Implemented in the library for device and interface recipients. Passed to the
* user application for other recipients via the
* \ref EVENT_USB_Device_ControlRequest() event when received in
* device mode. */
REQ_SetDescriptor = 7, /**< Not implemented in the library, passed to the user application
* via the \ref EVENT_USB_Device_ControlRequest() event when received in
* device mode. */
REQ_GetConfiguration = 8, /**< Implemented in the library for the device recipient. Passed
* to the user application for other recipients via the
* \ref EVENT_USB_Device_ControlRequest() event when received in
* device mode. */
REQ_SetConfiguration = 9, /**< Implemented in the library for the device recipient. Passed
* to the user application for other recipients via the
* \ref EVENT_USB_Device_ControlRequest() event when received in
* device mode. */
REQ_GetInterface = 10, /**< Not implemented in the library, passed to the user application
* via the \ref EVENT_USB_Device_ControlRequest() event when received in
* device mode. */
REQ_SetInterface = 11, /**< Not implemented in the library, passed to the user application
* via the \ref EVENT_USB_Device_ControlRequest() event when received in
* device mode. */
REQ_SynchFrame = 12, /**< Not implemented in the library, passed to the user application
* via the \ref EVENT_USB_Device_ControlRequest() event when received in
* device mode. */
};
/** Feature Selector values for Set Feature and Clear Feature standard control requests directed to the device, interface
* and endpoint recipients.
*/
enum USB_Feature_Selectors_t
{
FEATURE_SEL_EndpointHalt = 0x00, /**< Feature selector for Clear Feature or Set Feature commands. When
* used in a Set Feature or Clear Feature request this indicates that an
* endpoint (whose address is given elsewhere in the request) should have
* its stall condition changed.
*/
FEATURE_SEL_DeviceRemoteWakeup = 0x01, /**< Feature selector for Device level Remote Wakeup enable set or clear.
* This feature can be controlled by the host on devices which indicate
* remote wakeup support in their descriptors to selectively disable or
* enable remote wakeup.
*/
FEATURE_SEL_TestMode = 0x02, /**< Feature selector for Test Mode features, used to test the USB controller
* to check for incorrect operation.
*/
};
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Macros: */
#define FEATURE_SELFPOWERED_ENABLED (1 << 0)
#define FEATURE_REMOTE_WAKEUP_ENABLED (1 << 1)
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,133 @@
/*
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.
*/
/** \file
* \brief Common USB Controller definitions for all architectures.
* \copydetails Group_USBManagement
*
* \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.
*/
/** \ingroup Group_USB
* \defgroup Group_USBManagement USB Interface Management
* \brief USB Controller definitions for general USB controller management.
*
* Functions, macros, variables, enums and types related to the setup and management of the USB interface.
*
* @{
*/
#ifndef __USBCONTROLLER_H__
#define __USBCONTROLLER_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks and Defines: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Defines: */
/** \name Endpoint Direction Masks */
//@{
/** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
* direction for comparing with the \c ENDPOINT_DIR_* masks.
*/
#define ENDPOINT_DIR_MASK 0x80
/** Endpoint address direction mask for an OUT direction (Host to Device) endpoint. This may be ORed with
* the index of the address within a device to obtain the full endpoint address.
*/
#define ENDPOINT_DIR_OUT 0x00
/** Endpoint address direction mask for an IN direction (Device to Host) endpoint. This may be ORed with
* the index of the address within a device to obtain the full endpoint address.
*/
#define ENDPOINT_DIR_IN 0x80
//@}
/** \name Endpoint/Pipe Type Masks */
//@{
/** Mask for determining the type of an endpoint from an endpoint descriptor. This should then be compared
* with the \c EP_TYPE_* masks to determine the exact type of the endpoint.
*/
#define EP_TYPE_MASK 0x03
/** Mask for a CONTROL type endpoint or pipe.
*
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
*/
#define EP_TYPE_CONTROL 0x00
/** Mask for an ISOCHRONOUS type endpoint or pipe.
*
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
*/
#define EP_TYPE_ISOCHRONOUS 0x01
/** Mask for a BULK type endpoint or pipe.
*
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
*/
#define EP_TYPE_BULK 0x02
/** Mask for an INTERRUPT type endpoint or pipe.
*
* \note See \ref Group_EndpointManagement and \ref Group_PipeManagement for endpoint/pipe functions.
*/
#define EP_TYPE_INTERRUPT 0x03
//@}
/* Architecture Includes: */
#if (ARCH == ARCH_AVR8)
#include "AVR8/USBController_AVR8.h"
#elif (ARCH == ARCH_UC3)
#include "UC3/USBController_UC3.h"
#elif (ARCH == ARCH_XMEGA)
#include "XMEGA/USBController_XMEGA.h"
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,73 @@
/*
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.
*/
/** \file
* \brief USB controller interrupt service routine management.
*
* This file contains definitions required for the correct handling of low level USB service routine interrupts
* from the USB controller.
*
* \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.
*/
#ifndef __USBINTERRUPT_H__
#define __USBINTERRUPT_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Architecture Includes: */
#if (ARCH == ARCH_AVR8)
#include "AVR8/USBInterrupt_AVR8.h"
#elif (ARCH == ARCH_UC3)
#include "UC3/USBInterrupt_UC3.h"
#elif (ARCH == ARCH_XMEGA)
#include "XMEGA/USBInterrupt_XMEGA.h"
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,261 @@
/*
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.
*/
/** \file
* \brief USB mode and feature support definitions.
* \copydetails Group_USBMode
*
* \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.
*/
/** \ingroup Group_USB
* \defgroup Group_USBMode USB Mode Tokens
* \brief USB mode and feature support definitions.
*
* This file defines macros indicating the type of USB controller the library is being compiled for, and its
* capabilities. These macros may then be referenced in the user application to selectively enable or disable
* code sections depending on if they are defined or not.
*
* After the inclusion of the master USB driver header, one or more of the following tokens may be defined, to
* allow the user code to conditionally enable or disable code based on the USB controller family and allowable
* USB modes. These tokens may be tested against to eliminate code relating to a USB mode which is not enabled for
* the given compilation.
*
* @{
*/
#ifndef __USBMODE_H__
#define __USBMODE_H__
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
#if defined(__DOXYGEN__)
/** Indicates that the target AVR microcontroller belongs to the Series 2 AVR8 USB controller
* (i.e. AT90USBxxx2 or ATMEGAxxU2) when defined.
*/
#define USB_SERIES_2_AVR
/** Indicates that the target AVR microcontroller belongs to the Series 4 AVR8 USB controller
* (i.e. ATMEGAxxU4) when defined.
*/
#define USB_SERIES_4_AVR
/** Indicates that the target AVR microcontroller belongs to the Series 6 AVR8 USB controller
* (i.e. AT90USBxxx6) when defined.
*/
#define USB_SERIES_6_AVR
/** Indicates that the target AVR microcontroller belongs to the Series 7 AVR8 USB controller
* (i.e. AT90USBxxx7) when defined.
*/
#define USB_SERIES_7_AVR
/** Indicates that the target AVR microcontroller belongs to the AVR32 UC3A0 Series USB controller
* (i.e. AT32UC3A0*) when defined.
*/
#define USB_SERIES_UC3A0_AVR
/** Indicates that the target AVR microcontroller belongs to the AVR32 UC3A1 Series USB controller
* (i.e. AT32UC3A1*) when defined.
*/
#define USB_SERIES_UC3A1_AVR
/** Indicates that the target AVR microcontroller belongs to the AVR32 UC3A3 Series USB controller
* (i.e. AT32UC3A3*) when defined.
*/
#define USB_SERIES_UC3A3_AVR
/** Indicates that the target AVR microcontroller belongs to the AVR32 UC3B0 Series USB controller
* (i.e. AT32UC3B0*) when defined.
*/
#define USB_SERIES_UC3B0_AVR
/** Indicates that the target AVR microcontroller belongs to the AVR32 UC3B1 Series USB controller
* (i.e. AT32UC3B1*) when defined.
*/
#define USB_SERIES_UC3B1_AVR
/** Indicates that the target AVR microcontroller belongs to the XMEGA A1U Series USB controller
* (i.e. ATXMEGA*A1U) when defined.
*/
#define USB_SERIES_A1U_XMEGA
/** Indicates that the target AVR microcontroller belongs to the XMEGA A3U Series USB controller
* (i.e. ATXMEGA*A3U) when defined.
*/
#define USB_SERIES_A3U_XMEGA
/** Indicates that the target AVR microcontroller belongs to the XMEGA A4U Series USB controller
* (i.e. ATXMEGA*A4U) when defined.
*/
#define USB_SERIES_A4U_XMEGA
/** Indicates that the target AVR microcontroller belongs to the XMEGA B1 Series USB controller
* (i.e. ATXMEGA*B1) when defined.
*/
#define USB_SERIES_B1_XMEGA
/** Indicates that the target AVR microcontroller belongs to the XMEGA B3 Series USB controller
* (i.e. ATXMEGA*B3) when defined.
*/
#define USB_SERIES_B3_XMEGA
/** Indicates that the target microcontroller and compilation settings allow for the
* target to be configured in USB Device mode when defined.
*/
#define USB_CAN_BE_DEVICE
/** Indicates that the target microcontroller and compilation settings allow for the
* target to be configured in USB Host mode when defined.
*/
#define USB_CAN_BE_HOST
/** Indicates that the target microcontroller and compilation settings allow for the
* target to be configured in either USB Device or Host mode when defined.
*/
#define USB_CAN_BE_BOTH
#else
/* Macros: */
#if (defined(__AVR_AT90USB162__) || defined(__AVR_AT90USB82__) || \
defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__))
#define USB_SERIES_2_AVR
#define USB_CAN_BE_DEVICE
#elif (defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__))
#define USB_SERIES_4_AVR
#define USB_CAN_BE_DEVICE
#elif (defined(__AVR_ATmega32U6__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__))
#define USB_SERIES_6_AVR
#define USB_CAN_BE_DEVICE
#elif (defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__))
#define USB_SERIES_7_AVR
#define USB_CAN_BE_DEVICE
#define USB_CAN_BE_HOST
#elif (defined(__AVR32_UC3A0512__) || defined(__AVR32_UC3A0256__) || \
defined(__AVR32_UC3A0128__) || defined(__AVR32_UC3A064__))
#define USB_SERIES_UC3A0_AVR32
#define USB_CAN_BE_DEVICE
#define USB_CAN_BE_HOST
#elif (defined(__AVR32_UC3A1512__) || defined(__AVR32_UC3A1256__) || \
defined(__AVR32_UC3A1128__) || defined(__AVR32_UC3A164__))
#define USB_SERIES_UC3A1_AVR32
#define USB_CAN_BE_DEVICE
#define USB_CAN_BE_HOST
#elif (defined(__AVR32_UC3A3256__) || defined(__AVR32_UC3A3256S__) || \
defined(__AVR32_UC3A3128__) || defined(__AVR32_UC3A3128S__) || \
defined(__AVR32_UC3A364__) || defined(__AVR32_UC3A364S__))
#define USB_SERIES_UC3A3_AVR32
#define USB_CAN_BE_DEVICE
#define USB_CAN_BE_HOST
#elif (defined(__AVR32_UC3A4256__) || defined(__AVR32_UC3A4256S__) || \
defined(__AVR32_UC3A4128__) || defined(__AVR32_UC3A4128S__) || \
defined(__AVR32_UC3A464__) || defined(__AVR32_UC3A464S__))
#define USB_SERIES_UC3A4_AVR32
#define USB_CAN_BE_DEVICE
#define USB_CAN_BE_HOST
#elif (defined(__AVR32_UC3B0512__) || defined(__AVR32_UC3B0256__) || \
defined(__AVR32_UC3B0128__) || defined(__AVR32_UC3B064__))
#define USB_SERIES_UC3B0_AVR32
#define USB_CAN_BE_DEVICE
#define USB_CAN_BE_HOST
#elif (defined(__AVR32_UC3B1512__) || defined(__AVR32_UC3B1256__) || \
defined(__AVR32_UC3B1128__) || defined(__AVR32_UC3B164__))
#define USB_SERIES_UC3B1_AVR32
#define USB_CAN_BE_DEVICE
#define USB_CAN_BE_HOST
#elif (defined(__AVR_ATxmega128A1U__) || defined(__AVR_ATxmega64A1U__))
#define USB_SERIES_A1U_XMEGA
#define USB_CAN_BE_DEVICE
#elif (defined(__AVR_ATxmega64A3U__) || defined(__AVR_ATxmega128A3U__) || \
defined(__AVR_ATxmega192A3U__) || defined(__AVR_ATxmega256A3U__))
#define USB_SERIES_A3U_XMEGA
#define USB_CAN_BE_DEVICE
#elif (defined(__AVR_ATxmega256A3BU__))
#define USB_SERIES_A3BU_XMEGA
#define USB_CAN_BE_DEVICE
#elif (defined(__AVR_ATxmega16A4U__) || defined(__AVR_ATxmega32A4U__))
#define USB_SERIES_A4U_XMEGA
#define USB_CAN_BE_DEVICE
#elif (defined(__AVR_ATxmega128B1__) || defined(__AVR_ATxmega64B1__))
#define USB_SERIES_B1_XMEGA
#define USB_CAN_BE_DEVICE
#elif (defined(__AVR_ATxmega128B3__) || defined(__AVR_ATxmega64B3__))
#define USB_SERIES_B3_XMEGA
#define USB_CAN_BE_DEVICE
#endif
#if (defined(USB_CAN_BE_DEVICE) && defined(USB_CAN_BE_HOST))
#define USB_CAN_BE_BOTH
#endif
#if defined(USB_HOST_ONLY)
#if !defined(USB_CAN_BE_HOST)
#error USB_HOST_ONLY is not available for the currently selected microcontroller model.
#else
#undef USB_CAN_BE_DEVICE
#undef USB_CAN_BE_BOTH
#endif
#endif
#if defined(USB_DEVICE_ONLY)
#if !defined(USB_CAN_BE_DEVICE)
#error USB_DEVICE_ONLY is not available for the currently selected microcontroller model.
#else
#undef USB_CAN_BE_HOST
#undef USB_CAN_BE_BOTH
#endif
#endif
#if (defined(USB_HOST_ONLY) && defined(USB_DEVICE_ONLY))
#error USB_HOST_ONLY and USB_DEVICE_ONLY are mutually exclusive.
#endif
#if (!defined(USB_CAN_BE_DEVICE) && !defined(USB_CAN_BE_HOST))
#error The currently selected device or architecture is not supported under the USB component of the library.
#endif
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif
/** @} */

View File

@ -0,0 +1,89 @@
/*
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_USBTASK_C
#define __INCLUDE_FROM_USB_DRIVER
#include "USBTask.h"
volatile bool USB_IsInitialized;
USB_Request_Header_t USB_ControlRequest;
#if defined(USB_CAN_BE_HOST) && !defined(HOST_STATE_AS_GPIOR)
volatile uint8_t USB_HostState;
#endif
#if defined(USB_CAN_BE_DEVICE) && !defined(DEVICE_STATE_AS_GPIOR)
volatile uint8_t USB_DeviceState;
#endif
void USB_USBTask(void)
{
#if defined(USB_HOST_ONLY)
USB_HostTask();
#elif defined(USB_DEVICE_ONLY)
USB_DeviceTask();
#else
if (USB_CurrentMode == USB_MODE_Device)
USB_DeviceTask();
else if (USB_CurrentMode == USB_MODE_Host)
USB_HostTask();
#endif
}
#if defined(USB_CAN_BE_DEVICE)
static void USB_DeviceTask(void)
{
if (USB_DeviceState != DEVICE_STATE_Unattached)
{
uint8_t PrevEndpoint = Endpoint_GetCurrentEndpoint();
Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
if (Endpoint_IsSETUPReceived())
USB_Device_ProcessControlRequest();
Endpoint_SelectEndpoint(PrevEndpoint);
}
}
#endif
#if defined(USB_CAN_BE_HOST)
static void USB_HostTask(void)
{
uint8_t PrevPipe = Pipe_GetCurrentPipe();
Pipe_SelectPipe(PIPE_CONTROLPIPE);
USB_Host_ProcessNextHostState();
Pipe_SelectPipe(PrevPipe);
}
#endif

View File

@ -0,0 +1,204 @@
/*
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.
*/
/** \file
* \brief Main USB service task management.
*
* This file contains the function definitions required for the main USB service task, which must be called
* from the user application to ensure that the USB connection to or from a connected USB device is maintained.
*
* \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.
*/
#ifndef __USBTASK_H__
#define __USBTASK_H__
/* Includes: */
#include "../../../Common/Common.h"
#include "USBMode.h"
#include "USBController.h"
#include "Events.h"
#include "StdRequestType.h"
#include "StdDescriptors.h"
#if defined(USB_CAN_BE_DEVICE)
#include "DeviceStandardReq.h"
#endif
#if defined(USB_CAN_BE_HOST)
#include "HostStandardReq.h"
#endif
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
extern "C" {
#endif
/* Preprocessor Checks: */
#if !defined(__INCLUDE_FROM_USB_DRIVER)
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Public Interface - May be used in end-application: */
/* Global Variables: */
/** Indicates if the USB interface is currently initialized but not necessarily connected to a host
* or device (i.e. if \ref USB_Init() has been run). If this is false, all other library globals related
* to the USB driver are invalid.
*
* \note This variable should be treated as read-only in the user application, and never manually
* changed in value.
*
* \ingroup Group_USBManagement
*/
extern volatile bool USB_IsInitialized;
/** Structure containing the last received Control request when in Device mode (for use in user-applications
* inside of the \ref EVENT_USB_Device_ControlRequest() event, or for filling up with a control request to
* issue when in Host mode before calling \ref USB_Host_SendControlRequest().
*
* \note The contents of this structure is automatically endian-corrected for the current CPU architecture.
*
* \ingroup Group_USBManagement
*/
extern USB_Request_Header_t USB_ControlRequest;
#if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)
#if !defined(HOST_STATE_AS_GPIOR) || defined(__DOXYGEN__)
/** Indicates the current host state machine state. When in host mode, this indicates the state
* via one of the values of the \ref USB_Host_States_t enum values.
*
* This value should not be altered by the user application as it is handled automatically by the
* library.
*
* To reduce program size and speed up checks of this global on the AVR8 architecture, it can be
* placed into one of the AVR's \c GPIOR hardware registers instead of RAM by defining the
* \c HOST_STATE_AS_GPIOR token to a value between 0 and 2 in the project makefile and passing it to
* the compiler via the -D switch. When defined, the corresponding GPIOR register should not be used
* in the user application except implicitly via the library APIs.
*
* \note This global is only present if the user application can be a USB host.
*
* \see \ref USB_Host_States_t for a list of possible device states.
*
* \ingroup Group_Host
*/
extern volatile uint8_t USB_HostState;
#else
#define _GET_HOST_GPIOR_NAME2(y) GPIOR ## y
#define _GET_HOST_GPIOR_NAME(x) _GET_HOST_GPIOR_NAME2(x)
#define USB_HostState _GET_HOST_GPIOR_NAME(HOST_STATE_AS_GPIOR)
#endif
#endif
#if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
#if !defined(DEVICE_STATE_AS_GPIOR) || defined(__DOXYGEN__)
/** Indicates the current device state machine state. When in device mode, this indicates the state
* via one of the values of the \ref USB_Device_States_t enum values.
*
* This value should not be altered by the user application as it is handled automatically by the
* library. The only exception to this rule is if the NO_LIMITED_CONTROLLER_CONNECT token is used
* (see \ref EVENT_USB_Device_Connect() and \ref EVENT_USB_Device_Disconnect() events).
*
* To reduce program size and speed up checks of this global on the AVR8 architecture, it can be
* placed into one of the AVR's \c GPIOR hardware registers instead of RAM by defining the
* \c DEVICE_STATE_AS_GPIOR token to a value between 0 and 2 in the project makefile and passing it to
* the compiler via the -D switch. When defined, the corresponding GPIOR register should not be used
* in the user application except implicitly via the library APIs.
*
* \note This global is only present if the user application can be a USB device.
* \n\n
*
* \note This variable should be treated as read-only in the user application, and never manually
* changed in value except in the circumstances outlined above.
*
* \see \ref USB_Device_States_t for a list of possible device states.
*
* \ingroup Group_Device
*/
extern volatile uint8_t USB_DeviceState;
#else
#define _GET_DEVICE_GPIOR_NAME2(y) GPIOR ## y
#define _GET_DEVICE_GPIOR_NAME(x) _GET_DEVICE_GPIOR_NAME2(x)
#define USB_DeviceState _GET_DEVICE_GPIOR_NAME(DEVICE_STATE_AS_GPIOR)
#endif
#endif
/* Function Prototypes: */
/** This is the main USB management task. The USB driver requires this task to be executed
* continuously when the USB system is active (device attached in host mode, or attached to a host
* in device mode) in order to manage USB communications. This task may be executed inside an RTOS,
* fast timer ISR or the main user application loop.
*
* The USB task must be serviced within 30ms while in device mode, or within 1ms while in host mode.
* The task may be serviced at all times, or (for minimum CPU consumption):
*
* - In device mode, it may be disabled at start-up, enabled on the firing of the \ref EVENT_USB_Device_Connect()
* event and disabled again on the firing of the \ref EVENT_USB_Device_Disconnect() event.
*
* - In host mode, it may be disabled at start-up, enabled on the firing of the \ref EVENT_USB_Host_DeviceAttached()
* event and disabled again on the firing of the \ref EVENT_USB_Host_DeviceEnumerationComplete() or
* \ref EVENT_USB_Host_DeviceEnumerationFailed() events.
*
* If in device mode (only), the control endpoint can instead be managed via interrupts entirely by the library
* by defining the INTERRUPT_CONTROL_ENDPOINT token and passing it to the compiler via the -D switch.
*
* \see \ref Group_Events for more information on the USB events.
*
* \ingroup Group_USBManagement
*/
void USB_USBTask(void);
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Function Prototypes: */
#if defined(__INCLUDE_FROM_USBTASK_C)
#if defined(USB_CAN_BE_HOST)
static void USB_HostTask(void);
#endif
#if defined(USB_CAN_BE_DEVICE)
static void USB_DeviceTask(void);
#endif
#endif
/* Macros: */
#define HOST_TASK_NONBLOCK_WAIT(Duration, NextState) MACROS{ USB_HostState = HOST_STATE_WaitForDevice; \
WaitMSRemaining = (Duration); \
PostWaitState = (NextState); }MACROE
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
#endif
#endif

399
LUFA/Drivers/USB/USB.h Normal file
View File

@ -0,0 +1,399 @@
/*
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.
*/
/** \file
* \brief Master include file for the library USB functionality.
*
* Master include file for the library USB functionality.
*
* This file should be included in all user projects making use of the USB portions of the library, instead of
* the individual USB driver submodule headers.
*/
/** \defgroup Group_USB USB Core - LUFA/Drivers/USB/USB.h
*
* \section Sec_Dependencies Module Source Dependencies
* The following files must be built with any user project that uses this module:
* - LUFA/Drivers/USB/Core/ConfigDescriptor.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
* - LUFA/Drivers/USB/Core/DeviceStandardReq.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
* - LUFA/Drivers/USB/Core/Events.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
* - LUFA/Drivers/USB/Core/HostStandardReq.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
* - LUFA/Drivers/USB/Core/USBTask.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
* - LUFA/Drivers/USB/Core/<i>ARCH</i>/Device_<i>ARCH</i>.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
* - LUFA/Drivers/USB/Core/<i>ARCH</i>/Endpoint_<i>ARCH</i>.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
* - LUFA/Drivers/USB/Core/<i>ARCH</i>/EndpointStream_<i>ARCH</i>.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
* - LUFA/Drivers/USB/Core/<i>ARCH</i>/Host_<i>ARCH</i>.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
* - LUFA/Drivers/USB/Core/<i>ARCH</i>/Pipe_<i>ARCH</i>.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
* - LUFA/Drivers/USB/Core/<i>ARCH</i>/PipeStream_<i>ARCH</i>.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
* - LUFA/Drivers/USB/Core/<i>ARCH</i>/USBController_<i>ARCH</i>.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
* - LUFA/Drivers/USB/Core/<i>ARCH</i>/USBInterrupt_<i>ARCH</i>.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
* - LUFA/Drivers/USB/Class/Common/HIDParser.c <i>(Makefile source module name: LUFA_SRC_USB)</i>
*
* \section Sec_ModDescription Module Description
* Driver and framework for the USB controller of the selected architecture and microcontroller model. This module
* consists of many submodules, and is designed to provide an easy way to configure and control USB host, device
* or OTG mode USB applications.
*
* The USB stack requires the sole control over the USB controller in the microcontroller only; i.e. it does not
* require any additional timers or other peripherals to operate. This ensures that the USB stack requires as few
* resources as possible.
*
* The USB stack can be used in Device Mode for connections to USB Hosts (see \ref Group_Device), in Host mode for
* hosting of other USB devices (see \ref Group_Host), or as a dual role device which can either act as a USB host
* or device depending on what peripheral is connected (see \ref Group_OTG). Both modes also require a common set
* of USB management functions found \ref Group_USBManagement.
*/
/** \defgroup Group_USBClassDrivers USB Class Drivers
*
* Drivers for both host and device mode of the standard USB classes, for rapid application development.
* Class drivers give a framework which sits on top of the low level library API, allowing for standard
* USB classes to be implemented in a project with minimal user code. These drivers can be used in
* conjunction with the library low level APIs to implement interfaces both via the class drivers and via
* the standard library APIs.
*
* Multiple device mode class drivers can be used within a project, including multiple instances of the
* same class driver. In this way, USB Hosts and Devices can be made quickly using the internal class drivers
* so that more time and effort can be put into the end application instead of the USB protocol.
*
* The available class drivers and their modes are listed below.
*
* <table>
* <tr>
* <th width="200px">USB Class</th>
* <th width="90px">Device Mode</th>
* <th width="90px">Host Mode</th>
* </tr>
* <tr>
* <td>Android Open Accessory</td>
* <td bgcolor="#EE0000">No</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>Audio</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>CDC</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>HID</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>MIDI</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>Mass Storage</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>Printer</td>
* <td bgcolor="#EE0000">No</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>RNDIS</td>
* <td bgcolor="#00EE00">Yes</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* <tr>
* <td>Still Image</td>
* <td bgcolor="#EE0000">No</td>
* <td bgcolor="#00EE00">Yes</td>
* </tr>
* </table>
*
*
* \section Sec_UsingClassDrivers Using the Class Drivers
* To make the Class drivers easy to integrate into a user application, they all implement a standardized
* design with similarly named/used function, enums, defines and types. The two different modes are implemented
* slightly differently, and thus will be explained separately. For information on a specific class driver, read
* the class driver's module documentation.
*
* \subsection Sec_ClassDriverDevice Device Mode Class Drivers
* Implementing a Device Mode Class Driver in a user application requires a number of steps to be followed. Firstly,
* the module configuration and state structure must be added to the project source. These structures are named in a
* similar manner between classes, that of <tt>USB_ClassInfo_<i>{Class Name}</i>_Device_t</tt>, and are used to hold the
* complete state and configuration for each class instance. Multiple class instances is where the power of the class
* drivers lie; multiple interfaces of the same class simply require more instances of the Class Driver's \c USB_ClassInfo_*
* structure.
*
* Inside the ClassInfo structure lies two sections, a \c Config section, and a \c State section. The \c Config
* section contains the instance's configuration parameters, and <b>must have all fields set by the user application</b>
* before the class driver is used. Each Device mode Class driver typically contains a set of configuration parameters
* for the endpoint size/number of the associated logical USB interface, plus any class-specific configuration parameters.
*
* The \c State section of the \c USB_ClassInfo_* structures are designed to be controlled by the Class Drivers only for
* maintaining the Class Driver instance's state, and should not normally be set by the user application.
*
* The following is an example of a properly initialized instance of the Audio Class Driver structure:
*
* \code
* USB_ClassInfo_Audio_Device_t My_Audio_Interface =
* {
* .Config =
* {
* .StreamingInterfaceNumber = 1,
*
* .DataINEndpointNumber = 1,
* .DataINEndpointSize = 256,
* },
* };
* \endcode
*
* \note The class driver's configuration parameters should match those used in the device's descriptors that are
* sent to the host.
*
* To initialize the Class driver instance, the driver's <tt><i>{Class Name}</i>_Device_ConfigureEndpoints()</tt> function
* should be called in response to the \ref EVENT_USB_Device_ConfigurationChanged() event. This function will return a
* boolean true value if the driver successfully initialized the instance. Like all the class driver functions, this function
* takes in the address of the specific instance you wish to initialize - in this manner, multiple separate instances of
* the same class type can be initialized like this:
*
* \code
* void EVENT_USB_Device_ConfigurationChanged(void)
* {
* LEDs_SetAllLEDs(LEDMASK_USB_READY);
*
* if (!(Audio_Device_ConfigureEndpoints(&My_Audio_Interface)))
* LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
* }
* \endcode
*
* Once initialized, it is important to maintain the class driver's state by repeatedly calling the Class Driver's
* <tt><i>{Class Name}</i>_Device_USBTask()</tt> function in the main program loop. The exact implementation of this
* function varies between class drivers, and can be used for any internal class driver purpose to maintain each
* instance. Again, this function uses the address of the instance to operate on, and thus needs to be called for each
* separate instance, just like the main USB maintenance routine \ref USB_USBTask():
*
* \code
* int main(void)
* {
* SetupHardware();
*
* LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
*
* for (;;)
* {
* Create_And_Process_Samples();
*
* Audio_Device_USBTask(&My_Audio_Interface);
* USB_USBTask();
* }
* }
* \endcode
*
* The final standardized Device Class Driver function is the Control Request handler function
* <tt><i>{Class Name}</i>_Device_ProcessControlRequest()</tt>, which should be called when the
* \ref EVENT_USB_Device_ControlRequest() event fires. This function should also be called for
* each class driver instance, using the address of the instance to operate on as the function's
* parameter. The request handler will abort if it is determined that the current request is not
* targeted at the given class driver instance, thus these methods can safely be called
* one-after-another in the event handler with no form of error checking:
*
* \code
* void EVENT_USB_Device_ControlRequest(void)
* {
* Audio_Device_ProcessControlRequest(&My_Audio_Interface);
* }
* \endcode
*
* Each class driver may also define a set of callback functions (which are prefixed by \c CALLBACK_*
* in the function's name) which <b>must</b> also be added to the user application - refer to each
* individual class driver's documentation for mandatory callbacks. In addition, each class driver may
* also define a set of events (identifiable by their prefix of \c EVENT_* in the function's name), which
* the user application <b>may</b> choose to implement, or ignore if not needed.
*
* The individual Device Mode Class Driver documentation contains more information on the non-standardized,
* class-specific functions which the user application can then use on the driver instances, such as data
* read and write routines. See each driver's individual documentation for more information on the
* class-specific functions.
*
* \subsection Sec_ClassDriverHost Host Mode Class Drivers
* Implementing a Host Mode Class Driver in a user application requires a number of steps to be followed. Firstly,
* the module configuration and state structure must be added to the project source. These structures are named in a
* similar manner between classes, that of <tt>USB_ClassInfo_<b>{Class Name}</b>_Host_t</tt>, and are used to hold the
* complete state and configuration for each class instance. Multiple class instances is where the power of the class
* drivers lie; multiple interfaces of the same class simply require more instances of the Class Driver's \c USB_ClassInfo_*
* structure.
*
* Inside the \c USB_ClassInfo_* structure lies two sections, a \c Config section, and a \c State section. The \c Config
* section contains the instance's configuration parameters, and <b>must have all fields set by the user application</b>
* before the class driver is used. Each Device mode Class driver typically contains a set of configuration parameters
* for the endpoint size/number of the associated logical USB interface, plus any class-specific configuration parameters.
*
* The \c State section of the \c USB_ClassInfo_* structures are designed to be controlled by the Class Drivers only for
* maintaining the Class Driver instance's state, and should not normally be set by the user application.
*
* The following is an example of a properly initialized instance of the MIDI Class Driver structure:
*
* \code
* USB_ClassInfo_MIDI_Host_t My_MIDI_Interface =
* {
* .Config =
* {
* .DataINPipeNumber = 1,
* .DataINPipeDoubleBank = false,
*
* .DataOUTPipeNumber = 2,
* .DataOUTPipeDoubleBank = false,
* },
* };
* \endcode
*
* To initialize the Class driver instance, the driver's <tt><b>{Class Name}</b>_Host_ConfigurePipes()</tt> function
* should be called in response to the host state machine entering the \ref HOST_STATE_Addressed state. This function
* will return an error code from the class driver's <tt><b>{Class Name}</b>_EnumerationFailure_ErrorCodes_t</tt> enum
* to indicate if the driver successfully initialized the instance and bound it to an interface in the attached device.
* Like all the class driver functions, this function takes in the address of the specific instance you wish to initialize -
* in this manner, multiple separate instances of the same class type can be initialized. A fragment of a Class Driver
* based Host mode application may look like the following:
*
* \code
* switch (USB_HostState)
* {
* case HOST_STATE_Addressed:
* LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
*
* uint16_t ConfigDescriptorSize;
* uint8_t ConfigDescriptorData[512];
*
* if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
* sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
* {
* LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
* USB_HostState = HOST_STATE_WaitForDeviceRemoval;
* break;
* }
*
* if (MIDI_Host_ConfigurePipes(&My_MIDI_Interface,
* ConfigDescriptorSize, ConfigDescriptorData) != MIDI_ENUMERROR_NoError)
* {
* LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
* USB_HostState = HOST_STATE_WaitForDeviceRemoval;
* break;
* }
*
* // Other state handler code here
* \endcode
*
* Note that the function also required the device's configuration descriptor so that it can determine which interface
* in the device to bind to - this can be retrieved as shown in the above fragment using the
* \ref USB_Host_GetDeviceConfigDescriptor() function. If the device does not implement the interface the class driver
* is looking for, if all the matching interfaces are already bound to class driver instances or if an error occurs while
* binding to a device interface (for example, a device endpoint bank larger that the maximum supported bank size is used)
* the configuration will fail.
*
* Once initialized, it is important to maintain the class driver's state by repeatedly calling the Class Driver's
* <tt><b>{Class Name}</b>_Host_USBTask()</tt> function in the main program loop. The exact implementation of this
* function varies between class drivers, and can be used for any internal class driver purpose to maintain each
* instance. Again, this function uses the address of the instance to operate on, and thus needs to be called for each
* separate instance, just like the main USB maintenance routine \ref USB_USBTask():
*
* \code
* int main(void)
* {
* SetupHardware();
*
* LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
*
* for (;;)
* {
* switch (USB_HostState)
* {
* // Host state machine handling here
* }
*
* MIDI_Host_USBTask(&My_Audio_Interface);
* USB_USBTask();
* }
* }
* \endcode
*
* Each class driver may also define a set of callback functions (which are prefixed by \c CALLBACK_*
* in the function's name) which <b>must</b> also be added to the user application - refer to each
* individual class driver's documentation for mandatory callbacks. In addition, each class driver may
* also define a set of events (identifiable by their prefix of \c EVENT_* in the function's name), which
* the user application <b>may</b> choose to implement, or ignore if not needed.
*
* The individual Host Mode Class Driver documentation contains more information on the non-standardized,
* class-specific functions which the user application can then use on the driver instances, such as data
* read and write routines. See each driver's individual documentation for more information on the
* class-specific functions.
*/
#ifndef __USB_H__
#define __USB_H__
/* Macros: */
#define __INCLUDE_FROM_USB_DRIVER
/* Includes: */
#include "../../Common/Common.h"
#include "Core/USBMode.h"
/* Includes: */
#include "Core/USBTask.h"
#include "Core/Events.h"
#include "Core/StdDescriptors.h"
#include "Core/ConfigDescriptor.h"
#include "Core/USBController.h"
#include "Core/USBInterrupt.h"
#if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)
#include "Core/Host.h"
#include "Core/Pipe.h"
#include "Core/HostStandardReq.h"
#include "Core/PipeStream.h"
#endif
#if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
#include "Core/Device.h"
#include "Core/Endpoint.h"
#include "Core/DeviceStandardReq.h"
#include "Core/EndpointStream.h"
#endif
#if defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__)
#include "Core/OTG.h"
#endif
#include "Class/CDCClass.h"
#endif

18
LUFA/License.txt Normal file
View File

@ -0,0 +1,18 @@
Permission to use, copy, modify, and distribute 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.

52
LUFA/Version.h Normal file
View File

@ -0,0 +1,52 @@
/*
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.
*/
/** \file
*
* \brief LUFA library version constants.
*
* Version constants for informational purposes and version-specific macro creation. This header file contains the
* current LUFA version number in several forms, for use in the user-application (for example, for printing out
* whilst debugging, or for testing for version compatibility).
*/
#ifndef __LUFA_VERSION_H__
#define __LUFA_VERSION_H__
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Indicates the version number of the library, as an integer. */
#define LUFA_VERSION_INTEGER 0x000000
/** Indicates the version number of the library, as a string. */
#define LUFA_VERSION_STRING "000000"
#endif

92
LUFA/makefile Normal file
View File

@ -0,0 +1,92 @@
#
# LUFA Library
# Copyright (C) Dean Camera, 2011.
#
# dean [at] fourwalledcubicle [dot] com
# www.lufa-lib.org
#
# Makefile for the LUFA library itself. This can be used to generate the library documentation.
# Check to see if the LUFA_PATH variable has not been set (the makefile is not being included from a project makefile)
ifeq ($(origin LUFA_PATH), undefined)
LUFA_ROOT_PATH = .
ARCH = {AVR8,UC3,XMEGA}
else
LUFA_ROOT_PATH = $(LUFA_PATH)/LUFA
endif
# Check to see if the chip architecture has not been defined in the user makefile, set a default architecture if not
ifeq ($(origin ARCH), undefined)
ARCH = AVR8
endif
# Define module source file lists
LUFA_SRC_USB = $(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/Device_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/Endpoint_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/Host_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/Pipe_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/USBController_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/USBInterrupt_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/EndpointStream_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/$(ARCH)/PipeStream_$(ARCH).c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/ConfigDescriptor.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/DeviceStandardReq.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/Events.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/HostStandardReq.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Core/USBTask.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Common/HIDParser.c
LUFA_SRC_USBCLASS = $(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/AudioClassDevice.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/CDCClassDevice.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/HIDClassDevice.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/MassStorageClassDevice.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/MIDIClassDevice.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/RNDISClassDevice.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/AndroidAccessoryClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/AudioClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/CDCClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/HIDClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/MassStorageClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/MIDIClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/PrinterClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/RNDISClassHost.c \
$(LUFA_ROOT_PATH)/Drivers/USB/Class/Host/StillImageClassHost.c
LUFA_SRC_TEMPERATURE = $(LUFA_ROOT_PATH)/Drivers/Board/Temperature.c
LUFA_SRC_SERIAL = $(LUFA_ROOT_PATH)/Drivers/Peripheral/$(ARCH)/Serial_$(ARCH).c
LUFA_SRC_TWI = $(LUFA_ROOT_PATH)/Drivers/Peripheral/$(ARCH)/TWI_$(ARCH).c
LUFA_SRC_SCHEDULER = $(LUFA_ROOT_PATH)/Scheduler/Scheduler.c
# Check to see if the LUFA_PATH variable has not been set (the makefile is not being included from a project makefile)
ifeq ($(origin LUFA_PATH), undefined)
LUFA_SRC_ALL_FILES = $(LUFA_SRC_USB) \
$(LUFA_SRC_USBCLASS) \
$(LUFA_SRC_TEMPERATURE) \
$(LUFA_SRC_SERIAL) \
$(LUFA_SRC_TWI) \
$(LUFA_SRC_SCHEDULER)
all:
clean:
rm -f $(LUFA_SRC_ALL_FILES:%.c=%.o)
rm -f $(LUFA_SRC_ALL_FILES:%.c=%.lst)
clean_list:
doxygen:
@echo Generating LUFA Library Documentation...
( cat Doxygen.conf ; echo "PROJECT_NUMBER=`grep LUFA_VERSION_STRING Version.h | cut -d'"' -f2`" ) | doxygen -
@echo Documentation Generation Complete.
clean_doxygen:
rm -rf Documentation
checksource:
version:
@echo "LUFA `grep LUFA_VERSION_STRING Version.h | cut -d'"' -f2`"
.PHONY: all clean clean_list doxygen clean_doxygen version
endif

Some files were not shown because too many files have changed in this diff Show More