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