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 /**   HID Mouse Client Class                                              */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /* Include necessary system files.  */
24 
25 #define UX_SOURCE_CODE
26 
27 #include "ux_api.h"
28 #include "ux_host_class_hid.h"
29 #include "ux_host_class_hid_mouse.h"
30 #include "ux_host_stack.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _ux_host_class_hid_mouse_deactivate                 PORTABLE C      */
38 /*                                                           6.3.0        */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function performs the deactivation of a HID mouse.             */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    command                               Pointer to command            */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    Completion Status                                                   */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    _ux_host_class_hid_periodic_report_stop                             */
58 /*                                          Stop periodic report          */
59 /*    _ux_utility_memory_free               Free memory block             */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    HID Mouse Class                                                     */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
70 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*  10-31-2023     Chaoqiong Xiao           Modified comment(s),          */
73 /*                                            improved unload sequence,   */
74 /*                                            resulting in version 6.3.0  */
75 /*                                                                        */
76 /**************************************************************************/
_ux_host_class_hid_mouse_deactivate(UX_HOST_CLASS_HID_CLIENT_COMMAND * command)77 UINT  _ux_host_class_hid_mouse_deactivate(UX_HOST_CLASS_HID_CLIENT_COMMAND  *command)
78 {
79 
80 UX_HOST_CLASS_HID           *hid;
81 UX_HOST_CLASS_HID_CLIENT    *hid_client;
82 UINT                        status;
83 
84 
85     /* Get the instance to the HID class.  */
86     hid =  command -> ux_host_class_hid_client_command_instance;
87 
88     /* Stop the periodic report.  */
89     status =  _ux_host_class_hid_periodic_report_stop(hid);
90 
91     /* Get the HID client pointer.  */
92     hid_client =  hid -> ux_host_class_hid_client;
93 
94     /* If trace is enabled, insert this event into the trace buffer.  */
95     UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_HID_MOUSE_DEACTIVATE, hid, hid_client -> ux_host_class_hid_client_local_instance, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
96 
97     /* We may need to inform the application
98        if a function has been programmed in the system structure.  */
99     if (_ux_system_host -> ux_system_host_change_function != UX_NULL)
100     {
101 
102         /* Call system change function.  */
103         _ux_system_host ->  ux_system_host_change_function(UX_HID_CLIENT_REMOVAL, hid -> ux_host_class_hid_class, (VOID *) hid_client);
104     }
105 
106     /* Now free the instance memory.  */
107     _ux_utility_memory_free(hid_client -> ux_host_class_hid_client_local_instance);
108 
109     /* Return completion status.  */
110     return(status);
111 }
112 
113