Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_host_class_hid.h"
#include "ux_host_stack.h"
...
...
_ux_host_class_hid_field_decompress(UX_HOST_CLASS_HID_FIELD *, UCHAR *, UX_HOST_CLASS_HID_CLIENT_REPORT *)
Files
loading...
CodeScopeSTM32 Libraries and Samplesusbxcommon/usbx_host_classes/src/ux_host_class_hid_field_decompress.c
 
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** USBX Component */ /** */ /** HID Class */ /** */... /**************************************************************************/ /**************************************************************************/ /* Include necessary system files. */ #define UX_SOURCE_CODE #include "ux_api.h" #include "ux_host_class_hid.h" #include "ux_host_stack.h" ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _ux_host_class_hid_field_decompress PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function will decompress a field and return the usage/value. */ /* */ /* INPUT */ /* */ /* hid_field Pointer to HID field */ /* report_buffer Pointer to report buffer */ /* client_report Pointer to client report */ /* */ /* OUTPUT */ /* */ /* Completion Status */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* HID Class */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ UINT _ux_host_class_hid_field_decompress(UX_HOST_CLASS_HID_FIELD *hid_field, UCHAR *report_buffer, UX_HOST_CLASS_HID_CLIENT_REPORT *client_report) { ULONG field_report_count; ULONG field_report_size; ULONG data_offset_byte; ULONG data_offset_bit; ULONG data_offset_bit_in_report; ULONG field_value; ULONG field_value_bit_shifting; ULONG field_usage; ULONG report_content; /* Calculate the address of the beginning of the field in the report. */ data_offset_byte = (hid_field -> ux_host_class_hid_field_report_offset >> 3); /* Calculate the bit start address. Hopefully things will be on a boundary but not necessary. */ data_offset_bit = hid_field -> ux_host_class_hid_field_report_offset & 7; /* Each report field has a report_count value. This count is used to extract values from the incoming report and build each usage/value instance. *//* ... */ for (field_report_count = 0; field_report_count < hid_field -> ux_host_class_hid_field_report_count; field_report_count++) { /* Get the report size in bits. */ field_report_size = hid_field -> ux_host_class_hid_field_report_size; /* We use the bit offset for this report and not the generic field bit offset. */ data_offset_bit_in_report = data_offset_bit; /* Reset the local value. */ field_value = 0; /* And start with bit 0 in the target value. */ field_value_bit_shifting = 0; /* Build the value field bit by bit. */ while (field_report_size-- != 0) { /* Read the content. This method is redundant if we are not changing byte but it makes the algorithm much easier. *//* ... */ report_content = (ULONG) *(report_buffer + data_offset_byte + (data_offset_bit_in_report >> 3)); /* Shift the current value content to allow space to store the new bit. */ field_value |= ((report_content >> (data_offset_bit_in_report & 7)) & 1) << field_value_bit_shifting; /* Move to next bit in the report. */ data_offset_bit_in_report++; /* And the next bit in the value. */ field_value_bit_shifting++; }while (field_report_size-- != 0) { ... } /* The Usage value will depend if the data is defined as a variable or an array in the HID report. */ if (hid_field -> ux_host_class_hid_field_value & UX_HOST_CLASS_HID_ITEM_VARIABLE) { /* Take the usage directly from the usage array. */ field_usage = *(hid_field -> ux_host_class_hid_field_usages + field_report_count); }if (hid_field -> ux_host_class_hid_field_value & UX_HOST_CLASS_HID_ITEM_VARIABLE) { ... } else { /* This is an array, so compute the usage from the min value, the report count and the computed report value. *//* ... */ field_usage = hid_field -> ux_host_class_hid_field_usage_min + (ULONG)((SLONG)field_value - hid_field -> ux_host_class_hid_field_logical_min); /* Also add the usage page. */ field_usage |= (hid_field -> ux_host_class_hid_field_usage_page << 16); }else { ... } /* Put the value and the usage into the caller's buffer. */ *(client_report -> ux_host_class_hid_client_report_buffer + client_report -> ux_host_class_hid_client_report_actual_length) = field_usage; client_report -> ux_host_class_hid_client_report_actual_length++; *(client_report -> ux_host_class_hid_client_report_buffer + client_report -> ux_host_class_hid_client_report_actual_length) = field_value; client_report -> ux_host_class_hid_client_report_actual_length++; /* Calculate the next address for this field. */ data_offset_bit += hid_field -> ux_host_class_hid_field_report_size; }for (field_report_count = 0; field_report_count < hid_field -> ux_host_class_hid_field_report_count; field_report_count++) { ... } /* Return successful completion. */ return(UX_SUCCESS); }{ ... }