Zephyr API Documentation
3.6.99
A Scalable Open Source RTOS
|
USB Chapter 9 structures and definitions. More...
#include <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 |
struct | usb_setup_packet |
USB Setup Data packet defined in spec. More... | |
struct | usb_desc_header |
Header of an USB descriptor. More... | |
struct | usb_device_descriptor |
USB Standard Device Descriptor defined in spec. More... | |
struct | usb_device_qualifier_descriptor |
USB Device Qualifier Descriptor defined in spec. More... | |
struct | usb_cfg_descriptor |
USB Standard Configuration Descriptor defined in spec. More... | |
struct | usb_if_descriptor |
USB Standard Interface Descriptor defined in spec. More... | |
struct | usb_ep_desc_bmattr |
struct | usb_ep_descriptor |
USB Standard Endpoint Descriptor defined in spec. More... | |
struct | usb_string_descriptor |
USB Unicode (UTF16LE) String Descriptor defined in spec. More... | |
struct | usb_association_descriptor |
USB Association Descriptor defined in USB 3 spec. More... | |
Macros | |
#define | USB_REQTYPE_DIR_TO_DEVICE 0 |
USB Setup packet RequestType Direction values (from Table 9-2) | |
#define | USB_REQTYPE_DIR_TO_HOST 1 |
#define | USB_REQTYPE_TYPE_STANDARD 0 |
USB Setup packet RequestType Type values (from Table 9-2) | |
#define | USB_REQTYPE_TYPE_CLASS 1 |
#define | USB_REQTYPE_TYPE_VENDOR 2 |
#define | USB_REQTYPE_TYPE_RESERVED 3 |
#define | USB_REQTYPE_RECIPIENT_DEVICE 0 |
USB Setup packet RequestType Recipient values (from Table 9-2) | |
#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) |
Get data transfer direction from bmRequestType. | |
#define | USB_REQTYPE_GET_TYPE(bmRequestType) (((bmRequestType) >> 5) & 0x03U) |
Get request type from bmRequestType. | |
#define | USB_REQTYPE_GET_RECIPIENT(bmRequestType) ((bmRequestType) & 0x1FU) |
Get request recipient from bmRequestType. | |
#define | USB_SREQ_GET_STATUS 0x00 |
USB Standard Request Codes defined in spec. | |
#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 |
Descriptor Types defined in spec. | |
#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 |
Additional Descriptor Types defined in USB 3 spec. | |
#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 |
Class-Specific Descriptor Types as defined by USB Common Class Specification. | |
#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 |
USB Standard Feature Selectors defined in spec. | |
#define | USB_SFS_REMOTE_WAKEUP 0x01 |
#define | USB_SFS_TEST_MODE 0x02 |
#define | USB_GET_STATUS_SELF_POWERED BIT(0) |
Bits used for GetStatus response defined in spec. | |
#define | USB_GET_STATUS_REMOTE_WAKEUP BIT(1) |
#define | USB_SCD_RESERVED BIT(7) |
USB Standard Configuration Descriptor Characteristics from Table 9-10. | |
#define | USB_SCD_SELF_POWERED BIT(6) |
#define | USB_SCD_REMOTE_WAKEUP BIT(5) |
#define | USB_BCC_AUDIO 0x01 |
USB Defined Base Class Codes from https://www.usb.org/defined-class-codes. | |
#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 |
USB Specification Release Numbers (bcdUSB Descriptor field) | |
#define | USB_SRN_2_0 0x0200 |
#define | USB_SRN_2_0_1 0x0201 |
#define | USB_SRN_2_1 0x0210 |
#define | USB_DEC_TO_BCD(dec) ((((dec) / 10) << 4) | ((dec) % 10)) |
#define | USB_BCD_DRN |
USB Device release number (bcdDevice Descriptor field) | |
#define | USB_GET_DESCRIPTOR_TYPE(wValue) ((uint8_t)((wValue) >> 8)) |
Macro to obtain descriptor type from USB_SREQ_GET_DESCRIPTOR request. | |
#define | USB_GET_DESCRIPTOR_INDEX(wValue) ((uint8_t)(wValue)) |
Macro to obtain descriptor index from USB_SREQ_GET_DESCRIPTOR request. | |
#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) ((ep) & ~USB_EP_DIR_MASK) |
Get endpoint index (number) from endpoint address. | |
#define | USB_EP_GET_DIR(ep) ((ep) & USB_EP_DIR_MASK) |
Get direction based on endpoint address. | |
#define | USB_EP_GET_ADDR(idx, dir) ((idx) | ((dir) & USB_EP_DIR_MASK)) |
Get endpoint address from endpoint index and direction. | |
#define | USB_EP_DIR_IS_IN(ep) (USB_EP_GET_DIR(ep) == USB_EP_DIR_IN) |
True if the endpoint is an IN endpoint. | |
#define | USB_EP_DIR_IS_OUT(ep) (USB_EP_GET_DIR(ep) == USB_EP_DIR_OUT) |
True if the endpoint is 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_EP_TRANSFER_TYPE_MASK 0x3U |
USB endpoint transfer type mask. | |
#define | USB_EP_TYPE_CONTROL 0U |
USB endpoint transfer type control. | |
#define | USB_EP_TYPE_ISO 1U |
USB endpoint transfer type isochronous. | |
#define | USB_EP_TYPE_BULK 2U |
USB endpoint transfer type bulk. | |
#define | USB_EP_TYPE_INTERRUPT 3U |
USB endpoint transfer type interrupt. | |
#define | USB_FS_INT_EP_INTERVAL(us) CLAMP(((us) / 1000U), 1U, 255U) |
Calculate full speed interrupt endpoint bInterval from a value in microseconds. | |
#define | USB_HS_INT_EP_INTERVAL(us) CLAMP((ilog2((us) / 125U) + 1U), 1U, 16U) |
Calculate high speed interrupt endpoint bInterval from a value in microseconds. | |
#define | USB_FS_ISO_EP_INTERVAL(us) CLAMP(((us) / 1000U), 1U, 16U) |
Calculate high speed isochronous endpoint bInterval from a value in microseconds. | |
#define | USB_HS_ISO_EP_INTERVAL(us) CLAMP((ilog2((us) / 125U) + 1U), 1U, 16U) |
Calculate high speed isochronous endpoint bInterval from a value in microseconds. | |
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 |
#define USB_BCC_AUDIO 0x01 |
USB Defined Base Class Codes from https://www.usb.org/defined-class-codes.
#define USB_BCC_CDC_CONTROL 0x02 |
#define USB_BCC_CDC_DATA 0x0A |
#define USB_BCC_HID 0x03 |
#define USB_BCC_MASS_STORAGE 0x08 |
#define USB_BCC_MISCELLANEOUS 0xEF |
#define USB_BCC_VENDOR 0xFF |
#define USB_BCC_VIDEO 0x0E |
#define USB_BCC_WIRELESS_CONTROLLER 0xE0 |
#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)
#define USB_CONTROL_EP_OUT (USB_EP_DIR_OUT | 0U) |
USB Control Endpoints OUT address.
#define USB_DEC_TO_BCD | ( | dec | ) | ((((dec) / 10) << 4) | ((dec) % 10)) |
#define USB_DESC_BOS 15 |
#define USB_DESC_CONFIGURATION 2 |
#define USB_DESC_CS_CONFIGURATION 0x22 |
#define USB_DESC_CS_DEVICE 0x21 |
Class-Specific Descriptor Types as defined by USB Common Class Specification.
#define USB_DESC_CS_ENDPOINT 0x25 |
#define USB_DESC_CS_INTERFACE 0x24 |
#define USB_DESC_CS_STRING 0x23 |
#define USB_DESC_DEBUG 10 |
#define USB_DESC_DEVICE 1 |
Descriptor Types defined in spec.
Table 9-5
#define USB_DESC_DEVICE_CAPABILITY 16 |
#define USB_DESC_DEVICE_QUALIFIER 6 |
#define USB_DESC_ENDPOINT 5 |
#define USB_DESC_INTERFACE 4 |
#define USB_DESC_INTERFACE_ASSOC 11 |
#define USB_DESC_INTERFACE_POWER 8 |
#define USB_DESC_OTG 9 |
Additional Descriptor Types defined in USB 3 spec.
Table 9-5
#define USB_DESC_OTHER_SPEED 7 |
#define USB_DESC_STRING 3 |
#define USB_EP_DIR_IS_IN | ( | ep | ) | (USB_EP_GET_DIR(ep) == USB_EP_DIR_IN) |
True if the endpoint is an IN endpoint.
#define USB_EP_DIR_IS_OUT | ( | ep | ) | (USB_EP_GET_DIR(ep) == USB_EP_DIR_OUT) |
True if the endpoint is an OUT endpoint.
#define USB_EP_DIR_OUT 0U |
USB OUT endpoint direction.
#define USB_EP_GET_ADDR | ( | idx, | |
dir | |||
) | ((idx) | ((dir) & USB_EP_DIR_MASK)) |
Get endpoint address from endpoint index and direction.
#define USB_EP_GET_DIR | ( | ep | ) | ((ep) & USB_EP_DIR_MASK) |
Get direction based on endpoint address.
#define USB_EP_GET_IDX | ( | ep | ) | ((ep) & ~USB_EP_DIR_MASK) |
Get endpoint index (number) from endpoint address.
#define USB_EP_TRANSFER_TYPE_MASK 0x3U |
USB endpoint transfer type mask.
#define USB_EP_TYPE_BULK 2U |
USB endpoint transfer type bulk.
#define USB_EP_TYPE_CONTROL 0U |
USB endpoint transfer type control.
#define USB_EP_TYPE_INTERRUPT 3U |
USB endpoint transfer type interrupt.
#define USB_EP_TYPE_ISO 1U |
USB endpoint transfer type isochronous.
#define USB_FS_INT_EP_INTERVAL | ( | us | ) | CLAMP(((us) / 1000U), 1U, 255U) |
Calculate full speed interrupt endpoint bInterval from a value in microseconds.
#define USB_FS_ISO_EP_INTERVAL | ( | us | ) | CLAMP(((us) / 1000U), 1U, 16U) |
Calculate high speed isochronous endpoint bInterval from a value in microseconds.
#define USB_GET_DESCRIPTOR_INDEX | ( | wValue | ) | ((uint8_t)(wValue)) |
Macro to obtain descriptor index from USB_SREQ_GET_DESCRIPTOR request.
#define USB_GET_DESCRIPTOR_TYPE | ( | wValue | ) | ((uint8_t)((wValue) >> 8)) |
Macro to obtain descriptor type from USB_SREQ_GET_DESCRIPTOR request.
#define USB_GET_STATUS_REMOTE_WAKEUP BIT(1) |
#define USB_GET_STATUS_SELF_POWERED BIT(0) |
Bits used for GetStatus response defined in spec.
Figure 9-4
Calculate high speed interrupt endpoint bInterval from a value in microseconds.
Calculate high speed isochronous endpoint bInterval from a value in microseconds.
#define USB_REQTYPE_DIR_TO_DEVICE 0 |
USB Setup packet RequestType Direction values (from Table 9-2)
#define USB_REQTYPE_DIR_TO_HOST 1 |
#define USB_REQTYPE_GET_DIR | ( | bmRequestType | ) | (((bmRequestType) >> 7) & 0x01U) |
Get data transfer direction from bmRequestType.
#define USB_REQTYPE_GET_RECIPIENT | ( | bmRequestType | ) | ((bmRequestType) & 0x1FU) |
Get request recipient from bmRequestType.
#define USB_REQTYPE_GET_TYPE | ( | bmRequestType | ) | (((bmRequestType) >> 5) & 0x03U) |
Get request type from bmRequestType.
#define USB_REQTYPE_RECIPIENT_DEVICE 0 |
USB Setup packet RequestType Recipient values (from Table 9-2)
#define USB_REQTYPE_RECIPIENT_ENDPOINT 2 |
#define USB_REQTYPE_RECIPIENT_INTERFACE 1 |
#define USB_REQTYPE_RECIPIENT_OTHER 3 |
#define USB_REQTYPE_TYPE_CLASS 1 |
#define USB_REQTYPE_TYPE_RESERVED 3 |
#define USB_REQTYPE_TYPE_STANDARD 0 |
USB Setup packet RequestType Type values (from Table 9-2)
#define USB_REQTYPE_TYPE_VENDOR 2 |
#define USB_SCD_REMOTE_WAKEUP BIT(5) |
#define USB_SCD_RESERVED BIT(7) |
USB Standard Configuration Descriptor Characteristics from Table 9-10.
#define USB_SCD_SELF_POWERED BIT(6) |
#define USB_SFS_ENDPOINT_HALT 0x00 |
USB Standard Feature Selectors defined in spec.
Table 9-6
#define USB_SFS_REMOTE_WAKEUP 0x01 |
#define USB_SFS_TEST_MODE 0x02 |
#define USB_SREQ_CLEAR_FEATURE 0x01 |
#define USB_SREQ_GET_CONFIGURATION 0x08 |
#define USB_SREQ_GET_DESCRIPTOR 0x06 |
#define USB_SREQ_GET_INTERFACE 0x0A |
#define USB_SREQ_GET_STATUS 0x00 |
USB Standard Request Codes defined in spec.
Table 9-4
#define USB_SREQ_SET_ADDRESS 0x05 |
#define USB_SREQ_SET_CONFIGURATION 0x09 |
#define USB_SREQ_SET_DESCRIPTOR 0x07 |
#define USB_SREQ_SET_FEATURE 0x03 |
#define USB_SREQ_SET_INTERFACE 0x0B |
#define USB_SREQ_SYNCH_FRAME 0x0C |
#define USB_SRN_1_1 0x0110 |
USB Specification Release Numbers (bcdUSB Descriptor field)
#define USB_SRN_2_0 0x0200 |
#define USB_SRN_2_0_1 0x0201 |
#define USB_SRN_2_1 0x0210 |
|
inlinestatic |
Check if request transfer direction is to device.
setup | Pointer to USB Setup packet |
|
inlinestatic |
Check if request transfer direction is to host.
setup | Pointer to USB Setup packet |