Add constants header for common constants; helper macro for header

This commit is contained in:
Ciaran Woodward
2021-12-10 10:45:54 +00:00
parent ebeae1fa17
commit 3895b486ab
7 changed files with 141 additions and 35 deletions

View File

@@ -13,11 +13,13 @@
* Document section numbers refer to the HID Device Class Definition, version 1.11.
*/
#ifndef _HID_REPORT_DESCRIPTOR_
#define _HID_REPORT_DESCRIPTOR_
#ifndef _XUA_HID_REPORT_
#define _XUA_HID_REPORT_
#include <stddef.h>
#include "xua_hid_report_descriptor_constants.h"
#define HID_REPORT_ITEM_HDR_SIZE_MASK ( 0x03 )
#define HID_REPORT_ITEM_HDR_SIZE_SHIFT ( 0U )
@@ -44,12 +46,39 @@
#define HID_REPORT_ITEM_USAGE_TAG ( 0U )
#define HID_REPORT_ITEM_USAGE_TYPE ( 2U )
// Constants from the USB Device Class Definition for HID
#define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 )
#define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 )
#define HID_REPORT_ITEM_TYPE_LOCAL ( 0x02 )
#define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 )
/**
* @brief Helper macro to configure the location field of USB_HID_Report_Element_t.
*
* @param id The report ID that this element is within.
* @param len (only relevant for the usage_page elements in hidReports) The length
* of the report under this report ID.
* @param byte The byte location of this element in the report.
* @param bit The bit location (within the byte) of this element in the report.
*/
#define HID_REPORT_SET_LOC(id, len, byte, bit) (\
(( id << HID_REPORT_ELEMENT_LOC_ID_SHIFT ) & HID_REPORT_ELEMENT_LOC_ID_MASK ) | \
(( len << HID_REPORT_ELEMENT_LOC_LEN_SHIFT ) & HID_REPORT_ELEMENT_LOC_LEN_MASK ) | \
(( byte << HID_REPORT_ELEMENT_LOC_BYTE_SHIFT ) & HID_REPORT_ELEMENT_LOC_BYTE_MASK ) | \
(( bit << HID_REPORT_ELEMENT_LOC_BIT_SHIFT ) & HID_REPORT_ELEMENT_LOC_BIT_MASK ))
/**
* @brief Helper macro to configure the header field of USB_HID_Short_Item_t
*
* @param size The size of the report descriptor item (valid values: 0, 1, 2)
* @param type The type of the report descriptor item
* @param tag The tag
*/
#define HID_REPORT_SET_HEADER(size, type, tag) (\
(( size << HID_REPORT_ITEM_HDR_SIZE_SHIFT) & HID_REPORT_ITEM_HDR_SIZE_MASK ) |\
(( type << HID_REPORT_ITEM_HDR_TYPE_SHIFT) & HID_REPORT_ITEM_HDR_TYPE_MASK ) |\
(( tag << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_SHIFT ) )
#define HID_STATUS_GOOD ( 0U )
#define HID_STATUS_BAD_HEADER ( 1U )
#define HID_STATUS_BAD_ID ( 2U )
@@ -473,4 +502,4 @@ unsigned hidSetReportItem(
*/
void hidSetReportPeriod( const unsigned id, const unsigned period );
#endif // _HID_REPORT_DESCRIPTOR_
#endif // _XUA_HID_REPORT_

View File

@@ -0,0 +1,65 @@
// Copyright 2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
/**
* @brief Human Interface Device (HID) Report descriptor constants
*
* This file defines a collection of constants from the USB HID documents.
* This includes constants from:
* - Device Class Definition for Human Interface Devices, version 1.11
* - HID Usage Tables for Universal Serial Bus, version 1.22
*
* This file is incomplete, but can be expanded with new constants as necessary.
*/
#ifndef _XUA_HID_REPORT_DESCRIPTOR_CONSTANTS_
#define _XUA_HID_REPORT_DESCRIPTOR_CONSTANTS_
// Constants from the USB Device Class Definition for HID for type
#define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 )
#define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 )
#define HID_REPORT_ITEM_TYPE_LOCAL ( 0x02 )
#define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 )
// Constants from the USB Device Class Definition for HID for tag
// Main items
#define HID_REPORT_ITEM_TAG_INPUT ( 0x08 )
#define HID_REPORT_ITEM_TAG_OUTPUT ( 0x09 )
#define HID_REPORT_ITEM_TAG_FEATURE ( 0x0B )
#define HID_REPORT_ITEM_TAG_COLLECTION ( 0x0A )
#define HID_REPORT_ITEM_TAG_END_COLLECTION ( 0x0C )
// Global items
#define HID_REPORT_ITEM_TAG_USAGE_PAGE ( 0x00 )
#define HID_REPORT_ITEM_TAG_LOGICAL_MINIMUM ( 0x01 )
#define HID_REPORT_ITEM_TAG_LOGICAL_MAXIMUM ( 0x02 )
#define HID_REPORT_ITEM_TAG_PHYSICAL_MINIMUM ( 0x03 )
#define HID_REPORT_ITEM_TAG_PHYSICAL_MAXIMUM ( 0x04 )
#define HID_REPORT_ITEM_TAG_UNIT_EXPONENT ( 0x05 )
#define HID_REPORT_ITEM_TAG_UNIT ( 0x06 )
#define HID_REPORT_ITEM_TAG_REPORT_SIZE ( 0x07 )
#define HID_REPORT_ITEM_TAG_REPORT_ID ( 0x08 )
#define HID_REPORT_ITEM_TAG_REPORT_COUNT ( 0x09 )
#define HID_REPORT_ITEM_TAG_PUSH ( 0x0A )
#define HID_REPORT_ITEM_TAG_POP ( 0x0B )
// Local items
#define HID_REPORT_ITEM_TAG_USAGE ( 0x00 )
#define HID_REPORT_ITEM_TAG_USAGE_MINIMUM ( 0x01 )
#define HID_REPORT_ITEM_TAG_USAGE_MAXIMUM ( 0x02 )
#define HID_REPORT_ITEM_TAG_DESIGNATOR_INDEX ( 0x03 )
#define HID_REPORT_ITEM_TAG_DESIGNATOR_MINIMUM ( 0x04 )
#define HID_REPORT_ITEM_TAG_DESIGNATOR_MAXIMUM ( 0x05 )
#define HID_REPORT_ITEM_TAG_STRING_INDEX ( 0x07 )
#define HID_REPORT_ITEM_TAG_STRING_MINIMUM ( 0x08 )
#define HID_REPORT_ITEM_TAG_STRING_MAXIMUM ( 0x09 )
#define HID_REPORT_ITEM_TAG_DELIMITER ( 0x0A )
// Constants from HID Usage Tables
// Usage page IDs
#define USB_HID_USAGE_PAGE_ID_KEYBOARD ( 0x07 )
#define USB_HID_USAGE_PAGE_ID_TELEPHONY_DEVICE ( 0x0B )
#define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C )
#endif // _XUA_HID_REPORT_DESCRIPTOR_CONSTANTS_