These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usb.h Source File

usb.h

00001 /*----------------------------------------------------------------------------
00002  *      U S B  -  K e r n e l
00003  *----------------------------------------------------------------------------
00004  *      Name:    USB.H
00005  *      Purpose: USB Definitions
00006  *      Version: V1.10
00007  *----------------------------------------------------------------------------
00008  *      This software is supplied "AS IS" without any warranties, express,
00009  *      implied or statutory, including but not limited to the implied
00010  *      warranties of fitness for purpose, satisfactory quality and
00011  *      noninfringement. Keil extends you a royalty-free right to reproduce
00012  *      and distribute executable files created using this software for use
00013  *      on NXP Semiconductors LPC family microcontroller devices only. Nothing
00014  *      else gives you the right to use this software.
00015  *
00016  *      Copyright (c) 2005-2009 Keil Software.
00017  *---------------------------------------------------------------------------*/
00018 
00019 #ifndef __USB_H__
00020 #define __USB_H__
00021 
00022 
00023 #if defined   (  __GNUC__  )
00024 #define __packed __attribute__((__packed__))
00025 #endif
00026 
00027 
00028 #if defined     (  __CC_ARM  )
00029 typedef __packed union {
00030 #elif defined   (  __GNUC__  )
00031 typedef union __packed {
00032 #elif defined   (  __IAR_SYSTEMS_ICC__  )
00033 typedef __packed union {
00034 #endif
00035   uint16_t W;
00036 #if defined     (  __CC_ARM  )
00037   __packed struct {
00038 #elif defined   (  __GNUC__  )
00039   struct __packed {
00040 #elif defined   (  __IAR_SYSTEMS_ICC__  )
00041   __packed struct {
00042 #endif
00043     uint8_t L;
00044     uint8_t H;
00045   } WB;
00046 } WORD_BYTE;
00047 
00048 
00049 /* bmRequestType.Dir */
00050 #define REQUEST_HOST_TO_DEVICE     0
00051 #define REQUEST_DEVICE_TO_HOST     1
00052 
00053 /* bmRequestType.Type */
00054 #define REQUEST_STANDARD           0
00055 #define REQUEST_CLASS              1
00056 #define REQUEST_VENDOR             2
00057 #define REQUEST_RESERVED           3
00058 
00059 /* bmRequestType.Recipient */
00060 #define REQUEST_TO_DEVICE          0
00061 #define REQUEST_TO_INTERFACE       1
00062 #define REQUEST_TO_ENDPOINT        2
00063 #define REQUEST_TO_OTHER           3
00064 
00065 /* bmRequestType Definition */
00066 #if defined     (  __CC_ARM  )
00067 typedef __packed union _REQUEST_TYPE {
00068 #elif defined   (  __GNUC__  )
00069 typedef union __packed _REQUEST_TYPE {
00070 #elif defined   (  __IAR_SYSTEMS_ICC__  )
00071 typedef __packed union _REQUEST_TYPE {
00072 #endif
00073 #if defined     (  __CC_ARM  )
00074     __packed struct _BM {
00075 #elif defined   (  __GNUC__  )
00076     struct __packed _BM {
00077 #elif defined   (  __IAR_SYSTEMS_ICC__  )
00078     __packed struct _BM {
00079 #endif
00080     uint8_t Recipient : 5;
00081     uint8_t Type      : 2;
00082     uint8_t Dir       : 1;
00083   } BM;
00084   uint8_t B;
00085 } REQUEST_TYPE;
00086 
00087 /* USB Standard Request Codes */
00088 #define USB_REQUEST_GET_STATUS                 0
00089 #define USB_REQUEST_CLEAR_FEATURE              1
00090 #define USB_REQUEST_SET_FEATURE                3
00091 #define USB_REQUEST_SET_ADDRESS                5
00092 #define USB_REQUEST_GET_DESCRIPTOR             6
00093 #define USB_REQUEST_SET_DESCRIPTOR             7
00094 #define USB_REQUEST_GET_CONFIGURATION          8
00095 #define USB_REQUEST_SET_CONFIGURATION          9
00096 #define USB_REQUEST_GET_INTERFACE              10
00097 #define USB_REQUEST_SET_INTERFACE              11
00098 #define USB_REQUEST_SYNC_FRAME                 12
00099 
00100 /* USB GET_STATUS Bit Values */
00101 #define USB_GETSTATUS_SELF_POWERED             0x01
00102 #define USB_GETSTATUS_REMOTE_WAKEUP            0x02
00103 #define USB_GETSTATUS_ENDPOINT_STALL           0x01
00104 
00105 /* USB Standard Feature selectors */
00106 #define USB_FEATURE_ENDPOINT_STALL             0
00107 #define USB_FEATURE_REMOTE_WAKEUP              1
00108 
00109 /* USB Default Control Pipe Setup Packet */
00110 #if defined     (  __CC_ARM  )
00111 typedef __packed struct _USB_SETUP_PACKET {
00112 #elif defined   (  __GNUC__  )
00113 typedef struct __packed _USB_SETUP_PACKET {
00114 #elif defined   (  __IAR_SYSTEMS_ICC__  )
00115 typedef __packed struct _USB_SETUP_PACKET {
00116 #endif
00117   REQUEST_TYPE bmRequestType;
00118   uint8_t         bRequest;
00119   WORD_BYTE    wValue;
00120   WORD_BYTE    wIndex;
00121   uint16_t         wLength;
00122 } USB_SETUP_PACKET;
00123 
00124 
00125 /* USB Descriptor Types */
00126 #define USB_DEVICE_DESCRIPTOR_TYPE             1
00127 #define USB_CONFIGURATION_DESCRIPTOR_TYPE      2
00128 #define USB_STRING_DESCRIPTOR_TYPE             3
00129 #define USB_INTERFACE_DESCRIPTOR_TYPE          4
00130 #define USB_ENDPOINT_DESCRIPTOR_TYPE           5
00131 #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE   6
00132 #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7
00133 #define USB_INTERFACE_POWER_DESCRIPTOR_TYPE    8
00134 #define USB_OTG_DESCRIPTOR_TYPE                     9
00135 #define USB_DEBUG_DESCRIPTOR_TYPE                  10
00136 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE  11
00137 
00138 /* USB Device Classes */
00139 #define USB_DEVICE_CLASS_RESERVED              0x00
00140 #define USB_DEVICE_CLASS_AUDIO                 0x01
00141 #define USB_DEVICE_CLASS_COMMUNICATIONS        0x02
00142 #define USB_DEVICE_CLASS_HUMAN_INTERFACE       0x03
00143 #define USB_DEVICE_CLASS_MONITOR               0x04
00144 #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE    0x05
00145 #define USB_DEVICE_CLASS_POWER                 0x06
00146 #define USB_DEVICE_CLASS_PRINTER               0x07
00147 #define USB_DEVICE_CLASS_STORAGE               0x08
00148 #define USB_DEVICE_CLASS_HUB                   0x09
00149 #define USB_DEVICE_CLASS_MISCELLANEOUS         0xEF
00150 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC       0xFF
00151 
00152 /* bmAttributes in Configuration Descriptor */
00153 #define USB_CONFIG_POWERED_MASK                0xC0
00154 #define USB_CONFIG_BUS_POWERED                 0x80
00155 #define USB_CONFIG_SELF_POWERED                0xC0
00156 #define USB_CONFIG_REMOTE_WAKEUP               0x20
00157 
00158 /* bMaxPower in Configuration Descriptor */
00159 #define USB_CONFIG_POWER_MA(mA)                ((mA)/2)
00160 
00161 /* bEndpointAddress in Endpoint Descriptor */
00162 #define USB_ENDPOINT_DIRECTION_MASK            0x80
00163 #define USB_ENDPOINT_OUT(addr)                 ((addr) | 0x00)
00164 #define USB_ENDPOINT_IN(addr)                  ((addr) | 0x80)
00165 
00166 /* bmAttributes in Endpoint Descriptor */
00167 #define USB_ENDPOINT_TYPE_MASK                 0x03
00168 #define USB_ENDPOINT_TYPE_CONTROL              0x00
00169 #define USB_ENDPOINT_TYPE_ISOCHRONOUS          0x01
00170 #define USB_ENDPOINT_TYPE_BULK                 0x02
00171 #define USB_ENDPOINT_TYPE_INTERRUPT            0x03
00172 #define USB_ENDPOINT_SYNC_MASK                 0x0C
00173 #define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION   0x00
00174 #define USB_ENDPOINT_SYNC_ASYNCHRONOUS         0x04
00175 #define USB_ENDPOINT_SYNC_ADAPTIVE             0x08
00176 #define USB_ENDPOINT_SYNC_SYNCHRONOUS          0x0C
00177 #define USB_ENDPOINT_USAGE_MASK                0x30
00178 #define USB_ENDPOINT_USAGE_DATA                0x00
00179 #define USB_ENDPOINT_USAGE_FEEDBACK            0x10
00180 #define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK   0x20
00181 #define USB_ENDPOINT_USAGE_RESERVED            0x30
00182 
00183 /* USB Standard Device Descriptor */
00184 #if defined     (  __CC_ARM  )
00185 typedef __packed struct _USB_DEVICE_DESCRIPTOR {
00186 #elif defined   (  __GNUC__  )
00187 typedef struct __packed _USB_DEVICE_DESCRIPTOR {
00188 #elif defined   (  __IAR_SYSTEMS_ICC__  )
00189 typedef __packed struct _USB_DEVICE_DESCRIPTOR {
00190 #endif
00191   uint8_t  bLength;
00192   uint8_t  bDescriptorType;
00193   uint16_t  bcdUSB;
00194   uint8_t  bDeviceClass;
00195   uint8_t  bDeviceSubClass;
00196   uint8_t  bDeviceProtocol;
00197   uint8_t  bMaxPacketSize0;
00198   uint16_t  idVendor;
00199   uint16_t  idProduct;
00200   uint16_t  bcdDevice;
00201   uint8_t  iManufacturer;
00202   uint8_t  iProduct;
00203   uint8_t  iSerialNumber;
00204   uint8_t  bNumConfigurations;
00205 } USB_DEVICE_DESCRIPTOR;
00206 
00207 /* USB 2.0 Device Qualifier Descriptor */
00208 #if defined     (  __CC_ARM  )
00209 typedef __packed struct _USB_DEVICE_QUALIFIER_DESCRIPTOR {
00210 #elif defined   (  __GNUC__  )
00211 typedef struct __packed _USB_DEVICE_QUALIFIER_DESCRIPTOR {
00212 #elif defined   (  __IAR_SYSTEMS_ICC__  )
00213 typedef __packed struct _USB_DEVICE_QUALIFIER_DESCRIPTOR {
00214 #endif
00215   uint8_t  bLength;
00216   uint8_t  bDescriptorType;
00217   uint16_t  bcdUSB;
00218   uint8_t  bDeviceClass;
00219   uint8_t  bDeviceSubClass;
00220   uint8_t  bDeviceProtocol;
00221   uint8_t  bMaxPacketSize0;
00222   uint8_t  bNumConfigurations;
00223   uint8_t  bReserved;
00224 } USB_DEVICE_QUALIFIER_DESCRIPTOR;
00225 
00226 /* USB Standard Configuration Descriptor */
00227 #if defined     (  __CC_ARM  )
00228 typedef __packed struct _USB_CONFIGURATION_DESCRIPTOR {
00229 #elif defined   (  __GNUC__  )
00230 typedef struct __packed _USB_CONFIGURATION_DESCRIPTOR {
00231 #elif defined   (  __IAR_SYSTEMS_ICC__  )
00232 typedef __packed struct _USB_CONFIGURATION_DESCRIPTOR {
00233 #endif
00234   uint8_t  bLength;
00235   uint8_t  bDescriptorType;
00236   uint16_t  wTotalLength;
00237   uint8_t  bNumInterfaces;
00238   uint8_t  bConfigurationValue;
00239   uint8_t  iConfiguration;
00240   uint8_t  bmAttributes;
00241   uint8_t  bMaxPower;
00242 } USB_CONFIGURATION_DESCRIPTOR;
00243 
00244 /* USB Standard Interface Descriptor */
00245 #if defined     (  __CC_ARM  )
00246 typedef __packed struct _USB_INTERFACE_DESCRIPTOR {
00247 #elif defined   (  __GNUC__  )
00248 typedef struct __packed _USB_INTERFACE_DESCRIPTOR {
00249 #elif defined   (  __IAR_SYSTEMS_ICC__  )
00250 typedef __packed struct _USB_INTERFACE_DESCRIPTOR {
00251 #endif
00252   uint8_t  bLength;
00253   uint8_t  bDescriptorType;
00254   uint8_t  bInterfaceNumber;
00255   uint8_t  bAlternateSetting;
00256   uint8_t  bNumEndpoints;
00257   uint8_t  bInterfaceClass;
00258   uint8_t  bInterfaceSubClass;
00259   uint8_t  bInterfaceProtocol;
00260   uint8_t  iInterface;
00261 } USB_INTERFACE_DESCRIPTOR;
00262 
00263 /* USB Standard Endpoint Descriptor */
00264 #if defined     (  __CC_ARM  )
00265 typedef __packed struct _USB_ENDPOINT_DESCRIPTOR {
00266 #elif defined   (  __GNUC__  )
00267 typedef struct __packed _USB_ENDPOINT_DESCRIPTOR {
00268 #elif defined   (  __IAR_SYSTEMS_ICC__  )
00269 typedef __packed struct _USB_ENDPOINT_DESCRIPTOR {
00270 #endif
00271   uint8_t  bLength;
00272   uint8_t  bDescriptorType;
00273   uint8_t  bEndpointAddress;
00274   uint8_t  bmAttributes;
00275   uint16_t  wMaxPacketSize;
00276   uint8_t  bInterval;
00277 } USB_ENDPOINT_DESCRIPTOR;
00278 
00279 /* USB String Descriptor */
00280 #if defined     (  __CC_ARM  )
00281 typedef __packed struct _USB_STRING_DESCRIPTOR {
00282 #elif defined   (  __GNUC__  )
00283 typedef struct __packed _USB_STRING_DESCRIPTOR {
00284 #elif defined   (  __IAR_SYSTEMS_ICC__  )
00285 typedef __packed struct _USB_STRING_DESCRIPTOR {
00286 #endif
00287   uint8_t  bLength;
00288   uint8_t  bDescriptorType;
00289   uint16_t  bString/*[]*/;
00290 } USB_STRING_DESCRIPTOR;
00291 
00292 /* USB Common Descriptor */
00293 #if defined     (  __CC_ARM  )
00294 typedef __packed struct _USB_COMMON_DESCRIPTOR {
00295 #elif defined   (  __GNUC__  )
00296 typedef struct __packed _USB_COMMON_DESCRIPTOR {
00297 #elif defined   (  __IAR_SYSTEMS_ICC__  )
00298 typedef __packed struct _USB_COMMON_DESCRIPTOR {
00299 #endif
00300   uint8_t  bLength;
00301   uint8_t  bDescriptorType;
00302 } USB_COMMON_DESCRIPTOR;
00303 
00304 
00305 #endif  /* __USB_H__ */