Trying to Debug Teensy 3.x Joystick Software

Status
Not open for further replies.

Loren42

Well-known member
I'm trying to understand/modify the HID joystick descriptor file for the Teensy joystick program. The goal is to change the analog data resolution from 10 bits to 12.

The issue is determining what functions call what. Everything is programmed in Arduino, so debugging it is non-existent as far as I can tell.

I can't even find a linker file, so I don't know what the actual list of associated files are that make up the whole program.

I know that the four main files I need to work with are:
usb_desc.c,
usb_desc.h,
usb_joystick.c,
usb_joystick.h,
but there are associated intermediate files that I don't know about.

Does anyone have any recommendations or a way to sort this out?
 
As you mentioned there are no linker files, it just uses standard Arduino build. One of the main things that the build does when your USB type includes joystick, is the
define JOYSTICK_INTERFACE is defined, so you can search through everywhere that has that define is used. In the cores\teensy3 directory 6 files. You hit the main one.
The others are:
usb_inst.cpp - creates the instance of the object
usb_undef.h - Which undefines everything associated with the USB objects like this define...

There is maybe a little information in the main website like: https://www.pjrc.com/teensy/td_joystick.html
Which includes a link to Paul's more complicated Joystick code - https://forum.pjrc.com/threads/23681-Many-axis-joystick

I have not done as much with this side of the joystick code. Did more on getting joysticks to work on the T3.6(and T4.x) USB Host code.

Some of the more interesting things might be with data alignment with the HID data. That is there are place, where may need to be aligned on byte boundary and the whole report most be a multiple of 8 bits... So current smaller in bits: (32 buttons, 4 hat, 40 for Axis(x, y, z, Rz), 20 for sliders) = 96 or 12 bytes ...
If you just change the 4 axis, to 12 bits, that would add 8 bits total which I think should work. You will probably need to change report size, plug logical max for these.

And then it will take a complete reworking of the usb_joystick.h code to handle the differences in where each bit in the packet gets packed...

Maybe alternative to this, is to maybe take the easy way out and use the 64 byte JOYSTICK....
JOYSTICK_SIZE == 64
Here the code is setup I believe for all of the axis to be 16 bits..
 
Thanks, this helps a lot.

Ultimately I'm trying to replicate the structure of something I already have using an 8-bit Pic so that it works with the software on a PC. I want to learn some of the nuts and bolts, but my software skills are very rusty.

I do have another code question. On the JOYSTICK_SIZE == 64 version, ExtremeJoystickTest.ino has a line of code: Joystick.X(analogRead(A0) * 64);

I understand that this code multiplies the analog value by 64 before stuffing it in the structure. However, why use multiplication? Wouldn't it be more efficient to use : analogRead(A0) << 6) ?

I have not used Arm processors before, but was thinking multiplication would produce more machine code than a simple logical shift, or am I out in "left" field here? :)

By the way, love the picture of your dog. Is that a Rough Collie?
 
Warning I have not done much with this code, but:
(analogRead(A0) * 64) versus (analogRead(A0) << 6)

My guess would be a wash, as the hardware can do multiplication and if not, hopefully the compiler will optimize them to be same.

Yes the picture is of Laik who is our now 8 year old Rough Collie. And under my Profile page is a picture of our first Male collie Drake from many years ago.
 
I would not expect much in the way of optimization from the Arduino compiler, but who knows and it probably doesn't matter much with the speed of the Arm.

Wow, a blue merle, too! Beautiful pup. We recently lost our German Shepherd Dog, but would love a Collie puppy. Unfortunately, there are not a lot of choices in Florida. We had one when I was a young boy that my father picked out. Wonderful dog.
 
Status
Not open for further replies.
Back
Top