-
Notifications
You must be signed in to change notification settings - Fork 0
add host hid api to set/get protocol #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
0fa2351 to
43466b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds host HID API functions to get and set the HID protocol (boot vs report mode) and introduces an optional callback for the device side when the protocol changes.
Changes:
- Added new host-side APIs
ux_host_class_hid_protocol_set()andux_host_class_hid_protocol_get()with error checking wrappers - Added device-side optional callback
ux_device_class_hid_set_protocol_callbackthat is invoked when the protocol changes - Added validation of protocol values (must be 0 for BOOT or 1 for REPORT) in device control request handler
- Added comprehensive test to verify the new protocol callback functionality
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| common/usbx_host_classes/src/ux_host_class_hid_protocol_set.c | New file implementing SET_PROTOCOL request to switch between BOOT and REPORT protocols |
| common/usbx_host_classes/src/ux_host_class_hid_protocol_get.c | New file implementing GET_PROTOCOL request to read current protocol |
| common/usbx_host_classes/inc/ux_host_class_hid.h | Added function declarations, protocol constants, and macro definitions; removed trailing whitespace |
| common/usbx_host_classes/CMakeLists.txt | Added new source files to build |
| common/usbx_device_classes/src/ux_device_class_hid_control_request.c | Added protocol validation and optional callback invocation for SET_PROTOCOL |
| common/usbx_device_classes/src/ux_device_class_hid_initialize.c | Initialize the new set_protocol_callback field |
| common/usbx_device_classes/inc/ux_device_class_hid.h | Added callback field and parameter structure member |
| test/regression/usbx_ux_device_class_hid_set_protocol_callback_test.c | New comprehensive test file verifying protocol get/set APIs and callback behavior |
| test/regression/usbxtestcontrol.c | Added forward declaration and test array entry; removed trailing whitespace |
| test/cmake/usbx/regression/CMakeLists.txt | Added new test file to build |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (status != UX_SUCCESS && status != UX_TRANSFER_STALLED) | ||
| { | ||
| printf("Error on line %d, error code: 0x%x\n", __LINE__, status); | ||
| test_control_return(1); | ||
| } | ||
|
|
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate status check. This condition was already checked on lines 313-317. The second check on lines 319-323 is redundant and should be removed.
| if (status != UX_SUCCESS && status != UX_TRANSFER_STALLED) | |
| { | |
| printf("Error on line %d, error code: 0x%x\n", __LINE__, status); | |
| test_control_return(1); | |
| } |
| if (ux_device_class_hid_protocol_get(slave_hid) != 0) | ||
| { | ||
| printf("Error on line %d, protocol not set to boot\n", __LINE__); |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The protocol value check is incorrect. After setting the protocol to REPORT (value 1) on line 312, this check expects the protocol to be 0 (BOOT), but it should expect 1 (REPORT). The error message is also inconsistent - it says "protocol not set to boot" when checking after setting to REPORT mode.
| if (ux_device_class_hid_protocol_get(slave_hid) != 0) | |
| { | |
| printf("Error on line %d, protocol not set to boot\n", __LINE__); | |
| if (ux_device_class_hid_protocol_get(slave_hid) != 1) | |
| { | |
| printf("Error on line %d, protocol not set to report\n", __LINE__); |
| /* Ensure the instance is valid. */ | ||
| if (_ux_host_stack_class_instance_verify(_ux_system_host_class_hid_name, (VOID *) hid) != UX_SUCCESS) | ||
| { | ||
|
|
||
| /* If trace is enabled, insert this event into the trace buffer. */ | ||
| UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0) | ||
|
|
||
| #if defined(UX_HOST_STANDALONE) | ||
| hid -> ux_host_class_hid_status = UX_HOST_CLASS_INSTANCE_UNKNOWN; | ||
| #endif | ||
| return(UX_HOST_CLASS_INSTANCE_UNKNOWN); | ||
| } | ||
|
|
||
| /* Get the default control endpoint transfer request pointer. */ | ||
| control_endpoint = &hid -> ux_host_class_hid_device -> ux_device_control_endpoint; | ||
| transfer_request = &control_endpoint -> ux_endpoint_transfer_request; | ||
|
|
||
|
|
||
| #if !defined(UX_HOST_STANDALONE) | ||
|
|
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation in comments. Lines 58 and 70 have 3 spaces of indentation (missing one space), while line 77 has 5 spaces (one extra space). All comments should use 4 spaces to match the codebase standard, as seen in other files like ux_host_class_hid_idle_set.c.
| USHORT host_protocol = 0xFFFF; | ||
| status = ux_host_class_hid_protocol_get(hid, &host_protocol); | ||
| if (status != UX_SUCCESS && status != UX_TRANSFER_STALLED) | ||
|
|
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary blank line between the if condition and its opening brace. The opening brace should immediately follow the condition on the same or next line without an extra blank line.
|
|
||
| status = ux_host_class_hid_protocol_get(hid, &host_protocol); | ||
|
|
||
|
|
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary blank lines between the function call and the following if statement. There should be only one blank line for separation.
| test_control_return(1); | ||
| } | ||
|
|
||
|
|
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary extra blank line. There should be only one blank line for separation between code blocks.
43466b2 to
ab7206a
Compare
ab7206a to
1f6b9e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| status = ux_host_class_hid_protocol_get(hid, &host_protocol); | ||
|
|
||
| if (g_set_protocol_callback_calls < 1 || |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition checks if callback_calls is less than 1, which means it's verifying the callback has been called at least once. However, after setting protocol to BOOT (line 284) and then to REPORT (line 310), the callback should have been invoked twice. This check should verify that g_set_protocol_callback_calls is at least 2 (or equal to 2) to ensure both protocol changes triggered the callback.
| if (g_set_protocol_callback_calls < 1 || | |
| if (g_set_protocol_callback_calls < 2 || |
| hid -> ux_device_class_hid_callback = hid_parameter -> ux_device_class_hid_parameter_callback; | ||
| hid -> ux_device_class_hid_get_callback = hid_parameter -> ux_device_class_hid_parameter_get_callback; | ||
| hid -> ux_device_class_hid_set_protocol_callback = hid_parameter -> ux_device_class_hid_parameter_set_protocol_callback; | ||
|
|
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ux_device_class_hid_protocol field is not explicitly initialized in ux_device_class_hid_initialize. Since _ux_utility_memory_allocate typically zeroes allocated memory, the protocol will default to 0 (BOOT), but according to the USB HID specification (section 7.2.6), the default protocol should be REPORT (1) for boot-capable devices. The protocol field should be explicitly initialized to UX_DEVICE_CLASS_HID_PROTOCOL_REPORT (1) to comply with the USB HID specification and match the test expectations at line 261.
| /* Set default protocol to REPORT as required by USB HID specification (section 7.2.6). */ | |
| hid -> ux_device_class_hid_protocol = UX_DEVICE_CLASS_HID_PROTOCOL_REPORT; |
|
|
||
| if (ux_device_class_hid_protocol_get(slave_hid) != UX_DEVICE_CLASS_HID_PROTOCOL_REPORT) | ||
| { | ||
| printf("Error on line %d, protocol not set to boot\n", __LINE__); |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message states "protocol not set to boot" but this check is verifying that the protocol is set to REPORT (1), not boot. The error message should say "protocol not set to report" to accurately reflect what is being checked.
| printf("Error on line %d, protocol not set to boot\n", __LINE__); | |
| printf("Error on line %d, protocol not set to report\n", __LINE__); |
1f6b9e9 to
2f917d7
Compare
2f917d7 to
75f6b16
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,462 @@ | |||
| /* This tests focuses on code coverage of ux_host_class_hid_keyboard_callback. */ | |||
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment incorrectly states the test focuses on 'ux_host_class_hid_keyboard_callback' when it actually tests the protocol set/get functionality and callbacks. The comment should be updated to accurately reflect the test's purpose.
| /* This tests focuses on code coverage of ux_host_class_hid_keyboard_callback. */ | |
| /* This test focuses on HID device class protocol set/get functionality and related callbacks. */ |
| 0x81, 0x00, // INPUT (Data,Ary,Abs) | ||
| 0xc0 // END_COLLECTION | ||
| }; | ||
| #define HID_KEYBOARD_REPORT_LENGTH (sizeof(hid_keyboard_report)/sizeof(hid_keyboard_report)[0]) |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The macro incorrectly uses sizeof(hid_keyboard_report)[0] which should be sizeof(hid_keyboard_report[0]). This calculates the size of the array divided by the size of a single element. The current expression divides by the size of the array itself (treated as a pointer), which will always be 1 for a UCHAR array.
| #define HID_KEYBOARD_REPORT_LENGTH (sizeof(hid_keyboard_report)/sizeof(hid_keyboard_report)[0]) | |
| #define HID_KEYBOARD_REPORT_LENGTH (sizeof(hid_keyboard_report) / sizeof(hid_keyboard_report[0])) |
75f6b16 to
168aad0
Compare
No description provided.