Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor2 #3

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .assets/updater/README.txt

This file was deleted.

Binary file added .assets/updater/TUFUpdater.exe
Binary file not shown.
2 changes: 2 additions & 0 deletions .assets/updater/UpdateVSFighter.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
TUFUpdater.exe vsFIGHTER-Firmware_v2.0.0-beta1.hex
4 changes: 4 additions & 0 deletions .assets/updater/data/boards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Arduino Leonardo": "2341:0036",
"Adafruit ItsyBitsy 32u4": "239A:000E"
}
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions .assets/updater/update.bat

This file was deleted.

9 changes: 0 additions & 9 deletions .assets/updater/update.ps1

This file was deleted.

497 changes: 0 additions & 497 deletions .assets/updater/vsFIGHTER-Firmware.hex

This file was deleted.

541 changes: 541 additions & 0 deletions .assets/updater/vsFIGHTER-Firmware_v2.0.0-beta1.hex

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"configurations": [
{
"name": "Arduino",
"compilerPath": "C:\\Users\\jskuby\\AppData\\Local\\Arduino15\\packages\\Arduino-LUFA\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7\\bin\\avr-g++",
"compilerPath": "C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr\\bin\\avr-g++",
"compilerArgs": [
"-w",
"-std=gnu++11",
Expand All @@ -16,17 +16,18 @@
],
"intelliSenseMode": "gcc-x64",
"includePath": [
"C:\\Users\\jskuby\\AppData\\Local\\Arduino15\\packages\\Arduino-LUFA\\hardware\\avr\\0.93\\cores\\arduino",
"C:\\Users\\jskuby\\AppData\\Local\\Arduino15\\packages\\Arduino-LUFA\\hardware\\avr\\0.93\\variants\\leonardo",
"C:\\Users\\jskuby\\AppData\\Local\\Arduino15\\packages\\Arduino-LUFA\\hardware\\avr\\0.93\\libraries\\Arduino-LUFA",
"C:\\Users\\jskuby\\Documents\\Arduino\\libraries\\Bounce2\\src",
"C:\\Users\\jskuby\\AppData\\Local\\Arduino15\\packages\\Arduino-LUFA\\hardware\\avr\\0.93\\libraries\\EEPROM\\src",
"c:\\users\\jskuby\\appdata\\local\\arduino15\\packages\\arduino-lufa\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7\\lib\\gcc\\avr\\7.3.0\\include",
"c:\\users\\jskuby\\appdata\\local\\arduino15\\packages\\arduino-lufa\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7\\lib\\gcc\\avr\\7.3.0\\include-fixed",
"c:\\users\\jskuby\\appdata\\local\\arduino15\\packages\\arduino-lufa\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7\\avr\\include"
"C:\\Users\\jskuby\\AppData\\Local\\Arduino15\\packages\\Arduino-LUFA\\hardware\\avr\\0.93.0\\cores\\arduino",
"C:\\Users\\jskuby\\AppData\\Local\\Arduino15\\packages\\Arduino-LUFA\\hardware\\avr\\0.93.0\\variants\\leonardo",
"C:\\Users\\jskuby\\AppData\\Local\\Arduino15\\packages\\Arduino-LUFA\\hardware\\avr\\0.93.0\\libraries\\Arduino-LUFA",
"C:\\Users\\jskuby\\Documents\\Arduino\\libraries\\MPG\\src",
"C:\\Users\\jskuby\\Documents\\Arduino\\libraries\\FastLED\\src",
"C:\\Users\\jskuby\\AppData\\Local\\Arduino15\\packages\\Arduino-LUFA\\hardware\\avr\\0.93.0\\libraries\\EEPROM\\src",
"c:\\program files (x86)\\arduino\\hardware\\tools\\avr\\lib\\gcc\\avr\\7.3.0\\include",
"c:\\program files (x86)\\arduino\\hardware\\tools\\avr\\lib\\gcc\\avr\\7.3.0\\include-fixed",
"c:\\program files (x86)\\arduino\\hardware\\tools\\avr\\avr\\include"
],
"forcedInclude": [
"C:\\Users\\jskuby\\AppData\\Local\\Arduino15\\packages\\Arduino-LUFA\\hardware\\avr\\0.93\\cores\\arduino\\Arduino.h"
"C:\\Users\\jskuby\\AppData\\Local\\Arduino15\\packages\\Arduino-LUFA\\hardware\\avr\\0.93.0\\cores\\arduino\\Arduino.h"
],
"cStandard": "c11",
"cppStandard": "c++11",
Expand Down
12 changes: 12 additions & 0 deletions BoardSelect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef BOARD_SELECT_H_
#define BOARD_SELECT_H_

#if defined(REV_V3B)
#include "Boards/VsFighter_v3b.h"
#elif defined(REV_V2B)
#include "Boards/VsFighter_v2b.h"
#else
#include "Boards/VsFighter.h"
#endif

#endif
88 changes: 88 additions & 0 deletions Boards/VsFighter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#ifndef VSFIGHTER_H_
#define VSFIGHTER_H_

#include <MPGS.h>

// Pin mappings
#define PORT_PIN_UP PF7 // A0
#define PORT_PIN_DOWN PF6 // A1
#define PORT_PIN_LEFT PF5 // A2
#define PORT_PIN_RIGHT PF4 // A3
#define PORT_PIN_P1 PD2 // 1
#define PORT_PIN_P2 PD3 // 0
#define PORT_PIN_P3 PB1 // 15
#define PORT_PIN_P4 PD4 // 4
#define PORT_PIN_K1 PD0 // 3/SCL
#define PORT_PIN_K2 PD1 // 2/SDA
#define PORT_PIN_K3 PB6 // 10
#define PORT_PIN_K4 PD7 // 6
#define PORT_PIN_SELECT PB3 // 14
#define PORT_PIN_START PB2 // 16
#define PORT_PIN_LS PB4 // 8
#define PORT_PIN_RS PB5 // 9

// Input masks
#define PORTB_INPUT_MASK 0b01111110
#define PORTD_INPUT_MASK 0b10011111
#define PORTF_INPUT_MASK 0b11110000

// Index of register state in read results
#define PORTB_INDEX 0
#define PORTD_INDEX 1
#define PORTF_INDEX 2

class VsFighter: public MPGS {
public:
VsFighter(int debounceMS, GamepadStorage *storage) : MPGS(debounceMS, storage) {
hasAnalogTriggers = false;
hasLeftAnalogStick = false;
hasRightAnalogStick = false;
}

/**
* Perform pin setup and any other initialization the board requires
*/
void setup()
{
// Set to input (invert mask to set to 0)
DDRB = DDRB & ~PORTB_INPUT_MASK;
DDRD = DDRD & ~PORTD_INPUT_MASK;
DDRF = DDRF & ~PORTF_INPUT_MASK;

// Set to high/pullup
PORTB = PORTB | PORTB_INPUT_MASK;
PORTD = PORTD | PORTD_INPUT_MASK;
PORTF = PORTF | PORTF_INPUT_MASK;
}

void read()
{
// Cache port states
uint8_t ports[] = { ~PINB, ~PIND, ~PINF };

// Gather raw inputs
state.dpad = 0
| ((ports[PORTF_INDEX] >> PORT_PIN_UP & 1) ? GAMEPAD_MASK_UP : 0)
| ((ports[PORTF_INDEX] >> PORT_PIN_DOWN & 1) ? GAMEPAD_MASK_DOWN : 0)
| ((ports[PORTF_INDEX] >> PORT_PIN_LEFT & 1) ? GAMEPAD_MASK_LEFT : 0)
| ((ports[PORTF_INDEX] >> PORT_PIN_RIGHT & 1) ? GAMEPAD_MASK_RIGHT : 0)
;

state.buttons = 0
| ((ports[PORTD_INDEX] >> PORT_PIN_K1 & 1) ? GAMEPAD_MASK_B1 : 0) // Generic: K1, Switch: B, Xbox: A
| ((ports[PORTD_INDEX] >> PORT_PIN_K2 & 1) ? GAMEPAD_MASK_B2 : 0) // Generic: K2, Switch: A, Xbox: B
| ((ports[PORTD_INDEX] >> PORT_PIN_P1 & 1) ? GAMEPAD_MASK_B3 : 0) // Generic: P1, Switch: Y, Xbox: X
| ((ports[PORTD_INDEX] >> PORT_PIN_P2 & 1) ? GAMEPAD_MASK_B4 : 0) // Generic: P2, Switch: X, Xbox: Y
| ((ports[PORTD_INDEX] >> PORT_PIN_P4 & 1) ? GAMEPAD_MASK_L1 : 0) // Generic: P4, Switch: L, Xbox: LB
| ((ports[PORTB_INDEX] >> PORT_PIN_P3 & 1) ? GAMEPAD_MASK_R1 : 0) // Generic: P3, Switch: R, Xbox: RB
| ((ports[PORTD_INDEX] >> PORT_PIN_K4 & 1) ? GAMEPAD_MASK_L2 : 0) // Generic: K4, Switch: ZL, Xbox: LT (Digital)
| ((ports[PORTB_INDEX] >> PORT_PIN_K3 & 1) ? GAMEPAD_MASK_R2 : 0) // Generic: K3, Switch: ZR, Xbox: RT (Digital)
| ((ports[PORTB_INDEX] >> PORT_PIN_SELECT & 1) ? GAMEPAD_MASK_S1 : 0) // Generic: Select, Switch: -, Xbox: View
| ((ports[PORTB_INDEX] >> PORT_PIN_START & 1) ? GAMEPAD_MASK_S2 : 0) // Generic: Start, Switch: +, Xbox: Menu
| ((ports[PORTB_INDEX] >> PORT_PIN_LS & 1) ? GAMEPAD_MASK_L3 : 0) // All: Left Stick Click
| ((ports[PORTB_INDEX] >> PORT_PIN_RS & 1) ? GAMEPAD_MASK_R3 : 0) // All: Right Stick Click
;
}
};

#endif
101 changes: 101 additions & 0 deletions Boards/VsFighter_v2b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#ifndef VSFIGHTER_H_
#define VSFIGHTER_H_

#include <MPGS.h>

#define STATUS_LED_PIN 13 // PC7

// Pin mappings
#define PORT_PIN_UP PF7 // A0
#define PORT_PIN_DOWN PF6 // A1
#define PORT_PIN_LEFT PF5 // A2
#define PORT_PIN_RIGHT PF4 // A3
#define PORT_PIN_P1 PD2 // 1
#define PORT_PIN_P2 PD3 // 0
#define PORT_PIN_P3 PB1 // 15
#define PORT_PIN_P4 PD4 // 4
#define PORT_PIN_K1 PD0 // 3/SCL
#define PORT_PIN_K2 PD1 // 2/SDA
#define PORT_PIN_K3 PB6 // 10
#define PORT_PIN_K4 PD7 // 6
#define PORT_PIN_START PB3 // 14
#define PORT_PIN_SELECT PB5 // 9
#define PORT_PIN_LS PE6
#define PORT_PIN_RS PC6
#define PORT_PIN_HOME PB4 // 8

// Input masks
#define PORTB_INPUT_MASK 0b01111010
#define PORTC_INPUT_MASK 0b01000000
#define PORTD_INPUT_MASK 0b10011111
#define PORTE_INPUT_MASK 0b01000000
#define PORTF_INPUT_MASK 0b11110000

// Index of register state in read results
#define PORTB_INDEX 0
#define PORTC_INDEX 1
#define PORTD_INDEX 2
#define PORTE_INDEX 3
#define PORTF_INDEX 4

class VsFighter: public MPGS {
public:
VsFighter(int debounceMS, GamepadStorage *storage) : MPGS(debounceMS, storage) {
hasAnalogTriggers = false;
hasLeftAnalogStick = false;
hasRightAnalogStick = false;
}

/**
* Perform pin setup and any other initialization the board requires
*/
void setup() {
// Set to input (invert mask to set to 0)
DDRB = DDRB & ~PORTB_INPUT_MASK;
DDRC = DDRC & ~PORTC_INPUT_MASK;
DDRD = DDRD & ~PORTD_INPUT_MASK;
DDRE = DDRE & ~PORTE_INPUT_MASK;
DDRF = DDRF & ~PORTF_INPUT_MASK;

// Set to high/pullup
PORTB = PORTB | PORTB_INPUT_MASK;
PORTC = PORTC | PORTC_INPUT_MASK;
PORTD = PORTD | PORTD_INPUT_MASK;
PORTE = PORTE | PORTE_INPUT_MASK;
PORTF = PORTF | PORTF_INPUT_MASK;
}

/**
* Retrieve the raw inputs and save to the current GamepadState
*/
void read() {
// Cache port states
uint8_t ports[] = { ~PINB, ~PINC, ~PIND, ~PINE, ~PINF };

// Gather raw inputs
state.dpad = 0
| ((ports[PORTF_INDEX] >> PORT_PIN_UP & 1) ? GAMEPAD_MASK_UP : 0)
| ((ports[PORTF_INDEX] >> PORT_PIN_DOWN & 1) ? GAMEPAD_MASK_DOWN : 0)
| ((ports[PORTF_INDEX] >> PORT_PIN_LEFT & 1) ? GAMEPAD_MASK_LEFT : 0)
| ((ports[PORTF_INDEX] >> PORT_PIN_RIGHT & 1) ? GAMEPAD_MASK_RIGHT : 0)
;

state.buttons = 0
| ((ports[PORTD_INDEX] >> PORT_PIN_K1 & 1) ? GAMEPAD_MASK_B1 : 0) // Generic: K1, Switch: B, Xbox: A
| ((ports[PORTD_INDEX] >> PORT_PIN_K2 & 1) ? GAMEPAD_MASK_B2 : 0) // Generic: K2, Switch: A, Xbox: B
| ((ports[PORTD_INDEX] >> PORT_PIN_P1 & 1) ? GAMEPAD_MASK_B3 : 0) // Generic: P1, Switch: Y, Xbox: X
| ((ports[PORTD_INDEX] >> PORT_PIN_P2 & 1) ? GAMEPAD_MASK_B4 : 0) // Generic: P2, Switch: X, Xbox: Y
| ((ports[PORTD_INDEX] >> PORT_PIN_P4 & 1) ? GAMEPAD_MASK_L1 : 0) // Generic: P4, Switch: L, Xbox: LB
| ((ports[PORTB_INDEX] >> PORT_PIN_P3 & 1) ? GAMEPAD_MASK_R1 : 0) // Generic: P3, Switch: R, Xbox: RB
| ((ports[PORTD_INDEX] >> PORT_PIN_K4 & 1) ? GAMEPAD_MASK_L2 : 0) // Generic: K4, Switch: ZL, Xbox: LT (Digital)
| ((ports[PORTB_INDEX] >> PORT_PIN_K3 & 1) ? GAMEPAD_MASK_R2 : 0) // Generic: K3, Switch: ZR, Xbox: RT (Digital)
| ((ports[PORTB_INDEX] >> PORT_PIN_SELECT & 1) ? GAMEPAD_MASK_S1 : 0) // Generic: Select, Switch: -, Xbox: View
| ((ports[PORTB_INDEX] >> PORT_PIN_START & 1) ? GAMEPAD_MASK_S2 : 0) // Generic: Start, Switch: +, Xbox: Menu
| ((ports[PORTE_INDEX] >> PORT_PIN_LS & 1) ? GAMEPAD_MASK_L3 : 0) // All: Left Stick Click
| ((ports[PORTC_INDEX] >> PORT_PIN_RS & 1) ? GAMEPAD_MASK_R3 : 0) // All: Right Stick Click
| ((ports[PORTB_INDEX] >> PORT_PIN_HOME & 1) ? GAMEPAD_MASK_A1 : 0) // All: Home/Guide
;
}
};

#endif
103 changes: 103 additions & 0 deletions Boards/VsFighter_v3b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#ifndef VSFIGHTER_H_
#define VSFIGHTER_H_

#include <MPGS.h>

#define STATUS_LED_PIN 13 // PC7

// Pin mappings
#define PORT_PIN_UP PF7 // A0
#define PORT_PIN_DOWN PF6 // A1
#define PORT_PIN_LEFT PF5 // A2
#define PORT_PIN_RIGHT PF4 // A3
#define PORT_PIN_P1 PD2 // 1
#define PORT_PIN_P2 PD3 // 0
#define PORT_PIN_P3 PB1 // 15
#define PORT_PIN_P4 PD4 // 4
#define PORT_PIN_K1 PD0 // 3/SCL
#define PORT_PIN_K2 PD1 // 2/SDA
#define PORT_PIN_K3 PB6 // 10
#define PORT_PIN_K4 PD7 // 6
#define PORT_PIN_SELECT PB3 // 14
#define PORT_PIN_START PB2 // 16
#define PORT_PIN_LS PE6
#define PORT_PIN_RS PC6
#define PORT_PIN_HOME PB4 // 8
#define PORT_PIN_FUNC PB5 // 9

// Input masks
#define PORTB_INPUT_MASK 0b01111110
#define PORTC_INPUT_MASK 0b01000000
#define PORTD_INPUT_MASK 0b10011111
#define PORTE_INPUT_MASK 0b01000000
#define PORTF_INPUT_MASK 0b11110000

// Index of register state in read results
#define PORTB_INDEX 0
#define PORTC_INDEX 1
#define PORTD_INDEX 2
#define PORTE_INDEX 3
#define PORTF_INDEX 4

class VsFighter: public MPGS {
public:
VsFighter(int debounceMS, GamepadStorage *storage) : MPGS(debounceMS, storage) {
hasAnalogTriggers = false;
hasLeftAnalogStick = false;
hasRightAnalogStick = false;
}

/**
* Perform pin setup and any other initialization the board requires
*/
void setup() {
// Set to input (invert mask to set to 0)
DDRB = DDRB & ~PORTB_INPUT_MASK;
DDRC = DDRC & ~PORTC_INPUT_MASK;
DDRD = DDRD & ~PORTD_INPUT_MASK;
DDRE = DDRE & ~PORTE_INPUT_MASK;
DDRF = DDRF & ~PORTF_INPUT_MASK;

// Set to high/pullup
PORTB = PORTB | PORTB_INPUT_MASK;
PORTC = PORTC | PORTC_INPUT_MASK;
PORTD = PORTD | PORTD_INPUT_MASK;
PORTE = PORTE | PORTE_INPUT_MASK;
PORTF = PORTF | PORTF_INPUT_MASK;
}

/**
* Retrieve the raw inputs and save to the current GamepadState
*/
void read() {
// Cache port states
uint8_t ports[] = { ~PINB, ~PINC, ~PIND, ~PINE, ~PINF };

// Gather raw inputs
state.dpad = 0
| ((ports[PORTF_INDEX] >> PORT_PIN_UP & 1) ? GAMEPAD_MASK_UP : 0)
| ((ports[PORTF_INDEX] >> PORT_PIN_DOWN & 1) ? GAMEPAD_MASK_DOWN : 0)
| ((ports[PORTF_INDEX] >> PORT_PIN_LEFT & 1) ? GAMEPAD_MASK_LEFT : 0)
| ((ports[PORTF_INDEX] >> PORT_PIN_RIGHT & 1) ? GAMEPAD_MASK_RIGHT : 0)
;

state.buttons = 0
| ((ports[PORTD_INDEX] >> PORT_PIN_K1 & 1) ? GAMEPAD_MASK_B1 : 0) // Generic: K1, Switch: B, Xbox: A
| ((ports[PORTD_INDEX] >> PORT_PIN_K2 & 1) ? GAMEPAD_MASK_B2 : 0) // Generic: K2, Switch: A, Xbox: B
| ((ports[PORTD_INDEX] >> PORT_PIN_P1 & 1) ? GAMEPAD_MASK_B3 : 0) // Generic: P1, Switch: Y, Xbox: X
| ((ports[PORTD_INDEX] >> PORT_PIN_P2 & 1) ? GAMEPAD_MASK_B4 : 0) // Generic: P2, Switch: X, Xbox: Y
| ((ports[PORTD_INDEX] >> PORT_PIN_P4 & 1) ? GAMEPAD_MASK_L1 : 0) // Generic: P4, Switch: L, Xbox: LB
| ((ports[PORTB_INDEX] >> PORT_PIN_P3 & 1) ? GAMEPAD_MASK_R1 : 0) // Generic: P3, Switch: R, Xbox: RB
| ((ports[PORTD_INDEX] >> PORT_PIN_K4 & 1) ? GAMEPAD_MASK_L2 : 0) // Generic: K4, Switch: ZL, Xbox: LT (Digital)
| ((ports[PORTB_INDEX] >> PORT_PIN_K3 & 1) ? GAMEPAD_MASK_R2 : 0) // Generic: K3, Switch: ZR, Xbox: RT (Digital)
| ((ports[PORTB_INDEX] >> PORT_PIN_SELECT & 1) ? GAMEPAD_MASK_S1 : 0) // Generic: Select, Switch: -, Xbox: View
| ((ports[PORTB_INDEX] >> PORT_PIN_START & 1) ? GAMEPAD_MASK_S2 : 0) // Generic: Start, Switch: +, Xbox: Menu
| ((ports[PORTC_INDEX] >> PORT_PIN_LS & 1) ? GAMEPAD_MASK_L3 : 0) // All: Left Stick Click
| ((ports[PORTE_INDEX] >> PORT_PIN_RS & 1) ? GAMEPAD_MASK_R3 : 0) // All: Right Stick Click
| ((ports[PORTB_INDEX] >> PORT_PIN_HOME & 1) ? GAMEPAD_MASK_A1 : 0) // All: Home/Guide
| ((ports[PORTB_INDEX] >> PORT_PIN_FUNC & 1) ? GAMEPAD_MASK_A2 : 0) // All: Function/settings button
;
}
};

#endif
Loading