• AVR Freaks

PIC24FJ64GB002 as host for Xbox 360 controller

Author
simplerat
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2011/05/10 22:21:54
  • Location: 0
  • Status: offline
2011/05/30 13:58:16 (permalink)
0

PIC24FJ64GB002 as host for Xbox 360 controller

The overall project: I am trying to build something using the PIC24FJ64GB002 that will convert the USB output of all the buttons/joysticks of a wired xbox 360 controller to serial output. For now, I just want to be able to store the data coming from the controller to variables within the PIC. This is my first experience with the USB protocol and my first project using USB with a PIC. I want to make this project ONLY function for the xbox 360 controller; I do not want it to work for any other USB device and do not care about leaving room for future expansion. I would like to hard code as much information as possible without having the PIC read about the attached device every time, since the only thing that will ever be connected to this project is a wired xbox 360 controller.

The format of the xbox 360 data: http://free60.org/GamePad

What I've done so far: I have a female USB jack wired to the D+ and D- pins on the PIC and supply power the the female USB jack via a separate power supply that is not connected to the PIC. I have written code to activate the USB module and the 48MHz USB clock. When I plug in the xbox 360 controller I have written code to check the speed of the device (its full-speed) and set the appropriate registers, then reset the xbox controller to put it in the DEFAULT state. The datasheet says something about loading a Device Framework setup command into memory for the next step, but I'm not too sure what this is. If there were some file I could include with the project to give me access to all the control commands I might be able to keep writing my own code to enumerate and interact with this xbox controller. After I enumerate the xbox controller and get it in the CONFIGURED state I just need to strip off the USB "headers" and extract only the data packets.

What to do next? I have read http://www.microchip.com/forums/m524525.aspx but found it a little over my head. I am not sure if it is better for me to continue trying to write code on my own to enumerate and transfer data with the xbox controller or if I should use one of the generic USB examples Microchip has posted. If I use one of the USB demos by Microchip, I'm not sure which one to use. Does anyone know if someone has completed this type of project before? It seems like interacting with xbox controllers would be a pretty popular thing to do. Also, does any company make a USB-to-Serial device that can act as a USB host, configure an attached device, and then output the data via a UART? This is essentially what I am trying to build so if someone already makes it I'd like to buy it.


Any help pointing me in the right direction would be greatly appreciated.
#1

3 Replies Related Threads

    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re:PIC24FJ64GB002 as host for Xbox 360 controller 2011/05/31 08:54:45 (permalink)
    0

    I have read http://www.microchip.com/forums/m524525.aspx but found it a little over my head.

    As you have enough coding ability to make your PIC host put bus reset, modification of Microchip example should be much easier for you. I believe it's just because you aren't familiar with host terminology and this host stack yet.

    This post is applied to v2.8 (v2010-10-19), as it is, too.
    http://www.microchip.com/forums/fb.ashx?m=524616

    Here is supplement of above post.

    a) VID/PID
    Setting up the VID/PID of Xbox360 pad to TPL (Targeted Peripheral List), the host stack does enumeration automatically for you.

    b) Endpoint address
    Replacing the endpoint macros on usb_host_generic.c, you may use these functions for the target endpoints.
    IN 1 EP: USBHostGenericRxIsBusy() - USBHostGenericRead()
    OUT2 EP: USBHostGenericTxIsBusy() - USBHostGenericWrite()

    c) Main state machine
    Microchip host stack runs on a state machine in main loop. Your custom code is inserted as a couple of states in this state machine.

    To read out data from the game pad, you need at least two states.
    DEMO_STATE_ENTRY_RX
    - Using USBHostGenericRxIsBusy(), confirm that no transfer is going on the IN EP.
    - USBHostGenericRead() registers an IN transfer to the host stack.
    And then, your code moves to the next state.

    DEMO_STATE_WAITING_RX
    In this state, your code waits for completion of IN transfer.
    Completion is known by USBHostGenericRxIsBusy()
    And then, your code processes the received data on DataPacket[].
    And then, your code moves to the next state.

    To send data to the game pad, you also need two states, like above reception.


    You'll find debug output over UART2 is helpful on host coding using Microchip stack.
    http://www.microchip.com/forums/fb.ashx?m=578879

    Tsuneo
    #2
    simplerat
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2011/05/10 22:21:54
    • Location: 0
    • Status: offline
    Re:PIC24FJ64GB002 as host for Xbox 360 controller 2011/06/02 17:23:15 (permalink)
    0
    Thanks for the quick reply Tsuneo, but I have another question or two:

    1) main.c does not compile. I opened the C30 workspace in "USB Host - MCHPUSB - Generic Driver Demo" since that is the compiler I am using, but when I compile and build I get a bunch of errors about undefined variables such as:
    main.c: In function 'Switch3WasPressed':
    main.c:570: error: 'sw3_port' undeclared (first use in this function)
    main.c:570: error: 'sw3_bit' undeclared (first use in this function)


    2) It appears as though there are a lot of functions in main.c that are specific to a particular application, such as DisplayTemperature() and all the functions that deal with the LCD. If I just want to enumerate the xbox 360 controller and read its data packets do I even need any of that stuff?

    3) The ManageDemoState() function does not seem to be needed for my application. Is this correct? 
    #3
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    Re:PIC24FJ64GB002 as host for Xbox 360 controller 2011/06/02 23:39:23 (permalink)
    0
    1) Copy entire "USB Host - MCHPUSB - Generic Driver Demo" folder under "C:\Microchip Solutions v2010-10-19" folder, and rename copied Demo folder as you like
    2) Replace main.c in the new Demo folder with attached one
    3) Double click "USB Host - MCHPUSB - Generic Driver Demo - C30.mcp" in the new folder, and then MPLAB IDE runs.
    On MPLAB IDE,
    - Configure menu > Select Device > Device - Choose PIC24FJ64GB002 from pull-down menu
    - Delete "Source Files > Common > LCDBlocking.c" from workspace pane
    - Push "Build All" button

    Attached main.c is just a template for your startup on PIC24FJ64GB002.
    I confirmed that its compile passes with above procedure, but I didn't test it on a real chip yet.


    The outline of code flow is as follows,

    Just after power on, main.c initializes peripherals including USB. It enters the main loop and stays there. In the main loop, USBHostTasks() and ManageDemoState() are repeatedly called.

    In ManageDemoState(), the state machine stays in DEMO_STATE_IDLE until Xbox360 controller is attached (if you add the VID/PID to the TPL).

    When a Xbox360 controller is attached, the stack sees its VID/PID and enumerates the target device. And then, the stack calls USB_ApplicationEventHandler() callback on main.c, with EVENT_GENERIC_ATTACH. This event moves the state machine in ManageDemoState() into DEMO_STATE_MY_HANDLER. Your original sequence starts from here.

    Tsuneo
    post edited by chinzei - 2011/06/02 23:43:18
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5