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 /**************************************************************************/
15 /** */
16 /** USBX Component */
17 /** */
18 /** HID Keyboard Client */
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_class_hid_keyboard.h"
31 #include "ux_host_stack.h"
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _ux_host_class_hid_keyboard_deactivate PORTABLE C */
39 /* 6.1.11 */
40 /* AUTHOR */
41 /* */
42 /* Chaoqiong Xiao, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function performs the deactivation of a HID Keyboard Client. */
47 /* */
48 /* INPUT */
49 /* */
50 /* command Pointer to command */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* Completion Status */
55 /* */
56 /* CALLS */
57 /* */
58 /* _ux_host_class_hid_periodic_report_stop */
59 /* Stop periodic report */
60 /* _ux_utility_memory_free Release memory block */
61 /* _ux_host_semaphore_delete Delete semaphore */
62 /* _ux_utility_thread_delete Delete thread */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* HID Class */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
73 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
74 /* resulting in version 6.1 */
75 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
76 /* added standalone support, */
77 /* resulting in version 6.1.10 */
78 /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */
79 /* internal clean up, */
80 /* resulting in version 6.1.11 */
81 /* */
82 /**************************************************************************/
_ux_host_class_hid_keyboard_deactivate(UX_HOST_CLASS_HID_CLIENT_COMMAND * command)83 UINT _ux_host_class_hid_keyboard_deactivate(UX_HOST_CLASS_HID_CLIENT_COMMAND *command)
84 {
85
86 UX_HOST_CLASS_HID *hid;
87 UX_HOST_CLASS_HID_CLIENT *hid_client;
88 UX_HOST_CLASS_HID_KEYBOARD *keyboard_instance;
89 UINT status = UX_SUCCESS;
90
91
92 /* Get the instance to the HID class. */
93 hid = command -> ux_host_class_hid_client_command_instance;
94
95 /* Stop the periodic report. */
96 _ux_host_class_hid_periodic_report_stop(hid);
97
98 /* Get the HID client pointer. */
99 hid_client = hid -> ux_host_class_hid_client;
100
101 /* Get the remote control local instance. */
102 keyboard_instance = (UX_HOST_CLASS_HID_KEYBOARD *) hid_client -> ux_host_class_hid_client_local_instance;
103
104 #if !defined(UX_HOST_STANDALONE)
105
106 /* Stop the semaphore. */
107 status = _ux_host_semaphore_delete(&keyboard_instance -> ux_host_class_hid_keyboard_semaphore);
108
109 /* Terminate the thread. */
110 _ux_utility_thread_delete(&keyboard_instance -> ux_host_class_hid_keyboard_thread);
111
112 /* Return to the pool the thread stack. */
113 _ux_utility_memory_free(keyboard_instance -> ux_host_class_hid_keyboard_thread_stack);
114 #endif
115
116 /* Free memory for key states. */
117 _ux_utility_memory_free(keyboard_instance -> ux_host_class_hid_keyboard_key_state);
118
119 /* If trace is enabled, insert this event into the trace buffer. */
120 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_HID_KEYBOARD_DEACTIVATE, hid, keyboard_instance, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
121
122 /* Unload all the memory used by the keyboard client. */
123 _ux_utility_memory_free(keyboard_instance -> ux_host_class_hid_keyboard_usage_array);
124
125 /* Now free the instance memory. */
126 _ux_utility_memory_free(hid_client -> ux_host_class_hid_client_local_instance);
127
128 /* We may need to inform the application
129 if a function has been programmed in the system structure. */
130 if (_ux_system_host -> ux_system_host_change_function != UX_NULL)
131 {
132
133 /* Call system change function. */
134 _ux_system_host -> ux_system_host_change_function(UX_HID_CLIENT_REMOVAL, hid -> ux_host_class_hid_class, (VOID *) hid_client);
135 }
136
137 /* Return completion status. */
138 return(status);
139 }
140
141