HID报告描述符的GLOBAL ITEM
2022-05-16
567
0
HID报告描述符的GLOBAL ITEM相当于报告描述符的全部变量,只能不更新,以前的值就永远有意义。
ITEM_PREFIX的BIT2,BIT3为01,bit4-7的值为:
GLOBAL ITEM包括的内容有:
#define ITEM_TAG_GLOBAL_USAGE_PAGE 0x0
#define ITEM_TAG_GLOBAL_LOGICAL_MINIMUM 0x1
#define ITEM_TAG_GLOBAL_LOGICAL_MAXIMUM 0x2
#define ITEM_TAG_GLOBAL_PHYSICAL_MINIMUM 0x3
#define ITEM_TAG_GLOBAL_PHYSICAL_MAXIMUM 0x4
#define ITEM_TAG_GLOBAL_UNIT_EXPONENT 0x5
#define ITEM_TAG_GLOBAL_UNIT 0x6
#define ITEM_TAG_GLOBAL_REPORT_SIZE 0x7
#define ITEM_TAG_GLOBAL_REPORT_ID 0x8
#define ITEM_TAG_GLOBAL_REPORT_COUNT 0x9
#define ITEM_TAG_GLOBAL_PUSH 0xa
#define ITEM_TAG_GLOBAL_POP 0xb
UCHAR Size:2 | UCHAR Type:2 | UCHAR Tag:4 | |
---|---|---|---|
ITEM_TAG_GLOBAL_USAGE_PAGE | XX | ITEM_TYPE_GLOBAL=1 | 0 |
ITEM_TAG_GLOBAL_LOGICAL_MINIMUM | XX | ITEM_TYPE_GLOBAL=1 | 1 |
ITEM_TAG_GLOBAL_LOGICAL_MAXIMUM | XX | ITEM_TYPE_GLOBAL=1 | 2 |
ITEM_TAG_GLOBAL_PHYSICAL_MINIMUM | XX | ITEM_TYPE_GLOBAL=1 | 3 |
ITEM_TAG_GLOBAL_PHYSICAL_MAXIMUM | XX | ITEM_TYPE_GLOBAL=1 | 4 |
ITEM_TAG_GLOBAL_UNIT_EXPONENT | XX | IITEM_TYPE_GLOBAL=1 | 5 |
ITEM_TAG_GLOBAL_UNIT | XX | ITEM_TYPE_GLOBAL=1 | 6 |
ITEM_TAG_GLOBAL_REPORT_SIZE | XX | ITEM_TYPE_GLOBAL=1 | 7 |
ITEM_TAG_GLOBAL_REPORT_ID | XX | ITEM_TYPE_GLOBAL=1 | 8 |
ITEM_TAG_GLOBAL_REPORT_COUNT | XX | ITEM_TYPE_GLOBAL=1 | 9 |
ITEM_TAG_GLOBAL_PUSH | XX | ITEM_TYPE_GLOBAL=1 | 0x0a |
ITEM_TAG_GLOBAL_POP | XX | ITEM_TYPE_GLOBAL=1 | 0x0B |
全局项的功能比较简单,就是更新GLOBAL_ITEM_STATE GlobalItemState相关的参数。
typedef struct
{
...
//
// global item state
//
GLOBAL_ITEM_STATE GlobalItemState;
...
}HID_PARSER_CONTEXT, *PHID_PARSER_CONTEXT;
GLOBAL_ITEM_STATE的定义如下:
typedef struct __GLOBAL_ITEM_STATE_
{
USHORT UsagePage;
ULONG LogicalMinimum;
ULONG LogicialMaximum;
ULONG PhysicalMinimum;
ULONG PhysicalMaximum;
UCHAR UnitExponent;
UCHAR Unit;
ULONG ReportSize;
ULONG ReportCount;
UCHAR ReportId;
struct __GLOBAL_ITEM_STATE__ * Next;
}GLOBAL_ITEM_STATE, *PGLOBAL_ITEM_STATE;
分析过程如下:
case ITEM_TYPE_GLOBAL:
{
switch (CurrentItem->Tag) {
case ITEM_TAG_GLOBAL_USAGE_PAGE:
Parser->Debug("[HIDPARSE] ITEM_TAG_GLOBAL_USAGE_PAGE %x\n", Data);
ParserContext->GlobalItemState.UsagePage = Data;
break;
case ITEM_TAG_GLOBAL_LOGICAL_MINIMUM:
Parser->Debug("[HIDPARSE] ITEM_TAG_GLOBAL_LOGICAL_MINIMUM %x\n", Data);
ParserContext->GlobalItemState.LogicalMinimum = Data;
break;
case ITEM_TAG_GLOBAL_LOGICAL_MAXIMUM:
Parser->Debug("[HIDPARSE] ITEM_TAG_GLOBAL_LOCAL_MAXIMUM %x\n", Data);
ParserContext->GlobalItemState.LogicialMaximum = Data;
break;
case ITEM_TAG_GLOBAL_PHYSICAL_MINIMUM:
Parser->Debug("[HIDPARSE] ITEM_TAG_GLOBAL_PHYSICAL_MINIMUM %x\n", Data);
ParserContext->GlobalItemState.PhysicalMinimum = Data;
break;
case ITEM_TAG_GLOBAL_PHYSICAL_MAXIMUM:
Parser->Debug("[HIDPARSE] ITEM_TAG_GLOBAL_PHYSICAL_MAXIMUM %x\n", Data);
ParserContext->GlobalItemState.PhysicalMaximum = Data;
break;
case ITEM_TAG_GLOBAL_UNIT_EXPONENT:
Parser->Debug("[HIDPARSE] ITEM_TAG_GLOBAL_REPORT_UNIT_EXPONENT %x\n", Data);
ParserContext->GlobalItemState.UnitExponent = Data;
break;
case ITEM_TAG_GLOBAL_UNIT:
Parser->Debug("[HIDPARSE] ITEM_TAG_GLOBAL_REPORT_UNIT %x\n", Data);
ParserContext->GlobalItemState.Unit = Data;
break;
case ITEM_TAG_GLOBAL_REPORT_SIZE:
Parser->Debug("[HIDPARSE] ITEM_TAG_GLOBAL_REPORT_SIZE %x\n", Data);
ParserContext->GlobalItemState.ReportSize = Data;
break;
case ITEM_TAG_GLOBAL_REPORT_ID:
Parser->Debug("[HIDPARSE] ITEM_TAG_GLOBAL_REPORT_ID %x\n", Data);
ParserContext->GlobalItemState.ReportId = Data;
ParserContext->UseReportIDs = TRUE;
break;
case ITEM_TAG_GLOBAL_REPORT_COUNT:
Parser->Debug("[HIDPARSE] ITEM_TAG_GLOBAL_REPORT_COUNT %x\n", Data);
ParserContext->GlobalItemState.ReportCount = Data;
break;
case ITEM_TAG_GLOBAL_PUSH:
{
Parser->Debug("[HIDPARSE] ITEM_TAG_GLOBAL_PUSH\n");
//
// allocate global item state
//
LinkedGlobalItemState = (PGLOBAL_ITEM_STATE)Parser->Alloc(sizeof(GLOBAL_ITEM_STATE));
ASSERT(LinkedGlobalItemState);
//
// copy global item state
//
Parser->Copy(LinkedGlobalItemState, &ParserContext->GlobalItemState, sizeof(GLOBAL_ITEM_STATE));
//
// store pushed item in link member
//
ParserContext->GlobalItemState.Next = (struct __GLOBAL_ITEM_STATE__*)LinkedGlobalItemState;
break;
}
case ITEM_TAG_GLOBAL_POP:
{
Parser->Debug("[HIDPARSE] ITEM_TAG_GLOBAL_POP\n");
if (ParserContext->GlobalItemState.Next == NULL)
{
//
// pop without push
//
ASSERT(FALSE);
break;
}
//
// get link
//
LinkedGlobalItemState = (PGLOBAL_ITEM_STATE)ParserContext->GlobalItemState.Next;
//
// replace current item with linked one
//
Parser->Copy(&ParserContext->GlobalItemState, LinkedGlobalItemState, sizeof(GLOBAL_ITEM_STATE));
//
// free item
//
Parser->Free(LinkedGlobalItemState);
break;
}
default:
//
// unknown / unsupported tag
//
ASSERT(FALSE);
break;
}
break;
}
HID人机交互QQ群:564808376
UAC音频QQ群:218581009
UVC相机QQ群:331552032
BOT&UASP大容量存储QQ群:258159197
STC-USB单片机QQ群:315457461
USB技术交流QQ群2:580684376
USB技术交流QQ群:952873936