USB HID report descriptor

/*
23~16    15~8      7~4    3~2    1~0
[DATA]    [DATA]    bTag   bType    bSize
*/
#define ITEM_SIZE(x) ((x) & 0x03)

#define TYPE_MAIN (0)
#define TYPE_GLOBAL (0x04)
#define TYPE_LOCAL (0x08)

/* MAIN */
#define TAG_MAIN_INPUT (0x80)
#define TAG_MAIN_OUTPUT (0x90)
#define TAG_MAIN_FEATURE (0xB0)
#define TAG_MAIN_COLLECTION (0xA0)
#define TAG_MAIN_COL_END (0xC0)
/* GLOBAL */
#define TAG_GLOBAL_USAGE_PAGE (0x00)
#define TAG_GLOBAL_LOG_MIN (0x10)
#define TAG_GLOBAL_LOG_MAX (0x20)
#define TAG_GLOBAL_PHY_MIN (0x30)
#define TAG_GLOBAL_PHY_MAX (0x40)
#define TAG_GLOBAL_UNIT_EXP (0x50)
#define TAG_GLOBAL_UNIT (0x60)
#define TAG_GLOBAL_RPT_SIZE (0x70)
#define TAG_GLOBAL_RPT_ID (0x80)
#define TAG_GLOBAL_RPT_CNT (0x90)
#define TAG_GLOBAL_PUSH (0xA0)
#define TAG_GLOBAL_POP (0xB0)
/* LOCAL */
#define TAG_LOCAL_USAGE_ID (0x00)
#define TAG_LOCAL_USAGE_MIN (0x10)
#define TAG_LOCAL_USAGE_MAX (0x20)
#define TAG_LOCAL_DES_IDX (0x30)
#define TAG_LOCAL_DES_MIN (0x40)
#define TAG_LOCAL_DES_MAX (0x50)
#define TAG_LOCAL_NA (0x60)
#define TAG_LOCAL_STR_IDX (0x70)
#define TAG_LOCAL_STR_MIN (0x80)
#define TAG_LOCAL_STR_MAX (0x90)
#define TAG_LOCAL_Delimiter (0xA0)

#define USAGE_PAGE_2(x) (TAG_GLOBAL_USAGE_PAGE | TYPE_GLOBAL | ITEM_SIZE(2)), (uint8_t)((x) & 0x00ff), (uint8_t)((x)>>8)
#define USAGE_PAGE(x) (TAG_GLOBAL_USAGE_PAGE | TYPE_GLOBAL | ITEM_SIZE(1)), (x)
#define USAGE_ID(x) (TAG_LOCAL_USAGE_ID | TYPE_LOCAL | ITEM_SIZE(1)), (x)

#define LOGICAL_MIN(x) (TAG_GLOBAL_LOG_MIN | TYPE_GLOBAL | ITEM_SIZE(1)), (x)
#define LOGICAL_MAX(x) (TAG_GLOBAL_LOG_MAX | TYPE_GLOBAL | ITEM_SIZE(1)), (x)
#define LOGICAL_MAX_2(x) (TAG_GLOBAL_LOG_MAX | TYPE_GLOBAL | ITEM_SIZE(2)), (uint8_t)((x) & 0x00ff), (uint8_t)((x)>>8)

#define REPORT_ID(x) (TAG_GLOBAL_RPT_ID | TYPE_GLOBAL | ITEM_SIZE(1)), (x)
#define REPORT_SIZE(x) (TAG_GLOBAL_RPT_SIZE | TYPE_GLOBAL | ITEM_SIZE(1)), (x)
#define REPORT_CNT(x) (TAG_GLOBAL_RPT_CNT | TYPE_GLOBAL | ITEM_SIZE(1)), (x)

#define COLLECTION_END (TAG_MAIN_COL_END | TYPE_MAIN)
#define COLLECTION(x) (TAG_MAIN_COLLECTION | TYPE_MAIN | ITEM_SIZE(1)), (x)
#define FEATURE(x) (TAG_MAIN_FEATURE | TYPE_MAIN | ITEM_SIZE(1)), (x)
#define OUTPUT(x) (TAG_MAIN_OUTPUT | TYPE_MAIN | ITEM_SIZE(1)), (x)
#define INPUT(x) (TAG_MAIN_INPUT | TYPE_MAIN | ITEM_SIZE(1)), (x)

e.g:

const uint8_t CustomHID_ReportDescriptor[122] =
{
USAGE_PAGE(0x0D),
USAGE_ID(0x01),
COLLECTION(0x01),
//0x05, 0x0D, /* USAGE_PAGE (Vendor Page: 0x008D -- SCALE ) */
//0x09, 0x01, /* USAGE (Demo Kit) */
//0xa1, 0x01, /* COLLECTION (Application) */
/* 6 */

/* Led 1 */
REPORT_ID(0x01),
//0x85, 0x01, /* REPORT_ID (1) */
USAGE_ID(1),
//0x09, 0x01, /* USAGE (LED 1) */
LOGICAL_MIN(0),
//0x15, 0x00, /* LOGICAL_MINIMUM (0) */
LOGICAL_MAX(1),
//0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
REPORT_SIZE(8),
//0x75, 0x08, /* REPORT_SIZE (8) */
REPORT_CNT(1),
//0x95, 0x01, /* REPORT_COUNT (1) */
FEATURE(0x82),
//0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */

REPORT_ID(1),
//0x85, 0x01, /* REPORT_ID (1) */
USAGE_ID(1),
//0x09, 0x01, /* USAGE (LED 1) */
OUTPUT(0x82),
//0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
/* 26 */

/* Led 2 */
REPORT_ID(2),
//0x85, 0x02, /* REPORT_ID 2 */
USAGE_ID(2),
//0x09, 0x02, /* USAGE (LED 2) */
LOGICAL_MIN(0),
//0x15, 0x00, /* LOGICAL_MINIMUM (0) */
LOGICAL_MAX(1),
//0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
REPORT_SIZE(8),
//0x75, 0x08, /* REPORT_SIZE (8) */
REPORT_CNT(1),
//0x95, 0x01, /* REPORT_COUNT (1) */
FEATURE(0x82),
//0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */

REPORT_ID(2),
//0x85, 0x02, /* REPORT_ID (2) */
USAGE_ID(2),
//0x09, 0x02, /* USAGE (LED 2) */
OUTPUT(0x82),
//0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
/* 46 */

/* key Push Button */
REPORT_ID(3),
//0x85, 0x05, /* REPORT_ID (5) */
USAGE_ID(3),
//0x09, 0x05, /* USAGE (Push Button) */
LOGICAL_MIN(0),
//0x15, 0x00, /* LOGICAL_MINIMUM (0) */
LOGICAL_MAX(1),
//0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
REPORT_SIZE(1),
//0x75, 0x01, /* REPORT_SIZE (1) */
INPUT(0x82),
//0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */

USAGE_ID(3),
//0x09, 0x05, /* USAGE (Push Button) */
REPORT_SIZE(1),
//0x75, 0x01, /* REPORT_SIZE (1) */
FEATURE(0x82),
//0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */

REPORT_SIZE(7),
//0x75, 0x07, /* REPORT_SIZE (7) */
INPUT(0x83),
//0x81, 0x83, /* INPUT (Cnst,Var,Abs,Vol) */
REPORT_ID(3),
//0x85, 0x05, /* REPORT_ID (2) */

REPORT_SIZE(7),
//0x75, 0x07, /* REPORT_SIZE (7) */
FEATURE(0x83),
//0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */
/* 74 */

/* Tamper Push Button */
REPORT_ID(4),
//0x85, 0x06, /* REPORT_ID (6) */
USAGE_ID(4),
//0x09, 0x06, /* USAGE (Tamper Push Button) */
LOGICAL_MIN(0),
//0x15, 0x00, /* LOGICAL_MINIMUM (0) */
LOGICAL_MAX(1),
//0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
REPORT_SIZE(1),
//0x75, 0x01, /* REPORT_SIZE (1) */
INPUT(0x82),
//0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */

USAGE_ID(4),
//0x09, 0x06, /* USAGE (Tamper Push Button) */
REPORT_SIZE(1),
//0x75, 0x01, /* REPORT_SIZE (1) */
FEATURE(0x82),
//0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */

REPORT_SIZE(7),
//0x75, 0x07, /* REPORT_SIZE (7) */
INPUT(0x83),
//0x81, 0x83, /* INPUT (Cnst,Var,Abs,Vol) */
REPORT_ID(4),
//0x85, 0x06, /* REPORT_ID (6) */

REPORT_SIZE(7),
//0x75, 0x07, /* REPORT_SIZE (7) */
FEATURE(0x83),
//0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */
/* 102 */

/* ADC IN */
REPORT_ID(5),
//0x85, 0x07, /* REPORT_ID (7) */
USAGE_ID(5),
//0x09, 0x07, /* USAGE (ADC IN) */
LOGICAL_MIN(0),
//0x15, 0x00, /* LOGICAL_MINIMUM (0) */
LOGICAL_MAX_2(0x00ff),
//0x26, 0xff, 0x00, /* LOGICAL_MAXIMUM (255) */
REPORT_SIZE(8),
//0x75, 0x08, /* REPORT_SIZE (8) */
INPUT(0x82),
//0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
REPORT_ID(5),
//0x85, 0x07, /* REPORT_ID (7) */
USAGE_ID(5),
//0x09, 0x07, /* USAGE (ADC in) */
FEATURE(0x82),
//0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
/* 121 */

COLLECTION_END /* END_COLLECTION */
}; /* CustomHID_ReportDescriptor */

 

 

 

 

 

 

posted @ 2013-04-21 13:40  ele_eye  阅读(1139)  评论(0编辑  收藏  举报