Skip to content

File usb_std.h

File List > fw > rbcx-coprocessor > lib > libusb_stm32 > include > usb_std.h

Go to the documentation of this file.

/* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers
 *
 * Copyright ©2016 Dmitry Filimonchuk <dmitrystu[at]gmail[dot]com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *   http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _USB_STD_H_
#define _USB_STD_H_
#if defined(__cplusplus)
extern "C" {
#endif

#define __CAT(x,y) x ## y
#define CAT(x,y) __CAT(x,y)

#define VERSION_BCD(maj, min, rev)  (((maj & 0xFF) << 8) | ((min & 0x0F) << 4) | (rev & 0x0F))

#define USB_ARRAY_DESC(...)        {.bLength = 2 + sizeof((uint16_t[]){__VA_ARGS__}),\
                                    .bDescriptorType = USB_DTYPE_STRING,\
                                    .wString = {__VA_ARGS__}}
#define USB_STRING_DESC(s)         {.bLength = sizeof(CAT(u,s)),\
                                    .bDescriptorType = USB_DTYPE_STRING,\
                                    .wString = {CAT(u,s)}}

#define USB_CFG_POWER_MA(mA)        ((mA) >> 1)
#define USB_CFG_ATTR_RESERVED       0x80
#define USB_CFG_ATTR_SELFPOWERED    0x40
#define USB_EPDIR_IN                0x00    
#define USB_EPDIR_OUT               0x80    
#define USB_EPTYPE_CONTROL          0x00    
#define USB_EPTYPE_ISOCHRONUS       0x01    
#define USB_EPTYPE_BULK             0x02    
#define USB_EPTYPE_INTERRUPT        0x03    
#define USB_EPATTR_NO_SYNC          0x00    
#define USB_EPATTR_ASYNC            0x04    
#define USB_EPATTR_ADAPTIVE         0x08    
#define USB_EPATTR_SYNC             0x0C    
#define USB_EPUSAGE_DATA            0x00    
#define USB_EPUSAGE_FEEDBACK        0x10    
#define USB_EPUSAGE_IMP_FEEDBACK    0x20    
#define NO_DESCRIPTOR               0x00    
#define INTSERIALNO_DESCRIPTOR      0xFE    
#define USB_CLASS_PER_INTERFACE     0x00    
#define USB_SUBCLASS_NONE           0x00    
#define USB_PROTO_NONE              0x00    
#define USB_CLASS_AUDIO             0x01    
#define USB_CLASS_PHYSICAL          0x05    
#define USB_CLASS_STILL_IMAGE       0x06    
#define USB_CLASS_PRINTER           0x07    
#define USB_CLASS_MASS_STORAGE      0x08    
#define USB_CLASS_HUB               0x09    
#define USB_CLASS_CSCID             0x0B    
#define USB_CLASS_CONTENT_SEC       0x0D    
#define USB_CLASS_VIDEO             0x0E    
#define USB_CLASS_HEALTHCARE        0x0F    
#define USB_CLASS_AV                0x10    
#define USB_CLASS_BILLBOARD         0x11    
#define USB_CLASS_CBRIDGE           0x12    
#define USB_CLASS_DIAGNOSTIC        0xDC    
#define USB_CLASS_WIRELESS          0xE0    
#define USB_CLASS_MISC              0xEF    
#define USB_CLASS_APP_SPEC          0xFE    
#define USB_CLASS_VENDOR            0xFF    
#define USB_SUBCLASS_VENDOR         0xFF    
#define USB_PROTO_VENDOR            0xFF    
#define USB_CLASS_IAD               0xEF    
#define USB_SUBCLASS_IAD            0x02    
#define USB_PROTO_IAD               0x01    
#define USB_DTYPE_DEVICE            0x01    
#define USB_DTYPE_CONFIGURATION     0x02    
#define USB_DTYPE_STRING            0x03    
#define USB_DTYPE_INTERFACE         0x04    
#define USB_DTYPE_ENDPOINT          0x05    
#define USB_DTYPE_QUALIFIER         0x06    
#define USB_DTYPE_OTHER             0x07    
#define USB_DTYPE_INTERFACEPOWER    0x08    
#define USB_DTYPE_OTG               0x09    
#define USB_DTYPE_DEBUG             0x0A    
#define USB_DTYPE_INTERFASEASSOC    0x0B    
#define USB_DTYPE_CS_INTERFACE      0x24    
#define USB_DTYPE_CS_ENDPOINT       0x25    
#define USB_STD_GET_STATUS          0x00    
#define USB_STD_CLEAR_FEATURE       0x01    
#define USB_STD_SET_FEATURE         0x03    
#define USB_STD_SET_ADDRESS         0x05    
#define USB_STD_GET_DESCRIPTOR      0x06    
#define USB_STD_SET_DESCRIPTOR      0x07    
#define USB_STD_GET_CONFIG          0x08    
#define USB_STD_SET_CONFIG          0x09    
#define USB_STD_GET_INTERFACE       0x0A    
#define USB_STD_SET_INTERFACE       0x0B    
#define USB_STD_SYNCH_FRAME         0x0C    
#define USB_FEAT_ENDPOINT_HALT      0x00    
#define USB_FEAT_REMOTE_WKUP        0x01
#define USB_FEAT_TEST_MODE          0x02
#define USB_FEAT_DEBUG_MODE         0x06
#define USB_TEST_J                  0x01    
#define USB_TEST_K                  0x02    
#define USB_TEST_SE0_NAK            0x03    
#define USB_TEST_PACKET             0x04    
#define USB_TEST_FORCE_ENABLE       0x05    
#define USB_LANGID_AFR              0x0436   
#define USB_LANGID_SQI              0x041c   
#define USB_LANGID_ARA_SA           0x0401   
#define USB_LANGID_ARA_IQ           0x0801   
#define USB_LANGID_ARA_EG           0x0c01   
#define USB_LANGID_ARA_LY           0x1001   
#define USB_LANGID_ARA_DZ           0x1401   
#define USB_LANGID_ARA_MA           0x1801   
#define USB_LANGID_ARA_TN           0x1c01   
#define USB_LANGID_ARA_OM           0x2001   
#define USB_LANGID_ARA_YE           0x2401   
#define USB_LANGID_ARA_SY           0x2801   
#define USB_LANGID_ARA_JO           0x2c01   
#define USB_LANGID_ARA_LB           0x3001   
#define USB_LANGID_ARA_KW           0x3401   
#define USB_LANGID_ARA_AE           0x3801   
#define USB_LANGID_ARA_BH           0x3c01   
#define USB_LANGID_ARA_QA           0x4001   
#define USB_LANGID_HYE              0x042b   
#define USB_LANGID_ASM              0x044d   
#define USB_LANGID_AZE_LAT          0x042c   
#define USB_LANGID_AZE_CYR          0x082c   
#define USB_LANGID_EUS              0x042d   
#define USB_LANGID_BEL              0x0423   
#define USB_LANGID_BEN              0x0445   
#define USB_LANGID_BUL              0x0402   
#define USB_LANGID_MYA              0x0455   
#define USB_LANGID_CAT              0x0403   
#define USB_LANGID_ZHO_TW           0x0404   
#define USB_LANGID_ZHO_CN           0x0804   
#define USB_LANGID_ZHO_HK           0x0c04   
#define USB_LANGID_ZHO_SG           0x1004   
#define USB_LANGID_ZHO_MO           0x1404   
#define USB_LANGID_HRV              0x041a   
#define USB_LANGID_CZE              0x0405   
#define USB_LANGID_DAN              0x0406   
#define USB_LANGID_NLD_NL           0x0413   
#define USB_LANGID_NLD_BE           0x0813   
#define USB_LANGID_ENG_US           0x0409   
#define USB_LANGID_ENG_UK           0x0809   
#define USB_LANGID_ENG_AU           0x0c09   
#define USB_LANGID_ENG_CA           0x1009   
#define USB_LANGID_ENG_NZ           0x1409   
#define USB_LANGID_ENG_IE           0x1809   
#define USB_LANGID_ENG_ZA           0x1c09   
#define USB_LANGID_ENG_JM           0x2009   
#define USB_LANGID_ENG_CAR          0x2409   
#define USB_LANGID_ENG_BZ           0x2809   
#define USB_LANGID_ENG_TH           0x2c09   
#define USB_LANGID_ENG_ZW           0x3009   
#define USB_LANGID_ENG_PH           0x3409   
#define USB_LANGID_EST              0x0425   
#define USB_LANGID_FAO              0x0438   
#define USB_LANGID_FAS              0x0429   
#define USB_LANGID_FIN              0x040b   
#define USB_LANGID_FRA              0x040c   
#define USB_LANGID_FRA_BE           0x080c   
#define USB_LANGID_FRA_CA           0x0c0c   
#define USB_LANGID_FRA_SZ           0x100c   
#define USB_LANGID_FRA_LU           0x140c   
#define USB_LANGID_FRA_MC           0x180c   
#define USB_LANGID_KAT              0x0437   
#define USB_LANGID_DEU              0x0407   
#define USB_LANGID_DEU_SZ           0x0807   
#define USB_LANGID_DEU_AT           0x0c07   
#define USB_LANGID_DEU_LU           0x1007   
#define USB_LANGID_DEU_LI           0x1407   
#define USB_LANGID_ELL              0x0408   
#define USB_LANGID_GUJ              0x0447   
#define USB_LANGID_HEB              0x040d   
#define USB_LANGID_HIN              0x0439   
#define USB_LANGID_HUN              0x040e   
#define USB_LANGID_ISL              0x040f   
#define USB_LANGID_IND              0x0421   
#define USB_LANGID_ITA              0x0410   
#define USB_LANGID_ITA_SZ           0x0810   
#define USB_LANGID_JPN              0x0411   
#define USB_LANGID_KAN              0x044b   
#define USB_LANGID_KAS              0x0860   
#define USB_LANGID_KAZ              0x043f   
#define USB_LANGID_KOK              0x0457   
#define USB_LANGID_KOR              0x0412   
#define USB_LANGID_KOR_JOH          0x0812   
#define USB_LANGID_LAV              0x0426   
#define USB_LANGID_LIT              0x0427   
#define USB_LANGID_LIT_CLS          0x0827   
#define USB_LANGID_MKD              0x042f   
#define USB_LANGID_MSA              0x043e   
#define USB_LANGID_MSA_BN           0x083e   
#define USB_LANGID_MAL              0x044c   
#define USB_LANGID_MNI              0x0458   
#define USB_LANGID_MAR              0x044e   
#define USB_LANGID_NEP              0x0861   
#define USB_LANGID_NOB              0x0414   
#define USB_LANGID_NNO              0x0814   
#define USB_LANGID_ORI              0x0448   
#define USB_LANGID_POL              0x0415   
#define USB_LANGID_POR_BR           0x0416   
#define USB_LANGID_POR              0x0816   
#define USB_LANGID_PAN              0x0446   
#define USB_LANGID_RON              0x0418   
#define USB_LANGID_RUS              0x0419   
#define USB_LANGID_SAN              0x044f   
#define USB_LANGID_SRB_CYR          0x0c1a   
#define USB_LANGID_SRB_LAT          0x081a   
#define USB_LANGID_SND              0x0459   
#define USB_LANGID_SLK              0x041b   
#define USB_LANGID_SLV              0x0424   
#define USB_LANGID_SPA              0x040a   
#define USB_LANGID_SPA_MX           0x080a   
#define USB_LANGID_SPA_MDN          0x0c0a   
#define USB_LANGID_SPA_GT           0x100a   
#define USB_LANGID_SPA_CR           0x140a   
#define USB_LANGID_SPA_PA           0x180a   
#define USB_LANGID_SPA_DO           0x1c0a   
#define USB_LANGID_SPA_VE           0x200a   
#define USB_LANGID_SPA_CO           0x240a   
#define USB_LANGID_SPA_PE           0x280a   
#define USB_LANGID_SPA_AR           0x2c0a   
#define USB_LANGID_SPA_EC           0x300a   
#define USB_LANGID_SPA_CL           0x340a   
#define USB_LANGID_SPA_UY           0x380a   
#define USB_LANGID_SPA_PY           0x3c0a   
#define USB_LANGID_SPA_BO           0x400a   
#define USB_LANGID_SPA_SV           0x440a   
#define USB_LANGID_SPA_HN           0x480a   
#define USB_LANGID_SPA_NI           0x4c0a   
#define USB_LANGID_SPA_PR           0x500a   
#define USB_LANGID_NSO              0x0430   
#define USB_LANGID_SWA              0x0441   
#define USB_LANGID_SWE              0x041d   
#define USB_LANGID_SWE_FI           0x081d   
#define USB_LANGID_TAM              0x0449   
#define USB_LANGID_TAT              0x0444   
#define USB_LANGID_TEL              0x044a   
#define USB_LANGID_THA              0x041e   
#define USB_LANGID_TUR              0x041f   
#define USB_LANGIG_UKR              0x0422   
#define USB_LANGID_URD_PK           0x0420   
#define USB_LANGID_URD_IN           0x0820   
#define USB_LANGID_UZB_LAT          0x0443   
#define USB_LANGID_UZB_CYR          0x0843   
#define USB_LANGID_VIE              0x042a   
struct usb_header_descriptor {
    uint8_t bLength;                
    uint8_t bDescriptorType;        
} __attribute__((packed));

struct usb_device_descriptor {
    uint8_t  bLength;               
    uint8_t  bDescriptorType;       
    uint16_t bcdUSB;                
    uint8_t  bDeviceClass;          
    uint8_t  bDeviceSubClass;       
    uint8_t  bDeviceProtocol;       
    uint8_t  bMaxPacketSize0;       
    uint16_t idVendor;              
    uint16_t idProduct;             
    uint16_t bcdDevice;             
    uint8_t  iManufacturer;         
    uint8_t  iProduct;              
    uint8_t  iSerialNumber;         
    uint8_t  bNumConfigurations;    
} __attribute__((packed));

struct usb_qualifier_descriptor {
    uint8_t  bLength;               
    uint8_t  bDescriptorType;       
    uint16_t bcdUSB;                
    uint8_t  bDeviceClass;          
    uint8_t  bDeviceSubClass;       
    uint8_t  bDeviceProtocol;       
    uint8_t  bMaxPacketSize0;       
    uint8_t  bNumConfigurations;    
    uint8_t  bReserved;             
} __attribute__((packed));

struct usb_config_descriptor {
    uint8_t  bLength;               
    uint8_t  bDescriptorType;       
    uint16_t wTotalLength;          
    uint8_t  bNumInterfaces;        
    uint8_t  bConfigurationValue;   
    uint8_t  iConfiguration;        
    uint8_t  bmAttributes;          
    uint8_t  bMaxPower;             
} __attribute__((packed));

struct usb_interface_descriptor {
    uint8_t bLength;                
    uint8_t bDescriptorType;        
    uint8_t bInterfaceNumber;       
    uint8_t bAlternateSetting;      
    uint8_t bNumEndpoints;          
    uint8_t bInterfaceClass;        
    uint8_t bInterfaceSubClass;     
    uint8_t bInterfaceProtocol;     
    uint8_t iInterface;             
} __attribute__((packed));

struct usb_iad_descriptor {
    uint8_t bLength;                
    uint8_t bDescriptorType;        
    uint8_t bFirstInterface;        
    uint8_t bInterfaceCount;        
    uint8_t bFunctionClass;         
    uint8_t bFunctionSubClass;      
    uint8_t bFunctionProtocol;      
    uint8_t iFunction;              
} __attribute__((packed));

struct usb_endpoint_descriptor {
    uint8_t  bLength;               
    uint8_t  bDescriptorType;       
    uint8_t  bEndpointAddress;      
    uint8_t  bmAttributes;          
    uint16_t wMaxPacketSize;        
    uint8_t  bInterval;             
} __attribute__((packed));

struct usb_string_descriptor {
    uint8_t  bLength;               
    uint8_t  bDescriptorType;       
    uint16_t wString[];             
} __attribute__((packed, aligned(2)));

struct usb_debug_descriptor {
    uint8_t  bLength;               
    uint8_t  bDescriptorType;       
    uint8_t  bDebugInEndpoint;      
    uint8_t  bDebugOutEndpoint;     
} __attribute__((packed));

#if defined (__cplusplus)
}
#endif
#endif //_USB_STD_H_