forked from eclipse-threadx/usbx
-
Notifications
You must be signed in to change notification settings - Fork 0
add optional hid set protocol callback #3
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
5
commits into
master
Choose a base branch
from
add_set_protocol_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
5 commits
Select commit
Hold shift + click to select a range
cd5f682
add optional hid set protocol callback
ayedm1 828a0fb
add host hid api to set/get protocol
ayedm1 c0d6a88
add Host hid apis to set/get protocol and a callback for device hid c…
ayedm1 1a1a7e6
Merge branch 'add_set_protocol_callback' of https://github.com/ayedm1…
ayedm1 8a7e153
Merge branch 'master' of https://github.com/ayedm1/eclipse_usbx into …
ayedm1 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
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.
145 changes: 145 additions & 0 deletions
145
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,145 @@ | ||
| /*************************************************************************** | ||
| * Copyright (c) 2025-present Eclipse ThreadX Contributors | ||
| * | ||
| * 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-10-2026 Mohamed AYED Initial Version 6.x */ | ||
| /**************************************************************************/ | ||
| 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 = 0x00; | ||
|
|
||
| /* 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)); | ||
| } |
148 changes: 148 additions & 0 deletions
148
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,148 @@ | ||
| /*************************************************************************** | ||
| * Copyright (c) 2025-present Eclipse ThreadX Contributors | ||
| * | ||
| * 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-10-2026 Mohamed AYED Initial Version 6.x */ | ||
| /**************************************************************************/ | ||
| 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)); | ||
| } |
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
Oops, something went wrong.
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 comment on line 370 describes the callback as being invoked when protocol changes between boot and report. However, it would be clearer to specify the exact values of the protocol parameter: "protocol is 0 for Boot or 1 for Report protocol" to match the USB HID specification.