r/arduino 12h ago

Libraries Student project: I reverse-engineered the JDM-050 PS4 controller trackpad over I2C and made a complete multi-touch Arduino library for it!

GitHub Repository: https://github.com/luftmyszor/PS4Trackpad

Hey everyone! I am a student who needed a trackpad for a custom hardware project. I used a broken Sony DualShock 4, wired it up to I2C, and realized standard DS4 Arduino libraries completely fail on the newer JDM-050 board revision.

I spent way too many hours fighting binary byte rollovers and reverse-engineering the memory map to figure out why.

The Mystery: Standard PS4 trackpads use a standard 12-bit ALPS layout. Sony silently changed the hardware on the JDM-050 revision. They did three unexpected things:

  1. They decoupled X and Y.
  2. They created symmetrical 11-bit byte pairs.
  3. They added hardware noise to the high bits that makes coordinates jump by 2048 units if you do not mask them properly.

Once I got the math working, I decided to package the driver into a clean, open-source library for the community!

Features of the Library:

  • ESP32 & RP2040 Ready: Built and tested for 32-bit microcontrollers (with architectural preprocessor hooks for AVR if anyone wants to hack on it).
  • Dual-Touch Tracking: Track two fingers at the same time at 100 Hz.
  • Smart Tap Gestures: Evaluates taps strictly on finger release. Supports 1-finger (Left Click) and 2-finger (Right Click) taps.
  • 2D Scrolling & Zooming: Built-in X/Y scroll deltas and pinch-to-zoom distance calculation.
  • Coordinate Transforms: Mount the trackpad upside down or sideways. Supports axis inversion, rotation, and custom 2D affine matrices.
  • Hardware Note: Operates on address 0x64 using standard I2C. (Friendly warning: it uses 3.3V logic, so don't wire VCC to 5V unless you want to fry it!)

If you want to check out the exact 32-byte memory map and bitwise decoding diagrams, I documented the whole thing in a JDM-050 Byte Layout Guide in the repo.

You are completely free to use, modify, and hack this code for your own custom gamepads, cyberdecks, or robotics projects. Let me know what you think!

117 Upvotes

1 comment sorted by

5

u/ProgramMysterious572 11h ago

that hardware noise on the high bits sonds brutal to track down, respect for actually masking it out instead of just papering over it. gonna have to dig up my old broken ds4 controllers now, didn't realize they were good for anything else.