PSP USB HID descriptor

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
OldPrisoneR
Posts: 53
Joined: Thu Mar 20, 2008 2:33 am

PSP USB HID descriptor

Post by OldPrisoneR »

Hello :p

I'm trying to write USBdriver for PSP to let the host detect it as a HID device (GAMEPAD)

First problem:
I need send HID descriptor to the host, but currently I don't know how to achieve that aim :(

PSP sends dev. descriptor
then it sends config., interface and EP descriptors...
But we need it to send config., interface, HID and EP descriptors...

I suppose we must try to with sceUsbbdReqRecv and sceUsbbdReqSend
Anyway, any suggestions are welcome :)

I've done some code, check it, if you are interesting in

source code
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

Something to do with USB Host Mode support?
Last edited by KickinAezz on Mon Nov 10, 2008 1:53 pm, edited 1 time in total.
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.
User avatar
ghost_gluck
Posts: 7
Joined: Fri Apr 04, 2008 5:09 am

Post by ghost_gluck »

May be, this information is helpful, see below:

Code: Select all

char ReportDescriptor[77] = {
    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x15, 0x00,                    // LOGICAL_MINIMUM (0)
    0x09, 0x04,                    // USAGE (Joystick)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x05, 0x02,                    //   USAGE_PAGE (Simulation Controls)
    0x09, 0xbb,                    //   USAGE (Throttle)
    0x15, 0x81,                    //   LOGICAL_MINIMUM (-127)
    0x25, 0x7f,                    //   LOGICAL_MAXIMUM (127)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
    0x05, 0x01,                    //   USAGE_PAGE (Generic Desktop)
    0x09, 0x01,                    //   USAGE (Pointer)
    0xa1, 0x00,                    //   COLLECTION (Physical)
    0x09, 0x30,                    //     USAGE (X)
    0x09, 0x31,                    //     USAGE (Y)
    0x95, 0x02,                    //     REPORT_COUNT (2)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
    0xc0,                          //   END_COLLECTION
    0x09, 0x39,                    //   USAGE (Hat switch)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x03,                    //   LOGICAL_MAXIMUM (3)
    0x35, 0x00,                    //   PHYSICAL_MINIMUM (0)
    0x46, 0x0e, 0x01,              //   PHYSICAL_MAXIMUM (270)
    0x65, 0x14,                    //   UNIT (Eng Rot:Angular Pos)
    0x75, 0x04,                    //   REPORT_SIZE (4)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
    0x05, 0x09,                    //   USAGE_PAGE (Button)
    0x19, 0x01,                    //   USAGE_MINIMUM (Button 1)
    0x29, 0x04,                    //   USAGE_MAXIMUM (Button 4)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x95, 0x04,                    //   REPORT_COUNT (4)
    0x55, 0x00,                    //   UNIT_EXPONENT (0)
    0x65, 0x00,                    //   UNIT (None)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
    0xc0                           // END_COLLECTION
};
This information was get from HID Descriptor tool, profile - joystk.hid (http://www.usb.org/developers/hidpage/dt2_4.zip). from http://www.usb.org/developers/hidpage
Probably, you were used this tool, but i couldn't see RootDescriptor's description in sources.
OldPrisoneR
Posts: 53
Joined: Thu Mar 20, 2008 2:33 am

Post by OldPrisoneR »

ghost_gluck wrote:...but i couldn't see RootDescriptor's description in sources.
Currently I'm trying to figure out how to send that HID descriptor
bearing in mind that idenfication process is as follows(approx):
host> GET DEVICE DESCRIPTOR
psp sends DEVICE DESCRIPTOR
host> GET DESCRIPTORS
psp sends CONFIG. INTERFACE and EP DESCRIPTORs
But we need also to send HID descriptor between INTERFACE and EP DESCRIPTORs at this stage.
And this is the main problem(currently)...
At last we must send ReportDescriptor (thx for example and links btw :))
So that's why I haven't included ReportDescriptor in source code
User avatar
ghost_gluck
Posts: 7
Joined: Fri Apr 04, 2008 5:09 am

Post by ghost_gluck »

Now I find USB Joystick Project on PIC18F2550 with sources at http://www.helmpcb.com/Electronics/USBJ ... stick.aspx
Project contain Schematic and Source files http://www.helmpcb.com/Electronics/USBJ ... -35-23.zip

See USB Joystick\Source Code\USBdsc.c, line 36.
unsigned char const DescTables[] = {
}
At line 100 begins Endpoint1 TX descriptor and at end of this descriptor, starts ReportDescriptor from joystk.hid

I don't develop HID devices or devices, based on PIC microcontrollers and i don't fully understand, how HID layer and PIC hardware works. But i find in the source directory USBJoystick_callertable.txt. This file contains list of called functions and they order. May be, this information is helpful to you.

I download mikroC v8 compiler http://www.mikroe.com/en/compilers/mikroc/pic/ for investigate functions and documentation about libraries, included in USBJoystick project.

Additional Projects http://pe.ece.olin.edu/ece/projects.html

PS. Sorry for my bad English, because it is not my native language.
mydipper
Posts: 6
Joined: Sun Oct 05, 2008 2:51 am

Post by mydipper »

I also found the USBJoy project on AVR ATmega8.

website :
http://www.raijuu.net/2008/08/usbjoy/

source code :
http://avrusb.wikidot.com/local--files/ ... 060108.zip

It contains the source code for PlayStation and PlayStation 2 joypad.

However, it is hard for me to follow, because my technical base is not on the programming..

Sorry for bad English, too ;)
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

KickinAezz wrote:Something to do with USB Host Mode support?
No its got nothing to do with host mode. HID is slave....

@OP, it looks like all you need to do is figure out how to use those two functions. Ask SilverSpring or someone, he would probably have the most vast knowledge of all the firmware functions.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Re: PSP USB HID descriptor

Post by jimparis »

OldPrisoneR wrote:Hello :p

I'm trying to write USBdriver for PSP to let the host detect it as a HID device (GAMEPAD)

First problem:
I need send HID descriptor to the host, but currently I don't know how to achieve that aim :(

PSP sends dev. descriptor
then it sends config., interface and EP descriptors...
But we need it to send config., interface, HID and EP descriptors...
Take a look at the source for libhid. They request the HID descriptor with a control request on endpoint 0x81:

Code: Select all

  TRACE("retrieving HID descriptor for USB device %s...", hidif->id);
  int len = usb_control_msg(hidif->dev_handle,
      USB_ENDPOINT_IN+1,
      USB_REQ_GET_DESCRIPTOR,
      &#40;USB_DT_HID << 8&#41; + 0, hidif->interface,
      &#40;char*&#41;buffer, BUFLEN,
      USB_TIMEOUT&#41;;
I imagine you'll just need to listen for this control request and respond with your descriptor.
User avatar
ghost_gluck
Posts: 7
Joined: Fri Apr 04, 2008 5:09 am

Post by ghost_gluck »

In my opinion, UsbRequest function from source code is a callback, which called when data received to the device.

IMHO this function can handle all request from HOST to DEVICE.
But i don't know how to write from DEVICE to HOST.
Do UsbData might be used as input and output buffer?
If No - how i can manipulate with data?

I install USBTrace from http://sysnucleus.com/ to get raw exchange protocol between devices.

Do i need to start send descriptors at start?
What kind of packets i need to send at start?

jimparis, Did you mean about libusb for HOST or DEVICE?
If HOST then DEVICE must be HID compatible and standard drivers was used for USB HID Joystick from microsoft.
If DEVICE - please specify, where we can download port of libhid for PSP.

OldPrisoneR, As i see, you use part of usbhostfs driver.
Sorry for terrible english. My native language is C++...
OldPrisoneR
Posts: 53
Joined: Thu Mar 20, 2008 2:33 am

Post by OldPrisoneR »

In my opinion, UsbRequest function from source code is a callback, which called when data received to the device.
Probably yes, but at first we must send all necessary descriptors
(cuz currently, as you may see, it's not called at all)
But i don't know how to write from DEVICE to HOST.
sceUsbbdReqSend - IN for HOST
sceUsbbdReqRecv - OUT for HOST
Just fill UsbdDeviceReq structure propertly
Do i need to start send descriptors at start?
What kind of packets i need to send at start?
You see, when you call sceUsbActivate PSP automaticly send all descriptors which you have set up in UsbDriver structure - and that's the main problem
jimparis, Did you mean about libusb for HOST or DEVICE?
If HOST then DEVICE must be HID compatible and standard drivers was used for USB HID Joystick from microsoft.
If DEVICE - please specify, where we can download port of libhid for PSP.
He ment libhid for PC no doubts :p

P.S.: I've used RemoteJoy src ;) thx TyRaNiD
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

ghost_gluck wrote:In my opinion, UsbRequest function from source code is a callback, which called when data received to the device.

IMHO this function can handle all request from HOST to DEVICE.
But i don't know how to write from DEVICE to HOST.
All USB transactions are originated by the host. The device writes data to the host ONLY in response to a request from the host.
Do i need to start send descriptors at start?
What kind of packets i need to send at start?
You just need to respond to the requests for descriptors -- see my post above.
jimparis, Did you mean about libusb for HOST or DEVICE?
If HOST then DEVICE must be HID compatible and standard drivers was used for USB HID Joystick from microsoft.
If DEVICE - please specify, where we can download port of libhid for PSP.
I'm talking about libhid on the host. This has nothing to do with Microsoft (?!) HID drivers -- it is a complete HID layer on top of libusb. You can use that source to see how the HID descriptors are requested from the device. Then you can code the device side to watch for those requests and respond accordingly.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

OldPrisoneR wrote:You see, when you call sceUsbActivate PSP automaticly send all descriptors which you have set up in UsbDriver structure - and that's the main problem
So you never see the control request that I outlined in my post above? If not, you're going to have to dig deeper into sceUsbActivate and see why that request is not making it through.
User avatar
ghost_gluck
Posts: 7
Joined: Fri Apr 04, 2008 5:09 am

Post by ghost_gluck »

jimparis wrote:
ghost_gluck wrote:In my opinion, UsbRequest function from source code is a callback, which called when data received to the device.

IMHO this function can handle all request from HOST to DEVICE.
But i don't know how to write from DEVICE to HOST.
All USB transactions are originated by the host. The device writes data to the host ONLY in response to a request from the host.
As "write from DEVICE to HOST" i mean transmit data to output buffer or send response.
Do i need to start send descriptors at start?
What kind of packets i need to send at start?
You just need to respond to the requests for descriptors -- see my post above.
Now i know how implemented device registration and data exchange on PSP after I was investigating documentation and source code of the sample and usbhostfs.
jimparis, Did you mean about libusb for HOST or DEVICE?
If HOST then DEVICE must be HID compatible and standard drivers was used for USB HID Joystick from microsoft.
If DEVICE - please specify, where we can download port of libhid for PSP.
I'm talking about libhid on the host. This has nothing to do with Microsoft (?!) HID drivers -- it is a complete HID layer on top of libusb. You can use that source to see how the HID descriptors are requested from the device. Then you can code the device side to watch for those requests and respond accordingly.
As "Microsoft HID drivers" i mean default HID layer implemetation in M$ Windoze.
I could not saw HID descriptor in USB trace log in answer on request "GET_DESCRIPTOR_FROM_DEVICE" and device could not recognized by OS, because device's configuration block does not have HID descriptor and device identify itself as HID compatible. aren't?

Now i don't know, how to attach HID Descriptor to the configuration. May be it's not possible at this moment. May be new firmware have new functions like sceUsbbdRegisterEx and data structures to register device with all descriptors.

P.S. More detail investigation of usb.prx is need.
Sorry for terrible english. My native language is C++...
OldPrisoneR
Posts: 53
Joined: Thu Mar 20, 2008 2:33 am

Post by OldPrisoneR »

It makes me wonder, why there are two pointers in UsbData::Interfaces (pinterdesc[2])
Is that means we can use two interface descriptors?

If that's true we can send HID descriptor (it has the same size) instead of second interface...
but where should we put the second interface in?
UsbData::InterDesc::desc has only 12 bytes
And we need at least 9+9=18 bytes

BTW, wtf is UsbData::InterDesc::pad for??? :p
hnaves
Posts: 30
Joined: Tue Feb 03, 2009 3:01 am

Post by hnaves »

I managed to implement the HID descriptor

http://ifile.it/1qwfehc
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Nice, certainly plenty of stuff I never worked out when implementing usbhostfs, surprised it works ;) At least I can see why the padding was there (I kinda guessed it might be something like extra fields but I didn't need to spend any extra time finding out).

Now we will see if any of those people wanting to make the PSP a gamepad come back and do some work ;)
Post Reply