1
0
mirror of https://github.com/MickGyver/DaemonBite-Retro-Controllers-USB synced 2024-11-21 08:45:06 -05:00

Removed the need for the switch.

This commit is contained in:
MickGyver 2020-01-30 23:28:04 +02:00
parent 74aec33869
commit b414a311bd
3 changed files with 14 additions and 34 deletions

View File

@ -104,6 +104,19 @@ word SegaController32U4::getStateMD()
(bitRead(_inputReg2, DB9_PIN9_BIT) == LOW) ? _currentState |= SC_BTN_C : _currentState &= ~SC_BTN_C;
}
}
else // No Mega Drive controller is connected, use SMS/Atari mode
{
// Clear current state
_currentState = 0;
// Read input pins for Up, Down, Left, Right, Fire1, Fire2
if (bitRead(_inputReg1, DB9_PIN1_BIT) == LOW) { _currentState |= SC_BTN_UP; }
if (bitRead(_inputReg1, DB9_PIN2_BIT) == LOW) { _currentState |= SC_BTN_DOWN; }
if (bitRead(_inputReg1, DB9_PIN3_BIT) == LOW) { _currentState |= SC_BTN_LEFT; }
if (bitRead(_inputReg1, DB9_PIN4_BIT) == LOW) { _currentState |= SC_BTN_RIGHT; }
if (bitRead(_inputReg2, DB9_PIN6_BIT) == LOW) { _currentState |= SC_BTN_A; }
if (bitRead(_inputReg2, DB9_PIN9_BIT) == LOW) { _currentState |= SC_BTN_B; }
}
}
else // Select pin is LOW
{
@ -122,8 +135,6 @@ word SegaController32U4::getStateMD()
(bitRead(_inputReg2, DB9_PIN9_BIT) == LOW) ? _currentState |= SC_BTN_START : _currentState &= ~SC_BTN_START;
}
}
else
_currentState = 0; // Reset buttons if no controller is connected
}
}
else
@ -133,23 +144,3 @@ word SegaController32U4::getStateMD()
return _currentState;
}
word SegaController32U4::getStateSMS()
{
// Clear current state
_currentState = 0;
// Read input register(s)
_inputReg1 = PINF;
_inputReg2 = PINB;
// Read input pins for Up, Down, Left, Right, Fire1, Fire2
if (bitRead(_inputReg1, DB9_PIN1_BIT) == LOW) { _currentState |= SC_BTN_UP; }
if (bitRead(_inputReg1, DB9_PIN2_BIT) == LOW) { _currentState |= SC_BTN_DOWN; }
if (bitRead(_inputReg1, DB9_PIN3_BIT) == LOW) { _currentState |= SC_BTN_LEFT; }
if (bitRead(_inputReg1, DB9_PIN4_BIT) == LOW) { _currentState |= SC_BTN_RIGHT; }
if (bitRead(_inputReg2, DB9_PIN6_BIT) == LOW) { _currentState |= SC_BTN_A; }
if (bitRead(_inputReg2, DB9_PIN9_BIT) == LOW) { _currentState |= SC_BTN_B; }
return _currentState;
}

View File

@ -63,8 +63,6 @@ class SegaController32U4 {
word getStateMD();
word getStateSMS();
private:
word _currentState;

View File

@ -40,8 +40,6 @@
// 6 14 PB3
// 7 6 PD7
// 9 15 PB1
//
// Connect a slide switch to pins GND,GND and 2
SegaController32U4 controller;
@ -55,19 +53,12 @@ word lastState = 1;
void setup()
{
// Setup switch pin (2, PD1)
DDRD &= ~B00000010; // input
PORTD |= B00000010; // high to enable internal pull-up
Gamepad.begin(1);
}
void loop()
{
if(PIND & B00000010)
currentState = controller.getStateMD();
else
currentState = controller.getStateSMS();
currentState = controller.getStateMD();
sendState();
}