GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hid_report_item_analyse.c Lines: 18 18 100.0 %
Date: 2024-12-12 17:16:36 Branches: 4 4 100.0 %

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 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_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_host_class_hid_report_item_analyse              PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function gets the report descriptor and analyzes it.           */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    descriptor                            Pointer to descriptor         */
49
/*    item                                  Pointer to item               */
50
/*                                                                        */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    Completion Status                                                   */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*    None                                                                */
58
/*                                                                        */
59
/*  CALLED BY                                                             */
60
/*                                                                        */
61
/*    HID Class                                                           */
62
/*                                                                        */
63
/*  RELEASE HISTORY                                                       */
64
/*                                                                        */
65
/*    DATE              NAME                      DESCRIPTION             */
66
/*                                                                        */
67
/*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
68
/*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
69
/*                                            resulting in version 6.1    */
70
/*                                                                        */
71
/**************************************************************************/
72
14080
UINT  _ux_host_class_hid_report_item_analyse(UCHAR *descriptor, UX_HOST_CLASS_HID_ITEM *item)
73
{
74
75
UCHAR       item_byte;
76
77
78
    /* Get the first byte from the descriptor.  */
79
14080
    item_byte =  *descriptor;
80
81
    /*  We need to determine if this is a short or long item.
82
        For long items, the tag is always 1111.  */
83
14080
    if ((item_byte & UX_HOST_CLASS_HID_ITEM_TAG_MASK) == UX_HOST_CLASS_HID_ITEM_TAG_LONG)
84
    {
85
86
        /* We have a long item, mark its format.  */
87
6
        item -> ux_host_class_hid_item_report_format =  UX_HOST_CLASS_HID_ITEM_TAG_LONG;
88
89
        /* Set the type.  */
90
6
        item -> ux_host_class_hid_item_report_type =  (item_byte >> 2) & 3;
91
92
        /* Get its length (byte 1).  */
93
6
        item -> ux_host_class_hid_item_report_length =  (USHORT) *(descriptor + 1);
94
95
        /* Then the tag (byte 2).  */
96
6
        item -> ux_host_class_hid_item_report_tag =  *(descriptor + 2);
97
    }
98
    else
99
    {
100
101
        /* We have a short item. Mark its format */
102
14074
        item -> ux_host_class_hid_item_report_format =  UX_HOST_CLASS_HID_ITEM_TAG_SHORT;
103
104
        /* Get the length of the item.  */
105
14074
        switch (item_byte & UX_HOST_CLASS_HID_ITEM_LENGTH_MASK)
106
        {
107
108
31
        case 3:
109
110
31
            item -> ux_host_class_hid_item_report_length =  4;
111
31
            break;
112
113
14043
        default:
114
115
14043
            item -> ux_host_class_hid_item_report_length =  item_byte & UX_HOST_CLASS_HID_ITEM_LENGTH_MASK;
116
14043
            break;
117
        }
118
119
        /* Set the type.  */
120
14074
        item -> ux_host_class_hid_item_report_type =  (item_byte >> 2) & 3;
121
122
        /* Set the tag.  */
123
14074
        item -> ux_host_class_hid_item_report_tag =  item_byte >> 4;
124
    }
125
126
    /* Return successful completion.  */
127
14080
    return(UX_SUCCESS);
128
}
129