├── .gitignore
├── README
├── TODO
├── examples
├── UsbDeviceDemo1-python
│ └── usb_device_demo1.py
├── UsbDeviceDemo1
│ └── UsbDeviceDemo1.pde
├── UsbStreamDemo1-python
│ └── usb_stream_demo1.py
├── UsbStreamDemo1
│ └── UsbStreamDemo1.pde
├── UsbStreamDemo2-python
│ ├── crypty.py
│ └── usb_stream_demo2.py
├── UsbStreamDemo2
│ └── UsbStreamDemo2.pde
└── arduino
│ ├── __init__.py
│ └── usbdevice.py
└── libraries
├── UsbDevice
├── ArduinoNotes.txt
├── Changelog.txt
├── CommercialLicense.txt
├── License.txt
├── Readme.txt
├── USB-ID-FAQ.txt
├── USB-IDs-for-free.txt
├── USBID-License.txt
├── UsbDevice.c
├── UsbDevice.h
├── asmcommon.inc
├── oddebug.c
├── oddebug.h
├── usbconfig-prototype.h
├── usbconfig.h
├── usbdrv.c
├── usbdrv.h
├── usbdrvasm.S
├── usbdrvasm.asm
├── usbdrvasm12.inc
├── usbdrvasm128.inc
├── usbdrvasm15.inc
├── usbdrvasm16.inc
├── usbdrvasm165.inc
├── usbdrvasm18-crc.inc
├── usbdrvasm20.inc
└── usbportability.h
├── UsbKeyboard
├── ArduinoNotes.txt
├── UsbKeyboard.h
├── examples
│ └── UsbKeyboardDemo1
│ │ └── UsbKeyboardDemo1.pde
├── usbconfig.h
└── utility
│ ├── Changelog.txt
│ ├── CommercialLicense.txt
│ ├── License.txt
│ ├── Readme.txt
│ ├── USB-ID-FAQ.txt
│ ├── USB-IDs-for-free.txt
│ ├── asmcommon.inc
│ ├── oddebug.c
│ ├── oddebug.h
│ ├── usbconfig-prototype.h
│ ├── usbdrv.c
│ ├── usbdrv.h
│ ├── usbdrvasm.S
│ ├── usbdrvasm.asm
│ ├── usbdrvasm12.inc
│ ├── usbdrvasm128.inc
│ ├── usbdrvasm15.inc
│ ├── usbdrvasm16.inc
│ ├── usbdrvasm165.inc
│ ├── usbdrvasm18-crc.inc
│ ├── usbdrvasm18.inc
│ ├── usbdrvasm20.inc
│ └── usbportability.h
└── UsbStream
├── ArduinoNotes.txt
├── Changelog.txt
├── CommercialLicense.txt
├── License.txt
├── Readme.txt
├── USB-ID-FAQ.txt
├── USB-IDs-for-free.txt
├── USBID-License.txt
├── UsbStream.cpp
├── UsbStream.h
├── asmcommon.inc
├── oddebug.c
├── oddebug.h
├── rx_buffer.h
├── usbconfig-prototype.h
├── usbconfig.h
├── usbdrv.c
├── usbdrv.h
├── usbdrvasm.S
├── usbdrvasm.asm
├── usbdrvasm12.inc
├── usbdrvasm128.inc
├── usbdrvasm15.inc
├── usbdrvasm16.inc
├── usbdrvasm165.inc
├── usbdrvasm18-crc.inc
├── usbdrvasm20.inc
└── usbportability.h
/.gitignore:
--------------------------------------------------------------------------------
1 | # Emacs backup files
2 | *~
3 |
4 | # OS X Finder droppings
5 | \.DS_Store
6 |
7 | # Python bytecode files
8 | *.pyc
9 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Arduino / AVRUSB integration
2 | ----------------------------
3 |
4 | * NOTE: This should now work with Arduino IDE 0018 onward but I've only
5 | tested with 0020.
6 |
7 | * Source now available as a Mercurial repository here:
8 |
9 |
10 |
11 | * Build the USB mini-shield documented here:
12 |
13 | NOTE: The code will NOW ONLY WORK WITH THE PCB DESIGN
14 | *NOT* THE PROTOBOARD DESIGN.
15 |
16 |
17 |
18 | * Copy 'UsbKeyboard' directory in the 'libraries' directory to your
19 | Arduino 'hardware/libraries' directory.
20 |
21 | * Open an example sketch from 'examples' directory.
22 |
23 | * See 'libraries/UsbKeyboard/ArduinoNotes.txt' for more.
24 |
25 | * I've had some USB ports on a MacBook Pro not work while others do.
26 |
27 | * Consider GPL 2.0 unless licensed otherwise.
28 |
29 | * Feedback to: follower@rancidbacon.com
30 |
31 |
32 | Version history:
33 |
34 | * 2008-08-12 -- "Muck and Crud" -- Initial alpha release
35 |
36 | * 2009-10-16 -- "Not a Patch On" -- Incorporate previous changes & pcb design
37 |
38 | * 2009-10-18 -- "All Your Upgrade" -- Upgrade base V-USB version to 2009-08-22
39 |
40 | * 2010-10-17 -- "Year, So What" -- Update to work with recent IDEs
41 |
--------------------------------------------------------------------------------
/TODO:
--------------------------------------------------------------------------------
1 |
2 | * Import UsbStreamDynamic etc from SVN repository.
3 |
4 | * Upgrade to latest V-USB version.
5 |
6 |
7 |
--------------------------------------------------------------------------------
/examples/UsbDeviceDemo1-python/usb_device_demo1.py:
--------------------------------------------------------------------------------
1 | #/usr/bin/python
2 |
3 | #
4 | # Written for PyUSB 1.0 (w/libusb 1.0.3)
5 | #
6 | # Includes functionality to retrieve string descriptors
7 | #
8 | # Author: follower@rancidbacon.com
9 | #
10 | # Version: 20091020
11 | #
12 |
13 | import usb # 1.0 not 0.4
14 |
15 |
16 | def getStringDescriptor(device, index):
17 | """
18 | """
19 | response = device.ctrl_transfer(usb.util.ENDPOINT_IN,
20 | usb.legacy.REQ_GET_DESCRIPTOR,
21 | (usb.util.DESC_TYPE_STRING << 8) | index,
22 | 0, # language id
23 | 255) # length
24 |
25 | # TODO: Refer to 'libusb_get_string_descriptor_ascii' for error handling
26 |
27 | return response[2:].tostring().decode('utf-16')
28 |
29 |
30 |
31 | if __name__ == "__main__":
32 |
33 | device = usb.core.find(idVendor=0x16c0, idProduct=0x05df)
34 |
35 | if not device:
36 | raise Exception("Device not found")
37 |
38 | print "0x%04x 0x%04x %s %s" % (device.idVendor, device.idProduct,
39 | getStringDescriptor(device, device.iProduct),
40 | getStringDescriptor(device, device.iManufacturer))
41 |
42 | # TODO: Tidy this all up:
43 |
44 | request_type = usb.util.build_request_type(usb.util.CTRL_IN,
45 | usb.util.CTRL_TYPE_CLASS,
46 | usb.util.CTRL_RECIPIENT_DEVICE)
47 |
48 | USBRQ_HID_GET_REPORT = 0x01
49 | USBRQ_HID_SET_REPORT = 0x09
50 | USB_HID_REPORT_TYPE_FEATURE = 0x03
51 |
52 | response = device.ctrl_transfer(request_type,
53 | USBRQ_HID_GET_REPORT,
54 | (USB_HID_REPORT_TYPE_FEATURE << 8) | 0,
55 | 0, # ignored
56 | 128) # length
57 |
58 | for byte in response:
59 | print "0x%02x" % byte,
60 |
61 | print
62 |
63 | response[0] = not response [0]
64 |
65 | print
66 |
67 | request_type = usb.util.build_request_type(usb.util.CTRL_OUT,
68 | usb.util.CTRL_TYPE_CLASS,
69 | usb.util.CTRL_RECIPIENT_DEVICE)
70 |
71 | bytes_sent = device.ctrl_transfer(request_type,
72 | USBRQ_HID_SET_REPORT,
73 | (USB_HID_REPORT_TYPE_FEATURE << 8) | 0,
74 | 0, # ignored (report id?)
75 | response)
76 |
77 | print
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/examples/UsbDeviceDemo1/UsbDeviceDemo1.pde:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | byte value = 0;
5 |
6 | void setup() {
7 | UsbDevice.begin();
8 | }
9 |
10 | void loop() {
11 | UsbDevice.refresh();
12 |
13 | value = EEPROM.read(0);
14 |
15 | if (value == 0) {
16 | digitalWrite(13, LOW);
17 | } else {
18 | digitalWrite(13, HIGH);
19 | }
20 | }
21 |
22 |
23 |
--------------------------------------------------------------------------------
/examples/UsbStreamDemo1-python/usb_stream_demo1.py:
--------------------------------------------------------------------------------
1 | #/usr/bin/python
2 |
3 | #
4 | # Written for PyUSB 1.0 (w/libusb 1.0.3)
5 | #
6 | # Includes functionality to retrieve string descriptors
7 | #
8 | # Author: follower@rancidbacon.com
9 | #
10 | # Version: 20091021
11 | #
12 |
13 | #
14 | # Assumes 'UsbStreamDemo1.pde' is loaded on Arduino and
15 | # LEDs are present on pins 11, 12 and 13.
16 | #
17 |
18 | import usb # 1.0 not 0.4
19 |
20 | import sys
21 | sys.path.append("..")
22 |
23 | from arduino.usbdevice import ArduinoUsbDevice
24 |
25 |
26 | if __name__ == "__main__":
27 |
28 | theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)
29 |
30 | print "Found: 0x%04x 0x%04x %s %s" % (theDevice.idVendor,
31 | theDevice.idProduct,
32 | theDevice.productName,
33 | theDevice.manufacturer)
34 |
35 |
36 | try:
37 | print "Read: 0x%02x" % theDevice.read()
38 | except:
39 | # TODO: Check for exception properly
40 | print "No data read."
41 |
42 |
43 | import sys
44 | import time
45 | import random
46 |
47 | if sys.argv[1:]:
48 | sequence = sys.argv[1:]
49 | else:
50 | sequence = [11,12,13]* 20
51 | random.shuffle(sequence)
52 |
53 | print "Look over there, flashing lights!"
54 |
55 | for pin in sequence:
56 | pin = int(pin)
57 |
58 | theDevice.write(pin)
59 |
60 | if pin != theDevice.read():
61 | print "Pin response didn't match."
62 |
63 | time.sleep(0.2)
64 |
65 | print
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/examples/UsbStreamDemo1/UsbStreamDemo1.pde:
--------------------------------------------------------------------------------
1 | #include
2 | void setup() {
3 | UsbStream.begin();
4 |
5 | UsbStream.write(0xff);
6 | }
7 |
8 | int pins[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
9 |
10 | void loop() {
11 | UsbStream.refresh();
12 |
13 | if (UsbStream.available() > 0) {
14 | int pin = UsbStream.read();
15 | pins[pin] = !pins[pin];
16 | digitalWrite(pin, pins[pin]);
17 | UsbStream.write(pin);
18 | }
19 | }
20 |
21 |
22 |
--------------------------------------------------------------------------------
/examples/UsbStreamDemo2-python/crypty.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | import sys
4 | import random
5 |
6 | def encrypty_(byte):
7 | """
8 | """
9 | hn = byte & 0xf0
10 | ln = byte & 0x0f
11 |
12 | hr = random.randint(0,15)
13 | lr = random.randint(0,15)
14 |
15 | high = (hn ^ (hr << 4)) | hr
16 | low = (ln ^ lr) | (lr << 4)
17 |
18 | return (high, low)
19 |
20 |
21 | def decrypty_(bytes):
22 | """
23 | """
24 | high = bytes[0]
25 | low = bytes[1]
26 |
27 | hr = high &0x0f
28 | hen = high &0xf0
29 | hn = hen ^ (hr << 4)
30 |
31 | lr = (low & 0xf0) >> 4
32 | len_ = low & 0x0f
33 | ln = len_ ^ lr
34 |
35 | byte = hn | ln
36 |
37 | return byte
38 |
39 |
40 |
41 | if __name__ == "__main__":
42 |
43 | if len(sys.argv) > 1:
44 | plain = sys.argv[1]
45 | else:
46 | plain = "'oinkhello'[4:]+', '+'worldgone'[:5]"
47 |
48 | result = []
49 |
50 | for char in plain:
51 | result.extend(encrypty_(ord(char)))
52 |
53 | e = "".join(["%02x" %i for i in result])
54 |
55 | print e
56 |
57 |
58 | bytes = [int(i + j, 16) for i,j in zip(e[::2], e[1::2])]
59 | un = "".join([chr(decrypty_((byte1, byte2)))
60 | for byte1, byte2 in zip(bytes[::2], bytes[1::2])])
61 |
62 | if eval(un) != eval(plain):
63 | print "Something didn't work."
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/examples/UsbStreamDemo2-python/usb_stream_demo2.py:
--------------------------------------------------------------------------------
1 | #/usr/bin/python
2 |
3 | #
4 | # Written for PyUSB 1.0 (w/libusb 1.0.3)
5 | #
6 | # Includes functionality to retrieve string descriptors
7 | #
8 | # Author: follower@rancidbacon.com
9 | #
10 | # Version: 20091021
11 | #
12 |
13 | #
14 | # Assumes 'UsbStreamDemo1.pde' is loaded on Arduino and
15 | # LEDs are present on pins 11, 12 and 13.
16 | #
17 |
18 | import usb # 1.0 not 0.4
19 |
20 | import sys
21 | sys.path.append("..")
22 |
23 | from arduino.usbdevice import ArduinoUsbDevice
24 |
25 |
26 | def decrypty_(byte1, byte2):
27 | """
28 | """
29 | theDevice.write(byte1)
30 | theDevice.write(byte2)
31 | return chr(theDevice.read())
32 |
33 |
34 | if __name__ == "__main__":
35 |
36 | if len(sys.argv) > 1:
37 | source = sys.argv[1]
38 | else:
39 | source = "13e971c3bd7ef968ac92174cbd63ca1ddb849f1e3161beb0a926b8e4af1c1338cecb02f34622a89e137c468f9e7060c33402ac3f8e044216bd96aca4062702f89cc7216ccfc9afb6"
40 |
41 |
42 | theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)
43 |
44 | print "Found: 0x%04x 0x%04x %s %s" % (theDevice.idVendor,
45 | theDevice.idProduct,
46 | theDevice.productName,
47 | theDevice.manufacturer)
48 |
49 | bytes = [int(i + j, 16) for i,j in zip(source[::2], source[1::2])]
50 | un = "".join([decrypty_(byte1, byte2)
51 | for byte1, byte2 in zip(bytes[::2], bytes[1::2])])
52 |
53 | print eval(un)
54 |
55 | raise SystemExit
56 |
57 |
58 | try:
59 | print "Read: 0x%02x" % theDevice.read()
60 | except:
61 | # TODO: Check for exception properly
62 | print "No data read."
63 |
64 |
65 | import sys
66 | import time
67 | import random
68 |
69 | if sys.argv[1:]:
70 | sequence = sys.argv[1:]
71 | else:
72 | sequence = [11,12,13]* 20
73 | random.shuffle(sequence)
74 |
75 | print "Look over there, flashing lights!"
76 |
77 | for pin in sequence:
78 | pin = int(pin)
79 |
80 | theDevice.write(pin)
81 |
82 | if pin != theDevice.read():
83 | print "Pin response didn't match."
84 |
85 | time.sleep(0.2)
86 |
87 | print
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/examples/UsbStreamDemo2/UsbStreamDemo2.pde:
--------------------------------------------------------------------------------
1 | #include
2 | void setup() {
3 | UsbStream.begin();
4 | }
5 |
6 | byte bytes[2];
7 | int offset = 0;
8 |
9 | byte decrypt_(byte *bytes) {
10 | byte high = bytes[0];
11 | byte low = bytes[1];
12 |
13 | byte hr = high &0x0f;
14 | byte hen = high &0xf0;
15 | byte hn = hen ^ (hr << 4);
16 |
17 | byte lr = (low & 0xf0) >> 4;
18 | byte len_ = low & 0x0f;
19 | byte ln = len_ ^ lr;
20 |
21 | byte result = hn | ln;
22 |
23 | return result;
24 | }
25 |
26 | void loop() {
27 | UsbStream.refresh();
28 |
29 | if (UsbStream.available() > 0) {
30 | bytes[offset] = UsbStream.read();
31 | if (offset == 1) {
32 | UsbStream.write(decrypt_(bytes));
33 | offset = 0;
34 | } else {
35 | offset++;
36 | }
37 | }
38 | }
39 |
40 |
41 |
--------------------------------------------------------------------------------
/examples/arduino/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gloob/vusb-for-arduino/5e3777a3c3944b7cf7e64f2fddd574e4395e8e02/examples/arduino/__init__.py
--------------------------------------------------------------------------------
/examples/arduino/usbdevice.py:
--------------------------------------------------------------------------------
1 | #/usr/bin/python
2 |
3 | #
4 | # Written for PyUSB 1.0 (w/libusb 1.0.3)
5 | #
6 | # Includes functionality to retrieve string descriptors
7 | #
8 | # Author: follower@rancidbacon.com
9 | #
10 | # Version: 20091022
11 | #
12 |
13 | import usb # 1.0 not 0.4
14 |
15 |
16 | def getStringDescriptor(device, index):
17 | """
18 | """
19 | response = device.ctrl_transfer(usb.util.ENDPOINT_IN,
20 | usb.legacy.REQ_GET_DESCRIPTOR,
21 | (usb.util.DESC_TYPE_STRING << 8) | index,
22 | 0, # language id
23 | 255) # length
24 |
25 | # TODO: Refer to 'libusb_get_string_descriptor_ascii' for error handling
26 |
27 | return response[2:].tostring().decode('utf-16')
28 |
29 |
30 | REQUEST_TYPE_SEND = usb.util.build_request_type(usb.util.CTRL_OUT,
31 | usb.util.CTRL_TYPE_CLASS,
32 | usb.util.CTRL_RECIPIENT_DEVICE)
33 |
34 | REQUEST_TYPE_RECEIVE = usb.util.build_request_type(usb.util.CTRL_IN,
35 | usb.util.CTRL_TYPE_CLASS,
36 | usb.util.CTRL_RECIPIENT_DEVICE)
37 |
38 | USBRQ_HID_GET_REPORT = 0x01
39 | USBRQ_HID_SET_REPORT = 0x09
40 | USB_HID_REPORT_TYPE_FEATURE = 0x03
41 |
42 |
43 | class ArduinoUsbDevice(object):
44 | """
45 | """
46 |
47 | def __init__(self, idVendor, idProduct):
48 | """
49 | """
50 | self.idVendor = idVendor
51 | self.idProduct = idProduct
52 |
53 | # TODO: Make more compliant by checking serial number also.
54 | self.device = usb.core.find(idVendor=self.idVendor,
55 | idProduct=self.idProduct)
56 |
57 | if not self.device:
58 | raise Exception("Device not found")
59 |
60 |
61 | def write(self, byte):
62 | """
63 | """
64 | # TODO: Return bytes written?
65 | self._transfer(REQUEST_TYPE_SEND, USBRQ_HID_SET_REPORT,
66 | byte,
67 | []) # ignored
68 |
69 |
70 | def read(self):
71 | """
72 | """
73 | response = self._transfer(REQUEST_TYPE_RECEIVE, USBRQ_HID_GET_REPORT,
74 | 0, # ignored
75 | 1) # length
76 |
77 | if not response:
78 | raise Exception("No Data")
79 |
80 | return response[0]
81 |
82 |
83 | def _transfer(self, request_type, request, index, value):
84 | """
85 | """
86 | return self.device.ctrl_transfer(request_type, request,
87 | (USB_HID_REPORT_TYPE_FEATURE << 8) | 0,
88 | index,
89 | value)
90 |
91 |
92 | @property
93 | def productName(self):
94 | """
95 | """
96 | return getStringDescriptor(self.device, self.device.iProduct)
97 |
98 |
99 | @property
100 | def manufacturer(self):
101 | """
102 | """
103 | return getStringDescriptor(self.device, self.device.iManufacturer)
104 |
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/libraries/UsbDevice/ArduinoNotes.txt:
--------------------------------------------------------------------------------
1 | Notes On Integrating AVRUSB with Arduino
2 | ========================================
3 |
4 | * Note the license(s) under which AVRUSB is distributed.
5 |
6 | * See also: http://code.rancidbacon.com/ProjectLogArduinoUSB
7 |
8 | * Note: The pins we use on the PCB (not protoboard) hardware shield are:
9 |
10 | INT0 == PD2 == IC Pin 4 == Arduino Digital Pin 2 == D+
11 |
12 | ---- == PD4 == -------- == Arduino Digital Pin 4 == D-
13 |
14 | ---- == PD5 == -------- == Arduino Digital Pin 5 == pull-up
15 |
16 | (DONE: Change to not use PD3 so INT1 is left free?)
17 |
18 | * In order to compile a valid 'usbconfig.h' file must exit. The content of this
19 | file will vary depending on whether the device is a generic USB device,
20 | generic HID device or specific class of HID device for example.
21 |
22 | The file 'usbconfig-prototype.h' can be used as a starting point, however
23 | it might be easier to use the 'usbconfig.h' from one of the example projects.
24 |
25 | TODO: Specify the settings that need to be changed to match the shield
26 | design we use.
27 |
28 | * (NOTE: Initial 'usbconfig.h' used will be based on the file from
29 | 'HIDKeys.2007-03-29'.) (Note: Have now upgraded to V-USB 2009-08-22.)
30 |
31 | * At present the IDE won't compile our library so it needs to be pre-compiled
32 | with:
33 |
34 | avr-g++ -Wall -Os -I. -DF_CPU=16000000 -mmcu=atmega168 -c usbdrvasm.S -c usbdrv.c
35 |
--------------------------------------------------------------------------------
/libraries/UsbDevice/CommercialLicense.txt:
--------------------------------------------------------------------------------
1 | V-USB Driver Software License Agreement
2 | Version 2009-08-03
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 (Clay Logic, www.claylogic.com). Both owners of the Vendor IDs
41 | have obtained these IDs from the USB Implementers Forum, Inc.
42 | (www.usb.org). OBJECTIVE DEVELOPMENT disclaims all liability which might
43 | arise from the assignment of USB IDs.
44 |
45 | 2.5 USB Certification. Although not part of this agreement, we want to make
46 | it clear that you cannot become USB certified when you use V-USB or a USB
47 | Product ID assigned by OBJECTIVE DEVELOPMENT. AVR microcontrollers don't
48 | meet the electrical specifications required by the USB specification and
49 | the USB Implementers Forum certifies only members who bought a Vendor ID of
50 | their own.
51 |
52 |
53 | 3 LICENSE RESTRICTIONS
54 |
55 | 3.1 Number of Units. Only one of the following three definitions is
56 | applicable. Which one is determined by the amount you pay to OBJECTIVE
57 | DEVELOPMENT, see section 4 ("Payment") below.
58 |
59 | Hobby License: You may use V-USB according to section 2 above in no more
60 | than 5 hardware units. These units must not be sold for profit.
61 |
62 | Entry Level License: You may use V-USB according to section 2 above in no
63 | more than 150 hardware units.
64 |
65 | Professional License: You may use V-USB according to section 2 above in
66 | any number of hardware units, except for large scale production ("unlimited
67 | fair use"). Quantities below 10,000 units are not considered large scale
68 | production. If your reach quantities which are obviously large scale
69 | production, you must pay a license fee of 0.10 EUR per unit for all units
70 | above 10,000.
71 |
72 | 3.2 Rental. You may not rent, lease, or lend V-USB or otherwise encumber
73 | any copy of V-USB, or any of the rights granted herein.
74 |
75 | 3.3 Transfer. You may not transfer your rights under this Agreement to
76 | another party without OBJECTIVE DEVELOPMENT's prior written consent. If
77 | such consent is obtained, you may permanently transfer this License to
78 | another party. The recipient of such transfer must agree to all terms and
79 | conditions of this Agreement.
80 |
81 | 3.4 Reservation of Rights. OBJECTIVE DEVELOPMENT retains all rights not
82 | expressly granted.
83 |
84 | 3.5 Non-Exclusive Rights. Your license rights under this Agreement are
85 | non-exclusive.
86 |
87 | 3.6 Third Party Rights. This Agreement cannot grant you rights controlled
88 | by third parties. In particular, you are not allowed to use the USB logo or
89 | other trademarks owned by the USB Implementers Forum, Inc. without their
90 | consent. Since such consent depends on USB certification, it should be
91 | noted that V-USB will not pass certification because it does not
92 | implement checksum verification and the microcontroller ports do not meet
93 | the electrical specifications.
94 |
95 |
96 | 4 PAYMENT
97 |
98 | The payment amount depends on the variation of this agreement (according to
99 | section 3.1) into which you want to enter. Concrete prices are listed on
100 | OBJECTIVE DEVELOPMENT's web site, usually at
101 | http://www.obdev.at/vusb/license.html. You agree to pay the amount listed
102 | there to OBJECTIVE DEVELOPMENT or OBJECTIVE DEVELOPMENT's payment processor
103 | or reseller.
104 |
105 |
106 | 5 COPYRIGHT AND OWNERSHIP
107 |
108 | V-USB is protected by copyright laws and international copyright
109 | treaties, as well as other intellectual property laws and treaties. V-USB
110 | is licensed, not sold.
111 |
112 |
113 | 6 TERM AND TERMINATION
114 |
115 | 6.1 Term. This Agreement shall continue indefinitely. However, OBJECTIVE
116 | DEVELOPMENT may terminate this Agreement and revoke the granted license and
117 | USB-IDs if you fail to comply with any of its terms and conditions.
118 |
119 | 6.2 Survival of Terms. All provisions regarding secrecy, confidentiality
120 | and limitation of liability shall survive termination of this agreement.
121 |
122 |
123 | 7 DISCLAIMER OF WARRANTY AND LIABILITY
124 |
125 | LIMITED WARRANTY. V-USB IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
126 | KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, OBJECTIVE
127 | DEVELOPMENT AND ITS SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES, EITHER
128 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
129 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND
130 | NON-INFRINGEMENT, WITH REGARD TO V-USB, AND THE PROVISION OF OR FAILURE
131 | TO PROVIDE SUPPORT SERVICES. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL
132 | RIGHTS. YOU MAY HAVE OTHERS, WHICH VARY FROM STATE/JURISDICTION TO
133 | STATE/JURISDICTION.
134 |
135 | LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
136 | IN NO EVENT SHALL OBJECTIVE DEVELOPMENT OR ITS SUPPLIERS BE LIABLE FOR ANY
137 | SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER
138 | (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
139 | BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY
140 | LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE V-USB OR THE
141 | PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF OBJECTIVE
142 | DEVELOPMENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY
143 | CASE, OBJECTIVE DEVELOPMENT'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS
144 | AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR V-USB.
145 |
146 |
147 | 8 MISCELLANEOUS TERMS
148 |
149 | 8.1 Marketing. OBJECTIVE DEVELOPMENT has the right to mention for marketing
150 | purposes that you entered into this agreement.
151 |
152 | 8.2 Entire Agreement. This document represents the entire agreement between
153 | OBJECTIVE DEVELOPMENT and you. It may only be modified in writing signed by
154 | an authorized representative of both, OBJECTIVE DEVELOPMENT and you.
155 |
156 | 8.3 Severability. In case a provision of these terms and conditions should
157 | be or become partly or entirely invalid, ineffective, or not executable,
158 | the validity of all other provisions shall not be affected.
159 |
160 | 8.4 Applicable Law. This agreement is governed by the laws of the Republic
161 | of Austria.
162 |
163 | 8.5 Responsible Courts. The responsible courts in Vienna/Austria will have
164 | exclusive jurisdiction regarding all disputes in connection with this
165 | agreement.
166 |
167 |
--------------------------------------------------------------------------------
/libraries/UsbDevice/Readme.txt:
--------------------------------------------------------------------------------
1 | This is the Readme file to Objective Development's firmware-only USB driver
2 | for Atmel AVR microcontrollers. For more information please visit
3 | http://www.obdev.at/vusb/
4 |
5 | This directory contains the USB firmware only. Copy it as-is to your own
6 | project and add all .c and .S files to your project (these files are marked
7 | with an asterisk in the list below). Then copy usbconfig-prototype.h as
8 | usbconfig.h to your project and edit it according to your configuration.
9 |
10 |
11 | TECHNICAL DOCUMENTATION
12 | =======================
13 | The technical documentation (API) for the firmware driver is contained in the
14 | file "usbdrv.h". Please read all of it carefully! Configuration options are
15 | documented in "usbconfig-prototype.h".
16 |
17 | The driver consists of the following files:
18 | Readme.txt ............. The file you are currently reading.
19 | Changelog.txt .......... Release notes for all versions of the driver.
20 | usbdrv.h ............... Driver interface definitions and technical docs.
21 | * usbdrv.c ............... High level language part of the driver. Link this
22 | module to your code!
23 | * usbdrvasm.S ............ Assembler part of the driver. This module is mostly
24 | a stub and includes one of the usbdrvasm*.S files
25 | depending on processor clock. Link this module to
26 | your code!
27 | usbdrvasm*.inc ......... Assembler routines for particular clock frequencies.
28 | Included by usbdrvasm.S, don't link it directly!
29 | asmcommon.inc .......... Common assembler routines. Included by
30 | usbdrvasm*.inc, don't link it directly!
31 | usbconfig-prototype.h .. Prototype for your own usbdrv.h file.
32 | * oddebug.c .............. Debug functions. Only used when DEBUG_LEVEL is
33 | defined to a value greater than 0. Link this module
34 | to your code!
35 | oddebug.h .............. Interface definitions of the debug module.
36 | usbportability.h ....... Header with compiler-dependent stuff.
37 | usbdrvasm.asm .......... Compatibility stub for IAR-C-compiler. Use this
38 | module instead of usbdrvasm.S when you assembler
39 | with IAR's tools.
40 | License.txt ............ Open Source license for this driver.
41 | CommercialLicense.txt .. Optional commercial license for this driver.
42 | USB-ID-FAQ.txt ......... General infos about USB Product- and Vendor-IDs.
43 | USB-IDs-for-free.txt ... List and terms of use for free shared PIDs.
44 |
45 | (*) ... These files should be linked to your project.
46 |
47 |
48 | CPU CORE CLOCK FREQUENCY
49 | ========================
50 | We supply assembler modules for clock frequencies of 12 MHz, 12.8 MHz, 15 MHz,
51 | 16 MHz, 16.5 MHz 18 MHz and 20 MHz. Other clock rates are not supported. The
52 | actual clock rate must be configured in usbdrv.h unless you use the default
53 | 12 MHz.
54 |
55 | 12 MHz Clock
56 | This is the traditional clock rate of V-USB because it's the lowest clock
57 | rate where the timing constraints of the USB spec can be met.
58 |
59 | 15 MHz Clock
60 | Similar to 12 MHz, but some NOPs inserted. On the other hand, the higher clock
61 | rate allows for some loops which make the resulting code size somewhat smaller
62 | than the 12 MHz version.
63 |
64 | 16 MHz Clock
65 | This clock rate has been added for users of the Arduino board and other
66 | ready-made boards which come with a fixed 16 MHz crystal. It's also an option
67 | if you need the slightly higher clock rate for performance reasons. Since
68 | 16 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code
69 | is somewhat tricky and has to insert a leap cycle every third byte.
70 |
71 | 12.8 MHz and 16.5 MHz Clock
72 | The assembler modules for these clock rates differ from the other modules
73 | because they have been built for an RC oscillator with only 1% precision. The
74 | receiver code inserts leap cycles to compensate for clock deviations. 1% is
75 | also the precision which can be achieved by calibrating the internal RC
76 | oscillator of the AVR. Please note that only AVRs with internal 64 MHz PLL
77 | oscillator can reach 16.5 MHz with the RC oscillator. This includes the very
78 | popular ATTiny25, ATTiny45, ATTiny85 series as well as the ATTiny26. Almost
79 | all AVRs can reach 12.8 MHz, although this is outside the specified range.
80 |
81 | See the EasyLogger example at http://www.obdev.at/vusb/easylogger.html for
82 | code which calibrates the RC oscillator based on the USB frame clock.
83 |
84 | 18 MHz Clock
85 | This module is closer to the USB specification because it performs an on the
86 | fly CRC check for incoming packets. Packets with invalid checksum are
87 | discarded as required by the spec. If you also implement checks for data
88 | PID toggling on application level (see option USB_CFG_CHECK_DATA_TOGGLING
89 | in usbconfig.h for more info), this ensures data integrity. Due to the CRC
90 | tables and alignment requirements, this code is bigger than modules for other
91 | clock rates. To activate this module, you must define USB_CFG_CHECK_CRC to 1
92 | and USB_CFG_CLOCK_KHZ to 18000 in usbconfig.h.
93 |
94 | 20 MHz Clock
95 | This module is for people who won't do it with less than the maximum. Since
96 | 20 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code
97 | uses similar tricks as the 16 MHz module to insert leap cycles.
98 |
99 |
100 | USB IDENTIFIERS
101 | ===============
102 | Every USB device needs a vendor- and a product-identifier (VID and PID). VIDs
103 | are obtained from usb.org for a price of 1,500 USD. Once you have a VID, you
104 | can assign PIDs at will.
105 |
106 | Since an entry level cost of 1,500 USD is too high for most small companies
107 | and hobbyists, we provide some VID/PID pairs for free. See the file
108 | USB-IDs-for-free.txt for details.
109 |
110 | Objective Development also has some license offerings which include product
111 | IDs. See http://www.obdev.at/vusb/ for details.
112 |
113 |
114 | DEVELOPMENT SYSTEM
115 | ==================
116 | This driver has been developed and optimized for the GNU compiler version 3
117 | (gcc 3). It does work well with gcc 4, but with bigger code size. We recommend
118 | that you use the GNU compiler suite because it is freely available. V-USB
119 | has also been ported to the IAR compiler and assembler. It has been tested
120 | with IAR 4.10B/W32 and 4.12A/W32 on an ATmega8 with the "small" and "tiny"
121 | memory model. Not every release is tested with IAR CC and the driver may
122 | therefore fail to compile with IAR. Please note that gcc is more efficient for
123 | usbdrv.c because this module has been deliberately optimized for gcc.
124 |
125 |
126 | USING V-USB FOR FREE
127 | ====================
128 | The AVR firmware driver is published under the GNU General Public License
129 | Version 2 (GPL2) and the GNU General Public License Version 3 (GPL3). It is
130 | your choice whether you apply the terms of version 2 or version 3.
131 |
132 | If you decide for the free GPL2 or GPL3, we STRONGLY ENCOURAGE you to do the
133 | following things IN ADDITION to the obligations from the GPL:
134 |
135 | (1) Publish your entire project on a web site and drop us a note with the URL.
136 | Use the form at http://www.obdev.at/vusb/feedback.html for your submission.
137 | If you don't have a web site, you can publish the project in obdev's
138 | documentation wiki at
139 | http://www.obdev.at/goto.php?t=vusb-wiki&p=hosted-projects.
140 |
141 | (2) Adhere to minimum publication standards. Please include AT LEAST:
142 | - a circuit diagram in PDF, PNG or GIF format
143 | - full source code for the host software
144 | - a Readme.txt file in ASCII format which describes the purpose of the
145 | project and what can be found in which directories and which files
146 | - a reference to http://www.obdev.at/vusb/
147 |
148 | (3) If you improve the driver firmware itself, please give us a free license
149 | to your modifications for our commercial license offerings.
150 |
151 |
152 | COMMERCIAL LICENSES FOR V-USB
153 | =============================
154 | If you don't want to publish your source code under the terms of the GPL,
155 | you can simply pay money for V-USB. As an additional benefit you get
156 | USB PIDs for free, reserved exclusively to you. See the file
157 | "CommercialLicense.txt" for details.
158 |
159 |
--------------------------------------------------------------------------------
/libraries/UsbDevice/USB-ID-FAQ.txt:
--------------------------------------------------------------------------------
1 | Version 2009-08-22
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 (Clay Logic, www.claylogic.com). Both VID owners have received their
111 | Vendor-ID directly from usb.org.
112 |
113 |
114 | =========================================================================
115 | CAN I USE USB-IDs FROM OBJECTIVE DEVELOPMENT WITH OTHER DRIVERS/HARDWARE?
116 | =========================================================================
117 |
118 | The short answer is: Yes. All you get is a guarantee that the IDs are never
119 | assigned to anybody else. What more do you need?
120 |
121 |
122 | ============================
123 | WHAT ABOUT SHARED ID PAIRS?
124 | ============================
125 |
126 | Objective Development has reserved some PID/VID pairs for shared use. You
127 | have no guarantee of uniqueness for them, except that no USB compliant device
128 | uses them. In order to avoid technical problems, we must ensure that all
129 | devices with the same pair of IDs use the same driver on kernel level. For
130 | details, see the file USB-IDs-for-free.txt.
131 |
132 |
133 | ======================================================
134 | I HAVE HEARD THAT SUB-LICENSING OF USB-IDs IS ILLEGAL?
135 | ======================================================
136 |
137 | A 16 bit integer number cannot be protected by copyright laws. It is not
138 | sufficiently complex. And since none of the parties involved entered into the
139 | USB-IF Trademark License Agreement, we are not bound by this agreement. So
140 | there is no reason why it should be illegal to sub-license USB-IDs.
141 |
142 |
143 | =============================================
144 | WHO IS LIABLE IF THERE ARE INCOMPATIBILITIES?
145 | =============================================
146 |
147 | Objective Development disclaims all liabilities which might arise from the
148 | assignment of IDs. If you guarantee product features to your customers
149 | without proper disclaimer, YOU are liable for that.
150 |
--------------------------------------------------------------------------------
/libraries/UsbDevice/USB-IDs-for-free.txt:
--------------------------------------------------------------------------------
1 | Version 2009-08-22
2 |
3 | ===========================
4 | FREE USB-IDs FOR SHARED USE
5 | ===========================
6 |
7 | Objective Development has reserved a set of USB Product-IDs for use according
8 | to the guidelines outlined below. For more information about the concept of
9 | USB IDs please see the file USB-ID-FAQ.txt. Objective Development guarantees
10 | that the IDs listed below are not used by any USB compliant devices.
11 |
12 |
13 | ====================
14 | MECHANISM OF SHARING
15 | ====================
16 |
17 | From a technical point of view, two different devices can share the same USB
18 | Vendor- and Product-ID if they require the same driver on operating system
19 | level. We make use of this fact by assigning separate IDs for various device
20 | classes. On application layer, devices must be distinguished by their textual
21 | name or serial number. We offer separate sets of IDs for discrimination by
22 | textual name and for serial number.
23 |
24 | Examples for shared use of USB IDs are included with V-USB in the "examples"
25 | subdirectory.
26 |
27 |
28 | ======================================
29 | IDs FOR DISCRIMINATION BY TEXTUAL NAME
30 | ======================================
31 |
32 | If you use one of the IDs listed below, your device and host-side software
33 | must conform to these rules:
34 |
35 | (1) The USB device MUST provide a textual representation of the manufacturer
36 | and product identification. The manufacturer identification MUST be available
37 | at least in USB language 0x0409 (English/US).
38 |
39 | (2) The textual manufacturer identification MUST contain either an Internet
40 | domain name (e.g. "mycompany.com") registered and owned by you, or an e-mail
41 | address under your control (e.g. "myname@gmx.net"). You can embed the domain
42 | name or e-mail address in any string you like, e.g. "Objective Development
43 | http://www.obdev.at/vusb/".
44 |
45 | (3) You are responsible for retaining ownership of the domain or e-mail
46 | address for as long as any of your products are in use.
47 |
48 | (4) You may choose any string for the textual product identification, as long
49 | as this string is unique within the scope of your textual manufacturer
50 | identification.
51 |
52 | (5) Application side device look-up MUST be based on the textual manufacturer
53 | and product identification in addition to VID/PID matching. The driver
54 | matching MUST be a comparison of the entire strings, NOT a sub-string match.
55 |
56 | (6) For devices which implement a particular USB device class (e.g. HID), the
57 | operating system's default class driver MUST be used. If an operating system
58 | driver for Vendor Class devices is needed, this driver must be libusb or
59 | libusb-win32 (see http://libusb.org/ and
60 | http://libusb-win32.sourceforge.net/).
61 |
62 | Table if IDs for discrimination by textual name:
63 |
64 | PID dec (hex) | VID dec (hex) | Description of use
65 | ==============+===============+============================================
66 | 1500 (0x05dc) | 5824 (0x16c0) | For Vendor Class devices with libusb
67 | --------------+---------------+--------------------------------------------
68 | 1503 (0x05df) | 5824 (0x16c0) | For generic HID class devices (which are
69 | | | NOT mice, keyboards or joysticks)
70 | --------------+---------------+--------------------------------------------
71 | 1505 (0x05e1) | 5824 (0x16c0) | For CDC-ACM class devices (modems)
72 | --------------+---------------+--------------------------------------------
73 | 1508 (0x05e4) | 5824 (0x16c0) | For MIDI class devices
74 | --------------+---------------+--------------------------------------------
75 |
76 | Note that Windows caches the textual product- and vendor-description for
77 | mice, keyboards and joysticks. Name-bsed discrimination is therefore not
78 | recommended for these device classes.
79 |
80 |
81 | =======================================
82 | IDs FOR DISCRIMINATION BY SERIAL NUMBER
83 | =======================================
84 |
85 | If you use one of the IDs listed below, your device and host-side software
86 | must conform to these rules:
87 |
88 | (1) The USB device MUST provide a textual representation of the serial
89 | number. The serial number string MUST be available at least in USB language
90 | 0x0409 (English/US).
91 |
92 | (2) The serial number MUST start with either an Internet domain name (e.g.
93 | "mycompany.com") registered and owned by you, or an e-mail address under your
94 | control (e.g. "myname@gmx.net"), both terminated with a colon (":") character.
95 | You MAY append any string you like for further discrimination of your devices.
96 |
97 | (3) You are responsible for retaining ownership of the domain or e-mail
98 | address for as long as any of your products are in use.
99 |
100 | (5) Application side device look-up MUST be based on the serial number string
101 | in addition to VID/PID matching. The matching must start at the first
102 | character of the serial number string and include the colon character
103 | terminating your domain or e-mail address. It MAY stop anywhere after that.
104 |
105 | (6) For devices which implement a particular USB device class (e.g. HID), the
106 | operating system's default class driver MUST be used. If an operating system
107 | driver for Vendor Class devices is needed, this driver must be libusb or
108 | libusb-win32 (see http://libusb.org/ and
109 | http://libusb-win32.sourceforge.net/).
110 |
111 | Table if IDs for discrimination by serial number string:
112 |
113 | PID dec (hex) | VID dec (hex) | Description of use
114 | ===============+===============+===========================================
115 | 10200 (0x27d8) | 5824 (0x16c0) | For Vendor Class devices with libusb
116 | ---------------+---------------+-------------------------------------------
117 | 10201 (0x27d9) | 5824 (0x16c0) | For generic HID class devices (which are
118 | | | NOT mice, keyboards or joysticks)
119 | ---------------+---------------+-------------------------------------------
120 | 10202 (0x27da) | 5824 (0x16c0) | For USB Mice
121 | ---------------+---------------+-------------------------------------------
122 | 10203 (0x27db) | 5824 (0x16c0) | For USB Keyboards
123 | ---------------+---------------+-------------------------------------------
124 | 10204 (0x27db) | 5824 (0x16c0) | For USB Joysticks
125 | ---------------+---------------+-------------------------------------------
126 | 10205 (0x27dc) | 5824 (0x16c0) | For CDC-ACM class devices (modems)
127 | ---------------+---------------+-------------------------------------------
128 | 10206 (0x27dd) | 5824 (0x16c0) | For MIDI class devices
129 | ---------------+---------------+-------------------------------------------
130 |
131 |
132 | =================
133 | ORIGIN OF USB-IDs
134 | =================
135 |
136 | OBJECTIVE DEVELOPMENT Software GmbH has obtained all VID/PID pairs listed
137 | here from Wouter van Ooijen (see www.voti.nl) for exclusive disposition.
138 | Wouter van Ooijen has obtained the VID from the USB Implementers Forum, Inc.
139 | (see www.usb.org). The VID is registered for the company name "Van Ooijen
140 | Technische Informatica".
141 |
142 |
143 | ==========
144 | DISCLAIMER
145 | ==========
146 |
147 | OBJECTIVE DEVELOPMENT Software GmbH disclaims all liability for any
148 | problems which are caused by the shared use of these VID/PID pairs.
149 |
--------------------------------------------------------------------------------
/libraries/UsbDevice/USBID-License.txt:
--------------------------------------------------------------------------------
1 | Royalty-Free Non-Exclusive Use of USB Product-IDs
2 | =================================================
3 |
4 | Version 2009-04-13
5 |
6 | Strictly speaking, this is not a license. You can't give a license to use
7 | a simple number (such as e.g. 1500) for any purpose. This is a set of rules
8 | which should make it possible to build USB devices without the requirement
9 | for individual USB IDs. If you break one of the rules, you will run into
10 | technical problems sooner or later, but you don't risk legal trouble.
11 |
12 |
13 | OBJECTIVE DEVELOPMENT Software GmbH hereby grants you the non-exclusive
14 | right to use four USB.org vendor-ID (VID) / product-ID (PID) pairs with
15 | products based on Objective Development's firmware-only USB driver for
16 | Atmel AVR microcontrollers:
17 |
18 | * VID = 5824 (=0x16c0) / PID = 1500 (=0x5dc) for devices implementing no
19 | USB device class (vendor-class devices with USB class = 0xff). Devices
20 | using this pair will be referred to as "VENDOR CLASS" devices.
21 |
22 | * VID = 5824 (=0x16c0) / PID = 1503 (=0x5df) for HID class devices
23 | (excluding mice and keyboards). Devices using this pair will be referred
24 | to as "HID CLASS" devices.
25 |
26 | * VID = 5824 (=0x16c0) / PID = 1505 (=0x5e1) for CDC class modem devices
27 | Devices using this pair will be referred to as "CDC-ACM CLASS" devices.
28 |
29 | * VID = 5824 (=0x16c0) / PID = 1508 (=0x5e4) for MIDI class devices
30 | Devices using this pair will be referred to as "MIDI CLASS" devices.
31 |
32 | Since the granted right is non-exclusive, the same VID/PID pairs may be
33 | used by many companies and individuals for different products. To avoid
34 | conflicts, your device and host driver software MUST adhere to the rules
35 | outlined below.
36 |
37 | OBJECTIVE DEVELOPMENT Software GmbH has obtained these VID/PID pairs from
38 | Wouter van Ooijen (see www.voti.nl) for exclusive disposition. Wouter van
39 | Ooijen has obtained the VID from the USB Implementers Forum, Inc.
40 | (see www.usb.org). The VID is registered for the company name
41 | "Van Ooijen Technische Informatica".
42 |
43 |
44 | RULES AND RESTRICTIONS
45 | ======================
46 |
47 | (1) The USB device MUST provide a textual representation of the
48 | manufacturer and product identification. The manufacturer identification
49 | MUST be available at least in USB language 0x0409 (English/US).
50 |
51 | (2) The textual manufacturer identification MUST contain either an Internet
52 | domain name (e.g. "mycompany.com") registered and owned by you, or an
53 | e-mail address under your control (e.g. "myname@gmx.net"). You can embed
54 | the domain name or e-mail address in any string you like, e.g. "Objective
55 | Development http://www.obdev.at/vusb/".
56 |
57 | (3) You are responsible for retaining ownership of the domain or e-mail
58 | address for as long as any of your products are in use.
59 |
60 | (4) You may choose any string for the textual product identification, as
61 | long as this string is unique within the scope of your textual manufacturer
62 | identification.
63 |
64 | (5) Matching of device-specific drivers MUST be based on the textual
65 | manufacturer and product identification in addition to the usual VID/PID
66 | matching. This means that operating system features which are based on
67 | VID/PID matching only (e.g. Windows kernel level drivers, automatic actions
68 | when the device is plugged in etc) MUST NOT be used. The driver matching
69 | MUST be a comparison of the entire strings, NOT a sub-string match. For
70 | CDC-ACM CLASS and MIDI CLASS devices, a generic class driver should be used
71 | and the matching is based on the USB device class.
72 |
73 | (6) The extent to which VID/PID matching is allowed for non device-specific
74 | drivers or features depends on the operating system and particular VID/PID
75 | pair used:
76 |
77 | * Mac OS X, Linux, FreeBSD and other Unixes: No VID/PID matching is
78 | required and hence no VID/PID-only matching is allowed at all.
79 |
80 | * Windows: The operating system performs VID/PID matching for the kernel
81 | level driver. You are REQUIRED to use libusb-win32 (see
82 | http://libusb-win32.sourceforge.net/) as the kernel level driver for
83 | VENDOR CLASS devices. HID CLASS devices all use the generic HID class
84 | driver shipped with Windows, except mice and keyboards. You therefore
85 | MUST NOT use any of the shared VID/PID pairs for mice or keyboards.
86 | CDC-ACM CLASS devices require a ".inf" file which matches on the VID/PID
87 | pair. This ".inf" file MUST load the "usbser" driver to configure the
88 | device as modem (COM-port).
89 |
90 | (7) OBJECTIVE DEVELOPMENT Software GmbH disclaims all liability for any
91 | problems which are caused by the shared use of these VID/PID pairs. You
92 | have been warned that the sharing of VID/PID pairs may cause problems. If
93 | you want to avoid them, get your own VID/PID pair for exclusive use.
94 |
95 |
96 | HOW TO IMPLEMENT THESE RULES
97 | ============================
98 |
99 | The following rules are for VENDOR CLASS and HID CLASS devices. CDC-ACM
100 | CLASS and MIDI CLASS devices use the operating system's class driver and
101 | don't need a custom driver.
102 |
103 | The host driver MUST iterate over all devices with the given VID/PID
104 | numbers in their device descriptors and query the string representation for
105 | the manufacturer name in USB language 0x0409 (English/US). It MUST compare
106 | the ENTIRE string with your textual manufacturer identification chosen in
107 | (2) above. A substring search for your domain or e-mail address is NOT
108 | acceptable. The driver MUST NOT touch the device (other than querying the
109 | descriptors) unless the strings match.
110 |
111 | For all USB devices with matching VID/PID and textual manufacturer
112 | identification, the host driver must query the textual product
113 | identification and string-compare it with the name of the product it can
114 | control. It may only initialize the device if the product matches exactly.
115 |
116 | Objective Development provides examples for these matching rules with the
117 | "PowerSwitch" project (using libusb) and with the "Automator" project
118 | (using Windows calls on Windows and libusb on Unix).
119 |
120 |
121 | Technical Notes:
122 | ================
123 |
124 | Sharing the same VID/PID pair among devices is possible as long as ALL
125 | drivers which match the VID/PID also perform matching on the textual
126 | identification strings. This is easy on all operating systems except
127 | Windows, since Windows establishes a static connection between the VID/PID
128 | pair and a kernel level driver. All devices with the same VID/PID pair must
129 | therefore use THE SAME kernel level driver.
130 |
131 | We therefore demand that you use libusb-win32 for VENDOR CLASS devices.
132 | This is a generic kernel level driver which allows all types of USB access
133 | for user space applications. This is only a partial solution of the
134 | problem, though, because different device drivers may come with different
135 | versions of libusb-win32 and they may not work with the libusb version of
136 | the respective other driver. You are therefore encouraged to test your
137 | driver against a broad range of libusb-win32 versions. Do not use new
138 | features in new versions, or check for their existence before you use them.
139 | When a new libusb-win32 becomes available, make sure that your driver is
140 | compatible with it.
141 |
142 | For HID CLASS devices it is necessary that all those devices bind to the
143 | same kernel driver: Microsoft's generic USB HID driver. This is true for
144 | all HID devices except those with a specialized driver. Currently, the only
145 | HIDs with specialized drivers are mice and keyboards. You therefore MUST
146 | NOT use a shared VID/PID with mouse and keyboard devices.
147 |
148 | Sharing the same VID/PID among different products is unusual and probably
149 | violates the USB specification. If you do it, you do it at your own risk.
150 |
151 | To avoid possible incompatibilities, we highly recommend that you get your
152 | own VID/PID pair if you intend to sell your product. Objective
153 | Development's commercial licenses for V-USB include a PID for
154 | unrestricted exclusive use.
155 |
--------------------------------------------------------------------------------
/libraries/UsbDevice/UsbDevice.c:
--------------------------------------------------------------------------------
1 | /* Name: main.c
2 | * Project: hid-data, example how to use HID for data transfer
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2008-04-11
5 | * Tabsize: 4
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | * This Revision: $Id: main.c 692 2008-11-07 15:07:40Z cs $
9 | */
10 |
11 | /*
12 | This example should run on most AVRs with only little changes. No special
13 | hardware resources except INT0 are used. You may have to change usbconfig.h for
14 | different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or
15 | at least be connected to INT0 as well.
16 | */
17 |
18 | #include
19 | #include
20 | #include /* for sei() */
21 | #include /* for _delay_ms() */
22 | #include
23 |
24 | #include /* required by usbdrv.h */
25 | #include "usbdrv.h"
26 | #include "oddebug.h" /* This is also an example for using debug macros */
27 |
28 | /* ------------------------------------------------------------------------- */
29 | /* ----------------------------- USB interface ----------------------------- */
30 | /* ------------------------------------------------------------------------- */
31 |
32 | PROGMEM char usbHidReportDescriptor[22] = { /* USB report descriptor */
33 | 0x06, 0x00, 0xff, // USAGE_PAGE (Generic Desktop)
34 | 0x09, 0x01, // USAGE (Vendor Usage 1)
35 | 0xa1, 0x01, // COLLECTION (Application)
36 | 0x15, 0x00, // LOGICAL_MINIMUM (0)
37 | 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
38 | 0x75, 0x08, // REPORT_SIZE (8)
39 | 0x95, 0x80, // REPORT_COUNT (128)
40 | 0x09, 0x00, // USAGE (Undefined)
41 | 0xb2, 0x02, 0x01, // FEATURE (Data,Var,Abs,Buf)
42 | 0xc0 // END_COLLECTION
43 | };
44 | /* Since we define only one feature report, we don't use report-IDs (which
45 | * would be the first byte of the report). The entire report consists of 128
46 | * opaque data bytes.
47 | */
48 |
49 | /* The following variables store the status of the current data transfer */
50 | static uchar currentAddress;
51 | static uchar bytesRemaining;
52 |
53 | /* ------------------------------------------------------------------------- */
54 |
55 | /* usbFunctionRead() is called when the host requests a chunk of data from
56 | * the device. For more information see the documentation in usbdrv/usbdrv.h.
57 | */
58 | #ifdef __cplusplus
59 | extern "C"{
60 | #endif
61 | uchar usbFunctionRead(uchar *data, uchar len)
62 | {
63 | if(len > bytesRemaining)
64 | len = bytesRemaining;
65 | eeprom_read_block(data, (uchar *)0 + currentAddress, len);
66 | currentAddress += len;
67 | bytesRemaining -= len;
68 | return len;
69 | }
70 |
71 | /* usbFunctionWrite() is called when the host sends a chunk of data to the
72 | * device. For more information see the documentation in usbdrv/usbdrv.h.
73 | */
74 | uchar usbFunctionWrite(uchar *data, uchar len)
75 | {
76 | if(bytesRemaining == 0)
77 | return 1; /* end of transfer */
78 | if(len > bytesRemaining)
79 | len = bytesRemaining;
80 | eeprom_write_block(data, (uchar *)0 + currentAddress, len);
81 | currentAddress += len;
82 | bytesRemaining -= len;
83 | return bytesRemaining == 0; /* return 1 if this was the last chunk */
84 | }
85 |
86 | /* ------------------------------------------------------------------------- */
87 |
88 |
89 | usbMsgLen_t usbFunctionSetup(uchar data[8])
90 | {
91 | usbRequest_t *rq = (usbRequest_t*)((void *)data);
92 |
93 | if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* HID class request */
94 | if(rq->bRequest == USBRQ_HID_GET_REPORT){ /* wValue: ReportType (highbyte), ReportID (lowbyte) */
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 usbFunctionRead() to obtain data */
99 | }else if(rq->bRequest == USBRQ_HID_SET_REPORT){
100 | /* since we have only one report type, we can ignore the report-ID */
101 | bytesRemaining = 128;
102 | currentAddress = 0;
103 | return USB_NO_MSG; /* use usbFunctionWrite() to receive data from host */
104 | }
105 | }else{
106 | /* ignore vendor type requests, we don't use any */
107 | }
108 | return 0;
109 | }
110 | #ifdef __cplusplus
111 | } // extern "C"
112 | #endif
113 |
114 |
115 | /* ------------------------------------------------------------------------- */
116 | #if 0
117 | int main(void)
118 | {
119 | uchar i;
120 |
121 | wdt_enable(WDTO_1S);
122 | /* Even if you don't use the watchdog, turn it off here. On newer devices,
123 | * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
124 | */
125 | DBG1(0x00, 0, 0); /* debug output: main starts */
126 | /* RESET status: all port bits are inputs without pull-up.
127 | * That's the way we need D+ and D-. Therefore we don't need any
128 | * additional hardware initialization.
129 | */
130 | odDebugInit();
131 | usbInit();
132 | usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
133 | i = 0;
134 | while(--i){ /* fake USB disconnect for > 250 ms */
135 | wdt_reset();
136 | _delay_ms(1);
137 | }
138 | usbDeviceConnect();
139 | sei();
140 | DBG1(0x01, 0, 0); /* debug output: main loop starts */
141 | for(;;){ /* main event loop */
142 | DBG1(0x02, 0, 0); /* debug output: main loop iterates */
143 | wdt_reset();
144 | usbPoll();
145 | }
146 | return 0;
147 | }
148 | #endif
149 | /* ------------------------------------------------------------------------- */
150 |
--------------------------------------------------------------------------------
/libraries/UsbDevice/UsbDevice.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Based on Obdev's AVRUSB code and under the same license.
3 | *
4 | * TODO: Make a proper file header. :-)
5 | */
6 | #ifndef __UsbDevice_h__
7 | #define __UsbDeviceh__
8 |
9 | #include
10 | #include
11 | #include
12 |
13 | #include "usbdrv.h"
14 |
15 | // TODO: Work around Arduino 12 issues better.
16 | //#include
17 | //#undef int()
18 |
19 | typedef uint8_t byte;
20 |
21 | #include /* for _delay_ms() */
22 |
23 | class UsbGenericDevice {
24 | public:
25 | UsbGenericDevice () {
26 | }
27 |
28 | void begin() {
29 | // disable timer 0 overflow interrupt (used for millis)
30 | TIMSK0&=!(1< 250 ms */
40 | _delay_ms(1);
41 | }
42 | usbDeviceConnect();
43 |
44 | sei();
45 | }
46 |
47 | // TODO: Deprecate update
48 | void update() {
49 | refresh();
50 | }
51 |
52 | void refresh() {
53 | usbPoll();
54 | }
55 |
56 | };
57 |
58 | UsbGenericDevice UsbDevice = UsbGenericDevice();
59 |
60 | #endif // __UsbDevice_h__
61 |
--------------------------------------------------------------------------------
/libraries/UsbDevice/asmcommon.inc:
--------------------------------------------------------------------------------
1 | /* Name: asmcommon.inc
2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2007-11-05
5 | * Tabsize: 4
6 | * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | * Revision: $Id$
9 | */
10 |
11 | /* Do not link this file! Link usbdrvasm.S instead, which includes the
12 | * appropriate implementation!
13 | */
14 |
15 | /*
16 | General Description:
17 | This file contains assembler code which is shared among the USB driver
18 | implementations for different CPU cocks. Since the code must be inserted
19 | in the middle of the module, it's split out into this file and #included.
20 |
21 | Jump destinations called from outside:
22 | sofError: Called when no start sequence was found.
23 | se0: Called when a package has been successfully received.
24 | overflow: Called when receive buffer overflows.
25 | doReturn: Called after sending data.
26 |
27 | Outside jump destinations used by this module:
28 | waitForJ: Called to receive an already arriving packet.
29 | sendAckAndReti:
30 | sendNakAndReti:
31 | sendCntAndReti:
32 | usbSendAndReti:
33 |
34 | The following macros must be defined before this file is included:
35 | .macro POP_STANDARD
36 | .endm
37 | .macro POP_RETI
38 | .endm
39 | */
40 |
41 | #define token x1
42 |
43 | overflow:
44 | ldi x2, 1< 0
14 |
15 | #warning "Never compile production devices with debugging enabled"
16 |
17 | static void uartPutc(char c)
18 | {
19 | while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */
20 | ODDBG_UDR = c;
21 | }
22 |
23 | static uchar hexAscii(uchar h)
24 | {
25 | h &= 0xf;
26 | if(h >= 10)
27 | h += 'a' - (uchar)10 - '0';
28 | h += '0';
29 | return h;
30 | }
31 |
32 | static void printHex(uchar c)
33 | {
34 | uartPutc(hexAscii(c >> 4));
35 | uartPutc(hexAscii(c));
36 | }
37 |
38 | void odDebug(uchar prefix, uchar *data, uchar len)
39 | {
40 | printHex(prefix);
41 | uartPutc(':');
42 | while(len--){
43 | uartPutc(' ');
44 | printHex(*data++);
45 | }
46 | uartPutc('\r');
47 | uartPutc('\n');
48 | }
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/libraries/UsbDevice/oddebug.h:
--------------------------------------------------------------------------------
1 | /* Name: oddebug.h
2 | * Project: AVR library
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2005-01-16
5 | * Tabsize: 4
6 | * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | * This Revision: $Id: oddebug.h 692 2008-11-07 15:07:40Z cs $
9 | */
10 |
11 | #ifndef __oddebug_h_included__
12 | #define __oddebug_h_included__
13 |
14 | /*
15 | General Description:
16 | This module implements a function for debug logs on the serial line of the
17 | AVR microcontroller. Debugging can be configured with the define
18 | 'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging
19 | calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is
20 | 2, DBG1 and DBG2 logs will be printed.
21 |
22 | A debug log consists of a label ('prefix') to indicate which debug log created
23 | the output and a memory block to dump in hex ('data' and 'len').
24 | */
25 |
26 |
27 | #ifndef F_CPU
28 | # define F_CPU 12000000 /* 12 MHz */
29 | #endif
30 |
31 | /* make sure we have the UART defines: */
32 | #include "usbportability.h"
33 |
34 | #ifndef uchar
35 | # define uchar unsigned char
36 | #endif
37 |
38 | #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */
39 | # warning "Debugging disabled because device has no UART"
40 | # undef DEBUG_LEVEL
41 | #endif
42 |
43 | #ifndef DEBUG_LEVEL
44 | # define DEBUG_LEVEL 0
45 | #endif
46 |
47 | /* ------------------------------------------------------------------------- */
48 |
49 | #if DEBUG_LEVEL > 0
50 | # define DBG1(prefix, data, len) odDebug(prefix, data, len)
51 | #else
52 | # define DBG1(prefix, data, len)
53 | #endif
54 |
55 | #if DEBUG_LEVEL > 1
56 | # define DBG2(prefix, data, len) odDebug(prefix, data, len)
57 | #else
58 | # define DBG2(prefix, data, len)
59 | #endif
60 |
61 | /* ------------------------------------------------------------------------- */
62 |
63 | #if DEBUG_LEVEL > 0
64 | extern void odDebug(uchar prefix, uchar *data, uchar len);
65 |
66 | /* Try to find our control registers; ATMEL likes to rename these */
67 |
68 | #if defined UBRR
69 | # define ODDBG_UBRR UBRR
70 | #elif defined UBRRL
71 | # define ODDBG_UBRR UBRRL
72 | #elif defined UBRR0
73 | # define ODDBG_UBRR UBRR0
74 | #elif defined UBRR0L
75 | # define ODDBG_UBRR UBRR0L
76 | #endif
77 |
78 | #if defined UCR
79 | # define ODDBG_UCR UCR
80 | #elif defined UCSRB
81 | # define ODDBG_UCR UCSRB
82 | #elif defined UCSR0B
83 | # define ODDBG_UCR UCSR0B
84 | #endif
85 |
86 | #if defined TXEN
87 | # define ODDBG_TXEN TXEN
88 | #else
89 | # define ODDBG_TXEN TXEN0
90 | #endif
91 |
92 | #if defined USR
93 | # define ODDBG_USR USR
94 | #elif defined UCSRA
95 | # define ODDBG_USR UCSRA
96 | #elif defined UCSR0A
97 | # define ODDBG_USR UCSR0A
98 | #endif
99 |
100 | #if defined UDRE
101 | # define ODDBG_UDRE UDRE
102 | #else
103 | # define ODDBG_UDRE UDRE0
104 | #endif
105 |
106 | #if defined UDR
107 | # define ODDBG_UDR UDR
108 | #elif defined UDR0
109 | # define ODDBG_UDR UDR0
110 | #endif
111 |
112 | static inline void odDebugInit(void)
113 | {
114 | ODDBG_UCR |= (1<
39 | #ifndef __IAR_SYSTEMS_ASM__
40 | # include
41 | #endif
42 |
43 | #define __attribute__(arg) /* not supported on IAR */
44 |
45 | #ifdef __IAR_SYSTEMS_ASM__
46 | # define __ASSEMBLER__ /* IAR does not define standard macro for asm */
47 | #endif
48 |
49 | #ifdef __HAS_ELPM__
50 | # define PROGMEM __farflash
51 | #else
52 | # define PROGMEM __flash
53 | #endif
54 |
55 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr))
56 |
57 | /* The following definitions are not needed by the driver, but may be of some
58 | * help if you port a gcc based project to IAR.
59 | */
60 | #define cli() __disable_interrupt()
61 | #define sei() __enable_interrupt()
62 | #define wdt_reset() __watchdog_reset()
63 | #define _BV(x) (1 << (x))
64 |
65 | /* assembler compatibility macros */
66 | #define nop2 rjmp $+2 /* jump to next instruction */
67 | #define XL r26
68 | #define XH r27
69 | #define YL r28
70 | #define YH r29
71 | #define ZL r30
72 | #define ZH r31
73 | #define lo8(x) LOW(x)
74 | #define hi8(x) (((x)>>8) & 0xff) /* not HIGH to allow XLINK to make a proper range check */
75 |
76 | /* Depending on the device you use, you may get problems with the way usbdrv.h
77 | * handles the differences between devices. Since IAR does not use #defines
78 | * for MCU registers, we can't check for the existence of a particular
79 | * register with an #ifdef. If the autodetection mechanism fails, include
80 | * definitions for the required USB_INTR_* macros in your usbconfig.h. See
81 | * usbconfig-prototype.h and usbdrv.h for details.
82 | */
83 |
84 | /* ------------------------------------------------------------------------- */
85 | #elif __CODEVISIONAVR__ /* check for CodeVision AVR */
86 | /* ------------------------------------------------------------------------- */
87 | /* This port is not working (yet) */
88 |
89 | /* #define F_CPU _MCU_CLOCK_FREQUENCY_ seems to be defined automatically */
90 |
91 | #include
92 | #include
93 |
94 | #define __attribute__(arg) /* not supported on IAR */
95 |
96 | #define PROGMEM __flash
97 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr))
98 |
99 | #ifndef __ASSEMBLER__
100 | static inline void cli(void)
101 | {
102 | #asm("cli");
103 | }
104 | static inline void sei(void)
105 | {
106 | #asm("sei");
107 | }
108 | #endif
109 | #define _delay_ms(t) delay_ms(t)
110 | #define _BV(x) (1 << (x))
111 | #define USB_CFG_USE_SWITCH_STATEMENT 1 /* macro for if() cascase fails for unknown reason */
112 |
113 | #define macro .macro
114 | #define endm .endmacro
115 | #define nop2 rjmp .+0 /* jump to next instruction */
116 |
117 | /* ------------------------------------------------------------------------- */
118 | #else /* default development environment is avr-gcc/avr-libc */
119 | /* ------------------------------------------------------------------------- */
120 |
121 | #include
122 | #ifdef __ASSEMBLER__
123 | # define _VECTOR(N) __vector_ ## N /* io.h does not define this for asm */
124 | #else
125 | # include
126 | #endif
127 |
128 | #define USB_READ_FLASH(addr) pgm_read_byte(addr)
129 |
130 | #define macro .macro
131 | #define endm .endm
132 | #define nop2 rjmp .+0 /* jump to next instruction */
133 |
134 | #endif /* development environment */
135 |
136 | /* for conveniecne, ensure that PRG_RDB exists */
137 | #ifndef PRG_RDB
138 | # define PRG_RDB(addr) USB_READ_FLASH(addr)
139 | #endif
140 | #endif /* __usbportability_h_INCLUDED__ */
141 |
--------------------------------------------------------------------------------
/libraries/UsbKeyboard/ArduinoNotes.txt:
--------------------------------------------------------------------------------
1 | Notes On Integrating AVRUSB with Arduino
2 | ========================================
3 |
4 | * Note the license(s) under which AVRUSB is distributed.
5 |
6 | * See also: http://code.rancidbacon.com/ProjectLogArduinoUSB
7 |
8 | * Note: The pins we use on the PCB (not protoboard) hardware shield are:
9 |
10 | INT0 == PD2 == IC Pin 4 == Arduino Digital Pin 2 == D+
11 |
12 | ---- == PD4 == -------- == Arduino Digital Pin 4 == D-
13 |
14 | ---- == PD5 == -------- == Arduino Digital Pin 5 == pull-up
15 |
16 | (DONE: Change to not use PD3 so INT1 is left free?)
17 |
18 | * In order to compile a valid 'usbconfig.h' file must exit. The content of this
19 | file will vary depending on whether the device is a generic USB device,
20 | generic HID device or specific class of HID device for example.
21 |
22 | The file 'usbconfig-prototype.h' can be used as a starting point, however
23 | it might be easier to use the 'usbconfig.h' from one of the example projects.
24 |
25 | TODO: Specify the settings that need to be changed to match the shield
26 | design we use.
27 |
28 | * (NOTE: Initial 'usbconfig.h' used will be based on the file from
29 | 'HIDKeys.2007-03-29'.) (Note: Have now upgraded to V-USB 2009-08-22.)
30 |
31 | * Versions of the Arduino IDE prior to 0018 won't compile our library
32 | so it needs to be pre-compiled with:
33 |
34 | avr-g++ -Wall -Os -I. -DF_CPU=16000000 -mmcu=atmega168 -c usbdrvasm.S -c usbdrv.c
35 |
--------------------------------------------------------------------------------
/libraries/UsbKeyboard/UsbKeyboard.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Based on Obdev's AVRUSB code and under the same license.
3 | *
4 | * TODO: Make a proper file header. :-)
5 | */
6 | #ifndef __UsbKeyboard_h__
7 | #define __UsbKeyboard_h__
8 |
9 | #include
10 |
11 | #include
12 | #include
13 | #include /* for sei() */
14 | #include /* for _delay_ms() */
15 |
16 | #include /* required by usbdrv.h */
17 |
18 | #ifdef __cplusplus
19 | extern "C"
20 | {
21 | #endif
22 |
23 | #include "utility/usbdrv.h"
24 |
25 | #ifdef __cplusplus
26 | }
27 | #endif
28 |
29 | typedef uint8_t byte;
30 |
31 | #define BUFFER_SIZE 4 // Minimum of 2: 1 for modifiers + 1 for keystroke
32 |
33 | static uchar idleRate; // in 4 ms units
34 |
35 | /* We use a simplifed keyboard report descriptor which does not support the
36 | * boot protocol. We don't allow setting status LEDs and but we do allow
37 | * simultaneous key presses.
38 | * The report descriptor has been created with usb.org's "HID Descriptor Tool"
39 | * which can be downloaded from http://www.usb.org/developers/hidpage/.
40 | * Redundant entries (such as LOGICAL_MINIMUM and USAGE_PAGE) have been omitted
41 | * for the second INPUT item.
42 | */
43 | PROGMEM const char usbHidReportDescriptor[35] = { /* USB report descriptor */
44 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
45 | 0x09, 0x06, // USAGE (Keyboard)
46 | 0xa1, 0x01, // COLLECTION (Application)
47 | 0x05, 0x07, // USAGE_PAGE (Keyboard)
48 | 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
49 | 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
50 | 0x15, 0x00, // LOGICAL_MINIMUM (0)
51 | 0x25, 0x01, // LOGICAL_MAXIMUM (1)
52 | 0x75, 0x01, // REPORT_SIZE (1)
53 | 0x95, 0x08, // REPORT_COUNT (8)
54 | 0x81, 0x02, // INPUT (Data,Var,Abs)
55 | 0x95, BUFFER_SIZE-1, // REPORT_COUNT (simultaneous keystrokes)
56 | 0x75, 0x08, // REPORT_SIZE (8)
57 | 0x25, 0x65, // LOGICAL_MAXIMUM (101)
58 | 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
59 | 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
60 | 0x81, 0x00, // INPUT (Data,Ary,Abs)
61 | 0xc0 // END_COLLECTION
62 | };
63 |
64 |
65 |
66 | /* Keyboard usage values, see usb.org's HID-usage-tables document, chapter
67 | * 10 Keyboard/Keypad Page for more codes.
68 | */
69 | #define MOD_CONTROL_LEFT (1<<0)
70 | #define MOD_SHIFT_LEFT (1<<1)
71 | #define MOD_ALT_LEFT (1<<2)
72 | #define MOD_GUI_LEFT (1<<3)
73 | #define MOD_CONTROL_RIGHT (1<<4)
74 | #define MOD_SHIFT_RIGHT (1<<5)
75 | #define MOD_ALT_RIGHT (1<<6)
76 | #define MOD_GUI_RIGHT (1<<7)
77 |
78 | #define KEY_A 4
79 | #define KEY_B 5
80 | #define KEY_C 6
81 | #define KEY_D 7
82 | #define KEY_E 8
83 | #define KEY_F 9
84 | #define KEY_G 10
85 | #define KEY_H 11
86 | #define KEY_I 12
87 | #define KEY_J 13
88 | #define KEY_K 14
89 | #define KEY_L 15
90 | #define KEY_M 16
91 | #define KEY_N 17
92 | #define KEY_O 18
93 | #define KEY_P 19
94 | #define KEY_Q 20
95 | #define KEY_R 21
96 | #define KEY_S 22
97 | #define KEY_T 23
98 | #define KEY_U 24
99 | #define KEY_V 25
100 | #define KEY_W 26
101 | #define KEY_X 27
102 | #define KEY_Y 28
103 | #define KEY_Z 29
104 | #define KEY_1 30
105 | #define KEY_2 31
106 | #define KEY_3 32
107 | #define KEY_4 33
108 | #define KEY_5 34
109 | #define KEY_6 35
110 | #define KEY_7 36
111 | #define KEY_8 37
112 | #define KEY_9 38
113 | #define KEY_0 39
114 |
115 | #define KEY_ENTER 40
116 |
117 | #define KEY_SPACE 44
118 |
119 | #define KEY_F1 58
120 | #define KEY_F2 59
121 | #define KEY_F3 60
122 | #define KEY_F4 61
123 | #define KEY_F5 62
124 | #define KEY_F6 63
125 | #define KEY_F7 64
126 | #define KEY_F8 65
127 | #define KEY_F9 66
128 | #define KEY_F10 67
129 | #define KEY_F11 68
130 | #define KEY_F12 69
131 |
132 | #define KEY_ARROW_LEFT 0x50
133 |
134 |
135 | class UsbKeyboardDevice {
136 | public:
137 | UsbKeyboardDevice () {
138 | PORTD = 0; // TODO: Only for USB pins?
139 | DDRD |= ~USBMASK;
140 |
141 | cli();
142 | usbDeviceDisconnect();
143 | usbDeviceConnect();
144 |
145 | usbInit();
146 |
147 | sei();
148 |
149 | // TODO: Remove the next two lines once we fix
150 | // missing first keystroke bug properly.
151 | memset(reportBuffer, 0, sizeof(reportBuffer));
152 | usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
153 | }
154 |
155 | void update() {
156 | usbPoll();
157 | }
158 |
159 | void sendKeyStroke(byte keyStroke) {
160 | sendKeyStroke(keyStroke, 0);
161 | }
162 |
163 | void sendKeyStroke(byte keyStroke, byte modifiers) {
164 |
165 | while (!usbInterruptIsReady()) {
166 | // Note: We wait until we can send keystroke
167 | // so we know the previous keystroke was
168 | // sent.
169 | }
170 |
171 | memset(reportBuffer, 0, sizeof(reportBuffer));
172 |
173 | reportBuffer[0] = modifiers;
174 | reportBuffer[1] = keyStroke;
175 |
176 | usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
177 |
178 | while (!usbInterruptIsReady()) {
179 | // Note: We wait until we can send keystroke
180 | // so we know the previous keystroke was
181 | // sent.
182 | }
183 |
184 | // This stops endlessly repeating keystrokes:
185 | memset(reportBuffer, 0, sizeof(reportBuffer));
186 | usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
187 |
188 | }
189 |
190 | //private: TODO: Make friend?
191 | uchar reportBuffer[4]; // buffer for HID reports [ 1 modifier byte + (len-1) key strokes]
192 |
193 | };
194 |
195 | UsbKeyboardDevice UsbKeyboard = UsbKeyboardDevice();
196 |
197 | usbMsgLen_t usbFunctionSetup(uchar data[8])
198 | {
199 | usbRequest_t *rq = (usbRequest_t *)((void *)data);
200 |
201 | usbMsgPtr = UsbKeyboard.reportBuffer; //
202 | if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){
203 | /* class request type */
204 |
205 | if(rq->bRequest == USBRQ_HID_GET_REPORT){
206 | /* wValue: ReportType (highbyte), ReportID (lowbyte) */
207 |
208 | /* we only have one report type, so don't look at wValue */
209 | // TODO: Ensure it's okay not to return anything here?
210 | return 0;
211 |
212 | }else if(rq->bRequest == USBRQ_HID_GET_IDLE){
213 | // usbMsgPtr = &idleRate;
214 | // return 1;
215 | return 0;
216 | }else if(rq->bRequest == USBRQ_HID_SET_IDLE){
217 | idleRate = rq->wValue.bytes[1];
218 | }
219 | }else{
220 | /* no vendor specific requests implemented */
221 | }
222 | return 0;
223 | }
224 |
225 | #endif // __UsbKeyboard_h__
226 |
--------------------------------------------------------------------------------
/libraries/UsbKeyboard/examples/UsbKeyboardDemo1/UsbKeyboardDemo1.pde:
--------------------------------------------------------------------------------
1 | #include "UsbKeyboard.h"
2 |
3 | #define BUTTON_PIN 12
4 |
5 | // If the timer isr is corrected
6 | // to not take so long change this to 0.
7 | #define BYPASS_TIMER_ISR 1
8 |
9 | void setup() {
10 | pinMode(BUTTON_PIN, INPUT);
11 | digitalWrite(BUTTON_PIN, HIGH);
12 |
13 | #if BYPASS_TIMER_ISR
14 | // disable timer 0 overflow interrupt (used for millis)
15 | TIMSK0&=!(1< 0
13 |
14 | #warning "Never compile production devices with debugging enabled"
15 |
16 | static void uartPutc(char c)
17 | {
18 | while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */
19 | ODDBG_UDR = c;
20 | }
21 |
22 | static uchar hexAscii(uchar h)
23 | {
24 | h &= 0xf;
25 | if(h >= 10)
26 | h += 'a' - (uchar)10 - '0';
27 | h += '0';
28 | return h;
29 | }
30 |
31 | static void printHex(uchar c)
32 | {
33 | uartPutc(hexAscii(c >> 4));
34 | uartPutc(hexAscii(c));
35 | }
36 |
37 | void odDebug(uchar prefix, uchar *data, uchar len)
38 | {
39 | printHex(prefix);
40 | uartPutc(':');
41 | while(len--){
42 | uartPutc(' ');
43 | printHex(*data++);
44 | }
45 | uartPutc('\r');
46 | uartPutc('\n');
47 | }
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/libraries/UsbKeyboard/utility/oddebug.h:
--------------------------------------------------------------------------------
1 | /* Name: oddebug.h
2 | * Project: AVR library
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2005-01-16
5 | * Tabsize: 4
6 | * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | */
9 |
10 | #ifndef __oddebug_h_included__
11 | #define __oddebug_h_included__
12 |
13 | /*
14 | General Description:
15 | This module implements a function for debug logs on the serial line of the
16 | AVR microcontroller. Debugging can be configured with the define
17 | 'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging
18 | calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is
19 | 2, DBG1 and DBG2 logs will be printed.
20 |
21 | A debug log consists of a label ('prefix') to indicate which debug log created
22 | the output and a memory block to dump in hex ('data' and 'len').
23 | */
24 |
25 |
26 | #ifndef F_CPU
27 | # define F_CPU 12000000 /* 12 MHz */
28 | #endif
29 |
30 | /* make sure we have the UART defines: */
31 | #include "usbportability.h"
32 |
33 | #ifndef uchar
34 | # define uchar unsigned char
35 | #endif
36 |
37 | #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */
38 | # warning "Debugging disabled because device has no UART"
39 | # undef DEBUG_LEVEL
40 | #endif
41 |
42 | #ifndef DEBUG_LEVEL
43 | # define DEBUG_LEVEL 0
44 | #endif
45 |
46 | /* ------------------------------------------------------------------------- */
47 |
48 | #if DEBUG_LEVEL > 0
49 | # define DBG1(prefix, data, len) odDebug(prefix, data, len)
50 | #else
51 | # define DBG1(prefix, data, len)
52 | #endif
53 |
54 | #if DEBUG_LEVEL > 1
55 | # define DBG2(prefix, data, len) odDebug(prefix, data, len)
56 | #else
57 | # define DBG2(prefix, data, len)
58 | #endif
59 |
60 | /* ------------------------------------------------------------------------- */
61 |
62 | #if DEBUG_LEVEL > 0
63 | extern void odDebug(uchar prefix, uchar *data, uchar len);
64 |
65 | /* Try to find our control registers; ATMEL likes to rename these */
66 |
67 | #if defined UBRR
68 | # define ODDBG_UBRR UBRR
69 | #elif defined UBRRL
70 | # define ODDBG_UBRR UBRRL
71 | #elif defined UBRR0
72 | # define ODDBG_UBRR UBRR0
73 | #elif defined UBRR0L
74 | # define ODDBG_UBRR UBRR0L
75 | #endif
76 |
77 | #if defined UCR
78 | # define ODDBG_UCR UCR
79 | #elif defined UCSRB
80 | # define ODDBG_UCR UCSRB
81 | #elif defined UCSR0B
82 | # define ODDBG_UCR UCSR0B
83 | #endif
84 |
85 | #if defined TXEN
86 | # define ODDBG_TXEN TXEN
87 | #else
88 | # define ODDBG_TXEN TXEN0
89 | #endif
90 |
91 | #if defined USR
92 | # define ODDBG_USR USR
93 | #elif defined UCSRA
94 | # define ODDBG_USR UCSRA
95 | #elif defined UCSR0A
96 | # define ODDBG_USR UCSR0A
97 | #endif
98 |
99 | #if defined UDRE
100 | # define ODDBG_UDRE UDRE
101 | #else
102 | # define ODDBG_UDRE UDRE0
103 | #endif
104 |
105 | #if defined UDR
106 | # define ODDBG_UDR UDR
107 | #elif defined UDR0
108 | # define ODDBG_UDR UDR0
109 | #endif
110 |
111 | static inline void odDebugInit(void)
112 | {
113 | ODDBG_UCR |= (1<
38 | #ifndef __IAR_SYSTEMS_ASM__
39 | # include
40 | #endif
41 |
42 | #define __attribute__(arg) /* not supported on IAR */
43 |
44 | #ifdef __IAR_SYSTEMS_ASM__
45 | # define __ASSEMBLER__ /* IAR does not define standard macro for asm */
46 | #endif
47 |
48 | #ifdef __HAS_ELPM__
49 | # define PROGMEM __farflash
50 | #else
51 | # define PROGMEM __flash
52 | #endif
53 |
54 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr))
55 |
56 | /* The following definitions are not needed by the driver, but may be of some
57 | * help if you port a gcc based project to IAR.
58 | */
59 | #define cli() __disable_interrupt()
60 | #define sei() __enable_interrupt()
61 | #define wdt_reset() __watchdog_reset()
62 | #define _BV(x) (1 << (x))
63 |
64 | /* assembler compatibility macros */
65 | #define nop2 rjmp $+2 /* jump to next instruction */
66 | #define XL r26
67 | #define XH r27
68 | #define YL r28
69 | #define YH r29
70 | #define ZL r30
71 | #define ZH r31
72 | #define lo8(x) LOW(x)
73 | #define hi8(x) (((x)>>8) & 0xff) /* not HIGH to allow XLINK to make a proper range check */
74 |
75 | /* Depending on the device you use, you may get problems with the way usbdrv.h
76 | * handles the differences between devices. Since IAR does not use #defines
77 | * for MCU registers, we can't check for the existence of a particular
78 | * register with an #ifdef. If the autodetection mechanism fails, include
79 | * definitions for the required USB_INTR_* macros in your usbconfig.h. See
80 | * usbconfig-prototype.h and usbdrv.h for details.
81 | */
82 |
83 | /* ------------------------------------------------------------------------- */
84 | #elif __CODEVISIONAVR__ /* check for CodeVision AVR */
85 | /* ------------------------------------------------------------------------- */
86 | /* This port is not working (yet) */
87 |
88 | /* #define F_CPU _MCU_CLOCK_FREQUENCY_ seems to be defined automatically */
89 |
90 | #include
91 | #include
92 |
93 | #define __attribute__(arg) /* not supported on IAR */
94 |
95 | #define PROGMEM __flash
96 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr))
97 |
98 | #ifndef __ASSEMBLER__
99 | static inline void cli(void)
100 | {
101 | #asm("cli");
102 | }
103 | static inline void sei(void)
104 | {
105 | #asm("sei");
106 | }
107 | #endif
108 | #define _delay_ms(t) delay_ms(t)
109 | #define _BV(x) (1 << (x))
110 | #define USB_CFG_USE_SWITCH_STATEMENT 1 /* macro for if() cascase fails for unknown reason */
111 |
112 | #define macro .macro
113 | #define endm .endmacro
114 | #define nop2 rjmp .+0 /* jump to next instruction */
115 |
116 | /* ------------------------------------------------------------------------- */
117 | #else /* default development environment is avr-gcc/avr-libc */
118 | /* ------------------------------------------------------------------------- */
119 |
120 | #include
121 | #ifdef __ASSEMBLER__
122 | # define _VECTOR(N) __vector_ ## N /* io.h does not define this for asm */
123 | #else
124 | # include
125 | #endif
126 |
127 | #if USB_CFG_DRIVER_FLASH_PAGE
128 | # define USB_READ_FLASH(addr) pgm_read_byte_far(((long)USB_CFG_DRIVER_FLASH_PAGE << 16) | (long)(addr))
129 | #else
130 | # define USB_READ_FLASH(addr) pgm_read_byte(addr)
131 | #endif
132 |
133 | #define macro .macro
134 | #define endm .endm
135 | #define nop2 rjmp .+0 /* jump to next instruction */
136 |
137 | #endif /* development environment */
138 |
139 | /* for conveniecne, ensure that PRG_RDB exists */
140 | #ifndef PRG_RDB
141 | # define PRG_RDB(addr) USB_READ_FLASH(addr)
142 | #endif
143 | #endif /* __usbportability_h_INCLUDED__ */
144 |
--------------------------------------------------------------------------------
/libraries/UsbStream/ArduinoNotes.txt:
--------------------------------------------------------------------------------
1 | Notes On Integrating AVRUSB with Arduino
2 | ========================================
3 |
4 | * Note the license(s) under which AVRUSB is distributed.
5 |
6 | * See also: http://code.rancidbacon.com/ProjectLogArduinoUSB
7 |
8 | * Note: The pins we use on the PCB (not protoboard) hardware shield are:
9 |
10 | INT0 == PD2 == IC Pin 4 == Arduino Digital Pin 2 == D+
11 |
12 | ---- == PD4 == -------- == Arduino Digital Pin 4 == D-
13 |
14 | ---- == PD5 == -------- == Arduino Digital Pin 5 == pull-up
15 |
16 | (DONE: Change to not use PD3 so INT1 is left free?)
17 |
18 | * In order to compile a valid 'usbconfig.h' file must exit. The content of this
19 | file will vary depending on whether the device is a generic USB device,
20 | generic HID device or specific class of HID device for example.
21 |
22 | The file 'usbconfig-prototype.h' can be used as a starting point, however
23 | it might be easier to use the 'usbconfig.h' from one of the example projects.
24 |
25 | TODO: Specify the settings that need to be changed to match the shield
26 | design we use.
27 |
28 | * (NOTE: Initial 'usbconfig.h' used will be based on the file from
29 | 'HIDKeys.2007-03-29'.) (Note: Have now upgraded to V-USB 2009-08-22.)
30 |
31 | * At present the IDE won't compile our library so it needs to be pre-compiled
32 | with:
33 |
34 | avr-g++ -Wall -Os -I. -DF_CPU=16000000 -mmcu=atmega168 -c usbdrvasm.S -c usbdrv.c
35 |
--------------------------------------------------------------------------------
/libraries/UsbStream/CommercialLicense.txt:
--------------------------------------------------------------------------------
1 | V-USB Driver Software License Agreement
2 | Version 2009-08-03
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 (Clay Logic, www.claylogic.com). Both owners of the Vendor IDs
41 | have obtained these IDs from the USB Implementers Forum, Inc.
42 | (www.usb.org). OBJECTIVE DEVELOPMENT disclaims all liability which might
43 | arise from the assignment of USB IDs.
44 |
45 | 2.5 USB Certification. Although not part of this agreement, we want to make
46 | it clear that you cannot become USB certified when you use V-USB or a USB
47 | Product ID assigned by OBJECTIVE DEVELOPMENT. AVR microcontrollers don't
48 | meet the electrical specifications required by the USB specification and
49 | the USB Implementers Forum certifies only members who bought a Vendor ID of
50 | their own.
51 |
52 |
53 | 3 LICENSE RESTRICTIONS
54 |
55 | 3.1 Number of Units. Only one of the following three definitions is
56 | applicable. Which one is determined by the amount you pay to OBJECTIVE
57 | DEVELOPMENT, see section 4 ("Payment") below.
58 |
59 | Hobby License: You may use V-USB according to section 2 above in no more
60 | than 5 hardware units. These units must not be sold for profit.
61 |
62 | Entry Level License: You may use V-USB according to section 2 above in no
63 | more than 150 hardware units.
64 |
65 | Professional License: You may use V-USB according to section 2 above in
66 | any number of hardware units, except for large scale production ("unlimited
67 | fair use"). Quantities below 10,000 units are not considered large scale
68 | production. If your reach quantities which are obviously large scale
69 | production, you must pay a license fee of 0.10 EUR per unit for all units
70 | above 10,000.
71 |
72 | 3.2 Rental. You may not rent, lease, or lend V-USB or otherwise encumber
73 | any copy of V-USB, or any of the rights granted herein.
74 |
75 | 3.3 Transfer. You may not transfer your rights under this Agreement to
76 | another party without OBJECTIVE DEVELOPMENT's prior written consent. If
77 | such consent is obtained, you may permanently transfer this License to
78 | another party. The recipient of such transfer must agree to all terms and
79 | conditions of this Agreement.
80 |
81 | 3.4 Reservation of Rights. OBJECTIVE DEVELOPMENT retains all rights not
82 | expressly granted.
83 |
84 | 3.5 Non-Exclusive Rights. Your license rights under this Agreement are
85 | non-exclusive.
86 |
87 | 3.6 Third Party Rights. This Agreement cannot grant you rights controlled
88 | by third parties. In particular, you are not allowed to use the USB logo or
89 | other trademarks owned by the USB Implementers Forum, Inc. without their
90 | consent. Since such consent depends on USB certification, it should be
91 | noted that V-USB will not pass certification because it does not
92 | implement checksum verification and the microcontroller ports do not meet
93 | the electrical specifications.
94 |
95 |
96 | 4 PAYMENT
97 |
98 | The payment amount depends on the variation of this agreement (according to
99 | section 3.1) into which you want to enter. Concrete prices are listed on
100 | OBJECTIVE DEVELOPMENT's web site, usually at
101 | http://www.obdev.at/vusb/license.html. You agree to pay the amount listed
102 | there to OBJECTIVE DEVELOPMENT or OBJECTIVE DEVELOPMENT's payment processor
103 | or reseller.
104 |
105 |
106 | 5 COPYRIGHT AND OWNERSHIP
107 |
108 | V-USB is protected by copyright laws and international copyright
109 | treaties, as well as other intellectual property laws and treaties. V-USB
110 | is licensed, not sold.
111 |
112 |
113 | 6 TERM AND TERMINATION
114 |
115 | 6.1 Term. This Agreement shall continue indefinitely. However, OBJECTIVE
116 | DEVELOPMENT may terminate this Agreement and revoke the granted license and
117 | USB-IDs if you fail to comply with any of its terms and conditions.
118 |
119 | 6.2 Survival of Terms. All provisions regarding secrecy, confidentiality
120 | and limitation of liability shall survive termination of this agreement.
121 |
122 |
123 | 7 DISCLAIMER OF WARRANTY AND LIABILITY
124 |
125 | LIMITED WARRANTY. V-USB IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
126 | KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, OBJECTIVE
127 | DEVELOPMENT AND ITS SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES, EITHER
128 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
129 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND
130 | NON-INFRINGEMENT, WITH REGARD TO V-USB, AND THE PROVISION OF OR FAILURE
131 | TO PROVIDE SUPPORT SERVICES. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL
132 | RIGHTS. YOU MAY HAVE OTHERS, WHICH VARY FROM STATE/JURISDICTION TO
133 | STATE/JURISDICTION.
134 |
135 | LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
136 | IN NO EVENT SHALL OBJECTIVE DEVELOPMENT OR ITS SUPPLIERS BE LIABLE FOR ANY
137 | SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER
138 | (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
139 | BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY
140 | LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE V-USB OR THE
141 | PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF OBJECTIVE
142 | DEVELOPMENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY
143 | CASE, OBJECTIVE DEVELOPMENT'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS
144 | AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR V-USB.
145 |
146 |
147 | 8 MISCELLANEOUS TERMS
148 |
149 | 8.1 Marketing. OBJECTIVE DEVELOPMENT has the right to mention for marketing
150 | purposes that you entered into this agreement.
151 |
152 | 8.2 Entire Agreement. This document represents the entire agreement between
153 | OBJECTIVE DEVELOPMENT and you. It may only be modified in writing signed by
154 | an authorized representative of both, OBJECTIVE DEVELOPMENT and you.
155 |
156 | 8.3 Severability. In case a provision of these terms and conditions should
157 | be or become partly or entirely invalid, ineffective, or not executable,
158 | the validity of all other provisions shall not be affected.
159 |
160 | 8.4 Applicable Law. This agreement is governed by the laws of the Republic
161 | of Austria.
162 |
163 | 8.5 Responsible Courts. The responsible courts in Vienna/Austria will have
164 | exclusive jurisdiction regarding all disputes in connection with this
165 | agreement.
166 |
167 |
--------------------------------------------------------------------------------
/libraries/UsbStream/Readme.txt:
--------------------------------------------------------------------------------
1 | This is the Readme file to Objective Development's firmware-only USB driver
2 | for Atmel AVR microcontrollers. For more information please visit
3 | http://www.obdev.at/vusb/
4 |
5 | This directory contains the USB firmware only. Copy it as-is to your own
6 | project and add all .c and .S files to your project (these files are marked
7 | with an asterisk in the list below). Then copy usbconfig-prototype.h as
8 | usbconfig.h to your project and edit it according to your configuration.
9 |
10 |
11 | TECHNICAL DOCUMENTATION
12 | =======================
13 | The technical documentation (API) for the firmware driver is contained in the
14 | file "usbdrv.h". Please read all of it carefully! Configuration options are
15 | documented in "usbconfig-prototype.h".
16 |
17 | The driver consists of the following files:
18 | Readme.txt ............. The file you are currently reading.
19 | Changelog.txt .......... Release notes for all versions of the driver.
20 | usbdrv.h ............... Driver interface definitions and technical docs.
21 | * usbdrv.c ............... High level language part of the driver. Link this
22 | module to your code!
23 | * usbdrvasm.S ............ Assembler part of the driver. This module is mostly
24 | a stub and includes one of the usbdrvasm*.S files
25 | depending on processor clock. Link this module to
26 | your code!
27 | usbdrvasm*.inc ......... Assembler routines for particular clock frequencies.
28 | Included by usbdrvasm.S, don't link it directly!
29 | asmcommon.inc .......... Common assembler routines. Included by
30 | usbdrvasm*.inc, don't link it directly!
31 | usbconfig-prototype.h .. Prototype for your own usbdrv.h file.
32 | * oddebug.c .............. Debug functions. Only used when DEBUG_LEVEL is
33 | defined to a value greater than 0. Link this module
34 | to your code!
35 | oddebug.h .............. Interface definitions of the debug module.
36 | usbportability.h ....... Header with compiler-dependent stuff.
37 | usbdrvasm.asm .......... Compatibility stub for IAR-C-compiler. Use this
38 | module instead of usbdrvasm.S when you assembler
39 | with IAR's tools.
40 | License.txt ............ Open Source license for this driver.
41 | CommercialLicense.txt .. Optional commercial license for this driver.
42 | USB-ID-FAQ.txt ......... General infos about USB Product- and Vendor-IDs.
43 | USB-IDs-for-free.txt ... List and terms of use for free shared PIDs.
44 |
45 | (*) ... These files should be linked to your project.
46 |
47 |
48 | CPU CORE CLOCK FREQUENCY
49 | ========================
50 | We supply assembler modules for clock frequencies of 12 MHz, 12.8 MHz, 15 MHz,
51 | 16 MHz, 16.5 MHz 18 MHz and 20 MHz. Other clock rates are not supported. The
52 | actual clock rate must be configured in usbdrv.h unless you use the default
53 | 12 MHz.
54 |
55 | 12 MHz Clock
56 | This is the traditional clock rate of V-USB because it's the lowest clock
57 | rate where the timing constraints of the USB spec can be met.
58 |
59 | 15 MHz Clock
60 | Similar to 12 MHz, but some NOPs inserted. On the other hand, the higher clock
61 | rate allows for some loops which make the resulting code size somewhat smaller
62 | than the 12 MHz version.
63 |
64 | 16 MHz Clock
65 | This clock rate has been added for users of the Arduino board and other
66 | ready-made boards which come with a fixed 16 MHz crystal. It's also an option
67 | if you need the slightly higher clock rate for performance reasons. Since
68 | 16 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code
69 | is somewhat tricky and has to insert a leap cycle every third byte.
70 |
71 | 12.8 MHz and 16.5 MHz Clock
72 | The assembler modules for these clock rates differ from the other modules
73 | because they have been built for an RC oscillator with only 1% precision. The
74 | receiver code inserts leap cycles to compensate for clock deviations. 1% is
75 | also the precision which can be achieved by calibrating the internal RC
76 | oscillator of the AVR. Please note that only AVRs with internal 64 MHz PLL
77 | oscillator can reach 16.5 MHz with the RC oscillator. This includes the very
78 | popular ATTiny25, ATTiny45, ATTiny85 series as well as the ATTiny26. Almost
79 | all AVRs can reach 12.8 MHz, although this is outside the specified range.
80 |
81 | See the EasyLogger example at http://www.obdev.at/vusb/easylogger.html for
82 | code which calibrates the RC oscillator based on the USB frame clock.
83 |
84 | 18 MHz Clock
85 | This module is closer to the USB specification because it performs an on the
86 | fly CRC check for incoming packets. Packets with invalid checksum are
87 | discarded as required by the spec. If you also implement checks for data
88 | PID toggling on application level (see option USB_CFG_CHECK_DATA_TOGGLING
89 | in usbconfig.h for more info), this ensures data integrity. Due to the CRC
90 | tables and alignment requirements, this code is bigger than modules for other
91 | clock rates. To activate this module, you must define USB_CFG_CHECK_CRC to 1
92 | and USB_CFG_CLOCK_KHZ to 18000 in usbconfig.h.
93 |
94 | 20 MHz Clock
95 | This module is for people who won't do it with less than the maximum. Since
96 | 20 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code
97 | uses similar tricks as the 16 MHz module to insert leap cycles.
98 |
99 |
100 | USB IDENTIFIERS
101 | ===============
102 | Every USB device needs a vendor- and a product-identifier (VID and PID). VIDs
103 | are obtained from usb.org for a price of 1,500 USD. Once you have a VID, you
104 | can assign PIDs at will.
105 |
106 | Since an entry level cost of 1,500 USD is too high for most small companies
107 | and hobbyists, we provide some VID/PID pairs for free. See the file
108 | USB-IDs-for-free.txt for details.
109 |
110 | Objective Development also has some license offerings which include product
111 | IDs. See http://www.obdev.at/vusb/ for details.
112 |
113 |
114 | DEVELOPMENT SYSTEM
115 | ==================
116 | This driver has been developed and optimized for the GNU compiler version 3
117 | (gcc 3). It does work well with gcc 4, but with bigger code size. We recommend
118 | that you use the GNU compiler suite because it is freely available. V-USB
119 | has also been ported to the IAR compiler and assembler. It has been tested
120 | with IAR 4.10B/W32 and 4.12A/W32 on an ATmega8 with the "small" and "tiny"
121 | memory model. Not every release is tested with IAR CC and the driver may
122 | therefore fail to compile with IAR. Please note that gcc is more efficient for
123 | usbdrv.c because this module has been deliberately optimized for gcc.
124 |
125 |
126 | USING V-USB FOR FREE
127 | ====================
128 | The AVR firmware driver is published under the GNU General Public License
129 | Version 2 (GPL2) and the GNU General Public License Version 3 (GPL3). It is
130 | your choice whether you apply the terms of version 2 or version 3.
131 |
132 | If you decide for the free GPL2 or GPL3, we STRONGLY ENCOURAGE you to do the
133 | following things IN ADDITION to the obligations from the GPL:
134 |
135 | (1) Publish your entire project on a web site and drop us a note with the URL.
136 | Use the form at http://www.obdev.at/vusb/feedback.html for your submission.
137 | If you don't have a web site, you can publish the project in obdev's
138 | documentation wiki at
139 | http://www.obdev.at/goto.php?t=vusb-wiki&p=hosted-projects.
140 |
141 | (2) Adhere to minimum publication standards. Please include AT LEAST:
142 | - a circuit diagram in PDF, PNG or GIF format
143 | - full source code for the host software
144 | - a Readme.txt file in ASCII format which describes the purpose of the
145 | project and what can be found in which directories and which files
146 | - a reference to http://www.obdev.at/vusb/
147 |
148 | (3) If you improve the driver firmware itself, please give us a free license
149 | to your modifications for our commercial license offerings.
150 |
151 |
152 | COMMERCIAL LICENSES FOR V-USB
153 | =============================
154 | If you don't want to publish your source code under the terms of the GPL,
155 | you can simply pay money for V-USB. As an additional benefit you get
156 | USB PIDs for free, reserved exclusively to you. See the file
157 | "CommercialLicense.txt" for details.
158 |
159 |
--------------------------------------------------------------------------------
/libraries/UsbStream/USB-ID-FAQ.txt:
--------------------------------------------------------------------------------
1 | Version 2009-08-22
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 (Clay Logic, www.claylogic.com). Both VID owners have received their
111 | Vendor-ID directly from usb.org.
112 |
113 |
114 | =========================================================================
115 | CAN I USE USB-IDs FROM OBJECTIVE DEVELOPMENT WITH OTHER DRIVERS/HARDWARE?
116 | =========================================================================
117 |
118 | The short answer is: Yes. All you get is a guarantee that the IDs are never
119 | assigned to anybody else. What more do you need?
120 |
121 |
122 | ============================
123 | WHAT ABOUT SHARED ID PAIRS?
124 | ============================
125 |
126 | Objective Development has reserved some PID/VID pairs for shared use. You
127 | have no guarantee of uniqueness for them, except that no USB compliant device
128 | uses them. In order to avoid technical problems, we must ensure that all
129 | devices with the same pair of IDs use the same driver on kernel level. For
130 | details, see the file USB-IDs-for-free.txt.
131 |
132 |
133 | ======================================================
134 | I HAVE HEARD THAT SUB-LICENSING OF USB-IDs IS ILLEGAL?
135 | ======================================================
136 |
137 | A 16 bit integer number cannot be protected by copyright laws. It is not
138 | sufficiently complex. And since none of the parties involved entered into the
139 | USB-IF Trademark License Agreement, we are not bound by this agreement. So
140 | there is no reason why it should be illegal to sub-license USB-IDs.
141 |
142 |
143 | =============================================
144 | WHO IS LIABLE IF THERE ARE INCOMPATIBILITIES?
145 | =============================================
146 |
147 | Objective Development disclaims all liabilities which might arise from the
148 | assignment of IDs. If you guarantee product features to your customers
149 | without proper disclaimer, YOU are liable for that.
150 |
--------------------------------------------------------------------------------
/libraries/UsbStream/USB-IDs-for-free.txt:
--------------------------------------------------------------------------------
1 | Version 2009-08-22
2 |
3 | ===========================
4 | FREE USB-IDs FOR SHARED USE
5 | ===========================
6 |
7 | Objective Development has reserved a set of USB Product-IDs for use according
8 | to the guidelines outlined below. For more information about the concept of
9 | USB IDs please see the file USB-ID-FAQ.txt. Objective Development guarantees
10 | that the IDs listed below are not used by any USB compliant devices.
11 |
12 |
13 | ====================
14 | MECHANISM OF SHARING
15 | ====================
16 |
17 | From a technical point of view, two different devices can share the same USB
18 | Vendor- and Product-ID if they require the same driver on operating system
19 | level. We make use of this fact by assigning separate IDs for various device
20 | classes. On application layer, devices must be distinguished by their textual
21 | name or serial number. We offer separate sets of IDs for discrimination by
22 | textual name and for serial number.
23 |
24 | Examples for shared use of USB IDs are included with V-USB in the "examples"
25 | subdirectory.
26 |
27 |
28 | ======================================
29 | IDs FOR DISCRIMINATION BY TEXTUAL NAME
30 | ======================================
31 |
32 | If you use one of the IDs listed below, your device and host-side software
33 | must conform to these rules:
34 |
35 | (1) The USB device MUST provide a textual representation of the manufacturer
36 | and product identification. The manufacturer identification MUST be available
37 | at least in USB language 0x0409 (English/US).
38 |
39 | (2) The textual manufacturer identification MUST contain either an Internet
40 | domain name (e.g. "mycompany.com") registered and owned by you, or an e-mail
41 | address under your control (e.g. "myname@gmx.net"). You can embed the domain
42 | name or e-mail address in any string you like, e.g. "Objective Development
43 | http://www.obdev.at/vusb/".
44 |
45 | (3) You are responsible for retaining ownership of the domain or e-mail
46 | address for as long as any of your products are in use.
47 |
48 | (4) You may choose any string for the textual product identification, as long
49 | as this string is unique within the scope of your textual manufacturer
50 | identification.
51 |
52 | (5) Application side device look-up MUST be based on the textual manufacturer
53 | and product identification in addition to VID/PID matching. The driver
54 | matching MUST be a comparison of the entire strings, NOT a sub-string match.
55 |
56 | (6) For devices which implement a particular USB device class (e.g. HID), the
57 | operating system's default class driver MUST be used. If an operating system
58 | driver for Vendor Class devices is needed, this driver must be libusb or
59 | libusb-win32 (see http://libusb.org/ and
60 | http://libusb-win32.sourceforge.net/).
61 |
62 | Table if IDs for discrimination by textual name:
63 |
64 | PID dec (hex) | VID dec (hex) | Description of use
65 | ==============+===============+============================================
66 | 1500 (0x05dc) | 5824 (0x16c0) | For Vendor Class devices with libusb
67 | --------------+---------------+--------------------------------------------
68 | 1503 (0x05df) | 5824 (0x16c0) | For generic HID class devices (which are
69 | | | NOT mice, keyboards or joysticks)
70 | --------------+---------------+--------------------------------------------
71 | 1505 (0x05e1) | 5824 (0x16c0) | For CDC-ACM class devices (modems)
72 | --------------+---------------+--------------------------------------------
73 | 1508 (0x05e4) | 5824 (0x16c0) | For MIDI class devices
74 | --------------+---------------+--------------------------------------------
75 |
76 | Note that Windows caches the textual product- and vendor-description for
77 | mice, keyboards and joysticks. Name-bsed discrimination is therefore not
78 | recommended for these device classes.
79 |
80 |
81 | =======================================
82 | IDs FOR DISCRIMINATION BY SERIAL NUMBER
83 | =======================================
84 |
85 | If you use one of the IDs listed below, your device and host-side software
86 | must conform to these rules:
87 |
88 | (1) The USB device MUST provide a textual representation of the serial
89 | number. The serial number string MUST be available at least in USB language
90 | 0x0409 (English/US).
91 |
92 | (2) The serial number MUST start with either an Internet domain name (e.g.
93 | "mycompany.com") registered and owned by you, or an e-mail address under your
94 | control (e.g. "myname@gmx.net"), both terminated with a colon (":") character.
95 | You MAY append any string you like for further discrimination of your devices.
96 |
97 | (3) You are responsible for retaining ownership of the domain or e-mail
98 | address for as long as any of your products are in use.
99 |
100 | (5) Application side device look-up MUST be based on the serial number string
101 | in addition to VID/PID matching. The matching must start at the first
102 | character of the serial number string and include the colon character
103 | terminating your domain or e-mail address. It MAY stop anywhere after that.
104 |
105 | (6) For devices which implement a particular USB device class (e.g. HID), the
106 | operating system's default class driver MUST be used. If an operating system
107 | driver for Vendor Class devices is needed, this driver must be libusb or
108 | libusb-win32 (see http://libusb.org/ and
109 | http://libusb-win32.sourceforge.net/).
110 |
111 | Table if IDs for discrimination by serial number string:
112 |
113 | PID dec (hex) | VID dec (hex) | Description of use
114 | ===============+===============+===========================================
115 | 10200 (0x27d8) | 5824 (0x16c0) | For Vendor Class devices with libusb
116 | ---------------+---------------+-------------------------------------------
117 | 10201 (0x27d9) | 5824 (0x16c0) | For generic HID class devices (which are
118 | | | NOT mice, keyboards or joysticks)
119 | ---------------+---------------+-------------------------------------------
120 | 10202 (0x27da) | 5824 (0x16c0) | For USB Mice
121 | ---------------+---------------+-------------------------------------------
122 | 10203 (0x27db) | 5824 (0x16c0) | For USB Keyboards
123 | ---------------+---------------+-------------------------------------------
124 | 10204 (0x27db) | 5824 (0x16c0) | For USB Joysticks
125 | ---------------+---------------+-------------------------------------------
126 | 10205 (0x27dc) | 5824 (0x16c0) | For CDC-ACM class devices (modems)
127 | ---------------+---------------+-------------------------------------------
128 | 10206 (0x27dd) | 5824 (0x16c0) | For MIDI class devices
129 | ---------------+---------------+-------------------------------------------
130 |
131 |
132 | =================
133 | ORIGIN OF USB-IDs
134 | =================
135 |
136 | OBJECTIVE DEVELOPMENT Software GmbH has obtained all VID/PID pairs listed
137 | here from Wouter van Ooijen (see www.voti.nl) for exclusive disposition.
138 | Wouter van Ooijen has obtained the VID from the USB Implementers Forum, Inc.
139 | (see www.usb.org). The VID is registered for the company name "Van Ooijen
140 | Technische Informatica".
141 |
142 |
143 | ==========
144 | DISCLAIMER
145 | ==========
146 |
147 | OBJECTIVE DEVELOPMENT Software GmbH disclaims all liability for any
148 | problems which are caused by the shared use of these VID/PID pairs.
149 |
--------------------------------------------------------------------------------
/libraries/UsbStream/USBID-License.txt:
--------------------------------------------------------------------------------
1 | Royalty-Free Non-Exclusive Use of USB Product-IDs
2 | =================================================
3 |
4 | Version 2009-04-13
5 |
6 | Strictly speaking, this is not a license. You can't give a license to use
7 | a simple number (such as e.g. 1500) for any purpose. This is a set of rules
8 | which should make it possible to build USB devices without the requirement
9 | for individual USB IDs. If you break one of the rules, you will run into
10 | technical problems sooner or later, but you don't risk legal trouble.
11 |
12 |
13 | OBJECTIVE DEVELOPMENT Software GmbH hereby grants you the non-exclusive
14 | right to use four USB.org vendor-ID (VID) / product-ID (PID) pairs with
15 | products based on Objective Development's firmware-only USB driver for
16 | Atmel AVR microcontrollers:
17 |
18 | * VID = 5824 (=0x16c0) / PID = 1500 (=0x5dc) for devices implementing no
19 | USB device class (vendor-class devices with USB class = 0xff). Devices
20 | using this pair will be referred to as "VENDOR CLASS" devices.
21 |
22 | * VID = 5824 (=0x16c0) / PID = 1503 (=0x5df) for HID class devices
23 | (excluding mice and keyboards). Devices using this pair will be referred
24 | to as "HID CLASS" devices.
25 |
26 | * VID = 5824 (=0x16c0) / PID = 1505 (=0x5e1) for CDC class modem devices
27 | Devices using this pair will be referred to as "CDC-ACM CLASS" devices.
28 |
29 | * VID = 5824 (=0x16c0) / PID = 1508 (=0x5e4) for MIDI class devices
30 | Devices using this pair will be referred to as "MIDI CLASS" devices.
31 |
32 | Since the granted right is non-exclusive, the same VID/PID pairs may be
33 | used by many companies and individuals for different products. To avoid
34 | conflicts, your device and host driver software MUST adhere to the rules
35 | outlined below.
36 |
37 | OBJECTIVE DEVELOPMENT Software GmbH has obtained these VID/PID pairs from
38 | Wouter van Ooijen (see www.voti.nl) for exclusive disposition. Wouter van
39 | Ooijen has obtained the VID from the USB Implementers Forum, Inc.
40 | (see www.usb.org). The VID is registered for the company name
41 | "Van Ooijen Technische Informatica".
42 |
43 |
44 | RULES AND RESTRICTIONS
45 | ======================
46 |
47 | (1) The USB device MUST provide a textual representation of the
48 | manufacturer and product identification. The manufacturer identification
49 | MUST be available at least in USB language 0x0409 (English/US).
50 |
51 | (2) The textual manufacturer identification MUST contain either an Internet
52 | domain name (e.g. "mycompany.com") registered and owned by you, or an
53 | e-mail address under your control (e.g. "myname@gmx.net"). You can embed
54 | the domain name or e-mail address in any string you like, e.g. "Objective
55 | Development http://www.obdev.at/vusb/".
56 |
57 | (3) You are responsible for retaining ownership of the domain or e-mail
58 | address for as long as any of your products are in use.
59 |
60 | (4) You may choose any string for the textual product identification, as
61 | long as this string is unique within the scope of your textual manufacturer
62 | identification.
63 |
64 | (5) Matching of device-specific drivers MUST be based on the textual
65 | manufacturer and product identification in addition to the usual VID/PID
66 | matching. This means that operating system features which are based on
67 | VID/PID matching only (e.g. Windows kernel level drivers, automatic actions
68 | when the device is plugged in etc) MUST NOT be used. The driver matching
69 | MUST be a comparison of the entire strings, NOT a sub-string match. For
70 | CDC-ACM CLASS and MIDI CLASS devices, a generic class driver should be used
71 | and the matching is based on the USB device class.
72 |
73 | (6) The extent to which VID/PID matching is allowed for non device-specific
74 | drivers or features depends on the operating system and particular VID/PID
75 | pair used:
76 |
77 | * Mac OS X, Linux, FreeBSD and other Unixes: No VID/PID matching is
78 | required and hence no VID/PID-only matching is allowed at all.
79 |
80 | * Windows: The operating system performs VID/PID matching for the kernel
81 | level driver. You are REQUIRED to use libusb-win32 (see
82 | http://libusb-win32.sourceforge.net/) as the kernel level driver for
83 | VENDOR CLASS devices. HID CLASS devices all use the generic HID class
84 | driver shipped with Windows, except mice and keyboards. You therefore
85 | MUST NOT use any of the shared VID/PID pairs for mice or keyboards.
86 | CDC-ACM CLASS devices require a ".inf" file which matches on the VID/PID
87 | pair. This ".inf" file MUST load the "usbser" driver to configure the
88 | device as modem (COM-port).
89 |
90 | (7) OBJECTIVE DEVELOPMENT Software GmbH disclaims all liability for any
91 | problems which are caused by the shared use of these VID/PID pairs. You
92 | have been warned that the sharing of VID/PID pairs may cause problems. If
93 | you want to avoid them, get your own VID/PID pair for exclusive use.
94 |
95 |
96 | HOW TO IMPLEMENT THESE RULES
97 | ============================
98 |
99 | The following rules are for VENDOR CLASS and HID CLASS devices. CDC-ACM
100 | CLASS and MIDI CLASS devices use the operating system's class driver and
101 | don't need a custom driver.
102 |
103 | The host driver MUST iterate over all devices with the given VID/PID
104 | numbers in their device descriptors and query the string representation for
105 | the manufacturer name in USB language 0x0409 (English/US). It MUST compare
106 | the ENTIRE string with your textual manufacturer identification chosen in
107 | (2) above. A substring search for your domain or e-mail address is NOT
108 | acceptable. The driver MUST NOT touch the device (other than querying the
109 | descriptors) unless the strings match.
110 |
111 | For all USB devices with matching VID/PID and textual manufacturer
112 | identification, the host driver must query the textual product
113 | identification and string-compare it with the name of the product it can
114 | control. It may only initialize the device if the product matches exactly.
115 |
116 | Objective Development provides examples for these matching rules with the
117 | "PowerSwitch" project (using libusb) and with the "Automator" project
118 | (using Windows calls on Windows and libusb on Unix).
119 |
120 |
121 | Technical Notes:
122 | ================
123 |
124 | Sharing the same VID/PID pair among devices is possible as long as ALL
125 | drivers which match the VID/PID also perform matching on the textual
126 | identification strings. This is easy on all operating systems except
127 | Windows, since Windows establishes a static connection between the VID/PID
128 | pair and a kernel level driver. All devices with the same VID/PID pair must
129 | therefore use THE SAME kernel level driver.
130 |
131 | We therefore demand that you use libusb-win32 for VENDOR CLASS devices.
132 | This is a generic kernel level driver which allows all types of USB access
133 | for user space applications. This is only a partial solution of the
134 | problem, though, because different device drivers may come with different
135 | versions of libusb-win32 and they may not work with the libusb version of
136 | the respective other driver. You are therefore encouraged to test your
137 | driver against a broad range of libusb-win32 versions. Do not use new
138 | features in new versions, or check for their existence before you use them.
139 | When a new libusb-win32 becomes available, make sure that your driver is
140 | compatible with it.
141 |
142 | For HID CLASS devices it is necessary that all those devices bind to the
143 | same kernel driver: Microsoft's generic USB HID driver. This is true for
144 | all HID devices except those with a specialized driver. Currently, the only
145 | HIDs with specialized drivers are mice and keyboards. You therefore MUST
146 | NOT use a shared VID/PID with mouse and keyboard devices.
147 |
148 | Sharing the same VID/PID among different products is unusual and probably
149 | violates the USB specification. If you do it, you do it at your own risk.
150 |
151 | To avoid possible incompatibilities, we highly recommend that you get your
152 | own VID/PID pair if you intend to sell your product. Objective
153 | Development's commercial licenses for V-USB include a PID for
154 | unrestricted exclusive use.
155 |
--------------------------------------------------------------------------------
/libraries/UsbStream/UsbStream.cpp:
--------------------------------------------------------------------------------
1 | /* Name: main.c
2 | * Based on project: hid-data, example how to use HID for data transfer
3 | * (Uses modified descriptor and usbFunctionSetup from it.)
4 | * Original author: Christian Starkjohann
5 | * Arduino modifications by: Philip J. Lindsay
6 | * Creation Date: 2008-04-11
7 | * Tabsize: 4
8 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
9 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
10 | * This Revision: $Id: main.c 692 2008-11-07 15:07:40Z cs $
11 | */
12 |
13 | /*
14 | This example should run on most AVRs with only little changes. No special
15 | hardware resources except INT0 are used. You may have to change usbconfig.h for
16 | different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or
17 | at least be connected to INT0 as well.
18 | */
19 |
20 | #include
21 | #include
22 | #include /* for sei() */
23 | #include /* for _delay_ms() */
24 | #include
25 |
26 | #include /* required by usbdrv.h */
27 | #include "usbdrv.h"
28 | #include "oddebug.h" /* This is also an example for using debug macros */
29 |
30 | #include "UsbStream.h"
31 |
32 | // Ring buffer implementation nicked from HardwareSerial.cpp
33 | // TODO: Don't nick it. :)
34 | ring_buffer rx_buffer = { { 0 }, 0, 0 };
35 | ring_buffer tx_buffer = { { 0 }, 0, 0 };
36 |
37 |
38 | inline void store_char(unsigned char c, ring_buffer *the_buffer)
39 | {
40 | int i = (the_buffer->head + 1) % RING_BUFFER_SIZE;
41 |
42 | // if we should be storing the received character into the location
43 | // just before the tail (meaning that the head would advance to the
44 | // current location of the tail), we're about to overflow the buffer
45 | // and so we don't write the character or advance the head.
46 | if (i != the_buffer->tail) {
47 | the_buffer->buffer[the_buffer->head] = c;
48 | the_buffer->head = i;
49 | }
50 | }
51 |
52 | UsbStreamDevice::UsbStreamDevice(ring_buffer *rx_buffer,
53 | ring_buffer *tx_buffer) {
54 | _rx_buffer = rx_buffer;
55 | _tx_buffer = tx_buffer;
56 | }
57 |
58 | void UsbStreamDevice::begin() {
59 | // disable timer 0 overflow interrupt (used for millis)
60 | TIMSK0&=!(1< 250 ms */
70 | _delay_ms(1);
71 | }
72 | usbDeviceConnect();
73 |
74 | sei();
75 | }
76 |
77 | // TODO: Deprecate update
78 | void UsbStreamDevice::update() {
79 | refresh();
80 | }
81 |
82 | void UsbStreamDevice::refresh() {
83 | usbPoll();
84 | }
85 |
86 | int UsbStreamDevice::available() {
87 | /*
88 | */
89 | return (RING_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RING_BUFFER_SIZE;
90 | }
91 |
92 | int UsbStreamDevice::read() {
93 | /*
94 | */
95 | // if the head isn't ahead of the tail, we don't have any characters
96 | if (_rx_buffer->head == _rx_buffer->tail) {
97 | return -1;
98 | } else {
99 | unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
100 | _rx_buffer->tail = (_rx_buffer->tail + 1) % RING_BUFFER_SIZE;
101 | return c;
102 | }
103 | }
104 |
105 | void UsbStreamDevice::write(byte c) {
106 | /*
107 | */
108 | store_char(c, _tx_buffer);
109 | }
110 |
111 | // TODO: Handle this better?
112 | int tx_available() {
113 | /*
114 | */
115 | return (RING_BUFFER_SIZE + tx_buffer.head - tx_buffer.tail) % RING_BUFFER_SIZE;
116 | }
117 |
118 | int tx_read() {
119 | /*
120 | */
121 | // if the head isn't ahead of the tail, we don't have any characters
122 | if (tx_buffer.head == tx_buffer.tail) {
123 | return -1;
124 | } else {
125 | unsigned char c = tx_buffer.buffer[tx_buffer.tail];
126 | tx_buffer.tail = (tx_buffer.tail + 1) % RING_BUFFER_SIZE;
127 | return c;
128 | }
129 | }
130 |
131 |
132 |
133 |
134 | /* ------------------------------------------------------------------------- */
135 | /* ----------------------------- USB interface ----------------------------- */
136 | /* ------------------------------------------------------------------------- */
137 |
138 | #ifdef __cplusplus
139 | extern "C"{
140 | #endif
141 | PROGMEM char usbHidReportDescriptor[22] = { /* USB report descriptor */
142 | 0x06, 0x00, 0xff, // USAGE_PAGE (Generic Desktop)
143 | 0x09, 0x01, // USAGE (Vendor Usage 1)
144 | 0xa1, 0x01, // COLLECTION (Application)
145 | 0x15, 0x00, // LOGICAL_MINIMUM (0)
146 | 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
147 | 0x75, 0x08, // REPORT_SIZE (8)
148 | 0x95, 0x01, // REPORT_COUNT (1)
149 | 0x09, 0x00, // USAGE (Undefined)
150 | 0xb2, 0x02, 0x01, // FEATURE (Data,Var,Abs,Buf)
151 | 0xc0 // END_COLLECTION
152 | };
153 | /* Since we define only one feature report, we don't use report-IDs (which
154 | * would be the first byte of the report). The entire report consists of 1
155 | * opaque data bytes.
156 | */
157 |
158 | /* ------------------------------------------------------------------------- */
159 |
160 | usbMsgLen_t usbFunctionSetup(uchar data[8])
161 | {
162 | usbRequest_t *rq = (usbRequest_t*)((void *)data);
163 |
164 | if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* HID class request */
165 | if(rq->bRequest == USBRQ_HID_GET_REPORT){ /* wValue: ReportType (highbyte), ReportID (lowbyte) */
166 | /* since we have only one report type, we can ignore the report-ID */
167 | static uchar dataBuffer[1]; /* buffer must stay valid when usbFunctionSetup returns */
168 | if (tx_available()) {
169 | dataBuffer[0] = tx_read();
170 | usbMsgPtr = dataBuffer; /* tell the driver which data to return */
171 | return 1; /* tell the driver to send 1 byte */
172 | } else {
173 | // Drop through to return 0 (which will stall the request?)
174 | }
175 | }else if(rq->bRequest == USBRQ_HID_SET_REPORT){
176 | /* since we have only one report type, we can ignore the report-ID */
177 |
178 | // TODO: Check race issues?
179 | store_char(rq->wIndex.bytes[0], &rx_buffer);
180 |
181 | }
182 | }else{
183 | /* ignore vendor type requests, we don't use any */
184 | }
185 | return 0;
186 | }
187 | #ifdef __cplusplus
188 | } // extern "C"
189 | #endif
190 |
191 | UsbStreamDevice UsbStream = UsbStreamDevice(&rx_buffer, &tx_buffer);
192 |
193 |
194 |
--------------------------------------------------------------------------------
/libraries/UsbStream/UsbStream.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Based on Obdev's AVRUSB code and under the same license.
3 | *
4 | * TODO: Make a proper file header. :-)
5 | */
6 | #ifndef __UsbStream_h__
7 | #define __UsbStream_h__
8 |
9 | #include
10 | #include
11 | #include
12 |
13 | #include "usbdrv.h"
14 |
15 | // TODO: Work around Arduino 12 issues better.
16 | //#include
17 | //#undef int()
18 |
19 | typedef uint8_t byte;
20 |
21 | #include /* for _delay_ms() */
22 |
23 | #define RING_BUFFER_SIZE 8
24 |
25 |
26 | struct ring_buffer {
27 | unsigned char buffer[RING_BUFFER_SIZE];
28 | int head;
29 | int tail;
30 | };
31 |
32 |
33 |
34 |
35 |
36 | class UsbStreamDevice {
37 | private:
38 | ring_buffer *_rx_buffer;
39 | ring_buffer *_tx_buffer;
40 |
41 | public:
42 | UsbStreamDevice (ring_buffer *rx_buffer, ring_buffer *tx_buffer);
43 |
44 | void begin();
45 |
46 | // TODO: Deprecate update
47 | void update();
48 |
49 | void refresh();
50 |
51 | int available();
52 | int read();
53 | void write(byte c);
54 | };
55 |
56 | extern UsbStreamDevice UsbStream;
57 |
58 | #endif // __UsbStream_h__
59 |
--------------------------------------------------------------------------------
/libraries/UsbStream/asmcommon.inc:
--------------------------------------------------------------------------------
1 | /* Name: asmcommon.inc
2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2007-11-05
5 | * Tabsize: 4
6 | * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | * Revision: $Id$
9 | */
10 |
11 | /* Do not link this file! Link usbdrvasm.S instead, which includes the
12 | * appropriate implementation!
13 | */
14 |
15 | /*
16 | General Description:
17 | This file contains assembler code which is shared among the USB driver
18 | implementations for different CPU cocks. Since the code must be inserted
19 | in the middle of the module, it's split out into this file and #included.
20 |
21 | Jump destinations called from outside:
22 | sofError: Called when no start sequence was found.
23 | se0: Called when a package has been successfully received.
24 | overflow: Called when receive buffer overflows.
25 | doReturn: Called after sending data.
26 |
27 | Outside jump destinations used by this module:
28 | waitForJ: Called to receive an already arriving packet.
29 | sendAckAndReti:
30 | sendNakAndReti:
31 | sendCntAndReti:
32 | usbSendAndReti:
33 |
34 | The following macros must be defined before this file is included:
35 | .macro POP_STANDARD
36 | .endm
37 | .macro POP_RETI
38 | .endm
39 | */
40 |
41 | #define token x1
42 |
43 | overflow:
44 | ldi x2, 1< 0
14 |
15 | #warning "Never compile production devices with debugging enabled"
16 |
17 | static void uartPutc(char c)
18 | {
19 | while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */
20 | ODDBG_UDR = c;
21 | }
22 |
23 | static uchar hexAscii(uchar h)
24 | {
25 | h &= 0xf;
26 | if(h >= 10)
27 | h += 'a' - (uchar)10 - '0';
28 | h += '0';
29 | return h;
30 | }
31 |
32 | static void printHex(uchar c)
33 | {
34 | uartPutc(hexAscii(c >> 4));
35 | uartPutc(hexAscii(c));
36 | }
37 |
38 | void odDebug(uchar prefix, uchar *data, uchar len)
39 | {
40 | printHex(prefix);
41 | uartPutc(':');
42 | while(len--){
43 | uartPutc(' ');
44 | printHex(*data++);
45 | }
46 | uartPutc('\r');
47 | uartPutc('\n');
48 | }
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/libraries/UsbStream/oddebug.h:
--------------------------------------------------------------------------------
1 | /* Name: oddebug.h
2 | * Project: AVR library
3 | * Author: Christian Starkjohann
4 | * Creation Date: 2005-01-16
5 | * Tabsize: 4
6 | * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 | * This Revision: $Id: oddebug.h 692 2008-11-07 15:07:40Z cs $
9 | */
10 |
11 | #ifndef __oddebug_h_included__
12 | #define __oddebug_h_included__
13 |
14 | /*
15 | General Description:
16 | This module implements a function for debug logs on the serial line of the
17 | AVR microcontroller. Debugging can be configured with the define
18 | 'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging
19 | calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is
20 | 2, DBG1 and DBG2 logs will be printed.
21 |
22 | A debug log consists of a label ('prefix') to indicate which debug log created
23 | the output and a memory block to dump in hex ('data' and 'len').
24 | */
25 |
26 |
27 | #ifndef F_CPU
28 | # define F_CPU 12000000 /* 12 MHz */
29 | #endif
30 |
31 | /* make sure we have the UART defines: */
32 | #include "usbportability.h"
33 |
34 | #ifndef uchar
35 | # define uchar unsigned char
36 | #endif
37 |
38 | #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */
39 | # warning "Debugging disabled because device has no UART"
40 | # undef DEBUG_LEVEL
41 | #endif
42 |
43 | #ifndef DEBUG_LEVEL
44 | # define DEBUG_LEVEL 0
45 | #endif
46 |
47 | /* ------------------------------------------------------------------------- */
48 |
49 | #if DEBUG_LEVEL > 0
50 | # define DBG1(prefix, data, len) odDebug(prefix, data, len)
51 | #else
52 | # define DBG1(prefix, data, len)
53 | #endif
54 |
55 | #if DEBUG_LEVEL > 1
56 | # define DBG2(prefix, data, len) odDebug(prefix, data, len)
57 | #else
58 | # define DBG2(prefix, data, len)
59 | #endif
60 |
61 | /* ------------------------------------------------------------------------- */
62 |
63 | #if DEBUG_LEVEL > 0
64 | extern void odDebug(uchar prefix, uchar *data, uchar len);
65 |
66 | /* Try to find our control registers; ATMEL likes to rename these */
67 |
68 | #if defined UBRR
69 | # define ODDBG_UBRR UBRR
70 | #elif defined UBRRL
71 | # define ODDBG_UBRR UBRRL
72 | #elif defined UBRR0
73 | # define ODDBG_UBRR UBRR0
74 | #elif defined UBRR0L
75 | # define ODDBG_UBRR UBRR0L
76 | #endif
77 |
78 | #if defined UCR
79 | # define ODDBG_UCR UCR
80 | #elif defined UCSRB
81 | # define ODDBG_UCR UCSRB
82 | #elif defined UCSR0B
83 | # define ODDBG_UCR UCSR0B
84 | #endif
85 |
86 | #if defined TXEN
87 | # define ODDBG_TXEN TXEN
88 | #else
89 | # define ODDBG_TXEN TXEN0
90 | #endif
91 |
92 | #if defined USR
93 | # define ODDBG_USR USR
94 | #elif defined UCSRA
95 | # define ODDBG_USR UCSRA
96 | #elif defined UCSR0A
97 | # define ODDBG_USR UCSR0A
98 | #endif
99 |
100 | #if defined UDRE
101 | # define ODDBG_UDRE UDRE
102 | #else
103 | # define ODDBG_UDRE UDRE0
104 | #endif
105 |
106 | #if defined UDR
107 | # define ODDBG_UDR UDR
108 | #elif defined UDR0
109 | # define ODDBG_UDR UDR0
110 | #endif
111 |
112 | static inline void odDebugInit(void)
113 | {
114 | ODDBG_UCR |= (1<
39 | #ifndef __IAR_SYSTEMS_ASM__
40 | # include
41 | #endif
42 |
43 | #define __attribute__(arg) /* not supported on IAR */
44 |
45 | #ifdef __IAR_SYSTEMS_ASM__
46 | # define __ASSEMBLER__ /* IAR does not define standard macro for asm */
47 | #endif
48 |
49 | #ifdef __HAS_ELPM__
50 | # define PROGMEM __farflash
51 | #else
52 | # define PROGMEM __flash
53 | #endif
54 |
55 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr))
56 |
57 | /* The following definitions are not needed by the driver, but may be of some
58 | * help if you port a gcc based project to IAR.
59 | */
60 | #define cli() __disable_interrupt()
61 | #define sei() __enable_interrupt()
62 | #define wdt_reset() __watchdog_reset()
63 | #define _BV(x) (1 << (x))
64 |
65 | /* assembler compatibility macros */
66 | #define nop2 rjmp $+2 /* jump to next instruction */
67 | #define XL r26
68 | #define XH r27
69 | #define YL r28
70 | #define YH r29
71 | #define ZL r30
72 | #define ZH r31
73 | #define lo8(x) LOW(x)
74 | #define hi8(x) (((x)>>8) & 0xff) /* not HIGH to allow XLINK to make a proper range check */
75 |
76 | /* Depending on the device you use, you may get problems with the way usbdrv.h
77 | * handles the differences between devices. Since IAR does not use #defines
78 | * for MCU registers, we can't check for the existence of a particular
79 | * register with an #ifdef. If the autodetection mechanism fails, include
80 | * definitions for the required USB_INTR_* macros in your usbconfig.h. See
81 | * usbconfig-prototype.h and usbdrv.h for details.
82 | */
83 |
84 | /* ------------------------------------------------------------------------- */
85 | #elif __CODEVISIONAVR__ /* check for CodeVision AVR */
86 | /* ------------------------------------------------------------------------- */
87 | /* This port is not working (yet) */
88 |
89 | /* #define F_CPU _MCU_CLOCK_FREQUENCY_ seems to be defined automatically */
90 |
91 | #include
92 | #include
93 |
94 | #define __attribute__(arg) /* not supported on IAR */
95 |
96 | #define PROGMEM __flash
97 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr))
98 |
99 | #ifndef __ASSEMBLER__
100 | static inline void cli(void)
101 | {
102 | #asm("cli");
103 | }
104 | static inline void sei(void)
105 | {
106 | #asm("sei");
107 | }
108 | #endif
109 | #define _delay_ms(t) delay_ms(t)
110 | #define _BV(x) (1 << (x))
111 | #define USB_CFG_USE_SWITCH_STATEMENT 1 /* macro for if() cascase fails for unknown reason */
112 |
113 | #define macro .macro
114 | #define endm .endmacro
115 | #define nop2 rjmp .+0 /* jump to next instruction */
116 |
117 | /* ------------------------------------------------------------------------- */
118 | #else /* default development environment is avr-gcc/avr-libc */
119 | /* ------------------------------------------------------------------------- */
120 |
121 | #include
122 | #ifdef __ASSEMBLER__
123 | # define _VECTOR(N) __vector_ ## N /* io.h does not define this for asm */
124 | #else
125 | # include
126 | #endif
127 |
128 | #define USB_READ_FLASH(addr) pgm_read_byte(addr)
129 |
130 | #define macro .macro
131 | #define endm .endm
132 | #define nop2 rjmp .+0 /* jump to next instruction */
133 |
134 | #endif /* development environment */
135 |
136 | /* for conveniecne, ensure that PRG_RDB exists */
137 | #ifndef PRG_RDB
138 | # define PRG_RDB(addr) USB_READ_FLASH(addr)
139 | #endif
140 | #endif /* __usbportability_h_INCLUDED__ */
141 |
--------------------------------------------------------------------------------