15#include <zephyr/version.h>
20#ifndef ZEPHYR_INCLUDE_USB_CH9_H_
21#define ZEPHYR_INCLUDE_USB_CH9_H_
28#ifdef CONFIG_LITTLE_ENDIAN
52#define USB_REQTYPE_DIR_TO_DEVICE 0
53#define USB_REQTYPE_DIR_TO_HOST 1
56#define USB_REQTYPE_TYPE_STANDARD 0
57#define USB_REQTYPE_TYPE_CLASS 1
58#define USB_REQTYPE_TYPE_VENDOR 2
59#define USB_REQTYPE_TYPE_RESERVED 3
62#define USB_REQTYPE_RECIPIENT_DEVICE 0
63#define USB_REQTYPE_RECIPIENT_INTERFACE 1
64#define USB_REQTYPE_RECIPIENT_ENDPOINT 2
65#define USB_REQTYPE_RECIPIENT_OTHER 3
68#define USB_REQTYPE_GET_DIR(bmRequestType) (((bmRequestType) >> 7) & 0x01U)
70#define USB_REQTYPE_GET_TYPE(bmRequestType) (((bmRequestType) >> 5) & 0x03U)
72#define USB_REQTYPE_GET_RECIPIENT(bmRequestType) ((bmRequestType) & 0x1FU)
97#define USB_SREQ_GET_STATUS 0x00
98#define USB_SREQ_CLEAR_FEATURE 0x01
99#define USB_SREQ_SET_FEATURE 0x03
100#define USB_SREQ_SET_ADDRESS 0x05
101#define USB_SREQ_GET_DESCRIPTOR 0x06
102#define USB_SREQ_SET_DESCRIPTOR 0x07
103#define USB_SREQ_GET_CONFIGURATION 0x08
104#define USB_SREQ_SET_CONFIGURATION 0x09
105#define USB_SREQ_GET_INTERFACE 0x0A
106#define USB_SREQ_SET_INTERFACE 0x0B
107#define USB_SREQ_SYNCH_FRAME 0x0C
110#define USB_DESC_DEVICE 1
111#define USB_DESC_CONFIGURATION 2
112#define USB_DESC_STRING 3
113#define USB_DESC_INTERFACE 4
114#define USB_DESC_ENDPOINT 5
115#define USB_DESC_DEVICE_QUALIFIER 6
116#define USB_DESC_OTHER_SPEED 7
117#define USB_DESC_INTERFACE_POWER 8
119#define USB_DESC_OTG 9
120#define USB_DESC_DEBUG 10
121#define USB_DESC_INTERFACE_ASSOC 11
122#define USB_DESC_BOS 15
123#define USB_DESC_DEVICE_CAPABILITY 16
128#define USB_DESC_CS_DEVICE 0x21
129#define USB_DESC_CS_CONFIGURATION 0x22
130#define USB_DESC_CS_STRING 0x23
131#define USB_DESC_CS_INTERFACE 0x24
132#define USB_DESC_CS_ENDPOINT 0x25
135#define USB_SFS_ENDPOINT_HALT 0x00
136#define USB_SFS_REMOTE_WAKEUP 0x01
137#define USB_SFS_TEST_MODE 0x02
140#define USB_GET_STATUS_SELF_POWERED BIT(0)
141#define USB_GET_STATUS_REMOTE_WAKEUP BIT(1)
206#ifdef CONFIG_LITTLE_ENDIAN
252#define USB_SCD_RESERVED BIT(7)
253#define USB_SCD_SELF_POWERED BIT(6)
254#define USB_SCD_REMOTE_WAKEUP BIT(5)
257#define USB_BCC_AUDIO 0x01
258#define USB_BCC_CDC_CONTROL 0x02
259#define USB_BCC_HID 0x03
260#define USB_BCC_MASS_STORAGE 0x08
261#define USB_BCC_CDC_DATA 0x0A
262#define USB_BCC_VIDEO 0x0E
263#define USB_BCC_WIRELESS_CONTROLLER 0xE0
264#define USB_BCC_MISCELLANEOUS 0xEF
265#define USB_BCC_APPLICATION 0xFE
266#define USB_BCC_VENDOR 0xFF
269#define USB_SRN_1_1 0x0110
270#define USB_SRN_2_0 0x0200
271#define USB_SRN_2_0_1 0x0201
272#define USB_SRN_2_1 0x0210
274#define USB_DEC_TO_BCD(dec) ((((dec) / 10) << 4) | ((dec) % 10))
277#define USB_BCD_DRN (USB_DEC_TO_BCD(KERNEL_VERSION_MAJOR) << 8 | \
278 USB_DEC_TO_BCD(KERNEL_VERSION_MINOR))
281#define USB_GET_DESCRIPTOR_TYPE(wValue) ((uint8_t)((wValue) >> 8))
284#define USB_GET_DESCRIPTOR_INDEX(wValue) ((uint8_t)(wValue))
287#define USB_CONTROL_EP_MPS 64U
290#define USB_EP_DIR_MASK (uint8_t)BIT(7)
293#define USB_EP_DIR_IN (uint8_t)BIT(7)
296#define USB_EP_DIR_OUT 0U
304#define USB_EP_GET_IDX(ep) ((ep) & ~USB_EP_DIR_MASK)
307#define USB_EP_GET_DIR(ep) ((ep) & USB_EP_DIR_MASK)
310#define USB_EP_GET_ADDR(idx, dir) ((idx) | ((dir) & USB_EP_DIR_MASK))
313#define USB_EP_DIR_IS_IN(ep) (USB_EP_GET_DIR(ep) == USB_EP_DIR_IN)
316#define USB_EP_DIR_IS_OUT(ep) (USB_EP_GET_DIR(ep) == USB_EP_DIR_OUT)
319#define USB_CONTROL_EP_OUT (USB_EP_DIR_OUT | 0U)
322#define USB_CONTROL_EP_IN (USB_EP_DIR_IN | 0U)
325#define USB_EP_TRANSFER_TYPE_MASK 0x3U
328#define USB_EP_TYPE_CONTROL 0U
331#define USB_EP_TYPE_ISO 1U
334#define USB_EP_TYPE_BULK 2U
337#define USB_EP_TYPE_INTERRUPT 3U
340#define USB_FS_INT_EP_INTERVAL(us) CLAMP(((us) / 1000U), 1U, 255U)
343#define USB_HS_INT_EP_INTERVAL(us) CLAMP((ilog2((us) / 125U) + 1U), 1U, 16U)
346#define USB_FS_ISO_EP_INTERVAL(us) CLAMP(((us) / 1000U), 1U, 16U)
349#define USB_HS_ISO_EP_INTERVAL(us) CLAMP((ilog2((us) / 125U) + 1U), 1U, 16U)
Provide ilog2() function.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
USB Association Descriptor defined in USB 3 spec.
Definition usb_ch9.h:240
uint8_t bLength
Definition usb_ch9.h:241
uint8_t bFunctionClass
Definition usb_ch9.h:245
uint8_t bFunctionSubClass
Definition usb_ch9.h:246
uint8_t iFunction
Definition usb_ch9.h:248
uint8_t bFunctionProtocol
Definition usb_ch9.h:247
uint8_t bInterfaceCount
Definition usb_ch9.h:244
uint8_t bFirstInterface
Definition usb_ch9.h:243
uint8_t bDescriptorType
Definition usb_ch9.h:242
USB Standard Configuration Descriptor defined in spec.
Definition usb_ch9.h:181
uint8_t bLength
Definition usb_ch9.h:182
uint8_t bmAttributes
Definition usb_ch9.h:188
uint8_t bMaxPower
Definition usb_ch9.h:189
uint8_t bConfigurationValue
Definition usb_ch9.h:186
uint8_t bDescriptorType
Definition usb_ch9.h:183
uint8_t iConfiguration
Definition usb_ch9.h:187
uint8_t bNumInterfaces
Definition usb_ch9.h:185
uint16_t wTotalLength
Definition usb_ch9.h:184
USB Standard Device Descriptor defined in spec.
Definition usb_ch9.h:150
uint16_t idVendor
Definition usb_ch9.h:158
uint8_t iSerialNumber
Definition usb_ch9.h:163
uint16_t bcdDevice
Definition usb_ch9.h:160
uint8_t bDeviceProtocol
Definition usb_ch9.h:156
uint8_t bNumConfigurations
Definition usb_ch9.h:164
uint16_t idProduct
Definition usb_ch9.h:159
uint16_t bcdUSB
Definition usb_ch9.h:153
uint8_t bDeviceClass
Definition usb_ch9.h:154
uint8_t bMaxPacketSize0
Definition usb_ch9.h:157
uint8_t iProduct
Definition usb_ch9.h:162
uint8_t iManufacturer
Definition usb_ch9.h:161
uint8_t bDescriptorType
Definition usb_ch9.h:152
uint8_t bDeviceSubClass
Definition usb_ch9.h:155
uint8_t bLength
Definition usb_ch9.h:151
USB Device Qualifier Descriptor defined in spec.
Definition usb_ch9.h:168
uint8_t bDescriptorType
Definition usb_ch9.h:170
uint8_t bNumConfigurations
Definition usb_ch9.h:176
uint8_t bDeviceSubClass
Definition usb_ch9.h:173
uint8_t bDeviceProtocol
Definition usb_ch9.h:174
uint8_t bReserved
Definition usb_ch9.h:177
uint16_t bcdUSB
Definition usb_ch9.h:171
uint8_t bLength
Definition usb_ch9.h:169
uint8_t bMaxPacketSize0
Definition usb_ch9.h:175
uint8_t bDeviceClass
Definition usb_ch9.h:172
uint8_t transfer
Definition usb_ch9.h:215
uint8_t synch
Definition usb_ch9.h:214
uint8_t reserved
Definition usb_ch9.h:212
uint8_t usage
Definition usb_ch9.h:213
USB Standard Endpoint Descriptor defined in spec.
Definition usb_ch9.h:220
uint8_t bDescriptorType
Definition usb_ch9.h:222
uint8_t bEndpointAddress
Definition usb_ch9.h:223
struct usb_ep_desc_bmattr Attributes
Definition usb_ch9.h:226
uint8_t bInterval
Definition usb_ch9.h:229
uint16_t wMaxPacketSize
Definition usb_ch9.h:228
uint8_t bmAttributes
Definition usb_ch9.h:225
uint8_t bLength
Definition usb_ch9.h:221
USB Standard Interface Descriptor defined in spec.
Definition usb_ch9.h:193
uint8_t bAlternateSetting
Definition usb_ch9.h:197
uint8_t bInterfaceSubClass
Definition usb_ch9.h:200
uint8_t bInterfaceProtocol
Definition usb_ch9.h:201
uint8_t bNumEndpoints
Definition usb_ch9.h:198
uint8_t bInterfaceClass
Definition usb_ch9.h:199
uint8_t iInterface
Definition usb_ch9.h:202
uint8_t bDescriptorType
Definition usb_ch9.h:195
uint8_t bLength
Definition usb_ch9.h:194
uint8_t bInterfaceNumber
Definition usb_ch9.h:196
uint8_t recipient
Definition usb_ch9.h:35
uint8_t type
Definition usb_ch9.h:34
uint8_t direction
Definition usb_ch9.h:33
USB Setup Data packet defined in spec.
Definition usb_ch9.h:40
uint8_t bmRequestType
Definition usb_ch9.h:42
uint16_t wLength
Definition usb_ch9.h:48
uint16_t wValue
Definition usb_ch9.h:46
uint16_t wIndex
Definition usb_ch9.h:47
uint8_t bRequest
Definition usb_ch9.h:45
struct usb_req_type_field RequestType
Definition usb_ch9.h:43
USB Unicode (UTF16LE) String Descriptor defined in spec.
Definition usb_ch9.h:233
uint8_t bDescriptorType
Definition usb_ch9.h:235
uint8_t bLength
Definition usb_ch9.h:234
uint16_t bString
Definition usb_ch9.h:236
#define USB_REQTYPE_DIR_TO_DEVICE
USB Setup packet RequestType Direction values (from Table 9-2)
Definition usb_ch9.h:52
static bool usb_reqtype_is_to_device(const struct usb_setup_packet *setup)
Check if request transfer direction is to device.
Definition usb_ch9.h:91
static bool usb_reqtype_is_to_host(const struct usb_setup_packet *setup)
Check if request transfer direction is to host.
Definition usb_ch9.h:80
#define USB_REQTYPE_DIR_TO_HOST
Definition usb_ch9.h:53
USB Hub Class device API header.