1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** USBX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** HID Class */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
/**************************************************************************/ |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#define UX_SOURCE_CODE |
27 |
|
|
|
28 |
|
|
#include "ux_api.h" |
29 |
|
|
#include "ux_host_class_hid.h" |
30 |
|
|
#include "ux_host_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_host_class_hid_interrupt_endpoint_search PORTABLE C */ |
38 |
|
|
/* 6.1.12 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function searches for the handle of the only interrupt */ |
46 |
|
|
/* endpoint in the default alternate setting of the HID interface. */ |
47 |
|
|
/* The interrupt endpoint should always be there. The actual first */ |
48 |
|
|
/* transfer on the interrupt endpoint does not start until a HID */ |
49 |
|
|
/* client has claimed ownership of the HID device. */ |
50 |
|
|
/* */ |
51 |
|
|
/* INPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* hid Pointer to HID class */ |
54 |
|
|
/* */ |
55 |
|
|
/* OUTPUT */ |
56 |
|
|
/* */ |
57 |
|
|
/* Completion Status */ |
58 |
|
|
/* */ |
59 |
|
|
/* CALLS */ |
60 |
|
|
/* */ |
61 |
|
|
/* _ux_utility_memory_allocate Allocate memory block */ |
62 |
|
|
/* */ |
63 |
|
|
/* CALLED BY */ |
64 |
|
|
/* */ |
65 |
|
|
/* HID Class */ |
66 |
|
|
/* */ |
67 |
|
|
/**************************************************************************/ |
68 |
|
294 |
UINT _ux_host_class_hid_interrupt_endpoint_search(UX_HOST_CLASS_HID *hid) |
69 |
|
|
{ |
70 |
|
|
|
71 |
|
294 |
UINT status = UX_ENDPOINT_HANDLE_UNKNOWN; |
72 |
|
|
UX_INTERFACE *interface_ptr; |
73 |
|
|
UX_ENDPOINT *endpoint; |
74 |
|
|
UX_TRANSFER *transfer_request; |
75 |
|
|
|
76 |
|
|
|
77 |
|
|
/* Search the interrupt endpoint. It is attached to the interface container. */ |
78 |
|
294 |
interface_ptr = hid -> ux_host_class_hid_interface; |
79 |
|
294 |
endpoint = interface_ptr -> ux_interface_first_endpoint; |
80 |
✓✓ |
306 |
while(endpoint != UX_NULL) |
81 |
|
|
{ |
82 |
|
|
|
83 |
|
|
/* Find interrupt IN endpoint. */ |
84 |
✓✓ |
294 |
if (((endpoint -> ux_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_IN) && |
85 |
✓✓ |
289 |
((endpoint -> ux_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_INTERRUPT_ENDPOINT)) |
86 |
|
|
{ |
87 |
|
|
|
88 |
|
|
/* The endpoint is correct, save it. */ |
89 |
|
282 |
hid -> ux_host_class_hid_interrupt_endpoint = endpoint; |
90 |
|
|
|
91 |
|
|
/* Fill in the transfer request with the length requested for this endpoint. */ |
92 |
|
282 |
transfer_request = &endpoint -> ux_endpoint_transfer_request; |
93 |
|
282 |
transfer_request -> ux_transfer_request_requested_length = hid -> ux_host_class_hid_interrupt_endpoint -> ux_endpoint_descriptor.wMaxPacketSize; |
94 |
|
282 |
transfer_request -> ux_transfer_request_actual_length = 0; |
95 |
|
|
|
96 |
|
|
/* The direction is always IN for the HID interrupt endpoint. */ |
97 |
|
282 |
transfer_request -> ux_transfer_request_type = UX_REQUEST_IN; |
98 |
|
|
|
99 |
|
|
/* There is a callback function associated with the transfer request, so we need the class instance. */ |
100 |
|
282 |
transfer_request -> ux_transfer_request_class_instance = (VOID *) hid; |
101 |
|
|
|
102 |
|
|
/* Interrupt transactions have a completion routine. */ |
103 |
|
282 |
transfer_request -> ux_transfer_request_completion_function = _ux_host_class_hid_transfer_request_completed; |
104 |
|
|
|
105 |
|
|
/* Transfer timeout : wait forever. */ |
106 |
|
282 |
transfer_request -> ux_transfer_request_timeout_value = UX_WAIT_FOREVER; |
107 |
|
|
|
108 |
|
|
/* Obtain a buffer for this transaction. The buffer will always be reused. */ |
109 |
|
282 |
transfer_request -> ux_transfer_request_data_pointer = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, |
110 |
|
|
transfer_request -> ux_transfer_request_requested_length); |
111 |
|
|
|
112 |
|
|
/* If the endpoint is available and we have memory, we mark the interrupt endpoint as ready. */ |
113 |
✓✓ |
282 |
if (transfer_request -> ux_transfer_request_data_pointer != UX_NULL) |
114 |
|
|
{ |
115 |
|
275 |
hid -> ux_host_class_hid_interrupt_endpoint_status = UX_HOST_CLASS_HID_INTERRUPT_ENDPOINT_READY; |
116 |
|
275 |
status = UX_SUCCESS; |
117 |
|
|
#if !defined(UX_HOST_CLASS_HID_INTERRUPT_OUT_SUPPORT) |
118 |
|
|
|
119 |
|
|
/* We have found the interrupt IN endpoint, just stop searching. */ |
120 |
|
275 |
break; |
121 |
|
|
#endif |
122 |
|
|
} |
123 |
|
|
else |
124 |
|
|
{ |
125 |
|
7 |
status = UX_MEMORY_INSUFFICIENT; |
126 |
|
7 |
break; |
127 |
|
|
} |
128 |
|
|
} |
129 |
|
|
#if defined(UX_HOST_CLASS_HID_INTERRUPT_OUT_SUPPORT) |
130 |
|
|
else if (((endpoint -> ux_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_OUT) && |
131 |
|
|
((endpoint -> ux_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_INTERRUPT_ENDPOINT)) |
132 |
|
|
{ |
133 |
|
|
|
134 |
|
|
/* Found the interrupt OUT endpoint, save it. */ |
135 |
|
|
hid -> ux_host_class_hid_interrupt_out_endpoint = endpoint; |
136 |
|
|
} |
137 |
|
|
#endif |
138 |
|
|
|
139 |
|
|
/* Check next endpoint. */ |
140 |
|
12 |
endpoint = endpoint -> ux_endpoint_next_endpoint; |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
/* Return completion status. */ |
144 |
|
294 |
return(status); |
145 |
|
|
} |
146 |
|
|
|