00001 /* Name: usbconfig.h 00002 * Project: AVR USB driver 00003 * Author: Christian Starkjohann 00004 * Creation Date: 2005-04-01 00005 * Tabsize: 4 00006 * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH 00007 * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt) 00008 * This Revision: $Id: usbconfig-prototype.h 555 2008-04-17 19:25:20Z cs $ 00009 */ 00010 00011 #ifndef __usbconfig_h_included__ 00012 #define __usbconfig_h_included__ 00013 00014 /* 00015 General Description: 00016 This file is an example configuration (with inline documentation) for the USB 00017 driver. It configures AVR-USB for USB D+ connected to Port D bit 2 (which is 00018 also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may 00019 wire the lines to any other port, as long as D+ is also wired to INT0 (or any 00020 other hardware interrupt, as long as it is the highest level interrupt, see 00021 section at the end of this file). 00022 + To create your own usbconfig.h file, copy this file to your project's 00023 + firmware source directory) and rename it to "usbconfig.h". 00024 + Then edit it accordingly. 00025 */ 00026 00027 /* ---------------------------- Hardware Config ---------------------------- */ 00028 00029 #define USB_CFG_IOPORTNAME D 00030 /* This is the port where the USB bus is connected. When you configure it to 00031 * "B", the registers PORTB, PINB and DDRB will be used. 00032 */ 00033 #define USB_CFG_DMINUS_BIT 4 00034 /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. 00035 * This may be any bit in the port. 00036 */ 00037 #define USB_CFG_DPLUS_BIT 2 00038 /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. 00039 * This may be any bit in the port. Please note that D+ must also be connected 00040 * to interrupt pin INT0! [You can also use other interrupts, see section 00041 * "Optional MCU Description" below, or you can connect D- to the interrupt, as 00042 * it is required if you use the USB_COUNT_SOF feature. If you use D- for the 00043 * interrupt, the USB interrupt will also be triggered at Start-Of-Frame 00044 * markers every millisecond.] 00045 */ 00046 #define USB_CFG_CLOCK_KHZ (F_CPU/1000) 00047 /* Clock rate of the AVR in MHz. Legal values are 12000, 15000, 16000 or 16500. 00048 * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1% 00049 * deviation from the nominal frequency. All other rates require a precision 00050 * of 2000 ppm and thus a crystal! 00051 * Default if not specified: 12 MHz 00052 */ 00053 00054 /* ----------------------- Optional Hardware Config ------------------------ */ 00055 00056 /* #define USB_CFG_PULLUP_IOPORTNAME D */ 00057 /* If you connect the 1.5k pullup resistor from D- to a port pin instead of 00058 * V+, you can connect and disconnect the device from firmware by calling 00059 * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). 00060 * This constant defines the port on which the pullup resistor is connected. 00061 */ 00062 /* #define USB_CFG_PULLUP_BIT 4 */ 00063 /* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined 00064 * above) where the 1.5k pullup resistor is connected. See description 00065 * above for details. 00066 */ 00067 00068 /* --------------------------- Functional Range ---------------------------- */ 00069 00070 #define USB_CFG_HAVE_INTRIN_ENDPOINT 0 00071 /* Define this to 1 if you want to compile a version with two endpoints: The 00072 * default control endpoint 0 and an interrupt-in endpoint (any other endpoint 00073 * number). 00074 */ 00075 #define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 00076 /* Define this to 1 if you want to compile a version with three endpoints: The 00077 * default control endpoint 0, an interrupt-in endpoint 3 (or the number 00078 * configured below) and a catch-all default interrupt-in endpoint as above. 00079 * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. 00080 */ 00081 #define USB_CFG_EP3_NUMBER 3 00082 /* If the so-called endpoint 3 is used, it can now be configured to any other 00083 * endpoint number (except 0) with this macro. Default if undefined is 3. 00084 */ 00085 /* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ 00086 /* The above macro defines the startup condition for data toggling on the 00087 * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. 00088 * Since the token is toggled BEFORE sending any data, the first packet is 00089 * sent with the oposite value of this configuration! 00090 */ 00091 #define USB_CFG_IMPLEMENT_HALT 0 00092 /* Define this to 1 if you also want to implement the ENDPOINT_HALT feature 00093 * for endpoint 1 (interrupt endpoint). Although you may not need this feature, 00094 * it is required by the standard. We have made it a config option because it 00095 * bloats the code considerably. 00096 */ 00097 #define USB_CFG_INTR_POLL_INTERVAL 10 00098 /* If you compile a version with endpoint 1 (interrupt-in), this is the poll 00099 * interval. The value is in milliseconds and must not be less than 10 ms for 00100 * low speed devices. 00101 */ 00102 #define USB_CFG_IS_SELF_POWERED 0 00103 /* Define this to 1 if the device has its own power supply. Set it to 0 if the 00104 * device is powered from the USB bus. 00105 */ 00106 #define USB_CFG_MAX_BUS_POWER 100 00107 /* Set this variable to the maximum USB bus power consumption of your device. 00108 * The value is in milliamperes. [It will be divided by two since USB 00109 * communicates power requirements in units of 2 mA.] 00110 */ 00111 #define USB_CFG_IMPLEMENT_FN_WRITE 0 00112 /* Set this to 1 if you want usbFunctionWrite() to be called for control-out 00113 * transfers. Set it to 0 if you don't need it and want to save a couple of 00114 * bytes. 00115 */ 00116 #define USB_CFG_IMPLEMENT_FN_READ 0 00117 /* Set this to 1 if you need to send control replies which are generated 00118 * "on the fly" when usbFunctionRead() is called. If you only want to send 00119 * data from a static buffer, set it to 0 and return the data from 00120 * usbFunctionSetup(). This saves a couple of bytes. 00121 */ 00122 #define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 00123 /* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. 00124 * You must implement the function usbFunctionWriteOut() which receives all 00125 * interrupt/bulk data sent to any endpoint other than 0. The endpoint number 00126 * can be found in 'usbRxToken'. 00127 */ 00128 #define USB_CFG_HAVE_FLOWCONTROL 0 00129 /* Define this to 1 if you want flowcontrol over USB data. See the definition 00130 * of the macros usbDisableAllRequests() and usbEnableAllRequests() in 00131 * usbdrv.h. 00132 */ 00133 /* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */ 00134 /* This macro is a hook if you want to do unconventional things. If it is 00135 * defined, it's inserted at the beginning of received message processing. 00136 * If you eat the received message and don't want default processing to 00137 * proceed, do a return after doing your things. One possible application 00138 * (besides debugging) is to flash a status LED on each packet. 00139 */ 00140 /* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */ 00141 /* This macro is a hook if you need to know when an USB RESET occurs. It has 00142 * one parameter which distinguishes between the start of RESET state and its 00143 * end. 00144 */ 00145 /* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */ 00146 /* This macro (if defined) is executed when a USB SET_ADDRESS request was 00147 * received. 00148 */ 00149 #define USB_COUNT_SOF 0 00150 /* define this macro to 1 if you need the global variable "usbSofCount" which 00151 * counts SOF packets. This feature requires that the hardware interrupt is 00152 * connected to D- instead of D+. 00153 */ 00154 #define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0 00155 /* define this macro to 1 if you want the function usbMeasureFrameLength() 00156 * compiled in. This function can be used to calibrate the AVR's RC oscillator. 00157 */ 00158 00159 /* -------------------------- Device Description --------------------------- */ 00160 00161 #define USB_CFG_VENDOR_ID 0xc0, 0x16 00162 /* USB vendor ID for the device, low byte first. If you have registered your 00163 * own Vendor ID, define it here. Otherwise you use one of obdev's free shared 00164 * VID/PID pairs. Be sure to read USBID-License.txt for rules! 00165 * + This template uses obdev's shared VID/PID pair: 0x16c0/0x5dc. 00166 * + Use this VID/PID pair ONLY if you understand the implications! 00167 */ 00168 #define USB_CFG_DEVICE_ID 0xdc, 0x05 00169 /* This is the ID of the product, low byte first. It is interpreted in the 00170 * scope of the vendor ID. If you have registered your own VID with usb.org 00171 * or if you have licensed a PID from somebody else, define it here. Otherwise 00172 * you use obdev's free shared VID/PID pair. Be sure to read the rules in 00173 * USBID-License.txt! 00174 * + This template uses obdev's shared VID/PID pair: 0x16c0/0x5dc. 00175 * + Use this VID/PID pair ONLY if you understand the implications! 00176 */ 00177 #define USB_CFG_DEVICE_VERSION 0x00, 0x01 00178 /* Version number of the device: Minor number first, then major number. 00179 */ 00180 #define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't' 00181 #define USB_CFG_VENDOR_NAME_LEN 8 00182 /* These two values define the vendor name returned by the USB device. The name 00183 * must be given as a list of characters under single quotes. The characters 00184 * are interpreted as Unicode (UTF-16) entities. 00185 * If you don't want a vendor name string, undefine these macros. 00186 * ALWAYS define a vendor name containing your Internet domain name if you use 00187 * obdev's free shared VID/PID pair. See the file USBID-License.txt for 00188 * details. 00189 */ 00190 #define USB_CFG_DEVICE_NAME 'T', 'e', 'm', 'p', 'l', 'a', 't', 'e' 00191 #define USB_CFG_DEVICE_NAME_LEN 8 00192 /* Same as above for the device name. If you don't want a device name, undefine 00193 * the macros. See the file USBID-License.txt before you assign a name if you 00194 * use a shared VID/PID. 00195 */ 00196 /*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */ 00197 /*#define USB_CFG_SERIAL_NUMBER_LEN 0 */ 00198 /* Same as above for the serial number. If you don't want a serial number, 00199 * undefine the macros. 00200 * It may be useful to provide the serial number through other means than at 00201 * compile time. See the section about descriptor properties below for how 00202 * to fine tune control over USB descriptors such as the string descriptor 00203 * for the serial number. 00204 */ 00205 #define USB_CFG_DEVICE_CLASS 0xff /* set to 0 if deferred to interface */ 00206 #define USB_CFG_DEVICE_SUBCLASS 0 00207 /* See USB specification if you want to conform to an existing device class. 00208 * Class 0xff is "vendor specific". 00209 */ 00210 #define USB_CFG_INTERFACE_CLASS 0 /* define class here if not at device level */ 00211 #define USB_CFG_INTERFACE_SUBCLASS 0 00212 #define USB_CFG_INTERFACE_PROTOCOL 0 00213 /* See USB specification if you want to conform to an existing device class or 00214 * protocol. The following classes must be set at interface level: 00215 * HID class is 3, no subclass and protocol required (but may be useful!) 00216 * CDC class is 2, use subclass 2 and protocol 1 for ACM 00217 */ 00218 /* #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 42 */ 00219 /* Define this to the length of the HID report descriptor, if you implement 00220 * an HID device. Otherwise don't define it or define it to 0. 00221 * If you use this define, you must add a PROGMEM character array named 00222 * "usbHidReportDescriptor" to your code which contains the report descriptor. 00223 * Don't forget to keep the array and this define in sync! 00224 */ 00225 00226 /* #define USB_PUBLIC static */ 00227 /* Use the define above if you #include usbdrv.c instead of linking against it. 00228 * This technique saves a couple of bytes in flash memory. 00229 */ 00230 00231 /* ------------------- Fine Control over USB Descriptors ------------------- */ 00232 /* If you don't want to use the driver's default USB descriptors, you can 00233 * provide our own. These can be provided as (1) fixed length static data in 00234 * flash memory, (2) fixed length static data in RAM or (3) dynamically at 00235 * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more 00236 * information about this function. 00237 * Descriptor handling is configured through the descriptor's properties. If 00238 * no properties are defined or if they are 0, the default descriptor is used. 00239 * Possible properties are: 00240 * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched 00241 * at runtime via usbFunctionDescriptor(). 00242 * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found 00243 * in static memory is in RAM, not in flash memory. 00244 * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), 00245 * the driver must know the descriptor's length. The descriptor itself is 00246 * found at the address of a well known identifier (see below). 00247 * List of static descriptor names (must be declared PROGMEM if in flash): 00248 * char usbDescriptorDevice[]; 00249 * char usbDescriptorConfiguration[]; 00250 * char usbDescriptorHidReport[]; 00251 * char usbDescriptorString0[]; 00252 * int usbDescriptorStringVendor[]; 00253 * int usbDescriptorStringDevice[]; 00254 * int usbDescriptorStringSerialNumber[]; 00255 * Other descriptors can't be provided statically, they must be provided 00256 * dynamically at runtime. 00257 * 00258 * Descriptor properties are or-ed or added together, e.g.: 00259 * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) 00260 * 00261 * The following descriptors are defined: 00262 * USB_CFG_DESCR_PROPS_DEVICE 00263 * USB_CFG_DESCR_PROPS_CONFIGURATION 00264 * USB_CFG_DESCR_PROPS_STRINGS 00265 * USB_CFG_DESCR_PROPS_STRING_0 00266 * USB_CFG_DESCR_PROPS_STRING_VENDOR 00267 * USB_CFG_DESCR_PROPS_STRING_PRODUCT 00268 * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 00269 * USB_CFG_DESCR_PROPS_HID 00270 * USB_CFG_DESCR_PROPS_HID_REPORT 00271 * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver) 00272 * 00273 */ 00274 00275 #define USB_CFG_DESCR_PROPS_DEVICE 0 00276 #define USB_CFG_DESCR_PROPS_CONFIGURATION 0 00277 #define USB_CFG_DESCR_PROPS_STRINGS 0 00278 #define USB_CFG_DESCR_PROPS_STRING_0 0 00279 #define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 00280 #define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 00281 #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 00282 #define USB_CFG_DESCR_PROPS_HID 0 00283 #define USB_CFG_DESCR_PROPS_HID_REPORT 0 00284 #define USB_CFG_DESCR_PROPS_UNKNOWN 0 00285 00286 /* ----------------------- Optional MCU Description ------------------------ */ 00287 00288 /* The following configurations have working defaults in usbdrv.h. You 00289 * usually don't need to set them explicitly. Only if you want to run 00290 * the driver on a device which is not yet supported or with a compiler 00291 * which is not fully supported (such as IAR C) or if you use a differnt 00292 * interrupt than INT0, you may have to define some of these. 00293 */ 00294 /* #define USB_INTR_CFG MCUCR */ 00295 /* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */ 00296 /* #define USB_INTR_CFG_CLR 0 */ 00297 /* #define USB_INTR_ENABLE GIMSK */ 00298 /* #define USB_INTR_ENABLE_BIT INT0 */ 00299 /* #define USB_INTR_PENDING GIFR */ 00300 /* #define USB_INTR_PENDING_BIT INTF0 */ 00301 /* #define USB_INTR_VECTOR SIG_INTERRUPT0 */ 00302 00303 #endif /* __usbconfig_h_included__ */