Problem regarding getting the USB HID generic example to work with a report id.
I started a new empty project with the "KL27Z" SDK and initialzied the USB Middleware via the "Config Tool". There I selected the generic HID example and just shorted the descriptor a little bit.
This is how my descriptor looks like:
uint8_t g_UsbDeviceInterface0HidGenericReportDescriptor[] = {
0x05U, 0x81U, /* Usage Page (Vendor defined) */
0x09U, 0x82U, /* Usage (Vendor defined) */
0xA1U, 0x01U, /* Collection (Application) */
0x09U, 0x01U, /* Usage (Vendor defined) */
0x15U, 0x00U, /* Logical Minimum (0) */
0x26U, 0xFFU, 0x00U, /* Logical Maximum (255) */
0x75U, 0x08U, /* Report Size (8U) */
0x95U, 0x08U, /* Report Count (8U) */
0x81U, 0x02U, /* Input(Data, Variable, Absolute) */
0x09U, 0x01U, /* Usage (Vendor defined) */
0x91U, 0x02U, /* Output(Data, Variable, Absolute) */
0xC0U, /* End collection, */
};
And I just used the example code to return the received values to the host:
static usb_status_t USB_DeviceHidGenericAction(void)
{
for (int i = 0; i < USB_INTERFACE_0_HID_GENERIC_OUTPUT_REPORT_LENGTH; i++)
{
s_UsbDeviceHidGeneric.inBuffer[i] = s_UsbDeviceHidGeneric.outBuffer[i];
}
USB_DeviceHidSend(s_UsbDeviceComposite->interface0HidGenericHandle, USB_INTERFACE_0_HID_GENERIC_SETTING_0_EP_1_INTERRUPT_IN,
(uint8_t *)s_UsbDeviceHidGeneric.inBuffer,
USB_INTERFACE_0_HID_GENERIC_INPUT_REPORT_LENGTH);
return USB_DeviceHidRecv(s_UsbDeviceComposite->interface0HidGenericHandle, USB_INTERFACE_0_HID_GENERIC_SETTING_0_EP_1_INTERRUPT_OUT,
(uint8_t *)s_UsbDeviceHidGeneric.outBuffer,
USB_INTERFACE_0_HID_GENERIC_OUTPUT_REPORT_LENGTH);
}
usb_status_t USB_DeviceInterface0HidGenericCallback(class_handle_t handle, uint32_t event, void *param)
{
usb_status_t error = kStatus_USB_Error;
switch (event)
{
case kUSB_DeviceHidEventSendResponse:
break;
case kUSB_DeviceHidEventRecvResponse:
if (s_UsbDeviceComposite->attach)
{
return USB_DeviceHidGenericAction();
}
break;
case kUSB_DeviceHidEventGetReport:
case kUSB_DeviceHidEventSetReport:
case kUSB_DeviceHidEventRequestReportBuffer:
error = kStatus_USB_InvalidRequest;
break;
case kUSB_DeviceHidEventGetIdle:
case kUSB_DeviceHidEventGetProtocol:
case kUSB_DeviceHidEventSetIdle:
case kUSB_DeviceHidEventSetProtocol:
break;
default:
break;
}
return error;
}
I confirmed that it works with a small python script.
Then i wanted to change it so I that the report uses a report id.
I changed the descriptor and it now looks like this:
uint8_t g_UsbDeviceInterface0HidGenericReportDescriptor[] = {
0x05U, 0x81U, /* Usage Page (Vendor defined) */
0x09U, 0x82U, /* Usage (Vendor defined) */
0xA1U, 0x01U, /* Collection (Application) */
0x09U, 0x01U, /* Usage (Vendor defined) */
0x85U, 0x02U, /* Report ID (2) */
0x15U, 0x00U, /* Logical Minimum (0) */
0x26U, 0xFFU, 0x00U, /* Logical Maximum (255) */
0x75U, 0x08U, /* Report Size (8U) */
0x95U, 0x08U, /* Report Count (8U) */
0x81U, 0x02U, /* Input(Data, Variable, Absolute) */
0x09U, 0x01U, /* Usage (Vendor defined) */
0x91U, 0x02U, /* Output(Data, Variable, Absolute) */
0xC0U, /* End collection, */
};
But now the devices does not send back the bytes when I run the python script.
If I set a breakpoint in the "USB_DeviceHidGenericAction()" function it stops there and calls the "USB_DeviceHidSend()" function.
Do I have to insert the report id somwhere in the message and how would I do it.
I tried to just set s_UsbDeviceHidGeneric.inBuffer[0] to the report id but that didn't worked.
I'm new to this, never done something with USB before and the SDK is really overwhelming.
Help would be appreciated.
Hi,
Please refer this link. hid-reporter
BTW, you can use hid descriptor to generate the reporter. You can download here. hid_descriptor_tool
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------