Add svn:eol-style property to source files, so that the line endings are correctly converted to the target system's native end of line style.
This commit is contained in:
parent
e331b531c6
commit
071e02c6b6
839 changed files with 274562 additions and 274562 deletions
|
@ -1,141 +1,141 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr,
|
||||
void* BufferPtr, 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 = DESCRIPTOR_CAST(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* BytesRem, void** CurrConfigLoc, ConfigComparatorPtr_t 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;
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr,
|
||||
void* BufferPtr, 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 = DESCRIPTOR_CAST(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* BytesRem, void** CurrConfigLoc, ConfigComparatorPtr_t 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;
|
||||
}
|
||||
|
|
|
@ -1,286 +1,286 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 Configuration descriptor parser API.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* \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
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to the parsing of Configuration Descriptors.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __CONFIGDESCRIPTOR_H__
|
||||
#define __CONFIGDESCRIPTOR_H__
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "../../../Common/Common.h"
|
||||
#include "../HighLevel/USBMode.h"
|
||||
#include "../LowLevel/HostChapter9.h"
|
||||
#include "../HighLevel/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: */
|
||||
/** Mask for determining the type of an endpoint from an endpoint descriptor. This should then be compared
|
||||
* with the EP_TYPE_* masks to determine the exact type of the endpoint.
|
||||
*/
|
||||
#define EP_TYPE_MASK 0x03
|
||||
|
||||
/** 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_CAST(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_CAST(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 (* const ConfigComparatorPtr_t)(void*);
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Searches for the next descriptor in the given configuration descriptor using a premade 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* BytesRem, void** CurrConfigLoc, ConfigComparatorPtr_t ComparatorRoutine);
|
||||
|
||||
/* 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 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 uint16_t 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(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr, void* BufferPtr,
|
||||
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);
|
||||
|
||||
/* 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** const CurrConfigLoc)
|
||||
ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
|
||||
static inline void USB_GetNextDescriptor(uint16_t* const BytesRem,
|
||||
void** const CurrConfigLoc)
|
||||
{
|
||||
uint16_t CurrDescriptorSize = DESCRIPTOR_CAST(*CurrConfigLoc, USB_Descriptor_Header_t).Size;
|
||||
|
||||
*CurrConfigLoc += CurrDescriptorSize;
|
||||
*BytesRem -= CurrDescriptorSize;
|
||||
}
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 Configuration descriptor parser API.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* \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
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to the parsing of Configuration Descriptors.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __CONFIGDESCRIPTOR_H__
|
||||
#define __CONFIGDESCRIPTOR_H__
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "../../../Common/Common.h"
|
||||
#include "../HighLevel/USBMode.h"
|
||||
#include "../LowLevel/HostChapter9.h"
|
||||
#include "../HighLevel/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: */
|
||||
/** Mask for determining the type of an endpoint from an endpoint descriptor. This should then be compared
|
||||
* with the EP_TYPE_* masks to determine the exact type of the endpoint.
|
||||
*/
|
||||
#define EP_TYPE_MASK 0x03
|
||||
|
||||
/** 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_CAST(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_CAST(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 (* const ConfigComparatorPtr_t)(void*);
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Searches for the next descriptor in the given configuration descriptor using a premade 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* BytesRem, void** CurrConfigLoc, ConfigComparatorPtr_t ComparatorRoutine);
|
||||
|
||||
/* 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 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 uint16_t 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(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr, void* BufferPtr,
|
||||
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);
|
||||
|
||||
/* 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** const CurrConfigLoc)
|
||||
ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);
|
||||
static inline void USB_GetNextDescriptor(uint16_t* const BytesRem,
|
||||
void** const CurrConfigLoc)
|
||||
{
|
||||
uint16_t CurrDescriptorSize = DESCRIPTOR_CAST(*CurrConfigLoc, USB_Descriptor_Header_t).Size;
|
||||
|
||||
*CurrConfigLoc += CurrDescriptorSize;
|
||||
*BytesRem -= CurrDescriptorSize;
|
||||
}
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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)
|
||||
{
|
||||
|
||||
}
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -1,362 +1,362 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 events manager.
|
||||
*
|
||||
* This file 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).
|
||||
*
|
||||
* \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
|
||||
*
|
||||
* 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 <avr/io.h>
|
||||
|
||||
#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 stack initialization failure. This event fires when the USB interface fails to
|
||||
* initialize correctly due to a hardware or software fault.
|
||||
*
|
||||
* \note This event only exists on USB AVR models which support dual role modes.
|
||||
*
|
||||
* \param[in] ErrorCode Error code indicating the failure reason, a value in \ref USB_InitErrorCodes_t
|
||||
*/
|
||||
void EVENT_USB_InitFailure(const uint8_t ErrorCode);
|
||||
|
||||
/** 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 connected before the role change).
|
||||
*
|
||||
* \note This event only exists on USB AVR models which support dual role modes.
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist if the USB_DEVICE_ONLY or 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 USB AVR models which supports host mode.
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist if the 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 USB AVR models which supports host mode.
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist if the 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 USB AVR models which supports host mode.
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist if the 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 USB AVR models which supports host mode.
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist if the 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 device connection. This event fires when the AVR in device mode and the device is connected
|
||||
* to a host, beginning the enumeration process, measured by a rising level on the AVR's VBUS 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 smaller series 2 USB AVRs with limited USB controllers, VBUS 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 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 series 2 USB AVRs with limited USB controllers
|
||||
* if NO_LIMITED_CONTROLLER_CONNECT is not defined.
|
||||
*
|
||||
* \see USBTask.h 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 AVR in device mode and the device is disconnected
|
||||
* from a host, measured by a falling level on the AVR's VBUS pin.
|
||||
*
|
||||
* \note For the smaller series 2 USB AVRs with limited USB controllers, VBUS 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 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 series 2 USB AVRs with limited USB controllers
|
||||
* if NO_LIMITED_CONTROLLER_CONNECT is not defined.
|
||||
*
|
||||
* \see USBTask.h for more information on the USB management task and reducing CPU usage.
|
||||
*/
|
||||
void EVENT_USB_Device_Disconnect(void);
|
||||
|
||||
/** Event for unhandled control requests. This event fires when a the USB host issues a control
|
||||
* request to the control endpoint (address 0) that the library does not handle. This may either
|
||||
* be a standard request that the library has no handler code for, or a class specific request
|
||||
* issued to the device which must be handled appropriately.
|
||||
*
|
||||
* 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 interally 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, requests
|
||||
* are automatically STALLed.
|
||||
*
|
||||
* \note This event does not exist if the 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_UnhandledControlRequest(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_ConfigurationNumber has been changed.
|
||||
*
|
||||
* \note This event does not exist if the 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 USB_HOST_ONLY token is supplied to the compiler (see
|
||||
* \ref Group_USBManagement documentation).
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist on the series 2 USB AVRs when the 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 USB_HOST_ONLY token is supplied to the compiler (see
|
||||
* \ref Group_USBManagement documentation).
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist on the series 2 USB AVRs when the NO_LIMITED_CONTROLLER_CONNECT
|
||||
* compile time token is not set - see \ref EVENT_USB_Device_Connect.
|
||||
*
|
||||
* \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 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 wakeups.
|
||||
*
|
||||
* \note 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 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_InitFailure(const uint8_t ErrorCode) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
|
||||
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);
|
||||
#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_UnhandledControlRequest(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
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 events manager.
|
||||
*
|
||||
* This file 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).
|
||||
*
|
||||
* \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
|
||||
*
|
||||
* 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 <avr/io.h>
|
||||
|
||||
#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 stack initialization failure. This event fires when the USB interface fails to
|
||||
* initialize correctly due to a hardware or software fault.
|
||||
*
|
||||
* \note This event only exists on USB AVR models which support dual role modes.
|
||||
*
|
||||
* \param[in] ErrorCode Error code indicating the failure reason, a value in \ref USB_InitErrorCodes_t
|
||||
*/
|
||||
void EVENT_USB_InitFailure(const uint8_t ErrorCode);
|
||||
|
||||
/** 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 connected before the role change).
|
||||
*
|
||||
* \note This event only exists on USB AVR models which support dual role modes.
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist if the USB_DEVICE_ONLY or 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 USB AVR models which supports host mode.
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist if the 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 USB AVR models which supports host mode.
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist if the 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 USB AVR models which supports host mode.
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist if the 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 USB AVR models which supports host mode.
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist if the 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 device connection. This event fires when the AVR in device mode and the device is connected
|
||||
* to a host, beginning the enumeration process, measured by a rising level on the AVR's VBUS 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 smaller series 2 USB AVRs with limited USB controllers, VBUS 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 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 series 2 USB AVRs with limited USB controllers
|
||||
* if NO_LIMITED_CONTROLLER_CONNECT is not defined.
|
||||
*
|
||||
* \see USBTask.h 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 AVR in device mode and the device is disconnected
|
||||
* from a host, measured by a falling level on the AVR's VBUS pin.
|
||||
*
|
||||
* \note For the smaller series 2 USB AVRs with limited USB controllers, VBUS 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 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 series 2 USB AVRs with limited USB controllers
|
||||
* if NO_LIMITED_CONTROLLER_CONNECT is not defined.
|
||||
*
|
||||
* \see USBTask.h for more information on the USB management task and reducing CPU usage.
|
||||
*/
|
||||
void EVENT_USB_Device_Disconnect(void);
|
||||
|
||||
/** Event for unhandled control requests. This event fires when a the USB host issues a control
|
||||
* request to the control endpoint (address 0) that the library does not handle. This may either
|
||||
* be a standard request that the library has no handler code for, or a class specific request
|
||||
* issued to the device which must be handled appropriately.
|
||||
*
|
||||
* 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 interally 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, requests
|
||||
* are automatically STALLed.
|
||||
*
|
||||
* \note This event does not exist if the 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_UnhandledControlRequest(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_ConfigurationNumber has been changed.
|
||||
*
|
||||
* \note This event does not exist if the 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 USB_HOST_ONLY token is supplied to the compiler (see
|
||||
* \ref Group_USBManagement documentation).
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist on the series 2 USB AVRs when the 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 USB_HOST_ONLY token is supplied to the compiler (see
|
||||
* \ref Group_USBManagement documentation).
|
||||
* \n\n
|
||||
*
|
||||
* \note This event does not exist on the series 2 USB AVRs when the NO_LIMITED_CONTROLLER_CONNECT
|
||||
* compile time token is not set - see \ref EVENT_USB_Device_Connect.
|
||||
*
|
||||
* \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 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 wakeups.
|
||||
*
|
||||
* \note 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 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_InitFailure(const uint8_t ErrorCode) ATTR_WEAK ATTR_ALIAS(USB_Event_Stub);
|
||||
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);
|
||||
#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_UnhandledControlRequest(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
|
||||
|
||||
/** @} */
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,226 +1,226 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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.
|
||||
*
|
||||
* This file contains structures and macros for the easy creation and parsing of standard USB control requests.
|
||||
*
|
||||
* \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
|
||||
*
|
||||
* 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__
|
||||
|
||||
/* 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 (Standard, Class
|
||||
* or Vendor Specific). 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
|
||||
|
||||
/** 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)
|
||||
|
||||
/** 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)
|
||||
|
||||
/** 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)
|
||||
|
||||
/** Feature indicator for Clear Feature or Set Feature commands. When used in a Clear Feature
|
||||
* request this indicates that an endpoint (whose address is given elsewhere in the request
|
||||
* should have its stall condition cleared. If used in a similar manner inside a Set Feature
|
||||
* request, this stalls an endpoint.
|
||||
*/
|
||||
#define FEATURE_ENDPOINT_HALT 0x00
|
||||
|
||||
/** Feature indicator for Clear Feature or Set Feature commands. When used in a Clear Feature
|
||||
* request this indicates that the remote wakeup enabled device should not issue remote
|
||||
* wakeup requests until further notice. If used in a similar manner inside a Set Feature
|
||||
* request, this re-enabled the remote wakeup feature on the device.
|
||||
*/
|
||||
#define FEATURE_REMOTE_WAKEUP 0x01
|
||||
|
||||
/* 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. */
|
||||
} 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, endpoint and interface
|
||||
* recipients. Passed to the user application for other recipients
|
||||
* via the \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
|
||||
* device mode. */
|
||||
REQ_ClearFeature = 1, /**< Implemented in the library for device, endpoint and interface
|
||||
* recipients. Passed to the user application for other recipients
|
||||
* via the \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
|
||||
* device mode. */
|
||||
REQ_SetFeature = 3, /**< Implemented in the library for device, endpoint and interface
|
||||
* recipients. Passed to the user application for other recipients
|
||||
* via the \ref EVENT_USB_Device_UnhandledControlRequest() 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_UnhandledControlRequest() event when received in
|
||||
* device mode. */
|
||||
REQ_GetDescriptor = 6, /**< Implemented in the library for all recipients and all request
|
||||
* types. */
|
||||
REQ_SetDescriptor = 7, /**< Not implemented in the library, passed to the user application
|
||||
* via the \ref EVENT_USB_Device_UnhandledControlRequest() 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_UnhandledControlRequest() 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_UnhandledControlRequest() 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_UnhandledControlRequest() 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_UnhandledControlRequest() 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_UnhandledControlRequest() event when received in
|
||||
* device mode. */
|
||||
};
|
||||
|
||||
/* 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
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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.
|
||||
*
|
||||
* This file contains structures and macros for the easy creation and parsing of standard USB control requests.
|
||||
*
|
||||
* \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
|
||||
*
|
||||
* 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__
|
||||
|
||||
/* 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 (Standard, Class
|
||||
* or Vendor Specific). 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
|
||||
|
||||
/** 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)
|
||||
|
||||
/** 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)
|
||||
|
||||
/** 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)
|
||||
|
||||
/** Feature indicator for Clear Feature or Set Feature commands. When used in a Clear Feature
|
||||
* request this indicates that an endpoint (whose address is given elsewhere in the request
|
||||
* should have its stall condition cleared. If used in a similar manner inside a Set Feature
|
||||
* request, this stalls an endpoint.
|
||||
*/
|
||||
#define FEATURE_ENDPOINT_HALT 0x00
|
||||
|
||||
/** Feature indicator for Clear Feature or Set Feature commands. When used in a Clear Feature
|
||||
* request this indicates that the remote wakeup enabled device should not issue remote
|
||||
* wakeup requests until further notice. If used in a similar manner inside a Set Feature
|
||||
* request, this re-enabled the remote wakeup feature on the device.
|
||||
*/
|
||||
#define FEATURE_REMOTE_WAKEUP 0x01
|
||||
|
||||
/* 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. */
|
||||
} 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, endpoint and interface
|
||||
* recipients. Passed to the user application for other recipients
|
||||
* via the \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
|
||||
* device mode. */
|
||||
REQ_ClearFeature = 1, /**< Implemented in the library for device, endpoint and interface
|
||||
* recipients. Passed to the user application for other recipients
|
||||
* via the \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
|
||||
* device mode. */
|
||||
REQ_SetFeature = 3, /**< Implemented in the library for device, endpoint and interface
|
||||
* recipients. Passed to the user application for other recipients
|
||||
* via the \ref EVENT_USB_Device_UnhandledControlRequest() 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_UnhandledControlRequest() event when received in
|
||||
* device mode. */
|
||||
REQ_GetDescriptor = 6, /**< Implemented in the library for all recipients and all request
|
||||
* types. */
|
||||
REQ_SetDescriptor = 7, /**< Not implemented in the library, passed to the user application
|
||||
* via the \ref EVENT_USB_Device_UnhandledControlRequest() 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_UnhandledControlRequest() 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_UnhandledControlRequest() 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_UnhandledControlRequest() 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_UnhandledControlRequest() 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_UnhandledControlRequest() event when received in
|
||||
* device mode. */
|
||||
};
|
||||
|
||||
/* 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
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -1,83 +1,83 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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/pipe stream callback management.
|
||||
*
|
||||
* This file contains definitions for the creation of optional callback routines which can be passed to the
|
||||
* endpoint and/or pipe stream APIs, to abort the transfer currently in progress when a condition is met.
|
||||
*
|
||||
* \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_StreamCallbacks Endpoint and Pipe Stream Callbacks
|
||||
*
|
||||
* Macros and enums for the stream callback routines. This module contains the code required to easily set up
|
||||
* stream callback functions which can be used to force early abort of a stream read/write process. Each callback
|
||||
* should take no arguments, and return a value from the \ref StreamCallback_Return_ErrorCodes_t enum.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __STREAMCALLBACK_H__
|
||||
#define __STREAMCALLBACK_H__
|
||||
|
||||
/* 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: */
|
||||
/** Used with the Endpoint and Pipe stream functions as the callback function parameter, indicating that the stream
|
||||
* call has no callback function to be called between USB packets.
|
||||
*/
|
||||
#define NO_STREAM_CALLBACK NULL
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible error return codes of a stream callback function */
|
||||
enum StreamCallback_Return_ErrorCodes_t
|
||||
{
|
||||
STREAMCALLBACK_Continue = 0, /**< Continue sending or receiving the stream. */
|
||||
STREAMCALLBACK_Abort = 1, /**< Abort the stream send or receiving process. */
|
||||
};
|
||||
|
||||
/* Type Defines: */
|
||||
/** Type define for a Stream Callback function (function taking no arguments and retuning a
|
||||
* uint8_t value). Stream callback functions should have an identical function signature if they
|
||||
* are to be used as the callback parameter of the stream functions.
|
||||
*/
|
||||
typedef uint8_t (* const StreamCallbackPtr_t)(void);
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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/pipe stream callback management.
|
||||
*
|
||||
* This file contains definitions for the creation of optional callback routines which can be passed to the
|
||||
* endpoint and/or pipe stream APIs, to abort the transfer currently in progress when a condition is met.
|
||||
*
|
||||
* \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_StreamCallbacks Endpoint and Pipe Stream Callbacks
|
||||
*
|
||||
* Macros and enums for the stream callback routines. This module contains the code required to easily set up
|
||||
* stream callback functions which can be used to force early abort of a stream read/write process. Each callback
|
||||
* should take no arguments, and return a value from the \ref StreamCallback_Return_ErrorCodes_t enum.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __STREAMCALLBACK_H__
|
||||
#define __STREAMCALLBACK_H__
|
||||
|
||||
/* 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: */
|
||||
/** Used with the Endpoint and Pipe stream functions as the callback function parameter, indicating that the stream
|
||||
* call has no callback function to be called between USB packets.
|
||||
*/
|
||||
#define NO_STREAM_CALLBACK NULL
|
||||
|
||||
/* Enums: */
|
||||
/** Enum for the possible error return codes of a stream callback function */
|
||||
enum StreamCallback_Return_ErrorCodes_t
|
||||
{
|
||||
STREAMCALLBACK_Continue = 0, /**< Continue sending or receiving the stream. */
|
||||
STREAMCALLBACK_Abort = 1, /**< Abort the stream send or receiving process. */
|
||||
};
|
||||
|
||||
/* Type Defines: */
|
||||
/** Type define for a Stream Callback function (function taking no arguments and retuning a
|
||||
* uint8_t value). Stream callback functions should have an identical function signature if they
|
||||
* are to be used as the callback parameter of the stream functions.
|
||||
*/
|
||||
typedef uint8_t (* const StreamCallbackPtr_t)(void);
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -1,138 +1,138 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 capability macros.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* \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
|
||||
*
|
||||
* 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__
|
||||
|
||||
/* 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 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 USB controller
|
||||
* (i.e. ATMEGAXXU4) when defined.
|
||||
*/
|
||||
#define USB_SERIES_4_AVR
|
||||
|
||||
/** Indicates that the target AVR microcontroller belongs to the Series 6 USB controller
|
||||
* (i.e. AT90USBXXX6) when defined.
|
||||
*/
|
||||
#define USB_SERIES_6_AVR
|
||||
|
||||
/** Indicates that the target AVR microcontroller belongs to the Series 7 USB controller
|
||||
* (i.e. AT90USBXXX7) when defined.
|
||||
*/
|
||||
#define USB_SERIES_7_AVR
|
||||
|
||||
/** Indicates that the target AVR 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 AVR 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 AVR 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
|
||||
#elif (defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__))
|
||||
#define USB_SERIES_4_AVR
|
||||
#elif (defined(__AVR_ATmega32U6__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__))
|
||||
#define USB_SERIES_6_AVR
|
||||
#elif (defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__))
|
||||
#define USB_SERIES_7_AVR
|
||||
#endif
|
||||
|
||||
#if !defined(USB_SERIES_7_AVR)
|
||||
#if defined(USB_HOST_ONLY)
|
||||
#error USB_HOST_ONLY is not available for the currently selected USB AVR model.
|
||||
#endif
|
||||
|
||||
#if !defined(USB_DEVICE_ONLY)
|
||||
#define USB_DEVICE_ONLY
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (!defined(USB_DEVICE_ONLY) && !defined(USB_HOST_ONLY))
|
||||
#define USB_CAN_BE_BOTH
|
||||
#define USB_CAN_BE_HOST
|
||||
#define USB_CAN_BE_DEVICE
|
||||
#elif defined(USB_HOST_ONLY)
|
||||
#define USB_CAN_BE_HOST
|
||||
#elif defined(USB_DEVICE_ONLY)
|
||||
#define USB_CAN_BE_DEVICE
|
||||
#endif
|
||||
|
||||
#if (defined(USB_HOST_ONLY) && defined(USB_DEVICE_ONLY))
|
||||
#error USB_HOST_ONLY and USB_DEVICE_ONLY are mutually exclusive.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 capability macros.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* \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
|
||||
*
|
||||
* 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__
|
||||
|
||||
/* 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 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 USB controller
|
||||
* (i.e. ATMEGAXXU4) when defined.
|
||||
*/
|
||||
#define USB_SERIES_4_AVR
|
||||
|
||||
/** Indicates that the target AVR microcontroller belongs to the Series 6 USB controller
|
||||
* (i.e. AT90USBXXX6) when defined.
|
||||
*/
|
||||
#define USB_SERIES_6_AVR
|
||||
|
||||
/** Indicates that the target AVR microcontroller belongs to the Series 7 USB controller
|
||||
* (i.e. AT90USBXXX7) when defined.
|
||||
*/
|
||||
#define USB_SERIES_7_AVR
|
||||
|
||||
/** Indicates that the target AVR 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 AVR 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 AVR 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
|
||||
#elif (defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__))
|
||||
#define USB_SERIES_4_AVR
|
||||
#elif (defined(__AVR_ATmega32U6__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__))
|
||||
#define USB_SERIES_6_AVR
|
||||
#elif (defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__))
|
||||
#define USB_SERIES_7_AVR
|
||||
#endif
|
||||
|
||||
#if !defined(USB_SERIES_7_AVR)
|
||||
#if defined(USB_HOST_ONLY)
|
||||
#error USB_HOST_ONLY is not available for the currently selected USB AVR model.
|
||||
#endif
|
||||
|
||||
#if !defined(USB_DEVICE_ONLY)
|
||||
#define USB_DEVICE_ONLY
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (!defined(USB_DEVICE_ONLY) && !defined(USB_HOST_ONLY))
|
||||
#define USB_CAN_BE_BOTH
|
||||
#define USB_CAN_BE_HOST
|
||||
#define USB_CAN_BE_DEVICE
|
||||
#elif defined(USB_HOST_ONLY)
|
||||
#define USB_CAN_BE_HOST
|
||||
#elif defined(USB_DEVICE_ONLY)
|
||||
#define USB_CAN_BE_DEVICE
|
||||
#endif
|
||||
|
||||
#if (defined(USB_HOST_ONLY) && defined(USB_DEVICE_ONLY))
|
||||
#error USB_HOST_ONLY and USB_DEVICE_ONLY are mutually exclusive.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
|
@ -1,88 +1,88 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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
|
||||
|
|
|
@ -1,204 +1,204 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "../LowLevel/LowLevel.h"
|
||||
#include "Events.h"
|
||||
#include "StdRequestType.h"
|
||||
#include "StdDescriptors.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
#include "../LowLevel/DevChapter9.h"
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
#include "../LowLevel/HostChapter9.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 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_UnhandledControlRequest() event, or for filling up with a control request to issue when
|
||||
* in Host mode before calling \ref USB_Host_SendControlRequest().
|
||||
*
|
||||
* \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 may be altered by the user application to implement the \ref HOST_STATE_Addressed,
|
||||
* \ref HOST_STATE_Configured and \ref HOST_STATE_Suspended states which are not implemented by
|
||||
* the library.
|
||||
*
|
||||
* To reduce program size and speed up checks of this global, it can be placed into one of the AVR's
|
||||
* GPIOR hardware registers instead of RAM by defining the 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, it can be placed into one of the AVR's
|
||||
* GPIOR hardware registers instead of RAM by defining the 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 that this task 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
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2010.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2010 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 <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "../LowLevel/LowLevel.h"
|
||||
#include "Events.h"
|
||||
#include "StdRequestType.h"
|
||||
#include "StdDescriptors.h"
|
||||
#include "USBMode.h"
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
#include "../LowLevel/DevChapter9.h"
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
#include "../LowLevel/HostChapter9.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 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_UnhandledControlRequest() event, or for filling up with a control request to issue when
|
||||
* in Host mode before calling \ref USB_Host_SendControlRequest().
|
||||
*
|
||||
* \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 may be altered by the user application to implement the \ref HOST_STATE_Addressed,
|
||||
* \ref HOST_STATE_Configured and \ref HOST_STATE_Suspended states which are not implemented by
|
||||
* the library.
|
||||
*
|
||||
* To reduce program size and speed up checks of this global, it can be placed into one of the AVR's
|
||||
* GPIOR hardware registers instead of RAM by defining the 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, it can be placed into one of the AVR's
|
||||
* GPIOR hardware registers instead of RAM by defining the 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 that this task 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue