Sega pinout and swap 1p vs 2p pins so 1p works with radio

This commit is contained in:
Travis Burtrum 2020-12-28 01:15:13 -05:00
parent f754902fe1
commit 91b9703118
2 changed files with 62 additions and 56 deletions

View File

@ -23,35 +23,35 @@ Wiring
![DB-25 Pinout](images/db25pins.jpg)
| DB-25 Pins | Arduino Pro Micro GPIO | ESP32 GPIO | RADIO | SNES | PSX | N64 | Gamecube |
|---------------|------------------------|------------|----------|--------|--------|----------|----------|
| 1 | 1 | | - | - | - | - | - |
| 2 | 2 | | - | LATCH | DATA | DATA1 | DATA1 |
| 3 | 3 | | - | CLOCK | CMD | - | - |
| 4 | 4 | | - | - | ATT | - | - |
| 5 | 5 | | - | - | CLK | - | - |
| 6 | 6 | | - | - | - | - | - |
| 7 | 7 | | CE | - | - | - | - |
| 8 | 8 | | CSN | - | - | - | - |
| 9 | 9 | | - | - | - | - | - |
| 10 | 10 | | - | - | - | - | - |
| 11 | 0 | | - | - | - | - | - |
| 12 | - | | - | - | - | - | - |
| 13 | - | | - | - | - | - | - |
| 14 | 14 | | MISO | - | - | - | - |
| 15 | 15 | | SCLK | - | - | - | - |
| 16 | 16 | | MOSI | - | - | - | - |
| 17 | - | | - | - | - | - | - |
| 18 | 18 | | - | DATA1 | - | - | - |
| 19 | 19 | | - | DATA2 | - | - | - |
| 20 | 20 | | - | DATA3 | - | - | - |
| 21 | 21 | | - | DATA4 | - | - | - |
| 22 | - | | - | - | - | - | - |
| 23 | - | | 3.3V VCC | - | - | 3.3V VCC | 3.3V VCC |
| 24 | 5V VCC | | 5V VCC | 5V VCC | 5V VCC | - | 5V VCC |
| 25 | GND | | GND | GND | - | GND | GND |
| DB-25 Pins | Arduino Pro Micro GPIO | ESP32 GPIO | Radio | SNES | PSX | N64 | Gamecube | Genesis |
|---------------|------------------------|------------|----------|--------|--------|----------|----------|-------------|
| 1 | 1 | | - | - | - | - | - | P1-1 |
| 2 | 2 | | - | LATCH | DATA | DATA1 | DATA1 | P1-3 |
| 3 | 3 | | - | CLOCK | CMD | - | - | P1-4 |
| 4 | 4 | | - | - | ATT | - | - | P1-6 |
| 5 | 5 | | - | - | CLK | - | - | P1-7 |
| 6 | 6 | | - | - | - | - | - | P1-9 |
| 7 | 7 | | CE | - | - | - | - | P2-7* |
| 8 | 8 | | CSN | - | - | - | - | - |
| 9 | 9 | | - | - | - | - | - | - |
| 10 | 10 | | - | - | - | - | - | - |
| 11 | 0 | | - | - | - | - | - | P1-2 |
| 12 | - | | - | - | - | - | - | - |
| 13 | - | | - | - | - | - | - | - |
| 14 | 14 | | MISO | - | - | - | - | P2-6* |
| 15 | 15 | | SCLK | - | - | - | - | P2-9* |
| 16 | 16 | | MOSI | - | - | - | - | - |
| 17 | - | | - | - | - | - | - | - |
| 18 | 18 | | - | DATA1 | - | - | - | P2-1 |
| 19 | 19 | | - | DATA2 | - | - | - | P2-2 |
| 20 | 20 | | - | DATA3 | - | - | - | P2-3 |
| 21 | 21 | | - | DATA4 | - | - | - | P2-4 |
| 22 | - | | - | - | - | - | - | - |
| 23 | - | | 3.3V VCC | - | - | 3.3V VCC | 3.3V VCC | - |
| 24 | 5V VCC | | 5V VCC | 5V VCC | 5V VCC | - | 5V VCC | PX-5 5V VCC |
| 25 | GND | | GND | GND | - | GND | GND | PX-8 GND |
* 2nd player Genesis is incompatible with Radio because it uses the same pins, 1 player Genesis is compatible
Credits / Links
---------------

View File

@ -1,4 +1,19 @@
/*
Genesis/Atari/Megadrive:
LOOKING AT THE PLUG ON FRONT OF CONSOLE (not coming from controller)
1 2 3 4 5
-----------------------
\ o o o o o /
\ o o o o /
\-----------------/
6 7 8 9
PIN # USAGE
5: 5V VCC
8: GND
*/
#include "Arduino.h"
#ifndef GAMEPAD_COUNT
@ -33,11 +48,18 @@ enum
#define OPT_PIN_READ1(X) (bitRead(reg1, DATA_PIN[c][X]))
#define OPT_PIN_READ2(X) (bitRead(reg2, DATA_PIN[c][X]))
static const int DATA_PIN_SELECT[GAMEPAD_COUNT] = {
5,
#if GAMEPAD_COUNT > 1
7,
#endif
};
//individual data pin BIT for each controller, they are read in bulk
static const int DATA_PIN[GAMEPAD_COUNT][PIN_COUNT] = {
{7, 6, 5, 4, 3, 1},
#if GAMEPAD_COUNT > 1
{3, 2, 1, 0, 4, 7},
#if GAMEPAD_COUNT > 1
{7, 6, 5, 4, 3, 1},
#endif
};
@ -65,17 +87,17 @@ static const int DATA_PIN[GAMEPAD_COUNT][PIN_COUNT] = {
#else // end esp32 pins, start generic pins
static const int DATA_PIN_SELECT[GAMEPAD_COUNT] = {
7,
#if GAMEPAD_COUNT > 1
5,
#if GAMEPAD_COUNT > 1
7,
#endif
};
//individual data pin for each controller
static const int DATA_PIN[GAMEPAD_COUNT][PIN_COUNT] = {
{18, 19, 20, 21, 14, 15},
#if GAMEPAD_COUNT > 1
{1, 0, 2, 3, 4, 6},
#if GAMEPAD_COUNT > 1
{18, 19, 20, 21, 14, 15},
#endif
};
#endif // esp32 vs generic pins
@ -145,10 +167,10 @@ class SegaControllers32U4 {
#if CODE_PLATFORM == 2
void readPort(byte c, byte reg1, byte reg2);
byte _inputReg3;
#if GAMEPAD_COUNT > 1
byte _inputReg1;
byte _inputReg2;
#if GAMEPAD_COUNT > 1
byte _inputReg3;
#endif // GAMEPAD_COUNT
#else
void readPort(byte c);
@ -156,21 +178,6 @@ class SegaControllers32U4 {
};
SegaControllers32U4::SegaControllers32U4(void) {
#if CODE_PLATFORM == 2
// Setup input pins (A0,A1,A2,A3,14,15 or PF7,PF6,PF5,PF4,PB3,PB1)
DDRF &= ~B11110000; // input
PORTF |= B11110000; // high to enable internal pull-up
DDRB &= ~B00001010; // input
PORTB |= B00001010; // high to enable internal pull-up
// Setup input pins (TXO,RXI,2,3,4,6 or PD3,PD2,PD1,PD0,PD4,PD7)
DDRD &= ~B10011111; // input
PORTD |= B10011111; // high to enable internal pull-up
DDRC |= B01000000; // Select pins as output
DDRE |= B01000000;
PORTC |= B01000000; // Select pins high
PORTE |= B01000000;
#else
for (int c = 0; c < GAMEPAD_COUNT; c++) {
// Setup output pin
pinMode(DATA_PIN_SELECT[c], OUTPUT);
@ -181,7 +188,6 @@ SegaControllers32U4::SegaControllers32U4(void) {
pinMode(DATA_PIN[c][i], INPUT_PULLUP);
}
}
#endif
_pinSelect = true;
for (int c = 0; c < GAMEPAD_COUNT; c++) {
@ -212,15 +218,15 @@ void SegaControllers32U4::readState() {
delayMicroseconds(SC_CYCLE_DELAY);
// Read all input registers
_inputReg3 = PIND;
#if GAMEPAD_COUNT > 1
_inputReg1 = PINF;
_inputReg2 = PINB;
#if GAMEPAD_COUNT > 1
_inputReg3 = PIND;
#endif
readPort(0, _inputReg1, _inputReg2);
readPort(0, _inputReg3, _inputReg3);
#if GAMEPAD_COUNT > 1
readPort(1, _inputReg3, _inputReg3);
readPort(1, _inputReg1, _inputReg2);
#endif
}