├── Hardware ├── BOM.txt ├── Dual-NES-Adapter.gif ├── Dual-SNES-Adapter.gif ├── Dual-SNES-NES-Adapter.gif ├── EAGLE │ ├── DualJoyDivision.brd │ ├── DualJoyDivision.sch │ ├── JoyDivision.brd │ └── JoyDivision.sch ├── Information.txt ├── License.txt ├── NES-Adapter.gif ├── SNES-Adapter.gif ├── Schematic-Dual.png └── Schematic.png ├── README.md ├── Source ├── License.txt ├── Makefile ├── Makefile-Dual ├── amstrad.c ├── bootloader │ ├── Makefile │ ├── bootloaderconfig.h │ ├── flashme.sh │ ├── how_to_program.txt │ ├── main.c │ ├── usbconfig.h │ └── usbdrv │ │ ├── Changelog.txt │ │ ├── CommercialLicense.txt │ │ ├── License.txt │ │ ├── Readme.txt │ │ ├── USB-ID-FAQ.txt │ │ ├── USB-IDs-for-free.txt │ │ ├── asmcommon.inc │ │ ├── oddebug.c │ │ ├── oddebug.h │ │ ├── usbconfig-prototype.h │ │ ├── usbdrv.c │ │ ├── usbdrv.h │ │ ├── usbdrvasm.S │ │ ├── usbdrvasm.asm │ │ ├── usbdrvasm12.inc │ │ ├── usbdrvasm128.inc │ │ ├── usbdrvasm15.inc │ │ ├── usbdrvasm16.inc │ │ ├── usbdrvasm165.inc │ │ ├── usbdrvasm18-crc.inc │ │ ├── usbdrvasm20.inc │ │ └── usbportability.h ├── cd32.c ├── joystick.c ├── msx.c ├── nes.c ├── sega.c ├── snes.c ├── snesnes.c ├── usbconfig.h └── usbdrv │ ├── Changelog.txt │ ├── CommercialLicense.txt │ ├── License.txt │ ├── Readme.txt │ ├── USB-ID-FAQ.txt │ ├── USB-IDs-for-free.txt │ ├── USBID-License.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 │ ├── usbdrvasm20.inc │ └── usbportability.h └── bootloadHID └── commandline ├── Makefile ├── Makefile.MorphOS ├── Makefile.windows ├── bootloadHID.exe ├── bootloadHID_MorphOS ├── bootloadHID_raspi ├── debug.h ├── hidsdi.h ├── main.c ├── usb-libusb.c ├── usb-morphos.c ├── usb-windows.c ├── usbcalls.c └── usbcalls.h /Hardware/BOM.txt: -------------------------------------------------------------------------------- 1 | Orginal JoyDivision : 2 | 3 | Qty Value Device Package Parts Description 4 | 1 M09D M09D X2 SUB-D 5 | 1 1.5k R-EU_M0805 M0805 R3 RESISTOR, European symbol 6 | 1 12M XTAL/S QS Q1 CRYSTAL 7 | 2 27p C-EUC0805 C0805 C1, C2 CAPACITOR, European symbol 8 | 2 3.6V ZENER-DIODESOD80C SOD80C D1, D2 Z-Diode 9 | 2 68 R-EU_M0805 M0805 R1, R2 RESISTOR, European symbol 10 | 1 MEGA8-AI MEGA8-AI TQFP32-08 IC1 MICROCONTROLLER AVR ATMEGA8-8AU 11 | 1 USB-A-H USB-A-H USB-A-H JP1 USB Connectors 12 | 13 | 14 | Dual JoyDivision : 15 | 16 | Qty Value Device Package Parts Description 17 | 1 DB25D M25D X1 Various DB25 connectors 18 | 1 M04PTH 1X04 * Solder Pads 19 | 1 1.5k R-EU_M0805 M0805 R3 RESISTOR, European symbol 20 | 1 12M XTAL/S QS Q1 CRYSTAL 21 | 2 27p C-EUC0805 C0805 C1, C2 CAPACITOR, European symbol 22 | 2 3.6V ZENER-DIODESOD80C SOD80C D1, D2 Z-Diode 23 | 2 68 R-EU_M0805 M0805 R1, R2 RESISTOR, European symbol 24 | 1 MEGA8-AI MEGA8-AI TQFP32-08 IC1 MICROCONTROLLER 25 | -------------------------------------------------------------------------------- /Hardware/Dual-NES-Adapter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Hardware/Dual-NES-Adapter.gif -------------------------------------------------------------------------------- /Hardware/Dual-SNES-Adapter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Hardware/Dual-SNES-Adapter.gif -------------------------------------------------------------------------------- /Hardware/Dual-SNES-NES-Adapter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Hardware/Dual-SNES-NES-Adapter.gif -------------------------------------------------------------------------------- /Hardware/Information.txt: -------------------------------------------------------------------------------- 1 | If you like to order an allready design PCB (using the EAGLE-files), 2 | I've prepared a link to OSH park which delivers quick and with good quality and great price : 3 | 4 | * JoyDivision - https://www.oshpark.com/shared_projects/wz2Vsnir 5 | * Dual JoyDivision - https://www.oshpark.com/shared_projects/gp5bRPie 6 | 7 | // Stefan Blixth - stefan@onyxsoft.se 8 | -------------------------------------------------------------------------------- /Hardware/NES-Adapter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Hardware/NES-Adapter.gif -------------------------------------------------------------------------------- /Hardware/SNES-Adapter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Hardware/SNES-Adapter.gif -------------------------------------------------------------------------------- /Hardware/Schematic-Dual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Hardware/Schematic-Dual.png -------------------------------------------------------------------------------- /Hardware/Schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Hardware/Schematic.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # joydivision 2 | Source for the digital joystick adapter JoyDivision - http://www.onyxsoft.se/joydivision.html 3 | -------------------------------------------------------------------------------- /Source/Makefile: -------------------------------------------------------------------------------- 1 | # Name: Makefile 2 | # Project: hid-mouse example 3 | # Author: Christian Starkjohann 4 | # Creation Date: 2008-04-07 5 | # Tabsize: 4 6 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH 7 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 8 | 9 | DEVICE = atmega8 10 | F_CPU = 12000000 # in Hz 11 | FUSE_L = 0xff 12 | FUSE_H = 0xc9 13 | AVRDUDE = avrdude -c usbasp -p $(DEVICE) # edit this line for your programmer 14 | 15 | #CFLAGS options : -DEDUARANA = Use this flag to build a firmware compatible with Edu Aranas joystick adapter - 16 | #CFLAGS options : -DTHEC64 = Using this if you would like to make the HID device compatible with the THEC64 emulator/computer 17 | #CFLAGS options : -DTHEA500 = Using this if you would like to make the HID device compatible with the THEA500 mini emulator/computer 18 | 19 | CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 20 | OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o 21 | JOY_OBJ = $(OBJECTS) joystick.o 22 | CD32_OBJ = $(OBJECTS) cd32.o 23 | SEGA_OBJ = $(OBJECTS) sega.o 24 | NES_OBJ = $(OBJECTS) nes.o 25 | SNES_OBJ = $(OBJECTS) snes.o 26 | MSX_OBJ = $(OBJECTS) msx.o 27 | AMST_OBJ = $(OBJECTS) amstrad.o 28 | 29 | COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE) 30 | 31 | ############################################################################## 32 | # Fuse values for particular devices 33 | ############################################################################## 34 | # If your device is not listed here, go to 35 | # http://palmavr.sourceforge.net/cgi-bin/fc.cgi 36 | # and choose options for external crystal clock and no clock divider 37 | # 38 | ################################## ATMega8 ################################## 39 | # ATMega8 FUSE_L (Fuse low byte): 40 | # 0x9f = 1 0 0 1 1 1 1 1 41 | # ^ ^ \ / \--+--/ 42 | # | | | +------- CKSEL 3..0 (external >8M crystal) 43 | # | | +--------------- SUT 1..0 (crystal osc, BOD enabled) 44 | # | +------------------ BODEN (BrownOut Detector enabled) 45 | # +-------------------- BODLEVEL (2.7V) 46 | # ATMega8 FUSE_H (Fuse high byte): 47 | # 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000) 48 | # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0 49 | # | | | | | +-------- BOOTSZ1 50 | # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase) 51 | # | | | +-------------- CKOPT (full output swing) 52 | # | | +---------------- SPIEN (allow serial programming) 53 | # | +------------------ WDTON (WDT not always on) 54 | # +-------------------- RSTDISBL (reset pin is enabled) 55 | # 56 | ############################## ATMega48/88/168 ############################## 57 | # ATMega*8 FUSE_L (Fuse low byte): 58 | # 0xdf = 1 1 0 1 1 1 1 1 59 | # ^ ^ \ / \--+--/ 60 | # | | | +------- CKSEL 3..0 (external >8M crystal) 61 | # | | +--------------- SUT 1..0 (crystal osc, BOD enabled) 62 | # | +------------------ CKOUT (if 0: Clock output enabled) 63 | # +-------------------- CKDIV8 (if 0: divide by 8) 64 | # ATMega*8 FUSE_H (Fuse high byte): 65 | # 0xde = 1 1 0 1 1 1 1 0 66 | # ^ ^ ^ ^ ^ \-+-/ 67 | # | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V) 68 | # | | | | + --------- EESAVE (preserve EEPROM over chip erase) 69 | # | | | +-------------- WDTON (if 0: watchdog always on) 70 | # | | +---------------- SPIEN (allow serial programming) 71 | # | +------------------ DWEN (debug wire enable) 72 | # +-------------------- RSTDISBL (reset pin is enabled) 73 | # 74 | ############################## ATTiny25/45/85 ############################### 75 | # ATMega*5 FUSE_L (Fuse low byte): 76 | # 0xef = 1 1 1 0 1 1 1 1 77 | # ^ ^ \+/ \--+--/ 78 | # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) 79 | # | | +--------------- SUT 1..0 (BOD enabled, fast rising power) 80 | # | +------------------ CKOUT (clock output on CKOUT pin -> disabled) 81 | # +-------------------- CKDIV8 (divide clock by 8 -> don't divide) 82 | # ATMega*5 FUSE_H (Fuse high byte): 83 | # 0xdd = 1 1 0 1 1 1 0 1 84 | # ^ ^ ^ ^ ^ \-+-/ 85 | # | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V) 86 | # | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved) 87 | # | | | +-------------- WDTON (watchdog timer always on -> disable) 88 | # | | +---------------- SPIEN (enable serial programming -> enabled) 89 | # | +------------------ DWEN (debug wire enable) 90 | # +-------------------- RSTDISBL (disable external reset -> enabled) 91 | # 92 | ################################ ATTiny2313 ################################# 93 | # ATTiny2313 FUSE_L (Fuse low byte): 94 | # 0xef = 1 1 1 0 1 1 1 1 95 | # ^ ^ \+/ \--+--/ 96 | # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) 97 | # | | +--------------- SUT 1..0 (BOD enabled, fast rising power) 98 | # | +------------------ CKOUT (clock output on CKOUT pin -> disabled) 99 | # +-------------------- CKDIV8 (divide clock by 8 -> don't divide) 100 | # ATTiny2313 FUSE_H (Fuse high byte): 101 | # 0xdb = 1 1 0 1 1 0 1 1 102 | # ^ ^ ^ ^ \-+-/ ^ 103 | # | | | | | +---- RSTDISBL (disable external reset -> enabled) 104 | # | | | | +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V) 105 | # | | | +-------------- WDTON (watchdog timer always on -> disable) 106 | # | | +---------------- SPIEN (enable serial programming -> enabled) 107 | # | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved) 108 | # +-------------------- DWEN (debug wire enable) 109 | 110 | 111 | # symbolic targets: 112 | help: 113 | @echo "This Makefile has no default rule. Use one of the following:" 114 | @echo "make joystick ..... to build joystick.hex" 115 | @echo "make cd32 ......... to build cd32.hex" 116 | @echo "make sega ......... to build sega.hex" 117 | @echo "make nes .......... to build nes.hex" 118 | @echo "make snes ......... to build snes.hex" 119 | @echo "make msx .......... to build msx.hex" 120 | @echo "make amstrad ...... to build amstrad.hex" 121 | @echo "make all .......... to build joystick.hex, cd32.hex, sega.hex, nes.hex, snes.hex, msx.hex & amstrad.hex" 122 | @echo "=======================================================================================================" 123 | @echo "make fuse ......... to flash the fuses" 124 | @echo "make flashjoy ..... to flash the Joystick firmware" 125 | @echo "make flashcd32 .... to flash the CD32 firmware" 126 | @echo "make flashsega .... to flash the Sega firmware" 127 | @echo "make flashnes ..... to flash the NES firmware" 128 | @echo "make flashsnes .... to flash the SNES firmware" 129 | @echo "make flashmsx ..... to flash the MSX firmware" 130 | @echo "make flashamstrad . to flash the Amstrad firmware" 131 | @echo "make clean ........ to delete objects and hex file" 132 | 133 | all: joystick.hex cd32.hex sega.hex nes.hex snes.hex msx.hex amstrad.hex 134 | 135 | joystick: joystick.hex 136 | 137 | cd32: cd32.hex 138 | 139 | sega: sega.hex 140 | 141 | nes: nes.hex 142 | 143 | snes: snes.hex 144 | 145 | msx: msx.hex 146 | 147 | amstrad: amstrad.hex 148 | 149 | # rule for programming fuse bits: 150 | fuse: 151 | @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \ 152 | { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; } 153 | $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m 154 | 155 | # rule for uploading firmware: 156 | flashjoy: joystick.hex 157 | $(AVRDUDE) -U flash:w:joystick.hex:i 158 | 159 | flashcd32: cd32.hex 160 | $(AVRDUDE) -U flash:w:cd32.hex:i 161 | 162 | flashsega: sega.hex 163 | $(AVRDUDE) -U flash:w:sega.hex:i 164 | 165 | flashnes: nes.hex 166 | $(AVRDUDE) -U flash:w:nes.hex:i 167 | 168 | flashsnes: snes.hex 169 | $(AVRDUDE) -U flash:w:snes.hex:i 170 | 171 | flashmsx: msx.hex 172 | $(AVRDUDE) -U flash:w:msx.hex:i 173 | 174 | flashamstrad: amstrad.hex 175 | $(AVRDUDE) -U flash:w:amstrad.hex:i 176 | 177 | # rule for deleting dependent files (those which can be built by Make): 178 | clean: 179 | rm -f *.hex *.lst *.obj *.cof *.list *.map *.eep.hex *.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s 180 | 181 | # Generic rule for compiling C files: 182 | .c.o: 183 | $(COMPILE) -c $< -o $@ 184 | 185 | # Generic rule for assembling Assembler source files: 186 | .S.o: 187 | $(COMPILE) -x assembler-with-cpp -c $< -o $@ 188 | # "-x assembler-with-cpp" should not be necessary since this is the default 189 | # file type for the .S (with capital S) extension. However, upper case 190 | # characters are not always preserved on Windows. To ensure WinAVR 191 | # compatibility define the file type manually. 192 | 193 | # Generic rule for compiling C to assembler, used for debugging only. 194 | .c.s: 195 | $(COMPILE) -S $< -o $@ 196 | 197 | # file targets: 198 | 199 | # Since we don't want to ship the driver multipe times, we copy it into this project: 200 | usbdrv: 201 | cp -r ../../../usbdrv . 202 | 203 | joystick.elf: usbdrv $(JOY_OBJ) 204 | $(COMPILE) -o joystick.elf $(JOY_OBJ) 205 | 206 | cd32.elf: usbdrv $(CD32_OBJ) 207 | $(COMPILE) -o cd32.elf $(CD32_OBJ) 208 | 209 | sega.elf: usbdrv $(SEGA_OBJ) 210 | $(COMPILE) -o sega.elf $(SEGA_OBJ) 211 | 212 | nes.elf: usbdrv $(NES_OBJ) 213 | $(COMPILE) -o nes.elf $(NES_OBJ) 214 | 215 | snes.elf: usbdrv $(SNES_OBJ) 216 | $(COMPILE) -o snes.elf $(SNES_OBJ) 217 | 218 | msx.elf: usbdrv $(MSX_OBJ) 219 | $(COMPILE) -o msx.elf $(MSX_OBJ) 220 | 221 | amstrad.elf: usbdrv $(AMST_OBJ) 222 | $(COMPILE) -o amstrad.elf $(AMST_OBJ) 223 | 224 | joystick.hex: joystick.elf 225 | rm -f joystick.hex joystick.eep.hex 226 | avr-objcopy -j .text -j .data -O ihex joystick.elf joystick.hex 227 | avr-size joystick.hex 228 | 229 | cd32.hex: cd32.elf 230 | rm -f cd32.hex cd32.eep.hex 231 | avr-objcopy -j .text -j .data -O ihex cd32.elf cd32.hex 232 | avr-size cd32.hex 233 | 234 | sega.hex: sega.elf 235 | rm -f sega.hex sega.eep.hex 236 | avr-objcopy -j .text -j .data -O ihex sega.elf sega.hex 237 | avr-size sega.hex 238 | 239 | nes.hex: nes.elf 240 | rm -f nes.hex nes.eep.hex 241 | avr-objcopy -j .text -j .data -O ihex nes.elf nes.hex 242 | avr-size nes.hex 243 | 244 | snes.hex: snes.elf 245 | rm -f snes.hex snes.eep.hex 246 | avr-objcopy -j .text -j .data -O ihex snes.elf snes.hex 247 | avr-size snes.hex 248 | 249 | msx.hex: msx.elf 250 | rm -f msx.hex msx.eep.hex 251 | avr-objcopy -j .text -j .data -O ihex msx.elf msx.hex 252 | avr-size msx.hex 253 | 254 | amstrad.hex: amstrad.elf 255 | rm -f amstrad.hex amstrad.eep.hex 256 | avr-objcopy -j .text -j .data -O ihex amstrad.elf amstrad.hex 257 | avr-size amstrad.hex 258 | 259 | cpp: 260 | $(COMPILE) -E joystick.c 261 | $(COMPILE) -E cd32.c 262 | $(COMPILE) -E sega.c 263 | $(COMPILE) -E nes.c 264 | $(COMPILE) -E snes.c 265 | $(COMPILE) -E msx.c 266 | $(COMPILE) -E amstrad.c 267 | -------------------------------------------------------------------------------- /Source/Makefile-Dual: -------------------------------------------------------------------------------- 1 | # Name: Makefile 2 | # Project: hid-mouse example 3 | # Author: Christian Starkjohann 4 | # Creation Date: 2008-04-07 5 | # Tabsize: 4 6 | # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH 7 | # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 8 | 9 | DEVICE = atmega8 10 | F_CPU = 12000000 # in Hz 11 | FUSE_L = 0xff 12 | FUSE_H = 0xc9 13 | AVRDUDE = avrdude -c usbasp -p $(DEVICE) # edit this line for your programmer 14 | 15 | #CFLAGS options : -DDUAL_JOYDIVISION = Used for enable the second port on the JoyDivision adapter 16 | #CFLAGS options : -DTHEC64 = Using this if you would like to make the HID device compatible with the THEC64 emulator/computer 17 | #CFLAGS options : -DTHEA500 = Using this if you would like to make the HID device compatible with the THEA500 mini emulator/computer 18 | 19 | CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 -DDUAL_JOYDIVISION 20 | OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o 21 | JOY_OBJ = $(OBJECTS) joystick.o 22 | CD32_OBJ = $(OBJECTS) cd32.o 23 | SEGA_OBJ = $(OBJECTS) sega.o 24 | NES_OBJ = $(OBJECTS) nes.o 25 | SNES_OBJ = $(OBJECTS) snes.o 26 | MSX_OBJ = $(OBJECTS) msx.o 27 | AMST_OBJ = $(OBJECTS) amstrad.o 28 | NINT_OBJ = $(OBJECTS) snesnes.o 29 | 30 | COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE) 31 | 32 | ############################################################################## 33 | # Fuse values for particular devices 34 | ############################################################################## 35 | # If your device is not listed here, go to 36 | # http://palmavr.sourceforge.net/cgi-bin/fc.cgi 37 | # and choose options for external crystal clock and no clock divider 38 | # 39 | ################################## ATMega8 ################################## 40 | # ATMega8 FUSE_L (Fuse low byte): 41 | # 0x9f = 1 0 0 1 1 1 1 1 42 | # ^ ^ \ / \--+--/ 43 | # | | | +------- CKSEL 3..0 (external >8M crystal) 44 | # | | +--------------- SUT 1..0 (crystal osc, BOD enabled) 45 | # | +------------------ BODEN (BrownOut Detector enabled) 46 | # +-------------------- BODLEVEL (2.7V) 47 | # ATMega8 FUSE_H (Fuse high byte): 48 | # 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000) 49 | # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0 50 | # | | | | | +-------- BOOTSZ1 51 | # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase) 52 | # | | | +-------------- CKOPT (full output swing) 53 | # | | +---------------- SPIEN (allow serial programming) 54 | # | +------------------ WDTON (WDT not always on) 55 | # +-------------------- RSTDISBL (reset pin is enabled) 56 | # 57 | ############################## ATMega48/88/168 ############################## 58 | # ATMega*8 FUSE_L (Fuse low byte): 59 | # 0xdf = 1 1 0 1 1 1 1 1 60 | # ^ ^ \ / \--+--/ 61 | # | | | +------- CKSEL 3..0 (external >8M crystal) 62 | # | | +--------------- SUT 1..0 (crystal osc, BOD enabled) 63 | # | +------------------ CKOUT (if 0: Clock output enabled) 64 | # +-------------------- CKDIV8 (if 0: divide by 8) 65 | # ATMega*8 FUSE_H (Fuse high byte): 66 | # 0xde = 1 1 0 1 1 1 1 0 67 | # ^ ^ ^ ^ ^ \-+-/ 68 | # | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V) 69 | # | | | | + --------- EESAVE (preserve EEPROM over chip erase) 70 | # | | | +-------------- WDTON (if 0: watchdog always on) 71 | # | | +---------------- SPIEN (allow serial programming) 72 | # | +------------------ DWEN (debug wire enable) 73 | # +-------------------- RSTDISBL (reset pin is enabled) 74 | # 75 | ############################## ATTiny25/45/85 ############################### 76 | # ATMega*5 FUSE_L (Fuse low byte): 77 | # 0xef = 1 1 1 0 1 1 1 1 78 | # ^ ^ \+/ \--+--/ 79 | # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) 80 | # | | +--------------- SUT 1..0 (BOD enabled, fast rising power) 81 | # | +------------------ CKOUT (clock output on CKOUT pin -> disabled) 82 | # +-------------------- CKDIV8 (divide clock by 8 -> don't divide) 83 | # ATMega*5 FUSE_H (Fuse high byte): 84 | # 0xdd = 1 1 0 1 1 1 0 1 85 | # ^ ^ ^ ^ ^ \-+-/ 86 | # | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V) 87 | # | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved) 88 | # | | | +-------------- WDTON (watchdog timer always on -> disable) 89 | # | | +---------------- SPIEN (enable serial programming -> enabled) 90 | # | +------------------ DWEN (debug wire enable) 91 | # +-------------------- RSTDISBL (disable external reset -> enabled) 92 | # 93 | ################################ ATTiny2313 ################################# 94 | # ATTiny2313 FUSE_L (Fuse low byte): 95 | # 0xef = 1 1 1 0 1 1 1 1 96 | # ^ ^ \+/ \--+--/ 97 | # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz) 98 | # | | +--------------- SUT 1..0 (BOD enabled, fast rising power) 99 | # | +------------------ CKOUT (clock output on CKOUT pin -> disabled) 100 | # +-------------------- CKDIV8 (divide clock by 8 -> don't divide) 101 | # ATTiny2313 FUSE_H (Fuse high byte): 102 | # 0xdb = 1 1 0 1 1 0 1 1 103 | # ^ ^ ^ ^ \-+-/ ^ 104 | # | | | | | +---- RSTDISBL (disable external reset -> enabled) 105 | # | | | | +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V) 106 | # | | | +-------------- WDTON (watchdog timer always on -> disable) 107 | # | | +---------------- SPIEN (enable serial programming -> enabled) 108 | # | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved) 109 | # +-------------------- DWEN (debug wire enable) 110 | 111 | 112 | # symbolic targets: 113 | help: 114 | @echo "This Makefile has no default rule. Use one of the following:" 115 | @echo "make joystick ..... to build joystick.hex" 116 | @echo "make cd32 ......... to build cd32.hex" 117 | @echo "make sega ......... to build sega.hex" 118 | @echo "make nes .......... to build nes.hex" 119 | @echo "make snes ......... to build snes.hex" 120 | @echo "make msx .......... to build msx.hex" 121 | @echo "make amstrad ...... to build amstrad.hex" 122 | @echo "make snesnes ...... to build snesnes.hex" 123 | @echo "make all .......... to build joystick.hex, cd32.hex, sega.hex, nes.hex, snes.hex, msx.hex, amstrad.hex & snesnes.hex" 124 | @echo "====================================================================================================================" 125 | @echo "make fuse ......... to flash the fuses" 126 | @echo "make flashjoy ..... to flash the Joystick firmware" 127 | @echo "make flashcd32 .... to flash the CD32 firmware" 128 | @echo "make flashsega .... to flash the Sega firmware" 129 | @echo "make flashnes ..... to flash the NES firmware" 130 | @echo "make flashsnes .... to flash the SNES firmware" 131 | @echo "make flashmsx ..... to flash the MSX firmware" 132 | @echo "make flashamstrad . to flash the Amstrad firmware" 133 | @echo "make flashsnesnes . to flash the SNES+NES firmware" 134 | @echo "make clean ........ to delete objects and hex file" 135 | 136 | all: joystick-dual.hex cd32-dual.hex sega-dual.hex nes-dual.hex snes-dual.hex msx-dual.hex amstrad-dual.hex snesnes-dual.hex 137 | 138 | joystick: joystick-dual.hex 139 | 140 | cd32: cd32-dual.hex 141 | 142 | sega: sega-dual.hex 143 | 144 | nes: nes-dual.hex 145 | 146 | snes: snes-dual.hex 147 | 148 | msx: msx-dual.hex 149 | 150 | amstrad: amstrad-dual.hex 151 | 152 | snesnes: snesnes-dual.hex 153 | 154 | # rule for programming fuse bits: 155 | fuse: 156 | @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \ 157 | { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; } 158 | $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m 159 | 160 | # rule for uploading firmware: 161 | flashjoy: joystick-dual.hex 162 | $(AVRDUDE) -U flash:w:joystick-dual.hex:i 163 | 164 | flashcd32: cd32-dual.hex 165 | $(AVRDUDE) -U flash:w:cd32-dual.hex:i 166 | 167 | flashsega: sega-dual.hex 168 | $(AVRDUDE) -U flash:w:sega-dual.hex:i 169 | 170 | flashnes: nes-dual.hex 171 | $(AVRDUDE) -U flash:w:nes-dual.hex:i 172 | 173 | flashsnes: snes-dual.hex 174 | $(AVRDUDE) -U flash:w:snes-dual.hex:i 175 | 176 | flashmsx: msx-dual.hex 177 | $(AVRDUDE) -U flash:w:msx-dual.hex:i 178 | 179 | flashamstrad: amstrad-dual.hex 180 | $(AVRDUDE) -U flash:w:amstrad-dual.hex:i 181 | 182 | flashsnesnes: snesnes-dual.hex 183 | $(AVRDUDE) -U flash:w:snesnes-dual.hex:i 184 | 185 | # rule for deleting dependent files (those which can be built by Make): 186 | clean: 187 | rm -f *.hex *.lst *.obj *.cof *.list *.map *.eep.hex *.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s 188 | 189 | # Generic rule for compiling C files: 190 | .c.o: 191 | $(COMPILE) -c $< -o $@ 192 | 193 | # Generic rule for assembling Assembler source files: 194 | .S.o: 195 | $(COMPILE) -x assembler-with-cpp -c $< -o $@ 196 | # "-x assembler-with-cpp" should not be necessary since this is the default 197 | # file type for the .S (with capital S) extension. However, upper case 198 | # characters are not always preserved on Windows. To ensure WinAVR 199 | # compatibility define the file type manually. 200 | 201 | # Generic rule for compiling C to assembler, used for debugging only. 202 | .c.s: 203 | $(COMPILE) -S $< -o $@ 204 | 205 | # file targets: 206 | 207 | # Since we don't want to ship the driver multipe times, we copy it into this project: 208 | usbdrv: 209 | cp -r ../../../usbdrv . 210 | 211 | joystick.elf: usbdrv $(JOY_OBJ) 212 | $(COMPILE) -o joystick.elf $(JOY_OBJ) 213 | 214 | cd32.elf: usbdrv $(CD32_OBJ) 215 | $(COMPILE) -o cd32.elf $(CD32_OBJ) 216 | 217 | sega.elf: usbdrv $(SEGA_OBJ) 218 | $(COMPILE) -o sega.elf $(SEGA_OBJ) 219 | 220 | nes.elf: usbdrv $(NES_OBJ) 221 | $(COMPILE) -o nes.elf $(NES_OBJ) 222 | 223 | snes.elf: usbdrv $(SNES_OBJ) 224 | $(COMPILE) -o snes.elf $(SNES_OBJ) 225 | 226 | msx.elf: usbdrv $(MSX_OBJ) 227 | $(COMPILE) -o msx.elf $(MSX_OBJ) 228 | 229 | amstrad.elf: usbdrv $(AMST_OBJ) 230 | $(COMPILE) -o amstrad.elf $(AMST_OBJ) 231 | 232 | snesnes.elf: usbdrv $(NINT_OBJ) 233 | $(COMPILE) -o snesnes.elf $(NINT_OBJ) 234 | 235 | 236 | joystick-dual.hex: joystick.elf 237 | rm -f joystick-dual.hex joystick.eep.hex 238 | avr-objcopy -j .text -j .data -O ihex joystick.elf joystick-dual.hex 239 | avr-size joystick-dual.hex 240 | 241 | cd32-dual.hex: cd32.elf 242 | rm -f cd32-dual.hex cd32.eep.hex 243 | avr-objcopy -j .text -j .data -O ihex cd32.elf cd32-dual.hex 244 | avr-size cd32-dual.hex 245 | 246 | sega-dual.hex: sega.elf 247 | rm -f sega-dual.hex sega.eep.hex 248 | avr-objcopy -j .text -j .data -O ihex sega.elf sega-dual.hex 249 | avr-size sega-dual.hex 250 | 251 | nes-dual.hex: nes.elf 252 | rm -f nes-dual.hex nes.eep.hex 253 | avr-objcopy -j .text -j .data -O ihex nes.elf nes-dual.hex 254 | avr-size nes-dual.hex 255 | 256 | snes-dual.hex: snes.elf 257 | rm -f snes-dual.hex snes.eep.hex 258 | avr-objcopy -j .text -j .data -O ihex snes.elf snes-dual.hex 259 | avr-size snes-dual.hex 260 | 261 | msx-dual.hex: msx.elf 262 | rm -f msx-dual.hex msx.eep.hex 263 | avr-objcopy -j .text -j .data -O ihex msx.elf msx-dual.hex 264 | avr-size msx-dual.hex 265 | 266 | amstrad-dual.hex: amstrad.elf 267 | rm -f amstrad-dual.hex amstrad.eep.hex 268 | avr-objcopy -j .text -j .data -O ihex amstrad.elf amstrad-dual.hex 269 | avr-size amstrad-dual.hex 270 | 271 | snesnes-dual.hex: snesnes.elf 272 | rm -f snesnes-dual.hex snesnes.eep.hex 273 | avr-objcopy -j .text -j .data -O ihex snesnes.elf snesnes-dual.hex 274 | avr-size snesnes-dual.hex 275 | 276 | cpp: 277 | $(COMPILE) -E joystick.c 278 | $(COMPILE) -E cd32.c 279 | $(COMPILE) -E sega.c 280 | $(COMPILE) -E nes.c 281 | $(COMPILE) -E snes.c 282 | $(COMPILE) -E msx.c 283 | $(COMPILE) -E amstrad.c 284 | $(COMPILE) -E snesnes.c 285 | -------------------------------------------------------------------------------- /Source/amstrad.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Source/amstrad.c -------------------------------------------------------------------------------- /Source/bootloader/Makefile: -------------------------------------------------------------------------------- 1 | # Name: Makefile 2 | # Project: bootloadHID 3 | # Author: Christian Starkjohann 4 | # Creation Date: 2007-03-19 5 | # Tabsize: 4 6 | # Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH 7 | # License: GNU GPL v2 (see License.txt) 8 | # This Revision: $Id$ 9 | 10 | ############################################################################### 11 | # Configure the following variables according to your AVR. The example below 12 | # is for an ATMega8. Program the device with 13 | # make fuse # to set the clock generator, boot section size etc. 14 | # make flash # to load the boot loader into flash 15 | # make lock # to protect the boot loader from overwriting 16 | 17 | DEVICE = atmega8 18 | BOOTLOADER_ADDRESS = 1800 19 | F_CPU = 12000000 20 | FUSEH = 0xc0 21 | FUSEL = 0x9f 22 | # Fuse high byte: 23 | # 0xc0 = 1 1 0 0 0 0 0 0 <-- BOOTRST (boot reset vector at 0x1800) 24 | # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0 25 | # | | | | | +-------- BOOTSZ1 26 | # | | | | + --------- EESAVE (preserve EEPROM over chip erase) 27 | # | | | +-------------- CKOPT (full output swing) 28 | # | | +---------------- SPIEN (allow serial programming) 29 | # | +------------------ WDTON (WDT not always on) 30 | # +-------------------- RSTDISBL (reset pin is enabled) 31 | # Fuse low byte: 32 | # 0x9f = 1 0 0 1 1 1 1 1 33 | # ^ ^ \ / \--+--/ 34 | # | | | +------- CKSEL 3..0 (external >8M crystal) 35 | # | | +--------------- SUT 1..0 (crystal osc, BOD enabled) 36 | # | +------------------ BODEN (BrownOut Detector enabled) 37 | # +-------------------- BODLEVEL (2.7V) 38 | 39 | ############################################################################### 40 | 41 | AVRDUDE = avrdude -c stk500v2 -P avrdoper -p $(DEVICE) 42 | 43 | LDFLAGS += -Wl,--relax,--gc-sections -Wl,--section-start=.text=$(BOOTLOADER_ADDRESS) 44 | 45 | # Omit -fno-* options when using gcc 3, it does not support them. 46 | # use -EDUARANA for support for Edu Aranas joystick adapater 47 | COMPILE = avr-gcc -Wall -Os -fno-move-loop-invariants -fno-tree-scev-cprop -fno-inline-small-functions -Iusbdrv -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -DDEBUG_LEVEL=0 48 | # NEVER compile the final product with debugging! Any debug output will 49 | # distort timing so that the specs can't be met. 50 | 51 | OBJECTS = usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o 52 | 53 | 54 | # symbolic targets: 55 | all: main.hex 56 | 57 | .c.o: 58 | $(COMPILE) -c $< -o $@ 59 | 60 | .S.o: 61 | $(COMPILE) -x assembler-with-cpp -c $< -o $@ 62 | # "-x assembler-with-cpp" should not be necessary since this is the default 63 | # file type for the .S (with capital S) extension. However, upper case 64 | # characters are not always preserved on Windows. To ensure WinAVR 65 | # compatibility define the file type manually. 66 | 67 | .c.s: 68 | $(COMPILE) -S $< -o $@ 69 | 70 | flash: all 71 | $(AVRDUDE) -U flash:w:main.hex:i 72 | 73 | readflash: 74 | $(AVRDUDE) -U flash:r:read.hex:i 75 | 76 | fuse: 77 | $(AVRDUDE) -U hfuse:w:$(FUSEH):m -U lfuse:w:$(FUSEL):m 78 | 79 | lock: 80 | $(AVRDUDE) -U lock:w:0x2f:m 81 | 82 | read_fuses: 83 | $(UISP) --rd_fuses 84 | 85 | clean: 86 | rm -f main.hex main.bin *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s 87 | 88 | # file targets: 89 | main.bin: $(OBJECTS) 90 | $(COMPILE) -o main.bin $(OBJECTS) $(LDFLAGS) 91 | 92 | main.hex: main.bin 93 | rm -f main.hex main.eep.hex 94 | avr-objcopy -j .text -j .data -O ihex main.bin main.hex 95 | avr-size main.hex 96 | 97 | disasm: main.bin 98 | avr-objdump -d main.bin 99 | 100 | cpp: 101 | $(COMPILE) -E main.c 102 | -------------------------------------------------------------------------------- /Source/bootloader/bootloaderconfig.h: -------------------------------------------------------------------------------- 1 | /* Name: bootloaderconfig.h 2 | * Project: AVR bootloader HID 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2007-03-19 5 | * Tabsize: 4 6 | * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: GNU GPL v2 (see License.txt) 8 | * This Revision: $Id$ 9 | */ 10 | 11 | #ifndef __bootloaderconfig_h_included__ 12 | #define __bootloaderconfig_h_included__ 13 | 14 | /* 15 | General Description: 16 | This file (together with some settings in Makefile) configures the boot loader 17 | according to the hardware. 18 | 19 | This file contains (besides the hardware configuration normally found in 20 | usbconfig.h) two functions or macros: bootLoaderInit() and 21 | bootLoaderCondition(). Whether you implement them as macros or as static 22 | inline functions is up to you, decide based on code size and convenience. 23 | 24 | bootLoaderInit() is called as one of the first actions after reset. It should 25 | be a minimum initialization of the hardware so that the boot loader condition 26 | can be read. This will usually consist of activating a pull-up resistor for an 27 | external jumper which selects boot loader mode. You may call leaveBootloader() 28 | from this function if you know that the main code should run. 29 | 30 | bootLoaderCondition() is called immediately after initialization and in each 31 | main loop iteration. If it returns TRUE, the boot loader will be active. If it 32 | returns FALSE, the boot loader jumps to address 0 (the loaded application) 33 | immediately. 34 | 35 | For compatibility with Thomas Fischl's avrusbboot, we also support the macro 36 | names BOOTLOADER_INIT and BOOTLOADER_CONDITION for this functionality. If 37 | these macros are defined, the boot loader usees them. 38 | */ 39 | 40 | /* ---------------------------- Hardware Config ---------------------------- */ 41 | #ifdef EDUARANA 42 | #define USB_CFG_IOPORTNAME B 43 | #define USB_CFG_DMINUS_BIT 0 44 | #define USB_CFG_DPLUS_BIT 1 45 | #else 46 | 47 | #define USB_CFG_IOPORTNAME D 48 | /* This is the port where the USB bus is connected. When you configure it to 49 | * "B", the registers PORTB, PINB and DDRB will be used. 50 | */ 51 | #define USB_CFG_DMINUS_BIT 0 52 | /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. 53 | * This may be any bit in the port. 54 | */ 55 | #define USB_CFG_DPLUS_BIT 2 56 | #endif 57 | /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. 58 | * This may be any bit in the port. Please note that D+ must also be connected 59 | * to interrupt pin INT0! [You can also use other interrupts, see section 60 | * "Optional MCU Description" below, or you can connect D- to the interrupt, as 61 | * it is required if you use the USB_COUNT_SOF feature. If you use D- for the 62 | * interrupt, the USB interrupt will also be triggered at Start-Of-Frame 63 | * markers every millisecond.] 64 | */ 65 | #define USB_CFG_CLOCK_KHZ (F_CPU/1000) 66 | /* Clock rate of the AVR in MHz. Legal values are 12000, 12800, 15000, 16000, 67 | * 16500 and 20000. The 12.8 MHz and 16.5 MHz versions of the code require no 68 | * crystal, they tolerate +/- 1% deviation from the nominal frequency. All 69 | * other rates require a precision of 2000 ppm and thus a crystal! 70 | * Default if not specified: 12 MHz 71 | */ 72 | 73 | /* ----------------------- Optional Hardware Config ------------------------ */ 74 | 75 | /* #define USB_CFG_PULLUP_IOPORTNAME D */ 76 | /* If you connect the 1.5k pullup resistor from D- to a port pin instead of 77 | * V+, you can connect and disconnect the device from firmware by calling 78 | * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). 79 | * This constant defines the port on which the pullup resistor is connected. 80 | */ 81 | /* #define USB_CFG_PULLUP_BIT 4 */ 82 | /* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined 83 | * above) where the 1.5k pullup resistor is connected. See description 84 | * above for details. 85 | */ 86 | 87 | /* --------------------------- Functional Range ---------------------------- */ 88 | 89 | #define BOOTLOADER_CAN_EXIT 1 90 | /* If this macro is defined to 1, the boot loader command line utility can 91 | * initiate a reboot after uploading the FLASH when the "-r" command line 92 | * option is given. If you define it to 0 or leave it undefined, the "-r" 93 | * option won't work and you save a couple of bytes in the boot loader. This 94 | * may be of advantage if you compile with gcc 4 instead of gcc 3 because it 95 | * generates slightly larger code. 96 | * If you need to save even more memory, consider using your own vector table. 97 | * Since only the reset vector and INT0 (the first two vectors) are used, 98 | * this saves quite a bit of flash. See Alexander Neumann's boot loader for 99 | * an example: http://git.lochraster.org:2080/?p=fd0/usbload;a=tree 100 | */ 101 | 102 | /* ------------------------------------------------------------------------- */ 103 | 104 | /* Example configuration: Port D bit 3 is connected to a jumper which ties 105 | * this pin to GND if the boot loader is requested. Initialization allows 106 | * several clock cycles for the input voltage to stabilize before 107 | * bootLoaderCondition() samples the value. 108 | * We use a function for bootLoaderInit() for convenience and a macro for 109 | * bootLoaderCondition() for efficiency. 110 | */ 111 | 112 | #ifndef __ASSEMBLER__ /* assembler cannot parse function definitions */ 113 | #include 114 | 115 | static inline void bootLoaderInit(void) 116 | { 117 | #ifdef EDUARANA 118 | PORTD = 1 << PD5; /* activate pull-up for key */ 119 | #else 120 | PORTC = 1 << PC1; /* activate pull-up for key */ 121 | #endif 122 | _delay_us(10); /* wait for levels to stabilize */ 123 | } 124 | 125 | #ifdef EDUARANA 126 | #define bootLoaderCondition() ((PIND & (1 << PD5)) == 0) /* True if jumper is set */ 127 | #else 128 | #define bootLoaderCondition() ((PINC & (1 << PC1)) == 0) /* True if jumper is set */ 129 | #endif 130 | 131 | #endif 132 | 133 | /* ------------------------------------------------------------------------- */ 134 | 135 | #endif /* __bootloader_h_included__ */ 136 | -------------------------------------------------------------------------------- /Source/bootloader/flashme.sh: -------------------------------------------------------------------------------- 1 | sudo avrdude -c usbasp -P avrdoper -p atmega8 -U hfuse:w:0xc0:m -U lfuse:w:0x9f:m 2 | sudo avrdude -c usbasp -P avrdoper -p atmega8 -U flash:w:main.hex:i -------------------------------------------------------------------------------- /Source/bootloader/how_to_program.txt: -------------------------------------------------------------------------------- 1 | sudo avrdude -c usbasp -P avrdoper -p atmega8 -U hfuse:w:0xc0:m -U lfuse:w:0x9f:m 2 | sudo avrdude -c usbasp -P avrdoper -p atmega8 -U flash:w:main.hex:i -------------------------------------------------------------------------------- /Source/bootloader/main.c: -------------------------------------------------------------------------------- 1 | /* Name: main.c 2 | * Project: AVR bootloader HID 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2007-03-19 5 | * Tabsize: 4 6 | * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: GNU GPL v2 (see License.txt) 8 | * This Revision: $Id$ 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | static void leaveBootloader() __attribute__((__noreturn__)); 20 | 21 | #include "bootloaderconfig.h" 22 | #include "usbdrv.c" 23 | 24 | /* ------------------------------------------------------------------------ */ 25 | 26 | #ifndef ulong 27 | # define ulong unsigned long 28 | #endif 29 | #ifndef uint 30 | # define uint unsigned int 31 | #endif 32 | 33 | #if (FLASHEND) > 0xffff /* we need long addressing */ 34 | # define addr_t ulong 35 | #else 36 | # define addr_t uint 37 | #endif 38 | 39 | static addr_t currentAddress; /* in bytes */ 40 | static uchar offset; /* data already processed in current transfer */ 41 | #if BOOTLOADER_CAN_EXIT 42 | static uchar exitMainloop; 43 | #endif 44 | 45 | 46 | const PROGMEM char usbHidReportDescriptor[33] = { 47 | 0x06, 0x00, 0xff, // USAGE_PAGE (Generic Desktop) 48 | 0x09, 0x01, // USAGE (Vendor Usage 1) 49 | 0xa1, 0x01, // COLLECTION (Application) 50 | 0x15, 0x00, // LOGICAL_MINIMUM (0) 51 | 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) 52 | 0x75, 0x08, // REPORT_SIZE (8) 53 | 54 | 0x85, 0x01, // REPORT_ID (1) 55 | 0x95, 0x06, // REPORT_COUNT (6) 56 | 0x09, 0x00, // USAGE (Undefined) 57 | 0xb2, 0x02, 0x01, // FEATURE (Data,Var,Abs,Buf) 58 | 59 | 0x85, 0x02, // REPORT_ID (2) 60 | 0x95, 0x83, // REPORT_COUNT (131) 61 | 0x09, 0x00, // USAGE (Undefined) 62 | 0xb2, 0x02, 0x01, // FEATURE (Data,Var,Abs,Buf) 63 | 0xc0 // END_COLLECTION 64 | }; 65 | 66 | /* allow compatibility with avrusbboot's bootloaderconfig.h: */ 67 | #ifdef BOOTLOADER_INIT 68 | # define bootLoaderInit() BOOTLOADER_INIT 69 | #endif 70 | #ifdef BOOTLOADER_CONDITION 71 | # define bootLoaderCondition() BOOTLOADER_CONDITION 72 | #endif 73 | 74 | /* compatibility with ATMega88 and other new devices: */ 75 | #ifndef TCCR0 76 | #define TCCR0 TCCR0B 77 | #endif 78 | #ifndef GICR 79 | #define GICR MCUCR 80 | #endif 81 | 82 | static void (*nullVector)(void) __attribute__((__noreturn__)); 83 | 84 | static void leaveBootloader() 85 | { 86 | DBG1(0x01, 0, 0); 87 | cli(); 88 | boot_rww_enable(); 89 | USB_INTR_ENABLE = 0; 90 | USB_INTR_CFG = 0; /* also reset config bits */ 91 | #if F_CPU == 12800000 92 | TCCR0 = 0; /* default value */ 93 | #endif 94 | GICR = (1 << IVCE); /* enable change of interrupt vectors */ 95 | GICR = (0 << IVSEL); /* move interrupts to application flash section */ 96 | /* We must go through a global function pointer variable instead of writing 97 | * ((void (*)(void))0)(); 98 | * because the compiler optimizes a constant 0 to "rcall 0" which is not 99 | * handled correctly by the assembler. 100 | */ 101 | nullVector(); 102 | } 103 | 104 | uchar usbFunctionSetup(uchar data[8]) 105 | { 106 | usbRequest_t *rq = (void *)data; 107 | static uchar replyBuffer[7] = { 108 | 1, /* report ID */ 109 | SPM_PAGESIZE & 0xff, 110 | SPM_PAGESIZE >> 8, 111 | ((long)FLASHEND + 1) & 0xff, 112 | (((long)FLASHEND + 1) >> 8) & 0xff, 113 | (((long)FLASHEND + 1) >> 16) & 0xff, 114 | (((long)FLASHEND + 1) >> 24) & 0xff 115 | }; 116 | 117 | if(rq->bRequest == USBRQ_HID_SET_REPORT){ 118 | if(rq->wValue.bytes[0] == 2){ 119 | offset = 0; 120 | return USB_NO_MSG; 121 | } 122 | #if BOOTLOADER_CAN_EXIT 123 | else{ 124 | exitMainloop = 1; 125 | } 126 | #endif 127 | }else if(rq->bRequest == USBRQ_HID_GET_REPORT){ 128 | usbMsgPtr = (usbMsgPtr_t)replyBuffer; 129 | return 7; 130 | } 131 | return 0; 132 | } 133 | 134 | uchar usbFunctionWrite(uchar *data, uchar len) 135 | { 136 | union { 137 | addr_t l; 138 | uint s[sizeof(addr_t)/2]; 139 | uchar c[sizeof(addr_t)]; 140 | } address; 141 | uchar isLast; 142 | 143 | address.l = currentAddress; 144 | if(offset == 0){ 145 | DBG1(0x30, data, 3); 146 | address.c[0] = data[1]; 147 | address.c[1] = data[2]; 148 | #if (FLASHEND) > 0xffff /* we need long addressing */ 149 | address.c[2] = data[3]; 150 | address.c[3] = 0; 151 | #endif 152 | data += 4; 153 | len -= 4; 154 | } 155 | DBG1(0x31, (void *)¤tAddress, 4); 156 | offset += len; 157 | isLast = offset & 0x80; /* != 0 if last block received */ 158 | do{ 159 | addr_t prevAddr; 160 | #if SPM_PAGESIZE > 256 161 | uint pageAddr; 162 | #else 163 | uchar pageAddr; 164 | #endif 165 | DBG1(0x32, 0, 0); 166 | pageAddr = address.s[0] & (SPM_PAGESIZE - 1); 167 | if(pageAddr == 0){ /* if page start: erase */ 168 | DBG1(0x33, 0, 0); 169 | #ifndef TEST_MODE 170 | cli(); 171 | boot_page_erase(address.l); /* erase page */ 172 | sei(); 173 | boot_spm_busy_wait(); /* wait until page is erased */ 174 | #endif 175 | } 176 | cli(); 177 | boot_page_fill(address.l, *(short *)data); 178 | sei(); 179 | prevAddr = address.l; 180 | address.l += 2; 181 | data += 2; 182 | /* write page when we cross page boundary */ 183 | pageAddr = address.s[0] & (SPM_PAGESIZE - 1); 184 | if(pageAddr == 0){ 185 | DBG1(0x34, 0, 0); 186 | #ifndef TEST_MODE 187 | cli(); 188 | boot_page_write(prevAddr); 189 | sei(); 190 | boot_spm_busy_wait(); 191 | #endif 192 | } 193 | len -= 2; 194 | }while(len); 195 | currentAddress = address.l; 196 | DBG1(0x35, (void *)¤tAddress, 4); 197 | return isLast; 198 | } 199 | 200 | static void initForUsbConnectivity(void) 201 | { 202 | uchar i = 0; 203 | 204 | #if F_CPU == 12800000 205 | TCCR0 = 3; /* 1/64 prescaler */ 206 | #endif 207 | usbInit(); 208 | /* enforce USB re-enumerate: */ 209 | usbDeviceDisconnect(); /* do this while interrupts are disabled */ 210 | do{ /* fake USB disconnect for > 250 ms */ 211 | wdt_reset(); 212 | _delay_ms(1); 213 | }while(--i); 214 | usbDeviceConnect(); 215 | sei(); 216 | } 217 | 218 | int __attribute__((noreturn)) main(void) 219 | { 220 | /* initialize hardware */ 221 | bootLoaderInit(); 222 | odDebugInit(); 223 | DBG1(0x00, 0, 0); 224 | /* jump to application if jumper is set */ 225 | if(bootLoaderCondition()){ 226 | uchar i = 0, j = 0; 227 | #ifndef TEST_MODE 228 | GICR = (1 << IVCE); /* enable change of interrupt vectors */ 229 | GICR = (1 << IVSEL); /* move interrupts to boot flash section */ 230 | #endif 231 | initForUsbConnectivity(); 232 | do{ /* main event loop */ 233 | wdt_reset(); 234 | usbPoll(); 235 | #if BOOTLOADER_CAN_EXIT 236 | if(exitMainloop){ 237 | #if F_CPU == 12800000 238 | break; /* memory is tight at 12.8 MHz, save exit delay below */ 239 | #endif 240 | if(--i == 0){ 241 | if(--j == 0) 242 | break; 243 | } 244 | } 245 | #endif 246 | }while(bootLoaderCondition()); 247 | } 248 | leaveBootloader(); 249 | } 250 | 251 | -------------------------------------------------------------------------------- /Source/bootloader/usbdrv/CommercialLicense.txt: -------------------------------------------------------------------------------- 1 | V-USB Driver Software License Agreement 2 | Version 2012-07-09 3 | 4 | THIS LICENSE AGREEMENT GRANTS YOU CERTAIN RIGHTS IN A SOFTWARE. YOU CAN 5 | ENTER INTO THIS AGREEMENT AND ACQUIRE THE RIGHTS OUTLINED BELOW BY PAYING 6 | THE AMOUNT ACCORDING TO SECTION 4 ("PAYMENT") TO OBJECTIVE DEVELOPMENT. 7 | 8 | 9 | 1 DEFINITIONS 10 | 11 | 1.1 "OBJECTIVE DEVELOPMENT" shall mean OBJECTIVE DEVELOPMENT Software GmbH, 12 | Grosse Schiffgasse 1A/7, 1020 Wien, AUSTRIA. 13 | 14 | 1.2 "You" shall mean the Licensee. 15 | 16 | 1.3 "V-USB" shall mean all files included in the package distributed under 17 | the name "vusb" by OBJECTIVE DEVELOPMENT (http://www.obdev.at/vusb/) 18 | unless otherwise noted. This includes the firmware-only USB device 19 | implementation for Atmel AVR microcontrollers, some simple device examples 20 | and host side software examples and libraries. 21 | 22 | 23 | 2 LICENSE GRANTS 24 | 25 | 2.1 Source Code. OBJECTIVE DEVELOPMENT shall furnish you with the source 26 | code of V-USB. 27 | 28 | 2.2 Distribution and Use. OBJECTIVE DEVELOPMENT grants you the 29 | non-exclusive right to use, copy and distribute V-USB with your hardware 30 | product(s), restricted by the limitations in section 3 below. 31 | 32 | 2.3 Modifications. OBJECTIVE DEVELOPMENT grants you the right to modify 33 | the source code and your copy of V-USB according to your needs. 34 | 35 | 2.4 USB IDs. OBJECTIVE DEVELOPMENT furnishes you with one or two USB 36 | Product ID(s), sent to you in e-mail. These Product IDs are reserved 37 | exclusively for you. OBJECTIVE DEVELOPMENT has obtained USB Product ID 38 | ranges under the Vendor ID 5824 from Wouter van Ooijen (Van Ooijen 39 | Technische Informatica, www.voti.nl) and under the Vendor ID 8352 from 40 | Jason Kotzin (now flirc.tv, Inc.). Both owners of the Vendor IDs have 41 | obtained these IDs from the USB Implementers Forum, Inc. (www.usb.org). 42 | OBJECTIVE DEVELOPMENT disclaims all liability which might arise from the 43 | assignment of USB IDs. 44 | 45 | 2.5 USB Certification. Although not part of this agreement, we want to make 46 | it clear that you cannot become USB certified when you use V-USB or a USB 47 | Product ID assigned by OBJECTIVE DEVELOPMENT. AVR microcontrollers don't 48 | meet the electrical specifications required by the USB specification and 49 | the USB Implementers Forum certifies only members who bought a Vendor ID of 50 | their own. 51 | 52 | 53 | 3 LICENSE RESTRICTIONS 54 | 55 | 3.1 Number of Units. Only one of the following three definitions is 56 | applicable. Which one is determined by the amount you pay to OBJECTIVE 57 | DEVELOPMENT, see section 4 ("Payment") below. 58 | 59 | Hobby License: You may use V-USB according to section 2 above in no more 60 | than 5 hardware units. These units must not be sold for profit. 61 | 62 | Entry Level License: You may use V-USB according to section 2 above in no 63 | more than 150 hardware units. 64 | 65 | Professional License: You may use V-USB according to section 2 above in 66 | any number of hardware units, except for large scale production ("unlimited 67 | fair use"). Quantities below 10,000 units are not considered large scale 68 | production. If your reach quantities which are obviously large scale 69 | production, you must pay a license fee of 0.10 EUR per unit for all units 70 | above 10,000. 71 | 72 | 3.2 Rental. You may not rent, lease, or lend V-USB or otherwise encumber 73 | any copy of V-USB, or any of the rights granted herein. 74 | 75 | 3.3 Transfer. You may not transfer your rights under this Agreement to 76 | another party without OBJECTIVE DEVELOPMENT's prior written consent. If 77 | such consent is obtained, you may permanently transfer this License to 78 | another party. The recipient of such transfer must agree to all terms and 79 | conditions of this Agreement. 80 | 81 | 3.4 Reservation of Rights. OBJECTIVE DEVELOPMENT retains all rights not 82 | expressly granted. 83 | 84 | 3.5 Non-Exclusive Rights. Your license rights under this Agreement are 85 | non-exclusive. 86 | 87 | 3.6 Third Party Rights. This Agreement cannot grant you rights controlled 88 | by third parties. In particular, you are not allowed to use the USB logo or 89 | other trademarks owned by the USB Implementers Forum, Inc. without their 90 | consent. Since such consent depends on USB certification, it should be 91 | noted that V-USB will not pass certification because it does not 92 | implement checksum verification and the microcontroller ports do not meet 93 | the electrical specifications. 94 | 95 | 96 | 4 PAYMENT 97 | 98 | The payment amount depends on the variation of this agreement (according to 99 | section 3.1) into which you want to enter. Concrete prices are listed on 100 | OBJECTIVE DEVELOPMENT's web site, usually at 101 | http://www.obdev.at/vusb/license.html. You agree to pay the amount listed 102 | there to OBJECTIVE DEVELOPMENT or OBJECTIVE DEVELOPMENT's payment processor 103 | or reseller. 104 | 105 | 106 | 5 COPYRIGHT AND OWNERSHIP 107 | 108 | V-USB is protected by copyright laws and international copyright 109 | treaties, as well as other intellectual property laws and treaties. V-USB 110 | is licensed, not sold. 111 | 112 | 113 | 6 TERM AND TERMINATION 114 | 115 | 6.1 Term. This Agreement shall continue indefinitely. However, OBJECTIVE 116 | DEVELOPMENT may terminate this Agreement and revoke the granted license and 117 | USB-IDs if you fail to comply with any of its terms and conditions. 118 | 119 | 6.2 Survival of Terms. All provisions regarding secrecy, confidentiality 120 | and limitation of liability shall survive termination of this agreement. 121 | 122 | 123 | 7 DISCLAIMER OF WARRANTY AND LIABILITY 124 | 125 | LIMITED WARRANTY. V-USB IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 126 | KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, OBJECTIVE 127 | DEVELOPMENT AND ITS SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES, EITHER 128 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 129 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND 130 | NON-INFRINGEMENT, WITH REGARD TO V-USB, AND THE PROVISION OF OR FAILURE 131 | TO PROVIDE SUPPORT SERVICES. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL 132 | RIGHTS. YOU MAY HAVE OTHERS, WHICH VARY FROM STATE/JURISDICTION TO 133 | STATE/JURISDICTION. 134 | 135 | LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, 136 | IN NO EVENT SHALL OBJECTIVE DEVELOPMENT OR ITS SUPPLIERS BE LIABLE FOR ANY 137 | SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER 138 | (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, 139 | BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY 140 | LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE V-USB OR THE 141 | PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF OBJECTIVE 142 | DEVELOPMENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY 143 | CASE, OBJECTIVE DEVELOPMENT'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS 144 | AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR V-USB. 145 | 146 | 147 | 8 MISCELLANEOUS TERMS 148 | 149 | 8.1 Marketing. OBJECTIVE DEVELOPMENT has the right to mention for marketing 150 | purposes that you entered into this agreement. 151 | 152 | 8.2 Entire Agreement. This document represents the entire agreement between 153 | OBJECTIVE DEVELOPMENT and you. It may only be modified in writing signed by 154 | an authorized representative of both, OBJECTIVE DEVELOPMENT and you. 155 | 156 | 8.3 Severability. In case a provision of these terms and conditions should 157 | be or become partly or entirely invalid, ineffective, or not executable, 158 | the validity of all other provisions shall not be affected. 159 | 160 | 8.4 Applicable Law. This agreement is governed by the laws of the Republic 161 | of Austria. 162 | 163 | 8.5 Responsible Courts. The responsible courts in Vienna/Austria will have 164 | exclusive jurisdiction regarding all disputes in connection with this 165 | agreement. 166 | 167 | -------------------------------------------------------------------------------- /Source/bootloader/usbdrv/Readme.txt: -------------------------------------------------------------------------------- 1 | This is the Readme file to Objective Development's firmware-only USB driver 2 | for Atmel AVR microcontrollers. For more information please visit 3 | http://www.obdev.at/vusb/ 4 | 5 | This directory contains the USB firmware only. Copy it as-is to your own 6 | project and add all .c and .S files to your project (these files are marked 7 | with an asterisk in the list below). Then copy usbconfig-prototype.h as 8 | usbconfig.h to your project and edit it according to your configuration. 9 | 10 | 11 | TECHNICAL DOCUMENTATION 12 | ======================= 13 | The technical documentation (API) for the firmware driver is contained in the 14 | file "usbdrv.h". Please read all of it carefully! Configuration options are 15 | documented in "usbconfig-prototype.h". 16 | 17 | The driver consists of the following files: 18 | Readme.txt ............. The file you are currently reading. 19 | Changelog.txt .......... Release notes for all versions of the driver. 20 | usbdrv.h ............... Driver interface definitions and technical docs. 21 | * usbdrv.c ............... High level language part of the driver. Link this 22 | module to your code! 23 | * usbdrvasm.S ............ Assembler part of the driver. This module is mostly 24 | a stub and includes one of the usbdrvasm*.S files 25 | depending on processor clock. Link this module to 26 | your code! 27 | usbdrvasm*.inc ......... Assembler routines for particular clock frequencies. 28 | Included by usbdrvasm.S, don't link it directly! 29 | asmcommon.inc .......... Common assembler routines. Included by 30 | usbdrvasm*.inc, don't link it directly! 31 | usbconfig-prototype.h .. Prototype for your own usbdrv.h file. 32 | * oddebug.c .............. Debug functions. Only used when DEBUG_LEVEL is 33 | defined to a value greater than 0. Link this module 34 | to your code! 35 | oddebug.h .............. Interface definitions of the debug module. 36 | usbportability.h ....... Header with compiler-dependent stuff. 37 | usbdrvasm.asm .......... Compatibility stub for IAR-C-compiler. Use this 38 | module instead of usbdrvasm.S when you assembler 39 | with IAR's tools. 40 | License.txt ............ Open Source license for this driver. 41 | CommercialLicense.txt .. Optional commercial license for this driver. 42 | USB-ID-FAQ.txt ......... General infos about USB Product- and Vendor-IDs. 43 | USB-IDs-for-free.txt ... List and terms of use for free shared PIDs. 44 | 45 | (*) ... These files should be linked to your project. 46 | 47 | 48 | CPU CORE CLOCK FREQUENCY 49 | ======================== 50 | We supply assembler modules for clock frequencies of 12 MHz, 12.8 MHz, 15 MHz, 51 | 16 MHz, 16.5 MHz 18 MHz and 20 MHz. Other clock rates are not supported. The 52 | actual clock rate must be configured in usbconfig.h. 53 | 54 | 12 MHz Clock 55 | This is the traditional clock rate of V-USB because it's the lowest clock 56 | rate where the timing constraints of the USB spec can be met. 57 | 58 | 15 MHz Clock 59 | Similar to 12 MHz, but some NOPs inserted. On the other hand, the higher clock 60 | rate allows for some loops which make the resulting code size somewhat smaller 61 | than the 12 MHz version. 62 | 63 | 16 MHz Clock 64 | This clock rate has been added for users of the Arduino board and other 65 | ready-made boards which come with a fixed 16 MHz crystal. It's also an option 66 | if you need the slightly higher clock rate for performance reasons. Since 67 | 16 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code 68 | is somewhat tricky and has to insert a leap cycle every third byte. 69 | 70 | 12.8 MHz and 16.5 MHz Clock 71 | The assembler modules for these clock rates differ from the other modules 72 | because they have been built for an RC oscillator with only 1% precision. The 73 | receiver code inserts leap cycles to compensate for clock deviations. 1% is 74 | also the precision which can be achieved by calibrating the internal RC 75 | oscillator of the AVR. Please note that only AVRs with internal 64 MHz PLL 76 | oscillator can reach 16.5 MHz with the RC oscillator. This includes the very 77 | popular ATTiny25, ATTiny45, ATTiny85 series as well as the ATTiny26. Almost 78 | all AVRs can reach 12.8 MHz, although this is outside the specified range. 79 | 80 | See the EasyLogger example at http://www.obdev.at/vusb/easylogger.html for 81 | code which calibrates the RC oscillator based on the USB frame clock. 82 | 83 | 18 MHz Clock 84 | This module is closer to the USB specification because it performs an on the 85 | fly CRC check for incoming packets. Packets with invalid checksum are 86 | discarded as required by the spec. If you also implement checks for data 87 | PID toggling on application level (see option USB_CFG_CHECK_DATA_TOGGLING 88 | in usbconfig.h for more info), this ensures data integrity. Due to the CRC 89 | tables and alignment requirements, this code is bigger than modules for other 90 | clock rates. To activate this module, you must define USB_CFG_CHECK_CRC to 1 91 | and USB_CFG_CLOCK_KHZ to 18000 in usbconfig.h. 92 | 93 | 20 MHz Clock 94 | This module is for people who won't do it with less than the maximum. Since 95 | 20 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code 96 | uses similar tricks as the 16 MHz module to insert leap cycles. 97 | 98 | 99 | USB IDENTIFIERS 100 | =============== 101 | Every USB device needs a vendor- and a product-identifier (VID and PID). VIDs 102 | are obtained from usb.org for a price of 1,500 USD. Once you have a VID, you 103 | can assign PIDs at will. 104 | 105 | Since an entry level cost of 1,500 USD is too high for most small companies 106 | and hobbyists, we provide some VID/PID pairs for free. See the file 107 | USB-IDs-for-free.txt for details. 108 | 109 | Objective Development also has some license offerings which include product 110 | IDs. See http://www.obdev.at/vusb/ for details. 111 | 112 | 113 | DEVELOPMENT SYSTEM 114 | ================== 115 | This driver has been developed and optimized for the GNU compiler version 3 116 | and 4. We recommend that you use the GNU compiler suite because it is freely 117 | available. V-USB has also been ported to the IAR compiler and assembler. It 118 | has been tested with IAR 4.10B/W32 and 4.12A/W32 on an ATmega8 with the 119 | "small" and "tiny" memory model. Not every release is tested with IAR CC and 120 | the driver may therefore fail to compile with IAR. Please note that gcc is 121 | more efficient for usbdrv.c because this module has been deliberately 122 | optimized for gcc. 123 | 124 | Gcc version 3 produces smaller code than version 4 due to new optimizing 125 | capabilities which don't always improve things on 8 bit CPUs. The code size 126 | generated by gcc 4 can be reduced with the compiler options 127 | -fno-move-loop-invariants, -fno-tree-scev-cprop and 128 | -fno-inline-small-functions in addition to -Os. On devices with more than 129 | 8k of flash memory, we also recommend the linker option --relax (written as 130 | -Wl,--relax for gcc) to convert absolute calls into relative where possible. 131 | 132 | For more information about optimizing options see: 133 | 134 | http://www.tty1.net/blog/2008-04-29-avr-gcc-optimisations_en.html 135 | 136 | These optimizations are good for gcc 4.x. Version 3.x of gcc does not support 137 | most of these options and produces good code anyway. 138 | 139 | 140 | USING V-USB FOR FREE 141 | ==================== 142 | The AVR firmware driver is published under the GNU General Public License 143 | Version 2 (GPL2) and the GNU General Public License Version 3 (GPL3). It is 144 | your choice whether you apply the terms of version 2 or version 3. 145 | 146 | If you decide for the free GPL2 or GPL3, we STRONGLY ENCOURAGE you to do the 147 | following things IN ADDITION to the obligations from the GPL: 148 | 149 | (1) Publish your entire project on a web site and drop us a note with the URL. 150 | Use the form at http://www.obdev.at/vusb/feedback.html for your submission. 151 | If you don't have a web site, you can publish the project in obdev's 152 | documentation wiki at 153 | http://www.obdev.at/goto.php?t=vusb-wiki&p=hosted-projects. 154 | 155 | (2) Adhere to minimum publication standards. Please include AT LEAST: 156 | - a circuit diagram in PDF, PNG or GIF format 157 | - full source code for the host software 158 | - a Readme.txt file in ASCII format which describes the purpose of the 159 | project and what can be found in which directories and which files 160 | - a reference to http://www.obdev.at/vusb/ 161 | 162 | (3) If you improve the driver firmware itself, please give us a free license 163 | to your modifications for our commercial license offerings. 164 | 165 | 166 | COMMERCIAL LICENSES FOR V-USB 167 | ============================= 168 | If you don't want to publish your source code under the terms of the GPL, 169 | you can simply pay money for V-USB. As an additional benefit you get 170 | USB PIDs for free, reserved exclusively to you. See the file 171 | "CommercialLicense.txt" for details. 172 | 173 | -------------------------------------------------------------------------------- /Source/bootloader/usbdrv/USB-ID-FAQ.txt: -------------------------------------------------------------------------------- 1 | Version 2012-07-09 2 | 3 | ========================== 4 | WHY DO WE NEED THESE IDs? 5 | ========================== 6 | 7 | USB is more than a low level protocol for data transport. It also defines a 8 | common set of requests which must be understood by all devices. And as part 9 | of these common requests, the specification defines data structures, the 10 | USB Descriptors, which are used to describe the properties of the device. 11 | 12 | From the perspective of an operating system, it is therefore possible to find 13 | out basic properties of a device (such as e.g. the manufacturer and the name 14 | of the device) without a device-specific driver. This is essential because 15 | the operating system can choose a driver to load based on this information 16 | (Plug-And-Play). 17 | 18 | Among the most important properties in the Device Descriptor are the USB 19 | Vendor- and Product-ID. Both are 16 bit integers. The most simple form of 20 | driver matching is based on these IDs. The driver announces the Vendor- and 21 | Product-IDs of the devices it can handle and the operating system loads the 22 | appropriate driver when the device is connected. 23 | 24 | It is obvious that this technique only works if the pair Vendor- plus 25 | Product-ID is unique: Only devices which require the same driver can have the 26 | same pair of IDs. 27 | 28 | 29 | ===================================================== 30 | HOW DOES THE USB STANDARD ENSURE THAT IDs ARE UNIQUE? 31 | ===================================================== 32 | 33 | Since it is so important that USB IDs are unique, the USB Implementers Forum, 34 | Inc. (usb.org) needs a way to enforce this legally. It is not forbidden by 35 | law to build a device and assign it any random numbers as IDs. Usb.org 36 | therefore needs an agreement to regulate the use of USB IDs. The agreement 37 | binds only parties who agreed to it, of course. Everybody else is free to use 38 | any numbers for their IDs. 39 | 40 | So how can usb.org ensure that every manufacturer of USB devices enters into 41 | an agreement with them? They do it via trademark licensing. Usb.org has 42 | registered the trademark "USB", all associated logos and related terms. If 43 | you want to put an USB logo on your product or claim that it is USB 44 | compliant, you must license these trademarks from usb.org. And this is where 45 | you enter into an agreement. See the "USB-IF Trademark License Agreement and 46 | Usage Guidelines for the USB-IF Logo" at 47 | http://www.usb.org/developers/logo_license/. 48 | 49 | Licensing the USB trademarks requires that you buy a USB Vendor-ID from 50 | usb.org (one-time fee of ca. 2,000 USD), that you become a member of usb.org 51 | (yearly fee of ca. 4,000 USD) and that you meet all the technical 52 | specifications from the USB spec. 53 | 54 | This means that most hobbyists and small companies will never be able to 55 | become USB compliant, just because membership is so expensive. And you can't 56 | be compliant with a driver based on V-USB anyway, because the AVR's port pins 57 | don't meet the electrical specifications for USB. So, in principle, all 58 | hobbyists and small companies are free to choose any random numbers for their 59 | IDs. They have nothing to lose... 60 | 61 | There is one exception worth noting, though: If you use a sub-component which 62 | implements USB, the vendor of the sub-components may guarantee USB 63 | compliance. This might apply to some or all of FTDI's solutions. 64 | 65 | 66 | ======================================================================= 67 | WHY SHOULD YOU OBTAIN USB IDs EVEN IF YOU DON'T LICENSE USB TRADEMARKS? 68 | ======================================================================= 69 | 70 | You have learned in the previous section that you are free to choose any 71 | numbers for your IDs anyway. So why not do exactly this? There is still the 72 | technical issue. If you choose IDs which are already in use by somebody else, 73 | operating systems will load the wrong drivers and your device won't work. 74 | Even if you choose IDs which are not currently in use, they may be in use in 75 | the next version of the operating system or even after an automatic update. 76 | 77 | So what you need is a pair of Vendor- and Product-IDs for which you have the 78 | guarantee that no USB compliant product uses them. This implies that no 79 | operating system will ever ship with drivers responsible for these IDs. 80 | 81 | 82 | ============================================== 83 | HOW DOES OBJECTIVE DEVELOPMENT HANDLE USB IDs? 84 | ============================================== 85 | 86 | Objective Development gives away pairs of USB-IDs with their V-USB licenses. 87 | In order to ensure that these IDs are unique, Objective Development has an 88 | agreement with the company/person who has bought the USB Vendor-ID from 89 | usb.org. This agreement ensures that a range of USB Product-IDs is reserved 90 | for assignment by Objective Development and that the owner of the Vendor-ID 91 | won't give it to anybody else. 92 | 93 | This means that you have to trust three parties to ensure uniqueness of 94 | your IDs: 95 | 96 | - Objective Development, that they don't give the same PID to more than 97 | one person. 98 | - The owner of the Vendor-ID that they don't assign PIDs from the range 99 | assigned to Objective Development to anybody else. 100 | - Usb.org that they don't assign the same Vendor-ID a second time. 101 | 102 | 103 | ================================== 104 | WHO IS THE OWNER OF THE VENDOR-ID? 105 | ================================== 106 | 107 | Objective Development has obtained ranges of USB Product-IDs under two 108 | Vendor-IDs: Under Vendor-ID 5824 from Wouter van Ooijen (Van Ooijen 109 | Technische Informatica, www.voti.nl) and under Vendor-ID 8352 from Jason 110 | Kotzin (now flirc.tv, Inc.). Both VID owners have received their Vendor-ID 111 | directly from usb.org. 112 | 113 | 114 | ========================================================================= 115 | CAN I USE USB-IDs FROM OBJECTIVE DEVELOPMENT WITH OTHER DRIVERS/HARDWARE? 116 | ========================================================================= 117 | 118 | The short answer is: Yes. All you get is a guarantee that the IDs are never 119 | assigned to anybody else. What more do you need? 120 | 121 | 122 | ============================ 123 | WHAT ABOUT SHARED ID PAIRS? 124 | ============================ 125 | 126 | Objective Development has reserved some PID/VID pairs for shared use. You 127 | have no guarantee of uniqueness for them, except that no USB compliant device 128 | uses them. In order to avoid technical problems, we must ensure that all 129 | devices with the same pair of IDs use the same driver on kernel level. For 130 | details, see the file USB-IDs-for-free.txt. 131 | 132 | 133 | ====================================================== 134 | I HAVE HEARD THAT SUB-LICENSING OF USB-IDs IS ILLEGAL? 135 | ====================================================== 136 | 137 | A 16 bit integer number cannot be protected by copyright laws. It is not 138 | sufficiently complex. And since none of the parties involved entered into the 139 | USB-IF Trademark License Agreement, we are not bound by this agreement. So 140 | there is no reason why it should be illegal to sub-license USB-IDs. 141 | 142 | 143 | ============================================= 144 | WHO IS LIABLE IF THERE ARE INCOMPATIBILITIES? 145 | ============================================= 146 | 147 | Objective Development disclaims all liabilities which might arise from the 148 | assignment of IDs. If you guarantee product features to your customers 149 | without proper disclaimer, YOU are liable for that. 150 | -------------------------------------------------------------------------------- /Source/bootloader/usbdrv/USB-IDs-for-free.txt: -------------------------------------------------------------------------------- 1 | Version 2009-08-22 2 | 3 | =========================== 4 | FREE USB-IDs FOR SHARED USE 5 | =========================== 6 | 7 | Objective Development has reserved a set of USB Product-IDs for use according 8 | to the guidelines outlined below. For more information about the concept of 9 | USB IDs please see the file USB-ID-FAQ.txt. Objective Development guarantees 10 | that the IDs listed below are not used by any USB compliant devices. 11 | 12 | 13 | ==================== 14 | MECHANISM OF SHARING 15 | ==================== 16 | 17 | From a technical point of view, two different devices can share the same USB 18 | Vendor- and Product-ID if they require the same driver on operating system 19 | level. We make use of this fact by assigning separate IDs for various device 20 | classes. On application layer, devices must be distinguished by their textual 21 | name or serial number. We offer separate sets of IDs for discrimination by 22 | textual name and for serial number. 23 | 24 | Examples for shared use of USB IDs are included with V-USB in the "examples" 25 | subdirectory. 26 | 27 | 28 | ====================================== 29 | IDs FOR DISCRIMINATION BY TEXTUAL NAME 30 | ====================================== 31 | 32 | If you use one of the IDs listed below, your device and host-side software 33 | must conform to these rules: 34 | 35 | (1) The USB device MUST provide a textual representation of the manufacturer 36 | and product identification. The manufacturer identification MUST be available 37 | at least in USB language 0x0409 (English/US). 38 | 39 | (2) The textual manufacturer identification MUST contain either an Internet 40 | domain name (e.g. "mycompany.com") registered and owned by you, or an e-mail 41 | address under your control (e.g. "myname@gmx.net"). You can embed the domain 42 | name or e-mail address in any string you like, e.g. "Objective Development 43 | http://www.obdev.at/vusb/". 44 | 45 | (3) You are responsible for retaining ownership of the domain or e-mail 46 | address for as long as any of your products are in use. 47 | 48 | (4) You may choose any string for the textual product identification, as long 49 | as this string is unique within the scope of your textual manufacturer 50 | identification. 51 | 52 | (5) Application side device look-up MUST be based on the textual manufacturer 53 | and product identification in addition to VID/PID matching. The driver 54 | matching MUST be a comparison of the entire strings, NOT a sub-string match. 55 | 56 | (6) For devices which implement a particular USB device class (e.g. HID), the 57 | operating system's default class driver MUST be used. If an operating system 58 | driver for Vendor Class devices is needed, this driver must be libusb or 59 | libusb-win32 (see http://libusb.org/ and 60 | http://libusb-win32.sourceforge.net/). 61 | 62 | Table if IDs for discrimination by textual name: 63 | 64 | PID dec (hex) | VID dec (hex) | Description of use 65 | ==============+===============+============================================ 66 | 1500 (0x05dc) | 5824 (0x16c0) | For Vendor Class devices with libusb 67 | --------------+---------------+-------------------------------------------- 68 | 1503 (0x05df) | 5824 (0x16c0) | For generic HID class devices (which are 69 | | | NOT mice, keyboards or joysticks) 70 | --------------+---------------+-------------------------------------------- 71 | 1505 (0x05e1) | 5824 (0x16c0) | For CDC-ACM class devices (modems) 72 | --------------+---------------+-------------------------------------------- 73 | 1508 (0x05e4) | 5824 (0x16c0) | For MIDI class devices 74 | --------------+---------------+-------------------------------------------- 75 | 76 | Note that Windows caches the textual product- and vendor-description for 77 | mice, keyboards and joysticks. Name-bsed discrimination is therefore not 78 | recommended for these device classes. 79 | 80 | 81 | ======================================= 82 | IDs FOR DISCRIMINATION BY SERIAL NUMBER 83 | ======================================= 84 | 85 | If you use one of the IDs listed below, your device and host-side software 86 | must conform to these rules: 87 | 88 | (1) The USB device MUST provide a textual representation of the serial 89 | number, unless ONLY the operating system's default class driver is used. 90 | The serial number string MUST be available at least in USB language 0x0409 91 | (English/US). 92 | 93 | (2) The serial number MUST start with either an Internet domain name (e.g. 94 | "mycompany.com") registered and owned by you, or an e-mail address under your 95 | control (e.g. "myname@gmx.net"), both terminated with a colon (":") character. 96 | You MAY append any string you like for further discrimination of your devices. 97 | 98 | (3) You are responsible for retaining ownership of the domain or e-mail 99 | address for as long as any of your products are in use. 100 | 101 | (5) Application side device look-up MUST be based on the serial number string 102 | in addition to VID/PID matching. The matching must start at the first 103 | character of the serial number string and include the colon character 104 | terminating your domain or e-mail address. It MAY stop anywhere after that. 105 | 106 | (6) For devices which implement a particular USB device class (e.g. HID), the 107 | operating system's default class driver MUST be used. If an operating system 108 | driver for Vendor Class devices is needed, this driver must be libusb or 109 | libusb-win32 (see http://libusb.org/ and 110 | http://libusb-win32.sourceforge.net/). 111 | 112 | (7) If ONLY the operating system's default class driver is used, e.g. for 113 | mice, keyboards, joysticks, CDC or MIDI devices and no discrimination by an 114 | application is needed, the serial number may be omitted. 115 | 116 | 117 | Table if IDs for discrimination by serial number string: 118 | 119 | PID dec (hex) | VID dec (hex) | Description of use 120 | ===============+===============+=========================================== 121 | 10200 (0x27d8) | 5824 (0x16c0) | For Vendor Class devices with libusb 122 | ---------------+---------------+------------------------------------------- 123 | 10201 (0x27d9) | 5824 (0x16c0) | For generic HID class devices (which are 124 | | | NOT mice, keyboards or joysticks) 125 | ---------------+---------------+------------------------------------------- 126 | 10202 (0x27da) | 5824 (0x16c0) | For USB Mice 127 | ---------------+---------------+------------------------------------------- 128 | 10203 (0x27db) | 5824 (0x16c0) | For USB Keyboards 129 | ---------------+---------------+------------------------------------------- 130 | 10204 (0x27dc) | 5824 (0x16c0) | For USB Joysticks 131 | ---------------+---------------+------------------------------------------- 132 | 10205 (0x27dd) | 5824 (0x16c0) | For CDC-ACM class devices (modems) 133 | ---------------+---------------+------------------------------------------- 134 | 10206 (0x27de) | 5824 (0x16c0) | For MIDI class devices 135 | ---------------+---------------+------------------------------------------- 136 | 137 | 138 | ================= 139 | ORIGIN OF USB-IDs 140 | ================= 141 | 142 | OBJECTIVE DEVELOPMENT Software GmbH has obtained all VID/PID pairs listed 143 | here from Wouter van Ooijen (see www.voti.nl) for exclusive disposition. 144 | Wouter van Ooijen has obtained the VID from the USB Implementers Forum, Inc. 145 | (see www.usb.org). The VID is registered for the company name "Van Ooijen 146 | Technische Informatica". 147 | 148 | 149 | ========== 150 | DISCLAIMER 151 | ========== 152 | 153 | OBJECTIVE DEVELOPMENT Software GmbH disclaims all liability for any 154 | problems which are caused by the shared use of these VID/PID pairs. 155 | -------------------------------------------------------------------------------- /Source/bootloader/usbdrv/asmcommon.inc: -------------------------------------------------------------------------------- 1 | /* Name: asmcommon.inc 2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2007-11-05 5 | * Tabsize: 4 6 | * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 8 | */ 9 | 10 | /* Do not link this file! Link usbdrvasm.S instead, which includes the 11 | * appropriate implementation! 12 | */ 13 | 14 | /* 15 | General Description: 16 | This file contains assembler code which is shared among the USB driver 17 | implementations for different CPU cocks. Since the code must be inserted 18 | in the middle of the module, it's split out into this file and #included. 19 | 20 | Jump destinations called from outside: 21 | sofError: Called when no start sequence was found. 22 | se0: Called when a package has been successfully received. 23 | overflow: Called when receive buffer overflows. 24 | doReturn: Called after sending data. 25 | 26 | Outside jump destinations used by this module: 27 | waitForJ: Called to receive an already arriving packet. 28 | sendAckAndReti: 29 | sendNakAndReti: 30 | sendCntAndReti: 31 | usbSendAndReti: 32 | 33 | The following macros must be defined before this file is included: 34 | .macro POP_STANDARD 35 | .endm 36 | .macro POP_RETI 37 | .endm 38 | */ 39 | 40 | #define token x1 41 | 42 | overflow: 43 | ldi x2, 1< 0 13 | 14 | #warning "Never compile production devices with debugging enabled" 15 | 16 | static void uartPutc(char c) 17 | { 18 | while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */ 19 | ODDBG_UDR = c; 20 | } 21 | 22 | static uchar hexAscii(uchar h) 23 | { 24 | h &= 0xf; 25 | if(h >= 10) 26 | h += 'a' - (uchar)10 - '0'; 27 | h += '0'; 28 | return h; 29 | } 30 | 31 | static void printHex(uchar c) 32 | { 33 | uartPutc(hexAscii(c >> 4)); 34 | uartPutc(hexAscii(c)); 35 | } 36 | 37 | void odDebug(uchar prefix, uchar *data, uchar len) 38 | { 39 | printHex(prefix); 40 | uartPutc(':'); 41 | while(len--){ 42 | uartPutc(' '); 43 | printHex(*data++); 44 | } 45 | uartPutc('\r'); 46 | uartPutc('\n'); 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /Source/bootloader/usbdrv/oddebug.h: -------------------------------------------------------------------------------- 1 | /* Name: oddebug.h 2 | * Project: AVR library 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2005-01-16 5 | * Tabsize: 4 6 | * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 8 | */ 9 | 10 | #ifndef __oddebug_h_included__ 11 | #define __oddebug_h_included__ 12 | 13 | /* 14 | General Description: 15 | This module implements a function for debug logs on the serial line of the 16 | AVR microcontroller. Debugging can be configured with the define 17 | 'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging 18 | calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is 19 | 2, DBG1 and DBG2 logs will be printed. 20 | 21 | A debug log consists of a label ('prefix') to indicate which debug log created 22 | the output and a memory block to dump in hex ('data' and 'len'). 23 | */ 24 | 25 | 26 | #ifndef F_CPU 27 | # define F_CPU 12000000 /* 12 MHz */ 28 | #endif 29 | 30 | /* make sure we have the UART defines: */ 31 | #include "usbportability.h" 32 | 33 | #ifndef uchar 34 | # define uchar unsigned char 35 | #endif 36 | 37 | #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */ 38 | # warning "Debugging disabled because device has no UART" 39 | # undef DEBUG_LEVEL 40 | #endif 41 | 42 | #ifndef DEBUG_LEVEL 43 | # define DEBUG_LEVEL 0 44 | #endif 45 | 46 | /* ------------------------------------------------------------------------- */ 47 | 48 | #if DEBUG_LEVEL > 0 49 | # define DBG1(prefix, data, len) odDebug(prefix, data, len) 50 | #else 51 | # define DBG1(prefix, data, len) 52 | #endif 53 | 54 | #if DEBUG_LEVEL > 1 55 | # define DBG2(prefix, data, len) odDebug(prefix, data, len) 56 | #else 57 | # define DBG2(prefix, data, len) 58 | #endif 59 | 60 | /* ------------------------------------------------------------------------- */ 61 | 62 | #if DEBUG_LEVEL > 0 63 | extern void odDebug(uchar prefix, uchar *data, uchar len); 64 | 65 | /* Try to find our control registers; ATMEL likes to rename these */ 66 | 67 | #if defined UBRR 68 | # define ODDBG_UBRR UBRR 69 | #elif defined UBRRL 70 | # define ODDBG_UBRR UBRRL 71 | #elif defined UBRR0 72 | # define ODDBG_UBRR UBRR0 73 | #elif defined UBRR0L 74 | # define ODDBG_UBRR UBRR0L 75 | #endif 76 | 77 | #if defined UCR 78 | # define ODDBG_UCR UCR 79 | #elif defined UCSRB 80 | # define ODDBG_UCR UCSRB 81 | #elif defined UCSR0B 82 | # define ODDBG_UCR UCSR0B 83 | #endif 84 | 85 | #if defined TXEN 86 | # define ODDBG_TXEN TXEN 87 | #else 88 | # define ODDBG_TXEN TXEN0 89 | #endif 90 | 91 | #if defined USR 92 | # define ODDBG_USR USR 93 | #elif defined UCSRA 94 | # define ODDBG_USR UCSRA 95 | #elif defined UCSR0A 96 | # define ODDBG_USR UCSR0A 97 | #endif 98 | 99 | #if defined UDRE 100 | # define ODDBG_UDRE UDRE 101 | #else 102 | # define ODDBG_UDRE UDRE0 103 | #endif 104 | 105 | #if defined UDR 106 | # define ODDBG_UDR UDR 107 | #elif defined UDR0 108 | # define ODDBG_UDR UDR0 109 | #endif 110 | 111 | static inline void odDebugInit(void) 112 | { 113 | ODDBG_UCR |= (1< 38 | #ifndef __IAR_SYSTEMS_ASM__ 39 | # include 40 | #endif 41 | 42 | #define __attribute__(arg) /* not supported on IAR */ 43 | 44 | #ifdef __IAR_SYSTEMS_ASM__ 45 | # define __ASSEMBLER__ /* IAR does not define standard macro for asm */ 46 | #endif 47 | 48 | #ifdef __HAS_ELPM__ 49 | # define PROGMEM __farflash 50 | #else 51 | # define PROGMEM __flash 52 | #endif 53 | 54 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr)) 55 | 56 | /* The following definitions are not needed by the driver, but may be of some 57 | * help if you port a gcc based project to IAR. 58 | */ 59 | #define cli() __disable_interrupt() 60 | #define sei() __enable_interrupt() 61 | #define wdt_reset() __watchdog_reset() 62 | #define _BV(x) (1 << (x)) 63 | 64 | /* assembler compatibility macros */ 65 | #define nop2 rjmp $+2 /* jump to next instruction */ 66 | #define XL r26 67 | #define XH r27 68 | #define YL r28 69 | #define YH r29 70 | #define ZL r30 71 | #define ZH r31 72 | #define lo8(x) LOW(x) 73 | #define hi8(x) (((x)>>8) & 0xff) /* not HIGH to allow XLINK to make a proper range check */ 74 | 75 | /* Depending on the device you use, you may get problems with the way usbdrv.h 76 | * handles the differences between devices. Since IAR does not use #defines 77 | * for MCU registers, we can't check for the existence of a particular 78 | * register with an #ifdef. If the autodetection mechanism fails, include 79 | * definitions for the required USB_INTR_* macros in your usbconfig.h. See 80 | * usbconfig-prototype.h and usbdrv.h for details. 81 | */ 82 | 83 | /* ------------------------------------------------------------------------- */ 84 | #elif __CODEVISIONAVR__ /* check for CodeVision AVR */ 85 | /* ------------------------------------------------------------------------- */ 86 | /* This port is not working (yet) */ 87 | 88 | /* #define F_CPU _MCU_CLOCK_FREQUENCY_ seems to be defined automatically */ 89 | 90 | #include 91 | #include 92 | 93 | #define __attribute__(arg) /* not supported on IAR */ 94 | 95 | #define PROGMEM __flash 96 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr)) 97 | 98 | #ifndef __ASSEMBLER__ 99 | static inline void cli(void) 100 | { 101 | #asm("cli"); 102 | } 103 | static inline void sei(void) 104 | { 105 | #asm("sei"); 106 | } 107 | #endif 108 | #define _delay_ms(t) delay_ms(t) 109 | #define _BV(x) (1 << (x)) 110 | #define USB_CFG_USE_SWITCH_STATEMENT 1 /* macro for if() cascase fails for unknown reason */ 111 | 112 | #define macro .macro 113 | #define endm .endmacro 114 | #define nop2 rjmp .+0 /* jump to next instruction */ 115 | 116 | /* ------------------------------------------------------------------------- */ 117 | #else /* default development environment is avr-gcc/avr-libc */ 118 | /* ------------------------------------------------------------------------- */ 119 | 120 | #include 121 | #ifdef __ASSEMBLER__ 122 | # define _VECTOR(N) __vector_ ## N /* io.h does not define this for asm */ 123 | #else 124 | # include 125 | #endif 126 | 127 | #if USB_CFG_DRIVER_FLASH_PAGE 128 | # define USB_READ_FLASH(addr) pgm_read_byte_far(((long)USB_CFG_DRIVER_FLASH_PAGE << 16) | (long)(addr)) 129 | #else 130 | # define USB_READ_FLASH(addr) pgm_read_byte(addr) 131 | #endif 132 | 133 | #define macro .macro 134 | #define endm .endm 135 | #define nop2 rjmp .+0 /* jump to next instruction */ 136 | 137 | #endif /* development environment */ 138 | 139 | /* for conveniecne, ensure that PRG_RDB exists */ 140 | #ifndef PRG_RDB 141 | # define PRG_RDB(addr) USB_READ_FLASH(addr) 142 | #endif 143 | #endif /* __usbportability_h_INCLUDED__ */ 144 | -------------------------------------------------------------------------------- /Source/cd32.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Source/cd32.c -------------------------------------------------------------------------------- /Source/joystick.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Source/joystick.c -------------------------------------------------------------------------------- /Source/msx.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Source/msx.c -------------------------------------------------------------------------------- /Source/nes.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Source/nes.c -------------------------------------------------------------------------------- /Source/sega.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Source/sega.c -------------------------------------------------------------------------------- /Source/snes.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Source/snes.c -------------------------------------------------------------------------------- /Source/snesnes.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/Source/snesnes.c -------------------------------------------------------------------------------- /Source/usbdrv/CommercialLicense.txt: -------------------------------------------------------------------------------- 1 | V-USB Driver Software License Agreement 2 | Version 2012-07-09 3 | 4 | THIS LICENSE AGREEMENT GRANTS YOU CERTAIN RIGHTS IN A SOFTWARE. YOU CAN 5 | ENTER INTO THIS AGREEMENT AND ACQUIRE THE RIGHTS OUTLINED BELOW BY PAYING 6 | THE AMOUNT ACCORDING TO SECTION 4 ("PAYMENT") TO OBJECTIVE DEVELOPMENT. 7 | 8 | 9 | 1 DEFINITIONS 10 | 11 | 1.1 "OBJECTIVE DEVELOPMENT" shall mean OBJECTIVE DEVELOPMENT Software GmbH, 12 | Grosse Schiffgasse 1A/7, 1020 Wien, AUSTRIA. 13 | 14 | 1.2 "You" shall mean the Licensee. 15 | 16 | 1.3 "V-USB" shall mean all files included in the package distributed under 17 | the name "vusb" by OBJECTIVE DEVELOPMENT (http://www.obdev.at/vusb/) 18 | unless otherwise noted. This includes the firmware-only USB device 19 | implementation for Atmel AVR microcontrollers, some simple device examples 20 | and host side software examples and libraries. 21 | 22 | 23 | 2 LICENSE GRANTS 24 | 25 | 2.1 Source Code. OBJECTIVE DEVELOPMENT shall furnish you with the source 26 | code of V-USB. 27 | 28 | 2.2 Distribution and Use. OBJECTIVE DEVELOPMENT grants you the 29 | non-exclusive right to use, copy and distribute V-USB with your hardware 30 | product(s), restricted by the limitations in section 3 below. 31 | 32 | 2.3 Modifications. OBJECTIVE DEVELOPMENT grants you the right to modify 33 | the source code and your copy of V-USB according to your needs. 34 | 35 | 2.4 USB IDs. OBJECTIVE DEVELOPMENT furnishes you with one or two USB 36 | Product ID(s), sent to you in e-mail. These Product IDs are reserved 37 | exclusively for you. OBJECTIVE DEVELOPMENT has obtained USB Product ID 38 | ranges under the Vendor ID 5824 from Wouter van Ooijen (Van Ooijen 39 | Technische Informatica, www.voti.nl) and under the Vendor ID 8352 from 40 | Jason Kotzin (now flirc.tv, Inc.). Both owners of the Vendor IDs have 41 | obtained these IDs from the USB Implementers Forum, Inc. (www.usb.org). 42 | OBJECTIVE DEVELOPMENT disclaims all liability which might arise from the 43 | assignment of USB IDs. 44 | 45 | 2.5 USB Certification. Although not part of this agreement, we want to make 46 | it clear that you cannot become USB certified when you use V-USB or a USB 47 | Product ID assigned by OBJECTIVE DEVELOPMENT. AVR microcontrollers don't 48 | meet the electrical specifications required by the USB specification and 49 | the USB Implementers Forum certifies only members who bought a Vendor ID of 50 | their own. 51 | 52 | 53 | 3 LICENSE RESTRICTIONS 54 | 55 | 3.1 Number of Units. Only one of the following three definitions is 56 | applicable. Which one is determined by the amount you pay to OBJECTIVE 57 | DEVELOPMENT, see section 4 ("Payment") below. 58 | 59 | Hobby License: You may use V-USB according to section 2 above in no more 60 | than 5 hardware units. These units must not be sold for profit. 61 | 62 | Entry Level License: You may use V-USB according to section 2 above in no 63 | more than 150 hardware units. 64 | 65 | Professional License: You may use V-USB according to section 2 above in 66 | any number of hardware units, except for large scale production ("unlimited 67 | fair use"). Quantities below 10,000 units are not considered large scale 68 | production. If your reach quantities which are obviously large scale 69 | production, you must pay a license fee of 0.10 EUR per unit for all units 70 | above 10,000. 71 | 72 | 3.2 Rental. You may not rent, lease, or lend V-USB or otherwise encumber 73 | any copy of V-USB, or any of the rights granted herein. 74 | 75 | 3.3 Transfer. You may not transfer your rights under this Agreement to 76 | another party without OBJECTIVE DEVELOPMENT's prior written consent. If 77 | such consent is obtained, you may permanently transfer this License to 78 | another party. The recipient of such transfer must agree to all terms and 79 | conditions of this Agreement. 80 | 81 | 3.4 Reservation of Rights. OBJECTIVE DEVELOPMENT retains all rights not 82 | expressly granted. 83 | 84 | 3.5 Non-Exclusive Rights. Your license rights under this Agreement are 85 | non-exclusive. 86 | 87 | 3.6 Third Party Rights. This Agreement cannot grant you rights controlled 88 | by third parties. In particular, you are not allowed to use the USB logo or 89 | other trademarks owned by the USB Implementers Forum, Inc. without their 90 | consent. Since such consent depends on USB certification, it should be 91 | noted that V-USB will not pass certification because it does not 92 | implement checksum verification and the microcontroller ports do not meet 93 | the electrical specifications. 94 | 95 | 96 | 4 PAYMENT 97 | 98 | The payment amount depends on the variation of this agreement (according to 99 | section 3.1) into which you want to enter. Concrete prices are listed on 100 | OBJECTIVE DEVELOPMENT's web site, usually at 101 | http://www.obdev.at/vusb/license.html. You agree to pay the amount listed 102 | there to OBJECTIVE DEVELOPMENT or OBJECTIVE DEVELOPMENT's payment processor 103 | or reseller. 104 | 105 | 106 | 5 COPYRIGHT AND OWNERSHIP 107 | 108 | V-USB is protected by copyright laws and international copyright 109 | treaties, as well as other intellectual property laws and treaties. V-USB 110 | is licensed, not sold. 111 | 112 | 113 | 6 TERM AND TERMINATION 114 | 115 | 6.1 Term. This Agreement shall continue indefinitely. However, OBJECTIVE 116 | DEVELOPMENT may terminate this Agreement and revoke the granted license and 117 | USB-IDs if you fail to comply with any of its terms and conditions. 118 | 119 | 6.2 Survival of Terms. All provisions regarding secrecy, confidentiality 120 | and limitation of liability shall survive termination of this agreement. 121 | 122 | 123 | 7 DISCLAIMER OF WARRANTY AND LIABILITY 124 | 125 | LIMITED WARRANTY. V-USB IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 126 | KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, OBJECTIVE 127 | DEVELOPMENT AND ITS SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES, EITHER 128 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 129 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND 130 | NON-INFRINGEMENT, WITH REGARD TO V-USB, AND THE PROVISION OF OR FAILURE 131 | TO PROVIDE SUPPORT SERVICES. THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL 132 | RIGHTS. YOU MAY HAVE OTHERS, WHICH VARY FROM STATE/JURISDICTION TO 133 | STATE/JURISDICTION. 134 | 135 | LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, 136 | IN NO EVENT SHALL OBJECTIVE DEVELOPMENT OR ITS SUPPLIERS BE LIABLE FOR ANY 137 | SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER 138 | (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, 139 | BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY 140 | LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE V-USB OR THE 141 | PROVISION OF OR FAILURE TO PROVIDE SUPPORT SERVICES, EVEN IF OBJECTIVE 142 | DEVELOPMENT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY 143 | CASE, OBJECTIVE DEVELOPMENT'S ENTIRE LIABILITY UNDER ANY PROVISION OF THIS 144 | AGREEMENT SHALL BE LIMITED TO THE AMOUNT ACTUALLY PAID BY YOU FOR V-USB. 145 | 146 | 147 | 8 MISCELLANEOUS TERMS 148 | 149 | 8.1 Marketing. OBJECTIVE DEVELOPMENT has the right to mention for marketing 150 | purposes that you entered into this agreement. 151 | 152 | 8.2 Entire Agreement. This document represents the entire agreement between 153 | OBJECTIVE DEVELOPMENT and you. It may only be modified in writing signed by 154 | an authorized representative of both, OBJECTIVE DEVELOPMENT and you. 155 | 156 | 8.3 Severability. In case a provision of these terms and conditions should 157 | be or become partly or entirely invalid, ineffective, or not executable, 158 | the validity of all other provisions shall not be affected. 159 | 160 | 8.4 Applicable Law. This agreement is governed by the laws of the Republic 161 | of Austria. 162 | 163 | 8.5 Responsible Courts. The responsible courts in Vienna/Austria will have 164 | exclusive jurisdiction regarding all disputes in connection with this 165 | agreement. 166 | 167 | -------------------------------------------------------------------------------- /Source/usbdrv/Readme.txt: -------------------------------------------------------------------------------- 1 | This is the Readme file to Objective Development's firmware-only USB driver 2 | for Atmel AVR microcontrollers. For more information please visit 3 | http://www.obdev.at/vusb/ 4 | 5 | This directory contains the USB firmware only. Copy it as-is to your own 6 | project and add all .c and .S files to your project (these files are marked 7 | with an asterisk in the list below). Then copy usbconfig-prototype.h as 8 | usbconfig.h to your project and edit it according to your configuration. 9 | 10 | 11 | TECHNICAL DOCUMENTATION 12 | ======================= 13 | The technical documentation (API) for the firmware driver is contained in the 14 | file "usbdrv.h". Please read all of it carefully! Configuration options are 15 | documented in "usbconfig-prototype.h". 16 | 17 | The driver consists of the following files: 18 | Readme.txt ............. The file you are currently reading. 19 | Changelog.txt .......... Release notes for all versions of the driver. 20 | usbdrv.h ............... Driver interface definitions and technical docs. 21 | * usbdrv.c ............... High level language part of the driver. Link this 22 | module to your code! 23 | * usbdrvasm.S ............ Assembler part of the driver. This module is mostly 24 | a stub and includes one of the usbdrvasm*.S files 25 | depending on processor clock. Link this module to 26 | your code! 27 | usbdrvasm*.inc ......... Assembler routines for particular clock frequencies. 28 | Included by usbdrvasm.S, don't link it directly! 29 | asmcommon.inc .......... Common assembler routines. Included by 30 | usbdrvasm*.inc, don't link it directly! 31 | usbconfig-prototype.h .. Prototype for your own usbdrv.h file. 32 | * oddebug.c .............. Debug functions. Only used when DEBUG_LEVEL is 33 | defined to a value greater than 0. Link this module 34 | to your code! 35 | oddebug.h .............. Interface definitions of the debug module. 36 | usbportability.h ....... Header with compiler-dependent stuff. 37 | usbdrvasm.asm .......... Compatibility stub for IAR-C-compiler. Use this 38 | module instead of usbdrvasm.S when you assembler 39 | with IAR's tools. 40 | License.txt ............ Open Source license for this driver. 41 | CommercialLicense.txt .. Optional commercial license for this driver. 42 | USB-ID-FAQ.txt ......... General infos about USB Product- and Vendor-IDs. 43 | USB-IDs-for-free.txt ... List and terms of use for free shared PIDs. 44 | 45 | (*) ... These files should be linked to your project. 46 | 47 | 48 | CPU CORE CLOCK FREQUENCY 49 | ======================== 50 | We supply assembler modules for clock frequencies of 12 MHz, 12.8 MHz, 15 MHz, 51 | 16 MHz, 16.5 MHz 18 MHz and 20 MHz. Other clock rates are not supported. The 52 | actual clock rate must be configured in usbconfig.h. 53 | 54 | 12 MHz Clock 55 | This is the traditional clock rate of V-USB because it's the lowest clock 56 | rate where the timing constraints of the USB spec can be met. 57 | 58 | 15 MHz Clock 59 | Similar to 12 MHz, but some NOPs inserted. On the other hand, the higher clock 60 | rate allows for some loops which make the resulting code size somewhat smaller 61 | than the 12 MHz version. 62 | 63 | 16 MHz Clock 64 | This clock rate has been added for users of the Arduino board and other 65 | ready-made boards which come with a fixed 16 MHz crystal. It's also an option 66 | if you need the slightly higher clock rate for performance reasons. Since 67 | 16 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code 68 | is somewhat tricky and has to insert a leap cycle every third byte. 69 | 70 | 12.8 MHz and 16.5 MHz Clock 71 | The assembler modules for these clock rates differ from the other modules 72 | because they have been built for an RC oscillator with only 1% precision. The 73 | receiver code inserts leap cycles to compensate for clock deviations. 1% is 74 | also the precision which can be achieved by calibrating the internal RC 75 | oscillator of the AVR. Please note that only AVRs with internal 64 MHz PLL 76 | oscillator can reach 16.5 MHz with the RC oscillator. This includes the very 77 | popular ATTiny25, ATTiny45, ATTiny85 series as well as the ATTiny26. Almost 78 | all AVRs can reach 12.8 MHz, although this is outside the specified range. 79 | 80 | See the EasyLogger example at http://www.obdev.at/vusb/easylogger.html for 81 | code which calibrates the RC oscillator based on the USB frame clock. 82 | 83 | 18 MHz Clock 84 | This module is closer to the USB specification because it performs an on the 85 | fly CRC check for incoming packets. Packets with invalid checksum are 86 | discarded as required by the spec. If you also implement checks for data 87 | PID toggling on application level (see option USB_CFG_CHECK_DATA_TOGGLING 88 | in usbconfig.h for more info), this ensures data integrity. Due to the CRC 89 | tables and alignment requirements, this code is bigger than modules for other 90 | clock rates. To activate this module, you must define USB_CFG_CHECK_CRC to 1 91 | and USB_CFG_CLOCK_KHZ to 18000 in usbconfig.h. 92 | 93 | 20 MHz Clock 94 | This module is for people who won't do it with less than the maximum. Since 95 | 20 MHz is not divisible by the USB low speed bit clock of 1.5 MHz, the code 96 | uses similar tricks as the 16 MHz module to insert leap cycles. 97 | 98 | 99 | USB IDENTIFIERS 100 | =============== 101 | Every USB device needs a vendor- and a product-identifier (VID and PID). VIDs 102 | are obtained from usb.org for a price of 1,500 USD. Once you have a VID, you 103 | can assign PIDs at will. 104 | 105 | Since an entry level cost of 1,500 USD is too high for most small companies 106 | and hobbyists, we provide some VID/PID pairs for free. See the file 107 | USB-IDs-for-free.txt for details. 108 | 109 | Objective Development also has some license offerings which include product 110 | IDs. See http://www.obdev.at/vusb/ for details. 111 | 112 | 113 | DEVELOPMENT SYSTEM 114 | ================== 115 | This driver has been developed and optimized for the GNU compiler version 3 116 | and 4. We recommend that you use the GNU compiler suite because it is freely 117 | available. V-USB has also been ported to the IAR compiler and assembler. It 118 | has been tested with IAR 4.10B/W32 and 4.12A/W32 on an ATmega8 with the 119 | "small" and "tiny" memory model. Not every release is tested with IAR CC and 120 | the driver may therefore fail to compile with IAR. Please note that gcc is 121 | more efficient for usbdrv.c because this module has been deliberately 122 | optimized for gcc. 123 | 124 | Gcc version 3 produces smaller code than version 4 due to new optimizing 125 | capabilities which don't always improve things on 8 bit CPUs. The code size 126 | generated by gcc 4 can be reduced with the compiler options 127 | -fno-move-loop-invariants, -fno-tree-scev-cprop and 128 | -fno-inline-small-functions in addition to -Os. On devices with more than 129 | 8k of flash memory, we also recommend the linker option --relax (written as 130 | -Wl,--relax for gcc) to convert absolute calls into relative where possible. 131 | 132 | For more information about optimizing options see: 133 | 134 | http://www.tty1.net/blog/2008-04-29-avr-gcc-optimisations_en.html 135 | 136 | These optimizations are good for gcc 4.x. Version 3.x of gcc does not support 137 | most of these options and produces good code anyway. 138 | 139 | 140 | USING V-USB FOR FREE 141 | ==================== 142 | The AVR firmware driver is published under the GNU General Public License 143 | Version 2 (GPL2) and the GNU General Public License Version 3 (GPL3). It is 144 | your choice whether you apply the terms of version 2 or version 3. 145 | 146 | If you decide for the free GPL2 or GPL3, we STRONGLY ENCOURAGE you to do the 147 | following things IN ADDITION to the obligations from the GPL: 148 | 149 | (1) Publish your entire project on a web site and drop us a note with the URL. 150 | Use the form at http://www.obdev.at/vusb/feedback.html for your submission. 151 | If you don't have a web site, you can publish the project in obdev's 152 | documentation wiki at 153 | http://www.obdev.at/goto.php?t=vusb-wiki&p=hosted-projects. 154 | 155 | (2) Adhere to minimum publication standards. Please include AT LEAST: 156 | - a circuit diagram in PDF, PNG or GIF format 157 | - full source code for the host software 158 | - a Readme.txt file in ASCII format which describes the purpose of the 159 | project and what can be found in which directories and which files 160 | - a reference to http://www.obdev.at/vusb/ 161 | 162 | (3) If you improve the driver firmware itself, please give us a free license 163 | to your modifications for our commercial license offerings. 164 | 165 | 166 | COMMERCIAL LICENSES FOR V-USB 167 | ============================= 168 | If you don't want to publish your source code under the terms of the GPL, 169 | you can simply pay money for V-USB. As an additional benefit you get 170 | USB PIDs for free, reserved exclusively to you. See the file 171 | "CommercialLicense.txt" for details. 172 | 173 | -------------------------------------------------------------------------------- /Source/usbdrv/USB-ID-FAQ.txt: -------------------------------------------------------------------------------- 1 | Version 2012-07-09 2 | 3 | ========================== 4 | WHY DO WE NEED THESE IDs? 5 | ========================== 6 | 7 | USB is more than a low level protocol for data transport. It also defines a 8 | common set of requests which must be understood by all devices. And as part 9 | of these common requests, the specification defines data structures, the 10 | USB Descriptors, which are used to describe the properties of the device. 11 | 12 | From the perspective of an operating system, it is therefore possible to find 13 | out basic properties of a device (such as e.g. the manufacturer and the name 14 | of the device) without a device-specific driver. This is essential because 15 | the operating system can choose a driver to load based on this information 16 | (Plug-And-Play). 17 | 18 | Among the most important properties in the Device Descriptor are the USB 19 | Vendor- and Product-ID. Both are 16 bit integers. The most simple form of 20 | driver matching is based on these IDs. The driver announces the Vendor- and 21 | Product-IDs of the devices it can handle and the operating system loads the 22 | appropriate driver when the device is connected. 23 | 24 | It is obvious that this technique only works if the pair Vendor- plus 25 | Product-ID is unique: Only devices which require the same driver can have the 26 | same pair of IDs. 27 | 28 | 29 | ===================================================== 30 | HOW DOES THE USB STANDARD ENSURE THAT IDs ARE UNIQUE? 31 | ===================================================== 32 | 33 | Since it is so important that USB IDs are unique, the USB Implementers Forum, 34 | Inc. (usb.org) needs a way to enforce this legally. It is not forbidden by 35 | law to build a device and assign it any random numbers as IDs. Usb.org 36 | therefore needs an agreement to regulate the use of USB IDs. The agreement 37 | binds only parties who agreed to it, of course. Everybody else is free to use 38 | any numbers for their IDs. 39 | 40 | So how can usb.org ensure that every manufacturer of USB devices enters into 41 | an agreement with them? They do it via trademark licensing. Usb.org has 42 | registered the trademark "USB", all associated logos and related terms. If 43 | you want to put an USB logo on your product or claim that it is USB 44 | compliant, you must license these trademarks from usb.org. And this is where 45 | you enter into an agreement. See the "USB-IF Trademark License Agreement and 46 | Usage Guidelines for the USB-IF Logo" at 47 | http://www.usb.org/developers/logo_license/. 48 | 49 | Licensing the USB trademarks requires that you buy a USB Vendor-ID from 50 | usb.org (one-time fee of ca. 2,000 USD), that you become a member of usb.org 51 | (yearly fee of ca. 4,000 USD) and that you meet all the technical 52 | specifications from the USB spec. 53 | 54 | This means that most hobbyists and small companies will never be able to 55 | become USB compliant, just because membership is so expensive. And you can't 56 | be compliant with a driver based on V-USB anyway, because the AVR's port pins 57 | don't meet the electrical specifications for USB. So, in principle, all 58 | hobbyists and small companies are free to choose any random numbers for their 59 | IDs. They have nothing to lose... 60 | 61 | There is one exception worth noting, though: If you use a sub-component which 62 | implements USB, the vendor of the sub-components may guarantee USB 63 | compliance. This might apply to some or all of FTDI's solutions. 64 | 65 | 66 | ======================================================================= 67 | WHY SHOULD YOU OBTAIN USB IDs EVEN IF YOU DON'T LICENSE USB TRADEMARKS? 68 | ======================================================================= 69 | 70 | You have learned in the previous section that you are free to choose any 71 | numbers for your IDs anyway. So why not do exactly this? There is still the 72 | technical issue. If you choose IDs which are already in use by somebody else, 73 | operating systems will load the wrong drivers and your device won't work. 74 | Even if you choose IDs which are not currently in use, they may be in use in 75 | the next version of the operating system or even after an automatic update. 76 | 77 | So what you need is a pair of Vendor- and Product-IDs for which you have the 78 | guarantee that no USB compliant product uses them. This implies that no 79 | operating system will ever ship with drivers responsible for these IDs. 80 | 81 | 82 | ============================================== 83 | HOW DOES OBJECTIVE DEVELOPMENT HANDLE USB IDs? 84 | ============================================== 85 | 86 | Objective Development gives away pairs of USB-IDs with their V-USB licenses. 87 | In order to ensure that these IDs are unique, Objective Development has an 88 | agreement with the company/person who has bought the USB Vendor-ID from 89 | usb.org. This agreement ensures that a range of USB Product-IDs is reserved 90 | for assignment by Objective Development and that the owner of the Vendor-ID 91 | won't give it to anybody else. 92 | 93 | This means that you have to trust three parties to ensure uniqueness of 94 | your IDs: 95 | 96 | - Objective Development, that they don't give the same PID to more than 97 | one person. 98 | - The owner of the Vendor-ID that they don't assign PIDs from the range 99 | assigned to Objective Development to anybody else. 100 | - Usb.org that they don't assign the same Vendor-ID a second time. 101 | 102 | 103 | ================================== 104 | WHO IS THE OWNER OF THE VENDOR-ID? 105 | ================================== 106 | 107 | Objective Development has obtained ranges of USB Product-IDs under two 108 | Vendor-IDs: Under Vendor-ID 5824 from Wouter van Ooijen (Van Ooijen 109 | Technische Informatica, www.voti.nl) and under Vendor-ID 8352 from Jason 110 | Kotzin (now flirc.tv, Inc.). Both VID owners have received their Vendor-ID 111 | directly from usb.org. 112 | 113 | 114 | ========================================================================= 115 | CAN I USE USB-IDs FROM OBJECTIVE DEVELOPMENT WITH OTHER DRIVERS/HARDWARE? 116 | ========================================================================= 117 | 118 | The short answer is: Yes. All you get is a guarantee that the IDs are never 119 | assigned to anybody else. What more do you need? 120 | 121 | 122 | ============================ 123 | WHAT ABOUT SHARED ID PAIRS? 124 | ============================ 125 | 126 | Objective Development has reserved some PID/VID pairs for shared use. You 127 | have no guarantee of uniqueness for them, except that no USB compliant device 128 | uses them. In order to avoid technical problems, we must ensure that all 129 | devices with the same pair of IDs use the same driver on kernel level. For 130 | details, see the file USB-IDs-for-free.txt. 131 | 132 | 133 | ====================================================== 134 | I HAVE HEARD THAT SUB-LICENSING OF USB-IDs IS ILLEGAL? 135 | ====================================================== 136 | 137 | A 16 bit integer number cannot be protected by copyright laws. It is not 138 | sufficiently complex. And since none of the parties involved entered into the 139 | USB-IF Trademark License Agreement, we are not bound by this agreement. So 140 | there is no reason why it should be illegal to sub-license USB-IDs. 141 | 142 | 143 | ============================================= 144 | WHO IS LIABLE IF THERE ARE INCOMPATIBILITIES? 145 | ============================================= 146 | 147 | Objective Development disclaims all liabilities which might arise from the 148 | assignment of IDs. If you guarantee product features to your customers 149 | without proper disclaimer, YOU are liable for that. 150 | -------------------------------------------------------------------------------- /Source/usbdrv/USB-IDs-for-free.txt: -------------------------------------------------------------------------------- 1 | Version 2009-08-22 2 | 3 | =========================== 4 | FREE USB-IDs FOR SHARED USE 5 | =========================== 6 | 7 | Objective Development has reserved a set of USB Product-IDs for use according 8 | to the guidelines outlined below. For more information about the concept of 9 | USB IDs please see the file USB-ID-FAQ.txt. Objective Development guarantees 10 | that the IDs listed below are not used by any USB compliant devices. 11 | 12 | 13 | ==================== 14 | MECHANISM OF SHARING 15 | ==================== 16 | 17 | From a technical point of view, two different devices can share the same USB 18 | Vendor- and Product-ID if they require the same driver on operating system 19 | level. We make use of this fact by assigning separate IDs for various device 20 | classes. On application layer, devices must be distinguished by their textual 21 | name or serial number. We offer separate sets of IDs for discrimination by 22 | textual name and for serial number. 23 | 24 | Examples for shared use of USB IDs are included with V-USB in the "examples" 25 | subdirectory. 26 | 27 | 28 | ====================================== 29 | IDs FOR DISCRIMINATION BY TEXTUAL NAME 30 | ====================================== 31 | 32 | If you use one of the IDs listed below, your device and host-side software 33 | must conform to these rules: 34 | 35 | (1) The USB device MUST provide a textual representation of the manufacturer 36 | and product identification. The manufacturer identification MUST be available 37 | at least in USB language 0x0409 (English/US). 38 | 39 | (2) The textual manufacturer identification MUST contain either an Internet 40 | domain name (e.g. "mycompany.com") registered and owned by you, or an e-mail 41 | address under your control (e.g. "myname@gmx.net"). You can embed the domain 42 | name or e-mail address in any string you like, e.g. "Objective Development 43 | http://www.obdev.at/vusb/". 44 | 45 | (3) You are responsible for retaining ownership of the domain or e-mail 46 | address for as long as any of your products are in use. 47 | 48 | (4) You may choose any string for the textual product identification, as long 49 | as this string is unique within the scope of your textual manufacturer 50 | identification. 51 | 52 | (5) Application side device look-up MUST be based on the textual manufacturer 53 | and product identification in addition to VID/PID matching. The driver 54 | matching MUST be a comparison of the entire strings, NOT a sub-string match. 55 | 56 | (6) For devices which implement a particular USB device class (e.g. HID), the 57 | operating system's default class driver MUST be used. If an operating system 58 | driver for Vendor Class devices is needed, this driver must be libusb or 59 | libusb-win32 (see http://libusb.org/ and 60 | http://libusb-win32.sourceforge.net/). 61 | 62 | Table if IDs for discrimination by textual name: 63 | 64 | PID dec (hex) | VID dec (hex) | Description of use 65 | ==============+===============+============================================ 66 | 1500 (0x05dc) | 5824 (0x16c0) | For Vendor Class devices with libusb 67 | --------------+---------------+-------------------------------------------- 68 | 1503 (0x05df) | 5824 (0x16c0) | For generic HID class devices (which are 69 | | | NOT mice, keyboards or joysticks) 70 | --------------+---------------+-------------------------------------------- 71 | 1505 (0x05e1) | 5824 (0x16c0) | For CDC-ACM class devices (modems) 72 | --------------+---------------+-------------------------------------------- 73 | 1508 (0x05e4) | 5824 (0x16c0) | For MIDI class devices 74 | --------------+---------------+-------------------------------------------- 75 | 76 | Note that Windows caches the textual product- and vendor-description for 77 | mice, keyboards and joysticks. Name-bsed discrimination is therefore not 78 | recommended for these device classes. 79 | 80 | 81 | ======================================= 82 | IDs FOR DISCRIMINATION BY SERIAL NUMBER 83 | ======================================= 84 | 85 | If you use one of the IDs listed below, your device and host-side software 86 | must conform to these rules: 87 | 88 | (1) The USB device MUST provide a textual representation of the serial 89 | number, unless ONLY the operating system's default class driver is used. 90 | The serial number string MUST be available at least in USB language 0x0409 91 | (English/US). 92 | 93 | (2) The serial number MUST start with either an Internet domain name (e.g. 94 | "mycompany.com") registered and owned by you, or an e-mail address under your 95 | control (e.g. "myname@gmx.net"), both terminated with a colon (":") character. 96 | You MAY append any string you like for further discrimination of your devices. 97 | 98 | (3) You are responsible for retaining ownership of the domain or e-mail 99 | address for as long as any of your products are in use. 100 | 101 | (5) Application side device look-up MUST be based on the serial number string 102 | in addition to VID/PID matching. The matching must start at the first 103 | character of the serial number string and include the colon character 104 | terminating your domain or e-mail address. It MAY stop anywhere after that. 105 | 106 | (6) For devices which implement a particular USB device class (e.g. HID), the 107 | operating system's default class driver MUST be used. If an operating system 108 | driver for Vendor Class devices is needed, this driver must be libusb or 109 | libusb-win32 (see http://libusb.org/ and 110 | http://libusb-win32.sourceforge.net/). 111 | 112 | (7) If ONLY the operating system's default class driver is used, e.g. for 113 | mice, keyboards, joysticks, CDC or MIDI devices and no discrimination by an 114 | application is needed, the serial number may be omitted. 115 | 116 | 117 | Table if IDs for discrimination by serial number string: 118 | 119 | PID dec (hex) | VID dec (hex) | Description of use 120 | ===============+===============+=========================================== 121 | 10200 (0x27d8) | 5824 (0x16c0) | For Vendor Class devices with libusb 122 | ---------------+---------------+------------------------------------------- 123 | 10201 (0x27d9) | 5824 (0x16c0) | For generic HID class devices (which are 124 | | | NOT mice, keyboards or joysticks) 125 | ---------------+---------------+------------------------------------------- 126 | 10202 (0x27da) | 5824 (0x16c0) | For USB Mice 127 | ---------------+---------------+------------------------------------------- 128 | 10203 (0x27db) | 5824 (0x16c0) | For USB Keyboards 129 | ---------------+---------------+------------------------------------------- 130 | 10204 (0x27dc) | 5824 (0x16c0) | For USB Joysticks 131 | ---------------+---------------+------------------------------------------- 132 | 10205 (0x27dd) | 5824 (0x16c0) | For CDC-ACM class devices (modems) 133 | ---------------+---------------+------------------------------------------- 134 | 10206 (0x27de) | 5824 (0x16c0) | For MIDI class devices 135 | ---------------+---------------+------------------------------------------- 136 | 137 | 138 | ================= 139 | ORIGIN OF USB-IDs 140 | ================= 141 | 142 | OBJECTIVE DEVELOPMENT Software GmbH has obtained all VID/PID pairs listed 143 | here from Wouter van Ooijen (see www.voti.nl) for exclusive disposition. 144 | Wouter van Ooijen has obtained the VID from the USB Implementers Forum, Inc. 145 | (see www.usb.org). The VID is registered for the company name "Van Ooijen 146 | Technische Informatica". 147 | 148 | 149 | ========== 150 | DISCLAIMER 151 | ========== 152 | 153 | OBJECTIVE DEVELOPMENT Software GmbH disclaims all liability for any 154 | problems which are caused by the shared use of these VID/PID pairs. 155 | -------------------------------------------------------------------------------- /Source/usbdrv/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 | -------------------------------------------------------------------------------- /Source/usbdrv/asmcommon.inc: -------------------------------------------------------------------------------- 1 | /* Name: asmcommon.inc 2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2007-11-05 5 | * Tabsize: 4 6 | * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 8 | */ 9 | 10 | /* Do not link this file! Link usbdrvasm.S instead, which includes the 11 | * appropriate implementation! 12 | */ 13 | 14 | /* 15 | General Description: 16 | This file contains assembler code which is shared among the USB driver 17 | implementations for different CPU cocks. Since the code must be inserted 18 | in the middle of the module, it's split out into this file and #included. 19 | 20 | Jump destinations called from outside: 21 | sofError: Called when no start sequence was found. 22 | se0: Called when a package has been successfully received. 23 | overflow: Called when receive buffer overflows. 24 | doReturn: Called after sending data. 25 | 26 | Outside jump destinations used by this module: 27 | waitForJ: Called to receive an already arriving packet. 28 | sendAckAndReti: 29 | sendNakAndReti: 30 | sendCntAndReti: 31 | usbSendAndReti: 32 | 33 | The following macros must be defined before this file is included: 34 | .macro POP_STANDARD 35 | .endm 36 | .macro POP_RETI 37 | .endm 38 | */ 39 | 40 | #define token x1 41 | 42 | overflow: 43 | ldi x2, 1< 0 13 | 14 | #warning "Never compile production devices with debugging enabled" 15 | 16 | static void uartPutc(char c) 17 | { 18 | while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */ 19 | ODDBG_UDR = c; 20 | } 21 | 22 | static uchar hexAscii(uchar h) 23 | { 24 | h &= 0xf; 25 | if(h >= 10) 26 | h += 'a' - (uchar)10 - '0'; 27 | h += '0'; 28 | return h; 29 | } 30 | 31 | static void printHex(uchar c) 32 | { 33 | uartPutc(hexAscii(c >> 4)); 34 | uartPutc(hexAscii(c)); 35 | } 36 | 37 | void odDebug(uchar prefix, uchar *data, uchar len) 38 | { 39 | printHex(prefix); 40 | uartPutc(':'); 41 | while(len--){ 42 | uartPutc(' '); 43 | printHex(*data++); 44 | } 45 | uartPutc('\r'); 46 | uartPutc('\n'); 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /Source/usbdrv/oddebug.h: -------------------------------------------------------------------------------- 1 | /* Name: oddebug.h 2 | * Project: AVR library 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2005-01-16 5 | * Tabsize: 4 6 | * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 8 | */ 9 | 10 | #ifndef __oddebug_h_included__ 11 | #define __oddebug_h_included__ 12 | 13 | /* 14 | General Description: 15 | This module implements a function for debug logs on the serial line of the 16 | AVR microcontroller. Debugging can be configured with the define 17 | 'DEBUG_LEVEL'. If this macro is not defined or defined to 0, all debugging 18 | calls are no-ops. If it is 1, DBG1 logs will appear, but not DBG2. If it is 19 | 2, DBG1 and DBG2 logs will be printed. 20 | 21 | A debug log consists of a label ('prefix') to indicate which debug log created 22 | the output and a memory block to dump in hex ('data' and 'len'). 23 | */ 24 | 25 | 26 | #ifndef F_CPU 27 | # define F_CPU 12000000 /* 12 MHz */ 28 | #endif 29 | 30 | /* make sure we have the UART defines: */ 31 | #include "usbportability.h" 32 | 33 | #ifndef uchar 34 | # define uchar unsigned char 35 | #endif 36 | 37 | #if DEBUG_LEVEL > 0 && !(defined TXEN || defined TXEN0) /* no UART in device */ 38 | # warning "Debugging disabled because device has no UART" 39 | # undef DEBUG_LEVEL 40 | #endif 41 | 42 | #ifndef DEBUG_LEVEL 43 | # define DEBUG_LEVEL 0 44 | #endif 45 | 46 | /* ------------------------------------------------------------------------- */ 47 | 48 | #if DEBUG_LEVEL > 0 49 | # define DBG1(prefix, data, len) odDebug(prefix, data, len) 50 | #else 51 | # define DBG1(prefix, data, len) 52 | #endif 53 | 54 | #if DEBUG_LEVEL > 1 55 | # define DBG2(prefix, data, len) odDebug(prefix, data, len) 56 | #else 57 | # define DBG2(prefix, data, len) 58 | #endif 59 | 60 | /* ------------------------------------------------------------------------- */ 61 | 62 | #if DEBUG_LEVEL > 0 63 | extern void odDebug(uchar prefix, uchar *data, uchar len); 64 | 65 | /* Try to find our control registers; ATMEL likes to rename these */ 66 | 67 | #if defined UBRR 68 | # define ODDBG_UBRR UBRR 69 | #elif defined UBRRL 70 | # define ODDBG_UBRR UBRRL 71 | #elif defined UBRR0 72 | # define ODDBG_UBRR UBRR0 73 | #elif defined UBRR0L 74 | # define ODDBG_UBRR UBRR0L 75 | #endif 76 | 77 | #if defined UCR 78 | # define ODDBG_UCR UCR 79 | #elif defined UCSRB 80 | # define ODDBG_UCR UCSRB 81 | #elif defined UCSR0B 82 | # define ODDBG_UCR UCSR0B 83 | #endif 84 | 85 | #if defined TXEN 86 | # define ODDBG_TXEN TXEN 87 | #else 88 | # define ODDBG_TXEN TXEN0 89 | #endif 90 | 91 | #if defined USR 92 | # define ODDBG_USR USR 93 | #elif defined UCSRA 94 | # define ODDBG_USR UCSRA 95 | #elif defined UCSR0A 96 | # define ODDBG_USR UCSR0A 97 | #endif 98 | 99 | #if defined UDRE 100 | # define ODDBG_UDRE UDRE 101 | #else 102 | # define ODDBG_UDRE UDRE0 103 | #endif 104 | 105 | #if defined UDR 106 | # define ODDBG_UDR UDR 107 | #elif defined UDR0 108 | # define ODDBG_UDR UDR0 109 | #endif 110 | 111 | static inline void odDebugInit(void) 112 | { 113 | ODDBG_UCR |= (1< 38 | #ifndef __IAR_SYSTEMS_ASM__ 39 | # include 40 | #endif 41 | 42 | #define __attribute__(arg) /* not supported on IAR */ 43 | 44 | #ifdef __IAR_SYSTEMS_ASM__ 45 | # define __ASSEMBLER__ /* IAR does not define standard macro for asm */ 46 | #endif 47 | 48 | #ifdef __HAS_ELPM__ 49 | # define PROGMEM __farflash 50 | #else 51 | # define PROGMEM __flash 52 | #endif 53 | 54 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr)) 55 | 56 | /* The following definitions are not needed by the driver, but may be of some 57 | * help if you port a gcc based project to IAR. 58 | */ 59 | #define cli() __disable_interrupt() 60 | #define sei() __enable_interrupt() 61 | #define wdt_reset() __watchdog_reset() 62 | #define _BV(x) (1 << (x)) 63 | 64 | /* assembler compatibility macros */ 65 | #define nop2 rjmp $+2 /* jump to next instruction */ 66 | #define XL r26 67 | #define XH r27 68 | #define YL r28 69 | #define YH r29 70 | #define ZL r30 71 | #define ZH r31 72 | #define lo8(x) LOW(x) 73 | #define hi8(x) (((x)>>8) & 0xff) /* not HIGH to allow XLINK to make a proper range check */ 74 | 75 | /* Depending on the device you use, you may get problems with the way usbdrv.h 76 | * handles the differences between devices. Since IAR does not use #defines 77 | * for MCU registers, we can't check for the existence of a particular 78 | * register with an #ifdef. If the autodetection mechanism fails, include 79 | * definitions for the required USB_INTR_* macros in your usbconfig.h. See 80 | * usbconfig-prototype.h and usbdrv.h for details. 81 | */ 82 | 83 | /* ------------------------------------------------------------------------- */ 84 | #elif __CODEVISIONAVR__ /* check for CodeVision AVR */ 85 | /* ------------------------------------------------------------------------- */ 86 | /* This port is not working (yet) */ 87 | 88 | /* #define F_CPU _MCU_CLOCK_FREQUENCY_ seems to be defined automatically */ 89 | 90 | #include 91 | #include 92 | 93 | #define __attribute__(arg) /* not supported on IAR */ 94 | 95 | #define PROGMEM __flash 96 | #define USB_READ_FLASH(addr) (*(PROGMEM char *)(addr)) 97 | 98 | #ifndef __ASSEMBLER__ 99 | static inline void cli(void) 100 | { 101 | #asm("cli"); 102 | } 103 | static inline void sei(void) 104 | { 105 | #asm("sei"); 106 | } 107 | #endif 108 | #define _delay_ms(t) delay_ms(t) 109 | #define _BV(x) (1 << (x)) 110 | #define USB_CFG_USE_SWITCH_STATEMENT 1 /* macro for if() cascase fails for unknown reason */ 111 | 112 | #define macro .macro 113 | #define endm .endmacro 114 | #define nop2 rjmp .+0 /* jump to next instruction */ 115 | 116 | /* ------------------------------------------------------------------------- */ 117 | #else /* default development environment is avr-gcc/avr-libc */ 118 | /* ------------------------------------------------------------------------- */ 119 | 120 | #include 121 | #ifdef __ASSEMBLER__ 122 | # define _VECTOR(N) __vector_ ## N /* io.h does not define this for asm */ 123 | #else 124 | # include 125 | #endif 126 | 127 | #if USB_CFG_DRIVER_FLASH_PAGE 128 | # define USB_READ_FLASH(addr) pgm_read_byte_far(((long)USB_CFG_DRIVER_FLASH_PAGE << 16) | (long)(addr)) 129 | #else 130 | # define USB_READ_FLASH(addr) pgm_read_byte(addr) 131 | #endif 132 | 133 | #define macro .macro 134 | #define endm .endm 135 | #define nop2 rjmp .+0 /* jump to next instruction */ 136 | 137 | #endif /* development environment */ 138 | 139 | /* for conveniecne, ensure that PRG_RDB exists */ 140 | #ifndef PRG_RDB 141 | # define PRG_RDB(addr) USB_READ_FLASH(addr) 142 | #endif 143 | #endif /* __usbportability_h_INCLUDED__ */ 144 | -------------------------------------------------------------------------------- /bootloadHID/commandline/Makefile: -------------------------------------------------------------------------------- 1 | # Name: Makefile 2 | # Project: Automator 3 | # Author: Christian Starkjohann 4 | # Creation Date: 2006-02-01 5 | # Tabsize: 4 6 | # Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH 7 | # License: Proprietary, free under certain conditions. See Documentation. 8 | # This Revision: $Id$ 9 | 10 | # Please read the definitions below and edit them as appropriate for your 11 | # system: 12 | 13 | # Use the following 3 lines on Unix and Mac OS X: 14 | USBFLAGS= `libusb-config --cflags` 15 | USBLIBS= `libusb-config --libs` 16 | EXE_SUFFIX= 17 | 18 | # Use the following 3 lines on Windows and comment out the 3 above: 19 | #USBFLAGS= 20 | #USBLIBS= -lhid -lusb -lsetupapi 21 | #EXE_SUFFIX= .exe 22 | 23 | CC= gcc 24 | CXX= g++ 25 | CFLAGS= -O2 -Wall $(USBFLAGS) 26 | LIBS= $(USBLIBS) 27 | ARCH_COMPILE= 28 | ARCH_LINK= 29 | 30 | OBJ= main.o usbcalls.o 31 | PROGRAM= bootloadHID$(EXE_SUFFIX) 32 | 33 | all: $(PROGRAM) 34 | 35 | $(PROGRAM): $(OBJ) 36 | $(CC) $(ARCH_LINK) $(CFLAGS) -o $(PROGRAM) $(OBJ) $(LIBS) 37 | 38 | 39 | strip: $(PROGRAM) 40 | strip $(PROGRAM) 41 | 42 | clean: 43 | rm -f $(OBJ) $(PROGRAM) 44 | 45 | .c.o: 46 | $(CC) $(ARCH_COMPILE) $(CFLAGS) -c $*.c -o $*.o 47 | -------------------------------------------------------------------------------- /bootloadHID/commandline/Makefile.MorphOS: -------------------------------------------------------------------------------- 1 | # Name: Makefile 2 | # Project: Automator 3 | # Author: Christian Starkjohann 4 | # Creation Date: 2006-02-01 5 | # Tabsize: 4 6 | # Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH 7 | # License: Proprietary, free under certain conditions. See Documentation. 8 | # This Revision: $Id$ 9 | 10 | # Please read the definitions below and edit them as appropriate for your 11 | # system: 12 | 13 | # Use the following 3 lines on Unix and Mac OS X: 14 | USBFLAGS= 15 | USBLIBS= 16 | EXE_SUFFIX= _MorphOS 17 | 18 | # Use the following 3 lines on Windows and comment out the 3 above: 19 | #USBFLAGS= 20 | #USBLIBS= -lhid -lusb -lsetupapi 21 | #EXE_SUFFIX= .exe 22 | 23 | CC= ppc-morphos-gcc 24 | CXX= ppc-morphos-g++ 25 | CFLAGS= -O2 -Wall $(USBFLAGS) -noixemul 26 | LIBS= $(USBLIBS) 27 | ARCH_COMPILE= 28 | ARCH_LINK= 29 | 30 | OBJ= main.o usbcalls.o 31 | PROGRAM= bootloadHID$(EXE_SUFFIX) 32 | 33 | all: $(PROGRAM) 34 | 35 | $(PROGRAM): $(OBJ) 36 | $(CC) $(ARCH_LINK) $(CFLAGS) -o $(PROGRAM) $(OBJ) $(LIBS) 37 | 38 | 39 | strip: $(PROGRAM) 40 | ppc-morphos-strip $(PROGRAM) 41 | 42 | clean: 43 | rm -f $(OBJ) $(PROGRAM) 44 | 45 | .c.o: 46 | $(CC) $(ARCH_COMPILE) $(CFLAGS) -c $*.c -o $*.o 47 | -------------------------------------------------------------------------------- /bootloadHID/commandline/Makefile.windows: -------------------------------------------------------------------------------- 1 | # Name: Makefile.windows 2 | # Project: Automator 3 | # Author: Christian Starkjohann 4 | # Creation Date: 2006-02-20 5 | # Tabsize: 4 6 | # Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH 7 | # License: Proprietary, free under certain conditions. See Documentation. 8 | # This Revision: $Id$ 9 | 10 | # You may use this file with 11 | # make -f Makefile.windows 12 | # on Windows with MinGW instead of editing the main Makefile. 13 | 14 | include Makefile 15 | 16 | USBFLAGS= 17 | USBLIBS= -lhid -lusb -lsetupapi 18 | EXE_SUFFIX= .exe 19 | -------------------------------------------------------------------------------- /bootloadHID/commandline/bootloadHID.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/bootloadHID/commandline/bootloadHID.exe -------------------------------------------------------------------------------- /bootloadHID/commandline/bootloadHID_MorphOS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/bootloadHID/commandline/bootloadHID_MorphOS -------------------------------------------------------------------------------- /bootloadHID/commandline/bootloadHID_raspi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/bootloadHID/commandline/bootloadHID_raspi -------------------------------------------------------------------------------- /bootloadHID/commandline/debug.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/bootloadHID/commandline/debug.h -------------------------------------------------------------------------------- /bootloadHID/commandline/hidsdi.h: -------------------------------------------------------------------------------- 1 | /* Name: hidsdi.h 2 | * Project: usbcalls library 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2006-02-02 5 | * Tabsize: 4 6 | * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: Proprietary, free under certain conditions. See Documentation. 8 | * This Revision: $Id$ 9 | */ 10 | 11 | /* 12 | General Description 13 | This file is a replacement for hidsdi.h from the Windows DDK. It defines some 14 | of the types and function prototypes of this header for our project. If you 15 | have the Windows DDK version of this file or a version shipped with MinGW, use 16 | that instead. 17 | */ 18 | 19 | #ifndef _HIDSDI_H 20 | #define _HIDSDI_H 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | typedef struct{ 28 | ULONG Size; 29 | USHORT VendorID; 30 | USHORT ProductID; 31 | USHORT VersionNumber; 32 | }HIDD_ATTRIBUTES; 33 | 34 | void __stdcall HidD_GetHidGuid(OUT LPGUID hidGuid); 35 | 36 | BOOLEAN __stdcall HidD_GetAttributes(IN HANDLE device, OUT HIDD_ATTRIBUTES *attributes); 37 | 38 | BOOLEAN __stdcall HidD_GetManufacturerString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); 39 | BOOLEAN __stdcall HidD_GetProductString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); 40 | BOOLEAN __stdcall HidD_GetSerialNumberString(IN HANDLE device, OUT void *buffer, IN ULONG bufferLen); 41 | 42 | BOOLEAN __stdcall HidD_GetFeature(IN HANDLE device, OUT void *reportBuffer, IN ULONG bufferLen); 43 | BOOLEAN __stdcall HidD_SetFeature(IN HANDLE device, IN void *reportBuffer, IN ULONG bufferLen); 44 | 45 | BOOLEAN __stdcall HidD_GetNumInputBuffers(IN HANDLE device, OUT ULONG *numBuffers); 46 | BOOLEAN __stdcall HidD_SetNumInputBuffers(IN HANDLE device, OUT ULONG numBuffers); 47 | 48 | #include 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /bootloadHID/commandline/main.c: -------------------------------------------------------------------------------- 1 | /* Name: main.c 2 | * Project: AVR bootloader HID 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2007-03-19 5 | * Tabsize: 4 6 | * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: Proprietary, free under certain conditions. See Documentation. 8 | * This Revision: $Id$ 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "usbcalls.h" 16 | 17 | #define IDENT_VENDOR_NUM 0x16c0 18 | #define IDENT_VENDOR_STRING "obdev.at" 19 | #define IDENT_PRODUCT_NUM 1503 20 | #define IDENT_PRODUCT_STRING "HIDBoot" 21 | 22 | /* ------------------------------------------------------------------------- */ 23 | 24 | static char dataBuffer[65536 + 256]; /* buffer for file data */ 25 | static int startAddress, endAddress; 26 | static char leaveBootLoader = 0; 27 | 28 | /* ------------------------------------------------------------------------- */ 29 | 30 | static int parseUntilColon(FILE *fp) 31 | { 32 | int c; 33 | 34 | do{ 35 | c = getc(fp); 36 | }while(c != ':' && c != EOF); 37 | return c; 38 | } 39 | 40 | static int parseHex(FILE *fp, int numDigits) 41 | { 42 | int i; 43 | char temp[9]; 44 | 45 | for(i = 0; i < numDigits; i++) 46 | temp[i] = getc(fp); 47 | temp[i] = 0; 48 | return strtol(temp, NULL, 16); 49 | } 50 | 51 | /* ------------------------------------------------------------------------- */ 52 | 53 | static int parseIntelHex(char *hexfile, char buffer[65536 + 256], int *startAddr, int *endAddr) 54 | { 55 | int address, base, d, segment, i, lineLen, sum; 56 | FILE *input; 57 | 58 | input = fopen(hexfile, "r"); 59 | if(input == NULL){ 60 | fprintf(stderr, "error opening %s: %s\n", hexfile, strerror(errno)); 61 | return 1; 62 | } 63 | while(parseUntilColon(input) == ':'){ 64 | sum = 0; 65 | sum += lineLen = parseHex(input, 2); 66 | base = address = parseHex(input, 4); 67 | sum += address >> 8; 68 | sum += address; 69 | sum += segment = parseHex(input, 2); /* segment value? */ 70 | if(segment != 0) /* ignore lines where this byte is not 0 */ 71 | continue; 72 | for(i = 0; i < lineLen ; i++){ 73 | d = parseHex(input, 2); 74 | buffer[address++] = d; 75 | sum += d; 76 | } 77 | sum += parseHex(input, 2); 78 | if((sum & 0xff) != 0){ 79 | fprintf(stderr, "Warning: Checksum error between address 0x%x and 0x%x\n", base, address); 80 | } 81 | if(*startAddr > base) 82 | *startAddr = base; 83 | if(*endAddr < address) 84 | *endAddr = address; 85 | } 86 | fclose(input); 87 | return 0; 88 | } 89 | 90 | /* ------------------------------------------------------------------------- */ 91 | 92 | char *usbErrorMessage(int errCode) 93 | { 94 | static char buffer[80]; 95 | 96 | switch(errCode){ 97 | case USB_ERROR_ACCESS: return "Access to device denied"; 98 | case USB_ERROR_NOTFOUND: return "The specified device was not found"; 99 | case USB_ERROR_BUSY: return "The device is used by another application"; 100 | case USB_ERROR_IO: return "Communication error with device"; 101 | default: 102 | sprintf(buffer, "Unknown USB error %d", errCode); 103 | return buffer; 104 | } 105 | return NULL; /* not reached */ 106 | } 107 | 108 | static int getUsbInt(char *buffer, int numBytes) 109 | { 110 | int shift = 0, value = 0, i; 111 | 112 | for(i = 0; i < numBytes; i++){ 113 | value |= ((int)*buffer & 0xff) << shift; 114 | shift += 8; 115 | buffer++; 116 | } 117 | return value; 118 | } 119 | 120 | static void setUsbInt(char *buffer, int value, int numBytes) 121 | { 122 | int i; 123 | 124 | for(i = 0; i < numBytes; i++){ 125 | *buffer++ = value; 126 | value >>= 8; 127 | } 128 | } 129 | 130 | /* ------------------------------------------------------------------------- */ 131 | 132 | typedef struct deviceInfo{ 133 | char reportId; 134 | char pageSize[2]; 135 | char flashSize[4]; 136 | }deviceInfo_t; 137 | 138 | typedef struct deviceData{ 139 | char reportId; 140 | char address[3]; 141 | char data[128]; 142 | }deviceData_t; 143 | 144 | static int uploadData(char *dataBuffer, int startAddr, int endAddr) 145 | { 146 | usbDevice_t *dev = NULL; 147 | int err = 0, len, mask, pageSize, deviceSize; 148 | union{ 149 | char bytes[1]; 150 | deviceInfo_t info; 151 | deviceData_t data; 152 | } buffer; 153 | 154 | if((err = usbOpenDevice(&dev, IDENT_VENDOR_NUM, IDENT_VENDOR_STRING, IDENT_PRODUCT_NUM, IDENT_PRODUCT_STRING, 1)) != 0){ 155 | fprintf(stderr, "Error opening HIDBoot device: %s\n", usbErrorMessage(err)); 156 | goto errorOccurred; 157 | } 158 | 159 | len = sizeof(buffer); 160 | if(endAddr > startAddr){ // we need to upload data 161 | if((err = usbGetReport(dev, USB_HID_REPORT_TYPE_FEATURE, 1, buffer.bytes, &len)) != 0){ 162 | fprintf(stderr, "Error reading page size: %s\n", usbErrorMessage(err)); 163 | goto errorOccurred; 164 | } 165 | if(len < sizeof(buffer.info)){ 166 | fprintf(stderr, "Not enough bytes in device info report (%d instead of %d)\n", len, (int)sizeof(buffer.info)); 167 | err = -1; 168 | goto errorOccurred; 169 | } 170 | pageSize = getUsbInt(buffer.info.pageSize, 2); 171 | deviceSize = getUsbInt(buffer.info.flashSize, 4); 172 | printf("Page size = %d (0x%x)\n", pageSize, pageSize); 173 | printf("Device size = %d (0x%x); %d bytes remaining\n", deviceSize, deviceSize, deviceSize - 2048); 174 | if(endAddr > deviceSize - 2048){ 175 | fprintf(stderr, "Data (%d bytes) exceeds remaining flash size!\n", endAddr); 176 | err = -1; 177 | goto errorOccurred; 178 | } 179 | if(pageSize < 128){ 180 | mask = 127; 181 | }else{ 182 | mask = pageSize - 1; 183 | } 184 | startAddr &= ~mask; // round down 185 | endAddr = (endAddr + mask) & ~mask; // round up 186 | printf("Uploading %d (0x%x) bytes starting at %d (0x%x)\n", endAddr - startAddr, endAddr - startAddr, startAddr, startAddr); 187 | while(startAddr < endAddr){ 188 | buffer.data.reportId = 2; 189 | memcpy(buffer.data.data, dataBuffer + startAddr, 128); 190 | setUsbInt(buffer.data.address, startAddr, 3); 191 | printf("\r0x%05x ... 0x%05x", startAddr, startAddr + (int)sizeof(buffer.data.data)); 192 | fflush(stdout); 193 | if((err = usbSetReport(dev, USB_HID_REPORT_TYPE_FEATURE, buffer.bytes, sizeof(buffer.data))) != 0){ 194 | fprintf(stderr, "Error uploading data block: %s\n", usbErrorMessage(err)); 195 | goto errorOccurred; 196 | } 197 | startAddr += sizeof(buffer.data.data); 198 | } 199 | printf("\n"); 200 | } 201 | 202 | if(leaveBootLoader){ 203 | // and now leave boot loader: 204 | buffer.info.reportId = 1; 205 | usbSetReport(dev, USB_HID_REPORT_TYPE_FEATURE, buffer.bytes, sizeof(buffer.info)); 206 | // Ignore errors here. If the device reboots before we poll the response, 207 | // this request fails. 208 | // 209 | } 210 | errorOccurred: 211 | if(dev != NULL) 212 | usbCloseDevice(dev); 213 | 214 | return err; 215 | } 216 | 217 | /* ------------------------------------------------------------------------- */ 218 | 219 | static void printUsage(char *pname) 220 | { 221 | fprintf(stderr, "usage: %s [-r] []\n", pname); 222 | } 223 | 224 | int main(int argc, char **argv) 225 | { 226 | char *file = NULL; 227 | 228 | if(argc < 2){ 229 | printUsage(argv[0]); 230 | return 1; 231 | } 232 | if(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0){ 233 | printUsage(argv[0]); 234 | return 1; 235 | } 236 | if(strcmp(argv[1], "-r") == 0){ 237 | leaveBootLoader = 1; 238 | if(argc >= 3){ 239 | file = argv[2]; 240 | } 241 | }else{ 242 | file = argv[1]; 243 | } 244 | startAddress = sizeof(dataBuffer); 245 | endAddress = 0; 246 | if(file != NULL){ // an upload file was given, load the data 247 | memset(dataBuffer, -1, sizeof(dataBuffer)); 248 | if(parseIntelHex(file, dataBuffer, &startAddress, &endAddress)) 249 | return 1; 250 | if(startAddress >= endAddress){ 251 | fprintf(stderr, "No data in input file, exiting.\n"); 252 | return 0; 253 | } 254 | } 255 | // if no file was given, endAddress is less than startAddress and no data is uploaded 256 | if(uploadData(dataBuffer, startAddress, endAddress)) 257 | return 1; 258 | return 0; 259 | } 260 | 261 | /* ------------------------------------------------------------------------- */ 262 | 263 | 264 | -------------------------------------------------------------------------------- /bootloadHID/commandline/usb-libusb.c: -------------------------------------------------------------------------------- 1 | /* Name: usb-libusb.c 2 | * Project: usbcalls library 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2006-02-02 5 | * Tabsize: 4 6 | * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: Proprietary, free under certain conditions. See Documentation. 8 | * This Revision: $Id$ 9 | */ 10 | 11 | /* 12 | General Description: 13 | This module implements USB HID report receiving/sending based on libusb. It 14 | does not read and parse the report descriptor. You must therefore be careful 15 | to pass correctly formatted data blocks of correct size. In order to be 16 | compatible with the Windows implementation, we add a zero report ID for all 17 | reports which don't have an ID. Since we don't parse the descriptor, the caller 18 | must tell us whether report IDs are used or not in usbOpenDevice(). 19 | 20 | The implementation of dummy report IDs is a hack. Whether they are used is 21 | stored in a global variable, not in the device structure (just laziness, don't 22 | want to allocate memory for that). If you open more than one device and the 23 | devices differ in report ID usage, you must change the code. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #define usbDevice usb_dev_handle /* use libusb's device structure */ 31 | #include "usbcalls.h" 32 | 33 | /* ------------------------------------------------------------------------- */ 34 | 35 | #define USBRQ_HID_GET_REPORT 0x01 36 | #define USBRQ_HID_SET_REPORT 0x09 37 | 38 | static int usesReportIDs; 39 | 40 | /* ------------------------------------------------------------------------- */ 41 | 42 | static int usbGetStringAscii(usb_dev_handle *dev, int index, int langid, char *buf, int buflen) 43 | { 44 | char buffer[256]; 45 | int rval, i; 46 | 47 | if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, langid, buffer, sizeof(buffer), 1000)) < 0) 48 | return rval; 49 | if(buffer[1] != USB_DT_STRING) 50 | return 0; 51 | if((unsigned char)buffer[0] < rval) 52 | rval = (unsigned char)buffer[0]; 53 | rval /= 2; 54 | /* lossy conversion to ISO Latin1 */ 55 | for(i=1;i buflen) /* destination buffer overflow */ 57 | break; 58 | buf[i-1] = buffer[2 * i]; 59 | if(buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */ 60 | buf[i-1] = '?'; 61 | } 62 | buf[i-1] = 0; 63 | return i-1; 64 | } 65 | 66 | int usbOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int _usesReportIDs) 67 | { 68 | struct usb_bus *bus; 69 | struct usb_device *dev; 70 | usb_dev_handle *handle = NULL; 71 | int errorCode = USB_ERROR_NOTFOUND; 72 | static int didUsbInit = 0; 73 | 74 | if(!didUsbInit){ 75 | usb_init(); 76 | didUsbInit = 1; 77 | } 78 | usb_find_busses(); 79 | usb_find_devices(); 80 | for(bus=usb_get_busses(); bus; bus=bus->next){ 81 | for(dev=bus->devices; dev; dev=dev->next){ 82 | if(dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product){ 83 | char string[256]; 84 | int len; 85 | handle = usb_open(dev); /* we need to open the device in order to query strings */ 86 | if(!handle){ 87 | errorCode = USB_ERROR_ACCESS; 88 | fprintf(stderr, "Warning: cannot open USB device: %s\n", usb_strerror()); 89 | continue; 90 | } 91 | if(vendorName == NULL && productName == NULL){ /* name does not matter */ 92 | break; 93 | } 94 | /* now check whether the names match: */ 95 | len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, 0x0409, string, sizeof(string)); 96 | if(len < 0){ 97 | errorCode = USB_ERROR_IO; 98 | fprintf(stderr, "Warning: cannot query manufacturer for device: %s\n", usb_strerror()); 99 | }else{ 100 | errorCode = USB_ERROR_NOTFOUND; 101 | /* fprintf(stderr, "seen device from vendor ->%s<-\n", string); */ 102 | if(strcmp(string, vendorName) == 0){ 103 | len = usbGetStringAscii(handle, dev->descriptor.iProduct, 0x0409, string, sizeof(string)); 104 | if(len < 0){ 105 | errorCode = USB_ERROR_IO; 106 | fprintf(stderr, "Warning: cannot query product for device: %s\n", usb_strerror()); 107 | }else{ 108 | errorCode = USB_ERROR_NOTFOUND; 109 | /* fprintf(stderr, "seen product ->%s<-\n", string); */ 110 | if(strcmp(string, productName) == 0) 111 | break; 112 | } 113 | } 114 | } 115 | usb_close(handle); 116 | handle = NULL; 117 | } 118 | } 119 | if(handle) 120 | break; 121 | } 122 | if(handle != NULL){ 123 | int rval, retries = 3; 124 | if(usb_set_configuration(handle, 1)){ 125 | fprintf(stderr, "Warning: could not set configuration: %s\n", usb_strerror()); 126 | } 127 | /* now try to claim the interface and detach the kernel HID driver on 128 | * linux and other operating systems which support the call. 129 | */ 130 | while((rval = usb_claim_interface(handle, 0)) != 0 && retries-- > 0){ 131 | #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP 132 | if(usb_detach_kernel_driver_np(handle, 0) < 0){ 133 | fprintf(stderr, "Warning: could not detach kernel HID driver: %s\n", usb_strerror()); 134 | } 135 | #endif 136 | } 137 | #ifndef __APPLE__ 138 | if(rval != 0) 139 | fprintf(stderr, "Warning: could not claim interface\n"); 140 | #endif 141 | /* Continue anyway, even if we could not claim the interface. Control transfers 142 | * should still work. 143 | */ 144 | errorCode = 0; 145 | *device = handle; 146 | usesReportIDs = _usesReportIDs; 147 | } 148 | return errorCode; 149 | } 150 | 151 | /* ------------------------------------------------------------------------- */ 152 | 153 | void usbCloseDevice(usbDevice_t *device) 154 | { 155 | if(device != NULL) 156 | usb_close(device); 157 | } 158 | 159 | /* ------------------------------------------------------------------------- */ 160 | 161 | int usbSetReport(usbDevice_t *device, int reportType, char *buffer, int len) 162 | { 163 | int bytesSent; 164 | 165 | if(!usesReportIDs){ 166 | buffer++; /* skip dummy report ID */ 167 | len--; 168 | } 169 | bytesSent = usb_control_msg(device, USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_ENDPOINT_OUT, USBRQ_HID_SET_REPORT, reportType << 8 | buffer[0], 0, buffer, len, 5000); 170 | if(bytesSent != len){ 171 | if(bytesSent < 0) 172 | fprintf(stderr, "Error sending message: %s\n", usb_strerror()); 173 | return USB_ERROR_IO; 174 | } 175 | return 0; 176 | } 177 | 178 | /* ------------------------------------------------------------------------- */ 179 | 180 | int usbGetReport(usbDevice_t *device, int reportType, int reportNumber, char *buffer, int *len) 181 | { 182 | int bytesReceived, maxLen = *len; 183 | 184 | if(!usesReportIDs){ 185 | buffer++; /* make room for dummy report ID */ 186 | maxLen--; 187 | } 188 | bytesReceived = usb_control_msg(device, USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_ENDPOINT_IN, USBRQ_HID_GET_REPORT, reportType << 8 | reportNumber, 0, buffer, maxLen, 5000); 189 | if(bytesReceived < 0){ 190 | fprintf(stderr, "Error sending message: %s\n", usb_strerror()); 191 | return USB_ERROR_IO; 192 | } 193 | *len = bytesReceived; 194 | if(!usesReportIDs){ 195 | buffer[-1] = reportNumber; /* add dummy report ID */ 196 | *len++; 197 | } 198 | return 0; 199 | } 200 | 201 | /* ------------------------------------------------------------------------- */ 202 | 203 | 204 | -------------------------------------------------------------------------------- /bootloadHID/commandline/usb-morphos.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/develin4000/joydivision/ac6d35f5cf4815db82bd6d34dd9c85188106b25d/bootloadHID/commandline/usb-morphos.c -------------------------------------------------------------------------------- /bootloadHID/commandline/usb-windows.c: -------------------------------------------------------------------------------- 1 | /* Name: usb-windows.c 2 | * Project: usbcalls library 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2006-02-02 5 | * Tabsize: 4 6 | * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: Proprietary, free under certain conditions. See Documentation. 8 | * This Revision: $Id$ 9 | */ 10 | 11 | /* 12 | General Description: 13 | This module implements USB HID report receiving and sending with native 14 | Windows API functions. If you compile with MinGW, no software from Microsoft 15 | (no DDK) is needed. We supply the missing types and function prototypes in 16 | hidsdi.h. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "hidsdi.h" 23 | #include 24 | 25 | #include "usbcalls.h" 26 | 27 | #ifdef DEBUG 28 | #define DEBUG_PRINT(arg) printf arg 29 | #else 30 | #define DEBUG_PRINT(arg) 31 | #endif 32 | 33 | /* ------------------------------------------------------------------------ */ 34 | 35 | static void convertUniToAscii(char *buffer) 36 | { 37 | unsigned short *uni = (void *)buffer; 38 | char *ascii = buffer; 39 | 40 | while(*uni != 0){ 41 | if(*uni >= 256){ 42 | *ascii++ = '?'; 43 | }else{ 44 | *ascii++ = *uni++; 45 | } 46 | } 47 | *ascii++ = 0; 48 | } 49 | 50 | int usbOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int usesReportIDs) 51 | { 52 | GUID hidGuid; /* GUID for HID driver */ 53 | HDEVINFO deviceInfoList; 54 | SP_DEVICE_INTERFACE_DATA deviceInfo; 55 | SP_DEVICE_INTERFACE_DETAIL_DATA *deviceDetails = NULL; 56 | DWORD size; 57 | int i, openFlag = 0; /* may be FILE_FLAG_OVERLAPPED */ 58 | int errorCode = USB_ERROR_NOTFOUND; 59 | HANDLE handle = INVALID_HANDLE_VALUE; 60 | HIDD_ATTRIBUTES deviceAttributes; 61 | 62 | HidD_GetHidGuid(&hidGuid); 63 | deviceInfoList = SetupDiGetClassDevs(&hidGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); 64 | deviceInfo.cbSize = sizeof(deviceInfo); 65 | for(i=0;;i++){ 66 | if(handle != INVALID_HANDLE_VALUE){ 67 | CloseHandle(handle); 68 | handle = INVALID_HANDLE_VALUE; 69 | } 70 | if(!SetupDiEnumDeviceInterfaces(deviceInfoList, 0, &hidGuid, i, &deviceInfo)) 71 | break; /* no more entries */ 72 | /* first do a dummy call just to determine the actual size required */ 73 | SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, NULL, 0, &size, NULL); 74 | if(deviceDetails != NULL) 75 | free(deviceDetails); 76 | deviceDetails = malloc(size); 77 | deviceDetails->cbSize = sizeof(*deviceDetails); 78 | /* this call is for real: */ 79 | SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, deviceDetails, size, &size, NULL); 80 | DEBUG_PRINT(("checking HID path \"%s\"\n", deviceDetails->DevicePath)); 81 | /* attempt opening for R/W -- we don't care about devices which can't be accessed */ 82 | handle = CreateFile(deviceDetails->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, openFlag, NULL); 83 | if(handle == INVALID_HANDLE_VALUE){ 84 | DEBUG_PRINT(("opening failed: %d\n", (int)GetLastError())); 85 | /* errorCode = USB_ERROR_ACCESS; opening will always fail for mouse -- ignore */ 86 | continue; 87 | } 88 | deviceAttributes.Size = sizeof(deviceAttributes); 89 | HidD_GetAttributes(handle, &deviceAttributes); 90 | DEBUG_PRINT(("device attributes: vid=%d pid=%d\n", deviceAttributes.VendorID, deviceAttributes.ProductID)); 91 | if(deviceAttributes.VendorID != vendor || deviceAttributes.ProductID != product) 92 | continue; /* ignore this device */ 93 | errorCode = USB_ERROR_NOTFOUND; 94 | if(vendorName != NULL && productName != NULL){ 95 | char buffer[512]; 96 | if(!HidD_GetManufacturerString(handle, buffer, sizeof(buffer))){ 97 | DEBUG_PRINT(("error obtaining vendor name\n")); 98 | errorCode = USB_ERROR_IO; 99 | continue; 100 | } 101 | convertUniToAscii(buffer); 102 | DEBUG_PRINT(("vendorName = \"%s\"\n", buffer)); 103 | if(strcmp(vendorName, buffer) != 0) 104 | continue; 105 | if(!HidD_GetProductString(handle, buffer, sizeof(buffer))){ 106 | DEBUG_PRINT(("error obtaining product name\n")); 107 | errorCode = USB_ERROR_IO; 108 | continue; 109 | } 110 | convertUniToAscii(buffer); 111 | DEBUG_PRINT(("productName = \"%s\"\n", buffer)); 112 | if(strcmp(productName, buffer) != 0) 113 | continue; 114 | } 115 | break; /* we have found the device we are looking for! */ 116 | } 117 | SetupDiDestroyDeviceInfoList(deviceInfoList); 118 | if(deviceDetails != NULL) 119 | free(deviceDetails); 120 | if(handle != INVALID_HANDLE_VALUE){ 121 | *device = (usbDevice_t *)handle; 122 | errorCode = 0; 123 | } 124 | return errorCode; 125 | } 126 | 127 | /* ------------------------------------------------------------------------ */ 128 | 129 | void usbCloseDevice(usbDevice_t *device) 130 | { 131 | CloseHandle((HANDLE)device); 132 | } 133 | 134 | /* ------------------------------------------------------------------------ */ 135 | 136 | int usbSetReport(usbDevice_t *device, int reportType, char *buffer, int len) 137 | { 138 | HANDLE handle = (HANDLE)device; 139 | BOOLEAN rval = 0; 140 | DWORD bytesWritten; 141 | 142 | switch(reportType){ 143 | case USB_HID_REPORT_TYPE_INPUT: 144 | break; 145 | case USB_HID_REPORT_TYPE_OUTPUT: 146 | rval = WriteFile(handle, buffer, len, &bytesWritten, NULL); 147 | break; 148 | case USB_HID_REPORT_TYPE_FEATURE: 149 | rval = HidD_SetFeature(handle, buffer, len); 150 | break; 151 | } 152 | return rval == 0 ? USB_ERROR_IO : 0; 153 | } 154 | 155 | /* ------------------------------------------------------------------------ */ 156 | 157 | int usbGetReport(usbDevice_t *device, int reportType, int reportNumber, char *buffer, int *len) 158 | { 159 | HANDLE handle = (HANDLE)device; 160 | BOOLEAN rval = 0; 161 | DWORD bytesRead; 162 | 163 | switch(reportType){ 164 | case USB_HID_REPORT_TYPE_INPUT: 165 | buffer[0] = reportNumber; 166 | rval = ReadFile(handle, buffer, *len, &bytesRead, NULL); 167 | if(rval) 168 | *len = bytesRead; 169 | break; 170 | case USB_HID_REPORT_TYPE_OUTPUT: 171 | break; 172 | case USB_HID_REPORT_TYPE_FEATURE: 173 | buffer[0] = reportNumber; 174 | rval = HidD_GetFeature(handle, buffer, *len); 175 | break; 176 | } 177 | return rval == 0 ? USB_ERROR_IO : 0; 178 | } 179 | 180 | /* ------------------------------------------------------------------------ */ 181 | -------------------------------------------------------------------------------- /bootloadHID/commandline/usbcalls.c: -------------------------------------------------------------------------------- 1 | /* Name: usbcalls.c 2 | * Project: usbcalls library 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2006-02-02 5 | * Tabsize: 4 6 | * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: Proprietary, free under certain conditions. See Documentation. 8 | * This Revision: $Id$ 9 | */ 10 | 11 | /* This file includes the appropriate implementation based on platform 12 | * specific defines. 13 | */ 14 | 15 | 16 | #ifdef __MORPHOS__ 17 | # include "usb-morphos.c" 18 | #elif defined __AROS__ 19 | # include "usb-aros.c" 20 | #elif defined __amigaos4__ 21 | # include "usb-amigaos4.c" 22 | #elif defined WIN32 23 | # include "usb-windows.c" 24 | #else 25 | # include "usb-libusb.c" 26 | #endif 27 | 28 | /* 29 | #ifdef __MORPHOS__ 30 | # include "usb-morphos.c" 31 | #else 32 | 33 | #if defined(WIN32) 34 | # include "usb-windows.c" 35 | #else 36 | // e.g. defined(__APPLE__) 37 | # include "usb-libusb.c" 38 | #endif 39 | #endif 40 | */ 41 | -------------------------------------------------------------------------------- /bootloadHID/commandline/usbcalls.h: -------------------------------------------------------------------------------- 1 | /* Name: usbcalls.h 2 | * Project: usbcalls library 3 | * Author: Christian Starkjohann 4 | * Creation Date: 2006-02-02 5 | * Tabsize: 4 6 | * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH 7 | * License: Proprietary, free under certain conditions. See Documentation. 8 | * This Revision: $Id$ 9 | */ 10 | 11 | #ifndef __usbcalls_h_INCLUDED__ 12 | #define __usbcalls_h_INCLUDED__ 13 | 14 | /* 15 | General Description: 16 | This module implements an abstraction layer for access to USB/HID communication 17 | functions. An implementation based on libusb (portable to Linux, FreeBSD and 18 | Mac OS X) and a native implementation for Windows are provided. 19 | */ 20 | 21 | /* ------------------------------------------------------------------------ */ 22 | 23 | #define USB_HID_REPORT_TYPE_INPUT 1 24 | #define USB_HID_REPORT_TYPE_OUTPUT 2 25 | #define USB_HID_REPORT_TYPE_FEATURE 3 26 | /* Numeric constants for 'reportType' parameters */ 27 | 28 | #define USB_ERROR_NONE 0 29 | #define USB_ERROR_ACCESS 1 30 | #define USB_ERROR_NOTFOUND 2 31 | #define USB_ERROR_BUSY 16 32 | #define USB_ERROR_IO 5 33 | /* These are the error codes which can be returned by functions of this 34 | * module. 35 | */ 36 | 37 | /* ------------------------------------------------------------------------ */ 38 | 39 | typedef struct usbDevice usbDevice_t; 40 | /* This type represents a USB device internally. Only opaque pointers to this 41 | * type are available outside the module implementation. 42 | */ 43 | 44 | /* ------------------------------------------------------------------------ */ 45 | 46 | int usbOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int usesReportIDs); 47 | /* This function opens a USB device. 'vendor' and 'product' are the numeric 48 | * Vendor-ID and Product-ID of the device we want to open. If 'vendorName' and 49 | * 'productName' are both not NULL, only devices with matching manufacturer- 50 | * and product name strings are accepted. If the device uses report IDs, 51 | * 'usesReportIDs' must be set to a non-zero value. 52 | * Returns: If a matching device has been found, USB_ERROR_NONE is returned and 53 | * '*device' is set to an opaque pointer representing the device. The device 54 | * must be closed with usbCloseDevice(). If the device has not been found or 55 | * opening failed, an error code is returned. 56 | */ 57 | void usbCloseDevice(usbDevice_t *device); 58 | /* Every device opened with usbOpenDevice() must be closed with this function. 59 | */ 60 | int usbSetReport(usbDevice_t *device, int reportType, char *buffer, int len); 61 | /* This function sends a report to the device. 'reportType' specifies the type 62 | * of report (see USB_HID_REPORT_TYPE* constants). The report ID must be in the 63 | * first byte of buffer and the length 'len' of the report is specified 64 | * including this report ID. If no report IDs are used, buffer[0] must be set 65 | * to 0 (dummy report ID). 66 | * Returns: 0 on success, an error code otherwise. 67 | */ 68 | int usbGetReport(usbDevice_t *device, int reportType, int reportID, char *buffer, int *len); 69 | /* This function obtains a report from the device. 'reportType' specifies the 70 | * type of report (see USB_HID_REPORT_TYPE* constants). The requested report ID 71 | * is passed in 'reportID'. The caller must pass a buffer of the size of the 72 | * expected report in 'buffer' and initialize the variable in '*len' to the 73 | * total size of this buffer. Upon successful return, the report (prefixed with 74 | * a report ID) is in 'buffer' and the actual length of the report is returned 75 | * in '*len'. 76 | * Returns: 0 on success, an error code otherwise. 77 | */ 78 | 79 | /* ------------------------------------------------------------------------ */ 80 | 81 | #endif /* __usbcalls_h_INCLUDED__ */ 82 | --------------------------------------------------------------------------------