update hid

This commit is contained in:
Steven Dan
2026-05-27 18:26:20 +08:00
parent 28f1746fee
commit b280e68bb5

View File

@@ -16,6 +16,18 @@
#include "debug_print.h"
#if XUA_HID_ENABLED
#include <xccompat.h>
#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<datalength; i++) {
c_hidRcvData <: buffer[i];
case HID_SET_REPORT:
// only support to get 64Bytes max for each XUD_GetBuffer. For more than 64Bytes, need to call XUD_GetBuffer every 64Bytes and call XUD_DoSetRequestStatus finally after get all the data
if((result = XUD_GetBuffer(c_ep0_out, (buffer, unsigned char[]), datalength)) != XUD_RES_OKAY)
{
// debug_printf("HID_SET_REPORT return\n");
return result;
}
}
}
if((sp.wValue & 0xff) == HID_PASS_REPORT_ID)
{
if (buffer[1] == 0x55 && buffer[2] == 0xAA && buffer[3] == 0x00 && buffer[4] == 0xEE && buffer[5] == 0x39)
{
if (xmos_printf(&buffer[1], datalength-1) == -1)
{
// debug_printf(" HID_SET_REPORT error\n");
return XUD_RES_ERR;
}
}
else
{
process_send_params(&buffer[1], datalength - 1);
}
}
else if((sp.wValue & 0xff) == 0)
{
#if MQA_EN
MQA_XMOS_HostReadWrite(buffer, sizeof(buffer)-1, datalength);
#if 0
debug_printf("%d:\n", datalength);
for(int i=0; i < datalength; i++)
{
debug_printf("%c",(buffer, unsigned char[])[i]);
}
debug_printf("\n");
#endif
if (buffer[1] == 0x77 && ((buffer[2] >= 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 )