Commit of new class abstraction APIs for all device demos other than the MIDI demo - not documented yet.
Removed scheduler and memory allocation libraries. Added new EVENT_USB_StartOfFrame event in the library to indicate the start of each USB frame (when generated). Removed Tx interrupt from the USBtoSerial demo; now sends characters via polling to ensure more time for the Rx interrupt.
This commit is contained in:
parent
2440ca268a
commit
d1e5266036
106 changed files with 3072 additions and 5760 deletions
326
LUFA/Drivers/USB/Class/Host/HIDParser.c
Normal file
326
LUFA/Drivers/USB/Class/Host/HIDParser.c
Normal file
|
@ -0,0 +1,326 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2009.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, 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.
|
||||
*/
|
||||
|
||||
#include "HIDParser.h"
|
||||
|
||||
uint8_t USB_ProcessHIDReport(const uint8_t* ReportData, uint16_t ReportSize, HID_ReportInfo_t* const ParserData)
|
||||
{
|
||||
HID_StateTable_t StateTable[HID_STATETABLE_STACK_DEPTH];
|
||||
HID_StateTable_t* CurrStateTable = &StateTable[0];
|
||||
uint16_t UsageStack[HID_USAGE_STACK_DEPTH];
|
||||
uint8_t UsageStackSize = 0;
|
||||
uint16_t BitOffsetIn = 0;
|
||||
uint16_t BitOffsetOut = 0;
|
||||
#if defined(HID_ENABLE_FEATURE_PROCESSING)
|
||||
uint16_t BitOffsetFeature = 0;
|
||||
#endif
|
||||
HID_CollectionPath_t* CurrCollectionPath = NULL;
|
||||
|
||||
memset((void*)ParserData, 0x00, sizeof(HID_ReportInfo_t));
|
||||
memset((void*)StateTable, 0x00, sizeof(StateTable));
|
||||
|
||||
while (ReportSize)
|
||||
{
|
||||
uint32_t ReportItemData = 0;
|
||||
|
||||
switch (*ReportData & DATA_SIZE_MASK)
|
||||
{
|
||||
case DATA_SIZE_4:
|
||||
ReportItemData = *((uint32_t*)(ReportData + 1));
|
||||
break;
|
||||
case DATA_SIZE_2:
|
||||
ReportItemData = *((uint16_t*)(ReportData + 1));
|
||||
break;
|
||||
case DATA_SIZE_1:
|
||||
ReportItemData = *((uint8_t*)(ReportData + 1));
|
||||
break;
|
||||
}
|
||||
|
||||
switch (*ReportData & (TYPE_MASK | TAG_MASK))
|
||||
{
|
||||
case (TYPE_GLOBAL | TAG_GLOBAL_PUSH):
|
||||
if (CurrStateTable == &StateTable[HID_STATETABLE_STACK_DEPTH])
|
||||
return HID_PARSE_HIDStackOverflow;
|
||||
|
||||
memcpy((CurrStateTable - 1),
|
||||
CurrStateTable,
|
||||
sizeof(HID_ReportItem_t));
|
||||
|
||||
CurrStateTable++;
|
||||
break;
|
||||
case (TYPE_GLOBAL | TAG_GLOBAL_POP):
|
||||
if (CurrStateTable == &StateTable[0])
|
||||
return HID_PARSE_HIDStackUnderflow;
|
||||
|
||||
CurrStateTable--;
|
||||
break;
|
||||
case (TYPE_GLOBAL | TAG_GLOBAL_USAGEPAGE):
|
||||
CurrStateTable->Attributes.Usage.Page = ReportItemData;
|
||||
break;
|
||||
case (TYPE_GLOBAL | TAG_GLOBAL_LOGICALMIN):
|
||||
CurrStateTable->Attributes.Logical.Minimum = ReportItemData;
|
||||
break;
|
||||
case (TYPE_GLOBAL | TAG_GLOBAL_LOGICALMAX):
|
||||
CurrStateTable->Attributes.Logical.Maximum = ReportItemData;
|
||||
break;
|
||||
case (TYPE_GLOBAL | TAG_GLOBAL_PHYSMIN):
|
||||
CurrStateTable->Attributes.Physical.Minimum = ReportItemData;
|
||||
break;
|
||||
case (TYPE_GLOBAL | TAG_GLOBAL_PHYSMAX):
|
||||
CurrStateTable->Attributes.Physical.Maximum = ReportItemData;
|
||||
break;
|
||||
case (TYPE_GLOBAL | TAG_GLOBAL_UNITEXP):
|
||||
CurrStateTable->Attributes.Unit.Exponent = ReportItemData;
|
||||
break;
|
||||
case (TYPE_GLOBAL | TAG_GLOBAL_UNIT):
|
||||
CurrStateTable->Attributes.Unit.Type = ReportItemData;
|
||||
break;
|
||||
case (TYPE_GLOBAL | TAG_GLOBAL_REPORTSIZE):
|
||||
CurrStateTable->Attributes.BitSize = ReportItemData;
|
||||
break;
|
||||
case (TYPE_GLOBAL | TAG_GLOBAL_REPORTCOUNT):
|
||||
CurrStateTable->ReportCount = ReportItemData;
|
||||
break;
|
||||
case (TYPE_GLOBAL | TAG_GLOBAL_REPORTID):
|
||||
CurrStateTable->ReportID = ReportItemData;
|
||||
break;
|
||||
case (TYPE_LOCAL | TAG_LOCAL_USAGE):
|
||||
if (UsageStackSize == HID_USAGE_STACK_DEPTH)
|
||||
return HID_PARSE_UsageStackOverflow;
|
||||
|
||||
UsageStack[UsageStackSize++] = ReportItemData;
|
||||
break;
|
||||
case (TYPE_LOCAL | TAG_LOCAL_USAGEMIN):
|
||||
CurrStateTable->Attributes.Usage.MinMax.Minimum = ReportItemData;
|
||||
break;
|
||||
case (TYPE_LOCAL | TAG_LOCAL_USAGEMAX):
|
||||
CurrStateTable->Attributes.Usage.MinMax.Maximum = ReportItemData;
|
||||
break;
|
||||
case (TYPE_MAIN | TAG_MAIN_COLLECTION):
|
||||
if (CurrCollectionPath == NULL)
|
||||
{
|
||||
CurrCollectionPath = &ParserData->CollectionPaths[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
HID_CollectionPath_t* ParentCollectionPath = CurrCollectionPath;
|
||||
|
||||
CurrCollectionPath = &ParserData->CollectionPaths[1];
|
||||
|
||||
while (CurrCollectionPath->Parent != NULL);
|
||||
{
|
||||
if (CurrCollectionPath == &ParserData->CollectionPaths[HID_MAX_COLLECTIONS])
|
||||
return HID_PARSE_InsufficientCollectionPaths;
|
||||
|
||||
CurrCollectionPath++;
|
||||
}
|
||||
|
||||
CurrCollectionPath->Parent = ParentCollectionPath;
|
||||
}
|
||||
|
||||
CurrCollectionPath->Type = ReportItemData;
|
||||
CurrCollectionPath->Usage.Page = CurrStateTable->Attributes.Usage.Page;
|
||||
|
||||
if (UsageStackSize)
|
||||
{
|
||||
CurrCollectionPath->Usage.Usage = UsageStack[0];
|
||||
|
||||
for (uint8_t i = 0; i < UsageStackSize; i++)
|
||||
UsageStack[i] = UsageStack[i + 1];
|
||||
|
||||
UsageStackSize--;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrCollectionPath->Usage.Usage = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
case (TYPE_MAIN | TAG_MAIN_ENDCOLLECTION):
|
||||
if (CurrCollectionPath == NULL)
|
||||
return HID_PARSE_UnexpectedEndCollection;
|
||||
|
||||
CurrCollectionPath = CurrCollectionPath->Parent;
|
||||
|
||||
break;
|
||||
case (TYPE_MAIN | TAG_MAIN_INPUT):
|
||||
case (TYPE_MAIN | TAG_MAIN_OUTPUT):
|
||||
#if defined(HID_ENABLE_FEATURE_PROCESSING)
|
||||
case (TYPE_MAIN | TAG_MAIN_FEATURE):
|
||||
#endif
|
||||
for (uint8_t ReportItemNum = 0; ReportItemNum < CurrStateTable->ReportCount; ReportItemNum++)
|
||||
{
|
||||
HID_ReportItem_t* CurrReportItem = &ParserData->ReportItems[ParserData->TotalReportItems];
|
||||
|
||||
if (ParserData->TotalReportItems == HID_MAX_REPORTITEMS)
|
||||
return HID_PARSE_InsufficientReportItems;
|
||||
|
||||
memcpy(&CurrReportItem->Attributes,
|
||||
&CurrStateTable->Attributes,
|
||||
sizeof(HID_ReportItem_Attributes_t));
|
||||
|
||||
CurrReportItem->ItemFlags = ReportItemData;
|
||||
CurrReportItem->CollectionPath = CurrCollectionPath;
|
||||
CurrReportItem->ReportID = CurrStateTable->ReportID;
|
||||
|
||||
if (UsageStackSize)
|
||||
{
|
||||
CurrReportItem->Attributes.Usage.Usage = UsageStack[0];
|
||||
|
||||
for (uint8_t i = 0; i < UsageStackSize; i++)
|
||||
UsageStack[i] = UsageStack[i + 1];
|
||||
|
||||
UsageStackSize--;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrReportItem->Attributes.Usage.Usage = 0;
|
||||
}
|
||||
|
||||
switch (*ReportData & TAG_MASK)
|
||||
{
|
||||
case TAG_MAIN_INPUT:
|
||||
CurrReportItem->ItemType = REPORT_ITEM_TYPE_In;
|
||||
CurrReportItem->BitOffset = BitOffsetIn;
|
||||
|
||||
BitOffsetIn += CurrStateTable->Attributes.BitSize;
|
||||
|
||||
break;
|
||||
case TAG_MAIN_OUTPUT:
|
||||
CurrReportItem->ItemType = REPORT_ITEM_TYPE_Out;
|
||||
CurrReportItem->BitOffset = BitOffsetOut;
|
||||
|
||||
BitOffsetOut += CurrStateTable->Attributes.BitSize;
|
||||
|
||||
break;
|
||||
#if defined(HID_ENABLE_FEATURE_PROCESSING)
|
||||
case TAG_MAIN_FEATURE:
|
||||
CurrReportItem->ItemType = REPORT_ITEM_TYPE_Feature;
|
||||
CurrReportItem->BitOffset = BitOffsetFeature;
|
||||
|
||||
BitOffsetFeature += CurrStateTable->Attributes.BitSize;
|
||||
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(HID_INCLUDE_CONSTANT_DATA_ITEMS)
|
||||
if (!(ReportItemData & IOF_CONSTANT))
|
||||
ParserData->TotalReportItems++;
|
||||
#else
|
||||
ParserData->TotalReportItems++;
|
||||
#endif
|
||||
}
|
||||
|
||||
UsageStackSize = 0;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ((*ReportData & TYPE_MASK) == TYPE_MAIN)
|
||||
{
|
||||
CurrStateTable->Attributes.Usage.MinMax.Minimum = 0;
|
||||
CurrStateTable->Attributes.Usage.MinMax.Maximum = 0;
|
||||
UsageStackSize = 0;
|
||||
}
|
||||
|
||||
switch (*ReportData & DATA_SIZE_MASK)
|
||||
{
|
||||
case DATA_SIZE_4:
|
||||
ReportSize -= 5;
|
||||
ReportData += 5;
|
||||
break;
|
||||
case DATA_SIZE_2:
|
||||
ReportSize -= 3;
|
||||
ReportData += 3;
|
||||
break;
|
||||
case DATA_SIZE_1:
|
||||
ReportSize -= 2;
|
||||
ReportData += 2;
|
||||
break;
|
||||
case DATA_SIZE_0:
|
||||
ReportSize -= 1;
|
||||
ReportData += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return HID_PARSE_Successful;
|
||||
}
|
||||
|
||||
bool USB_GetHIDReportItemInfo(const uint8_t* ReportData, HID_ReportItem_t* const ReportItem)
|
||||
{
|
||||
uint16_t DataBitsRem = ReportItem->Attributes.BitSize;
|
||||
uint16_t CurrentBit = ReportItem->BitOffset;
|
||||
uint32_t BitMask = (1 << 0);
|
||||
|
||||
ReportItem->Value = 0;
|
||||
|
||||
if (ReportItem->ReportID)
|
||||
{
|
||||
if (ReportItem->ReportID != ReportData[0])
|
||||
return false;
|
||||
|
||||
ReportData++;
|
||||
}
|
||||
|
||||
while (DataBitsRem--)
|
||||
{
|
||||
if (ReportData[CurrentBit / 8] & (1 << (CurrentBit % 8)))
|
||||
ReportItem->Value |= BitMask;
|
||||
|
||||
CurrentBit++;
|
||||
BitMask <<= 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void USB_SetHIDReportItemInfo(uint8_t* ReportData, const HID_ReportItem_t* ReportItem)
|
||||
{
|
||||
uint16_t DataBitsRem = ReportItem->Attributes.BitSize;
|
||||
uint16_t CurrentBit = ReportItem->BitOffset;
|
||||
uint32_t BitMask = (1 << 0);
|
||||
|
||||
if (ReportItem->ReportID)
|
||||
{
|
||||
ReportData[0] = ReportItem->ReportID;
|
||||
ReportData++;
|
||||
}
|
||||
|
||||
while (DataBitsRem--)
|
||||
{
|
||||
if (ReportItem->Value & (1 << (CurrentBit % 8)))
|
||||
ReportData[CurrentBit / 8] |= BitMask;
|
||||
|
||||
CurrentBit++;
|
||||
BitMask <<= 1;
|
||||
}
|
||||
}
|
263
LUFA/Drivers/USB/Class/Host/HIDParser.h
Normal file
263
LUFA/Drivers/USB/Class/Host/HIDParser.h
Normal file
|
@ -0,0 +1,263 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2009.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaim all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* USB Human Interface Device (HID) Class report descriptor processing routines. This file allows for the easy
|
||||
* parsing of the complex HID report descriptor, which describes the data that the device transmits to the host.
|
||||
*
|
||||
*/
|
||||
|
||||
/** \ingroup Group_USB
|
||||
* @defgroup Group_HIDParser HID Report Parser
|
||||
*
|
||||
* Functions, macros, variables, enums and types related to the parsing of HID class device report descriptors.
|
||||
*
|
||||
* The processed HID report is presented back to the user application as a flat structure containing each report
|
||||
* item's IN, OUT and FEATURE (if desired) items along with each item's attributes.
|
||||
*
|
||||
* This library portion also allows for easy setting and retrieval of data from a HID report, including devices
|
||||
* with multiple reports on the one HID interface.
|
||||
*
|
||||
* By default, FEATURE reports and IN/OUT reports with constant data are ignored in the HID report when processed
|
||||
* to save on memory. This can be overridden by defining the HID_ENABLE_FEATURE_PROCESSING or
|
||||
* HID_INCLUDE_CONSTANT_DATA_ITEMS tokens in the user project makefile, passing them to the compiler via the -D
|
||||
* switch.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __HIDPARSER_H__
|
||||
#define __HIDPARSER_H__
|
||||
|
||||
/* Includes: */
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "HIDReportData.h"
|
||||
|
||||
#include "../../../../Common/Common.h"
|
||||
|
||||
/* Enable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Preprocessor checks and defines: */
|
||||
#if !defined(HID_STATETABLE_STACK_DEPTH) || defined(__DOXYGEN__)
|
||||
/** Constant indicating the maximum stack depth of the state table. A larger state table
|
||||
* allows for more PUSH/POP report items to be nested, but consumes more memory. By default
|
||||
* this is set to 3 levels (allowing for two PUSHes to be nested) but this can be overridden by
|
||||
* defining HID_STATETABLE_STACK_DEPTH to another value in the user project makefile, passing the
|
||||
* define to the compiler using the -D compiler switch.
|
||||
*/
|
||||
#define HID_STATETABLE_STACK_DEPTH 3
|
||||
#endif
|
||||
|
||||
#if !defined(HID_USAGE_STACK_DEPTH) || defined(__DOXYGEN__)
|
||||
/** Constant indicating the maximum stack depth of the usage table. A larger usage table
|
||||
* allows for more USAGE items to be indicated sequentially for REPORT COUNT entries of more than
|
||||
* one, but requires more stack space. By default this is set to 8 levels (allowing for a report
|
||||
* item with a count of 8) but this can be overridden by defining HID_USAGE_STACK_DEPTH to another
|
||||
* value in the user project makefile, passing the define to the compiler using the -D compiler
|
||||
* switch.
|
||||
*/
|
||||
#define HID_USAGE_STACK_DEPTH 8
|
||||
#endif
|
||||
|
||||
#if !defined(HID_MAX_COLLECTIONS) || defined(__DOXYGEN__)
|
||||
/** Constant indicating the maximum number of COLLECTION items (nested or unnested) that can be
|
||||
* processed in the report item descriptor. A large value allows for more COLLECTION items to be
|
||||
* processed, but consumes more memory. By default this is set to 5 collections, but this can be
|
||||
* overridden by defining HID_MAX_COLLECTIONS to another value in the user project makefile, passing
|
||||
* the define to the compiler using the -D compiler switch.
|
||||
*/
|
||||
#define HID_MAX_COLLECTIONS 5
|
||||
#endif
|
||||
|
||||
#if !defined(HID_MAX_REPORTITEMS) || defined(__DOXYGEN__)
|
||||
/** Constant indicating the maximum number of report items (IN, OUT or FEATURE if enabled) that can be
|
||||
* processed in the report item descriptor. A large value allows for more report items to be
|
||||
* processed, but consumes more memory. By default this is set to 30 items, but this can be
|
||||
* overridden by defining HID_MAX_REPORTITEMS to another value in the user project makefile, passing
|
||||
* the define to the compiler using the -D compiler switch.
|
||||
*/
|
||||
#define HID_MAX_REPORTITEMS 30
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Enums: */
|
||||
/** Enum for indicating what type of report item an entry in a \ref HID_ReportInfo_t ReportItem array is */
|
||||
enum HID_ReportItemTypes_t
|
||||
{
|
||||
REPORT_ITEM_TYPE_In = 0, /**< Indicates that the item is an IN report type. */
|
||||
REPORT_ITEM_TYPE_Out = 1, /**< Indicates that the item is an OUT report type. */
|
||||
REPORT_ITEM_TYPE_Feature = 2, /**< Indicates that the item is a FEATURE report type. */
|
||||
};
|
||||
|
||||
/** Enum for the possible error codes in the return value of the \ref USB_ProcessHIDReport() function */
|
||||
enum HID_Parse_ErrorCodes_t
|
||||
{
|
||||
HID_PARSE_Successful = 0, /**< Successful parse of the HID report descriptor, no error. */
|
||||
HID_PARSE_HIDStackOverflow = 1, /**< More than \ref HID_STATETABLE_STACK_DEPTH nested PUSHes in the report. */
|
||||
HID_PARSE_HIDStackUnderflow = 2, /**< A POP was found when the state table stack was empty. */
|
||||
HID_PARSE_InsufficientReportItems = 3, /**< More than \ref HID_MAX_REPORTITEMS report items in the report. */
|
||||
HID_PARSE_UnexpectedEndCollection = 4, /**< END COLLECTION found without matching COLLECTION item. */
|
||||
HID_PARSE_InsufficientCollectionPaths = 5, /**< More than \ref HID_MAX_COLLECTIONS collections in the report. */
|
||||
HID_PARSE_UsageStackOverflow = 6, /**< More than \ref HID_USAGE_STACK_DEPTH usages listed in a row. */
|
||||
};
|
||||
|
||||
/* Type Defines: */
|
||||
/** Type define for an attribute with both minimum and maximum values (e.g. Logical Min/Max). */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Minimum; /**< Minimum value for the attribute. */
|
||||
uint32_t Maximum; /**< Maximum value for the attribute. */
|
||||
} HID_MinMax_t;
|
||||
|
||||
/** Type define for the Unit attributes of a report item. */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Type; /**< Unit type (refer to HID specifications for details). */
|
||||
uint8_t Exponent; /**< Unit exponent (refer to HID specifications for details). */
|
||||
} HID_Unit_t;
|
||||
|
||||
/** Type define for the Usage attributes of a report item. */
|
||||
typedef struct
|
||||
{
|
||||
uint16_t Page; /**< Usage page of the report item. */
|
||||
uint16_t Usage; /**< Usage of the report item. */
|
||||
HID_MinMax_t MinMax; /**< Usage minimum and maximum of the report item. */
|
||||
} HID_Usage_t;
|
||||
|
||||
/** Type define for a COLLECTION object. Contains the collection attributes and a reference to the
|
||||
* parent collection if any.
|
||||
*/
|
||||
typedef struct CollectionPath
|
||||
{
|
||||
uint8_t Type; /**< Collection type (e.g. "Generic Desktop"). */
|
||||
HID_Usage_t Usage; /**< Collection usage. */
|
||||
struct CollectionPath* Parent; /**< Reference to parent collection, or NULL if root collection. */
|
||||
} HID_CollectionPath_t;
|
||||
|
||||
/** Type define for all the data attributes of a report item, except flags. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t BitSize; /**< Size in bits of the report item's data. */
|
||||
|
||||
HID_Usage_t Usage; /**< Usage of the report item. */
|
||||
HID_Unit_t Unit; /**< Unit type and exponent of the report item. */
|
||||
HID_MinMax_t Logical; /**< Logical minimum and maximum of the report item. */
|
||||
HID_MinMax_t Physical; /**< Physical minimum and maximum of the report item. */
|
||||
} HID_ReportItem_Attributes_t;
|
||||
|
||||
/** Type define for a report item (IN, OUT or FEATURE) attributes and other details. */
|
||||
typedef struct
|
||||
{
|
||||
uint16_t BitOffset; /**< Bit offset in the IN, OUT or FEATURE report of the item. */
|
||||
uint8_t ItemType; /**< Report item type, a value in HID_Types_t. */
|
||||
uint16_t ItemFlags; /**< Item data flags, such as constant/variable, etc. */
|
||||
uint8_t ReportID; /**< Report ID this item belongs to, or 0x00 if device has only one report */
|
||||
HID_CollectionPath_t* CollectionPath; /**< Collection path of the item. */
|
||||
|
||||
HID_ReportItem_Attributes_t Attributes; /**< Report item attributes. */
|
||||
|
||||
uint32_t Value; /**< Current value of the report item. */
|
||||
} HID_ReportItem_t;
|
||||
|
||||
/** Type define for a complete processed HID report, including all report item data and collections. */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t TotalReportItems; /**< Total number of report items stored in the
|
||||
* ReportItems array. */
|
||||
|
||||
HID_ReportItem_t ReportItems[HID_MAX_REPORTITEMS]; /**< Report items array, including
|
||||
* all IN, OUT and FEATURE items. */
|
||||
|
||||
HID_CollectionPath_t CollectionPaths[HID_MAX_COLLECTIONS]; /**< All collection items, referenced
|
||||
* by the report items. */
|
||||
} HID_ReportInfo_t;
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** Function to process a given HID report returned from an attached device, and store it into a given
|
||||
* \ref HID_ReportInfo_t structure.
|
||||
*
|
||||
* \param ReportData Buffer containing the device's HID report table
|
||||
* \param ReportSize Size in bytes of the HID report table
|
||||
* \param ParserData Pointer to a \ref HID_ReportInfo_t instance for the parser output
|
||||
*
|
||||
* \return A value in the \ref HID_Parse_ErrorCodes_t enum
|
||||
*/
|
||||
uint8_t USB_ProcessHIDReport(const uint8_t* ReportData, uint16_t ReportSize, HID_ReportInfo_t* const ParserData)
|
||||
ATTR_NON_NULL_PTR_ARG(1, 3);
|
||||
|
||||
/** Extracts the given report item's value out of the given HID report and places it into the Value
|
||||
* member of the report item's \ref HID_ReportItem_t structure.
|
||||
*
|
||||
* \param ReportData Buffer containing an IN or FEATURE report from an attached device
|
||||
* \param ReportItem Pointer to the report item of interest in a \ref HID_ReportInfo_t ReportItem array
|
||||
*
|
||||
* \returns Boolean true if the item to retrieve was located in the given report, false otherwise
|
||||
*/
|
||||
bool USB_GetHIDReportItemInfo(const uint8_t* ReportData, HID_ReportItem_t* const ReportItem)
|
||||
ATTR_NON_NULL_PTR_ARG(1, 2);
|
||||
|
||||
/** Retrieves the given report item's value out of the Value member of the report item's
|
||||
* \ref HID_ReportItem_t structure and places it into the correct position in the HID report
|
||||
* buffer. The report buffer is assumed to have the appropriate bits cleared before calling
|
||||
* this function (i.e., the buffer should be explicitly cleared before report values are added).
|
||||
*
|
||||
* If the device has multiple HID reports, the report ID is set to the report ID of the given item.
|
||||
*
|
||||
* \param ReportData Buffer holding the current OUT report data
|
||||
* \param ReportItem Pointer to the report item of interest in a \ref HID_ReportInfo_t ReportItem array
|
||||
*/
|
||||
void USB_SetHIDReportItemInfo(uint8_t* ReportData, const HID_ReportItem_t* ReportItem)
|
||||
ATTR_NON_NULL_PTR_ARG(1, 2);
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Type Defines: */
|
||||
typedef struct
|
||||
{
|
||||
HID_ReportItem_Attributes_t Attributes;
|
||||
uint8_t ReportCount;
|
||||
uint8_t ReportID;
|
||||
} HID_StateTable_t;
|
||||
#endif
|
||||
|
||||
/* Disable C linkage for C++ Compilers: */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
140
LUFA/Drivers/USB/Class/Host/HIDReportData.h
Normal file
140
LUFA/Drivers/USB/Class/Host/HIDReportData.h
Normal file
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2009.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.fourwalledcubicle.com
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
and its documentation for any purpose and without fee is hereby
|
||||
granted, 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
|
||||
*
|
||||
* Constants for HID report item attributes. Refer to the HID specification for details on each
|
||||
* flag's meaning when applied to an IN, OUT or FEATURE item.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_HIDParser
|
||||
* @defgroup Group_HIDIOFConst Input/Output/Feature Masks
|
||||
*
|
||||
* Masks indicating the type of Input, Output of Feature HID report item.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __HIDREPORTDATA_H__
|
||||
#define __HIDREPORTDATA_H__
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** HID_ReportItem_t.ItemFlags flag for constant data. */
|
||||
#define IOF_CONSTANT (1 << 0)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for data. */
|
||||
#define IOF_DATA (0 << 0)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for variable data. */
|
||||
#define IOF_VARIABLE (1 << 1)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for array data. */
|
||||
#define IOF_ARRAY (0 << 1)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for relative data. */
|
||||
#define IOF_RELATIVE (1 << 2)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for absolute data. */
|
||||
#define IOF_ABSOLUTE (0 << 2)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for wrapped value data. */
|
||||
#define IOF_WRAP (1 << 3)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for non-wrapped value data. */
|
||||
#define IOF_NOWRAP (0 << 3)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for non linear data. */
|
||||
#define IOF_NONLINEAR (1 << 4)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for linear data. */
|
||||
#define IOF_LINEAR (0 << 4)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for no preferred state. */
|
||||
#define IOF_NOPREFERRED (1 << 5)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for preferred state items. */
|
||||
#define IOF_PREFERREDSTATE (0 << 5)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for null state items. */
|
||||
#define IOF_NULLSTATE (1 << 6)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for no null position data. */
|
||||
#define IOF_NONULLPOSITION (0 << 6)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for buffered bytes. */
|
||||
#define IOF_BUFFEREDBYTES (1 << 8)
|
||||
|
||||
/** HID_ReportItem_t.ItemFlags flag for bit field data. */
|
||||
#define IOF_BITFIELD (0 << 8)
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define DATA_SIZE_MASK 0x03
|
||||
#define TYPE_MASK 0x0C
|
||||
#define TAG_MASK 0xF0
|
||||
|
||||
#define DATA_SIZE_0 0x00
|
||||
#define DATA_SIZE_1 0x01
|
||||
#define DATA_SIZE_2 0x02
|
||||
#define DATA_SIZE_4 0x03
|
||||
|
||||
#define TYPE_MAIN 0x00
|
||||
#define TYPE_GLOBAL 0x04
|
||||
#define TYPE_LOCAL 0x08
|
||||
|
||||
#define TAG_MAIN_INPUT 0x80
|
||||
#define TAG_MAIN_OUTPUT 0x90
|
||||
#define TAG_MAIN_COLLECTION 0xA0
|
||||
#define TAG_MAIN_FEATURE 0xB0
|
||||
#define TAG_MAIN_ENDCOLLECTION 0xC0
|
||||
|
||||
#define TAG_GLOBAL_USAGEPAGE 0x00
|
||||
#define TAG_GLOBAL_LOGICALMIN 0x10
|
||||
#define TAG_GLOBAL_LOGICALMAX 0x20
|
||||
#define TAG_GLOBAL_PHYSMIN 0x30
|
||||
#define TAG_GLOBAL_PHYSMAX 0x40
|
||||
#define TAG_GLOBAL_UNITEXP 0x50
|
||||
#define TAG_GLOBAL_UNIT 0x60
|
||||
#define TAG_GLOBAL_REPORTSIZE 0x70
|
||||
#define TAG_GLOBAL_REPORTID 0x80
|
||||
#define TAG_GLOBAL_REPORTCOUNT 0x90
|
||||
#define TAG_GLOBAL_PUSH 0xA0
|
||||
#define TAG_GLOBAL_POP 0xB0
|
||||
|
||||
#define TAG_LOCAL_USAGE 0x00
|
||||
#define TAG_LOCAL_USAGEMIN 0x10
|
||||
#define TAG_LOCAL_USAGEMAX 0x20
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue