From b280e68bb577e591261d399f35b4b2bb7811ed2c Mon Sep 17 00:00:00 2001 From: Steven Dan Date: Wed, 27 May 2026 18:26:20 +0800 Subject: [PATCH] update hid --- lib_xua/lib_xua/src/hid/hid.xc | 136 +++++++++++++++++++++++---------- 1 file changed, 94 insertions(+), 42 deletions(-) diff --git a/lib_xua/lib_xua/src/hid/hid.xc b/lib_xua/lib_xua/src/hid/hid.xc index 98f9ff3..df0f1e1 100644 --- a/lib_xua/lib_xua/src/hid/hid.xc +++ b/lib_xua/lib_xua/src/hid/hid.xc @@ -16,6 +16,18 @@ #include "debug_print.h" #if XUA_HID_ENABLED +#include + +#define HID_PASS_REPORT_ID 0x1 +#define HID_BUTTON_REPORT_ID 0x2 +unsigned char g_hid_pass_push[65] = {0x1}; + +static unsigned s_hidChangePending = 0U; +static unsigned s_hidCurrentPeriod = ENDPOINT_INT_INTERVAL_IN_HID * MS_IN_TICKS; +static unsigned s_hidIdleActive = 0U; +static unsigned s_hidIndefiniteDuration = 0U; +static unsigned s_hidNextReportTime = 0U; +static unsigned s_hidReportTime = 0U; extern unsigned g_log_switch; static unsigned HidCalcNewReportTime( const unsigned currentPeriod, const unsigned reportTime, const unsigned reportToSetIdleInterval, const unsigned newPeriod ); @@ -24,6 +36,14 @@ static unsigned HidFindSetIdleActivationPoint( const unsigned currentPeriod, static XUD_Result_t HidProcessSetIdleRequest( XUD_ep c_ep0_out, XUD_ep c_ep0_in, USB_SetupPacket_t &sp ); static unsigned HidTimeDiff( const unsigned earlierTime, const unsigned laterTime ); +extern int xmos_printf(unsigned char *data, unsigned char len); + +extern void flash_read_did(uint8_t data[], unsigned char len); +extern void flash_read_uid(uint8_t data[], unsigned char len); +extern uint8_t key_verify(unsigned sec_write, uint8_t expected_bin[]); +extern void flash_sec_erase(); +extern unsigned int read_key(void); +extern unsigned int g_xu316_id; extern unsigned char process_send_params(uint8_t data[], uint16_t len); extern unsigned char process_read_params(uint8_t response[]); XUD_Result_t HidInterfaceClassRequests( @@ -44,19 +64,35 @@ XUD_Result_t HidInterfaceClassRequests( case HID_GET_REPORT: unsigned ret_len = 65; -#if ((USE_EX3D == 1) || (EQ_EN == 1)) - buffer[0] = 0x1; - process_read_params(&buffer[1]); -#endif -#if DEBUG_MEMORY_LOG_ENABLED - unsigned log_switch; - buffer[0] = 0x1; - - GET_SHARED_GLOBAL(log_switch, g_log_switch); - if (log_switch) { - ret_len = 65; - UserReadHIDLog(&buffer[1]); + if ((sp.wValue & 0xff) == HID_PASS_REPORT_ID) + { + buffer[0] = HID_PASS_REPORT_ID; + process_read_params(&buffer[1]); } + +#if DEBUG_MEMORY_LOG_ENABLED + unsigned log_switch; + GET_SHARED_GLOBAL(log_switch, g_log_switch); + if (log_switch) { + ret_len = 65; + UserReadHIDLog(&buffer[1]); + } + +#endif + + if ((sp.wValue & 0xff) == 0) + { + ret_len = 65; + } + +#if 0 + debug_printf("%d:\n", ret_len); + for(int i=0; i < ret_len; i++) + { + printhex((buffer, unsigned char[])[i]); + printstr("-"); + } + printstrln("\n"); #endif return XUD_DoGetRequest(c_ep0_out, c_ep0_in, (buffer, unsigned char []), ret_len, sp.wLength); break; @@ -67,45 +103,61 @@ XUD_Result_t HidInterfaceClassRequests( /* Do nothing - i.e. STALL */ break; -#if ((USE_EX3D == 1) || (EQ_EN == 1)) - case HID_SET_REPORT: - result = XUD_GetBuffer(c_ep0_out, (buffer, unsigned char[]), datalength); - if(result == XUD_RES_OKAY) { -#if 0// USE_EX3D == 1 - if(datalength > 0) { - unsafe - { - c_hidRcvData <: (unsigned char)datalength; - for(unsigned i=0; i= 0x70) || (buffer[2] == 0x5b))) - { - process_send_params(&buffer[1], datalength - 1); - } - - result = XUD_DoSetRequestStatus(c_ep0_in); - } - break; #endif + } - case HID_SET_IDLE: - result = HidProcessSetIdleRequest( c_ep0_out, c_ep0_in, sp ); - break; + /* Send 0 Length as status stage */ + XUD_DoSetRequestStatus(c_ep0_in); + break; - case HID_SET_PROTOCOL: - break; + case HID_SET_IDLE: + result = HidProcessSetIdleRequest( c_ep0_out, c_ep0_in, sp ); + break; - default: - break; - } + case HID_SET_PROTOCOL: + /* Do nothing - i.e. STALL */ + break; + } - return result; + return XUD_RES_ERR; } unsigned HidIsSetIdleSilenced( const unsigned id )