forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PSP USB HID descriptor

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
OldPrisoneR



Joined: 20 Mar 2008
Posts: 53

PostPosted: Mon Nov 10, 2008 2:32 am    Post subject: PSP USB HID descriptor Reply with quote

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
Back to top
View user's profile Send private message
KickinAezz



Joined: 03 Jun 2007
Posts: 328

PostPosted: Mon Nov 10, 2008 11:26 am    Post subject: Reply with quote

Something to do with USB Host Mode support?
_________________
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.


Last edited by KickinAezz on Mon Nov 10, 2008 1:53 pm; edited 1 time in total
Back to top
View user's profile Send private message
ghost_gluck



Joined: 04 Apr 2008
Posts: 7

PostPosted: Mon Nov 10, 2008 12:16 pm    Post subject: Reply with quote

May be, this information is helpful, see below:

Code:

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.
Back to top
View user's profile Send private message
OldPrisoneR



Joined: 20 Mar 2008
Posts: 53

PostPosted: Mon Nov 10, 2008 6:08 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
ghost_gluck



Joined: 04 Apr 2008
Posts: 7

PostPosted: Mon Nov 10, 2008 8:01 pm    Post subject: Reply with quote

Now I find USB Joystick Project on PIC18F2550 with sources at http://www.helmpcb.com/Electronics/USBJoystick/USBJoystick.aspx
Project contain Schematic and Source files http://www.helmpcb.com/Electronics/USBJoystick/USB%20Joystick%2001-03-08,%2016-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.
Back to top
View user's profile Send private message
mydipper



Joined: 05 Oct 2008
Posts: 6

PostPosted: Mon Nov 10, 2008 9:26 pm    Post subject: Reply with quote

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/project:usbjoy/usbjoy_20060108.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 ;)
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Tue Nov 11, 2008 2:05 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Tue Nov 11, 2008 5:49 am    Post subject: Re: PSP USB HID descriptor Reply with quote

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:
  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,
      (USB_DT_HID << 8) + 0, hidif->interface,
      (char*)buffer, BUFLEN,
      USB_TIMEOUT);

I imagine you'll just need to listen for this control request and respond with your descriptor.
Back to top
View user's profile Send private message
ghost_gluck



Joined: 04 Apr 2008
Posts: 7

PostPosted: Tue Nov 11, 2008 7:13 pm    Post subject: Reply with quote

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++...
Back to top
View user's profile Send private message
OldPrisoneR



Joined: 20 Mar 2008
Posts: 53

PostPosted: Wed Nov 12, 2008 1:32 am    Post subject: Reply with quote

Quote:
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)
Quote:
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
Quote:
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
Quote:
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
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Wed Nov 12, 2008 10:14 am    Post subject: Reply with quote

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.

Quote:
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.

Quote:
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.
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Wed Nov 12, 2008 10:16 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
ghost_gluck



Joined: 04 Apr 2008
Posts: 7

PostPosted: Wed Nov 12, 2008 9:53 pm    Post subject: Reply with quote

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.

Quote:

Quote:
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.

Quote:

Quote:
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++...
Back to top
View user's profile Send private message
OldPrisoneR



Joined: 20 Mar 2008
Posts: 53

PostPosted: Thu Nov 13, 2008 1:40 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
hnaves



Joined: 03 Feb 2009
Posts: 30

PostPosted: Sat Jun 06, 2009 7:39 am    Post subject: Reply with quote

I managed to implement the HID descriptor

http://ifile.it/1qwfehc
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sat Jun 06, 2009 6:22 pm    Post subject: Reply with quote

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 ;)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group