-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathusbd_core_hid.c
More file actions
186 lines (152 loc) · 5.98 KB
/
Copy pathusbd_core_hid.c
File metadata and controls
186 lines (152 loc) · 5.98 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/**
* @file usbd_core_hid.c
* @brief Human Interface Device driver
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <string.h>
#include "rl_usb.h"
#include "usb_for_lib.h"
/*
* Get Descriptor USB Device Request - HID specific handling
* Parameters: None
* Return Value: TRUE - Success, FALSE - Error
*/
__WEAK BOOL USBD_ReqGetDescriptor_HID(U8 **pD, U32 *len)
{
switch (USBD_SetupPacket.wValueH) {
case HID_HID_DESCRIPTOR_TYPE:
if (USBD_SetupPacket.wIndexL != usbd_hid_if_num
#if (USBD_WEBUSB_ENABLE)
&& USBD_SetupPacket.wIndexL != usbd_webusb_if_num
#endif
) {
return (__FALSE);
}
if ((!usbd_hs_enable) && (USBD_HighSpeed == __TRUE)) {
return (__FALSE); /* High speed request but high-speed not enabled */
}
if (USBD_HighSpeed == __FALSE) {
*pD = (U8 *)USBD_ConfigDescriptor;
} else {
*pD = (U8 *)USBD_ConfigDescriptor_HS;
}
USBD_EP0Data.pData = *pD + USBD_HID_DescriptorOffset;
*len = USB_HID_DESC_SIZE;
break;
case HID_REPORT_DESCRIPTOR_TYPE:
if (USBD_SetupPacket.wIndexL != usbd_hid_if_num
#if (USBD_WEBUSB_ENABLE)
&& USBD_SetupPacket.wIndexL != usbd_webusb_if_num
#endif
) {
return (__FALSE);
}
USBD_EP0Data.pData = (U8 *)USBD_HID_ReportDescriptor;
*len = USBD_HID_ReportDescriptorSize;
break;
case HID_PHYSICAL_DESCRIPTOR_TYPE:
return (__FALSE); /* HID Physical Descriptor is not supported */
default:
return (__FALSE);
}
return (__TRUE);
}
/*
* USB Device Endpoint 0 Event Callback - HID specific handling (Setup Request To Interface)
* Parameters: none
* Return Value: TRUE - Setup class request ok, FALSE - Setup class request not supported
*/
__WEAK BOOL USBD_EndPoint0_Setup_HID_ReqToIF(void)
{
if (USBD_SetupPacket.wIndexL == usbd_hid_if_num
#if (USBD_WEBUSB_ENABLE)
|| USBD_SetupPacket.wIndexL == usbd_webusb_if_num
#endif
) {
switch (USBD_SetupPacket.bRequest) {
case HID_REQUEST_GET_REPORT:
if (USBD_HID_GetReport()) {
if (USBD_SetupPacket.wValueH == HID_REPORT_INPUT) {
USBD_EP0Data.pData = &USBD_HID_InReport[1]; /* point to data to be sent (skip ReportID) */
} else if (USBD_SetupPacket.wValueH == HID_REPORT_FEATURE) {
USBD_EP0Data.pData = &USBD_HID_FeatReport[1]; /* point to data to be sent (skip ReportID) */
}
USBD_DataInStage(); /* send requested data */
return (__TRUE);
}
break;
case HID_REQUEST_SET_REPORT:
if (USBD_SetupPacket.wValueH == HID_REPORT_OUTPUT) {
USBD_EP0Data.pData = &USBD_HID_OutReport[1]; /* out data to be received (skip ReportID) */
} else if (USBD_SetupPacket.wValueH == HID_REPORT_FEATURE) {
USBD_EP0Data.pData = &USBD_HID_FeatReport[1]; /* out data to be received (skip ReportID) */
}
return (__TRUE);
case HID_REQUEST_GET_IDLE:
if (USBD_HID_GetIdle()) {
USBD_EP0Data.pData = USBD_EP0Buf; /* point to data to be sent */
USBD_DataInStage(); /* send requested data */
return (__TRUE);
}
break;
case HID_REQUEST_SET_IDLE:
if (USBD_HID_SetIdle()) {
USBD_StatusInStage(); /* send Acknowledge */
return (__TRUE);
}
break;
case HID_REQUEST_GET_PROTOCOL:
if (USBD_HID_GetProtocol()) {
USBD_EP0Data.pData = USBD_EP0Buf; /* point to data to be sent */
USBD_DataInStage(); /* send requested data */
return (__TRUE);
}
break;
case HID_REQUEST_SET_PROTOCOL:
if (USBD_HID_SetProtocol()) {
USBD_StatusInStage(); /* send Acknowledge */
return (__TRUE);
}
break;
}
}
return (__FALSE);
}
/*
* USB Device Endpoint 0 Event Callback - HID specific handling (Out Request To Interface)
* Parameters: none
* Return Value: TRUE - Out class request ok, FALSE - Out class request not supported
*/
__WEAK BOOL USBD_EndPoint0_Out_HID_ReqToIF(void)
{
if (USBD_SetupPacket.wIndexL == usbd_hid_if_num
#if (USBD_WEBUSB_ENABLE)
|| USBD_SetupPacket.wIndexL == usbd_webusb_if_num
#endif
) {
switch (USBD_SetupPacket.bRequest) {
case HID_REQUEST_SET_REPORT:
if (USBD_HID_SetReport()) {
USBD_StatusInStage(); /* send Acknowledge */
return (__TRUE);
}
break;
}
}
return (__FALSE);
}