|
Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
|
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. | |
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.
| #define USB_BCC_APPLICATION 0xFE |
Application-specific device class.
| #define USB_BCC_AUDIO 0x01 |
Audio device class.
| #define USB_BCC_CDC_CONTROL 0x02 |
CDC control device class.
| #define USB_BCC_CDC_DATA 0x0A |
CDC data device class.
| #define USB_BCC_HID 0x03 |
HID device class.
| #define USB_BCC_MASS_STORAGE 0x08 |
Mass storage device class.
| #define USB_BCC_MCTP 0x14 |
MCTP device class.
| #define USB_BCC_MISCELLANEOUS 0xEF |
Miscellaneous device class.
| #define USB_BCC_VENDOR 0xFF |
Vendor-specific device class.
| #define USB_BCC_VIDEO 0x0E |
Video device class.
| #define USB_BCC_WIRELESS_CONTROLLER 0xE0 |
Wireless controller device class.
| #define USB_BCD_DRN |
USB Device release number (bcdDevice Descriptor field).
| #define USB_CONTROL_EP_IN (USB_EP_DIR_IN | 0U) |
USB Control Endpoints IN address.
| #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.
| #define USB_CONTROL_EP_OUT (USB_EP_DIR_OUT | 0U) |
USB Control Endpoints OUT address.
| #define USB_DEC_TO_BCD | ( | dec | ) |
Convert a decimal value to BCD representation.
| dec | Decimal value. |
| #define USB_DESC_BOS 15 |
Binary object store descriptor type.
| #define USB_DESC_CONFIGURATION 2 |
Configuration descriptor type.
| #define USB_DESC_CS_CONFIGURATION 0x22 |
Class-specific configuration descriptor type.
| #define USB_DESC_CS_DEVICE 0x21 |
Class-specific device descriptor type.
| #define USB_DESC_CS_ENDPOINT 0x25 |
Class-specific endpoint descriptor type.
| #define USB_DESC_CS_INTERFACE 0x24 |
Class-specific interface descriptor type.
| #define USB_DESC_CS_STRING 0x23 |
Class-specific string descriptor type.
| #define USB_DESC_DEBUG 10 |
Debug descriptor type.
| #define USB_DESC_DEVICE 1 |
Device descriptor type.
| #define USB_DESC_DEVICE_CAPABILITY 16 |
Device capability descriptor type.
| #define USB_DESC_DEVICE_QUALIFIER 6 |
Device qualifier descriptor type.
| #define USB_DESC_ENDPOINT 5 |
Endpoint descriptor type.
| #define USB_DESC_INTERFACE 4 |
Interface descriptor type.
| #define USB_DESC_INTERFACE_ASSOC 11 |
Interface association descriptor type.
| #define USB_DESC_INTERFACE_POWER 8 |
Interface power descriptor type.
| #define USB_DESC_OTG 9 |
OTG descriptor type.
| #define USB_DESC_OTHER_SPEED 7 |
Other speed configuration descriptor type.
| #define USB_DESC_STRING 3 |
String descriptor type.
| #define USB_EP_DIR_IS_IN | ( | ep | ) |
Determine if an endpoint address refers to an IN endpoint.
| ep | Endpoint address. |
| true | Endpoint is an IN endpoint. |
| false | Endpoint is an OUT endpoint. |
| #define USB_EP_DIR_IS_OUT | ( | ep | ) |
Determine if an endpoint address refers to an OUT endpoint.
| ep | Endpoint address. |
| true | Endpoint is an OUT endpoint. |
| false | Endpoint is an IN endpoint. |
| #define USB_EP_DIR_OUT 0U |
USB OUT endpoint direction.
| #define USB_EP_GET_ADDR | ( | idx, | |
| dir ) |
Get endpoint address from endpoint index and direction.
| idx | Endpoint index. |
| dir | Endpoint direction (USB_EP_DIR_IN or USB_EP_DIR_OUT). |
| #define USB_EP_GET_DIR | ( | ep | ) |
Get direction based on endpoint address.
| ep | Endpoint address. |
| #define USB_EP_GET_IDX | ( | ep | ) |
Get endpoint index (number) from endpoint address.
| ep | Endpoint address. |
| #define USB_EP_TRANSFER_TYPE_MASK 0x3U |
Mask for endpoint transfer type.
| #define USB_EP_TYPE_BULK 2U |
Bulk transfer endpoint.
| #define USB_EP_TYPE_CONTROL 0U |
Control transfer endpoint.
| #define USB_EP_TYPE_INTERRUPT 3U |
Interrupt transfer endpoint.
| #define USB_EP_TYPE_ISO 1U |
Isochronous transfer endpoint.
| #define USB_FS_INT_EP_INTERVAL | ( | us | ) |
| #define USB_FS_ISO_EP_INTERVAL | ( | us | ) |
| #define USB_GET_DESCRIPTOR_INDEX | ( | wValue | ) |
| #define USB_GET_DESCRIPTOR_TYPE | ( | wValue | ) |
Obtain descriptor type from USB_SREQ_GET_DESCRIPTOR request value.
| wValue | GET_DESCRIPTOR request wValue field. |
wValue. | #define USB_GET_STATUS_REMOTE_WAKEUP BIT(1) |
Remote wakeup status bit.
| #define USB_GET_STATUS_SELF_POWERED BIT(0) |
Self-powered status bit.
| #define USB_HS_INT_EP_INTERVAL | ( | us | ) |
| #define USB_HS_ISO_EP_INTERVAL | ( | us | ) |
| #define USB_MPS_ADDITIONAL_TRANSACTIONS | ( | mps | ) |
Get number of additional transactions per microframe from MPS.
| mps | Encoded Max Packet Size. |
| #define USB_MPS_EP_SIZE | ( | mps | ) |
| #define USB_MPS_TO_TPL | ( | mps | ) |
Calculate total payload length from Max Packet Size value.
| mps | Encoded Max Packet Size. |
| #define USB_REQTYPE_DIR_TO_DEVICE 0 |
Host-to-device data direction.
| #define USB_REQTYPE_DIR_TO_HOST 1 |
Device-to-host data direction.
| #define USB_REQTYPE_GET_DIR | ( | bmRequestType | ) |
Get data transfer direction from bmRequestType.
| bmRequestType | Encoded request type. |
| #define USB_REQTYPE_GET_RECIPIENT | ( | bmRequestType | ) |
Get request recipient from bmRequestType.
| bmRequestType | Encoded request type. |
| #define USB_REQTYPE_GET_TYPE | ( | bmRequestType | ) |
Get request type from bmRequestType.
| bmRequestType | Encoded request type. |
| #define USB_REQTYPE_RECIPIENT_DEVICE 0 |
Device recipient.
| #define USB_REQTYPE_RECIPIENT_ENDPOINT 2 |
Endpoint recipient.
| #define USB_REQTYPE_RECIPIENT_INTERFACE 1 |
Interface recipient.
| #define USB_REQTYPE_RECIPIENT_OTHER 3 |
Other recipient.
| #define USB_REQTYPE_TYPE_CLASS 1 |
Class-specific request.
| #define USB_REQTYPE_TYPE_RESERVED 3 |
Reserved request type.
| #define USB_REQTYPE_TYPE_STANDARD 0 |
Standard USB request.
| #define USB_REQTYPE_TYPE_VENDOR 2 |
Vendor-specific request.
| #define USB_SCD_REMOTE_WAKEUP BIT(5) |
Remote wakeup configuration bit.
| #define USB_SCD_RESERVED BIT(7) |
Reserved configuration bit.
| #define USB_SCD_SELF_POWERED BIT(6) |
Self-powered configuration bit.
| #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.
| #define USB_SFS_TEST_MODE_FORCE_ENABLE 0x05 |
Test_Force_Enable test mode.
| #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_PACKET 0x04 |
Test_Packet test mode.
| #define USB_SFS_TEST_MODE_SE0_NAK 0x03 |
Test_SE0_NAK test mode.
| #define USB_SREQ_CLEAR_FEATURE 0x01 |
Clear Feature request.
| #define USB_SREQ_GET_CONFIGURATION 0x08 |
Get Configuration request.
| #define USB_SREQ_GET_DESCRIPTOR 0x06 |
Get Descriptor request.
| #define USB_SREQ_GET_INTERFACE 0x0A |
Get Interface request.
| #define USB_SREQ_GET_STATUS 0x00 |
Get Status request.
| #define USB_SREQ_SET_ADDRESS 0x05 |
Set Address request.
| #define USB_SREQ_SET_CONFIGURATION 0x09 |
Set Configuration request.
| #define USB_SREQ_SET_DESCRIPTOR 0x07 |
Set Descriptor request.
| #define USB_SREQ_SET_FEATURE 0x03 |
Set Feature request.
| #define USB_SREQ_SET_INTERFACE 0x0B |
Set Interface request.
| #define USB_SREQ_SYNCH_FRAME 0x0C |
Synch Frame request.
| #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.
| #define USB_TPL_IS_VALID | ( | tpl | ) |
Determine whether total payload length value is valid according to USB 2.0.
| tpl | Total payload length in bytes. |
| true | Payload length is valid. |
| false | Payload length is invalid. |
| #define USB_TPL_ROUND_UP | ( | tpl | ) |
Round up total payload length to the next valid value.
| tpl | Total payload length in bytes. |
| #define USB_TPL_TO_MPS | ( | tpl | ) |
Calculate Max Packet Size value from total payload length.
| tpl | Total payload length in bytes. |
|
inlinestatic |
Check if request transfer direction is to device.
| setup | Pointer to USB Setup packet. |
| true | Transfer direction is host-to-device. |
| false | Transfer direction is device-to-host. |
|
inlinestatic |
Check if request transfer direction is to host.
| setup | Pointer to USB Setup packet. |
| true | Transfer direction is device-to-host. |
| false | Transfer direction is host-to-device. |