forked from eclipse-threadx/usbx
-
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
Open
ayedm1
wants to merge
3
commits into
master
Choose a base branch
from
add_set_get_hid_host_api_and_device_callback
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
146 changes: 146 additions & 0 deletions
146
common/usbx_host_classes/src/ux_host_class_hid_protocol_get.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| /*************************************************************************** | ||
| * Copyright (c) 2024 Microsoft Corporation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the MIT License which is available at | ||
| * https://opensource.org/licenses/MIT. | ||
| * | ||
| * SPDX-License-Identifier: MIT | ||
| **************************************************************************/ | ||
|
|
||
|
|
||
| /**************************************************************************/ | ||
| /**************************************************************************/ | ||
| /** */ | ||
| /** USBX Component */ | ||
| /** */ | ||
| /** Host HID Class */ | ||
| /** */ | ||
| /**************************************************************************/ | ||
| /**************************************************************************/ | ||
|
|
||
| /* Include necessary system files. */ | ||
|
|
||
| #define UX_SOURCE_CODE | ||
|
|
||
| #include "ux_api.h" | ||
| #include "ux_host_class_hid.h" | ||
| #include "ux_host_stack.h" | ||
|
|
||
| /**************************************************************************/ | ||
| /* */ | ||
| /* FUNCTION RELEASE */ | ||
| /* */ | ||
| /* _ux_host_class_hid_protocol_get PORTABLE C */ | ||
| /* */ | ||
| /* DESCRIPTION */ | ||
| /* */ | ||
| /* This function performs a GET_PROTOCOL to the HID device to read */ | ||
| /* current protocol (BOOT=0 or REPORT=1). */ | ||
| /* */ | ||
| /* INPUT */ | ||
| /* */ | ||
| /* hid Pointer to HID class */ | ||
| /* protocol Destination for protocol */ | ||
| /* */ | ||
| /* OUTPUT */ | ||
| /* */ | ||
| /* Completion Status */ | ||
| /* */ | ||
| /* CALLED BY */ | ||
| /* */ | ||
| /* Application */ | ||
| /* */ | ||
| /* RELEASE HISTORY */ | ||
| /* */ | ||
| /* DATE NAME DESCRIPTION */ | ||
| /* */ | ||
| /* 01-15-2026 Mohamed AYED Initial Version 6.4.6 */ | ||
| /* */ | ||
| /**************************************************************************/ | ||
| UINT _ux_host_class_hid_protocol_get(UX_HOST_CLASS_HID *hid, USHORT *protocol) | ||
| { | ||
|
|
||
| UX_ENDPOINT *control_endpoint; | ||
| UX_TRANSFER *transfer_request; | ||
| UINT status; | ||
| UCHAR proto_byte = 0xFFu; | ||
|
|
||
| /* 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) | ||
|
|
||
| /* Protect thread reentry to this instance. */ | ||
| status = _ux_host_semaphore_get(&hid -> ux_host_class_hid_semaphore, UX_WAIT_FOREVER); | ||
| if (status != UX_SUCCESS) | ||
| return(status); | ||
|
|
||
| #endif | ||
|
|
||
| /* Create a transfer request for the GET_PROTOCOL request. */ | ||
| transfer_request -> ux_transfer_request_data_pointer = &proto_byte; | ||
| transfer_request -> ux_transfer_request_requested_length = 1; | ||
| transfer_request -> ux_transfer_request_function = UX_HOST_CLASS_HID_GET_PROTOCOL; | ||
| transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE; | ||
| transfer_request -> ux_transfer_request_value = 0; | ||
| transfer_request -> ux_transfer_request_index = hid -> ux_host_class_hid_interface -> ux_interface_descriptor.bInterfaceNumber; | ||
|
|
||
| /* Send request to HCD layer. */ | ||
| status = _ux_host_stack_transfer_request(transfer_request); | ||
|
|
||
| #if !defined(UX_HOST_STANDALONE) | ||
| /* Unprotect thread reentry to this instance. */ | ||
| _ux_host_semaphore_put(&hid -> ux_host_class_hid_semaphore); | ||
| #endif | ||
|
|
||
| if (status == UX_SUCCESS && protocol) | ||
| *protocol = (USHORT)proto_byte; | ||
|
|
||
| return(status); | ||
| } | ||
|
|
||
| /**************************************************************************/ | ||
| /* */ | ||
| /* FUNCTION RELEASE */ | ||
| /* */ | ||
| /* _uxe_host_class_hid_protocol_get PORTABLE C */ | ||
| /* */ | ||
| /* DESCRIPTION */ | ||
| /* */ | ||
| /* This function checks errors in HID protocol get function call. */ | ||
| /* */ | ||
| /* INPUT */ | ||
| /* */ | ||
| /* hid Pointer to HID class */ | ||
| /* protocol Destination for protocol */ | ||
| /* */ | ||
| /* OUTPUT */ | ||
| /* */ | ||
| /* Status */ | ||
| /* */ | ||
| /**************************************************************************/ | ||
| UINT _uxe_host_class_hid_protocol_get(UX_HOST_CLASS_HID *hid, USHORT *protocol) | ||
| { | ||
| /* Sanity check. */ | ||
| if (hid == UX_NULL || protocol == UX_NULL) | ||
| return(UX_INVALID_PARAMETER); | ||
|
|
||
| /* Invoke protocol get function. */ | ||
| return(_ux_host_class_hid_protocol_get(hid, protocol)); | ||
| } |
147 changes: 147 additions & 0 deletions
147
common/usbx_host_classes/src/ux_host_class_hid_protocol_set.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| /*************************************************************************** | ||
| * Copyright (c) 2024 Microsoft Corporation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the MIT License which is available at | ||
| * https://opensource.org/licenses/MIT. | ||
| * | ||
| * SPDX-License-Identifier: MIT | ||
| **************************************************************************/ | ||
|
|
||
|
|
||
| /**************************************************************************/ | ||
| /**************************************************************************/ | ||
| /** */ | ||
| /** USBX Component */ | ||
| /** */ | ||
| /** Host HID Class */ | ||
| /** */ | ||
| /**************************************************************************/ | ||
| /**************************************************************************/ | ||
|
|
||
| /* Include necessary system files. */ | ||
|
|
||
| #define UX_SOURCE_CODE | ||
|
|
||
| #include "ux_api.h" | ||
| #include "ux_host_class_hid.h" | ||
| #include "ux_host_stack.h" | ||
|
|
||
| /**************************************************************************/ | ||
| /* */ | ||
| /* FUNCTION RELEASE */ | ||
| /* */ | ||
| /* _ux_host_class_hid_protocol_set PORTABLE C */ | ||
| /* */ | ||
| /* DESCRIPTION */ | ||
| /* */ | ||
| /* This function performs a SET_PROTOCOL to the HID device to switch */ | ||
| /* between BOOT (0) and REPORT (1) protocols. */ | ||
| /* */ | ||
| /* INPUT */ | ||
| /* */ | ||
| /* hid Pointer to HID class */ | ||
| /* protocol Protocol (BOOT/REPORT) */ | ||
| /* */ | ||
| /* OUTPUT */ | ||
| /* */ | ||
| /* Completion Status */ | ||
| /* */ | ||
| /* CALLED BY */ | ||
| /* */ | ||
| /* Application */ | ||
| /* */ | ||
| /* RELEASE HISTORY */ | ||
| /* */ | ||
| /* DATE NAME DESCRIPTION */ | ||
| /* */ | ||
| /* 01-15-2026 Mohamed AYED Initial Version 6.4.6 */ | ||
| /* */ | ||
| /**************************************************************************/ | ||
| UINT _ux_host_class_hid_protocol_set(UX_HOST_CLASS_HID *hid, USHORT protocol) | ||
| { | ||
|
|
||
| UX_ENDPOINT *control_endpoint; | ||
| UX_TRANSFER *transfer_request; | ||
| UINT status; | ||
|
|
||
| /* 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) | ||
|
|
||
| /* Protect thread reentry to this instance. */ | ||
| status = _ux_host_semaphore_get(&hid -> ux_host_class_hid_semaphore, UX_WAIT_FOREVER); | ||
| if (status != UX_SUCCESS) | ||
| return(status); | ||
|
|
||
| #endif | ||
|
|
||
| /* Create a transfer request for the SET_PROTOCOL request. */ | ||
| transfer_request -> ux_transfer_request_data_pointer = UX_NULL; | ||
| transfer_request -> ux_transfer_request_requested_length = 0; | ||
| transfer_request -> ux_transfer_request_function = UX_HOST_CLASS_HID_SET_PROTOCOL; | ||
| transfer_request -> ux_transfer_request_type = UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE; | ||
| transfer_request -> ux_transfer_request_value = (UINT)protocol; | ||
| transfer_request -> ux_transfer_request_index = hid -> ux_host_class_hid_interface -> ux_interface_descriptor.bInterfaceNumber; | ||
|
|
||
| /* Send request to HCD layer. */ | ||
| status = _ux_host_stack_transfer_request(transfer_request); | ||
|
|
||
| #if !defined(UX_HOST_STANDALONE) | ||
| /* Unprotect thread reentry to this instance. */ | ||
| _ux_host_semaphore_put(&hid -> ux_host_class_hid_semaphore); | ||
| #endif | ||
|
|
||
| /* Return the function status. */ | ||
| return(status); | ||
| } | ||
|
|
||
| /**************************************************************************/ | ||
| /* */ | ||
| /* FUNCTION RELEASE */ | ||
| /* */ | ||
| /* _uxe_host_class_hid_protocol_set PORTABLE C */ | ||
| /* */ | ||
| /* DESCRIPTION */ | ||
| /* */ | ||
| /* This function checks errors in HID protocol set function call. */ | ||
| /* */ | ||
| /* INPUT */ | ||
| /* */ | ||
| /* hid Pointer to HID class */ | ||
| /* protocol Protocol (BOOT/REPORT) */ | ||
| /* */ | ||
| /* OUTPUT */ | ||
| /* */ | ||
| /* Status */ | ||
| /* */ | ||
| /**************************************************************************/ | ||
| UINT _uxe_host_class_hid_protocol_set(UX_HOST_CLASS_HID *hid, USHORT protocol) | ||
| { | ||
| /* Sanity check. */ | ||
| if (hid == UX_NULL) | ||
| return(UX_INVALID_PARAMETER); | ||
|
|
||
| /* Validate protocol value: must be BOOT(0) or REPORT(1). */ | ||
| if (protocol != UX_HOST_CLASS_HID_PROTOCOL_BOOT && | ||
| protocol != UX_HOST_CLASS_HID_PROTOCOL_REPORT) | ||
| return(UX_INVALID_PARAMETER); | ||
|
|
||
| /* Invoke protocol set function. */ | ||
| return(_ux_host_class_hid_protocol_set(hid, protocol)); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.