Please note as of Wednesday, August 15th, 2018 this wiki has been set to read only. If you are a TI Employee and require Edit ability please contact x0211426 from the company directory.
Stellaris USB Host Joystick
USB Joystick with Stellaris
This is a sample project showing how to use standard HID Joystick with the Stellaris Evalbot (http://www.ti.com/tool/ek-evalbot).
HID standard allow designing devices with different amount of analog and digital(buttons) inputs. Therefore every HID device will have different report frame that includes all specific inputs. Keyboard and Mouse have fixed report frame size (for example mouse report always consist at least 3 byes: byte 0 with active buttons, byte 1 with x movement and byte 2 with y movement). As a result keyboard and mouse are easier to handle. Different joystick will have different report frames. There are 2 ways for solving this issue:
- Reading HID Report Descriptor
- Writing code for specific joystick
In first case host device is "learning" how report packet look-like using Report Descriptor that host can request after basic USB enumeration. This is how your PC acts. This way is complicated and require detailed study of USB HID documentation (http://www.usb.org/developers/hidpage/)
In second case we are omitting Report Descriptor parsing and assuming that connected device has known report packet. Programmer must know what bits are responsible for what function by reverse engineering or manufacturer documentation.
In this project report structure was reverse engineered using PC USB analyser with software HID parser.
Logitech Extreme 3D Pro
- idVendor: 0x046D
- idProduct: 0xC215
|Report descriptor (packet) structure|
|0.7||X7||analog value X LSB|
|1.7||Y5||analog value Y LSB|
|1.1||X9||analog value X MSB|
|2.3||Y9||analog value Y MSB|
|3[0:7]||Rz||analog value yaw (rotation)|
|4[0:7]||B[1:8]||Buttons 1 to 8|
|6[0:7]||B[9:12]||Buttons 9 to 12|
Step 1 - Mouse demo
Mouse and keyboard are most common USB HID (Human Interface Device) devices. Joystick is also HID class device and HID driver from StellarisWare is a good starting point for custom Joystick driver.
There are no USB examples in StellarisWare for Evalbot but we can modify example for board with similar chip.
- Download most recent StellarisWare release (http://www.ti.com/lsds/ti/microcontroller/arm_stellaris/code_examples.page)
- Below you will find sample Evalbot HID mouse host project based on ...\StellarisWare\boards\ek-lm3s9d92\usb_host_mouse
- Build the project. It should compile without any errors or warnings. Resolve any issues with the paths (ex. StellarisWare directory)
If you connect Evalbot to the PC you should be able to open terminal (115200 8N1, DTR on). If you connect mouse to the Evalbot and move it you will see following sequence:
Host Mode. Event Connected ^ Mouse Connected Pos: 1, 0 Buttons: 000 Pos: 11, 0 Buttons: 000 Pos: 11, -3 Buttons: 000 [...]
Additionally LEDs on Ethernet socket will toggle on mouse buttons press.
Evalbot can be powered using either batteries or USB device port.
With working mouse project user can modify sub-driver (usbhhidmouse.c) to get the joystick report data.
- Copy content of linked resource usbhhidmouse.c into new file usbhhidjoy.c.
- Repeat for header file.
- Replace word mouse to joy in both files.
- In usbhhidjoy.c change USBHMS_REPORT_SIZE value to 7. This is a hardware specific value.
- In USBHJoyOpen function replace USBH_HID_DEV_MOUSE to USBH_HID_DEV_NONE. Label is a bit misleading and should be USBH_HID_DEV_OTHER. HID Joysticks will respond with HID subclass value of 0 instead of 2 (mouse) or 1 (keyboard).
- Disable boot protocol (simple protocol for mouse and keyboard support in PC BIOS) support by setting boot value to 0 in function USBHHIDSetProtocol(pUSBHJoy->ulJoyInstance, 0);. The function is located in USBHjoyInit.
- Write UpdateJoyState function. This function is hardware specific and will most likely not work with any other joystick. User needs to understand report data of his/her joystick and write appropriate "decoding" function.
- In main.c replace g_ulMouseInstance with g_ulJoyInstance and USBHMouseOpen with USBHJoyOpen.
- In main.c replace USBHMouseInit(g_ulMouseInstance); with USBHJoyInit(g_ulJoyInstance);
Sample project: File:Evalbot Joystick.zip
- Demo project does not check USB device VID and PID. This should be done to avoid wrong decoding of unsupported joystick report data.
- This demo does not support events like mouse demo does.