Add Host HID APIs to set/get protocol and and optional device HID changes protocol callback#244
Conversation
rahmanih
left a comment
There was a problem hiding this comment.
IIRC, this PR implements 2 features in HID Device and Host Classes.
please split them in separate commits.
in the simulator test, i test the callback with new apis |
|
the regression test updates can be made in a separate commit too. |
0f90e31 to
b024452
Compare
b024452 to
6ea0ac4
Compare
|
How to test: 1- Update middleware
|
ea1f53c to
9032773
Compare
… set/get protocol 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. - 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 comprehensive test to verify the new protocol callback functionality
9032773 to
63a0d44
Compare
|
@rahmanih: Please confirm whether I can merge this or not. Thanks. |
|
@ABOUSTM Could you please provide your review. |
Three bugs fixed in the new _ux_host_class_hid_protocol_get/set functions: 1. protocol_get: use a cache-safe allocated buffer for the DMA transfer instead of the caller's USHORT* directly. The caller's stack memory is not guaranteed to be DMA-safe on cache-incoherent embedded targets, and writing 1 byte into a USHORT* yields incorrect results on big-endian platforms. Follows the same pattern as ux_host_class_hid_idle_get. 2. Both functions: acquire ux_device_protection_semaphore in RTOS mode before submitting the transfer, in addition to the HID instance semaphore. All other control transfer functions (idle_get, idle_set) take both semaphores. Missing the device semaphore allowed concurrent callers to corrupt the shared transfer_request fields. 3. Both functions: add proper standalone (UX_HOST_STANDALONE) locking using UX_DISABLE/UX_RESTORE to atomically check and set UX_HOST_CLASS_HID_FLAG_LOCK and UX_DEVICE_FLAG_LOCK, and set UX_TRANSFER_FLAG_AUTO_DEVICE_UNLOCK + UX_TRANSFER_STATE_RESET on the transfer request before initiating. Follows the idle_get inline standalone pattern. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
I am merging into dev now, and this will ship with our Q2 2026 release next week. Please open a new PR if there are remaining issues with the code. |
Two issues discovered while reviewing and fixing thread-safety issues in the new ux_host_class_hid_protocol_get/set functions (PR #244). 1. idle_get.c: wrong operator acquires no lock in standalone mode Line 104 used '&= ~UX_HOST_CLASS_HID_FLAG_LOCK' (the release/clear operation) instead of '|= UX_HOST_CLASS_HID_FLAG_LOCK' (acquire/set). The preceding check correctly returns UX_BUSY when the flag is set, but the follow-on line then immediately clears it instead of setting it. The net effect is that the HID instance is never actually locked in UX_HOST_STANDALONE mode, making the mutual-exclusion check a no-op. 2. idle_set.c: standalone path used a blocking spin-loop The standalone branch called _ux_host_class_hid_idle_set_run() in a do/while loop, blocking the caller until the transfer completed. This is inconsistent with every other inline HID control-transfer function (idle_get, report_get, report_set, protocol_get, protocol_set) which all use the direct UX_DISABLE/UX_RESTORE atomic flag pattern and return UX_BUSY if the instance or device endpoint is already locked. Replaced with the same inline standalone locking pattern used by the other functions: atomic HID FLAG_LOCK acquire, atomic DEVICE_FLAG_LOCK acquire with AUTO_DEVICE_UNLOCK + UX_TRANSFER_STATE_RESET, and an AUTO_WAIT check at completion consistent with idle_get behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.