Re-factor HID descriptors.

This commit is contained in:
mbanth
2021-05-06 17:16:24 +01:00
parent 21eee27d64
commit 49f1739098
5 changed files with 191 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
// Copyright 2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
/**
* @brief Human Interface Device (HID) descriptor
*
* This file defines the structure of the HID descriptor.
* Document section numbers refer to the HID Device Class Definition, version 1.11.
*/
#ifndef _HID_DESCRIPTOR_
#define _HID_DESCRIPTOR_
/* USB HID Descriptor (section 6.2.1) */
typedef struct
{
unsigned char bLength; /* Size of the descriptor (bytes) */
unsigned char bDescriptorType0; /* Descriptor type, a constant, 0x21 (section 7.1) */
unsigned char bcdHID[2]; /* HID class specification release */
unsigned char bCountryCode; /* Country code of localized hardware */
unsigned char bNumDescriptors; /* Number of class descriptors */
unsigned char bDescriptorType1; /* Type of 1st class descriptor (section 7.1) */
unsigned char wDescriptorLength1[2]; /* Length in bytes of the 1st class descriptor */
} __attribute__((packed)) USB_HID_Descriptor_t;
#endif // _HID_DESCRIPTOR_

View File

@@ -0,0 +1,54 @@
// Copyright 2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
/**
* @brief Human Interface Device (HID) Endpoint descriptors
*
* This file lists the contents of the HID Endpoint descriptor returned during enumeration.
*/
#ifndef _HID_DESCRIPTOR_CONTENTS_
#define _HID_DESCRIPTOR_CONTENTS_
#include "descriptor_defs.h"
#if (AUDIO_CLASS == 1)
/* HID descriptor */
0x09, /* 0 bLength : Size of descriptor in Bytes */
0x21, /* 1 bDescriptorType (HID) */
0x10, /* 2 bcdHID */
0x01, /* 3 bcdHID */
0x00, /* 4 bCountryCode */
0x01, /* 5 bNumDescriptors */
0x22, /* 6 bDescriptorType[0] (Report) */
sizeof(hidReportDescriptor) & 0xff, /* 7 wDescriptorLength[0] */
sizeof(hidReportDescriptor) >> 8, /* 8 wDescriptorLength[0] */
#elif (AUDIO_CLASS == 2)
.HID_Descriptor =
{
/* HID descriptor */
.bLength = 0x09,
.bDescriptorType0 = 0x21,
.bcdHID =
{
0x10,
0x01,
},
.bCountryCode = 0x00,
.bNumDescriptors = 0x01,
.bDescriptorType1 = 0x22,
.wDescriptorLength1 =
{
sizeof(hidReportDescriptor) & 0xff,
sizeof(hidReportDescriptor) >> 8,
},
},
#else
#error "Unknown Audio Class"
#endif
#endif // _HID_DESCRIPTOR_CONTENTS_

View File

@@ -0,0 +1,20 @@
// Copyright 2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
/**
* @brief Human Interface Device (HID) descriptors
*
* This file lists the contents of the HID descriptors returned during enumeration.
* The full definition of the enumerated descriptors appears in xua_ep0_descriptors.h.
* That file should #include the contents of this one at an appropriate point in the
* definition of the cfgDesc_Audio1 and cfgDesc_Audio2 arrays.
*/
#ifndef _HID_DESCRIPTORS_
#define _HID_DESCRIPTORS_
#include "xua_hid_interface_descriptor_contents.h"
#include "xua_hid_descriptor_contents.h"
#include "xua_hid_endpoint_descriptor_contents.h"
#endif // _HID_DESCRIPTORS_

View File

@@ -0,0 +1,43 @@
// Copyright 2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
/**
* @brief Human Interface Device (HID) Endpoint descriptors
*
* This file lists the contents of the HID Endpoint descriptor returned during enumeration.
*/
#ifndef _HID_ENDPOINT_DESCRIPTOR_CONTENTS_
#define _HID_ENDPOINT_DESCRIPTOR_CONTENTS_
#include "descriptor_defs.h"
#if (AUDIO_CLASS == 1)
/* HID Endpoint descriptor (IN) */
0x07, /* 0 bLength */
0x05, /* 1 bDescriptorType */
ENDPOINT_ADDRESS_IN_HID, /* 2 bEndpointAddress */
0x03, /* 3 bmAttributes (INTERRUPT) */
0x40, /* 4 wMaxPacketSize */
0x00, /* 5 wMaxPacketSize */
ENDPOINT_INT_INTERVAL_IN_HID, /* 6 bInterval */
#elif (AUDIO_CLASS == 2)
.HID_In_Endpoint =
{
/* Endpoint descriptor (IN) */
.bLength = 0x7,
.bDescriptorType = 5,
.bEndpointAddress = ENDPOINT_ADDRESS_IN_HID,
.bmAttributes = 3,
.wMaxPacketSize = 64,
.bInterval = ENDPOINT_INT_INTERVAL_IN_HID,
},
#else
#error "Unknown Audio Class"
#endif
#endif // _HID_ENDPOINT_DESCRIPTOR_CONTENTS_

View File

@@ -0,0 +1,48 @@
// Copyright 2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
/**
* @brief Human Interface Device (HID) Interface descriptor
*
* This file lists the contents of the HID Interface descriptor returned during enumeration.
*/
#ifndef _HID_INTERFACE_DESCRIPTOR_CONTENTS_
#define _HID_INTERFACE_DESCRIPTOR_CONTENTS_
#include "descriptor_defs.h"
#if (AUDIO_CLASS == 1)
/* HID interface descriptor */
0x09, /* 0 bLength : Size of descriptor in Bytes */
0x04, /* 1 bDescriptorType (Interface: 0x04)*/
INTERFACE_NUMBER_HID, /* 2 bInterfaceNumber : Number of interface */
0x00, /* 3 bAlternateSetting : Value used alternate interfaces using SetInterface Request */
0x01, /* 4: bNumEndpoints : Number of endpoitns for this interface (excluding 0) */
0x03, /* 5: bInterfaceClass */
0x00, /* 6: bInterfaceSubClass - no boot device */
0x00, /* 7: bInterfaceProtocol*/
0x00, /* 8 iInterface */
#elif (AUDIO_CLASS == 2)
.HID_Interface =
{
/* HID interface descriptor */
.bLength = 0x09,
.bDescriptorType = 0x04,
.bInterfaceNumber = INTERFACE_NUMBER_HID,
.bAlternateSetting = 0x00, /* alternate interfaces using SetInterface Request */
.bNumEndpoints = 0x01,
.bInterfaceClass = 0x03,
.bInterfaceSubClass = 0x00, /* no boot device */
.bInterfaceProtocol = 0x00,
.iInterface = 0x00,
},
#else
#error "Unknown Audio Class"
#endif
#endif // _HID_INTERFACE_DESCRIPTOR_CONTENTS_