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 |
|
|
/** USBX Component */ |
14 |
|
|
/** */ |
15 |
|
|
/** Device HID Class */ |
16 |
|
|
/** */ |
17 |
|
|
/**************************************************************************/ |
18 |
|
|
/**************************************************************************/ |
19 |
|
|
|
20 |
|
|
#define UX_SOURCE_CODE |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
/* Include necessary system files. */ |
24 |
|
|
|
25 |
|
|
#include "ux_api.h" |
26 |
|
|
#include "ux_device_class_hid.h" |
27 |
|
|
#include "ux_device_stack.h" |
28 |
|
|
|
29 |
|
|
|
30 |
|
|
/**************************************************************************/ |
31 |
|
|
/* */ |
32 |
|
|
/* FUNCTION RELEASE */ |
33 |
|
|
/* */ |
34 |
|
|
/* _ux_device_class_hid_uninitialize PORTABLE C */ |
35 |
|
|
/* 6.x */ |
36 |
|
|
/* AUTHOR */ |
37 |
|
|
/* */ |
38 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
39 |
|
|
/* */ |
40 |
|
|
/* DESCRIPTION */ |
41 |
|
|
/* */ |
42 |
|
|
/* This function uninitializes the USB HID device. */ |
43 |
|
|
/* */ |
44 |
|
|
/* INPUT */ |
45 |
|
|
/* */ |
46 |
|
|
/* command Pointer to hid command */ |
47 |
|
|
/* */ |
48 |
|
|
/* OUTPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* Completion Status */ |
51 |
|
|
/* */ |
52 |
|
|
/* CALLS */ |
53 |
|
|
/* */ |
54 |
|
|
/* _ux_device_thread_delete Remove storage thread. */ |
55 |
|
|
/* _ux_utility_memory_free Free memory used by storage */ |
56 |
|
|
/* _ux_utility_event_flags_delete Remove flag event structure */ |
57 |
|
|
/* */ |
58 |
|
|
/* */ |
59 |
|
|
/* CALLED BY */ |
60 |
|
|
/* */ |
61 |
|
|
/* USBX Source Code */ |
62 |
|
|
/* */ |
63 |
|
|
/* RELEASE HISTORY */ |
64 |
|
|
/* */ |
65 |
|
|
/* DATE NAME DESCRIPTION */ |
66 |
|
|
/* */ |
67 |
|
|
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ |
68 |
|
|
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ |
69 |
|
|
/* resulting in version 6.1 */ |
70 |
|
|
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ |
71 |
|
|
/* added standalone support, */ |
72 |
|
|
/* added interrupt OUT support,*/ |
73 |
|
|
/* resulting in version 6.1.10 */ |
74 |
|
|
/* 04-25-2022 Chaoqiong Xiao Modified comment(s), */ |
75 |
|
|
/* resulting in version 6.1.11 */ |
76 |
|
|
/* 07-29-2022 Chaoqiong Xiao Modified comment(s), */ |
77 |
|
|
/* fixed parameter/variable */ |
78 |
|
|
/* names conflict C++ keyword, */ |
79 |
|
|
/* resulting in version 6.1.12 */ |
80 |
|
|
/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ |
81 |
|
|
/* added zero copy support, */ |
82 |
|
|
/* added a new mode to manage */ |
83 |
|
|
/* endpoint buffer in classes, */ |
84 |
|
|
/* resulting in version 6.3.0 */ |
85 |
|
|
/* xx-xx-xxxx Mohamed ayed Modified comment(s), */ |
86 |
|
|
/* added sanity check before */ |
87 |
|
|
/* freed hid memory, */ |
88 |
|
|
/* remove extra spaces, */ |
89 |
|
|
/* resulting in version 6.x */ |
90 |
|
|
/* */ |
91 |
|
|
/**************************************************************************/ |
92 |
|
158 |
UINT _ux_device_class_hid_uninitialize(UX_SLAVE_CLASS_COMMAND *command) |
93 |
|
|
{ |
94 |
|
|
|
95 |
|
|
UX_SLAVE_CLASS_HID *hid; |
96 |
|
|
UX_SLAVE_CLASS *class_ptr; |
97 |
|
|
|
98 |
|
|
|
99 |
|
|
/* Get the class container. */ |
100 |
|
158 |
class_ptr = command -> ux_slave_class_command_class_ptr; |
101 |
|
|
|
102 |
|
|
/* Get the class instance in the container. */ |
103 |
|
158 |
hid = (UX_SLAVE_CLASS_HID *) class_ptr -> ux_slave_class_instance; |
104 |
|
|
|
105 |
|
|
|
106 |
|
|
/* Sanity check. */ |
107 |
✓✗ |
158 |
if (hid != UX_NULL) |
108 |
|
|
{ |
109 |
|
|
|
110 |
|
|
#if !defined(UX_DEVICE_STANDALONE) |
111 |
|
|
|
112 |
|
|
/* Remove HID thread. */ |
113 |
|
158 |
_ux_device_thread_delete(&class_ptr -> ux_slave_class_thread); |
114 |
|
|
|
115 |
|
|
/* Remove the thread used by HID. */ |
116 |
|
158 |
_ux_utility_memory_free(class_ptr -> ux_slave_class_thread_stack); |
117 |
|
|
|
118 |
|
|
/* Delete the event flag group for the hid class. */ |
119 |
|
158 |
_ux_device_event_flags_delete(&hid -> ux_device_class_hid_event_flags_group); |
120 |
|
|
#endif |
121 |
|
|
|
122 |
|
|
/* Free memory for the array. */ |
123 |
|
|
#if (UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1) && defined(UX_DEVICE_CLASS_HID_ZERO_COPY) |
124 |
|
|
_ux_utility_memory_free(hid -> ux_device_class_hid_event_array -> ux_device_class_hid_event_buffer); |
125 |
|
|
#endif |
126 |
|
158 |
_ux_utility_memory_free(hid -> ux_device_class_hid_event_array); |
127 |
|
|
|
128 |
|
|
#if defined(UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT) |
129 |
|
|
|
130 |
|
|
#if !defined(UX_DEVICE_STANDALONE) |
131 |
|
|
|
132 |
|
|
/* Free read mutex. */ |
133 |
|
|
_ux_device_mutex_delete(&hid -> ux_device_class_hid_read_mutex); |
134 |
|
|
#endif |
135 |
|
|
|
136 |
|
|
/* Uninitialize receiver. */ |
137 |
|
|
if (hid -> ux_device_class_hid_receiver) |
138 |
|
|
hid -> ux_device_class_hid_receiver -> |
139 |
|
|
ux_device_class_hid_receiver_uninitialize(hid -> ux_device_class_hid_receiver); |
140 |
|
|
#endif |
141 |
|
|
|
142 |
|
|
#if defined(UX_DEVICE_CLASS_HID_OWN_ENDPOINT_BUFFER) |
143 |
|
|
_ux_utility_memory_free(hid -> ux_device_class_hid_endpoint_buffer); |
144 |
|
|
#endif |
145 |
|
|
|
146 |
|
|
/* Free the resources. */ |
147 |
|
158 |
_ux_utility_memory_free(hid); |
148 |
|
|
} |
149 |
|
|
/* Return completion status. */ |
150 |
|
158 |
return(UX_SUCCESS); |
151 |
|
|
} |
152 |
|
|
|