I am trying to modify Darran Hunt's USB HID joystick firmware, which is based on the joystick demo from the LUFA project, to report the readings from a 3-axis accelerometer (sparkfun ADXL335) as a 3-axis joystick.
I believe that I have come up with a suitable descriptor, using the guide & tool linked here;
char ReportDescriptor[30] = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x04, // USAGE (Joystick)
0xa1, 0x01, // COLLECTION (Application)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x09, 0x32, // USAGE (Z)
0x15, 0x81, // LOGICAL_MINIMUM (-127)
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x03, // REPORT_COUNT (3)
0x81, 0x82, // INPUT (Data,Var,Abs,Vol)
0xc0, // END_COLLECTION
0xc0 // END_COLLECTION
};
The overall size of the report remains at 3 bytes - Darran's original descriptor had 1 byte each for X & Y joysticks plus 1 byte for a bitmask for buttons, I changed the button bitmask byte into the Z joystick byte.
typedef struct {
int8_t x; /**< Current absolute joystick X position, as a signed 8-bit integer */
int8_t y; /**< Current absolute joystick Y position, as a signed 8-bit integer */
uint8_t button; /**< Bit mask of the currently pressed joystick buttons */
} USB_JoystickReport_Data_t;
typedef struct {
int8_t x; /**< Current absolute joystick X position, as a signed 8-bit integer */
int8_t y; /**< Current absolute joystick Y position, as a signed 8-bit integer */
int8_t z; /**< Current absolute joystick Z position, as a signed 8-bit integer */
} USB_JoystickReport_Data_t;
My problems lie with actually compiling it - I can't compile Darran's original source, let alone my modified source!
I have performed the following steps so far, overcoming some errors but getting stuck on more;
- download 'current' release of LUFA - LUFA-120219
- extract
- cd into LUFA root directory
- make clean; make
Running make on my 64-bit Arch Linux workstation (3.2.11-1, avr-libc 1.8.0-1, avr-gcc 4.6.3-1) results in;
Linking: AudioInput.elf
collect2: ld terminated with signal 11 [Segmentation fault]
make[4]: *** [AudioInput.elf] Error 1
make[3]: *** [all] Error 2
make[2]: *** [all] Error 2
make[1]: *** [all] Error 2
make: *** [all] Error 2
So I created a new i386 Debian virtual machine (2.6.32-5, avr-libc 1.6.8-2, gcc-avr 4.3.5-1) which seems to loop several times when I run make (eg it compiles everything successfully, then does it all again, then again, etc.) but after a while it stops after a successful compile.
So then I do;
- cd into Projects folder
- download Darran's arduino-joystick source
- extract
- cd into arduino-joystick directory
- make clean; make
This throws up several errors. I'll start with the ones I can fix.
Arduino-joystick.h:53:40: warning: LUFA/Drivers/USB/Class/CDC.h: No such file or directory
Fixed by changing the #include to LUFA/Drivers/USB/Class/CDCClass.h
Descriptors.h:43:42: warning: LUFA/Drivers/USB/Class/HID.h: No such file or directory
Fixed by changing the #include to LUFA/Drivers/USB/Class/HIDClass.h
There is then an error about LEDs.h;
./Board/LEDs/h:48:5: error: #error Do not include this file directly. Include LUDA/Drivers/Board/LEDs.h instead.
As far as I can tell arduino-joystick.c includes ardunio-joystick.h which includes LUFA/Drivers/Board/LEDs.h which includes Board/LEDs.h so this error shouldn't be thrown? Commenting out the check in Board/LEDs.h obviously removes the error, but doesn't seem the right way to do it!
I think that USB_Descriptor_t in Descriptors.h:54 also needs to be changed to USB_Descriptor_HID_t.
Finally, the big problem, is many errors along the lines of;
../../LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h:84:5: error: #error F_USB is not defined. You must define F_USB to the frequency of the unprescaled USB controller clock in your project makefile.
I can't find any reference to F_USB in any makefile & wouldn't have any idea what to set it to either!
If anybody can shed any help on this whatsoever, I would be extremely grateful. I was hoping to get this working in time for a meeting I have with an interested party on Monday...