We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I'm just implementing the Keil HID sample code, but I found some strange things even the compiler complains about:
In usbcore.c there are some variables used without being set before. The variables are "alt" in USB_SetConfiguration() and "msk", "old", "alt" and "ifn" in USB_SetInterface().
__inline BOOL USB_SetConfiguration(void) { USB_COMMON_DESCRIPTOR *pD; DWORD alt, n, m; : case USB_INTERFACE_DESCRIPTOR_TYPE: alt = ((USB_INTERFACE_DESCRIPTOR *) pD)->bAlternateSetting; break; case USB_ENDPOINT_DESCRIPTOR_TYPE: if (alt == 0) { : } : }
The code at USB_ENDPOINT_DESCRIPTOR_TYPE is executed when "alt" is 0 by chance only and setting "alt" in USB_INTERFACE_DESCRIPTOR_TYPE has no effect as "alt" is an auto-variable loosing it's contents after USB_SetConfiguration() is finished.
USB_SetInterface() shows similar things.
The source code does work in my environment, but I'm anxious that this is by chance only.
Could anybody explain me how to come to a more reliable solution?
BTW: Code parts like
(BYTE *) pD += pD->bLength;
in a sample code scare me even after more than 20 years C programming (Realview complains as well).
Regards Herbert
Hello Herbert,
"Regarding Keil's HID sample code I would like to know how difficult it is to make it functional for Linux as well."
USB is a standard protocol. As long as you follow the USB spec, your device works on any OS (, in principle :-) ). Surely, Windows give us some (many?) exceptions, but Linux doesn't have so much exception. I don't see any problem on the HID example which disturbs working on Linux.
"As far as I know not answering GET_REPORT(Feature) is one of the problems causing not to be operable under Linux but there may be others as well."
The example declares no feature report. Then, even if you see STALL for GET_REPORT(Feature), it is the expected result.
- Declare a feature report in the report descriptor - Modify HID_GetReport() handler
hiduser.c /* * HID Get Report Request Callback * Called automatically on HID Get Report Request * Parameters: None (global SetupPacket and EP0Buf) * Return Value: TRUE - Success, FALSE - Error */ BOOL HID_GetReport (void) { /* ReportID = SetupPacket.wValue.WB.L; */ switch (SetupPacket.wValue.WB.H) { case HID_REPORT_INPUT: GetInReport(); EP0Buf[0] = InReport; break; case HID_REPORT_OUTPUT: return (FALSE); /* Not Supported */ case HID_REPORT_FEATURE: /* EP0Buf[] = ...; */ /* break; */ return (FALSE); /* Not Supported */ } return (TRUE); }
Tsuneo