Xbox controller emulator for Atmel AVR microcontrollers

Discussion in 'Xbox (Original console)' started by ripdajacker, Feb 24, 2018.

  1. ripdajacker

    ripdajacker Member

    Joined:
    Feb 24, 2018
    Messages:
    15
    Likes Received:
    14
    Hello all

    A couple of days ago I read a post on ogxbox.com regarding using a 360 controller on an OG xbox.
    I decided to give it a shot.

    The progress so far is that the chip registers as an OG xbox controller on all PCs but NOT on the Xbox. I've tried it with or without hubs, with different polling speeds and whatnot.

    I would love the help of the community to accomplish this.

    The code
    XPAD emulator: https://github.com/ripdajacker/xpad-avr
    HID joystick to SPI redirect application: https://github.com/ripdajacker/hidjoy2spi

    What can I do?
    For now wait, I will post a tutorial on how to set the converter up as soon as it is viable.

    Coming soon:
    Very elaborate latency measurements.
     
    Last edited: Mar 16, 2018
  2. dans87

    dans87 Site Supporter 2013,14,15

    Joined:
    Jan 6, 2013
    Messages:
    359
    Likes Received:
    33
  3. ripdajacker

    ripdajacker Member

    Joined:
    Feb 24, 2018
    Messages:
    15
    Likes Received:
    14
    If you have one lying around sure thing :) Most of the chinese ones identify as the same xbox controller with vendor id 0xFFFF.

    I have a PS2-XBOX adapter and this one is interesting. It is a basic HID device if you plug it in to a PC, but when you plug it into an Xbox it is an xpad. I verified this with a logic analyzer. This means the method may be somewhat flawed, but it would be nice to have as many unique examples as possible.

    During my research I fell over XQEMU which happens to implement an xbox controller in software.
    I will look into this the next couple of days.
     
  4. ripdajacker

    ripdajacker Member

    Joined:
    Feb 24, 2018
    Messages:
    15
    Likes Received:
    14
    Update:
    The controller emulator now registers correctly on an Xbox.

    Next step: Getting the button press data on to the control over serial.
     
  5. Alessio

    Alessio Rising Member

    Joined:
    Sep 8, 2015
    Messages:
    70
    Likes Received:
    17
    Would be useful to test a converter that comes with a steering wheel that works with xbox ps2 and pc ? Steering wheel has ps2 port that plugs to the converter . I can even use a ps2 pad on xbox or pc via this converter
     
  6. Alessio

    Alessio Rising Member

    Joined:
    Sep 8, 2015
    Messages:
    70
    Likes Received:
    17
    Or a Logitech xbox wireless controller
     
  7. rso

    rso Gone. See y'all elsewhere, maybe.

    Joined:
    Mar 26, 2010
    Messages:
    2,190
    Likes Received:
    447
    Good job. Keeping an eye on this, in order to maybe eventually mod it into a DIY Steel Battalion controller/cockpit.
     
    Last edited: Mar 1, 2018
  8. Dr.Funk

    Dr.Funk Lost Media Enthusiast

    Joined:
    Feb 28, 2018
    Messages:
    23
    Likes Received:
    5
    As rso said I cant wait to turn this into a diy steel battailon controler.
     
    CodeAsm likes this.
  9. mcnj

    mcnj Newly Registered

    Joined:
    Nov 28, 2012
    Messages:
    1
    Likes Received:
    2
    GoTeamScotch and rso like this.
  10. rso

    rso Gone. See y'all elsewhere, maybe.

    Joined:
    Mar 26, 2010
    Messages:
    2,190
    Likes Received:
    447
    note regarding that last link: since gitorious is pretty much down already and might go down for good at any time (not unlike like this forum...), y'all might want to clone the relevant code from where it moved to while you still can.
     
  11. ripdajacker

    ripdajacker Member

    Joined:
    Feb 24, 2018
    Messages:
    15
    Likes Received:
    14
    Kade looks awesome and there's certainly some relevant Xbox-specific code.
    The code has been moved to github: https://github.com/bootsector/usb-retropad-adapter/

    For this project I still need a USB host which can interface with a 360 controller and translate it into signals the OG Xbox understands. The cheap version of this is just to use two atmega chips communicating over serial.
     
  12. rso

    rso Gone. See y'all elsewhere, maybe.

    Joined:
    Mar 26, 2010
    Messages:
    2,190
    Likes Received:
    447
    > two atmega chips communicating over serial
    sounds laggy :/
     
  13. ripdajacker

    ripdajacker Member

    Joined:
    Feb 24, 2018
    Messages:
    15
    Likes Received:
    14
    At 115200 baud you can send an entire controller state every 2ms.
    On the output end the delay should be negligible since the buffer is emptied every 4ms.

    I hope the delay won't be noticeable, if it is I'll look into using some other means of communication.
     
  14. zzattack

    zzattack Spirited Member

    Joined:
    Nov 19, 2014
    Messages:
    161
    Likes Received:
    62
    Bigger cortex m micro with both host and device capability a possibility?
     
  15. ripdajacker

    ripdajacker Member

    Joined:
    Feb 24, 2018
    Messages:
    15
    Likes Received:
    14
    Yes a cortex would work. If anyone is up for it an OrangePI with OTG could work too, albeit I am not sure what it would require to do the xpad emulation using the USB gadget framework in linux.

    The ATMega32u4 cannot act as a USB host, so a host shield (or a teensy) is needed.

    A couple of metrics:
    A cheap PS2 to Xbox adapter sends gamepad state every 8ms.
    An original Xbox S controller sends every 4ms.

    A frame at 60fps is ~16ms, at 30fps it's 33ms.
    This means a total latency of less than 16ms is proably good enough for most people.

    From the initial test with a baud rate of 57600 through a linux PC I can get around 25ms latency from the PC receives the HID report till it is sent to the Xbox. I suspect the host shield will reduce this drastically because it offloads the USB processing to a dedicated chip and sends stuff to the atmega over SPI, which will run way faster than 57kbit (running on 16mhz this would be in the "couple of megabits" range).

    Next steps:
    A USB shield is coming to me from china, so in 2-3 weeks I'll be able to give it a go.

    In the meantime:
    If you are a programmer, check out the code.
     
    zzattack likes this.
  16. nonosto

    nonosto Intrepid Member

    Joined:
    Jan 5, 2012
    Messages:
    691
    Likes Received:
    53
    So nice, a Porshe fanatec wheel with Outrun 2 SP from chihiro .... my dream...
     
    Anthony817 likes this.
  17. zzattack

    zzattack Spirited Member

    Joined:
    Nov 19, 2014
    Messages:
    161
    Likes Received:
    62
    I developed the 'MUNIA' (multi use nintendo input adapter) and am planning on doing something similar for PS2 and original xbox controllers. This device can take inputs from snes, n64 and NGC and output to snes, n64, NGC or PC. That means you can use your SNES controller to play on the NGC, use your NGC controller to play on N64 or any other combination you can make. Its main intended purpose though is viewing the inputs on PC to form an overlay on twitch so the controller state is replicated on screen.
    I've been meaning to build this for xbox and ps2 and especially the xbox one requires a decent microcontroller. I had begun to make a design with 2 microcontrollers, one as USB host and the other as normal device. The micros were shared an SPi bus to exchange packets but halfway through development I stopped. It was incredibly annoying to update 2 devices and keep them in sync, so I decided I'd rather do it properly instead using a single micro with both host and client capability. I'm sure the 2-mcu approach can work but I found it too cumbersome to work on.
     
  18. nonosto

    nonosto Intrepid Member

    Joined:
    Jan 5, 2012
    Messages:
    691
    Likes Received:
    53
    Input lag?
     
  19. ripdajacker

    ripdajacker Member

    Joined:
    Feb 24, 2018
    Messages:
    15
    Likes Received:
    14
    @zzattack The PS2 controller is not USB and you clock it yourself, which means there's basically no lag.
    Do you have any code from your initial attempts?
    Did you find a micro that has host + client support at the same time?
     
  20. zzattack

    zzattack Spirited Member

    Joined:
    Nov 19, 2014
    Messages:
    161
    Likes Received:
    62
    For the 'input viewer' part I always configure the microcontroller to be a spy on the bus. This is more difficult, but guarantees there is absolutely no delay between original controller and console. For xbox and other USB-based protocols this is not going to be possible though.
    The only microprocessors with double USB PHY that I know are STM32F4x5 and STM32F466 with the latter being somewhat affordable. There's probably a few more possible choices but these are the ones I know of.
     

Share This Page