├── .gitignore
├── Makefile
├── README.md
├── Readme.txt
├── circuits
├── Readme.txt
├── tiny45-rc.sch
├── with-series-diodes.sch
├── with-vreg.sch
└── with-zener.sch
├── examples
├── Readme.txt
├── custom-class
│ ├── Readme.txt
│ ├── commandline
│ │ └── set-led.c
│ ├── firmware
│ │ ├── Makefile
│ │ ├── main.c
│ │ └── requests.h
│ └── make-files.sh
├── drivertest
│ ├── commandline
│ │ └── runtest.c
│ ├── firmware
│ │ ├── Makefile
│ │ ├── main.c
│ │ ├── requests.h
│ │ └── usbconfig.h
│ └── make-files.sh
├── hid-custom-rq
│ ├── Readme.txt
│ ├── firmware
│ │ ├── main.c
│ │ └── requests.h
│ └── make-files.sh
├── hid-data
│ ├── Readme.txt
│ ├── commandline
│ │ ├── Makefile
│ │ ├── Makefile.windows
│ │ └── hidtool.c
│ ├── firmware
│ │ └── main.c
│ └── make-files.sh
├── hid-mouse
│ ├── Readme.txt
│ ├── firmware
│ │ └── main.c
│ └── make-files.sh
└── usbtool
│ ├── Makefile
│ ├── Makefile.windows
│ ├── Readme.txt
│ ├── make-files.sh
│ └── usbtool.c
├── libs-device
├── Readme.txt
├── osccal.c
├── osccal.h
└── osctune.h
├── libs-host
├── Readme.txt
├── hiddata.c
├── hiddata.h
├── hidsdi.h
├── opendevice.c
└── opendevice.h
├── mkdist.sh
├── tests
├── Makefile
├── Readme.txt
├── compare-sizes.awk
├── main.c
├── null.c
├── sizes-reference
│ ├── sizes-20080418-gcc3.4.6.txt
│ ├── sizes-20080418-gcc4.2.2.txt
│ ├── sizes-20080513-gcc3.4.6.txt
│ ├── sizes-20080513-gcc4.3.0.txt
│ ├── sizes-20081022-gcc3.4.6.txt
│ ├── sizes-20081022-gcc4.3.0.txt
│ ├── sizes-20081126-gcc3.4.6.txt
│ ├── sizes-20081126-gcc4.3.0.txt
│ ├── sizes-20090323-gcc3.4.6.txt
│ ├── sizes-20090323-gcc4.3.2.txt
│ ├── sizes-20090415-gcc3.4.6.txt
│ ├── sizes-20090415-gcc4.3.2.txt
│ ├── sizes-20100715-gcc3.4.6.txt
│ ├── sizes-20100715-gcc4.3.3.txt
│ ├── sizes-20120109-gcc3.4.6.txt
│ ├── sizes-20120109-gcc4.3.3.txt
│ └── sizes-20121206-gcc4.6.2.txt
└── usbconfig.h
├── usbdrv
├── Changelog.txt
├── CommercialLicense.txt
├── License.txt
├── Readme.txt
├── USB-ID-FAQ.txt
├── USB-IDs-for-free.txt
├── asmcommon.inc
├── oddebug.c
├── oddebug.h
├── usbconfig-prototype.h
├── usbdrv.c
├── usbdrv.h
├── usbdrvasm.S
├── usbdrvasm.asm
├── usbdrvasm12.inc
├── usbdrvasm128.inc
├── usbdrvasm15.inc
├── usbdrvasm16.inc
├── usbdrvasm165.inc
├── usbdrvasm18-crc.inc
├── usbdrvasm18.inc
├── usbdrvasm20.inc
└── usbportability.h
└── v-usb.xcodeproj
├── project.pbxproj
└── project.xcworkspace
└── contents.xcworkspacedata
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | ._*
3 | *.o
4 | *.elf
5 | *.hex
6 | *.exe
7 | /*.xcodeproj/project.xcworkspace/xcuserdata
8 | examples/*/*/Makefile*
9 | examples/*/*/opendevice.*
10 | examples/*/opendevice.*
11 | examples/*/firmware/usbdrv
12 | examples/*/firmware/usbconfig.h
13 | examples/*/firmware/osccal.*
14 | examples/*/commandline/hiddata.*
15 | examples/*/commandline/hidsdi.h
16 | examples/hid-custom-rq/commandline
17 | examples/custom-class/commandline/set-led
18 | examples/drivertest/commandline/runtest
19 | examples/hid-data/commandline/hidtool
20 | examples/usbtool/usbtool
21 | tests/sizes.txt
22 | tests/usbdrv
23 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # Name: Makefile
2 | # Project: v-usb
3 | # Author: Christian Starkjohann
4 | # Creation Date: 2012-12-05
5 | # Tabsize: 4
6 | # Copyright: (c) 2012 by OBJECTIVE DEVELOPMENT Software GmbH
7 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 |
9 | # This is the main Makefile. The two primary targets are "all", to build
10 | # everything which can be built (except tests), and "clean" to remove all
11 | # dependent files. In a repository clone, derived source files are generated
12 | # and deleted as well.
13 | #
14 | # We distinguish between repository clones and source packages by the existence
15 | # of make-files.sh scripts in various subdirectories.
16 |
17 |
18 | all:
19 | if [ ! -f examples/hid-mouse/firmware/Makefile ]; then \
20 | $(MAKE) files; \
21 | fi
22 | if [ -n "$(uname -s | grep -i mingw)" ]; then \
23 | $(MAKE) windows; \
24 | else \
25 | $(MAKE) unix; \
26 | fi
27 |
28 | clean:
29 | $(MAKE) unixclean
30 | if cross-make.sh --help >/dev/null 2>&1; then \
31 | $(MAKE) windowsclean; \
32 | fi
33 | $(MAKE) filesremove
34 |
35 |
36 | unix unixclean:
37 | target=$$(echo $@ | sed -e 's/unix//g'); \
38 | find . -mindepth 3 -name Makefile -print | while read i; do \
39 | dir=$$(dirname $$i); \
40 | dirname=$$(basename $$dir); \
41 | pushd $$dir >/dev/null; \
42 | if [ "$$dirname" = firmware -a -z "$$target" ]; then \
43 | if ! $(MAKE) hex; then break; fi; \
44 | else \
45 | if ! $(MAKE) $$target; then break; fi;\
46 | fi; \
47 | popd >/dev/null; \
48 | done
49 |
50 |
51 | windows windowsclean:
52 | target=$$(echo $@ | sed -e 's/windows//g'); \
53 | find . -mindepth 3 -name Makefile.windows -execdir cross-make.sh $$target \; ; \
54 | if [ -z "$$target" ]; then target=hex; fi; \
55 | find . -mindepth 2 -name firmware -exec sh -c "cd '{}'; $(MAKE) $$target" \;
56 |
57 | files filesremove:
58 | target=$$(echo $@ | sed -e 's/files//g'); \
59 | find . -mindepth 2 -name make-files.sh -execdir ./make-files.sh $$target \;
60 |
61 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | What is V-USB?
2 | ==============
3 | V-USB is a firmware-only USB driver for Atmel's AVR microcontrollers.
4 | For more information please visit .
5 |
6 | What is in this Repository?
7 | ===========================
8 | This repository contains the source code of the driver (in the usbdrv
9 | subdirectory), examples (in the examples) subdirectory and other things
10 | you might need when you design a device using V-USB.
11 |
12 | When you check out this repository, the resulting directory is *not* equivalent
13 | to the source code package which can be downloaded at
14 | . Some files in the source code package are generated
15 | by scripts when the package is created. On the other hand, the scripts which
16 | generate source files and the package are not contained in the package itself.
17 |
18 | If you want to know more about the files and directories, see the file
19 | Readme.txt in the top level directory.
20 |
21 | How do I Add the Driver to My Project?
22 | ======================================
23 | Simply copy the entire usbdrv subdirectory into your project's firmware
24 | source code directory. Then edit the firmware's Makefile and add the following
25 | object files to your binary:
26 |
27 | usbdrv/usbdrv.o
28 | usbdrv/usbdrvasm.o
29 | usbdrv/oddebug.o
30 |
31 | Then make sure that your Makefile contains rules to convert *.S and *.c to
32 | object files. See the Makefiles in the examples subdirectory for an
33 | inspiration.
34 |
--------------------------------------------------------------------------------
/Readme.txt:
--------------------------------------------------------------------------------
1 | This is the Readme file for V-USB and related code. V-USB is Objective
2 | Development's firmware-only USB driver for Atmel's(r) AVR(r) microcontrollers.
3 | For more information please visit http://www.obdev.at/vusb/.
4 |
5 | To avoid name confusion: This project was formerly known as AVR-USB. Due to
6 | a trademark issue, it was renamed to V-USB in April 2009.
7 |
8 |
9 | WHAT IS INCLUDED IN THIS PACKAGE?
10 | =================================
11 | This package consists of the device side USB driver firmware, library code
12 | for device and host and fully working examples for device and host:
13 |
14 | Readme.txt .............. The file you are currently reading.
15 | usbdrv .................. V-USB firmware, to be included in your project.
16 | examples ................ Example code for device and host side.
17 | libs-device ............. Useful code snippets for the device firmware.
18 | libs-host ............... Useful code snippets for host-side drivers.
19 | circuits ................ Example circuits using this driver.
20 | Changelog.txt ........... Documentation of changes between versions.
21 | License.txt ............. Free Open Source license for this package (GPL).
22 | CommercialLicense.txt ... Alternative commercial license for this package.
23 | USB-ID-FAQ.txt .......... General infos about USB Product- and Vendor-IDs.
24 | USB-IDs-for-free.txt .... List and terms of use for free shared PIDs.
25 |
26 | Each subdirectory contains a separate Readme file which explains its
27 | contents. We recommend that you also read the Readme.txt file in the
28 | usbdrv subdirectory.
29 |
30 |
31 | PREREQUISITES
32 | =============
33 | The AVR code of V-USB is written in C and assembler. You need either
34 | avr-gcc or IAR CC to compile the project. We recommend avr-gcc because it
35 | is free and easily available. Gcc version 3 generates slightly more
36 | efficient code than version 4 for V-USB. Not every release is tested with
37 | the IAR compiler. Previous versions have been tested with IAR 4.10B/W32 and
38 | 4.12A/W32 on an ATmega8 with the "small" and "tiny" memory model.
39 |
40 | Ready made avr-gcc tool chains are available for most operating systems:
41 | * Windows: WinAVR http://winavr.sourceforge.net/
42 | * Mac: CrossPack for AVR Development http://www.obdev.at/crosspack/
43 | * Linux and other Unixes: Most free Unixes have optional packages for AVR
44 | development. If not, follow the instructions at
45 | http://www.nongnu.org/avr-libc/user-manual/install_tools.html
46 |
47 | Our host side examples are compiled with gcc on all platforms. Gcc is the
48 | default C compiler on Mac, Linux and many other Unixes. On windows, we
49 | recommend MinGW (http://www.mingw.org/). Use the automated MinGW installer
50 | for least troubles. You also need MSYS from the same site to work with
51 | standard Makefiles.
52 |
53 | Most examples also depend on libusb. Libusb is available from
54 | http://libusb.sourceforge.net/ for Unix and
55 | http://libusb-win32.sourceforge.net/ for Windows.
56 |
57 |
58 | TECHNICAL DOCUMENTATION
59 | =======================
60 | The API reference of the driver firmware can be found in usbdrv/usbdrv.h.
61 | Documentation for host and device library files are in the respective header
62 | files. For more information, see our documentation wiki at
63 | http://www.obdev.at/goto.php?t=vusb-wiki.
64 |
65 | See the file usbdrv/Readme.txt for more info about the driver itself.
66 |
67 |
68 | LICENSE
69 | =======
70 | V-USB and related code is distributed under the terms of the GNU General
71 | Public License (GPL) version 2 (see License.txt for details) and the GNU
72 | General Public License (GPL) version 3. It is your choice whether you apply
73 | the terms of version 2 or version 3. In addition to the terms of the GPL, we
74 | strongly encourage you to publish your entire project and mail OBJECTIVE
75 | DEVELOPMENT a link to your publication.
76 |
77 | Alternatively, we offer a commercial license without the restrictions of the
78 | GPL. See CommercialLicense.txt for details.
79 |
80 |
81 | ----------------------------------------------------------------------------
82 | (c) 2010 by OBJECTIVE DEVELOPMENT Software GmbH.
83 | http://www.obdev.at/
84 |
--------------------------------------------------------------------------------
/circuits/Readme.txt:
--------------------------------------------------------------------------------
1 | This is the Readme file for the V-USB example circuits directory.
2 |
3 |
4 | CIRCUITS IN THIS DIRECTORY
5 | ==========================
6 | Since USB requires 3.3 V levels on D+ and D- but delivers a power supply of
7 | ca. 5 V, some kind of level conversion must be performed. There are several
8 | ways to implement this level conversion, see the example circuits below.
9 |
10 | with-vreg.png and with-vreg.sch (EAGLE schematics):
11 | This circuit uses a low drop voltage regulator to reduce the USB supply to
12 | 3.3 V. You MUST use a low drop regulator because standard regulators such
13 | as the LM317 require at least ca. 2 V drop. The advantage of this approach
14 | is that it comes closest to the voltage levels required by the USB
15 | specification and that the circuit is powered from a regulated supply. If
16 | no USB cable is used (connector directly soldered on PCB), you can even
17 | omit the 68 Ohm series resistors. The disadvantage is that you may want to
18 | use other chips in your design which require 5 V. Please check that the AVR
19 | used in your design allows the chosen clock rate at 3.3 V.
20 |
21 | with-zener.png and with-zener.sch (EAGLE schematics):
22 | This circuit enforces lower voltage levels on D+ and D- with zener diodes.
23 | The zener diodes MUST be low power / low current types to ensure that the
24 | 1k5 pull-up resistor on D- generates a voltage of well above 2.5 V (but
25 | below 3.6 V). The advantage of this circuit is its simplicity and that the
26 | circuit can be powered at 5 V (usually precise enough if the cable drop is
27 | neglected). The disadvantage is that some zener diodes have a lower voltage
28 | than 3 V when powered through 1k5 and the choice of components becomes
29 | relevant. In addition to that, the power consumption during USB data
30 | transfer is increased because the current is only limited by the 68 Ohm
31 | series resistor. The zeners may even distort the signal waveforms due to
32 | their capacity.
33 |
34 | with-series-diodes.png and with-series-diodes.sch (EAGLE schematics):
35 | This is a simplified low-cost version of the voltage regulator approach.
36 | Instead of using a voltage regulator, we reduce the voltage by the forward
37 | voltage of two silicon diodes (roughly 1.4 V). This gives ca. 3.6 V which
38 | is practically inside the allowed range. The big disadvantage is that the
39 | supply is not regulated -- it even depends strongly on the power
40 | consumption. This cannot be tolerated for analog circuits.
41 |
42 | tiny45-rc.png and tiny45-rc.sch (EAGLE schematics):
43 | This is mostly an example for connecting an 8 pin device using the internal
44 | RC oscillator for system clock. This example uses series diodes to limit
45 | the supply, but you may choose any other method. Please note that you must
46 | choose a clock rate of 12.8 or 16.5 MHz because only the receiver modules
47 | for these frequencies have a PLL to allow higher clock rate tolerances.
48 |
49 |
50 | GENERAL DESIGN NOTES
51 | ====================
52 | All examples have D+ on hardware interrupt INT0 because this is the highest
53 | priority interrupt on AVRs. You may use other hardware interrupts (and
54 | configure the options at the end of usbconfig.h accordingly) if you make sure
55 | that no higher priority interrupt is used.
56 |
57 | If you use USB_SOF_HOOK or USB_COUNT_SOF in usbconfig.h, you must wire D- to
58 | the interrupt instead. This way the interrupt is triggered on USB Start Of
59 | Frame pulses as well.
60 |
61 | Most examples have a 1M pull-down resistor at D+. This pull-up ensures that
62 | in self-powered designs no interrupts occur while USB is not connected. You
63 | may omit this resistor in bus-powered designs. Older examples had a pull-up
64 | resistor instead. This is not compatible with the zener diode approach to
65 | level conversion: 1M pull-up in conjunction with a 3.6 V zener diode give an
66 | invalid logic level.
67 |
68 | All examples with ATMega8/88/168 have D+ at port D bit 2 (because this is
69 | hardware interrupt 0) and D- on port D bit 4 because it is also a clock input
70 | for timer/counter 0. This way the firmware can easily check for activity on
71 | D- (USB frame pulses) by checking the counter value in regular intervals. If
72 | no activity is found, the firmware should (according to the USB
73 | specification) put the system into a low power suspend mode.
74 |
75 |
76 |
77 | ----------------------------------------------------------------------------
78 | (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH.
79 | http://www.obdev.at/
80 |
--------------------------------------------------------------------------------
/circuits/tiny45-rc.sch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/obdev/v-usb/7a28fdc685952412dad2b8842429127bc1cf9fa7/circuits/tiny45-rc.sch
--------------------------------------------------------------------------------
/circuits/with-series-diodes.sch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/obdev/v-usb/7a28fdc685952412dad2b8842429127bc1cf9fa7/circuits/with-series-diodes.sch
--------------------------------------------------------------------------------
/circuits/with-vreg.sch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/obdev/v-usb/7a28fdc685952412dad2b8842429127bc1cf9fa7/circuits/with-vreg.sch
--------------------------------------------------------------------------------
/circuits/with-zener.sch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/obdev/v-usb/7a28fdc685952412dad2b8842429127bc1cf9fa7/circuits/with-zener.sch
--------------------------------------------------------------------------------
/examples/Readme.txt:
--------------------------------------------------------------------------------
1 | This is the Readme file for the directory "examples" of V-USB, a firmware-
2 | only USB driver for AVR microcontrollers.
3 |
4 | WHAT IS IN THIS DIRECTORY?
5 | ==========================
6 | This directory contains examples which are mostly for educational purposes.
7 | Examples can be device firmware only, host software only or both. Here is
8 | a summary:
9 |
10 | custom-class
11 | A custom class device with host software based on libusb. It demonstrates
12 | the straight forward way of sending small amounts of data to a device and
13 | receiving data from the device. It does NOT demonstrate how to send large
14 | amounts of data to the device or how to receive data generated on the fly
15 | by the device (how to use usbFunctionWrite() and usbFunctionRead()). See
16 | the hid-data example for how usbFunctionWrite() and usbFunctionRead() are
17 | used.
18 |
19 | hid-custom-rq
20 | This example implements the same functionality as the custom-class example
21 | above, but declares the device as HID. This prevents the "give me a driver
22 | CD" dialog on Windows. The device can still be controlled with libusb as in
23 | the previous example (on Windows, the filter version of libusb-win32 must
24 | be installed). In addition to the features presented in custom-class, this
25 | example demonstrates how a HID class device is defined.
26 |
27 | hid-mouse
28 | This example implements a mouse device. No host driver is required since
29 | today's operating systems have drivers for USB mice built-in. It
30 | demonstrates how a real-world HID class device is implemented and how
31 | interrupt-in endpoints are used.
32 |
33 | hid-data
34 | This example demonstrates how the HID class can be misused to transfer
35 | arbitrary data over HID feature reports. This technique is of great value
36 | on Windows because no driver DLLs are needed (the hid-custom-rq example
37 | still requires the libusb-win32 DLL, although it may be in the program's
38 | directory). The host side application requires no installation, it can
39 | even be started directly from a CD. This example also demonstrates how
40 | to transfer data using usbFunctionWrite() and usbFunctionRead().
41 |
42 | usbtool
43 | This is a general purpose development and debugging tool for USB devices.
44 | You can use it during development of your device to test various requests
45 | without special test programs. But it is also an example how all the
46 | libusb API functions are used.
47 |
48 | More information about each example can be found in the Readme file in the
49 | respective directory.
50 |
51 | Hardware dependencies of AVR code has been kept at a minimum. All examples
52 | should work on any AVR chip which has enough resources to run the driver.
53 | Makefile and usbconfig.h have been configured for the metaboard hardware (see
54 | http://www.obdev.at/goto.php?t=metaboard for details). Edit the target
55 | device, fuse values, clock rate and programmer in Makefile and the I/O pins
56 | dedicated to USB in usbconfig.h.
57 |
58 |
59 | WHAT IS NOT DEMONSTRATED IN THESE EXAMPLES?
60 | ===========================================
61 | These examples show only the most basic functionality. More elaborate
62 | examples and real world applications showing more features of the driver are
63 | available at http://www.obdev.at/vusb/projects.html. Most of these
64 | features are described in our documentation wiki at
65 | http://www.obdev.at/goto.php?t=vusb-wiki.
66 |
67 | To mention just a few:
68 |
69 | Using RC oscillator for system clock
70 | The 12.8 MHz and 16.5 MHz modules of V-USB have been designed to cope
71 | with clock rate deviations up to 1%. This allows an RC oscillator to be
72 | used. Since the AVR's RC oscillator has a factory precision of only 10%,
73 | it must be calibrated to an external reference. The EasyLogger example
74 | shows how this can be done.
75 |
76 | Dynamically generated descriptors
77 | Sometimes you want to implement different typtes of USB device depending
78 | on a jumper or other condition. V-USB has a very flexible interface for
79 | providing USB descriptors. See AVR-Doper for how to provide descriptors
80 | at runtime.
81 |
82 | Virtual COM port
83 | Some people prefer a virtual serial interface to communicate with their
84 | device. We strongly discourage this method because it does things
85 | forbidden by the USB specification. If you still want to go this route,
86 | see AVR-CDC.
87 |
88 | Implementing suspend mode
89 | V-USB does not implement suspend mode. This means that the device does
90 | not reduce power consumption when the host goes into sleep mode. Device
91 | firmware is free to implement suspend mode, though. See USB2LPT for an
92 | example.
93 |
94 | The projects mentioned above can best be found on
95 |
96 | http://www.obdev.at/vusb/prjall.html
97 |
98 | where all projects are listed.
99 |
100 | ----------------------------------------------------------------------------
101 | (c) 2009 by OBJECTIVE DEVELOPMENT Software GmbH.
102 | http://www.obdev.at/
103 |
--------------------------------------------------------------------------------
/examples/custom-class/Readme.txt:
--------------------------------------------------------------------------------
1 | This is the Readme file for the custom-class example. In this example, we
2 | show how an LED can be controlled via USB.
3 |
4 |
5 | WHAT IS DEMONSTRATED?
6 | =====================
7 | This example shows how small amounts of data (several bytes) can be
8 | transferred between the device and the host. In addition to a very basic
9 | USB device, it demonstrates how to build a host side driver application
10 | using libusb or libusb-win32. It does NOT show how usbFunctionWrite() and
11 | usbFunctionRead() are used. See the hid-data example if you want to learn
12 | about these functions.
13 |
14 |
15 | PREREQUISITES
16 | =============
17 | Target hardware: You need an AVR based circuit based on one of the examples
18 | (see the "circuits" directory at the top level of this package), e.g. the
19 | metaboard (http://www.obdev.at/goto.php?t=metaboard).
20 |
21 | AVR development environment: You need the gcc tool chain for the AVR, see
22 | the Prerequisites section in the top level Readme file for how to obtain it.
23 |
24 | Host development environment: A C compiler and libusb. See the top level
25 | Readme file, section Prerequisites for more information.
26 |
27 |
28 | BUILDING THE FIRMWARE
29 | =====================
30 | Change to the "firmware" directory and modify Makefile according to your
31 | architecture (CPU clock, target device, fuse values) and ISP programmer. Then
32 | edit usbconfig.h according to your pin assignments for D+ and D-. The default
33 | settings are for the metaboard hardware. You should have wired an LED with a
34 | current limiting resistor of ca. 270 Ohm to a free I/O pin. Change the
35 | defines in main.c to match the port and bit number.
36 |
37 | Type "make hex" to build main.hex, then "make flash" to upload the firmware
38 | to the device. Don't forget to run "make fuse" once to program the fuses. If
39 | you use a prototyping board with boot loader, follow the instructions of the
40 | boot loader instead.
41 |
42 | Please note that the first "make hex" copies the driver from the top level
43 | into the firmware directory. If you use a different build system than our
44 | Makefile, you must copy the driver by hand.
45 |
46 |
47 | BUILDING THE HOST SOFTWARE
48 | ==========================
49 | Since the host software is based on libusb or libusb-win32, make sure that
50 | this library is installed. On Unix, ensure that libusb-config is in your
51 | search PATH. On Windows, edit Makefile.windows and set the library path
52 | appropriately. Then type "make" on Unix or "make -f Makefile.windows" on
53 | Windows to build the command line tool.
54 |
55 |
56 | USING THE COMMAND LINE TOOL
57 | ===========================
58 | The command line tool has three valid arguments: "status" to query the
59 | current LED status, "on" to turn on the LED and "off" to turn it off.
60 |
61 |
62 | ----------------------------------------------------------------------------
63 | (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH.
64 | http://www.obdev.at/
65 |
--------------------------------------------------------------------------------
/examples/custom-class/commandline/set-led.c:
--------------------------------------------------------------------------------
1 | /* Name: set-led.c
2 | * Project: custom-class, a basic USB example
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-10
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | /*
11 | General Description:
12 | This is the host-side driver for the custom-class example device. It searches
13 | the USB for the LEDControl device and sends the requests understood by this
14 | device.
15 | This program must be linked with libusb on Unix and libusb-win32 on Windows.
16 | See http://libusb.sourceforge.net/ or http://libusb-win32.sourceforge.net/
17 | respectively.
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include /* this is libusb */
24 | #include "opendevice.h" /* common code moved to separate module */
25 |
26 | #include "../firmware/requests.h" /* custom request numbers */
27 | #include "../firmware/usbconfig.h" /* device's VID/PID and names */
28 |
29 | static void usage(char *name)
30 | {
31 | fprintf(stderr, "usage:\n");
32 | fprintf(stderr, " %s on ....... turn on LED\n", name);
33 | fprintf(stderr, " %s off ...... turn off LED\n", name);
34 | fprintf(stderr, " %s status ... ask current status of LED\n", name);
35 | #if ENABLE_TEST
36 | fprintf(stderr, " %s test ..... run driver reliability test\n", name);
37 | #endif /* ENABLE_TEST */
38 | }
39 |
40 | int main(int argc, char **argv)
41 | {
42 | libusb_device_handle *handle = NULL;
43 | const unsigned char rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID};
44 | char vendor[] = {USB_CFG_VENDOR_NAME, 0}, product[] = {USB_CFG_DEVICE_NAME, 0};
45 | char buffer[4];
46 | int cnt, vid, pid, isOn, r;
47 |
48 | r = libusb_init(NULL);
49 | if (0 != r) {
50 | fprintf(stderr, "Warning: cannot initialize libusb: %s\n", libusb_strerror(r));
51 | exit(1);
52 | }
53 | if(argc < 2){ /* we need at least one argument */
54 | usage(argv[0]);
55 | exit(1);
56 | }
57 | /* compute VID/PID from usbconfig.h so that there is a central source of information */
58 | vid = rawVid[1] * 256 + rawVid[0];
59 | pid = rawPid[1] * 256 + rawPid[0];
60 | /* The following function is in opendevice.c: */
61 | if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){
62 | fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid);
63 | exit(1);
64 | }
65 | /* Since we use only control endpoint 0, we don't need to choose a
66 | * configuration and interface. Reading device descriptor and setting a
67 | * configuration and interface is done through endpoint 0 after all.
68 | * However, newer versions of Linux require that we claim an interface
69 | * even for endpoint 0. Enable the following code if your operating system
70 | * needs it: */
71 | #if 0
72 | int retries = 1, usbConfiguration = 1, usbInterface = 0;
73 | r = libusb_set_configuration(handle, usbConfiguration);
74 | if(r != 0 && showWarnings){
75 | fprintf(stderr, "Warning: could not set configuration: %s\n", libusb_strerror(r));
76 | }
77 | /* now try to claim the interface and detach the kernel HID driver on
78 | * Linux and other operating systems which support the call. */
79 | while((len = libusb_claim_interface(handle, usbInterface)) != 0 && retries-- > 0){
80 | #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
81 | r = libusb_detach_kernel_driver(handle, 0);
82 | if(r != 0 && showWarnings){
83 | fprintf(stderr, "Warning: could not detach kernel driver: %s\n", libusb_strerror(r));
84 | }
85 | #endif
86 | }
87 | #endif
88 |
89 | if(strcasecmp(argv[1], "status") == 0){
90 | cnt = libusb_control_transfer(handle, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN, CUSTOM_RQ_GET_STATUS, 0, 0, (unsigned char *)buffer, sizeof(buffer), 5000);
91 | if(cnt < 1){
92 | if(cnt < 0){
93 | fprintf(stderr, "USB error: %s\n", libusb_strerror(cnt));
94 | }else{
95 | fprintf(stderr, "only %d bytes received.\n", cnt);
96 | }
97 | }else{
98 | printf("LED is %s\n", buffer[0] ? "on" : "off");
99 | }
100 | }else if((isOn = (strcasecmp(argv[1], "on") == 0)) || strcasecmp(argv[1], "off") == 0){
101 | cnt = libusb_control_transfer(handle, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, isOn, 0, (unsigned char *)buffer, 0, 5000);
102 | if(cnt < 0){
103 | fprintf(stderr, "USB error: %s\n", libusb_strerror(cnt));
104 | }
105 | #if ENABLE_TEST
106 | }else if(strcasecmp(argv[1], "test") == 0){
107 | int i;
108 | srandomdev();
109 | for(i = 0; i < 50000; i++){
110 | int value = random() & 0xffff, index = random() & 0xffff;
111 | int rxValue, rxIndex;
112 | if((i+1) % 100 == 0){
113 | fprintf(stderr, "\r%05d", i+1);
114 | fflush(stderr);
115 | }
116 | cnt = libusb_control_transfer(handle, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_ECHO, value, index, (unsigned char *)buffer, sizeof(buffer), 5000);
117 | if(cnt < 0){
118 | fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, libusb_strerror(cnt));
119 | break;
120 | }else if(cnt != 4){
121 | fprintf(stderr, "\nerror in iteration %d: %d bytes received instead of 4\n", i, cnt);
122 | break;
123 | }
124 | rxValue = ((int)buffer[0] & 0xff) | (((int)buffer[1] & 0xff) << 8);
125 | rxIndex = ((int)buffer[2] & 0xff) | (((int)buffer[3] & 0xff) << 8);
126 | if(rxValue != value || rxIndex != index){
127 | fprintf(stderr, "\ndata error in iteration %d:\n", i);
128 | fprintf(stderr, "rxValue = 0x%04x value = 0x%04x\n", rxValue, value);
129 | fprintf(stderr, "rxIndex = 0x%04x index = 0x%04x\n", rxIndex, index);
130 | }
131 | }
132 | fprintf(stderr, "\nTest completed.\n");
133 | #endif /* ENABLE_TEST */
134 | }else{
135 | usage(argv[0]);
136 | exit(1);
137 | }
138 | libusb_close(handle);
139 | return 0;
140 | }
141 |
--------------------------------------------------------------------------------
/examples/custom-class/firmware/Makefile:
--------------------------------------------------------------------------------
1 | # Name: Makefile
2 | # Project: custom-class example
3 | # Author: Christian Starkjohann
4 | # Creation Date: 2008-04-07
5 | # Tabsize: 4
6 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 |
9 | DEVICE = atmega168
10 | F_CPU = 16000000 # in Hz
11 | FUSE_L = # see below for fuse values for particular devices
12 | FUSE_H =
13 | AVRDUDE = avrdude -c usbasp -p $(DEVICE) # edit this line for your programmer
14 |
15 | CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
16 | OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o
17 |
18 | COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
19 |
20 | ##############################################################################
21 | # Fuse values for particular devices
22 | ##############################################################################
23 | # If your device is not listed here, go to
24 | # http://palmavr.sourceforge.net/cgi-bin/fc.cgi
25 | # and choose options for external crystal clock and no clock divider
26 | #
27 | ################################## ATMega8 ##################################
28 | # ATMega8 FUSE_L (Fuse low byte):
29 | # 0x9f = 1 0 0 1 1 1 1 1
30 | # ^ ^ \ / \--+--/
31 | # | | | +------- CKSEL 3..0 (external >8M crystal)
32 | # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
33 | # | +------------------ BODEN (BrownOut Detector enabled)
34 | # +-------------------- BODLEVEL (2.7V)
35 | # ATMega8 FUSE_H (Fuse high byte):
36 | # 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
37 | # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
38 | # | | | | | +-------- BOOTSZ1
39 | # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
40 | # | | | +-------------- CKOPT (full output swing)
41 | # | | +---------------- SPIEN (allow serial programming)
42 | # | +------------------ WDTON (WDT not always on)
43 | # +-------------------- RSTDISBL (reset pin is enabled)
44 | #
45 | ############################## ATMega48/88/168 ##############################
46 | # ATMega*8 FUSE_L (Fuse low byte):
47 | # 0xdf = 1 1 0 1 1 1 1 1
48 | # ^ ^ \ / \--+--/
49 | # | | | +------- CKSEL 3..0 (external >8M crystal)
50 | # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
51 | # | +------------------ CKOUT (if 0: Clock output enabled)
52 | # +-------------------- CKDIV8 (if 0: divide by 8)
53 | # ATMega*8 FUSE_H (Fuse high byte):
54 | # 0xde = 1 1 0 1 1 1 1 0
55 | # ^ ^ ^ ^ ^ \-+-/
56 | # | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V)
57 | # | | | | + --------- EESAVE (preserve EEPROM over chip erase)
58 | # | | | +-------------- WDTON (if 0: watchdog always on)
59 | # | | +---------------- SPIEN (allow serial programming)
60 | # | +------------------ DWEN (debug wire enable)
61 | # +-------------------- RSTDISBL (reset pin is enabled)
62 | #
63 | ############################## ATTiny25/45/85 ###############################
64 | # ATMega*5 FUSE_L (Fuse low byte):
65 | # 0xef = 1 1 1 0 1 1 1 1
66 | # ^ ^ \+/ \--+--/
67 | # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz)
68 | # | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
69 | # | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
70 | # +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
71 | # ATMega*5 FUSE_H (Fuse high byte):
72 | # 0xdd = 1 1 0 1 1 1 0 1
73 | # ^ ^ ^ ^ ^ \-+-/
74 | # | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V)
75 | # | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved)
76 | # | | | +-------------- WDTON (watchdog timer always on -> disable)
77 | # | | +---------------- SPIEN (enable serial programming -> enabled)
78 | # | +------------------ DWEN (debug wire enable)
79 | # +-------------------- RSTDISBL (disable external reset -> enabled)
80 | #
81 | ################################ ATTiny2313 #################################
82 | # ATTiny2313 FUSE_L (Fuse low byte):
83 | # 0xef = 1 1 1 0 1 1 1 1
84 | # ^ ^ \+/ \--+--/
85 | # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz)
86 | # | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
87 | # | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
88 | # +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
89 | # ATTiny2313 FUSE_H (Fuse high byte):
90 | # 0xdb = 1 1 0 1 1 0 1 1
91 | # ^ ^ ^ ^ \-+-/ ^
92 | # | | | | | +---- RSTDISBL (disable external reset -> enabled)
93 | # | | | | +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V)
94 | # | | | +-------------- WDTON (watchdog timer always on -> disable)
95 | # | | +---------------- SPIEN (enable serial programming -> enabled)
96 | # | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved)
97 | # +-------------------- DWEN (debug wire enable)
98 |
99 |
100 | # symbolic targets:
101 | help:
102 | @echo "This Makefile has no default rule. Use one of the following:"
103 | @echo "make hex ....... to build main.hex"
104 | @echo "make program ... to flash fuses and firmware"
105 | @echo "make fuse ...... to flash the fuses"
106 | @echo "make flash ..... to flash the firmware (use this on metaboard)"
107 | @echo "make clean ..... to delete objects and hex file"
108 |
109 | hex: main.hex
110 |
111 | program: flash fuse
112 |
113 | # rule for programming fuse bits:
114 | fuse:
115 | @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \
116 | { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; }
117 | $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m
118 |
119 | # rule for uploading firmware:
120 | flash: main.hex
121 | $(AVRDUDE) -U flash:w:main.hex:i
122 |
123 | # rule for deleting dependent files (those which can be built by Make):
124 | clean:
125 | rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s
126 |
127 | # Generic rule for compiling C files:
128 | .c.o:
129 | $(COMPILE) -c $< -o $@
130 |
131 | # Generic rule for assembling Assembler source files:
132 | .S.o:
133 | $(COMPILE) -x assembler-with-cpp -c $< -o $@
134 | # "-x assembler-with-cpp" should not be necessary since this is the default
135 | # file type for the .S (with capital S) extension. However, upper case
136 | # characters are not always preserved on Windows. To ensure WinAVR
137 | # compatibility define the file type manually.
138 |
139 | # Generic rule for compiling C to assembler, used for debugging only.
140 | .c.s:
141 | $(COMPILE) -S $< -o $@
142 |
143 | # file targets:
144 |
145 | # Since we don't want to ship the driver multipe times, we copy it into this project:
146 | usbdrv:
147 | cp -r ../../../usbdrv .
148 |
149 | main.elf: usbdrv $(OBJECTS) # usbdrv dependency only needed because we copy it
150 | $(COMPILE) -o main.elf $(OBJECTS)
151 |
152 | main.hex: main.elf
153 | rm -f main.hex main.eep.hex
154 | avr-objcopy -j .text -j .data -O ihex main.elf main.hex
155 | avr-size main.hex
156 |
157 | # debugging targets:
158 |
159 | disasm: main.elf
160 | avr-objdump -d main.elf
161 |
162 | cpp:
163 | $(COMPILE) -E main.c
164 |
--------------------------------------------------------------------------------
/examples/custom-class/firmware/main.c:
--------------------------------------------------------------------------------
1 | /* Name: main.c
2 | * Project: custom-class, a basic USB example
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-09
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | /*
11 | This example should run on most AVRs with only little changes. No special
12 | hardware resources except INT0 are used. You may have to change usbconfig.h for
13 | different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or
14 | at least be connected to INT0 as well.
15 | We assume that an LED is connected to port B bit 0. If you connect it to a
16 | different port or bit, change the macros below:
17 | */
18 | #define LED_PORT_DDR DDRB
19 | #define LED_PORT_OUTPUT PORTB
20 | #define LED_BIT 0
21 |
22 | #include
23 | #include
24 | #include /* for sei() */
25 | #include /* for _delay_ms() */
26 |
27 | #include /* required by usbdrv.h */
28 | #include "usbdrv.h"
29 | #include "oddebug.h" /* This is also an example for using debug macros */
30 | #include "requests.h" /* The custom request numbers we use */
31 |
32 | /* ------------------------------------------------------------------------- */
33 | /* ----------------------------- USB interface ----------------------------- */
34 | /* ------------------------------------------------------------------------- */
35 |
36 | usbMsgLen_t usbFunctionSetup(uchar data[8])
37 | {
38 | usbRequest_t *rq = (void *)data;
39 | static uchar dataBuffer[4]; /* buffer must stay valid when usbFunctionSetup returns */
40 |
41 | if(rq->bRequest == CUSTOM_RQ_ECHO){ /* echo -- used for reliability tests */
42 | dataBuffer[0] = rq->wValue.bytes[0];
43 | dataBuffer[1] = rq->wValue.bytes[1];
44 | dataBuffer[2] = rq->wIndex.bytes[0];
45 | dataBuffer[3] = rq->wIndex.bytes[1];
46 | usbMsgPtr = dataBuffer; /* tell the driver which data to return */
47 | return 4;
48 | }else if(rq->bRequest == CUSTOM_RQ_SET_STATUS){
49 | if(rq->wValue.bytes[0] & 1){ /* set LED */
50 | LED_PORT_OUTPUT |= _BV(LED_BIT);
51 | }else{ /* clear LED */
52 | LED_PORT_OUTPUT &= ~_BV(LED_BIT);
53 | }
54 | }else if(rq->bRequest == CUSTOM_RQ_GET_STATUS){
55 | dataBuffer[0] = ((LED_PORT_OUTPUT & _BV(LED_BIT)) != 0);
56 | usbMsgPtr = dataBuffer; /* tell the driver which data to return */
57 | return 1; /* tell the driver to send 1 byte */
58 | }
59 | return 0; /* default for not implemented requests: return no data back to host */
60 | }
61 |
62 | /* ------------------------------------------------------------------------- */
63 |
64 | int __attribute__((noreturn)) main(void)
65 | {
66 | uchar i;
67 |
68 | wdt_enable(WDTO_1S);
69 | /* If you don't use the watchdog, replace the call above with a wdt_disable().
70 | * On newer devices, the status of the watchdog (on/off, period) is PRESERVED
71 | * OVER RESET!
72 | */
73 | /* RESET status: all port bits are inputs without pull-up.
74 | * That's the way we need D+ and D-. Therefore we don't need any
75 | * additional hardware initialization.
76 | */
77 | odDebugInit();
78 | DBG1(0x00, 0, 0); /* debug output: main starts */
79 | usbInit();
80 | usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
81 | i = 0;
82 | while(--i){ /* fake USB disconnect for > 250 ms */
83 | wdt_reset();
84 | _delay_ms(1);
85 | }
86 | usbDeviceConnect();
87 | LED_PORT_DDR |= _BV(LED_BIT); /* make the LED bit an output */
88 | sei();
89 | DBG1(0x01, 0, 0); /* debug output: main loop starts */
90 | for(;;){ /* main event loop */
91 | DBG1(0x02, 0, 0); /* debug output: main loop iterates */
92 | wdt_reset();
93 | usbPoll();
94 | }
95 | }
96 |
97 | /* ------------------------------------------------------------------------- */
98 |
--------------------------------------------------------------------------------
/examples/custom-class/firmware/requests.h:
--------------------------------------------------------------------------------
1 | /* Name: requests.h
2 | * Project: custom-class, a basic USB example
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-09
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | /* This header is shared between the firmware and the host software. It
11 | * defines the USB request numbers (and optionally data types) used to
12 | * communicate between the host and the device.
13 | */
14 |
15 | #ifndef __REQUESTS_H_INCLUDED__
16 | #define __REQUESTS_H_INCLUDED__
17 |
18 | #define CUSTOM_RQ_ECHO 0
19 | /* Request that the device sends back wValue and wIndex. This is used with
20 | * random data to test the reliability of the communication.
21 | */
22 | #define CUSTOM_RQ_SET_STATUS 1
23 | /* Set the LED status. Control-OUT.
24 | * The requested status is passed in the "wValue" field of the control
25 | * transfer. No OUT data is sent. Bit 0 of the low byte of wValue controls
26 | * the LED.
27 | */
28 |
29 | #define CUSTOM_RQ_GET_STATUS 2
30 | /* Get the current LED status. Control-IN.
31 | * This control transfer involves a 1 byte data phase where the device sends
32 | * the current status to the host. The status is in bit 0 of the byte.
33 | */
34 |
35 | #endif /* __REQUESTS_H_INCLUDED__ */
36 |
--------------------------------------------------------------------------------
/examples/custom-class/make-files.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Author: Christian Starkjohann
3 | # Creation Date: 2008-04-17
4 | # Tabsize: 4
5 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
6 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
7 |
8 |
9 | if [ "$1" = remove ]; then
10 | (cd firmware; make clean)
11 | rm -f firmware/usbconfig.h
12 | rm -rf firmware/usbdrv
13 | rm -f commandline/Makefile.windows
14 | rm -f commandline/Makefile
15 | rm -f commandline/opendevice.[ch]
16 | exit
17 | fi
18 |
19 | cat << \EOF | sed -n -f /dev/stdin ../../usbdrv/usbconfig-prototype.h >firmware/usbconfig.h
20 | /^\( [*] \)\{0,1\}[+].*$/ d
21 | s/^#define USB_CFG_DMINUS_BIT .*$/#define USB_CFG_DMINUS_BIT 4/g
22 | s|^.*#define USB_CFG_CLOCK_KHZ.*$|#define USB_CFG_CLOCK_KHZ (F_CPU/1000)|g
23 | s/^#define USB_CFG_DEVICE_NAME .*$/#define USB_CFG_DEVICE_NAME 'L', 'E', 'D', 'C', 'o', 'n', 't', 'r', 'o', 'l'/g
24 | s/^#define USB_CFG_DEVICE_NAME_LEN .*$/#define USB_CFG_DEVICE_NAME_LEN 10/g
25 |
26 | s/^#define USB_CFG_MAX_BUS_POWER .*$/#define USB_CFG_MAX_BUS_POWER 40/g
27 | p
28 | EOF
29 |
30 | cat << \EOF | sed -n -f /dev/stdin ../usbtool/Makefile.windows >commandline/Makefile.windows
31 | /^\( [*] \)\{0,1\}[+].*$/ d
32 | s/^# Project: .*$/# Project: custom-class example/g
33 | p
34 | EOF
35 |
36 | cat << \EOF | sed -n -f /dev/stdin ../usbtool/Makefile >commandline/Makefile
37 | /^\( [*] \)\{0,1\}[+].*$/ d
38 | s/^# Project: .*$/# Project: custom-class example/g
39 | s/^NAME = .*$/NAME = set-led/g
40 | p
41 | EOF
42 |
43 | cp ../../libs-host/opendevice.[ch] commandline/
44 |
--------------------------------------------------------------------------------
/examples/drivertest/commandline/runtest.c:
--------------------------------------------------------------------------------
1 | /* Name: runtest.c
2 | * Author: Christian Starkjohann
3 | * Creation Date: 2008-04-10
4 | * Tabsize: 4
5 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
6 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
7 | */
8 |
9 | /*
10 | General Description:
11 | */
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include /* this is libusb */
18 | #include "opendevice.h" /* common code moved to separate module */
19 |
20 | #include "../firmware/requests.h" /* custom request numbers */
21 | #include "../firmware/usbconfig.h" /* device's VID/PID and names */
22 |
23 | #define uchar unsigned char
24 |
25 | static void hexdump(char *_buffer, int len, FILE *fp)
26 | {
27 | int i;
28 | uchar *buffer = (uchar *)_buffer;
29 |
30 | for(i = 0; i < len; i++){
31 | if(i != 0){
32 | if(i % 16 == 0){
33 | fprintf(fp, "\n");
34 | }else{
35 | fprintf(fp, " ");
36 | }
37 | }
38 | fprintf(fp, "%02x", buffer[i]);
39 | }
40 | if(i != 0)
41 | fprintf(fp, "\n");
42 | }
43 |
44 | static void fillBuffer(char *buffer, int len)
45 | {
46 | static int type = 0;
47 |
48 | if(type == 0){ /* all 0 */
49 | bzero(buffer, len);
50 | }else if(type == 1){ /* all 0xff */
51 | memset(buffer, 0xff, len);
52 | }else{ /* random */
53 | int i;
54 | for(i = 0; i < len; i++){
55 | buffer[i] = random() & 0xff;
56 | }
57 | }
58 | if(++type >= 1000)
59 | type = 0;
60 | }
61 |
62 | static int compareBuffers(char *txBuffer, char *rxBuffer, int len)
63 | {
64 | int i, rval = 0;
65 |
66 | for(i = 0; i < len; i++){
67 | if(rxBuffer[i] != txBuffer[i]){
68 | fprintf(stderr, "compare error at index %d: byte is 0x%x instead of 0x%x\n", i, rxBuffer[i], txBuffer[i]);
69 | rval = 1;
70 | }
71 | }
72 | if(rval){
73 | fprintf(stderr, "txBuffer was:\n");
74 | hexdump(txBuffer, len, stderr);
75 | fprintf(stderr, "rxBuffer is:\n");
76 | hexdump(rxBuffer, len, stderr);
77 | }
78 | return rval;
79 | }
80 |
81 | int main(int argc, char **argv)
82 | {
83 | libusb_device_handle *handle = NULL;
84 | const uchar rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID};
85 | char vendor[] = {USB_CFG_VENDOR_NAME, 0}, product[] = {USB_CFG_DEVICE_NAME, 0};
86 | char txBuffer[64], rxBuffer[64];
87 | int cnt, vid, pid, i, j, r;
88 |
89 | r = libusb_init(NULL);
90 | if (0 != r) {
91 | fprintf(stderr, "Warning: cannot initialize libusb: %s\n", libusb_strerror(r));
92 | exit(1);
93 | }
94 | /* compute VID/PID from usbconfig.h so that there is a central source of information */
95 | vid = rawVid[1] * 256 + rawVid[0];
96 | pid = rawPid[1] * 256 + rawPid[0];
97 | /* The following function is in opendevice.c: */
98 | if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){
99 | fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid);
100 | exit(1);
101 | }
102 | if(argc > 1 && strcasecmp(argv[1], "osccal") == 0){
103 | if(argc > 2){ /* set osccal */
104 | int osccal = atoi(argv[2]);
105 | printf("setting osccal to %d\n", osccal);
106 | cnt = libusb_control_transfer(handle, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN, CUSTOM_RQ_SET_OSCCAL, osccal, 0, (unsigned char *)txBuffer, 0, 5000);
107 | if(cnt < 0){
108 | fprintf(stderr, "\nUSB error setting osccal: %s\n", libusb_strerror(cnt));
109 | }
110 | }else{
111 | cnt = libusb_control_transfer(handle, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN, CUSTOM_RQ_GET_OSCCAL, 0, 0, (unsigned char *)rxBuffer, 1, 5000);
112 | if(cnt < 0){
113 | fprintf(stderr, "\nUSB error getting osccal: %s\n", libusb_strerror(cnt));
114 | }else{
115 | printf("osccal = %d\n", (unsigned char)rxBuffer[0]);
116 | }
117 | }
118 | }else{
119 | #ifdef __linux__
120 | srandom(time(NULL));
121 | #else
122 | srandomdev();
123 | #endif
124 | for(i = 0; i <= 100000; i++){
125 | fillBuffer(txBuffer, sizeof(txBuffer));
126 | cnt = libusb_control_transfer(handle, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT, CUSTOM_RQ_SET_DATA, 0, 0, (unsigned char *)txBuffer, sizeof(txBuffer), 5000);
127 | if(cnt < 0){
128 | fprintf(stderr, "\nUSB tx error in iteration %d: %s\n", i, libusb_strerror(cnt));
129 | break;
130 | }else if(cnt != sizeof(txBuffer)){
131 | fprintf(stderr, "\nerror in iteration %d: %d bytes sent instead of %d\n", i, cnt, (int)sizeof(txBuffer));
132 | break;
133 | }
134 | for(j = 0; j < sizeof(rxBuffer); j++){
135 | rxBuffer[j] = ~txBuffer[j];
136 | }
137 | cnt = libusb_control_transfer(handle, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN, CUSTOM_RQ_GET_DATA, 0, 0, (unsigned char *)rxBuffer, sizeof(rxBuffer), 5000);
138 | if(cnt < 0){
139 | fprintf(stderr, "\nUSB rx error in iteration %d: %s\n", i, libusb_strerror(cnt));
140 | break;
141 | }else if(cnt != sizeof(txBuffer)){
142 | fprintf(stderr, "\nerror in iteration %d: %d bytes received instead of %d\n", i, cnt, (int)sizeof(rxBuffer));
143 | break;
144 | }
145 | if(compareBuffers(txBuffer, rxBuffer, sizeof(rxBuffer))){
146 | fprintf(stderr, "\ncompare error in iteration %d.\n", i);
147 | break;
148 | }
149 | if(i != 0 && i % 100 == 0){
150 | printf(".");
151 | fflush(stdout);
152 | if(i % 5000 == 0)
153 | printf(" %6d\n", i);
154 | }
155 | }
156 | fprintf(stderr, "\nTest completed.\n");
157 | }
158 | libusb_close(handle);
159 | return 0;
160 | }
161 |
--------------------------------------------------------------------------------
/examples/drivertest/firmware/Makefile:
--------------------------------------------------------------------------------
1 | # Name: Makefile
2 | # Project: drivertest example
3 | # Author: Christian Starkjohann
4 | # Creation Date: 2008-04-07
5 | # Tabsize: 4
6 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 |
9 | DEVICE = atmega8
10 | F_CPU = 12800000 # in Hz
11 | FUSE_L = 0x94
12 | FUSE_H = 0xc9
13 | AVRDUDE = avrdude -c stk500v2 -P avrdoper -p $(DEVICE) # edit this line for your programmer
14 |
15 | CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 -DTUNE_OSCCAL=1 -DCALIBRATE_OSCCAL=0
16 | OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o
17 |
18 | COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
19 |
20 | ##############################################################################
21 | # Fuse values for particular devices
22 | ##############################################################################
23 | # If your device is not listed here, go to
24 | # http://palmavr.sourceforge.net/cgi-bin/fc.cgi
25 | # and choose options for external crystal clock and no clock divider
26 | #
27 | ################################## ATMega8 ##################################
28 | # ATMega8 FUSE_L (Fuse low byte):
29 | # 0x9f = 1 0 0 1 1 1 1 1
30 | # ^ ^ \ / \--+--/
31 | # | | | +------- CKSEL 3..0 (external >8M crystal)
32 | # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
33 | # | +------------------ BODEN (BrownOut Detector enabled)
34 | # +-------------------- BODLEVEL (2.7V)
35 | # ATMega8 FUSE_H (Fuse high byte):
36 | # 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
37 | # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
38 | # | | | | | +-------- BOOTSZ1
39 | # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
40 | # | | | +-------------- CKOPT (full output swing)
41 | # | | +---------------- SPIEN (allow serial programming)
42 | # | +------------------ WDTON (WDT not always on)
43 | # +-------------------- RSTDISBL (reset pin is enabled)
44 | #
45 | ############################## ATMega48/88/168 ##############################
46 | # ATMega*8 FUSE_L (Fuse low byte):
47 | # 0xdf = 1 1 0 1 1 1 1 1
48 | # ^ ^ \ / \--+--/
49 | # | | | +------- CKSEL 3..0 (external >8M crystal)
50 | # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
51 | # | +------------------ CKOUT (if 0: Clock output enabled)
52 | # +-------------------- CKDIV8 (if 0: divide by 8)
53 | # ATMega*8 FUSE_H (Fuse high byte):
54 | # 0xde = 1 1 0 1 1 1 1 0
55 | # ^ ^ ^ ^ ^ \-+-/
56 | # | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V)
57 | # | | | | + --------- EESAVE (preserve EEPROM over chip erase)
58 | # | | | +-------------- WDTON (if 0: watchdog always on)
59 | # | | +---------------- SPIEN (allow serial programming)
60 | # | +------------------ DWEN (debug wire enable)
61 | # +-------------------- RSTDISBL (reset pin is enabled)
62 | #
63 | ############################## ATTiny25/45/85 ###############################
64 | # ATMega*5 FUSE_L (Fuse low byte):
65 | # 0xef = 1 1 1 0 1 1 1 1
66 | # ^ ^ \+/ \--+--/
67 | # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz)
68 | # | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
69 | # | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
70 | # +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
71 | # ATMega*5 FUSE_H (Fuse high byte):
72 | # 0xdd = 1 1 0 1 1 1 0 1
73 | # ^ ^ ^ ^ ^ \-+-/
74 | # | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V)
75 | # | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved)
76 | # | | | +-------------- WDTON (watchdog timer always on -> disable)
77 | # | | +---------------- SPIEN (enable serial programming -> enabled)
78 | # | +------------------ DWEN (debug wire enable)
79 | # +-------------------- RSTDISBL (disable external reset -> enabled)
80 | #
81 | ################################ ATTiny2313 #################################
82 | # ATTiny2313 FUSE_L (Fuse low byte):
83 | # 0xef = 1 1 1 0 1 1 1 1
84 | # ^ ^ \+/ \--+--/
85 | # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz)
86 | # | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
87 | # | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
88 | # +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
89 | # ATTiny2313 FUSE_H (Fuse high byte):
90 | # 0xdb = 1 1 0 1 1 0 1 1
91 | # ^ ^ ^ ^ \-+-/ ^
92 | # | | | | | +---- RSTDISBL (disable external reset -> enabled)
93 | # | | | | +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V)
94 | # | | | +-------------- WDTON (watchdog timer always on -> disable)
95 | # | | +---------------- SPIEN (enable serial programming -> enabled)
96 | # | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved)
97 | # +-------------------- DWEN (debug wire enable)
98 |
99 |
100 | # symbolic targets:
101 | help:
102 | @echo "This Makefile has no default rule. Use one of the following:"
103 | @echo "make hex ....... to build main.hex"
104 | @echo "make program ... to flash fuses and firmware"
105 | @echo "make fuse ...... to flash the fuses"
106 | @echo "make flash ..... to flash the firmware (use this on metaboard)"
107 | @echo "make clean ..... to delete objects and hex file"
108 |
109 | hex: main.hex
110 |
111 | program: flash fuse
112 |
113 | # rule for programming fuse bits:
114 | fuse:
115 | @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \
116 | { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; }
117 | $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m
118 |
119 | # rule for uploading firmware:
120 | flash: main.hex
121 | $(AVRDUDE) -U flash:w:main.hex:i
122 |
123 | # rule for deleting dependent files (those which can be built by Make):
124 | clean:
125 | rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s
126 |
127 | # Generic rule for compiling C files:
128 | .c.o:
129 | $(COMPILE) -c $< -o $@
130 |
131 | # Generic rule for assembling Assembler source files:
132 | .S.o:
133 | $(COMPILE) -x assembler-with-cpp -c $< -o $@
134 | # "-x assembler-with-cpp" should not be necessary since this is the default
135 | # file type for the .S (with capital S) extension. However, upper case
136 | # characters are not always preserved on Windows. To ensure WinAVR
137 | # compatibility define the file type manually.
138 |
139 | # Generic rule for compiling C to assembler, used for debugging only.
140 | .c.s:
141 | $(COMPILE) -S $< -o $@
142 |
143 | # file targets:
144 |
145 | # Since we don't want to ship the driver multipe times, we copy it into this project:
146 | usbdrv:
147 | cp -r ../../../usbdrv .
148 |
149 | main.elf: usbdrv $(OBJECTS) # usbdrv dependency only needed because we copy it
150 | $(COMPILE) -o main.elf $(OBJECTS)
151 |
152 | main.hex: main.elf
153 | rm -f main.hex main.eep.hex
154 | avr-objcopy -j .text -j .data -O ihex main.elf main.hex
155 | avr-size main.hex
156 |
157 | # debugging targets:
158 |
159 | disasm: main.elf
160 | avr-objdump -d main.elf
161 |
162 | cpp:
163 | $(COMPILE) -E main.c
164 |
--------------------------------------------------------------------------------
/examples/drivertest/firmware/main.c:
--------------------------------------------------------------------------------
1 | /* Name: main.c
2 | * Project: hid-custom-rq example
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-07
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | /*
11 | This example should run on most AVRs with only little changes. No special
12 | hardware resources except INT0 are used. You may have to change usbconfig.h for
13 | different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or
14 | at least be connected to INT0 as well.
15 | */
16 |
17 | #include
18 | #include
19 | #include /* for sei() */
20 | #include /* for _delay_ms() */
21 |
22 | #include /* required by usbdrv.h */
23 | #include "usbdrv.h"
24 | #include "oddebug.h" /* This is also an example for using debug macros */
25 | #include "requests.h" /* The custom request numbers we use */
26 |
27 | #if TUNE_OSCCAL
28 | uchar lastTimer0Value;
29 | #endif
30 |
31 | #if CALIBRATE_OSCCAL
32 | #include "osccal.c"
33 | #endif
34 |
35 |
36 | /* ------------------------------------------------------------------------- */
37 | /* ----------------------------- USB interface ----------------------------- */
38 | /* ------------------------------------------------------------------------- */
39 |
40 | static uchar dataBuffer[64];
41 | static uchar writeIndex;
42 |
43 | uchar usbFunctionWrite(uchar *data, uchar len)
44 | {
45 |
46 | if(writeIndex + len <= sizeof(dataBuffer)){
47 | uchar i;
48 | for(i = 0; i < len; i++){
49 | dataBuffer[writeIndex++] = *data++;
50 | }
51 | }
52 | return writeIndex >= sizeof(dataBuffer);
53 | }
54 |
55 | usbMsgLen_t usbFunctionSetup(uchar data[8])
56 | {
57 | usbRequest_t *rq = (void *)data;
58 |
59 | DBG1(0x50, &rq->bRequest, 1); /* debug output: print our request */
60 | if(rq->bRequest == CUSTOM_RQ_SET_DATA){
61 | writeIndex = 0;
62 | return USB_NO_MSG;
63 | }else if(rq->bRequest == CUSTOM_RQ_GET_DATA){
64 | usbMsgPtr = dataBuffer; /* tell the driver which data to return */
65 | return sizeof(dataBuffer); /* tell the driver how many bytes to send */
66 | }else if(rq->bRequest == CUSTOM_RQ_SET_OSCCAL){
67 | OSCCAL = rq->wValue.bytes[0];
68 | }else if(rq->bRequest == CUSTOM_RQ_GET_OSCCAL){
69 | usbMsgPtr = (uchar *)&OSCCAL;
70 | return 1;
71 | }
72 | return 0; /* default for not implemented requests: return no data back to host */
73 | }
74 |
75 | /* ------------------------------------------------------------------------- */
76 |
77 | int __attribute__((noreturn)) main(void)
78 | {
79 | uchar i;
80 |
81 | wdt_enable(WDTO_1S);
82 | /* If you don't use the watchdog, replace the call above with a wdt_disable().
83 | * On newer devices, the status of the watchdog (on/off, period) is PRESERVED
84 | * OVER RESET!
85 | */
86 | odDebugInit();
87 | DBG1(0x00, 0, 0); /* debug output: main starts */
88 | /* RESET status: all port bits are inputs without pull-up.
89 | * That's the way we need D+ and D-. Therefore we don't need any
90 | * additional hardware initialization.
91 | */
92 | TCCR2 = 9 | (1 << COM20);
93 | OCR2 = 3; /* should give F_CPU/8 clock */
94 |
95 | DDRB = (1 << 2) | (1 << 3);
96 | TCCR0 = 3; /* 1/64 prescaler */
97 | usbInit();
98 | usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
99 | i = 0;
100 | while(--i){ /* fake USB disconnect for > 250 ms */
101 | wdt_reset();
102 | _delay_ms(1);
103 | }
104 | usbDeviceConnect();
105 | sei();
106 | DBG1(0x01, 0, 0); /* debug output: main loop starts */
107 | for(;;){ /* main event loop */
108 | wdt_reset();
109 | usbPoll();
110 | cli(); /* disable interrupts for some cycles, use other cli as nop */
111 | cli();
112 | cli();
113 | cli();
114 | cli();
115 | cli();
116 | cli();
117 | cli();
118 | cli();
119 | cli();
120 | cli();
121 | cli();
122 | cli();
123 | cli();
124 | sei();
125 | }
126 | }
127 |
128 | /* ------------------------------------------------------------------------- */
129 |
--------------------------------------------------------------------------------
/examples/drivertest/firmware/requests.h:
--------------------------------------------------------------------------------
1 | /* Name: requests.h
2 | * Project: custom-class, a basic USB example
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-09
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | /* This header is shared between the firmware and the host software. It
11 | * defines the USB request numbers (and optionally data types) used to
12 | * communicate between the host and the device.
13 | */
14 |
15 | #ifndef __REQUESTS_H_INCLUDED__
16 | #define __REQUESTS_H_INCLUDED__
17 |
18 | #define CUSTOM_RQ_SET_DATA 1
19 | /* Send data to device. Control-OUT with 64 bytes data.
20 | */
21 |
22 | #define CUSTOM_RQ_GET_DATA 2
23 | /* Get data from device. Control-IN with 64 bytes data.
24 | */
25 | #define CUSTOM_RQ_SET_OSCCAL 3
26 | #define CUSTOM_RQ_GET_OSCCAL 4
27 |
28 | #endif /* __REQUESTS_H_INCLUDED__ */
29 |
--------------------------------------------------------------------------------
/examples/drivertest/make-files.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Author: Christian Starkjohann
3 | # Creation Date: 2008-04-17
4 | # Tabsize: 4
5 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
6 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
7 |
8 |
9 | if [ "$1" = remove ]; then
10 | (cd firmware; make clean)
11 | rm -rf firmware/usbdrv
12 | rm -f firmware/osccal.[ch]
13 | rm -f commandline/Makefile.windows
14 | rm -f commandline/Makefile
15 | rm -f commandline/opendevice.[ch]
16 | exit
17 | fi
18 |
19 | cat << \EOF | sed -n -f /dev/stdin ../usbtool/Makefile.windows >commandline/Makefile.windows
20 | /^\( [*] \)\{0,1\}[+].*$/ d
21 | s/^# Project: .*$/# Project: hid-custom-rq example/g
22 | p
23 | EOF
24 |
25 | cat << \EOF | sed -n -f /dev/stdin ../usbtool/Makefile >commandline/Makefile
26 | /^\( [*] \)\{0,1\}[+].*$/ d
27 | s/^# Project: .*$/# Project: hid-custom-rq example/g
28 | s/^NAME = .*$/NAME = runtest/g
29 | p
30 | EOF
31 |
32 | cp ../../libs-host/opendevice.[ch] commandline/
33 | cp ../../libs-device/osccal.[ch] firmware/
34 |
--------------------------------------------------------------------------------
/examples/hid-custom-rq/Readme.txt:
--------------------------------------------------------------------------------
1 | This is the Readme file for the hid-custom-rq example. This is basically the
2 | same as the custom-class example, except that the device conforms to the USB
3 | HID class.
4 |
5 |
6 | WHAT IS DEMONSTRATED?
7 | =====================
8 | This example demonstrates how custom requests can be sent to devices which
9 | are otherwise HID compliant. This mechanism can be used to prevent the
10 | "driver CD" dialog on Windows and still control the device with libusb-win32.
11 | It can also be used to extend the functionality of the USB class, e.g. by
12 | setting parameters.
13 |
14 | Please note that you should install the filter version of libusb-win32 to
15 | take full advantage or this mode. The device driver version only has access
16 | to devices which have been registered for it with a *.inf file. The filter
17 | version has access to all devices.
18 |
19 |
20 | MORE INFORMATION
21 | ================
22 | For information about how to build this example and how to use the command
23 | line tool see the Readme file in the custom-class example.
24 |
25 |
26 | ----------------------------------------------------------------------------
27 | (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH.
28 | http://www.obdev.at/
29 |
--------------------------------------------------------------------------------
/examples/hid-custom-rq/firmware/main.c:
--------------------------------------------------------------------------------
1 | /* Name: main.c
2 | * Project: hid-custom-rq example
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-07
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | /*
11 | This example should run on most AVRs with only little changes. No special
12 | hardware resources except INT0 are used. You may have to change usbconfig.h for
13 | different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or
14 | at least be connected to INT0 as well.
15 | We assume that an LED is connected to port B bit 0. If you connect it to a
16 | different port or bit, change the macros below:
17 | */
18 | #define LED_PORT_DDR DDRB
19 | #define LED_PORT_OUTPUT PORTB
20 | #define LED_BIT 0
21 |
22 | #include
23 | #include
24 | #include /* for sei() */
25 | #include /* for _delay_ms() */
26 |
27 | #include /* required by usbdrv.h */
28 | #include "usbdrv.h"
29 | #include "oddebug.h" /* This is also an example for using debug macros */
30 | #include "requests.h" /* The custom request numbers we use */
31 |
32 | /* ------------------------------------------------------------------------- */
33 | /* ----------------------------- USB interface ----------------------------- */
34 | /* ------------------------------------------------------------------------- */
35 |
36 | PROGMEM const char usbHidReportDescriptor[22] = { /* USB report descriptor */
37 | 0x06, 0x00, 0xff, // USAGE_PAGE (Generic Desktop)
38 | 0x09, 0x01, // USAGE (Vendor Usage 1)
39 | 0xa1, 0x01, // COLLECTION (Application)
40 | 0x15, 0x00, // LOGICAL_MINIMUM (0)
41 | 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
42 | 0x75, 0x08, // REPORT_SIZE (8)
43 | 0x95, 0x01, // REPORT_COUNT (1)
44 | 0x09, 0x00, // USAGE (Undefined)
45 | 0xb2, 0x02, 0x01, // FEATURE (Data,Var,Abs,Buf)
46 | 0xc0 // END_COLLECTION
47 | };
48 | /* The descriptor above is a dummy only, it silences the drivers. The report
49 | * it describes consists of one byte of undefined data.
50 | * We don't transfer our data through HID reports, we use custom requests
51 | * instead.
52 | */
53 |
54 | /* ------------------------------------------------------------------------- */
55 |
56 | usbMsgLen_t usbFunctionSetup(uchar data[8])
57 | {
58 | usbRequest_t *rq = (void *)data;
59 |
60 | if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR){
61 | DBG1(0x50, &rq->bRequest, 1); /* debug output: print our request */
62 | if(rq->bRequest == CUSTOM_RQ_SET_STATUS){
63 | if(rq->wValue.bytes[0] & 1){ /* set LED */
64 | LED_PORT_OUTPUT |= _BV(LED_BIT);
65 | }else{ /* clear LED */
66 | LED_PORT_OUTPUT &= ~_BV(LED_BIT);
67 | }
68 | }else if(rq->bRequest == CUSTOM_RQ_GET_STATUS){
69 | static uchar dataBuffer[1]; /* buffer must stay valid when usbFunctionSetup returns */
70 | dataBuffer[0] = ((LED_PORT_OUTPUT & _BV(LED_BIT)) != 0);
71 | usbMsgPtr = dataBuffer; /* tell the driver which data to return */
72 | return 1; /* tell the driver to send 1 byte */
73 | }
74 | }else{
75 | /* calss requests USBRQ_HID_GET_REPORT and USBRQ_HID_SET_REPORT are
76 | * not implemented since we never call them. The operating system
77 | * won't call them either because our descriptor defines no meaning.
78 | */
79 | }
80 | return 0; /* default for not implemented requests: return no data back to host */
81 | }
82 |
83 | /* ------------------------------------------------------------------------- */
84 |
85 | int __attribute__((noreturn)) main(void)
86 | {
87 | uchar i;
88 |
89 | wdt_enable(WDTO_1S);
90 | /* If you don't use the watchdog, replace the call above with a wdt_disable().
91 | * On newer devices, the status of the watchdog (on/off, period) is PRESERVED
92 | * OVER RESET!
93 | */
94 | /* RESET status: all port bits are inputs without pull-up.
95 | * That's the way we need D+ and D-. Therefore we don't need any
96 | * additional hardware initialization.
97 | */
98 | odDebugInit();
99 | DBG1(0x00, 0, 0); /* debug output: main starts */
100 | usbInit();
101 | usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
102 | i = 0;
103 | while(--i){ /* fake USB disconnect for > 250 ms */
104 | wdt_reset();
105 | _delay_ms(1);
106 | }
107 | usbDeviceConnect();
108 | LED_PORT_DDR |= _BV(LED_BIT); /* make the LED bit an output */
109 | sei();
110 | DBG1(0x01, 0, 0); /* debug output: main loop starts */
111 | for(;;){ /* main event loop */
112 | #if 0 /* this is a bit too aggressive for a debug output */
113 | DBG2(0x02, 0, 0); /* debug output: main loop iterates */
114 | #endif
115 | wdt_reset();
116 | usbPoll();
117 | }
118 | }
119 |
120 | /* ------------------------------------------------------------------------- */
121 |
--------------------------------------------------------------------------------
/examples/hid-custom-rq/firmware/requests.h:
--------------------------------------------------------------------------------
1 | /* Name: requests.h
2 | * Project: custom-class, a basic USB example
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-09
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | /* This header is shared between the firmware and the host software. It
11 | * defines the USB request numbers (and optionally data types) used to
12 | * communicate between the host and the device.
13 | */
14 |
15 | #ifndef __REQUESTS_H_INCLUDED__
16 | #define __REQUESTS_H_INCLUDED__
17 |
18 | #define CUSTOM_RQ_SET_STATUS 1
19 | /* Set the LED status. Control-OUT.
20 | * The requested status is passed in the "wValue" field of the control
21 | * transfer. No OUT data is sent. Bit 0 of the low byte of wValue controls
22 | * the LED.
23 | */
24 |
25 | #define CUSTOM_RQ_GET_STATUS 2
26 | /* Get the current LED status. Control-IN.
27 | * This control transfer involves a 1 byte data phase where the device sends
28 | * the current status to the host. The status is in bit 0 of the byte.
29 | */
30 |
31 | #endif /* __REQUESTS_H_INCLUDED__ */
32 |
--------------------------------------------------------------------------------
/examples/hid-custom-rq/make-files.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Author: Christian Starkjohann
3 | # Creation Date: 2008-04-17
4 | # Tabsize: 4
5 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
6 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
7 |
8 |
9 | if [ "$1" = remove ]; then
10 | (cd firmware; make clean)
11 | rm -f firmware/usbconfig.h
12 | rm -rf firmware/usbdrv
13 | rm -f firmware/Makefile
14 | rm -rf commandline
15 | exit
16 | fi
17 |
18 | cat << \EOF | sed -n -f /dev/stdin ../../usbdrv/usbconfig-prototype.h >firmware/usbconfig.h
19 | /^\( [*] \)\{0,1\}[+].*$/ d
20 | s/^#define USB_CFG_DMINUS_BIT .*$/#define USB_CFG_DMINUS_BIT 4/g
21 | s|^.*#define USB_CFG_CLOCK_KHZ.*$|#define USB_CFG_CLOCK_KHZ (F_CPU/1000)|g
22 | s/^#define USB_CFG_HAVE_INTRIN_ENDPOINT .*$/#define USB_CFG_HAVE_INTRIN_ENDPOINT 1/g
23 | s|^#define USB_CFG_DEVICE_ID .*$|#define USB_CFG_DEVICE_ID 0xdf, 0x05 /* obdev's shared PID for HIDs */|g
24 | s/^#define USB_CFG_DEVICE_NAME .*$/#define USB_CFG_DEVICE_NAME 'L', 'E', 'D', 'C', 't', 'l', 'H', 'I', 'D'/g
25 | s/^#define USB_CFG_DEVICE_NAME_LEN .*$/#define USB_CFG_DEVICE_NAME_LEN 9/g
26 |
27 | s/^#define USB_CFG_INTR_POLL_INTERVAL .*$/#define USB_CFG_INTR_POLL_INTERVAL 100/g
28 | s/^#define USB_CFG_MAX_BUS_POWER .*$/#define USB_CFG_MAX_BUS_POWER 40/g
29 | s/^#define USB_CFG_DEVICE_CLASS .*$/#define USB_CFG_DEVICE_CLASS 0/g
30 | s/^#define USB_CFG_INTERFACE_CLASS .*$/#define USB_CFG_INTERFACE_CLASS 3/g
31 | s/^.*#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH.*$/#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 22/g
32 | p
33 | EOF
34 |
35 | cat << \EOF | sed -n -f /dev/stdin ../custom-class/firmware/Makefile >firmware/Makefile
36 | /^\( [*] \)\{0,1\}[+].*$/ d
37 | s/^# Project: .*$/# Project: hid-custom-rq example/g
38 | p
39 | EOF
40 |
41 | mkdir commandline 2>/dev/null
42 | cat << \EOF | sed -n -f /dev/stdin ../custom-class/commandline/set-led.c >commandline/set-led.c
43 | /^\( [*] \)\{0,1\}[+].*$/ d
44 | s/^ [*] Project: .*$/ * Project: hid-custom-rq example/g
45 | p
46 | EOF
47 |
48 | cat << \EOF | sed -n -f /dev/stdin ../usbtool/Makefile.windows >commandline/Makefile.windows
49 | /^\( [*] \)\{0,1\}[+].*$/ d
50 | s/^# Project: .*$/# Project: hid-custom-rq example/g
51 | p
52 | EOF
53 |
54 | cat << \EOF | sed -n -f /dev/stdin ../usbtool/Makefile >commandline/Makefile
55 | /^\( [*] \)\{0,1\}[+].*$/ d
56 | s/^# Project: .*$/# Project: hid-custom-rq example/g
57 | s/^NAME = .*$/NAME = set-led/g
58 | p
59 | EOF
60 |
61 | cp ../../libs-host/opendevice.[ch] commandline/
62 |
--------------------------------------------------------------------------------
/examples/hid-data/Readme.txt:
--------------------------------------------------------------------------------
1 | This is the Readme file for the hid-data example. In this example, we show
2 | how blocks of data can be exchanged with the device using only functionality
3 | compliant to the HID class. Since class drivers for HID are included with
4 | Windows, you don't need to install drivers on Windows.
5 |
6 |
7 | WHAT IS DEMONSTRATED?
8 | =====================
9 | This example demonstrates how the HID class can be misused to transfer fixed
10 | size blocks of data (up to the driver's transfer size limit) over HID feature
11 | reports. This technique is of great value on Windows because no driver DLLs
12 | are needed (the hid-custom-rq example still requires the libusb-win32 DLL,
13 | although it may be in the program's directory). The host side application
14 | requires no installation, it can even be started directly from a CD. This
15 | example also demonstrates how to transfer data using usbFunctionWrite() and
16 | usbFunctionRead().
17 |
18 |
19 | PREREQUISITES
20 | =============
21 | Target hardware: You need an AVR based circuit based on one of the examples
22 | (see the "circuits" directory at the top level of this package), e.g. the
23 | metaboard (http://www.obdev.at/goto.php?t=metaboard).
24 |
25 | AVR development environment: You need the gcc tool chain for the AVR, see
26 | the Prerequisites section in the top level Readme file for how to obtain it.
27 |
28 | Host development environment: A C compiler and libusb on Unix. On Windows
29 | you need the Driver Development Kit (DDK) Instead of libusb. MinGW ships
30 | with a free version of the DDK.
31 |
32 |
33 | BUILDING THE FIRMWARE
34 | =====================
35 | Change to the "firmware" directory and modify Makefile according to your
36 | architecture (CPU clock, target device, fuse values) and ISP programmer. Then
37 | edit usbconfig.h according to your pin assignments for D+ and D-. The default
38 | settings are for the metaboard hardware.
39 |
40 | Type "make hex" to build main.hex, then "make flash" to upload the firmware
41 | to the device. Don't forget to run "make fuse" once to program the fuses. If
42 | you use a prototyping board with boot loader, follow the instructions of the
43 | boot loader instead.
44 |
45 | Please note that the first "make hex" copies the driver from the top level
46 | into the firmware directory. If you use a different build system than our
47 | Makefile, you must copy the driver by hand.
48 |
49 |
50 | BUILDING THE HOST SOFTWARE
51 | ==========================
52 | Make sure that you have libusb (on Unix) or the DDK (on Windows) installed.
53 | We recommend MinGW on Windows since it includes a free version of the DDK.
54 | Then change to directory "commandline" and run "make" on Unix or
55 | "make -f Makefile.windows" on Windows.
56 |
57 |
58 | USING THE COMMAND LINE TOOL
59 | ===========================
60 | The device implements a data store of 128 bytes in EEPROM. You can send a
61 | block of 128 bytes to the device or read the block using the command line
62 | tool.
63 |
64 | To send a block to the device, use e.g.
65 |
66 | hidtool write 0x01,0x02,0x03,0x04,...
67 |
68 | and to receive the block, use
69 |
70 | hidtool read
71 |
72 |
73 | ----------------------------------------------------------------------------
74 | (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH.
75 | http://www.obdev.at/
76 |
--------------------------------------------------------------------------------
/examples/hid-data/commandline/Makefile:
--------------------------------------------------------------------------------
1 | # Name: Makefile
2 | # Project: hid-data example
3 | # Author: Christian Starkjohann
4 | # Creation Date: 2008-04-11
5 | # Tabsize: 4
6 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 |
9 | # Please read the definitions below and edit them as appropriate for your
10 | # system:
11 |
12 | # Use the following 3 lines on Unix and Mac OS X:
13 | USBFLAGS= `pkg-config --cflags libusb-1.0`
14 | USBLIBS= `pkg-config --libs libusb-1.0`
15 | EXE_SUFFIX=
16 |
17 | # Use the following 3 lines on Windows and comment out the 3 above:
18 | #USBFLAGS = -I/usr/local/include/libusb-1.0
19 | #USBLIBS = -L/usr/local/lib -lhid -lusb-1.0 -lsetupapi
20 | #EXE_SUFFIX = .exe
21 |
22 | CC= gcc
23 | CFLAGS= -O -Wall $(USBFLAGS)
24 | LIBS= $(USBLIBS)
25 |
26 | OBJ= hidtool.o hiddata.o
27 | PROGRAM= hidtool$(EXE_SUFFIX)
28 |
29 | all: $(PROGRAM)
30 |
31 | $(PROGRAM): $(OBJ)
32 | $(CC) -o $(PROGRAM) $(OBJ) $(LIBS)
33 |
34 | strip: $(PROGRAM)
35 | strip $(PROGRAM)
36 |
37 | clean:
38 | rm -f $(OBJ) $(PROGRAM)
39 |
40 | .c.o:
41 | $(CC) $(ARCH_COMPILE) $(CFLAGS) -c $*.c -o $*.o
42 |
--------------------------------------------------------------------------------
/examples/hid-data/commandline/Makefile.windows:
--------------------------------------------------------------------------------
1 | # Name: Makefile.windows
2 | # Project: hid-data example
3 | # Author: Christian Starkjohann
4 | # Creation Date: 2008-04-11
5 | # Tabsize: 4
6 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 |
9 | # You may use this file with
10 | # make -f Makefile.windows
11 | # on Windows with MinGW instead of editing the main Makefile.
12 |
13 | include Makefile
14 |
15 | USBFLAGS = -I/usr/local/mingw/include/libusb-1.0
16 | USBLIBS = -L/usr/local/mingw/lib -lhid -lusb-1.0 -lsetupapi
17 | EXE_SUFFIX= .exe
18 |
--------------------------------------------------------------------------------
/examples/hid-data/commandline/hidtool.c:
--------------------------------------------------------------------------------
1 | /* Name: hidtool.c
2 | * Project: hid-data example
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-11
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | #include
11 | #include
12 | #include
13 | #include "hiddata.h"
14 | #include "../firmware/usbconfig.h" /* for device VID, PID, vendor name and product name */
15 |
16 | /* ------------------------------------------------------------------------- */
17 |
18 | static char *usbErrorMessage(int errCode)
19 | {
20 | static char buffer[80];
21 |
22 | switch(errCode){
23 | case USBOPEN_ERR_ACCESS: return "Access to device denied";
24 | case USBOPEN_ERR_NOTFOUND: return "The specified device was not found";
25 | case USBOPEN_ERR_IO: return "Communication error with device";
26 | default:
27 | sprintf(buffer, "Unknown USB error %d", errCode);
28 | return buffer;
29 | }
30 | return NULL; /* not reached */
31 | }
32 |
33 | static usbDevice_t *openDevice(void)
34 | {
35 | usbDevice_t *dev = NULL;
36 | unsigned char rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID};
37 | char vendorName[] = {USB_CFG_VENDOR_NAME, 0}, productName[] = {USB_CFG_DEVICE_NAME, 0};
38 | int vid = rawVid[0] + 256 * rawVid[1];
39 | int pid = rawPid[0] + 256 * rawPid[1];
40 | int err;
41 |
42 | if((err = usbhidOpenDevice(&dev, vid, vendorName, pid, productName, 0)) != 0){
43 | fprintf(stderr, "error finding %s: %s\n", productName, usbErrorMessage(err));
44 | return NULL;
45 | }
46 | return dev;
47 | }
48 |
49 | /* ------------------------------------------------------------------------- */
50 |
51 | static void hexdump(char *buffer, int len)
52 | {
53 | int i;
54 | FILE *fp = stdout;
55 |
56 | for(i = 0; i < len; i++){
57 | if(i != 0){
58 | if(i % 16 == 0){
59 | fprintf(fp, "\n");
60 | }else{
61 | fprintf(fp, " ");
62 | }
63 | }
64 | fprintf(fp, "0x%02x", buffer[i] & 0xff);
65 | }
66 | if(i != 0)
67 | fprintf(fp, "\n");
68 | }
69 |
70 | static int hexread(char *buffer, char *string, int buflen)
71 | {
72 | char *s;
73 | int pos = 0;
74 |
75 | while((s = strtok(string, ", ")) != NULL && pos < buflen){
76 | string = NULL;
77 | buffer[pos++] = (char)strtol(s, NULL, 0);
78 | }
79 | return pos;
80 | }
81 |
82 | /* ------------------------------------------------------------------------- */
83 |
84 | static void usage(char *myName)
85 | {
86 | fprintf(stderr, "usage:\n");
87 | fprintf(stderr, " %s read\n", myName);
88 | fprintf(stderr, " %s write \n", myName);
89 | }
90 |
91 | int main(int argc, char **argv)
92 | {
93 | usbDevice_t *dev;
94 | char buffer[129]; /* room for dummy report ID */
95 | int err;
96 |
97 | if(argc < 2){
98 | usage(argv[0]);
99 | exit(1);
100 | }
101 | if((dev = openDevice()) == NULL)
102 | exit(1);
103 | if(strcasecmp(argv[1], "read") == 0){
104 | int len = sizeof(buffer);
105 | if((err = usbhidGetReport(dev, 0, buffer, &len)) != 0){
106 | fprintf(stderr, "error reading data: %s\n", usbErrorMessage(err));
107 | }else{
108 | hexdump(buffer + 1, sizeof(buffer) - 1);
109 | }
110 | }else if(strcasecmp(argv[1], "write") == 0){
111 | int i, pos;
112 | memset(buffer, 0, sizeof(buffer));
113 | for(pos = 1, i = 2; i < argc && pos < sizeof(buffer); i++){
114 | pos += hexread(buffer + pos, argv[i], sizeof(buffer) - pos);
115 | }
116 | if((err = usbhidSetReport(dev, buffer, sizeof(buffer))) != 0) /* add a dummy report ID */
117 | fprintf(stderr, "error writing data: %s\n", usbErrorMessage(err));
118 | }else{
119 | usage(argv[0]);
120 | exit(1);
121 | }
122 | usbhidCloseDevice(dev);
123 | return 0;
124 | }
125 |
126 | /* ------------------------------------------------------------------------- */
127 |
--------------------------------------------------------------------------------
/examples/hid-data/firmware/main.c:
--------------------------------------------------------------------------------
1 | /* Name: main.c
2 | * Project: hid-data, example how to use HID for data transfer
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-11
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | /*
11 | This example should run on most AVRs with only little changes. No special
12 | hardware resources except INT0 are used. You may have to change usbconfig.h for
13 | different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or
14 | at least be connected to INT0 as well.
15 | */
16 |
17 | #include
18 | #include
19 | #include /* for sei() */
20 | #include /* for _delay_ms() */
21 | #include
22 |
23 | #include /* required by usbdrv.h */
24 | #include "usbdrv.h"
25 | #include "oddebug.h" /* This is also an example for using debug macros */
26 |
27 | /* ------------------------------------------------------------------------- */
28 | /* ----------------------------- USB interface ----------------------------- */
29 | /* ------------------------------------------------------------------------- */
30 |
31 | PROGMEM const char usbHidReportDescriptor[22] = { /* USB report descriptor */
32 | 0x06, 0x00, 0xff, // USAGE_PAGE (Generic Desktop)
33 | 0x09, 0x01, // USAGE (Vendor Usage 1)
34 | 0xa1, 0x01, // COLLECTION (Application)
35 | 0x15, 0x00, // LOGICAL_MINIMUM (0)
36 | 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
37 | 0x75, 0x08, // REPORT_SIZE (8)
38 | 0x95, 0x80, // REPORT_COUNT (128)
39 | 0x09, 0x00, // USAGE (Undefined)
40 | 0xb2, 0x02, 0x01, // FEATURE (Data,Var,Abs,Buf)
41 | 0xc0 // END_COLLECTION
42 | };
43 | /* Since we define only one feature report, we don't use report-IDs (which
44 | * would be the first byte of the report). The entire report consists of 128
45 | * opaque data bytes.
46 | */
47 |
48 | /* The following variables store the status of the current data transfer */
49 | static uchar currentAddress;
50 | static uchar bytesRemaining;
51 |
52 | /* ------------------------------------------------------------------------- */
53 |
54 | /* usbFunctionRead() is called when the host requests a chunk of data from
55 | * the device. For more information see the documentation in usbdrv/usbdrv.h.
56 | */
57 | uchar usbFunctionRead(uchar *data, uchar len)
58 | {
59 | if(len > bytesRemaining)
60 | len = bytesRemaining;
61 | eeprom_read_block(data, (uchar *)0 + currentAddress, len);
62 | currentAddress += len;
63 | bytesRemaining -= len;
64 | return len;
65 | }
66 |
67 | /* usbFunctionWrite() is called when the host sends a chunk of data to the
68 | * device. For more information see the documentation in usbdrv/usbdrv.h.
69 | */
70 | uchar usbFunctionWrite(uchar *data, uchar len)
71 | {
72 | if(bytesRemaining == 0)
73 | return 1; /* end of transfer */
74 | if(len > bytesRemaining)
75 | len = bytesRemaining;
76 | eeprom_write_block(data, (uchar *)0 + currentAddress, len);
77 | currentAddress += len;
78 | bytesRemaining -= len;
79 | return bytesRemaining == 0; /* return 1 if this was the last chunk */
80 | }
81 |
82 | /* ------------------------------------------------------------------------- */
83 |
84 | usbMsgLen_t usbFunctionSetup(uchar data[8])
85 | {
86 | usbRequest_t *rq = (void *)data;
87 |
88 | if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* HID class request */
89 | if(rq->bRequest == USBRQ_HID_GET_REPORT){ /* wValue: ReportType (highbyte), ReportID (lowbyte) */
90 | /* since we have only one report type, we can ignore the report-ID */
91 | bytesRemaining = 128;
92 | currentAddress = 0;
93 | return USB_NO_MSG; /* use usbFunctionRead() to obtain data */
94 | }else if(rq->bRequest == USBRQ_HID_SET_REPORT){
95 | /* since we have only one report type, we can ignore the report-ID */
96 | bytesRemaining = 128;
97 | currentAddress = 0;
98 | return USB_NO_MSG; /* use usbFunctionWrite() to receive data from host */
99 | }
100 | }else{
101 | /* ignore vendor type requests, we don't use any */
102 | }
103 | return 0;
104 | }
105 |
106 | /* ------------------------------------------------------------------------- */
107 |
108 | int main(void)
109 | {
110 | uchar i;
111 |
112 | wdt_enable(WDTO_1S);
113 | /* If you don't use the watchdog, replace the call above with a wdt_disable().
114 | * On newer devices, the status of the watchdog (on/off, period) is PRESERVED
115 | * OVER RESET!
116 | */
117 | /* RESET status: all port bits are inputs without pull-up.
118 | * That's the way we need D+ and D-. Therefore we don't need any
119 | * additional hardware initialization.
120 | */
121 | odDebugInit();
122 | DBG1(0x00, 0, 0); /* debug output: main starts */
123 | usbInit();
124 | usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
125 | i = 0;
126 | while(--i){ /* fake USB disconnect for > 250 ms */
127 | wdt_reset();
128 | _delay_ms(1);
129 | }
130 | usbDeviceConnect();
131 | sei();
132 | DBG1(0x01, 0, 0); /* debug output: main loop starts */
133 | for(;;){ /* main event loop */
134 | DBG1(0x02, 0, 0); /* debug output: main loop iterates */
135 | wdt_reset();
136 | usbPoll();
137 | }
138 | return 0;
139 | }
140 |
141 | /* ------------------------------------------------------------------------- */
142 |
--------------------------------------------------------------------------------
/examples/hid-data/make-files.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Author: Christian Starkjohann
3 | # Creation Date: 2008-04-17
4 | # Tabsize: 4
5 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
6 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
7 |
8 |
9 | if [ "$1" = remove ]; then
10 | (cd firmware; make clean)
11 | rm -f firmware/usbconfig.h
12 | rm -rf firmware/usbdrv
13 | rm -f firmware/Makefile
14 | rm -f commandline/hiddata.[ch]
15 | rm -f commandline/hidsdi.h
16 | exit
17 | fi
18 |
19 | cat << \EOF | sed -n -f /dev/stdin ../../usbdrv/usbconfig-prototype.h >firmware/usbconfig.h
20 | /^\( [*] \)\{0,1\}[+].*$/ d
21 | s/^#define USB_CFG_DMINUS_BIT .*$/#define USB_CFG_DMINUS_BIT 4/g
22 | s|^.*#define USB_CFG_CLOCK_KHZ.*$|#define USB_CFG_CLOCK_KHZ (F_CPU/1000)|g
23 | s/^#define USB_CFG_HAVE_INTRIN_ENDPOINT .*$/#define USB_CFG_HAVE_INTRIN_ENDPOINT 1/g
24 | s|^#define USB_CFG_DEVICE_ID .*$|#define USB_CFG_DEVICE_ID 0xdf, 0x05 /* obdev's shared PID for HIDs */|g
25 | s/^#define USB_CFG_DEVICE_NAME .*$/#define USB_CFG_DEVICE_NAME 'D', 'a', 't', 'a', 'S', 't', 'o', 'r', 'e'/g
26 | s/^#define USB_CFG_DEVICE_NAME_LEN .*$/#define USB_CFG_DEVICE_NAME_LEN 9/g
27 |
28 | s/^#define USB_CFG_INTR_POLL_INTERVAL .*$/#define USB_CFG_INTR_POLL_INTERVAL 100/g
29 | s/^#define USB_CFG_MAX_BUS_POWER .*$/#define USB_CFG_MAX_BUS_POWER 20/g
30 | s/^#define USB_CFG_IMPLEMENT_FN_WRITE .*$/#define USB_CFG_IMPLEMENT_FN_WRITE 1/g
31 | s/^#define USB_CFG_IMPLEMENT_FN_READ .*$/#define USB_CFG_IMPLEMENT_FN_READ 1/g
32 | s/^#define USB_CFG_DEVICE_CLASS .*$/#define USB_CFG_DEVICE_CLASS 0/g
33 | s/^#define USB_CFG_INTERFACE_CLASS .*$/#define USB_CFG_INTERFACE_CLASS 3/g
34 | s/^.*#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH.*$/#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 22/g
35 | p
36 | EOF
37 |
38 | cat << \EOF | sed -n -f /dev/stdin ../custom-class/firmware/Makefile >firmware/Makefile
39 | /^\( [*] \)\{0,1\}[+].*$/ d
40 | s/^# Project: .*$/# Project: hid-data example/g
41 | p
42 | EOF
43 |
44 | cp ../../libs-host/hiddata.[ch] ../../libs-host/hidsdi.h commandline
45 |
--------------------------------------------------------------------------------
/examples/hid-mouse/Readme.txt:
--------------------------------------------------------------------------------
1 | This is the Readme file for hid-mouse, an example of a USB mouse device. In
2 | order to have as little dependencies on hardware and architecture as
3 | possible, mouse movements are computed internally so that the mouse pointer
4 | moves in a circle.
5 |
6 |
7 | WHAT IS DEMONSTRATED?
8 | =====================
9 | This example demonstrates how HID class devices are implemented. The example
10 | is kept as simple as possible, except the report descriptor which is taken
11 | from a real-world mouse.
12 |
13 | It does NOT include a host side driver because all modern operating systems
14 | include one. It does NOT implement USBRQ_HID_SET_REPORT and report-IDs. See
15 | the "hid-data" example for this topic. It does NOT implement any special
16 | features such as suspend mode etc.
17 |
18 |
19 | PREREQUISITES
20 | =============
21 | Target hardware: You need an AVR based circuit based on one of the examples
22 | (see the "circuits" directory at the top level of this package), e.g. the
23 | metaboard (http://www.obdev.at/goto.php?t=metaboard).
24 |
25 | AVR development environment: You need the gcc tool chain for the AVR, see
26 | the Prerequisites section in the top level Readme file for how to obtain it.
27 |
28 |
29 | BUILDING THE FIRMWARE
30 | =====================
31 | Change to the "firmware" directory and modify Makefile according to your
32 | architecture (CPU clock, target device, fuse values) and ISP programmer. Then
33 | edit usbconfig.h according to your pin assignments for D+ and D-. The default
34 | settings are for the metaboard hardware.
35 |
36 | Type "make hex" to build main.hex, then "make flash" to upload the firmware
37 | to the device. Don't forget to run "make fuse" once to program the fuses. If
38 | you use a prototyping board with boot loader, follow the instructions of the
39 | boot loader instead.
40 |
41 | Please note that the first "make hex" copies the driver from the top level
42 | into the firmware directory. If you use a different build system than our
43 | Makefile, you must copy the driver by hand.
44 |
45 |
46 | ----------------------------------------------------------------------------
47 | (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH.
48 | http://www.obdev.at/
49 |
--------------------------------------------------------------------------------
/examples/hid-mouse/firmware/main.c:
--------------------------------------------------------------------------------
1 | /* Name: main.c
2 | * Project: hid-mouse, a very simple HID example
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-07
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | /*
11 | This example should run on most AVRs with only little changes. No special
12 | hardware resources except INT0 are used. You may have to change usbconfig.h for
13 | different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or
14 | at least be connected to INT0 as well.
15 |
16 | We use VID/PID 0x046D/0xC00E which is taken from a Logitech mouse. Don't
17 | publish any hardware using these IDs! This is for demonstration only!
18 | */
19 |
20 | #include
21 | #include
22 | #include /* for sei() */
23 | #include /* for _delay_ms() */
24 |
25 | #include /* required by usbdrv.h */
26 | #include "usbdrv.h"
27 | #include "oddebug.h" /* This is also an example for using debug macros */
28 |
29 | /* ------------------------------------------------------------------------- */
30 | /* ----------------------------- USB interface ----------------------------- */
31 | /* ------------------------------------------------------------------------- */
32 |
33 | PROGMEM const char usbHidReportDescriptor[52] = { /* USB report descriptor, size must match usbconfig.h */
34 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
35 | 0x09, 0x02, // USAGE (Mouse)
36 | 0xa1, 0x01, // COLLECTION (Application)
37 | 0x09, 0x01, // USAGE (Pointer)
38 | 0xA1, 0x00, // COLLECTION (Physical)
39 | 0x05, 0x09, // USAGE_PAGE (Button)
40 | 0x19, 0x01, // USAGE_MINIMUM
41 | 0x29, 0x03, // USAGE_MAXIMUM
42 | 0x15, 0x00, // LOGICAL_MINIMUM (0)
43 | 0x25, 0x01, // LOGICAL_MAXIMUM (1)
44 | 0x95, 0x03, // REPORT_COUNT (3)
45 | 0x75, 0x01, // REPORT_SIZE (1)
46 | 0x81, 0x02, // INPUT (Data,Var,Abs)
47 | 0x95, 0x01, // REPORT_COUNT (1)
48 | 0x75, 0x05, // REPORT_SIZE (5)
49 | 0x81, 0x03, // INPUT (Const,Var,Abs)
50 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
51 | 0x09, 0x30, // USAGE (X)
52 | 0x09, 0x31, // USAGE (Y)
53 | 0x09, 0x38, // USAGE (Wheel)
54 | 0x15, 0x81, // LOGICAL_MINIMUM (-127)
55 | 0x25, 0x7F, // LOGICAL_MAXIMUM (127)
56 | 0x75, 0x08, // REPORT_SIZE (8)
57 | 0x95, 0x03, // REPORT_COUNT (3)
58 | 0x81, 0x06, // INPUT (Data,Var,Rel)
59 | 0xC0, // END_COLLECTION
60 | 0xC0, // END COLLECTION
61 | };
62 | /* This is the same report descriptor as seen in a Logitech mouse. The data
63 | * described by this descriptor consists of 4 bytes:
64 | * . . . . . B2 B1 B0 .... one byte with mouse button states
65 | * X7 X6 X5 X4 X3 X2 X1 X0 .... 8 bit signed relative coordinate x
66 | * Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 .... 8 bit signed relative coordinate y
67 | * W7 W6 W5 W4 W3 W2 W1 W0 .... 8 bit signed relative coordinate wheel
68 | */
69 | typedef struct{
70 | uchar buttonMask;
71 | char dx;
72 | char dy;
73 | char dWheel;
74 | }report_t;
75 |
76 | static report_t reportBuffer;
77 | static int sinus = 7 << 6, cosinus = 0;
78 | static uchar idleRate; /* repeat rate for keyboards, never used for mice */
79 |
80 |
81 | /* The following function advances sin/cos by a fixed angle
82 | * and stores the difference to the previous coordinates in the report
83 | * descriptor.
84 | * The algorithm is the simulation of a second order differential equation.
85 | */
86 | static void advanceCircleByFixedAngle(void)
87 | {
88 | char d;
89 |
90 | #define DIVIDE_BY_64(val) (val + (val > 0 ? 32 : -32)) >> 6 /* rounding divide */
91 | reportBuffer.dx = d = DIVIDE_BY_64(cosinus);
92 | sinus += d;
93 | reportBuffer.dy = d = DIVIDE_BY_64(sinus);
94 | cosinus -= d;
95 | }
96 |
97 | /* ------------------------------------------------------------------------- */
98 |
99 | usbMsgLen_t usbFunctionSetup(uchar data[8])
100 | {
101 | usbRequest_t *rq = (void *)data;
102 |
103 | /* The following requests are never used. But since they are required by
104 | * the specification, we implement them in this example.
105 | */
106 | if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* class request type */
107 | DBG1(0x50, &rq->bRequest, 1); /* debug output: print our request */
108 | if(rq->bRequest == USBRQ_HID_GET_REPORT){ /* wValue: ReportType (highbyte), ReportID (lowbyte) */
109 | /* we only have one report type, so don't look at wValue */
110 | usbMsgPtr = (void *)&reportBuffer;
111 | return sizeof(reportBuffer);
112 | }else if(rq->bRequest == USBRQ_HID_GET_IDLE){
113 | usbMsgPtr = &idleRate;
114 | return 1;
115 | }else if(rq->bRequest == USBRQ_HID_SET_IDLE){
116 | idleRate = rq->wValue.bytes[1];
117 | }
118 | }else{
119 | /* no vendor specific requests implemented */
120 | }
121 | return 0; /* default for not implemented requests: return no data back to host */
122 | }
123 |
124 | /* ------------------------------------------------------------------------- */
125 |
126 | int __attribute__((noreturn)) main(void)
127 | {
128 | uchar i;
129 |
130 | wdt_enable(WDTO_1S);
131 | /* If you don't use the watchdog, replace the call above with a wdt_disable().
132 | * On newer devices, the status of the watchdog (on/off, period) is PRESERVED
133 | * OVER RESET!
134 | */
135 | /* RESET status: all port bits are inputs without pull-up.
136 | * That's the way we need D+ and D-. Therefore we don't need any
137 | * additional hardware initialization.
138 | */
139 | odDebugInit();
140 | DBG1(0x00, 0, 0); /* debug output: main starts */
141 | usbInit();
142 | usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
143 | i = 0;
144 | while(--i){ /* fake USB disconnect for > 250 ms */
145 | wdt_reset();
146 | _delay_ms(1);
147 | }
148 | usbDeviceConnect();
149 | sei();
150 | DBG1(0x01, 0, 0); /* debug output: main loop starts */
151 | for(;;){ /* main event loop */
152 | DBG1(0x02, 0, 0); /* debug output: main loop iterates */
153 | wdt_reset();
154 | usbPoll();
155 | if(usbInterruptIsReady()){
156 | /* called after every poll of the interrupt endpoint */
157 | advanceCircleByFixedAngle();
158 | DBG1(0x03, 0, 0); /* debug output: interrupt report prepared */
159 | usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
160 | }
161 | }
162 | }
163 |
164 | /* ------------------------------------------------------------------------- */
165 |
--------------------------------------------------------------------------------
/examples/hid-mouse/make-files.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Author: Christian Starkjohann
3 | # Creation Date: 2008-04-17
4 | # Tabsize: 4
5 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
6 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
7 |
8 |
9 | if [ "$1" = remove ]; then
10 | (cd firmware; make clean)
11 | rm -f firmware/usbconfig.h
12 | rm -rf firmware/usbdrv
13 | rm -f firmware/Makefile
14 | exit
15 | fi
16 |
17 | cat << \EOF | sed -n -f /dev/stdin ../../usbdrv/usbconfig-prototype.h >firmware/usbconfig.h
18 | /^\( [*] \)\{0,1\}[+].*$/ d
19 | s/^#define USB_CFG_DMINUS_BIT .*$/#define USB_CFG_DMINUS_BIT 4/g
20 | s|^.*#define USB_CFG_CLOCK_KHZ.*$|#define USB_CFG_CLOCK_KHZ (F_CPU/1000)|g
21 | s/^#define USB_CFG_HAVE_INTRIN_ENDPOINT .*$/#define USB_CFG_HAVE_INTRIN_ENDPOINT 1/g
22 | s|^#define USB_CFG_DEVICE_ID .*$|#define USB_CFG_DEVICE_ID 0xe8, 0x03 /* VOTI's lab use PID */|g
23 | s/^#define USB_CFG_DEVICE_NAME .*$/#define USB_CFG_DEVICE_NAME 'M', 'o', 'u', 's', 'e'/g
24 | s/^#define USB_CFG_DEVICE_NAME_LEN .*$/#define USB_CFG_DEVICE_NAME_LEN 5/g
25 |
26 | s/^#define USB_CFG_INTR_POLL_INTERVAL .*$/#define USB_CFG_INTR_POLL_INTERVAL 100/g
27 | s/^#define USB_CFG_MAX_BUS_POWER .*$/#define USB_CFG_MAX_BUS_POWER 20/g
28 | s/^#define USB_CFG_DEVICE_CLASS .*$/#define USB_CFG_DEVICE_CLASS 0/g
29 | s/^#define USB_CFG_INTERFACE_CLASS .*$/#define USB_CFG_INTERFACE_CLASS 3/g
30 | s/^.*#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH.*$/#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 52/g
31 | p
32 | EOF
33 |
34 | cat << \EOF | sed -n -f /dev/stdin ../custom-class/firmware/Makefile >firmware/Makefile
35 | /^\( [*] \)\{0,1\}[+].*$/ d
36 | s/^# Project: .*$/# Project: hid-mouse example/g
37 | p
38 | EOF
39 |
--------------------------------------------------------------------------------
/examples/usbtool/Makefile:
--------------------------------------------------------------------------------
1 | # Name: Makefile
2 | # Project: usbtool
3 | # Author: Christian Starkjohann
4 | # Creation Date: 2008-04-06
5 | # Tabsize: 4
6 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 |
9 |
10 | # Concigure the following definitions according to your system.
11 | # This Makefile has been tested on Mac OS X, Linux and Windows.
12 |
13 | # Use the following 3 lines on Unix (uncomment the framework on Mac OS X):
14 | USBFLAGS = `pkg-config --cflags libusb-1.0`
15 | USBLIBS = `pkg-config --libs libusb-1.0`
16 | EXE_SUFFIX =
17 |
18 | # Use the following 3 lines on Windows and comment out the 3 above. You may
19 | # have to change the include paths to where you installed libusb-win32
20 | #USBFLAGS = -I/usr/local/include/libusb-1.0
21 | #USBLIBS = -L/usr/local/lib -lusb-1.0
22 | #EXE_SUFFIX = .exe
23 |
24 | NAME = usbtool
25 |
26 | OBJECTS = opendevice.o $(NAME).o
27 |
28 | CC = gcc
29 | CFLAGS = $(CPPFLAGS) $(USBFLAGS) -O -g -Wall
30 | LIBS = $(USBLIBS)
31 |
32 | PROGRAM = $(NAME)$(EXE_SUFFIX)
33 |
34 |
35 | all: $(PROGRAM)
36 |
37 | .c.o:
38 | $(CC) $(CFLAGS) -c $<
39 |
40 | $(PROGRAM): $(OBJECTS)
41 | $(CC) -o $(PROGRAM) $(OBJECTS) $(LIBS)
42 |
43 | strip: $(PROGRAM)
44 | strip $(PROGRAM)
45 |
46 | clean:
47 | rm -f *.o $(PROGRAM)
48 |
--------------------------------------------------------------------------------
/examples/usbtool/Makefile.windows:
--------------------------------------------------------------------------------
1 | # Name: Makefile.windows
2 | # Project: usbtool
3 | # Author: Christian Starkjohann
4 | # Creation Date: 2008-04-06
5 | # Tabsize: 4
6 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 |
9 | # You may use this file with
10 | # make -f Makefile.windows
11 | # on Windows with MinGW instead of editing the main Makefile.
12 |
13 | include Makefile
14 |
15 | USBFLAGS = -I/usr/local/mingw/include/libusb-1.0
16 | USBLIBS = -L/usr/local/mingw/lib -lusb-1.0
17 | EXE_SUFFIX = .exe
18 |
--------------------------------------------------------------------------------
/examples/usbtool/make-files.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Author: Christian Starkjohann
3 | # Creation Date: 2008-04-17
4 | # Tabsize: 4
5 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
6 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
7 |
8 |
9 | if [ "$1" = remove ]; then
10 | make clean
11 | rm -f opendevice.[ch]
12 | exit
13 | fi
14 |
15 | cp ../../libs-host/opendevice.[ch] .
16 |
--------------------------------------------------------------------------------
/libs-device/Readme.txt:
--------------------------------------------------------------------------------
1 | This is the Readme file for the libs-device directory. This directory contains
2 | code snippets which may be useful for USB device firmware.
3 |
4 |
5 | WHAT IS INCLUDED IN THIS DIRECTORY?
6 | ===================================
7 |
8 | osccal.c and osccal.h
9 | This module contains a function which calibrates the AVR's built-in RC
10 | oscillator based on the USB frame clock. See osccal.h for a documentation
11 | of the API.
12 |
13 | osctune.h
14 | This header file contains a code snippet for usbconfig.h. With this code,
15 | you can keep the AVR's internal RC oscillator in sync with the USB frame
16 | clock. This is a continuous synchronization, not a single calibration at
17 | USB reset as with osccal.c above. Please note that this code works only
18 | if D- is wired to the interrupt, not D+.
19 |
20 | ----------------------------------------------------------------------------
21 | (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH.
22 | http://www.obdev.at/
23 |
--------------------------------------------------------------------------------
/libs-device/osccal.c:
--------------------------------------------------------------------------------
1 | /* Name: osccal.c
2 | * Author: Christian Starkjohann
3 | * Creation Date: 2008-04-10
4 | * Tabsize: 4
5 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
6 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
7 | */
8 |
9 | #include
10 |
11 | #ifndef uchar
12 | #define uchar unsigned char
13 | #endif
14 |
15 | /* ------------------------------------------------------------------------- */
16 | /* ------------------------ Oscillator Calibration ------------------------- */
17 | /* ------------------------------------------------------------------------- */
18 |
19 | /* This is a "C" implementation. You can customize it to your needs easily.
20 | * If you want smaller code size, there is an improved version in the
21 | * micronucleous project. See
22 | * https://github.com/micronucleus/micronucleus/blob/master/firmware/osccalASM.S
23 | */
24 |
25 | /* Calibrate the RC oscillator. Our timing reference is the Start Of Frame
26 | * signal (a single SE0 bit) repeating every millisecond immediately after
27 | * a USB RESET. We first do a binary search for the OSCCAL value and then
28 | * optimize this value with a neighboorhod search.
29 | */
30 | void calibrateOscillator(void)
31 | {
32 | uchar step = 128;
33 | uchar trialValue = 0, optimumValue;
34 | int x, optimumDev, targetValue = (unsigned)(1499 * (double)F_CPU / 10.5e6 + 0.5);
35 |
36 | /* do a binary search: */
37 | do{
38 | OSCCAL = trialValue + step;
39 | x = usbMeasureFrameLength(); /* proportional to current real frequency */
40 | if(x < targetValue) /* frequency still too low */
41 | trialValue += step;
42 | step >>= 1;
43 | }while(step > 0);
44 | /* We have a precision of +/- 1 for optimum OSCCAL here */
45 | /* now do a neighborhood search for optimum value */
46 | optimumValue = trialValue;
47 | optimumDev = x; /* this is certainly far away from optimum */
48 | for(OSCCAL = trialValue - 1; OSCCAL <= trialValue + 1; OSCCAL++){
49 | x = usbMeasureFrameLength() - targetValue;
50 | if(x < 0)
51 | x = -x;
52 | if(x < optimumDev){
53 | optimumDev = x;
54 | optimumValue = OSCCAL;
55 | }
56 | }
57 | OSCCAL = optimumValue;
58 | }
59 | /*
60 | Note: This calibration algorithm may try OSCCAL values of up to 192 even if
61 | the optimum value is far below 192. It may therefore exceed the allowed clock
62 | frequency of the CPU in low voltage designs!
63 | You may replace this search algorithm with any other algorithm you like if
64 | you have additional constraints such as a maximum CPU clock.
65 | For version 5.x RC oscillators (those with a split range of 2x128 steps, e.g.
66 | ATTiny25, ATTiny45, ATTiny85), it may be useful to search for the optimum in
67 | both regions.
68 | */
69 |
--------------------------------------------------------------------------------
/libs-device/osccal.h:
--------------------------------------------------------------------------------
1 | /* Name: osccal.h
2 | * Author: Christian Starkjohann
3 | * Creation Date: 2008-04-10
4 | * Tabsize: 4
5 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
6 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
7 | */
8 |
9 | /*
10 | General Description:
11 | This module contains a function which calibrates the AVR's internal RC
12 | oscillator so that the CPU runs at F_CPU (F_CPU is a macro which must be
13 | defined when the module is compiled, best passed in the compiler command
14 | line). The time reference is the USB frame clock of 1 kHz available
15 | immediately after a USB RESET condition. Timing is done by counting CPU
16 | cycles, so all interrupts must be disabled while the calibration runs. For
17 | low level timing measurements, usbMeasureFrameLength() is called. This
18 | function must be enabled in usbconfig.h by defining
19 | USB_CFG_HAVE_MEASURE_FRAME_LENGTH to 1. It is recommended to call
20 | calibrateOscillator() from the reset hook in usbconfig.h:
21 |
22 | #ifndef __ASSEMBLER__
23 | #include // for sei()
24 | extern void calibrateOscillator(void);
25 | #endif
26 | #define USB_RESET_HOOK(resetStarts) if(!resetStarts){cli(); calibrateOscillator(); sei();}
27 |
28 | This routine is an alternative to the continuous synchronization described
29 | in osctune.h.
30 |
31 | Algorithm used:
32 | calibrateOscillator() first does a binary search in the OSCCAL register for
33 | the best matching oscillator frequency. Then it does a next neighbor search
34 | to find the value with the lowest clock rate deviation. It is guaranteed to
35 | find the best match among neighboring values, but for version 5 oscillators
36 | (which have a discontinuous relationship between OSCCAL and frequency) a
37 | better match might be available in another OSCCAL region.
38 |
39 | Limitations:
40 | This calibration algorithm may try OSCCAL values of up to 192 even if the
41 | optimum value is far below 192. It may therefore exceed the allowed clock
42 | frequency of the CPU in low voltage designs!
43 | Precision depends on the OSCCAL vs. frequency dependency of the oscillator.
44 | Typical precision for an ATMega168 (derived from the OSCCAL vs. F_RC diagram
45 | in the data sheet) should be in the range of 0.4%. Only the 12.8 MHz and
46 | 16.5 MHz versions of V-USB (with built-in receiver PLL) can tolerate this
47 | deviation! All other frequency modules require at least 0.2% precision.
48 | */
49 |
50 | #ifndef __OSCCAL_H_INCLUDED__
51 | #define __OSCCAL_H_INCLUDED__
52 |
53 | void calibrateOscillator(void);
54 | /* This function calibrates the RC oscillator so that the CPU runs at F_CPU.
55 | * It MUST be called immediately after the end of a USB RESET condition!
56 | * Disable all interrupts during the call!
57 | * It is recommended that you store the resulting value in EEPROM so that a
58 | * good guess value is available after the next reset.
59 | */
60 |
61 |
62 | #endif /* __OSCCAL_H_INCLUDED__ */
63 |
--------------------------------------------------------------------------------
/libs-device/osctune.h:
--------------------------------------------------------------------------------
1 | /* Name: osctune.h
2 | * Author: Christian Starkjohann
3 | * Creation Date: 2008-10-18
4 | * Tabsize: 4
5 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
6 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
7 | */
8 |
9 | /*
10 | General Description:
11 | This file is declared as C-header file although it is mostly documentation
12 | how the RC oscillator can be kept in sync to the USB frame rate. The code
13 | shown here must be added to usbconfig.h or this header file is included from
14 | there. This code works only if D- is wired to the interrupt, not D+!!!
15 |
16 | This is an alternative to the osccal routine in osccal.c. It has the advantage
17 | that the synchronization is done continuously and that it has more compact
18 | code size. The disadvantages are slow synchronization (it may take a while
19 | until the driver works), that messages immediately after the SOF pulse may be
20 | lost (and need to be retried by the host) and that the interrupt is on D-
21 | contrary to most examples.
22 |
23 | You may want to store a good calibration value in EEPROM for the next startup.
24 | You know that the calibration value is good when the first USB message is
25 | received. Do not store the value on every received message because the EEPROM
26 | has a limited endurance.
27 |
28 | Notes:
29 | (*) You must declare the global character variable "lastTimer0Value" in your
30 | main code.
31 |
32 | (*) Timer 0 must be free running (not written by your code) and the prescaling
33 | must be consistent with the TIMER0_PRESCALING define.
34 |
35 | (*) Good values for Timer 0 prescaling depend on how precise the clock must
36 | be tuned and how far away from the default clock rate the target clock is.
37 | For precise tuning, choose a low prescaler factor, for a broad range of tuning
38 | choose a high one. A prescaler factor of 64 is good for the entire OSCCAL
39 | range and allows a precision of better than +/-1%. A prescaler factor of 8
40 | allows tuning to slightly more than +/-6% of the default frequency and is
41 | more precise than one step of OSCCAL. It is therefore not suitable to tune an
42 | 8 MHz oscillator to 12.5 MHz.
43 |
44 | Thanks to Henrik Haftmann for the idea to this routine!
45 | */
46 |
47 | #define TIMER0_PRESCALING 64 /* must match the configuration for TIMER0 in main */
48 | #define TOLERATED_DEVIATION_PPT 5 /* max clock deviation before we tune in 1/10 % */
49 | /* derived constants: */
50 | #define EXPECTED_TIMER0_INCREMENT ((F_CPU / (1000 * TIMER0_PRESCALING)) & 0xff)
51 | #define TOLERATED_DEVIATION (TOLERATED_DEVIATION_PPT * F_CPU / (1000000 * TIMER0_PRESCALING))
52 |
53 | #ifdef __ASSEMBLER__
54 | macro tuneOsccal
55 | push YH ;[0]
56 | in YL, TCNT0 ;[2]
57 | lds YH, lastTimer0Value ;[3]
58 | sts lastTimer0Value, YL ;[5]
59 | sub YL, YH ;[7] time passed since last frame
60 | subi YL, EXPECTED_TIMER0_INCREMENT ;[8]
61 | #if OSCCAL > 0x3f /* outside I/O addressable range */
62 | lds YH, OSCCAL ;[6]
63 | #else
64 | in YH, OSCCAL ;[6] assembler modle uses __SFR_OFFSET == 0
65 | #endif
66 | cpi YL, TOLERATED_DEVIATION + 1 ;[10]
67 | brmi notTooHigh ;[11]
68 | subi YH, 1 ;[12] clock rate was too high
69 | ; brcs tuningOverflow ; optionally check for overflow
70 | rjmp osctuneDone ;[13]
71 | notTooHigh:
72 | cpi YL, -TOLERATED_DEVIATION ;[13]
73 | brpl osctuneDone ;[14] not too low
74 | inc YH ;[15] clock rate was too low
75 | ; breq tuningOverflow ; optionally check for overflow
76 | osctuneDone:
77 | #if OSCCAL > 0x3f /* outside I/O addressable range */
78 | sts OSCCAL, YH ;[12-13] store tuned value
79 | #else
80 | out OSCCAL, YH ;[12-13] store tuned value
81 | #endif
82 | tuningOverflow:
83 | pop YH ;[17]
84 | endm ;[19] max number of cycles
85 | #endif
86 |
87 | #define USB_SOF_HOOK tuneOsccal
88 |
--------------------------------------------------------------------------------
/libs-host/Readme.txt:
--------------------------------------------------------------------------------
1 | This is the Readme file for the libs-host directory. This directory contains
2 | code snippets which may be useful for host side USB software.
3 |
4 |
5 | WHAT IS INCLUDED IN THIS DIRECTORY?
6 | ===================================
7 |
8 | opendevice.c and opendevice.h
9 | This module contains a function to find and open a device given its
10 | numeric IDs (VID, PID), names (vendor name and product name) and serial
11 | number. It is based on libusb/libusb-win32 and returns a libusb device
12 | handle. See opendevice.h for an API documentation.
13 |
14 | hiddata.c and hiddata.h
15 | This module contains functions for data transfer over HID feature reports.
16 | It is based on libusb on Unix and native Windows functions on Windows. No
17 | driver DLL is needed on Windows. See hiddata.h for an API documentation.
18 |
19 | hidsdi.h
20 | This DDK header file is missing in the free MinGW version of the Windows
21 | DDK. Use this version if you get an "include file not found" error.
22 |
23 |
24 | ----------------------------------------------------------------------------
25 | (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH.
26 | http://www.obdev.at/
27 |
--------------------------------------------------------------------------------
/libs-host/hiddata.h:
--------------------------------------------------------------------------------
1 | /* Name: hiddata.h
2 | * Author: Christian Starkjohann
3 | * Creation Date: 2008-04-11
4 | * Tabsize: 4
5 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
6 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
7 | */
8 |
9 | #ifndef __HIDDATA_H_INCLUDED__
10 | #define __HIDDATA_H_INCLUDED__
11 |
12 | /*
13 | General Description:
14 | This module implements an abstraction layer for data transfer over HID feature
15 | requests. The implementation uses native Windows functions on Windows so that
16 | no driver installation is required and libusb on Unix. You must link the
17 | appropriate libraries in either case: "-lhid -lusb -lsetupapi" on Windows and
18 | `libusb-config --libs` on Unix.
19 | */
20 |
21 | /* ------------------------------------------------------------------------ */
22 |
23 | #define USBOPEN_SUCCESS 0 /* no error */
24 | #define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */
25 | #define USBOPEN_ERR_IO 2 /* I/O error */
26 | #define USBOPEN_ERR_NOTFOUND 3 /* device not found */
27 |
28 | /* ------------------------------------------------------------------------ */
29 |
30 | typedef struct usbDevice usbDevice_t;
31 | /* Opaque data type representing the USB device. This can be a Windows handle
32 | * or a libusb handle, depending on the backend implementation.
33 | */
34 |
35 | /* ------------------------------------------------------------------------ */
36 |
37 | int usbhidOpenDevice(usbDevice_t **device, int vendorID, char *vendorName, int productID, char *productName, int usesReportIDs);
38 | /* This function opens a USB device. 'vendorID' and 'productID' are the numeric
39 | * Vendor-ID and Product-ID of the device we want to open. If 'vendorName' and
40 | * 'productName' are both not NULL, only devices with matching manufacturer-
41 | * and product name strings are accepted. If the device uses report IDs,
42 | * 'usesReportIDs' must be set to a non-zero value.
43 | * Returns: If a matching device has been found, USBOPEN_SUCCESS is returned
44 | * and '*device' is set to an opaque pointer representing the device. The
45 | * device must be closed with usbhidCloseDevice(). If the device has not been
46 | * found or opening failed, an error code is returned.
47 | */
48 | void usbhidCloseDevice(usbDevice_t *device);
49 | /* Every device opened with usbhidOpenDevice() must be closed with this function.
50 | */
51 | int usbhidSetReport(usbDevice_t *device, char *buffer, int len);
52 | /* This function sends a feature report to the device. The report ID must be
53 | * in the first byte of buffer and the length 'len' of the report is specified
54 | * including this report ID. If no report IDs are used, buffer[0] must be set
55 | * to 0 (dummy report ID).
56 | * Returns: 0 on success, an error code otherwise.
57 | */
58 | int usbhidGetReport(usbDevice_t *device, int reportID, char *buffer, int *len);
59 | /* This function obtains a feature report from the device. The requested
60 | * report-ID is passed in 'reportID'. The caller must pass a buffer of the size
61 | * of the expected report in 'buffer' and initialize the variable pointed to by
62 | * 'len' to the total size of this buffer. Upon successful return, the report
63 | * (prefixed with the report-ID) is in 'buffer' and the actual length of the
64 | * report is returned in '*len'.
65 | * Returns: 0 on success, an error code otherwise.
66 | */
67 |
68 | /* ------------------------------------------------------------------------ */
69 |
70 | #endif /* __HIDDATA_H_INCLUDED__ */
71 |
--------------------------------------------------------------------------------
/libs-host/hidsdi.h:
--------------------------------------------------------------------------------
1 | /* Name: hidsdi.h
2 | * Author: Christian Starkjohann
3 | * Creation Date: 2006-02-02
4 | * Tabsize: 4
5 | * Copyright: (c) 2006-2008 by OBJECTIVE DEVELOPMENT Software GmbH
6 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
7 | */
8 |
9 | /*
10 | General Description
11 | This file is a replacement for hidsdi.h from the Windows DDK. It defines some
12 | of the types and function prototypes of this header for our project. If you
13 | have the Windows DDK version of this file or a version shipped with MinGW, use
14 | that instead.
15 | */
16 |
17 | #ifndef _HIDSDI_H
18 | #define _HIDSDI_H
19 |
20 | #include
21 |
22 | #include
23 | #include
24 |
25 | typedef struct{
26 | ULONG Size;
27 | USHORT VendorID;
28 | USHORT ProductID;
29 | USHORT VersionNumber;
30 | }HIDD_ATTRIBUTES;
31 |
32 | void __stdcall HidD_GetHidGuid(OUT LPGUID hidGuid);
33 |
34 | BOOLEAN __stdcall HidD_GetAttributes(IN HANDLE device, OUT HIDD_ATTRIBUTES *attributes);
35 |
36 | BOOLEAN __stdcall HidD_GetManufacturerString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen);
37 | BOOLEAN __stdcall HidD_GetProductString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen);
38 | BOOLEAN __stdcall HidD_GetSerialNumberString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen);
39 |
40 | BOOLEAN __stdcall HidD_GetFeature(IN HANDLE device, OUT void *reportBuffer, IN ULONG bufferLen);
41 | BOOLEAN __stdcall HidD_SetFeature(IN HANDLE device, IN void *reportBuffer, IN ULONG bufferLen);
42 |
43 | BOOLEAN __stdcall HidD_GetNumInputBuffers(IN HANDLE device, OUT ULONG *numBuffers);
44 | BOOLEAN __stdcall HidD_SetNumInputBuffers(IN HANDLE device, OUT ULONG numBuffers);
45 |
46 | #include
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/libs-host/opendevice.h:
--------------------------------------------------------------------------------
1 | /* Name: opendevice.h
2 | * Project: V-USB host-side library
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-10
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | /*
11 | General Description:
12 | This module offers additional functionality for host side drivers based on
13 | libusb or libusb-win32. It includes a function to find and open a device
14 | based on numeric IDs and textual description. It also includes a function to
15 | obtain textual descriptions from a device.
16 |
17 | To use this functionality, simply copy opendevice.c and opendevice.h into your
18 | project and add them to your Makefile. You may modify and redistribute these
19 | files according to the GNU General Public License (GPL) version 2 or 3.
20 | */
21 |
22 | #ifndef __OPENDEVICE_H_INCLUDED__
23 | #define __OPENDEVICE_H_INCLUDED__
24 |
25 | #include /* this is libusb, see http://libusb.sourceforge.net/ */
26 | #include
27 |
28 | int usbGetStringAscii(libusb_device_handle *dev, int index, char *buf, int buflen);
29 | /* This function gets a string descriptor from the device. 'index' is the
30 | * string descriptor index. The string is returned in ISO Latin 1 encoding in
31 | * 'buf' and it is terminated with a 0-character. The buffer size must be
32 | * passed in 'buflen' to prevent buffer overflows. A libusb device handle
33 | * must be given in 'dev'.
34 | * Returns: The length of the string (excluding the terminating 0) or
35 | * a negative number in case of an error. If there was an error, use
36 | * libusb_strerror() to obtain the error message.
37 | */
38 |
39 | int usbOpenDevice(libusb_device_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp);
40 | /* This function iterates over all devices on all USB busses and searches for
41 | * a device. Matching is done first by means of Vendor- and Product-ID (passed
42 | * in 'vendorID' and 'productID'. An ID of 0 matches any numeric ID (wildcard).
43 | * When a device matches by its IDs, matching by names is performed. Name
44 | * matching can be done on textual vendor name ('vendorNamePattern'), product
45 | * name ('productNamePattern') and serial number ('serialNamePattern'). A
46 | * device matches only if all non-null pattern match. If you don't care about
47 | * a string, pass NULL for the pattern. Patterns are Unix shell style pattern:
48 | * '*' stands for 0 or more characters, '?' for one single character, a list
49 | * of characters in square brackets for a single character from the list
50 | * (dashes are allowed to specify a range) and if the lis of characters begins
51 | * with a caret ('^'), it matches one character which is NOT in the list.
52 | * Other parameters to the function: If 'warningsFp' is not NULL, warning
53 | * messages are printed to this file descriptor with fprintf(). If
54 | * 'printMatchingDevicesFp' is not NULL, no device is opened but matching
55 | * devices are printed to the given file descriptor with fprintf().
56 | * If a device is opened, the resulting USB handle is stored in '*device'. A
57 | * pointer to a "libusb_device_handle *" type variable must be passed here.
58 | * Returns: 0 on success, an error code (see defines below) on failure.
59 | */
60 |
61 | /* usbOpenDevice() error codes: */
62 | #define USBOPEN_SUCCESS 0 /* no error */
63 | #define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */
64 | #define USBOPEN_ERR_IO 2 /* I/O error */
65 | #define USBOPEN_ERR_NOTFOUND 3 /* device not found */
66 |
67 |
68 | /* Obdev's free USB IDs, see USB-IDs-for-free.txt for details */
69 |
70 | #define USB_VID_OBDEV_SHARED 5824 /* obdev's shared vendor ID */
71 | #define USB_PID_OBDEV_SHARED_CUSTOM 1500 /* shared PID for custom class devices */
72 | #define USB_PID_OBDEV_SHARED_HID 1503 /* shared PID for HIDs except mice & keyboards */
73 | #define USB_PID_OBDEV_SHARED_CDCACM 1505 /* shared PID for CDC Modem devices */
74 | #define USB_PID_OBDEV_SHARED_MIDI 1508 /* shared PID for MIDI class devices */
75 |
76 | #endif /* __OPENDEVICE_H_INCLUDED__ */
77 |
--------------------------------------------------------------------------------
/mkdist.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Name: mkdist.sh
3 | # Project: v-usb
4 | # Author: Christian Starkjohann
5 | # Creation Date: 2008-04-18
6 | # Tabsize: 4
7 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
8 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
9 |
10 | # This script was created for Mac OS X with EAGLE and ImageMagick installed
11 | # The "open" command is specific to Mac OS X and is used to start GUI
12 | # applications or open files and directories.
13 |
14 | name=vusb
15 |
16 | #PATH="$PATH"
17 | eagle=~/Applications/EAGLE/EAGLE.app/Contents/MacOS/EAGLE
18 |
19 | #-------------------------------------------------------------------
20 | # initial user dialog:
21 | #-------------------------------------------------------------------
22 |
23 | changes=$(git status --porcelain --untracked-files=no)
24 | if [ -n "$changes" ]; then
25 | echo "There are uncommitted changes. Please commit them before making a release!"
26 | exit 1
27 | fi
28 |
29 | branch="$(git symbolic-ref HEAD)"
30 | branch="${branch##refs/heads/}"
31 | if [ "$branch" != master ]; then
32 | echo "Warning: On branch $branch, not master! Type enter to continue anyway."
33 | read dummy
34 | fi
35 |
36 | if [ "$1" = public ]; then
37 | echo "Generating a public (tagged) release"
38 | isPublic=yes
39 | today=`date +%Y%m%d`
40 | releasedate=`grep '^[*] Release ' usbdrv/Changelog.txt | awk '{date=$NF} END{gsub("-", "", date); print date}'`
41 | if [ "$releasedate" != "$today" ]; then
42 | echo "Release is not documented in usbdrv/Changelog.txt, please do that!"
43 | exit 1
44 | fi
45 | cat << EOF | sed -n -f /dev/stdin usbdrv/usbdrv.h >usbdrv/usbdrv.h.new
46 | /^\( [*] \)\{0,1\}[+].*\$/ d
47 | s/^#define USBDRV_VERSION .*\$/#define USBDRV_VERSION $today/g
48 | p
49 | EOF
50 | if cmp --silent usbdrv/usbdrv.h usbdrv/usbdrv.h.new; then
51 | rm usbdrv/usbdrv.h.new #files are equal
52 | else
53 | rm usbdrv/usbdrv.h
54 | mv usbdrv/usbdrv.h.new usbdrv/usbdrv.h
55 | git add usbdrv/usbdrv.h
56 | git commit -m "RELEASE: Updated version number to $today"
57 | fi
58 | else
59 | echo "For a public release (tagged in subversion) add parameter \"public\""
60 | isPublic=no
61 | fi
62 |
63 | #-------------------------------------------------------------------
64 | # determine version and tag in GIT
65 | #-------------------------------------------------------------------
66 |
67 | version=`grep USBDRV_VERSION usbdrv/usbdrv.h | awk '{print $NF}'`
68 | if [ "$isPublic" != yes ]; then
69 | version="$version"-priv
70 | else
71 | (
72 | currentGcc=`avr-gcc-select | awk '{print $NF}'`
73 | cd tests
74 | for i in 3 4; do
75 | avr-gcc-select $i >/dev/null 2>&1
76 | gccvers=`avr-gcc --version | awk '{print $NF; exit}'`
77 | file=sizes-$version-gcc$gccvers.txt
78 | make sizes
79 | mv sizes.txt sizes-reference/$file
80 | git add sizes-reference/$file
81 | done
82 | git commit -m "RELEASE: Added sizes files for this version"
83 | avr-gcc-select $currentGcc
84 | )
85 | echo "Tagging as version $version"
86 | git tag "releases/$version"
87 | fi
88 |
89 | #-------------------------------------------------------------------
90 | # checkout source from repository
91 | #-------------------------------------------------------------------
92 |
93 | echo "Creating distribution for $name version $version"
94 | pkgname="$name-$version"
95 |
96 | rm -rf "/tmp/$pkgname"
97 | rm -f "/tmp/$pkgname".*
98 | mkdir "/tmp/$pkgname"
99 | git archive --format tar "$branch" | tar -x -C "/tmp/$pkgname"
100 | cd "/tmp/$pkgname"
101 |
102 | #-------------------------------------------------------------------
103 | # Automatically create PNG files from EAGLE design
104 | #-------------------------------------------------------------------
105 |
106 | # Script for exporting circuit diagram:
107 | tname="mkdist-$$"
108 | cat >/tmp/$tname.scr <$(SIZES_TMP)
31 | $(MAKE) clean; $(MAKE) main.elf
32 | avr-size main.elf | tail -1 | awk '{print "Minimum_with_16_MHz", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
33 | $(MAKE) clean; $(MAKE) main.elf F_CPU=12000000
34 | avr-size main.elf | tail -1 | awk '{print "Minimum_with_12_MHz", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
35 | $(MAKE) clean; $(MAKE) main.elf F_CPU=12800000
36 | avr-size main.elf | tail -1 | awk '{print "Minimum_with_12_8_MHz", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
37 | $(MAKE) clean; $(MAKE) main.elf F_CPU=15000000
38 | avr-size main.elf | tail -1 | awk '{print "Minimum_with_15_MHz", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
39 | $(MAKE) clean; $(MAKE) main.elf F_CPU=16500000
40 | avr-size main.elf | tail -1 | awk '{print "Minimum_with_16_5_MHz", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
41 | $(MAKE) clean; $(MAKE) main.elf F_CPU=18000000
42 | avr-size main.elf | tail -1 | awk '{print "Minimum_with_18_MHz", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
43 | $(MAKE) clean; $(MAKE) main.elf F_CPU=18000000 CRCFLAG="-DUSE_CRC=1"
44 | avr-size main.elf | tail -1 | awk '{print "Minimum_with_18_MHz+CRC", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
45 | $(MAKE) clean; $(MAKE) main.elf F_CPU=20000000
46 | avr-size main.elf | tail -1 | awk '{print "Minimum_with_20_MHz", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
47 | $(MAKE) clean; $(MAKE) main.elf DEFINES=-DUSB_CFG_IMPLEMENT_FN_WRITE=1
48 | avr-size main.elf | tail -1 | awk '{print "With_usbFunctionWrite", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
49 | $(MAKE) clean; $(MAKE) main.elf DEFINES=-DUSB_CFG_IMPLEMENT_FN_READ=1
50 | avr-size main.elf | tail -1 | awk '{print "With_usbFunctionRead", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
51 | $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSB_CFG_IMPLEMENT_FN_READ=1 -DUSB_CFG_IMPLEMENT_FN_WRITE=1"
52 | avr-size main.elf | tail -1 | awk '{print "With_usbFunctionRead_and_Write", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
53 | $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSB_CFG_IMPLEMENT_FN_WRITEOUT=1"
54 | avr-size main.elf | tail -1 | awk '{print "With_usbFunctionWriteOut", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
55 | $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSB_CFG_HAVE_INTRIN_ENDPOINT=1"
56 | avr-size main.elf | tail -1 | awk '{print "With_Interrupt_In_Endpoint_1", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
57 | $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSB_CFG_IMPLEMENT_HALT=1 -DUSB_CFG_HAVE_INTRIN_ENDPOINT=1"
58 | avr-size main.elf | tail -1 | awk '{print "With_Interrupt_In_Endpoint_1_and_Halt", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
59 | $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSB_CFG_HAVE_INTRIN_ENDPOINT3=1"
60 | avr-size main.elf | tail -1 | awk '{print "With_Interrupt_In_Endpoint_1_and_3", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
61 | $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSE_DYNAMIC_DESCRIPTOR=1"
62 | avr-size main.elf | tail -1 | awk '{print "With_Dynamic_Descriptor", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
63 | $(MAKE) clean; $(MAKE) main.elf "DEFINES=-DUSB_CFG_LONG_TRANSFERS=1"
64 | avr-size main.elf | tail -1 | awk '{print "With_Long_Transfers", $$1+$$2, $$3+$$2}' >>$(SIZES_TMP)
65 | cat $(SIZES_TMP) | awk 'BEGIN{printf("%39s %5s %5s %5s %5s\n"), "Variation", "Flash", "RAM", "+F", "+RAM"}\
66 | /^null/{nullRom=$$2; nullRam=$$3; next} \
67 | {rom=$$2-nullRom; ram=$$3-nullRam; if(!refRom){refRom=rom; refRam=ram} \
68 | printf("%39s %5d %5d %+5d %+5d\n", $$1, rom, ram, rom-refRom, ram-refRam)}' | tee sizes.txt
69 | rm $(SIZES_TMP)
70 |
71 | test:
72 | for freq in 12000000 12800000 15000000 16000000 16500000 18000000 20000000; do \
73 | for opt in USB_COUNT_SOF USB_CFG_HAVE_INTRIN_ENDPOINT USB_CFG_HAVE_INTRIN_ENDPOINT3 USB_CFG_HAVE_MEASURE_FRAME_LENGTH USB_CFG_LONG_TRANSFERS; do \
74 | $(MAKE) clean; $(MAKE) main.elf F_CPU=$$freq "DEFINES=-D$$opt=1" || exit 1; \
75 | $(MAKE) clean; $(MAKE) main.elf F_CPU=$$freq "DEFINES=-D$$opt=1 -DDUSB_CFG_IMPLEMENT_FN_WRITEOUT=1" || exit 1; \
76 | done \
77 | done
78 |
79 | # The following rule is used to check the compiler
80 | devices: #exclude devices without RAM for stack and atmega603 for gcc 3
81 | excludes="at90s1200 attiny11 attiny12 attiny15 attiny28"; \
82 | for gccVersion in 3 4; do \
83 | avr-gcc-select $$gccVersion; \
84 | for device in `echo | avr-gcc -xc -mmcu=x - 2>&1 | egrep '^ *at[a-zA-Z0-9_-]+$$'`; do \
85 | if echo "$$excludes" | grep "$$device" >/dev/null; then continue; fi; \
86 | if [ "$$gccVersion" = 3 -a "$$device" = atmega603 ]; then continue; fi; \
87 | $(MAKE) clean; $(MAKE) null.elf DEVICE=$$device || exit 1; \
88 | done \
89 | done
90 | $(MAKE) clean
91 | avr-gcc-select 3
92 | @echo "+++ Device test succeeded!"
93 |
94 | # rule for deleting dependent files (those which can be built by Make):
95 | clean:
96 | rm -f *.hex *.lst *.map *.elf *.o
97 | rm -rf usbdrv
98 |
99 | # Generic rule for compiling C files:
100 | .c.o:
101 | $(COMPILE) -c $< -o $@
102 |
103 | # Generic rule for assembling Assembler source files:
104 | .S.o:
105 | $(COMPILE) -x assembler-with-cpp -c $< -o $@
106 | # "-x assembler-with-cpp" should not be necessary since this is the default
107 | # file type for the .S (with capital S) extension. However, upper case
108 | # characters are not always preserved on Windows. To ensure WinAVR
109 | # compatibility define the file type manually.
110 |
111 | # Generic rule for compiling C to assembler, used for debugging only.
112 | .c.s:
113 | $(COMPILE) -S $< -o $@
114 |
115 | # file targets:
116 |
117 | # Since we don't want to ship the driver multipe times, we copy it into this project:
118 | usbdrv:
119 | cp -r ../usbdrv .
120 |
121 | main.elf: usbdrv $(OBJECTS) # usbdrv dependency only needed because we copy it
122 | $(COMPILE) -o main.elf $(OBJECTS)
123 |
124 | main_i.elf: usbdrv main.o usbdrv/usbdrvasm.o # usbdrv dependency only needed because we copy it
125 | $(COMPILE) -o main_i.elf main.o usbdrv/usbdrvasm.o
126 |
127 | null.elf: null.o
128 | $(COMPILE) -o null.elf null.o
129 |
--------------------------------------------------------------------------------
/tests/Readme.txt:
--------------------------------------------------------------------------------
1 | This is the Readme file for the directory "tests" of V-USB, a firmware-only
2 | USB driver for AVR microcontrollers.
3 |
4 | WHAT IS IN THIS DIRECTORY?
5 | ==========================
6 | This directory is for driver development only. It contains tests to check
7 | whether all branches of #ifdef code compile as they should and whether the
8 | code size of the driver increased.
9 |
10 |
11 | ----------------------------------------------------------------------------
12 | (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH.
13 | http://www.obdev.at/
14 |
--------------------------------------------------------------------------------
/tests/compare-sizes.awk:
--------------------------------------------------------------------------------
1 | #!/usr/bin/awk -f
2 | # Name: compare-sizes.awk
3 | # Project: v-usb
4 | # Author: Christian Starkjohann
5 | # Creation Date: 2008-04-29
6 | # Tabsize: 4
7 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
8 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
9 |
10 | BEGIN{
11 | opt = 0;
12 | if(ARGC != 3){
13 | printf("usage: compare-sizes.awk file1 file2\n");
14 | printf(" computes size differences between two size lists\n");
15 | exit 1;
16 | }
17 | file1 = ARGV[1];
18 | file2 = ARGV[2];
19 | }
20 |
21 | {
22 | if(($2 + 0) != 0){
23 | if(!hadOption[$1]){
24 | hadOption[$1] = 1;
25 | options[opt++] = $1;
26 | }
27 | flash[FILENAME, $1] = $2;
28 | ram[FILENAME, $1] = $3;
29 | }
30 | }
31 |
32 | END{
33 | if(opt > 0){
34 | printf ("%39s %6s %5s\n", "Variation", "+Flash", "+RAM");
35 | }
36 | for(i = 0; i < opt; i++){
37 | option = options[i];
38 | if(!flash[file2, option] || !flash[file1, option]){
39 | printf("%39s %6s %5s\n", option, "n/a", "n/a");
40 | }else{
41 | printf("%39s %+6d %+5d\n", option, flash[file2, option] - flash[file1, option], ram[file2, option] - ram[file1, option]);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tests/main.c:
--------------------------------------------------------------------------------
1 | /* Name: main.c
2 | * Project: Testing driver features
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-29
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | /*
11 | This module is a do-nothing test code linking against (or including) the USB
12 | driver. It is used to determine the code size for various options and to
13 | check whether the code compiles with all options.
14 | */
15 | #include
16 | #include /* for sei() */
17 | #include /* required by usbdrv.h */
18 | #include /* for _delay_ms() */
19 | #include "usbdrv.h"
20 | #if USE_INCLUDE
21 | #include "usbdrv.c"
22 | #endif
23 |
24 | /* ------------------------------------------------------------------------- */
25 | /* ----------------------------- USB interface ----------------------------- */
26 | /* ------------------------------------------------------------------------- */
27 |
28 | #if USB_CFG_IMPLEMENT_FN_WRITE
29 | uchar usbFunctionWrite(uchar *data, uchar len)
30 | {
31 | return 1;
32 | }
33 | #endif
34 |
35 | #if USB_CFG_IMPLEMENT_FN_READ
36 | uchar usbFunctionRead(uchar *data, uchar len)
37 | {
38 | return len;
39 | }
40 | #endif
41 |
42 | #if USB_CFG_IMPLEMENT_FN_WRITEOUT
43 | void usbFunctionWriteOut(uchar *data, uchar len)
44 | {
45 | }
46 | #endif
47 |
48 | #if USE_DYNAMIC_DESCRIPTOR
49 |
50 | static PROGMEM const char myDescriptorDevice[] = { /* USB device descriptor */
51 | 18, /* sizeof(usbDescriptorDevice): length of descriptor in bytes */
52 | USBDESCR_DEVICE, /* descriptor type */
53 | 0x10, 0x01, /* USB version supported */
54 | USB_CFG_DEVICE_CLASS,
55 | USB_CFG_DEVICE_SUBCLASS,
56 | 0, /* protocol */
57 | 8, /* max packet size */
58 | /* the following two casts affect the first byte of the constant only, but
59 | * that's sufficient to avoid a warning with the default values.
60 | */
61 | (char)USB_CFG_VENDOR_ID,/* 2 bytes */
62 | (char)USB_CFG_DEVICE_ID,/* 2 bytes */
63 | USB_CFG_DEVICE_VERSION, /* 2 bytes */
64 | USB_CFG_DESCR_PROPS_STRING_VENDOR != 0 ? 1 : 0, /* manufacturer string index */
65 | USB_CFG_DESCR_PROPS_STRING_PRODUCT != 0 ? 2 : 0, /* product string index */
66 | USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER != 0 ? 3 : 0, /* serial number string index */
67 | 1, /* number of configurations */
68 | };
69 |
70 | static PROGMEM const char myDescriptorConfiguration[] = { /* USB configuration descriptor */
71 | 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */
72 | USBDESCR_CONFIG, /* descriptor type */
73 | 18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + (USB_CFG_DESCR_PROPS_HID & 0xff), 0,
74 | /* total length of data returned (including inlined descriptors) */
75 | 1, /* number of interfaces in this configuration */
76 | 1, /* index of this configuration */
77 | 0, /* configuration name string index */
78 | #if USB_CFG_IS_SELF_POWERED
79 | USBATTR_SELFPOWER, /* attributes */
80 | #else
81 | 0, /* attributes */
82 | #endif
83 | USB_CFG_MAX_BUS_POWER/2, /* max USB current in 2mA units */
84 | /* interface descriptor follows inline: */
85 | 9, /* sizeof(usbDescrInterface): length of descriptor in bytes */
86 | USBDESCR_INTERFACE, /* descriptor type */
87 | 0, /* index of this interface */
88 | 0, /* alternate setting for this interface */
89 | USB_CFG_HAVE_INTRIN_ENDPOINT, /* endpoints excl 0: number of endpoint descriptors to follow */
90 | USB_CFG_INTERFACE_CLASS,
91 | USB_CFG_INTERFACE_SUBCLASS,
92 | USB_CFG_INTERFACE_PROTOCOL,
93 | 0, /* string index for interface */
94 | #if (USB_CFG_DESCR_PROPS_HID & 0xff) /* HID descriptor */
95 | 9, /* sizeof(usbDescrHID): length of descriptor in bytes */
96 | USBDESCR_HID, /* descriptor type: HID */
97 | 0x01, 0x01, /* BCD representation of HID version */
98 | 0x00, /* target country code */
99 | 0x01, /* number of HID Report (or other HID class) Descriptor infos to follow */
100 | 0x22, /* descriptor type: report */
101 | USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH, 0, /* total length of report descriptor */
102 | #endif
103 | #if USB_CFG_HAVE_INTRIN_ENDPOINT /* endpoint descriptor for endpoint 1 */
104 | 7, /* sizeof(usbDescrEndpoint) */
105 | USBDESCR_ENDPOINT, /* descriptor type = endpoint */
106 | (char)0x81, /* IN endpoint number 1 */
107 | 0x03, /* attrib: Interrupt endpoint */
108 | 8, 0, /* maximum packet size */
109 | USB_CFG_INTR_POLL_INTERVAL, /* in ms */
110 | #endif
111 | };
112 |
113 | USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(usbRequest_t *rq)
114 | {
115 | uchar *p = 0, len = 0;
116 |
117 | if(rq->wValue.bytes[1] == USBDESCR_DEVICE){
118 | p = (uchar *)myDescriptorDevice;
119 | len = sizeof(myDescriptorDevice);
120 | }else{ /* must be configuration descriptor */
121 | p = (uchar *)(myDescriptorConfiguration);
122 | len = sizeof(myDescriptorConfiguration);
123 | }
124 | usbMsgPtr = (usbMsgPtr_t)p;
125 | return len;
126 | }
127 | #endif
128 |
129 | USB_PUBLIC usbMsgLen_t usbFunctionSetup(uchar data[8])
130 | {
131 | usbRequest_t *rq = (void *)data;
132 |
133 | if(rq->bRequest == 0) /* request using usbFunctionRead()/usbFunctionWrite() */
134 | return 0xff;
135 | return 0; /* default for not implemented requests: return no data back to host */
136 | }
137 |
138 | /* ------------------------------------------------------------------------- */
139 |
140 | int main(void)
141 | {
142 | uchar i;
143 |
144 | usbInit();
145 | usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
146 | i = 0;
147 | while(--i){ /* fake USB disconnect for > 250 ms */
148 | _delay_ms(1);
149 | }
150 | usbDeviceConnect();
151 | sei();
152 | for(;;){ /* main event loop */
153 | usbPoll();
154 | }
155 | return 0;
156 | }
157 |
158 | /* ------------------------------------------------------------------------- */
159 |
--------------------------------------------------------------------------------
/tests/null.c:
--------------------------------------------------------------------------------
1 | /* Name: null.c
2 | * Project: Testing driver features
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-29
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | /*
11 | This is a NULL main() function to find out the code size required by libusb's
12 | startup code, interrupt vectors etc.
13 | */
14 | #include
15 |
16 |
17 | /* ------------------------------------------------------------------------- */
18 |
19 | int main(void)
20 | {
21 | for(;;);
22 | return 0;
23 | }
24 |
25 | /* ------------------------------------------------------------------------- */
26 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20080418-gcc3.4.6.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1154 45 +0 +0
3 | Minimum_with_12_MHz 1274 45 +120 +0
4 | Minimum_with_15_MHz 1260 45 +106 +0
5 | Minimum_with_16_5_MHz 1276 45 +122 +0
6 | With_usbFunctionWrite 1214 45 +60 +0
7 | With_usbFunctionRead 1200 45 +46 +0
8 | With_usbFunctionRead_and_Write 1246 45 +92 +0
9 | With_usbFunctionWriteOut 1178 45 +24 +0
10 | With_Interrupt_In_Endpoint_1 1284 58 +130 +13
11 | With_Interrupt_In_Endpoint_1_and_Halt 1372 58 +218 +13
12 | With_Interrupt_In_Endpoint_1_and_3 1386 69 +232 +24
13 | With_Dynamic_Descriptor 1186 45 +32 +0
14 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20080418-gcc4.2.2.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1208 45 +0 +0
3 | Minimum_with_12_MHz 1328 45 +120 +0
4 | Minimum_with_15_MHz 1314 45 +106 +0
5 | Minimum_with_16_5_MHz 1330 45 +122 +0
6 | With_usbFunctionWrite 1268 45 +60 +0
7 | With_usbFunctionRead 1264 45 +56 +0
8 | With_usbFunctionRead_and_Write 1314 45 +106 +0
9 | With_usbFunctionWriteOut 1218 45 +10 +0
10 | With_Interrupt_In_Endpoint_1 1340 58 +132 +13
11 | With_Interrupt_In_Endpoint_1_and_Halt 1414 58 +206 +13
12 | With_Interrupt_In_Endpoint_1_and_3 1426 69 +218 +24
13 | With_Dynamic_Descriptor 1238 45 +30 +0
14 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20080513-gcc3.4.6.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1154 45 +0 +0
3 | Minimum_with_12_MHz 1274 45 +120 +0
4 | Minimum_with_15_MHz 1260 45 +106 +0
5 | Minimum_with_16_5_MHz 1276 45 +122 +0
6 | Minimum_with_20_MHz 1136 45 -18 +0
7 | With_usbFunctionWrite 1214 45 +60 +0
8 | With_usbFunctionRead 1192 45 +38 +0
9 | With_usbFunctionRead_and_Write 1234 45 +80 +0
10 | With_usbFunctionWriteOut 1178 45 +24 +0
11 | With_Interrupt_In_Endpoint_1 1280 57 +126 +12
12 | With_Interrupt_In_Endpoint_1_and_Halt 1370 57 +216 +12
13 | With_Interrupt_In_Endpoint_1_and_3 1346 69 +192 +24
14 | With_Dynamic_Descriptor 1182 45 +28 +0
15 | With_Long_Transfers 1200 47 +46 +2
16 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20080513-gcc4.3.0.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1192 45 +0 +0
3 | Minimum_with_12_MHz 1312 45 +120 +0
4 | Minimum_with_15_MHz 1298 45 +106 +0
5 | Minimum_with_16_5_MHz 1314 45 +122 +0
6 | Minimum_with_20_MHz 1174 45 -18 +0
7 | With_usbFunctionWrite 1246 45 +54 +0
8 | With_usbFunctionRead 1242 45 +50 +0
9 | With_usbFunctionRead_and_Write 1280 45 +88 +0
10 | With_usbFunctionWriteOut 1208 45 +16 +0
11 | With_Interrupt_In_Endpoint_1 1320 57 +128 +12
12 | With_Interrupt_In_Endpoint_1_and_Halt 1410 57 +218 +12
13 | With_Interrupt_In_Endpoint_1_and_3 1428 69 +236 +24
14 | With_Dynamic_Descriptor 1212 45 +20 +0
15 | With_Long_Transfers 1270 47 +78 +2
16 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20081022-gcc3.4.6.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1152 45 +0 +0
3 | Minimum_with_12_MHz 1202 45 +50 +0
4 | Minimum_with_12_8_MHz 1522 45 +370 +0
5 | Minimum_with_15_MHz 1258 45 +106 +0
6 | Minimum_with_16_5_MHz 1274 45 +122 +0
7 | Minimum_with_20_MHz 1134 45 -18 +0
8 | With_usbFunctionWrite 1212 45 +60 +0
9 | With_usbFunctionRead 1190 45 +38 +0
10 | With_usbFunctionRead_and_Write 1232 45 +80 +0
11 | With_usbFunctionWriteOut 1176 45 +24 +0
12 | With_Interrupt_In_Endpoint_1 1278 57 +126 +12
13 | With_Interrupt_In_Endpoint_1_and_Halt 1368 57 +216 +12
14 | With_Interrupt_In_Endpoint_1_and_3 1344 69 +192 +24
15 | With_Dynamic_Descriptor 1180 45 +28 +0
16 | With_Long_Transfers 1198 47 +46 +2
17 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20081022-gcc4.3.0.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1194 45 +0 +0
3 | Minimum_with_12_MHz 1244 45 +50 +0
4 | Minimum_with_12_8_MHz 1564 45 +370 +0
5 | Minimum_with_15_MHz 1300 45 +106 +0
6 | Minimum_with_16_5_MHz 1316 45 +122 +0
7 | Minimum_with_20_MHz 1176 45 -18 +0
8 | With_usbFunctionWrite 1248 45 +54 +0
9 | With_usbFunctionRead 1244 45 +50 +0
10 | With_usbFunctionRead_and_Write 1282 45 +88 +0
11 | With_usbFunctionWriteOut 1210 45 +16 +0
12 | With_Interrupt_In_Endpoint_1 1322 57 +128 +12
13 | With_Interrupt_In_Endpoint_1_and_Halt 1412 57 +218 +12
14 | With_Interrupt_In_Endpoint_1_and_3 1430 69 +236 +24
15 | With_Dynamic_Descriptor 1214 45 +20 +0
16 | With_Long_Transfers 1272 47 +78 +2
17 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20081126-gcc3.4.6.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1152 45 +0 +0
3 | Minimum_with_12_MHz 1202 45 +50 +0
4 | Minimum_with_12_8_MHz 1522 45 +370 +0
5 | Minimum_with_15_MHz 1258 45 +106 +0
6 | Minimum_with_16_5_MHz 1274 45 +122 +0
7 | Minimum_with_20_MHz 1134 45 -18 +0
8 | With_usbFunctionWrite 1212 45 +60 +0
9 | With_usbFunctionRead 1190 45 +38 +0
10 | With_usbFunctionRead_and_Write 1232 45 +80 +0
11 | With_usbFunctionWriteOut 1176 45 +24 +0
12 | With_Interrupt_In_Endpoint_1 1278 57 +126 +12
13 | With_Interrupt_In_Endpoint_1_and_Halt 1368 57 +216 +12
14 | With_Interrupt_In_Endpoint_1_and_3 1344 69 +192 +24
15 | With_Dynamic_Descriptor 1180 45 +28 +0
16 | With_Long_Transfers 1198 47 +46 +2
17 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20081126-gcc4.3.0.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1194 45 +0 +0
3 | Minimum_with_12_MHz 1244 45 +50 +0
4 | Minimum_with_12_8_MHz 1564 45 +370 +0
5 | Minimum_with_15_MHz 1300 45 +106 +0
6 | Minimum_with_16_5_MHz 1316 45 +122 +0
7 | Minimum_with_20_MHz 1176 45 -18 +0
8 | With_usbFunctionWrite 1248 45 +54 +0
9 | With_usbFunctionRead 1244 45 +50 +0
10 | With_usbFunctionRead_and_Write 1282 45 +88 +0
11 | With_usbFunctionWriteOut 1210 45 +16 +0
12 | With_Interrupt_In_Endpoint_1 1322 57 +128 +12
13 | With_Interrupt_In_Endpoint_1_and_Halt 1412 57 +218 +12
14 | With_Interrupt_In_Endpoint_1_and_3 1430 69 +236 +24
15 | With_Dynamic_Descriptor 1214 45 +20 +0
16 | With_Long_Transfers 1272 47 +78 +2
17 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20090323-gcc3.4.6.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1152 45 +0 +0
3 | Minimum_with_12_MHz 1202 45 +50 +0
4 | Minimum_with_12_8_MHz 1522 45 +370 +0
5 | Minimum_with_15_MHz 1258 45 +106 +0
6 | Minimum_with_16_5_MHz 1274 45 +122 +0
7 | Minimum_with_18_MHz+CRC 2268 45 +1116 +0
8 | Minimum_with_20_MHz 1134 45 -18 +0
9 | With_usbFunctionWrite 1212 45 +60 +0
10 | With_usbFunctionRead 1190 45 +38 +0
11 | With_usbFunctionRead_and_Write 1232 45 +80 +0
12 | With_usbFunctionWriteOut 1176 45 +24 +0
13 | With_Interrupt_In_Endpoint_1 1278 57 +126 +12
14 | With_Interrupt_In_Endpoint_1_and_Halt 1368 57 +216 +12
15 | With_Interrupt_In_Endpoint_1_and_3 1344 69 +192 +24
16 | With_Dynamic_Descriptor 1180 45 +28 +0
17 | With_Long_Transfers 1198 47 +46 +2
18 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20090323-gcc4.3.2.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1224 45 +0 +0
3 | Minimum_with_12_MHz 1274 45 +50 +0
4 | Minimum_with_12_8_MHz 1594 45 +370 +0
5 | Minimum_with_15_MHz 1330 45 +106 +0
6 | Minimum_with_16_5_MHz 1346 45 +122 +0
7 | Minimum_with_18_MHz+CRC 2298 45 +1074 +0
8 | Minimum_with_20_MHz 1206 45 -18 +0
9 | With_usbFunctionWrite 1284 45 +60 +0
10 | With_usbFunctionRead 1280 45 +56 +0
11 | With_usbFunctionRead_and_Write 1318 45 +94 +0
12 | With_usbFunctionWriteOut 1246 45 +22 +0
13 | With_Interrupt_In_Endpoint_1 1358 57 +134 +12
14 | With_Interrupt_In_Endpoint_1_and_Halt 1448 57 +224 +12
15 | With_Interrupt_In_Endpoint_1_and_3 1466 69 +242 +24
16 | With_Dynamic_Descriptor 1250 45 +26 +0
17 | With_Long_Transfers 1302 47 +78 +2
18 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20090415-gcc3.4.6.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1152 45 +0 +0
3 | Minimum_with_12_MHz 1202 45 +50 +0
4 | Minimum_with_12_8_MHz 1522 45 +370 +0
5 | Minimum_with_15_MHz 1258 45 +106 +0
6 | Minimum_with_16_5_MHz 1274 45 +122 +0
7 | Minimum_with_18_MHz+CRC 2268 45 +1116 +0
8 | Minimum_with_20_MHz 1134 45 -18 +0
9 | With_usbFunctionWrite 1212 45 +60 +0
10 | With_usbFunctionRead 1190 45 +38 +0
11 | With_usbFunctionRead_and_Write 1232 45 +80 +0
12 | With_usbFunctionWriteOut 1176 45 +24 +0
13 | With_Interrupt_In_Endpoint_1 1278 57 +126 +12
14 | With_Interrupt_In_Endpoint_1_and_Halt 1368 57 +216 +12
15 | With_Interrupt_In_Endpoint_1_and_3 1344 69 +192 +24
16 | With_Dynamic_Descriptor 1180 45 +28 +0
17 | With_Long_Transfers 1198 47 +46 +2
18 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20090415-gcc4.3.2.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1224 45 +0 +0
3 | Minimum_with_12_MHz 1274 45 +50 +0
4 | Minimum_with_12_8_MHz 1594 45 +370 +0
5 | Minimum_with_15_MHz 1330 45 +106 +0
6 | Minimum_with_16_5_MHz 1346 45 +122 +0
7 | Minimum_with_18_MHz+CRC 2298 45 +1074 +0
8 | Minimum_with_20_MHz 1206 45 -18 +0
9 | With_usbFunctionWrite 1284 45 +60 +0
10 | With_usbFunctionRead 1280 45 +56 +0
11 | With_usbFunctionRead_and_Write 1318 45 +94 +0
12 | With_usbFunctionWriteOut 1246 45 +22 +0
13 | With_Interrupt_In_Endpoint_1 1358 57 +134 +12
14 | With_Interrupt_In_Endpoint_1_and_Halt 1448 57 +224 +12
15 | With_Interrupt_In_Endpoint_1_and_3 1466 69 +242 +24
16 | With_Dynamic_Descriptor 1250 45 +26 +0
17 | With_Long_Transfers 1302 47 +78 +2
18 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20100715-gcc3.4.6.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1152 45 +0 +0
3 | Minimum_with_12_MHz 1202 45 +50 +0
4 | Minimum_with_12_8_MHz 1518 45 +366 +0
5 | Minimum_with_15_MHz 1258 45 +106 +0
6 | Minimum_with_16_5_MHz 1274 45 +122 +0
7 | Minimum_with_18_MHz+CRC 2268 45 +1116 +0
8 | Minimum_with_20_MHz 1134 45 -18 +0
9 | With_usbFunctionWrite 1212 45 +60 +0
10 | With_usbFunctionRead 1190 45 +38 +0
11 | With_usbFunctionRead_and_Write 1232 45 +80 +0
12 | With_usbFunctionWriteOut 1176 45 +24 +0
13 | With_Interrupt_In_Endpoint_1 1278 57 +126 +12
14 | With_Interrupt_In_Endpoint_1_and_Halt 1368 57 +216 +12
15 | With_Interrupt_In_Endpoint_1_and_3 1344 69 +192 +24
16 | With_Dynamic_Descriptor 1180 45 +28 +0
17 | With_Long_Transfers 1198 47 +46 +2
18 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20100715-gcc4.3.3.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1226 45 +0 +0
3 | Minimum_with_12_MHz 1276 45 +50 +0
4 | Minimum_with_12_8_MHz 1592 45 +366 +0
5 | Minimum_with_15_MHz 1332 45 +106 +0
6 | Minimum_with_16_5_MHz 1348 45 +122 +0
7 | Minimum_with_18_MHz+CRC 2298 45 +1072 +0
8 | Minimum_with_20_MHz 1208 45 -18 +0
9 | With_usbFunctionWrite 1286 45 +60 +0
10 | With_usbFunctionRead 1282 45 +56 +0
11 | With_usbFunctionRead_and_Write 1320 45 +94 +0
12 | With_usbFunctionWriteOut 1248 45 +22 +0
13 | With_Interrupt_In_Endpoint_1 1360 57 +134 +12
14 | With_Interrupt_In_Endpoint_1_and_Halt 1450 57 +224 +12
15 | With_Interrupt_In_Endpoint_1_and_3 1418 69 +192 +24
16 | With_Dynamic_Descriptor 1252 45 +26 +0
17 | With_Long_Transfers 1304 47 +78 +2
18 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20120109-gcc3.4.6.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1152 45 +0 +0
3 | Minimum_with_12_MHz 1202 45 +50 +0
4 | Minimum_with_12_8_MHz 1518 45 +366 +0
5 | Minimum_with_15_MHz 1258 45 +106 +0
6 | Minimum_with_16_5_MHz 1274 45 +122 +0
7 | Minimum_with_18_MHz+CRC 2268 45 +1116 +0
8 | Minimum_with_20_MHz 1134 45 -18 +0
9 | With_usbFunctionWrite 1212 45 +60 +0
10 | With_usbFunctionRead 1190 45 +38 +0
11 | With_usbFunctionRead_and_Write 1232 45 +80 +0
12 | With_usbFunctionWriteOut 1176 45 +24 +0
13 | With_Interrupt_In_Endpoint_1 1278 57 +126 +12
14 | With_Interrupt_In_Endpoint_1_and_Halt 1368 57 +216 +12
15 | With_Interrupt_In_Endpoint_1_and_3 1344 69 +192 +24
16 | With_Dynamic_Descriptor 1180 45 +28 +0
17 | With_Long_Transfers 1206 47 +54 +2
18 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20120109-gcc4.3.3.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1226 45 +0 +0
3 | Minimum_with_12_MHz 1276 45 +50 +0
4 | Minimum_with_12_8_MHz 1592 45 +366 +0
5 | Minimum_with_15_MHz 1332 45 +106 +0
6 | Minimum_with_16_5_MHz 1348 45 +122 +0
7 | Minimum_with_18_MHz+CRC 2298 45 +1072 +0
8 | Minimum_with_20_MHz 1208 45 -18 +0
9 | With_usbFunctionWrite 1286 45 +60 +0
10 | With_usbFunctionRead 1282 45 +56 +0
11 | With_usbFunctionRead_and_Write 1320 45 +94 +0
12 | With_usbFunctionWriteOut 1248 45 +22 +0
13 | With_Interrupt_In_Endpoint_1 1360 57 +134 +12
14 | With_Interrupt_In_Endpoint_1_and_Halt 1450 57 +224 +12
15 | With_Interrupt_In_Endpoint_1_and_3 1418 69 +192 +24
16 | With_Dynamic_Descriptor 1252 45 +26 +0
17 | With_Long_Transfers 1300 47 +74 +2
18 |
--------------------------------------------------------------------------------
/tests/sizes-reference/sizes-20121206-gcc4.6.2.txt:
--------------------------------------------------------------------------------
1 | Variation Flash RAM +F +RAM
2 | Minimum_with_16_MHz 1192 45 +0 +0
3 | Minimum_with_12_MHz 1242 45 +50 +0
4 | Minimum_with_12_8_MHz 1558 45 +366 +0
5 | Minimum_with_15_MHz 1298 45 +106 +0
6 | Minimum_with_16_5_MHz 1314 45 +122 +0
7 | Minimum_with_18_MHz+CRC 2262 45 +1070 +0
8 | Minimum_with_20_MHz 1174 45 -18 +0
9 | With_usbFunctionWrite 1252 45 +60 +0
10 | With_usbFunctionRead 1248 45 +56 +0
11 | With_usbFunctionRead_and_Write 1286 45 +94 +0
12 | With_usbFunctionWriteOut 1214 45 +22 +0
13 | With_Interrupt_In_Endpoint_1 1328 57 +136 +12
14 | With_Interrupt_In_Endpoint_1_and_Halt 1420 57 +228 +12
15 | With_Interrupt_In_Endpoint_1_and_3 1386 69 +194 +24
16 | With_Dynamic_Descriptor 1198 45 +6 +0
17 | With_Long_Transfers 1236 47 +44 +2
18 |
--------------------------------------------------------------------------------
/usbdrv/CommercialLicense.txt:
--------------------------------------------------------------------------------
1 | V-USB Driver Software License Agreement
2 | Version 2012-07-09
3 |
4 | THIS LICENSE AGREEMENT GRANTS YOU CERTAIN RIGHTS IN A SOFTWARE. YOU CAN
5 | ENTER INTO THIS AGREEMENT AND ACQUIRE THE RIGHTS OUTLINED BELOW BY PAYING
6 | THE AMOUNT ACCORDING TO SECTION 4 ("PAYMENT") TO OBJECTIVE DEVELOPMENT.
7 |
8 |
9 | 1 DEFINITIONS
10 |
11 | 1.1 "OBJECTIVE DEVELOPMENT" shall mean OBJECTIVE DEVELOPMENT Software GmbH,
12 | Grosse Schiffgasse 1A/7, 1020 Wien, AUSTRIA.
13 |
14 | 1.2 "You" shall mean the Licensee.
15 |
16 | 1.3 "V-USB" shall mean all files included in the package distributed under
17 | the name "vusb" by OBJECTIVE DEVELOPMENT (http://www.obdev.at/vusb/)
18 | unless otherwise noted. This includes the firmware-only USB device
19 | implementation for Atmel AVR microcontrollers, some simple device examples
20 | and host side software examples and libraries.
21 |
22 |
23 | 2 LICENSE GRANTS
24 |
25 | 2.1 Source Code. OBJECTIVE DEVELOPMENT shall furnish you with the source
26 | code of V-USB.
27 |
28 | 2.2 Distribution and Use. OBJECTIVE DEVELOPMENT grants you the
29 | non-exclusive right to use, copy and distribute V-USB with your hardware
30 | product(s), restricted by the limitations in section 3 below.
31 |
32 | 2.3 Modifications. OBJECTIVE DEVELOPMENT grants you the right to modify
33 | the source code and your copy of V-USB according to your needs.
34 |
35 | 2.4 USB IDs. OBJECTIVE DEVELOPMENT furnishes you with one or two USB
36 | Product ID(s), sent to you in e-mail. These Product IDs are reserved
37 | exclusively for you. OBJECTIVE DEVELOPMENT has obtained USB Product ID
38 | ranges under the Vendor ID 5824 from Wouter van Ooijen (Van Ooijen
39 | Technische Informatica, www.voti.nl) and under the Vendor ID 8352 from
40 | Jason Kotzin (now flirc.tv, Inc.). Both owners of the Vendor IDs have
41 | obtained these IDs from the USB Implementers Forum, Inc. (www.usb.org).
42 | OBJECTIVE DEVELOPMENT disclaims all liability which might arise from the
43 | assignment of USB IDs.
44 |
45 | 2.5 USB Certification. Although not part of this agreement, we want to make
46 | it clear that you cannot become USB certified when you use V-USB or a USB
47 | Product ID assigned by OBJECTIVE DEVELOPMENT. AVR microcontrollers don't
48 | meet the electrical specifications required by the USB specification and
49 | the USB Implementers Forum certifies only members who bought a Vendor ID of
50 | their own.
51 |
52 |
53 | 3 LICENSE RESTRICTIONS
54 |
55 | 3.1 Number of Units. Only one of the following three definitions is
56 | applicable. Which one is determined by the amount you pay to OBJECTIVE
57 | DEVELOPMENT, see section 4 ("Payment") below.
58 |
59 | Hobby License: You may use V-USB according to section 2 above in no more
60 | than 5 hardware units. These units must not be sold for profit.
61 |
62 | Entry Level License: You may use V-USB according to section 2 above in no
63 | more than 150 hardware units.
64 |
65 | Professional License: You may use V-USB according to section 2 above in
66 | any number of hardware units, except for large scale production ("unlimited
67 | fair use"). Quantities below 10,000 units are not considered large scale
68 | production. If your reach quantities which are obviously large scale
69 | production, you must pay a license fee of 0.10 EUR per unit for all units
70 | above 10,000.
71 |
72 | 3.2 Rental. You may not rent, lease, or lend V-USB or otherwise encumber
73 | any copy of V-USB, or any of the rights granted herein.
74 |
75 | 3.3 Transfer. You may not transfer your rights under this Agreement to
76 | another party without OBJECTIVE DEVELOPMENT's prior written consent. If
77 | such consent is obtained, you may permanently transfer this License to
78 | another party. The recipient of such transfer must agree to all terms and
79 | conditions of this Agreement.
80 |
81 | 3.4 Reservation of Rights. OBJECTIVE DEVELOPMENT retains all rights not
82 | expressly granted.
83 |
84 | 3.5 Non-Exclusive Rights. Your license rights under this Agreement are
85 | non-exclusive.
86 |
87 | 3.6 Third Party Rights. This Agreement cannot grant you rights controlled
88 | by third parties. In particular, you are not allowed to use the USB logo or
89 | other trademarks owned by the USB Implementers Forum, Inc. without their
90 | consent. Since such consent depends on USB certification, it should be
91 | noted that V-USB will not pass certification because it does not
92 | implement checksum verification and the microcontroller ports do not meet
93 | the electrical specifications.
94 |
95 |
96 | 4 PAYMENT
97 |
98 | The payment amount depends on the variation of this agreement (according to
99 | section 3.1) into which you want to enter. Concrete prices are listed on
100 | OBJECTIVE DEVELOPMENT's web site, usually at
101 | http://www.obdev.at/vusb/license.html. You agree to pay the amount listed
102 | there to OBJECTIVE DEVELOPMENT or OBJECTIVE DEVELOPMENT's payment processor
103 | or reseller.
104 |
105 |
106 | 5 COPYRIGHT AND OWNERSHIP
107 |
108 | V-USB is protected by copyright laws and international copyright
109 | treaties, as well as other intellectual property laws and treaties. V-USB
110 | is licensed, not sold.
111 |
112 |
113 | 6 TERM AND TERMINATION
114 |
115 | 6.1 Term. This Agreement shall continue indefinitely. However, OBJECTIVE
116 | DEVELOPMENT may terminate this Agreement and revoke the granted license and
117 | USB-IDs if you fail to comply with any of its terms and conditions.
118 |
119 | 6.2 Survival of Terms. All provisions regarding secrecy, confidentiality
120 | and limitation of liability shall survive termination of this agreement.
121 |
122 |
123 | 7 DISCLAIMER OF WARRANTY AND LIABILITY
124 |
125 | LIMITED WARRANTY. V-USB IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
126 | KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, OBJECTIVE
127 | DEVELOPMENT AND ITS SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES, EITHER
128 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
129 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND
130 | NON-INFRINGEMENT, WITH REGARD TO V-USB, AND THE PROVISION OF OR FAILURE
131 | TO PROVIDE SUPPORT SERVICES. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL
132 | RIGHTS. YOU MAY HAVE OTHERS, WHICH VARY FROM STATE/JURISDICTION TO
133 | STATE/JURISDICTION.
134 |
135 | LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
136 | IN NO EVENT SHALL OBJECTIVE DEVELOPMENT OR ITS SUPPLIERS BE LIABLE FOR ANY
137 | SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER
138 | (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
139 | BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY
140 | LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE V-USB OR THE
141 | PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF OBJECTIVE
142 | DEVELOPMENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY
143 | CASE, OBJECTIVE DEVELOPMENT'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS
144 | AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR V-USB.
145 |
146 |
147 | 8 MISCELLANEOUS TERMS
148 |
149 | 8.1 Marketing. OBJECTIVE DEVELOPMENT has the right to mention for marketing
150 | purposes that you entered into this agreement.
151 |
152 | 8.2 Entire Agreement. This document represents the entire agreement between
153 | OBJECTIVE DEVELOPMENT and you. It may only be modified in writing signed by
154 | an authorized representative of both, OBJECTIVE DEVELOPMENT and you.
155 |
156 | 8.3 Severability. In case a provision of these terms and conditions should
157 | be or become partly or entirely invalid, ineffective, or not executable,
158 | the validity of all other provisions shall not be affected.
159 |
160 | 8.4 Applicable Law. This agreement is governed by the laws of the Republic
161 | of Austria.
162 |
163 | 8.5 Responsible Courts. The responsible courts in Vienna/Austria will have
164 | exclusive jurisdiction regarding all disputes in connection with this
165 | agreement.
166 |
167 |
--------------------------------------------------------------------------------
/usbdrv/Readme.txt:
--------------------------------------------------------------------------------
1 | This is the Readme file to Objective Development's firmware-only USB driver
2 | for Atmel AVR microcontrollers. For more information please visit
3 | http://www.obdev.at/vusb/
4 |
5 | This directory contains the USB firmware only. Copy it as-is to your own
6 | project and add all .c and .S files to your project (these files are marked
7 | with an asterisk in the list below). Then copy usbconfig-prototype.h as
8 | usbconfig.h to your project and edit it according to your configuration.
9 |
10 |
11 | TECHNICAL DOCUMENTATION
12 | =======================
13 | The technical documentation (API) for the firmware driver is contained in the
14 | file "usbdrv.h". Please read all of it carefully! Configuration options are
15 | documented in "usbconfig-prototype.h".
16 |
17 | The driver consists of the following files:
18 | Readme.txt ............. The file you are currently reading.
19 | Changelog.txt .......... Release notes for all versions of the driver.
20 | usbdrv.h ............... Driver interface definitions and technical docs.
21 | * usbdrv.c ............... High level language part of the driver. Link this
22 | module to your code!
23 | * usbdrvasm.S ............ Assembler part of the driver. This module is mostly
24 | a stub and includes one of the usbdrvasm*.S files
25 | depending on processor clock. Link this module to
26 | your code!
27 | usbdrvasm*.inc ......... Assembler routines for particular clock frequencies.
28 | Included by usbdrvasm.S, don't link it directly!
29 | asmcommon.inc .......... Common assembler routines. Included by
30 | usbdrvasm*.inc, don't link it directly!
31 | usbconfig-prototype.h .. Prototype for your own usbdrv.h file.
32 | * oddebug.c .............. Debug functions. Only used when DEBUG_LEVEL is
33 | defined to a value greater than 0. Link this module
34 | to your code!
35 | oddebug.h .............. Interface definitions of the debug module.
36 | usbportability.h ....... Header with compiler-dependent stuff.
37 | usbdrvasm.asm .......... Compatibility stub for IAR-C-compiler. Use this
38 | module instead of usbdrvasm.S when you assembler
39 | with IAR's tools.
40 | License.txt ............ Open Source license for this driver.
41 | CommercialLicense.txt .. Optional commercial license for this driver.
42 | USB-ID-FAQ.txt ......... General infos about USB Product- and Vendor-IDs.
43 | USB-IDs-for-free.txt ... List and terms of use for free shared PIDs.
44 |
45 | (*) ... These files should be linked to your project.
46 |
47 |
48 | CPU CORE CLOCK FREQUENCY
49 | ========================
50 | We supply assembler modules for clock frequencies of 12 MHz, 12.8 MHz, 15 MHz,
51 | 16 MHz, 16.5 MHz 18 MHz and 20 MHz. Other clock rates are not supported. The
52 | actual clock rate must be configured in usbconfig.h.
53 |
54 | 12 MHz Clock
55 | This is the traditional clock rate of V-USB because it's the lowest clock
56 | rate where the timing constraints of the USB spec can be met.
57 |
58 | 15 MHz Clock
59 | Similar to 12 MHz, but some NOPs inserted. On the other hand, the higher clock
60 | rate allows for some loops which make the resulting code size somewhat smaller
61 | than the 12 MHz version.
62 |
63 | 16 MHz Clock
64 | This clock rate has been added for users of the Arduino board and other
65 | ready-made boards which come with a fixed 16 MHz crystal. It's also an option
66 | if you need the slightly higher clock rate for performance reasons. Since
67 | 16 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code
68 | is somewhat tricky and has to insert a leap cycle every third byte.
69 |
70 | 12.8 MHz and 16.5 MHz Clock
71 | The assembler modules for these clock rates differ from the other modules
72 | because they have been built for an RC oscillator with only 1% precision. The
73 | receiver code inserts leap cycles to compensate for clock deviations. 1% is
74 | also the precision which can be achieved by calibrating the internal RC
75 | oscillator of the AVR. Please note that only AVRs with internal 64 MHz PLL
76 | oscillator can reach 16.5 MHz with the RC oscillator. This includes the very
77 | popular ATTiny25, ATTiny45, ATTiny85 series as well as the ATTiny26. Almost
78 | all AVRs can reach 12.8 MHz, although this is outside the specified range.
79 |
80 | See the EasyLogger example at http://www.obdev.at/vusb/easylogger.html for
81 | code which calibrates the RC oscillator based on the USB frame clock.
82 |
83 | 18 MHz Clock
84 | This module is closer to the USB specification because it performs an on the
85 | fly CRC check for incoming packets. Packets with invalid checksum are
86 | discarded as required by the spec. If you also implement checks for data
87 | PID toggling on application level (see option USB_CFG_CHECK_DATA_TOGGLING
88 | in usbconfig.h for more info), this ensures data integrity. Due to the CRC
89 | tables and alignment requirements, this code is bigger than modules for other
90 | clock rates. To activate this module, you must define USB_CFG_CHECK_CRC to 1
91 | and USB_CFG_CLOCK_KHZ to 18000 in usbconfig.h.
92 |
93 | 20 MHz Clock
94 | This module is for people who won't do it with less than the maximum. Since
95 | 20 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code
96 | uses similar tricks as the 16 MHz module to insert leap cycles.
97 |
98 |
99 | USB IDENTIFIERS
100 | ===============
101 | Every USB device needs a vendor- and a product-identifier (VID and PID). VIDs
102 | are obtained from usb.org for a price of 1,500 USD. Once you have a VID, you
103 | can assign PIDs at will.
104 |
105 | Since an entry level cost of 1,500 USD is too high for most small companies
106 | and hobbyists, we provide some VID/PID pairs for free. See the file
107 | USB-IDs-for-free.txt for details.
108 |
109 | Objective Development also has some license offerings which include product
110 | IDs. See http://www.obdev.at/vusb/ for details.
111 |
112 |
113 | DEVELOPMENT SYSTEM
114 | ==================
115 | This driver has been developed and optimized for the GNU compiler version 3
116 | and 4. We recommend that you use the GNU compiler suite because it is freely
117 | available. V-USB has also been ported to the IAR compiler and assembler. It
118 | has been tested with IAR 4.10B/W32 and 4.12A/W32 on an ATmega8 with the
119 | "small" and "tiny" memory model. Not every release is tested with IAR CC and
120 | the driver may therefore fail to compile with IAR. Please note that gcc is
121 | more efficient for usbdrv.c because this module has been deliberately
122 | optimized for gcc.
123 |
124 | Gcc version 3 produces smaller code than version 4 due to new optimizing
125 | capabilities which don't always improve things on 8 bit CPUs. The code size
126 | generated by gcc 4 can be reduced with the compiler options
127 | -fno-move-loop-invariants, -fno-tree-scev-cprop and
128 | -fno-inline-small-functions in addition to -Os. On devices with more than
129 | 8k of flash memory, we also recommend the linker option --relax (written as
130 | -Wl,--relax for gcc) to convert absolute calls into relative where possible.
131 |
132 | For more information about optimizing options see:
133 |
134 | http://www.tty1.net/blog/2008-04-29-avr-gcc-optimisations_en.html
135 |
136 | These optimizations are good for gcc 4.x. Version 3.x of gcc does not support
137 | most of these options and produces good code anyway.
138 |
139 |
140 | USING V-USB FOR FREE
141 | ====================
142 | The AVR firmware driver is published under the GNU General Public License
143 | Version 2 (GPL2) and the GNU General Public License Version 3 (GPL3). It is
144 | your choice whether you apply the terms of version 2 or version 3.
145 |
146 | If you decide for the free GPL2 or GPL3, we STRONGLY ENCOURAGE you to do the
147 | following things IN ADDITION to the obligations from the GPL:
148 |
149 | (1) Publish your entire project on a web site and drop us a note with the URL.
150 | Use the form at http://www.obdev.at/vusb/feedback.html for your submission.
151 | If you don't have a web site, you can publish the project in obdev's
152 | documentation wiki at
153 | http://www.obdev.at/goto.php?t=vusb-wiki&p=hosted-projects.
154 |
155 | (2) Adhere to minimum publication standards. Please include AT LEAST:
156 | - a circuit diagram in PDF, PNG or GIF format
157 | - full source code for the host software
158 | - a Readme.txt file in ASCII format which describes the purpose of the
159 | project and what can be found in which directories and which files
160 | - a reference to http://www.obdev.at/vusb/
161 |
162 | (3) If you improve the driver firmware itself, please give us a free license
163 | to your modifications for our commercial license offerings.
164 |
165 |
166 | COMMERCIAL LICENSES FOR V-USB
167 | =============================
168 | If you don't want to publish your source code under the terms of the GPL,
169 | you can simply pay money for V-USB. As an additional benefit you get
170 | USB PIDs for free, reserved exclusively to you. See the file
171 | "CommercialLicense.txt" for details.
172 |
173 |
--------------------------------------------------------------------------------
/usbdrv/USB-ID-FAQ.txt:
--------------------------------------------------------------------------------
1 | Version 2012-07-09
2 |
3 | ==========================
4 | WHY DO WE NEED THESE IDs?
5 | ==========================
6 |
7 | USB is more than a low level protocol for data transport. It also defines a
8 | common set of requests which must be understood by all devices. And as part
9 | of these common requests, the specification defines data structures, the
10 | USB Descriptors, which are used to describe the properties of the device.
11 |
12 | From the perspective of an operating system, it is therefore possible to find
13 | out basic properties of a device (such as e.g. the manufacturer and the name
14 | of the device) without a device-specific driver. This is essential because
15 | the operating system can choose a driver to load based on this information
16 | (Plug-And-Play).
17 |
18 | Among the most important properties in the Device Descriptor are the USB
19 | Vendor- and Product-ID. Both are 16 bit integers. The most simple form of
20 | driver matching is based on these IDs. The driver announces the Vendor- and
21 | Product-IDs of the devices it can handle and the operating system loads the
22 | appropriate driver when the device is connected.
23 |
24 | It is obvious that this technique only works if the pair Vendor- plus
25 | Product-ID is unique: Only devices which require the same driver can have the
26 | same pair of IDs.
27 |
28 |
29 | =====================================================
30 | HOW DOES THE USB STANDARD ENSURE THAT IDs ARE UNIQUE?
31 | =====================================================
32 |
33 | Since it is so important that USB IDs are unique, the USB Implementers Forum,
34 | Inc. (usb.org) needs a way to enforce this legally. It is not forbidden by
35 | law to build a device and assign it any random numbers as IDs. Usb.org
36 | therefore needs an agreement to regulate the use of USB IDs. The agreement
37 | binds only parties who agreed to it, of course. Everybody else is free to use
38 | any numbers for their IDs.
39 |
40 | So how can usb.org ensure that every manufacturer of USB devices enters into
41 | an agreement with them? They do it via trademark licensing. Usb.org has
42 | registered the trademark "USB", all associated logos and related terms. If
43 | you want to put an USB logo on your product or claim that it is USB
44 | compliant, you must license these trademarks from usb.org. And this is where
45 | you enter into an agreement. See the "USB-IF Trademark License Agreement and
46 | Usage Guidelines for the USB-IF Logo" at
47 | http://www.usb.org/developers/logo_license/.
48 |
49 | Licensing the USB trademarks requires that you buy a USB Vendor-ID from
50 | usb.org (one-time fee of ca. 2,000 USD), that you become a member of usb.org
51 | (yearly fee of ca. 4,000 USD) and that you meet all the technical
52 | specifications from the USB spec.
53 |
54 | This means that most hobbyists and small companies will never be able to
55 | become USB compliant, just because membership is so expensive. And you can't
56 | be compliant with a driver based on V-USB anyway, because the AVR's port pins
57 | don't meet the electrical specifications for USB. So, in principle, all
58 | hobbyists and small companies are free to choose any random numbers for their
59 | IDs. They have nothing to lose...
60 |
61 | There is one exception worth noting, though: If you use a sub-component which
62 | implements USB, the vendor of the sub-components may guarantee USB
63 | compliance. This might apply to some or all of FTDI's solutions.
64 |
65 |
66 | =======================================================================
67 | WHY SHOULD YOU OBTAIN USB IDs EVEN IF YOU DON'T LICENSE USB TRADEMARKS?
68 | =======================================================================
69 |
70 | You have learned in the previous section that you are free to choose any
71 | numbers for your IDs anyway. So why not do exactly this? There is still the
72 | technical issue. If you choose IDs which are already in use by somebody else,
73 | operating systems will load the wrong drivers and your device won't work.
74 | Even if you choose IDs which are not currently in use, they may be in use in
75 | the next version of the operating system or even after an automatic update.
76 |
77 | So what you need is a pair of Vendor- and Product-IDs for which you have the
78 | guarantee that no USB compliant product uses them. This implies that no
79 | operating system will ever ship with drivers responsible for these IDs.
80 |
81 |
82 | ==============================================
83 | HOW DOES OBJECTIVE DEVELOPMENT HANDLE USB IDs?
84 | ==============================================
85 |
86 | Objective Development gives away pairs of USB-IDs with their V-USB licenses.
87 | In order to ensure that these IDs are unique, Objective Development has an
88 | agreement with the company/person who has bought the USB Vendor-ID from
89 | usb.org. This agreement ensures that a range of USB Product-IDs is reserved
90 | for assignment by Objective Development and that the owner of the Vendor-ID
91 | won't give it to anybody else.
92 |
93 | This means that you have to trust three parties to ensure uniqueness of
94 | your IDs:
95 |
96 | - Objective Development, that they don't give the same PID to more than
97 | one person.
98 | - The owner of the Vendor-ID that they don't assign PIDs from the range
99 | assigned to Objective Development to anybody else.
100 | - Usb.org that they don't assign the same Vendor-ID a second time.
101 |
102 |
103 | ==================================
104 | WHO IS THE OWNER OF THE VENDOR-ID?
105 | ==================================
106 |
107 | Objective Development has obtained ranges of USB Product-IDs under two
108 | Vendor-IDs: Under Vendor-ID 5824 from Wouter van Ooijen (Van Ooijen
109 | Technische Informatica, www.voti.nl) and under Vendor-ID 8352 from Jason
110 | Kotzin (now flirc.tv, Inc.). Both VID owners have received their Vendor-ID
111 | directly from usb.org.
112 |
113 |
114 | =========================================================================
115 | CAN I USE USB-IDs FROM OBJECTIVE DEVELOPMENT WITH OTHER DRIVERS/HARDWARE?
116 | =========================================================================
117 |
118 | The short answer is: Yes. All you get is a guarantee that the IDs are never
119 | assigned to anybody else. What more do you need?
120 |
121 |
122 | ============================
123 | WHAT ABOUT SHARED ID PAIRS?
124 | ============================
125 |
126 | Objective Development has reserved some PID/VID pairs for shared use. You
127 | have no guarantee of uniqueness for them, except that no USB compliant device
128 | uses them. In order to avoid technical problems, we must ensure that all
129 | devices with the same pair of IDs use the same driver on kernel level. For
130 | details, see the file USB-IDs-for-free.txt.
131 |
132 |
133 | ======================================================
134 | I HAVE HEARD THAT SUB-LICENSING OF USB-IDs IS ILLEGAL?
135 | ======================================================
136 |
137 | A 16 bit integer number cannot be protected by copyright laws. It is not
138 | sufficiently complex. And since none of the parties involved entered into the
139 | USB-IF Trademark License Agreement, we are not bound by this agreement. So
140 | there is no reason why it should be illegal to sub-license USB-IDs.
141 |
142 |
143 | =============================================
144 | WHO IS LIABLE IF THERE ARE INCOMPATIBILITIES?
145 | =============================================
146 |
147 | Objective Development disclaims all liabilities which might arise from the
148 | assignment of IDs. If you guarantee product features to your customers
149 | without proper disclaimer, YOU are liable for that.
150 |
--------------------------------------------------------------------------------
/usbdrv/USB-IDs-for-free.txt:
--------------------------------------------------------------------------------
1 | Version 2009-08-22
2 |
3 | ===========================
4 | FREE USB-IDs FOR SHARED USE
5 | ===========================
6 |
7 | Objective Development has reserved a set of USB Product-IDs for use according
8 | to the guidelines outlined below. For more information about the concept of
9 | USB IDs please see the file USB-ID-FAQ.txt. Objective Development guarantees
10 | that the IDs listed below are not used by any USB compliant devices.
11 |
12 |
13 | ====================
14 | MECHANISM OF SHARING
15 | ====================
16 |
17 | From a technical point of view, two different devices can share the same USB
18 | Vendor- and Product-ID if they require the same driver on operating system
19 | level. We make use of this fact by assigning separate IDs for various device
20 | classes. On application layer, devices must be distinguished by their textual
21 | name or serial number. We offer separate sets of IDs for discrimination by
22 | textual name and for serial number.
23 |
24 | Examples for shared use of USB IDs are included with V-USB in the "examples"
25 | subdirectory.
26 |
27 |
28 | ======================================
29 | IDs FOR DISCRIMINATION BY TEXTUAL NAME
30 | ======================================
31 |
32 | If you use one of the IDs listed below, your device and host-side software
33 | must conform to these rules:
34 |
35 | (1) The USB device MUST provide a textual representation of the manufacturer
36 | and product identification. The manufacturer identification MUST be available
37 | at least in USB language 0x0409 (English/US).
38 |
39 | (2) The textual manufacturer identification MUST contain either an Internet
40 | domain name (e.g. "mycompany.com") registered and owned by you, or an e-mail
41 | address under your control (e.g. "myname@gmx.net"). You can embed the domain
42 | name or e-mail address in any string you like, e.g. "Objective Development
43 | http://www.obdev.at/vusb/".
44 |
45 | (3) You are responsible for retaining ownership of the domain or e-mail
46 | address for as long as any of your products are in use.
47 |
48 | (4) You may choose any string for the textual product identification, as long
49 | as this string is unique within the scope of your textual manufacturer
50 | identification.
51 |
52 | (5) Application side device look-up MUST be based on the textual manufacturer
53 | and product identification in addition to VID/PID matching. The driver
54 | matching MUST be a comparison of the entire strings, NOT a sub-string match.
55 |
56 | (6) For devices which implement a particular USB device class (e.g. HID), the
57 | operating system's default class driver MUST be used. If an operating system
58 | driver for Vendor Class devices is needed, this driver must be libusb or
59 | libusb-win32 (see http://libusb.org/ and
60 | http://libusb-win32.sourceforge.net/).
61 |
62 | Table if IDs for discrimination by textual name:
63 |
64 | PID dec (hex) | VID dec (hex) | Description of use
65 | ==============+===============+============================================
66 | 1500 (0x05dc) | 5824 (0x16c0) | For Vendor Class devices with libusb
67 | --------------+---------------+--------------------------------------------
68 | 1503 (0x05df) | 5824 (0x16c0) | For generic HID class devices (which are
69 | | | NOT mice, keyboards or joysticks)
70 | --------------+---------------+--------------------------------------------
71 | 1505 (0x05e1) | 5824 (0x16c0) | For CDC-ACM class devices (modems)
72 | --------------+---------------+--------------------------------------------
73 | 1508 (0x05e4) | 5824 (0x16c0) | For MIDI class devices
74 | --------------+---------------+--------------------------------------------
75 |
76 | Note that Windows caches the textual product- and vendor-description for
77 | mice, keyboards and joysticks. Name-bsed discrimination is therefore not
78 | recommended for these device classes.
79 |
80 |
81 | =======================================
82 | IDs FOR DISCRIMINATION BY SERIAL NUMBER
83 | =======================================
84 |
85 | If you use one of the IDs listed below, your device and host-side software
86 | must conform to these rules:
87 |
88 | (1) The USB device MUST provide a textual representation of the serial
89 | number, unless ONLY the operating system's default class driver is used.
90 | The serial number string MUST be available at least in USB language 0x0409
91 | (English/US).
92 |
93 | (2) The serial number MUST start with either an Internet domain name (e.g.
94 | "mycompany.com") registered and owned by you, or an e-mail address under your
95 | control (e.g. "myname@gmx.net"), both terminated with a colon (":") character.
96 | You MAY append any string you like for further discrimination of your devices.
97 |
98 | (3) You are responsible for retaining ownership of the domain or e-mail
99 | address for as long as any of your products are in use.
100 |
101 | (5) Application side device look-up MUST be based on the serial number string
102 | in addition to VID/PID matching. The matching must start at the first
103 | character of the serial number string and include the colon character
104 | terminating your domain or e-mail address. It MAY stop anywhere after that.
105 |
106 | (6) For devices which implement a particular USB device class (e.g. HID), the
107 | operating system's default class driver MUST be used. If an operating system
108 | driver for Vendor Class devices is needed, this driver must be libusb or
109 | libusb-win32 (see http://libusb.org/ and
110 | http://libusb-win32.sourceforge.net/).
111 |
112 | (7) If ONLY the operating system's default class driver is used, e.g. for
113 | mice, keyboards, joysticks, CDC or MIDI devices and no discrimination by an
114 | application is needed, the serial number may be omitted.
115 |
116 |
117 | Table if IDs for discrimination by serial number string:
118 |
119 | PID dec (hex) | VID dec (hex) | Description of use
120 | ===============+===============+===========================================
121 | 10200 (0x27d8) | 5824 (0x16c0) | For Vendor Class devices with libusb
122 | ---------------+---------------+-------------------------------------------
123 | 10201 (0x27d9) | 5824 (0x16c0) | For generic HID class devices (which are
124 | | | NOT mice, keyboards or joysticks)
125 | ---------------+---------------+-------------------------------------------
126 | 10202 (0x27da) | 5824 (0x16c0) | For USB Mice
127 | ---------------+---------------+-------------------------------------------
128 | 10203 (0x27db) | 5824 (0x16c0) | For USB Keyboards
129 | ---------------+---------------+-------------------------------------------
130 | 10204 (0x27dc) | 5824 (0x16c0) | For USB Joysticks
131 | ---------------+---------------+-------------------------------------------
132 | 10205 (0x27dd) | 5824 (0x16c0) | For CDC-ACM class devices (modems)
133 | ---------------+---------------+-------------------------------------------
134 | 10206 (0x27de) | 5824 (0x16c0) | For MIDI class devices
135 | ---------------+---------------+-------------------------------------------
136 | 10207 (0x27df) | 5824 (0x16c0) | For Mass Storage class devices
137 | ---------------+---------------+-------------------------------------------
138 | 10208 (0x27e0) | 5824 (0x16c0) | For Audio class devices
139 | ---------------+---------------+-------------------------------------------
140 | 10209 (0x27e1) | 5824 (0x16c0) | For CDC-ECM class devices
141 | ---------------+---------------+-------------------------------------------
142 | 10210 (0x27e2) | 5824 (0x16c0) | For MTP class devices
143 | ---------------+---------------+-------------------------------------------
144 |
145 | Note that the last six cannot be implemented using V-USB in a standards
146 | compliant way because they require bulk endpoints which are forbidden for
147 | low speed devices. We provide them nevertheless, either if you want to
148 | implement a non-compliant device or implement it using other technology
149 | than V-USB.
150 |
151 |
152 | =================
153 | ORIGIN OF USB-IDs
154 | =================
155 |
156 | OBJECTIVE DEVELOPMENT Software GmbH has obtained all VID/PID pairs listed
157 | here from Wouter van Ooijen (see www.voti.nl) for exclusive disposition.
158 | Wouter van Ooijen has obtained the VID from the USB Implementers Forum, Inc.
159 | (see www.usb.org). The VID is registered for the company name "Van Ooijen
160 | Technische Informatica".
161 |
162 |
163 | ==========
164 | DISCLAIMER
165 | ==========
166 |
167 | OBJECTIVE DEVELOPMENT Software GmbH disclaims all liability for any
168 | problems which are caused by the shared use of these VID/PID pairs.
169 |
--------------------------------------------------------------------------------
/usbdrv/asmcommon.inc:
--------------------------------------------------------------------------------
1 | /* Name: asmcommon.inc
2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2007-11-05
5 | * Tabsize: 4
6 | * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | /* Do not link this file! Link usbdrvasm.S instead, which includes the
11 | * appropriate implementation!
12 | */
13 |
14 | /*
15 | General Description:
16 | This file contains assembler code which is shared among the USB driver
17 | implementations for different CPU cocks. Since the code must be inserted
18 | in the middle of the module, it's split out into this file and #included.
19 |
20 | Jump destinations called from outside:
21 | sofError: Called when no start sequence was found.
22 | se0: Called when a package has been successfully received.
23 | overflow: Called when receive buffer overflows.
24 | doReturn: Called after sending data.
25 |
26 | Outside jump destinations used by this module:
27 | waitForJ: Called to receive an already arriving packet.
28 | sendAckAndReti:
29 | sendNakAndReti:
30 | sendCntAndReti:
31 | usbSendAndReti:
32 |
33 | The following macros must be defined before this file is included:
34 | .macro POP_STANDARD
35 | .endm
36 | .macro POP_RETI
37 | .endm
38 | */
39 |
40 | #define token x1
41 |
42 | overflow:
43 | ldi x2, 1< 0
13 |
14 | #warning "Never compile production devices with debugging enabled"
15 |
16 | static void uartPutc(char c)
17 | {
18 | while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */
19 | ODDBG_UDR = c;
20 | }
21 |
22 | static uchar hexAscii(uchar h)
23 | {
24 | h &= 0xf;
25 | if(h >= 10)
26 | h += 'a' - (uchar)10 - '0';
27 | h += '0';
28 | return h;
29 | }
30 |
31 | static void printHex(uchar c)
32 | {
33 | uartPutc(hexAscii(c >> 4));
34 | uartPutc(hexAscii(c));
35 | }
36 |
37 | void odDebug(uchar prefix, uchar *data, uchar len)
38 | {
39 | printHex(prefix);
40 | uartPutc(':');
41 | while(len--){
42 | uartPutc(' ');
43 | printHex(*data++);
44 | }
45 | uartPutc('\r');
46 | uartPutc('\n');
47 | }
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/usbdrv/oddebug.h:
--------------------------------------------------------------------------------
1 | /* Name: oddebug.h
2 | * Project: AVR library
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2005-01-16
5 | * Tabsize: 4
6 | * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | #ifndef __oddebug_h_included__
11 | #define __oddebug_h_included__
12 |
13 | /*
14 | General Description:
15 | This module implements a function for debug logs on the serial line of the
16 | AVR microcontroller. Debugging can be configured with the define
17 | 'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging
18 | calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is
19 | 2, DBG1 and DBG2 logs will be printed.
20 |
21 | A debug log consists of a label ('prefix') to indicate which debug log created
22 | the output and a memory block to dump in hex ('data' and 'len').
23 | */
24 |
25 |
26 | #ifndef F_CPU
27 | # define F_CPU 12000000 /* 12 MHz */
28 | #endif
29 |
30 | /* make sure we have the UART defines: */
31 | #include "usbportability.h"
32 |
33 | #ifndef uchar
34 | # define uchar unsigned char
35 | #endif
36 |
37 | #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */
38 | # warning "Debugging disabled because device has no UART"
39 | # undef DEBUG_LEVEL
40 | #endif
41 |
42 | #ifndef DEBUG_LEVEL
43 | # define DEBUG_LEVEL 0
44 | #endif
45 |
46 | /* ------------------------------------------------------------------------- */
47 |
48 | #if DEBUG_LEVEL > 0
49 | # define DBG1(prefix, data, len) odDebug(prefix, data, len)
50 | #else
51 | # define DBG1(prefix, data, len)
52 | #endif
53 |
54 | #if DEBUG_LEVEL > 1
55 | # define DBG2(prefix, data, len) odDebug(prefix, data, len)
56 | #else
57 | # define DBG2(prefix, data, len)
58 | #endif
59 |
60 | /* ------------------------------------------------------------------------- */
61 |
62 | #if DEBUG_LEVEL > 0
63 | extern void odDebug(uchar prefix, uchar *data, uchar len);
64 |
65 | /* Try to find our control registers; ATMEL likes to rename these */
66 |
67 | #if defined UBRR
68 | # define ODDBG_UBRR UBRR
69 | #elif defined UBRRL
70 | # define ODDBG_UBRR UBRRL
71 | #elif defined UBRR0
72 | # define ODDBG_UBRR UBRR0
73 | #elif defined UBRR0L
74 | # define ODDBG_UBRR UBRR0L
75 | #endif
76 |
77 | #if defined UCR
78 | # define ODDBG_UCR UCR
79 | #elif defined UCSRB
80 | # define ODDBG_UCR UCSRB
81 | #elif defined UCSR0B
82 | # define ODDBG_UCR UCSR0B
83 | #endif
84 |
85 | #if defined TXEN
86 | # define ODDBG_TXEN TXEN
87 | #else
88 | # define ODDBG_TXEN TXEN0
89 | #endif
90 |
91 | #if defined USR
92 | # define ODDBG_USR USR
93 | #elif defined UCSRA
94 | # define ODDBG_USR UCSRA
95 | #elif defined UCSR0A
96 | # define ODDBG_USR UCSR0A
97 | #endif
98 |
99 | #if defined UDRE
100 | # define ODDBG_UDRE UDRE
101 | #else
102 | # define ODDBG_UDRE UDRE0
103 | #endif
104 |
105 | #if defined UDR
106 | # define ODDBG_UDR UDR
107 | #elif defined UDR0
108 | # define ODDBG_UDR UDR0
109 | #endif
110 |
111 | static inline void odDebugInit(void)
112 | {
113 | ODDBG_UCR |= (1<
38 | #ifndef __IAR_SYSTEMS_ASM__
39 | # include
40 | #endif
41 |
42 | #define __attribute__(arg) /* not supported on IAR */
43 |
44 | #ifdef __IAR_SYSTEMS_ASM__
45 | # define __ASSEMBLER__ /* IAR does not define standard macro for asm */
46 | #endif
47 |
48 | #ifdef __HAS_ELPM__
49 | # define PROGMEM __farflash
50 | #else
51 | # define PROGMEM __flash
52 | #endif
53 |
54 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr))
55 |
56 | /* The following definitions are not needed by the driver, but may be of some
57 | * help if you port a gcc based project to IAR.
58 | */
59 | #define cli() __disable_interrupt()
60 | #define sei() __enable_interrupt()
61 | #define wdt_reset() __watchdog_reset()
62 | #define _BV(x) (1 << (x))
63 |
64 | /* assembler compatibility macros */
65 | #define nop2 rjmp $+2 /* jump to next instruction */
66 | #define XL r26
67 | #define XH r27
68 | #define YL r28
69 | #define YH r29
70 | #define ZL r30
71 | #define ZH r31
72 | #define lo8(x) LOW(x)
73 | #define hi8(x) (((x)>>8) & 0xff) /* not HIGH to allow XLINK to make a proper range check */
74 |
75 | /* Depending on the device you use, you may get problems with the way usbdrv.h
76 | * handles the differences between devices. Since IAR does not use #defines
77 | * for MCU registers, we can't check for the existence of a particular
78 | * register with an #ifdef. If the autodetection mechanism fails, include
79 | * definitions for the required USB_INTR_* macros in your usbconfig.h. See
80 | * usbconfig-prototype.h and usbdrv.h for details.
81 | */
82 |
83 | /* ------------------------------------------------------------------------- */
84 | #elif __CODEVISIONAVR__ /* check for CodeVision AVR */
85 | /* ------------------------------------------------------------------------- */
86 | /* This port is not working (yet) */
87 |
88 | /* #define F_CPU _MCU_CLOCK_FREQUENCY_ seems to be defined automatically */
89 |
90 | #include
91 | #include
92 |
93 | #define __attribute__(arg) /* not supported on IAR */
94 |
95 | #define PROGMEM __flash
96 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr))
97 |
98 | #ifndef __ASSEMBLER__
99 | static inline void cli(void)
100 | {
101 | #asm("cli");
102 | }
103 | static inline void sei(void)
104 | {
105 | #asm("sei");
106 | }
107 | #endif
108 | #define _delay_ms(t) delay_ms(t)
109 | #define _BV(x) (1 << (x))
110 | #define USB_CFG_USE_SWITCH_STATEMENT 1 /* macro for if() cascase fails for unknown reason */
111 |
112 | #define macro .macro
113 | #define endm .endmacro
114 | #define nop2 rjmp .+0 /* jump to next instruction */
115 |
116 | /* ------------------------------------------------------------------------- */
117 | #else /* default development environment is avr-gcc/avr-libc */
118 | /* ------------------------------------------------------------------------- */
119 |
120 | #include
121 | #ifdef __ASSEMBLER__
122 | # define _VECTOR(N) __vector_ ## N /* io.h does not define this for asm */
123 | #else
124 | # include
125 | #endif
126 |
127 | #if USB_CFG_DRIVER_FLASH_PAGE
128 | # define USB_READ_FLASH(addr) pgm_read_byte_far(((long)USB_CFG_DRIVER_FLASH_PAGE << 16) | (long)(addr))
129 | #else
130 | # define USB_READ_FLASH(addr) pgm_read_byte(addr)
131 | #endif
132 |
133 | #define macro .macro
134 | #define endm .endm
135 | #define nop2 rjmp .+0 /* jump to next instruction */
136 |
137 | #endif /* development environment */
138 |
139 | /* for conveniecne, ensure that PRG_RDB exists */
140 | #ifndef PRG_RDB
141 | # define PRG_RDB(addr) USB_READ_FLASH(addr)
142 | #endif
143 | #endif /* __usbportability_h_INCLUDED__ */
144 |
--------------------------------------------------------------------------------
/v-usb.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------