diff options
Diffstat (limited to 'lib/vusb')
94 files changed, 13174 insertions, 0 deletions
diff --git a/lib/vusb/.gitignore b/lib/vusb/.gitignore new file mode 100644 index 000000000..20c204a9e --- /dev/null +++ b/lib/vusb/.gitignore | |||
@@ -0,0 +1,22 @@ | |||
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 | ||
diff --git a/lib/vusb/Makefile b/lib/vusb/Makefile new file mode 100644 index 000000000..a6eb8a54b --- /dev/null +++ b/lib/vusb/Makefile | |||
@@ -0,0 +1,60 @@ | |||
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 | |||
diff --git a/lib/vusb/README.md b/lib/vusb/README.md new file mode 100644 index 000000000..88b29da28 --- /dev/null +++ b/lib/vusb/README.md | |||
@@ -0,0 +1,33 @@ | |||
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 <http://www.obdev.at/vusb/>. | ||
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 | <http://www.obdev.at/vusb/>. 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. | ||
diff --git a/lib/vusb/Readme.txt b/lib/vusb/Readme.txt new file mode 100644 index 000000000..84d27f997 --- /dev/null +++ b/lib/vusb/Readme.txt | |||
@@ -0,0 +1,83 @@ | |||
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/ | ||
diff --git a/lib/vusb/circuits/Readme.txt b/lib/vusb/circuits/Readme.txt new file mode 100644 index 000000000..1aa52182e --- /dev/null +++ b/lib/vusb/circuits/Readme.txt | |||
@@ -0,0 +1,79 @@ | |||
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/ | ||
diff --git a/lib/vusb/circuits/tiny45-rc.sch b/lib/vusb/circuits/tiny45-rc.sch new file mode 100644 index 000000000..349f1ad60 --- /dev/null +++ b/lib/vusb/circuits/tiny45-rc.sch | |||
Binary files differ | |||
diff --git a/lib/vusb/circuits/with-series-diodes.sch b/lib/vusb/circuits/with-series-diodes.sch new file mode 100644 index 000000000..d84d99e56 --- /dev/null +++ b/lib/vusb/circuits/with-series-diodes.sch | |||
Binary files differ | |||
diff --git a/lib/vusb/circuits/with-vreg.sch b/lib/vusb/circuits/with-vreg.sch new file mode 100644 index 000000000..1f1797bdd --- /dev/null +++ b/lib/vusb/circuits/with-vreg.sch | |||
Binary files differ | |||
diff --git a/lib/vusb/circuits/with-zener.sch b/lib/vusb/circuits/with-zener.sch new file mode 100644 index 000000000..624177a7d --- /dev/null +++ b/lib/vusb/circuits/with-zener.sch | |||
Binary files differ | |||
diff --git a/lib/vusb/examples/Readme.txt b/lib/vusb/examples/Readme.txt new file mode 100644 index 000000000..82b10fe3d --- /dev/null +++ b/lib/vusb/examples/Readme.txt | |||
@@ -0,0 +1,102 @@ | |||
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/ | ||
diff --git a/lib/vusb/examples/custom-class/Readme.txt b/lib/vusb/examples/custom-class/Readme.txt new file mode 100644 index 000000000..815518ea1 --- /dev/null +++ b/lib/vusb/examples/custom-class/Readme.txt | |||
@@ -0,0 +1,64 @@ | |||
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/ | ||
diff --git a/lib/vusb/examples/custom-class/commandline/set-led.c b/lib/vusb/examples/custom-class/commandline/set-led.c new file mode 100644 index 000000000..fe0d75d71 --- /dev/null +++ b/lib/vusb/examples/custom-class/commandline/set-led.c | |||
@@ -0,0 +1,134 @@ | |||
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 <stdio.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | #include <usb.h> /* 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 | usb_dev_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; | ||
47 | |||
48 | usb_init(); | ||
49 | if(argc < 2){ /* we need at least one argument */ | ||
50 | usage(argv[0]); | ||
51 | exit(1); | ||
52 | } | ||
53 | /* compute VID/PID from usbconfig.h so that there is a central source of information */ | ||
54 | vid = rawVid[1] * 256 + rawVid[0]; | ||
55 | pid = rawPid[1] * 256 + rawPid[0]; | ||
56 | /* The following function is in opendevice.c: */ | ||
57 | if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){ | ||
58 | fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid); | ||
59 | exit(1); | ||
60 | } | ||
61 | /* Since we use only control endpoint 0, we don't need to choose a | ||
62 | * configuration and interface. Reading device descriptor and setting a | ||
63 | * configuration and interface is done through endpoint 0 after all. | ||
64 | * However, newer versions of Linux require that we claim an interface | ||
65 | * even for endpoint 0. Enable the following code if your operating system | ||
66 | * needs it: */ | ||
67 | #if 0 | ||
68 | int retries = 1, usbConfiguration = 1, usbInterface = 0; | ||
69 | if(usb_set_configuration(handle, usbConfiguration) && showWarnings){ | ||
70 | fprintf(stderr, "Warning: could not set configuration: %s\n", usb_strerror()); | ||
71 | } | ||
72 | /* now try to claim the interface and detach the kernel HID driver on | ||
73 | * Linux and other operating systems which support the call. */ | ||
74 | while((len = usb_claim_interface(handle, usbInterface)) != 0 && retries-- > 0){ | ||
75 | #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP | ||
76 | if(usb_detach_kernel_driver_np(handle, 0) < 0 && showWarnings){ | ||
77 | fprintf(stderr, "Warning: could not detach kernel driver: %s\n", usb_strerror()); | ||
78 | } | ||
79 | #endif | ||
80 | } | ||
81 | #endif | ||
82 | |||
83 | if(strcasecmp(argv[1], "status") == 0){ | ||
84 | cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_STATUS, 0, 0, buffer, sizeof(buffer), 5000); | ||
85 | if(cnt < 1){ | ||
86 | if(cnt < 0){ | ||
87 | fprintf(stderr, "USB error: %s\n", usb_strerror()); | ||
88 | }else{ | ||
89 | fprintf(stderr, "only %d bytes received.\n", cnt); | ||
90 | } | ||
91 | }else{ | ||
92 | printf("LED is %s\n", buffer[0] ? "on" : "off"); | ||
93 | } | ||
94 | }else if((isOn = (strcasecmp(argv[1], "on") == 0)) || strcasecmp(argv[1], "off") == 0){ | ||
95 | cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, isOn, 0, buffer, 0, 5000); | ||
96 | if(cnt < 0){ | ||
97 | fprintf(stderr, "USB error: %s\n", usb_strerror()); | ||
98 | } | ||
99 | #if ENABLE_TEST | ||
100 | }else if(strcasecmp(argv[1], "test") == 0){ | ||
101 | int i; | ||
102 | srandomdev(); | ||
103 | for(i = 0; i < 50000; i++){ | ||
104 | int value = random() & 0xffff, index = random() & 0xffff; | ||
105 | int rxValue, rxIndex; | ||
106 | if((i+1) % 100 == 0){ | ||
107 | fprintf(stderr, "\r%05d", i+1); | ||
108 | fflush(stderr); | ||
109 | } | ||
110 | cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_ECHO, value, index, buffer, sizeof(buffer), 5000); | ||
111 | if(cnt < 0){ | ||
112 | fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror()); | ||
113 | break; | ||
114 | }else if(cnt != 4){ | ||
115 | fprintf(stderr, "\nerror in iteration %d: %d bytes received instead of 4\n", i, cnt); | ||
116 | break; | ||
117 | } | ||
118 | rxValue = ((int)buffer[0] & 0xff) | (((int)buffer[1] & 0xff) << 8); | ||
119 | rxIndex = ((int)buffer[2] & 0xff) | (((int)buffer[3] & 0xff) << 8); | ||
120 | if(rxValue != value || rxIndex != index){ | ||
121 | fprintf(stderr, "\ndata error in iteration %d:\n", i); | ||
122 | fprintf(stderr, "rxValue = 0x%04x value = 0x%04x\n", rxValue, value); | ||
123 | fprintf(stderr, "rxIndex = 0x%04x index = 0x%04x\n", rxIndex, index); | ||
124 | } | ||
125 | } | ||
126 | fprintf(stderr, "\nTest completed.\n"); | ||
127 | #endif /* ENABLE_TEST */ | ||
128 | }else{ | ||
129 | usage(argv[0]); | ||
130 | exit(1); | ||
131 | } | ||
132 | usb_close(handle); | ||
133 | return 0; | ||
134 | } | ||
diff --git a/lib/vusb/examples/custom-class/firmware/main.c b/lib/vusb/examples/custom-class/firmware/main.c new file mode 100644 index 000000000..5c07a7fb0 --- /dev/null +++ b/lib/vusb/examples/custom-class/firmware/main.c | |||
@@ -0,0 +1,97 @@ | |||
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 <avr/io.h> | ||
23 | #include <avr/wdt.h> | ||
24 | #include <avr/interrupt.h> /* for sei() */ | ||
25 | #include <util/delay.h> /* for _delay_ms() */ | ||
26 | |||
27 | #include <avr/pgmspace.h> /* 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 | /* ------------------------------------------------------------------------- */ | ||
diff --git a/lib/vusb/examples/custom-class/firmware/requests.h b/lib/vusb/examples/custom-class/firmware/requests.h new file mode 100644 index 000000000..3d09e66e8 --- /dev/null +++ b/lib/vusb/examples/custom-class/firmware/requests.h | |||
@@ -0,0 +1,35 @@ | |||
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__ */ | ||
diff --git a/lib/vusb/examples/custom-class/make-files.sh b/lib/vusb/examples/custom-class/make-files.sh new file mode 100755 index 000000000..df3fa5eed --- /dev/null +++ b/lib/vusb/examples/custom-class/make-files.sh | |||
@@ -0,0 +1,43 @@ | |||
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/ | ||
diff --git a/lib/vusb/examples/drivertest/commandline/runtest.c b/lib/vusb/examples/drivertest/commandline/runtest.c new file mode 100644 index 000000000..3d04421f4 --- /dev/null +++ b/lib/vusb/examples/drivertest/commandline/runtest.c | |||
@@ -0,0 +1,151 @@ | |||
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 <stdio.h> | ||
14 | #include <stdlib.h> | ||
15 | #include <string.h> | ||
16 | #include <usb.h> /* this is libusb */ | ||
17 | #include "opendevice.h" /* common code moved to separate module */ | ||
18 | |||
19 | #include "../firmware/requests.h" /* custom request numbers */ | ||
20 | #include "../firmware/usbconfig.h" /* device's VID/PID and names */ | ||
21 | |||
22 | #define uchar unsigned char | ||
23 | |||
24 | static void hexdump(char *_buffer, int len, FILE *fp) | ||
25 | { | ||
26 | int i; | ||
27 | uchar *buffer = (uchar *)_buffer; | ||
28 | |||
29 | for(i = 0; i < len; i++){ | ||
30 | if(i != 0){ | ||
31 | if(i % 16 == 0){ | ||
32 | fprintf(fp, "\n"); | ||
33 | }else{ | ||
34 | fprintf(fp, " "); | ||
35 | } | ||
36 | } | ||
37 | fprintf(fp, "%02x", buffer[i]); | ||
38 | } | ||
39 | if(i != 0) | ||
40 | fprintf(fp, "\n"); | ||
41 | } | ||
42 | |||
43 | static void fillBuffer(char *buffer, int len) | ||
44 | { | ||
45 | static int type = 0; | ||
46 | |||
47 | if(type == 0){ /* all 0 */ | ||
48 | bzero(buffer, len); | ||
49 | }else if(type == 1){ /* all 0xff */ | ||
50 | memset(buffer, 0xff, len); | ||
51 | }else{ /* random */ | ||
52 | int i; | ||
53 | for(i = 0; i < len; i++){ | ||
54 | buffer[i] = random() & 0xff; | ||
55 | } | ||
56 | } | ||
57 | if(++type >= 1000) | ||
58 | type = 0; | ||
59 | } | ||
60 | |||
61 | static int compareBuffers(char *txBuffer, char *rxBuffer, int len) | ||
62 | { | ||
63 | int i, rval = 0; | ||
64 | |||
65 | for(i = 0; i < len; i++){ | ||
66 | if(rxBuffer[i] != txBuffer[i]){ | ||
67 | fprintf(stderr, "compare error at index %d: byte is 0x%x instead of 0x%x\n", i, rxBuffer[i], txBuffer[i]); | ||
68 | rval = 1; | ||
69 | } | ||
70 | } | ||
71 | if(rval){ | ||
72 | fprintf(stderr, "txBuffer was:\n"); | ||
73 | hexdump(txBuffer, len, stderr); | ||
74 | fprintf(stderr, "rxBuffer is:\n"); | ||
75 | hexdump(rxBuffer, len, stderr); | ||
76 | } | ||
77 | return rval; | ||
78 | } | ||
79 | |||
80 | int main(int argc, char **argv) | ||
81 | { | ||
82 | usb_dev_handle *handle = NULL; | ||
83 | const uchar rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID}; | ||
84 | char vendor[] = {USB_CFG_VENDOR_NAME, 0}, product[] = {USB_CFG_DEVICE_NAME, 0}; | ||
85 | char txBuffer[64], rxBuffer[64]; | ||
86 | int cnt, vid, pid, i, j; | ||
87 | |||
88 | usb_init(); | ||
89 | /* compute VID/PID from usbconfig.h so that there is a central source of information */ | ||
90 | vid = rawVid[1] * 256 + rawVid[0]; | ||
91 | pid = rawPid[1] * 256 + rawPid[0]; | ||
92 | /* The following function is in opendevice.c: */ | ||
93 | if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){ | ||
94 | fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid); | ||
95 | exit(1); | ||
96 | } | ||
97 | if(argc > 1 && strcasecmp(argv[1], "osccal") == 0){ | ||
98 | if(argc > 2){ /* set osccal */ | ||
99 | int osccal = atoi(argv[2]); | ||
100 | printf("setting osccal to %d\n", osccal); | ||
101 | cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_SET_OSCCAL, osccal, 0, txBuffer, 0, 5000); | ||
102 | if(cnt < 0){ | ||
103 | fprintf(stderr, "\nUSB error setting osccal: %s\n", usb_strerror()); | ||
104 | } | ||
105 | }else{ | ||
106 | cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_OSCCAL, 0, 0, rxBuffer, 1, 5000); | ||
107 | if(cnt < 0){ | ||
108 | fprintf(stderr, "\nUSB error getting osccal: %s\n", usb_strerror()); | ||
109 | }else{ | ||
110 | printf("osccal = %d\n", (unsigned char)rxBuffer[0]); | ||
111 | } | ||
112 | } | ||
113 | }else{ | ||
114 | srandomdev(); | ||
115 | for(i = 0; i <= 100000; i++){ | ||
116 | fillBuffer(txBuffer, sizeof(txBuffer)); | ||
117 | cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_DATA, 0, 0, txBuffer, sizeof(txBuffer), 5000); | ||
118 | if(cnt < 0){ | ||
119 | fprintf(stderr, "\nUSB tx error in iteration %d: %s\n", i, usb_strerror()); | ||
120 | break; | ||
121 | }else if(cnt != sizeof(txBuffer)){ | ||
122 | fprintf(stderr, "\nerror in iteration %d: %d bytes sent instead of %d\n", i, cnt, (int)sizeof(txBuffer)); | ||
123 | break; | ||
124 | } | ||
125 | for(j = 0; j < sizeof(rxBuffer); j++){ | ||
126 | rxBuffer[j] = ~txBuffer[j]; | ||
127 | } | ||
128 | cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_DATA, 0, 0, rxBuffer, sizeof(rxBuffer), 5000); | ||
129 | if(cnt < 0){ | ||
130 | fprintf(stderr, "\nUSB rx error in iteration %d: %s\n", i, usb_strerror()); | ||
131 | break; | ||
132 | }else if(cnt != sizeof(txBuffer)){ | ||
133 | fprintf(stderr, "\nerror in iteration %d: %d bytes received instead of %d\n", i, cnt, (int)sizeof(rxBuffer)); | ||
134 | break; | ||
135 | } | ||
136 | if(compareBuffers(txBuffer, rxBuffer, sizeof(rxBuffer))){ | ||
137 | fprintf(stderr, "\ncompare error in iteration %d.\n", i); | ||
138 | break; | ||
139 | } | ||
140 | if(i != 0 && i % 100 == 0){ | ||
141 | printf("."); | ||
142 | fflush(stdout); | ||
143 | if(i % 5000 == 0) | ||
144 | printf(" %6d\n", i); | ||
145 | } | ||
146 | } | ||
147 | fprintf(stderr, "\nTest completed.\n"); | ||
148 | } | ||
149 | usb_close(handle); | ||
150 | return 0; | ||
151 | } | ||
diff --git a/lib/vusb/examples/drivertest/firmware/main.c b/lib/vusb/examples/drivertest/firmware/main.c new file mode 100644 index 000000000..d24e50f67 --- /dev/null +++ b/lib/vusb/examples/drivertest/firmware/main.c | |||
@@ -0,0 +1,128 @@ | |||
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 <avr/io.h> | ||
18 | #include <avr/wdt.h> | ||
19 | #include <avr/interrupt.h> /* for sei() */ | ||
20 | #include <util/delay.h> /* for _delay_ms() */ | ||
21 | |||
22 | #include <avr/pgmspace.h> /* 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 | /* ------------------------------------------------------------------------- */ | ||
diff --git a/lib/vusb/examples/drivertest/firmware/requests.h b/lib/vusb/examples/drivertest/firmware/requests.h new file mode 100644 index 000000000..475101a37 --- /dev/null +++ b/lib/vusb/examples/drivertest/firmware/requests.h | |||
@@ -0,0 +1,28 @@ | |||
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__ */ | ||
diff --git a/lib/vusb/examples/drivertest/make-files.sh b/lib/vusb/examples/drivertest/make-files.sh new file mode 100755 index 000000000..af4ef7950 --- /dev/null +++ b/lib/vusb/examples/drivertest/make-files.sh | |||
@@ -0,0 +1,33 @@ | |||
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/ | ||
diff --git a/lib/vusb/examples/hid-custom-rq/Readme.txt b/lib/vusb/examples/hid-custom-rq/Readme.txt new file mode 100644 index 000000000..6a2ab3b6c --- /dev/null +++ b/lib/vusb/examples/hid-custom-rq/Readme.txt | |||
@@ -0,0 +1,28 @@ | |||
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/ | ||
diff --git a/lib/vusb/examples/hid-custom-rq/firmware/main.c b/lib/vusb/examples/hid-custom-rq/firmware/main.c new file mode 100644 index 000000000..605d58b47 --- /dev/null +++ b/lib/vusb/examples/hid-custom-rq/firmware/main.c | |||
@@ -0,0 +1,120 @@ | |||
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 <avr/io.h> | ||
23 | #include <avr/wdt.h> | ||
24 | #include <avr/interrupt.h> /* for sei() */ | ||
25 | #include <util/delay.h> /* for _delay_ms() */ | ||
26 | |||
27 | #include <avr/pgmspace.h> /* 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 | /* ------------------------------------------------------------------------- */ | ||
diff --git a/lib/vusb/examples/hid-custom-rq/firmware/requests.h b/lib/vusb/examples/hid-custom-rq/firmware/requests.h new file mode 100644 index 000000000..630a68551 --- /dev/null +++ b/lib/vusb/examples/hid-custom-rq/firmware/requests.h | |||
@@ -0,0 +1,31 @@ | |||
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__ */ | ||
diff --git a/lib/vusb/examples/hid-custom-rq/make-files.sh b/lib/vusb/examples/hid-custom-rq/make-files.sh new file mode 100755 index 000000000..844761489 --- /dev/null +++ b/lib/vusb/examples/hid-custom-rq/make-files.sh | |||
@@ -0,0 +1,61 @@ | |||
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/ | ||
diff --git a/lib/vusb/examples/hid-data/Readme.txt b/lib/vusb/examples/hid-data/Readme.txt new file mode 100644 index 000000000..cb17baa01 --- /dev/null +++ b/lib/vusb/examples/hid-data/Readme.txt | |||
@@ -0,0 +1,75 @@ | |||
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/ | ||
diff --git a/lib/vusb/examples/hid-data/commandline/hidtool.c b/lib/vusb/examples/hid-data/commandline/hidtool.c new file mode 100644 index 000000000..609531253 --- /dev/null +++ b/lib/vusb/examples/hid-data/commandline/hidtool.c | |||
@@ -0,0 +1,126 @@ | |||
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 <stdio.h> | ||
11 | #include <string.h> | ||
12 | #include <stdlib.h> | ||
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 <listofbytes>\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 | /* ------------------------------------------------------------------------- */ | ||
diff --git a/lib/vusb/examples/hid-data/firmware/main.c b/lib/vusb/examples/hid-data/firmware/main.c new file mode 100644 index 000000000..7c8c85e4b --- /dev/null +++ b/lib/vusb/examples/hid-data/firmware/main.c | |||
@@ -0,0 +1,141 @@ | |||
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 <avr/io.h> | ||
18 | #include <avr/wdt.h> | ||
19 | #include <avr/interrupt.h> /* for sei() */ | ||
20 | #include <util/delay.h> /* for _delay_ms() */ | ||
21 | #include <avr/eeprom.h> | ||
22 | |||
23 | #include <avr/pgmspace.h> /* 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 | /* ------------------------------------------------------------------------- */ | ||
diff --git a/lib/vusb/examples/hid-data/make-files.sh b/lib/vusb/examples/hid-data/make-files.sh new file mode 100755 index 000000000..3da9bd549 --- /dev/null +++ b/lib/vusb/examples/hid-data/make-files.sh | |||
@@ -0,0 +1,44 @@ | |||
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 | ||
diff --git a/lib/vusb/examples/hid-mouse/Readme.txt b/lib/vusb/examples/hid-mouse/Readme.txt new file mode 100644 index 000000000..e0c814281 --- /dev/null +++ b/lib/vusb/examples/hid-mouse/Readme.txt | |||
@@ -0,0 +1,48 @@ | |||
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/ | ||
diff --git a/lib/vusb/examples/hid-mouse/firmware/main.c b/lib/vusb/examples/hid-mouse/firmware/main.c new file mode 100644 index 000000000..e98673123 --- /dev/null +++ b/lib/vusb/examples/hid-mouse/firmware/main.c | |||
@@ -0,0 +1,164 @@ | |||
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 <avr/io.h> | ||
21 | #include <avr/wdt.h> | ||
22 | #include <avr/interrupt.h> /* for sei() */ | ||
23 | #include <util/delay.h> /* for _delay_ms() */ | ||
24 | |||
25 | #include <avr/pgmspace.h> /* 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 | /* ------------------------------------------------------------------------- */ | ||
diff --git a/lib/vusb/examples/hid-mouse/make-files.sh b/lib/vusb/examples/hid-mouse/make-files.sh new file mode 100755 index 000000000..3e931c4ee --- /dev/null +++ b/lib/vusb/examples/hid-mouse/make-files.sh | |||
@@ -0,0 +1,38 @@ | |||
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 | ||
diff --git a/lib/vusb/examples/usbtool/Makefile b/lib/vusb/examples/usbtool/Makefile new file mode 100644 index 000000000..1f2a8ab81 --- /dev/null +++ b/lib/vusb/examples/usbtool/Makefile | |||
@@ -0,0 +1,47 @@ | |||
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 = `libusb-config --cflags` | ||
15 | USBLIBS = `libusb-config --libs` | ||
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 | ||
21 | #USBLIBS = -L/usr/local/lib -lusb | ||
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) | ||
diff --git a/lib/vusb/examples/usbtool/Makefile.windows b/lib/vusb/examples/usbtool/Makefile.windows new file mode 100644 index 000000000..8298dd3b1 --- /dev/null +++ b/lib/vusb/examples/usbtool/Makefile.windows | |||
@@ -0,0 +1,17 @@ | |||
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 | ||
16 | USBLIBS = -L/usr/local/mingw/lib -lusb | ||
17 | EXE_SUFFIX = .exe | ||
diff --git a/lib/vusb/examples/usbtool/Readme.txt b/lib/vusb/examples/usbtool/Readme.txt new file mode 100644 index 000000000..33f527cc4 --- /dev/null +++ b/lib/vusb/examples/usbtool/Readme.txt | |||
@@ -0,0 +1,209 @@ | |||
1 | This is the Readme file for usbtool, a general purpose command line utility | ||
2 | which can send USB requests to arbitrary devices. Usbtool is based on libusb. | ||
3 | |||
4 | |||
5 | WHAT IS USBTOOL GOOD FOR? | ||
6 | ========================= | ||
7 | When you implement a communication protocol like USB, you must usually write | ||
8 | two programs: one on each end of the communication. For USB, this means that | ||
9 | you must write a firmware for the device and driver software for the host. | ||
10 | |||
11 | Usbtool can save you the work of writing the host software, at least during | ||
12 | firmware development and testing. Usbtool can send control-in and -out | ||
13 | requests to arbitrary devices and send and receive data on interrupt- and | ||
14 | bulk-endpoints. | ||
15 | |||
16 | Usbtool is not only a useful developer tool, it's also an example for using | ||
17 | libusb for communication with the device. | ||
18 | |||
19 | |||
20 | SYNOPSIS | ||
21 | ======== | ||
22 | usbtool [options] <command> | ||
23 | |||
24 | |||
25 | COMMANDS | ||
26 | ======== | ||
27 | list | ||
28 | This command prints a list of devices found on all available USB busses. | ||
29 | Options -v, -V, -p and -P can be used to filter the list. | ||
30 | |||
31 | control in|out <type> <recipient> <request> <value> <index> | ||
32 | Sends a control-in or control-out request to the device. The request | ||
33 | parameters are: | ||
34 | type ........ Type of request, can be "standard", "class", "vendor" or | ||
35 | "reserved". The type determines which software module in | ||
36 | the device is responsible for answering the request: | ||
37 | Standard requests are answered by the driver, class | ||
38 | requests by the class implementation (e.g. HID, CDC) and | ||
39 | vendor requests by custom code. | ||
40 | recipient ... Recipient of the request in the device. Can be "device", | ||
41 | "interface", "endpoint" or "other". For standard and | ||
42 | class requests, the specification defines a recipient for | ||
43 | each request. For vendor requests, choose whatever your | ||
44 | code expects. | ||
45 | request ..... 8 bit numeric value identifying the request. | ||
46 | value ....... 16 bit numeric value passed to the device. | ||
47 | index ....... another 16 bit numeric value passed to the device. | ||
48 | Use options -v, -V, -p and -P to single out a particular device. Use | ||
49 | options -d or -D to to send data in an OUT request. Use options -n, -O | ||
50 | and -b to determine what to do with data received in an IN request. | ||
51 | |||
52 | interrupt in|out | ||
53 | Sends or receives data on an interrupt-out resp. -in endpoint. | ||
54 | Use options -v, -V, -p and -P to single out a particular device. Use | ||
55 | options -d or -D to to send data to an OUT endpoint. Use options -n, -O | ||
56 | and -b to determine what to do with data received from an IN endpoint. | ||
57 | Use option -e to set the endpoint number, -c to choose a configuration | ||
58 | -i to claim a particular interface. | ||
59 | |||
60 | bulk in|out | ||
61 | Same as "interrupt in" and "interrupt out", but for bulk endpoints. | ||
62 | |||
63 | |||
64 | OPTIONS | ||
65 | ======= | ||
66 | Most options have already been mentioned at the commands which use them. | ||
67 | here is a complete list: | ||
68 | |||
69 | -h or -? | ||
70 | Prints a short help. | ||
71 | |||
72 | -v <vendor-id> | ||
73 | Numeric vendor ID, can be "*" to allow any VID. Take only devices with | ||
74 | matching vendor ID into account. | ||
75 | |||
76 | -p <product-id> | ||
77 | Numeric product ID, can be "*" to allow any PID. Take only devices with | ||
78 | matching product ID into account. | ||
79 | |||
80 | -V <vendor-name-pattern> | ||
81 | Shell style matching pattern for vendor name. Take only devices into | ||
82 | account which have a vendor name that matches this pattern. | ||
83 | |||
84 | -P <product-name-pattern> | ||
85 | Shell style matching pattern for product name. Take only devices into | ||
86 | account which have a product name that matches this pattern. | ||
87 | |||
88 | -S <serial-pattern> | ||
89 | Shell style matching pattern for serial number. Take only devices into | ||
90 | account which have a serial number that matches this pattern. | ||
91 | |||
92 | -d <databytes> | ||
93 | Data bytes to send to the device, comma separated list of numeric values. | ||
94 | E.g.: "1,2,3,4,5". | ||
95 | |||
96 | -D <file> | ||
97 | Binary data sent to the device should be taken from this file. | ||
98 | |||
99 | -O <file> | ||
100 | Write received data bytes to the given file. Format is either hex or | ||
101 | binary, depending on the -b flag. By default, received data is printed | ||
102 | to standard output. | ||
103 | |||
104 | -b | ||
105 | Request binary output format for files and standard output. Default is | ||
106 | a hexadecimal listing. | ||
107 | |||
108 | -n <count> | ||
109 | Numeric value: Maximum number of bytes to receive. This value is passed | ||
110 | directly to the libusb API functions. | ||
111 | |||
112 | -e <endpoint> | ||
113 | Numeric value: Endpoint number for interrupt and bulk commands. | ||
114 | |||
115 | -t <timeout> | ||
116 | Numeric value: Timeout in milliseconds for the request. This value is | ||
117 | passed directly to the libusb API functions. | ||
118 | |||
119 | -c <configuration> | ||
120 | Numeric value: Interrupt and bulk endpoints can usually only be used if | ||
121 | a configuration and an interface has been chosen. Use -c and -i to | ||
122 | specify configuration and interface values. | ||
123 | |||
124 | -i <interface> | ||
125 | Numeric value: Interrupt and bulk endpoints can usually only be used if | ||
126 | a configuration and an interface has been chosen. Use -c and -i to | ||
127 | specify configuration and interface values. | ||
128 | |||
129 | -w | ||
130 | Usbtool may be too verbose with warnings for some applications. Use this | ||
131 | option to suppress USB warnings. | ||
132 | |||
133 | |||
134 | NUMERIC VALUES | ||
135 | ============== | ||
136 | All numeric values can be given in hexadecimal, decimal or octal. Hex values | ||
137 | are identified by their 0x or 0X prefix, octal values by a leading "0" (the | ||
138 | digit zero) and decimal values because they start with a non-zero digit. An | ||
139 | optional sign character is allowed. The special value "*" is translated to | ||
140 | zero and stands for "any value" in some contexts. | ||
141 | |||
142 | |||
143 | SHELL STYLE MATCHING PATTERNS | ||
144 | ============================= | ||
145 | Some options take shell style matching patterns as an argument. This refers | ||
146 | to Unix shells and their file wildcard operations: | ||
147 | + "*" (asterisk character) matches any number (0 to infinite) of any | ||
148 | characters. | ||
149 | + "?" matches exactly one arbitrary character. | ||
150 | + A list of characters in square brackets (e.g. "[abc]") matches any of the | ||
151 | characters in the list. If a dash ("-") is in the list, it must be the | ||
152 | first or the last character. If a caret ("^") is in the list, it must | ||
153 | not be the first character. A closing square bracket ("]") must be the | ||
154 | first character in the list. A range of characters can be specified in | ||
155 | the way "[a-z]". This matches all characters with numeric representation | ||
156 | (usually ASCII) starting with "a" and ending with "z". The entire | ||
157 | construct matches only one character. | ||
158 | + A list of characters in square brackets starting with a caret ("^"), e.g. | ||
159 | ("[^abc]") matches any character NOT in the list. The other rules are as | ||
160 | above. | ||
161 | + "\" (backslash) followed by any character matches that following | ||
162 | character. This can be used to escape "*", "?", "[" and "\". | ||
163 | |||
164 | |||
165 | BUILDING USBTOOL | ||
166 | ================ | ||
167 | Usbtool uses libusb on Unix and libusb-win32 on Windows. These libraries can | ||
168 | be obtained from http://libusb.sourceforge.net/ and | ||
169 | http://libusb-win32.sourceforge.net/ respectively. On Unix, a simple "make" | ||
170 | should compile the sources (although you may have to edit Makefile to | ||
171 | include or remove additional libraries). On Windows, we recommend that you | ||
172 | use MinGW and MSYS. See the top level Readme file for details. Edit | ||
173 | Makefile.windows according to your library installation paths and build with | ||
174 | "make -f Makefile.windows". | ||
175 | |||
176 | |||
177 | EXAMPLES | ||
178 | ======== | ||
179 | To list all devices connected to your computer, do | ||
180 | |||
181 | usbtool -w list | ||
182 | |||
183 | To check whether our selection options single out the desired device, use eg. | ||
184 | |||
185 | usbtool -w -P LEDControl list | ||
186 | |||
187 | This command shows all LEDControl devices connected or prints nothing if | ||
188 | none is found. LEDControl is the device from the "custom-class" example. | ||
189 | |||
190 | You can also send commands to the LEDControl device using usbtool. From | ||
191 | the file requests.h in custom-class/firmware, we know that the set-status | ||
192 | request has numeric value 1 and the get-status request is 2. See this file | ||
193 | for details of the protocol used. We can therefore query the status with | ||
194 | |||
195 | usbtool -w -P LEDControl control in vendor device 2 0 0 | ||
196 | |||
197 | This command prints 0x00 if the LED is off or 0x01 if it is on. To turn the | ||
198 | LED on, use | ||
199 | |||
200 | usbtool -w -P LEDControl control out vendor device 1 1 0 | ||
201 | |||
202 | and to turn it off, use | ||
203 | |||
204 | usbtool -w -P LEDControl control out vendor device 1 0 0 | ||
205 | |||
206 | |||
207 | ---------------------------------------------------------------------------- | ||
208 | (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH. | ||
209 | http://www.obdev.at/ | ||
diff --git a/lib/vusb/examples/usbtool/make-files.sh b/lib/vusb/examples/usbtool/make-files.sh new file mode 100755 index 000000000..8519514a8 --- /dev/null +++ b/lib/vusb/examples/usbtool/make-files.sh | |||
@@ -0,0 +1,15 @@ | |||
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] . | ||
diff --git a/lib/vusb/examples/usbtool/usbtool.c b/lib/vusb/examples/usbtool/usbtool.c new file mode 100644 index 000000000..56bdac109 --- /dev/null +++ b/lib/vusb/examples/usbtool/usbtool.c | |||
@@ -0,0 +1,355 @@ | |||
1 | /* Name: usbtool.c | ||
2 | * Project: V-USB examples, host side | ||
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 | /* | ||
11 | General Description: | ||
12 | This command line tool can perform various USB requests at arbitrary | ||
13 | USB devices. It is intended as universal host side tool for experimentation | ||
14 | and debugging purposes. It must be linked with libusb, a library for accessing | ||
15 | the USB bus from Linux, FreeBSD, Mac OS X and other Unix operating systems. | ||
16 | Libusb can be obtained from http://libusb.sourceforge.net/. | ||
17 | On Windows use libusb-win32 from http://libusb-win32.sourceforge.net/. | ||
18 | */ | ||
19 | |||
20 | #include <stdio.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | #include <unistd.h> | ||
24 | #include <stdarg.h> | ||
25 | #include <ctype.h> | ||
26 | #include <errno.h> | ||
27 | |||
28 | #include <usb.h> /* this is libusb, see http://libusb.sourceforge.net/ */ | ||
29 | #include "opendevice.h" /* common code moved to separate module */ | ||
30 | |||
31 | #define DEFAULT_USB_VID 0 /* any */ | ||
32 | #define DEFAULT_USB_PID 0 /* any */ | ||
33 | |||
34 | static void usage(char *name) | ||
35 | { | ||
36 | fprintf(stderr, "usage: %s [options] <command>\n", name); | ||
37 | fprintf(stderr, | ||
38 | "Options are:\n" | ||
39 | " -h or -? (print this help and exit)\n" | ||
40 | " -v <vendor-id> (defaults to 0x%x, can be '*' for any VID)\n" | ||
41 | " -p <product-id> (defaults to 0x%x, can be '*' for any PID)\n" | ||
42 | " -V <vendor-name-pattern> (shell style matching, defaults to '*')\n" | ||
43 | " -P <product-name-pattern> (shell style matching, defaults to '*')\n" | ||
44 | " -S <serial-pattern> (shell style matching, defaults to '*')\n" | ||
45 | " -d <databytes> (data byte for request, comma separated list)\n" | ||
46 | " -D <file> (binary data for request taken from file)\n" | ||
47 | " -O <file> (write received data bytes to file)\n" | ||
48 | " -b (binary output format, default is hex)\n" | ||
49 | " -n <count> (maximum number of bytes to receive)\n" | ||
50 | " -e <endpoint> (specify endpoint for some commands)\n" | ||
51 | " -t <timeout> (specify USB timeout in milliseconds)\n" | ||
52 | " -c <configuration> (device configuration to choose)\n" | ||
53 | " -i <interface> (configuration interface to claim)\n" | ||
54 | " -w (suppress USB warnings, default is verbose)\n" | ||
55 | "\n" | ||
56 | "Commands are:\n" | ||
57 | " list (list all matching devices by name)\n" | ||
58 | " control in|out <type> <recipient> <request> <value> <index> (send control request)\n" | ||
59 | " interrupt in|out (send or receive interrupt data)\n" | ||
60 | " bulk in|out (send or receive bulk data)\n" | ||
61 | "For valid enum values for <type> and <recipient> pass \"x\" for the value.\n" | ||
62 | "Objective Development's free VID/PID pairs are:\n" | ||
63 | " 5824/1500 for vendor class devices\n" | ||
64 | " 5824/1503 for HID class devices excluding mice and keyboards\n" | ||
65 | " 5824/1505 for CDC-ACM class devices\n" | ||
66 | " 5824/1508 for MIDI class devices\n" | ||
67 | , DEFAULT_USB_VID, DEFAULT_USB_PID | ||
68 | ); | ||
69 | |||
70 | |||
71 | } | ||
72 | |||
73 | static int vendorID = DEFAULT_USB_VID; | ||
74 | static int productID = DEFAULT_USB_PID; | ||
75 | static char *vendorNamePattern = "*"; | ||
76 | static char *productNamePattern = "*"; | ||
77 | static char *serialPattern = "*"; | ||
78 | static char *sendBytes = NULL; | ||
79 | static int sendByteCount; | ||
80 | static char *outputFile = NULL; | ||
81 | static int endpoint = 0; | ||
82 | static int outputFormatIsBinary = 0; | ||
83 | static int showWarnings = 1; | ||
84 | static int usbTimeout = 5000; | ||
85 | static int usbCount = 128; | ||
86 | static int usbConfiguration = 1; | ||
87 | static int usbInterface = 0; | ||
88 | |||
89 | static int usbDirection, usbType, usbRecipient, usbRequest, usbValue, usbIndex; /* arguments of control transfer */ | ||
90 | |||
91 | /* ------------------------------------------------------------------------- */ | ||
92 | |||
93 | /* ASCII to integer (number parsing) which allows hex (0x prefix), | ||
94 | * octal (0 prefix) and decimal (1-9 prefix) input. | ||
95 | */ | ||
96 | static int myAtoi(char *text) | ||
97 | { | ||
98 | long l; | ||
99 | char *endPtr; | ||
100 | |||
101 | if(strcmp(text, "*") == 0) | ||
102 | return 0; | ||
103 | l = strtol(text, &endPtr, 0); | ||
104 | if(endPtr == text){ | ||
105 | fprintf(stderr, "warning: can't parse numeric parameter ->%s<-, defaults to 0.\n", text); | ||
106 | l = 0; | ||
107 | }else if(*endPtr != 0){ | ||
108 | fprintf(stderr, "warning: numeric parameter ->%s<- only partially parsed.\n", text); | ||
109 | } | ||
110 | return l; | ||
111 | } | ||
112 | |||
113 | static int parseEnum(char *text, ...) | ||
114 | { | ||
115 | va_list vlist; | ||
116 | char *entries[64]; | ||
117 | int i, numEntries; | ||
118 | |||
119 | va_start(vlist, text); | ||
120 | for(i = 0; i < 64; i++){ | ||
121 | entries[i] = va_arg(vlist, char *); | ||
122 | if(entries[i] == NULL) | ||
123 | break; | ||
124 | } | ||
125 | numEntries = i; | ||
126 | va_end(vlist); | ||
127 | for(i = 0; i < numEntries; i++){ | ||
128 | if(strcasecmp(text, entries[i]) == 0) | ||
129 | return i; | ||
130 | } | ||
131 | if(isdigit(*text)){ | ||
132 | return myAtoi(text); | ||
133 | } | ||
134 | fprintf(stderr, "Enum value \"%s\" not allowed. Allowed values are:\n", text); | ||
135 | for(i = 0; i < numEntries; i++){ | ||
136 | fprintf(stderr, " %s\n", entries[i]); | ||
137 | } | ||
138 | exit(1); | ||
139 | } | ||
140 | |||
141 | /* ------------------------------------------------------------------------- */ | ||
142 | |||
143 | #define ACTION_LIST 0 | ||
144 | #define ACTION_CONTROL 1 | ||
145 | #define ACTION_INTERRUPT 2 | ||
146 | #define ACTION_BULK 3 | ||
147 | |||
148 | int main(int argc, char **argv) | ||
149 | { | ||
150 | usb_dev_handle *handle = NULL; | ||
151 | int opt, len, action, argcnt; | ||
152 | char *myName = argv[0], *s, *rxBuffer = NULL; | ||
153 | FILE *fp; | ||
154 | |||
155 | while((opt = getopt(argc, argv, "?hv:p:V:P:S:d:D:O:e:n:tbw")) != -1){ | ||
156 | switch(opt){ | ||
157 | case 'h': | ||
158 | case '?': /* -h or -? (print this help and exit) */ | ||
159 | usage(myName); | ||
160 | exit(1); | ||
161 | case 'v': /* -v <vendor-id> (defaults to 0x%x, can be '*' for any VID) */ | ||
162 | vendorID = myAtoi(optarg); | ||
163 | break; | ||
164 | case 'p': /* -p <product-id> (defaults to 0x%x, can be '*' for any PID) */ | ||
165 | productID = myAtoi(optarg); | ||
166 | break; | ||
167 | case 'V': /* -V <vendor-name-pattern> (shell style matching, defaults to '*') */ | ||
168 | vendorNamePattern = optarg; | ||
169 | break; | ||
170 | case 'P': /* -P <product-name-pattern> (shell style matching, defaults to '*') */ | ||
171 | productNamePattern = optarg; | ||
172 | break; | ||
173 | case 'S': /* -S <serial-pattern> (shell style matching, defaults to '*') */ | ||
174 | serialPattern = optarg; | ||
175 | break; | ||
176 | case 'd': /* -d <databytes> (data bytes for requests given on command line) */ | ||
177 | while((s = strtok(optarg, ", ")) != NULL){ | ||
178 | optarg = NULL; | ||
179 | if(sendBytes != NULL){ | ||
180 | sendBytes = realloc(sendBytes, sendByteCount + 1); | ||
181 | }else{ | ||
182 | sendBytes = malloc(sendByteCount + 1); | ||
183 | } | ||
184 | sendBytes[sendByteCount++] = myAtoi(s); | ||
185 | } | ||
186 | break; | ||
187 | case 'D': /* -D <file> (data bytes for request taken from file) */ | ||
188 | if((fp = fopen(optarg, "rb")) == NULL){ | ||
189 | fprintf(stderr, "error opening %s: %s\n", optarg, strerror(errno)); | ||
190 | exit(1); | ||
191 | } | ||
192 | fseek(fp, 0, SEEK_END); | ||
193 | len = ftell(fp); | ||
194 | fseek(fp, 0, SEEK_SET); | ||
195 | if(sendBytes != NULL){ | ||
196 | sendBytes = realloc(sendBytes, sendByteCount + len); | ||
197 | }else{ | ||
198 | sendBytes = malloc(sendByteCount + len); | ||
199 | } | ||
200 | fread(sendBytes + sendByteCount, 1, len, fp); /* would need error checking */ | ||
201 | sendByteCount += len; | ||
202 | fclose(fp); | ||
203 | break; | ||
204 | case 'O': /* -O <file> (write received data bytes to file) */ | ||
205 | outputFile = optarg; | ||
206 | break; | ||
207 | case 'e': /* -e <endpoint> (specify endpoint for some commands) */ | ||
208 | endpoint = myAtoi(optarg); | ||
209 | break; | ||
210 | case 't': /* -t <timeout> (specify USB timeout in milliseconds) */ | ||
211 | usbTimeout = myAtoi(optarg); | ||
212 | break; | ||
213 | case 'b': /* -b (binary output format, default is hex) */ | ||
214 | outputFormatIsBinary = 1; | ||
215 | break; | ||
216 | case 'n': /* -n <count> (maximum number of bytes to receive) */ | ||
217 | usbCount = myAtoi(optarg); | ||
218 | break; | ||
219 | case 'c': /* -c <configuration> (device configuration to choose) */ | ||
220 | usbConfiguration = myAtoi(optarg); | ||
221 | break; | ||
222 | case 'i': /* -i <interface> (configuration interface to claim) */ | ||
223 | usbInterface = myAtoi(optarg); | ||
224 | break; | ||
225 | case 'w': /* -w (suppress USB warnings, default is verbose) */ | ||
226 | showWarnings = 0; | ||
227 | break; | ||
228 | default: | ||
229 | fprintf(stderr, "Option -%c unknown\n", opt); | ||
230 | exit(1); | ||
231 | } | ||
232 | } | ||
233 | argc -= optind; | ||
234 | argv += optind; | ||
235 | if(argc < 1){ | ||
236 | usage(myName); | ||
237 | exit(1); | ||
238 | } | ||
239 | argcnt = 2; | ||
240 | if(strcasecmp(argv[0], "list") == 0){ | ||
241 | action = ACTION_LIST; | ||
242 | argcnt = 1; | ||
243 | }else if(strcasecmp(argv[0], "control") == 0){ | ||
244 | action = ACTION_CONTROL; | ||
245 | argcnt = 7; | ||
246 | }else if(strcasecmp(argv[0], "interrupt") == 0){ | ||
247 | action = ACTION_INTERRUPT; | ||
248 | }else if(strcasecmp(argv[0], "bulk") == 0){ | ||
249 | action = ACTION_BULK; | ||
250 | }else{ | ||
251 | fprintf(stderr, "command %s not known\n", argv[0]); | ||
252 | usage(myName); | ||
253 | exit(1); | ||
254 | } | ||
255 | if(argc < argcnt){ | ||
256 | fprintf(stderr, "Not enough arguments.\n"); | ||
257 | usage(myName); | ||
258 | exit(1); | ||
259 | } | ||
260 | if(argc > argcnt){ | ||
261 | fprintf(stderr, "Warning: only %d arguments expected, rest ignored.\n", argcnt); | ||
262 | } | ||
263 | usb_init(); | ||
264 | if(usbOpenDevice(&handle, vendorID, vendorNamePattern, productID, productNamePattern, serialPattern, action == ACTION_LIST ? stdout : NULL, showWarnings ? stderr : NULL) != 0){ | ||
265 | fprintf(stderr, "Could not find USB device with VID=0x%x PID=0x%x Vname=%s Pname=%s Serial=%s\n", vendorID, productID, vendorNamePattern, productNamePattern, serialPattern); | ||
266 | exit(1); | ||
267 | } | ||
268 | if(action == ACTION_LIST) | ||
269 | exit(0); /* we've done what we were asked to do already */ | ||
270 | usbDirection = parseEnum(argv[1], "out", "in", NULL); | ||
271 | if(usbDirection){ /* IN transfer */ | ||
272 | rxBuffer = malloc(usbCount); | ||
273 | } | ||
274 | if(action == ACTION_CONTROL){ | ||
275 | int requestType; | ||
276 | usbType = parseEnum(argv[2], "standard", "class", "vendor", "reserved", NULL); | ||
277 | usbRecipient = parseEnum(argv[3], "device", "interface", "endpoint", "other", NULL); | ||
278 | usbRequest = myAtoi(argv[4]); | ||
279 | usbValue = myAtoi(argv[5]); | ||
280 | usbIndex = myAtoi(argv[6]); | ||
281 | requestType = ((usbDirection & 1) << 7) | ((usbType & 3) << 5) | (usbRecipient & 0x1f); | ||
282 | if(usbDirection){ /* IN transfer */ | ||
283 | len = usb_control_msg(handle, requestType, usbRequest, usbValue, usbIndex, rxBuffer, usbCount, usbTimeout); | ||
284 | }else{ /* OUT transfer */ | ||
285 | len = usb_control_msg(handle, requestType, usbRequest, usbValue, usbIndex, sendBytes, sendByteCount, usbTimeout); | ||
286 | } | ||
287 | }else{ /* must be ACTION_INTERRUPT or ACTION_BULK */ | ||
288 | int retries = 1; | ||
289 | if(usb_set_configuration(handle, usbConfiguration) && showWarnings){ | ||
290 | fprintf(stderr, "Warning: could not set configuration: %s\n", usb_strerror()); | ||
291 | } | ||
292 | /* now try to claim the interface and detach the kernel HID driver on | ||
293 | * linux and other operating systems which support the call. | ||
294 | */ | ||
295 | while((len = usb_claim_interface(handle, usbInterface)) != 0 && retries-- > 0){ | ||
296 | #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP | ||
297 | if(usb_detach_kernel_driver_np(handle, 0) < 0 && showWarnings){ | ||
298 | fprintf(stderr, "Warning: could not detach kernel driver: %s\n", usb_strerror()); | ||
299 | } | ||
300 | #endif | ||
301 | } | ||
302 | if(len != 0 && showWarnings) | ||
303 | fprintf(stderr, "Warning: could not claim interface: %s\n", usb_strerror()); | ||
304 | if(action == ACTION_INTERRUPT){ | ||
305 | if(usbDirection){ /* IN transfer */ | ||
306 | len = usb_interrupt_read(handle, endpoint, rxBuffer, usbCount, usbTimeout); | ||
307 | }else{ | ||
308 | len = usb_interrupt_write(handle, endpoint, sendBytes, sendByteCount, usbTimeout); | ||
309 | } | ||
310 | }else{ | ||
311 | if(usbDirection){ /* IN transfer */ | ||
312 | len = usb_bulk_read(handle, endpoint, rxBuffer, usbCount, usbTimeout); | ||
313 | }else{ | ||
314 | len = usb_bulk_write(handle, endpoint, sendBytes, sendByteCount, usbTimeout); | ||
315 | } | ||
316 | } | ||
317 | } | ||
318 | if(len < 0){ | ||
319 | fprintf(stderr, "USB error: %s\n", usb_strerror()); | ||
320 | exit(1); | ||
321 | } | ||
322 | if(usbDirection == 0) /* OUT */ | ||
323 | printf("%d bytes sent.\n", len); | ||
324 | if(rxBuffer != NULL){ | ||
325 | FILE *fp = stdout; | ||
326 | if(outputFile != NULL){ | ||
327 | fp = fopen(outputFile, outputFormatIsBinary ? "wb" : "w"); | ||
328 | if(fp == NULL){ | ||
329 | fprintf(stderr, "Error writing \"%s\": %s\n", outputFile, strerror(errno)); | ||
330 | exit(1); | ||
331 | } | ||
332 | } | ||
333 | if(outputFormatIsBinary){ | ||
334 | fwrite(rxBuffer, 1, len, fp); | ||
335 | }else{ | ||
336 | int i; | ||
337 | for(i = 0; i < len; i++){ | ||
338 | if(i != 0){ | ||
339 | if(i % 16 == 0){ | ||
340 | fprintf(fp, "\n"); | ||
341 | }else{ | ||
342 | fprintf(fp, " "); | ||
343 | } | ||
344 | } | ||
345 | fprintf(fp, "0x%02x", rxBuffer[i] & 0xff); | ||
346 | } | ||
347 | if(i != 0) | ||
348 | fprintf(fp, "\n"); | ||
349 | } | ||
350 | } | ||
351 | usb_close(handle); | ||
352 | if(rxBuffer != NULL) | ||
353 | free(rxBuffer); | ||
354 | return 0; | ||
355 | } | ||
diff --git a/lib/vusb/libs-device/Readme.txt b/lib/vusb/libs-device/Readme.txt new file mode 100644 index 000000000..76518dc90 --- /dev/null +++ b/lib/vusb/libs-device/Readme.txt | |||
@@ -0,0 +1,22 @@ | |||
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/ | ||
diff --git a/lib/vusb/libs-device/osccal.c b/lib/vusb/libs-device/osccal.c new file mode 100644 index 000000000..ea170ec66 --- /dev/null +++ b/lib/vusb/libs-device/osccal.c | |||
@@ -0,0 +1,68 @@ | |||
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 <avr/io.h> | ||
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 | */ | ||
diff --git a/lib/vusb/libs-device/osccal.h b/lib/vusb/libs-device/osccal.h new file mode 100644 index 000000000..1ed600697 --- /dev/null +++ b/lib/vusb/libs-device/osccal.h | |||
@@ -0,0 +1,62 @@ | |||
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 <avr/interrupt.h> // 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__ */ | ||
diff --git a/lib/vusb/libs-device/osctune.h b/lib/vusb/libs-device/osctune.h new file mode 100644 index 000000000..12961e504 --- /dev/null +++ b/lib/vusb/libs-device/osctune.h | |||
@@ -0,0 +1,87 @@ | |||
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 | ||
diff --git a/lib/vusb/libs-host/Readme.txt b/lib/vusb/libs-host/Readme.txt new file mode 100644 index 000000000..5117d18f7 --- /dev/null +++ b/lib/vusb/libs-host/Readme.txt | |||
@@ -0,0 +1,26 @@ | |||
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/ | ||
diff --git a/lib/vusb/libs-host/hiddata.c b/lib/vusb/libs-host/hiddata.c new file mode 100644 index 000000000..203ed19d6 --- /dev/null +++ b/lib/vusb/libs-host/hiddata.c | |||
@@ -0,0 +1,323 @@ | |||
1 | /* Name: hiddata.c | ||
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 | #include <stdio.h> | ||
10 | #include "hiddata.h" | ||
11 | |||
12 | /* ######################################################################## */ | ||
13 | #if defined(WIN32) /* ##################################################### */ | ||
14 | /* ######################################################################## */ | ||
15 | |||
16 | #include <windows.h> | ||
17 | #include <setupapi.h> | ||
18 | #include "hidsdi.h" | ||
19 | #include <ddk/hidpi.h> | ||
20 | |||
21 | #ifdef DEBUG | ||
22 | #define DEBUG_PRINT(arg) printf arg | ||
23 | #else | ||
24 | #define DEBUG_PRINT(arg) | ||
25 | #endif | ||
26 | |||
27 | /* ------------------------------------------------------------------------ */ | ||
28 | |||
29 | static void convertUniToAscii(char *buffer) | ||
30 | { | ||
31 | unsigned short *uni = (void *)buffer; | ||
32 | char *ascii = buffer; | ||
33 | |||
34 | while(*uni != 0){ | ||
35 | if(*uni >= 256){ | ||
36 | *ascii++ = '?'; | ||
37 | }else{ | ||
38 | *ascii++ = *uni++; | ||
39 | } | ||
40 | } | ||
41 | *ascii++ = 0; | ||
42 | } | ||
43 | |||
44 | int usbhidOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int usesReportIDs) | ||
45 | { | ||
46 | GUID hidGuid; /* GUID for HID driver */ | ||
47 | HDEVINFO deviceInfoList; | ||
48 | SP_DEVICE_INTERFACE_DATA deviceInfo; | ||
49 | SP_DEVICE_INTERFACE_DETAIL_DATA *deviceDetails = NULL; | ||
50 | DWORD size; | ||
51 | int i, openFlag = 0; /* may be FILE_FLAG_OVERLAPPED */ | ||
52 | int errorCode = USBOPEN_ERR_NOTFOUND; | ||
53 | HANDLE handle = INVALID_HANDLE_VALUE; | ||
54 | HIDD_ATTRIBUTES deviceAttributes; | ||
55 | |||
56 | HidD_GetHidGuid(&hidGuid); | ||
57 | deviceInfoList = SetupDiGetClassDevs(&hidGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); | ||
58 | deviceInfo.cbSize = sizeof(deviceInfo); | ||
59 | for(i=0;;i++){ | ||
60 | if(handle != INVALID_HANDLE_VALUE){ | ||
61 | CloseHandle(handle); | ||
62 | handle = INVALID_HANDLE_VALUE; | ||
63 | } | ||
64 | if(!SetupDiEnumDeviceInterfaces(deviceInfoList, 0, &hidGuid, i, &deviceInfo)) | ||
65 | break; /* no more entries */ | ||
66 | /* first do a dummy call just to determine the actual size required */ | ||
67 | SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, NULL, 0, &size, NULL); | ||
68 | if(deviceDetails != NULL) | ||
69 | free(deviceDetails); | ||
70 | deviceDetails = malloc(size); | ||
71 | deviceDetails->cbSize = sizeof(*deviceDetails); | ||
72 | /* this call is for real: */ | ||
73 | SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, deviceDetails, size, &size, NULL); | ||
74 | DEBUG_PRINT(("checking HID path \"%s\"\n", deviceDetails->DevicePath)); | ||
75 | #if 0 | ||
76 | /* If we want to access a mouse our keyboard, we can only use feature | ||
77 | * requests as the device is locked by Windows. It must be opened | ||
78 | * with ACCESS_TYPE_NONE. | ||
79 | */ | ||
80 | handle = CreateFile(deviceDetails->DevicePath, ACCESS_TYPE_NONE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, openFlag, NULL); | ||
81 | #endif | ||
82 | /* attempt opening for R/W -- we don't care about devices which can't be accessed */ | ||
83 | handle = CreateFile(deviceDetails->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, openFlag, NULL); | ||
84 | if(handle == INVALID_HANDLE_VALUE){ | ||
85 | DEBUG_PRINT(("opening failed: %d\n", (int)GetLastError())); | ||
86 | /* errorCode = USBOPEN_ERR_ACCESS; opening will always fail for mouse -- ignore */ | ||
87 | continue; | ||
88 | } | ||
89 | deviceAttributes.Size = sizeof(deviceAttributes); | ||
90 | HidD_GetAttributes(handle, &deviceAttributes); | ||
91 | DEBUG_PRINT(("device attributes: vid=%d pid=%d\n", deviceAttributes.VendorID, deviceAttributes.ProductID)); | ||
92 | if(deviceAttributes.VendorID != vendor || deviceAttributes.ProductID != product) | ||
93 | continue; /* ignore this device */ | ||
94 | errorCode = USBOPEN_ERR_NOTFOUND; | ||
95 | if(vendorName != NULL && productName != NULL){ | ||
96 | char buffer[512]; | ||
97 | if(!HidD_GetManufacturerString(handle, buffer, sizeof(buffer))){ | ||
98 | DEBUG_PRINT(("error obtaining vendor name\n")); | ||
99 | errorCode = USBOPEN_ERR_IO; | ||
100 | continue; | ||
101 | } | ||
102 | convertUniToAscii(buffer); | ||
103 | DEBUG_PRINT(("vendorName = \"%s\"\n", buffer)); | ||
104 | if(strcmp(vendorName, buffer) != 0) | ||
105 | continue; | ||
106 | if(!HidD_GetProductString(handle, buffer, sizeof(buffer))){ | ||
107 | DEBUG_PRINT(("error obtaining product name\n")); | ||
108 | errorCode = USBOPEN_ERR_IO; | ||
109 | continue; | ||
110 | } | ||
111 | convertUniToAscii(buffer); | ||
112 | DEBUG_PRINT(("productName = \"%s\"\n", buffer)); | ||
113 | if(strcmp(productName, buffer) != 0) | ||
114 | continue; | ||
115 | } | ||
116 | break; /* we have found the device we are looking for! */ | ||
117 | } | ||
118 | SetupDiDestroyDeviceInfoList(deviceInfoList); | ||
119 | if(deviceDetails != NULL) | ||
120 | free(deviceDetails); | ||
121 | if(handle != INVALID_HANDLE_VALUE){ | ||
122 | *device = (usbDevice_t *)handle; | ||
123 | errorCode = 0; | ||
124 | } | ||
125 | return errorCode; | ||
126 | } | ||
127 | |||
128 | /* ------------------------------------------------------------------------ */ | ||
129 | |||
130 | void usbhidCloseDevice(usbDevice_t *device) | ||
131 | { | ||
132 | CloseHandle((HANDLE)device); | ||
133 | } | ||
134 | |||
135 | /* ------------------------------------------------------------------------ */ | ||
136 | |||
137 | int usbhidSetReport(usbDevice_t *device, char *buffer, int len) | ||
138 | { | ||
139 | BOOLEAN rval; | ||
140 | |||
141 | rval = HidD_SetFeature((HANDLE)device, buffer, len); | ||
142 | return rval == 0 ? USBOPEN_ERR_IO : 0; | ||
143 | } | ||
144 | |||
145 | /* ------------------------------------------------------------------------ */ | ||
146 | |||
147 | int usbhidGetReport(usbDevice_t *device, int reportNumber, char *buffer, int *len) | ||
148 | { | ||
149 | BOOLEAN rval = 0; | ||
150 | |||
151 | buffer[0] = reportNumber; | ||
152 | rval = HidD_GetFeature((HANDLE)device, buffer, *len); | ||
153 | return rval == 0 ? USBOPEN_ERR_IO : 0; | ||
154 | } | ||
155 | |||
156 | /* ------------------------------------------------------------------------ */ | ||
157 | |||
158 | /* ######################################################################## */ | ||
159 | #else /* defined WIN32 #################################################### */ | ||
160 | /* ######################################################################## */ | ||
161 | |||
162 | #include <string.h> | ||
163 | #include <usb.h> | ||
164 | |||
165 | #define usbDevice usb_dev_handle /* use libusb's device structure */ | ||
166 | |||
167 | /* ------------------------------------------------------------------------- */ | ||
168 | |||
169 | #define USBRQ_HID_GET_REPORT 0x01 | ||
170 | #define USBRQ_HID_SET_REPORT 0x09 | ||
171 | |||
172 | #define USB_HID_REPORT_TYPE_FEATURE 3 | ||
173 | |||
174 | |||
175 | static int usesReportIDs; | ||
176 | |||
177 | /* ------------------------------------------------------------------------- */ | ||
178 | |||
179 | static int usbhidGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen) | ||
180 | { | ||
181 | char buffer[256]; | ||
182 | int rval, i; | ||
183 | |||
184 | if((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use libusb version if it works */ | ||
185 | return rval; | ||
186 | if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, 0x0409, buffer, sizeof(buffer), 5000)) < 0) | ||
187 | return rval; | ||
188 | if(buffer[1] != USB_DT_STRING){ | ||
189 | *buf = 0; | ||
190 | return 0; | ||
191 | } | ||
192 | if((unsigned char)buffer[0] < rval) | ||
193 | rval = (unsigned char)buffer[0]; | ||
194 | rval /= 2; | ||
195 | /* lossy conversion to ISO Latin1: */ | ||
196 | for(i=1;i<rval;i++){ | ||
197 | if(i > buflen) /* destination buffer overflow */ | ||
198 | break; | ||
199 | buf[i-1] = buffer[2 * i]; | ||
200 | if(buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */ | ||
201 | buf[i-1] = '?'; | ||
202 | } | ||
203 | buf[i-1] = 0; | ||
204 | return i-1; | ||
205 | } | ||
206 | |||
207 | int usbhidOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int _usesReportIDs) | ||
208 | { | ||
209 | struct usb_bus *bus; | ||
210 | struct usb_device *dev; | ||
211 | usb_dev_handle *handle = NULL; | ||
212 | int errorCode = USBOPEN_ERR_NOTFOUND; | ||
213 | static int didUsbInit = 0; | ||
214 | |||
215 | if(!didUsbInit){ | ||
216 | usb_init(); | ||
217 | didUsbInit = 1; | ||
218 | } | ||
219 | usb_find_busses(); | ||
220 | usb_find_devices(); | ||
221 | for(bus=usb_get_busses(); bus; bus=bus->next){ | ||
222 | for(dev=bus->devices; dev; dev=dev->next){ | ||
223 | if(dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product){ | ||
224 | char string[256]; | ||
225 | int len; | ||
226 | handle = usb_open(dev); /* we need to open the device in order to query strings */ | ||
227 | if(!handle){ | ||
228 | errorCode = USBOPEN_ERR_ACCESS; | ||
229 | fprintf(stderr, "Warning: cannot open USB device: %s\n", usb_strerror()); | ||
230 | continue; | ||
231 | } | ||
232 | if(vendorName == NULL && productName == NULL){ /* name does not matter */ | ||
233 | break; | ||
234 | } | ||
235 | /* now check whether the names match: */ | ||
236 | len = usbhidGetStringAscii(handle, dev->descriptor.iManufacturer, string, sizeof(string)); | ||
237 | if(len < 0){ | ||
238 | errorCode = USBOPEN_ERR_IO; | ||
239 | fprintf(stderr, "Warning: cannot query manufacturer for device: %s\n", usb_strerror()); | ||
240 | }else{ | ||
241 | errorCode = USBOPEN_ERR_NOTFOUND; | ||
242 | /* fprintf(stderr, "seen device from vendor ->%s<-\n", string); */ | ||
243 | if(strcmp(string, vendorName) == 0){ | ||
244 | len = usbhidGetStringAscii(handle, dev->descriptor.iProduct, string, sizeof(string)); | ||
245 | if(len < 0){ | ||
246 | errorCode = USBOPEN_ERR_IO; | ||
247 | fprintf(stderr, "Warning: cannot query product for device: %s\n", usb_strerror()); | ||
248 | }else{ | ||
249 | errorCode = USBOPEN_ERR_NOTFOUND; | ||
250 | /* fprintf(stderr, "seen product ->%s<-\n", string); */ | ||
251 | if(strcmp(string, productName) == 0) | ||
252 | break; | ||
253 | } | ||
254 | } | ||
255 | } | ||
256 | usb_close(handle); | ||
257 | handle = NULL; | ||
258 | } | ||
259 | } | ||
260 | if(handle) | ||
261 | break; | ||
262 | } | ||
263 | if(handle != NULL){ | ||
264 | errorCode = 0; | ||
265 | *device = (void *)handle; | ||
266 | usesReportIDs = _usesReportIDs; | ||
267 | } | ||
268 | return errorCode; | ||
269 | } | ||
270 | |||
271 | /* ------------------------------------------------------------------------- */ | ||
272 | |||
273 | void usbhidCloseDevice(usbDevice_t *device) | ||
274 | { | ||
275 | if(device != NULL) | ||
276 | usb_close((void *)device); | ||
277 | } | ||
278 | |||
279 | /* ------------------------------------------------------------------------- */ | ||
280 | |||
281 | int usbhidSetReport(usbDevice_t *device, char *buffer, int len) | ||
282 | { | ||
283 | int bytesSent, reportId = buffer[0]; | ||
284 | |||
285 | if(!usesReportIDs){ | ||
286 | buffer++; /* skip dummy report ID */ | ||
287 | len--; | ||
288 | } | ||
289 | bytesSent = usb_control_msg((void *)device, USB_TYPE_CLASS | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, USBRQ_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE << 8 | (reportId & 0xff), 0, buffer, len, 5000); | ||
290 | if(bytesSent != len){ | ||
291 | if(bytesSent < 0) | ||
292 | fprintf(stderr, "Error sending message: %s\n", usb_strerror()); | ||
293 | return USBOPEN_ERR_IO; | ||
294 | } | ||
295 | return 0; | ||
296 | } | ||
297 | |||
298 | /* ------------------------------------------------------------------------- */ | ||
299 | |||
300 | int usbhidGetReport(usbDevice_t *device, int reportNumber, char *buffer, int *len) | ||
301 | { | ||
302 | int bytesReceived, maxLen = *len; | ||
303 | |||
304 | if(!usesReportIDs){ | ||
305 | buffer++; /* make room for dummy report ID */ | ||
306 | maxLen--; | ||
307 | } | ||
308 | bytesReceived = usb_control_msg((void *)device, USB_TYPE_CLASS | USB_RECIP_DEVICE | USB_ENDPOINT_IN, USBRQ_HID_GET_REPORT, USB_HID_REPORT_TYPE_FEATURE << 8 | reportNumber, 0, buffer, maxLen, 5000); | ||
309 | if(bytesReceived < 0){ | ||
310 | fprintf(stderr, "Error sending message: %s\n", usb_strerror()); | ||
311 | return USBOPEN_ERR_IO; | ||
312 | } | ||
313 | *len = bytesReceived; | ||
314 | if(!usesReportIDs){ | ||
315 | buffer[-1] = reportNumber; /* add dummy report ID */ | ||
316 | (*len)++; | ||
317 | } | ||
318 | return 0; | ||
319 | } | ||
320 | |||
321 | /* ######################################################################## */ | ||
322 | #endif /* defined WIN32 ################################################### */ | ||
323 | /* ######################################################################## */ | ||
diff --git a/lib/vusb/libs-host/hiddata.h b/lib/vusb/libs-host/hiddata.h new file mode 100644 index 000000000..245453d43 --- /dev/null +++ b/lib/vusb/libs-host/hiddata.h | |||
@@ -0,0 +1,70 @@ | |||
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__ */ | ||
diff --git a/lib/vusb/libs-host/hidsdi.h b/lib/vusb/libs-host/hidsdi.h new file mode 100644 index 000000000..fe6da085d --- /dev/null +++ b/lib/vusb/libs-host/hidsdi.h | |||
@@ -0,0 +1,48 @@ | |||
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 <pshpack4.h> | ||
21 | |||
22 | #include <ddk/hidusage.h> | ||
23 | #include <ddk/hidpi.h> | ||
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 <poppack.h> | ||
47 | |||
48 | #endif | ||
diff --git a/lib/vusb/libs-host/opendevice.c b/lib/vusb/libs-host/opendevice.c new file mode 100644 index 000000000..ea88e8624 --- /dev/null +++ b/lib/vusb/libs-host/opendevice.c | |||
@@ -0,0 +1,202 @@ | |||
1 | /* Name: opendevice.c | ||
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 | The functions in this module can be used to find and open a device based on | ||
13 | libusb or libusb-win32. | ||
14 | */ | ||
15 | |||
16 | #include <stdio.h> | ||
17 | #include "opendevice.h" | ||
18 | |||
19 | /* ------------------------------------------------------------------------- */ | ||
20 | |||
21 | #define MATCH_SUCCESS 1 | ||
22 | #define MATCH_FAILED 0 | ||
23 | #define MATCH_ABORT -1 | ||
24 | |||
25 | /* private interface: match text and p, return MATCH_SUCCESS, MATCH_FAILED, or MATCH_ABORT. */ | ||
26 | static int _shellStyleMatch(char *text, char *p) | ||
27 | { | ||
28 | int last, matched, reverse; | ||
29 | |||
30 | for(; *p; text++, p++){ | ||
31 | if(*text == 0 && *p != '*') | ||
32 | return MATCH_ABORT; | ||
33 | switch(*p){ | ||
34 | case '\\': | ||
35 | /* Literal match with following character. */ | ||
36 | p++; | ||
37 | /* FALLTHROUGH */ | ||
38 | default: | ||
39 | if(*text != *p) | ||
40 | return MATCH_FAILED; | ||
41 | continue; | ||
42 | case '?': | ||
43 | /* Match anything. */ | ||
44 | continue; | ||
45 | case '*': | ||
46 | while(*++p == '*') | ||
47 | /* Consecutive stars act just like one. */ | ||
48 | continue; | ||
49 | if(*p == 0) | ||
50 | /* Trailing star matches everything. */ | ||
51 | return MATCH_SUCCESS; | ||
52 | while(*text) | ||
53 | if((matched = _shellStyleMatch(text++, p)) != MATCH_FAILED) | ||
54 | return matched; | ||
55 | return MATCH_ABORT; | ||
56 | case '[': | ||
57 | reverse = p[1] == '^'; | ||
58 | if(reverse) /* Inverted character class. */ | ||
59 | p++; | ||
60 | matched = MATCH_FAILED; | ||
61 | if(p[1] == ']' || p[1] == '-') | ||
62 | if(*++p == *text) | ||
63 | matched = MATCH_SUCCESS; | ||
64 | for(last = *p; *++p && *p != ']'; last = *p) | ||
65 | if (*p == '-' && p[1] != ']' ? *text <= *++p && *text >= last : *text == *p) | ||
66 | matched = MATCH_SUCCESS; | ||
67 | if(matched == reverse) | ||
68 | return MATCH_FAILED; | ||
69 | continue; | ||
70 | } | ||
71 | } | ||
72 | return *text == 0; | ||
73 | } | ||
74 | |||
75 | /* public interface for shell style matching: returns 0 if fails, 1 if matches */ | ||
76 | static int shellStyleMatch(char *text, char *pattern) | ||
77 | { | ||
78 | if(pattern == NULL) /* NULL pattern is synonymous to "*" */ | ||
79 | return 1; | ||
80 | return _shellStyleMatch(text, pattern) == MATCH_SUCCESS; | ||
81 | } | ||
82 | |||
83 | /* ------------------------------------------------------------------------- */ | ||
84 | |||
85 | int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen) | ||
86 | { | ||
87 | char buffer[256]; | ||
88 | int rval, i; | ||
89 | |||
90 | if((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use libusb version if it works */ | ||
91 | return rval; | ||
92 | if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, 0x0409, buffer, sizeof(buffer), 5000)) < 0) | ||
93 | return rval; | ||
94 | if(buffer[1] != USB_DT_STRING){ | ||
95 | *buf = 0; | ||
96 | return 0; | ||
97 | } | ||
98 | if((unsigned char)buffer[0] < rval) | ||
99 | rval = (unsigned char)buffer[0]; | ||
100 | rval /= 2; | ||
101 | /* lossy conversion to ISO Latin1: */ | ||
102 | for(i=1;i<rval;i++){ | ||
103 | if(i > buflen) /* destination buffer overflow */ | ||
104 | break; | ||
105 | buf[i-1] = buffer[2 * i]; | ||
106 | if(buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */ | ||
107 | buf[i-1] = '?'; | ||
108 | } | ||
109 | buf[i-1] = 0; | ||
110 | return i-1; | ||
111 | } | ||
112 | |||
113 | /* ------------------------------------------------------------------------- */ | ||
114 | |||
115 | int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp) | ||
116 | { | ||
117 | struct usb_bus *bus; | ||
118 | struct usb_device *dev; | ||
119 | usb_dev_handle *handle = NULL; | ||
120 | int errorCode = USBOPEN_ERR_NOTFOUND; | ||
121 | |||
122 | usb_find_busses(); | ||
123 | usb_find_devices(); | ||
124 | for(bus = usb_get_busses(); bus; bus = bus->next){ | ||
125 | for(dev = bus->devices; dev; dev = dev->next){ /* iterate over all devices on all busses */ | ||
126 | if((vendorID == 0 || dev->descriptor.idVendor == vendorID) | ||
127 | && (productID == 0 || dev->descriptor.idProduct == productID)){ | ||
128 | char vendor[256], product[256], serial[256]; | ||
129 | int len; | ||
130 | handle = usb_open(dev); /* we need to open the device in order to query strings */ | ||
131 | if(!handle){ | ||
132 | errorCode = USBOPEN_ERR_ACCESS; | ||
133 | if(warningsFp != NULL) | ||
134 | fprintf(warningsFp, "Warning: cannot open VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); | ||
135 | continue; | ||
136 | } | ||
137 | /* now check whether the names match: */ | ||
138 | len = vendor[0] = 0; | ||
139 | if(dev->descriptor.iManufacturer > 0){ | ||
140 | len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, vendor, sizeof(vendor)); | ||
141 | } | ||
142 | if(len < 0){ | ||
143 | errorCode = USBOPEN_ERR_ACCESS; | ||
144 | if(warningsFp != NULL) | ||
145 | fprintf(warningsFp, "Warning: cannot query manufacturer for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); | ||
146 | }else{ | ||
147 | errorCode = USBOPEN_ERR_NOTFOUND; | ||
148 | /* printf("seen device from vendor ->%s<-\n", vendor); */ | ||
149 | if(shellStyleMatch(vendor, vendorNamePattern)){ | ||
150 | len = product[0] = 0; | ||
151 | if(dev->descriptor.iProduct > 0){ | ||
152 | len = usbGetStringAscii(handle, dev->descriptor.iProduct, product, sizeof(product)); | ||
153 | } | ||
154 | if(len < 0){ | ||
155 | errorCode = USBOPEN_ERR_ACCESS; | ||
156 | if(warningsFp != NULL) | ||
157 | fprintf(warningsFp, "Warning: cannot query product for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); | ||
158 | }else{ | ||
159 | errorCode = USBOPEN_ERR_NOTFOUND; | ||
160 | /* printf("seen product ->%s<-\n", product); */ | ||
161 | if(shellStyleMatch(product, productNamePattern)){ | ||
162 | len = serial[0] = 0; | ||
163 | if(dev->descriptor.iSerialNumber > 0){ | ||
164 | len = usbGetStringAscii(handle, dev->descriptor.iSerialNumber, serial, sizeof(serial)); | ||
165 | } | ||
166 | if(len < 0){ | ||
167 | errorCode = USBOPEN_ERR_ACCESS; | ||
168 | if(warningsFp != NULL) | ||
169 | fprintf(warningsFp, "Warning: cannot query serial for VID=0x%04x PID=0x%04x: %s\n", dev->descriptor.idVendor, dev->descriptor.idProduct, usb_strerror()); | ||
170 | } | ||
171 | if(shellStyleMatch(serial, serialNamePattern)){ | ||
172 | if(printMatchingDevicesFp != NULL){ | ||
173 | if(serial[0] == 0){ | ||
174 | fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product); | ||
175 | }else{ | ||
176 | fprintf(printMatchingDevicesFp, "VID=0x%04x PID=0x%04x vendor=\"%s\" product=\"%s\" serial=\"%s\"\n", dev->descriptor.idVendor, dev->descriptor.idProduct, vendor, product, serial); | ||
177 | } | ||
178 | }else{ | ||
179 | break; | ||
180 | } | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | usb_close(handle); | ||
187 | handle = NULL; | ||
188 | } | ||
189 | } | ||
190 | if(handle) /* we have found a deice */ | ||
191 | break; | ||
192 | } | ||
193 | if(handle != NULL){ | ||
194 | errorCode = 0; | ||
195 | *device = handle; | ||
196 | } | ||
197 | if(printMatchingDevicesFp != NULL) /* never return an error for listing only */ | ||
198 | errorCode = 0; | ||
199 | return errorCode; | ||
200 | } | ||
201 | |||
202 | /* ------------------------------------------------------------------------- */ | ||
diff --git a/lib/vusb/libs-host/opendevice.h b/lib/vusb/libs-host/opendevice.h new file mode 100644 index 000000000..c92527634 --- /dev/null +++ b/lib/vusb/libs-host/opendevice.h | |||
@@ -0,0 +1,76 @@ | |||
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 <usb.h> /* this is libusb, see http://libusb.sourceforge.net/ */ | ||
26 | #include <stdio.h> | ||
27 | |||
28 | int usbGetStringAscii(usb_dev_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 | * usb_strerror() to obtain the error message. | ||
37 | */ | ||
38 | |||
39 | int usbOpenDevice(usb_dev_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 "usb_dev_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__ */ | ||
diff --git a/lib/vusb/mkdist.sh b/lib/vusb/mkdist.sh new file mode 100755 index 000000000..25c104001 --- /dev/null +++ b/lib/vusb/mkdist.sh | |||
@@ -0,0 +1,149 @@ | |||
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 <<EOF | ||
109 | EXPORT IMAGE 'circuits/image.png' monochrome 300; | ||
110 | QUIT | ||
111 | EOF | ||
112 | |||
113 | # Copy the schematics file and run the script on it: | ||
114 | for i in circuits/*.sch; do | ||
115 | rm -f "circuits/image.png" | ||
116 | cp "$i" /tmp/$tname.sch | ||
117 | $eagle -S/tmp/$tname.scr /tmp/$tname.sch | ||
118 | file=`basename -s .sch $i` | ||
119 | mv circuits/image.png circuits/$file.png | ||
120 | done | ||
121 | rm /tmp/$tname.scr /tmp/$tname.sch | ||
122 | |||
123 | #------------------------------------------------------------------- | ||
124 | # Generate all derived files | ||
125 | #------------------------------------------------------------------- | ||
126 | |||
127 | make files | ||
128 | |||
129 | #------------------------------------------------------------------- | ||
130 | # Remove unnecessary files from distribution and create archive | ||
131 | #------------------------------------------------------------------- | ||
132 | |||
133 | rm -rf examples/drivertest v-usb.xcodeproj | ||
134 | find . -name 'make-files.sh' -exec rm '{}' \; # remove helper scripts | ||
135 | rm -f mkdist.sh README.md .gitignore | ||
136 | ( | ||
137 | cd usbdrv | ||
138 | cp Changelog.txt License.txt CommercialLicense.txt USB-IDs-for-free.txt USB-ID-FAQ.txt .. | ||
139 | ) | ||
140 | cd .. | ||
141 | echo "Creating /tmp/$pkgname.zip and /tmp/$pkgname.tar.gz" | ||
142 | zip -rq9 "$pkgname.zip" "$pkgname" | ||
143 | tar cfz "$pkgname.tar.gz" "$pkgname" | ||
144 | open /tmp | ||
145 | |||
146 | echo | ||
147 | echo "***********************************************************************" | ||
148 | echo "Don't forget to push GIT repo (including tags!) to origin!" | ||
149 | echo "***********************************************************************" | ||
diff --git a/lib/vusb/tests/Makefile b/lib/vusb/tests/Makefile new file mode 100644 index 000000000..43f8da12e --- /dev/null +++ b/lib/vusb/tests/Makefile | |||
@@ -0,0 +1,128 @@ | |||
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 = attiny2313 | ||
10 | F_CPU = 16000000 # in Hz | ||
11 | DEFINES = | ||
12 | |||
13 | CFLAGS = $(DEFINES) -Iusbdrv -I. -DDEBUG_LEVEL=0 | ||
14 | OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o | ||
15 | |||
16 | COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CRCFLAG) $(CFLAGS) -mmcu=$(DEVICE) | ||
17 | |||
18 | SIZES_TMP = /tmp/sizetmp.txt | ||
19 | |||
20 | # symbolic targets: | ||
21 | help: | ||
22 | @echo "This Makefile has no default rule. Use one of the following:" | ||
23 | @echo "make clean ..... to delete objects and hex file" | ||
24 | @echo "make sizes ..... compute code and RAM sizes for various options" | ||
25 | @echo "make test ...... test with all features whether everything compiles" | ||
26 | |||
27 | sizes sizes.txt: | ||
28 | rm -f $(SIZES_TMP) sizes.txt | ||
29 | $(MAKE) null.elf | ||
30 | avr-size null.elf | tail -1 | awk '{print "null", $$1+$$2, $$3+$$2}' >$(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 | ||
diff --git a/lib/vusb/tests/Readme.txt b/lib/vusb/tests/Readme.txt new file mode 100644 index 000000000..3f0d36df0 --- /dev/null +++ b/lib/vusb/tests/Readme.txt | |||
@@ -0,0 +1,13 @@ | |||
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/ | ||
diff --git a/lib/vusb/tests/compare-sizes.awk b/lib/vusb/tests/compare-sizes.awk new file mode 100755 index 000000000..47868c4c4 --- /dev/null +++ b/lib/vusb/tests/compare-sizes.awk | |||
@@ -0,0 +1,44 @@ | |||
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 | } | ||
diff --git a/lib/vusb/tests/main.c b/lib/vusb/tests/main.c new file mode 100644 index 000000000..a6efb8c20 --- /dev/null +++ b/lib/vusb/tests/main.c | |||
@@ -0,0 +1,158 @@ | |||
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 <avr/io.h> | ||
16 | #include <avr/interrupt.h> /* for sei() */ | ||
17 | #include <avr/pgmspace.h> /* required by usbdrv.h */ | ||
18 | #include <util/delay.h> /* 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 | /* ------------------------------------------------------------------------- */ | ||
diff --git a/lib/vusb/tests/null.c b/lib/vusb/tests/null.c new file mode 100644 index 000000000..f668354b6 --- /dev/null +++ b/lib/vusb/tests/null.c | |||
@@ -0,0 +1,25 @@ | |||
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 <avr/io.h> | ||
15 | |||
16 | |||
17 | /* ------------------------------------------------------------------------- */ | ||
18 | |||
19 | int main(void) | ||
20 | { | ||
21 | for(;;); | ||
22 | return 0; | ||
23 | } | ||
24 | |||
25 | /* ------------------------------------------------------------------------- */ | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20080418-gcc3.4.6.txt b/lib/vusb/tests/sizes-reference/sizes-20080418-gcc3.4.6.txt new file mode 100644 index 000000000..2257e891a --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20080418-gcc3.4.6.txt | |||
@@ -0,0 +1,13 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20080418-gcc4.2.2.txt b/lib/vusb/tests/sizes-reference/sizes-20080418-gcc4.2.2.txt new file mode 100644 index 000000000..f776893e6 --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20080418-gcc4.2.2.txt | |||
@@ -0,0 +1,13 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20080513-gcc3.4.6.txt b/lib/vusb/tests/sizes-reference/sizes-20080513-gcc3.4.6.txt new file mode 100644 index 000000000..d292bfb43 --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20080513-gcc3.4.6.txt | |||
@@ -0,0 +1,15 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20080513-gcc4.3.0.txt b/lib/vusb/tests/sizes-reference/sizes-20080513-gcc4.3.0.txt new file mode 100644 index 000000000..e3218b4ce --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20080513-gcc4.3.0.txt | |||
@@ -0,0 +1,15 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20081022-gcc3.4.6.txt b/lib/vusb/tests/sizes-reference/sizes-20081022-gcc3.4.6.txt new file mode 100644 index 000000000..0dfafa707 --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20081022-gcc3.4.6.txt | |||
@@ -0,0 +1,16 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20081022-gcc4.3.0.txt b/lib/vusb/tests/sizes-reference/sizes-20081022-gcc4.3.0.txt new file mode 100644 index 000000000..42e2ba9ae --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20081022-gcc4.3.0.txt | |||
@@ -0,0 +1,16 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20081126-gcc3.4.6.txt b/lib/vusb/tests/sizes-reference/sizes-20081126-gcc3.4.6.txt new file mode 100644 index 000000000..0dfafa707 --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20081126-gcc3.4.6.txt | |||
@@ -0,0 +1,16 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20081126-gcc4.3.0.txt b/lib/vusb/tests/sizes-reference/sizes-20081126-gcc4.3.0.txt new file mode 100644 index 000000000..42e2ba9ae --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20081126-gcc4.3.0.txt | |||
@@ -0,0 +1,16 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20090323-gcc3.4.6.txt b/lib/vusb/tests/sizes-reference/sizes-20090323-gcc3.4.6.txt new file mode 100644 index 000000000..18e72a660 --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20090323-gcc3.4.6.txt | |||
@@ -0,0 +1,17 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20090323-gcc4.3.2.txt b/lib/vusb/tests/sizes-reference/sizes-20090323-gcc4.3.2.txt new file mode 100644 index 000000000..9b4f4ee05 --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20090323-gcc4.3.2.txt | |||
@@ -0,0 +1,17 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20090415-gcc3.4.6.txt b/lib/vusb/tests/sizes-reference/sizes-20090415-gcc3.4.6.txt new file mode 100644 index 000000000..18e72a660 --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20090415-gcc3.4.6.txt | |||
@@ -0,0 +1,17 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20090415-gcc4.3.2.txt b/lib/vusb/tests/sizes-reference/sizes-20090415-gcc4.3.2.txt new file mode 100644 index 000000000..9b4f4ee05 --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20090415-gcc4.3.2.txt | |||
@@ -0,0 +1,17 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20100715-gcc3.4.6.txt b/lib/vusb/tests/sizes-reference/sizes-20100715-gcc3.4.6.txt new file mode 100644 index 000000000..a7550ee0e --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20100715-gcc3.4.6.txt | |||
@@ -0,0 +1,17 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20100715-gcc4.3.3.txt b/lib/vusb/tests/sizes-reference/sizes-20100715-gcc4.3.3.txt new file mode 100644 index 000000000..ce162f331 --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20100715-gcc4.3.3.txt | |||
@@ -0,0 +1,17 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20120109-gcc3.4.6.txt b/lib/vusb/tests/sizes-reference/sizes-20120109-gcc3.4.6.txt new file mode 100644 index 000000000..50c8f2646 --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20120109-gcc3.4.6.txt | |||
@@ -0,0 +1,17 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20120109-gcc4.3.3.txt b/lib/vusb/tests/sizes-reference/sizes-20120109-gcc4.3.3.txt new file mode 100644 index 000000000..14b9ca972 --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20120109-gcc4.3.3.txt | |||
@@ -0,0 +1,17 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/sizes-reference/sizes-20121206-gcc4.6.2.txt b/lib/vusb/tests/sizes-reference/sizes-20121206-gcc4.6.2.txt new file mode 100644 index 000000000..266ac68ec --- /dev/null +++ b/lib/vusb/tests/sizes-reference/sizes-20121206-gcc4.6.2.txt | |||
@@ -0,0 +1,17 @@ | |||
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 | ||
diff --git a/lib/vusb/tests/usbconfig.h b/lib/vusb/tests/usbconfig.h new file mode 100644 index 000000000..e079e0661 --- /dev/null +++ b/lib/vusb/tests/usbconfig.h | |||
@@ -0,0 +1,299 @@ | |||
1 | /* Name: usbconfig.h | ||
2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers | ||
3 | * Author: Christian Starkjohann | ||
4 | * Creation Date: 2005-04-01 | ||
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 __usbconfig_h_included__ | ||
11 | #define __usbconfig_h_included__ | ||
12 | |||
13 | /* | ||
14 | General Description: | ||
15 | This is the config file for tests. It is not updated to the latest set of | ||
16 | features. Don't use it as a prototype, use usbconfig-prototype.h instead! | ||
17 | */ | ||
18 | |||
19 | /* ---------------------------- Hardware Config ---------------------------- */ | ||
20 | |||
21 | #define USB_CFG_IOPORTNAME D | ||
22 | #define USB_CFG_DMINUS_BIT 4 | ||
23 | #define USB_CFG_DPLUS_BIT 2 | ||
24 | #define USB_CFG_CLOCK_KHZ (F_CPU/1000) | ||
25 | #ifdef USE_CRC | ||
26 | # define USB_CFG_CHECK_CRC 1 | ||
27 | #else | ||
28 | # define USB_CFG_CHECK_CRC 0 | ||
29 | #endif | ||
30 | |||
31 | |||
32 | /* ----------------------- Optional Hardware Config ------------------------ */ | ||
33 | |||
34 | /* #define USB_CFG_PULLUP_IOPORTNAME D */ | ||
35 | /* If you connect the 1.5k pullup resistor from D- to a port pin instead of | ||
36 | * V+, you can connect and disconnect the device from firmware by calling | ||
37 | * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). | ||
38 | * This constant defines the port on which the pullup resistor is connected. | ||
39 | */ | ||
40 | /* #define USB_CFG_PULLUP_BIT 4 */ | ||
41 | /* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined | ||
42 | * above) where the 1.5k pullup resistor is connected. See description | ||
43 | * above for details. | ||
44 | */ | ||
45 | |||
46 | /* --------------------------- Functional Range ---------------------------- */ | ||
47 | |||
48 | #ifndef USB_CFG_HAVE_INTRIN_ENDPOINT3 | ||
49 | #define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 | ||
50 | #endif | ||
51 | /* Define this to 1 if you want to compile a version with three endpoints: The | ||
52 | * default control endpoint 0, an interrupt-in endpoint 3 (or the number | ||
53 | * configured below) and a catch-all default interrupt-in endpoint as above. | ||
54 | * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. | ||
55 | */ | ||
56 | #ifndef USB_CFG_HAVE_INTRIN_ENDPOINT | ||
57 | #define USB_CFG_HAVE_INTRIN_ENDPOINT USB_CFG_HAVE_INTRIN_ENDPOINT3 | ||
58 | #endif | ||
59 | /* Define this to 1 if you want to compile a version with two endpoints: The | ||
60 | * default control endpoint 0 and an interrupt-in endpoint (any other endpoint | ||
61 | * number). | ||
62 | */ | ||
63 | #define USB_CFG_EP3_NUMBER 3 | ||
64 | /* If the so-called endpoint 3 is used, it can now be configured to any other | ||
65 | * endpoint number (except 0) with this macro. Default if undefined is 3. | ||
66 | */ | ||
67 | /* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ | ||
68 | /* The above macro defines the startup condition for data toggling on the | ||
69 | * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. | ||
70 | * Since the token is toggled BEFORE sending any data, the first packet is | ||
71 | * sent with the oposite value of this configuration! | ||
72 | */ | ||
73 | //#define USB_CFG_IMPLEMENT_HALT 0 | ||
74 | /* Define this to 1 if you also want to implement the ENDPOINT_HALT feature | ||
75 | * for endpoint 1 (interrupt endpoint). Although you may not need this feature, | ||
76 | * it is required by the standard. We have made it a config option because it | ||
77 | * bloats the code considerably. | ||
78 | */ | ||
79 | #define USB_CFG_INTR_POLL_INTERVAL 10 | ||
80 | /* If you compile a version with endpoint 1 (interrupt-in), this is the poll | ||
81 | * interval. The value is in milliseconds and must not be less than 10 ms for | ||
82 | * low speed devices. | ||
83 | */ | ||
84 | #define USB_CFG_IS_SELF_POWERED 0 | ||
85 | /* Define this to 1 if the device has its own power supply. Set it to 0 if the | ||
86 | * device is powered from the USB bus. | ||
87 | */ | ||
88 | #define USB_CFG_MAX_BUS_POWER 40 | ||
89 | /* Set this variable to the maximum USB bus power consumption of your device. | ||
90 | * The value is in milliamperes. [It will be divided by two since USB | ||
91 | * communicates power requirements in units of 2 mA.] | ||
92 | */ | ||
93 | //#define USB_CFG_IMPLEMENT_FN_WRITE 0 | ||
94 | /* Set this to 1 if you want usbFunctionWrite() to be called for control-out | ||
95 | * transfers. Set it to 0 if you don't need it and want to save a couple of | ||
96 | * bytes. | ||
97 | */ | ||
98 | //#define USB_CFG_IMPLEMENT_FN_READ 0 | ||
99 | /* Set this to 1 if you need to send control replies which are generated | ||
100 | * "on the fly" when usbFunctionRead() is called. If you only want to send | ||
101 | * data from a static buffer, set it to 0 and return the data from | ||
102 | * usbFunctionSetup(). This saves a couple of bytes. | ||
103 | */ | ||
104 | //#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 | ||
105 | /* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. | ||
106 | * You must implement the function usbFunctionWriteOut() which receives all | ||
107 | * interrupt/bulk data sent to any endpoint other than 0. The endpoint number | ||
108 | * can be found in 'usbRxToken'. | ||
109 | */ | ||
110 | #define USB_CFG_HAVE_FLOWCONTROL 0 | ||
111 | /* Define this to 1 if you want flowcontrol over USB data. See the definition | ||
112 | * of the macros usbDisableAllRequests() and usbEnableAllRequests() in | ||
113 | * usbdrv.h. | ||
114 | */ | ||
115 | //#define USB_CFG_LONG_TRANSFERS 0 | ||
116 | /* Define this to 1 if you want to send/receive blocks of more than 254 bytes | ||
117 | * in a single control-in or control-out transfer. Note that the capability | ||
118 | * for long transfers increases the driver size. | ||
119 | */ | ||
120 | /* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */ | ||
121 | /* This macro is a hook if you want to do unconventional things. If it is | ||
122 | * defined, it's inserted at the beginning of received message processing. | ||
123 | * If you eat the received message and don't want default processing to | ||
124 | * proceed, do a return after doing your things. One possible application | ||
125 | * (besides debugging) is to flash a status LED on each packet. | ||
126 | */ | ||
127 | /* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */ | ||
128 | /* This macro is a hook if you need to know when an USB RESET occurs. It has | ||
129 | * one parameter which distinguishes between the start of RESET state and its | ||
130 | * end. | ||
131 | */ | ||
132 | /* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */ | ||
133 | /* This macro (if defined) is executed when a USB SET_ADDRESS request was | ||
134 | * received. | ||
135 | */ | ||
136 | //#define USB_COUNT_SOF 0 | ||
137 | /* define this macro to 1 if you need the global variable "usbSofCount" which | ||
138 | * counts SOF packets. This feature requires that the hardware interrupt is | ||
139 | * connected to D- instead of D+. | ||
140 | */ | ||
141 | //#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0 | ||
142 | /* define this macro to 1 if you want the function usbMeasureFrameLength() | ||
143 | * compiled in. This function can be used to calibrate the AVR's RC oscillator. | ||
144 | */ | ||
145 | |||
146 | /* -------------------------- Device Description --------------------------- */ | ||
147 | |||
148 | #define USB_CFG_VENDOR_ID 0xc0, 0x16 | ||
149 | /* USB vendor ID for the device, low byte first. If you have registered your | ||
150 | * own Vendor ID, define it here. Otherwise you use one of obdev's free shared | ||
151 | * VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! | ||
152 | */ | ||
153 | #define USB_CFG_DEVICE_ID 0x08, 0x3e /* 1000 dec, "free for lab use" */ | ||
154 | /* This is the ID of the product, low byte first. It is interpreted in the | ||
155 | * scope of the vendor ID. If you have registered your own VID with usb.org | ||
156 | * or if you have licensed a PID from somebody else, define it here. Otherwise | ||
157 | * you use obdev's free shared VID/PID pair. Be sure to read the rules in | ||
158 | * USB-IDs-for-free.txt! | ||
159 | */ | ||
160 | #define USB_CFG_DEVICE_VERSION 0x00, 0x01 | ||
161 | /* Version number of the device: Minor number first, then major number. | ||
162 | */ | ||
163 | #define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't' | ||
164 | #define USB_CFG_VENDOR_NAME_LEN 8 | ||
165 | /* These two values define the vendor name returned by the USB device. The name | ||
166 | * must be given as a list of characters under single quotes. The characters | ||
167 | * are interpreted as Unicode (UTF-16) entities. | ||
168 | * If you don't want a vendor name string, undefine these macros. | ||
169 | * ALWAYS define a vendor name containing your Internet domain name if you use | ||
170 | * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for | ||
171 | * details. | ||
172 | */ | ||
173 | #define USB_CFG_DEVICE_NAME 'T', 'e', 's', 't' | ||
174 | #define USB_CFG_DEVICE_NAME_LEN 4 | ||
175 | /* Same as above for the device name. If you don't want a device name, undefine | ||
176 | * the macros. See the file USB-IDs-for-free.txt before you assign a name if | ||
177 | * you use a shared VID/PID. | ||
178 | */ | ||
179 | /*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */ | ||
180 | /*#define USB_CFG_SERIAL_NUMBER_LEN 0 */ | ||
181 | /* Same as above for the serial number. If you don't want a serial number, | ||
182 | * undefine the macros. | ||
183 | * It may be useful to provide the serial number through other means than at | ||
184 | * compile time. See the section about descriptor properties below for how | ||
185 | * to fine tune control over USB descriptors such as the string descriptor | ||
186 | * for the serial number. | ||
187 | */ | ||
188 | #define USB_CFG_DEVICE_CLASS 0xff /* set to 0 if deferred to interface */ | ||
189 | #define USB_CFG_DEVICE_SUBCLASS 0 | ||
190 | /* See USB specification if you want to conform to an existing device class. | ||
191 | * Class 0xff is "vendor specific". | ||
192 | */ | ||
193 | #define USB_CFG_INTERFACE_CLASS 0 /* define class here if not at device level */ | ||
194 | #define USB_CFG_INTERFACE_SUBCLASS 0 | ||
195 | #define USB_CFG_INTERFACE_PROTOCOL 0 | ||
196 | /* See USB specification if you want to conform to an existing device class or | ||
197 | * protocol. The following classes must be set at interface level: | ||
198 | * HID class is 3, no subclass and protocol required (but may be useful!) | ||
199 | * CDC class is 2, use subclass 2 and protocol 1 for ACM | ||
200 | */ | ||
201 | /* #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 42 */ | ||
202 | /* Define this to the length of the HID report descriptor, if you implement | ||
203 | * an HID device. Otherwise don't define it or define it to 0. | ||
204 | * If you use this define, you must add a PROGMEM character array named | ||
205 | * "usbHidReportDescriptor" to your code which contains the report descriptor. | ||
206 | * Don't forget to keep the array and this define in sync! | ||
207 | */ | ||
208 | |||
209 | /* #define USB_PUBLIC static */ | ||
210 | /* Use the define above if you #include usbdrv.c instead of linking against it. | ||
211 | * This technique saves a couple of bytes in flash memory. | ||
212 | */ | ||
213 | |||
214 | /* ------------------- Fine Control over USB Descriptors ------------------- */ | ||
215 | /* If you don't want to use the driver's default USB descriptors, you can | ||
216 | * provide our own. These can be provided as (1) fixed length static data in | ||
217 | * flash memory, (2) fixed length static data in RAM or (3) dynamically at | ||
218 | * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more | ||
219 | * information about this function. | ||
220 | * Descriptor handling is configured through the descriptor's properties. If | ||
221 | * no properties are defined or if they are 0, the default descriptor is used. | ||
222 | * Possible properties are: | ||
223 | * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched | ||
224 | * at runtime via usbFunctionDescriptor(). | ||
225 | * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found | ||
226 | * in static memory is in RAM, not in flash memory. | ||
227 | * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), | ||
228 | * the driver must know the descriptor's length. The descriptor itself is | ||
229 | * found at the address of a well known identifier (see below). | ||
230 | * List of static descriptor names (must be declared PROGMEM if in flash): | ||
231 | * char usbDescriptorDevice[]; | ||
232 | * char usbDescriptorConfiguration[]; | ||
233 | * char usbDescriptorHidReport[]; | ||
234 | * char usbDescriptorString0[]; | ||
235 | * int usbDescriptorStringVendor[]; | ||
236 | * int usbDescriptorStringDevice[]; | ||
237 | * int usbDescriptorStringSerialNumber[]; | ||
238 | * Other descriptors can't be provided statically, they must be provided | ||
239 | * dynamically at runtime. | ||
240 | * | ||
241 | * Descriptor properties are or-ed or added together, e.g.: | ||
242 | * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) | ||
243 | * | ||
244 | * The following descriptors are defined: | ||
245 | * USB_CFG_DESCR_PROPS_DEVICE | ||
246 | * USB_CFG_DESCR_PROPS_CONFIGURATION | ||
247 | * USB_CFG_DESCR_PROPS_STRINGS | ||
248 | * USB_CFG_DESCR_PROPS_STRING_0 | ||
249 | * USB_CFG_DESCR_PROPS_STRING_VENDOR | ||
250 | * USB_CFG_DESCR_PROPS_STRING_PRODUCT | ||
251 | * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER | ||
252 | * USB_CFG_DESCR_PROPS_HID | ||
253 | * USB_CFG_DESCR_PROPS_HID_REPORT | ||
254 | * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver) | ||
255 | * | ||
256 | */ | ||
257 | |||
258 | #if USE_DYNAMIC_DESCRIPTOR | ||
259 | #define USB_CFG_DESCR_PROPS_DEVICE USB_PROP_IS_DYNAMIC | ||
260 | #define USB_CFG_DESCR_PROPS_CONFIGURATION USB_PROP_IS_DYNAMIC | ||
261 | #else | ||
262 | #define USB_CFG_DESCR_PROPS_DEVICE 0 | ||
263 | #define USB_CFG_DESCR_PROPS_CONFIGURATION 0 | ||
264 | #endif | ||
265 | #define USB_CFG_DESCR_PROPS_STRINGS 0 | ||
266 | #define USB_CFG_DESCR_PROPS_STRING_0 0 | ||
267 | #define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 | ||
268 | #define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 | ||
269 | #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 | ||
270 | #define USB_CFG_DESCR_PROPS_HID 0 | ||
271 | #define USB_CFG_DESCR_PROPS_HID_REPORT 0 | ||
272 | #define USB_CFG_DESCR_PROPS_UNKNOWN 0 | ||
273 | |||
274 | #define usbMsgPtr_t unsigned short | ||
275 | /* If usbMsgPtr_t is not defined, it defaults to 'uchar *'. We define it to | ||
276 | * a scalar type here because gcc generates slightly shorter code for scalar | ||
277 | * arithmetics than for pointer arithmetics. Remove this define for backward | ||
278 | * type compatibility or define it to an 8 bit type if you use data in RAM only | ||
279 | * and all RAM is below 256 bytes (tiny memory model in IAR CC). | ||
280 | */ | ||
281 | |||
282 | /* ----------------------- Optional MCU Description ------------------------ */ | ||
283 | |||
284 | /* The following configurations have working defaults in usbdrv.h. You | ||
285 | * usually don't need to set them explicitly. Only if you want to run | ||
286 | * the driver on a device which is not yet supported or with a compiler | ||
287 | * which is not fully supported (such as IAR C) or if you use a differnt | ||
288 | * interrupt than INT0, you may have to define some of these. | ||
289 | */ | ||
290 | /* #define USB_INTR_CFG MCUCR */ | ||
291 | /* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */ | ||
292 | /* #define USB_INTR_CFG_CLR 0 */ | ||
293 | /* #define USB_INTR_ENABLE GIMSK */ | ||
294 | /* #define USB_INTR_ENABLE_BIT INT0 */ | ||
295 | /* #define USB_INTR_PENDING GIFR */ | ||
296 | /* #define USB_INTR_PENDING_BIT INTF0 */ | ||
297 | /* #define USB_INTR_VECTOR INT0_vect */ | ||
298 | |||
299 | #endif /* __usbconfig_h_included__ */ | ||
diff --git a/lib/vusb/usbdrv/Changelog.txt b/lib/vusb/usbdrv/Changelog.txt new file mode 100644 index 000000000..79b521559 --- /dev/null +++ b/lib/vusb/usbdrv/Changelog.txt | |||
@@ -0,0 +1,329 @@ | |||
1 | This file documents changes in the firmware-only USB driver for atmel's AVR | ||
2 | microcontrollers. New entries are always appended to the end of the file. | ||
3 | Scroll down to the bottom to see the most recent changes. | ||
4 | |||
5 | 2005-04-01: | ||
6 | - Implemented endpoint 1 as interrupt-in endpoint. | ||
7 | - Moved all configuration options to usbconfig.h which is not part of the | ||
8 | driver. | ||
9 | - Changed interface for usbVendorSetup(). | ||
10 | - Fixed compatibility with ATMega8 device. | ||
11 | - Various minor optimizations. | ||
12 | |||
13 | 2005-04-11: | ||
14 | - Changed interface to application: Use usbFunctionSetup(), usbFunctionRead() | ||
15 | and usbFunctionWrite() now. Added configuration options to choose which | ||
16 | of these functions to compile in. | ||
17 | - Assembler module delivers receive data non-inverted now. | ||
18 | - Made register and bit names compatible with more AVR devices. | ||
19 | |||
20 | 2005-05-03: | ||
21 | - Allow address of usbRxBuf on any memory page as long as the buffer does | ||
22 | not cross 256 byte page boundaries. | ||
23 | - Better device compatibility: works with Mega88 now. | ||
24 | - Code optimization in debugging module. | ||
25 | - Documentation updates. | ||
26 | |||
27 | 2006-01-02: | ||
28 | - Added (free) default Vendor- and Product-IDs bought from voti.nl. | ||
29 | - Added USBID-License.txt file which defines the rules for using the free | ||
30 | shared VID/PID pair. | ||
31 | - Added Readme.txt to the usbdrv directory which clarifies administrative | ||
32 | issues. | ||
33 | |||
34 | 2006-01-25: | ||
35 | - Added "configured state" to become more standards compliant. | ||
36 | - Added "HALT" state for interrupt endpoint. | ||
37 | - Driver passes the "USB Command Verifier" test from usb.org now. | ||
38 | - Made "serial number" a configuration option. | ||
39 | - Minor optimizations, we now recommend compiler option "-Os" for best | ||
40 | results. | ||
41 | - Added a version number to usbdrv.h | ||
42 | |||
43 | 2006-02-03: | ||
44 | - New configuration variable USB_BUFFER_SECTION for the memory section where | ||
45 | the USB rx buffer will go. This defaults to ".bss" if not defined. Since | ||
46 | this buffer MUST NOT cross 256 byte pages (not even touch a page at the | ||
47 | end), the user may want to pass a linker option similar to | ||
48 | "-Wl,--section-start=.mybuffer=0x800060". | ||
49 | - Provide structure for usbRequest_t. | ||
50 | - New defines for USB constants. | ||
51 | - Prepared for HID implementations. | ||
52 | - Increased data size limit for interrupt transfers to 8 bytes. | ||
53 | - New macro usbInterruptIsReady() to query interrupt buffer state. | ||
54 | |||
55 | 2006-02-18: | ||
56 | - Ensure that the data token which is sent as an ack to an OUT transfer is | ||
57 | always zero sized. This fixes a bug where the host reports an error after | ||
58 | sending an out transfer to the device, although all data arrived at the | ||
59 | device. | ||
60 | - Updated docs in usbdrv.h to reflect changed API in usbFunctionWrite(). | ||
61 | |||
62 | * Release 2006-02-20 | ||
63 | |||
64 | - Give a compiler warning when compiling with debugging turned on. | ||
65 | - Added Oleg Semyonov's changes for IAR-cc compatibility. | ||
66 | - Added new (optional) functions usbDeviceConnect() and usbDeviceDisconnect() | ||
67 | (also thanks to Oleg!). | ||
68 | - Rearranged tests in usbPoll() to save a couple of instructions in the most | ||
69 | likely case that no actions are pending. | ||
70 | - We need a delay between the SET ADDRESS request until the new address | ||
71 | becomes active. This delay was handled in usbPoll() until now. Since the | ||
72 | spec says that the delay must not exceed 2ms, previous versions required | ||
73 | aggressive polling during the enumeration phase. We have now moved the | ||
74 | handling of the delay into the interrupt routine. | ||
75 | - We must not reply with NAK to a SETUP transaction. We can only achieve this | ||
76 | by making sure that the rx buffer is empty when SETUP tokens are expected. | ||
77 | We therefore don't pass zero sized data packets from the status phase of | ||
78 | a transfer to usbPoll(). This change MAY cause troubles if you rely on | ||
79 | receiving a less than 8 bytes long packet in usbFunctionWrite() to | ||
80 | identify the end of a transfer. usbFunctionWrite() will NEVER be called | ||
81 | with a zero length. | ||
82 | |||
83 | * Release 2006-03-14 | ||
84 | |||
85 | - Improved IAR C support: tiny memory model, more devices | ||
86 | - Added template usbconfig.h file under the name usbconfig-prototype.h | ||
87 | |||
88 | * Release 2006-03-26 | ||
89 | |||
90 | - Added provision for one more interrupt-in endpoint (endpoint 3). | ||
91 | - Added provision for one interrupt-out endpoint (endpoint 1). | ||
92 | - Added flowcontrol macros for USB. | ||
93 | - Added provision for custom configuration descriptor. | ||
94 | - Allow ANY two port bits for D+ and D-. | ||
95 | - Merged (optional) receive endpoint number into global usbRxToken variable. | ||
96 | - Use USB_CFG_IOPORTNAME instead of USB_CFG_IOPORT. We now construct the | ||
97 | variable name from the single port letter instead of computing the address | ||
98 | of related ports from the output-port address. | ||
99 | |||
100 | * Release 2006-06-26 | ||
101 | |||
102 | - Updated documentation in usbdrv.h and usbconfig-prototype.h to reflect the | ||
103 | new features. | ||
104 | - Removed "#warning" directives because IAR does not understand them. Use | ||
105 | unused static variables instead to generate a warning. | ||
106 | - Do not include <avr/io.h> when compiling with IAR. | ||
107 | - Introduced USB_CFG_DESCR_PROPS_* in usbconfig.h to configure how each | ||
108 | USB descriptor should be handled. It is now possible to provide descriptor | ||
109 | data in Flash, RAM or dynamically at runtime. | ||
110 | - STALL is now a status in usbTxLen* instead of a message. We can now conform | ||
111 | to the spec and leave the stall status pending until it is cleared. | ||
112 | - Made usbTxPacketCnt1 and usbTxPacketCnt3 public. This allows the | ||
113 | application code to reset data toggling on interrupt pipes. | ||
114 | |||
115 | * Release 2006-07-18 | ||
116 | |||
117 | - Added an #if !defined __ASSEMBLER__ to the warning in usbdrv.h. This fixes | ||
118 | an assembler error. | ||
119 | - usbDeviceDisconnect() takes pull-up resistor to high impedance now. | ||
120 | |||
121 | * Release 2007-02-01 | ||
122 | |||
123 | - Merged in some code size improvements from usbtiny (thanks to Dick | ||
124 | Streefland for these optimizations!) | ||
125 | - Special alignment requirement for usbRxBuf not required any more. Thanks | ||
126 | again to Dick Streefland for this hint! | ||
127 | - Reverted to "#warning" instead of unused static variables -- new versions | ||
128 | of IAR CC should handle this directive. | ||
129 | - Changed Open Source license to GNU GPL v2 in order to make linking against | ||
130 | other free libraries easier. We no longer require publication of the | ||
131 | circuit diagrams, but we STRONGLY encourage it. If you improve the driver | ||
132 | itself, PLEASE grant us a royalty free license to your changes for our | ||
133 | commercial license. | ||
134 | |||
135 | * Release 2007-03-29 | ||
136 | |||
137 | - New configuration option "USB_PUBLIC" in usbconfig.h. | ||
138 | - Set USB version number to 1.10 instead of 1.01. | ||
139 | - Code used USB_CFG_DESCR_PROPS_STRING_DEVICE and | ||
140 | USB_CFG_DESCR_PROPS_STRING_PRODUCT inconsistently. Changed all occurrences | ||
141 | to USB_CFG_DESCR_PROPS_STRING_PRODUCT. | ||
142 | - New assembler module for 16.5 MHz RC oscillator clock with PLL in receiver | ||
143 | code. | ||
144 | - New assembler module for 16 MHz crystal. | ||
145 | - usbdrvasm.S contains common code only, clock-specific parts have been moved | ||
146 | to usbdrvasm12.S, usbdrvasm16.S and usbdrvasm165.S respectively. | ||
147 | |||
148 | * Release 2007-06-25 | ||
149 | |||
150 | - 16 MHz module: Do SE0 check in stuffed bits as well. | ||
151 | |||
152 | * Release 2007-07-07 | ||
153 | |||
154 | - Define hi8(x) for IAR compiler to limit result to 8 bits. This is necessary | ||
155 | for negative values. | ||
156 | - Added 15 MHz module contributed by V. Bosch. | ||
157 | - Interrupt vector name can now be configured. This is useful if somebody | ||
158 | wants to use a different hardware interrupt than INT0. | ||
159 | |||
160 | * Release 2007-08-07 | ||
161 | |||
162 | - Moved handleIn3 routine in usbdrvasm16.S so that relative jump range is | ||
163 | not exceeded. | ||
164 | - More config options: USB_RX_USER_HOOK(), USB_INITIAL_DATATOKEN, | ||
165 | USB_COUNT_SOF | ||
166 | - USB_INTR_PENDING can now be a memory address, not just I/O | ||
167 | |||
168 | * Release 2007-09-19 | ||
169 | |||
170 | - Split out common parts of assembler modules into separate include file | ||
171 | - Made endpoint numbers configurable so that given interface definitions | ||
172 | can be matched. See USB_CFG_EP3_NUMBER in usbconfig-prototype.h. | ||
173 | - Store endpoint number for interrupt/bulk-out so that usbFunctionWriteOut() | ||
174 | can handle any number of endpoints. | ||
175 | - Define usbDeviceConnect() and usbDeviceDisconnect() even if no | ||
176 | USB_CFG_PULLUP_IOPORTNAME is defined. Directly set D+ and D- to 0 in this | ||
177 | case. | ||
178 | |||
179 | * Release 2007-12-01 | ||
180 | |||
181 | - Optimize usbDeviceConnect() and usbDeviceDisconnect() for less code size | ||
182 | when USB_CFG_PULLUP_IOPORTNAME is not defined. | ||
183 | |||
184 | * Release 2007-12-13 | ||
185 | |||
186 | - Renamed all include-only assembler modules from *.S to *.inc so that | ||
187 | people don't add them to their project sources. | ||
188 | - Distribute leap bits in tx loop more evenly for 16 MHz module. | ||
189 | - Use "macro" and "endm" instead of ".macro" and ".endm" for IAR | ||
190 | - Avoid compiler warnings for constant expr range by casting some values in | ||
191 | USB descriptors. | ||
192 | |||
193 | * Release 2008-01-21 | ||
194 | |||
195 | - Fixed bug in 15 and 16 MHz module where the new address set with | ||
196 | SET_ADDRESS was already accepted at the next NAK or ACK we send, not at | ||
197 | the next data packet we send. This caused problems when the host polled | ||
198 | too fast. Thanks to Alexander Neumann for his help and patience debugging | ||
199 | this issue! | ||
200 | |||
201 | * Release 2008-02-05 | ||
202 | |||
203 | - Fixed bug in 16.5 MHz module where a register was used in the interrupt | ||
204 | handler before it was pushed. This bug was introduced with version | ||
205 | 2007-09-19 when common parts were moved to a separate file. | ||
206 | - Optimized CRC routine (thanks to Reimar Doeffinger). | ||
207 | |||
208 | * Release 2008-02-16 | ||
209 | |||
210 | - Removed outdated IAR compatibility stuff (code sections). | ||
211 | - Added hook macros for USB_RESET_HOOK() and USB_SET_ADDRESS_HOOK(). | ||
212 | - Added optional routine usbMeasureFrameLength() for calibration of the | ||
213 | internal RC oscillator. | ||
214 | |||
215 | * Release 2008-02-28 | ||
216 | |||
217 | - USB_INITIAL_DATATOKEN defaults to USBPID_DATA1 now, which means that we | ||
218 | start with sending USBPID_DATA0. | ||
219 | - Changed defaults in usbconfig-prototype.h | ||
220 | - Added free USB VID/PID pair for MIDI class devices | ||
221 | - Restructured AVR-USB as separate package, not part of PowerSwitch any more. | ||
222 | |||
223 | * Release 2008-04-18 | ||
224 | |||
225 | - Restructured usbdrv.c so that it is easier to read and understand. | ||
226 | - Better code optimization with gcc 4. | ||
227 | - If a second interrupt in endpoint is enabled, also add it to config | ||
228 | descriptor. | ||
229 | - Added config option for long transfers (above 254 bytes), see | ||
230 | USB_CFG_LONG_TRANSFERS in usbconfig.h. | ||
231 | - Added 20 MHz module contributed by Jeroen Benschop. | ||
232 | |||
233 | * Release 2008-05-13 | ||
234 | |||
235 | - Fixed bug in libs-host/hiddata.c function usbhidGetReport(): length | ||
236 | was not incremented, pointer to length was incremented instead. | ||
237 | - Added code to command line tool(s) which claims an interface. This code | ||
238 | is disabled by default, but may be necessary on newer Linux kernels. | ||
239 | - Added usbconfig.h option "USB_CFG_CHECK_DATA_TOGGLING". | ||
240 | - New header "usbportability.h" prepares ports to other development | ||
241 | environments. | ||
242 | - Long transfers (above 254 bytes) did not work when usbFunctionRead() was | ||
243 | used to supply the data. Fixed this bug. [Thanks to Alexander Neumann!] | ||
244 | - In hiddata.c (example code for sending/receiving data over HID), use | ||
245 | USB_RECIP_DEVICE instead of USB_RECIP_INTERFACE for control transfers so | ||
246 | that we need not claim the interface. | ||
247 | - in usbPoll() loop 20 times polling for RESET state instead of 10 times. | ||
248 | This accounts for the higher clock rates we now support. | ||
249 | - Added a module for 12.8 MHz RC oscillator with PLL in receiver loop. | ||
250 | - Added hook to SOF code so that oscillator can be tuned to USB frame clock. | ||
251 | - Added timeout to waitForJ loop. Helps preventing unexpected hangs. | ||
252 | - Added example code for oscillator tuning to libs-device (thanks to | ||
253 | Henrik Haftmann for the idea to this routine). | ||
254 | - Implemented option USB_CFG_SUPPRESS_INTR_CODE. | ||
255 | |||
256 | * Release 2008-10-22 | ||
257 | |||
258 | - Fixed libs-device/osctune.h: OSCCAL is memory address on ATMega88 and | ||
259 | similar, not offset of 0x20 needs to be added. | ||
260 | - Allow distribution under GPLv3 for those who have to link against other | ||
261 | code distributed under GPLv3. | ||
262 | |||
263 | * Release 2008-11-26 | ||
264 | |||
265 | - Removed libusb-win32 dependency for hid-data example in Makefile.windows. | ||
266 | It was never required and confused many people. | ||
267 | - Added extern uchar usbRxToken to usbdrv.h. | ||
268 | - Integrated a module with CRC checks at 18 MHz by Lukas Schrittwieser. | ||
269 | |||
270 | * Release 2009-03-23 | ||
271 | |||
272 | - Hid-mouse example used settings from hid-data example, fixed that. | ||
273 | - Renamed project to V-USB due to a trademark issue with Atmel(r). | ||
274 | - Changed CommercialLicense.txt and USBID-License.txt to make the | ||
275 | background of USB ID registration clearer. | ||
276 | |||
277 | * Release 2009-04-15 | ||
278 | |||
279 | - Changed CommercialLicense.txt to reflect the new range of PIDs from | ||
280 | Jason Kotzin. | ||
281 | - Removed USBID-License.txt in favor of USB-IDs-for-free.txt and | ||
282 | USB-ID-FAQ.txt | ||
283 | - Fixed a bug in the 12.8 MHz module: End Of Packet decection was made in | ||
284 | the center between bit 0 and 1 of each byte. This is where the data lines | ||
285 | are expected to change and the sampled data may therefore be nonsense. | ||
286 | We therefore check EOP ONLY if bits 0 AND 1 have both been read as 0 on D-. | ||
287 | - Fixed a bitstuffing problem in the 16 MHz module: If bit 6 was stuffed, | ||
288 | the unstuffing code in the receiver routine was 1 cycle too long. If | ||
289 | multiple bytes had the unstuffing in bit 6, the error summed up until the | ||
290 | receiver was out of sync. | ||
291 | - Included option for faster CRC routine. | ||
292 | Thanks to Slawomir Fras (BoskiDialer) for this code! | ||
293 | - Updated bits in Configuration Descriptor's bmAttributes according to | ||
294 | USB 1.1 (in particular bit 7, it is a must-be-set bit now). | ||
295 | |||
296 | * Release 2009-08-22 | ||
297 | |||
298 | - Moved first DBG1() after odDebugInit() in all examples. | ||
299 | - Use vector INT0_vect instead of SIG_INTERRUPT0 if defined. This makes | ||
300 | V-USB compatible with the new "p" suffix devices (e.g. ATMega328p). | ||
301 | - USB_CFG_CLOCK_KHZ setting is now required in usbconfig.h (no default any | ||
302 | more). | ||
303 | - New option USB_CFG_DRIVER_FLASH_PAGE allows boot loaders on devices with | ||
304 | more than 64 kB flash. | ||
305 | - Built-in configuration descriptor allows custom definition for second | ||
306 | endpoint now. | ||
307 | |||
308 | * Release 2010-07-15 | ||
309 | |||
310 | - Fixed bug in usbDriverSetup() which prevented descriptor sizes above 255 | ||
311 | bytes. | ||
312 | - Avoid a compiler warning for unused parameter in usbHandleResetHook() when | ||
313 | compiler option -Wextra is enabled. | ||
314 | - Fixed wrong hex value for some IDs in USB-IDs-for-free.txt. | ||
315 | - Keep a define for USBATTR_BUSPOWER, although the flag does not exist | ||
316 | in USB 1.1 any more. Set it to 0. This is for backward compatibility. | ||
317 | |||
318 | * Release 2012-01-09 | ||
319 | |||
320 | - Define a separate (defined) type for usbMsgPtr so that projects using a | ||
321 | tiny memory model can define it to an 8 bit type in usbconfig.h. This | ||
322 | change also saves a couple of bytes when using a scalar 16 bit type. | ||
323 | - Inserted "const" keyword for all PROGMEM declarations because new GCC | ||
324 | requires it. | ||
325 | - Fixed problem with dependence of usbportability.h on usbconfig.h. This | ||
326 | problem occurred with IAR CC only. | ||
327 | - Prepared repository for github.com. | ||
328 | |||
329 | * Release 2012-12-06 \ No newline at end of file | ||
diff --git a/lib/vusb/usbdrv/CommercialLicense.txt b/lib/vusb/usbdrv/CommercialLicense.txt new file mode 100644 index 000000000..de1a2b09b --- /dev/null +++ b/lib/vusb/usbdrv/CommercialLicense.txt | |||
@@ -0,0 +1,166 @@ | |||
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 | |||
diff --git a/lib/vusb/usbdrv/License.txt b/lib/vusb/usbdrv/License.txt new file mode 100644 index 000000000..4460cfbae --- /dev/null +++ b/lib/vusb/usbdrv/License.txt | |||
@@ -0,0 +1,361 @@ | |||
1 | OBJECTIVE DEVELOPMENT GmbH's V-USB driver software is distributed under the | ||
2 | terms and conditions of the GNU GPL version 2 or the GNU GPL version 3. It is | ||
3 | your choice whether you apply the terms of version 2 or version 3. The full | ||
4 | text of GPLv2 is included below. In addition to the requirements in the GPL, | ||
5 | we STRONGLY ENCOURAGE you to do the following: | ||
6 | |||
7 | (1) Publish your entire project on a web site and drop us a note with the URL. | ||
8 | Use the form at http://www.obdev.at/vusb/feedback.html for your submission. | ||
9 | |||
10 | (2) Adhere to minimum publication standards. Please include AT LEAST: | ||
11 | - a circuit diagram in PDF, PNG or GIF format | ||
12 | - full source code for the host software | ||
13 | - a Readme.txt file in ASCII format which describes the purpose of the | ||
14 | project and what can be found in which directories and which files | ||
15 | - a reference to http://www.obdev.at/vusb/ | ||
16 | |||
17 | (3) If you improve the driver firmware itself, please give us a free license | ||
18 | to your modifications for our commercial license offerings. | ||
19 | |||
20 | |||
21 | |||
22 | GNU GENERAL PUBLIC LICENSE | ||
23 | Version 2, June 1991 | ||
24 | |||
25 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. | ||
26 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
27 | Everyone is permitted to copy and distribute verbatim copies | ||
28 | of this license document, but changing it is not allowed. | ||
29 | |||
30 | Preamble | ||
31 | |||
32 | The licenses for most software are designed to take away your | ||
33 | freedom to share and change it. By contrast, the GNU General Public | ||
34 | License is intended to guarantee your freedom to share and change free | ||
35 | software--to make sure the software is free for all its users. This | ||
36 | General Public License applies to most of the Free Software | ||
37 | Foundation's software and to any other program whose authors commit to | ||
38 | using it. (Some other Free Software Foundation software is covered by | ||
39 | the GNU Library General Public License instead.) You can apply it to | ||
40 | your programs, too. | ||
41 | |||
42 | When we speak of free software, we are referring to freedom, not | ||
43 | price. Our General Public Licenses are designed to make sure that you | ||
44 | have the freedom to distribute copies of free software (and charge for | ||
45 | this service if you wish), that you receive source code or can get it | ||
46 | if you want it, that you can change the software or use pieces of it | ||
47 | in new free programs; and that you know you can do these things. | ||
48 | |||
49 | To protect your rights, we need to make restrictions that forbid | ||
50 | anyone to deny you these rights or to ask you to surrender the rights. | ||
51 | These restrictions translate to certain responsibilities for you if you | ||
52 | distribute copies of the software, or if you modify it. | ||
53 | |||
54 | For example, if you distribute copies of such a program, whether | ||
55 | gratis or for a fee, you must give the recipients all the rights that | ||
56 | you have. You must make sure that they, too, receive or can get the | ||
57 | source code. And you must show them these terms so they know their | ||
58 | rights. | ||
59 | |||
60 | We protect your rights with two steps: (1) copyright the software, and | ||
61 | (2) offer you this license which gives you legal permission to copy, | ||
62 | distribute and/or modify the software. | ||
63 | |||
64 | Also, for each author's protection and ours, we want to make certain | ||
65 | that everyone understands that there is no warranty for this free | ||
66 | software. If the software is modified by someone else and passed on, we | ||
67 | want its recipients to know that what they have is not the original, so | ||
68 | that any problems introduced by others will not reflect on the original | ||
69 | authors' reputations. | ||
70 | |||
71 | Finally, any free program is threatened constantly by software | ||
72 | patents. We wish to avoid the danger that redistributors of a free | ||
73 | program will individually obtain patent licenses, in effect making the | ||
74 | program proprietary. To prevent this, we have made it clear that any | ||
75 | patent must be licensed for everyone's free use or not licensed at all. | ||
76 | |||
77 | The precise terms and conditions for copying, distribution and | ||
78 | modification follow. | ||
79 | |||
80 | GNU GENERAL PUBLIC LICENSE | ||
81 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||
82 | |||
83 | 0. This License applies to any program or other work which contains | ||
84 | a notice placed by the copyright holder saying it may be distributed | ||
85 | under the terms of this General Public License. The "Program", below, | ||
86 | refers to any such program or work, and a "work based on the Program" | ||
87 | means either the Program or any derivative work under copyright law: | ||
88 | that is to say, a work containing the Program or a portion of it, | ||
89 | either verbatim or with modifications and/or translated into another | ||
90 | language. (Hereinafter, translation is included without limitation in | ||
91 | the term "modification".) Each licensee is addressed as "you". | ||
92 | |||
93 | Activities other than copying, distribution and modification are not | ||
94 | covered by this License; they are outside its scope. The act of | ||
95 | running the Program is not restricted, and the output from the Program | ||
96 | is covered only if its contents constitute a work based on the | ||
97 | Program (independent of having been made by running the Program). | ||
98 | Whether that is true depends on what the Program does. | ||
99 | |||
100 | 1. You may copy and distribute verbatim copies of the Program's | ||
101 | source code as you receive it, in any medium, provided that you | ||
102 | conspicuously and appropriately publish on each copy an appropriate | ||
103 | copyright notice and disclaimer of warranty; keep intact all the | ||
104 | notices that refer to this License and to the absence of any warranty; | ||
105 | and give any other recipients of the Program a copy of this License | ||
106 | along with the Program. | ||
107 | |||
108 | You may charge a fee for the physical act of transferring a copy, and | ||
109 | you may at your option offer warranty protection in exchange for a fee. | ||
110 | |||
111 | 2. You may modify your copy or copies of the Program or any portion | ||
112 | of it, thus forming a work based on the Program, and copy and | ||
113 | distribute such modifications or work under the terms of Section 1 | ||
114 | above, provided that you also meet all of these conditions: | ||
115 | |||
116 | a) You must cause the modified files to carry prominent notices | ||
117 | stating that you changed the files and the date of any change. | ||
118 | |||
119 | b) You must cause any work that you distribute or publish, that in | ||
120 | whole or in part contains or is derived from the Program or any | ||
121 | part thereof, to be licensed as a whole at no charge to all third | ||
122 | parties under the terms of this License. | ||
123 | |||
124 | c) If the modified program normally reads commands interactively | ||
125 | when run, you must cause it, when started running for such | ||
126 | interactive use in the most ordinary way, to print or display an | ||
127 | announcement including an appropriate copyright notice and a | ||
128 | notice that there is no warranty (or else, saying that you provide | ||
129 | a warranty) and that users may redistribute the program under | ||
130 | these conditions, and telling the user how to view a copy of this | ||
131 | License. (Exception: if the Program itself is interactive but | ||
132 | does not normally print such an announcement, your work based on | ||
133 | the Program is not required to print an announcement.) | ||
134 | |||
135 | These requirements apply to the modified work as a whole. If | ||
136 | identifiable sections of that work are not derived from the Program, | ||
137 | and can be reasonably considered independent and separate works in | ||
138 | themselves, then this License, and its terms, do not apply to those | ||
139 | sections when you distribute them as separate works. But when you | ||
140 | distribute the same sections as part of a whole which is a work based | ||
141 | on the Program, the distribution of the whole must be on the terms of | ||
142 | this License, whose permissions for other licensees extend to the | ||
143 | entire whole, and thus to each and every part regardless of who wrote it. | ||
144 | |||
145 | Thus, it is not the intent of this section to claim rights or contest | ||
146 | your rights to work written entirely by you; rather, the intent is to | ||
147 | exercise the right to control the distribution of derivative or | ||
148 | collective works based on the Program. | ||
149 | |||
150 | In addition, mere aggregation of another work not based on the Program | ||
151 | with the Program (or with a work based on the Program) on a volume of | ||
152 | a storage or distribution medium does not bring the other work under | ||
153 | the scope of this License. | ||
154 | |||
155 | 3. You may copy and distribute the Program (or a work based on it, | ||
156 | under Section 2) in object code or executable form under the terms of | ||
157 | Sections 1 and 2 above provided that you also do one of the following: | ||
158 | |||
159 | a) Accompany it with the complete corresponding machine-readable | ||
160 | source code, which must be distributed under the terms of Sections | ||
161 | 1 and 2 above on a medium customarily used for software interchange; or, | ||
162 | |||
163 | b) Accompany it with a written offer, valid for at least three | ||
164 | years, to give any third party, for a charge no more than your | ||
165 | cost of physically performing source distribution, a complete | ||
166 | machine-readable copy of the corresponding source code, to be | ||
167 | distributed under the terms of Sections 1 and 2 above on a medium | ||
168 | customarily used for software interchange; or, | ||
169 | |||
170 | c) Accompany it with the information you received as to the offer | ||
171 | to distribute corresponding source code. (This alternative is | ||
172 | allowed only for noncommercial distribution and only if you | ||
173 | received the program in object code or executable form with such | ||
174 | an offer, in accord with Subsection b above.) | ||
175 | |||
176 | The source code for a work means the preferred form of the work for | ||
177 | making modifications to it. For an executable work, complete source | ||
178 | code means all the source code for all modules it contains, plus any | ||
179 | associated interface definition files, plus the scripts used to | ||
180 | control compilation and installation of the executable. However, as a | ||
181 | special exception, the source code distributed need not include | ||
182 | anything that is normally distributed (in either source or binary | ||
183 | form) with the major components (compiler, kernel, and so on) of the | ||
184 | operating system on which the executable runs, unless that component | ||
185 | itself accompanies the executable. | ||
186 | |||
187 | If distribution of executable or object code is made by offering | ||
188 | access to copy from a designated place, then offering equivalent | ||
189 | access to copy the source code from the same place counts as | ||
190 | distribution of the source code, even though third parties are not | ||
191 | compelled to copy the source along with the object code. | ||
192 | |||
193 | 4. You may not copy, modify, sublicense, or distribute the Program | ||
194 | except as expressly provided under this License. Any attempt | ||
195 | otherwise to copy, modify, sublicense or distribute the Program is | ||
196 | void, and will automatically terminate your rights under this License. | ||
197 | However, parties who have received copies, or rights, from you under | ||
198 | this License will not have their licenses terminated so long as such | ||
199 | parties remain in full compliance. | ||
200 | |||
201 | 5. You are not required to accept this License, since you have not | ||
202 | signed it. However, nothing else grants you permission to modify or | ||
203 | distribute the Program or its derivative works. These actions are | ||
204 | prohibited by law if you do not accept this License. Therefore, by | ||
205 | modifying or distributing the Program (or any work based on the | ||
206 | Program), you indicate your acceptance of this License to do so, and | ||
207 | all its terms and conditions for copying, distributing or modifying | ||
208 | the Program or works based on it. | ||
209 | |||
210 | 6. Each time you redistribute the Program (or any work based on the | ||
211 | Program), the recipient automatically receives a license from the | ||
212 | original licensor to copy, distribute or modify the Program subject to | ||
213 | these terms and conditions. You may not impose any further | ||
214 | restrictions on the recipients' exercise of the rights granted herein. | ||
215 | You are not responsible for enforcing compliance by third parties to | ||
216 | this License. | ||
217 | |||
218 | 7. If, as a consequence of a court judgment or allegation of patent | ||
219 | infringement or for any other reason (not limited to patent issues), | ||
220 | conditions are imposed on you (whether by court order, agreement or | ||
221 | otherwise) that contradict the conditions of this License, they do not | ||
222 | excuse you from the conditions of this License. If you cannot | ||
223 | distribute so as to satisfy simultaneously your obligations under this | ||
224 | License and any other pertinent obligations, then as a consequence you | ||
225 | may not distribute the Program at all. For example, if a patent | ||
226 | license would not permit royalty-free redistribution of the Program by | ||
227 | all those who receive copies directly or indirectly through you, then | ||
228 | the only way you could satisfy both it and this License would be to | ||
229 | refrain entirely from distribution of the Program. | ||
230 | |||
231 | If any portion of this section is held invalid or unenforceable under | ||
232 | any particular circumstance, the balance of the section is intended to | ||
233 | apply and the section as a whole is intended to apply in other | ||
234 | circumstances. | ||
235 | |||
236 | It is not the purpose of this section to induce you to infringe any | ||
237 | patents or other property right claims or to contest validity of any | ||
238 | such claims; this section has the sole purpose of protecting the | ||
239 | integrity of the free software distribution system, which is | ||
240 | implemented by public license practices. Many people have made | ||
241 | generous contributions to the wide range of software distributed | ||
242 | through that system in reliance on consistent application of that | ||
243 | system; it is up to the author/donor to decide if he or she is willing | ||
244 | to distribute software through any other system and a licensee cannot | ||
245 | impose that choice. | ||
246 | |||
247 | This section is intended to make thoroughly clear what is believed to | ||
248 | be a consequence of the rest of this License. | ||
249 | |||
250 | 8. If the distribution and/or use of the Program is restricted in | ||
251 | certain countries either by patents or by copyrighted interfaces, the | ||
252 | original copyright holder who places the Program under this License | ||
253 | may add an explicit geographical distribution limitation excluding | ||
254 | those countries, so that distribution is permitted only in or among | ||
255 | countries not thus excluded. In such case, this License incorporates | ||
256 | the limitation as if written in the body of this License. | ||
257 | |||
258 | 9. The Free Software Foundation may publish revised and/or new versions | ||
259 | of the General Public License from time to time. Such new versions will | ||
260 | be similar in spirit to the present version, but may differ in detail to | ||
261 | address new problems or concerns. | ||
262 | |||
263 | Each version is given a distinguishing version number. If the Program | ||
264 | specifies a version number of this License which applies to it and "any | ||
265 | later version", you have the option of following the terms and conditions | ||
266 | either of that version or of any later version published by the Free | ||
267 | Software Foundation. If the Program does not specify a version number of | ||
268 | this License, you may choose any version ever published by the Free Software | ||
269 | Foundation. | ||
270 | |||
271 | 10. If you wish to incorporate parts of the Program into other free | ||
272 | programs whose distribution conditions are different, write to the author | ||
273 | to ask for permission. For software which is copyrighted by the Free | ||
274 | Software Foundation, write to the Free Software Foundation; we sometimes | ||
275 | make exceptions for this. Our decision will be guided by the two goals | ||
276 | of preserving the free status of all derivatives of our free software and | ||
277 | of promoting the sharing and reuse of software generally. | ||
278 | |||
279 | NO WARRANTY | ||
280 | |||
281 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | ||
282 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | ||
283 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | ||
284 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | ||
285 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
286 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | ||
287 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | ||
288 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | ||
289 | REPAIR OR CORRECTION. | ||
290 | |||
291 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | ||
292 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | ||
293 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, | ||
294 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING | ||
295 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | ||
296 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | ||
297 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | ||
298 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | ||
299 | POSSIBILITY OF SUCH DAMAGES. | ||
300 | |||
301 | END OF TERMS AND CONDITIONS | ||
302 | |||
303 | How to Apply These Terms to Your New Programs | ||
304 | |||
305 | If you develop a new program, and you want it to be of the greatest | ||
306 | possible use to the public, the best way to achieve this is to make it | ||
307 | free software which everyone can redistribute and change under these terms. | ||
308 | |||
309 | To do so, attach the following notices to the program. It is safest | ||
310 | to attach them to the start of each source file to most effectively | ||
311 | convey the exclusion of warranty; and each file should have at least | ||
312 | the "copyright" line and a pointer to where the full notice is found. | ||
313 | |||
314 | <one line to give the program's name and a brief idea of what it does.> | ||
315 | Copyright (C) <year> <name of author> | ||
316 | |||
317 | This program is free software; you can redistribute it and/or modify | ||
318 | it under the terms of the GNU General Public License as published by | ||
319 | the Free Software Foundation; either version 2 of the License, or | ||
320 | (at your option) any later version. | ||
321 | |||
322 | This program is distributed in the hope that it will be useful, | ||
323 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
324 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
325 | GNU General Public License for more details. | ||
326 | |||
327 | You should have received a copy of the GNU General Public License | ||
328 | along with this program; if not, write to the Free Software | ||
329 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
330 | |||
331 | |||
332 | Also add information on how to contact you by electronic and paper mail. | ||
333 | |||
334 | If the program is interactive, make it output a short notice like this | ||
335 | when it starts in an interactive mode: | ||
336 | |||
337 | Gnomovision version 69, Copyright (C) year name of author | ||
338 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | ||
339 | This is free software, and you are welcome to redistribute it | ||
340 | under certain conditions; type `show c' for details. | ||
341 | |||
342 | The hypothetical commands `show w' and `show c' should show the appropriate | ||
343 | parts of the General Public License. Of course, the commands you use may | ||
344 | be called something other than `show w' and `show c'; they could even be | ||
345 | mouse-clicks or menu items--whatever suits your program. | ||
346 | |||
347 | You should also get your employer (if you work as a programmer) or your | ||
348 | school, if any, to sign a "copyright disclaimer" for the program, if | ||
349 | necessary. Here is a sample; alter the names: | ||
350 | |||
351 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program | ||
352 | `Gnomovision' (which makes passes at compilers) written by James Hacker. | ||
353 | |||
354 | <signature of Ty Coon>, 1 April 1989 | ||
355 | Ty Coon, President of Vice | ||
356 | |||
357 | This General Public License does not permit incorporating your program into | ||
358 | proprietary programs. If your program is a subroutine library, you may | ||
359 | consider it more useful to permit linking proprietary applications with the | ||
360 | library. If this is what you want to do, use the GNU Library General | ||
361 | Public License instead of this License. | ||
diff --git a/lib/vusb/usbdrv/Readme.txt b/lib/vusb/usbdrv/Readme.txt new file mode 100644 index 000000000..970dc66b2 --- /dev/null +++ b/lib/vusb/usbdrv/Readme.txt | |||
@@ -0,0 +1,172 @@ | |||
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 | |||
diff --git a/lib/vusb/usbdrv/USB-ID-FAQ.txt b/lib/vusb/usbdrv/USB-ID-FAQ.txt new file mode 100644 index 000000000..a4a6bd6ec --- /dev/null +++ b/lib/vusb/usbdrv/USB-ID-FAQ.txt | |||
@@ -0,0 +1,149 @@ | |||
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. | ||
diff --git a/lib/vusb/usbdrv/USB-IDs-for-free.txt b/lib/vusb/usbdrv/USB-IDs-for-free.txt new file mode 100644 index 000000000..8f444272a --- /dev/null +++ b/lib/vusb/usbdrv/USB-IDs-for-free.txt | |||
@@ -0,0 +1,168 @@ | |||
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. "[email protected]"). 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. "[email protected]"), 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. | ||
diff --git a/lib/vusb/usbdrv/asmcommon.inc b/lib/vusb/usbdrv/asmcommon.inc new file mode 100644 index 000000000..906dc1496 --- /dev/null +++ b/lib/vusb/usbdrv/asmcommon.inc | |||
@@ -0,0 +1,209 @@ | |||
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<<USB_INTR_PENDING_BIT | ||
44 | USB_STORE_PENDING(x2) ; clear any pending interrupts | ||
45 | ignorePacket: | ||
46 | clr token | ||
47 | rjmp storeTokenAndReturn | ||
48 | |||
49 | ;---------------------------------------------------------------------------- | ||
50 | ; Processing of received packet (numbers in brackets are cycles after center of SE0) | ||
51 | ;---------------------------------------------------------------------------- | ||
52 | ;This is the only non-error exit point for the software receiver loop | ||
53 | ;we don't check any CRCs here because there is no time left. | ||
54 | se0: | ||
55 | subi cnt, USB_BUFSIZE ;[5] | ||
56 | neg cnt ;[6] | ||
57 | sub YL, cnt ;[7] | ||
58 | sbci YH, 0 ;[8] | ||
59 | ldi x2, 1<<USB_INTR_PENDING_BIT ;[9] | ||
60 | USB_STORE_PENDING(x2) ;[10] clear pending intr and check flag later. SE0 should be over. | ||
61 | ld token, y ;[11] | ||