1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci/** 17094332d3Sopenharmony_ci * @addtogroup USB 18094332d3Sopenharmony_ci * @{ 19094332d3Sopenharmony_ci * 20094332d3Sopenharmony_ci * @brief Declares USB-related APIs, including the custom data types and functions 21094332d3Sopenharmony_ci * used to obtain descriptors, interface objects, and request objects, and to submit requests. 22094332d3Sopenharmony_ci * 23094332d3Sopenharmony_ci * @since 1.0 24094332d3Sopenharmony_ci * @version 1.0 25094332d3Sopenharmony_ci */ 26094332d3Sopenharmony_ci 27094332d3Sopenharmony_ci/** 28094332d3Sopenharmony_ci * @file usb_ddk.h 29094332d3Sopenharmony_ci * 30094332d3Sopenharmony_ci * @brief Defines the USB-related structures. 31094332d3Sopenharmony_ci * 32094332d3Sopenharmony_ci * @since 1.0 33094332d3Sopenharmony_ci * @version 1.0 34094332d3Sopenharmony_ci */ 35094332d3Sopenharmony_ci 36094332d3Sopenharmony_ci#ifndef USB_DDK_H 37094332d3Sopenharmony_ci#define USB_DDK_H 38094332d3Sopenharmony_ci 39094332d3Sopenharmony_ci#include "hdf_base.h" 40094332d3Sopenharmony_ci#include <endian.h> 41094332d3Sopenharmony_ci 42094332d3Sopenharmony_ci#ifdef __BYTE_ORDER 43094332d3Sopenharmony_ci#if __BYTE_ORDER == __LITTLE_ENDIAN 44094332d3Sopenharmony_ci/** 45094332d3Sopenharmony_ci * @brief Implements 16-bit little-endian conversion. 46094332d3Sopenharmony_ci */ 47094332d3Sopenharmony_ci#define CPU_TO_LE16(x) (x) 48094332d3Sopenharmony_ci/** 49094332d3Sopenharmony_ci * @brief Implements 32-bit little-endian conversion. 50094332d3Sopenharmony_ci */ 51094332d3Sopenharmony_ci#define CPU_TO_LE32(x) (x) 52094332d3Sopenharmony_ci#else 53094332d3Sopenharmony_ci/** 54094332d3Sopenharmony_ci * @brief Implements 16-bit little-endian conversion. 55094332d3Sopenharmony_ci */ 56094332d3Sopenharmony_ci#define CPU_TO_LE16(x) ((((x) >> 8) & 0xffu) | (((x)&0xffu) << 8)) 57094332d3Sopenharmony_ci/** 58094332d3Sopenharmony_ci * @brief Implements 32-bit little-endian conversion. 59094332d3Sopenharmony_ci */ 60094332d3Sopenharmony_ci#define CPU_TO_LE32(x) \ 61094332d3Sopenharmony_ci ((((x)&0xff000000u) >> 24) | (((x)&0x00ff0000u) >> 8) | (((x)&0x0000ff00u) << 8) | (((x)&0x000000ffu) << 24)) 62094332d3Sopenharmony_ci#endif 63094332d3Sopenharmony_ci#endif 64094332d3Sopenharmony_ci 65094332d3Sopenharmony_ci/** 66094332d3Sopenharmony_ci * @brief Implements 16-bit little-endian conversion. 67094332d3Sopenharmony_ci */ 68094332d3Sopenharmony_ci#define LE16_TO_CPU CPU_TO_LE16 69094332d3Sopenharmony_ci/** 70094332d3Sopenharmony_ci * @brief Implements 16-bit little-endian conversion. 71094332d3Sopenharmony_ci */ 72094332d3Sopenharmony_ci#define LE32_TO_CPU CPU_TO_LE32 73094332d3Sopenharmony_ci 74094332d3Sopenharmony_ci/** 75094332d3Sopenharmony_ci * @brief Configures the bus power-on feature. 76094332d3Sopenharmony_ci */ 77094332d3Sopenharmony_ci#define USB_CFG_BUS_POWERED 0x80 78094332d3Sopenharmony_ci 79094332d3Sopenharmony_ci/** 80094332d3Sopenharmony_ci * @brief Configures the automatic power-on feature. 81094332d3Sopenharmony_ci */ 82094332d3Sopenharmony_ci#define USB_CFG_SELF_POWERED 0x40 83094332d3Sopenharmony_ci 84094332d3Sopenharmony_ci/** 85094332d3Sopenharmony_ci * @brief Configures the remote wakeup feature. 86094332d3Sopenharmony_ci */ 87094332d3Sopenharmony_ci#define USB_CFG_REMOTE_WAKEUP 0x20 88094332d3Sopenharmony_ci 89094332d3Sopenharmony_ci/** 90094332d3Sopenharmony_ci * @brief Defines the data direction bit offset. For details, see {@link UsbRequestDirection}. 91094332d3Sopenharmony_ci */ 92094332d3Sopenharmony_ci#define USB_DIR_OFFSET 0x07 93094332d3Sopenharmony_ci 94094332d3Sopenharmony_ci/** 95094332d3Sopenharmony_ci * @brief Defines the control request type offset. For details, see {@link UsbControlRequestType}. 96094332d3Sopenharmony_ci */ 97094332d3Sopenharmony_ci#define USB_TYPE_OFFSET 0x05 98094332d3Sopenharmony_ci 99094332d3Sopenharmony_ci/** 100094332d3Sopenharmony_ci * @brief Defines the control request packet type offset. For details, see {@link UsbRequestTargetType}. 101094332d3Sopenharmony_ci */ 102094332d3Sopenharmony_ci#define USB_RECIP_OFFSET 0x00 103094332d3Sopenharmony_ci 104094332d3Sopenharmony_ci/** 105094332d3Sopenharmony_ci * @brief Defines the USB string index. 106094332d3Sopenharmony_ci */ 107094332d3Sopenharmony_cienum { 108094332d3Sopenharmony_ci /** Manufacturer index */ 109094332d3Sopenharmony_ci USB_FUNC_MANUFACTURER_IDX, 110094332d3Sopenharmony_ci /** Product index */ 111094332d3Sopenharmony_ci USB_FUNC_PRODUCT_IDX, 112094332d3Sopenharmony_ci /** Product SN index */ 113094332d3Sopenharmony_ci USB_FUNC_SERIAL_IDX, 114094332d3Sopenharmony_ci /** Index of the first valid string */ 115094332d3Sopenharmony_ci USB_FUNC_FIRST_AVAIL_IDX, 116094332d3Sopenharmony_ci}; 117094332d3Sopenharmony_ci 118094332d3Sopenharmony_ci/** 119094332d3Sopenharmony_ci * @brief Renames a descriptor structure. 120094332d3Sopenharmony_ci */ 121094332d3Sopenharmony_cienum { 122094332d3Sopenharmony_ci FUNCTIONFS_DESCRIPTORS_MAGIC = 1, 123094332d3Sopenharmony_ci FUNCTIONFS_STRINGS_MAGIC = 2, 124094332d3Sopenharmony_ci FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3, 125094332d3Sopenharmony_ci}; 126094332d3Sopenharmony_ci 127094332d3Sopenharmony_cienum FunctionfsFlags { 128094332d3Sopenharmony_ci FUNCTIONFS_HAS_FS_DESC = 1, 129094332d3Sopenharmony_ci FUNCTIONFS_HAS_HS_DESC = 2, 130094332d3Sopenharmony_ci FUNCTIONFS_HAS_SS_DESC = 4, 131094332d3Sopenharmony_ci FUNCTIONFS_HAS_MS_OS_DESC = 8, 132094332d3Sopenharmony_ci FUNCTIONFS_VIRTUAL_ADDR = 16, 133094332d3Sopenharmony_ci FUNCTIONFS_EVENTFD = 32, 134094332d3Sopenharmony_ci FUNCTIONFS_ALL_CTRL_RECIP = 64, 135094332d3Sopenharmony_ci FUNCTIONFS_CONFIG0_SETUP = 128, 136094332d3Sopenharmony_ci}; 137094332d3Sopenharmony_ci 138094332d3Sopenharmony_cienum UsbDeviceSpeed { 139094332d3Sopenharmony_ci USB_DDK_SPEED_UNKNOWN = 0, 140094332d3Sopenharmony_ci USB_DDK_SPEED_LOW, 141094332d3Sopenharmony_ci USB_DDK_SPEED_FULL, 142094332d3Sopenharmony_ci USB_DDK_SPEED_HIGH, 143094332d3Sopenharmony_ci USB_DDK_SPEED_WIRELESS, 144094332d3Sopenharmony_ci USB_DDK_SPEED_SUPER, 145094332d3Sopenharmony_ci USB_DDK_SPEED_SUPER_PLUS, 146094332d3Sopenharmony_ci}; 147094332d3Sopenharmony_ci 148094332d3Sopenharmony_cistruct UsbCtrlRequest { 149094332d3Sopenharmony_ci uint8_t bRequestType; 150094332d3Sopenharmony_ci uint8_t bRequest; 151094332d3Sopenharmony_ci uint16_t wValue; 152094332d3Sopenharmony_ci uint16_t wIndex; 153094332d3Sopenharmony_ci uint16_t wLength; 154094332d3Sopenharmony_ci} __attribute__((packed)); 155094332d3Sopenharmony_ci 156094332d3Sopenharmony_cistruct UsbDescriptorHeader { 157094332d3Sopenharmony_ci uint8_t bLength; 158094332d3Sopenharmony_ci uint8_t bDescriptorType; 159094332d3Sopenharmony_ci} __attribute__((packed)); 160094332d3Sopenharmony_ci 161094332d3Sopenharmony_citypedef struct UsbDeviceDescriptor { 162094332d3Sopenharmony_ci uint8_t bLength; 163094332d3Sopenharmony_ci uint8_t bDescriptorType; 164094332d3Sopenharmony_ci uint16_t bcdUSB; 165094332d3Sopenharmony_ci uint8_t bDeviceClass; 166094332d3Sopenharmony_ci uint8_t bDeviceSubClass; 167094332d3Sopenharmony_ci uint8_t bDeviceProtocol; 168094332d3Sopenharmony_ci uint8_t bMaxPacketSize0; 169094332d3Sopenharmony_ci uint16_t idVendor; 170094332d3Sopenharmony_ci uint16_t idProduct; 171094332d3Sopenharmony_ci uint16_t bcdDevice; 172094332d3Sopenharmony_ci uint8_t iManufacturer; 173094332d3Sopenharmony_ci uint8_t iProduct; 174094332d3Sopenharmony_ci uint8_t iSerialNumber; 175094332d3Sopenharmony_ci uint8_t bNumConfigurations; 176094332d3Sopenharmony_ci} __attribute__((packed)) UsbDeviceDescriptor; 177094332d3Sopenharmony_ci 178094332d3Sopenharmony_cistruct UsbConfigDescriptor { 179094332d3Sopenharmony_ci uint8_t bLength; 180094332d3Sopenharmony_ci uint8_t bDescriptorType; 181094332d3Sopenharmony_ci uint16_t wTotalLength; 182094332d3Sopenharmony_ci uint8_t bNumInterfaces; 183094332d3Sopenharmony_ci uint8_t bConfigurationValue; 184094332d3Sopenharmony_ci uint8_t iConfiguration; 185094332d3Sopenharmony_ci uint8_t bmAttributes; 186094332d3Sopenharmony_ci uint8_t bMaxPower; 187094332d3Sopenharmony_ci} __attribute__((packed)); 188094332d3Sopenharmony_ci 189094332d3Sopenharmony_cistruct UsbStringDescriptor { 190094332d3Sopenharmony_ci uint8_t bLength; 191094332d3Sopenharmony_ci uint8_t bDescriptorType; 192094332d3Sopenharmony_ci uint16_t wData[1]; 193094332d3Sopenharmony_ci} __attribute__((packed)); 194094332d3Sopenharmony_ci 195094332d3Sopenharmony_cistruct UsbInterfaceDescriptor { 196094332d3Sopenharmony_ci uint8_t bLength; 197094332d3Sopenharmony_ci uint8_t bDescriptorType; 198094332d3Sopenharmony_ci uint8_t bInterfaceNumber; 199094332d3Sopenharmony_ci uint8_t bAlternateSetting; 200094332d3Sopenharmony_ci uint8_t bNumEndpoints; 201094332d3Sopenharmony_ci uint8_t bInterfaceClass; 202094332d3Sopenharmony_ci uint8_t bInterfaceSubClass; 203094332d3Sopenharmony_ci uint8_t bInterfaceProtocol; 204094332d3Sopenharmony_ci uint8_t iInterface; 205094332d3Sopenharmony_ci} __attribute__((packed)); 206094332d3Sopenharmony_ci 207094332d3Sopenharmony_cistruct UsbEndpointDescriptor { 208094332d3Sopenharmony_ci uint8_t bLength; 209094332d3Sopenharmony_ci uint8_t bDescriptorType; 210094332d3Sopenharmony_ci uint8_t bEndpointAddress; 211094332d3Sopenharmony_ci uint8_t bmAttributes; 212094332d3Sopenharmony_ci uint16_t wMaxPacketSize; 213094332d3Sopenharmony_ci uint8_t bInterval; 214094332d3Sopenharmony_ci uint8_t bRefresh; 215094332d3Sopenharmony_ci uint8_t bSynchAddress; 216094332d3Sopenharmony_ci} __attribute__((packed)); 217094332d3Sopenharmony_ci 218094332d3Sopenharmony_cistruct UsbSspIsocEpCompDescriptor { 219094332d3Sopenharmony_ci uint8_t bLength; 220094332d3Sopenharmony_ci uint8_t bDescriptorType; 221094332d3Sopenharmony_ci uint16_t wReseved; 222094332d3Sopenharmony_ci uint32_t dwBytesPerInterval; 223094332d3Sopenharmony_ci} __attribute__((packed)); 224094332d3Sopenharmony_ci 225094332d3Sopenharmony_cistruct UsbSsEpCompDescriptor { 226094332d3Sopenharmony_ci uint8_t bLength; 227094332d3Sopenharmony_ci uint8_t bDescriptorType; 228094332d3Sopenharmony_ci uint8_t bMaxBurst; 229094332d3Sopenharmony_ci uint8_t bmAttributes; 230094332d3Sopenharmony_ci uint16_t wBytesPerInterval; 231094332d3Sopenharmony_ci} __attribute__((packed)); 232094332d3Sopenharmony_ci 233094332d3Sopenharmony_cistruct UsbQualifierDescriptor { 234094332d3Sopenharmony_ci uint8_t bLength; 235094332d3Sopenharmony_ci uint8_t bDescriptorType; 236094332d3Sopenharmony_ci uint16_t bcdUSB; 237094332d3Sopenharmony_ci uint8_t bDeviceClass; 238094332d3Sopenharmony_ci uint8_t bDeviceSubClass; 239094332d3Sopenharmony_ci uint8_t bDeviceProtocol; 240094332d3Sopenharmony_ci uint8_t bMaxPacketSize0; 241094332d3Sopenharmony_ci uint8_t bNumConfigurations; 242094332d3Sopenharmony_ci uint8_t bRESERVED; 243094332d3Sopenharmony_ci} __attribute__((packed)); 244094332d3Sopenharmony_ci 245094332d3Sopenharmony_cistruct UsbOtgDescriptor { 246094332d3Sopenharmony_ci uint8_t bLength; 247094332d3Sopenharmony_ci uint8_t bDescriptorType; 248094332d3Sopenharmony_ci uint8_t bmAttributes; 249094332d3Sopenharmony_ci} __attribute__((packed)); 250094332d3Sopenharmony_ci 251094332d3Sopenharmony_cistruct UsbOtg20Descriptor { 252094332d3Sopenharmony_ci uint8_t bLength; 253094332d3Sopenharmony_ci uint8_t bDescriptorType; 254094332d3Sopenharmony_ci uint8_t bmAttributes; 255094332d3Sopenharmony_ci uint16_t bcdOTG; 256094332d3Sopenharmony_ci} __attribute__((packed)); 257094332d3Sopenharmony_ci 258094332d3Sopenharmony_cistruct UsbInterfaceAssocDescriptor { 259094332d3Sopenharmony_ci uint8_t bLength; 260094332d3Sopenharmony_ci uint8_t bDescriptorType; 261094332d3Sopenharmony_ci uint8_t bFirstInterface; 262094332d3Sopenharmony_ci uint8_t bInterfaceCount; 263094332d3Sopenharmony_ci uint8_t bFunctionClass; 264094332d3Sopenharmony_ci uint8_t bFunctionSubClass; 265094332d3Sopenharmony_ci uint8_t bFunctionProtocol; 266094332d3Sopenharmony_ci uint8_t iFunction; 267094332d3Sopenharmony_ci} __attribute__((packed)); 268094332d3Sopenharmony_ci 269094332d3Sopenharmony_cistruct UsbFunctionfsStringsHead { 270094332d3Sopenharmony_ci uint32_t magic; 271094332d3Sopenharmony_ci uint32_t length; 272094332d3Sopenharmony_ci uint32_t strCount; 273094332d3Sopenharmony_ci uint32_t langCount; 274094332d3Sopenharmony_ci} __attribute__((packed)); 275094332d3Sopenharmony_ci 276094332d3Sopenharmony_cistruct UsbFunctionfsDescsHeadV2 { 277094332d3Sopenharmony_ci uint32_t magic; 278094332d3Sopenharmony_ci uint32_t length; 279094332d3Sopenharmony_ci uint32_t flags; 280094332d3Sopenharmony_ci} __attribute__((packed)); 281094332d3Sopenharmony_ci 282094332d3Sopenharmony_cistruct UsbSecurityDescriptor { 283094332d3Sopenharmony_ci uint8_t bLength; 284094332d3Sopenharmony_ci uint8_t bDescriptorType; 285094332d3Sopenharmony_ci uint16_t wTotalLength; 286094332d3Sopenharmony_ci uint8_t bNumEncryptionTypes; 287094332d3Sopenharmony_ci} __attribute__((packed)); 288094332d3Sopenharmony_ci 289094332d3Sopenharmony_cistruct UsbCdcLineCoding { 290094332d3Sopenharmony_ci uint32_t dwDTERate; 291094332d3Sopenharmony_ci uint8_t bCharFormat; 292094332d3Sopenharmony_ci 293094332d3Sopenharmony_ci#define USB_CDC_1_STOP_BITS 0 294094332d3Sopenharmony_ci#define USB_CDC_1_5_STOP_BITS 1 295094332d3Sopenharmony_ci#define USB_CDC_2_STOP_BITS 2 296094332d3Sopenharmony_ci uint8_t bParityType; 297094332d3Sopenharmony_ci 298094332d3Sopenharmony_ci#define USB_CDC_NO_PARITY 0 299094332d3Sopenharmony_ci#define USB_CDC_ODD_PARITY 1 300094332d3Sopenharmony_ci#define USB_CDC_EVEN_PARITY 2 301094332d3Sopenharmony_ci#define USB_CDC_MARK_PARITY 3 302094332d3Sopenharmony_ci#define USB_CDC_SPACE_PARITY 4 303094332d3Sopenharmony_ci uint8_t bDataBits; 304094332d3Sopenharmony_ci} __attribute__((packed)); 305094332d3Sopenharmony_ci 306094332d3Sopenharmony_cistruct UsbCdcNotification { 307094332d3Sopenharmony_ci uint8_t bmRequestType; 308094332d3Sopenharmony_ci uint8_t bNotificationType; 309094332d3Sopenharmony_ci uint16_t wValue; 310094332d3Sopenharmony_ci uint16_t wIndex; 311094332d3Sopenharmony_ci uint16_t wLength; 312094332d3Sopenharmony_ci} __attribute__((packed)); 313094332d3Sopenharmony_ci 314094332d3Sopenharmony_cistruct UsbCdcHeaderDesc { 315094332d3Sopenharmony_ci uint8_t bLength; 316094332d3Sopenharmony_ci uint8_t bDescriptorType; 317094332d3Sopenharmony_ci uint8_t bDescriptorSubType; 318094332d3Sopenharmony_ci uint16_t bcdCDC; 319094332d3Sopenharmony_ci} __attribute__((packed)); 320094332d3Sopenharmony_ci 321094332d3Sopenharmony_cistruct UsbCdcCallMgmtDescriptor { 322094332d3Sopenharmony_ci uint8_t bLength; 323094332d3Sopenharmony_ci uint8_t bDescriptorType; 324094332d3Sopenharmony_ci uint8_t bDescriptorSubType; 325094332d3Sopenharmony_ci uint8_t bmCapabilities; 326094332d3Sopenharmony_ci 327094332d3Sopenharmony_ci#define USB_CDC_CALL_MGMT_CAP_CALL_MGMT 0x01 328094332d3Sopenharmony_ci#define USB_CDC_CALL_MGMT_CAP_DATA_INTF 0x02 329094332d3Sopenharmony_ci uint8_t bDataInterface; 330094332d3Sopenharmony_ci} __attribute__((packed)); 331094332d3Sopenharmony_ci 332094332d3Sopenharmony_cistruct UsbCdcAcmDescriptor { 333094332d3Sopenharmony_ci uint8_t bLength; 334094332d3Sopenharmony_ci uint8_t bDescriptorType; 335094332d3Sopenharmony_ci uint8_t bDescriptorSubType; 336094332d3Sopenharmony_ci uint8_t bmCapabilities; 337094332d3Sopenharmony_ci} __attribute__((packed)); 338094332d3Sopenharmony_ci 339094332d3Sopenharmony_cistruct UsbCdcUnionDesc { 340094332d3Sopenharmony_ci uint8_t bLength; 341094332d3Sopenharmony_ci uint8_t bDescriptorType; 342094332d3Sopenharmony_ci uint8_t bDescriptorSubType; 343094332d3Sopenharmony_ci uint8_t bMasterInterface0; 344094332d3Sopenharmony_ci uint8_t bSlaveInterface0; 345094332d3Sopenharmony_ci} __attribute__((packed)); 346094332d3Sopenharmony_ci 347094332d3Sopenharmony_cistruct UsbDebugDescriptor { 348094332d3Sopenharmony_ci uint8_t bLength; 349094332d3Sopenharmony_ci uint8_t bDescriptorType; 350094332d3Sopenharmony_ci uint8_t bDebugInEndpoint; 351094332d3Sopenharmony_ci uint8_t bDebugOutEndpoint; 352094332d3Sopenharmony_ci} __attribute__((packed)); 353094332d3Sopenharmony_ci 354094332d3Sopenharmony_cistruct UsbCdcEtherDesc { 355094332d3Sopenharmony_ci uint8_t bLength; 356094332d3Sopenharmony_ci uint8_t bDescriptorType; 357094332d3Sopenharmony_ci uint8_t bDescriptorSubType; 358094332d3Sopenharmony_ci 359094332d3Sopenharmony_ci uint8_t iMACAddress; 360094332d3Sopenharmony_ci uint32_t bmEthernetStatistics; 361094332d3Sopenharmony_ci uint16_t wMaxSegmentSize; 362094332d3Sopenharmony_ci uint16_t wNumberMCFilters; 363094332d3Sopenharmony_ci uint8_t bNumberPowerFilters; 364094332d3Sopenharmony_ci} __attribute__((packed)); 365094332d3Sopenharmony_ci 366094332d3Sopenharmony_ci#define USB_DDK_ENDPOINT_NUMBER_MASK 0x0F 367094332d3Sopenharmony_ci#define USB_DDK_ENDPOINT_DIR_MASK 0x80 368094332d3Sopenharmony_ci#define USB_DDK_DIR_OUT 0x00 369094332d3Sopenharmony_ci#define USB_DDK_DIR_IN 0x80 370094332d3Sopenharmony_ci 371094332d3Sopenharmony_ci#define USB_DDK_DT_DEVICE 0x01 372094332d3Sopenharmony_ci#define USB_DDK_DT_CONFIG 0x02 373094332d3Sopenharmony_ci#define USB_DDK_DT_STRING 0x03 374094332d3Sopenharmony_ci#define USB_DDK_DT_INTERFACE 0x04 375094332d3Sopenharmony_ci#define USB_DDK_DT_ENDPOINT 0x05 376094332d3Sopenharmony_ci#define USB_DDK_DT_DEVICE_QUALIFIER 0x06 377094332d3Sopenharmony_ci#define USB_DDK_DT_OTHER_SPEED_CONFIG 0x07 378094332d3Sopenharmony_ci#define USB_DDK_DT_INTERFACE_POWER 0x08 379094332d3Sopenharmony_ci#define USB_DDK_DT_OTG 0x09 380094332d3Sopenharmony_ci#define USB_DDK_DT_DEBUG 0x0A 381094332d3Sopenharmony_ci#define USB_DDK_DT_INTERFACE_ASSOCIATION 0x0B 382094332d3Sopenharmony_ci#define USB_DDK_DT_SECURITY 0x0C 383094332d3Sopenharmony_ci#define USB_DDK_DT_KEY 0x0D 384094332d3Sopenharmony_ci#define USB_DDK_DT_ENCRYPTION_TYPE 0x0E 385094332d3Sopenharmony_ci#define USB_DDK_DT_BOS 0x0F 386094332d3Sopenharmony_ci#define USB_DDK_DT_DEVICE_CAPABILITY 0x10 387094332d3Sopenharmony_ci#define USB_DDK_DT_WIRELESS_ENDPOINT_COMP 0x11 388094332d3Sopenharmony_ci#define USB_DDK_DT_WIRE_ADAPTER 0x21 389094332d3Sopenharmony_ci#define USB_DDK_DT_RPIPE 0x22 390094332d3Sopenharmony_ci#define USB_DDK_DT_CS_RADIO_CONTROL 0x23 391094332d3Sopenharmony_ci#define USB_DDK_DT_PIPE_USAGE 0x24 392094332d3Sopenharmony_ci#define USB_DDK_DT_SS_ENDPOINT_COMP 0x30 393094332d3Sopenharmony_ci#define USB_DDK_DT_SSP_ISOC_ENDPOINT_COMP 0x31 394094332d3Sopenharmony_ci#define USB_DDK_DT_CS_DEVICE (USB_DDK_TYPE_CLASS | USB_DDK_DT_DEVICE) 395094332d3Sopenharmony_ci#define USB_DDK_DT_CS_CONFIG (USB_DDK_TYPE_CLASS | USB_DDK_DT_CONFIG) 396094332d3Sopenharmony_ci#define USB_DDK_DT_CS_STRING (USB_DDK_TYPE_CLASS | USB_DDK_DT_STRING) 397094332d3Sopenharmony_ci#define USB_DDK_DT_CS_INTERFACE (USB_DDK_TYPE_CLASS | USB_DDK_DT_INTERFACE) 398094332d3Sopenharmony_ci#define USB_DDK_DT_CS_ENDPOINT (USB_DDK_TYPE_CLASS | USB_DDK_DT_ENDPOINT) 399094332d3Sopenharmony_ci 400094332d3Sopenharmony_ci#define USB_DDK_DT_SS_EP_COMP_SIZE 0x06 401094332d3Sopenharmony_ci#define USB_DDK_DT_ENDPOINT_SIZE 0x07 402094332d3Sopenharmony_ci#define USB_DDK_DT_SSP_ISOC_EP_COMP_SIZE 0x08 403094332d3Sopenharmony_ci#define USB_DDK_DT_INTERFACE_ASSOCIATION_SIZE 0x08 404094332d3Sopenharmony_ci#define USB_DDK_DT_CONFIG_SIZE 0x09 405094332d3Sopenharmony_ci#define USB_DDK_DT_INTERFACE_SIZE 0x09 406094332d3Sopenharmony_ci#define USB_DDK_DT_ENDPOINT_AUDIO_SIZE 0x09 407094332d3Sopenharmony_ci#define USB_DDK_DT_DEVICE_SIZE 0x12 408094332d3Sopenharmony_ci 409094332d3Sopenharmony_ci#define USB_DDK_CLASS_PER_INTERFACE 0x00 410094332d3Sopenharmony_ci#define USB_DDK_CLASS_AUDIO 0x01 411094332d3Sopenharmony_ci#define USB_DDK_CLASS_COMM 0x02 412094332d3Sopenharmony_ci#define USB_DDK_CLASS_HID 0x03 413094332d3Sopenharmony_ci#define USB_DDK_CLASS_PHYSICAL 0x05 414094332d3Sopenharmony_ci#define USB_DDK_CLASS_STILL_IMAGE 0x06 415094332d3Sopenharmony_ci#define USB_DDK_CLASS_PRINTER 0x07 416094332d3Sopenharmony_ci#define USB_DDK_CLASS_MASS_STORAGE 0x08 417094332d3Sopenharmony_ci#define USB_DDK_CLASS_HUB 0x09 418094332d3Sopenharmony_ci#define USB_DDK_CLASS_CDC_DATA 0x0A 419094332d3Sopenharmony_ci#define USB_DDK_CLASS_CSCID 0x0B 420094332d3Sopenharmony_ci#define USB_DDK_CLASS_CONTENT_SEC 0x0D 421094332d3Sopenharmony_ci#define USB_DDK_CLASS_VIDEO 0x0E 422094332d3Sopenharmony_ci#define USB_DDK_CLASS_WIRELESS_CONTROLLER 0xE0 423094332d3Sopenharmony_ci#define USB_DDK_CLASS_MISC 0xEF 424094332d3Sopenharmony_ci#define USB_DDK_CLASS_APP_SPEC 0xFE 425094332d3Sopenharmony_ci#define USB_DDK_CLASS_VENDOR_SPEC 0xFF 426094332d3Sopenharmony_ci#define USB_DDK_SUBCLASS_VENDOR_SPEC 0xFF 427094332d3Sopenharmony_ci 428094332d3Sopenharmony_ci#define USB_DDK_CDC_NOTIFY_NETWORK_CONNECTION 0x00 429094332d3Sopenharmony_ci#define USB_DDK_CDC_NOTIFY_RESPONSE_AVAILABLE 0x01 430094332d3Sopenharmony_ci#define USB_DDK_CDC_NOTIFY_SERIAL_STATE 0x20 431094332d3Sopenharmony_ci#define USB_DDK_CDC_NOTIFY_SPEED_CHANGE 0x2A 432094332d3Sopenharmony_ci 433094332d3Sopenharmony_ci#define USB_DDK_CDC_SEND_ENCAPSULATED_COMMAND 0x00 434094332d3Sopenharmony_ci#define USB_DDK_CDC_GET_ENCAPSULATED_RESPONSE 0x01 435094332d3Sopenharmony_ci#define USB_DDK_CDC_REQ_SET_LINE_CODING 0x20 436094332d3Sopenharmony_ci#define USB_DDK_CDC_REQ_GET_LINE_CODING 0x21 437094332d3Sopenharmony_ci#define USB_DDK_CDC_REQ_SET_CONTROL_LINE_STATE 0x22 438094332d3Sopenharmony_ci#define USB_DDK_CDC_REQ_SEND_BREAK 0x23 439094332d3Sopenharmony_ci#define USB_DDK_CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40 440094332d3Sopenharmony_ci#define USB_DDK_CDC_SET_ETHERNET_PM_PATTERN_FILTER 0x41 441094332d3Sopenharmony_ci#define USB_DDK_CDC_GET_ETHERNET_PM_PATTERN_FILTER 0x42 442094332d3Sopenharmony_ci#define USB_DDK_CDC_SET_ETHERNET_PACKET_FILTER 0x43 443094332d3Sopenharmony_ci#define USB_DDK_CDC_GET_ETHERNET_STATISTIC 0x44 444094332d3Sopenharmony_ci#define USB_DDK_CDC_GET_NTB_PARAMETERS 0x80 445094332d3Sopenharmony_ci#define USB_DDK_CDC_GET_NET_ADDRESS 0x81 446094332d3Sopenharmony_ci#define USB_DDK_CDC_SET_NET_ADDRESS 0x82 447094332d3Sopenharmony_ci#define USB_DDK_CDC_GET_NTB_FORMAT 0x83 448094332d3Sopenharmony_ci#define USB_DDK_CDC_SET_NTB_FORMAT 0x84 449094332d3Sopenharmony_ci#define USB_DDK_CDC_GET_NTB_INPUT_SIZE 0x85 450094332d3Sopenharmony_ci#define USB_DDK_CDC_SET_NTB_INPUT_SIZE 0x86 451094332d3Sopenharmony_ci#define USB_DDK_CDC_GET_MAX_DATAGRAM_SIZE 0x87 452094332d3Sopenharmony_ci#define USB_DDK_CDC_SET_MAX_DATAGRAM_SIZE 0x88 453094332d3Sopenharmony_ci#define USB_DDK_CDC_GET_CRC_MODE 0x89 454094332d3Sopenharmony_ci#define USB_DDK_CDC_SET_CRC_MODE 0x8A 455094332d3Sopenharmony_ci 456094332d3Sopenharmony_ci#define USB_DDK_CDC_COMM_FEATURE 0x01 457094332d3Sopenharmony_ci#define USB_DDK_CDC_CAP_LINE 0x02 458094332d3Sopenharmony_ci#define USB_DDK_CDC_CAP_BRK 0x04 459094332d3Sopenharmony_ci#define USB_DDK_CDC_CAP_NOTIFY 0x08 460094332d3Sopenharmony_ci 461094332d3Sopenharmony_ci#define USB_DDK_CDC_HEADER_TYPE 0x00 462094332d3Sopenharmony_ci#define USB_DDK_CDC_CALL_MANAGEMENT_TYPE 0x01 463094332d3Sopenharmony_ci#define USB_DDK_CDC_ACM_TYPE 0x02 464094332d3Sopenharmony_ci#define USB_DDK_CDC_UNION_TYPE 0x06 465094332d3Sopenharmony_ci#define USB_DDK_CDC_COUNTRY_TYPE 0x07 466094332d3Sopenharmony_ci#define USB_DDK_CDC_NETWORK_TERMINAL_TYPE 0x0a 467094332d3Sopenharmony_ci#define USB_DDK_CDC_ETHERNET_TYPE 0x0f 468094332d3Sopenharmony_ci#define USB_DDK_CDC_WHCM_TYPE 0x11 469094332d3Sopenharmony_ci#define USB_DDK_CDC_MDLM_TYPE 0x12 470094332d3Sopenharmony_ci#define USB_DDK_CDC_MDLM_DETAIL_TYPE 0x13 471094332d3Sopenharmony_ci#define USB_DDK_CDC_DMM_TYPE 0x14 472094332d3Sopenharmony_ci#define USB_DDK_CDC_OBEX_TYPE 0x15 473094332d3Sopenharmony_ci#define USB_DDK_CDC_NCM_TYPE 0x1A 474094332d3Sopenharmony_ci#define USB_DDK_CDC_MBIM_TYPE 0x1B 475094332d3Sopenharmony_ci#define USB_DDK_CDC_MBIM_EXTENDED_TYPE 0x1C 476094332d3Sopenharmony_ci 477094332d3Sopenharmony_ci#define USB_DDK_CDC_PROTO_NONE 0x00 478094332d3Sopenharmony_ci#define USB_DDK_CDC_ACM_PROTO_AT_V25TER 0x01 479094332d3Sopenharmony_ci#define USB_DDK_CDC_ACM_PROTO_AT_PCCA101 0x02 480094332d3Sopenharmony_ci#define USB_DDK_CDC_ACM_PROTO_AT_PCCA101_WAKE 0x03 481094332d3Sopenharmony_ci#define USB_DDK_CDC_ACM_PROTO_AT_GSM 0x04 482094332d3Sopenharmony_ci#define USB_DDK_CDC_ACM_PROTO_AT_3G 0x05 483094332d3Sopenharmony_ci#define USB_DDK_CDC_ACM_PROTO_AT_CDMA 0x06 484094332d3Sopenharmony_ci#define USB_DDK_CDC_PROTO_EEM 0x07 485094332d3Sopenharmony_ci 486094332d3Sopenharmony_ci#define USB_DDK_CDC_NCM_PROTO_NTB 0x01 487094332d3Sopenharmony_ci#define USB_DDK_CDC_MBIM_PROTO_NTB 0x02 488094332d3Sopenharmony_ci 489094332d3Sopenharmony_ci#define USB_DDK_CDC_SUBCLASS_ACM 0x02 490094332d3Sopenharmony_ci#define USB_DDK_CDC_SUBCLASS_ETHERNET 0x06 491094332d3Sopenharmony_ci#define USB_DDK_CDC_SUBCLASS_WHCM 0x08 492094332d3Sopenharmony_ci#define USB_DDK_CDC_SUBCLASS_DMM 0x09 493094332d3Sopenharmony_ci#define USB_DDK_CDC_SUBCLASS_MDLM 0x0A 494094332d3Sopenharmony_ci#define USB_DDK_CDC_SUBCLASS_OBEX 0x0B 495094332d3Sopenharmony_ci#define USB_DDK_CDC_SUBCLASS_EEM 0x0C 496094332d3Sopenharmony_ci#define USB_DDK_CDC_SUBCLASS_NCM 0x0D 497094332d3Sopenharmony_ci#define USB_DDK_CDC_SUBCLASS_MBIM 0x0E 498094332d3Sopenharmony_ci 499094332d3Sopenharmony_ci#define USB_DDK_CDC_PACKET_TYPE_PROMISCUOUS (1 << 0) 500094332d3Sopenharmony_ci#define USB_DDK_CDC_PACKET_TYPE_ALL_MULTICAST (1 << 1) 501094332d3Sopenharmony_ci#define USB_DDK_CDC_PACKET_TYPE_DIRECTED (1 << 2) 502094332d3Sopenharmony_ci#define USB_DDK_CDC_PACKET_TYPE_BROADCAST (1 << 3) 503094332d3Sopenharmony_ci#define USB_DDK_CDC_PACKET_TYPE_MULTICAST (1 << 4) 504094332d3Sopenharmony_ci 505094332d3Sopenharmony_ci#define USB_DDK_CDC_ACM_PROTO_VENDOR 0xFF 506094332d3Sopenharmony_ci 507094332d3Sopenharmony_ci#define USB_DDK_TYPE_MASK (0x03 << 5) 508094332d3Sopenharmony_ci#define USB_DDK_TYPE_STANDARD (0x00 << 5) 509094332d3Sopenharmony_ci#define USB_DDK_TYPE_CLASS (0x01 << 5) 510094332d3Sopenharmony_ci#define USB_DDK_TYPE_VENDOR (0x02 << 5) 511094332d3Sopenharmony_ci#define USB_DDK_TYPE_RESERVED (0x03 << 5) 512094332d3Sopenharmony_ci 513094332d3Sopenharmony_ci#define USB_DDK_ENDPOINT_XFERTYPE_MASK 0x03 514094332d3Sopenharmony_ci#define USB_DDK_ENDPOINT_XFER_CONTROL 0x00 515094332d3Sopenharmony_ci#define USB_DDK_ENDPOINT_XFER_ISOC 0x01 516094332d3Sopenharmony_ci#define USB_DDK_ENDPOINT_XFER_BULK 0x02 517094332d3Sopenharmony_ci#define USB_DDK_ENDPOINT_XFER_INT 0x03 518094332d3Sopenharmony_ci#define USB_DDK_ENDPOINT_MAX_ADJUSTABLE 0x80 519094332d3Sopenharmony_ci 520094332d3Sopenharmony_ci#define USB_DDK_RECIP_MASK 0x1F 521094332d3Sopenharmony_ci#define USB_DDK_RECIP_DEVICE 0x00 522094332d3Sopenharmony_ci#define USB_DDK_RECIP_INTERFACE 0x01 523094332d3Sopenharmony_ci#define USB_DDK_RECIP_ENDPOINT 0x02 524094332d3Sopenharmony_ci#define USB_DDK_RECIP_OTHER 0x03 525094332d3Sopenharmony_ci 526094332d3Sopenharmony_ci#define USB_DDK_REQ_GET_STATUS 0x00 527094332d3Sopenharmony_ci#define USB_DDK_REQ_CLEAR_FEATURE 0x01 528094332d3Sopenharmony_ci#define USB_DDK_REQ_SET_FEATURE 0x03 529094332d3Sopenharmony_ci#define USB_DDK_REQ_SET_ADDRESS 0x05 530094332d3Sopenharmony_ci#define USB_DDK_REQ_GET_DESCRIPTOR 0x06 531094332d3Sopenharmony_ci#define USB_DDK_REQ_SET_DESCRIPTOR 0x07 532094332d3Sopenharmony_ci#define USB_DDK_REQ_GET_CONFIGURATION 0x08 533094332d3Sopenharmony_ci#define USB_DDK_REQ_SET_CONFIGURATION 0x09 534094332d3Sopenharmony_ci#define USB_DDK_REQ_GET_INTERFACE 0x0A 535094332d3Sopenharmony_ci#define USB_DDK_REQ_SET_INTERFACE 0x0B 536094332d3Sopenharmony_ci#define USB_DDK_REQ_SYNCH_FRAME 0x0C 537094332d3Sopenharmony_ci#define USB_DDK_REQ_SET_SEL 0x30 538094332d3Sopenharmony_ci#define USB_DDK_REQ_SET_ISOCH_DELAY 0x31 539094332d3Sopenharmony_ci 540094332d3Sopenharmony_ci/** 541094332d3Sopenharmony_ci * @brief Checks whether the specified endpoint is in the input direction (the direction in 542094332d3Sopenharmony_ci * which data is transferred from the device to the host). For details, see {@link UsbRequestDirection}. 543094332d3Sopenharmony_ci * 544094332d3Sopenharmony_ci * @param ep Indicates the endpoint address, which is in the <b>uint8_t</b> format. 545094332d3Sopenharmony_ci * 546094332d3Sopenharmony_ci * @return Returns <b>1</b> if the specified endpoint is in the input direction; returns <b>0</b> otherwise. 547094332d3Sopenharmony_ci */ 548094332d3Sopenharmony_ciinline int32_t UsbEndpointDirIn(uint8_t ep) 549094332d3Sopenharmony_ci{ 550094332d3Sopenharmony_ci return ((ep & USB_DDK_ENDPOINT_DIR_MASK) == USB_DDK_DIR_IN); 551094332d3Sopenharmony_ci} 552094332d3Sopenharmony_ci 553094332d3Sopenharmony_ci/** 554094332d3Sopenharmony_ci * @brief Checks whether the specified endpoint is in the output direction (the direction in which data is 555094332d3Sopenharmony_ci * transferred from the host to the device). For details, see {@link UsbRequestDirection}. 556094332d3Sopenharmony_ci * 557094332d3Sopenharmony_ci * @param ep Indicates the endpoint address, which is in the <b>uint8_t</b> format. 558094332d3Sopenharmony_ci * 559094332d3Sopenharmony_ci * @return Returns <b>1</b> if the specified endpoint is in the output direction; returns <b>0</b> otherwise. 560094332d3Sopenharmony_ci */ 561094332d3Sopenharmony_ciinline int32_t UsbEndpointDirOut(uint8_t ep) 562094332d3Sopenharmony_ci{ 563094332d3Sopenharmony_ci return ((ep & USB_DDK_ENDPOINT_DIR_MASK) == USB_DDK_DIR_OUT); 564094332d3Sopenharmony_ci} 565094332d3Sopenharmony_ci 566094332d3Sopenharmony_ci#endif /* USB_DDK_H */ 567094332d3Sopenharmony_ci/** @} */ 568