From 487ab06213c2151a02451cae2b7c6059b73dafdf Mon Sep 17 00:00:00 2001 From: Virgil_lai <414785686@qq.com> Date: Fri, 8 Dec 2023 00:34:32 +0800 Subject: [PATCH] add pawpaw hid code --- lib_xua/api/xua_buffer.h | 8 +++ lib_xua/src/core/buffer/ep/ep_buffer.xc | 71 +++++++++++++++++++++- lib_xua/src/core/endpoint0/xua_endpoint0.c | 24 ++++++++ lib_xua/src/core/main.xc | 4 ++ 4 files changed, 106 insertions(+), 1 deletion(-) diff --git a/lib_xua/api/xua_buffer.h b/lib_xua/api/xua_buffer.h index d7d182d7..8a03a365 100644 --- a/lib_xua/api/xua_buffer.h +++ b/lib_xua/api/xua_buffer.h @@ -50,6 +50,10 @@ void XUA_Buffer( #if (HID_CONTROLS) , chanend c_hid #endif + #ifdef PAWPAW_INOUTHID + , chanend c_hid + , chanend c_hid_out + #endif//#ifdef PAWPAW_INOUTHID , chanend c_aud #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) || defined(__DOXYGEN__) , client interface pll_ref_if i_pll_ref @@ -78,6 +82,10 @@ void XUA_Buffer_Ep(chanend c_aud_out, #if (HID_CONTROLS) , chanend c_hid #endif +#ifdef PAWPAW_INOUTHID + , chanend c_hid + , chanend c_hid_out +#endif //#ifdef PAWPAW_INOUTHID #ifdef CHAN_BUFF_CTRL , chanend c_buff_ctrl #endif diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index a2e42199..de9c134b 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -17,6 +17,12 @@ unsigned char g_hidData[HID_MAX_DATA_BYTES] = {0U}; #endif +#ifdef PAWPAW_INOUTHID +#include "stdio.h" +unsigned char g_hidData_in[PAWPAW_CFG_HID_IN_BUFSIZE] = {0}; +unsigned char g_hidData_out[PAWPAW_CFG_HID_OUT_BUFSIZE] = {0}; +#endif//#ifdef PAWPAW_INOUTHID + void GetADCCounts(unsigned samFreq, int &min, int &mid, int &max); #define BUFFER_SIZE_OUT (1028 >> 2) #define BUFFER_SIZE_IN (1028 >> 2) @@ -103,6 +109,10 @@ void XUA_Buffer( #if (HID_CONTROLS ) , chanend c_hid #endif +#ifdef PAWPAW_INOUTHID + , chanend c_hid + , chanend c_hid_out +#endif//#ifdef PAWPAW_INOUTHID , chanend c_aud #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) , client interface pll_ref_if i_pll_ref @@ -137,6 +147,11 @@ void XUA_Buffer( #if XUA_HID_ENABLED , c_hid #endif + +#ifdef PAWPAW_INOUTHID + , c_hid + , c_hid_out +#endif //#ifdef PAWPAW_INOUTHID #ifdef CHAN_BUFF_CTRL , c_buff_ctrl #endif @@ -187,6 +202,11 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #if(HID_CONTROLS) , chanend c_hid #endif +#ifdef PAWPAW_INOUTHID + , chanend c_hid + , chanend c_hid_out +#endif//#ifdef PAWPAW_INOUTHID + #ifdef CHAN_BUFF_CTRL , chanend c_buff_ctrl #endif @@ -227,6 +247,12 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #if XUA_HID_ENABLED XUD_ep ep_hid = XUD_InitEp(c_hid); #endif + +#ifdef PAWPAW_INOUTHID + XUD_ep ep_hid = XUD_InitEp(c_hid); + XUD_ep ep_hid_out = XUD_InitEp(c_hid_out);//dwj+ +#endif//#ifdef PAWPAW_INOUTHID + unsigned u_tmp; unsigned sampleFreq = DEFAULT_FREQ; unsigned masterClockFreq = DEFAULT_MCLK_FREQ; @@ -365,6 +391,11 @@ void XUA_Buffer_Ep(register chanend c_aud_out, i_pll_ref.toggle(); #endif +#ifdef PAWPAW_INOUTHID + XUD_SetReady_In(ep_hid, g_hidData_in, PAWPAW_CFG_HID_IN_BUFSIZE);// 上行 + XUD_SetReady_Out(ep_hid_out,g_hidData_out);// 下行 +#endif //#ifdef PAWPAW_INOUTHID + while(1) { XUD_Result_t result; @@ -898,7 +929,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #endif #if XUA_HID_ENABLED - /* HID Report Data */ + /* HID Report Data */ case XUD_SetData_Select(c_hid, ep_hid, result): hid_ready_flag = 0U; unsigned reportTime; @@ -910,6 +941,44 @@ void XUA_Buffer_Ep(register chanend c_aud_out, break; #endif + +#ifdef PAWPAW_INOUTHID + case XUD_SetData_Select(c_hid, ep_hid, result): + { + // debug_printf("HID IN\n"); + g_hidData_in[0]=0x01; + g_hidData_in[1]=0xc1; + g_hidData_in[2]=0xd2; + g_hidData_in[3]=0xe3; + g_hidData_in[4]=0xf4; + g_hidData_in[5]=0x05; + g_hidData_in[6]=0x06; + g_hidData_in[7]=0x07; + + XUD_SetReady_In(ep_hid, g_hidData_in, PAWPAW_CFG_HID_IN_BUFSIZE); + } + break; + +#if (HID_OUT_REQUIRED) + case XUD_GetData_Select(c_hid_out, ep_hid_out,length, result): + { + XUD_SetReady_Out(ep_hid_out,g_hidData_out); + + // XMOS 获取到的HID数据 + // g_hidData_out[0]...g_hidData_out[7] + // printf("g_hidData_out %d\n",length); + // for (size_t i = 0; i < 5; i++) + // { + // printf("%x ",g_hidData_out[i]); + // } + // printf("\n",length); + + } + break; +#endif //#if (HID_OUT_REQUIRED) + +#endif//#ifdef PAWPAW_INOUTHID + #ifdef MIDI /* Received word from MIDI thread - Check for ACK or Data */ case midi_get_ack_or_data(c_midi, is_ack, datum): diff --git a/lib_xua/src/core/endpoint0/xua_endpoint0.c b/lib_xua/src/core/endpoint0/xua_endpoint0.c index c24dfefc..3354e5b5 100755 --- a/lib_xua/src/core/endpoint0/xua_endpoint0.c +++ b/lib_xua/src/core/endpoint0/xua_endpoint0.c @@ -450,6 +450,30 @@ static unsigned char hidReportDescriptorPtr[] = { #endif +#ifdef PAWPAW_INOUTHID +#define hidReportDescriptorLength (sizeof(hidReportDescriptorPtr)) +static unsigned char hidReportDescriptorPtr[] = { + 0x05, 0x0c, // HID_USAGE_PAGE (Vendor Defined) + 0x09, 0x01, // USAGE (Undefined) + 0xa1, 0x01, // COLLECTION (Application) + // Report ID if any + 0x09, 0x02, // USAGE (Undefined) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, PAWPAW_CFG_HID_IN_BUFSIZE, // REPORT_COUNT (report_size) + 0x81, 0x02, // INPUT (Data,Var,Abs) + // Output + 0x09, 0x03, // USAGE (Undefined) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, PAWPAW_CFG_HID_OUT_BUFSIZE, // REPORT_COUNT (report_size) + 0x91, 0x02, // OUTPUT (Data,Var,Abs) + 0xc0 // END_COLLECTION +}; +#endif //#ifdef PAWPAW_INOUTHID + void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, NULLABLE_RESOURCE(chanend, c_audioControl), chanend c_mix_ctl, chanend c_clk_ctl, chanend c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_) diff --git a/lib_xua/src/core/main.xc b/lib_xua/src/core/main.xc index 1aac13db..e6519421 100755 --- a/lib_xua/src/core/main.xc +++ b/lib_xua/src/core/main.xc @@ -565,6 +565,10 @@ int main() #if (XUA_HID_ENABLED) , c_xud_in[ENDPOINT_NUMBER_IN_HID] #endif +#ifdef PAWPAW_INOUTHID + , c_xud_in[ENDPOINT_NUMBER_IN_HID] + , c_xud_out[ENDPOINT_NUMBER_OUT_HID] +#endif //#ifdef PAWPAW_INOUTHID , c_mix_out #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) , i_pll_ref