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 Mouse Client 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_class_hid_mouse.h"
31 #include "ux_host_stack.h"
32 
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _ux_host_class_hid_mouse_callback                   PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Chaoqiong Xiao, Microsoft Corporation                               */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function is the callback mechanism for a report registration.  */
47 /*    For the mouse, we filter the mouse coordinate changes and the       */
48 /*    state of the buttons.                                               */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    callback                              Pointer to callback           */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    None                                                                */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    None                                                                */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    HID Class                                                           */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
71 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*                                                                        */
74 /**************************************************************************/
_ux_host_class_hid_mouse_callback(UX_HOST_CLASS_HID_REPORT_CALLBACK * callback)75 VOID  _ux_host_class_hid_mouse_callback(UX_HOST_CLASS_HID_REPORT_CALLBACK *callback)
76 {
77 
78 UX_HOST_CLASS_HID_CLIENT    *hid_client;
79 UX_HOST_CLASS_HID_MOUSE     *mouse_instance;
80 
81     /* Get the HID client instance that issued the callback.  */
82     hid_client =  callback -> ux_host_class_hid_report_callback_client;
83 
84     /* Get the mouse local instance */
85     mouse_instance =  (UX_HOST_CLASS_HID_MOUSE *) hid_client -> ux_host_class_hid_client_local_instance;
86 
87     /* Analyze the usage we have received.  */
88     switch (callback -> ux_host_class_hid_report_callback_usage)
89     {
90 
91 
92         /* X/Y Axis movement.  */
93         case    UX_HOST_CLASS_HID_MOUSE_AXIS_X      :
94 
95             /* Add the deplacement to the position.  */
96             mouse_instance -> ux_host_class_hid_mouse_x_position += (SCHAR) callback -> ux_host_class_hid_report_callback_value;
97 
98             break;
99 
100         case    UX_HOST_CLASS_HID_MOUSE_AXIS_Y      :
101 
102             /* Add the deplacement to the position.  */
103             mouse_instance  -> ux_host_class_hid_mouse_y_position += (SCHAR) callback -> ux_host_class_hid_report_callback_value;
104             break;
105 
106         /* Buttons.  */
107         case    UX_HOST_CLASS_HID_MOUSE_BUTTON_1    :
108 
109             /* Check the state of button 1.  */
110             if (callback -> ux_host_class_hid_report_callback_value == UX_TRUE)
111                 mouse_instance  -> ux_host_class_hid_mouse_buttons |= UX_HOST_CLASS_HID_MOUSE_BUTTON_1_PRESSED;
112             else
113                 mouse_instance  -> ux_host_class_hid_mouse_buttons &= (ULONG)~UX_HOST_CLASS_HID_MOUSE_BUTTON_1_PRESSED;
114             break;
115 
116         case    UX_HOST_CLASS_HID_MOUSE_BUTTON_2    :
117 
118             /* Check the state of button 2.  */
119             if (callback -> ux_host_class_hid_report_callback_value == UX_TRUE)
120                 mouse_instance  -> ux_host_class_hid_mouse_buttons |= UX_HOST_CLASS_HID_MOUSE_BUTTON_2_PRESSED;
121             else
122                 mouse_instance  -> ux_host_class_hid_mouse_buttons &= (ULONG)~UX_HOST_CLASS_HID_MOUSE_BUTTON_2_PRESSED;
123             break;
124 
125         case    UX_HOST_CLASS_HID_MOUSE_BUTTON_3    :
126 
127             /* Check the state of button 3.  */
128             if (callback -> ux_host_class_hid_report_callback_value == UX_TRUE)
129                 mouse_instance  -> ux_host_class_hid_mouse_buttons |= UX_HOST_CLASS_HID_MOUSE_BUTTON_3_PRESSED;
130             else
131                 mouse_instance  -> ux_host_class_hid_mouse_buttons &= (ULONG)~UX_HOST_CLASS_HID_MOUSE_BUTTON_3_PRESSED;
132             break;
133 
134 
135         /* Wheel movement.  */
136         case    UX_HOST_CLASS_HID_MOUSE_WHEEL      :
137 
138             mouse_instance -> ux_host_class_hid_mouse_wheel += (SCHAR) callback -> ux_host_class_hid_report_callback_value;
139 
140             break;
141 
142         default :
143 
144             /* We have received a Usage we don't know about. Ignore it.  */
145             break;
146     }
147 
148     /* Return to caller.  */
149     return;
150 }
151 
152