From b414a311bd88560be298afa82dbbd636fa6fe3fa Mon Sep 17 00:00:00 2001 From: MickGyver Date: Thu, 30 Jan 2020 23:28:04 +0200 Subject: [PATCH] Removed the need for the switch. --- SegaControllerUSB/SegaController32U4.cpp | 35 +++++++++--------------- SegaControllerUSB/SegaController32U4.h | 2 -- SegaControllerUSB/SegaControllerUSB.ino | 11 +------- 3 files changed, 14 insertions(+), 34 deletions(-) diff --git a/SegaControllerUSB/SegaController32U4.cpp b/SegaControllerUSB/SegaController32U4.cpp index cfe88bb..754fc4e 100644 --- a/SegaControllerUSB/SegaController32U4.cpp +++ b/SegaControllerUSB/SegaController32U4.cpp @@ -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; -} diff --git a/SegaControllerUSB/SegaController32U4.h b/SegaControllerUSB/SegaController32U4.h index 53b73cf..3954b39 100644 --- a/SegaControllerUSB/SegaController32U4.h +++ b/SegaControllerUSB/SegaController32U4.h @@ -63,8 +63,6 @@ class SegaController32U4 { word getStateMD(); - word getStateSMS(); - private: word _currentState; diff --git a/SegaControllerUSB/SegaControllerUSB.ino b/SegaControllerUSB/SegaControllerUSB.ino index 4224a89..fc38641 100644 --- a/SegaControllerUSB/SegaControllerUSB.ino +++ b/SegaControllerUSB/SegaControllerUSB.ino @@ -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(); }