Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
usb_ch9.h File Reference

USB Chapter 9 structures and definitions. More...

#include <version.h>
#include <sys/util.h>

Go to the source code of this file.

Data Structures

struct  usb_req_type_field
 
struct  usb_setup_packet
 
struct  usb_desc_header
 
struct  usb_device_descriptor
 
struct  usb_cfg_descriptor
 
struct  usb_if_descriptor
 
struct  usb_ep_descriptor
 
struct  usb_string_descriptor
 
struct  usb_association_descriptor
 

Macros

#define USB_REQTYPE_DIR_TO_DEVICE   0
 
#define USB_REQTYPE_DIR_TO_HOST   1
 
#define USB_REQTYPE_TYPE_STANDARD   0
 
#define USB_REQTYPE_TYPE_CLASS   1
 
#define USB_REQTYPE_TYPE_VENDOR   2
 
#define USB_REQTYPE_TYPE_RESERVED   3
 
#define USB_REQTYPE_RECIPIENT_DEVICE   0
 
#define USB_REQTYPE_RECIPIENT_INTERFACE   1
 
#define USB_REQTYPE_RECIPIENT_ENDPOINT   2
 
#define USB_REQTYPE_RECIPIENT_OTHER   3
 
#define USB_REQTYPE_GET_DIR(bmRequestType)   (((bmRequestType) >> 7) & 0x01U)
 
#define USB_REQTYPE_GET_TYPE(bmRequestType)   (((bmRequestType) >> 5) & 0x03U)
 
#define USB_REQTYPE_GET_RECIPIENT(bmRequestType)   ((bmRequestType) & 0x1FU)
 
#define USB_SREQ_GET_STATUS   0x00
 
#define USB_SREQ_CLEAR_FEATURE   0x01
 
#define USB_SREQ_SET_FEATURE   0x03
 
#define USB_SREQ_SET_ADDRESS   0x05
 
#define USB_SREQ_GET_DESCRIPTOR   0x06
 
#define USB_SREQ_SET_DESCRIPTOR   0x07
 
#define USB_SREQ_GET_CONFIGURATION   0x08
 
#define USB_SREQ_SET_CONFIGURATION   0x09
 
#define USB_SREQ_GET_INTERFACE   0x0A
 
#define USB_SREQ_SET_INTERFACE   0x0B
 
#define USB_SREQ_SYNCH_FRAME   0x0C
 
#define USB_DESC_DEVICE   1
 
#define USB_DESC_CONFIGURATION   2
 
#define USB_DESC_STRING   3
 
#define USB_DESC_INTERFACE   4
 
#define USB_DESC_ENDPOINT   5
 
#define USB_DESC_DEVICE_QUALIFIER   6
 
#define USB_DESC_OTHER_SPEED   7
 
#define USB_DESC_INTERFACE_POWER   8
 
#define USB_DESC_OTG   9
 
#define USB_DESC_DEBUG   10
 
#define USB_DESC_INTERFACE_ASSOC   11
 
#define USB_DESC_BOS   15
 
#define USB_DESC_DEVICE_CAPABILITY   16
 
#define USB_DESC_CS_DEVICE   0x21
 
#define USB_DESC_CS_CONFIGURATION   0x22
 
#define USB_DESC_CS_STRING   0x23
 
#define USB_DESC_CS_INTERFACE   0x24
 
#define USB_DESC_CS_ENDPOINT   0x25
 
#define USB_SFS_ENDPOINT_HALT   0x00
 
#define USB_SFS_REMOTE_WAKEUP   0x01
 
#define USB_SFS_TEST_MODE   0x02
 
#define USB_GET_STATUS_SELF_POWERED   BIT(0)
 
#define USB_GET_STATUS_REMOTE_WAKEUP   BIT(1)
 
#define USB_SCD_RESERVED   BIT(7)
 
#define USB_SCD_SELF_POWERED   BIT(6)
 
#define USB_SCD_REMOTE_WAKEUP   BIT(5)
 
#define USB_SCD_ATTRIBUTES
 
#define USB_BCC_AUDIO   0x01
 
#define USB_BCC_CDC_CONTROL   0x02
 
#define USB_BCC_HID   0x03
 
#define USB_BCC_MASS_STORAGE   0x08
 
#define USB_BCC_CDC_DATA   0x0A
 
#define USB_BCC_VIDEO   0x0E
 
#define USB_BCC_WIRELESS_CONTROLLER   0xE0
 
#define USB_BCC_MISCELLANEOUS   0xEF
 
#define USB_BCC_APPLICATION   0xFE
 
#define USB_BCC_VENDOR   0xFF
 
#define USB_SRN_1_1   0x0110
 
#define USB_SRN_2_0   0x0200
 
#define USB_SRN_2_1   0x0210
 
#define USB_DEC_TO_BCD(dec)   ((((dec) / 10) << 4) | ((dec) % 10))
 
#define USB_BCD_DRN
 
#define USB_GET_DESCRIPTOR_TYPE(wValue)   ((uint8_t)((wValue) >> 8))
 
#define USB_GET_DESCRIPTOR_INDEX(wValue)   ((uint8_t)(wValue))
 
#define USB_CONTROL_EP_OUT   0
 
#define USB_CONTROL_EP_IN   0x80
 
#define USB_CONTROL_EP_MPS   64
 

Functions

static bool usb_reqtype_is_to_host (struct usb_setup_packet *setup)
 Check if request transfer direction is to host. More...
 
static bool usb_reqtype_is_to_device (struct usb_setup_packet *setup)
 Check if request transfer direction is to device. More...
 

Detailed Description

USB Chapter 9 structures and definitions.

This file contains the USB Chapter 9 structures definitions and follows, with few exceptions, the USB Specification 2.0.

Macro Definition Documentation

◆ USB_BCC_APPLICATION

#define USB_BCC_APPLICATION   0xFE

◆ USB_BCC_AUDIO

#define USB_BCC_AUDIO   0x01

USB Defined Base Class Codes from https://www.usb.org/defined-class-codes

◆ USB_BCC_CDC_CONTROL

#define USB_BCC_CDC_CONTROL   0x02

◆ USB_BCC_CDC_DATA

#define USB_BCC_CDC_DATA   0x0A

◆ USB_BCC_HID

#define USB_BCC_HID   0x03

◆ USB_BCC_MASS_STORAGE

#define USB_BCC_MASS_STORAGE   0x08

◆ USB_BCC_MISCELLANEOUS

#define USB_BCC_MISCELLANEOUS   0xEF

◆ USB_BCC_VENDOR

#define USB_BCC_VENDOR   0xFF

◆ USB_BCC_VIDEO

#define USB_BCC_VIDEO   0x0E

◆ USB_BCC_WIRELESS_CONTROLLER

#define USB_BCC_WIRELESS_CONTROLLER   0xE0

◆ USB_BCD_DRN

#define USB_BCD_DRN
Value:
(USB_DEC_TO_BCD(KERNEL_VERSION_MAJOR) << 8 | \
USB_DEC_TO_BCD(KERNEL_VERSION_MINOR))
#define USB_DEC_TO_BCD(dec)
Definition: usb_ch9.h:246

USB Device release number (bcdDevice Descriptor field)

◆ USB_CONTROL_EP_IN

#define USB_CONTROL_EP_IN   0x80

◆ USB_CONTROL_EP_MPS

#define USB_CONTROL_EP_MPS   64

USB Control Endpoints maximum packet size (MPS)

◆ USB_CONTROL_EP_OUT

#define USB_CONTROL_EP_OUT   0

USB Control Endpoints OUT and IN Address

◆ USB_DEC_TO_BCD

#define USB_DEC_TO_BCD (   dec)    ((((dec) / 10) << 4) | ((dec) % 10))

◆ USB_DESC_BOS

#define USB_DESC_BOS   15

◆ USB_DESC_CONFIGURATION

#define USB_DESC_CONFIGURATION   2

◆ USB_DESC_CS_CONFIGURATION

#define USB_DESC_CS_CONFIGURATION   0x22

◆ USB_DESC_CS_DEVICE

#define USB_DESC_CS_DEVICE   0x21

Class-Specific Descriptor Types as defined by USB Common Class Specification

◆ USB_DESC_CS_ENDPOINT

#define USB_DESC_CS_ENDPOINT   0x25

◆ USB_DESC_CS_INTERFACE

#define USB_DESC_CS_INTERFACE   0x24

◆ USB_DESC_CS_STRING

#define USB_DESC_CS_STRING   0x23

◆ USB_DESC_DEBUG

#define USB_DESC_DEBUG   10

◆ USB_DESC_DEVICE

#define USB_DESC_DEVICE   1

Descriptor Types defined in spec. Table 9-5

◆ USB_DESC_DEVICE_CAPABILITY

#define USB_DESC_DEVICE_CAPABILITY   16

◆ USB_DESC_DEVICE_QUALIFIER

#define USB_DESC_DEVICE_QUALIFIER   6

◆ USB_DESC_ENDPOINT

#define USB_DESC_ENDPOINT   5

◆ USB_DESC_INTERFACE

#define USB_DESC_INTERFACE   4

◆ USB_DESC_INTERFACE_ASSOC

#define USB_DESC_INTERFACE_ASSOC   11

◆ USB_DESC_INTERFACE_POWER

#define USB_DESC_INTERFACE_POWER   8

◆ USB_DESC_OTG

#define USB_DESC_OTG   9

Additional Descriptor Types defined in USB 3 spec. Table 9-5

◆ USB_DESC_OTHER_SPEED

#define USB_DESC_OTHER_SPEED   7

◆ USB_DESC_STRING

#define USB_DESC_STRING   3

◆ USB_GET_DESCRIPTOR_INDEX

#define USB_GET_DESCRIPTOR_INDEX (   wValue)    ((uint8_t)(wValue))

Macro to obtain descriptor index from USB_SREQ_GET_DESCRIPTOR request

◆ USB_GET_DESCRIPTOR_TYPE

#define USB_GET_DESCRIPTOR_TYPE (   wValue)    ((uint8_t)((wValue) >> 8))

Macro to obtain descriptor type from USB_SREQ_GET_DESCRIPTOR request

◆ USB_GET_STATUS_REMOTE_WAKEUP

#define USB_GET_STATUS_REMOTE_WAKEUP   BIT(1)

◆ USB_GET_STATUS_SELF_POWERED

#define USB_GET_STATUS_SELF_POWERED   BIT(0)

Bits used for GetStatus response defined in spec. Figure 9-4

◆ USB_REQTYPE_DIR_TO_DEVICE

#define USB_REQTYPE_DIR_TO_DEVICE   0

USB Setup packet RequestType Direction values (from Table 9-2)

◆ USB_REQTYPE_DIR_TO_HOST

#define USB_REQTYPE_DIR_TO_HOST   1

◆ USB_REQTYPE_GET_DIR

#define USB_REQTYPE_GET_DIR (   bmRequestType)    (((bmRequestType) >> 7) & 0x01U)

Get data transfer direction from bmRequestType

◆ USB_REQTYPE_GET_RECIPIENT

#define USB_REQTYPE_GET_RECIPIENT (   bmRequestType)    ((bmRequestType) & 0x1FU)

Get request recipient from bmRequestType

◆ USB_REQTYPE_GET_TYPE

#define USB_REQTYPE_GET_TYPE (   bmRequestType)    (((bmRequestType) >> 5) & 0x03U)

Get request type from bmRequestType

◆ USB_REQTYPE_RECIPIENT_DEVICE

#define USB_REQTYPE_RECIPIENT_DEVICE   0

USB Setup packet RequestType Recipient values (from Table 9-2)

◆ USB_REQTYPE_RECIPIENT_ENDPOINT

#define USB_REQTYPE_RECIPIENT_ENDPOINT   2

◆ USB_REQTYPE_RECIPIENT_INTERFACE

#define USB_REQTYPE_RECIPIENT_INTERFACE   1

◆ USB_REQTYPE_RECIPIENT_OTHER

#define USB_REQTYPE_RECIPIENT_OTHER   3

◆ USB_REQTYPE_TYPE_CLASS

#define USB_REQTYPE_TYPE_CLASS   1

◆ USB_REQTYPE_TYPE_RESERVED

#define USB_REQTYPE_TYPE_RESERVED   3

◆ USB_REQTYPE_TYPE_STANDARD

#define USB_REQTYPE_TYPE_STANDARD   0

USB Setup packet RequestType Type values (from Table 9-2)

◆ USB_REQTYPE_TYPE_VENDOR

#define USB_REQTYPE_TYPE_VENDOR   2

◆ USB_SCD_ATTRIBUTES

#define USB_SCD_ATTRIBUTES
Value:
COND_CODE_1(CONFIG_USB_SELF_POWERED, \
COND_CODE_1(CONFIG_USB_DEVICE_REMOTE_WAKEUP, \
#define USB_SCD_SELF_POWERED
Definition: usb_ch9.h:221
#define USB_SCD_RESERVED
Definition: usb_ch9.h:220
#define USB_SCD_REMOTE_WAKEUP
Definition: usb_ch9.h:222

◆ USB_SCD_REMOTE_WAKEUP

#define USB_SCD_REMOTE_WAKEUP   BIT(5)

◆ USB_SCD_RESERVED

#define USB_SCD_RESERVED   BIT(7)

USB Standard Configuration Descriptor Characteristics from Table 9-10

◆ USB_SCD_SELF_POWERED

#define USB_SCD_SELF_POWERED   BIT(6)

◆ USB_SFS_ENDPOINT_HALT

#define USB_SFS_ENDPOINT_HALT   0x00

USB Standard Feature Selectors defined in spec. Table 9-6

◆ USB_SFS_REMOTE_WAKEUP

#define USB_SFS_REMOTE_WAKEUP   0x01

◆ USB_SFS_TEST_MODE

#define USB_SFS_TEST_MODE   0x02

◆ USB_SREQ_CLEAR_FEATURE

#define USB_SREQ_CLEAR_FEATURE   0x01

◆ USB_SREQ_GET_CONFIGURATION

#define USB_SREQ_GET_CONFIGURATION   0x08

◆ USB_SREQ_GET_DESCRIPTOR

#define USB_SREQ_GET_DESCRIPTOR   0x06

◆ USB_SREQ_GET_INTERFACE

#define USB_SREQ_GET_INTERFACE   0x0A

◆ USB_SREQ_GET_STATUS

#define USB_SREQ_GET_STATUS   0x00

USB Standard Request Codes defined in spec. Table 9-4

◆ USB_SREQ_SET_ADDRESS

#define USB_SREQ_SET_ADDRESS   0x05

◆ USB_SREQ_SET_CONFIGURATION

#define USB_SREQ_SET_CONFIGURATION   0x09

◆ USB_SREQ_SET_DESCRIPTOR

#define USB_SREQ_SET_DESCRIPTOR   0x07

◆ USB_SREQ_SET_FEATURE

#define USB_SREQ_SET_FEATURE   0x03

◆ USB_SREQ_SET_INTERFACE

#define USB_SREQ_SET_INTERFACE   0x0B

◆ USB_SREQ_SYNCH_FRAME

#define USB_SREQ_SYNCH_FRAME   0x0C

◆ USB_SRN_1_1

#define USB_SRN_1_1   0x0110

USB Specification Release Numbers (bcdUSB Descriptor field)

◆ USB_SRN_2_0

#define USB_SRN_2_0   0x0200

◆ USB_SRN_2_1

#define USB_SRN_2_1   0x0210

Function Documentation

◆ usb_reqtype_is_to_device()

static bool usb_reqtype_is_to_device ( struct usb_setup_packet setup)
inlinestatic

Check if request transfer direction is to device.

Parameters
setupPointer to USB Setup packet
Returns
true If transfer direction is to device

◆ usb_reqtype_is_to_host()

static bool usb_reqtype_is_to_host ( struct usb_setup_packet setup)
inlinestatic

Check if request transfer direction is to host.

Parameters
setupPointer to USB Setup packet
Returns
true If transfer direction is to host