forked from PAWPAW-Mirror/lib_xua
Merge pull request #1 from michaelb/pendragon
Add UAC1 HID support for Voice Command detection
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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/*
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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,12 +875,12 @@ 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):
|
||||
{
|
||||
g_hidData[0]=0;
|
||||
UserReadHIDButtons(g_hidData);
|
||||
UserReadHIDData(g_hidData);
|
||||
XUD_SetReady_In(ep_hid, g_hidData, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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) */
|
||||
@@ -555,16 +555,11 @@ unsigned char hidReportDescriptor[] =
|
||||
0xa1, 0x01, /* Collection (Application) */
|
||||
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) */
|
||||
0x09, 0xcf, /* Usage (Voice Command), use 0xcd for (Play/Pause OSC) */
|
||||
0x75, 0x01, /* Report Size (1) */
|
||||
0x95, 0x06, /* Report Count (6) */
|
||||
0x81, 0x02, /* Input (Data, Var, Abs) */
|
||||
0x95, 0x02, /* Report Count (2) */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0x81, 0x06, /* Input (Data, Var, Rel) */
|
||||
0x95, 0x07, /* Report Count (7) */
|
||||
0x81, 0x01, /* Input (Cnst, Ary, Abs) */
|
||||
0xc0 /* End collection */
|
||||
};
|
||||
@@ -769,7 +764,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;
|
||||
@@ -1084,7 +1079,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 +1099,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
|
||||
0x0000, /* 9 bmControls */
|
||||
0, /* 11 iTerminal */
|
||||
},
|
||||
#endif
|
||||
#endif /* (NUM_USB_CHAN_OUT > 0) */
|
||||
|
||||
|
||||
|
||||
@@ -1259,7 +1254,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
|
||||
},
|
||||
0, /* 60 iFeature */
|
||||
},
|
||||
#endif
|
||||
#endif /* (INPUT_VOLUME_CONTROL == 1) */
|
||||
|
||||
.Audio_In_OutputTerminal =
|
||||
{
|
||||
@@ -1280,7 +1275,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 +1369,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 +1566,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 +1810,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 +1883,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 +2039,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 */
|
||||
@@ -2153,7 +2148,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 */
|
||||
@@ -2192,17 +2187,17 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
|
||||
#endif
|
||||
|
||||
};
|
||||
#endif
|
||||
#endif /* (AUDIO_CLASS == 2) */
|
||||
|
||||
#ifdef HID_CONTROLS
|
||||
#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] */
|
||||
@@ -2309,18 +2304,13 @@ 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
|
||||
#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
|
||||
@@ -2333,12 +2323,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)
|
||||
@@ -2840,6 +2830,39 @@ 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) */
|
||||
0x17, /* 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) */
|
||||
0x40, /* 4 wMaxPacketSize */
|
||||
0x00, /* 5 wMaxPacketSize */
|
||||
0x08, /* 6 bInterval */
|
||||
#endif
|
||||
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
44
lib_xua/src/core/user/user_hid.xc
Normal file
44
lib_xua/src/core/user/user_hid.xc
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2019, XMOS Ltd, All rights reserved
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#include <xs1.h>
|
||||
#include "user_hid.h"
|
||||
|
||||
#define HID_DEASSERT_COUNT 10000000
|
||||
#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 ])
|
||||
{
|
||||
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 ) && ( tick_count <= ( HID_INTERRUPT_COUNT + HID_DEASSERT_COUNT ))) {
|
||||
for( unsigned idx = 0; idx < HID_DATA_SIZE; ++idx ) {
|
||||
hidData[ idx ] = HID_REPORT_DATA;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user