1 /*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 /**
17 * @addtogroup USB
18 * @{
19 *
20 * @brief Declares USB-related APIs, including the custom data types and functions
21 * used to obtain descriptors, interface objects, and request objects, and to submit requests.
22 *
23 * @since 1.0
24 * @version 1.0
25 */
26
27 /**
28 * @file usb_ddk.h
29 *
30 * @brief Defines the USB-related structures.
31 *
32 * @since 1.0
33 * @version 1.0
34 */
35
36 #ifndef USB_DDK_H
37 #define USB_DDK_H
38
39 #include "hdf_base.h"
40 #include <endian.h>
41
42 #if __BYTE_ORDER == __LITTLE_ENDIAN
43 /**
44 * @brief Implements 16-bit little-endian conversion.
45 */
46 #define CpuToLe16(x) (x)
47 /**
48 * @brief Implements 32-bit little-endian conversion.
49 */
50 #define CpuToLe32(x) (x)
51 #else
52 /**
53 * @brief Implements 16-bit little-endian conversion.
54 */
55 #define CpuToLe16(x) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8))
56 /**
57 * @brief Implements 32-bit little-endian conversion.
58 */
59 #define CpuToLe32(x) \
60 ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \
61 (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
62 #endif
63
64 /**
65 * @brief Implements 16-bit little-endian conversion.
66 */
67 #define Le16ToCpu CpuToLe16
68 /**
69 * @brief Implements 16-bit little-endian conversion.
70 */
71 #define Le32ToCpu CpuToLe32
72
73 /**
74 * @brief Configures the bus power-on feature.
75 */
76 #define USB_CFG_BUS_POWERED 0x80
77
78 /**
79 * @brief Configures the automatic power-on feature.
80 */
81 #define USB_CFG_SELF_POWERED 0x40
82
83 /**
84 * @brief Configures the remote wakeup feature.
85 */
86 #define USB_CFG_REMOTE_WAKEUP 0x20
87
88 /**
89 * @brief Defines the data direction bit offset. For details, see {@link UsbRequestDirection}.
90 */
91 #define USB_DIR_OFFSET 0x07
92
93 /**
94 * @brief Defines the control request type offset. For details, see {@link UsbControlRequestType}.
95 */
96 #define USB_TYPE_OFFSET 0x05
97
98 /**
99 * @brief Defines the control request packet type offset. For details, see {@link UsbRequestTargetType}.
100 */
101 #define USB_RECIP_OFFSET 0x00
102
103 /**
104 * @brief Defines the USB string index.
105 */
106 enum {
107 /** Manufacturer index */
108 USB_FUNC_MANUFACTURER_IDX,
109 /** Product index */
110 USB_FUNC_PRODUCT_IDX,
111 /** Product SN index */
112 USB_FUNC_SERIAL_IDX,
113 /** Index of the first valid string */
114 USB_FUNC_FIRST_AVAIL_IDX,
115 };
116
117 /**
118 * @brief Renames a descriptor structure.
119 */
120 enum {
121 FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
122 FUNCTIONFS_STRINGS_MAGIC = 2,
123 FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
124 };
125
126 enum functionfs_flags {
127 FUNCTIONFS_HAS_FS_DESC = 1,
128 FUNCTIONFS_HAS_HS_DESC = 2,
129 FUNCTIONFS_HAS_SS_DESC = 4,
130 FUNCTIONFS_HAS_MS_OS_DESC = 8,
131 FUNCTIONFS_VIRTUAL_ADDR = 16,
132 FUNCTIONFS_EVENTFD = 32,
133 FUNCTIONFS_ALL_CTRL_RECIP = 64,
134 FUNCTIONFS_CONFIG0_SETUP = 128,
135 };
136
137 enum UsbDeviceSpeed {
138 USB_DDK_SPEED_UNKNOWN = 0,
139 USB_DDK_SPEED_LOW,
140 USB_DDK_SPEED_FULL,
141 USB_DDK_SPEED_HIGH,
142 USB_DDK_SPEED_WIRELESS,
143 USB_DDK_SPEED_SUPER,
144 USB_DDK_SPEED_SUPER_PLUS,
145 };
146
147 struct UsbCtrlRequest {
148 uint8_t bRequestType;
149 uint8_t bRequest;
150 uint16_t wValue;
151 uint16_t wIndex;
152 uint16_t wLength;
153 } __attribute__ ((packed));
154
155 struct UsbDescriptorHeader {
156 uint8_t bLength;
157 uint8_t bDescriptorType;
158 } __attribute__ ((packed));
159
160 struct UsbDeviceDescriptor {
161 uint8_t bLength;
162 uint8_t bDescriptorType;
163 uint16_t bcdUSB;
164 uint8_t bDeviceClass;
165 uint8_t bDeviceSubClass;
166 uint8_t bDeviceProtocol;
167 uint8_t bMaxPacketSize0;
168 uint16_t idVendor;
169 uint16_t idProduct;
170 uint16_t bcdDevice;
171 uint8_t iManufacturer;
172 uint8_t iProduct;
173 uint8_t iSerialNumber;
174 uint8_t bNumConfigurations;
175 } __attribute__ ((packed));
176
177 struct UsbConfigDescriptor {
178 uint8_t bLength;
179 uint8_t bDescriptorType;
180 uint16_t wTotalLength;
181 uint8_t bNumInterfaces;
182 uint8_t bConfigurationValue;
183 uint8_t iConfiguration;
184 uint8_t bmAttributes;
185 uint8_t bMaxPower;
186 } __attribute__ ((packed));
187
188 struct UsbStringDescriptor {
189 uint8_t bLength;
190 uint8_t bDescriptorType;
191 uint16_t wData[1];
192 } __attribute__ ((packed));
193
194 struct UsbInterfaceDescriptor {
195 uint8_t bLength;
196 uint8_t bDescriptorType;
197 uint8_t bInterfaceNumber;
198 uint8_t bAlternateSetting;
199 uint8_t bNumEndpoints;
200 uint8_t bInterfaceClass;
201 uint8_t bInterfaceSubClass;
202 uint8_t bInterfaceProtocol;
203 uint8_t iInterface;
204 } __attribute__ ((packed));
205
206 struct UsbEndpointDescriptor {
207 uint8_t bLength;
208 uint8_t bDescriptorType;
209 uint8_t bEndpointAddress;
210 uint8_t bmAttributes;
211 uint16_t wMaxPacketSize;
212 uint8_t bInterval;
213 uint8_t bRefresh;
214 uint8_t bSynchAddress;
215 } __attribute__ ((packed));
216
217 struct UsbSspIsocEpCompDescriptor {
218 uint8_t bLength;
219 uint8_t bDescriptorType;
220 uint16_t wReseved;
221 uint32_t dwBytesPerInterval;
222 } __attribute__ ((packed));
223
224 struct UsbSsEpCompDescriptor {
225 uint8_t bLength;
226 uint8_t bDescriptorType;
227 uint8_t bMaxBurst;
228 uint8_t bmAttributes;
229 uint16_t wBytesPerInterval;
230 } __attribute__ ((packed));
231
232 struct UsbQualifierDescriptor {
233 uint8_t bLength;
234 uint8_t bDescriptorType;
235 uint16_t bcdUSB;
236 uint8_t bDeviceClass;
237 uint8_t bDeviceSubClass;
238 uint8_t bDeviceProtocol;
239 uint8_t bMaxPacketSize0;
240 uint8_t bNumConfigurations;
241 uint8_t bRESERVED;
242 } __attribute__ ((packed));
243
244 struct UsbOtgDescriptor {
245 uint8_t bLength;
246 uint8_t bDescriptorType;
247 uint8_t bmAttributes;
248 } __attribute__ ((packed));
249
250 struct UsbOtg20Descriptor {
251 uint8_t bLength;
252 uint8_t bDescriptorType;
253 uint8_t bmAttributes;
254 uint16_t bcdOTG;
255 } __attribute__ ((packed));
256
257 struct UsbInterfaceAssocDescriptor {
258 uint8_t bLength;
259 uint8_t bDescriptorType;
260 uint8_t bFirstInterface;
261 uint8_t bInterfaceCount;
262 uint8_t bFunctionClass;
263 uint8_t bFunctionSubClass;
264 uint8_t bFunctionProtocol;
265 uint8_t iFunction;
266 } __attribute__ ((packed));
267
268 struct UsbFunctionfsStringsHead {
269 uint32_t magic;
270 uint32_t length;
271 uint32_t str_count;
272 uint32_t lang_count;
273 } __attribute__((packed));
274
275 struct UsbFunctionfsDescsHeadV2 {
276 uint32_t magic;
277 uint32_t length;
278 uint32_t flags;
279 } __attribute__((packed));
280
281 struct UsbSecurityDescriptor {
282 uint8_t bLength;
283 uint8_t bDescriptorType;
284 uint16_t wTotalLength;
285 uint8_t bNumEncryptionTypes;
286 } __attribute__((packed));
287
288 struct UsbCdcLineCoding {
289 uint32_t dwDTERate;
290 uint8_t bCharFormat;
291
292 #define USB_CDC_1_STOP_BITS 0
293 #define USB_CDC_1_5_STOP_BITS 1
294 #define USB_CDC_2_STOP_BITS 2
295 uint8_t bParityType;
296
297 #define USB_CDC_NO_PARITY 0
298 #define USB_CDC_ODD_PARITY 1
299 #define USB_CDC_EVEN_PARITY 2
300 #define USB_CDC_MARK_PARITY 3
301 #define USB_CDC_SPACE_PARITY 4
302 uint8_t bDataBits;
303 } __attribute__ ((packed));
304
305 struct UsbCdcNotification {
306 uint8_t bmRequestType;
307 uint8_t bNotificationType;
308 uint16_t wValue;
309 uint16_t wIndex;
310 uint16_t wLength;
311 } __attribute__ ((packed));
312
313 struct UsbCdcHeaderDesc {
314 uint8_t bLength;
315 uint8_t bDescriptorType;
316 uint8_t bDescriptorSubType;
317 uint16_t bcdCDC;
318 } __attribute__ ((packed));
319
320 struct UsbCdcCallMgmtDescriptor {
321 uint8_t bLength;
322 uint8_t bDescriptorType;
323 uint8_t bDescriptorSubType;
324 uint8_t bmCapabilities;
325
326 #define USB_CDC_CALL_MGMT_CAP_CALL_MGMT 0x01
327 #define USB_CDC_CALL_MGMT_CAP_DATA_INTF 0x02
328 uint8_t bDataInterface;
329 } __attribute__ ((packed));
330
331 struct UsbCdcAcmDescriptor {
332 uint8_t bLength;
333 uint8_t bDescriptorType;
334 uint8_t bDescriptorSubType;
335 uint8_t bmCapabilities;
336 } __attribute__ ((packed));
337
338 struct UsbCdcUnionDesc {
339 uint8_t bLength;
340 uint8_t bDescriptorType;
341 uint8_t bDescriptorSubType;
342 uint8_t bMasterInterface0;
343 uint8_t bSlaveInterface0;
344 } __attribute__ ((packed));
345
346 struct UsbDebugDescriptor {
347 uint8_t bLength;
348 uint8_t bDescriptorType;
349 uint8_t bDebugInEndpoint;
350 uint8_t bDebugOutEndpoint;
351 } __attribute__((packed));
352
353 struct UsbCdcEtherDesc {
354 uint8_t bLength;
355 uint8_t bDescriptorType;
356 uint8_t bDescriptorSubType;
357
358 uint8_t iMACAddress;
359 uint32_t bmEthernetStatistics;
360 uint16_t wMaxSegmentSize;
361 uint16_t wNumberMCFilters;
362 uint8_t bNumberPowerFilters;
363 } __attribute__ ((packed));
364
365 #define USB_DDK_ENDPOINT_NUMBER_MASK 0x0F
366 #define USB_DDK_ENDPOINT_DIR_MASK 0x80
367 #define USB_DDK_DIR_OUT 0x00
368 #define USB_DDK_DIR_IN 0x80
369
370 #define USB_DDK_DT_DEVICE 0x01
371 #define USB_DDK_DT_CONFIG 0x02
372 #define USB_DDK_DT_STRING 0x03
373 #define USB_DDK_DT_INTERFACE 0x04
374 #define USB_DDK_DT_ENDPOINT 0x05
375 #define USB_DDK_DT_DEVICE_QUALIFIER 0x06
376 #define USB_DDK_DT_OTHER_SPEED_CONFIG 0x07
377 #define USB_DDK_DT_INTERFACE_POWER 0x08
378 #define USB_DDK_DT_OTG 0x09
379 #define USB_DDK_DT_DEBUG 0x0A
380 #define USB_DDK_DT_INTERFACE_ASSOCIATION 0x0B
381 #define USB_DDK_DT_SECURITY 0x0C
382 #define USB_DDK_DT_KEY 0x0D
383 #define USB_DDK_DT_ENCRYPTION_TYPE 0x0E
384 #define USB_DDK_DT_BOS 0x0F
385 #define USB_DDK_DT_DEVICE_CAPABILITY 0x10
386 #define USB_DDK_DT_WIRELESS_ENDPOINT_COMP 0x11
387 #define USB_DDK_DT_WIRE_ADAPTER 0x21
388 #define USB_DDK_DT_RPIPE 0x22
389 #define USB_DDK_DT_CS_RADIO_CONTROL 0x23
390 #define USB_DDK_DT_PIPE_USAGE 0x24
391 #define USB_DDK_DT_SS_ENDPOINT_COMP 0x30
392 #define USB_DDK_DT_SSP_ISOC_ENDPOINT_COMP 0x31
393 #define USB_DDK_DT_CS_DEVICE (USB_DDK_TYPE_CLASS | USB_DDK_DT_DEVICE)
394 #define USB_DDK_DT_CS_CONFIG (USB_DDK_TYPE_CLASS | USB_DDK_DT_CONFIG)
395 #define USB_DDK_DT_CS_STRING (USB_DDK_TYPE_CLASS | USB_DDK_DT_STRING)
396 #define USB_DDK_DT_CS_INTERFACE (USB_DDK_TYPE_CLASS | USB_DDK_DT_INTERFACE)
397 #define USB_DDK_DT_CS_ENDPOINT (USB_DDK_TYPE_CLASS | USB_DDK_DT_ENDPOINT)
398
399 #define USB_DDK_DT_SS_EP_COMP_SIZE 0x06
400 #define USB_DDK_DT_ENDPOINT_SIZE 0x07
401 #define USB_DDK_DT_SSP_ISOC_EP_COMP_SIZE 0x08
402 #define USB_DDK_DT_INTERFACE_ASSOCIATION_SIZE 0x08
403 #define USB_DDK_DT_CONFIG_SIZE 0x09
404 #define USB_DDK_DT_INTERFACE_SIZE 0x09
405 #define USB_DDK_DT_ENDPOINT_AUDIO_SIZE 0x09
406 #define USB_DDK_DT_DEVICE_SIZE 0x12
407
408 #define USB_DDK_CLASS_PER_INTERFACE 0x00
409 #define USB_DDK_CLASS_AUDIO 0x01
410 #define USB_DDK_CLASS_COMM 0x02
411 #define USB_DDK_CLASS_HID 0x03
412 #define USB_DDK_CLASS_PHYSICAL 0x05
413 #define USB_DDK_CLASS_STILL_IMAGE 0x06
414 #define USB_DDK_CLASS_PRINTER 0x07
415 #define USB_DDK_CLASS_MASS_STORAGE 0x08
416 #define USB_DDK_CLASS_HUB 0x09
417 #define USB_DDK_CLASS_CDC_DATA 0x0A
418 #define USB_DDK_CLASS_CSCID 0x0B
419 #define USB_DDK_CLASS_CONTENT_SEC 0x0D
420 #define USB_DDK_CLASS_VIDEO 0x0E
421 #define USB_DDK_CLASS_WIRELESS_CONTROLLER 0xE0
422 #define USB_DDK_CLASS_MISC 0xEF
423 #define USB_DDK_CLASS_APP_SPEC 0xFE
424 #define USB_DDK_CLASS_VENDOR_SPEC 0xFF
425 #define USB_DDK_SUBCLASS_VENDOR_SPEC 0xFF
426
427 #define USB_DDK_CDC_NOTIFY_NETWORK_CONNECTION 0x00
428 #define USB_DDK_CDC_NOTIFY_RESPONSE_AVAILABLE 0x01
429 #define USB_DDK_CDC_NOTIFY_SERIAL_STATE 0x20
430 #define USB_DDK_CDC_NOTIFY_SPEED_CHANGE 0x2A
431
432 #define USB_DDK_CDC_SEND_ENCAPSULATED_COMMAND 0x00
433 #define USB_DDK_CDC_GET_ENCAPSULATED_RESPONSE 0x01
434 #define USB_DDK_CDC_REQ_SET_LINE_CODING 0x20
435 #define USB_DDK_CDC_REQ_GET_LINE_CODING 0x21
436 #define USB_DDK_CDC_REQ_SET_CONTROL_LINE_STATE 0x22
437 #define USB_DDK_CDC_REQ_SEND_BREAK 0x23
438 #define USB_DDK_CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40
439 #define USB_DDK_CDC_SET_ETHERNET_PM_PATTERN_FILTER 0x41
440 #define USB_DDK_CDC_GET_ETHERNET_PM_PATTERN_FILTER 0x42
441 #define USB_DDK_CDC_SET_ETHERNET_PACKET_FILTER 0x43
442 #define USB_DDK_CDC_GET_ETHERNET_STATISTIC 0x44
443 #define USB_DDK_CDC_GET_NTB_PARAMETERS 0x80
444 #define USB_DDK_CDC_GET_NET_ADDRESS 0x81
445 #define USB_DDK_CDC_SET_NET_ADDRESS 0x82
446 #define USB_DDK_CDC_GET_NTB_FORMAT 0x83
447 #define USB_DDK_CDC_SET_NTB_FORMAT 0x84
448 #define USB_DDK_CDC_GET_NTB_INPUT_SIZE 0x85
449 #define USB_DDK_CDC_SET_NTB_INPUT_SIZE 0x86
450 #define USB_DDK_CDC_GET_MAX_DATAGRAM_SIZE 0x87
451 #define USB_DDK_CDC_SET_MAX_DATAGRAM_SIZE 0x88
452 #define USB_DDK_CDC_GET_CRC_MODE 0x89
453 #define USB_DDK_CDC_SET_CRC_MODE 0x8A
454
455 #define USB_DDK_CDC_COMM_FEATURE 0x01
456 #define USB_DDK_CDC_CAP_LINE 0x02
457 #define USB_DDK_CDC_CAP_BRK 0x04
458 #define USB_DDK_CDC_CAP_NOTIFY 0x08
459
460 #define USB_DDK_CDC_HEADER_TYPE 0x00
461 #define USB_DDK_CDC_CALL_MANAGEMENT_TYPE 0x01
462 #define USB_DDK_CDC_ACM_TYPE 0x02
463 #define USB_DDK_CDC_UNION_TYPE 0x06
464 #define USB_DDK_CDC_COUNTRY_TYPE 0x07
465 #define USB_DDK_CDC_NETWORK_TERMINAL_TYPE 0x0a
466 #define USB_DDK_CDC_ETHERNET_TYPE 0x0f
467 #define USB_DDK_CDC_WHCM_TYPE 0x11
468 #define USB_DDK_CDC_MDLM_TYPE 0x12
469 #define USB_DDK_CDC_MDLM_DETAIL_TYPE 0x13
470 #define USB_DDK_CDC_DMM_TYPE 0x14
471 #define USB_DDK_CDC_OBEX_TYPE 0x15
472 #define USB_DDK_CDC_NCM_TYPE 0x1A
473 #define USB_DDK_CDC_MBIM_TYPE 0x1B
474 #define USB_DDK_CDC_MBIM_EXTENDED_TYPE 0x1C
475
476 #define USB_DDK_CDC_PROTO_NONE 0x00
477 #define USB_DDK_CDC_ACM_PROTO_AT_V25TER 0x01
478 #define USB_DDK_CDC_ACM_PROTO_AT_PCCA101 0x02
479 #define USB_DDK_CDC_ACM_PROTO_AT_PCCA101_WAKE 0x03
480 #define USB_DDK_CDC_ACM_PROTO_AT_GSM 0x04
481 #define USB_DDK_CDC_ACM_PROTO_AT_3G 0x05
482 #define USB_DDK_CDC_ACM_PROTO_AT_CDMA 0x06
483 #define USB_DDK_CDC_PROTO_EEM 0x07
484
485 #define USB_DDK_CDC_NCM_PROTO_NTB 0x01
486 #define USB_DDK_CDC_MBIM_PROTO_NTB 0x02
487
488 #define USB_DDK_CDC_SUBCLASS_ACM 0x02
489 #define USB_DDK_CDC_SUBCLASS_ETHERNET 0x06
490 #define USB_DDK_CDC_SUBCLASS_WHCM 0x08
491 #define USB_DDK_CDC_SUBCLASS_DMM 0x09
492 #define USB_DDK_CDC_SUBCLASS_MDLM 0x0A
493 #define USB_DDK_CDC_SUBCLASS_OBEX 0x0B
494 #define USB_DDK_CDC_SUBCLASS_EEM 0x0C
495 #define USB_DDK_CDC_SUBCLASS_NCM 0x0D
496 #define USB_DDK_CDC_SUBCLASS_MBIM 0x0E
497
498 #define USB_DDK_CDC_PACKET_TYPE_PROMISCUOUS (1 << 0)
499 #define USB_DDK_CDC_PACKET_TYPE_ALL_MULTICAST (1 << 1)
500 #define USB_DDK_CDC_PACKET_TYPE_DIRECTED (1 << 2)
501 #define USB_DDK_CDC_PACKET_TYPE_BROADCAST (1 << 3)
502 #define USB_DDK_CDC_PACKET_TYPE_MULTICAST (1 << 4)
503
504 #define USB_DDK_CDC_ACM_PROTO_VENDOR 0xFF
505
506 #define USB_DDK_TYPE_MASK (0x03 << 5)
507 #define USB_DDK_TYPE_STANDARD (0x00 << 5)
508 #define USB_DDK_TYPE_CLASS (0x01 << 5)
509 #define USB_DDK_TYPE_VENDOR (0x02 << 5)
510 #define USB_DDK_TYPE_RESERVED (0x03 << 5)
511
512 #define USB_DDK_ENDPOINT_XFERTYPE_MASK 0x03
513 #define USB_DDK_ENDPOINT_XFER_CONTROL 0x00
514 #define USB_DDK_ENDPOINT_XFER_ISOC 0x01
515 #define USB_DDK_ENDPOINT_XFER_BULK 0x02
516 #define USB_DDK_ENDPOINT_XFER_INT 0x03
517 #define USB_DDK_ENDPOINT_MAX_ADJUSTABLE 0x80
518
519 #define USB_DDK_RECIP_MASK 0x1F
520 #define USB_DDK_RECIP_DEVICE 0x00
521 #define USB_DDK_RECIP_INTERFACE 0x01
522 #define USB_DDK_RECIP_ENDPOINT 0x02
523 #define USB_DDK_RECIP_OTHER 0x03
524
525 #define USB_DDK_REQ_GET_STATUS 0x00
526 #define USB_DDK_REQ_CLEAR_FEATURE 0x01
527 #define USB_DDK_REQ_SET_FEATURE 0x03
528 #define USB_DDK_REQ_SET_ADDRESS 0x05
529 #define USB_DDK_REQ_GET_DESCRIPTOR 0x06
530 #define USB_DDK_REQ_SET_DESCRIPTOR 0x07
531 #define USB_DDK_REQ_GET_CONFIGURATION 0x08
532 #define USB_DDK_REQ_SET_CONFIGURATION 0x09
533 #define USB_DDK_REQ_GET_INTERFACE 0x0A
534 #define USB_DDK_REQ_SET_INTERFACE 0x0B
535 #define USB_DDK_REQ_SYNCH_FRAME 0x0C
536 #define USB_DDK_REQ_SET_SEL 0x30
537 #define USB_DDK_REQ_SET_ISOCH_DELAY 0x31
538
539 #define UsbiDescriptorHeader UsbDescriptorHeader
540 #define UsbiConfigurationDescriptor UsbConfigDescriptor
541 #define UsbiInterfaceDescriptor UsbInterfaceDescriptor
542
543 /**
544 * @brief Checks whether the specified endpoint is in the input direction (the direction in
545 * which data is transferred from the device to the host). For details, see {@link UsbRequestDirection}.
546 *
547 * @param ep Indicates the endpoint address, which is in the <b>uint8_t</b> format.
548 *
549 * @return Returns <b>1</b> if the specified endpoint is in the input direction; returns <b>0</b> otherwise.
550 */
UsbEndpointDirIn(uint8_t ep)551 static inline int32_t UsbEndpointDirIn(uint8_t ep)
552 {
553 return ((ep & USB_DDK_ENDPOINT_DIR_MASK) == USB_DDK_DIR_IN);
554 }
555
556 /**
557 * @brief Checks whether the specified endpoint is in the output direction (the direction in which data is
558 * transferred from the host to the device). For details, see {@link UsbRequestDirection}.
559 *
560 * @param ep Indicates the endpoint address, which is in the <b>uint8_t</b> format.
561 *
562 * @return Returns <b>1</b> if the specified endpoint is in the output direction; returns <b>0</b> otherwise.
563 */
UsbEndpointDirOut(uint8_t ep)564 static inline int32_t UsbEndpointDirOut(uint8_t ep)
565 {
566 return ((ep & USB_DDK_ENDPOINT_DIR_MASK) == USB_DDK_DIR_OUT);
567 }
568
569 #endif /* USB_DDK_H */
570 /** @} */
571