DualShock 3 support

91 views
Skip to first unread message

Marcelo Lorenzati

unread,
Jul 5, 2020, 12:23:35 AM7/5/20
to Unijoysticle
Hello, I'm starting the build process of the unijoysticle 2, with an ESP32S dev kit, I was checking the supported devices and the Dual Shock 3 is not included, is it just including the Device HID or is there any code wise requirement? Could be supported?

Ricardo Quesada

unread,
Jul 5, 2020, 12:41:36 AM7/5/20
to Marcelo Lorenzati, Unijoysticle
My understanding is that DS3 doesn't have the bluetooth discovery
code. If you pair the DS3 via USB, then it should work. But
Unijoysticle doesn't have USB, so, no support for DS3.

On Sat, Jul 4, 2020 at 9:23 PM Marcelo Lorenzati <mlore...@gmail.com> wrote:
>
> Hello, I'm starting the build process of the unijoysticle 2, with an ESP32S dev kit, I was checking the supported devices and the Dual Shock 3 is not included, is it just including the Device HID or is there any code wise requirement? Could be supported?
>
> --
> You received this message because you are subscribed to the Google Groups "Unijoysticle" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to unijoysticle...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/unijoysticle/9e4d444a-256e-4572-b7fe-a2b3691ab6a3o%40googlegroups.com.

Marcelo Lorenzati

unread,
Jul 5, 2020, 1:13:52 AM7/5/20
to Unijoysticle
Thanks for the prompt reply! So up to now I now near to zero about the bt stack and how it's used on the ESP but I found a post about using the PlayStation 3 controller in Bluetooth mode with Linux in C, I know its dependant on the SW stack on linux but I thought it could be taken the same principle.
I also understand that pairing is done first through USB, but if there is a way of inspecting the pairing wether by USB or by using an android app like the Sixaxis Controller would be an option.


On Sunday, 5 July 2020 01:41:36 UTC-3, Ricardo Quesada wrote:
My understanding is that DS3 doesn't have the bluetooth discovery
code. If you pair the DS3 via USB, then it should work. But
Unijoysticle doesn't have USB, so, no support for DS3.

On Sat, Jul 4, 2020 at 9:23 PM Marcelo Lorenzati <mlore...@gmail.com> wrote:
>
> Hello, I'm starting the build process of the unijoysticle 2, with an ESP32S dev kit, I was checking the supported devices and the Dual Shock 3 is not included, is it just including the Device HID or is there any code wise requirement? Could be supported?
>
> --
> You received this message because you are subscribed to the Google Groups "Unijoysticle" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to unijoy...@googlegroups.com.

Ricardo Quesada

unread,
Jul 5, 2020, 9:00:31 AM7/5/20
to Marcelo Lorenzati, Unijoysticle
Yes, Linux has support for DS3.
But as the article mentions, if the gamepad is not already paired, you
have to pair it using USB first (see section 3.1 of the article)
> To unsubscribe from this group and stop receiving emails from it, send an email to unijoysticle...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/unijoysticle/f519eaae-355c-455e-a154-d69e109bc4ado%40googlegroups.com.

Marcelo Lorenzati

unread,
Jul 5, 2020, 6:11:36 PM7/5/20
to Unijoysticle
I was thinking a sort of companion pc app to connect to usb, where you share credentianls to the unijoysticle through wifi.
I know, its easier to get other kind of bt devices :).
Thanks!

Ricardo Quesada

unread,
Jul 5, 2020, 8:00:26 PM7/5/20
to Marcelo Lorenzati, Unijoysticle
yes, that should be possible, I guess. It is not something that I have
in my roadmap.
But If you want to work on that, great.
> To unsubscribe from this group and stop receiving emails from it, send an email to unijoysticle...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/unijoysticle/d7968c9c-6c79-43cf-99ad-21ff62c0b3ceo%40googlegroups.com.

Marce

unread,
Jul 8, 2020, 8:05:01 PM7/8/20
to Ricardo Quesada, Unijoysticle
Sharing the prototype board I built
image.png
image.png
Until I get a supported bluetooth controller will remain sitting the board, do you know if there is any android app that properly simulates a BT controller with the proper pairing process?
Best,
Marcelo

Ricardo Quesada

unread,
Jul 8, 2020, 9:42:19 PM7/8/20
to Marce, Unijoysticle
nice!

Unfortunately I couldn't find any Android app that simulates a Bluetooth Classic gamepad... although it shouldn't be too hard to create one (assuming that Android exposes the needed APIs).

Marce

unread,
Jul 10, 2020, 2:27:57 AM7/10/20
to Ricardo Quesada, Unijoysticle
Ok, after some brief investigation, it is just as simple as using an application to update the master where the ds3 will connect to.

I placed the mac address reported by the unijoysticle and after I press the PS button I get a request in the unijoysticle:

--> GAP_EVENT_INQUIRY_COMPLETE
--> Scanning for new devices...
--> GAP_EVENT_INQUIRY_COMPLETE
--> Scanning for new devices...
--> HCI_EVENT_CONNECTION_REQUEST: link_type = 1 <--
on_hci_connection_request from: address = 04:98:F3:BF:67:79, cod=0x0508
--> HCI_EVENT_ROLE_CHANGE
--> HCI_EVENT_CONNECTION_COMPLETE
--> HCI_EVENT_COMMAND_COMPLETE: opcode = 0x040c - status=0
--> HCI_EVENT_PIN_CODE_REQUEST
79 67 BF F3 98 04
[00:00:20.909] LOG -- hci.c.4098: hci_send_cmd called but cannot send packet now
Using pin code: --> GAP_EVENT_INQUIRY_COMPLETE
--> Scanning for new devices...

What would be missing to honor the DS3 request?

Ricardo Quesada

unread,
Jul 10, 2020, 9:53:47 AM7/10/20
to Marce, Unijoysticle
I wouldn't know. 

Just a few things to keep in mind:
 - in theory, esp-idf 4.1-beta2 fixes an issue on reconnects... you might want to try it, although I haven't tested it.

Try setting, right at the beginning, when initializing bluetooth (in uni_bluetooth.c):
    gap_set_security_level(0);


That being said, usually when a device is paired, no only the mac address is saved, but also some kind of key.
But I guess if you se "security level 0", no key will be needed (???)... I'm just guessing.



somewhere in the code set:

Marcelo Lorenzati

unread,
Sep 6, 2020, 10:31:31 PM9/6/20
to Unijoysticle
I was able to make the connection to the DS3, but I need some pointers since I'm new with btstack and the unijoysticle.
-First point is that I used latest idf version.
-Then I needed to set gap security to zero (ds3 does not care much for security), if not request pin and does not continue.
-On side note you need to set the mac address of the esp32 to the ds3 so it connects when pushing the ps button(not a deal in this discussion)
-I implemented the uni_hid_parser methods for ds3, but the issue is that I need first to enable the reports for PS3
Tried to added in a the setup callback, but is not called prior the set player. when setting it right after the detection of the controller type, the enabling works (y receive reports).
-setting the leds are not working for me at the moment :( I might be mapping wrongly the data.

Could I push it in a branch to have collaboration?

Ricardo Quesada

unread,
Sep 7, 2020, 12:20:02 PM9/7/20
to Marcelo Lorenzati, Unijoysticle
Hi Marcelo,

where is your code? just let us know where it is hosted and I'll try it... I have a dual-six-axis clone... I can try with it.

Marce

unread,
Sep 7, 2020, 12:56:10 PM9/7/20
to Ricardo Quesada, Unijoysticle
I can either make a branch in your repo or a branch in a fork of your repo.
I clean it a little bit and push it, just let me know.
I took as reference to understand activation and parsing:

You received this message because you are subscribed to a topic in the Google Groups "Unijoysticle" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/unijoysticle/KFXjJELD-00/unsubscribe.
To unsubscribe from this group and all its topics, send an email to unijoysticle...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/unijoysticle/CAK7XcBenEwjSKFqYmEMzoFJiuuUSK8qAAxdaF%3Dszmx2DzAf6HQ%40mail.gmail.com.

Ricardo Quesada

unread,
Sep 7, 2020, 1:03:04 PM9/7/20
to Marce, Unijoysticle
Yes, 

I think the best way is that you fork the unijoysticle repo, create a branch in your fork (e.g: "ds3_support"), and once you have it working you can send the pull request.

Marce

unread,
Sep 7, 2020, 5:53:44 PM9/7/20
to Ricardo Quesada, Unijoysticle
Ok I created this PR in https://gitlab.com/ricardoquesada/unijoysticle2/-/merge_requests/4

What it does:
-Authenticates, the device will not shut down
-Enables reports, now the raw reports are received, the disclaimer is where is being done, IIUC it should be in the setup
-Parses correctly the buttons and the axis, more work to detect when to update is needed.

What it does not:
-Send proper commands to update leds
-Manage the rumble

How to connect:
Set ESP32 mac address into DS by connecting it to a PC and run:
Hope you can help, the project is really good and I think DS3 would be nice addition to the supported list

Best,
Marcelo Lorenzati

Ricardo Quesada

unread,
Sep 7, 2020, 6:35:03 PM9/7/20
to Marce, Unijoysticle
Thanks Marcelo,

I'll try it with Six-Axis clone... hopefully it works... if it doesn't i'll get an original one and I'll try it with it.

Marce

unread,
Sep 7, 2020, 6:48:05 PM9/7/20
to Ricardo Quesada, Unijoysticle
Cool! I made a minor update due to a typo... updating dpad instead of button, and some level of update change detection.

Marce

unread,
Sep 7, 2020, 11:12:22 PM9/7/20
to Ricardo Quesada, Unijoysticle
JFYI, i tested the current state of the art and works pretty fine!
I just think I have inverted the accelerometers in X axis...

Marce

unread,
Sep 8, 2020, 1:31:59 AM9/8/20
to Ricardo Quesada, Unijoysticle
Also I saw what is the problem about either setting the leds or enabling, its using the hid_control_cid instead of the hid_interrupt_cid, which does not have a queuing mechanism.

 l2cap_send(d->hid_control_cidpacket_buffer + PACKET_OFFSETsizeof(ds3_control_packet)-PACKET_OFFSET);

Marce

unread,
Sep 8, 2020, 2:26:52 AM9/8/20
to Ricardo Quesada, Unijoysticle
Everything is updated and working as a first approach. There is a delayed retry timer to try a failed control (which is just the first time when connected)

Let me know if it is ok.

Best

Marcelo Lorenzati

Ricardo Quesada

unread,
Sep 8, 2020, 11:23:24 AM9/8/20
to Marce, Unijoysticle
Thanks Marcelo,

I'll try during the weekend at the latest.

Marce

unread,
Sep 9, 2020, 8:44:14 PM9/9/20
to Ricardo Quesada, Unijoysticle
Perfect! everything is updated and mapped from reports to the gamepad data.
Just one question to be sure, current code is not using brake/accelerate isn't it? I have it mapped, I see the correct value in the unijoy register, but is not being used ( I imagine is a pwm kind of signal to simulate discharge of internal Cap on pin 5 pin 9 of Joy 1 isn't it?)
Also, I saw a mouse implementation, is it simulating AMIGA Mouse? 

Ricardo Quesada

unread,
Sep 9, 2020, 10:16:18 PM9/9/20
to Marce, Unijoysticle
Great.

exactly that. For the moment they are not being used, but ideally they should be mapped to Pot 1 and Pot 2 for the C64 (perhaps for the Unijosyticle 3?).
The mouse for the Amiga / AtariSt is not finished yet.... something on my todo list.

Marce

unread,
Sep 10, 2020, 8:53:36 AM9/10/20
to Ricardo Quesada, Unijoysticle
IIRC on the schematics POTX an POTY (db9 pins 5 and 9) are already mapped into the esp to GPIO16 ang GPIO 33, and based on the functioning rational of the RC timed ADC of the C64 is just a matter of create a PWM signal on those pins, at least double the frequency of full C64 RC time (~512us).
With this you play with the carge/discharge time of the cap and it will work  without any other required change.
Just for reference:

What do you think?

Best

PD: I'm from Argentina :) So we can speak spanish if you like

Ricardo Quesada

unread,
Sep 10, 2020, 10:14:59 AM9/10/20
to Marce, Unijoysticle
yes, Joystick #1 has pins 5 and 9 mapped, mostly to support mouse on AtariST/Amiga.
For the C64 it is more complex... PWM might work. I haven't tried it yet, but please, feel free to test it. If it works, it would be great.

I tried other other methods, but I had issues in making it stable. Mostly related to the 3.3v of the ESP32 vs the 5v of the C64. As an example, with an Arduino I was able to have stable values.


[In this forum, let's keep discussing in English so other members can read our messages].

Ricardo Quesada

unread,
Sep 12, 2020, 12:41:30 AM9/12/20
to Marce, Unijoysticle
So I tested it today and found some issues, mostly because I don't know how to pair the gamepad.
What I did:

- Plug-in sixaxis to my linux machine
- run `sixaxispairer` using the mac-address used by Unijosyticle (libusb mode... the one that runs on linux)
- Run `sixaxispaier` again and reports the correct mac address
- Unplug the gamepad
- Press "Start" button in gamepad

... and nothing happened.
Should I press something else? what button combination should I press to establish the connection?


BTW: In case you are not familiar, you test the Unijoysticle without using a real device. Just do:

$ cd ~/unijoysticle2/firmware/tools
$ make -j
$ sudo ./unijoysticle

And if you pay attention to the 'gcc' output you will notice some warnings. Could you fix them?
You might not notice any warning if you are using the esp-idf toolchain because they are using an older gcc version.

Marce

unread,
Sep 12, 2020, 2:04:45 PM9/12/20
to Ricardo Quesada, Unijoysticle
Weird, I did that.
I checked in the logs the mac address of the unijoysticle.
I ran the sixaxis tool and wrote that mac to the DS3
I started the unijoysticle and pushed the PS button, you'll see in the logs the interaction until the led is set

attached my config if it is relevant, also the btstack and idf branches are:
btstack: master 
Author: Matthias Ringwald <matt...@ringwald.ch>
Date:   Sun Aug 30 13:33:00 2020 +0200
    Move btstack_linked_queue into core, mention in Changelog

idf:  v4.1

Hope it helps

I tested the amiga version also, for the 3 buttons, looks ok with one controller, with two I see weird stuff were one controller actions the button 2 and 3 of the other..


sdkconfig

Ricardo Quesada

unread,
Sep 12, 2020, 3:27:38 PM9/12/20
to Marce, Unijoysticle
Ok. Thanks.
I've just ordered an original sixaxis... perhaps the clone one has other issues... although I was able to connect it to my linux machine... I have to debug it and see what is happening. But I'll wait for the original sixaxis to arrive first.

Just to confirm, and assuming that you have bluetooth in your machine, could you try the unijoysticle that is in "firmware/tools" ? Just do:
$ cd unijoysticle2/firmware/tools
$ make
$ sudo ./unijoysticle

thanks.

Marce

unread,
Sep 12, 2020, 11:00:04 PM9/12/20
to Ricardo Quesada, Unijoysticle

Ricardo Quesada

unread,
Sep 17, 2020, 10:38:39 AM9/17/20
to Marce, Unijoysticle
I'm still waiting for the genuine-ds3 to arrive... seller hasn't shipped it yet *sigh*

Marce

unread,
Sep 17, 2020, 1:56:01 PM9/17/20
to Ricardo Quesada, Unijoysticle
I just built my third board of the Unijoysticle :) 
image.png
image.png

Ricardo Quesada

unread,
Sep 17, 2020, 2:17:46 PM9/17/20
to Marce, Unijoysticle
nice !!!
And with a case (bonus point!). Is that a 3d printed case?

Marce

unread,
Sep 17, 2020, 2:31:23 PM9/17/20
to Ricardo Quesada, Unijoysticle
Indeed, I own a prusa Mk3 and I started a while ago to model cases for fun.
We share a facebook group for fans of the Commodore (from C16, C64, C128, VIC20, AMIGA500 to 4000) and I build stuff to collaborate with them.


Ricardo Quesada

unread,
Sep 17, 2020, 2:41:54 PM9/17/20
to Marce, Unijoysticle
What software do you recommend to design the model?
I got my first 3d printer 1 month ago, and I'd like to design a case as well. In fact this morning I checked-in a change for the board that contains a mounting hole.
I was planning to use FreeCad. Not sure whether there is a better alternative for Linux.

I'd join the group, but I don't use Facebook.

Marce

unread,
Sep 17, 2020, 6:23:25 PM9/17/20
to Ricardo Quesada, Unijoysticle
Well since I work on multiple computers from pc to mac, I prefer web apps.
For 3D modeling I use https://www.tinkercad.com/ and for EDA I use https://easyeda.com/

Ricardo Quesada

unread,
Sep 17, 2020, 6:25:35 PM9/17/20
to Marce, Unijoysticle
ok. thanks!

Ricardo Quesada

unread,
Sep 19, 2020, 4:48:36 PM9/19/20
to Marce, Unijoysticle
genuine ds3 arrived.
works Ok, although it doesn't always connect. I'll merge your PR, and try to understand why it fails to connect on certain occasions.
Thanks for the patch!

Ricardo Quesada

unread,
Sep 19, 2020, 6:30:09 PM9/19/20
to Marce, Unijoysticle
I removed the retry-logic from ds3 and used it to uni_hid_device_queue func that is intended to do the retries.
now  setting the LEDs works in a reliable way, but I still cannot set the "stream report"... or at least I cannot receive it in a reliable way.
I know that it works (sometimes) because I saw it working once, but perhaps the "give me stream report" needs to be send after the handshake is finished ?

any idea?

Marce

unread,
Sep 19, 2020, 9:20:29 PM9/19/20
to Ricardo Quesada, Unijoysticle
Wow those are superv news!
I knew the retry logic was error prone, what I saw is that this goes to a different hid service used in the other controllers.
From what I saw, the unijoysticle tries to set the leds first instead of opening the report channel, that's why when it tries after setting the led the api says the service is busy.
My understanding was that your queuing was done for the other hid service, not the one I'm calling to start the reports.
Sorry for the fuzzy reply, I'm not in the computer with the repo and in gitlab the branch is closed due the merge.


Ricardo Quesada

unread,
Sep 19, 2020, 10:08:11 PM9/19/20
to Marce, Unijoysticle
Yes, thanks.
I had to add a "send_ctrl_report" that queues the sends in case it fails.

Yes, the issue was that the LEDs were being set before that "send stream" report and for some reason that was annoying the DS3 controller.
I fixed it by adding a state machine... I'm still testing it... but everything seems to be working now.
I'll commit my changes later tonight.

Marce

unread,
Sep 19, 2020, 10:52:25 PM9/19/20
to Ricardo Quesada, Unijoysticle
Excellent! I'll try when it is available.

Thanks!

Ricardo Quesada

unread,
Sep 20, 2020, 12:49:01 AM9/20/20
to Marce, Unijoysticle
fixed.
please, once you have time, give it a try to make sure everything is working.
thanks.

Marce

unread,
Sep 20, 2020, 9:47:30 PM9/20/20
to Ricardo Quesada, Unijoysticle
You are fast! I didn't have time this weekend, I'll give it a try.
This EOW was PS2 to amiga / Atari, Maxduinos and Epyx carts

Glad to have minimally collaborated in the unijoysticle, was fun to learn btstack with it.
Reply all
Reply to author
Forward
0 new messages