├── Diagram.png ├── .gitattributes ├── Readme.md └── PS2toXBOX └── PS2toXBOX.ino /Diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eolvera85/PS2toXBOX/HEAD/Diagram.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # PS2 to Xbox OG Controller Adapter 2 | Compatible with boards based on ATMEGA32u4 at 16MHZ 3 | 4 | Features: 5 | - Native USB on development boards 6 | - Compatible with PS1/PS2 Controllers 7 | 8 | Components: 9 | - Board ATMEGA32u4 at 5V/16MHz (Great 3.3v/16MHZ) 10 | - Micro USB to Xbox OG Controller Cable (Depending on the board) 11 | - Regulator 3.3V (Optional) 12 | - Level Shffter 5v/3.3v (Optional) 13 | 14 | Notes: 15 | For its correct operation it is necessary that the signals between the board and the controller operate at 3.3v, which is the power supply voltage of the controller, for this the following can be done: (Diagram) 16 | - Remove the diode and add a 3.3v regulator (Based on ProMicro) 17 | - Level Shifter 5v/3.3v 18 | 19 | This project is functional with the physical controls of psx/ps2, to combine it with the BlueRetro project it is necessary to modify unofficial functions in BlueRetro (Pressure buttons and/or Rumble) 20 | 21 | ![alt text](Diagram.png?raw=true) 22 | 23 | ### Pin Connection 24 | | GPIO ATMEGA32u4 | CONTROLLER | 25 | | ----------------- | ----- | 26 | | 2 | PS2_DAT | 27 | | 3 | PS2_CMD | 28 | | 4 | PS2_ATT | 29 | | 5 | PS2_CLK | 30 | | 3.3v | PS2_VCC | 31 | | GND | PS2_GND | 32 | 33 | Libraries used: 34 | - [PsxNewLib](https://github.com/SukkoPera/PsxNewLib) 35 | - [DigitalIO](https://github.com/greiman/DigitalIO) 36 | - [OGXBOX-PAD](https://github.com/eolvera85/OGXBOX-PAD) 37 | -------------------------------------------------------------------------------- /PS2toXBOX/PS2toXBOX.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const byte PIN_PS2_DAT = 2; 5 | const byte PIN_PS2_CMD = 3; 6 | const byte PIN_PS2_ATT = 4; 7 | const byte PIN_PS2_CLK = 5; 8 | 9 | const unsigned long POLLING_INTERVAL = 1000U / 50U; 10 | PsxControllerBitBang psx; 11 | 12 | boolean haveController; 13 | byte axisX, axisY; 14 | bool enableAnalogButton; 15 | bool enableAnalogSticks; 16 | bool enableRumble; 17 | bool okRumble; 18 | uint8_t lValue; 19 | uint8_t hValue; 20 | OgXbox ogxbox(DUKE); 21 | 22 | void setup() { 23 | haveController = false; 24 | okRumble = false; 25 | ogxbox.begin(); 26 | } 27 | 28 | void loop() { 29 | static unsigned long last = 0; 30 | 31 | if (millis() - last >= POLLING_INTERVAL) { 32 | last = millis(); 33 | 34 | if (!haveController) { 35 | if (psx.begin()) { 36 | psx.enterConfigMode(); 37 | 38 | enableAnalogSticks = psx.enableAnalogSticks(); 39 | enableAnalogButton = psx.enableAnalogButtons(); 40 | enableRumble = psx.enableRumble(); 41 | 42 | psx.exitConfigMode(); 43 | 44 | haveController = true; 45 | } 46 | } 47 | else { 48 | if (!psx.read()) { 49 | haveController = false; 50 | } 51 | else { 52 | if (enableRumble && okRumble) 53 | psx.setRumble(lValue > 0x00, hValue); 54 | else 55 | psx.setRumble(false, 0x00); 56 | 57 | if (enableAnalogButton) { 58 | ogxbox.setDpad(psx.getAnalogButton(PSAB_PAD_UP) > 0x00, 59 | psx.getAnalogButton(PSAB_PAD_DOWN) > 0x00, 60 | psx.getAnalogButton(PSAB_PAD_LEFT) > 0x00, 61 | psx.getAnalogButton(PSAB_PAD_RIGHT) > 0x00); 62 | 63 | ogxbox.pressAnalogButton(ANA_BTN_A, psx.getAnalogButton(PSAB_CROSS)); 64 | ogxbox.pressAnalogButton(ANA_BTN_B, psx.getAnalogButton(PSAB_CIRCLE)); 65 | ogxbox.pressAnalogButton(ANA_BTN_X, psx.getAnalogButton(PSAB_SQUARE)); 66 | ogxbox.pressAnalogButton(ANA_BTN_Y, psx.getAnalogButton(PSAB_TRIANGLE)); 67 | ogxbox.pressAnalogButton(ANA_BTN_BLACK, psx.getAnalogButton(PSAB_R1)); 68 | ogxbox.pressAnalogButton(ANA_BTN_WHITE, psx.getAnalogButton(PSAB_L1)); 69 | 70 | ogxbox.setLeftTrigger(psx.getAnalogButton(PSAB_L2)); 71 | ogxbox.setRightTrigger(psx.getAnalogButton(PSAB_R2)); 72 | } 73 | else { 74 | ogxbox.setDpad(psx.buttonPressed(PSB_PAD_UP), 75 | psx.buttonPressed(PSB_PAD_DOWN), 76 | psx.buttonPressed(PSB_PAD_LEFT), 77 | psx.buttonPressed(PSB_PAD_RIGHT)); 78 | 79 | ogxbox.setButton(BUTTON_A, psx.buttonPressed(PSB_CROSS)); 80 | ogxbox.setButton(BUTTON_B, psx.buttonPressed(PSB_CIRCLE)); 81 | ogxbox.setButton(BUTTON_X, psx.buttonPressed(PSB_SQUARE)); 82 | ogxbox.setButton(BUTTON_Y, psx.buttonPressed(PSB_TRIANGLE)); 83 | ogxbox.setButton(BUTTON_BLACK, psx.buttonPressed(PSB_R1)); 84 | ogxbox.setButton(BUTTON_WHITE, psx.buttonPressed(PSB_L1)); 85 | 86 | ogxbox.setLeftTrigger(psx.buttonPressed(PSB_L2) ? 0xFF : 0x00); 87 | ogxbox.setRightTrigger(psx.buttonPressed(PSB_R2) ? 0xFF : 0x00); 88 | } 89 | 90 | ogxbox.setButton(BUTTON_START, psx.buttonPressed(PSB_START)); 91 | ogxbox.setButton(BUTTON_BACK, psx.buttonPressed(PSB_SELECT)); 92 | ogxbox.setButton(BUTTON_LS, psx.buttonPressed(PSB_L3)); 93 | ogxbox.setButton(BUTTON_RS, psx.buttonPressed(PSB_R3)); 94 | 95 | if (enableAnalogSticks) { 96 | psx.getLeftAnalog(axisX, axisY); 97 | ogxbox.setLeftJoystick(map(axisX, ANALOG_MIN_VALUE, ANALOG_MAX_VALUE, DUKE_JOYSTICK_MIN, DUKE_JOYSTICK_MAX), 98 | map(axisY, ANALOG_MIN_VALUE, ANALOG_MAX_VALUE, DUKE_JOYSTICK_MAX, DUKE_JOYSTICK_MIN)); 99 | 100 | psx.getRightAnalog(axisX, axisY); 101 | ogxbox.setRightJoystick(map(axisX, ANALOG_MIN_VALUE, ANALOG_MAX_VALUE, DUKE_JOYSTICK_MIN, DUKE_JOYSTICK_MAX), 102 | map(axisY, ANALOG_MIN_VALUE, ANALOG_MAX_VALUE, DUKE_JOYSTICK_MAX, DUKE_JOYSTICK_MIN)); 103 | } 104 | else { 105 | ogxbox.setLeftJoystick(0, 0); 106 | ogxbox.setRightJoystick(0, 0); 107 | } 108 | 109 | ogxbox.sendReport(); 110 | okRumble = ogxbox.getRumble(lValue, hValue); 111 | } 112 | } 113 | } 114 | } 115 | --------------------------------------------------------------------------------