Thursday 25 August 2011

PS button difficulties

Activating this PS buttons is more difficult than expected. I found different sources that claims to succesfully make this button work:
The first one is a nice project using a breakout board with an AVR to implement a USB controller for PS3 with home button enabled. The second one is another project with AVR chip, it's a controller simulator that gets its input from a serial port intead of directly checking button states. Both projects provides complete source code which is pretty nice. The third one is a thread discussion of people trying to make the button work, it gives some information of what seems required or not but gives no code whatsoever.

Everybody seems to agree the magic bytes are:
0x21, 0x26, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00
Everybody agree these bytes should be sent to the host after the HID report descriptor. But it is not clear if these bytes should be sent in the data stage of the setup request, or in a spearate transfer just after. But from what people says in the thread, it seems it should be in the data stage. But it's just speculation as I can't find any confirmation in the projects source code. For the first project, the magic bytes are sent when the hosts does a HID class request GET_REPORT (not on a standard request GET_DESCRIPTOR that actually sends the HID report descriptor). And for the second project, the bytes are defined but does not used at all.

As the only project that seems to potentially work is the first one (it actually uses the magic bytes), I tried to use the same HID report descriptor and report data structure they have, added the piece of code sending the magic bytes on GET_REPORT. But no success. I don't event get the regular button events to be catched by the host. I highly doupt the report descriptor does not correspond the actual report data strucutre, in additoin this report descriptor contains some Sony specific stuff. If they are required to make it work on PS3 i'm pretty sure it will make it fail on Mac. The PS3 never send any GET_REPORT request. Not sure if this is due to the fact I use two endpoints (ep0 for control ep1 for Interrupt) whereas the project uses juste one endpoint (ep0). I don't think so as the original PS3 controller uses three endpoints. The number of endpoint should not alter the behavior.

It is pretty unclear what are the conditions the HID report must match to work with the magic bytes and make the PS3 happy. The thread lists some requirements point, but again it's just conversational and not strictly clear (is order important? etc...). It is not clear also if a specific vendor/product ID should be used. I guess no, because I doupt Sony does a firmware update anytime a new controller construcor pops-out.

I'm going to do some more investigation with different report variations. It saw the original PS3 controller defines some Feature fields in the reports, and there features sizes are 8 bytes just like the magic bytes. May be a hint?

8 comments:

  1. Did you solve the home button problem? There is an interesting project called AVR Joystick of micronics.de that I wish to adapt to PS3. Could you have a look?

    ReplyDelete
  2. Not yet, it's on hold for some time now, not sure when i'll get back to it. I checked http://www.mictronics.de/projects/avr-usb-joystick/ you talked about. It does not seem to handle any PS3 specifics. Seems to be a simple USB Joystick example.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Just chiming in here to help anyone out, from what I know anyways. Yes you need to wait for a feature get request and also the ID. If your report is using report ID 0 ( like the PS3 ) the you look for 0x0300 ( or first byte of 3 and second byte of 0 on v-usb). This should only really happen during start up. Now it also is important that you have that feature report in the descriptor.

    My observations thus far are that the PS3 is constantly sending this feature report. That is not how it should work IMO but I have not used vender specific before. I have used the physical layer PID and for its feature reports they are only when needed and done only at start up. When I attempt to reply with these magic bytes nothing happens. Maybe this is because the ps3 is not getting what its looking for, so it keep trying? If I learn more ill post it.

    ReplyDelete
  5. Just a heads up my issue was local, the feature report is working but my reply does not. The PS3 does send 0x0300 feature report ID 0 and I have confirmed that is true. when I attempt a reply and then later try button 13 (HOME), nothing happens.

    For me I use a report ID for my device. So I get 0x0301 from the PS3 and I did try adding a report ID 1 to the beginning of the magic bytes but still no luck. However this proves the PS3 is just a regular USB host since it adapts to my modified descriptor.

    I only wish there was a way to log USB traffic on the PS3 ( not attaching it to a host computer ). I don't actually own a PS3 but have a friend testing for me.

    I hope to figure this out and if I do I’ll post results but I see no reason anyone should have troubles with a normal PS3 descriptor. And no, I do not feel the device set up needs anything fancy.


    ReplyDelete
  6. Wow I learned something interesting. It does depend on how out lay out the descriptor. For example if I take the suggest descriptor (one all over the net) and set it up so that the analogs are up top the home button will not work. My current project has the analogs before the buttons and I believe that is my issue. Rearranging a descriptor is not all that easy so it may take time before I figure this out. I bet anyone trying their own project on a PS3 with home button issue may now have a shot with this tip.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  7. Ahh, bingo that was it! What a nasty little thing... For whatever reason, I don't know, the buttons must be first in the descriptor. Meaning the buffer[0] = button 1-8 and buffer[1] = buttons 9-16.

    To recap: You need the following.
    1: add the check for 0x3000 in usb set up. (0x3001 if you have a report ID)
    2: reply with magic bytes.
    3: buttons must be the first int the report buffer poll
    4: you need the vendor specific, or at least 1 usage.

    example
    0x06, 0x00, 0xff, // USAGE_PAGE (Vendor Specific)
    0x09, 0x20, // Unknown
    0x75, 0x08, // REPORT_SIZE (8)
    0x95, 0x01, // REPORT_COUNT (1)
    0x81, 0x02, // INPUT (Data,Var,Abs)

    Without these in my code, ps home didn’t work.

    If you need help send email to my user name above at yahoo dot com. ;) I own you ps3!

    ReplyDelete