OpenStickCommunity / OpenStickCommunity/GP2040-CE
Gyroscope/Accelerometer support for PS4, PS3, and Switch modes
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 2.5k
- Forks
- 666
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 7
Description
This is WIP on my branch here: https://github.com/vgf89/GP2040-CE/tree/DS4-IMU
I'm using an MPU6050 breakout board. Once I'm pretty much done I'll submit a pull request.
TODO:
- Implement MPU6050 library, initial PoC test (spitting data out to analog stick state)
- Add missing PS4 report fields
- Extend gamepad state to include accel/gyro data (G's, deg/sec floats)
- Populate PS4 report (verify scale/format of accel/gyro)
- Test with PS4 and SteamInput (had to add 0x054c id to get motion on PC)
- Add drift calibration (on startup for now, but it needs to be saved in flash and put on a hotkey or something)
- Implement AddonOptions/WebUI
- SDA/SCL pins, i2c block, i2c speed, address 0x68/0x69
-
sensor rates -
sensor scale (precision vs max speed tradeoff) -
low pass filter setting (should decrease jitter at the expense of responsiveness and latency)These settings seem mostly unnecessary now that I've played with them. Low pass filter increases latency and decreases throughput too much, and the amount of noise and accuracy seems similar on different scale settings. Compared to a real DS4, the highest speeds and scales actually seems right. Their IMU is extremely similar in capabilities anyways, so I'm not too surprised. - Orientation options: N W S E aka 0 90 180 270
- Upside-down checkbox
- Gyro calibration from within UI,
or a hotkey?
- Verify ideal default options
- PS3, Switch support?
- Optional: Make timestamp time dependent
- Optional: Add automatic gyro drift calibration at standstill
Have you checked the GP2040-CE documentation HERE to confirm this feature doesn't already exist?
Yes
Which problem is this feature request solving?
PS4, PS3, and Switch controllers support gyroscope and accelerometer aka IMU inputs. Many popular Switch games use it (Zelda BOTW/TOTK where it's required to complete some puzzles, Splatoon for precision aiming, optional Mario Kart steering control) and a handful of PS3 and PS4 titles do as well. Steam Input in particular allows heavy customization of controllers including gyro aiming, which makes PC mouse-based first and third person shooters enjoyable. GP2040-CE does not have any way of collecting or packaging motion data.
Describe the solution you would like to see
It looks like analog controls are being actively worked on (which is awesome BTW!), but adding motion controls as well would make it fairly trivial to create nearly fully-featured handheld controllers for Switch, PS3, and PS4 systems.
Adding motion to PS4 mode especially would help in making more featureful controllers for PC/Linux(Steam Deck)/Steam Input since that could support analog triggers and a touchpad as well. It might be easiest to add motion to this mode as it's currently just padded out (or in the mystery field I guess) in the report descriptor: https://github.com/OpenStickCommunity/GP2040-CE/blob/13d8daa41eea633da0f23981d992554def5931e1/headers/gamepad/descriptors/PS4Descriptors.h#L129
Looks like the descriptor for PS3 cuts off before it gets to the motion data. I'm pretty unfamiliar with USB/HID descriptors. How easy would it be to extend this to include motion data? https://github.com/OpenStickCommunity/GP2040-CE/blob/13d8daa41eea633da0f23981d992554def5931e1/headers/gamepad/descriptors/HIDDescriptors.h#L122
I don't know enough about Switch to have any suggestions there and its descriptor looks... more barebones/less documented than the other ones? Or I'm just not looking in the right places. Anyways I've found some relevant discussion as well as a what appears to be a PR for a complete Switch Pro Controller emulator for Arduino Pro Micro. I've linked all of that below.
Of course we would also need support for a 6DoF IMU chip to make any of this usable. It appears that many IMUs support both I2C and SPI. For starters, Switch controllers supposedly to use an LSM6DS, for which Sparkfun has a breakout board, documentation, and a tutorial. (EDIT: MPU6050 breakouts are also widely available and way cheaper)
References:
https://www.psdevwiki.com/ps4/DS4-USB#Data_Format
http://eleccelerator.com/wiki/index.php/DualShock_3#HID_Report_Mapping
https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/issues/7
https://github.com/matlo/GIMX-firmwares/pull/5/files
https://www.sparkfun.com/products/18020
Describe alternatives you've considered
I've just had a look around the repo and found the relevant documentation I've linked above. Hacking together a custom controller firmware might be possible with GIMX as a base, but I'd much prefer to use an RP2040 board instead of an Arduino if/when I start trying to build controllers.
Can you submit a pull request?
WIP
Are you planning on working on this feature yourself?
PS4 WIP. Not sure about PS3 or Switch yet.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the DS4-IMU branch and the referenced headers/gamepad/descriptors/PS4Descriptors.h and HIDDescriptors.h files first. Compare the existing PS4 work with the requested PS3 and Switch support, then verify the scope for IMU calibration and reporting; done requires a reviewed implementation rather than the current WIP state.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100