Interfacing Logitech Gamepad with Arduino using USB Host Shield

Hi to all Arduino developers!

I am trying to interface Logitech Dual Action Gamepad http://www.logitech.com/gaming/controllers/devices/288 with Arduino using oleg's USB Host Shield 2.0. This host shield works with two version of code library.

  1. Legacy Host Library GitHub - felis/USB_Host_Shield: Libraries and code for Circuits@Home Arduino USB Host Shield
  2. Host Library 2.0 GitHub - felis/USB_Host_Shield_2.0: Revision 2.0 of USB Host Library for Arduino.

Library 2.0 supports USB Hub too. I want to Interface Gampad and other USB device (mostly USB touchscreen monitor) so I need Hub functionality working.

I started reading [this http://www.circuitsathome.com/communicating-arduino-with-hid-devices-part-1](http://this http://www.circuitsathome.com/communicating-arduino-with-hid-devices-part-1) article about how to read HID reports from Gamepad with Legacy Host Library .(Article is about USB mouce but Gamepad is almost the same). I test the programs on that article with Gamepad and it worked fine. But now I want to develop same sort of program with USB Hub and Library 2.0. and I have some confusion.

I am trying to write similar function to this one for Gamepad

void mouse1_init( void )
{
 byte rcode = 0;  //return code
 byte tmpdata;
 byte* byte_ptr = &tmpdata;
  /**/
  ep_record[ 0 ] = *( Usb.getDevTableEntry( 0,0 ));  //copy endpoint 0 parameters
  ep_record[ 1 ].MaxPktSize = EP_MAXPKTSIZE;
  ep_record[ 1 ].sndToggle = bmSNDTOG0;
  ep_record[ 1 ].rcvToggle = bmRCVTOG0;
  Usb.setDevTableEntry( 1, ep_record );              //plug kbd.endpoint parameters to devtable
  /* Configure device */
  rcode = Usb.setConf( DEVADDR, 0, CONFVALUE );
  if( rcode ) {
    Serial.print("Error configuring mouse. Return code : ");
    Serial.println( rcode, HEX );
    while(1);  //stop
  }//if( rcode...
  rcode = Usb.getIdle( DEVADDR, 0, 0, 0, (char *)byte_ptr );
  if( rcode ) {
    Serial.print("Get Idle error. Return code : ");
    Serial.println( rcode, HEX );
    while(1);  //stop
  }
  Serial.print("Idle Rate: ");
  Serial.print(( tmpdata * 4 ), DEC );        //rate is returned in multiples of 4ms
  Serial.println(" ms");
  tmpdata = 0;
  rcode = Usb.setIdle( DEVADDR, 0, 0, 0, tmpdata );
  if( rcode ) {
    Serial.print("Set Idle error. Return code : ");
    Serial.println( rcode, HEX );
    while(1);  //stop
  }
  Usb.setUsbTaskState( USB_STATE_RUNNING );
  return;
}
  1. With new Library do I need to initialize the gamepad this way?
  2. New library does not have get/setDevTableEntry. Is it same as get/setEpInfoEntry?
  3. getIdle/setIdle are not in new Library but that should be ok i think.

So how does the initialization process go for HID devices with new library. I have attached output of Hub test program and HID report descriptor of Gamepad.

I would appreciate your help and many thanks!

Parin

HID report descriptor.doc (28.5 KB)

HUB+GAMEPAD OUTPUT.txt (1.6 KB)