├── .gitignore ├── .gitmodules ├── ATmega8u2Code ├── ButtonMapping.txt ├── HexFiles │ └── batchisp.exe ├── Makefile ├── Serial_AVR8.c ├── Serial_AVR8.h ├── UnoJoy.atsln ├── UnoJoy.avrgccproj ├── UnoJoy.avrsln ├── UnoJoy.avrsuo ├── UnoJoy.c ├── UnoJoy.cproj ├── dataForController_t.h ├── gpl.txt ├── physicalButtonList_t.h ├── usb_gamepad.c └── usb_gamepad.h ├── ArdPIUino ├── ArdPIUino.h ├── ArdPIUino.ino └── CRC32.h ├── ArdPIUino_conmuted ├── ArdPIUino.h ├── ArdPIUino.ino └── CRC32.h ├── Arduino-usbserial-atmega16u2-Uno-Rev3.hex ├── Arduino-usbserial-uno.hex ├── ArduinoPIUAux └── ArduinoPIUAux.ino ├── ArduinoPIUAux_Lights ├── ArduinoPIUAux_Lights.fzz ├── ArduinoPIUAux_Lights.ino ├── ArduinoPIUAux_Lights.png └── wiring.md ├── CRC32.h ├── Config └── LUFAConfig.h ├── Descriptors.c ├── Descriptors.h ├── LICENSE ├── PIUIO.c ├── PIUIO.h ├── PIUIO.hex ├── PIUIO_leonardo.c ├── PIUIO_leonardo.hex ├── TurnIntoAPIUIO.bat ├── TurnIntoAnArduino.bat ├── asf.xml ├── doxyfile ├── makefile ├── makefile.leonardo └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.elf 2 | *.bin 3 | *.eep 4 | *.map 5 | *.lss 6 | *.sym 7 | *.a 8 | *.d 9 | *.o 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lufa"] 2 | path = lufa 3 | url = https://github.com/abcminiuser/lufa.git 4 | -------------------------------------------------------------------------------- /ATmega8u2Code/ButtonMapping.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is a quick reference to what 3 | * buttons correspond to what between the 4 | * PS3 and the Windows dialog 5 | */ 6 | 7 | 8 | Windows : PS3 9 | 1 : Square 10 | 2 : Cross 11 | 3 : Circle 12 | 4 : Triangle 13 | 5 : L1 14 | 6 : R1 15 | 7 : L2 16 | 8 : R2 17 | 9 : Select 18 | 10 : Start 19 | 11 : L3 20 | 12 : R3 21 | 13 : Home 22 | 23 | Hat Switch : D-Pad 24 | 25 | X/Y Axis : Left Stick X/Y 26 | Z Axis: Right Stick X 27 | Z Rotation: Right Stick Y 28 | -------------------------------------------------------------------------------- /ATmega8u2Code/HexFiles/batchisp.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ckdur/PIUIO_Arduino/8fe6a9e39834d287ef6faa94dc9868920603f086/ATmega8u2Code/HexFiles/batchisp.exe -------------------------------------------------------------------------------- /ATmega8u2Code/Makefile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ckdur/PIUIO_Arduino/8fe6a9e39834d287ef6faa94dc9868920603f086/ATmega8u2Code/Makefile -------------------------------------------------------------------------------- /ATmega8u2Code/Serial_AVR8.c: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | #define __INCLUDE_FROM_SERIAL_C 32 | #include "../Serial.h" 33 | 34 | FILE USARTSerialStream; 35 | 36 | int Serial_putchar(char DataByte, 37 | FILE *Stream) 38 | { 39 | (void)Stream; 40 | 41 | Serial_SendByte(DataByte); 42 | return 0; 43 | } 44 | 45 | int Serial_getchar(FILE *Stream) 46 | { 47 | (void)Stream; 48 | 49 | if (!(Serial_IsCharReceived())) 50 | return _FDEV_EOF; 51 | 52 | return Serial_ReceiveByte(); 53 | } 54 | 55 | int Serial_getchar_Blocking(FILE *Stream) 56 | { 57 | (void)Stream; 58 | 59 | while (!(Serial_IsCharReceived())); 60 | return Serial_ReceiveByte(); 61 | } 62 | 63 | void Serial_SendString_P(const char* FlashStringPtr) 64 | { 65 | uint8_t CurrByte; 66 | 67 | while ((CurrByte = pgm_read_byte(FlashStringPtr)) != 0x00) 68 | { 69 | Serial_SendByte(CurrByte); 70 | FlashStringPtr++; 71 | } 72 | } 73 | 74 | void Serial_SendString(const char* StringPtr) 75 | { 76 | uint8_t CurrByte; 77 | 78 | while ((CurrByte = *StringPtr) != 0x00) 79 | { 80 | Serial_SendByte(CurrByte); 81 | StringPtr++; 82 | } 83 | } 84 | 85 | void Serial_SendData(const uint8_t* Buffer, 86 | uint16_t Length) 87 | { 88 | while (Length--) 89 | Serial_SendByte(*(Buffer++)); 90 | } 91 | 92 | void Serial_CreateStream(FILE* Stream) 93 | { 94 | if (!(Stream)) 95 | { 96 | Stream = &USARTSerialStream; 97 | stdin = Stream; 98 | stdout = Stream; 99 | } 100 | 101 | *Stream = (FILE)FDEV_SETUP_STREAM(Serial_putchar, Serial_getchar, _FDEV_SETUP_RW); 102 | } 103 | 104 | void Serial_CreateBlockingStream(FILE* Stream) 105 | { 106 | if (!(Stream)) 107 | { 108 | Stream = &USARTSerialStream; 109 | stdin = Stream; 110 | stdout = Stream; 111 | } 112 | 113 | *Stream = (FILE)FDEV_SETUP_STREAM(Serial_putchar, Serial_getchar_Blocking, _FDEV_SETUP_RW); 114 | } 115 | -------------------------------------------------------------------------------- /ATmega8u2Code/Serial_AVR8.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2012. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaim all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * \brief Serial USART Peripheral Driver (AVR8) 33 | * 34 | * On-chip serial USART driver for the 8-bit AVR microcontrollers. 35 | * 36 | * \note This file should not be included directly. It is automatically included as needed by the USART driver 37 | * dispatch header located in LUFA/Drivers/Peripheral/Serial.h. 38 | */ 39 | 40 | /** \ingroup Group_Serial 41 | * \defgroup Group_Serial_AVR8 Serial USART Peripheral Driver (AVR8) 42 | * 43 | * \section Sec_ModDescription Module Description 44 | * On-chip serial USART driver for the 8-bit AVR microcontrollers. 45 | * 46 | * \note This file should not be included directly. It is automatically included as needed by the USART driver 47 | * dispatch header located in LUFA/Drivers/Peripheral/Serial.h. 48 | * 49 | * \section Sec_ExampleUsage Example Usage 50 | * The following snippet is an example of how this module may be used within a typical 51 | * application. 52 | * 53 | * \code 54 | * // Initialize the serial USART driver before first use, with 9600 baud (and no double-speed mode) 55 | * Serial_Init(9600, false); 56 | * 57 | * // Send a string through the USART 58 | * Serial_TxString("Test String\r\n"); 59 | * 60 | * // Receive a byte through the USART 61 | * uint8_t DataByte = Serial_RxByte(); 62 | * \endcode 63 | * 64 | * @{ 65 | */ 66 | 67 | #ifndef __SERIAL_AVR8_H__ 68 | #define __SERIAL_AVR8_H__ 69 | 70 | /* Includes: */ 71 | #include "../../../Common/Common.h" 72 | #include "../../Misc/TerminalCodes.h" 73 | 74 | #include 75 | 76 | /* Enable C linkage for C++ Compilers: */ 77 | #if defined(__cplusplus) 78 | extern "C" { 79 | #endif 80 | 81 | /* Preprocessor Checks: */ 82 | #if !defined(__INCLUDE_FROM_SERIAL_H) && !defined(__INCLUDE_FROM_SERIAL_C) 83 | #error Do not include this file directly. Include LUFA/Drivers/Peripheral/Serial.h instead. 84 | #endif 85 | 86 | /* Private Interface - For use in library only: */ 87 | #if !defined(__DOXYGEN__) 88 | /* External Variables: */ 89 | extern FILE USARTSerialStream; 90 | 91 | /* Function Prototypes: */ 92 | int Serial_putchar(char DataByte, 93 | FILE *Stream); 94 | int Serial_getchar(FILE *Stream); 95 | int Serial_getchar_Blocking(FILE *Stream); 96 | #endif 97 | 98 | /* Public Interface - May be used in end-application: */ 99 | /* Macros: */ 100 | /** Macro for calculating the baud value from a given baud rate when the \c U2X (double speed) bit is 101 | * not set. 102 | * 103 | * \param[in] Baud Target serial UART baud rate. 104 | * 105 | * \return Closest UBRR register value for the given UART frequency. 106 | */ 107 | #define SERIAL_UBBRVAL(Baud) ((((F_CPU / 16) + (Baud / 2)) / (Baud)) - 1) 108 | 109 | /** Macro for calculating the baud value from a given baud rate when the \c U2X (double speed) bit is 110 | * set. 111 | * 112 | * \param[in] Baud Target serial UART baud rate. 113 | * 114 | * \return Closest UBRR register value for the given UART frequency. 115 | */ 116 | #define SERIAL_2X_UBBRVAL(Baud) ((((F_CPU / 8) + (Baud / 2)) / (Baud)) - 1) 117 | 118 | /* Function Prototypes: */ 119 | /** Transmits a given string located in program space (FLASH) through the USART. 120 | * 121 | * \param[in] FlashStringPtr Pointer to a string located in program space. 122 | */ 123 | void Serial_SendString_P(const char* FlashStringPtr) ATTR_NON_NULL_PTR_ARG(1); 124 | 125 | /** Transmits a given string located in SRAM memory through the USART. 126 | * 127 | * \param[in] StringPtr Pointer to a string located in SRAM space. 128 | */ 129 | void Serial_SendString(const char* StringPtr) ATTR_NON_NULL_PTR_ARG(1); 130 | 131 | /** Transmits a given buffer located in SRAM memory through the USART. 132 | * 133 | * \param[in] Buffer Pointer to a buffer containing the data to send. 134 | * \param[in] Length Length of the data to send, in bytes. 135 | */ 136 | void Serial_SendData(const uint8_t* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); 137 | 138 | /** Creates a standard character stream from the USART so that it can be used with all the regular functions 139 | * in the avr-libc \c library that accept a \c FILE stream as a destination (e.g. \c fprintf). The created 140 | * stream is bidirectional and can be used for both input and output functions. 141 | * 142 | * Reading data from this stream is non-blocking, i.e. in most instances, complete strings cannot be read in by a single 143 | * fetch, as the endpoint will not be ready at some point in the transmission, aborting the transfer. However, this may 144 | * be used when the read data is processed byte-per-bye (via \c getc()) or when the user application will implement its own 145 | * line buffering. 146 | * 147 | * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed, if \c NULL, \c stdout 148 | * and \c stdin will be configured to use the USART. 149 | * 150 | * \pre The USART must first be configured via a call to \ref Serial_Init() before the stream is used. 151 | */ 152 | void Serial_CreateStream(FILE* Stream); 153 | 154 | /** Identical to \ref Serial_CreateStream(), except that reads are blocking until the calling stream function terminates 155 | * the transfer. 156 | * 157 | * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed, if \c NULL, \c stdout 158 | * and \c stdin will be configured to use the USART. 159 | * 160 | * \pre The USART must first be configured via a call to \ref Serial_Init() before the stream is used. 161 | */ 162 | void Serial_CreateBlockingStream(FILE* Stream); 163 | 164 | /* Inline Functions: */ 165 | /** Initializes the USART, ready for serial data transmission and reception. This initializes the interface to 166 | * standard 8-bit, no parity, 1 stop bit settings suitable for most applications. 167 | * 168 | * \param[in] BaudRate Serial baud rate, in bits per second. 169 | * \param[in] DoubleSpeed Enables double speed mode when set, halving the sample time to double the baud rate. 170 | */ 171 | static inline void Serial_Init(const uint32_t BaudRate, 172 | const bool DoubleSpeed) 173 | { 174 | UBRR1 = (DoubleSpeed ? SERIAL_2X_UBBRVAL(BaudRate) : SERIAL_UBBRVAL(BaudRate)); 175 | 176 | UCSR1C = ((1 << UCSZ11) | (1 << UCSZ10)); 177 | UCSR1A = (DoubleSpeed ? (1 << U2X1) : 0); 178 | UCSR1B = ((1 << TXEN1) | (1 << RXEN1)); 179 | 180 | DDRD |= (1 << 3); 181 | PORTD |= (1 << 2); 182 | } 183 | 184 | /** Turns off the USART driver, disabling and returning used hardware to their default configuration. */ 185 | static inline void Serial_Disable(void) 186 | { 187 | UCSR1B = 0; 188 | UCSR1A = 0; 189 | UCSR1C = 0; 190 | 191 | UBRR1 = 0; 192 | 193 | DDRD &= ~(1 << 3); 194 | PORTD &= ~(1 << 2); 195 | } 196 | 197 | /** Indicates whether a character has been received through the USART. 198 | * 199 | * \return Boolean \c true if a character has been received, \c false otherwise. 200 | */ 201 | static inline bool Serial_IsCharReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; 202 | static inline bool Serial_IsCharReceived(void) 203 | { 204 | return ((UCSR1A & (1 << RXC1)) ? true : false); 205 | } 206 | 207 | /** Transmits a given byte through the USART. 208 | * 209 | * \param[in] DataByte Byte to transmit through the USART. 210 | */ 211 | static inline void Serial_SendByte(const char DataByte) ATTR_ALWAYS_INLINE; 212 | static inline void Serial_SendByte(const char DataByte) 213 | { 214 | while (!(UCSR1A & (1 << UDRE1))); 215 | UDR1 = DataByte; 216 | } 217 | 218 | /** Receives the next byte from the USART. 219 | * 220 | * \return Next byte received from the USART, or a negative value if no byte has been received. 221 | */ 222 | static inline int16_t Serial_ReceiveByte(void) ATTR_ALWAYS_INLINE; 223 | static inline int16_t Serial_ReceiveByte(void) 224 | { 225 | if (!(Serial_IsCharReceived())) 226 | return -1; 227 | 228 | return UDR1; 229 | } 230 | 231 | /* Disable C linkage for C++ Compilers: */ 232 | #if defined(__cplusplus) 233 | } 234 | #endif 235 | 236 | #endif 237 | 238 | /** @} */ 239 | 240 | -------------------------------------------------------------------------------- /ATmega8u2Code/UnoJoy.atsln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Atmel Studio Solution File, Format Version 11.00 4 | Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "UnoJoy", "UnoJoy.cproj", "{6974E705-4DBA-49AB-8AB5-42EA03CD49C4}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|AVR = Debug|AVR 9 | Hex Files|AVR = Hex Files|AVR 10 | HexFiles|AVR = HexFiles|AVR 11 | Release|AVR = Release|AVR 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {6974E705-4DBA-49AB-8AB5-42EA03CD49C4}.Debug|AVR.ActiveCfg = Debug|AVR 15 | {6974E705-4DBA-49AB-8AB5-42EA03CD49C4}.Debug|AVR.Build.0 = Debug|AVR 16 | {6974E705-4DBA-49AB-8AB5-42EA03CD49C4}.Hex Files|AVR.ActiveCfg = Hex Files|AVR 17 | {6974E705-4DBA-49AB-8AB5-42EA03CD49C4}.Hex Files|AVR.Build.0 = Hex Files|AVR 18 | {6974E705-4DBA-49AB-8AB5-42EA03CD49C4}.HexFiles|AVR.ActiveCfg = HexFiles|AVR 19 | {6974E705-4DBA-49AB-8AB5-42EA03CD49C4}.HexFiles|AVR.Build.0 = HexFiles|AVR 20 | {6974E705-4DBA-49AB-8AB5-42EA03CD49C4}.Release|AVR.ActiveCfg = Release|AVR 21 | {6974E705-4DBA-49AB-8AB5-42EA03CD49C4}.Release|AVR.Build.0 = Release|AVR 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /ATmega8u2Code/UnoJoy.avrgccproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 2.0 5 | 5.0 6 | {6974e705-4dba-49ab-8ab5-42ea03cd49c4} 7 | ATmega8U2 8 | none 9 | $(MSBuildProjectName).elf 10 | $(MSBuildProjectDirectory)\$(Configuration) 11 | 12 | 13 | VersatilityUSB 14 | UnoJoy 15 | VersatilityUSB 16 | 17 | Executable 18 | C 19 | com.Atmel.AVRGCC8 20 | True 21 | 22 | 23 | 24 | 25 | True 26 | True 27 | 28 | 29 | F_CPU=16000000UL 30 | 31 | 32 | Optimize for size (-Os) 33 | True 34 | True 35 | True 36 | 37 | 38 | 39 | 40 | 41 |
0x200
42 |
43 |
44 |
45 | True 46 |
47 | 48 | 49 | 50 | True 51 | True 52 | 53 | 54 | F_CPU=16000000UL 55 | 56 | 57 | Optimize for size (-Os) 58 | True 59 | True 60 | Default (-g2) 61 | True 62 | --std=gnu99 63 | Default (-g2) 64 | 65 | 66 | 67 | 68 | 69 |
0x200
70 |
71 |
72 |
73 | True 74 | False 75 | C:\Users\Rocktopus\Dropbox\VersatilityUSB\Makefile 76 |
77 | 78 | 79 | 80 | True 81 | True 82 | 83 | 84 | F_CPU=16000000UL 85 | 86 | 87 | Optimize for size (-Os) 88 | True 89 | True 90 | True 91 | 92 | 93 | 94 | 95 | 96 |
0x200
97 |
98 |
99 |
100 | True 101 | bin\Hex Files\ 102 |
103 | 104 | 105 | 106 | True 107 | True 108 | 109 | 110 | F_CPU=16000000UL 111 | 112 | 113 | Optimize for size (-Os) 114 | True 115 | True 116 | True 117 | 118 | 119 | 120 | 121 | 122 |
0x200
123 |
124 |
125 |
126 | True 127 | bin\HexFiles\ 128 |
129 | 130 | 131 | compile 132 | 133 | 134 | compile 135 | 136 | 137 | compile 138 | 139 | 140 | compile 141 | 142 | 143 | compile 144 | 145 | 146 | 147 | 148 | compile 149 | 150 | 151 | 152 |
-------------------------------------------------------------------------------- /ATmega8u2Code/UnoJoy.avrsln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # AvrStudio Solution File, Format Version 11.00 4 | Project("{D1100916-62DA-4D80-A9B4-55A1E7CCEEB3}") = "UnoJoy", "UnoJoy.avrgccproj", "{6974E705-4DBA-49AB-8AB5-42EA03CD49C4}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | HexFiles|AVR = HexFiles|AVR 9 | Release|AVR = Release|AVR 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {6974E705-4DBA-49AB-8AB5-42EA03CD49C4}.HexFiles|AVR.ActiveCfg = HexFiles|AVR 13 | {6974E705-4DBA-49AB-8AB5-42EA03CD49C4}.HexFiles|AVR.Build.0 = HexFiles|AVR 14 | {6974E705-4DBA-49AB-8AB5-42EA03CD49C4}.Release|AVR.ActiveCfg = Release|AVR 15 | {6974E705-4DBA-49AB-8AB5-42EA03CD49C4}.Release|AVR.Build.0 = Release|AVR 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /ATmega8u2Code/UnoJoy.avrsuo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ckdur/PIUIO_Arduino/8fe6a9e39834d287ef6faa94dc9868920603f086/ATmega8u2Code/UnoJoy.avrsuo -------------------------------------------------------------------------------- /ATmega8u2Code/UnoJoy.c: -------------------------------------------------------------------------------- 1 | /* UnoJoy.c 2 | * Copyright (C) 2012 Alan Chatham 3 | * Made in conjunction with the RMIT Exertion Games Lab 4 | * 5 | * Based on works by: 6 | * Josh Kropf 7 | * grunskis 8 | * Toodles 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | /* Keyboard example for Teensy USB Development Board 25 | * http://www.pjrc.com/teensy/usb_keyboard.html 26 | * Copyright (c) 2008 PJRC.COM, LLC 27 | * 28 | * Permission is hereby granted, free of charge, to any person obtaining a copy 29 | * of this software and associated documentation files (the "Software"), to deal 30 | * in the Software without restriction, including without limitation the rights 31 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 32 | * copies of the Software, and to permit persons to whom the Software is 33 | * furnished to do so, subject to the following conditions: 34 | * 35 | * The above copyright notice and this permission notice shall be included in 36 | * all copies or substantial portions of the Software. 37 | * 38 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 39 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 40 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 41 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 42 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 43 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 44 | * THE SOFTWARE. 45 | */ 46 | 47 | 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include "dataForController_t.h" 54 | #include "usb_gamepad.h" 55 | 56 | #define RXLED 4 57 | #define TXLED 5 58 | 59 | #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) 60 | 61 | // This sets up an empty controller data packet and sends it out 62 | // to all the controllers attached. 63 | void setControllersToZero(void){ 64 | dataForController_t emptyData; 65 | emptyData.leftStickX = 128; 66 | emptyData.leftStickY = 128; 67 | emptyData.rightStickX = 128; 68 | emptyData.rightStickY = 128; 69 | sendPS3Data(emptyData); 70 | } 71 | 72 | // Initializes the USART to receive and transmit, 73 | // takes in a value you can find in the datasheet 74 | // based on desired communication and clock speeds 75 | void USART_Init(uint16_t baudSetting){ 76 | // Set baud rate 77 | UBRR1 = baudSetting; 78 | // Enable receiver and transmitter 79 | UCSR1B = (1<> 0); 199 | dataToSend.circleOn = 1 & (buttonData1 >> 1); 200 | dataToSend.squareOn = 1 & (buttonData1 >> 2); 201 | dataToSend.crossOn = 1 & (buttonData1 >> 3); 202 | dataToSend.l1On = 1 & (buttonData1 >> 4); 203 | dataToSend.l2On = 1 & (buttonData1 >> 5); 204 | dataToSend.l3On = 1 & (buttonData1 >> 6); 205 | dataToSend.r1On = 1 & (buttonData1 >> 7); 206 | 207 | dataToSend.r2On = 1 & (buttonData2 >> 0); 208 | dataToSend.r3On = 1 & (buttonData2 >> 1); 209 | dataToSend.selectOn = 1 & (buttonData2 >> 2); 210 | dataToSend.startOn = 1 & (buttonData2 >> 3); 211 | dataToSend.homeOn = 1 & (buttonData2 >> 4); 212 | dataToSend.dpadLeftOn = 1 & (buttonData2 >> 5); 213 | dataToSend.dpadUpOn = 1 & (buttonData2 >> 6); 214 | dataToSend.dpadRightOn = 1 & (buttonData2 >> 7); 215 | 216 | dataToSend.dpadDownOn = 1 & (buttonData3 >> 0); 217 | 218 | 219 | // Finally, we send the data out via the USB port 220 | sendPS3Data(dataToSend); 221 | 222 | } 223 | } -------------------------------------------------------------------------------- /ATmega8u2Code/UnoJoy.cproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 2.0 5 | 6.0 6 | {6974e705-4dba-49ab-8ab5-42ea03cd49c4} 7 | ATmega8U2 8 | none 9 | $(MSBuildProjectDirectory)\$(Configuration) 10 | 11 | 12 | VersatilityUSB 13 | UnoJoy 14 | VersatilityUSB 15 | 16 | Executable 17 | C 18 | com.Atmel.AVRGCC8 19 | Native 20 | true 21 | false 22 | 23 | 0 24 | 3.1.3 25 | 26 | 27 | UnoJoy 28 | .elf 29 | 30 | 31 | True 32 | True 33 | True 34 | True 35 | True 36 | 37 | 38 | F_CPU=16000000UL 39 | 40 | 41 | Optimize for size (-Os) 42 | True 43 | True 44 | True 45 | 46 | 47 | m 48 | 49 | 50 | 51 | 52 | 53 | 54 | False 55 | C:\Users\Rocktopus\Dropbox\VersatilityUSB\Makefile 56 | UnoJoy 57 | .elf 58 | 59 | 60 | True 61 | True 62 | True 63 | True 64 | True 65 | 66 | 67 | F_CPU=16000000UL 68 | 69 | 70 | Optimize for size (-Os) 71 | True 72 | True 73 | Default (-g2) 74 | True 75 | --std=gnu99 76 | 77 | 78 | m 79 | 80 | 81 | Default (-Wa,-g) 82 | 83 | 84 | 85 | 86 | bin\Hex Files\ 87 | UnoJoy 88 | .elf 89 | 90 | 91 | True 92 | True 93 | True 94 | True 95 | True 96 | 97 | 98 | F_CPU=16000000UL 99 | 100 | 101 | Optimize for size (-Os) 102 | True 103 | True 104 | True 105 | 106 | 107 | m 108 | 109 | 110 | 111 | 112 | 113 | 114 | bin\HexFiles\ 115 | UnoJoy 116 | .elf 117 | 118 | 119 | True 120 | True 121 | True 122 | True 123 | True 124 | 125 | 126 | F_CPU=16000000UL 127 | 128 | 129 | Optimize for size (-Os) 130 | True 131 | True 132 | True 133 | 134 | 135 | m 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | compile 144 | 145 | 146 | compile 147 | 148 | 149 | compile 150 | 151 | 152 | compile 153 | 154 | 155 | 156 | 157 | compile 158 | 159 | 160 | 161 | -------------------------------------------------------------------------------- /ATmega8u2Code/dataForController_t.h: -------------------------------------------------------------------------------- 1 | /* dataForController_t.h 2 | * 3 | * Alan Chatham - 2011 4 | * 5 | * This is simply a typedef for a struct 6 | * that holds information about controller 7 | * button presses. It is used by the controller 8 | * libraries to pass information from an application 9 | * to a library function that formats and sends 10 | * appropriate controller data 11 | */ 12 | 13 | #ifndef DATA_FOR_CONTROLLER_T 14 | #define DATA_FOR_CONTROLLER_T 15 | 16 | typedef struct dataForController_t 17 | { 18 | uint8_t triangleOn : 1; // variables to abstractly tell us which buttons are pressed 19 | uint8_t circleOn : 1; 20 | uint8_t squareOn : 1; 21 | uint8_t crossOn : 1; 22 | uint8_t l1On : 1; 23 | uint8_t l2On : 1; 24 | uint8_t l3On : 1; 25 | uint8_t r1On : 1; 26 | 27 | uint8_t r2On : 1; 28 | uint8_t r3On : 1; 29 | uint8_t selectOn : 1; 30 | uint8_t startOn : 1; 31 | uint8_t homeOn : 1; 32 | uint8_t dpadLeftOn : 1; 33 | uint8_t dpadUpOn : 1; 34 | uint8_t dpadRightOn : 1; 35 | 36 | uint8_t dpadDownOn : 1; 37 | uint8_t leftStickX : 8; 38 | uint8_t leftStickY : 8; 39 | uint8_t rightStickX : 8; 40 | uint8_t rightStickY : 8; 41 | } dataForController_t; 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /ATmega8u2Code/physicalButtonList_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * typedefs.h 3 | * 4 | * Created: 12/13/2011 2:26:51 PM 5 | * Author: Alan Chatham 6 | * 7 | * This file contains all the typedef'ed structs we're using to store button data 8 | */ 9 | 10 | 11 | #ifndef PHYSICAL_BUTTON_LIST_T 12 | #define PHYSICAL_BUTTON_LIST_T 13 | 14 | // How many total inputs do we have? 15 | #define NUMBER_OF_INPUTS 36 16 | #define NUMBER_OF_DIGITAL_BUTTONS 27 17 | 18 | // This one is an abstract representation of what physical buttons we have 19 | // on the controller itself 20 | typedef struct physicalButtonList_t{ 21 | uint8_t r3On; 22 | uint8_t startOn; 23 | uint8_t r2On; 24 | uint8_t r1On; 25 | uint8_t triangleOn; 26 | uint8_t circleOn; 27 | uint8_t squareOn; 28 | uint8_t crossOn; 29 | uint8_t l1On; 30 | uint8_t l2On; 31 | uint8_t selectOn; 32 | uint8_t dpadDownOn; 33 | uint8_t dpadRightOn; 34 | uint8_t dpadLeftOn; 35 | uint8_t dpadUpOn; 36 | uint8_t menuOn; 37 | 38 | uint8_t leftStickX; 39 | uint8_t leftStickY; 40 | uint8_t rightStickX; 41 | uint8_t rightStickY; 42 | 43 | uint8_t joy3X; 44 | uint8_t joy3Y; 45 | uint8_t joy4X; 46 | uint8_t joy4Y; 47 | 48 | uint8_t l3On; 49 | uint8_t joy3ButtonOn; 50 | uint8_t joy4ButtonOn; 51 | uint8_t handsFree1; 52 | uint8_t handsFree2; 53 | uint8_t handsFree3; 54 | uint8_t handsFree4; 55 | uint8_t buttonBelowLStick; 56 | uint8_t buttonBelowRStick; 57 | uint8_t sipSwitch; 58 | uint8_t puffSwitch; 59 | uint8_t programButtonOn; 60 | 61 | } physicalButtonList_t; 62 | #endif // PHYSICAL_BUTTON_LIST_T 63 | -------------------------------------------------------------------------------- /ATmega8u2Code/usb_gamepad.c: -------------------------------------------------------------------------------- 1 | /* PS3 Teensy HID Gamepad 2 | * Copyright (C) 2010 Josh Kropf 3 | * 4 | * Based on works by: 5 | * grunskis 6 | * Toodles 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | 22 | /* USB Keyboard Example for Teensy USB Development Board 23 | * http://www.pjrc.com/teensy/usb_keyboard.html 24 | * Copyright (c) 2009 PJRC.COM, LLC 25 | * 26 | * Permission is hereby granted, free of charge, to any person obtaining a copy 27 | * of this software and associated documentation files (the "Software"), to deal 28 | * in the Software without restriction, including without limitation the rights 29 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 30 | * copies of the Software, and to permit persons to whom the Software is 31 | * furnished to do so, subject to the following conditions: 32 | * 33 | * The above copyright notice and this permission notice shall be included in 34 | * all copies or substantial portions of the Software. 35 | * 36 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 37 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 38 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 39 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 40 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 41 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 42 | * THE SOFTWARE. 43 | */ 44 | 45 | #define USB_GAMEPAD_PRIVATE_INCLUDE 46 | 47 | #include "usb_gamepad.h" 48 | 49 | /************************************************************************** 50 | * 51 | * Configurable Options 52 | * 53 | **************************************************************************/ 54 | 55 | // You can change these to give your code its own name. 56 | #define STR_MANUFACTURER L"OpenChord X RMIT Exertion Games Lab" 57 | #define STR_PRODUCT L"UnoJoy Joystick" 58 | //#define STR_MANUFACTURER L"SEGA" 59 | //#define STR_PRODUCT L"VIRTUA STICK High Grade" 60 | 61 | 62 | // Mac OS-X and Linux automatically load the correct drivers. On 63 | // Windows, even though the driver is supplied by Microsoft, an 64 | // INF file is needed to load the driver. These numbers need to 65 | // match the INF file. 66 | #define VENDOR_ID 0x10C4 67 | #define PRODUCT_ID 0x82C0 68 | 69 | 70 | // USB devices are supposed to implement a halt feature, which is 71 | // rarely (if ever) used. If you comment this line out, the halt 72 | // code will be removed, saving 102 bytes of space (gcc 4.3.0). 73 | // This is not strictly USB compliant, but works with all major 74 | // operating systems. 75 | //#define SUPPORT_ENDPOINT_HALT 76 | 77 | 78 | 79 | /************************************************************************** 80 | * 81 | * Endpoint Buffer Configuration 82 | * 83 | **************************************************************************/ 84 | 85 | #define ENDPOINT0_SIZE 64 86 | 87 | #define GAMEPAD_INTERFACE 0 88 | #define GAMEPAD_ENDPOINT 1 89 | #define GAMEPAD_SIZE 64 90 | #define GAMEPAD_BUFFER EP_SINGLE_BUFFER //EP_DOUBLE_BUFFER 91 | 92 | static const uint8_t PROGMEM endpoint_config_table[] = { 93 | 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(GAMEPAD_SIZE) | GAMEPAD_BUFFER, 94 | 0, 95 | 0, 96 | 0 97 | }; 98 | 99 | 100 | /************************************************************************** 101 | * 102 | * Descriptor Data 103 | * 104 | **************************************************************************/ 105 | 106 | // Descriptors are the data that your computer reads when it auto-detects 107 | // this USB device (called "enumeration" in USB lingo). The most commonly 108 | // changed items are editable at the top of this file. Changing things 109 | // in here should only be done by those who've read chapter 9 of the USB 110 | // spec and relevant portions of any USB class specifications! 111 | 112 | 113 | static const uint8_t PROGMEM device_descriptor[] = { 114 | 18, // bLength 115 | 1, // bDescriptorType 116 | 0x10, 0x01, // bcdUSB 117 | 0, // bDeviceClass 118 | 0, // bDeviceSubClass 119 | 0, // bDeviceProtocol 120 | ENDPOINT0_SIZE, // bMaxPacketSize0 121 | LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor 122 | LSB(PRODUCT_ID), MSB(PRODUCT_ID), // idProduct 123 | 0x00, 0x01, // bcdDevice 124 | 1, // iManufacturer 125 | 2, // iProduct 126 | 0, // iSerialNumber 127 | 1 // bNumConfigurations 128 | }; 129 | 130 | static const uint8_t PROGMEM gamepad_hid_report_desc[] = { 131 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 132 | 0x09, 0x05, // USAGE (Gamepad) 133 | 0xa1, 0x01, // COLLECTION (Application) 134 | 0x15, 0x00, // LOGICAL_MINIMUM (0) 135 | 0x25, 0x01, // LOGICAL_MAXIMUM (1) 136 | 0x35, 0x00, // PHYSICAL_MINIMUM (0) 137 | 0x45, 0x01, // PHYSICAL_MAXIMUM (1) 138 | // AKA: buttons 139 | 0x75, 0x01, // REPORT_SIZE (1) 140 | 0x95, 0x0e, // REPORT_COUNT (13) 141 | 0x05, 0x09, // USAGE_PAGE (Button) 142 | 0x19, 0x01, // USAGE_MINIMUM (Button 1) 143 | 0x29, 0x0e, // USAGE_MAXIMUM (Button 13) 144 | 0x81, 0x02, // INPUT (Data,Var,Abs) 145 | 0x95, 0x02, // REPORT_COUNT (3) 146 | 0x81, 0x01, // INPUT (Cnst,Ary,Abs) 147 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 148 | 0x25, 0x07, // LOGICAL_MAXIMUM (7) 149 | 0x46, 0x3b, 0x01, // PHYSICAL_MAXIMUM (315) 150 | 0x75, 0x04, // REPORT_SIZE (4) 151 | 0x95, 0x01, // REPORT_COUNT (1) 152 | 0x65, 0x14, // UNIT (Eng Rot:Angular Pos) 153 | 0x09, 0x39, // USAGE (Hat switch) 154 | 0x81, 0x42, // INPUT (Data,Var,Abs,Null) 155 | 0x65, 0x00, // UNIT (None) 156 | 0x95, 0x01, // REPORT_COUNT (1) 157 | 0x81, 0x01, // INPUT (Cnst,Ary,Abs) 158 | // AKA: axes 159 | 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) 160 | 0x46, 0xff, 0x00, // PHYSICAL_MAXIMUM (255) 161 | 0x09, 0x30, // USAGE (X) 162 | 0x09, 0x31, // USAGE (Y) 163 | 0x09, 0x32, // USAGE (Z) 164 | 0x09, 0x35, // USAGE (Rz) 165 | 0x75, 0x08, // REPORT_SIZE (8) 166 | 0x95, 0x04, // REPORT_COUNT (6) 167 | 0x81, 0x02, // INPUT (Data,Var,Abs) 168 | 0x06, 0x00, 0xff, // USAGE_PAGE (Vendor Specific) 169 | 0x09, 0x20, // Unknown 170 | 0x09, 0x21, // Unknown 171 | 0x09, 0x22, // Unknown 172 | 0x09, 0x23, // Unknown 173 | 0x09, 0x24, // Unknown 174 | 0x09, 0x25, // Unknown 175 | 0x09, 0x26, // Unknown 176 | 0x09, 0x27, // Unknown 177 | 0x09, 0x28, // Unknown 178 | 0x09, 0x29, // Unknown 179 | 0x09, 0x2a, // Unknown 180 | 0x09, 0x2b, // Unknown 181 | 0x95, 0x0c, // REPORT_COUNT (12) 182 | 0x81, 0x02, // INPUT (Data,Var,Abs) 183 | 0x0a, 0x21, 0x26, // Unknown 184 | 0x95, 0x08, // REPORT_COUNT (8) 185 | 0xb1, 0x02, // FEATURE (Data,Var,Abs) 186 | 0xc0 // END_COLLECTION 187 | }; 188 | 189 | 190 | #define CONFIG1_DESC_SIZE (9+9+9+7) 191 | #define GAMEPAD_HID_DESC_OFFSET (9+9) 192 | static const uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = { 193 | // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10 194 | 9, // bLength; 195 | 2, // bDescriptorType; 196 | LSB(CONFIG1_DESC_SIZE), // wTotalLength 197 | MSB(CONFIG1_DESC_SIZE), 198 | 1, // bNumInterfaces 199 | 1, // bConfigurationValue 200 | 0, // iConfiguration 201 | 0x80, // bmAttributes 202 | 50, // bMaxPower 203 | // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 204 | 9, // bLength 205 | 4, // bDescriptorType 206 | GAMEPAD_INTERFACE, // bInterfaceNumber 207 | 0, // bAlternateSetting 208 | 1, // bNumEndpoints 209 | 0x03, // bInterfaceClass (0x03 = HID) 210 | 0x00, // bInterfaceSubClass (0x00 = No Boot) 211 | 0x00, // bInterfaceProtocol (0x00 = No Protocol) 212 | 0, // iInterface 213 | // HID interface descriptor, HID 1.11 spec, section 6.2.1 214 | 9, // bLength 215 | 0x21, // bDescriptorType 216 | 0x11, 0x01, // bcdHID 217 | 0, // bCountryCode 218 | 1, // bNumDescriptors 219 | 0x22, // bDescriptorType 220 | sizeof(gamepad_hid_report_desc), // wDescriptorLength 221 | 0, 222 | // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 223 | 7, // bLength 224 | 5, // bDescriptorType 225 | GAMEPAD_ENDPOINT | 0x80, // bEndpointAddress 226 | 0x03, // bmAttributes (0x03=intr) 227 | GAMEPAD_SIZE, 0, // wMaxPacketSize 228 | 10 // bInterval 229 | }; 230 | 231 | // If you're desperate for a little extra code memory, these strings 232 | // can be completely removed if iManufacturer, iProduct, iSerialNumber 233 | // in the device desciptor are changed to zeros. 234 | struct usb_string_descriptor_struct { 235 | uint8_t bLength; 236 | uint8_t bDescriptorType; 237 | int16_t wString[]; 238 | }; 239 | static const struct usb_string_descriptor_struct PROGMEM string0 = { 240 | 4, 241 | 3, 242 | {0x0409} 243 | }; 244 | static const struct usb_string_descriptor_struct PROGMEM string1 = { 245 | sizeof(STR_MANUFACTURER), 246 | 3, 247 | STR_MANUFACTURER 248 | }; 249 | static const struct usb_string_descriptor_struct PROGMEM string2 = { 250 | sizeof(STR_PRODUCT), 251 | 3, 252 | STR_PRODUCT 253 | }; 254 | 255 | // This table defines which descriptor data is sent for each specific 256 | // request from the host (in wValue and wIndex). 257 | static const struct descriptor_list_struct { 258 | uint16_t wValue; 259 | uint16_t wIndex; 260 | const uint8_t *addr; 261 | uint8_t length; 262 | } PROGMEM descriptor_list[] = { 263 | {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)}, 264 | {0x0200, 0x0000, config1_descriptor, sizeof(config1_descriptor)}, 265 | {0x2100, GAMEPAD_INTERFACE, config1_descriptor+GAMEPAD_HID_DESC_OFFSET, 9}, 266 | {0x2200, GAMEPAD_INTERFACE, gamepad_hid_report_desc, sizeof(gamepad_hid_report_desc)}, 267 | {0x0300, 0x0000, (const uint8_t *)&string0, 4}, 268 | {0x0301, 0x0409, (const uint8_t *)&string1, sizeof(STR_MANUFACTURER)}, 269 | {0x0302, 0x0409, (const uint8_t *)&string2, sizeof(STR_PRODUCT)} 270 | }; 271 | #define NUM_DESC_LIST (sizeof(descriptor_list)/sizeof(struct descriptor_list_struct)) 272 | 273 | 274 | /************************************************************************** 275 | * 276 | * Variables - these are the only non-stack RAM usage 277 | * 278 | **************************************************************************/ 279 | 280 | // zero when we are not configured, non-zero when enumerated 281 | static volatile uint8_t usb_configuration = 0; 282 | 283 | static const gamepad_state_t PROGMEM gamepad_idle_state = { 284 | .triangle_btn = 0, .square_btn = 0, .cross_btn = 0, .circle_btn = 0, 285 | .l1_btn = 0, .r1_btn = 0, .l2_btn = 0, .r2_btn = 0, 286 | .select_btn = 0, .start_btn = 0, .l3_btn = 0, .r3_btn = 0, .ps_btn = 0, 287 | .direction = 0x08, 288 | .l_x_axis = 0x80, .l_y_axis = 0x80, .r_x_axis = 0x80, .r_y_axis = 0x80, 289 | .up_axis = 0x00, .right_axis = 0x00, .down_axis = 0x00, .left_axis = 0x00, 290 | .circle_axis = 0x00, .cross_axis = 0x00, .square_axis = 0x00, .triangle_axis = 0x00, 291 | .l1_axis = 0x00, .r1_axis = 0x00, .l2_axis = 0x00, .r2_axis = 0x00 292 | }; 293 | 294 | /* 295 | * Series of bytes that appear in control packets right after the HID 296 | * descriptor is sent to the host. They where discovered by tracing output 297 | * from a Madcatz SF4 Joystick. Sending these bytes makes the PS button work. 298 | */ 299 | static const uint8_t PROGMEM magic_init_bytes[] = { 300 | 0x21, 0x26, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 301 | }; 302 | 303 | static uint8_t gamepad_idle_config = 0; 304 | 305 | // protocol setting from the host. We use exactly the same report 306 | // either way, so this variable only stores the setting since we 307 | // are required to be able to report which setting is in use. 308 | static uint8_t gamepad_protocol = 1; 309 | 310 | /************************************************************************** 311 | * 312 | * Public Functions - these are the API intended for the user 313 | * 314 | **************************************************************************/ 315 | 316 | // initialize USB 317 | // Returns 0 if initialized, 318 | // 1 if it timed out waiting for connection 319 | uint8_t usb_init(void) { 320 | HW_CONFIG(); 321 | USB_FREEZE(); // enable USB 322 | PLL_CONFIG(); // config PLL 323 | // wait a certain amount of time for PLL lock 324 | unsigned long timeoutCounter = 0; 325 | while (!(PLLCSR & (1<= USB_TIMEOUT) 329 | return 1; 330 | } 331 | USB_CONFIG(); // start USB clock 332 | UDCON = 0; // enable attach resistor 333 | usb_configuration = 0; 334 | UDIEN = (1<= NUM_DESC_LIST) { 587 | UECONX = (1< desc_length) len = desc_length; 609 | do { 610 | // wait for host ready for IN packet 611 | do { 612 | i = UEINTX; 613 | } while (!(i & ((1<= 1 && i <= MAX_ENDPOINT) { 675 | usb_send_in(); 676 | UENUM = i; 677 | if (bRequest == SET_FEATURE) { 678 | UECONX = (1<> 8); 722 | usb_send_in(); 723 | return; 724 | } 725 | if (bRequest == HID_SET_PROTOCOL) { 726 | gamepad_protocol = wValue; 727 | usb_send_in(); 728 | return; 729 | } 730 | } 731 | } 732 | } 733 | UECONX = (1< 5 | #include 6 | //#include "pindefs.h" 7 | #include "dataForController_t.h" 8 | #include "physicalButtonList_t.h" 9 | 10 | // Timeout in ms for the USB communication to start during initialization 11 | #define USB_TIMEOUT 1000 12 | 13 | uint8_t usb_init(void); // initialize everything 14 | uint8_t usb_configured(void); // is the USB port configured 15 | 16 | // This defines our gamepad_state_t type. This is half of changing what data UnoJoy sends out - the other half is changing 17 | // the HID Report Descriptor in usb_gamepad.c to reflect the different data contained here. 18 | 19 | typedef struct { 20 | // digital buttons, 0 = off, 1 = on 21 | 22 | uint8_t square_btn : 1; 23 | uint8_t cross_btn : 1; 24 | uint8_t circle_btn : 1; 25 | uint8_t triangle_btn : 1; 26 | 27 | uint8_t l1_btn : 1; 28 | uint8_t r1_btn : 1; 29 | uint8_t l2_btn : 1; 30 | uint8_t r2_btn : 1; 31 | 32 | uint8_t select_btn : 1; 33 | uint8_t start_btn : 1; 34 | uint8_t l3_btn : 1; 35 | uint8_t r3_btn : 1; 36 | 37 | uint8_t ps_btn : 1; 38 | // uint8_t l2_btn_alt : 1; 39 | 40 | // uint8_t r2_btn_alt : 1; 41 | uint8_t : 2; 42 | 43 | // digital direction, use the dir_* constants(enum) 44 | // 8 = center, 0 = up, 1 = up/right, 2 = right, 3 = right/down 45 | // 4 = down, 5 = down/left, 6 = left, 7 = left/up 46 | 47 | uint8_t direction; 48 | 49 | // left and right analog sticks, 0x00 left/up, 0x80 middle, 0xff right/down 50 | 51 | uint8_t l_x_axis; 52 | uint8_t l_y_axis; 53 | uint8_t r_x_axis; 54 | uint8_t r_y_axis; 55 | 56 | // Gonna assume these are button analog values for the d-pad. 57 | // NOTE: NOT EVEN SURE THIS IS RIGHT, OR IN THE CORRECT ORDER 58 | uint8_t up_axis; 59 | uint8_t right_axis; 60 | uint8_t down_axis; 61 | uint8_t left_axis; 62 | 63 | // button axis, 0x00 = unpressed, 0xff = fully pressed 64 | 65 | uint8_t triangle_axis; 66 | uint8_t circle_axis; 67 | uint8_t cross_axis; 68 | uint8_t square_axis; 69 | 70 | uint8_t l1_axis; 71 | uint8_t r1_axis; 72 | uint8_t l2_axis; 73 | uint8_t r2_axis; 74 | } gamepad_state_t; 75 | 76 | extern gamepad_state_t gamepad_state; 77 | 78 | void usb_gamepad_reset_state(void); 79 | 80 | int8_t usb_gamepad_send(void); 81 | 82 | int8_t sendPS3Data(dataForController_t); 83 | 84 | 85 | // Everything below this point is only intended for usb_gamepad.c 86 | #ifdef USB_GAMEPAD_PRIVATE_INCLUDE 87 | #include 88 | #include 89 | #include 90 | 91 | #define EP_TYPE_CONTROL 0x00 92 | #define EP_TYPE_BULK_IN 0x81 93 | #define EP_TYPE_BULK_OUT 0x80 94 | #define EP_TYPE_INTERRUPT_IN 0xC1 95 | #define EP_TYPE_INTERRUPT_OUT 0xC0 96 | #define EP_TYPE_ISOCHRONOUS_IN 0x41 97 | #define EP_TYPE_ISOCHRONOUS_OUT 0x40 98 | 99 | #define EP_SINGLE_BUFFER 0x02 100 | #define EP_DOUBLE_BUFFER 0x06 101 | 102 | #define EP_SIZE(s) ((s) == 64 ? 0x30 : \ 103 | ((s) == 32 ? 0x20 : \ 104 | ((s) == 16 ? 0x10 : \ 105 | 0x00))) 106 | 107 | #define MAX_ENDPOINT 4 108 | 109 | #define LSB(n) (n & 255) 110 | #define MSB(n) ((n >> 8) & 255) 111 | 112 | #if defined(__AVR_AT90USB162__) 113 | #define HW_CONFIG() 114 | #define PLL_CONFIG() (PLLCSR = ((1< 22 | // #include 23 | #include 24 | 25 | // CKDUR: Maybe we need this after 26 | unsigned long tick; 27 | unsigned char tmp1; 28 | unsigned char i; 29 | 30 | // RACERXL: Some Macros to help 31 | #define GETBIT(port,bit) ((unsigned char)(((unsigned char)(port)) & ((unsigned char)(0x01 << ((unsigned char)(bit)))))) 32 | #define SETBIT(port,bit) port |= (0x01 << (bit)) // RACERXL: Set Byte bit 33 | #define CLRBIT(port,bit) port &= ~(0x01 << (bit)) // RACERXL: Clr Byte bit 34 | 35 | static unsigned char Input[2]; // RACERXL: The actual 16 bits Input data 36 | static unsigned char Output[3]; // RACERXL: The actual 16 bits Output data 37 | 38 | // Call setupArdPIUino in the setup block of your program. 39 | // It sets up the hardware UnoJoy needs to work properly 40 | void setupArdPIUino(void); 41 | 42 | // You can also call the set 43 | void setupArdPIUino(int); 44 | 45 | //----- End of the interface code you should be using -----// 46 | //----- Below here is the actual implementation of 47 | 48 | // serialCheckInterval governs how many ms between 49 | // checks to the serial port for data. 50 | // It shouldn't go above 20 or so, otherwise you might 51 | // get unreliable data transmission to the UnoJoy firmware, 52 | // since after it sends a request, it waits 25 ms for a response. 53 | // If you really need to make it bigger than that, you'll have to 54 | // adjust that timeout in the UnoJoy ATmega8u2 firmware code as well. 55 | volatile int serialCheckInterval = 1; 56 | // This is an internal counter variable to count ms between 57 | // serial check times 58 | int serialCheckCounter = 0; 59 | 60 | // This is the setup function - it sets up the serial communication 61 | // and the timer interrupt for actually sending the data back and forth. 62 | void setupArdPIUino(void){ 63 | 64 | // Start the serial port at the specific, low-error rate UnoJoy uses. 65 | // If you want to change the rate, you'll have to change it in the 66 | // firmware for the ATmega8u2 as well. 250,000 is actually the best rate, 67 | // but it's not supported on Macs, breaking the processing debugger. 68 | Serial.begin(38400); 69 | 70 | // Now set up the Timer 0 compare register A 71 | // so that Timer0 (used for millis() and such) 72 | // also fires an interrupt when it's equal to 73 | // 128, not just on overflow. 74 | // This will fire our timer interrupt almost 75 | // every 1 ms (1024 us to be exact). 76 | OCR0A = 128; 77 | TIMSK0 |= (1 << OCIE0A); 78 | } 79 | 80 | // If you really need to change the serial polling 81 | // interval, use this function to initialize UnoJoy. 82 | // interval is the polling frequency, in ms. 83 | void setupArdPIUino(int interval){ 84 | serialCheckInterval = interval; 85 | setupArdPIUino(); 86 | } 87 | 88 | // This interrupt gets called approximately once per ms. 89 | // It counts how many ms between serial port polls, 90 | // and if it's been long enough, polls the serial 91 | // port to see if the UnoJoy firmware requested data. 92 | // If it did, it transmits the appropriate data back. 93 | ISR(TIMER0_COMPA_vect){ 94 | serialCheckCounter++; 95 | if (serialCheckCounter >= serialCheckInterval){ 96 | serialCheckCounter = 0; 97 | // If there is incoming data stored in the Arduino serial buffer 98 | while (Serial.available() > 0) { 99 | //pinMode(13, OUTPUT); 100 | //digitalWrite(13, HIGH); 101 | // Get incoming byte from the ATmega8u2 102 | byte inByte = Serial.read(); 103 | //Comment me if you dont like this 104 | //inByte = inByte - '0'; 105 | 106 | // CKDUR: That number tells us which byte 107 | if(inByte < 2) 108 | { 109 | Serial.write(Input[inByte]); 110 | //Serial.print(Input[inByte],BIN); 111 | } 112 | else if(3 == inByte) 113 | { 114 | for(i = 0; i < 3; i++) 115 | { 116 | tick = 0; 117 | while (Serial.available() <= 0 && tick < 10) tick++; 118 | if(tick >= 10) continue; 119 | Output[i] = Serial.read(); 120 | } 121 | } 122 | 123 | //digitalWrite(13, LOW); 124 | } 125 | } 126 | } 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /ArdPIUino/ArdPIUino.ino: -------------------------------------------------------------------------------- 1 | /***********************************************************/ 2 | /* ____ ___ _ _ ___ ___ ____ _ */ 3 | /* | _ \_ _| | | |_ _/ _ \ / ___| | ___ _ __ ___ */ 4 | /* | |_) | || | | || | | | | | | | |/ _ \| '_ \ / _ \ */ 5 | /* | __/| || |_| || | |_| | | |___| | (_) | | | | __/ */ 6 | /* |_| |___|\___/|___\___/ \____|_|\___/|_| |_|\___| */ 7 | /* */ 8 | /* By: Lucas Teske (USB-ON-AT90USBXXX BY CKDUR) */ 9 | /***********************************************************/ 10 | /* Basicly this is an PIUIO Clone with an ATMEGA8U2 and */ 11 | /* serial from ATMEGA328 interfaced on ARDUINO UNO */ 12 | /***********************************************************/ 13 | /* This is main code from ATMEGA328 pool system */ 14 | /***********************************************************/ 15 | /* License is WHAT? */ 16 | /* Please consult https://github.com/racerxdl/piuio_clone */ 17 | /***********************************************************/ 18 | 19 | #include "ArdPIUino.h" 20 | 21 | void setup(){ 22 | Input[0] = 0xFF; 23 | Input[1] = 0xFF; 24 | setupPins(); 25 | setupArdPIUino(); 26 | } 27 | 28 | unsigned char inputn,tmp2, tmp3; 29 | #define SET_THING if(tmp1) SETBIT(Input[inputn/8],inputn%8); else CLRBIT(Input[inputn/8],inputn%8); 30 | void loop(){ 31 | // CKDUR: This is void pollInputOutput() 32 | inputn = 4; tmp1 = digitalRead(2); SET_THING 33 | inputn = 3; tmp1 = digitalRead(3); SET_THING 34 | inputn = 2; tmp1 = digitalRead(4); SET_THING 35 | inputn = 1; tmp1 = digitalRead(5); SET_THING 36 | inputn = 0; tmp1 = digitalRead(6); SET_THING 37 | inputn = 12; tmp1 = digitalRead(7); SET_THING 38 | inputn = 11; tmp1 = digitalRead(8); SET_THING 39 | inputn = 10; tmp1 = digitalRead(9); SET_THING 40 | inputn = 9; tmp1 = digitalRead(10); SET_THING 41 | inputn = 8; tmp1 = digitalRead(11); SET_THING 42 | // inputn = 5; tmp1 = digitalRead(A1); SET_THING // CLEAR 43 | //inputn = 6; tmp1 = digitalRead(13); SET_THING // SERVICE 44 | inputn = 8+5; tmp1 = digitalRead(12); SET_THING // TEST 45 | //inputn = 7; tmp1 = digitalRead(A4); SET_THING // COIN 1 ? 46 | //inputn = 8+7; tmp1 = digitalRead(A5)?0:1; SET_THING // COIN 2 ? 47 | 48 | } 49 | 50 | void setupPins(void){ 51 | // CKDUR: For Programmer POV, this is easier 52 | //DDRC = 255; 53 | pinMode(A1, INPUT_PULLUP); 54 | pinMode(A2, INPUT_PULLUP); 55 | pinMode(A3, INPUT_PULLUP); 56 | pinMode(A4, INPUT_PULLUP); 57 | pinMode(A5, INPUT_PULLUP); 58 | //PORTC = 0; 59 | //DDRB = 0b00111110; 60 | pinMode(2, INPUT_PULLUP); 61 | pinMode(3, INPUT_PULLUP); 62 | pinMode(4, INPUT_PULLUP); 63 | pinMode(5, INPUT_PULLUP); 64 | pinMode(6, INPUT_PULLUP); 65 | pinMode(7, INPUT_PULLUP); 66 | pinMode(8, INPUT_PULLUP); 67 | pinMode(9, INPUT_PULLUP); 68 | pinMode(10, INPUT_PULLUP); 69 | pinMode(11, INPUT_PULLUP); 70 | pinMode(12, INPUT_PULLUP); 71 | pinMode(13, INPUT_PULLUP); 72 | } 73 | -------------------------------------------------------------------------------- /ArdPIUino/CRC32.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static PROGMEM prog_uint32_t crc_table[16] = { 4 | 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 5 | 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 6 | 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 7 | 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c 8 | }; 9 | 10 | unsigned long crc_update(unsigned long crc, byte data) 11 | { 12 | byte tbl_idx; 13 | tbl_idx = crc ^ (data >> (0 * 4)); 14 | crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); 15 | tbl_idx = crc ^ (data >> (1 * 4)); 16 | crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); 17 | return crc; 18 | } 19 | 20 | unsigned long crc_string(char *s) 21 | { 22 | unsigned long crc = ~0L; 23 | while (*s) 24 | crc = crc_update(crc, *s++); 25 | crc = ~crc; 26 | return crc; 27 | } 28 | 29 | void setup() 30 | { 31 | Serial.println(crc_string("HELLO"), HEX); 32 | } 33 | 34 | void loop() 35 | { 36 | } 37 | -------------------------------------------------------------------------------- /ArdPIUino_conmuted/ArdPIUino.h: -------------------------------------------------------------------------------- 1 | /***********************************************************/ 2 | /* ____ ___ _ _ ___ ___ ____ _ */ 3 | /* | _ \_ _| | | |_ _/ _ \ / ___| | ___ _ __ ___ */ 4 | /* | |_) | || | | || | | | | | | | |/ _ \| '_ \ / _ \ */ 5 | /* | __/| || |_| || | |_| | | |___| | (_) | | | | __/ */ 6 | /* |_| |___|\___/|___\___/ \____|_|\___/|_| |_|\___| */ 7 | /* */ 8 | /* By: Lucas Teske (USB-ON-AT90USBXXX BY CKDUR) */ 9 | /***********************************************************/ 10 | /* Basicly this is an PIUIO Clone with an ATMEGA8U2 and */ 11 | /* serial from ATMEGA328 interfaced on ARDUINO UNO */ 12 | /***********************************************************/ 13 | /* This is main code from ATMEGA328 pool system */ 14 | /***********************************************************/ 15 | /* License is WHAT? */ 16 | /* Please consult https://github.com/racerxdl/piuio_clone */ 17 | /***********************************************************/ 18 | 19 | #ifndef UNOJOY_H 20 | #define UNOJOY_H 21 | #include 22 | #include 23 | #include 24 | 25 | // CKDUR: Maybe we need this after 26 | unsigned long tick; 27 | unsigned char tmp1; 28 | unsigned char i; 29 | 30 | // RACERXL: Some Macros to help 31 | #define GETBIT(port,bit) ((unsigned char)(((unsigned char)(port)) & ((unsigned char)(0x01 << ((unsigned char)(bit)))))) 32 | #define SETBIT(port,bit) port |= (0x01 << (bit)) // RACERXL: Set Byte bit 33 | #define CLRBIT(port,bit) port &= ~(0x01 << (bit)) // RACERXL: Clr Byte bit 34 | 35 | static unsigned char Input[2]; // RACERXL: The actual 16 bits Input data 36 | static unsigned char Output[3]; // RACERXL: The actual 16 bits Output data 37 | 38 | // Call setupArdPIUino in the setup block of your program. 39 | // It sets up the hardware UnoJoy needs to work properly 40 | void setupArdPIUino(void); 41 | 42 | // You can also call the set 43 | void setupArdPIUino(int); 44 | 45 | //----- End of the interface code you should be using -----// 46 | //----- Below here is the actual implementation of 47 | 48 | // serialCheckInterval governs how many ms between 49 | // checks to the serial port for data. 50 | // It shouldn't go above 20 or so, otherwise you might 51 | // get unreliable data transmission to the UnoJoy firmware, 52 | // since after it sends a request, it waits 25 ms for a response. 53 | // If you really need to make it bigger than that, you'll have to 54 | // adjust that timeout in the UnoJoy ATmega8u2 firmware code as well. 55 | volatile int serialCheckInterval = 1; 56 | // This is an internal counter variable to count ms between 57 | // serial check times 58 | int serialCheckCounter = 0; 59 | 60 | // This is the setup function - it sets up the serial communication 61 | // and the timer interrupt for actually sending the data back and forth. 62 | void setupArdPIUino(void){ 63 | 64 | // Start the serial port at the specific, low-error rate UnoJoy uses. 65 | // If you want to change the rate, you'll have to change it in the 66 | // firmware for the ATmega8u2 as well. 250,000 is actually the best rate, 67 | // but it's not supported on Macs, breaking the processing debugger. 68 | Serial.begin(38400); 69 | 70 | // Now set up the Timer 0 compare register A 71 | // so that Timer0 (used for millis() and such) 72 | // also fires an interrupt when it's equal to 73 | // 128, not just on overflow. 74 | // This will fire our timer interrupt almost 75 | // every 1 ms (1024 us to be exact). 76 | OCR0A = 128; 77 | TIMSK0 |= (1 << OCIE0A); 78 | } 79 | 80 | // If you really need to change the serial polling 81 | // interval, use this function to initialize UnoJoy. 82 | // interval is the polling frequency, in ms. 83 | void setupArdPIUino(int interval){ 84 | serialCheckInterval = interval; 85 | setupArdPIUino(); 86 | } 87 | 88 | // This interrupt gets called approximately once per ms. 89 | // It counts how many ms between serial port polls, 90 | // and if it's been long enough, polls the serial 91 | // port to see if the UnoJoy firmware requested data. 92 | // If it did, it transmits the appropriate data back. 93 | ISR(TIMER0_COMPA_vect){ 94 | serialCheckCounter++; 95 | if (serialCheckCounter >= serialCheckInterval){ 96 | serialCheckCounter = 0; 97 | // If there is incoming data stored in the Arduino serial buffer 98 | while (Serial.available() > 0) { 99 | //pinMode(13, OUTPUT); 100 | //digitalWrite(13, HIGH); 101 | // Get incoming byte from the ATmega8u2 102 | byte inByte = Serial.read(); 103 | 104 | // CKDUR: That number tells us which byte 105 | if(inByte < 2) 106 | { 107 | Serial.write(Input[inByte]); 108 | } 109 | else if(3 == inByte) 110 | { 111 | for(i = 0; i < 3; i++) 112 | { 113 | tick = 0; 114 | while (Serial.available() <= 0 && tick < 10) tick++; 115 | if(tick >= 10) continue; 116 | Output[i] = Serial.read(); 117 | } 118 | } 119 | 120 | //digitalWrite(13, LOW); 121 | } 122 | } 123 | } 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /ArdPIUino_conmuted/ArdPIUino.ino: -------------------------------------------------------------------------------- 1 | /***********************************************************/ 2 | /* ____ ___ _ _ ___ ___ ____ _ */ 3 | /* | _ \_ _| | | |_ _/ _ \ / ___| | ___ _ __ ___ */ 4 | /* | |_) | || | | || | | | | | | | |/ _ \| '_ \ / _ \ */ 5 | /* | __/| || |_| || | |_| | | |___| | (_) | | | | __/ */ 6 | /* |_| |___|\___/|___\___/ \____|_|\___/|_| |_|\___| */ 7 | /* */ 8 | /* By: Lucas Teske (USB-ON-AT90USBXXX BY CKDUR) */ 9 | /***********************************************************/ 10 | /* Basicly this is an PIUIO Clone with an ATMEGA8U2 and */ 11 | /* serial from ATMEGA328 interfaced on ARDUINO UNO */ 12 | /***********************************************************/ 13 | /* This is main code from ATMEGA328 pool system */ 14 | /***********************************************************/ 15 | /* License is WHAT? */ 16 | /* Please consult https://github.com/racerxdl/piuio_clone */ 17 | /***********************************************************/ 18 | 19 | #include "ArdPIUino.h" 20 | 21 | void setup(){ 22 | setupPins(); 23 | setupArdPIUino(); 24 | } 25 | 26 | unsigned char inputn,tmp2, tmp3; 27 | void loop(){ 28 | // CKDUR: This is void pollInputOutput() 29 | 30 | // This will set outputs and get inputs 31 | // The board will use 4067 muxer that is 16-to-1 muxer. 32 | // PORTC is the Muxer Selector. (AKA A0 to A3) 33 | // PORTB0 is the Muxer Output (AKA D8) 34 | 35 | digitalWrite(12, HIGH); // Disable the latches input 36 | for(inputn=0;inputn<16;inputn++) { 37 | //PORTC = inputn; // Sets the muxer position 38 | digitalWrite(A4, GETBIT(inputn, 0)?HIGH:LOW); 39 | digitalWrite(A5, GETBIT(inputn, 1)?HIGH:LOW); 40 | digitalWrite(A2, GETBIT(inputn, 2)?HIGH:LOW); 41 | digitalWrite(A3, GETBIT(inputn, 3)?HIGH:LOW); 42 | delay(10); 43 | tmp1 = digitalRead(8)?0:1; // Gets the input 44 | if(tmp1) 45 | SETBIT(Input[inputn/8],inputn%8); // Sets if input = 1 46 | else 47 | CLRBIT(Input[inputn/8],inputn%8); // Clears if input = 0 48 | } 49 | // The board will use 4099 as output latch. Two are used to get 16 bit output. 50 | // PORTC is the address, PORTB1 is Data for First byte, PORTB2 is Data for Second, PORTB3 is Data for Third (AKA D9 TO D11) 51 | // The Latch input enables are in PORTB4 (D12) 52 | // So we will set two bits per loop cycle 53 | digitalWrite(12, LOW); // Enable the latches input 54 | for(inputn=0;inputn<8;inputn++) { 55 | digitalWrite(A4, GETBIT(inputn, 0)?HIGH:LOW); 56 | digitalWrite(A5, GETBIT(inputn, 1)?HIGH:LOW); 57 | digitalWrite(A2, GETBIT(inputn, 2)?HIGH:LOW); 58 | digitalWrite(A3, GETBIT(inputn, 3)?HIGH:LOW); // Sets the address 59 | 60 | tmp1 = GETBIT(Output[0],inputn); // Gets the output data 61 | tmp2 = GETBIT(Output[1],inputn); 62 | tmp3 = GETBIT(Output[2],inputn); // CKDUR: This is mine 63 | digitalWrite(9, tmp1?LOW:HIGH); // first latch 64 | digitalWrite(10, tmp2?LOW:HIGH); // second latch 65 | digitalWrite(11, tmp3?LOW:HIGH); // CKDUR: This is mine, third latch 66 | 67 | } 68 | digitalWrite(12, HIGH); // Disable the latches input, just in case. 69 | } 70 | 71 | void setupPins(void){ 72 | // CKDUR: For Programmer POV, this is easier 73 | //DDRC = 255; 74 | pinMode(A1, OUTPUT); 75 | pinMode(A2, OUTPUT); 76 | pinMode(A3, OUTPUT); 77 | pinMode(A4, OUTPUT); 78 | pinMode(A5, OUTPUT); 79 | //PORTC = 0; 80 | //DDRB = 0b00111110; 81 | pinMode(8, INPUT); 82 | pinMode(9, OUTPUT); 83 | pinMode(10, OUTPUT); 84 | pinMode(11, OUTPUT); 85 | pinMode(12, OUTPUT); 86 | } 87 | -------------------------------------------------------------------------------- /ArdPIUino_conmuted/CRC32.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static PROGMEM prog_uint32_t crc_table[16] = { 4 | 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 5 | 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 6 | 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 7 | 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c 8 | }; 9 | 10 | unsigned long crc_update(unsigned long crc, byte data) 11 | { 12 | byte tbl_idx; 13 | tbl_idx = crc ^ (data >> (0 * 4)); 14 | crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); 15 | tbl_idx = crc ^ (data >> (1 * 4)); 16 | crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); 17 | return crc; 18 | } 19 | 20 | unsigned long crc_string(char *s) 21 | { 22 | unsigned long crc = ~0L; 23 | while (*s) 24 | crc = crc_update(crc, *s++); 25 | crc = ~crc; 26 | return crc; 27 | } 28 | 29 | void setup() 30 | { 31 | Serial.println(crc_string("HELLO"), HEX); 32 | } 33 | 34 | void loop() 35 | { 36 | } 37 | -------------------------------------------------------------------------------- /Arduino-usbserial-atmega16u2-Uno-Rev3.hex: -------------------------------------------------------------------------------- 1 | :1000000090C00000A9C00000A7C00000A5C000006B 2 | :10001000A3C00000A1C000009FC000009DC0000060 3 | :100020009BC0000099C0000097C0000048C40000B9 4 | :100030000CC4000091C000008FC000008DC0000003 5 | :100040008BC0000089C0000087C0000085C0000090 6 | :1000500083C0000081C000007FC0000002C100001A 7 | :100060007BC0000079C0000077C0000075C00000B0 8 | :1000700073C0000071C000006FC000006DC00000C0 9 | :100080006BC0000069C0000067C0000065C00000D0 10 | :1000900063C0000061C000001201100102000008EE 11 | :1000A0004123430001000102DC0109023E0002017C 12 | :1000B00000C0320904000001020201000524000111 13 | :1000C0001004240206052406000107058203080027 14 | :1000D000FF09040100020A000000070504024000B5 15 | :1000E00001070583024000010403090432034100B3 16 | :1000F00072006400750069006E006F002000280027 17 | :100100007700770077002E006100720064007500B0 18 | :1001100069006E006F002E0063006300290000007C 19 | :10012000000011241FBECFEFD2E0DEBFCDBF11E033 20 | :10013000A0E0B1E0ECEAFFE002C005900D92A6312C 21 | :10014000B107D9F712E0A6E1B1E001C01D92AF32CC 22 | :10015000B107E1F7F1D028C753CF9C01DC01AE57BE 23 | :10016000BF4FED91FC91119741911196FC93EE9345 24 | :1001700080589F4FE817F90711F42D933C939FB7D0 25 | :10018000F894F901EC57FF4F8081815080839FBF25 26 | :10019000842F0895DF92EF92FF920F931F93FC013B 27 | :1001A0008489813019F0823021F405C040E3D42ED7 28 | :1001B00004C0DD2402C030E2D32E8389823011F4E2 29 | :1001C00088E0D82A8589873031F0883031F0863050 30 | :1001D00031F482E003C084E001C086E0D82A1092A6 31 | :1001E000C9001092C8001092CA00E784F088018903 32 | :1001F000128980E0E81681EEF80680E0080780E0CA 33 | :10020000180719F420E130E00FC0C801B701969536 34 | :1002100087957795679560587B47814E9F4FA801DA 35 | :100220009701A0D6215030403093CD002093CC00D0 36 | :10023000D092CA0080E0E81681EEF80680E0080758 37 | :1002400080E0180711F082E001C080E08093C800D0 38 | :1002500088E98093C9001F910F91FF90EF90DF9084 39 | :1002600008951F920F920FB60F9211242F938F9320 40 | :100270009F93EF93FF939091CE008EB38430F1F46F 41 | :10028000E0919901F0919A019083E0919901F091A8 42 | :100290009A01CF01019690939A018093990189590F 43 | :1002A000914021F489E191E0928381839FB7F89492 44 | :1002B00080919D018F5F80939D019FBFFF91EF9182 45 | :1002C0009F918F912F910F900FBE0F901F901895B7 46 | :1002D000FC01858580FF02C05F9808955F9A0895AC 47 | :1002E00080E091E0D5C580E091E088C584B7877F44 48 | :1002F00084BF28E10FB6F89420936000109260004C 49 | :100300000FBE87E690E09093CD008093CC0086E00E 50 | :100310008093CA001092C8002093C900539A5A9A39 51 | :100320008AB180638AB98BB180638BB983D284E050 52 | :1003300085BD5F9A579A08950F931F93CF93DF93CC 53 | :10034000D5DF2FB7F8948EE991E090931F02809348 54 | :100350001E0290932102809320022FBF2FB7F894A2 55 | :1003600089E191E090939A018093990190939C0187 56 | :1003700080939B012FBF7894CEE9D1E003E08FB743 57 | :10038000F894909122028FBF903809F180E091E0BB 58 | :10039000ABD497FD1CC0E0911E02F0911F02808338 59 | :1003A000E0911E02F0911F02CF01019690931F026F 60 | :1003B00080931E028E51924011F4D283C1839FB765 61 | :1003C000F894809122028F5F809322029FBF8FB7A3 62 | :1003D000F89410919D018FBFA89902C0113678F151 63 | :1003E000A89A80919D01882361F05D980093160181 64 | :1003F00008C089E191E0B1DE682F80E091E0DAD4B5 65 | :1004000011501123B1F780911601882351F080918A 66 | :10041000160181508093160180911601882309F4FA 67 | :100420005D9A80911701882351F0809117018150C6 68 | :100430008093170180911701882309F45C9A8FB784 69 | :10044000F894909122028FBF992369F08EE991E090 70 | :1004500084DE982F8091C80085FFFCCF9093CE005A 71 | :100460005C980093170180E091E095D42AD487CF5F 72 | :10047000DA01923049F0933061F09130F9F4E8E913 73 | :10048000F0E022E130E01EC0EAEAF0E02EE330E0E6 74 | :1004900019C0813049F0813018F0823079F408C0F9 75 | :1004A000E8EEF0E0849107C0ECEEF0E0849103C048 76 | :1004B000E0E2F1E08491282F30E004C0E0E0F0E0D9 77 | :1004C00020E030E0ED93FC93C901089528E030E08E 78 | :1004D00040E003C04F5F220F331F28173907D0F3C6 79 | :1004E000842F8295807F08958093E9008091EB00AE 80 | :1004F00081608093EB001092ED006093EC004093DC 81 | :10050000ED008091EE00881F8827881F08951092C3 82 | :10051000F40090E09093E9001092F0001092E8004F 83 | :100520001092ED008091EB008E7F8093EB009F5F37 84 | :10053000953081F708958091270288238CF403C0B9 85 | :100540008EB38823B1F08091E80082FFF9CF8091CB 86 | :10055000E8008B778093E80008958EB3882349F0F4 87 | :100560008091E80080FFF9CF8091E8008E7780933A 88 | :10057000E800089594E68091EC0080FF05C080912A 89 | :10058000E80080FF05C023C08091E80082FD1FC005 90 | :100590008EB3882311F482E008958EB3853011F470 91 | :1005A00083E008958091EB0085FF02C081E008950B 92 | :1005B0008091E10082FFDFCF8091E1008B7F80930B 93 | :1005C000E100992311F484E008959150D4CF80E0A4 94 | :1005D00008959C0140912D0250912E024617570715 95 | :1005E00018F4F90120E038C06115710511F0AB0174 96 | :1005F000F8CF8091E8008E778093E80040E050E0EB 97 | :10060000F0CF8091E80083FF02C081E008958091DF 98 | :10061000E80082FD2DC08EB3882381F18EB3853032 99 | :1006200079F18091E80080FF17C09091F20006C038 100 | :1006300081918093F100415050409F5F41155105D9 101 | :1006400011F09830A8F320E0983009F421E080916F 102 | :10065000E8008E778093E8004115510591F622233A 103 | :1006600081F606C08EB3882349F08EB3853041F001 104 | :100670008091E80082FFF6CF80E0089582E008953F 105 | :1006800083E008959C0140912D0250912E0246175F 106 | :10069000570710F490E03BC06115710511F0AB01F4 107 | :1006A000F9CF8091E8008E778093E80040E050E039 108 | :1006B000F1CF8091E80083FF02C081E0089580912E 109 | :1006C000E80082FD30C08EB3882399F18EB3853067 110 | :1006D00091F18091E80080FF1AC08091F20009C07A 111 | :1006E000F9012F5F3F4FE491E093F10041505040FA 112 | :1006F0008F5F4115510511F0883090F390E08830FC 113 | :1007000009F491E08091E8008E778093E80041152C 114 | :10071000510579F6992369F606C08EB3882349F00E 115 | :100720008EB3853041F08091E80082FFF6CF80E003 116 | :10073000089582E0089583E008959C016115710594 117 | :1007400029F48091E8008B778093E800F90120C0BC 118 | :100750008091E80083FF02C081E008958EB3882372 119 | :1007600039F18EB3853031F18091E80082FFF0CF0E 120 | :1007700006C08091F10081936150704021F080911A 121 | :10078000F2008823B1F78091E8008B778093E8002E 122 | :1007900061157105E9F606C08EB3882349F08EB362 123 | :1007A000853041F08091E80080FFF6CF80E0089529 124 | :1007B00082E0089583E0089542D044D01EBA10929A 125 | :1007C0002502109224021092230284E089BD89B58B 126 | :1007D000826089BD09B400FEFDCF8091D800982FBA 127 | :1007E0009F779093D80080688093D80080916300B1 128 | :1007F0008E7F809363008091D8008F7D8093D80096 129 | :100800008091E0008E7F8093E0008091E1008E7FF8 130 | :100810008093E1008091E20081608093E20080910A 131 | :10082000E100877F8093E1008091E20088608093FF 132 | :10083000E2000895C1DF81E08093260208951092BE 133 | :10084000E20008951092E10008951F920F920FB6F2 134 | :100850000F9211241F932F933F934F935F936F93A6 135 | :100860007F938F939F93AF93BF93EF93FF93E9EEA3 136 | :10087000F0E0108117701082E0EFF0E08081877F58 137 | :1008800080837894C3D0F894A9EEB0E01C92E0EF96 138 | :10089000F0E08081886080831C93FF91EF91BF918D 139 | :1008A000AF919F918F917F916F915F914F913F9108 140 | :1008B0002F911F910F900FBE0F901F9018951F92B0 141 | :1008C0000F920FB60F9211242F933F934F935F9384 142 | :1008D0006F937F938F939F93AF93BF93EF93FF9308 143 | :1008E0008091E10080FF1BC08091E20080FF17C073 144 | :1008F0008091E1008E7F8093E1008091E2008E7F05 145 | :100900008093E2008091E20080618093E200809118 146 | :10091000D80080628093D80019BC1EBAD1D18091D2 147 | :10092000E10084FF29C08091E20084FF25C084E0BB 148 | :1009300089BD89B5826089BD09B400FEFDCF809173 149 | :10094000D8008F7D8093D8008091E1008F7E8093C6 150 | :10095000E1008091E2008F7E8093E2008091E200CE 151 | :1009600081608093E20080912502882311F481E068 152 | :1009700001C084E08EBBA4D18091E10083FF27C039 153 | :100980008091E20083FF23C08091E100877F809304 154 | :10099000E10082E08EBB109225028091E1008E7F03 155 | :1009A0008093E1008091E2008E7F8093E20080914D 156 | :1009B000E20080618093E200AADD80E060E042E036 157 | :1009C00093DD8091F00088608093F00079D1809170 158 | :1009D000E10082FF0AC08091E20082FF06C08091A0 159 | :1009E000E1008B7F8093E1006BD1FF91EF91BF918C 160 | :1009F000AF919F918F917F916F915F914F913F91B7 161 | :100A00002F910F900FBE0F901F9018951F93DF939B 162 | :100A1000CF93CDB7DEB7AC970FB6F894DEBF0FBE5D 163 | :100A2000CDBFE7E2F2E08091F100819322E0EF3266 164 | :100A3000F207C9F78091270230912802353009F476 165 | :100A400087C0363040F43130C9F1313070F0333086 166 | :100A500009F01DC133C0383009F4EFC0393009F452 167 | :100A6000FEC0363009F013C192C0803821F08238C0 168 | :100A700009F00DC108C090912302809124028823BF 169 | :100A800099F0926011C080912B0287708093E900E9 170 | :100A90008091EB0090E025E0969587952A95E1F707 171 | :100AA000982F91701092E9008091E800877F8093E1 172 | :100AB000E8009093F1001092F100CAC0882319F069 173 | :100AC000823009F0E4C090E08F719070009721F0BF 174 | :100AD000029709F0DDC00CC080912902813009F035 175 | :100AE000D7C010922402333069F5809324022AC0C3 176 | :100AF00080912902882331F520912B02277009F477 177 | :100B0000C7C02093E9008091EB0080FFC1C0333063 178 | :100B100021F48091EB00806213C08091EB00806132 179 | :100B20008093EB0081E090E002C0880F991F2A9526 180 | :100B3000E2F78093EA001092EA008091EB0088606F 181 | :100B40008093EB001092E9008091E800877F83C0DA 182 | :100B5000882309F09CC0109129028091E800877FCA 183 | :100B60008093E800E8DC04C08EB3882309F490C0C9 184 | :100B70008091E80080FFF8CF812F8F7711F492E009 185 | :100B800001C093E09EBB80688093E30081C08058E1 186 | :100B9000823008F07CC08091290290912A0223E0E3 187 | :100BA0008C3D920799F55FB7F894DE0115964EE0FB 188 | :100BB00020E030E061E2E42FF0E0609357008491A0 189 | :100BC00020FF03C082958F704F5F982F9F70892FF1 190 | :100BD000805D8A3308F0895F8C9311961C9211977F 191 | :100BE0002F5F3F4F12962431310529F75FBF8AE20C 192 | :100BF0008B8383E08C838091E800877F8093E8007B 193 | :100C0000CE0103966AE270E0E4DC11C060912B0231 194 | :100C1000AE014F5F5F4F2CDCBC010097C9F18091A2 195 | :100C2000E800877F8093E80089819A812BDD80919D 196 | :100C3000E8008B778093E8002BC0803841F58091E5 197 | :100C4000E800877F8093E800809125028093F1007F 198 | :100C50008091E8008E778093E8006DDC19C08823CE 199 | :100C6000B1F490912902923098F48091E800877F46 200 | :100C70008093E800909325025EDC80912502882312 201 | :100C800011F483E001C084E08EBB2DDB01C028DBC2 202 | :100C90008091E80083FF0AC08091EB00806280931E 203 | :100CA000EB008091E800877F8093E800AC960FB658 204 | :100CB000F894DEBF0FBECDBFCF91DF911F91089595 205 | :100CC00008951F938EB3882361F01091E90010926C 206 | :100CD000E9008091E80083FF01C098DE177010934F 207 | :100CE000E9001F9108950895FC018EB3843021F529 208 | :100CF00087859089A189B2890097A105B105E1F0A6 209 | :100D000085818093E9008091E80082FF15C0809181 210 | :100D1000F200882319F42FEF3FEF04C08091F10017 211 | :100D2000282F30E08091F200882341F48091E80080 212 | :100D30008B778093E80002C02FEF3FEFC901089541 213 | :100D4000FC018EB3843011F587859089A189B28921 214 | :100D50000097A105B105D1F081818093E9008091D0 215 | :100D6000F2008823A9F09091E8008091E8008E7746 216 | :100D70008093E80095FD0CC0FDDB982F882349F493 217 | :100D80008091E8008E778093E80003C092E001C074 218 | :100D900090E0892F0895FC018EB3843051F487854B 219 | :100DA0009089A189B2890097A105B10511F0CF0101 220 | :100DB000C7CF08951F93FC01162F8EB38430D9F44A 221 | :100DC00087859089A189B2890097A105B10599F01D 222 | :100DD00081818093E9008091E80085FD08C08091C1 223 | :100DE000E8008E778093E800C5DB882329F4109310 224 | :100DF000F10080E001C082E01F9108950F931F93DE 225 | :100E0000CF93DF93EC010D96FC0189E0DF011D9289 226 | :100E10008A95E9F72A813B8109818C81882311F425 227 | :100E200010E001C014E0C90151DB182B1260802FC3 228 | :100E300061E8412F59DB882329F12E813F810D8103 229 | :100E40008885882311F410E001C014E0C9013EDB5D 230 | :100E5000182B1260802F60E8412F46DB882391F029 231 | :100E60002A853B8509858C85882311F410E001C013 232 | :100E700014E0C9012BDB182B1260802F61EC412F8D 233 | :100E800033DB01C080E0DF91CF911F910F91089576 234 | :100E9000CF93DF93EC018091E80083FF60C08881ED 235 | :100EA00090E020912B0230912C022817390709F08D 236 | :100EB00056C080912802813261F0823220F4803263 237 | :100EC00009F04DC019C0823269F1833209F047C080 238 | :100ED00038C080912702813A09F041C08091E80032 239 | :100EE000877F8093E800CE010F9667E070E071DBAA 240 | :100EF0008091E8008B7713C080912702813279F5C9 241 | :100F00008091E800877F8093E800CE010F9667E02C 242 | :100F100070E013DCCE013ED98091E8008E7780939B 243 | :100F2000E8001DC0809127028132C9F48091E80059 244 | :100F3000877F8093E800809129028D87CE01C8D9F0 245 | :100F40000DC080912702813251F48091E800877FA3 246 | :100F50008093E800CE0160912902C5DEECDADF91D2 247 | :100F6000CF910895A1E21A2EAA1BBB1BFD010DC053 248 | :100F7000AA1FBB1FEE1FFF1FA217B307E407F50749 249 | :100F800020F0A21BB30BE40BF50B661F771F881F25 250 | :100F9000991F1A9469F760957095809590959B01BB 251 | :0C0FA000AC01BD01CF010895F894FFCF13 252 | :100FAC0000034000000440000002080000000000A4 253 | :060FBC000000000000002F 254 | :00000001FF 255 | -------------------------------------------------------------------------------- /Arduino-usbserial-uno.hex: -------------------------------------------------------------------------------- 1 | :100000009CC00000B5C00000B3C00000B1C000003B 2 | :10001000AFC00000ADC00000ABC00000A9C0000030 3 | :10002000A7C00000A5C00000A3C0000054C4000089 4 | :1000300018C400009DC000009BC0000099C00000D3 5 | :1000400097C0000095C0000093C0000091C0000060 6 | :100050008FC000008DC000008BC000000EC10000EA 7 | :1000600087C0000085C0000083C0000081C0000080 8 | :100070007FC000007DC000007BC0000079C0000090 9 | :1000800077C0000075C0000073C0000071C00000A0 10 | :100090006FC000006DC000001201100102000008D6 11 | :1000A0004123010001000102DC0109023E000201BE 12 | :1000B00000C0320904000001020201000524000111 13 | :1000C0001004240206052406000107058203080027 14 | :1000D000FF09040100020A000000070504024000B5 15 | :1000E00001070583024000010403090432034100B3 16 | :1000F00072006400750069006E006F002000280027 17 | :100100007700770077002E006100720064007500B0 18 | :1001100069006E006F002E0063006300290000007C 19 | :100120001803410072006400750069006E006F00E2 20 | :10013000200055006E006F00000011241FBECFEF9D 21 | :10014000D2E0DEBFCDBF11E0A0E0B1E0E4ECFFE023 22 | :1001500002C005900D92A631B107D9F712E0A6E1D1 23 | :10016000B1E001C01D92AF32B107E1F7F1D028C76D 24 | :1001700047CF9C01DC01AE57BF4FED91FC91119729 25 | :1001800041911196FC93EE9380589F4FE817F90721 26 | :1001900011F42D933C939FB7F894F901EC57FF4F5E 27 | :1001A0008081815080839FBF842F0895DF92EF92DA 28 | :1001B000FF920F931F93FC018489813019F08230E4 29 | :1001C00021F405C040E3D42E04C0DD2402C030E297 30 | :1001D000D32E8389823011F488E0D82A858987302C 31 | :1001E00031F0883031F0863031F482E003C084E0B1 32 | :1001F00001C086E0D82A1092C9001092C80010925F 33 | :10020000CA00E784F0880189128980E0E81681EE4F 34 | :10021000F80680E0080780E0180719F420E130E0D4 35 | :100220000FC0C801B7019695879577956795605877 36 | :100230007B47814E9F4FA8019701A0D621503040A7 37 | :100240003093CD002093CC00D092CA0080E0E81615 38 | :1002500081EEF80680E0080780E0180711F082E0E0 39 | :1002600001C080E08093C80088E98093C9001F9195 40 | :100270000F91FF90EF90DF9008951F920F920FB6AD 41 | :100280000F9211242F938F939F93EF93FF9390914D 42 | :10029000CE008EB38430F1F4E0919901F0919A018F 43 | :1002A0009083E0919901F0919A01CF01019690938A 44 | :1002B0009A01809399018959914021F489E191E053 45 | :1002C000928381839FB7F89480919D018F5F809383 46 | :1002D0009D019FBFFF91EF919F918F912F910F9063 47 | :1002E0000FBE0F901F901895FC01858580FF02C0FE 48 | :1002F0005F9808955F9A089580E091E0D5C580E009 49 | :1003000091E088C584B7877F84BF28E10FB6F89451 50 | :1003100020936000109260000FBE87E690E09093FB 51 | :10032000CD008093CC0086E08093CA001092C80074 52 | :100330002093C900539A5A9A8AB180638AB98BB1C3 53 | :1003400080638BB983D284E085BD5F9A579A089504 54 | :100350000F931F93CF93DF93D5DF2FB7F8948EE9D8 55 | :1003600091E090931F0280931E029093210280934C 56 | :1003700020022FBF2FB7F89489E191E090939A0162 57 | :100380008093990190939C0180939B012FBF789457 58 | :10039000CEE9D1E003E08FB7F894909122028FBFAD 59 | :1003A000903809F180E091E0ABD497FD1CC0E0915A 60 | :1003B0001E02F0911F028083E0911E02F0911F0245 61 | :1003C000CF01019690931F0280931E028E5192409E 62 | :1003D00011F4D283C1839FB7F894809122028F5F7A 63 | :1003E000809322029FBF8FB7F89410919D018FBF19 64 | :1003F000A89902C0113678F1A89A80919D018823AE 65 | :1004000061F05D980093160108C089E191E0B1DECA 66 | :10041000682F80E091E0DAD411501123B1F7809178 67 | :100420001601882351F080911601815080931601A6 68 | :1004300080911601882309F45D9A80911701882321 69 | :1004400051F080911701815080931701809117011D 70 | :10045000882309F45C9A8FB7F894909122028FBF99 71 | :10046000992369F08EE991E084DE982F8091C8008D 72 | :1004700085FFFCCF9093CE005C980093170180E03D 73 | :1004800091E095D42AD487CFDA01923049F09330A5 74 | :1004900061F09130F9F4E8E9F0E022E130E01EC0CB 75 | :1004A000EAEAF0E02EE330E019C0813049F0813013 76 | :1004B00018F0823079F408C0E8EEF0E0849107C0CB 77 | :1004C000ECEEF0E0849103C0E0E2F1E08491282FAB 78 | :1004D00030E004C0E0E0F0E020E030E0ED93FC9399 79 | :1004E000C901089528E030E040E003C04F5F220FCB 80 | :1004F000331F28173907D0F3842F8295807F089502 81 | :100500008093E9008091EB0081608093EB00109272 82 | :10051000ED006093EC004093ED008091EE00881FA9 83 | :100520008827881F08951092F40090E09093E900C6 84 | :100530001092F0001092E8001092ED008091EB0014 85 | :100540008E7F8093EB009F5F953081F708958091B7 86 | :10055000270288238CF403C08EB38823B1F08091E6 87 | :10056000E80082FFF9CF8091E8008B778093E80064 88 | :1005700008958EB3882349F08091E80080FFF9CF79 89 | :100580008091E8008E778093E800089594E680914A 90 | :10059000EC0080FF05C08091E80080FF05C023C00B 91 | :1005A0008091E80082FD1FC08EB3882311F482E0A1 92 | :1005B00008958EB3853011F483E008958091EB00A7 93 | :1005C00085FF02C081E008958091E10082FFDFCFC6 94 | :1005D0008091E1008B7F8093E100992311F484E006 95 | :1005E00008959150D4CF80E008959C0140912D0250 96 | :1005F00050912E024617570718F4F90120E038C031 97 | :100600006115710511F0AB01F8CF8091E8008E778C 98 | :100610008093E80040E050E0F0CF8091E80083FF55 99 | :1006200002C081E008958091E80082FD2DC08EB364 100 | :10063000882381F18EB3853079F18091E80080FFC5 101 | :1006400017C09091F20006C081918093F100415053 102 | :1006500050409F5F4115510511F09830A8F320E0FC 103 | :10066000983009F421E08091E8008E778093E800CB 104 | :100670004115510591F6222381F606C08EB38823D9 105 | :1006800049F08EB3853041F08091E80082FFF6CFCB 106 | :1006900080E0089582E0089583E008959C014091F0 107 | :1006A0002D0250912E024617570710F490E03BC0E0 108 | :1006B0006115710511F0AB01F9CF8091E8008E77DB 109 | :1006C0008093E80040E050E0F1CF8091E80083FFA4 110 | :1006D00002C081E008958091E80082FD30C08EB3B1 111 | :1006E000882399F18EB3853091F18091E80080FFE5 112 | :1006F0001AC08091F20009C0F9012F5F3F4FE491C9 113 | :10070000E093F100415050408F5F4115510511F0C9 114 | :10071000883090F390E0883009F491E08091E8000F 115 | :100720008E778093E8004115510579F6992369F693 116 | :1007300006C08EB3882349F08EB3853041F0809196 117 | :10074000E80082FFF6CF80E0089582E0089583E01C 118 | :1007500008959C016115710529F48091E8008B775B 119 | :100760008093E800F90120C08091E80083FF02C077 120 | :1007700081E008958EB3882339F18EB3853031F14D 121 | :100780008091E80082FFF0CF06C08091F100819354 122 | :100790006150704021F08091F2008823B1F7809180 123 | :1007A000E8008B778093E80061157105E9F606C0D3 124 | :1007B0008EB3882349F08EB3853041F08091E800F4 125 | :1007C00080FFF6CF80E0089582E0089583E00895E9 126 | :1007D00042D044D01EBA10922502109224021092E8 127 | :1007E000230284E089BD89B5826089BD09B400FE19 128 | :1007F000FDCF8091D800982F9F779093D800806884 129 | :100800008093D800809163008E7F809363008091F5 130 | :10081000D8008F7D8093D8008091E0008E7F8093F8 131 | :10082000E0008091E1008E7F8093E1008091E20002 132 | :1008300081608093E2008091E100877F8093E100F6 133 | :100840008091E20088608093E2000895C1DF81E03A 134 | :100850008093260208951092E20008951092E1001C 135 | :1008600008951F920F920FB60F9211241F932F938A 136 | :100870003F934F935F936F937F938F939F93AF9328 137 | :10088000BF93EF93FF93E9EEF0E0108117701082B1 138 | :10089000E0EFF0E08081877F80837894C3D0F89484 139 | :1008A000A9EEB0E01C92E0EFF0E0808188608083E8 140 | :1008B0001C93FF91EF91BF91AF919F918F917F9189 141 | :1008C0006F915F914F913F912F911F910F900FBEAC 142 | :1008D0000F901F9018951F920F920FB60F92112430 143 | :1008E0002F933F934F935F936F937F938F939F9338 144 | :1008F000AF93BF93EF93FF938091E10080FF1BC004 145 | :100900008091E20080FF17C08091E1008E7F80938C 146 | :10091000E1008091E2008E7F8093E2008091E2000E 147 | :1009200080618093E2008091D80080628093D8003B 148 | :1009300019BC1EBAD1D18091E10084FF29C08091F9 149 | :10094000E20084FF25C084E089BD89B5826089BD4D 150 | :1009500009B400FEFDCF8091D8008F7D8093D80030 151 | :100960008091E1008F7E8093E1008091E2008F7E94 152 | :100970008093E2008091E20081608093E2008091A8 153 | :100980002502882311F481E001C084E08EBBA4D14C 154 | :100990008091E10083FF27C08091E20083FF23C0A4 155 | :1009A0008091E100877F8093E10082E08EBB10920E 156 | :1009B00025028091E1008E7F8093E1008091E2002A 157 | :1009C0008E7F8093E2008091E20080618093E2005C 158 | :1009D000AADD80E060E042E093DD8091F000886075 159 | :1009E0008093F00079D18091E10082FF0AC080916C 160 | :1009F000E20082FF06C08091E1008B7F8093E100DE 161 | :100A00006BD1FF91EF91BF91AF919F918F917F91AA 162 | :100A10006F915F914F913F912F910F900FBE0F906B 163 | :100A20001F9018951F93DF93CF93CDB7DEB7AC9788 164 | :100A30000FB6F894DEBF0FBECDBFE7E2F2E08091C3 165 | :100A4000F100819322E0EF32F207C9F7809127028B 166 | :100A500030912802353009F487C0363040F4313007 167 | :100A6000C9F1313070F0333009F01DC133C0383076 168 | :100A700009F4EFC0393009F4FEC0363009F013C173 169 | :100A800092C0803821F0823809F00DC108C09091E1 170 | :100A9000230280912402882399F0926011C08091F2 171 | :100AA0002B0287708093E9008091EB0090E025E0B5 172 | :100AB000969587952A95E1F7982F91701092E90005 173 | :100AC0008091E800877F8093E8009093F100109276 174 | :100AD000F100CAC0882319F0823009F0E4C090E028 175 | :100AE0008F719070009721F0029709F0DDC00CC063 176 | :100AF00080912902813009F0D7C01092240233304E 177 | :100B000069F5809324022AC080912902882331F557 178 | :100B100020912B02277009F4C7C02093E90080912F 179 | :100B2000EB0080FFC1C0333021F48091EB00806284 180 | :100B300013C08091EB0080618093EB0081E090E036 181 | :100B400002C0880F991F2A95E2F78093EA0010925D 182 | :100B5000EA008091EB0088608093EB001092E9003E 183 | :100B60008091E800877F83C0882309F09CC01091A2 184 | :100B700029028091E800877F8093E800E8DC04C0C8 185 | :100B80008EB3882309F490C08091E80080FFF8CFED 186 | :100B9000812F8F7711F492E001C093E09EBB8068B3 187 | :100BA0008093E30081C08058823008F07CC080913F 188 | :100BB000290290912A0223E08C3D920799F55FB7B4 189 | :100BC000F894DE0115964EE020E030E061E2E42F7B 190 | :100BD000F0E060935700849120FF03C082958F70EE 191 | :100BE0004F5F982F9F70892F805D8A3308F0895F4F 192 | :100BF0008C9311961C9211972F5F3F4F12962431C0 193 | :100C0000310529F75FBF8AE28B8383E08C83809173 194 | :100C1000E800877F8093E800CE0103966AE270E0E7 195 | :100C2000E4DC11C060912B02AE014F5F5F4F2CDC02 196 | :100C3000BC010097C9F18091E800877F8093E800AC 197 | :100C400089819A812BDD8091E8008B778093E80081 198 | :100C50002BC0803841F58091E800877F8093E800C1 199 | :100C6000809125028093F1008091E8008E77809337 200 | :100C7000E8006DDC19C08823B1F49091290292300C 201 | :100C800098F48091E800877F8093E8009093250294 202 | :100C90005EDC80912502882311F483E001C084E0AA 203 | :100CA0008EBB2DDB01C028DB8091E80083FF0AC0EA 204 | :100CB0008091EB0080628093EB008091E800877F59 205 | :100CC0008093E800AC960FB6F894DEBF0FBECDBFA0 206 | :100CD000CF91DF911F91089508951F938EB38823BC 207 | :100CE00061F01091E9001092E9008091E80083FF23 208 | :100CF00001C098DE17701093E9001F9108950895C0 209 | :100D0000FC018EB3843021F587859089A189B28951 210 | :100D10000097A105B105E1F085818093E9008091FC 211 | :100D2000E80082FF15C08091F200882319F42FEFAC 212 | :100D30003FEF04C08091F100282F30E08091F20055 213 | :100D4000882341F48091E8008B778093E80002C00B 214 | :100D50002FEF3FEFC9010895FC018EB3843011F5E8 215 | :100D600087859089A189B2890097A105B105D1F045 216 | :100D700081818093E9008091F2008823A9F090910D 217 | :100D8000E8008091E8008E778093E80095FD0CC024 218 | :100D9000FDDB982F882349F48091E8008E778093BB 219 | :100DA000E80003C092E001C090E0892F0895FC01A3 220 | :100DB0008EB3843051F487859089A189B2890097D8 221 | :100DC000A105B10511F0CF01C7CF08951F93FC0114 222 | :100DD000162F8EB38430D9F487859089A189B28982 223 | :100DE0000097A105B10599F081818093E900809178 224 | :100DF000E80085FD08C08091E8008E778093E800C8 225 | :100E0000C5DB882329F41093F10080E001C082E063 226 | :100E10001F9108950F931F93CF93DF93EC010D96CD 227 | :100E2000FC0189E0DF011D928A95E9F72A813B8167 228 | :100E300009818C81882311F410E001C014E0C901FC 229 | :100E400051DB182B1260802F61E8412F59DB88237A 230 | :100E500029F12E813F810D818885882311F410E0CE 231 | :100E600001C014E0C9013EDB182B1260802F60E83E 232 | :100E7000412F46DB882391F02A853B8509858C85A7 233 | :100E8000882311F410E001C014E0C9012BDB182BFA 234 | :100E90001260802F61EC412F33DB01C080E0DF91D5 235 | :100EA000CF911F910F910895CF93DF93EC01809123 236 | :100EB000E80083FF60C0888190E020912B02309190 237 | :100EC0002C022817390709F056C080912802813278 238 | :100ED00061F0823220F4803209F04DC019C08232B4 239 | :100EE00069F1833209F047C038C080912702813A06 240 | :100EF00009F041C08091E800877F8093E800CE012F 241 | :100F00000F9667E070E071DB8091E8008B7713C08B 242 | :100F100080912702813279F58091E800877F809364 243 | :100F2000E800CE010F9667E070E013DCCE013ED9F9 244 | :100F30008091E8008E778093E8001DC080912702A1 245 | :100F40008132C9F48091E800877F8093E800809126 246 | :100F500029028D87CE01C8D90DC080912702813228 247 | :100F600051F48091E800877F8093E800CE01609182 248 | :100F70002902C5DEECDADF91CF910895A1E21A2EA5 249 | :100F8000AA1BBB1BFD010DC0AA1FBB1FEE1FFF1F2D 250 | :100F9000A217B307E407F50720F0A21BB30BE40B7D 251 | :100FA000F50B661F771F881F991F1A9469F76095C4 252 | :100FB0007095809590959B01AC01BD01CF0108957E 253 | :040FC000F894FFCFD3 254 | :100FC400000340000004400000020800000000008C 255 | :060FD40000000000000017 256 | :00000001FF 257 | -------------------------------------------------------------------------------- /ArduinoPIUAux/ArduinoPIUAux.ino: -------------------------------------------------------------------------------- 1 | #define GETBIT(port,bit) ((unsigned char)(((unsigned char)(port)) & ((unsigned char)(0x01 << ((unsigned char)(bit)))))) 2 | #define SETBIT(port,bit) port |= (0x01 << (bit)) // RACERXL: Set Byte bit 3 | #define CLRBIT(port,bit) port &= ~(0x01 << (bit)) // RACERXL: Clr Byte bit 4 | 5 | static unsigned char Input[2]; // RACERXL: The actual 16 bits Input data 6 | static unsigned char Output[3]; // RACERXL: The actual 16 bits Output data 7 | 8 | void setup() { 9 | pinMode(A1, INPUT_PULLUP); 10 | pinMode(A2, INPUT_PULLUP); 11 | pinMode(A3, INPUT_PULLUP); 12 | pinMode(A4, INPUT_PULLUP); 13 | pinMode(A5, INPUT_PULLUP); 14 | pinMode(2, INPUT_PULLUP); 15 | pinMode(3, INPUT_PULLUP); 16 | pinMode(4, INPUT_PULLUP); 17 | pinMode(5, INPUT_PULLUP); 18 | pinMode(6, INPUT_PULLUP); 19 | pinMode(7, INPUT_PULLUP); 20 | pinMode(8, INPUT_PULLUP); 21 | pinMode(9, INPUT_PULLUP); 22 | pinMode(10, INPUT_PULLUP); 23 | pinMode(11, INPUT_PULLUP); 24 | pinMode(12, INPUT_PULLUP); 25 | pinMode(13, INPUT_PULLUP); 26 | 27 | Serial.begin(38400); 28 | Input[0]=0xFF; 29 | Input[1]=0xFF; 30 | } 31 | 32 | unsigned char inputn,tmp1; 33 | #define SET_THING if(tmp1) SETBIT(Input[inputn/8],inputn%8); else CLRBIT(Input[inputn/8],inputn%8); 34 | void loop() { 35 | POINT_RETURN: 36 | while (Serial.available() > 0) { 37 | byte inByte = Serial.read(); 38 | if(inByte == 0x56) 39 | { 40 | Serial.write(0xAE); 41 | Serial.flush(); 42 | for(int i = 0; i < 3; i++) 43 | { 44 | int count = 0; 45 | while (Serial.available() <= 0) 46 | { 47 | count++; 48 | if(count >= 10000) goto POINT_RETURN; 49 | } 50 | Output[i] = Serial.read(); 51 | } 52 | for(int i = 0; i < 2; i++) 53 | { 54 | Serial.write(Input[i]); 55 | Serial.flush(); 56 | //Serial.print(Input[1], BIN); 57 | //Serial.println(Input[0], BIN); 58 | } 59 | } 60 | } 61 | inputn = 4; tmp1 = digitalRead(2); SET_THING 62 | inputn = 3; tmp1 = digitalRead(3); SET_THING 63 | inputn = 2; tmp1 = digitalRead(4); SET_THING 64 | inputn = 1; tmp1 = digitalRead(5); SET_THING 65 | inputn = 0; tmp1 = digitalRead(6); SET_THING 66 | inputn = 12; tmp1 = digitalRead(7); SET_THING 67 | inputn = 11; tmp1 = digitalRead(8); SET_THING 68 | inputn = 10; tmp1 = digitalRead(9); SET_THING 69 | inputn = 9; tmp1 = digitalRead(10); SET_THING 70 | inputn = 8; tmp1 = digitalRead(11); SET_THING 71 | //inputn = 5; tmp1 = digitalRead(A1); SET_THING // CLEAR 72 | inputn = 6; tmp1 = digitalRead(12); SET_THING // SERVICE 73 | inputn = 8+5; tmp1 = digitalRead(13); SET_THING // TEST 74 | //inputn = 7; tmp1 = digitalRead(A4); SET_THING // COIN 1 ? 75 | //inputn = 8+7; tmp1 = digitalRead(A5)?0:1; SET_THING // COIN 2 ? 76 | } 77 | -------------------------------------------------------------------------------- /ArduinoPIUAux_Lights/ArduinoPIUAux_Lights.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ckdur/PIUIO_Arduino/8fe6a9e39834d287ef6faa94dc9868920603f086/ArduinoPIUAux_Lights/ArduinoPIUAux_Lights.fzz -------------------------------------------------------------------------------- /ArduinoPIUAux_Lights/ArduinoPIUAux_Lights.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Modified version of ArduinoPIUAux that adds in cab/pad lighting support 3 | * Configured to output lighting data to 3x 74xx595 shift registers hooked up to some MOSFETs to control lighting. You could use just 2 shift registers if you modified the code. 4 | * 5 | * You need to upload two sketches to your Arduino to turn it into a PIUIO 6 | * The main code (either this one or ArduinoPIUAux) is uploaded normally to the Arduino 7 | * The USB code is compiled manually and uploaded to the serial processor via the Uno's DFU mode 8 | * See readme.md for more information 9 | */ 10 | 11 | #define GETBIT(port,bit) ((unsigned char)(((unsigned char)(port)) & ((unsigned char)(0x01 << ((unsigned char)(bit)))))) 12 | #define SETBIT(port,bit) port |= (0x01 << (bit)) // RACERXL: Set Byte bit 13 | #define CLRBIT(port,bit) port &= ~(0x01 << (bit)) // RACERXL: Clr Byte bit 14 | 15 | static unsigned char Input[2]; // RACERXL: The actual 16 bits Input data 16 | static unsigned char Output[3]; // RACERXL: The actual 16 bits Output data 17 | 18 | #define pinPad0 5 //P1 DR 19 | #define pinPad1 3 //P1 DL 20 | #define pinPad2 4 //P1 C 21 | #define pinPad3 6 //P1 UR 22 | #define pinPad4 2 //P1 UL 23 | #define pinPad5 7 //P2 DR? 24 | #define pinPad6 8 //P2 DL? 25 | #define pinPad7 9 //P2 C 26 | #define pinPad8 10 //P2 UR? 27 | #define pinPad9 11 //P2 UL? 28 | 29 | #define pinClear A0 30 | #define pinService A2 31 | #define pinTest A1 32 | #define pinCoin 12 33 | 34 | #define pinLEDDat A3 //Pins for the shift registers for lighting 35 | #define pinLEDLat A4 36 | #define pinLEDClk A5 37 | 38 | bool enableManualLights = false; //Set to true to turn on panel lights when they're stepped on - disables the game controlling lighting 39 | 40 | byte cabLEDs = 255; 41 | byte padLEDsP1 = 0; 42 | byte padLEDsP2 = 0; 43 | 44 | void setup() { 45 | pinMode(pinClear, INPUT_PULLUP); //Clear 46 | pinMode(pinService, INPUT_PULLUP); //Service 47 | pinMode(pinTest, INPUT_PULLUP); //Test 48 | 49 | pinMode(pinPad0, INPUT);// Pad start 50 | pinMode(pinPad1, INPUT); 51 | pinMode(pinPad2, INPUT); 52 | pinMode(pinPad3, INPUT); 53 | pinMode(pinPad4, INPUT); 54 | pinMode(pinPad5, INPUT); 55 | pinMode(pinPad6, INPUT); 56 | pinMode(pinPad7, INPUT); 57 | pinMode(pinPad8, INPUT); 58 | pinMode(pinPad9, INPUT);// Pad end 59 | 60 | pinMode(pinCoin, INPUT_PULLUP);//Coin 61 | 62 | pinMode(pinLEDDat, OUTPUT); //Lighting shift register pins 63 | pinMode(pinLEDLat, OUTPUT); 64 | pinMode(pinLEDClk, OUTPUT); 65 | pinMode(13, OUTPUT);//Debug led 66 | 67 | Serial.begin(38400); 68 | Input[0]=0xFF; 69 | Input[1]=0xFF; 70 | 71 | cabLEDs = 255; padLEDsP1 = 0; padLEDsP2 = 0; //Write initial data to the shift registers for lighting 72 | writeLighting(); 73 | } 74 | 75 | unsigned char inputn,tmp1; 76 | #define SET_THING if(tmp1) SETBIT(Input[inputn/8],inputn%8); else CLRBIT(Input[inputn/8],inputn%8); 77 | void loop() { 78 | POINT_RETURN: 79 | while (Serial.available() > 0) { 80 | byte inByte = Serial.read(); 81 | if(inByte == 0x56) 82 | { 83 | Serial.write(0xAE); 84 | Serial.flush(); 85 | for(int i = 0; i < 3; i++) 86 | { 87 | int count = 0; 88 | while (Serial.available() <= 0) 89 | { 90 | count++; 91 | if(count >= 10000) goto POINT_RETURN; 92 | } 93 | Output[i] = Serial.read(); 94 | } 95 | for(int i = 0; i < 2; i++) 96 | { 97 | Serial.write(Input[i]); 98 | Serial.flush(); 99 | //Serial.print(Input[1], BIN); 100 | //Serial.println(Input[0], BIN); 101 | } 102 | } 103 | } 104 | 105 | if (!enableManualLights) { //Using game-controlled lighting, read lighting data and set lighting variables 106 | cabLEDs = 255; padLEDsP1 = 0; padLEDsP2 = 0; 107 | //padLEDsP1 = Output[0]; padLEDsP2 = Output[1]; cabLEDs = Output[2]; 108 | //Supposedly this is what the format is (from lowest to highest bit): 109 | //Source: https://github.com/racerxdl/piuio_clone/blob/master/docs/piuio.txt , modified with my own findings 110 | //Byte0: ZZABCDEx 111 | //Byte1: ZZABCDEI 112 | //Byte2: HGFxxxHN 113 | //A = UL, B = UR, C = C, D = DL, E = DR 114 | //N = Neon (in a byte not broken out?) 115 | //FG = Marquee L1/2 116 | //HI = Marquee R1/2 117 | 118 | if (bitRead(Output[0], 2)) { bitSet(padLEDsP1, 4); } //P1 Pad: UL 119 | if (bitRead(Output[0], 3)) { bitSet(padLEDsP1, 0); } //UR 120 | if (bitRead(Output[0], 4)) { bitSet(padLEDsP1, 2); } //C 121 | if (bitRead(Output[0], 5)) { bitSet(padLEDsP1, 3); } //DL 122 | if (bitRead(Output[0], 6)) { bitSet(padLEDsP1, 1); } //DR 123 | 124 | if (bitRead(Output[1], 2)) { bitSet(padLEDsP2, 4); } //P2 Pad: UL 125 | if (bitRead(Output[1], 3)) { bitSet(padLEDsP2, 0); } //UR 126 | if (bitRead(Output[1], 4)) { bitSet(padLEDsP2, 2); } //C 127 | if (bitRead(Output[1], 5)) { bitSet(padLEDsP2, 3); } //DL 128 | if (bitRead(Output[1], 6)) { bitSet(padLEDsP2, 1); } //DR 129 | 130 | if (bitRead(Output[2], 0)) { bitClear(cabLEDs, 1); } //Cab lights: Marquee R1. Inverted for use with the amp box 131 | if (bitRead(Output[2], 1)) { bitClear(cabLEDs, 3); } //Marquee R2 132 | if (bitRead(Output[1], 7)) { bitClear(cabLEDs, 2); } //Marquee L2 133 | if (bitRead(Output[2], 2)) { bitClear(cabLEDs, 4); } //Marquee L1 134 | if (bitRead(Output[2], 7)) { bitClear(cabLEDs, 5); } //Bass neon 135 | 136 | 137 | } 138 | 139 | if (enableManualLights) {cabLEDs = 255; padLEDsP1 = 0; padLEDsP2 = 0;} //Set initial lighting data if using manual lighting 140 | inputn = 4; tmp1 = digitalRead(pinPad0); if (enableManualLights && tmp1) { bitSet(padLEDsP1, 4); } SET_THING //P1 DR 141 | inputn = 3; tmp1 = digitalRead(pinPad1); if (enableManualLights && tmp1) { bitSet(padLEDsP1, 0); } SET_THING //P1 DL 142 | inputn = 2; tmp1 = digitalRead(pinPad2); if (enableManualLights && tmp1) { bitSet(padLEDsP1, 3); } SET_THING //P1 C 143 | inputn = 1; tmp1 = digitalRead(pinPad3); if (enableManualLights && tmp1) { bitSet(padLEDsP1, 1); } SET_THING //P1 UR 144 | inputn = 0; tmp1 = digitalRead(pinPad4); if (enableManualLights && tmp1) { bitSet(padLEDsP1, 2); } SET_THING //P1 UL 145 | inputn = 12; tmp1 = digitalRead(pinPad5); if (enableManualLights && tmp1) { bitSet(padLEDsP2, 4); } SET_THING //P2 146 | inputn = 11; tmp1 = digitalRead(pinPad6); if (enableManualLights && tmp1) { bitSet(padLEDsP2, 0); } SET_THING //P2 147 | inputn = 10; tmp1 = digitalRead(pinPad7); if (enableManualLights && tmp1) { bitSet(padLEDsP2, 3); } SET_THING //P2 C 148 | inputn = 9; tmp1 = digitalRead(pinPad8); if (enableManualLights && tmp1) { bitSet(padLEDsP2, 1); } SET_THING //P2 149 | inputn = 8; tmp1 = digitalRead(pinPad9); if (enableManualLights && tmp1) { bitSet(padLEDsP2, 2); } SET_THING //P2 150 | inputn = 5; tmp1 = digitalRead(pinClear); SET_THING // CLEAR? 151 | inputn = 6; tmp1 = digitalRead(pinService); SET_THING // SERVICE 152 | inputn = 8+5; tmp1 = digitalRead(pinTest); SET_THING // TEST 153 | inputn = 7; tmp1 = digitalRead(pinCoin); SET_THING // COIN 1 154 | //inputn = 8+7; tmp1 = digitalRead(A5)?0:1; SET_THING // COIN 2 ? 155 | 156 | 157 | writeLighting(); 158 | } 159 | 160 | //Writes lighting data to the 3 shift registers - Code can be modified to only use 2 161 | void writeLighting() { 162 | digitalWrite(pinLEDLat, LOW); //Set latch pin low and start shifting out the data 163 | shiftOut(pinLEDDat, pinLEDClk, LSBFIRST, padLEDsP2); 164 | shiftOut(pinLEDDat, pinLEDClk, LSBFIRST, cabLEDs); 165 | shiftOut(pinLEDDat, pinLEDClk, LSBFIRST, padLEDsP1); 166 | digitalWrite(pinLEDLat, HIGH); //Set latch pin high to make the shift registers output the new data 167 | } 168 | -------------------------------------------------------------------------------- /ArduinoPIUAux_Lights/ArduinoPIUAux_Lights.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ckdur/PIUIO_Arduino/8fe6a9e39834d287ef6faa94dc9868920603f086/ArduinoPIUAux_Lights/ArduinoPIUAux_Lights.png -------------------------------------------------------------------------------- /ArduinoPIUAux_Lights/wiring.md: -------------------------------------------------------------------------------- 1 | # Wiring 2 | 3 | A lot of what I've done is specific to my setup and was learned with *a lot of trial and error*. It's not perfect and you might need to do things differently, but this should at least give you a good start 4 | 5 | ## Panel sensors 6 | Sensors for each panel are wired up in parallel (so any activated sensor activates the entire panel). One end of the group is connected to +5V, the other to the Arduino and a pulldown resistor to ground. 7 | 8 | ## Cabinet buttons (test, service, etc) 9 | The cabinet buttons are directly connected to Arduino pins. On my cabinet, they're already wired up to ground on one side, so all you need to do are enable the Arduino's internal pullup resistors in the code and you'll be set. **Connect the button's ground (which was already wired up to the 12V power supply's ground in my cab) to the Arduino's ground to avoid issues.** 10 | 11 | ## Shift Registers 12 | My setup outputs lighting data to 3x 74HFC595 shift registers, but can be modified to only use 2. The shift register output pins are connected to the MOSFETs for panel lights. 13 | 14 | ## Panel lights 15 | Lighting for each panel is controlled by a MOSFET. I used the IRLB8721 but any other N-channel MOSFET should work. High-power loads may require a heatsink (The model above caps out at 2W without one, and my panel lights didn't draw that much power ). **Connect your 12V power supply's ground to the Arduino's ground to avoid issues.** 16 | 17 | ## Cabinet lights 18 | I interfaced with my Pump it Up SX cabinet's original, unmodified amp box to control cabinet lighting. Looking at the 7 pin connector that originally connected to a PIUIO with the tab on top, connect these pins to the 3rd shift register: 19 | | Green | Blue | Brown | Red | Orange | Yellow | Purple | 20 | |--|--|--|--|--|--|--| 21 | | Neon- | LeftCent- | RightCent- | Left- | Right- | FG (cabinet ground) | VCC | 22 | | 5 | 4 | 3 | 2 | 1 | | +5V | 23 | 24 | Each light is turned on by grounding its pin, so turning a shift register pin OFF turns the corresponding light ON. 25 | 26 | For other DIY cabinet lighting solutions, use the same circuit as the panel lights. 27 | -------------------------------------------------------------------------------- /CRC32.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static PROGMEM prog_uint32_t crc_table[16] = { 4 | 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 5 | 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 6 | 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 7 | 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c 8 | }; 9 | 10 | unsigned long crc_update(unsigned long crc, byte data) 11 | { 12 | byte tbl_idx; 13 | tbl_idx = crc ^ (data >> (0 * 4)); 14 | crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); 15 | tbl_idx = crc ^ (data >> (1 * 4)); 16 | crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); 17 | return crc; 18 | } 19 | 20 | unsigned long crc_string(char *s) 21 | { 22 | unsigned long crc = ~0L; 23 | while (*s) 24 | crc = crc_update(crc, *s++); 25 | crc = ~crc; 26 | return crc; 27 | } 28 | 29 | void setup() 30 | { 31 | Serial.println(crc_string("HELLO"), HEX); 32 | } 33 | 34 | void loop() 35 | { 36 | } 37 | -------------------------------------------------------------------------------- /Config/LUFAConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | LUFA Library 3 | Copyright (C) Dean Camera, 2014. 4 | 5 | dean [at] fourwalledcubicle [dot] com 6 | www.lufa-lib.org 7 | */ 8 | 9 | /* 10 | Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com) 11 | 12 | Permission to use, copy, modify, distribute, and sell this 13 | software and its documentation for any purpose is hereby granted 14 | without fee, provided that the above copyright notice appear in 15 | all copies and that both that the copyright notice and this 16 | permission notice and warranty disclaimer appear in supporting 17 | documentation, and that the name of the author not be used in 18 | advertising or publicity pertaining to distribution of the 19 | software without specific, written prior permission. 20 | 21 | The author disclaims all warranties with regard to this 22 | software, including all implied warranties of merchantability 23 | and fitness. In no event shall the author be liable for any 24 | special, indirect or consequential damages or any damages 25 | whatsoever resulting from loss of use, data or profits, whether 26 | in an action of contract, negligence or other tortious action, 27 | arising out of or in connection with the use or performance of 28 | this software. 29 | */ 30 | 31 | /** \file 32 | * \brief LUFA Library Configuration Header File 33 | * 34 | * This header file is used to configure LUFA's compile time options, 35 | * as an alternative to the compile time constants supplied through 36 | * a makefile. 37 | * 38 | * For information on what each token does, refer to the LUFA 39 | * manual section "Summary of Compile Tokens". 40 | */ 41 | 42 | #ifndef _LUFA_CONFIG_H_ 43 | #define _LUFA_CONFIG_H_ 44 | 45 | #if (ARCH == ARCH_AVR8) 46 | 47 | /* Non-USB Related Configuration Tokens: */ 48 | // #define DISABLE_TERMINAL_CODES 49 | 50 | /* USB Class Driver Related Tokens: */ 51 | // #define HID_HOST_BOOT_PROTOCOL_ONLY 52 | // #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} 53 | // #define HID_USAGE_STACK_DEPTH {Insert Value Here} 54 | // #define HID_MAX_COLLECTIONS {Insert Value Here} 55 | // #define HID_MAX_REPORTITEMS {Insert Value Here} 56 | // #define HID_MAX_REPORT_IDS {Insert Value Here} 57 | // #define NO_CLASS_DRIVER_AUTOFLUSH 58 | 59 | /* General USB Driver Related Tokens: */ 60 | // #define ORDERED_EP_CONFIG 61 | #define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL) 62 | #define USB_DEVICE_ONLY 63 | // #define USB_HOST_ONLY 64 | // #define USB_STREAM_TIMEOUT_MS {Insert Value Here} 65 | // #define NO_LIMITED_CONTROLLER_CONNECT 66 | // #define NO_SOF_EVENTS 67 | 68 | /* USB Device Mode Driver Related Tokens: */ 69 | // #define USE_RAM_DESCRIPTORS 70 | #define USE_FLASH_DESCRIPTORS 71 | // #define USE_EEPROM_DESCRIPTORS 72 | // #define NO_INTERNAL_SERIAL 73 | #define FIXED_CONTROL_ENDPOINT_SIZE 8 74 | // #define DEVICE_STATE_AS_GPIOR {Insert Value Here} 75 | #define FIXED_NUM_CONFIGURATIONS 1 76 | // #define CONTROL_ONLY_DEVICE 77 | // #define INTERRUPT_CONTROL_ENDPOINT 78 | // #define NO_DEVICE_REMOTE_WAKEUP 79 | // #define NO_DEVICE_SELF_POWER 80 | 81 | /* USB Host Mode Driver Related Tokens: */ 82 | // #define HOST_STATE_AS_GPIOR {Insert Value Here} 83 | // #define USB_HOST_TIMEOUT_MS {Insert Value Here} 84 | // #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here} 85 | // #define NO_AUTO_VBUS_MANAGEMENT 86 | // #define INVERTED_VBUS_ENABLE_LINE 87 | 88 | #elif (ARCH == ARCH_XMEGA) 89 | 90 | /* Non-USB Related Configuration Tokens: */ 91 | // #define DISABLE_TERMINAL_CODES 92 | 93 | /* USB Class Driver Related Tokens: */ 94 | // #define HID_HOST_BOOT_PROTOCOL_ONLY 95 | // #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} 96 | // #define HID_USAGE_STACK_DEPTH {Insert Value Here} 97 | // #define HID_MAX_COLLECTIONS {Insert Value Here} 98 | // #define HID_MAX_REPORTITEMS {Insert Value Here} 99 | // #define HID_MAX_REPORT_IDS {Insert Value Here} 100 | // #define NO_CLASS_DRIVER_AUTOFLUSH 101 | 102 | /* General USB Driver Related Tokens: */ 103 | #define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_RC32MCLKSRC | USB_OPT_BUSEVENT_PRIHIGH) 104 | // #define USB_STREAM_TIMEOUT_MS {Insert Value Here} 105 | // #define NO_LIMITED_CONTROLLER_CONNECT 106 | // #define NO_SOF_EVENTS 107 | 108 | /* USB Device Mode Driver Related Tokens: */ 109 | // #define USE_RAM_DESCRIPTORS 110 | #define USE_FLASH_DESCRIPTORS 111 | // #define USE_EEPROM_DESCRIPTORS 112 | // #define NO_INTERNAL_SERIAL 113 | #define FIXED_CONTROL_ENDPOINT_SIZE 8 114 | // #define DEVICE_STATE_AS_GPIOR {Insert Value Here} 115 | #define FIXED_NUM_CONFIGURATIONS 1 116 | // #define CONTROL_ONLY_DEVICE 117 | #define MAX_ENDPOINT_INDEX 1 118 | // #define NO_DEVICE_REMOTE_WAKEUP 119 | // #define NO_DEVICE_SELF_POWER 120 | 121 | #else 122 | 123 | #error Unsupported architecture for this LUFA configuration file. 124 | 125 | #endif 126 | #endif 127 | -------------------------------------------------------------------------------- /Descriptors.c: -------------------------------------------------------------------------------- 1 | /***********************************************************/ 2 | /* ____ ___ _ _ ___ ___ ____ _ */ 3 | /* | _ \_ _| | | |_ _/ _ \ / ___| | ___ _ __ ___ */ 4 | /* | |_) | || | | || | | | | | | | |/ _ \| '_ \ / _ \ */ 5 | /* | __/| || |_| || | |_| | | |___| | (_) | | | | __/ */ 6 | /* |_| |___|\___/|___\___/ \____|_|\___/|_| |_|\___| */ 7 | /* */ 8 | /* By: Lucas Teske (USB-ON-AT90USBXXX BY CKDUR) */ 9 | /***********************************************************/ 10 | /* Basicly this is an PIUIO Clone with an ATMEGA8U2 and */ 11 | /* serial from ATMEGA328 interfaced on ARDUINO UNO */ 12 | /***********************************************************/ 13 | /* This is the USB Configuration part */ 14 | /***********************************************************/ 15 | /* License is WHAT? */ 16 | /* Please consult https://github.com/racerxdl/piuio_clone */ 17 | /***********************************************************/ 18 | 19 | /** \file 20 | * 21 | * USB Device Descriptors, for library use when in USB device mode. Descriptors are special 22 | * computer-readable structures which the host requests upon device enumeration, to determine 23 | * the device's capabilities and functions. 24 | */ 25 | 26 | #include "Descriptors.h" 27 | 28 | /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall 29 | * device characteristics, including the supported USB version, control endpoint size and the 30 | * number of device configurations. The descriptor is read out by the USB host when the enumeration 31 | * process begins. 32 | */ 33 | const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = 34 | { 35 | // CKDUR: All "Device Description" is here 36 | .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, 37 | 38 | .USBSpecification = VERSION_BCD(1,0,0), 39 | .Class = 0xFF, // RACERXL: 0xFF is a vendor-specifc class. Thats what we want 40 | .SubClass = 0x00, 41 | .Protocol = 0x00, 42 | 43 | .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, // CKDUR: Was FIXED_CONTROL_ENDPOINT_SIZE = 8 44 | 45 | .VendorID = 0x0547, // PIUIO Vendor ID. Cypress 0x547 46 | .ProductID = 0x1002, // PIUIO Product ID. FX-USB 0x1002 47 | .ReleaseNumber = VERSION_BCD(1,0,0), // 0.0.1 :( 48 | 49 | .ManufacturerStrIndex = STRING_ID_Manufacturer, 50 | .ProductStrIndex = STRING_ID_Product, 51 | .SerialNumStrIndex = NO_DESCRIPTOR, 52 | 53 | .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS 54 | }; 55 | 56 | /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage 57 | * of the device in one of its supported configurations, including information about any device interfaces 58 | * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting 59 | * a configuration so that the host may correctly communicate with the USB device. 60 | */ 61 | // RACERXL: 62 | /* --------------------------- Functional Range ---------------------------- */ 63 | const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = 64 | { 65 | .Config = 66 | { 67 | .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, 68 | 69 | .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), 70 | .TotalInterfaces = 1, 71 | 72 | .ConfigurationNumber = 1, 73 | .ConfigurationStrIndex = NO_DESCRIPTOR, 74 | 75 | // RACERXL: PIUIO does have own power supply. But I dont like that lol, so mine is just USB powered. 76 | .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), 77 | 78 | // RACERXL: This is the value in mA, it will be divided by two (100 mean 50mA). Its just an info for PC 79 | .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) 80 | }, 81 | 82 | .HID_Interface = 83 | { 84 | .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, 85 | 86 | .InterfaceNumber = INTERFACE_ID_PIUIO, 87 | .AlternateSetting = 0x00, 88 | 89 | // RACERXL: We dont need any additional entry points, so this will be 0 CKDUR:1? 90 | .TotalEndpoints = 0, 91 | 92 | // CKDUR: The interface didn't have nothing 93 | .Class = 0x00, 94 | .SubClass = 0x00, 95 | .Protocol = 0x00, 96 | 97 | .InterfaceStrIndex = NO_DESCRIPTOR 98 | }, 99 | 100 | // CKDUR: We don't need HID! God! D: 101 | }; 102 | 103 | /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests 104 | * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate 105 | * via the language ID table available at USB.org what languages the device supports for its string descriptors. 106 | */ 107 | const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG); 108 | 109 | /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable 110 | * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device 111 | * Descriptor. 112 | */ 113 | const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(L"CKDUR"); // CKDUR: By me 114 | 115 | /** Product descriptor string. This is a Unicode string containing the product's details in human readable form, 116 | * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device 117 | * Descriptor. 118 | */ 119 | const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"PIUIO"); // CKDUR: Remember maybe we can name it FX-USB 120 | 121 | /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" 122 | * documentation) by the application code so that the address and size of a requested descriptor can be given 123 | * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function 124 | * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the 125 | * USB host. 126 | */ 127 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, 128 | const uint16_t wIndex, 129 | const void** const DescriptorAddress) 130 | { 131 | const uint8_t DescriptorType = (wValue >> 8); 132 | const uint8_t DescriptorNumber = (wValue & 0xFF); 133 | 134 | const void* Address = NULL; 135 | uint16_t Size = NO_DESCRIPTOR; 136 | 137 | switch (DescriptorType) 138 | { 139 | case DTYPE_Device: 140 | Address = &DeviceDescriptor; 141 | Size = sizeof(USB_Descriptor_Device_t); 142 | break; 143 | case DTYPE_Configuration: 144 | Address = &ConfigurationDescriptor; 145 | Size = sizeof(USB_Descriptor_Configuration_t); 146 | break; 147 | case DTYPE_String: 148 | switch (DescriptorNumber) 149 | { 150 | case STRING_ID_Language: 151 | Address = &LanguageString; 152 | Size = pgm_read_byte(&LanguageString.Header.Size); 153 | break; 154 | case STRING_ID_Manufacturer: 155 | Address = &ManufacturerString; 156 | Size = pgm_read_byte(&ManufacturerString.Header.Size); 157 | break; 158 | case STRING_ID_Product: 159 | Address = &ProductString; 160 | Size = pgm_read_byte(&ProductString.Header.Size); 161 | break; 162 | } 163 | 164 | break; 165 | } 166 | 167 | *DescriptorAddress = Address; 168 | return Size; 169 | } 170 | 171 | -------------------------------------------------------------------------------- /Descriptors.h: -------------------------------------------------------------------------------- 1 | /***********************************************************/ 2 | /* ____ ___ _ _ ___ ___ ____ _ */ 3 | /* | _ \_ _| | | |_ _/ _ \ / ___| | ___ _ __ ___ */ 4 | /* | |_) | || | | || | | | | | | | |/ _ \| '_ \ / _ \ */ 5 | /* | __/| || |_| || | |_| | | |___| | (_) | | | | __/ */ 6 | /* |_| |___|\___/|___\___/ \____|_|\___/|_| |_|\___| */ 7 | /* */ 8 | /* By: Lucas Teske (USB-ON-AT90USBXXX BY CKDUR) */ 9 | /***********************************************************/ 10 | /* Basicly this is an PIUIO Clone with an ATMEGA8U2 and */ 11 | /* serial from ATMEGA328 interfaced on ARDUINO UNO */ 12 | /***********************************************************/ 13 | /* This is the USB Configuration part (HEADER) */ 14 | /***********************************************************/ 15 | /* License is WHAT? */ 16 | /* Please consult https://github.com/racerxdl/piuio_clone */ 17 | /***********************************************************/ 18 | 19 | /** \file 20 | * 21 | * Header file for Descriptors.c. 22 | */ 23 | 24 | #ifndef _DESCRIPTORS_H_ 25 | #define _DESCRIPTORS_H_a 26 | 27 | #define USE_STATIC_OPTIONS USB_DEVICE_OPT_LOWSPEED 28 | #include 29 | 30 | #include 31 | 32 | /* Type Defines: */ 33 | /** Type define for the device configuration descriptor structure. This must be defined in the 34 | * application code, as the configuration descriptor contains several sub-descriptors which 35 | * vary between devices, and which describe the device's usage to the host. 36 | */ 37 | typedef struct 38 | { 39 | USB_Descriptor_Configuration_Header_t Config; 40 | 41 | // Joystick HID Interface 42 | USB_Descriptor_Interface_t HID_Interface; 43 | 44 | // CKDUR: We don't need HID! God! D: 45 | // RACERXL: We dont need any additional entry points, so this will be 0 46 | // CKDUR: But we need still one 47 | } USB_Descriptor_Configuration_t; 48 | 49 | /** Enum for the device interface descriptor IDs within the device. Each interface descriptor 50 | * should have a unique ID index associated with it, which can be used to refer to the 51 | * interface from other descriptors. 52 | */ 53 | enum InterfaceDescriptors_t 54 | { 55 | INTERFACE_ID_PIUIO = 0, /**< PIUIO interface desciptor ID */ 56 | }; 57 | 58 | /** Enum for the device string descriptor IDs within the device. Each string descriptor should 59 | * have a unique ID index associated with it, which can be used to refer to the string from 60 | * other descriptors. 61 | */ 62 | enum StringDescriptors_t 63 | { 64 | STRING_ID_Language = 0, /**< Supported Languages string descriptor ID (must be zero) */ 65 | STRING_ID_Manufacturer = 1, /**< Manufacturer string ID */ 66 | STRING_ID_Product = 2, /**< Product string ID */ 67 | }; 68 | 69 | /* Function Prototypes: */ 70 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, 71 | const uint16_t wIndex, 72 | const void** const DescriptorAddress) 73 | ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); 74 | 75 | #endif 76 | 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ckristian Duran 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PIUIO.c: -------------------------------------------------------------------------------- 1 | /***********************************************************/ 2 | /* ____ ___ _ _ ___ ___ ____ _ */ 3 | /* | _ \_ _| | | |_ _/ _ \ / ___| | ___ _ __ ___ */ 4 | /* | |_) | || | | || | | | | | | | |/ _ \| '_ \ / _ \ */ 5 | /* | __/| || |_| || | |_| | | |___| | (_) | | | | __/ */ 6 | /* |_| |___|\___/|___\___/ \____|_|\___/|_| |_|\___| */ 7 | /* */ 8 | /* By: Lucas Teske (USB-ON-AT90USBXXX BY CKDUR) */ 9 | /***********************************************************/ 10 | /* Basicly this is an PIUIO Clone with an ATMEGA8U2 and */ 11 | /* serial from ATMEGA328 interfaced on ARDUINO UNO */ 12 | /***********************************************************/ 13 | /* This is main code from PIUIO Clone */ 14 | /***********************************************************/ 15 | /* License is WHAT? */ 16 | /* Please consult https://github.com/racerxdl/piuio_clone */ 17 | /***********************************************************/ 18 | 19 | #include "PIUIO.h" 20 | 21 | #define PIUIO_CTL_REQ 0xAE 22 | #define RXLED 4 23 | #define TXLED 5 24 | 25 | // RACERXL: Some Vars to help 26 | #define GETBIT(port,bit) ((unsigned char)(((unsigned char)(port)) & ((unsigned char)(0x01 << ((unsigned char)(bit)))))) 27 | #define SETBIT(port,bit) port |= (0x01 << (bit)) // RACERXL: Set Byte bit 28 | #define CLRBIT(port,bit) port &= ~(0x01 << (bit)) // RACERXL: Clr Byte bit 29 | 30 | static unsigned char Input[2]; // RACERXL: 31 | static unsigned char Output[3]; // RACERXL: 32 | static unsigned char LampData[8]; // RACERXL: The LampData buffer received 33 | static unsigned char InputData[8]; // RACERXL: The InputData buffer to send 34 | static unsigned char i, tmp1; 35 | 36 | // This turns on one of the LEDs hooked up to the chip 37 | void LEDon(char ledNumber){ 38 | DDRD |= 1 << ledNumber; 39 | PORTD &= ~(1 << ledNumber); 40 | } 41 | 42 | // And this turns it off 43 | void LEDoff(char ledNumber){ 44 | DDRD &= ~(1 << ledNumber); 45 | PORTD |= 1 << ledNumber; 46 | } 47 | 48 | /** Configures the board hardware and chip peripherals for the demo's functionality. */ 49 | void SetupHardware(void) 50 | { 51 | #if (ARCH == ARCH_AVR8) 52 | /* Disable watchdog if enabled by bootloader/fuses */ 53 | wdt_reset(); 54 | MCUSR &= ~(1 << WDRF); 55 | wdt_disable(); 56 | 57 | /* Disable clock division */ 58 | clock_prescale_set(clock_div_1); 59 | 60 | // Start up the USART for serial communications 61 | // 25 corresponds to 38400 baud - see datasheet for more values 62 | //USART_Init(25);// 103 corresponds to 9600, 8 corresponds to 115200 baud, 3 for 250000 63 | Serial_Init(38400, false); 64 | 65 | #elif (ARCH == ARCH_XMEGA) 66 | /* Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it */ 67 | XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU); 68 | XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL); 69 | 70 | /* Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference */ 71 | XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ); 72 | XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); 73 | 74 | PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; 75 | #endif 76 | 77 | /* Hardware Initialization */ 78 | USB_Init(); 79 | } 80 | 81 | /** Event handler for the library USB Connection event. */ 82 | void EVENT_USB_Device_Connect(void) 83 | { 84 | // CKDUR: EMPTY 85 | } 86 | 87 | /** Event handler for the library USB Disconnection event. */ 88 | void EVENT_USB_Device_Disconnect(void) 89 | { 90 | // CKDUR: EMPTY 91 | } 92 | 93 | /** Event handler for the library USB Configuration Changed event. */ 94 | void EVENT_USB_Device_ConfigurationChanged(void) 95 | { 96 | bool ConfigSuccess = true; 97 | // CKDUR: RACERXL didn't enable SOFs 98 | USB_Device_EnableSOFEvents(); 99 | } 100 | 101 | int nControl = 0; 102 | 103 | /** Event handler for the library USB Control Request reception event. */ 104 | void EVENT_USB_Device_ControlRequest(void) 105 | { 106 | if (!(Endpoint_IsSETUPReceived())) 107 | return; 108 | // CKDUR: Here comes the magic 109 | // TODO: all 110 | if(USB_ControlRequest.bRequest == 0xAE) { // Access Game IO 111 | nControl++; 112 | if(!(USB_ControlRequest.bmRequestType & 0x80)) { 113 | 114 | Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); 115 | while (!(Endpoint_IsINReady())); 116 | 117 | // CKDUR: Read the lamp values 118 | Endpoint_ClearSETUP(); 119 | Endpoint_Read_Control_Stream_LE(LampData, 8); 120 | Endpoint_ClearIN(); 121 | 122 | /* mark the whole request as successful: */ 123 | //Endpoint_ClearStatusStage(); 124 | //LEDoff(RXLED); 125 | } // Reading input data 126 | else 127 | { 128 | //LEDon(TXLED); 129 | 130 | Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); 131 | 132 | // CKDUR: Set the switch state 133 | Endpoint_ClearSETUP(); 134 | Endpoint_Write_Control_Stream_LE(InputData, 8); 135 | Endpoint_ClearOUT(); 136 | 137 | /* mark the whole request as successful: */ 138 | //Endpoint_ClearStatusStage(); 139 | //LEDoff(TXLED); 140 | } 141 | } 142 | } 143 | 144 | /** Event handler for the USB device Start Of Frame event. */ 145 | // CKDUR: RACERXL didn't enable SOFs 146 | void EVENT_USB_Device_StartOfFrame(void) 147 | { 148 | } 149 | 150 | /** Main program entry point. This routine contains the overall program flow, including initial 151 | * setup of all components and the main program loop. 152 | */ 153 | int main(void) 154 | { 155 | nControl = 0; 156 | SetupHardware(); 157 | 158 | GlobalInterruptEnable(); 159 | 160 | for(i=0;i<8;i++){ 161 | InputData[i] = 0xFF; 162 | LampData[i] = 0x0; 163 | 164 | } 165 | 166 | for (;;) 167 | { 168 | RESTART: 169 | USB_USBTask(); 170 | 171 | if(nControl > 1000) LEDon(RXLED); 172 | if(nControl > 2000) {LEDoff(RXLED); nControl = 0;} 173 | 174 | Output[0] = LampData[0]; // The AM use unsigned short for those. 175 | Output[1] = LampData[2]; // So we just skip one byte 176 | Output[2] = LampData[3]; // CKDUR: But we can't skip 3rd 177 | tmp1 = GETBIT(LampData[1],2); // CKDUR: Also, we can't skip NEON data from 1st 178 | if(tmp1 > 0) {SETBIT(Output[2],7);} else {CLRBIT(Output[2],7);}; 179 | 180 | char tmp; 181 | int count = 0; 182 | unsigned char m[2]; 183 | Serial_SendByte(0x56); 184 | while(!Serial_IsCharReceived()) 185 | { 186 | count++; 187 | if(count >= 10000) goto RESTART; 188 | } 189 | while(Serial_IsCharReceived()) 190 | { 191 | tmp = Serial_ReceiveByte(); 192 | if(tmp == 0xAE) 193 | { 194 | // CKDUR: Write Lamp Buffer 195 | for(i = 0; i < 3; i++) 196 | { 197 | Serial_SendByte(Output[i]); 198 | } 199 | 200 | for(i = 0; i < 2; i++) 201 | { 202 | 203 | while(!Serial_IsCharReceived()) 204 | { 205 | count++; 206 | if(count >= 10000) goto RESTART; 207 | } 208 | m[i] = Serial_ReceiveByte(); 209 | } 210 | } 211 | } 212 | 213 | Input[0] = m[0]; 214 | Input[1] = m[1]; 215 | 216 | if(m[0] != 0xFF || m[1] != 0xFF) LEDon(TXLED); else LEDoff(TXLED); 217 | 218 | // CKDUR: I'll put some bits from the input 219 | // and adapt it to current InputData 220 | // For coin & service 221 | 222 | /*for(i=0;i<8;i++){ 223 | InputData[i] = 0xFF; 224 | }*/ 225 | // Clear button 226 | tmp1 = GETBIT(Input[0],5); SETBIT(Input[0],5); 227 | if(!tmp1) {CLRBIT(InputData[1],7);} else {SETBIT(InputData[1],7);}; 228 | if(!tmp1) {CLRBIT(InputData[3],7);} else {SETBIT(InputData[3],7);}; 229 | // Service button 230 | tmp1 = GETBIT(Input[0],6); SETBIT(Input[0],6); 231 | if(!tmp1) {CLRBIT(InputData[1],6);} else {SETBIT(InputData[1],6);}; 232 | if(!tmp1) {CLRBIT(InputData[3],6);} else {SETBIT(InputData[3],6);}; 233 | // Test button 234 | tmp1 = GETBIT(Input[1],5); SETBIT(Input[1],5); 235 | if(!tmp1) {CLRBIT(InputData[1],1);} else {SETBIT(InputData[1],1);}; 236 | if(!tmp1) {CLRBIT(InputData[3],1);} else {SETBIT(InputData[3],1);}; 237 | // CoinX button 238 | tmp1 = GETBIT(Input[0],7); SETBIT(Input[0],7); 239 | if(!tmp1) {CLRBIT(InputData[1],2);} else {SETBIT(InputData[1],2);}; 240 | tmp1 = GETBIT(Input[1],7); SETBIT(Input[1],7); 241 | if(!tmp1) {CLRBIT(InputData[3],2);} else {SETBIT(InputData[3],2);}; 242 | InputData[0] = Input[0]; // Andamiro uses unsigned short here also 243 | InputData[2] = Input[1]; 244 | } 245 | 246 | return 0; 247 | } 248 | 249 | 250 | -------------------------------------------------------------------------------- /PIUIO.h: -------------------------------------------------------------------------------- 1 | /***********************************************************/ 2 | /* ____ ___ _ _ ___ ___ ____ _ */ 3 | /* | _ \_ _| | | |_ _/ _ \ / ___| | ___ _ __ ___ */ 4 | /* | |_) | || | | || | | | | | | | |/ _ \| '_ \ / _ \ */ 5 | /* | __/| || |_| || | |_| | | |___| | (_) | | | | __/ */ 6 | /* |_| |___|\___/|___\___/ \____|_|\___/|_| |_|\___| */ 7 | /* */ 8 | /* By: Lucas Teske (USB-ON-AT90USBXXX BY CKDUR) */ 9 | /***********************************************************/ 10 | /* Basicly this is an PIUIO Clone with an ATMEGA8U2 and */ 11 | /* serial from ATMEGA328 interfaced on ARDUINO UNO */ 12 | /***********************************************************/ 13 | /* This is main code from PIUIO Clone (HEADER) */ 14 | /***********************************************************/ 15 | /* License is WHAT? */ 16 | /* Please consult https://github.com/racerxdl/piuio_clone */ 17 | /***********************************************************/ 18 | 19 | /** \file 20 | * 21 | * Header file for PIUIO.c. 22 | */ 23 | 24 | #ifndef _PIUIO_H_ 25 | #define _PIUIO_H_ 26 | 27 | /* Includes: */ 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "Descriptors.h" 35 | 36 | //#include 37 | //#include 38 | //#include 39 | #include 40 | #include 41 | #include 42 | 43 | /* Function Prototypes: */ 44 | void SetupHardware(void); 45 | 46 | void EVENT_USB_Device_Connect(void); 47 | void EVENT_USB_Device_Disconnect(void); 48 | void EVENT_USB_Device_ConfigurationChanged(void); 49 | void EVENT_USB_Device_ControlRequest(void); 50 | void EVENT_USB_Device_StartOfFrame(void); 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /PIUIO.hex: -------------------------------------------------------------------------------- 1 | :100000005BC0000074C0000072C0000070C000003F 2 | :100010006EC000006CC000006AC0000068C0000034 3 | :1000200066C0000064C0000062C00000ABC30000F6 4 | :100030005EC000005CC000005AC0000058C0000054 5 | :1000400056C0000054C0000052C0000050C0000064 6 | :100050004EC000004CC000004AC0000048C0000074 7 | :1000600046C0000044C0000042C0000040C0000084 8 | :100070003EC000000C0350004900550049004F00ED 9 | :1000800000000C0343004B004400550052000000E8 10 | :100090000403090409021200010100C0320904002E 11 | :1000A00000000000000012010001FF0000084705E9 12 | :1000B000021000010102000111241FBECFEFD2E0A7 13 | :1000C000DEBFCDBF11E0A0E0B1E0EEEBFBE002C08F 14 | :1000D00005900D92A030B107D9F721E0A0E0B1E082 15 | :1000E00001C01D92A532B207E1F790D066C588CF56 16 | :1000F0004AB121E030E0B90102C0660F771F8A954E 17 | :10010000E2F7CB01462B4AB99BB1809589238BB985 18 | :1001100008954AB121E030E0B90102C0660F771FAF 19 | :100120008A95E2F7CB01962F909594239AB99BB1CB 20 | :10013000892B8BB90895A89584B7877F84BF0FB6A4 21 | :10014000F894A89580916000886180936000109277 22 | :1001500060000FBE80E890E00FB6F89480936100D5 23 | :10016000909361000FBE89E190E09093CD00809361 24 | :10017000CC0086E08093CA001092C80088E180938A 25 | :10018000C900539A5A9AEFC208950895E2EEF0E03A 26 | :1001900080818460808308958091E80083FF26C079 27 | :1001A00080911E018E3A11F580910001909101011C 28 | :1001B0000196909301018093000180911D0110929E 29 | :1001C000E90087FD14C08091E80080FFFCCF80919A 30 | :1001D000E800877F8093E80068E070E08BE091E0C2 31 | :1001E000A2D18091E8008E778093E80008958091F5 32 | :1001F000E800877F8093E80068E070E083E091E0AA 33 | :1002000036D18091E8008B77EFCF0895CF93DF93BD 34 | :1002100000D0CDB7DEB710920101109200018BDF44 35 | :100220007894E3E0F1E0ABE0B1E089E09FEF81504A 36 | :1002300009F089C088E08093020106E5A3D480918B 37 | :10024000000190910101893E934014F084E050DF59 38 | :100250008091000190910101813D974034F084E04C 39 | :1002600058DF109201011092000180910B018093E0 40 | :10027000130180910D018093140180910E019091E2 41 | :100280000C0192FF63C08068809315018091C800C3 42 | :1002900085FFFCCF0093CE0090E080E02091C80065 43 | :1002A00027FF56C02091C80027FD59C0198110931F 44 | :1002B0001601FA80F09217011F3F21F48FEFF81614 45 | :1002C00009F48FC085E014DF90910401809106014C 46 | :1002D00015FD8AC09F77909304018F778093060164 47 | :1002E000909104018091060116FD83C09F7B90933D 48 | :1002F00004018F7B80930601909104018091060197 49 | :10030000F5FC7CC09D7F909304018D7F8093060156 50 | :10031000212F206E209316018091040117FD73C0D8 51 | :100320008B7F809304019F2D906A90931701809199 52 | :100330000601F7FC6AC08B7F8093060120930301BE 53 | :10034000909305017BCF91931D9271CF8F779CCFB6 54 | :100350000196803127E2920709F0A0CF6FCF20915C 55 | :10036000C80027FF9FCF2091CE002E3A09F09ACFE8 56 | :1003700010920201E0910201E33038F01092020184 57 | :10038000209102012230B8F08DCFF0E0ED5EFE4FFB 58 | :1003900020813091C80035FFFCCF2093CE00209102 59 | :1003A00002012F5F20930201E5CF0196803137E2F1 60 | :1003B00093070CF043CF3091C80037FFF6CF309150 61 | :1003C000C8004FEF5FEF37FD4091CE00E1E0F0E075 62 | :1003D000EC0FFD1FE20FF11D40832F5F2093020100 63 | :1003E000CFCF85E096DE70CF90689093040180684F 64 | :1003F00075CF90649093040180647CCF9260909359 65 | :100400000401826083CF84608CCF846095CF292FD4 66 | :1004100033272230310571F02330310581F021304E 67 | :100420003105A1F482E190E026EA30E0FA0131835F 68 | :100430002083089582E190E024E930E0F7CF992706 69 | :100440008130910571F038F0029771F090E080E012 70 | :1004500030E020E0EBCFE0E9F0E0849190E09F0114 71 | :10046000E5CFE2E8F0E0F9CFE4E7F0E0F6CFFC0119 72 | :10047000809123019091240186179707A0F06115C0 73 | :10048000710529F49091E8009E779093E80090E040 74 | :100490006115710551F4911108C08091E80082FF47 75 | :1004A00032C080E00895BC01F2CF80911C01882306 76 | :1004B000B1F18530B1F18091E80083FD2EC08091CB 77 | :1004C000E80082FDEACF8091E80080FFE1CF209133 78 | :1004D000F20030E06115710519F02830310558F04F 79 | :1004E00091E02830310509F090E02091E8002E7766 80 | :1004F0002093E800CDCF81918093F1006150710984 81 | :100500002F5F3F4FE7CF80911C01882341F085305A 82 | :1005100041F08091E80083FFC0CF81E0089582E040 83 | :10052000089583E00895FC016115710529F4909107 84 | :10053000E8009B779093E8006115710531F4809194 85 | :10054000E80080FF1BC080E0089580911C01882393 86 | :10055000F9F08530C9F08091E80083FD17C08091E3 87 | :10056000E80082FFE9CF8091F200882301F38091B7 88 | :10057000F100819361507109B1F7D9CF80911C01CD 89 | :10058000882331F08530D9F683E0089581E008951D 90 | :1005900082E00895FC018091230190912401861747 91 | :1005A0009707A0F06115710529F48091E8008E7716 92 | :1005B0008093E80090E06115710551F4911108C035 93 | :1005C0008091E80082FF33C080E00895BC01F2CF43 94 | :1005D00080911C018823B9F18530B9F18091E80040 95 | :1005E00083FD2FC08091E80082FDEACF8091E80072 96 | :1005F00080FFE1CF2091F20030E06115710519F024 97 | :100600002830310558F091E02830310509F090E0AC 98 | :100610008091E8008E778093E800CDCF849180931D 99 | :10062000F1003196615071092F5F3F4FE6CF809105 100 | :100630001C01882341F0853041F08091E80083FF60 101 | :10064000BFCF81E0089582E0089583E00895982F58 102 | :10065000953028F08F708093E90081E008959093A1 103 | :10066000E900242F762F50E0981731F07091EC00BC 104 | :100670002091ED005091F00021FD02C09F5FE8CF76 105 | :100680003091EB003E7F3093EB003091ED003D7FE9 106 | :100690003093ED003091EB0031603093EB007093BC 107 | :1006A000EC002093ED005093F0002091EE0027FD28 108 | :1006B000E5CF80E0089580911D0187FF13C08091F0 109 | :1006C000E80082FF06C08091E8008B778093E80005 110 | :1006D00004C080911C018111F2CF089580911C010A 111 | :1006E0008823D9F38091E80080FFF8CF8091E8005B 112 | :1006F0008E77ECCF41D043D08091D8008F77809314 113 | :10070000D8008091D80080688093D8008091D8006C 114 | :100710008F7D8093D80084E089BD86E089BD09B4CF 115 | :1007200000FEFDCF10921C011092180110921A01C8 116 | :100730001092190142E060E080E089DF8091E100E1 117 | :100740008E7F8093E1008091E20081608093E200DF 118 | :100750008091E20088608093E2008091E0008E7FCB 119 | :100760008093E0000895E3E6F0E080818E7F80834F 120 | :1007700081E080931B01BECF1092E2000895109299 121 | :10078000E10008951F920F920FB60F9211242F933C 122 | :100790003F934F935F936F937F938F939F93AF9309 123 | :1007A000BF93EF93FF938091E10082FF0AC0809195 124 | :1007B000E20082FF06C08091E1008B7F8093E10020 125 | :1007C00024DD8091E10080FF17C08091E20080FF6E 126 | :1007D00013C08091E2008E7F8093E2008091E2005E 127 | :1007E00080618093E2008091D80080628093D8007D 128 | :1007F00019BC10921C01C9DC8091E10084FF27C064 129 | :100800008091E20084FF23C084E089BD86E089BD39 130 | :1008100009B400FEFDCF8091D8008F7D8093D80071 131 | :100820008091E1008F7E8093E1008091E2008F7ED5 132 | :100830008093E2008091E20081608093E2008091E9 133 | :1008400018018823D9F184E080931C019DDC8091FC 134 | :10085000E10083FF22C08091E20083FF1EC08091EF 135 | :10086000E100877F8093E10082E080931C01109279 136 | :1008700018018091E1008E7F8093E1008091E20079 137 | :100880008E7F8093E2008091E20080618093E2009D 138 | :1008900042E060E080E0DBDE74D1FF91EF91BF9138 139 | :1008A000AF919F918F917F916F915F914F913F9108 140 | :1008B0002F910F900FBE0F901F9018958091E3001D 141 | :1008C00087FD02C081E0C0CF83E0BECF1F93CF93EE 142 | :1008D000DF93CDB7DEB7AA970FB6F894DEBF0FBE91 143 | :1008E000CDBFEDE1F1E08091F100819321E0E532AF 144 | :1008F000F207C9F751DC8091E80083FF10C08091B6 145 | :100900001D0190911E01953009F4D8C000F5913079 146 | :1009100009F48BC008F461C0933009F486C080915B 147 | :10092000E80083FF0AC08091E800877F8093E80099 148 | :100930008091EB0080628093EB00AA960FB6F8944A 149 | :10094000DEBF0FBECDBFDF91CF911F9108959830CC 150 | :1009500009F4ECC0993009F4F6C0963001F78058DC 151 | :100960008230E8F680911F01909120018C3D23E0B8 152 | :10097000920709F0C6C083E08A838AE289834FB771 153 | :10098000F894DE01139620E03EE051E2E32FF0E020 154 | :1009900050935700E49120FF03C0E295EF703F5F52 155 | :1009A000EF708E2F90E0EA3008F4A9C0C7968D93BF 156 | :1009B0009D932F5F243151F74FBF8091E800877FCF 157 | :1009C0008093E8006AE270E0CE01019650DD8091EC 158 | :1009D000E8008B778093E800A2CF803899F08238C6 159 | :1009E00009F09DCF809121018F70853008F097CF5D 160 | :1009F0008093E9008091EB0085FB882780F91092B5 161 | :100A0000E90006C08091190190911A01911182604C 162 | :100A10009091E800977F9093E8008093F100109206 163 | :100A2000F1008091E8008E7732C0282F2D7F09F0E9 164 | :100A300076CF8823E9F0823009F071CF80911F01D1 165 | :100A4000811120C0809121018F702FEF280F243059 166 | :100A500008F065CF8093E9002091EB0020FF12C0E1 167 | :100A60009330C9F48091EB0080628093EB000AC060 168 | :100A700080911F01813009F052CF933009F080E05E 169 | :100A800080931A011092E9008091E800877F80939B 170 | :100A9000E80011DE44CF9091EB0090619093EB0061 171 | :100AA00021E030E001C0220F8A95EAF72093EA00A6 172 | :100AB0001092EA008091EB008860D7CF81112FCF90 173 | :100AC00010911F011F778091E3008078812B809324 174 | :100AD000E3008091E800877F8093E800ECDD80915F 175 | :100AE000E80080FFFCCF8091E30080688093E30002 176 | :100AF00083E0111101C082E080931C0110CFC096E9 177 | :100B000056CF6091210170912201AE014F5F5F4F7E 178 | :100B10007EDCBC01892B09F402CF9091E800977F1D 179 | :100B20009093E80089819A8135DD51CF803809F0B2 180 | :100B3000F6CE8091E800877F8093E80080911801CD 181 | :100B40008093F1006ECF8111EACE90911F01923017 182 | :100B500008F0E5CE8091E800877F8093E8009093CD 183 | :100B60001801A9DD80911801882329F084E0809381 184 | :100B70001C010CDBD4CE8091E30087FDF7CF81E030 185 | :100B8000F6CF0895CF9380911C01882391F0C091F6 186 | :100B9000E900CF708091EC0080FD0DC080E0C82B93 187 | :100BA0001092E9008091E80083FD90DECF70C09341 188 | :0E0BB000E900CF91089580E8F2CFF894FFCFCE 189 | :00000001FF 190 | -------------------------------------------------------------------------------- /PIUIO_leonardo.c: -------------------------------------------------------------------------------- 1 | /***********************************************************/ 2 | /* ____ ___ _ _ ___ ___ ____ _ */ 3 | /* | _ \_ _| | | |_ _/ _ \ / ___| | ___ _ __ ___ */ 4 | /* | |_) | || | | || | | | | | | | |/ _ \| '_ \ / _ \ */ 5 | /* | __/| || |_| || | |_| | | |___| | (_) | | | | __/ */ 6 | /* |_| |___|\___/|___\___/ \____|_|\___/|_| |_|\___| */ 7 | /* */ 8 | /* By: USB-ON-ATMEGAU4 BY CKDUR */ 9 | /***********************************************************/ 10 | /* Basicly this is an PIUIO Clone with an ATMEGA32U2 */ 11 | /* interfaced on ARDUINO Leonardo */ 12 | /***********************************************************/ 13 | /* This is main code from PIUIO Clone */ 14 | /***********************************************************/ 15 | /* License is MIT */ 16 | /* Please consult https://github.com/ckdur/PIUIO_arduino */ 17 | /***********************************************************/ 18 | 19 | #include "PIUIO.h" 20 | 21 | #define PIUIO_CTL_REQ 0xAE 22 | 23 | #define GETBIT(port,bit) ((unsigned char)(((unsigned char)(port)) & ((unsigned char)(0x01 << ((unsigned char)(bit)))))) 24 | #define SETBIT(port,bit) port |= (0x01 << (bit)) 25 | #define CLRBIT(port,bit) port &= ~(0x01 << (bit)) 26 | 27 | static unsigned char LampData[8]; // The LampData buffer received 28 | static unsigned char InputData[8]; // The InputData buffer to send 29 | 30 | // This turns on one of the LEDs hooked up to the chip 31 | // NOTE: use the enum for the port 32 | enum IO_PORTS { 33 | IO_PORT_B, 34 | IO_PORT_C, 35 | IO_PORT_D, 36 | IO_PORT_E, 37 | IO_PORT_F 38 | }; 39 | 40 | // Sets or unsets the output mode 41 | void MODEon(char ledNumber, int port) { 42 | if(port == IO_PORT_B) { 43 | DDRB |= 1 << ledNumber; 44 | } 45 | if(port == IO_PORT_C) { 46 | DDRC |= 1 << ledNumber; 47 | } 48 | if(port == IO_PORT_D) { 49 | DDRD |= 1 << ledNumber; 50 | } 51 | if(port == IO_PORT_E) { 52 | DDRE |= 1 << ledNumber; 53 | } 54 | if(port == IO_PORT_F) { 55 | DDRF |= 1 << ledNumber; 56 | } 57 | } 58 | 59 | void MODEoff(char ledNumber, int port) { 60 | if(port == IO_PORT_B) { 61 | DDRB &= ~(1 << ledNumber); 62 | } 63 | if(port == IO_PORT_C) { 64 | DDRC &= ~(1 << ledNumber); 65 | } 66 | if(port == IO_PORT_D) { 67 | DDRD &= ~(1 << ledNumber); 68 | } 69 | if(port == IO_PORT_E) { 70 | DDRE &= ~(1 << ledNumber); 71 | } 72 | if(port == IO_PORT_F) { 73 | DDRF &= ~(1 << ledNumber); 74 | } 75 | } 76 | 77 | // Sets or unsets the output (remember to set the mode first) 78 | void LEDon(char ledNumber, int port){ 79 | if(port == IO_PORT_B) { 80 | PORTB |= 1 << ledNumber; 81 | } 82 | if(port == IO_PORT_C) { 83 | PORTC |= 1 << ledNumber; 84 | } 85 | if(port == IO_PORT_D) { 86 | PORTD |= 1 << ledNumber; 87 | } 88 | if(port == IO_PORT_E) { 89 | PORTE |= 1 << ledNumber; 90 | } 91 | if(port == IO_PORT_F) { 92 | PORTF |= 1 << ledNumber; 93 | } 94 | } 95 | 96 | // And this turns it off 97 | void LEDoff(char ledNumber, int port){ 98 | if(port == IO_PORT_B) { 99 | PORTB &= ~(1 << ledNumber); 100 | } 101 | if(port == IO_PORT_C) { 102 | PORTC &= ~(1 << ledNumber); 103 | } 104 | if(port == IO_PORT_D) { 105 | PORTD &= ~(1 << ledNumber); 106 | } 107 | if(port == IO_PORT_E) { 108 | PORTE &= ~(1 << ledNumber); 109 | } 110 | if(port == IO_PORT_F) { 111 | PORTF &= ~(1 << ledNumber); 112 | } 113 | } 114 | 115 | int READfrom(char ledNumber, int port){ 116 | int st = 0; 117 | if(port == IO_PORT_B) { 118 | st = (PINB & (1 << ledNumber)) ? 1 : 0; 119 | } 120 | if(port == IO_PORT_C) { 121 | st = (PINC & (1 << ledNumber)) ? 1 : 0; 122 | } 123 | if(port == IO_PORT_D) { 124 | st = (PIND & (1 << ledNumber)) ? 1 : 0; 125 | } 126 | if(port == IO_PORT_E) { 127 | st = (PINE & (1 << ledNumber)) ? 1 : 0; 128 | } 129 | if(port == IO_PORT_F) { 130 | st = (PINF & (1 << ledNumber)) ? 1 : 0; 131 | } 132 | return st; 133 | } 134 | 135 | // Configurations of all 136 | #define RXLED 0, IO_PORT_B 137 | #define TXLED 5, IO_PORT_D 138 | 139 | // As for the rest... 140 | // Check https://www.arduino.cc/en/uploads/Main/arduino-leonardo-schematic_3b.pdf for details 141 | #define DIO0 PD2, IO_PORT_D 142 | #define DIO1 PD3, IO_PORT_D 143 | #define DIO2 PD1, IO_PORT_D 144 | #define DIO3 PD0, IO_PORT_D 145 | #define DIO4 PD4, IO_PORT_D 146 | #define DIO5 PC6, IO_PORT_C 147 | #define DIO6 PD7, IO_PORT_D 148 | #define DIO7 PE6, IO_PORT_E 149 | #define DIO8 PB4, IO_PORT_B 150 | #define DIO9 PB5, IO_PORT_B 151 | #define DIO10 PB6, IO_PORT_B 152 | #define DIO11 PB7, IO_PORT_B 153 | #define DIO12 PD6, IO_PORT_D 154 | #define DIO13 PC7, IO_PORT_C 155 | #define DIOA0 PF7, IO_PORT_F 156 | #define DIOA1 PF6, IO_PORT_F 157 | #define DIOA2 PF5, IO_PORT_F 158 | #define DIOA3 PF4, IO_PORT_F 159 | #define DIOA4 PF1, IO_PORT_F 160 | #define DIOA5 PF0, IO_PORT_F 161 | 162 | // Now, assigning the IO according to ColombiaStep's stuff 163 | 164 | #define P1_PAD 165 | #define P2_PAD 166 | //#define DO_LED 167 | 168 | #if defined(P1_PAD) && defined(P2_PAD) && defined(DO_LED) 169 | #error "This implementation does not support P1 & P2 and Lights. You need to disable one of them" 170 | #endif 171 | 172 | #ifdef P1_PAD 173 | #define KEY_Q DIO8 174 | #define KEY_E DIO4 175 | #define KEY_S DIO10 176 | #define KEY_Z DIO6 177 | #define KEY_C DIO2 178 | 179 | #ifdef DO_LED 180 | #define LED_Q DIO7 181 | #define LED_E DIO3 182 | #define LED_S DIO9 183 | #define LED_Z DIO5 184 | #define LED_C DIO1 185 | #endif // DO_LED 186 | #endif 187 | 188 | #ifdef P2_PAD 189 | #ifndef P1_PAD 190 | #define KEY_7 DIO8 191 | #define KEY_9 DIO4 192 | #define KEY_5 DIO10 193 | #define KEY_1 DIO6 194 | #define KEY_3 DIO2 195 | #else 196 | #define KEY_7 DIO7 197 | #define KEY_9 DIO3 198 | #define KEY_5 DIO9 199 | #define KEY_1 DIO5 200 | #define KEY_3 DIO1 201 | #endif 202 | 203 | #ifdef DO_LED 204 | #define LED_7 DIO7 205 | #define LED_9 DIO3 206 | #define LED_5 DIO9 207 | #define LED_1 DIO5 208 | #define LED_3 DIO1 209 | #endif // DO_LED 210 | #endif 211 | 212 | #define KEY_COIN1 DIO13 213 | //#define KEY_COIN2 DIO13 214 | //#define KEY_CLEAR DIO13 215 | #define KEY_SERVICE DIO12 216 | #define KEY_TEST DIO11 217 | 218 | #define LED_NEON DIOA0 219 | #define LED_UL DIOA1 220 | #define LED_DL DIOA2 221 | #define LED_UR DIOA3 222 | #define LED_DL DIOA4 223 | 224 | /** Configures the board hardware and chip peripherals for the demo's functionality. */ 225 | void SetupHardware(void) 226 | { 227 | #if (ARCH == ARCH_AVR8) 228 | /* Disable watchdog if enabled by bootloader/fuses */ 229 | wdt_reset(); 230 | MCUSR &= ~(1 << WDRF); 231 | wdt_disable(); 232 | 233 | /* Disable clock division */ 234 | clock_prescale_set(clock_div_1); 235 | 236 | // Start up the USART for serial communications 237 | // 25 corresponds to 38400 baud - see datasheet for more values 238 | //USART_Init(25);// 103 corresponds to 9600, 8 corresponds to 115200 baud, 3 for 250000 239 | //Serial_Init(38400, false); 240 | 241 | #elif (ARCH == ARCH_XMEGA) 242 | /* Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it */ 243 | XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU); 244 | XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL); 245 | 246 | /* Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference */ 247 | XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ); 248 | XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); 249 | 250 | PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; 251 | #endif 252 | 253 | /* Hardware Initialization */ 254 | USB_Init(); 255 | } 256 | 257 | /** Event handler for the library USB Connection event. */ 258 | void EVENT_USB_Device_Connect(void) 259 | { 260 | // CKDUR: EMPTY 261 | } 262 | 263 | /** Event handler for the library USB Disconnection event. */ 264 | void EVENT_USB_Device_Disconnect(void) 265 | { 266 | // CKDUR: EMPTY 267 | } 268 | 269 | /** Event handler for the library USB Configuration Changed event. */ 270 | void EVENT_USB_Device_ConfigurationChanged(void) 271 | { 272 | bool ConfigSuccess = true; 273 | // CKDUR: RACERXL didn't enable SOFs 274 | USB_Device_EnableSOFEvents(); 275 | } 276 | 277 | int nControl = 0; 278 | 279 | /** Event handler for the library USB Control Request reception event. */ 280 | void EVENT_USB_Device_ControlRequest(void) 281 | { 282 | if (!(Endpoint_IsSETUPReceived())) 283 | return; 284 | // CKDUR: Here comes the magic 285 | if(USB_ControlRequest.bRequest == 0xAE) { // Access Game IO 286 | nControl++; 287 | if(!(USB_ControlRequest.bmRequestType & 0x80)) { 288 | 289 | Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); 290 | while (!(Endpoint_IsINReady())); 291 | 292 | // CKDUR: Read the lamp values 293 | Endpoint_ClearSETUP(); 294 | Endpoint_Read_Control_Stream_LE(LampData, 8); 295 | Endpoint_ClearIN(); 296 | 297 | /* mark the whole request as successful: */ 298 | //Endpoint_ClearStatusStage(); 299 | //LEDoff(RXLED); 300 | } // Reading input data 301 | else 302 | { 303 | //LEDon(TXLED); 304 | 305 | Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); 306 | 307 | // CKDUR: Set the switch state 308 | Endpoint_ClearSETUP(); 309 | Endpoint_Write_Control_Stream_LE(InputData, 8); 310 | Endpoint_ClearOUT(); 311 | 312 | /* mark the whole request as successful: */ 313 | //Endpoint_ClearStatusStage(); 314 | //LEDoff(TXLED); 315 | } 316 | } 317 | } 318 | 319 | /** Event handler for the USB device Start Of Frame event. */ 320 | // CKDUR: RACERXL didn't enable SOFs 321 | void EVENT_USB_Device_StartOfFrame(void) 322 | { 323 | } 324 | 325 | /** Main program entry point. This routine contains the overall program flow, including initial 326 | * setup of all components and the main program loop. 327 | */ 328 | int main(void) 329 | { 330 | nControl = 0; 331 | SetupHardware(); 332 | 333 | GlobalInterruptEnable(); 334 | 335 | int i; 336 | for(i=0;i<8;i++){ 337 | InputData[i] = 0xFF; 338 | LampData[i] = 0x0; 339 | 340 | } 341 | 342 | #ifdef KEY_Q 343 | MODEoff(KEY_Q); LEDon(KEY_Q); 344 | #endif 345 | #ifdef KEY_E 346 | MODEoff(KEY_E); LEDon(KEY_E); 347 | #endif 348 | #ifdef KEY_S 349 | MODEoff(KEY_S); LEDon(KEY_S); 350 | #endif 351 | #ifdef KEY_Z 352 | MODEoff(KEY_Z); LEDon(KEY_Z); 353 | #endif 354 | #ifdef KEY_C 355 | MODEoff(KEY_C); LEDon(KEY_C); 356 | #endif 357 | #ifdef KEY_7 358 | MODEoff(KEY_7); LEDon(KEY_7); 359 | #endif 360 | #ifdef KEY_9 361 | MODEoff(KEY_9); LEDon(KEY_9); 362 | #endif 363 | #ifdef KEY_5 364 | MODEoff(KEY_5); LEDon(KEY_5); 365 | #endif 366 | #ifdef KEY_1 367 | MODEoff(KEY_1); LEDon(KEY_1); 368 | #endif 369 | #ifdef KEY_3 370 | MODEoff(KEY_3); LEDon(KEY_3); 371 | #endif 372 | #ifdef KEY_CLEAR 373 | MODEoff(KEY_CLEAR); LEDon(KEY_CLEAR); 374 | #endif 375 | #ifdef KEY_SERVICE 376 | MODEoff(KEY_SERVICE); LEDon(KEY_SERVICE); 377 | #endif 378 | #ifdef KEY_TEST 379 | MODEoff(KEY_TEST); LEDon(KEY_TEST); 380 | #endif 381 | #ifdef KEY_COIN1 382 | MODEoff(KEY_COIN1); LEDon(KEY_COIN1); 383 | #endif 384 | #ifdef KEY_COIN2 385 | MODEoff(KEY_COIN2); LEDon(KEY_COIN2); 386 | #endif 387 | 388 | #ifdef LED_Q 389 | MODEon(LED_Q); 390 | #endif 391 | #ifdef LED_E 392 | MODEon(LED_E); 393 | #endif 394 | #ifdef LED_S 395 | MODEon(LED_S); 396 | #endif 397 | #ifdef LED_Z 398 | MODEon(LED_Z); 399 | #endif 400 | #ifdef LED_C 401 | MODEon(LED_C); 402 | #endif 403 | #ifdef LED_7 404 | MODEon(LED_7); 405 | #endif 406 | #ifdef LED_9 407 | MODEon(LED_9); 408 | #endif 409 | #ifdef LED_5 410 | MODEon(LED_5); 411 | #endif 412 | #ifdef LED_1 413 | MODEon(LED_1); 414 | #endif 415 | #ifdef LED_3 416 | MODEon(LED_3); 417 | #endif 418 | #ifdef LED_NEON 419 | MODEon(LED_NEON); 420 | #endif 421 | #ifdef LED_UL 422 | MODEon(LED_UL); 423 | #endif 424 | #ifdef LED_DL 425 | MODEon(LED_DL); 426 | #endif 427 | #ifdef LED_UR 428 | MODEon(LED_UR); 429 | #endif 430 | #ifdef LED_DR 431 | MODEon(LED_DR); 432 | #endif 433 | 434 | for (;;) 435 | { 436 | RESTART: 437 | USB_USBTask(); 438 | 439 | if(nControl > 1000) LEDon(RXLED); 440 | if(nControl > 2000) {LEDoff(RXLED); nControl = 0;} 441 | 442 | // Modify Input[x] and use Output[x] to IO the LEDs 443 | #ifdef KEY_Q 444 | if(READfrom(KEY_Q)) {SETBIT(InputData[0],0);} else {CLRBIT(InputData[0],0);} 445 | #endif 446 | #ifdef KEY_E 447 | if(READfrom(KEY_E)) {SETBIT(InputData[0],1);} else {CLRBIT(InputData[0],1);} 448 | #endif 449 | #ifdef KEY_S 450 | if(READfrom(KEY_S)) {SETBIT(InputData[0],2);} else {CLRBIT(InputData[0],2);} 451 | #endif 452 | #ifdef KEY_Z 453 | if(READfrom(KEY_Z)) {SETBIT(InputData[0],3);} else {CLRBIT(InputData[0],3);} 454 | #endif 455 | #ifdef KEY_C 456 | if(READfrom(KEY_C)) {SETBIT(InputData[0],4);} else {CLRBIT(InputData[0],4);} 457 | #endif 458 | #ifdef KEY_7 459 | if(READfrom(KEY_7)) {SETBIT(InputData[2],0);} else {CLRBIT(InputData[2],0);} 460 | #endif 461 | #ifdef KEY_9 462 | if(READfrom(KEY_9)) {SETBIT(InputData[2],1);} else {CLRBIT(InputData[2],1);} 463 | #endif 464 | #ifdef KEY_5 465 | if(READfrom(KEY_5)) {SETBIT(InputData[2],2);} else {CLRBIT(InputData[2],2);} 466 | #endif 467 | #ifdef KEY_1 468 | if(READfrom(KEY_1)) {SETBIT(InputData[2],3);} else {CLRBIT(InputData[2],3);} 469 | #endif 470 | #ifdef KEY_3 471 | if(READfrom(KEY_3)) {SETBIT(InputData[2],4);} else {CLRBIT(InputData[2],4);} 472 | #endif 473 | #ifdef KEY_CLEAR 474 | if(READfrom(KEY_CLEAR)) {SETBIT(InputData[1],7);} else {CLRBIT(InputData[1],7);} 475 | if(READfrom(KEY_CLEAR)) {SETBIT(InputData[3],7);} else {CLRBIT(InputData[3],7);} 476 | #endif 477 | #ifdef KEY_SERVICE 478 | if(READfrom(KEY_SERVICE)) {SETBIT(InputData[1],6);} else {CLRBIT(InputData[1],6);} 479 | if(READfrom(KEY_SERVICE)) {SETBIT(InputData[3],6);} else {CLRBIT(InputData[3],6);} 480 | #endif 481 | #ifdef KEY_TEST 482 | if(READfrom(KEY_TEST)) {SETBIT(InputData[1],1);} else {CLRBIT(InputData[1],1);} 483 | if(READfrom(KEY_TEST)) {SETBIT(InputData[3],1);} else {CLRBIT(InputData[3],1);} 484 | #endif 485 | #ifdef KEY_COIN1 486 | if(READfrom(KEY_COIN1)) {SETBIT(InputData[1],2);} else {CLRBIT(InputData[1],2);} 487 | #endif 488 | #ifdef KEY_COIN2 489 | if(READfrom(KEY_COIN2)) {SETBIT(InputData[3],2);} else {CLRBIT(InputData[3],2);} 490 | #endif 491 | 492 | #ifdef LED_Q 493 | if(GETBIT(LampData[0],2)) {LEDon(LED_Q);} else {LEDoff(LED_Q);} 494 | #endif 495 | #ifdef LED_E 496 | if(GETBIT(LampData[0],3)) {LEDon(LED_E);} else {LEDoff(LED_E);} 497 | #endif 498 | #ifdef LED_S 499 | if(GETBIT(LampData[0],4)) {LEDon(LED_Q);} else {LEDoff(LED_Q);} 500 | #endif 501 | #ifdef LED_Z 502 | if(GETBIT(LampData[0],5)) {LEDon(LED_Z);} else {LEDoff(LED_Z);} 503 | #endif 504 | #ifdef LED_C 505 | if(GETBIT(LampData[0],6)) {LEDon(LED_C);} else {LEDoff(LED_C);} 506 | #endif 507 | #ifdef LED_7 508 | if(GETBIT(LampData[2],2)) {LEDon(LED_7);} else {LEDoff(LED_7);} 509 | #endif 510 | #ifdef LED_9 511 | if(GETBIT(LampData[2],3)) {LEDon(LED_9);} else {LEDoff(LED_9);} 512 | #endif 513 | #ifdef LED_5 514 | if(GETBIT(LampData[2],4)) {LEDon(LED_5);} else {LEDoff(LED_5);} 515 | #endif 516 | #ifdef LED_1 517 | if(GETBIT(LampData[2],5)) {LEDon(LED_1);} else {LEDoff(LED_1);} 518 | #endif 519 | #ifdef LED_3 520 | if(GETBIT(LampData[2],6)) {LEDon(LED_3);} else {LEDoff(LED_3);} 521 | #endif 522 | #ifdef LED_NEON 523 | if(GETBIT(LampData[1],2)) {LEDon(LED_NEON);} else {LEDoff(LED_NEON);} 524 | #endif 525 | #ifdef LED_UL 526 | if(GETBIT(LampData[2],7)) {LEDon(LED_UL);} else {LEDoff(LED_UL);} 527 | #endif 528 | #ifdef LED_DL 529 | if(GETBIT(LampData[3],0)) {LEDon(LED_DL);} else {LEDoff(LED_DL);} 530 | #endif 531 | #ifdef LED_UR 532 | if(GETBIT(LampData[3],1)) {LEDon(LED_UR);} else {LEDoff(LED_UR);} 533 | #endif 534 | #ifdef LED_DR 535 | if(GETBIT(LampData[3],2)) {LEDon(LED_DR);} else {LEDoff(LED_DR);} 536 | #endif 537 | 538 | // Note: Logic is inverted in these leds 539 | if(InputData[0] != 0xFF || InputData[1] != 0xFF || InputData[2] != 0xFF || InputData[3] != 0xFF) LEDoff(TXLED); else LEDon(TXLED); 540 | } 541 | 542 | return 0; 543 | } 544 | 545 | 546 | -------------------------------------------------------------------------------- /PIUIO_leonardo.hex: -------------------------------------------------------------------------------- 1 | :1000000077C0000090C000008EC000008CC00000CF 2 | :100010008AC0000088C0000086C0000084C00000C4 3 | :1000200082C0000080C00000C9C300007CC0000086 4 | :100030007AC0000078C0000076C0000074C00000E4 5 | :1000400072C0000070C000006EC000006CC00000F4 6 | :100050006AC0000068C0000066C0000064C0000004 7 | :1000600062C0000060C000005EC000005CC0000014 8 | :100070005AC0000058C0000056C0000054C0000024 9 | :1000800052C0000050C000004EC000004CC0000034 10 | :100090004AC0000048C0000046C0000044C0000044 11 | :1000A00042C0000040C000003EC000000C035000F1 12 | :1000B0004900550049004F0000000C0343004B006D 13 | :1000C0004400550052000000040309040902120014 14 | :1000D000010100C03209040000000000000012010C 15 | :1000E0000001FF00000847050210000101020001A5 16 | :1000F00011241FBECFEFDAE0DEBFCDBF11E0A0E0DC 17 | :10010000B1E0ECE3FCE002C005900D92A030B10735 18 | :10011000D9F721E0A0E0B1E001C01D92AF31B207F4 19 | :10012000E1F75DD089C56CCFA89584B7877F84BF80 20 | :100130000FB6F894A8958091600088618093600064 21 | :10014000109260000FBE80E890E00FB6F8948093A4 22 | :100150006100909361000FBE14C308950895E2EE0C 23 | :10016000F0E080818460808308958091E80083FFBF 24 | :1001700026C0809118018E3A11F58091000190916E 25 | :100180000101019690930101809300018091170174 26 | :100190001092E90087FD14C08091E80080FFFCCF39 27 | :1001A0008091E800877F8093E80068E070E08AE053 28 | :1001B00091E0B9D18091E8008E778093E8000895AE 29 | :1001C0008091E800877F8093E80068E070E082E03B 30 | :1001D00091E04AD18091E8008B77EFCF089510929B 31 | :1001E000010110920001A0DF7894E2E0F1E0AAE0C2 32 | :1001F000B1E08FEF81931D9221E0EA30F207D1F751 33 | :1002000024982C9A54985C9A26982E9A57985F9A1C 34 | :100210005198599A6E98769A5098589A25982D9A8E 35 | :100220003E98469A53985B9A56985E9A27982F9ACA 36 | :100230003F98479A879A869A819A849AE2D48091C5 37 | :10024000000190910101893E93400CF0289A809121 38 | :10025000000190910101813D97402CF02898109267 39 | :10026000010110920001809102011C9BA5C08160D8 40 | :1002700080930201809102014C9BA0C08260809318 41 | :100280000201809102011E9B9BC084608093020149 42 | :1002900029B18091020130E0220F232F221F330B5E 43 | :1002A000232B09F48FC088608093020180910201A2 44 | :1002B000499B8AC080618093020180910401669B02 45 | :1002C00085C081608093040180910401489B80C0B7 46 | :1002D000826080930401809104011D9B7BC0846037 47 | :1002E0008093040180910401369B76C088608093DE 48 | :1002F0000401809104014B9B71C0806180930401D3 49 | :10030000809103014E9B6CC08064809303018091B7 50 | :1003100005014E9B67C080648093050123B18091E5 51 | :10032000030130E0220F232F221F330B232B09F46C 52 | :100330005BC082608093030123B18091050130E0AE 53 | :10034000220F232F221F330B232B09F44FC082606F 54 | :100350008093050126B18091030130E0220F232F05 55 | :10036000221F330B232B09F443C0846080930301C5 56 | :1003700080910B0182FF3EC08F9A80910C0187FF14 57 | :100380003BC08E9A80910D0180FF38C0899A81FF11 58 | :1003900037C08C9A809102018F3F61F480910301F4 59 | :1003A0008F3F41F4809104018F3F21F4809105013A 60 | :1003B0008F3F41F15D9842CF8E7F5ACF8D7F5FCFC7 61 | :1003C0008B7F64CF877F70CF8F7E75CF8E7F7ACF04 62 | :1003D0008D7F7FCF8B7F84CF877F89CF8F7E8ECF9E 63 | :1003E0008F7B93CF8F7B98CF8D7FA4CF8D7FB0CF26 64 | :1003F0008B7FBCCF8F98C1CF8E98C4CF8998C7CF41 65 | :100400008C98C8CF5D9A1ACF292F33272230310517 66 | :1004100071F02330310581F021303105A1F482E102 67 | :1004200090E02EED30E0FA0131832083089582E1DF 68 | :1004300090E02CEC30E0F7CF99278130910571F0F6 69 | :1004400038F0029771F090E080E030E020E0EBCFF0 70 | :10045000E8ECF0E0849190E09F01E5CFEAEBF0E07A 71 | :10046000F9CFECEAF0E0F6CFFC0180911D0190910C 72 | :100470001E0186179707A0F06115710529F4909168 73 | :10048000E8009E779093E80090E06115710551F4C3 74 | :10049000911108C08091E80082FF35C080E0089586 75 | :1004A000BC01F2CF809116018823C9F18530C9F1D2 76 | :1004B0008091E80083FD31C08091E80082FDEACFA1 77 | :1004C0008091E80080FFE1CF2091F3008091F2005D 78 | :1004D000322F282F6115710519F02830310558F099 79 | :1004E00091E02830310509F090E02091E8002E7766 80 | :1004F0002093E800CACF81918093F1006150710987 81 | :100500002F5F3F4FE7CF80911601882341F0853060 82 | :1005100041F08091E80083FFBDCF81E0089582E043 83 | :10052000089583E00895FC016115710529F4909107 84 | :10053000E8009B779093E8006115710531F4809194 85 | :10054000E80080FF1FC080E0089580911601882395 86 | :1005500019F18530E9F08091E80083FD1BC080919E 87 | :10056000E80082FFE9CF2091F3008091F200322F62 88 | :10057000282F232BE1F28091F100819361507109C2 89 | :1005800091F7D5CF80911601882331F08530B9F6E7 90 | :1005900083E0089581E0089582E00895FC01809150 91 | :1005A0001D0190911E0186179707A0F06115710536 92 | :1005B00029F48091E8008E778093E80090E061153F 93 | :1005C000710551F4911108C08091E80082FF36C096 94 | :1005D00080E00895BC01F2CF809116018823D1F10B 95 | :1005E0008530D1F18091E80083FD32C08091E80030 96 | :1005F00082FDEACF8091E80080FFE1CF2091F300F7 97 | :100600008091F200322F282F6115710519F02830E2 98 | :10061000310558F091E02830310509F090E08091E3 99 | :10062000E8008E778093E800CACF84918093F10030 100 | :100630003196615071092F5F3F4FE6CF80911601CF 101 | :10064000882341F0853041F08091E80083FFBCCFE2 102 | :1006500081E0089582E0089583E00895982F97300F 103 | :1006600028F08F708093E90081E008959093E9006D 104 | :10067000242F762F50E0981731F07091EC002091E4 105 | :10068000ED005091F00021FD02C09F5FE8CF309156 106 | :10069000EB003E7F3093EB003091ED003D7F3093D7 107 | :1006A000ED003091EB0031603093EB007093EC0083 108 | :1006B0002093ED005093F0002091EE0027FDE5CF50 109 | :1006C00080E008958091170187FF13C08091E800B2 110 | :1006D00082FF06C08091E8008B778093E80004C019 111 | :1006E000809116018111F2CF08958091160188231F 112 | :1006F000D9F38091E80080FFF8CF8091E8008E77F1 113 | :10070000ECCF0F931F93CF93DF934BD052D0C8ED14 114 | :10071000D0E088818F77888388818068888388810A 115 | :100720008F7D888319BC10921601109212011092CD 116 | :1007300014011092130100EE10E0F80180818B7F0C 117 | :10074000808388818160888342E060E080E086DF8A 118 | :10075000E1EEF0E080818E7F8083E2EEF0E0808148 119 | :1007600081608083808188608083F80180818E7FB2 120 | :100770008083888180618883DF91CF911F910F9161 121 | :100780000895E8EDF0E080818F7E8083E7EDF0E072 122 | :1007900080818160808384E082BF81E08093150145 123 | :1007A000B0CFE8EDF0E080818E7F80831092E20090 124 | :1007B00008951092DA001092E10008951F920F92AE 125 | :1007C0000FB60F9211242F933F934F935F936F9324 126 | :1007D0007F938F939F93AF93BF93EF93FF938091FA 127 | :1007E000E10082FF0AC08091E20082FF06C0809192 128 | :1007F000E1008B7F8093E100F1DC8091DA0080FFE3 129 | :1008000018C08091D80080FF14C08091DA008E7FDC 130 | :100810008093DA008091D90080FF8AC080E189BD91 131 | :1008200082E189BD09B400FEFDCF81E0809316010D 132 | :1008300094DC8091E10080FF18C08091E20080FF8D 133 | :1008400014C08091E2008E7F8093E2008091E200EC 134 | :1008500080618093E2008091D80080628093D8000C 135 | :1008600019BC85E080931601CBD18091E10084FF13 136 | :1008700028C08091E20084FF24C080E189BD82E12C 137 | :1008800089BD09B400FEFDCF8091D8008F7D809393 138 | :10089000D8008091E1008F7E8093E1008091E2009A 139 | :1008A0008F7E8093E2008091E20081608093E2007D 140 | :1008B00080911201882309F440C084E080931601DE 141 | :1008C0009FD18091E10083FF22C08091E20083FFED 142 | :1008D0001EC08091E100877F8093E10082E08093D9 143 | :1008E0001601109212018091E1008E7F8093E10049 144 | :1008F0008091E2008E7F8093E2008091E20080612F 145 | :100900008093E20042E060E080E0A8DE79D1FF91D0 146 | :10091000EF91BF91AF919F918F917F916F915F9177 147 | :100920004F913F912F910F900FBE0F901F901895F0 148 | :1009300019BC1092160112DC7CCF8091E30087FD78 149 | :1009400002C081E0BBCF83E0B9CF1F93CF93DF9389 150 | :10095000CDB7DEB7AA970FB6F894DEBF0FBECDBFF6 151 | :10096000E7E1F1E08091F100819321E0EF31F207BE 152 | :10097000C9F7FBDB8091E80083FF10C0809117016D 153 | :1009800090911801953009F4D8C000F5913009F420 154 | :100990008BC008F461C0933009F486C08091E800F0 155 | :1009A00083FF0AC08091E800877F8093E8008091F0 156 | :1009B000EB0080628093EB00AA960FB6F894DEBF3E 157 | :1009C0000FBECDBFDF91CF911F910895983009F4EC 158 | :1009D000ECC0993009F4F6C0963001F780588230A7 159 | :1009E000E8F68091190190911A018C3D23E092075D 160 | :1009F00009F0C6C083E08A838AE289834FB7F894FE 161 | :100A0000DE01139620E03EE051E2E32FF0E0509348 162 | :100A10005700E49120FF03C0E295EF703F5FEF7055 163 | :100A20008E2F90E0EA3008F4A9C0C7968D939D936D 164 | :100A30002F5F243151F74FBF8091E800877F80936B 165 | :100A4000E8006AE270E0CE0101960EDD8091E800D8 166 | :100A50008B778093E800A2CF803899F0823809F034 167 | :100A60009DCF80911B018F70873008F097CF8093C6 168 | :100A7000E9008091EB0085FB882780F91092E9005E 169 | :100A800006C08091130190911401911182609091A0 170 | :100A9000E800977F9093E8008093F1001092F100B6 171 | :100AA0008091E8008E7732C0282F2D7F09F076CF15 172 | :100AB0008823E9F0823009F071CF8091190181110A 173 | :100AC00020C080911B018F702FEF280F263008F077 174 | :100AD00065CF8093E9002091EB0020FF12C0933096 175 | :100AE000C9F48091EB0080628093EB000AC0809192 176 | :100AF0001901813009F052CF933009F080E08093E2 177 | :100B000014011092E9008091E800877F8093E8004B 178 | :100B1000D9DD44CF9091EB0090619093EB0021E000 179 | :100B200030E001C0220F8A95EAF72093EA00109284 180 | :100B3000EA008091EB008860D7CF81112FCF109110 181 | :100B400019011F778091E3008078812B8093E30067 182 | :100B50008091E800877F8093E800B4DD8091E80011 183 | :100B600080FFFCCF8091E30080688093E30083E006 184 | :100B7000111101C082E08093160110CFC09656CFAC 185 | :100B800060911B0170911C01AE014F5F5F4F3CDC17 186 | :100B9000BC01892B09F402CF9091E800977F9093D4 187 | :100BA000E80089819A81FADC51CF803809F0F6CECD 188 | :100BB0008091E800877F8093E80080911201809304 189 | :100BC000F1006ECF8111EACE90911901923008F0B8 190 | :100BD000E5CE8091E800877F8093E8009093120132 191 | :100BE00071DD80911201882329F084E08093160141 192 | :100BF000B6DAD4CE8091E30087FDF7CF81E0F6CF5F 193 | :100C00000895CF9380911601882391F0C091E90057 194 | :100C1000CF708091EC0080FD0DC080E0C82B109259 195 | :100C2000E9008091E80083FD90DECF70C093E90079 196 | :0C0C3000CF91089580E8F2CFF894FFCF38 197 | :00000001FF 198 | -------------------------------------------------------------------------------- /TurnIntoAPIUIO.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | if not exist ATmega8u2Code/HexFiles/batchisp.exe ( 3 | echo. 4 | echo The program used to flash the memory couldn't be found... 5 | echo Did you move this .bat file? Or delete something in the ATmega8u2Code folder? 6 | echo Press any key to exit... 7 | goto EXIT 8 | ) 9 | echo. 10 | echo Abracadabra! 11 | cd ATmega8u2Code/HexFiles 12 | echo Attempting to re-flash for an Arduino Uno R1/R2 13 | @echo on 14 | batchisp -device at90usb82 -hardware usb -operation erase f memory flash blankcheck loadbuffer "PIUIO.hex" program verify start reset 1024 15 | @echo off 16 | if %errorlevel% NEQ 0 ( 17 | goto R3FLASH 18 | ) 19 | else ( 20 | goto SUCCESS 21 | ) 22 | 23 | :R3FLASH 24 | echo Trying to re-flash for an Arduino Uno R3... 25 | @echo on 26 | batchisp -device atmega16u2 -hardware usb -operation erase f memory flash blankcheck loadbuffer "PIUIO.hex" program verify start reset 1024 27 | @echo off 28 | if %errorlevel% NEQ 0 ( 29 | echo %errorlevel% 30 | echo The firmware was NOT loaded... 31 | echo. 32 | echo Did you install the Atmel FLIP program? - http://www.atmel.com/tools/FLIP.aspx - 33 | echo Is the Arduino plugged in? 34 | echo Is is it in 'Arduino UNO DFU' mode? 35 | echo Press any key to exit.. 36 | goto EXIT 37 | ) else ( 38 | goto SUCCESS 39 | ) 40 | 41 | :SUCCESS 42 | echo Now, you need to unplug the Arduino and plug it back in, 43 | echo but it will show up as a joystick! Press any key to exit.... 44 | goto EXIT 45 | 46 | 47 | :EXIT 48 | pause > nul 49 | -------------------------------------------------------------------------------- /TurnIntoAnArduino.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | if not exist ATmega8u2Code/HexFiles/batchisp.exe ( 3 | echo. 4 | echo The program used to flash the memory couldn't be found... 5 | echo Did you move this .bat file? Or delete something in the ATmega8u2Code folder? 6 | echo Press any key to exit... 7 | goto EXIT 8 | ) 9 | echo. 10 | echo Like magic. 11 | cd ATmega8u2Code/HexFiles 12 | echo Attempting to re-flash for an Arduino Uno R1/R2 13 | @echo on 14 | batchisp -device at90usb82 -hardware usb -operation erase f memory flash blankcheck loadbuffer "Arduino-usbserial-uno.hex" program verify start reset 0 15 | @echo off 16 | if %errorlevel% NEQ 0 ( 17 | goto R3FLASH 18 | ) 19 | else ( 20 | goto SUCCESS 21 | ) 22 | 23 | :R3FLASH 24 | echo Trying to re-flash for an Arduino Uno R3 25 | @echo on 26 | batchisp -device atmega16u2 -hardware usb -operation erase f memory flash blankcheck loadbuffer "Arduino-usbserial-uno.hex" program verify start reset 0 27 | @echo off 28 | if %errorlevel% NEQ 0 ( 29 | echo %errorlevel% 30 | echo The firmware was NOT loaded... 31 | echo. 32 | echo Did you install the Atmel FLIP program? - http://www.atmel.com/tools/FLIP.aspx - 33 | echo Is the Arduino plugged in? 34 | echo Is is it in 'Arduino UNO DFU' mode? 35 | echo Press any key to exit.. 36 | goto EXIT 37 | ) else ( 38 | goto SUCCESS 39 | ) 40 | 41 | :SUCCESS 42 | echo Now, you need to unplug the Arduino and plug it back in, 43 | echo and it'll show back up as an Arduino. Press any key to exit.... 44 | goto EXIT 45 | 46 | 47 | :EXIT 48 | pause > nul -------------------------------------------------------------------------------- /asf.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | Joystick HID device demo, implementing a basic USB joystick that can send movement information to the host. This demo uses the user-friendly USB Class Driver APIs to provide a simple, abstracted interface into the USB stack. 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | # 2 | # LUFA Library 3 | # Copyright (C) Dean Camera, 2014. 4 | # 5 | # dean [at] fourwalledcubicle [dot] com 6 | # www.lufa-lib.org 7 | # 8 | # -------------------------------------- 9 | # LUFA Project Makefile. 10 | # -------------------------------------- 11 | 12 | # Run "make help" for target help. 13 | # MCU = atmega16u2 14 | 15 | MCU ?= at90usb82 16 | ARCH = AVR8 17 | BOARD = USBKEY 18 | F_CPU = 16000000 19 | F_USB = $(F_CPU) 20 | OPTIMIZATION = s 21 | TARGET = PIUIO 22 | SRC = $(TARGET).c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS) 23 | LUFA_PATH = ./lufa/LUFA 24 | CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/ 25 | LD_FLAGS = 26 | 27 | LUFA_OPTS = -D USB_DEVICE_ONLY 28 | LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8 29 | LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 30 | LUFA_OPTS += -D USE_FLASH_DESCRIPTORS 31 | LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0 32 | LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_LOWSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" 33 | LUFA_OPTS += -D NO_DEVICE_SELF_POWER 34 | LUFA_OPTS += -D NO_DEVICE_REMOTE_WAKEUP 35 | LUFA_OPTS += -D NO_INTERNAL_SERIAL 36 | 37 | # Default target 38 | all: 39 | 40 | # Include LUFA build script makefiles 41 | include $(LUFA_PATH)/Build/lufa_core.mk 42 | include $(LUFA_PATH)/Build/lufa_sources.mk 43 | include $(LUFA_PATH)/Build/lufa_build.mk 44 | include $(LUFA_PATH)/Build/lufa_cppcheck.mk 45 | include $(LUFA_PATH)/Build/lufa_doxygen.mk 46 | include $(LUFA_PATH)/Build/lufa_dfu.mk 47 | include $(LUFA_PATH)/Build/lufa_hid.mk 48 | include $(LUFA_PATH)/Build/lufa_avrdude.mk 49 | include $(LUFA_PATH)/Build/lufa_atprogram.mk 50 | -------------------------------------------------------------------------------- /makefile.leonardo: -------------------------------------------------------------------------------- 1 | # 2 | # LUFA Library 3 | # Copyright (C) Dean Camera, 2014. 4 | # 5 | # dean [at] fourwalledcubicle [dot] com 6 | # www.lufa-lib.org 7 | # 8 | # -------------------------------------- 9 | # LUFA Project Makefile. 10 | # -------------------------------------- 11 | 12 | # Run "make help" for target help. 13 | 14 | MCU ?= atmega32u4 15 | ARCH = AVR8 16 | BOARD = LEONARDO 17 | F_CPU = 16000000 18 | F_USB = $(F_CPU) 19 | OPTIMIZATION = s 20 | TARGET = PIUIO_leonardo 21 | SRC = PIUIO_leonardo.c Descriptors.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS) 22 | LUFA_PATH = ./lufa/LUFA 23 | CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/ 24 | LD_FLAGS = 25 | 26 | LUFA_OPTS = -D USB_DEVICE_ONLY 27 | LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8 28 | LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 29 | LUFA_OPTS += -D USE_FLASH_DESCRIPTORS 30 | LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0 31 | LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_LOWSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" 32 | LUFA_OPTS += -D NO_DEVICE_SELF_POWER 33 | LUFA_OPTS += -D NO_DEVICE_REMOTE_WAKEUP 34 | LUFA_OPTS += -D NO_INTERNAL_SERIAL 35 | 36 | # Default target 37 | all: 38 | 39 | # Include LUFA build script makefiles 40 | include $(LUFA_PATH)/Build/lufa_core.mk 41 | include $(LUFA_PATH)/Build/lufa_sources.mk 42 | include $(LUFA_PATH)/Build/lufa_build.mk 43 | include $(LUFA_PATH)/Build/lufa_cppcheck.mk 44 | include $(LUFA_PATH)/Build/lufa_doxygen.mk 45 | include $(LUFA_PATH)/Build/lufa_dfu.mk 46 | include $(LUFA_PATH)/Build/lufa_hid.mk 47 | include $(LUFA_PATH)/Build/lufa_avrdude.mk 48 | include $(LUFA_PATH)/Build/lufa_atprogram.mk 49 | 50 | program: 51 | avrdude -v -c avr109 -p m32u4 -P /dev/ttyACM0 -U flash:w:PIUIO_leonardo.hex:i 52 | 53 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Arduino Uno PIUIO 2 | 3 | Emulates a Pump it Up IO board (a.k.a. MK6 PIUIO) using an Arduino Uno. 4 | Tested and working with both input and lighting with Pump it Up Prime 2015, Stepmania 5 on Linux with djpohly's input driver, and on Windows with IO2KEY. 5 | 6 | 7 | ## Install 8 | First: 9 | 1. Upload ArduinoPIUAux (or ArduinoPIUAux_Lights for lighting support) onto your Arduino Uno (as you would a regular Arduino sketch) 10 | 11 | In linux ([WSL works too if you're on Windows 8/10](https://www.microsoft.com/en-us/p/debian/9msvkqc78pk6?activetab=pivot:overviewtab)): 12 | 1. `sudo apt-get install build-essential git gcc-avr avr-libc` 13 | 2. `git clone https://github.com/48productions/PIUIO_Arduino` 14 | 3. cd to the cloned folder, delete the lufa folder 15 | 4. `git clone https://github.com/abcminiuser/lufa` 16 | 5. `make` 17 | 6. Move PIUIO.hex,elf,bin,eep,lss,map,sym into ATmega8u2Code/HexFiles 18 | 19 | Then reboot into windows... 20 | 1. Install FLIP https://www.microchip.com/developmenttools/ProductDetails/flip 21 | 2. Plug in the Arduino UNO 22 | 3. Note down the port you plugged it into in device manager, you will need it 23 | 3. Put the UNO into DFU mode - With the Uno oriented with the USB port to the left, briefly bridge the left two pins on the 2x3 header near the USB port. 24 | 4. Install the device by going into device manager, finding the port you noted down earlier, then selecting from a list of drivers, have disk, naviate to "Program Files (x86)/Atmel/Flip 3.4.7/usb/" and then double click the inf 25 | 5. After the drivers are set up correctly, run TurnIntoAPIUIO.bat. Congrats, your Arduino is now a PIUIO! 26 | 27 | Note that you can't upload new sketches to your Arduino when it's acting as a PIUIO. If you ever need to change your Arduino back into an Arduino to upload new code: 28 | 1. Navigate to C:\Program Files (x86)\Arduino\hardware\arduino\avr\firmwares\atmegaxxu2\arduino-usbserial 29 | 2. Copy Arduino-usbserial-uno.hex into HexFiles 30 | 3. Put your arduino into DFU mode and run the batch script. Once this above file is copied, you just need to put the arduino in DFU mode and run the appropriate batch file to change between Arduino/PIUIO modes. 31 | --------------------------------------------------------------------------------