Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
usb_ch9.h File Reference

USB Chapter 9 structures and definitions. More...

#include <zephyr/version.h>
#include <zephyr/sys/util.h>
#include <zephyr/math/ilog2.h>
#include <zephyr/usb/class/usb_hub.h>

Go to the source code of this file.

Data Structures

struct  usb_req_type_field
 Representation of the bmRequestType bit field. More...
struct  usb_setup_packet
 USB Setup Data packet. More...
struct  usb_desc_header
 Header of a USB descriptor. More...
struct  usb_cs_desc_header
 Header of an USB class-specific descriptor. More...
struct  usb_device_descriptor
 USB Standard Device Descriptor. More...
struct  usb_device_qualifier_descriptor
 USB Device Qualifier Descriptor. More...
struct  usb_cfg_descriptor
 USB Standard Configuration Descriptor. More...
struct  usb_if_descriptor
 USB Standard Interface Descriptor. More...
struct  usb_ep_desc_bmattr
 Endpoint attribute bit fields. More...
struct  usb_ep_descriptor
 USB Standard Endpoint Descriptor. More...
struct  usb_string_descriptor
 USB Unicode (UTF16LE) String Descriptor. More...
struct  usb_association_descriptor
 USB Association Descriptor defined in USB 3 spec. More...

Macros

#define USB_REQTYPE_GET_DIR(bmRequestType)
 Get data transfer direction from bmRequestType.
#define USB_REQTYPE_GET_TYPE(bmRequestType)
 Get request type from bmRequestType.
#define USB_REQTYPE_GET_RECIPIENT(bmRequestType)
 Get request recipient from bmRequestType.
#define USB_DEC_TO_BCD(dec)
 Convert a decimal value to BCD representation.
#define USB_BCD_DRN
 USB Device release number (bcdDevice Descriptor field).
#define USB_GET_DESCRIPTOR_TYPE(wValue)
 Obtain descriptor type from USB_SREQ_GET_DESCRIPTOR request value.
#define USB_GET_DESCRIPTOR_INDEX(wValue)
 Obtain descriptor index from USB_SREQ_GET_DESCRIPTOR request value.
#define USB_CONTROL_EP_MPS   64U
 USB Control Endpoints maximum packet size (MPS).
#define USB_EP_DIR_MASK   (uint8_t)BIT(7)
 USB endpoint direction mask.
#define USB_EP_DIR_IN   (uint8_t)BIT(7)
 USB IN endpoint direction.
#define USB_EP_DIR_OUT   0U
 USB OUT endpoint direction.
#define USB_EP_GET_IDX(ep)
 Get endpoint index (number) from endpoint address.
#define USB_EP_GET_DIR(ep)
 Get direction based on endpoint address.
#define USB_EP_GET_ADDR(idx, dir)
 Get endpoint address from endpoint index and direction.
#define USB_EP_DIR_IS_IN(ep)
 Determine if an endpoint address refers to an IN endpoint.
#define USB_EP_DIR_IS_OUT(ep)
 Determine if an endpoint address refers to an OUT endpoint.
#define USB_CONTROL_EP_OUT   (USB_EP_DIR_OUT | 0U)
 USB Control Endpoints OUT address.
#define USB_CONTROL_EP_IN   (USB_EP_DIR_IN | 0U)
 USB Control Endpoints IN address.
#define USB_FS_INT_EP_INTERVAL(us)
 Calculate full speed interrupt endpoint bInterval from a value in microseconds.
#define USB_HS_INT_EP_INTERVAL(us)
 Calculate high speed interrupt endpoint bInterval from microseconds.
#define USB_FS_ISO_EP_INTERVAL(us)
 Calculate full speed isochronous endpoint bInterval from microseconds.
#define USB_HS_ISO_EP_INTERVAL(us)
 Calculate high speed isochronous endpoint bInterval from microseconds.
#define USB_MPS_EP_SIZE(mps)
 Get endpoint size field from Max Packet Size value.
#define USB_MPS_ADDITIONAL_TRANSACTIONS(mps)
 Get number of additional transactions per microframe from MPS.
#define USB_MPS_TO_TPL(mps)
 Calculate total payload length from Max Packet Size value.
#define USB_TPL_TO_MPS(tpl)
 Calculate Max Packet Size value from total payload length.
#define USB_TPL_ROUND_UP(tpl)
 Round up total payload length to the next valid value.
#define USB_TPL_IS_VALID(tpl)
 Determine whether total payload length value is valid according to USB 2.0.
USB Setup packet RequestType Direction values. See Table 9-2 of the specification.

#define USB_REQTYPE_DIR_TO_DEVICE   0
 Host-to-device data direction.
#define USB_REQTYPE_DIR_TO_HOST   1
 Device-to-host data direction.
USB Setup packet RequestType Type values. See Table 9-2 of the specification.

#define USB_REQTYPE_TYPE_STANDARD   0
 Standard USB request.
#define USB_REQTYPE_TYPE_CLASS   1
 Class-specific request.
#define USB_REQTYPE_TYPE_VENDOR   2
 Vendor-specific request.
#define USB_REQTYPE_TYPE_RESERVED   3
 Reserved request type.
USB Setup packet RequestType Recipient values. See Table 9-2 of the specification.

#define USB_REQTYPE_RECIPIENT_DEVICE   0
 Device recipient.
#define USB_REQTYPE_RECIPIENT_INTERFACE   1
 Interface recipient.
#define USB_REQTYPE_RECIPIENT_ENDPOINT   2
 Endpoint recipient.
#define USB_REQTYPE_RECIPIENT_OTHER   3
 Other recipient.
USB Standard Request Codes. See Table 9-4 of the specification.
#define USB_SREQ_GET_STATUS   0x00
 Get Status request.
#define USB_SREQ_CLEAR_FEATURE   0x01
 Clear Feature request.
#define USB_SREQ_SET_FEATURE   0x03
 Set Feature request.
#define USB_SREQ_SET_ADDRESS   0x05
 Set Address request.
#define USB_SREQ_GET_DESCRIPTOR   0x06
 Get Descriptor request.
#define USB_SREQ_SET_DESCRIPTOR   0x07
 Set Descriptor request.
#define USB_SREQ_GET_CONFIGURATION   0x08
 Get Configuration request.
#define USB_SREQ_SET_CONFIGURATION   0x09
 Set Configuration request.
#define USB_SREQ_GET_INTERFACE   0x0A
 Get Interface request.
#define USB_SREQ_SET_INTERFACE   0x0B
 Set Interface request.
#define USB_SREQ_SYNCH_FRAME   0x0C
 Synch Frame request.
Descriptor Types. See Table 9-5 of the specification.
#define USB_DESC_DEVICE   1
 Device descriptor type.
#define USB_DESC_CONFIGURATION   2
 Configuration descriptor type.
#define USB_DESC_STRING   3
 String descriptor type.
#define USB_DESC_INTERFACE   4
 Interface descriptor type.
#define USB_DESC_ENDPOINT   5
 Endpoint descriptor type.
#define USB_DESC_DEVICE_QUALIFIER   6
 Device qualifier descriptor type.
#define USB_DESC_OTHER_SPEED   7
 Other speed configuration descriptor type.
#define USB_DESC_INTERFACE_POWER   8
 Interface power descriptor type.
Additional Descriptor Types. See Table 9-5 of the specification.
#define USB_DESC_OTG   9
 OTG descriptor type.
#define USB_DESC_DEBUG   10
 Debug descriptor type.
#define USB_DESC_INTERFACE_ASSOC   11
 Interface association descriptor type.
#define USB_DESC_BOS   15
 Binary object store descriptor type.
#define USB_DESC_DEVICE_CAPABILITY   16
 Device capability descriptor type.
Class-Specific Descriptor Types defined by USB Common Class Specification
#define USB_DESC_CS_DEVICE   0x21
 Class-specific device descriptor type.
#define USB_DESC_CS_CONFIGURATION   0x22
 Class-specific configuration descriptor type.
#define USB_DESC_CS_STRING   0x23
 Class-specific string descriptor type.
#define USB_DESC_CS_INTERFACE   0x24
 Class-specific interface descriptor type.
#define USB_DESC_CS_ENDPOINT   0x25
 Class-specific endpoint descriptor type.
USB Standard Feature Selectors. See Table 9-6 of the specification.
#define USB_SFS_ENDPOINT_HALT   0x00
 Endpoint halt feature selector.
#define USB_SFS_REMOTE_WAKEUP   0x01
 Remote wakeup feature selector.
#define USB_SFS_TEST_MODE   0x02
 Test mode feature selector.
USB Test Mode Selectors. See Table 9-7 of the specification.
#define USB_SFS_TEST_MODE_J   0x01
 Test_J test mode.
#define USB_SFS_TEST_MODE_K   0x02
 Test_K test mode.
#define USB_SFS_TEST_MODE_SE0_NAK   0x03
 Test_SE0_NAK test mode.
#define USB_SFS_TEST_MODE_PACKET   0x04
 Test_Packet test mode.
#define USB_SFS_TEST_MODE_FORCE_ENABLE   0x05
 Test_Force_Enable test mode.
Bits used for GetStatus response. See Figure 9-4.
#define USB_GET_STATUS_SELF_POWERED   BIT(0)
 Self-powered status bit.
#define USB_GET_STATUS_REMOTE_WAKEUP   BIT(1)
 Remote wakeup status bit.
USB Standard Configuration Descriptor Characteristics. See Table 9-10 of the specification.
#define USB_SCD_RESERVED   BIT(7)
 Reserved configuration bit.
#define USB_SCD_SELF_POWERED   BIT(6)
 Self-powered configuration bit.
#define USB_SCD_REMOTE_WAKEUP   BIT(5)
 Remote wakeup configuration bit.
USB Defined Base Class Codes
#define USB_BCC_AUDIO   0x01
 Audio device class.
#define USB_BCC_CDC_CONTROL   0x02
 CDC control device class.
#define USB_BCC_HID   0x03
 HID device class.
#define USB_BCC_MASS_STORAGE   0x08
 Mass storage device class.
#define USB_BCC_CDC_DATA   0x0A
 CDC data device class.
#define USB_BCC_VIDEO   0x0E
 Video device class.
#define USB_BCC_MCTP   0x14
 MCTP device class.
#define USB_BCC_WIRELESS_CONTROLLER   0xE0
 Wireless controller device class.
#define USB_BCC_MISCELLANEOUS   0xEF
 Miscellaneous device class.
#define USB_BCC_APPLICATION   0xFE
 Application-specific device class.
#define USB_BCC_VENDOR   0xFF
 Vendor-specific device class.
USB Specification Release Numbers (bcdUSB Descriptor field)
#define USB_SRN_1_1   0x0110
 USB 1.1 specification release number.
#define USB_SRN_2_0   0x0200
 USB 2.0 specification release number.
#define USB_SRN_2_0_1   0x0201
 USB 2.0.1 specification release number.
#define USB_SRN_2_1   0x0210
 USB 2.1 specification release number.
USB endpoint transfer types
#define USB_EP_TRANSFER_TYPE_MASK   0x3U
 Mask for endpoint transfer type.
#define USB_EP_TYPE_CONTROL   0U
 Control transfer endpoint.
#define USB_EP_TYPE_ISO   1U
 Isochronous transfer endpoint.
#define USB_EP_TYPE_BULK   2U
 Bulk transfer endpoint.
#define USB_EP_TYPE_INTERRUPT   3U
 Interrupt transfer endpoint.

Functions

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

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

Application-specific device class.

◆ USB_BCC_AUDIO

#define USB_BCC_AUDIO   0x01

Audio device class.

◆ USB_BCC_CDC_CONTROL

#define USB_BCC_CDC_CONTROL   0x02

CDC control device class.

◆ USB_BCC_CDC_DATA

#define USB_BCC_CDC_DATA   0x0A

CDC data device class.

◆ USB_BCC_HID

#define USB_BCC_HID   0x03

HID device class.

◆ USB_BCC_MASS_STORAGE

#define USB_BCC_MASS_STORAGE   0x08

Mass storage device class.

◆ USB_BCC_MCTP

#define USB_BCC_MCTP   0x14

MCTP device class.

◆ USB_BCC_MISCELLANEOUS

#define USB_BCC_MISCELLANEOUS   0xEF

Miscellaneous device class.

◆ USB_BCC_VENDOR

#define USB_BCC_VENDOR   0xFF

Vendor-specific device class.

◆ USB_BCC_VIDEO

#define USB_BCC_VIDEO   0x0E

Video device class.

◆ USB_BCC_WIRELESS_CONTROLLER

#define USB_BCC_WIRELESS_CONTROLLER   0xE0

Wireless controller device class.

◆ 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)
Convert a decimal value to BCD representation.
Definition usb_ch9.h:545

USB Device release number (bcdDevice Descriptor field).

◆ USB_CONTROL_EP_IN

#define USB_CONTROL_EP_IN   (USB_EP_DIR_IN | 0U)

USB Control Endpoints IN address.

◆ USB_CONTROL_EP_MPS

#define USB_CONTROL_EP_MPS   64U

USB Control Endpoints maximum packet size (MPS).

This value may not be correct for devices operating at speeds other than high speed.

◆ USB_CONTROL_EP_OUT

#define USB_CONTROL_EP_OUT   (USB_EP_DIR_OUT | 0U)

USB Control Endpoints OUT address.

◆ USB_DEC_TO_BCD

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

Convert a decimal value to BCD representation.

Parameters
decDecimal value.
Returns
Value encoded as BCD.

◆ USB_DESC_BOS

#define USB_DESC_BOS   15

Binary object store descriptor type.

◆ USB_DESC_CONFIGURATION

#define USB_DESC_CONFIGURATION   2

Configuration descriptor type.

◆ USB_DESC_CS_CONFIGURATION

#define USB_DESC_CS_CONFIGURATION   0x22

Class-specific configuration descriptor type.

◆ USB_DESC_CS_DEVICE

#define USB_DESC_CS_DEVICE   0x21

Class-specific device descriptor type.

◆ USB_DESC_CS_ENDPOINT

#define USB_DESC_CS_ENDPOINT   0x25

Class-specific endpoint descriptor type.

◆ USB_DESC_CS_INTERFACE

#define USB_DESC_CS_INTERFACE   0x24

Class-specific interface descriptor type.

◆ USB_DESC_CS_STRING

#define USB_DESC_CS_STRING   0x23

Class-specific string descriptor type.

◆ USB_DESC_DEBUG

#define USB_DESC_DEBUG   10

Debug descriptor type.

◆ USB_DESC_DEVICE

#define USB_DESC_DEVICE   1

Device descriptor type.

◆ USB_DESC_DEVICE_CAPABILITY

#define USB_DESC_DEVICE_CAPABILITY   16

Device capability descriptor type.

◆ USB_DESC_DEVICE_QUALIFIER

#define USB_DESC_DEVICE_QUALIFIER   6

Device qualifier descriptor type.

◆ USB_DESC_ENDPOINT

#define USB_DESC_ENDPOINT   5

Endpoint descriptor type.

◆ USB_DESC_INTERFACE

#define USB_DESC_INTERFACE   4

Interface descriptor type.

◆ USB_DESC_INTERFACE_ASSOC

#define USB_DESC_INTERFACE_ASSOC   11

Interface association descriptor type.

◆ USB_DESC_INTERFACE_POWER

#define USB_DESC_INTERFACE_POWER   8

Interface power descriptor type.

◆ USB_DESC_OTG

#define USB_DESC_OTG   9

OTG descriptor type.

◆ USB_DESC_OTHER_SPEED

#define USB_DESC_OTHER_SPEED   7

Other speed configuration descriptor type.

◆ USB_DESC_STRING

#define USB_DESC_STRING   3

String descriptor type.

◆ USB_EP_DIR_IN

#define USB_EP_DIR_IN   (uint8_t)BIT(7)

USB IN endpoint direction.

◆ USB_EP_DIR_IS_IN

#define USB_EP_DIR_IS_IN ( ep)
Value:
#define USB_EP_GET_DIR(ep)
Get direction based on endpoint address.
Definition usb_ch9.h:608
#define USB_EP_DIR_IN
USB IN endpoint direction.
Definition usb_ch9.h:581

Determine if an endpoint address refers to an IN endpoint.

Parameters
epEndpoint address.
Return values
trueEndpoint is an IN endpoint.
falseEndpoint is an OUT endpoint.

◆ USB_EP_DIR_IS_OUT

#define USB_EP_DIR_IS_OUT ( ep)
Value:
#define USB_EP_DIR_OUT
USB OUT endpoint direction.
Definition usb_ch9.h:584

Determine if an endpoint address refers to an OUT endpoint.

Parameters
epEndpoint address.
Return values
trueEndpoint is an OUT endpoint.
falseEndpoint is an IN endpoint.

◆ USB_EP_DIR_MASK

#define USB_EP_DIR_MASK   (uint8_t)BIT(7)

USB endpoint direction mask.

◆ USB_EP_DIR_OUT

#define USB_EP_DIR_OUT   0U

USB OUT endpoint direction.

◆ USB_EP_GET_ADDR

#define USB_EP_GET_ADDR ( idx,
dir )
Value:
((idx) | ((dir) & USB_EP_DIR_MASK))
#define USB_EP_DIR_MASK
USB endpoint direction mask.
Definition usb_ch9.h:578

Get endpoint address from endpoint index and direction.

Parameters
idxEndpoint index.
dirEndpoint direction (USB_EP_DIR_IN or USB_EP_DIR_OUT).
Returns
Encoded endpoint address.

◆ USB_EP_GET_DIR

#define USB_EP_GET_DIR ( ep)
Value:

Get direction based on endpoint address.

Parameters
epEndpoint address.
Returns
Direction mask.

◆ USB_EP_GET_IDX

#define USB_EP_GET_IDX ( ep)
Value:

Get endpoint index (number) from endpoint address.

Parameters
epEndpoint address.
Returns
Endpoint number.

◆ USB_EP_TRANSFER_TYPE_MASK

#define USB_EP_TRANSFER_TYPE_MASK   0x3U

Mask for endpoint transfer type.

◆ USB_EP_TYPE_BULK

#define USB_EP_TYPE_BULK   2U

Bulk transfer endpoint.

◆ USB_EP_TYPE_CONTROL

#define USB_EP_TYPE_CONTROL   0U

Control transfer endpoint.

◆ USB_EP_TYPE_INTERRUPT

#define USB_EP_TYPE_INTERRUPT   3U

Interrupt transfer endpoint.

◆ USB_EP_TYPE_ISO

#define USB_EP_TYPE_ISO   1U

Isochronous transfer endpoint.

◆ USB_FS_INT_EP_INTERVAL

#define USB_FS_INT_EP_INTERVAL ( us)
Value:
CLAMP(((us) / 1000U), 1U, 255U)
#define CLAMP(val, low, high)
Clamp a value to a given range.
Definition util.h:602

Calculate full speed interrupt endpoint bInterval from a value in microseconds.

Parameters
usPolling interval in microseconds.
Returns
Encoded bInterval value.

◆ USB_FS_ISO_EP_INTERVAL

#define USB_FS_ISO_EP_INTERVAL ( us)
Value:
CLAMP((ilog2((us) / 1000U) + 1U), 1U, 16U)
#define ilog2(n)
Calculate integer log2.
Definition ilog2.h:100

Calculate full speed isochronous endpoint bInterval from microseconds.

Parameters
usPolling interval in microseconds.
Returns
Encoded bInterval value.

◆ USB_GET_DESCRIPTOR_INDEX

#define USB_GET_DESCRIPTOR_INDEX ( wValue)
Value:
((uint8_t)(wValue))
__UINT8_TYPE__ uint8_t
Definition stdint.h:88

Obtain descriptor index from USB_SREQ_GET_DESCRIPTOR request value.

Parameters
wValueGET_DESCRIPTOR request wValue field.
Returns
Descriptor index encoded in wValue.

◆ USB_GET_DESCRIPTOR_TYPE

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

Obtain descriptor type from USB_SREQ_GET_DESCRIPTOR request value.

Parameters
wValueGET_DESCRIPTOR request wValue field.
Returns
Descriptor type encoded in wValue.

◆ USB_GET_STATUS_REMOTE_WAKEUP

#define USB_GET_STATUS_REMOTE_WAKEUP   BIT(1)

Remote wakeup status bit.

◆ USB_GET_STATUS_SELF_POWERED

#define USB_GET_STATUS_SELF_POWERED   BIT(0)

Self-powered status bit.

◆ USB_HS_INT_EP_INTERVAL

#define USB_HS_INT_EP_INTERVAL ( us)
Value:
CLAMP((ilog2((us) / 125U) + 1U), 1U, 16U)

Calculate high speed interrupt endpoint bInterval from microseconds.

Parameters
usPolling interval in microseconds.
Returns
Encoded bInterval value.

◆ USB_HS_ISO_EP_INTERVAL

#define USB_HS_ISO_EP_INTERVAL ( us)
Value:
CLAMP((ilog2((us) / 125U) + 1U), 1U, 16U)

Calculate high speed isochronous endpoint bInterval from microseconds.

Parameters
usPolling interval in microseconds.
Returns
Encoded bInterval value.

◆ USB_MPS_ADDITIONAL_TRANSACTIONS

#define USB_MPS_ADDITIONAL_TRANSACTIONS ( mps)
Value:
(((mps) & 0x1800) >> 11)

Get number of additional transactions per microframe from MPS.

Parameters
mpsEncoded Max Packet Size.
Returns
Additional transactions per microframe.

◆ USB_MPS_EP_SIZE

#define USB_MPS_EP_SIZE ( mps)
Value:
((mps) & BIT_MASK(11))
#define BIT_MASK(n)
Bit mask with bits 0 through n-1 (inclusive) set, or 0 if n is 0.
Definition util_macro.h:68

Get endpoint size field from Max Packet Size value.

Parameters
mpsEncoded Max Packet Size.
Returns
Endpoint size field.

◆ USB_MPS_TO_TPL

#define USB_MPS_TO_TPL ( mps)
Value:
#define USB_MPS_ADDITIONAL_TRANSACTIONS(mps)
Get number of additional transactions per microframe from MPS.
Definition usb_ch9.h:714
#define USB_MPS_EP_SIZE(mps)
Get endpoint size field from Max Packet Size value.
Definition usb_ch9.h:705

Calculate total payload length from Max Packet Size value.

Parameters
mpsEncoded Max Packet Size.
Returns
Total payload length in bytes.

◆ USB_REQTYPE_DIR_TO_DEVICE

#define USB_REQTYPE_DIR_TO_DEVICE   0

Host-to-device data direction.

◆ USB_REQTYPE_DIR_TO_HOST

#define USB_REQTYPE_DIR_TO_HOST   1

Device-to-host data direction.

◆ USB_REQTYPE_GET_DIR

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

Get data transfer direction from bmRequestType.

Parameters
bmRequestTypeEncoded request type.
Returns
0 for host-to-device, 1 for device-to-host (see usb_reqtype_dir).

◆ USB_REQTYPE_GET_RECIPIENT

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

Get request recipient from bmRequestType.

Parameters
bmRequestTypeEncoded request type.
Returns
Encoded recipient value (see usb_reqtype_recipient).

◆ USB_REQTYPE_GET_TYPE

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

Get request type from bmRequestType.

Parameters
bmRequestTypeEncoded request type.
Returns
Encoded request type value (see usb_reqtype_type).

◆ USB_REQTYPE_RECIPIENT_DEVICE

#define USB_REQTYPE_RECIPIENT_DEVICE   0

Device recipient.

◆ USB_REQTYPE_RECIPIENT_ENDPOINT

#define USB_REQTYPE_RECIPIENT_ENDPOINT   2

Endpoint recipient.

◆ USB_REQTYPE_RECIPIENT_INTERFACE

#define USB_REQTYPE_RECIPIENT_INTERFACE   1

Interface recipient.

◆ USB_REQTYPE_RECIPIENT_OTHER

#define USB_REQTYPE_RECIPIENT_OTHER   3

Other recipient.

◆ USB_REQTYPE_TYPE_CLASS

#define USB_REQTYPE_TYPE_CLASS   1

Class-specific request.

◆ USB_REQTYPE_TYPE_RESERVED

#define USB_REQTYPE_TYPE_RESERVED   3

Reserved request type.

◆ USB_REQTYPE_TYPE_STANDARD

#define USB_REQTYPE_TYPE_STANDARD   0

Standard USB request.

◆ USB_REQTYPE_TYPE_VENDOR

#define USB_REQTYPE_TYPE_VENDOR   2

Vendor-specific request.

◆ USB_SCD_REMOTE_WAKEUP

#define USB_SCD_REMOTE_WAKEUP   BIT(5)

Remote wakeup configuration bit.

◆ USB_SCD_RESERVED

#define USB_SCD_RESERVED   BIT(7)

Reserved configuration bit.

◆ USB_SCD_SELF_POWERED

#define USB_SCD_SELF_POWERED   BIT(6)

Self-powered configuration bit.

◆ USB_SFS_ENDPOINT_HALT

#define USB_SFS_ENDPOINT_HALT   0x00

Endpoint halt feature selector.

◆ USB_SFS_REMOTE_WAKEUP

#define USB_SFS_REMOTE_WAKEUP   0x01

Remote wakeup feature selector.

◆ USB_SFS_TEST_MODE

#define USB_SFS_TEST_MODE   0x02

Test mode feature selector.

◆ USB_SFS_TEST_MODE_FORCE_ENABLE

#define USB_SFS_TEST_MODE_FORCE_ENABLE   0x05

Test_Force_Enable test mode.

◆ USB_SFS_TEST_MODE_J

#define USB_SFS_TEST_MODE_J   0x01

Test_J test mode.

◆ USB_SFS_TEST_MODE_K

#define USB_SFS_TEST_MODE_K   0x02

Test_K test mode.

◆ USB_SFS_TEST_MODE_PACKET

#define USB_SFS_TEST_MODE_PACKET   0x04

Test_Packet test mode.

◆ USB_SFS_TEST_MODE_SE0_NAK

#define USB_SFS_TEST_MODE_SE0_NAK   0x03

Test_SE0_NAK test mode.

◆ USB_SREQ_CLEAR_FEATURE

#define USB_SREQ_CLEAR_FEATURE   0x01

Clear Feature request.

◆ USB_SREQ_GET_CONFIGURATION

#define USB_SREQ_GET_CONFIGURATION   0x08

Get Configuration request.

◆ USB_SREQ_GET_DESCRIPTOR

#define USB_SREQ_GET_DESCRIPTOR   0x06

Get Descriptor request.

◆ USB_SREQ_GET_INTERFACE

#define USB_SREQ_GET_INTERFACE   0x0A

Get Interface request.

◆ USB_SREQ_GET_STATUS

#define USB_SREQ_GET_STATUS   0x00

Get Status request.

◆ USB_SREQ_SET_ADDRESS

#define USB_SREQ_SET_ADDRESS   0x05

Set Address request.

◆ USB_SREQ_SET_CONFIGURATION

#define USB_SREQ_SET_CONFIGURATION   0x09

Set Configuration request.

◆ USB_SREQ_SET_DESCRIPTOR

#define USB_SREQ_SET_DESCRIPTOR   0x07

Set Descriptor request.

◆ USB_SREQ_SET_FEATURE

#define USB_SREQ_SET_FEATURE   0x03

Set Feature request.

◆ USB_SREQ_SET_INTERFACE

#define USB_SREQ_SET_INTERFACE   0x0B

Set Interface request.

◆ USB_SREQ_SYNCH_FRAME

#define USB_SREQ_SYNCH_FRAME   0x0C

Synch Frame request.

◆ USB_SRN_1_1

#define USB_SRN_1_1   0x0110

USB 1.1 specification release number.

◆ USB_SRN_2_0

#define USB_SRN_2_0   0x0200

USB 2.0 specification release number.

◆ USB_SRN_2_0_1

#define USB_SRN_2_0_1   0x0201

USB 2.0.1 specification release number.

◆ USB_SRN_2_1

#define USB_SRN_2_1   0x0210

USB 2.1 specification release number.

◆ USB_TPL_IS_VALID

#define USB_TPL_IS_VALID ( tpl)
Value:
(((tpl) > 3072) ? false : \
((tpl) > 2048) ? ((tpl) % 3 == 0) : \
((tpl) > 1024) ? ((tpl) % 2 == 0) : \
((tpl) >= 0))
#define false
Definition stdbool.h:15

Determine whether total payload length value is valid according to USB 2.0.

Parameters
tplTotal payload length in bytes.
Return values
truePayload length is valid.
falsePayload length is invalid.

◆ USB_TPL_ROUND_UP

#define USB_TPL_ROUND_UP ( tpl)
Value:
(((tpl) > 2048) ? ROUND_UP(tpl, 3) : \
((tpl) > 1024) ? ROUND_UP(tpl, 2) : \
(tpl))
#define ROUND_UP(x, align)
Value of x rounded up to the next multiple of align.
Definition util.h:318

Round up total payload length to the next valid value.

Parameters
tplTotal payload length in bytes.
Returns
Rounded payload length.

◆ USB_TPL_TO_MPS

#define USB_TPL_TO_MPS ( tpl)
Value:
(((tpl) > 2048) ? ((2 << 11) | ((tpl) / 3)) : \
((tpl) > 1024) ? ((1 << 11) | ((tpl) / 2)) : \
(tpl))

Calculate Max Packet Size value from total payload length.

Parameters
tplTotal payload length in bytes.
Returns
Encoded Max Packet Size value.

Function Documentation

◆ usb_reqtype_is_to_device()

bool usb_reqtype_is_to_device ( const struct usb_setup_packet * setup)
inlinestatic

Check if request transfer direction is to device.

Parameters
setupPointer to USB Setup packet.
Return values
trueTransfer direction is host-to-device.
falseTransfer direction is device-to-host.

◆ usb_reqtype_is_to_host()

bool usb_reqtype_is_to_host ( const struct usb_setup_packet * setup)
inlinestatic

Check if request transfer direction is to host.

Parameters
setupPointer to USB Setup packet.
Return values
trueTransfer direction is device-to-host.
falseTransfer direction is host-to-device.