Help getting teensy working on XIM 3&Edge

Status
Not open for further replies.

W11cE

Member
[SOLVED] Help getting teensy working on XIM 3&Edge

These are the devices I am talking about http://xim3.com/
I am trying to get teensy 3.0 and/or 2.0 working on those in joystick mode. XIMs allow only one HID type per device. And because teensy is unknown device for Xims, it will choose input type depending on which usb port teensy is connected. Xims have preferred ports for mouse, keyboard and joystick.

In mouse port teensy is recognized as a mouse and mouse input works correctly
Keyboard and joystick share the same preferred port. In that port teensy is recognized as a keyboard and keyboard input works correctly on that one.

The joystick input does not work because of the shared preferred keyboard and joystick port. I have tried changing Vendor and Product IDs to Logitech Attack 3 ones. It is one of the supported joysticks. XIM recognizes teensy as a joystick now, but it doesnt recognize any input.

With teensy 3.0 swapping joystick endpoint from 4 to 1 any input causes X and Y to stuck to 0 on Xim. I have asked help from XIM creator, but all he said was that make it work like Logitech Attack 3.
And I have also tried PS3 gamepad codes on teensy 2.0, but those will cause also X and Y stuck to 0. Pressing some buttons will move it, but thats it.

Does anyone have any ideas that could help?
 
Last edited:
You can edit the usb code. For Teensy 3.0, the file you want is hardware/teensy/cores/teensy3/usb_desc.h

First, comment out these lines:

Code:
  #define KEYBOARD_INTERFACE    0       // Keyboard
  #define KEYBOARD_ENDPOINT     3
  #define KEYBOARD_SIZE         8
  #define KEYBOARD_INTERVAL     1
Next, edit the offsets, these lines:

Code:
  #define KEYBOARD_DESC_OFFSET  (9 + 9)
  #define MOUSE_DESC_OFFSET     (9 + 9+9+7 + 9)
  #define SEREMU_DESC_OFFSET    (9 + 9+9+7 + 9+9+7 + 9)
  #define JOYSTICK_DESC_OFFSET  (9 + 9+9+7 + 9+9+7 + 9+9+7+7 + 9)
  #define CONFIG_DESC_SIZE      (9 + 9+9+7 + 9+9+7 + 9+9+7+7 + 9+9+7)

Because the keyboard stuff won't be part of the descriptors anymore, remove the first "9+9+7". Also comment out the keyboard one. It ought to look like this:

Code:
  //#define KEYBOARD_DESC_OFFSET  (9 + 9)
  #define MOUSE_DESC_OFFSET     (9 + 9)
  #define SEREMU_DESC_OFFSET    (9 + 9+9+7 + 9)
  #define JOYSTICK_DESC_OFFSET  (9 + 9+9+7 + 9+9+7+7 + 9)
  #define CONFIG_DESC_SIZE      (9 + 9+9+7 + 9+9+7+7 + 9+9+7)

The last thing to edit is the number of interfaces.

Code:
  #define NUM_INTERFACE         4

Since you took one out, reduce this to 3.

When you recompile, if it fails because anything is missing, it'll probably be in the keyboard code. Since you're not using the keyboard, just comment out or delete anything troublesome... if it's in the keyboard stuff.

You can do something similar on Teensy 2.0. The 2.0 code doesn't automatically adapt as nicely to changes in the .h file, so you'll have to manually edit the data perhaps delete various keyboard stuff. But the process is similar.

Even though this might seem complex, keep in mind the USB configuration descriptor is just an array of bytes that tells the USB host what type of device it has. It doesn't matter if the keyboard is still there and functional on its USB endpoints... as long as the descriptor data doesn't mention the keyboard, the USB host will never try to access those endpoints.


If you want to read some (rather long and boring) documentation about USB descriptor formats, it's documented in the USB spec, section 9.5, starting on page 260 (the 288th page of the PDF).

http://www.pjrc.com/teensy/beta/usb20.pdf


The USB-IF publishes a testing tool that can verify if the descriptors and USB responses are correct. It's at www.usb.org. If you've made an error in the descriptors, it's actually pretty good at telling you what's wrong. But be careful running it... it replaces the Windows USB stack, so if things go badly (especially on XP) it can really trash a Windows installation pretty quickly. Make a full backup before running it.

Also, if you're running Linux, some of the more substantial descriptor errors are reported in the syslog log file. You might try "lsusb -v" to see how Linux views your descriptors.

On Mac, Apple has a tool called USB Prober as part of Xcode. It can read descriptors and show you how Mac OS-X views them.
 
Also... if anyone reading this is really good at C preprocessor macros, I'd really welcome any ideas for a way to automagically compute those offsets. Editing them is a pain....
 
Thanks Paul for your quick reply. Unfortunately that didnt make it working. Again after modifications it works on pc, but not on XIM. But now i think i know the reason why it doesnt work.

Maybe XIM reads only raw data that it gets. I read Logitech Attack 3 with USBlyzer and noticed that its raw data is only 5 bytes long. I quess first byte is for X, second for Y, third for Z, and 4th and 5th for buttons.
On teensy its 12 bytes. First 4 are all 0. The 5th has some changing values.
That would explain why X and Y has always been 0 on XIM and why with some setups there are some random button presses.

Does this explanation make any sense?

So, now i would need to edit joystick report descriptor in usb_desc.c ?
 
Well, you certainly can edit the code any way you like. You can edit the report descriptor to match another joystick.

You'll also need to edit the USB code which sends the data, so it only sends 5 bytes with the data format of the other joystick.
 
Well, after a lot of trying and failing i got it done. Now it works just as i wanted. :D

Thanks for your help :)
 
Status
Not open for further replies.
Back
Top