Hi Matt,
I have checked with the USB stack team, and they provided the following solution for your issue, please refer to it for details.
For set report request, there are two events, kUSB_DeviceHidEventRequestReportBuffer and kUSB_DeviceHidEventSetReport, can be used to implement the corresponding functionality.
The event kUSB_DeviceHidEventRequestReportBuffer will be received at first when the host sends a set report request, it is used by the stack to get the buffer from application to receive the report data sent by the host. Along with this event, a parameter (type is void*) is provided, and this parameter needs to be cast to a pointer to usb_device_hid_report_struct_t. The report data length is kept in field usb_device_hid_report_struct_t::reportLength. Users need to fill in a valid buffer address to usb_device_hid_report_struct_t:: reportBuffer
And then the event kUSB_DeviceHidEventSetReport will be received after the report data is received, same as before, a parameter is provided and need to be cast to a pointer to usb_device_hid_report_struct_t, the report data is kept in field usb_device_hid_report_struct_t:: reportBuffer.
The detail information please refer to the description of the structure usb_device_hid_report_struct_t.
I drafted a simple code for these two events.
static usb_device_hid_report_struct_t* g_output_report; /* Global variable */
static uint8_t s_UsbDeviceHidReportBuffer[HS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE];
case kUSB_DeviceHidEventRequestReportBuffer:
if (s_UsbDeviceComposite->attach)
{
g_output_report = (usb_device_hid_report_struct_t *)param;
if (g_output_report->reportLength <= sizeof(s_UsbDeviceHidReportBuffer))
{
g_output_report->reportBuffer = &s_UsbDeviceHidReportBuffer[0];
error = kStatus_USB_Success;
}
else
{
error = kStatus_USB_InvalidRequest;
}
}
break;
case kUSB_DeviceHidEventSetReport:
if (s_UsbDeviceComposite->attach)
{
uint32_t index = 0;
uint8_t *buff = NULL;
g_output_report = (usb_device_hid_report_struct_t *)param;
buff = g_output_report->reportBuffer;
printf("kUSB_DeviceHidEventSetReport!\r\n");
printf("Report ID: %d\r\n", g_output_report->reportId);
printf("Report Type: %d\r\n", g_output_report->reportType);
printf("Printing %d received data:\r\n", (uint8_t)g_output_report->reportLength);
for (index = 0; index < g_output_report->reportLength; index++) {
printf(" 0x%X ", buff[index]);
}
printf("\r\n");
error = kStatus_USB_Success;
}
break;
Hope that helps,
Have a great day,
Kan
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------