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: 2026-03-06 18:57:10 Branches: 6 14 42.9 %

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