Skip to content

Commit

Permalink
Adding PS1/PS2 device mode
Browse files Browse the repository at this point in the history
Fix to avoid taking wrong data of features mode from flash
  • Loading branch information
Loc15 committed Mar 4, 2024
1 parent 65dc9bc commit f61ebdc
Show file tree
Hide file tree
Showing 12 changed files with 1,029 additions and 298 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PicoGamepadCoverter is a project designed for RP2040 or Raspberry Pi Pico and va
- Read input from USB and Bluetooth controllers.
- Read inputs from no USB peripherals.
- Web interface to choose between modes.
- Different out modes (Dinput, Xinput, Switch, Bluetooth)
- Different out modes (Dinput, Xinput, Switch, Bluetooth, PS1/PS2)
- Easy to use, no overcomplicated options.

---
Expand Down Expand Up @@ -60,7 +60,7 @@ To get started with PicoGamepadConverter, follow the steps below:
![keyboard_connector](./docs/keyboard_connector.jpg)
![keyboard_pc](./docs/keyboard_pc.jpg)

- The conection for PS1 controllers are on **19 GPIO** for **COMMAND PIN**, **20 GPIO** for **CLOCK PIN**, **21 GPIO** for **ATTENTION PIN** and **22 GPIO** for **DATA PIN**
- The connection for PS1 controllers are on **19 GPIO** for **COMMAND PIN**, **20 GPIO** for **CLOCK PIN**, **21 GPIO** for **ATTENTION PIN** and **22 GPIO** for **DATA PIN**

![ps1_schematic](./docs/ps1_pinout.png)
![ps1_connector](./docs/ps1_connector.jpg)
Expand All @@ -72,6 +72,12 @@ To get started with PicoGamepadConverter, follow the steps below:

- On Bluetooth host mode you must put the mac address of your gamepad. You can get this address connecting you gamepad to a PC or a mobile phone. This address _should_ be put just once time, next time you just need choose the mode.

- The connection for PS1/PS2 device mode are on **19 GPIO** for **DATA PIN**, **20 GPIO** for **COMMAND PIN**, **21 GPIO** for **ATTENTION PIN**, **22 GPIO** for **CLOCK PIN** and **26 GPIO** for **ACKNOWLEDGE PIN**.

- On PS1/PS2 device mode, the host connection is on **native usb female connector on the microcontroller**.

![ps1_ps2_device_connection](./docs/PS1_PS2_pinout.png)

---
## Modes
Exist two parameter to choose on web interface, **host** and **device**. The first is the input and another one the output.
Expand All @@ -97,6 +103,9 @@ Exist two parameter to choose on web interface, **host** and **device**. The fir
#### Wireless MODES
- Bluetooth: Simulation of a generic HID gamepad.

#### SPECIAL MODES
- PS1/PS2: Simulation of a PS1 or PS2 controller.

---
## Features

Expand Down Expand Up @@ -128,7 +137,7 @@ Controllers that was tested on different host modes.

### Troubleshooting

- 8bitdo controllers sometimes have problems to connect on USB or Bluetooth mode. On USB if it doesn't connect reboot the microcontroller without disconnect.
- 8bitdo controllers sometimes have problems to connect on USB or Bluetooth mode. On USB if it doesn't connect reboot the microcontroller without disconnect. If it doesn't work either, [reset pico's flash](https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html#resetting-flash-memory).

- On Bluetooth if it doesn't connect on first, reboot and put your gamepad on pair mode.

Expand All @@ -144,6 +153,8 @@ Controllers that was tested on different host modes.
- [lurk101](https://github.com/lurk101/pico-ps2kbd) for Keyboard PS/2 example.
- [dotcypress](https://github.com/dotcypress/ula) for the Logic Analyzer compatible with PulseView. Was very useful for PS1 controller part.
- [usedbytes](https://github.com/usedbytes/picow_ds4) for ps4 bluetooth example.
- [dangiu](https://github.com/dangiu/PicoMemcard) for `psxSPI.pio` program from PicoMemcard project.
- [TonyMacDonald1995](https://github.com/TonyMacDonald1995/DS4toPS2) for PS2 controller simulation example.


## License
Expand Down
Binary file added docs/PS1_PS2_pinout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ add_subdirectory(host_files/parser-lib)
add_subdirectory(host_files/bluehost-lib)
add_subdirectory(device_files/rndis-lib)
add_subdirectory(device_files/bluehid-lib)
add_subdirectory(device_files/psx-device)
add_subdirectory(flash-lib)

pico_enable_stdio_uart(${target_name} 1)
Expand All @@ -65,7 +66,7 @@ add_compile_definitions(PICO_W=1)
target_include_directories(${target_name} PRIVATE ${CMAKE_CURRENT_LIST_DIR} device_files/switch device_files/xinput host_files)

target_link_libraries(${target_name} PRIVATE pico_stdlib pico_pio_usb pico_cyw43_arch_none tinyusb_device tinyusb_host ps2kbd-lib psx-lib rndis-lib parser-lib
bluehost-lib flash-lib bluehid-lib)
bluehost-lib flash-lib bluehid-lib psx-device)


pico_add_extra_outputs(${target_name})
Expand Down
27 changes: 26 additions & 1 deletion src/convert_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//Device
#include "SwitchDescriptors.h"
#include "PS3_Descriptors.h"
#include "controller_simulator.h"
//Host
#include "xinput_definitions.h"
#include "hid_definitions.h"
Expand Down Expand Up @@ -226,6 +227,29 @@ void new_report_fun(void *report, MODE mode_host, void *new_report, MODE mode_de
device_report->r_y_axis = XINPUT_TO_HID_Y(host_report.sThumbRY);
}
break;
case PSX:{
PSXInputState *device_report = new_report;

/*new data*/
device_report->buttons1 = ~(((host_report.wButtons & XINPUT_GAMEPAD_DPAD_UP ? 1 : 0)<<PSX_DEVICE_UP) | ((host_report.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT ? 1 : 0)<<PSX_DEVICE_RIGHT) |
((host_report.wButtons & XINPUT_GAMEPAD_DPAD_DOWN ? 1 : 0)<<PSX_DEVICE_DOWN) | ((host_report.wButtons & XINPUT_GAMEPAD_DPAD_LEFT ? 1 : 0)<<PSX_DEVICE_LEFT) |
((host_report.wButtons & XINPUT_GAMEPAD_START ? 1 : 0)<<PSX_DEVICE_START) | ((host_report.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB ? 1 : 0)<<PSX_DEVICE_R3) |
((host_report.wButtons & XINPUT_GAMEPAD_LEFT_THUMB ? 1 : 0)<<PSX_DEVICE_L3) | ((host_report.wButtons & XINPUT_GAMEPAD_BACK ? 1 : 0)<<PSX_DEVICE_SELECT));

device_report->buttons2 = ~(((host_report.wButtons & XINPUT_GAMEPAD_A ? 1 : 0)<<PSX_DEVICE_CROSS) | ((host_report.wButtons & XINPUT_GAMEPAD_B ? 1 : 0)<<PSX_DEVICE_CIRCLE) |
((host_report.wButtons & XINPUT_GAMEPAD_X ? 1 : 0)<<PSX_DEVICE_SQUARE) | ((host_report.wButtons & XINPUT_GAMEPAD_Y ? 1 : 0)<<PSX_DEVICE_TRIANGLE) |
((host_report.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER ? 1 : 0)<<PSX_DEVICE_R1) | ((host_report.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER ? 1 : 0)<<PSX_DEVICE_L1) |
((host_report.bRightTrigger > 127 ? 1 : 0)<<PSX_DEVICE_R2) | ((host_report.bLeftTrigger > 127 ? 1 : 0)<<PSX_DEVICE_L2));

device_report->lx = XINPUT_TO_HID_X(host_report.sThumbLX);
device_report->ly = XINPUT_TO_HID_Y(host_report.sThumbLY);
device_report->rx = XINPUT_TO_HID_X(host_report.sThumbRX);
device_report->ry = XINPUT_TO_HID_Y(host_report.sThumbRY);

device_report->l2 = host_report.bLeftTrigger;
device_report->r2 = host_report.bRightTrigger;
}
break;
default:
/*XINPUT*/
//diferent structure host -> device
Expand All @@ -242,7 +266,8 @@ void new_report_fun(void *report, MODE mode_host, void *new_report, MODE mode_de

void set_features_from_flash(unsigned char *data){
//set features
features.set_features = data[0];
//void incorrect data from flash
features.set_features = (data[0] > 1 ? 0 : data[0]);
//num features
features.num_enabled_features = data[1];
//enabled features
Expand Down
9 changes: 9 additions & 0 deletions src/device_files/psx-device/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later
#
add_library(psx-device INTERFACE)
target_include_directories(psx-device INTERFACE ${CMAKE_CURRENT_LIST_DIR})
target_link_libraries(psx-device INTERFACE pico_stdlib hardware_pio hardware_gpio)
target_sources(psx-device INTERFACE
${CMAKE_CURRENT_LIST_DIR}/controller_simulator.c
${CMAKE_CURRENT_LIST_DIR}/controller_simulator.h)
pico_generate_pio_header(psx-device ${CMAKE_CURRENT_LIST_DIR}/psxSPI.pio)
Loading

0 comments on commit f61ebdc

Please sign in to comment.