1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 /**************************************************************************/
13 /**                                                                       */
14 /** USBX Component                                                        */
15 /**                                                                       */
16 /**   Device HID Class                                                    */
17 /**                                                                       */
18 /**************************************************************************/
19 /**************************************************************************/
20 
21 #define UX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "ux_api.h"
27 #include "ux_device_class_hid.h"
28 #include "ux_device_stack.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _ux_device_class_hid_uninitialize                   PORTABLE C      */
36 /*                                                           6.1.12       */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function uninitializes the USB HID device.                     */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    command                              Pointer to hid command         */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    Completion Status                                                   */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    _ux_device_thread_delete             Remove storage thread.         */
56 /*    _ux_utility_memory_free              Free memory used by storage    */
57 /*    _ux_utility_event_flags_delete       Remove flag event structure    */
58 /*                                                                        */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    USBX Source Code                                                    */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
69 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
72 /*                                            added standalone support,   */
73 /*                                            added interrupt OUT support,*/
74 /*                                            resulting in version 6.1.10 */
75 /*  04-25-2022     Chaoqiong Xiao           Modified comment(s),          */
76 /*                                            resulting in version 6.1.11 */
77 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
78 /*                                            fixed parameter/variable    */
79 /*                                            names conflict C++ keyword, */
80 /*                                            resulting in version 6.1.12 */
81 /*                                                                        */
82 /**************************************************************************/
_ux_device_class_hid_uninitialize(UX_SLAVE_CLASS_COMMAND * command)83 UINT  _ux_device_class_hid_uninitialize(UX_SLAVE_CLASS_COMMAND *command)
84 {
85 
86 UX_SLAVE_CLASS_HID                      *hid;
87 UX_SLAVE_CLASS                          *class_ptr;
88 
89 
90     /* Get the class container.  */
91     class_ptr =  command -> ux_slave_class_command_class_ptr;
92 
93     /* Get the class instance in the container.  */
94     hid = (UX_SLAVE_CLASS_HID *) class_ptr -> ux_slave_class_instance;
95 
96 #if !defined(UX_DEVICE_STANDALONE)
97 
98     /* Remove HID thread.  */
99     _ux_device_thread_delete(&class_ptr -> ux_slave_class_thread);
100 
101     /* Remove the thread used by HID.  */
102     _ux_utility_memory_free(class_ptr -> ux_slave_class_thread_stack);
103 
104     /* Delete the event flag group for the hid class.  */
105     _ux_device_event_flags_delete(&hid -> ux_device_class_hid_event_flags_group);
106 #endif
107 
108     /* Free memory for the array. */
109     _ux_utility_memory_free(hid -> ux_device_class_hid_event_array);
110 
111 #if defined(UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT)
112 
113 #if !defined(UX_DEVICE_STANDALONE)
114 
115     /* Free read mutex.  */
116     _ux_device_mutex_delete(&hid -> ux_device_class_hid_read_mutex);
117 #endif
118 
119     /* Uninitialize receiver.  */
120     if (hid -> ux_device_class_hid_receiver)
121         hid -> ux_device_class_hid_receiver ->
122             ux_device_class_hid_receiver_uninitialize(hid -> ux_device_class_hid_receiver);
123 #endif
124 
125     /* Free the resources.  */
126     _ux_utility_memory_free(hid);
127 
128     /* Return completion status.  */
129     return(UX_SUCCESS);
130 }
131 
132