From c3a45b2cbad328c7c2abc0caac1f315d5d7665f1 Mon Sep 17 00:00:00 2001 From: mbanth Date: Tue, 27 Apr 2021 17:06:19 +0100 Subject: [PATCH 01/12] Change AC Search to Key code t or T --- lib_xua/src/core/endpoint0/xua_ep0_descriptors.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h index 89d8ba3d..f4e5472b 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -581,7 +581,7 @@ unsigned char devQualDesc_Null[] = #endif #if( 0 < HID_CONTROLS ) -unsigned char hidReportDescriptor[] = /* Voice Command usage as per request #HUTRR45 */ +unsigned char hidReportDescriptor[] = { 0x05, 0x01, /* Usage Page (Generic Desktop) */ 0x09, 0x06, /* Usage (Keyboard) */ @@ -593,9 +593,11 @@ unsigned char hidReportDescriptor[] = /* Voice Command usage as per request #HUT 0x81, 0x01, /* Input (Cnst, Ary, Abs, No Wrap, Lin, Pref, No Nul) */ 0x95, 0x01, /* Report Count (1) */ 0x25, 0x01, /* Logical Maximum (1) */ - 0x05, 0x0C, /* Usage Page (Consumer) */ - 0x0a, 0x21, 0x02, /* Usage (AC Search) */ + 0x05, 0x07, /* Usage Page (Key Codes) */ + 0x19, 0x17, /* Usage Minimum (Keyboard t or T) */ + 0x29, 0x17, /* Usage Maximum (Keyboard t or T) */ 0x81, 0x02, /* Input (Data, Var, Abs, No Wrap, Lin, Pref, No Nul) */ + 0x05, 0x0C, /* Usage Page (Consumer) */ 0x0a, 0x26, 0x02, /* Usage (AC Stop) */ 0x81, 0x02, /* Input (Data, Var, Abs, No Wrap, Lin, Pref, No Nul) */ 0x95, 0x02, /* Report Count (2) */ From 49f1739098ee28f1ee0167d578f2ef5b6a4592b6 Mon Sep 17 00:00:00 2001 From: mbanth Date: Thu, 6 May 2021 17:16:24 +0100 Subject: [PATCH 02/12] Re-factor HID descriptors. --- lib_xua/src/hid/xua_hid_descriptor.h | 26 +++++++++ lib_xua/src/hid/xua_hid_descriptor_contents.h | 54 +++++++++++++++++++ lib_xua/src/hid/xua_hid_descriptors.h | 20 +++++++ .../xua_hid_endpoint_descriptor_contents.h | 43 +++++++++++++++ .../xua_hid_interface_descriptor_contents.h | 48 +++++++++++++++++ 5 files changed, 191 insertions(+) create mode 100644 lib_xua/src/hid/xua_hid_descriptor.h create mode 100644 lib_xua/src/hid/xua_hid_descriptor_contents.h create mode 100644 lib_xua/src/hid/xua_hid_descriptors.h create mode 100644 lib_xua/src/hid/xua_hid_endpoint_descriptor_contents.h create mode 100644 lib_xua/src/hid/xua_hid_interface_descriptor_contents.h diff --git a/lib_xua/src/hid/xua_hid_descriptor.h b/lib_xua/src/hid/xua_hid_descriptor.h new file mode 100644 index 00000000..4fed07a2 --- /dev/null +++ b/lib_xua/src/hid/xua_hid_descriptor.h @@ -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_ diff --git a/lib_xua/src/hid/xua_hid_descriptor_contents.h b/lib_xua/src/hid/xua_hid_descriptor_contents.h new file mode 100644 index 00000000..cda7ce12 --- /dev/null +++ b/lib_xua/src/hid/xua_hid_descriptor_contents.h @@ -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_ diff --git a/lib_xua/src/hid/xua_hid_descriptors.h b/lib_xua/src/hid/xua_hid_descriptors.h new file mode 100644 index 00000000..e06ab90b --- /dev/null +++ b/lib_xua/src/hid/xua_hid_descriptors.h @@ -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_ diff --git a/lib_xua/src/hid/xua_hid_endpoint_descriptor_contents.h b/lib_xua/src/hid/xua_hid_endpoint_descriptor_contents.h new file mode 100644 index 00000000..105e037e --- /dev/null +++ b/lib_xua/src/hid/xua_hid_endpoint_descriptor_contents.h @@ -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_ diff --git a/lib_xua/src/hid/xua_hid_interface_descriptor_contents.h b/lib_xua/src/hid/xua_hid_interface_descriptor_contents.h new file mode 100644 index 00000000..3d0d62a9 --- /dev/null +++ b/lib_xua/src/hid/xua_hid_interface_descriptor_contents.h @@ -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_ From d765ba1dfb30db49d534c39232c636dee9f72f06 Mon Sep 17 00:00:00 2001 From: mbanth Date: Fri, 7 May 2021 10:11:55 +0100 Subject: [PATCH 03/12] Re-factor HID descriptors --- .../src/core/endpoint0/xua_ep0_descriptors.h | 92 ++++--------------- 1 file changed, 17 insertions(+), 75 deletions(-) diff --git a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h index e5c1628c..7dbb0be2 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -16,6 +16,7 @@ #include "usbaudiocommon.h" #include "xud_device.h" #include "usbaudio20.h" /* Defines from USB Audio 2.0 spec */ +#include "xua_hid_descriptor.h" #ifdef IAP_EA_NATIVE_TRANS #include "iap2.h" /* Defines iAP EA Native Transport protocol name */ @@ -810,7 +811,7 @@ typedef struct #if( 0 < HID_CONTROLS ) USB_Descriptor_Interface_t HID_Interface; - unsigned char hidDesc[9]; //TODO ideally we would have a struct for this. + USB_HID_Descriptor_t HID_Descriptor; USB_Descriptor_Endpoint_t HID_In_Endpoint; #endif @@ -2206,60 +2207,24 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= #endif /* IAP */ #if( 0 < HID_CONTROLS ) - .HID_Interface = - { - 9, /* 0 bLength : Size of descriptor in Bytes */ - 4, /* 1 bDescriptorType (Interface: 0x04)*/ - INTERFACE_NUMBER_HID, /* 2 bInterfaceNumber : Number of interface */ - 0, /* 3 bAlternateSetting : Value used alternate interfaces using SetInterface Request */ - 1, /* 4: bNumEndpoints : Number of endpoitns for this interface (excluding 0) */ - 3, /* 5: bInterfaceClass */ - 0, /* 6: bInterfaceSubClass - no boot device */ - 0, /* 7: bInterfaceProtocol*/ - 0, /* 8 iInterface */ - }, - - { - 9, /* 0 bLength : Size of descriptor in Bytes */ - 0x21, /* 1 bDescriptorType (HID) */ - 0x10, /* 2 bcdHID */ - 0x01, /* 3 bcdHID */ - 0, /* 4 bCountryCode */ - 1, /* 5 bNumDescriptors */ - 0x22, /* 6 bDescriptorType[0] (Report) */ - sizeof(hidReportDescriptor) & 0xff,/* 7 wDescriptorLength[0] */ - sizeof(hidReportDescriptor) >> 8, /* 8 wDescriptorLength[0] */ - }, - - .HID_In_Endpoint = - { - /* Endpoint descriptor (IN) */ - 0x7, /* 0 bLength */ - 5, /* 1 bDescriptorType */ - ENDPOINT_ADDRESS_IN_HID, /* 2 bEndpointAddress */ - 3, /* 3 bmAttributes (INTERRUPT) */ - 64, /* 4 wMaxPacketSize */ - ENDPOINT_INT_INTERVAL_IN_HID, /* 6 bInterval */ - } + #include "xua_hid_descriptors.h" #endif }; #endif /* (AUDIO_CLASS == 2) */ #if( 0 < HID_CONTROLS ) +#if (AUDIO_CLASS ==1 ) unsigned char hidDescriptor[] = { - 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] */ + #include "xua_hid_descriptor_contents.h" }; +#elif (AUDIO_CLASS == 2) +unsigned char* hidDescriptor = (unsigned char*) &cfgDesc_Audio2.HID_Descriptor; +#else + #error "Unknown Audio Class" #endif +#endif // 0 < HID_CONTROLS /* Configuration Descriptor for Null device */ @@ -2364,6 +2329,12 @@ const unsigned num_freqs_a1 = MAX(3, (0 #endif #if( 0 < HID_CONTROLS ) +/* + * The value of HID_INTERFACE_BYTES must match the length of the descriptors defined in + * - xua_hid_descriptor_contents.h + * - xua_hid_endpoint_descriptor_contents.h and + * - xua_hid_interface_descriptor_contents.h + */ #define HID_INTERFACE_BYTES ( 9 + 9 + 7 ) #define HID_INTERFACES_A1 1 #else @@ -2908,36 +2879,7 @@ unsigned char cfgDesc_Audio1[] = #endif #if( 0 < HID_CONTROLS ) - /* 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 */ - - /* 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] */ - - /* 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 */ + #include "xua_hid_descriptors.h" #endif }; From cf5c486c62b009ac3a8f6b4e61577e9200ccdd9d Mon Sep 17 00:00:00 2001 From: mbanth Date: Fri, 7 May 2021 14:34:30 +0100 Subject: [PATCH 04/12] Remove #if from comment to allow easier verification that each #if has a corresponding #end --- lib_xua/src/core/endpoint0/xua_ep0_descriptors.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h index 7dbb0be2..fb835907 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -1942,7 +1942,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .wLockDelay = 0x0008, }, #endif /* (INPUT_FORMAT_COUNT > 2) */ -#endif /* #if(NUM_USB_CHAN_IN > 0) */ +#endif /* (NUM_USB_CHAN_IN > 0) */ #ifdef MIDI /* MIDI Descriptors */ From 7d7ec6858d146052c95efd7ac7d5b885440d0f49 Mon Sep 17 00:00:00 2001 From: mbanth Date: Fri, 7 May 2021 16:35:30 +0100 Subject: [PATCH 05/12] Remove unnecessary #include --- lib_xua/src/hid/xua_hid_descriptor_contents.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib_xua/src/hid/xua_hid_descriptor_contents.h b/lib_xua/src/hid/xua_hid_descriptor_contents.h index cda7ce12..283a6d6b 100644 --- a/lib_xua/src/hid/xua_hid_descriptor_contents.h +++ b/lib_xua/src/hid/xua_hid_descriptor_contents.h @@ -10,8 +10,6 @@ #ifndef _HID_DESCRIPTOR_CONTENTS_ #define _HID_DESCRIPTOR_CONTENTS_ -#include "descriptor_defs.h" - #if (AUDIO_CLASS == 1) /* HID descriptor */ From 35fe4fadeb3bf0404b8235ca22cb32276c9a27c2 Mon Sep 17 00:00:00 2001 From: mbanth Date: Fri, 7 May 2021 16:46:37 +0100 Subject: [PATCH 06/12] Remove header guards. Since these files only include initialisation lists, no guard is needed. For UAC1 operation, one file has to be included twice, so including a guard breaks the implementation. --- lib_xua/src/hid/xua_hid_descriptor_contents.h | 5 ----- lib_xua/src/hid/xua_hid_endpoint_descriptor_contents.h | 5 ----- lib_xua/src/hid/xua_hid_interface_descriptor_contents.h | 5 ----- 3 files changed, 15 deletions(-) diff --git a/lib_xua/src/hid/xua_hid_descriptor_contents.h b/lib_xua/src/hid/xua_hid_descriptor_contents.h index 283a6d6b..31933979 100644 --- a/lib_xua/src/hid/xua_hid_descriptor_contents.h +++ b/lib_xua/src/hid/xua_hid_descriptor_contents.h @@ -7,9 +7,6 @@ * This file lists the contents of the HID Endpoint descriptor returned during enumeration. */ -#ifndef _HID_DESCRIPTOR_CONTENTS_ -#define _HID_DESCRIPTOR_CONTENTS_ - #if (AUDIO_CLASS == 1) /* HID descriptor */ @@ -48,5 +45,3 @@ #else #error "Unknown Audio Class" #endif - -#endif // _HID_DESCRIPTOR_CONTENTS_ diff --git a/lib_xua/src/hid/xua_hid_endpoint_descriptor_contents.h b/lib_xua/src/hid/xua_hid_endpoint_descriptor_contents.h index 105e037e..3fcef71e 100644 --- a/lib_xua/src/hid/xua_hid_endpoint_descriptor_contents.h +++ b/lib_xua/src/hid/xua_hid_endpoint_descriptor_contents.h @@ -7,9 +7,6 @@ * 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) @@ -39,5 +36,3 @@ #else #error "Unknown Audio Class" #endif - -#endif // _HID_ENDPOINT_DESCRIPTOR_CONTENTS_ diff --git a/lib_xua/src/hid/xua_hid_interface_descriptor_contents.h b/lib_xua/src/hid/xua_hid_interface_descriptor_contents.h index 3d0d62a9..fd0c0235 100644 --- a/lib_xua/src/hid/xua_hid_interface_descriptor_contents.h +++ b/lib_xua/src/hid/xua_hid_interface_descriptor_contents.h @@ -7,9 +7,6 @@ * 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) @@ -44,5 +41,3 @@ #else #error "Unknown Audio Class" #endif - -#endif // _HID_INTERFACE_DESCRIPTOR_CONTENTS_ From c31f1521c22e25f0b252c0e235e6ae527b857d10 Mon Sep 17 00:00:00 2001 From: mbanth Date: Mon, 10 May 2021 10:29:13 +0100 Subject: [PATCH 07/12] Removed unnecessary #include --- lib_xua/src/core/endpoint0/xua_ep0_descriptors.h | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h index fb835907..14f570f0 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -15,7 +15,6 @@ #include "usbaudio20.h" /* Defines from the USB Audio 2.0 Specifications */ #include "usbaudiocommon.h" #include "xud_device.h" -#include "usbaudio20.h" /* Defines from USB Audio 2.0 spec */ #include "xua_hid_descriptor.h" #ifdef IAP_EA_NATIVE_TRANS From 6b9249507d74e1468ee21cb5ecb3ee299a5fdfe7 Mon Sep 17 00:00:00 2001 From: mbanth Date: Mon, 10 May 2021 12:26:38 +0100 Subject: [PATCH 08/12] Define descriptor values --- lib_xua/src/hid/xua_hid_descriptor_contents.h | 53 ++++++++++++------- .../xua_hid_endpoint_descriptor_contents.h | 33 ++++++++---- .../xua_hid_interface_descriptor_contents.h | 48 +++++++++++------ 3 files changed, 88 insertions(+), 46 deletions(-) diff --git a/lib_xua/src/hid/xua_hid_descriptor_contents.h b/lib_xua/src/hid/xua_hid_descriptor_contents.h index 31933979..d91e7b15 100644 --- a/lib_xua/src/hid/xua_hid_descriptor_contents.h +++ b/lib_xua/src/hid/xua_hid_descriptor_contents.h @@ -7,38 +7,55 @@ * This file lists the contents of the HID Endpoint descriptor returned during enumeration. */ +#ifndef _HID_DESCRIPTOR_CONTENTS_ +#define _HID_DESCRIPTOR_CONTENTS_ + +#include "xua_hid_descriptor.h" + +#define HID_DESCRIPTOR_LENGTH_0 0x09 /* Size of descriptor in Bytes */ +#define HID_DESCRIPTOR_TYPE_0 0x21 /* HID 0x21 */ +#define HID_BCD_VERSION_LO 0x10 /* HID class specification release */ +#define HID_BCD_VERSION_HI 0x01 +#define HID_COUNTRY_CODE 0x00 /* Country code of localized hardware */ +#define HID_NUM_DESCRIPTORS 0x01 /* Number of class descriptors */ +#define HID_DESCRIPTOR_TYPE_1 0x22 /* Type of 1st class descriptor, Report 0x22 */ +#define HID_DESCRIPTOR_LENGTH_1_LO sizeof(hidReportDescriptor) & 0xff +#define HID_DESCRIPTOR_LENGTH_1_HI sizeof(hidReportDescriptor) >> 8 + +#endif // _HID_DESCRIPTOR_CONTENTS_ + #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] */ + HID_DESCRIPTOR_LENGTH_0, /* 0 bLength */ + HID_DESCRIPTOR_TYPE_0, /* 1 bDescriptorType (HID) */ + HID_BCD_VERSION_LO, /* 2 bcdHID */ + HID_BCD_VERSION_HI, /* 3 bcdHID */ + HID_COUNTRY_CODE, /* 4 bCountryCode */ + HID_NUM_DESCRIPTORS, /* 5 bNumDescriptors */ + HID_DESCRIPTOR_TYPE_1, /* 6 bDescriptorType[0] */ + HID_DESCRIPTOR_LENGTH_1_LO, /* 7 wDescriptorLength[0] */ + HID_DESCRIPTOR_LENGTH_1_HI, /* 8 wDescriptorLength[0] */ #elif (AUDIO_CLASS == 2) .HID_Descriptor = { /* HID descriptor */ - .bLength = 0x09, - .bDescriptorType0 = 0x21, + .bLength = sizeof(USB_HID_Descriptor_t), + .bDescriptorType0 = HID_DESCRIPTOR_TYPE_0, .bcdHID = { - 0x10, - 0x01, + HID_BCD_VERSION_LO, + HID_BCD_VERSION_HI, }, - .bCountryCode = 0x00, - .bNumDescriptors = 0x01, - .bDescriptorType1 = 0x22, + .bCountryCode = HID_COUNTRY_CODE, + .bNumDescriptors = HID_NUM_DESCRIPTORS, + .bDescriptorType1 = HID_DESCRIPTOR_TYPE_1, .wDescriptorLength1 = { - sizeof(hidReportDescriptor) & 0xff, - sizeof(hidReportDescriptor) >> 8, + HID_DESCRIPTOR_LENGTH_1_LO, + HID_DESCRIPTOR_LENGTH_1_HI, }, }, diff --git a/lib_xua/src/hid/xua_hid_endpoint_descriptor_contents.h b/lib_xua/src/hid/xua_hid_endpoint_descriptor_contents.h index 3fcef71e..bba85c72 100644 --- a/lib_xua/src/hid/xua_hid_endpoint_descriptor_contents.h +++ b/lib_xua/src/hid/xua_hid_endpoint_descriptor_contents.h @@ -7,29 +7,40 @@ * 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" +#define HID_ENDPOINT_DESCRIPTOR_LENGTH 0x07 /* Size of descriptor in Bytes */ +#define HID_ENDPOINT_DESCRIPTOR_TYPE 0x05 /* Endpoint 0x05 */ +#define HID_ENDPOINT_ATTRIBUTES 0x03 /* Interrupt */ +#define HID_ENDPOINT_DESCRIPTOR_PACKET_SIZE_LO 0x40 +#define HID_ENDPOINT_DESCRIPTOR_PACKET_SIZE_HI 0x00 + +#endif // _HID_ENDPOINT_DESCRIPTOR_CONTENTS_ + #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 */ + HID_ENDPOINT_DESCRIPTOR_LENGTH, /* 0 bLength */ + HID_ENDPOINT_DESCRIPTOR_TYPE, /* 1 bDescriptorType */ + ENDPOINT_ADDRESS_IN_HID, /* 2 bEndpointAddress */ + HID_ENDPOINT_ATTRIBUTES, /* 3 bmAttributes (INTERRUPT) */ + HID_ENDPOINT_DESCRIPTOR_PACKET_SIZE_LO, /* 4 wMaxPacketSize */ + HID_ENDPOINT_DESCRIPTOR_PACKET_SIZE_HI, /* 5 wMaxPacketSize */ + ENDPOINT_INT_INTERVAL_IN_HID, /* 6 bInterval */ #elif (AUDIO_CLASS == 2) .HID_In_Endpoint = { /* Endpoint descriptor (IN) */ - .bLength = 0x7, - .bDescriptorType = 5, + .bLength = sizeof(USB_Descriptor_Endpoint_t), + .bDescriptorType = HID_ENDPOINT_DESCRIPTOR_TYPE, .bEndpointAddress = ENDPOINT_ADDRESS_IN_HID, - .bmAttributes = 3, - .wMaxPacketSize = 64, + .bmAttributes = HID_ENDPOINT_ATTRIBUTES, + .wMaxPacketSize = HID_ENDPOINT_DESCRIPTOR_PACKET_SIZE_LO, .bInterval = ENDPOINT_INT_INTERVAL_IN_HID, }, diff --git a/lib_xua/src/hid/xua_hid_interface_descriptor_contents.h b/lib_xua/src/hid/xua_hid_interface_descriptor_contents.h index fd0c0235..20df1815 100644 --- a/lib_xua/src/hid/xua_hid_interface_descriptor_contents.h +++ b/lib_xua/src/hid/xua_hid_interface_descriptor_contents.h @@ -7,35 +7,49 @@ * 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" +#define HID_INTERFACE_DESCRIPTOR_LENGTH 0x09 /* Size of descriptor in Bytes */ +#define HID_INTERFACE_DESCRIPTOR_TYPE 0x04 /* Interface 0x04 */ +#define HID_INTERFACE_ALTERNATE_SETTING 0x00 /* Value used alternate interfaces using SetInterface Request */ +#define HID_INTERFACE_NUMBER_OF_ENDPOINTS 0x01 /* Number of endpoitns for this interface (excluding 0) */ +#define HID_INTERFACE_CLASS 0x03 +#define HID_INTERFACE_SUBCLASS 0x00 /* No boot device */ +#define HID_INTERFACE_PROTOCOL 0x00 +#define HID_INTERFACE_STRING_DESCRIPTOR_INDEX 0x00 + +#endif // _HID_INTERFACE_DESCRIPTOR_CONTENTS_ + #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 */ + HID_INTERFACE_DESCRIPTOR_LENGTH, /* 0 bLength */ + HID_INTERFACE_DESCRIPTOR_TYPE, /* 1 bDescriptorType */ + INTERFACE_NUMBER_HID, /* 2 bInterfaceNumber : Number of interface */ + HID_INTERFACE_ALTERNATE_SETTING, /* 3 bAlternateSetting */ + HID_INTERFACE_NUMBER_OF_ENDPOINTS, /* 4: bNumEndpoints */ + HID_INTERFACE_CLASS, /* 5: bInterfaceClass */ + HID_INTERFACE_SUBCLASS, /* 6: bInterfaceSubClass */ + HID_INTERFACE_PROTOCOL, /* 7: bInterfaceProtocol*/ + HID_INTERFACE_STRING_DESCRIPTOR_INDEX, /* 8 iInterface */ #elif (AUDIO_CLASS == 2) .HID_Interface = { /* HID interface descriptor */ - .bLength = 0x09, - .bDescriptorType = 0x04, + .bLength = sizeof(USB_Descriptor_Interface_t), + .bDescriptorType = HID_INTERFACE_DESCRIPTOR_TYPE, .bInterfaceNumber = INTERFACE_NUMBER_HID, - .bAlternateSetting = 0x00, /* alternate interfaces using SetInterface Request */ - .bNumEndpoints = 0x01, - .bInterfaceClass = 0x03, - .bInterfaceSubClass = 0x00, /* no boot device */ - .bInterfaceProtocol = 0x00, - .iInterface = 0x00, + .bAlternateSetting = HID_INTERFACE_ALTERNATE_SETTING, + .bNumEndpoints = HID_INTERFACE_NUMBER_OF_ENDPOINTS, + .bInterfaceClass = HID_INTERFACE_CLASS, + .bInterfaceSubClass = HID_INTERFACE_SUBCLASS, + .bInterfaceProtocol = HID_INTERFACE_PROTOCOL, + .iInterface = HID_INTERFACE_STRING_DESCRIPTOR_INDEX, }, #else From 8a869ce230591fbcfbf7958ac3514616e91fe6c4 Mon Sep 17 00:00:00 2001 From: mbanth Date: Mon, 10 May 2021 18:11:17 +0100 Subject: [PATCH 09/12] Update change log --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a0fed19f..3bff9ac7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,7 @@ lib_xua Change Log * FIXED: Runtime error when using mic array interface * CHANGED: Use XMOS Public Licence Version 1 * FIXED: Automate HID Report Descriptor length in AC1 HID Descriptor + * CHANGED: Move HID descriptors to ease maintenance 1.1.1 ----- From 703ba4975a46f0aaf7ae60745db422b59d98da16 Mon Sep 17 00:00:00 2001 From: mbanth Date: Thu, 13 May 2021 15:12:20 +0100 Subject: [PATCH 10/12] Manually revert Wake Word HID event from 't' back to AC Search --- lib_xua/src/core/endpoint0/xua_ep0_descriptors.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h index 14f570f0..47991bf9 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -593,11 +593,9 @@ unsigned char hidReportDescriptor[] = 0x81, 0x01, /* Input (Cnst, Ary, Abs, No Wrap, Lin, Pref, No Nul) */ 0x95, 0x01, /* Report Count (1) */ 0x25, 0x01, /* Logical Maximum (1) */ - 0x05, 0x07, /* Usage Page (Key Codes) */ - 0x19, 0x17, /* Usage Minimum (Keyboard t or T) */ - 0x29, 0x17, /* Usage Maximum (Keyboard t or T) */ - 0x81, 0x02, /* Input (Data, Var, Abs, No Wrap, Lin, Pref, No Nul) */ 0x05, 0x0C, /* Usage Page (Consumer) */ + 0x0a, 0x21, 0x02, /* Usage (AC Search) */ + 0x81, 0x02, /* Input (Data, Var, Abs, No Wrap, Lin, Pref, No Nul) */ 0x0a, 0x26, 0x02, /* Usage (AC Stop) */ 0x81, 0x02, /* Input (Data, Var, Abs, No Wrap, Lin, Pref, No Nul) */ 0x95, 0x02, /* Report Count (2) */ From 4b6a3697ac3d761f480cbd4de4214b2e47962f58 Mon Sep 17 00:00:00 2001 From: mbanth Date: Thu, 13 May 2021 16:16:52 +0100 Subject: [PATCH 11/12] Move change log entry to a new version --- CHANGELOG.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3bff9ac7..a5db13c9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ lib_xua Change Log ================== +1.3.0 +----- + + * CHANGED: Move HID descriptors to ease maintenance + 1.2.0 ----- From 89fe6c4d5de6f94a51f1b758772d3754d76384ee Mon Sep 17 00:00:00 2001 From: mbanth Date: Thu, 13 May 2021 16:18:02 +0100 Subject: [PATCH 12/12] Increase version number --- lib_xua/module_build_info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_xua/module_build_info b/lib_xua/module_build_info index 67df655e..39315c72 100644 --- a/lib_xua/module_build_info +++ b/lib_xua/module_build_info @@ -1,4 +1,4 @@ -VERSION = 1.2.0 +VERSION = 1.3.0 DEPENDENT_MODULES = lib_logging(>=3.0.0) \ lib_xassert(>=4.0.0) \