Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usb_config.c Source File

usb_config.c

00001 /* CMSIS-DAP Interface Firmware
00002  * Copyright (c) 2009-2019 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "util.h"
00018 
00019 /*------------------------------------------------------------------------------
00020  *      USB Device Configuration
00021  *----------------------------------------------------------------------------*/
00022 
00023 // <e> USB Device
00024 //   <i> Enable the USB Device functionality
00025 #define USBD_ENABLE                 1
00026 #define USBD_RTX_CORE_STACK         0
00027 #define USBD_RTX_DEVICE_STACK       0
00028 #define USBD_RTX_ENDPOINT0_STACK    0
00029 
00030 //   <o0.0> High-speed
00031 //     <i> Enable high-speed functionality (if device supports it)
00032 #define USBD_HS_ENABLE              0
00033 #if (defined(WEBUSB_INTERFACE) || defined(WINUSB_INTERFACE) || defined(BULK_ENDPOINT))
00034 #define USBD_BOS_ENABLE             1
00035 #else
00036 #define USBD_BOS_ENABLE             0
00037 #endif
00038 //   <h> Device Settings
00039 //     <i> These settings affect Device Descriptor
00040 //     <o0> Power
00041 //       <i> Default Power Setting
00042 //       <0=> Bus-powered
00043 //       <1=> Self-powered
00044 //     <o1> Max Endpoint 0 Packet Size
00045 //       <i> Maximum packet size for endpoint zero (bMaxPacketSize0)
00046 //       <8=> 8 Bytes <16=> 16 Bytes <32=> 32 Bytes <64=> 64 Bytes
00047 //     <o2.0..15> Vendor ID <0x0000-0xFFFF>
00048 //       <i> Vendor ID assigned by the USB-IF (idVendor)
00049 //     <o3.0..15> Product ID <0x0000-0xFFFF>
00050 //       <i> Product ID assigned by the manufacturer (idProduct)
00051 //     <o4.0..15> Device Release Number <0x0000-0xFFFF>
00052 //       <i> Device release number in binary-coded decimal (bcdDevice)
00053 //   </h>
00054 #define USBD_POWER                  0
00055 #define USBD_MAX_PACKET0            64
00056 #define USBD_DEVDESC_IDVENDOR       0x0D28
00057 #define USBD_DEVDESC_IDPRODUCT      0x0204
00058 #define USBD_DEVDESC_BCDDEVICE      0x1000 //was 0x0100
00059 
00060 //   <h> Configuration Settings
00061 //     <i> These settings affect Configuration Descriptor
00062 //     <o0.5> Remote Wakeup
00063 //       <i> Configuration support for remote wakeup (D5: of bmAttributes)
00064 //     <o1.0..7> Maximum Power Consumption (in mA) <0-510><#/2>
00065 //       <i> Maximum power consumption of the USB device
00066 //       <i> from the bus in this specific configuration
00067 //       <i> when the device is fully operational (bMaxPower)
00068 //   </h>
00069 #define USBD_CFGDESC_BMATTRIBUTES   0x80
00070 #define USBD_CFGDESC_BMAXPOWER      0xFA
00071 
00072 //   <h> String Settings
00073 //     <i> These settings affect String Descriptor
00074 //     <o0.0..15> Language ID <0x0000-0xFCFF>
00075 //       <i> English (United States) = 0x0409
00076 //     <s0.126> Manufacturer String
00077 //       <i> String descriptor describing manufacturer
00078 //     <s1.126> Product String
00079 //       <i> String descriptor describing product
00080 //     <e1.0> Serial Number
00081 //       <i> Enable serial number string
00082 //       <i> If disabled serial number string will not be assigned to the USB Device
00083 //       <s2.126> Serial Number String
00084 //         <i> String descriptor describing device's serial number
00085 //     </e>
00086 //   </h>
00087 #define USBD_STRDESC_LANGID         0x0409
00088 #define USBD_STRDESC_MAN            L"ARM"
00089 #ifndef USB_PROD_STR
00090 #define USBD_STRDESC_PROD           L"DAPLink CMSIS-DAP"
00091 #else
00092 #define _TOWIDE(x)                   L ## #x
00093 #define TOWIDE(x)                   _TOWIDE(x)
00094 #define USBD_STRDESC_PROD           TOWIDE(USB_PROD_STR)
00095 #endif
00096 #define USBD_STRDESC_SER_ENABLE     1
00097 #define USBD_STRDESC_SER            L"0001A0000000"
00098 
00099 //   <e0> Class Support
00100 //     <i> Enables USB Device Class specific Requests
00101 #define USBD_CLASS_ENABLE           1
00102 
00103 //     <e0.0> Human Interface Device (HID)
00104 //       <i> Enable class support for Human Interface Device (HID)
00105 //       <h> Interrupt Endpoint Settings
00106 //         <o1.0..4> Interrupt In Endpoint Number                  <1=>   1 <2=>   2 <3=>   3
00107 //                                                 <4=>   4        <5=>   5 <6=>   6 <7=>   7
00108 //                                                 <8=>   8        <9=>   9 <10=> 10 <11=> 11
00109 //                                                 <12=>  12       <13=> 13 <14=> 14 <15=> 15
00110 //         <o2.0..4> Interrupt Out Endpoint Number <0=>   Not used <1=>   1 <2=>   2 <3=>   3
00111 //                                                 <4=>   4        <5=>   5 <6=>   6 <7=>   7
00112 //                                                 <8=>   8        <9=>   9 <10=> 10 <11=> 11
00113 //                                                 <12=>  12       <13=> 13 <14=> 14 <15=> 15
00114 //           <i> If interrupt out endpoint is not used select "Not used"
00115 //         <h> Endpoint Settings
00116 //           <o3.0..7> Maximum Endpoint Packet Size (in bytes) <0-64>
00117 //           <o4.0..7> Endpoint polling Interval (in ms) <1-255>
00118 //           <e5> High-speed
00119 //             <i> If high-speed is enabled set endpoint settings for it
00120 //             <o6.0..10> Maximum Endpoint Packet Size (in bytes) <0-1024>
00121 //             <o6.11..12> Additional transactions per microframe <0=> None <1=> 1 additional <2=> 2 additional
00122 //             <o7.0..7> Endpoint polling Interval (in ms) <1=>      1 <2=>      2 <3=>      4 <4=>      8
00123 //                                                         <5=>     16 <6=>     32 <7=>     64 <8=>    128
00124 //                                                         <9=>    256 <10=>   512 <11=>  1024 <12=>  2048
00125 //                                                         <13=>  4096 <14=>  8192 <15=> 16384 <16=> 32768
00126 //           </e>
00127 //         </h>
00128 //       </h>
00129 //       <h> Human Interface Device Settings
00130 //         <i> Device specific settings
00131 //         <s0.126> HID Interface String
00132 //         <o8.0..4> Number of Input Reports <1-32>
00133 //         <o9.0..4> Number of Output Reports <1-32>
00134 //         <o10.0..15> Maximum Input Report Size (in bytes) <1-65535>
00135 //         <o11.0..15> Maximum Output Report Size (in bytes) <1-65535>
00136 //         <o12.0..15> Maximum Feature Report Size (in bytes) <1-65535>
00137 //       </h>
00138 //     </e>
00139 #ifndef HID_ENDPOINT
00140 #define HID_ENDPOINT 0
00141 #else
00142 #define HID_ENDPOINT 1
00143 #endif
00144 
00145 #ifndef WEBUSB_INTERFACE
00146 #define WEBUSB_INTERFACE 0
00147 #else
00148 #define WEBUSB_INTERFACE 1
00149 #endif
00150 
00151 #define USBD_HID_ENABLE             HID_ENDPOINT
00152 #ifndef BULK_ENDPOINT               //check if bulk endpoint is not enabled
00153 #define USBD_HID_EP_INTIN           1
00154 #define USBD_HID_EP_INTOUT          2
00155 #else                               //if bulk endpoint is enabled remove interrupt endpoints from the hid
00156 #define USBD_HID_EP_INTIN           0
00157 #define USBD_HID_EP_INTOUT          0
00158 #endif
00159 #define USBD_HID_EP_INTIN_STACK     0
00160 #define USBD_HID_WMAXPACKETSIZE     64
00161 #define USBD_HID_BINTERVAL          1
00162 #define USBD_HID_HS_ENABLE          0
00163 #define USBD_HID_HS_WMAXPACKETSIZE  64
00164 #define USBD_HID_HS_BINTERVAL       6
00165 #define USBD_HID_STRDESC            L"CMSIS-DAP v1"
00166 #define USBD_WEBUSB_STRDESC         L"WebUSB: CMSIS-DAP"
00167 #define USBD_HID_INREPORT_NUM       1
00168 #define USBD_HID_OUTREPORT_NUM      1
00169 #define USBD_HID_INREPORT_MAX_SZ    64
00170 #define USBD_HID_OUTREPORT_MAX_SZ   64
00171 #define USBD_HID_FEATREPORT_MAX_SZ  1
00172 
00173 //     <e0.0> Mass Storage Device (MSC)
00174 //       <i> Enable class support for Mass Storage Device (MSC)
00175 //       <h> Bulk Endpoint Settings
00176 //         <o1.0..4> Bulk In Endpoint Number                  <1=>   1 <2=>   2 <3=>   3
00177 //                                            <4=>   4        <5=>   5 <6=>   6 <7=>   7
00178 //                                            <8=>   8        <9=>   9 <10=> 10 <11=> 11
00179 //                                            <12=>  12       <13=> 13 <14=> 14 <15=> 15
00180 //         <o2.0..4> Bulk Out Endpoint Number                 <1=>   1 <2=>   2 <3=>   3
00181 //                                            <4=>   4        <5=>   5 <6=>   6 <7=>   7
00182 //                                            <8=>   8        <9=>   9 <10=> 10 <11=> 11
00183 //                                            <12=>  12       <13=> 13 <14=> 14 <15=> 15
00184 //         <h> Endpoint Settings
00185 //           <o3> Maximum Packet Size <1-1024>
00186 //           <e4> High-speed
00187 //             <i> If high-speed is enabled set endpoint settings for it
00188 //             <o5> Maximum Packet Size <1-1024>
00189 //             <o6> Maximum NAK Rate <0-255>
00190 //           </e>
00191 //         </h>
00192 //       </h>
00193 //       <h> Mass Storage Device Settings
00194 //         <i> Device specific settings
00195 //         <s0.126> MSC Interface String
00196 //         <h> Inquiry Data
00197 //           <s1.8>  Vendor Identification
00198 //           <s2.16> Product Identification
00199 //           <s3.4>  Product Revision Level
00200 //         </h>
00201 //       </h>
00202 //     </e>
00203 #ifndef MSC_ENDPOINT
00204 #define MSC_ENDPOINT 0
00205 #else
00206 #define MSC_ENDPOINT 1
00207 #endif
00208 #define USBD_MSC_ENABLE             MSC_ENDPOINT
00209 #define USBD_MSC_EP_BULKIN          3
00210 #define USBD_MSC_EP_BULKOUT         4
00211 #define USBD_MSC_EP_BULKIN_STACK    0
00212 #define USBD_MSC_WMAXPACKETSIZE     64
00213 #define USBD_MSC_HS_ENABLE          0
00214 #define USBD_MSC_HS_WMAXPACKETSIZE  512
00215 #define USBD_MSC_HS_BINTERVAL       0
00216 #define USBD_MSC_STRDESC            L"USB_MSC"
00217 #define USBD_MSC_INQUIRY_DATA       "MBED    "         \
00218                                     "VFS             " \
00219                                     "0.1"
00220 
00221 //     <e0.0> Audio Device (ADC)
00222 //       <i> Enable class support for Audio Device (ADC)
00223 //       <h> Isochronous Endpoint Settings
00224 //         <o1.0..4> Isochronous Out Endpoint Number                 <1=>   1 <2=>   2 <3=>   3
00225 //                                                   <4=>   4        <5=>   5 <6=>   6 <7=>   7
00226 //                                                   <8=>   8        <9=>   9 <10=> 10 <11=> 11
00227 //                                                   <12=>  12       <13=> 13 <14=> 14 <15=> 15
00228 //         <h> Endpoint Settings
00229 //           <o2.0..10> Maximum Endpoint Packet Size (in bytes) <0-1024>
00230 //           <o3.0..10> Endpoint polling Interval (in ms) <1=>      1 <2=>      2 <3=>      4 <4=>      8
00231 //                                                        <5=>     16 <6=>     32 <7=>     64 <8=>    128
00232 //                                                        <9=>    256 <10=>   512 <11=>  1024 <12=>  2048
00233 //                                                        <13=>  4096 <14=>  8192 <15=> 16384 <16=> 32768
00234 //           <e4> High-speed
00235 //             <i> If high-speed is enabled set endpoint settings for it
00236 //             <o5.0..10> Maximum Endpoint Packet Size (in bytes) <0-1024>
00237 //             <o5.11..12> Additional transactions per microframe <0=> None <1=> 1 additional <2=> 2 additional
00238 //           </e>
00239 //         </h>
00240 //       </h>
00241 //       <h> Audio Device Settings
00242 //         <i> Device specific settings
00243 //         <s0.126> Audio Control Interface String
00244 //         <s1.126> Audio Streaming (Zero Bandwidth) Interface String
00245 //         <s2.126> Audio Streaming (Operational) Interface String
00246 //         <o6.0..7> Audio Subframe Size (in bytes) <0-255>
00247 //         <o7.0..7> Sample Resolution (in bits) <0-255>
00248 //         <o8.0..23> Sample Frequency (in Hz) <0-16777215>
00249 //         <o9> Packet Size (in bytes) <1-256>
00250 //         <o10> Packet Count <1-16>
00251 //       </h>
00252 //     </e>
00253 #define USBD_ADC_ENABLE             0
00254 #define USBD_ADC_EP_ISOOUT          3
00255 #define USBD_ADC_WMAXPACKETSIZE     64
00256 #define USBD_ADC_BINTERVAL          1
00257 #define USBD_ADC_HS_ENABLE          0
00258 #define USBD_ADC_HS_WMAXPACKETSIZE  64
00259 #define USBD_ADC_CIF_STRDESC        L"USB_ADC"
00260 #define USBD_ADC_SIF1_STRDESC       L"USB_ADC1"
00261 #define USBD_ADC_SIF2_STRDESC       L"USB_ADC2"
00262 #define USBD_ADC_BSUBFRAMESIZE      2
00263 #define USBD_ADC_BBITRESOLUTION     16
00264 #define USBD_ADC_TSAMFREQ           32000
00265 #define USBD_ADC_CFG_P_S            32
00266 #define USBD_ADC_CFG_P_C            1
00267 
00268 //     <e0> Communication Device (CDC) - Abstract Control Model (ACM)
00269 //       <i> Enable class support for Communication Device (CDC) - Abstract Control Model (ACM)
00270 //       <h> Interrupt Endpoint Settings
00271 //         <o1.0..4> Interrupt In Endpoint Number                 <1=>   1 <2=>   2 <3=>   3
00272 //                                                <4=>   4        <5=>   5 <6=>   6 <7=>   7
00273 //                                                <8=>   8        <9=>   9 <10=> 10 <11=> 11
00274 //                                                <12=>  12       <13=> 13 <14=> 14 <15=> 15
00275 //         <h> Endpoint Settings
00276 //           <o2.0..10> Maximum Endpoint Packet Size (in bytes) <0-1024>
00277 //           <o3.0..10> Endpoint polling Interval (in ms) <0-255>
00278 //           <e4> High-speed
00279 //             <i> If high-speed is enabled set endpoint settings for it
00280 //             <o5.0..10> Maximum Endpoint Packet Size (in bytes) <0-1024>
00281 //             <o5.11..12> Additional transactions per microframe <0=> None <1=> 1 additional <2=> 2 additional
00282 //             <o6.0..10> Endpoint polling Interval (in ms) <1=>      1 <2=>      2 <3=>      4 <4=>      8
00283 //                                                          <5=>     16 <6=>     32 <7=>     64 <8=>    128
00284 //                                                          <9=>    256 <10=>   512 <11=>  1024 <12=>  2048
00285 //                                                          <13=>  4096 <14=>  8192 <15=> 16384 <16=> 32768
00286 //           </e4>
00287 //         </h>
00288 //       </h>
00289 //       <h> Bulk Endpoint Settings
00290 //         <o7.0..4> Bulk In Endpoint Number                  <1=>   1 <2=>   2 <3=>   3
00291 //                                            <4=>   4        <5=>   5 <6=>   6 <7=>   7
00292 //                                            <8=>   8        <9=>   9 <10=> 10 <11=> 11
00293 //                                            <12=>  12       <13=> 13 <14=> 14 <15=> 15
00294 //         <o8.0..4> Bulk Out Endpoint Number                 <1=>   1 <2=>   2 <3=>   3
00295 //                                            <4=>   4        <5=>   5 <6=>   6 <7=>   7
00296 //                                            <8=>   8        <9=>   9 <10=> 10 <11=> 11
00297 //                                            <12=>  12       <13=> 13 <14=> 14 <15=> 15
00298 //         <h> Endpoint Settings
00299 //           <o9> Maximum Packet Size <1-1024>
00300 //           <e10> High-speed
00301 //             <i> If high-speed is enabled set endpoint settings for it
00302 //             <o11> Maximum Packet Size <1-1024>
00303 //             <o12> Maximum NAK Rate <0-255>
00304 //           </e10>
00305 //         </h>
00306 //       </h>
00307 //       <h> Communication Device Settings
00308 //         <i> Device specific settings
00309 //         <s0.126> Communication Class Interface String
00310 //         <s1.126> Data Class Interface String
00311 //         <o13> Maximum Communication Device Send Buffer Size
00312 //            <8=>     8 Bytes <16=>   16 Bytes <32=>     32 Bytes <64=>  64 Bytes <128=> 128 Bytes
00313 //            <256=> 256 Bytes <512=> 512 Bytes <1024=> 1024 Bytes
00314 //         <o14> Maximum Communication Device Receive Buffer Size
00315 //            <i> Minimum size must be as big as maximum packet size for Bulk Out Endpoint
00316 //            <8=>     8 Bytes <16=>   16 Bytes <32=>     32 Bytes <64=>  64 Bytes <128=> 128 Bytes
00317 //            <256=> 256 Bytes <512=> 512 Bytes <1024=> 1024 Bytes
00318 //       </h>
00319 //     </e>
00320 #ifndef CDC_ENDPOINT
00321 #define CDC_ENDPOINT 0
00322 #else
00323 #define CDC_ENDPOINT 1
00324 #endif
00325 #define USBD_CDC_ACM_ENABLE             CDC_ENDPOINT
00326 #define USBD_CDC_ACM_EP_INTIN           5
00327 #define USBD_CDC_ACM_EP_INTIN_STACK     0
00328 #define USBD_CDC_ACM_WMAXPACKETSIZE     16
00329 #define USBD_CDC_ACM_BINTERVAL          32
00330 #define USBD_CDC_ACM_HS_ENABLE          0
00331 #define USBD_CDC_ACM_HS_WMAXPACKETSIZE  16
00332 #define USBD_CDC_ACM_HS_BINTERVAL       2
00333 #define USBD_CDC_ACM_EP_BULKIN          6
00334 #define USBD_CDC_ACM_EP_BULKOUT         7
00335 #define USBD_CDC_ACM_EP_BULKIN_STACK    0
00336 #define USBD_CDC_ACM_WMAXPACKETSIZE1    64
00337 #define USBD_CDC_ACM_HS_ENABLE1         0
00338 #define USBD_CDC_ACM_HS_WMAXPACKETSIZE1 64
00339 #define USBD_CDC_ACM_HS_BINTERVAL1      0
00340 #define USBD_CDC_ACM_CIF_STRDESC        L"mbed Serial Port"
00341 #define USBD_CDC_ACM_DIF_STRDESC        L"mbed Serial Port"
00342 #define USBD_CDC_ACM_SENDBUF_SIZE       64
00343 #define USBD_CDC_ACM_RECEIVEBUF_SIZE    64
00344 #if (((USBD_CDC_ACM_HS_ENABLE1) && (USBD_CDC_ACM_SENDBUF_SIZE    < USBD_CDC_ACM_HS_WMAXPACKETSIZE1)) || (USBD_CDC_ACM_SENDBUF_SIZE    < USBD_CDC_ACM_WMAXPACKETSIZE1))
00345 #error "Send Buffer size must be larger or equal to Bulk In maximum packet size!"
00346 #endif
00347 #if (((USBD_CDC_ACM_HS_ENABLE1) && (USBD_CDC_ACM_RECEIVEBUF_SIZE < USBD_CDC_ACM_HS_WMAXPACKETSIZE1)) || (USBD_CDC_ACM_RECEIVEBUF_SIZE < USBD_CDC_ACM_WMAXPACKETSIZE1))
00348 #error "Receive Buffer size must be larger or equal to Bulk Out maximum packet size!"
00349 #endif
00350 
00351 //     <e0> Custom Class Device
00352 //       <i> Enables USB Custom Class Requests
00353 //       <i> Class IDs:
00354 //       <i> 0x00 - Class Reserved ID
00355 //       <i> 0x01 - Class Audio ID
00356 //       <i> 0x02 - Class Communications ID
00357 //       <i> 0x03 - Class Human Interface ID
00358 //       <i> 0x04 - Class Monitor ID
00359 //       <i> 0x05 - Class Physical Interface ID
00360 //       <i> 0x06 - Class Power ID
00361 //       <i> 0x07 - Class Printer ID
00362 //       <i> 0x08 - Class Storage ID
00363 //       <i> 0x09 - Class HUB ID
00364 //       <i> 0xEF - Class Miscellaneous ID
00365 //       <i> 0xFF - Class Vendor Specific ID
00366 //     </e>
00367 #define USBD_CLS_ENABLE             0
00368 
00369 //     WebUSB support
00370 #define USBD_WEBUSB_ENABLE          WEBUSB_INTERFACE
00371 #define USBD_WEBUSB_VENDOR_CODE     0x21
00372 #define USBD_WEBUSB_LANDING_URL     "os.mbed.com/webusb/landing-page/?bid="
00373 #define USBD_WEBUSB_ORIGIN_URL      "os.mbed.com/"
00374 
00375 //     Microsoft OS Descriptors 2.0 (WinUSB) support
00376 #define USBD_WINUSB_ENABLE          WINUSB_INTERFACE
00377 #define USBD_WINUSB_VENDOR_CODE     0x20
00378 //   </e>
00379 // </e>
00380 
00381 #ifndef BULK_ENDPOINT
00382 #define BULK_ENDPOINT 0
00383 #else
00384 #define BULK_ENDPOINT 1
00385 #endif
00386 #define USBD_BULK_ENABLE             BULK_ENDPOINT
00387 #define USBD_BULK_EP_BULKIN          1
00388 #define USBD_BULK_EP_BULKOUT         2
00389 #define USBD_BULK_EP_BULKIN_SWO      10
00390 #define USBD_BULK_WMAXPACKETSIZE     64
00391 #define USBD_BULK_HS_ENABLE          0
00392 #define USBD_BULK_HS_WMAXPACKETSIZE  512
00393 #define USBD_BULK_STRDESC            L"CMSIS-DAP v2"
00394 
00395 /* USB Device Calculations ---------------------------------------------------*/
00396 
00397 #define USBD_IF_NUM_MAX             (USBD_BULK_ENABLE+USBD_WEBUSB_ENABLE+USBD_HID_ENABLE+USBD_MSC_ENABLE+(USBD_ADC_ENABLE*2)+(USBD_CDC_ACM_ENABLE*2)+USBD_CLS_ENABLE)
00398 #define USBD_MULTI_IF               (USBD_CDC_ACM_ENABLE*(USBD_HID_ENABLE|USBD_MSC_ENABLE|USBD_ADC_ENABLE|USBD_CLS_ENABLE|USBD_WEBUSB_ENABLE|USBD_BULK_ENABLE))
00399 // #define MAX(x, y)                   (((x) < (y)) ? (y) : (x))
00400 #define USBD_EP_NUM_CALC0           MAX((USBD_HID_ENABLE    *(USBD_HID_EP_INTIN     )), (USBD_HID_ENABLE    *(USBD_HID_EP_INTOUT!=0)*(USBD_HID_EP_INTOUT)))
00401 #define USBD_EP_NUM_CALC1           MAX((USBD_MSC_ENABLE    *(USBD_MSC_EP_BULKIN    )), (USBD_MSC_ENABLE    *(USBD_MSC_EP_BULKOUT)))
00402 #define USBD_EP_NUM_CALC2           MAX((USBD_ADC_ENABLE    *(USBD_ADC_EP_ISOOUT    )), (USBD_CDC_ACM_ENABLE*(USBD_CDC_ACM_EP_INTIN)))
00403 #define USBD_EP_NUM_CALC3           MAX((USBD_CDC_ACM_ENABLE*(USBD_CDC_ACM_EP_BULKIN)), (USBD_CDC_ACM_ENABLE*(USBD_CDC_ACM_EP_BULKOUT)))
00404 #define USBD_EP_NUM_CALC4           MAX(USBD_EP_NUM_CALC0, USBD_EP_NUM_CALC1)
00405 #define USBD_EP_NUM_CALC5           MAX(USBD_EP_NUM_CALC2, USBD_EP_NUM_CALC3)
00406 #define USBD_EP_NUM_CALC6           MAX(USBD_EP_NUM_CALC4, USBD_EP_NUM_CALC5)
00407 #define USBD_EP_NUM_CALC7           MAX((USBD_BULK_ENABLE*(USBD_BULK_EP_BULKIN)), (USBD_BULK_ENABLE*(USBD_BULK_EP_BULKOUT)))
00408 #define USBD_EP_NUM                 MAX(USBD_EP_NUM_CALC6, USBD_EP_NUM_CALC7)
00409 
00410 #if (USBD_EP_NUM > 7)
00411 #error "Max32620 only have 8 individual endpoints including EP0!"
00412 #endif
00413 
00414 #if    (USBD_HID_ENABLE)
00415 #if    (USBD_MSC_ENABLE)
00416 #if ((((USBD_HID_EP_INTIN   == USBD_MSC_EP_BULKIN)  || \
00417        (USBD_HID_EP_INTIN   == USBD_MSC_EP_BULKOUT)))   || \
00418       ((USBD_HID_EP_INTOUT  != 0)                   && \
00419        (USBD_HID_EP_INTOUT  == USBD_MSC_EP_BULKIN)  || \
00420        (USBD_HID_EP_INTOUT  == USBD_MSC_EP_BULKOUT)))
00421 #error "HID and Mass Storage Device Interface can not use same Endpoints!"
00422 #endif
00423 #endif
00424 #if    (USBD_ADC_ENABLE)
00425 #if   ((USBD_HID_EP_INTIN   == USBD_ADC_EP_ISOOUT)  || \
00426       ((USBD_HID_EP_INTOUT  != 0)                   && \
00427        (USBD_HID_EP_INTOUT  == USBD_ADC_EP_ISOOUT)))
00428 #error "HID and Audio Device Interface can not use same Endpoints!"
00429 #endif
00430 #endif
00431 #if    (USBD_CDC_ACM_ENABLE)
00432 #if  (((USBD_HID_EP_INTIN   == USBD_CDC_ACM_EP_INTIN)   || \
00433        (USBD_HID_EP_INTIN   == USBD_CDC_ACM_EP_BULKIN)  || \
00434        (USBD_HID_EP_INTIN   == USBD_CDC_ACM_EP_BULKOUT))|| \
00435       ((USBD_HID_EP_INTOUT  != 0)                       && \
00436       ((USBD_HID_EP_INTOUT  == USBD_CDC_ACM_EP_INTIN)   || \
00437        (USBD_HID_EP_INTOUT  == USBD_CDC_ACM_EP_BULKIN)  || \
00438        (USBD_HID_EP_INTOUT  == USBD_CDC_ACM_EP_BULKOUT))))
00439 #error "HID and Communication Device Interface can not use same Endpoints!"
00440 #endif
00441 #endif
00442 #endif
00443 
00444 #if    (USBD_MSC_ENABLE)
00445 #if    (USBD_ADC_ENABLE)
00446 #if   ((USBD_MSC_EP_BULKIN  == USBD_ADC_EP_ISOOUT)  || \
00447        (USBD_MSC_EP_BULKOUT == USBD_ADC_EP_ISOOUT))
00448 #error "Mass Storage Device and Audio Device Interface can not use same Endpoints!"
00449 #endif
00450 #endif
00451 #if    (USBD_CDC_ACM_ENABLE)
00452 #if   ((USBD_MSC_EP_BULKIN  == USBD_CDC_ACM_EP_INTIN)   || \
00453        (USBD_MSC_EP_BULKIN  == USBD_CDC_ACM_EP_BULKIN)  || \
00454        (USBD_MSC_EP_BULKIN  == USBD_CDC_ACM_EP_BULKOUT) || \
00455        (USBD_MSC_EP_BULKOUT == USBD_CDC_ACM_EP_INTIN)   || \
00456        (USBD_MSC_EP_BULKOUT == USBD_CDC_ACM_EP_BULKIN)  || \
00457        (USBD_MSC_EP_BULKOUT == USBD_CDC_ACM_EP_BULKOUT))
00458 #error "Mass Storage Device and Communication Device Interface can not use same Endpoints!"
00459 #endif
00460 #endif
00461 #endif
00462 
00463 #if    (USBD_ADC_ENABLE)
00464 #if    (USBD_CDC_ACM_ENABLE)
00465 #if   ((USBD_ADC_EP_ISOOUT  == USBD_CDC_ACM_EP_INTIN)   || \
00466        (USBD_ADC_EP_ISOOUT  == USBD_CDC_ACM_EP_BULKIN)  || \
00467        (USBD_ADC_EP_ISOOUT  == USBD_CDC_ACM_EP_BULKOUT))
00468 #error "Audio Device and Communication Device Interface can not use same Endpoints!"
00469 #endif
00470 #endif
00471 #endif
00472 #define USBD_ADC_CIF_NUM           (0)
00473 #define USBD_ADC_SIF1_NUM          (1)
00474 #define USBD_ADC_SIF2_NUM          (2)
00475 
00476 
00477 #define USBD_ADC_CIF_STR_NUM       (3+USBD_STRDESC_SER_ENABLE+0)
00478 #define USBD_ADC_SIF1_STR_NUM      (3+USBD_STRDESC_SER_ENABLE+1)
00479 #define USBD_ADC_SIF2_STR_NUM      (3+USBD_STRDESC_SER_ENABLE+2)
00480 #define USBD_CDC_ACM_CIF_STR_NUM   (3+USBD_STRDESC_SER_ENABLE+USBD_ADC_ENABLE*3+0)
00481 #define USBD_CDC_ACM_DIF_STR_NUM   (3+USBD_STRDESC_SER_ENABLE+USBD_ADC_ENABLE*3+1)
00482 #define USBD_HID_IF_STR_NUM        (3+USBD_STRDESC_SER_ENABLE+USBD_ADC_ENABLE*3+USBD_CDC_ACM_ENABLE*2)
00483 #define USBD_WEBUSB_IF_STR_NUM     (3+USBD_STRDESC_SER_ENABLE+USBD_ADC_ENABLE*3+USBD_CDC_ACM_ENABLE*2+USBD_HID_ENABLE)
00484 #define USBD_MSC_IF_STR_NUM        (3+USBD_STRDESC_SER_ENABLE+USBD_ADC_ENABLE*3+USBD_CDC_ACM_ENABLE*2+USBD_HID_ENABLE+USBD_WEBUSB_ENABLE)
00485 #define USBD_BULK_IF_STR_NUM       (3+USBD_STRDESC_SER_ENABLE+USBD_ADC_ENABLE*3+USBD_CDC_ACM_ENABLE*2+USBD_HID_ENABLE+USBD_WEBUSB_ENABLE+USBD_BULK_ENABLE)
00486 
00487 #if    (USBD_HID_ENABLE)
00488 #if    (USBD_HID_HS_ENABLE)
00489 #define USBD_HID_MAX_PACKET       ((USBD_HID_HS_WMAXPACKETSIZE > USBD_HID_WMAXPACKETSIZE) ? USBD_HID_HS_WMAXPACKETSIZE : USBD_HID_WMAXPACKETSIZE)
00490 #else
00491 #define USBD_HID_MAX_PACKET        (USBD_HID_WMAXPACKETSIZE)
00492 #endif
00493 #else
00494 #define USBD_HID_MAX_PACKET        (0)
00495 #endif
00496 #if    (USBD_MSC_ENABLE)
00497 #if    (USBD_MSC_HS_ENABLE)
00498 #define USBD_MSC_MAX_PACKET       ((USBD_MSC_HS_WMAXPACKETSIZE > USBD_MSC_WMAXPACKETSIZE) ? USBD_MSC_HS_WMAXPACKETSIZE : USBD_MSC_WMAXPACKETSIZE)
00499 #else
00500 #define USBD_MSC_MAX_PACKET        (USBD_MSC_WMAXPACKETSIZE)
00501 #endif
00502 #else
00503 #define USBD_MSC_MAX_PACKET        (0)
00504 #endif
00505 #if    (USBD_ADC_ENABLE)
00506 #if    (USBD_ADC_HS_ENABLE)
00507 #define USBD_ADC_MAX_PACKET       ((USBD_ADC_HS_WMAXPACKETSIZE > USBD_ADC_WMAXPACKETSIZE) ? USBD_ADC_HS_WMAXPACKETSIZE : USBD_ADC_WMAXPACKETSIZE)
00508 #else
00509 #define USBD_ADC_MAX_PACKET        (USBD_ADC_WMAXPACKETSIZE)
00510 #endif
00511 #else
00512 #define USBD_ADC_MAX_PACKET        (0)
00513 #endif
00514 #if    (USBD_CDC_ACM_ENABLE)
00515 #if    (USBD_CDC_ACM_HS_ENABLE)
00516 #define USBD_CDC_ACM_MAX_PACKET   ((USBD_CDC_ACM_HS_WMAXPACKETSIZE > USBD_CDC_ACM_WMAXPACKETSIZE) ? USBD_CDC_ACM_HS_WMAXPACKETSIZE : USBD_CDC_ACM_WMAXPACKETSIZE)
00517 #else
00518 #define USBD_CDC_ACM_MAX_PACKET    (USBD_CDC_ACM_WMAXPACKETSIZE)
00519 #endif
00520 #if    (USBD_CDC_ACM_HS_ENABLE1)
00521 #define USBD_CDC_ACM_MAX_PACKET1  ((USBD_CDC_ACM_HS_WMAXPACKETSIZE1 > USBD_CDC_ACM_WMAXPACKETSIZE1) ? USBD_CDC_ACM_HS_WMAXPACKETSIZE1 : USBD_CDC_ACM_WMAXPACKETSIZE1)
00522 #else
00523 #define USBD_CDC_ACM_MAX_PACKET1   (USBD_CDC_ACM_WMAXPACKETSIZE1)
00524 #endif
00525 #else
00526 #define USBD_CDC_ACM_MAX_PACKET    (0)
00527 #define USBD_CDC_ACM_MAX_PACKET1   (0)
00528 #endif
00529 
00530 #if    (USBD_BULK_ENABLE)
00531 #if    (USBD_BULK_HS_ENABLE)
00532 #define USBD_BULK_MAX_PACKET       ((USBD_BULK_HS_WMAXPACKETSIZE > USBD_BULK_WMAXPACKETSIZE) ? USBD_BULK_HS_WMAXPACKETSIZE : USBD_BULK_WMAXPACKETSIZE)
00533 #else
00534 #define USBD_BULK_MAX_PACKET        (USBD_BULK_WMAXPACKETSIZE)
00535 #endif
00536 #else
00537 #define USBD_BULK_MAX_PACKET        (0)
00538 #endif
00539 
00540 #define USBD_MAX_PACKET_CALC0     ((USBD_HID_MAX_PACKET   > USBD_HID_MAX_PACKET      ) ? (USBD_HID_MAX_PACKET  ) : (USBD_HID_MAX_PACKET      ))
00541 #define USBD_MAX_PACKET_CALC1     ((USBD_ADC_MAX_PACKET   > USBD_CDC_ACM_MAX_PACKET  ) ? (USBD_ADC_MAX_PACKET  ) : (USBD_CDC_ACM_MAX_PACKET  ))
00542 #define USBD_MAX_PACKET_CALC2     ((USBD_MAX_PACKET_CALC0 > USBD_MAX_PACKET_CALC1    ) ? (USBD_MAX_PACKET_CALC0) : (USBD_MAX_PACKET_CALC1    ))
00543 #define USBD_MAX_PACKET_CALC3     ((USBD_BULK_MAX_PACKET > USBD_CDC_ACM_MAX_PACKET1 ) ? (USBD_BULK_MAX_PACKET) : (USBD_CDC_ACM_MAX_PACKET1 ))
00544 #define USBD_MAX_PACKET           ((USBD_MAX_PACKET_CALC3 > USBD_MAX_PACKET_CALC2    ) ? (USBD_MAX_PACKET_CALC3) : (USBD_MAX_PACKET_CALC2    ))
00545 
00546 
00547 /*------------------------------------------------------------------------------
00548  *      USB Config Functions
00549  *----------------------------------------------------------------------------*/
00550 
00551 #ifndef  __USB_CONFIG___
00552 #define  __USB_CONFIG__
00553 
00554 #ifndef  __NO_USB_LIB_C
00555 #include "usb_lib.c"
00556 #endif
00557 
00558 #endif  /* __USB_CONFIG__ */