From 8ff44c553c82de73cad845f61c8752adfe702601 Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Mon, 23 Sep 2019 15:36:35 +0100 Subject: [PATCH 01/13] Add the specific directory that contains user_hid.h. Apparently xwaf doesn't recursively descend directory trees the way xmake does. --- 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 2a36dedf..f13abe6b 100644 --- a/lib_xua/module_build_info +++ b/lib_xua/module_build_info @@ -17,7 +17,7 @@ VERSION = 0.2.0 DEPENDENT_MODULES = lib_logging(>=2.1.0) lib_xassert(>=2.0.0) lib_xud(>=0.1.0) lib_spdif(>=3.0.0) -INCLUDE_DIRS = api src/* +INCLUDE_DIRS = api src/* src/core/user #ignore host dir SOURCE_DIRS = src/* From bb5757e099b9a71ab54ff0a8c815f1d8914e33ec Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Mon, 23 Sep 2019 17:29:39 +0100 Subject: [PATCH 02/13] Initial implementation of HID. --- lib_xua/src/core/buffer/ep/ep_buffer.xc | 2 +- lib_xua/src/core/user/user_hid.h | 4 +++- lib_xua/src/core/user/user_hid.xc | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 lib_xua/src/core/user/user_hid.xc diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index e510d37a..b9c01d6b 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -880,7 +880,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, case XUD_SetData_Select(c_hid, ep_hid, result): { g_hidData[0]=0; - UserReadHIDButtons(g_hidData); + UserReadHIDData(g_hidData); XUD_SetReady_In(ep_hid, g_hidData, 1); } break; diff --git a/lib_xua/src/core/user/user_hid.h b/lib_xua/src/core/user/user_hid.h index b2530d0f..6620c7dd 100644 --- a/lib_xua/src/core/user/user_hid.h +++ b/lib_xua/src/core/user/user_hid.h @@ -9,5 +9,7 @@ #define HID_CONTROL_VOLDN_SHIFT 0x04 #define HID_CONTROL_MUTE_SHIFT 0x05 -void UserReadHIDButtons(unsigned char hidData[]); +#define HID_DATA_SIZE 1 + +void UserReadHIDData(unsigned char hidData[HID_DATA_SIZE]); diff --git a/lib_xua/src/core/user/user_hid.xc b/lib_xua/src/core/user/user_hid.xc new file mode 100644 index 00000000..61466360 --- /dev/null +++ b/lib_xua/src/core/user/user_hid.xc @@ -0,0 +1,12 @@ +// Copyright (c) 2019, XMOS Ltd, All rights reserved +#include +#include +#include +#include "user_hid.h" + +void UserReadHIDData( unsigned char hidData[ HID_DATA_SIZE ]) +{ + for( unsigned idx = 0; idx < HID_DATA_SIZE; ++idx ) { + hidData[ idx ] = 1; + } +} \ No newline at end of file From 017d937ec7e74ae618d8d8540e7bce09d284ffa7 Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Wed, 25 Sep 2019 11:39:48 +0100 Subject: [PATCH 03/13] Add comments to match #endif directives to their corresponding #if or #ifdef directive. Added to aid reading. --- .../src/core/endpoint0/xua_ep0_descriptors.h | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h index b3129ac0..ea34ac2b 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -1084,7 +1084,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= }, 0, /* 60 iFeature */ }, -#endif +#endif /* (OUTPUT_VOLUME_CONTROL == 1) */ /* Output Terminal Descriptor (Audio) */ .Audio_Out_OutputTerminal = @@ -1104,7 +1104,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= 0x0000, /* 9 bmControls */ 0, /* 11 iTerminal */ }, -#endif +#endif /* (NUM_USB_CHAN_OUT > 0) */ @@ -1259,7 +1259,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= }, 0, /* 60 iFeature */ }, -#endif +#endif /* (INPUT_VOLUME_CONTROL == 1) */ .Audio_In_OutputTerminal = { @@ -1280,7 +1280,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bmControls = 0x0000, .iTerminal = offsetof(StringDescTable_t, usbOutputTermStr_Audio2)/sizeof(char *) }, -#endif +#endif /* (NUM_USB_CHAN_IN > 0) */ #if defined(MIXER) && (MAX_MIX_COUNT > 0) /* Extension Unit Descriptor (4.7.2.12) */ @@ -1374,7 +1374,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= 0x00, /* bmControls */ 0 /* Mixer unit string descriptor index */ }, -#endif +#endif /* defined(MIXER) && (MAX_MIX_COUNT > 0) */ #if (SPDIF_RX) || (ADAT_RX) /* Standard AS Interrupt Endpoint Descriptor (4.8.2.1): */ @@ -1571,7 +1571,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= 4, /* 6 bInterval. Only values <= 1 frame (4) supported by MS */ }, #endif -#endif +#endif /* OUTPUT_FORMAT_COUNT > 1 */ #if (OUTPUT_FORMAT_COUNT > 2) /* Standard AS Interface Descriptor (4.9.1) (Alt) */ .Audio_Out_StreamInterface_Alt3 = @@ -1815,7 +1815,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bLockDelayUnits = 0x02, .wLockDelay = 0x0008, }, -#endif +#endif /* (INPUT_FORMAT_COUNT > 1) */ #if (INPUT_FORMAT_COUNT > 2) /* Alternative 3 */ /* Standard AS Interface Descriptor (4.9.1) (Alt) */ @@ -1888,7 +1888,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .bLockDelayUnits = 0x02, .wLockDelay = 0x0008, }, -#endif +#endif /* (INPUT_FORMAT_COUNT > 2) */ #endif /* #if(NUM_USB_CHAN_IN > 0) */ #ifdef MIDI @@ -2044,7 +2044,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= 0x10, /* 7 bcdDFUVersion */ 0x01}, /* 7 bcdDFUVersion */ #endif -#endif +#endif /* (XUA_DFU_EN == 1) */ #ifdef IAP /* Interface descriptor */ @@ -2192,7 +2192,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= #endif }; -#endif +#endif /* (AUDIO_CLASS == 2) */ #ifdef HID_CONTROLS unsigned char hidDescriptor[] = From 75422de6d18a126af5fe52fc66457f676f0e16f6 Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Wed, 25 Sep 2019 11:42:59 +0100 Subject: [PATCH 04/13] Replace existing #ifdef HID_CONTROLS with #if( 0 < HID_CONTROLS ) to move to best practice regarding compile-time switches. --- lib_xua/src/core/endpoint0/xua_ep0_descriptors.h | 8 ++++---- 1 file changed, 4 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 ea34ac2b..0f762d61 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -547,7 +547,7 @@ unsigned char devQualDesc_Null[] = #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) unsigned char hidReportDescriptor[] = { 0x05, 0x0c, /* Usage Page (Consumer Device) */ @@ -769,7 +769,7 @@ typedef struct #endif #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) USB_Descriptor_Interface_t HID_Interface; unsigned char hidDesc[9]; //TODO ideally we would have a struct for this. USB_Descriptor_Endpoint_t HID_In_Endpoint; @@ -2153,7 +2153,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= #endif #endif /* IAP */ -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) .HID_Interface = { 9, /* 0 bLength : Size of descriptor in Bytes */ @@ -2194,7 +2194,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= }; #endif /* (AUDIO_CLASS == 2) */ -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) unsigned char hidDescriptor[] = { 9, /* 0 bLength : Size of descriptor in Bytes */ From 35393d37395bd6d49c3f54236e2dfd81f7b256f5 Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Wed, 25 Sep 2019 11:44:43 +0100 Subject: [PATCH 05/13] Remove duplicate definitions. --- lib_xua/src/core/endpoint0/xua_ep0_descriptors.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h index 0f762d61..d6eac320 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -2309,18 +2309,6 @@ const unsigned num_freqs_a1 = MAX(3, (0 #define DFU_INTERFACES_A1 0 #endif -/* Total number of bytes returned for the class-specific AudioControl interface descriptor. - * Includes the combined length of this descriptor header and all Unit and Terminal descriptors - * For us this is IT -> FU -> OT * 2 and a header */ -#define AC_TOTAL_LENGTH (AC_LENGTH + \ - (INPUT_INTERFACES_A1 * (12 + ( (8 + NUM_USB_CHAN_IN_FS) * INPUT_VOLUME_CONTROL) + 9)) +\ - (OUTPUT_INTERFACES_A1 * (12 + ( (8 + NUM_USB_CHAN_OUT_FS) * OUTPUT_VOLUME_CONTROL) + 9))) - -#define STREAMING_INTERFACES (INPUT_INTERFACES_A1 + OUTPUT_INTERFACES_A1) - -//#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) -//#define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (58 + num_freqs_a1 * 3)) + CONTROL_INTERFACE_BYTES + DFU_INTERFACE_BYTES) -//#endif /* Total number of bytes returned for the class-specific AudioControl interface descriptor. * Includes the combined length of this descriptor header and all Unit and Terminal descriptors From 958d52b5eb0e0a35eee4f998bf9b3b537c62b8cf Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Wed, 25 Sep 2019 11:45:40 +0100 Subject: [PATCH 06/13] Consistently use hex when defining descriptor values. --- lib_xua/src/core/endpoint0/xua_ep0_descriptors.h | 6 +++--- 1 file changed, 3 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 d6eac320..3cc81862 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -2197,12 +2197,12 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= #if( 0 < HID_CONTROLS ) unsigned char hidDescriptor[] = { - 9, /* 0 bLength : Size of descriptor in Bytes */ + 0x09, /* 0 bLength : Size of descriptor in Bytes */ 0x21, /* 1 bDescriptorType (HID) */ 0x10, /* 2 bcdHID */ 0x01, /* 3 bcdHID */ - 0, /* 4 bCountryCode */ - 1, /* 5 bNumDescriptors */ + 0x00, /* 4 bCountryCode */ + 0x01, /* 5 bNumDescriptors */ 0x22, /* 6 bDescriptorType[0] (Report) */ sizeof(hidReportDescriptor) & 0xff, /* 7 wDescriptorLength[0] */ sizeof(hidReportDescriptor) >> 8, /* 8 wDescriptorLength[0] */ From 3131b89a1d9691eb175f3cb51e564ffca5a150dd Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Wed, 25 Sep 2019 11:46:16 +0100 Subject: [PATCH 07/13] Add HID descriptors for UAC1. --- .../src/core/endpoint0/xua_ep0_descriptors.h | 45 +++++++++++++++++-- 1 file changed, 42 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 3cc81862..61ba05d7 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -2309,6 +2309,13 @@ const unsigned num_freqs_a1 = MAX(3, (0 #define DFU_INTERFACES_A1 0 #endif +#if( 0 < HID_CONTROLS ) +#define HID_INTERFACE_BYTES ( 9 + 9 + 7 ) +#define HID_INTERFACES_A1 1 +#else +#define HID_INTERFACE_BYTES 0 +#define HID_INTERFACES_A1 0 +#endif /* Total number of bytes returned for the class-specific AudioControl interface descriptor. * Includes the combined length of this descriptor header and all Unit and Terminal descriptors @@ -2321,12 +2328,12 @@ const unsigned num_freqs_a1 = MAX(3, (0 /* Number of interfaces for Audio 1.0 (+1 for control ) */ /* Note, this is different that INTERFACE_COUNT since we dont support items such as MIDI, iAP etc in UAC1 mode */ -#define NUM_INTERFACES_A1 (1+INPUT_INTERFACES_A1 + OUTPUT_INTERFACES_A1+NUM_CONTROL_USB_INTERFACES+DFU_INTERFACES_A1) +#define NUM_INTERFACES_A1 (1 + INPUT_INTERFACES_A1 + OUTPUT_INTERFACES_A1 + NUM_CONTROL_USB_INTERFACES + DFU_INTERFACES_A1 + HID_INTERFACES_A1) #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) -#define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (58 + num_freqs_a1 * 3)) + CONTROL_INTERFACE_BYTES + DFU_INTERFACE_BYTES) +#define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (58 + num_freqs_a1 * 3)) + CONTROL_INTERFACE_BYTES + DFU_INTERFACE_BYTES + HID_INTERFACE_BYTES) #else -#define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + CONTROL_INTERFACE_BYTES + DFU_INTERFACE_BYTES) +#define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + CONTROL_INTERFACE_BYTES + DFU_INTERFACE_BYTES + HID_INTERFACE_BYTES) #endif #define CHARIFY_SR(x) (x & 0xff),((x & 0xff00)>> 8),((x & 0xff0000)>> 16) @@ -2828,6 +2835,38 @@ unsigned char cfgDesc_Audio1[] = offsetof(StringDescTable_t, ctrlStr)/sizeof(char *), /* 8 iInterface */ #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) */ + 0x21, /* 7 wDescriptorLength[0] */ + 0x00, /* 8 wDescriptorLength[0] */ + + /* HID Endpoint descriptor (IN) */ + 0x07, /* 0 bLength */ + 0x05, /* 1 bDescriptorType */ + ENDPOINT_ADDRESS_IN_HID, /* 2 bEndpointAddress */ + 0x03, /* 3 bmAttributes (INTERRUPT) */ + 64, /* 4 wMaxPacketSize */ + 0x08, /* 6 bInterval */ +#endif + }; #endif #endif From 960333ca091b7bd8fa20c82c83c1a700477d8fce Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Wed, 25 Sep 2019 14:38:17 +0100 Subject: [PATCH 08/13] Add the missing MSB of the maximum packet size and use hex values instead of decimal. --- lib_xua/src/core/endpoint0/xua_ep0_descriptors.h | 3 ++- 1 file changed, 2 insertions(+), 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 61ba05d7..ae7ef76a 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -2863,7 +2863,8 @@ unsigned char cfgDesc_Audio1[] = 0x05, /* 1 bDescriptorType */ ENDPOINT_ADDRESS_IN_HID, /* 2 bEndpointAddress */ 0x03, /* 3 bmAttributes (INTERRUPT) */ - 64, /* 4 wMaxPacketSize */ + 0x40, /* 4 wMaxPacketSize */ + 0x00, /* 5 wMaxPacketSize */ 0x08, /* 6 bInterval */ #endif From d491eb2da91efd9b8b4beafdb218eb4e5e10dac1 Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Wed, 25 Sep 2019 16:12:59 +0100 Subject: [PATCH 09/13] Change HID Report descriptor to contain one variable bit in the lsb position. This bit reports the interrupt. The remaining seven bits are constant at zero. --- lib_xua/src/core/endpoint0/xua_ep0_descriptors.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h index ae7ef76a..bd95078e 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -556,15 +556,10 @@ unsigned char hidReportDescriptor[] = 0x15, 0x00, /* Logical Minimum (0) */ 0x25, 0x01, /* Logical Maximum (1) */ 0x09, 0xb0, /* Usage (Play) */ - 0x09, 0xb5, /* Usage (Scan Next Track) */ - 0x09, 0xb6, /* Usage (Scan Previous Track) */ - 0x09, 0xe9, /* Usage (Volume Up) */ - 0x09, 0xea, /* Usage (Volume Down) */ - 0x09, 0xe2, /* Usage (Mute) */ 0x75, 0x01, /* Report Size (1) */ - 0x95, 0x06, /* Report Count (6) */ + 0x95, 0x01, /* Report Count (1) */ 0x81, 0x02, /* Input (Data, Var, Abs) */ - 0x95, 0x02, /* Report Count (2) */ + 0x95, 0x07, /* Report Count (7) */ 0x81, 0x01, /* Input (Cnst, Ary, Abs) */ 0xc0 /* End collection */ }; @@ -2855,7 +2850,7 @@ unsigned char cfgDesc_Audio1[] = 0x00, /* 4 bCountryCode */ 0x01, /* 5 bNumDescriptors */ 0x22, /* 6 bDescriptorType[0] (Report) */ - 0x21, /* 7 wDescriptorLength[0] */ + 0x17, /* 7 wDescriptorLength[0] */ 0x00, /* 8 wDescriptorLength[0] */ /* HID Endpoint descriptor (IN) */ From 3c86da7c092c5c0c1a2a3fe16682c9fd3ca9b332 Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Wed, 25 Sep 2019 16:13:46 +0100 Subject: [PATCH 10/13] Add demo HID code that simulates an interrupt roughly every 10 seconds. --- lib_xua/src/core/user/user_hid.xc | 35 ++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/lib_xua/src/core/user/user_hid.xc b/lib_xua/src/core/user/user_hid.xc index 61466360..d27d6914 100644 --- a/lib_xua/src/core/user/user_hid.xc +++ b/lib_xua/src/core/user/user_hid.xc @@ -4,9 +4,38 @@ #include #include "user_hid.h" +#define HID_INTERRUPT_COUNT 1000000000 +#define HID_REPORT_DATA 0x01 + +static unsigned char initialised = 0; + +static unsigned int curr_time = 0; +static unsigned int last_time = 0; +static unsigned int tick_count = 0; + void UserReadHIDData( unsigned char hidData[ HID_DATA_SIZE ]) { - for( unsigned idx = 0; idx < HID_DATA_SIZE; ++idx ) { - hidData[ idx ] = 1; + timer tmr; + + if( !initialised ) { + tmr :> last_time; + initialised = 1; + } else { + tmr :> curr_time; + tick_count += ( last_time < curr_time ) ? curr_time - last_time : curr_time + ( UINT_MAX - last_time ); + + if( HID_INTERRUPT_COUNT <= tick_count ) { + for( unsigned idx = 0; idx < HID_DATA_SIZE; ++idx ) { + hidData[ idx ] = HID_REPORT_DATA; + } + + tick_count = 0; + } else { + for( unsigned idx = 0; idx < HID_DATA_SIZE; ++idx ) { + hidData[ idx ] = 0x00; + } + } + + last_time = curr_time; } -} \ No newline at end of file +} From 9472bd7dcef7db405ebf02a3cfa87e180054b9fe Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Thu, 26 Sep 2019 14:22:17 +0100 Subject: [PATCH 11/13] Change HID usage from Play On-Off Control (OOC) to Voice Command One-Shot Control (OSC). OSC requires relative data. --- lib_xua/src/core/endpoint0/xua_ep0_descriptors.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h index bd95078e..e6c56aa9 100644 --- a/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h +++ b/lib_xua/src/core/endpoint0/xua_ep0_descriptors.h @@ -555,10 +555,10 @@ unsigned char hidReportDescriptor[] = 0xa1, 0x01, /* Collection (Application) */ 0x15, 0x00, /* Logical Minimum (0) */ 0x25, 0x01, /* Logical Maximum (1) */ - 0x09, 0xb0, /* Usage (Play) */ + 0x09, 0xcf, /* Usage (Voice Command), use 0xcd for (Play/Pause OSC) */ 0x75, 0x01, /* Report Size (1) */ 0x95, 0x01, /* Report Count (1) */ - 0x81, 0x02, /* Input (Data, Var, Abs) */ + 0x81, 0x06, /* Input (Data, Var, Rel) */ 0x95, 0x07, /* Report Count (7) */ 0x81, 0x01, /* Input (Cnst, Ary, Abs) */ 0xc0 /* End collection */ From ba666fb314e96c8655688ca6925fbdf6f30597c7 Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Thu, 26 Sep 2019 14:27:20 +0100 Subject: [PATCH 12/13] Add a 100 ms assertion period when this demonstration code signals an NDP100 interrupt. When testing with the Play/Pause Usage (0xCD) with a Mac as USB Host, adding in this assertion period produced reliable playing and pausing of the iTunes app every 10 seconds. Without an explicit assertion period, i.e. sending only one report with the lsb set to 1b followed by many reports with the lsb set to 0b, the iTunes app behaved as though it did not see many of the Play/Pause signals. The inclusion of an assertion period may or may not help when reporting Voice Command events on Andriod. --- lib_xua/src/core/user/user_hid.xc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib_xua/src/core/user/user_hid.xc b/lib_xua/src/core/user/user_hid.xc index d27d6914..4319bf43 100644 --- a/lib_xua/src/core/user/user_hid.xc +++ b/lib_xua/src/core/user/user_hid.xc @@ -4,6 +4,7 @@ #include #include "user_hid.h" +#define HID_DEASSERT_COUNT 10000000 #define HID_INTERRUPT_COUNT 1000000000 #define HID_REPORT_DATA 0x01 @@ -24,16 +25,18 @@ void UserReadHIDData( unsigned char hidData[ HID_DATA_SIZE ]) tmr :> curr_time; tick_count += ( last_time < curr_time ) ? curr_time - last_time : curr_time + ( UINT_MAX - last_time ); - if( HID_INTERRUPT_COUNT <= tick_count ) { + if(( HID_INTERRUPT_COUNT <= tick_count ) && ( tick_count <= ( HID_INTERRUPT_COUNT + HID_DEASSERT_COUNT ))) { for( unsigned idx = 0; idx < HID_DATA_SIZE; ++idx ) { hidData[ idx ] = HID_REPORT_DATA; } - - tick_count = 0; } else { for( unsigned idx = 0; idx < HID_DATA_SIZE; ++idx ) { hidData[ idx ] = 0x00; - } + } + + if (( HID_INTERRUPT_COUNT + HID_DEASSERT_COUNT ) <= tick_count ) { + tick_count = 0; + } } last_time = curr_time; From 37bbea3726e4bebc2a0ebdb9ef5cd269593cbf9b Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Thu, 26 Sep 2019 14:45:17 +0100 Subject: [PATCH 13/13] Use a consistent method to interpret the HID_CONTROLS pre-processor symbol throughout the code base. --- lib_xua/api/xua_buffer.h | 4 ++-- lib_xua/api/xua_conf_default.h | 6 +----- lib_xua/src/core/buffer/decouple/decouple.xc | 2 +- lib_xua/src/core/buffer/ep/ep_buffer.xc | 14 +++++++------- lib_xua/src/core/endpoint0/descriptor_defs.h | 2 +- lib_xua/src/core/endpoint0/xua_endpoint0.c | 6 +++--- lib_xua/src/core/main.xc | 4 ++-- 7 files changed, 17 insertions(+), 21 deletions(-) diff --git a/lib_xua/api/xua_buffer.h b/lib_xua/api/xua_buffer.h index eaaef881..93ca3219 100644 --- a/lib_xua/api/xua_buffer.h +++ b/lib_xua/api/xua_buffer.h @@ -58,7 +58,7 @@ void XUA_Buffer( chanend c_sof, chanend c_aud_ctl, in port p_off_mclk -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) , chanend c_hid #endif , chanend c_aud @@ -97,7 +97,7 @@ void XUA_Buffer_Ep(chanend c_aud_out, chanend c_sof, chanend c_aud_ctl, in port p_off_mclk -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) , chanend c_hid #endif #ifdef CHAN_BUFF_CTRL diff --git a/lib_xua/api/xua_conf_default.h b/lib_xua/api/xua_conf_default.h index 677fad9e..5e311e9f 100644 --- a/lib_xua/api/xua_conf_default.h +++ b/lib_xua/api/xua_conf_default.h @@ -425,10 +425,6 @@ #define HID_CONTROLS (0) #endif -#if defined(HID_CONTROLS) && (HID_CONTROLS == 0) -#undef HID_CONTROLS -#endif - /* @brief Defines whether XMOS device runs as master (i.e. drives LR and Bit clocks) * * 0: XMOS is I2S master. 1: CODEC is I2s master. @@ -1177,7 +1173,7 @@ enum USBEndpointNumber_In #ifdef MIDI ENDPOINT_NUMBER_IN_MIDI, #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) ENDPOINT_NUMBER_IN_HID, #endif #ifdef IAP diff --git a/lib_xua/src/core/buffer/decouple/decouple.xc b/lib_xua/src/core/buffer/decouple/decouple.xc index e503ab71..8e291aef 100644 --- a/lib_xua/src/core/buffer/decouple/decouple.xc +++ b/lib_xua/src/core/buffer/decouple/decouple.xc @@ -12,7 +12,7 @@ #include "usbaudio20.h" /* Defines from the USB Audio 2.0 Specifications */ #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) #include "user_hid.h" #endif #define MAX(x,y) ((x)>(y) ? (x) : (y)) diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index b9c01d6b..5916da17 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -19,7 +19,7 @@ #include "xud.h" #include "testct_byref.h" -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) #include "user_hid.h" unsigned char g_hidData[1] = {0}; #endif @@ -120,7 +120,7 @@ void XUA_Buffer( chanend c_sof, chanend c_aud_ctl, in port p_off_mclk -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) , chanend c_hid #endif , chanend c_aud @@ -164,7 +164,7 @@ void XUA_Buffer( c_clk_int, #endif c_sof, c_aud_ctl, p_off_mclk -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) , c_hid #endif #ifdef CHAN_BUFF_CTRL @@ -223,7 +223,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, chanend c_sof, chanend c_aud_ctl, in port p_off_mclk -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) , chanend c_hid #endif #ifdef CHAN_BUFF_CTRL @@ -260,7 +260,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, XUD_ep ep_int = XUD_InitEp(c_ep_int); #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) XUD_ep ep_hid = XUD_InitEp(c_hid); #endif unsigned u_tmp; @@ -364,7 +364,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #endif #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) XUD_SetReady_In(ep_hid, g_hidData, 1); #endif @@ -875,7 +875,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #endif #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) /* HID Report Data */ case XUD_SetData_Select(c_hid, ep_hid, result): { diff --git a/lib_xua/src/core/endpoint0/descriptor_defs.h b/lib_xua/src/core/endpoint0/descriptor_defs.h index 1985d910..b348d6f1 100644 --- a/lib_xua/src/core/endpoint0/descriptor_defs.h +++ b/lib_xua/src/core/endpoint0/descriptor_defs.h @@ -54,7 +54,7 @@ enum USBInterfaceNumber INTERFACE_NUMBER_IAP_EA_NATIVE_TRANS, #endif #endif -#if defined(HID_CONTROLS) && (HID_CONTROLS != 0) +#if( 0 < HID_CONTROLS ) INTERFACE_NUMBER_HID, #endif INTERFACE_COUNT /* End marker */ diff --git a/lib_xua/src/core/endpoint0/xua_endpoint0.c b/lib_xua/src/core/endpoint0/xua_endpoint0.c index 11833693..b5d1d8b7 100755 --- a/lib_xua/src/core/endpoint0/xua_endpoint0.c +++ b/lib_xua/src/core/endpoint0/xua_endpoint0.c @@ -21,7 +21,7 @@ #include "vendorrequests.h" #include "xc_ptr.h" #include "xua_ep0_uacreqs.h" -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) #include "hid.h" #endif #if DSD_CHANS_DAC > 0 @@ -492,7 +492,7 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0 switch(sp.bRequest) { -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) case USB_GET_DESCRIPTOR: /* Check what inteface request is for */ @@ -871,7 +871,7 @@ void XUA_Endpoint0_lite_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend switch(sp.bRequest) { -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) case USB_GET_DESCRIPTOR: /* Check what inteface request is for */ diff --git a/lib_xua/src/core/main.xc b/lib_xua/src/core/main.xc index cb9d8af7..5a7aace0 100755 --- a/lib_xua/src/core/main.xc +++ b/lib_xua/src/core/main.xc @@ -259,7 +259,7 @@ XUD_EpType epTypeTableIn[ENDPOINT_COUNT_IN] = { XUD_EPTYPE_CTL | XUD_STATUS_ENAB #ifdef MIDI XUD_EPTYPE_BUL, #endif -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) XUD_EPTYPE_INT, #endif #ifdef IAP @@ -400,7 +400,7 @@ VENDOR_REQUESTS_PARAMS_DEC_ c_clk_int, #endif c_sof, c_aud_ctl, p_for_mclk_count -#ifdef HID_CONTROLS +#if( 0 < HID_CONTROLS ) , c_xud_in[ENDPOINT_NUMBER_IN_HID] #endif #ifdef CHAN_BUFF_CTRL