summaryrefslogtreecommitdiff
path: root/common/usbx_host_classes/src/ux_host_class_hid_mouse_callback.c
blob: 312bff1b3700193bf4a39d767f5abd739b45e465 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2026-present Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** USBX Component                                                        */
/**                                                                       */
/**   HID Mouse Client Class                                              */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/


/* Include necessary system files.  */

#define UX_SOURCE_CODE

#include "ux_api.h"
#include "ux_host_class_hid.h"
#include "ux_host_class_hid_mouse.h"
#include "ux_host_stack.h"


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _ux_host_class_hid_mouse_callback                   PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Chaoqiong Xiao, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function is the callback mechanism for a report registration.  */
/*    For the mouse, we filter the mouse coordinate changes and the       */
/*    state of the buttons.                                               */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    callback                              Pointer to callback           */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    None                                                                */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    None                                                                */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    HID Class                                                           */
/*                                                                        */
/**************************************************************************/
VOID  _ux_host_class_hid_mouse_callback(UX_HOST_CLASS_HID_REPORT_CALLBACK *callback)
{

UX_HOST_CLASS_HID_CLIENT    *hid_client;
UX_HOST_CLASS_HID_MOUSE     *mouse_instance;

    /* Get the HID client instance that issued the callback.  */
    hid_client =  callback -> ux_host_class_hid_report_callback_client;

    /* Get the mouse local instance */
    mouse_instance =  (UX_HOST_CLASS_HID_MOUSE *) hid_client -> ux_host_class_hid_client_local_instance;

    /* Analyze the usage we have received.  */
    switch (callback -> ux_host_class_hid_report_callback_usage)
    {


        /* X/Y Axis movement.  */
        case    UX_HOST_CLASS_HID_MOUSE_AXIS_X      :

            /* Add the deplacement to the position.  */
            mouse_instance -> ux_host_class_hid_mouse_x_position += (SCHAR) callback -> ux_host_class_hid_report_callback_value;

            break;

        case    UX_HOST_CLASS_HID_MOUSE_AXIS_Y      :

            /* Add the deplacement to the position.  */
            mouse_instance  -> ux_host_class_hid_mouse_y_position += (SCHAR) callback -> ux_host_class_hid_report_callback_value;
            break;

        /* Buttons.  */
        case    UX_HOST_CLASS_HID_MOUSE_BUTTON_1    :

            /* Check the state of button 1.  */
            if (callback -> ux_host_class_hid_report_callback_value == UX_TRUE)
                mouse_instance  -> ux_host_class_hid_mouse_buttons |= UX_HOST_CLASS_HID_MOUSE_BUTTON_1_PRESSED;
            else
                mouse_instance  -> ux_host_class_hid_mouse_buttons &= (ULONG)~UX_HOST_CLASS_HID_MOUSE_BUTTON_1_PRESSED;
            break;

        case    UX_HOST_CLASS_HID_MOUSE_BUTTON_2    :

            /* Check the state of button 2.  */
            if (callback -> ux_host_class_hid_report_callback_value == UX_TRUE)
                mouse_instance  -> ux_host_class_hid_mouse_buttons |= UX_HOST_CLASS_HID_MOUSE_BUTTON_2_PRESSED;
            else
                mouse_instance  -> ux_host_class_hid_mouse_buttons &= (ULONG)~UX_HOST_CLASS_HID_MOUSE_BUTTON_2_PRESSED;
            break;

        case    UX_HOST_CLASS_HID_MOUSE_BUTTON_3    :

            /* Check the state of button 3.  */
            if (callback -> ux_host_class_hid_report_callback_value == UX_TRUE)
                mouse_instance  -> ux_host_class_hid_mouse_buttons |= UX_HOST_CLASS_HID_MOUSE_BUTTON_3_PRESSED;
            else
                mouse_instance  -> ux_host_class_hid_mouse_buttons &= (ULONG)~UX_HOST_CLASS_HID_MOUSE_BUTTON_3_PRESSED;
            break;


        /* Wheel movement.  */
        case    UX_HOST_CLASS_HID_MOUSE_WHEEL      :

            mouse_instance -> ux_host_class_hid_mouse_wheel += (SCHAR) callback -> ux_host_class_hid_report_callback_value;

            break;

        default :

            /* We have received a Usage we don't know about. Ignore it.  */
            break;
    }

    /* Return to caller.  */
    return;
}