GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hid_mouse_callback.c Lines: 31 31 100.0 %
Date: 2026-03-06 18:57:10 Branches: 13 13 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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
/**************************************************************************/
67
336
VOID  _ux_host_class_hid_mouse_callback(UX_HOST_CLASS_HID_REPORT_CALLBACK *callback)
68
{
69
70
UX_HOST_CLASS_HID_CLIENT    *hid_client;
71
UX_HOST_CLASS_HID_MOUSE     *mouse_instance;
72
73
    /* Get the HID client instance that issued the callback.  */
74
336
    hid_client =  callback -> ux_host_class_hid_report_callback_client;
75
76
    /* Get the mouse local instance */
77
336
    mouse_instance =  (UX_HOST_CLASS_HID_MOUSE *) hid_client -> ux_host_class_hid_client_local_instance;
78
79
    /* Analyze the usage we have received.  */
80

336
    switch (callback -> ux_host_class_hid_report_callback_usage)
81
    {
82
83
84
        /* X/Y Axis movement.  */
85
48
        case    UX_HOST_CLASS_HID_MOUSE_AXIS_X      :
86
87
            /* Add the deplacement to the position.  */
88
48
            mouse_instance -> ux_host_class_hid_mouse_x_position += (SCHAR) callback -> ux_host_class_hid_report_callback_value;
89
90
48
            break;
91
92
48
        case    UX_HOST_CLASS_HID_MOUSE_AXIS_Y      :
93
94
            /* Add the deplacement to the position.  */
95
48
            mouse_instance  -> ux_host_class_hid_mouse_y_position += (SCHAR) callback -> ux_host_class_hid_report_callback_value;
96
48
            break;
97
98
        /* Buttons.  */
99
48
        case    UX_HOST_CLASS_HID_MOUSE_BUTTON_1    :
100
101
            /* Check the state of button 1.  */
102
48
            if (callback -> ux_host_class_hid_report_callback_value == UX_TRUE)
103
24
                mouse_instance  -> ux_host_class_hid_mouse_buttons |= UX_HOST_CLASS_HID_MOUSE_BUTTON_1_PRESSED;
104
            else
105
24
                mouse_instance  -> ux_host_class_hid_mouse_buttons &= (ULONG)~UX_HOST_CLASS_HID_MOUSE_BUTTON_1_PRESSED;
106
48
            break;
107
108
48
        case    UX_HOST_CLASS_HID_MOUSE_BUTTON_2    :
109
110
            /* Check the state of button 2.  */
111
48
            if (callback -> ux_host_class_hid_report_callback_value == UX_TRUE)
112
24
                mouse_instance  -> ux_host_class_hid_mouse_buttons |= UX_HOST_CLASS_HID_MOUSE_BUTTON_2_PRESSED;
113
            else
114
24
                mouse_instance  -> ux_host_class_hid_mouse_buttons &= (ULONG)~UX_HOST_CLASS_HID_MOUSE_BUTTON_2_PRESSED;
115
48
            break;
116
117
48
        case    UX_HOST_CLASS_HID_MOUSE_BUTTON_3    :
118
119
            /* Check the state of button 3.  */
120
48
            if (callback -> ux_host_class_hid_report_callback_value == UX_TRUE)
121
24
                mouse_instance  -> ux_host_class_hid_mouse_buttons |= UX_HOST_CLASS_HID_MOUSE_BUTTON_3_PRESSED;
122
            else
123
24
                mouse_instance  -> ux_host_class_hid_mouse_buttons &= (ULONG)~UX_HOST_CLASS_HID_MOUSE_BUTTON_3_PRESSED;
124
48
            break;
125
126
127
        /* Wheel movement.  */
128
48
        case    UX_HOST_CLASS_HID_MOUSE_WHEEL      :
129
130
48
            mouse_instance -> ux_host_class_hid_mouse_wheel += (SCHAR) callback -> ux_host_class_hid_report_callback_value;
131
132
48
            break;
133
134
48
        default :
135
136
            /* We have received a Usage we don't know about. Ignore it.  */
137
48
            break;
138
    }
139
140
    /* Return to caller.  */
141
336
    return;
142
}
143