Skip to content

Conversation

@ayedm1
Copy link
Owner

@ayedm1 ayedm1 commented Jan 14, 2026

No description provided.

Copilot AI review requested due to automatic review settings January 14, 2026 01:08
@github-actions
Copy link

github-actions bot commented Jan 14, 2026

Test Results

3 036 tests   3 036 ✔️  32m 38s ⏱️
     17 suites         0 💤
     17 files           0

Results for commit 168aad0.

♻️ This comment has been updated with latest results.

@ayedm1 ayedm1 force-pushed the add_set_get_hid_host_api_and_device_callback branch from 0fa2351 to 43466b2 Compare January 14, 2026 01:14
Copy link

Copilot AI left a 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() and ux_host_class_hid_protocol_get() with error checking wrappers
  • Added device-side optional callback ux_device_class_hid_set_protocol_callback that 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.

Comment on lines 319 to 324
if (status != UX_SUCCESS && status != UX_TRANSFER_STALLED)
{
printf("Error on line %d, error code: 0x%x\n", __LINE__, status);
test_control_return(1);
}

Copy link

Copilot AI Jan 14, 2026

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.

Suggested change
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 uses AI. Check for mistakes.
Comment on lines 337 to 339
if (ux_device_class_hid_protocol_get(slave_hid) != 0)
{
printf("Error on line %d, protocol not set to boot\n", __LINE__);
Copy link

Copilot AI Jan 14, 2026

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.

Suggested change
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__);

Copilot uses AI. Check for mistakes.
Comment on lines 58 to 86
/* 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)

Copy link

Copilot AI Jan 14, 2026

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.

Copilot uses AI. Check for mistakes.
USHORT host_protocol = 0xFFFF;
status = ux_host_class_hid_protocol_get(hid, &host_protocol);
if (status != UX_SUCCESS && status != UX_TRANSFER_STALLED)

Copy link

Copilot AI Jan 14, 2026

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.

Suggested change

Copilot uses AI. Check for mistakes.

status = ux_host_class_hid_protocol_get(hid, &host_protocol);


Copy link

Copilot AI Jan 14, 2026

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.

Suggested change

Copilot uses AI. Check for mistakes.
test_control_return(1);
}


Copy link

Copilot AI Jan 14, 2026

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.

Suggested change

Copilot uses AI. Check for mistakes.
@ayedm1 ayedm1 force-pushed the add_set_get_hid_host_api_and_device_callback branch from 43466b2 to ab7206a Compare January 14, 2026 02:39
Copilot AI review requested due to automatic review settings January 14, 2026 02:58
@ayedm1 ayedm1 force-pushed the add_set_get_hid_host_api_and_device_callback branch from ab7206a to 1f6b9e9 Compare January 14, 2026 02:58
Copy link

Copilot AI left a 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 ||
Copy link

Copilot AI Jan 14, 2026

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.

Suggested change
if (g_set_protocol_callback_calls < 1 ||
if (g_set_protocol_callback_calls < 2 ||

Copilot uses AI. Check for mistakes.
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;

Copy link

Copilot AI Jan 14, 2026

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.

Suggested change
/* 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;

Copilot uses AI. Check for mistakes.

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__);
Copy link

Copilot AI Jan 14, 2026

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.

Suggested change
printf("Error on line %d, protocol not set to boot\n", __LINE__);
printf("Error on line %d, protocol not set to report\n", __LINE__);

Copilot uses AI. Check for mistakes.
@ayedm1 ayedm1 force-pushed the add_set_get_hid_host_api_and_device_callback branch from 1f6b9e9 to 2f917d7 Compare January 14, 2026 03:13
Copilot AI review requested due to automatic review settings January 14, 2026 03:46
@ayedm1 ayedm1 force-pushed the add_set_get_hid_host_api_and_device_callback branch from 2f917d7 to 75f6b16 Compare January 14, 2026 03:46
Copy link

Copilot AI left a 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. */
Copy link

Copilot AI Jan 14, 2026

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.

Suggested change
/* 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. */

Copilot uses AI. Check for mistakes.
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0 // END_COLLECTION
};
#define HID_KEYBOARD_REPORT_LENGTH (sizeof(hid_keyboard_report)/sizeof(hid_keyboard_report)[0])
Copy link

Copilot AI Jan 14, 2026

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.

Suggested change
#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]))

Copilot uses AI. Check for mistakes.
@ayedm1 ayedm1 force-pushed the add_set_get_hid_host_api_and_device_callback branch from 75f6b16 to 168aad0 Compare January 14, 2026 04:01
@github-actions
Copy link

Code Coverage

Package Line Rate Branch Rate Health
core.src 96% 92%
usbx_device_classes.src 97% 90%
usbx_host_classes.src 96% 92%
Summary 96% (7650 / 7931) 92% (3394 / 3697)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants