GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hid_keyboard_key_get.c Lines: 17 22 77.3 %
Date: 2024-12-12 17:16:36 Branches: 6 14 42.9 %

Line Branch Exec Source
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 Remote Control 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_keyboard.h"
30
#include "ux_host_stack.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _ux_host_class_hid_keyboard_key_get                 PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function reads the key and keyboard state from the             */
46
/*    round-robin buffer.                                                 */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    keyboard_instance                     Pointer to remote control     */
51
/*    keyboard key                          Pointer to keyboard key       */
52
/*    keyboard state                        Pointer to keyboard state     */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    Completion Status                                                   */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _ux_host_stack_class_instance_verify  Verify instance               */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    User application                                                    */
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
/**************************************************************************/
75
4447
UINT  _ux_host_class_hid_keyboard_key_get(UX_HOST_CLASS_HID_KEYBOARD *keyboard_instance,
76
                                            ULONG *keyboard_key, ULONG *keyboard_state)
77
{
78
79
ULONG               *array_head;
80
ULONG               *array_tail;
81
ULONG               *array_end;
82
ULONG               *array_start;
83
UX_HOST_CLASS_HID   *hid;
84
85
    /* Get the HID class associated with the HID client. */
86
4447
    hid = keyboard_instance -> ux_host_class_hid_keyboard_hid;
87
88
    /* Ensure the instance is valid.  */
89
4447
    if (_ux_host_stack_class_instance_verify(_ux_system_host_class_hid_name, (VOID *) hid) != UX_SUCCESS)
90
    {
91
92
        /* If trace is enabled, insert this event into the trace buffer.  */
93
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)
94
95
1
        return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
96
    }
97
98
    /* Load the keyboard key and state from the usage array .  */
99
4446
    array_start =  keyboard_instance -> ux_host_class_hid_keyboard_usage_array;
100
4446
    array_end =    array_start + UX_HOST_CLASS_HID_KEYBOARD_USAGE_ARRAY_LENGTH;
101
4446
    array_head =   keyboard_instance -> ux_host_class_hid_keyboard_usage_array_head;
102
4446
    array_tail =   keyboard_instance -> ux_host_class_hid_keyboard_usage_array_tail;
103
104
    /* We want to extract a usage/value from the circular queue of the keyboard instance.  */
105
4446
    if (array_tail == array_head)
106
3752
        return(UX_ERROR);
107
108
    /* Get the usage/value from the current tail.  */
109
694
    *keyboard_key =  *array_tail;
110
694
    *keyboard_state =  *(array_tail + 1);
111
112
    /* Now we need to update the tail value. Are we at the end of the array?  */
113
694
    if ((array_tail+2) >= array_end)
114
20
        array_tail =  array_start;
115
    else
116
674
        array_tail+=2;
117
118
    /* Set the tail pointer.  */
119
694
    keyboard_instance -> ux_host_class_hid_keyboard_usage_array_tail =  array_tail;
120
121
    /* The status will tell the application there is something valid in the key/state.  */
122
694
    return(UX_SUCCESS);
123
}
124
125
/**************************************************************************/
126
/*                                                                        */
127
/*  FUNCTION                                               RELEASE        */
128
/*                                                                        */
129
/*    _uxe_host_class_hid_keyboard_key_get                PORTABLE C      */
130
/*                                                           6.3.0        */
131
/*  AUTHOR                                                                */
132
/*                                                                        */
133
/*    Chaoqiong Xiao, Microsoft Corporation                               */
134
/*                                                                        */
135
/*  DESCRIPTION                                                           */
136
/*                                                                        */
137
/*    This function checks errors in HID key get function call.           */
138
/*                                                                        */
139
/*  INPUT                                                                 */
140
/*                                                                        */
141
/*    keyboard_instance                     Pointer to remote control     */
142
/*    keyboard key                          Pointer to keyboard key       */
143
/*    keyboard state                        Pointer to keyboard state     */
144
/*                                                                        */
145
/*  OUTPUT                                                                */
146
/*                                                                        */
147
/*    Status                                                              */
148
/*                                                                        */
149
/*  CALLS                                                                 */
150
/*                                                                        */
151
/*    _ux_host_class_hid_keyboard_key_get   Get a keyboard key            */
152
/*                                                                        */
153
/*  CALLED BY                                                             */
154
/*                                                                        */
155
/*    Application                                                         */
156
/*                                                                        */
157
/*  RELEASE HISTORY                                                       */
158
/*                                                                        */
159
/*    DATE              NAME                      DESCRIPTION             */
160
/*                                                                        */
161
/*  10-31-2023     Chaoqiong Xiao           Initial Version 6.3.0         */
162
/*                                                                        */
163
/**************************************************************************/
164
UINT  _uxe_host_class_hid_keyboard_key_get(UX_HOST_CLASS_HID_KEYBOARD *keyboard_instance,
165
                                            ULONG *keyboard_key, ULONG *keyboard_state)
166
{
167
168
    /* Sanity checks.  */
169
    if ((keyboard_instance == UX_NULL) ||
170
        (keyboard_key == UX_NULL) || (keyboard_state == UX_NULL) ||
171
        (keyboard_key == keyboard_state))
172
        return(UX_INVALID_PARAMETER);
173
174
    /* Invoke key get function.  */
175
    return(_ux_host_class_hid_keyboard_key_get(keyboard_instance, keyboard_key, keyboard_state));
176
}