|
| 1 | +/*************************************************************************** |
| 2 | + * Copyright (c) 2024 Microsoft Corporation |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the MIT License which is available at |
| 6 | + * https://opensource.org/licenses/MIT. |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: MIT |
| 9 | + **************************************************************************/ |
| 10 | + |
| 11 | + |
| 12 | +/**************************************************************************/ |
| 13 | +/**************************************************************************/ |
| 14 | +/** */ |
| 15 | +/** USBX Component */ |
| 16 | +/** */ |
| 17 | +/** Host HID Class */ |
| 18 | +/** */ |
| 19 | +/**************************************************************************/ |
| 20 | +/**************************************************************************/ |
| 21 | + |
| 22 | +/* Include necessary system files. */ |
| 23 | + |
| 24 | +#define UX_SOURCE_CODE |
| 25 | + |
| 26 | +#include "ux_api.h" |
| 27 | +#include "ux_host_class_hid.h" |
| 28 | +#include "ux_host_stack.h" |
| 29 | + |
| 30 | +/**************************************************************************/ |
| 31 | +/* */ |
| 32 | +/* FUNCTION RELEASE */ |
| 33 | +/* */ |
| 34 | +/* _ux_host_class_hid_protocol_set PORTABLE C */ |
| 35 | +/* */ |
| 36 | +/* DESCRIPTION */ |
| 37 | +/* */ |
| 38 | +/* This function performs a SET_PROTOCOL to the HID device to switch */ |
| 39 | +/* between BOOT (0) and REPORT (1) protocols. */ |
| 40 | +/* */ |
| 41 | +/* INPUT */ |
| 42 | +/* */ |
| 43 | +/* hid Pointer to HID class */ |
| 44 | +/* protocol Protocol (BOOT/REPORT) */ |
| 45 | +/* */ |
| 46 | +/* OUTPUT */ |
| 47 | +/* */ |
| 48 | +/* Completion Status */ |
| 49 | +/* */ |
| 50 | +/**************************************************************************/ |
| 51 | +UINT _ux_host_class_hid_protocol_set(UX_HOST_CLASS_HID *hid, USHORT protocol) |
| 52 | +{ |
| 53 | + |
| 54 | +UX_ENDPOINT *control_endpoint; |
| 55 | +UX_TRANSFER *transfer_request; |
| 56 | +UINT status; |
| 57 | + |
| 58 | + /* Ensure the instance is valid. */ |
| 59 | + if (_ux_host_stack_class_instance_verify(_ux_system_host_class_hid_name, (VOID *) hid) != UX_SUCCESS) |
| 60 | + { |
| 61 | + |
| 62 | + /* If trace is enabled, insert this event into the trace buffer. */ |
| 63 | + UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0) |
| 64 | + |
| 65 | +#if defined(UX_HOST_STANDALONE) |
| 66 | + hid -> ux_host_class_hid_status = UX_HOST_CLASS_INSTANCE_UNKNOWN; |
| 67 | +#endif |
| 68 | + return(UX_HOST_CLASS_INSTANCE_UNKNOWN); |
| 69 | + } |
| 70 | + |
| 71 | + /* Get the default control endpoint transfer request pointer. */ |
| 72 | + control_endpoint = &hid -> ux_host_class_hid_device -> ux_device_control_endpoint; |
| 73 | + transfer_request = &control_endpoint -> ux_endpoint_transfer_request; |
| 74 | + |
| 75 | + |
| 76 | +#if !defined(UX_HOST_STANDALONE) |
| 77 | + |
| 78 | + /* Protect thread reentry to this instance. */ |
| 79 | + status = _ux_host_semaphore_get(&hid -> ux_host_class_hid_semaphore, UX_WAIT_FOREVER); |
| 80 | + if (status != UX_SUCCESS) |
| 81 | + return(status); |
| 82 | + |
| 83 | +#endif |
| 84 | + |
| 85 | + /* Create a transfer request for the SET_PROTOCOL request. */ |
| 86 | + transfer_request -> ux_transfer_request_data_pointer = UX_NULL; |
| 87 | + transfer_request -> ux_transfer_request_requested_length = 0; |
| 88 | + transfer_request -> ux_transfer_request_function = UX_HOST_CLASS_HID_SET_PROTOCOL; |
| 89 | + transfer_request -> ux_transfer_request_type = UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE; |
| 90 | + transfer_request -> ux_transfer_request_value = (UINT)protocol; |
| 91 | + transfer_request -> ux_transfer_request_index = hid -> ux_host_class_hid_interface -> ux_interface_descriptor.bInterfaceNumber; |
| 92 | + |
| 93 | + /* Send request to HCD layer. */ |
| 94 | + status = _ux_host_stack_transfer_request(transfer_request); |
| 95 | + |
| 96 | +#if !defined(UX_HOST_STANDALONE) |
| 97 | + /* Unprotect thread reentry to this instance. */ |
| 98 | + _ux_host_semaphore_put(&hid -> ux_host_class_hid_semaphore); |
| 99 | +#endif |
| 100 | + |
| 101 | + /* Return the function status. */ |
| 102 | + return(status); |
| 103 | +} |
| 104 | + |
| 105 | +/**************************************************************************/ |
| 106 | +/* */ |
| 107 | +/* FUNCTION RELEASE */ |
| 108 | +/* */ |
| 109 | +/* _uxe_host_class_hid_protocol_set PORTABLE C */ |
| 110 | +/* */ |
| 111 | +/* DESCRIPTION */ |
| 112 | +/* */ |
| 113 | +/* This function checks errors in HID protocol set function call. */ |
| 114 | +/* */ |
| 115 | +/* INPUT */ |
| 116 | +/* */ |
| 117 | +/* hid Pointer to HID class */ |
| 118 | +/* protocol Protocol (BOOT/REPORT) */ |
| 119 | +/* */ |
| 120 | +/* OUTPUT */ |
| 121 | +/* */ |
| 122 | +/* Status */ |
| 123 | +/* */ |
| 124 | +/**************************************************************************/ |
| 125 | +UINT _uxe_host_class_hid_protocol_set(UX_HOST_CLASS_HID *hid, USHORT protocol) |
| 126 | +{ |
| 127 | + /* Sanity check. */ |
| 128 | + if (hid == UX_NULL) |
| 129 | + return(UX_INVALID_PARAMETER); |
| 130 | + |
| 131 | + /* Validate protocol value: must be BOOT(0) or REPORT(1). */ |
| 132 | + if (protocol != UX_HOST_CLASS_HID_PROTOCOL_BOOT && |
| 133 | + protocol != UX_HOST_CLASS_HID_PROTOCOL_REPORT) |
| 134 | + return(UX_INVALID_PARAMETER); |
| 135 | + |
| 136 | + /* Invoke protocol set function. */ |
| 137 | + return(_ux_host_class_hid_protocol_set(hid, protocol)); |
| 138 | +} |
0 commit comments