2023-02-27 08:41 PM
The original CustomHID_Data_Setup function :
RESULT CustomHID_Data_Setup(uint8_t RequestNo)
{
uint8_t *(*CopyRoutine)(uint16_t);
if (pInformation->USBwIndex != 0)
return USB_UNSUPPORT;
CopyRoutine = NULL;
if ((RequestNo == GET_DESCRIPTOR)
&& (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
) // (( ==0x06 ))&&(0x01=(0x00|0x01))
{
if (pInformation->USBwValue1 == REPORT_DESCRIPTOR)
{
CopyRoutine = CustomHID_GetReportDescriptor;
}
else if (pInformation->USBwValue1 == HID_DESCRIPTOR_TYPE)
{
CopyRoutine = CustomHID_GetHIDDescriptor;
}
} /* End of GET_DESCRIPTOR */
/*** GET_PROTOCOL, GET_REPORT, SET_REPORT ***/
else if ( (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) )
{
switch( RequestNo )
{
case GET_PROTOCOL:
CopyRoutine = CustomHID_GetProtocolValue;
break;
case SET_REPORT:
CopyRoutine = CustomHID_SetReport_Feature;
Request = SET_REPORT;
break;
default:
break;
}
}
if (CopyRoutine == NULL)
{
return USB_UNSUPPORT;
}
pInformation->Ctrl_Info.CopyData = CopyRoutine;
pInformation->Ctrl_Info.Usb_wOffset = 0;
(*CopyRoutine)(0);
return USB_SUCCESS;
}
If I don't change the original code:
The result of usb communication is this:c00000004 stall pid.I guess because original code not have handle "get report".My request in host by feature.
So I changed the code.
The new core:
RESULT CustomHID_Data_Setup(uint8_t RequestNo)
{
uint8_t *(*CopyRoutine)(uint16_t);
if (pInformation->USBwIndex != 0)
return USB_UNSUPPORT;
CopyRoutine = NULL;
if ((RequestNo == GET_DESCRIPTOR)
&& (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
)
{
if (pInformation->USBwValue1 == REPORT_DESCRIPTOR)
{
CopyRoutine = CustomHID_GetReportDescriptor;
}
else if (pInformation->USBwValue1 == HID_DESCRIPTOR_TYPE)
{
CopyRoutine = CustomHID_GetHIDDescriptor;
}
} /* End of GET_DESCRIPTOR */
/*** GET_PROTOCOL, GET_REPORT, SET_REPORT ***/
else if ( (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) )
{
switch( RequestNo )
{
case GET_REPORT: //new insert
CopyRoutine = CustomHID_GetReport_Feature; //new insert
Request = GET_REPORT; //new insert
case GET_PROTOCOL:
CopyRoutine = CustomHID_GetProtocolValue;
break;
case SET_REPORT:
CopyRoutine = CustomHID_SetReport_Feature;
Request = SET_REPORT;
break;
default:
break;
}
}
if (CopyRoutine == NULL)
{
return USB_UNSUPPORT;
}
pInformation->Ctrl_Info.CopyData = CopyRoutine;
pInformation->Ctrl_Info.Usb_wOffset = 0;
(*CopyRoutine)(0);
return USB_SUCCESS;
}
add to new function:
uint8_t *CustomHID_GetReport_Feature(uint16_t Length)
{
return (uint8_t *)(&report[0]);
}
uint32_t report[]={0x01,0x01,0x02,0x03,0x04,0x03,0x02,0x64,0x64,0x00,0x00,0x00,0x00,0x04};
But the device only responded with a data 0.
I don`t know why?
Solved! Go to Solution.
2023-03-02 02:06 AM
Now is OK.
uint8_t *CustomHID_GetReport_Feature(uint16_t Length)
{
if (Length == 0)
{
pInformation->Ctrl_Info.Usb_wLength = Size ; //The size is your data length.
return NULL;
}
else
{
return (uint8_t *)(&report[0]);
}
}
I don't know why.Because I think it had return.But it's ok.!!!???
2023-02-28 01:25 AM
I forgot to add break, but stall pid=c0000004 appeared again.
2023-02-28 06:28 AM
uint32_t report[]?
The report is a sequence of bytes, not 32-bit words.
2023-02-28 05:37 PM
Thank you for your answer. Unfortunately, I still can't.
2023-03-02 02:06 AM
Now is OK.
uint8_t *CustomHID_GetReport_Feature(uint16_t Length)
{
if (Length == 0)
{
pInformation->Ctrl_Info.Usb_wLength = Size ; //The size is your data length.
return NULL;
}
else
{
return (uint8_t *)(&report[0]);
}
}
I don't know why.Because I think it had return.But it's ok.!!!???