Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
usb_ch9.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 PHYTEC Messtechnik GmbH
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
15#include <version.h>
16#include <sys/util.h>
17
18#ifndef ZEPHYR_INCLUDE_USB_CH9_H_
19#define ZEPHYR_INCLUDE_USB_CH9_H_
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
26#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
30#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
32 uint8_t type : 2;
34#endif
35} __packed;
36
39 union {
42 };
47};
48
50#define USB_REQTYPE_DIR_TO_DEVICE 0
51#define USB_REQTYPE_DIR_TO_HOST 1
52
54#define USB_REQTYPE_TYPE_STANDARD 0
55#define USB_REQTYPE_TYPE_CLASS 1
56#define USB_REQTYPE_TYPE_VENDOR 2
57#define USB_REQTYPE_TYPE_RESERVED 3
58
60#define USB_REQTYPE_RECIPIENT_DEVICE 0
61#define USB_REQTYPE_RECIPIENT_INTERFACE 1
62#define USB_REQTYPE_RECIPIENT_ENDPOINT 2
63#define USB_REQTYPE_RECIPIENT_OTHER 3
64
66#define USB_REQTYPE_GET_DIR(bmRequestType) (((bmRequestType) >> 7) & 0x01U)
68#define USB_REQTYPE_GET_TYPE(bmRequestType) (((bmRequestType) >> 5) & 0x03U)
70#define USB_REQTYPE_GET_RECIPIENT(bmRequestType) ((bmRequestType) & 0x1FU)
71
78static inline bool usb_reqtype_is_to_host(struct usb_setup_packet *setup)
79{
81}
82
89static inline bool usb_reqtype_is_to_device(struct usb_setup_packet *setup)
90{
92}
93
95#define USB_SREQ_GET_STATUS 0x00
96#define USB_SREQ_CLEAR_FEATURE 0x01
97#define USB_SREQ_SET_FEATURE 0x03
98#define USB_SREQ_SET_ADDRESS 0x05
99#define USB_SREQ_GET_DESCRIPTOR 0x06
100#define USB_SREQ_SET_DESCRIPTOR 0x07
101#define USB_SREQ_GET_CONFIGURATION 0x08
102#define USB_SREQ_SET_CONFIGURATION 0x09
103#define USB_SREQ_GET_INTERFACE 0x0A
104#define USB_SREQ_SET_INTERFACE 0x0B
105#define USB_SREQ_SYNCH_FRAME 0x0C
106
108#define USB_DESC_DEVICE 1
109#define USB_DESC_CONFIGURATION 2
110#define USB_DESC_STRING 3
111#define USB_DESC_INTERFACE 4
112#define USB_DESC_ENDPOINT 5
113#define USB_DESC_DEVICE_QUALIFIER 6
114#define USB_DESC_OTHER_SPEED 7
115#define USB_DESC_INTERFACE_POWER 8
117#define USB_DESC_OTG 9
118#define USB_DESC_DEBUG 10
119#define USB_DESC_INTERFACE_ASSOC 11
120#define USB_DESC_BOS 15
121#define USB_DESC_DEVICE_CAPABILITY 16
122
126#define USB_DESC_CS_DEVICE 0x21
127#define USB_DESC_CS_CONFIGURATION 0x22
128#define USB_DESC_CS_STRING 0x23
129#define USB_DESC_CS_INTERFACE 0x24
130#define USB_DESC_CS_ENDPOINT 0x25
131
133#define USB_SFS_ENDPOINT_HALT 0x00
134#define USB_SFS_REMOTE_WAKEUP 0x01
135#define USB_SFS_TEST_MODE 0x02
136
138#define USB_GET_STATUS_SELF_POWERED BIT(0)
139#define USB_GET_STATUS_REMOTE_WAKEUP BIT(1)
140
145} __packed;
146
163} __packed;
164
175} __packed;
176
188} __packed;
189
198} __packed;
199
205} __packed;
206
217} __packed;
218
220#define USB_SCD_RESERVED BIT(7)
221#define USB_SCD_SELF_POWERED BIT(6)
222#define USB_SCD_REMOTE_WAKEUP BIT(5)
223#define USB_SCD_ATTRIBUTES (USB_SCD_RESERVED | \
224 COND_CODE_1(CONFIG_USB_SELF_POWERED, \
225 (USB_SCD_SELF_POWERED), (0)) | \
226 COND_CODE_1(CONFIG_USB_DEVICE_REMOTE_WAKEUP, \
227 (USB_SCD_REMOTE_WAKEUP), (0)))
228
230#define USB_BCC_AUDIO 0x01
231#define USB_BCC_CDC_CONTROL 0x02
232#define USB_BCC_HID 0x03
233#define USB_BCC_MASS_STORAGE 0x08
234#define USB_BCC_CDC_DATA 0x0A
235#define USB_BCC_VIDEO 0x0E
236#define USB_BCC_WIRELESS_CONTROLLER 0xE0
237#define USB_BCC_MISCELLANEOUS 0xEF
238#define USB_BCC_APPLICATION 0xFE
239#define USB_BCC_VENDOR 0xFF
240
242#define USB_SRN_1_1 0x0110
243#define USB_SRN_2_0 0x0200
244#define USB_SRN_2_1 0x0210
245
246#define USB_DEC_TO_BCD(dec) ((((dec) / 10) << 4) | ((dec) % 10))
247
249#define USB_BCD_DRN (USB_DEC_TO_BCD(KERNEL_VERSION_MAJOR) << 8 | \
250 USB_DEC_TO_BCD(KERNEL_VERSION_MINOR))
251
253#define USB_GET_DESCRIPTOR_TYPE(wValue) ((uint8_t)((wValue) >> 8))
254
256#define USB_GET_DESCRIPTOR_INDEX(wValue) ((uint8_t)(wValue))
257
259#define USB_CONTROL_EP_OUT 0
260#define USB_CONTROL_EP_IN 0x80
261
263#define USB_CONTROL_EP_MPS 64
264
265#ifdef __cplusplus
266}
267#endif
268
269#endif /* ZEPHYR_INCLUDE_USB_CH9_H_ */
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Definition: usb_ch9.h:208
uint8_t bLength
Definition: usb_ch9.h:209
uint8_t bFunctionClass
Definition: usb_ch9.h:213
uint8_t bFunctionSubClass
Definition: usb_ch9.h:214
uint8_t iFunction
Definition: usb_ch9.h:216
uint8_t bFunctionProtocol
Definition: usb_ch9.h:215
uint8_t bInterfaceCount
Definition: usb_ch9.h:212
uint8_t bFirstInterface
Definition: usb_ch9.h:211
uint8_t bDescriptorType
Definition: usb_ch9.h:210
Definition: usb_ch9.h:166
uint8_t bLength
Definition: usb_ch9.h:167
uint8_t bmAttributes
Definition: usb_ch9.h:173
uint8_t bMaxPower
Definition: usb_ch9.h:174
uint8_t bConfigurationValue
Definition: usb_ch9.h:171
uint8_t bDescriptorType
Definition: usb_ch9.h:168
uint8_t iConfiguration
Definition: usb_ch9.h:172
uint8_t bNumInterfaces
Definition: usb_ch9.h:170
uint16_t wTotalLength
Definition: usb_ch9.h:169
Definition: usb_ch9.h:142
uint8_t bDescriptorType
Definition: usb_ch9.h:144
uint8_t bLength
Definition: usb_ch9.h:143
Definition: usb_ch9.h:148
uint16_t idVendor
Definition: usb_ch9.h:156
uint8_t iSerialNumber
Definition: usb_ch9.h:161
uint16_t bcdDevice
Definition: usb_ch9.h:158
uint8_t bDeviceProtocol
Definition: usb_ch9.h:154
uint8_t bNumConfigurations
Definition: usb_ch9.h:162
uint16_t idProduct
Definition: usb_ch9.h:157
uint16_t bcdUSB
Definition: usb_ch9.h:151
uint8_t bDeviceClass
Definition: usb_ch9.h:152
uint8_t bMaxPacketSize0
Definition: usb_ch9.h:155
uint8_t iProduct
Definition: usb_ch9.h:160
uint8_t iManufacturer
Definition: usb_ch9.h:159
uint8_t bDescriptorType
Definition: usb_ch9.h:150
uint8_t bDeviceSubClass
Definition: usb_ch9.h:153
uint8_t bLength
Definition: usb_ch9.h:149
Definition: usb_ch9.h:191
uint8_t bDescriptorType
Definition: usb_ch9.h:193
uint8_t bEndpointAddress
Definition: usb_ch9.h:194
uint8_t bInterval
Definition: usb_ch9.h:197
uint16_t wMaxPacketSize
Definition: usb_ch9.h:196
uint8_t bmAttributes
Definition: usb_ch9.h:195
uint8_t bLength
Definition: usb_ch9.h:192
Definition: usb_ch9.h:178
uint8_t bAlternateSetting
Definition: usb_ch9.h:182
uint8_t bInterfaceSubClass
Definition: usb_ch9.h:185
uint8_t bInterfaceProtocol
Definition: usb_ch9.h:186
uint8_t bNumEndpoints
Definition: usb_ch9.h:183
uint8_t bInterfaceClass
Definition: usb_ch9.h:184
uint8_t iInterface
Definition: usb_ch9.h:187
uint8_t bDescriptorType
Definition: usb_ch9.h:180
uint8_t bLength
Definition: usb_ch9.h:179
uint8_t bInterfaceNumber
Definition: usb_ch9.h:181
Definition: usb_ch9.h:25
uint8_t recipient
Definition: usb_ch9.h:27
uint8_t type
Definition: usb_ch9.h:28
uint8_t direction
Definition: usb_ch9.h:29
Definition: usb_ch9.h:38
uint8_t bmRequestType
Definition: usb_ch9.h:40
uint16_t wLength
Definition: usb_ch9.h:46
uint16_t wValue
Definition: usb_ch9.h:44
uint16_t wIndex
Definition: usb_ch9.h:45
uint8_t bRequest
Definition: usb_ch9.h:43
struct usb_req_type_field RequestType
Definition: usb_ch9.h:41
Definition: usb_ch9.h:201
uint8_t bDescriptorType
Definition: usb_ch9.h:203
uint8_t bLength
Definition: usb_ch9.h:202
uint16_t bString
Definition: usb_ch9.h:204
static bool usb_reqtype_is_to_host(struct usb_setup_packet *setup)
Check if request transfer direction is to host.
Definition: usb_ch9.h:78
static bool usb_reqtype_is_to_device(struct usb_setup_packet *setup)
Check if request transfer direction is to device.
Definition: usb_ch9.h:89
#define USB_REQTYPE_DIR_TO_DEVICE
Definition: usb_ch9.h:50
#define USB_REQTYPE_DIR_TO_HOST
Definition: usb_ch9.h:51
Misc utilities.