Problems: Due as an HID Joystick.

Using leojoy as a base and some other stuff. I'm having trouble getting my code to work. This code works fine for leonardo based boards. But I can't get it to even compile when it's set to the Due.
I haven't bought the Due yet, but no point in buying it if it won't compile.
This is the same code that works for the Leonardos.

/*
Arduino Leonardo Joystick!

Modified heavily for 10 Bit resolution on all Axis and rotations.

Note you need the modified HID.cpp in this file and the USBAPI.h with it!
*/



    /*    
     *     Joystick Configuration
     *     ----------------------
     *     
     *     Enable or Disable each item you are using.
     *     
     *     They will still appear in the control panel. Except when disabled, they will be locked to mid axis
     *     or not respond to random noise on unterminated pins.
     *     
     *     It is a good idea to disable any axis you do not have connected to a potentiometer or button. This 
     *     will prevent noise from accidently triggering inputs in the game.
     *     
     */
    bool xAxis_Enable = true;
    bool yAxis_Enable = true;
    bool zAxis_Enable = false;
    bool xRotAxis_Enable = false;
    bool yRotAxis_Enable = false;
    bool zRotAxis_Enable = false;
    bool throttle_Enable = false;
    bool rudder_Enable = false;
    bool buttons_Enable = true;

    /*
      Button pin assignments... nice and easy to remap them here
    */
    
    int button1 = 0;         
    int button2 = 1;        
    int button3 = 2;         
    int button4 = 3;        
    int button5 = 4;          
    int button6 = 5;           
    int button7 = 6;          
    int button8 = 7; 
    int button9 = 8;          
    int button10 = 9;           
    int button11 = 10;           
    int yValue;    
    
    // Create a Joystick object by calling a JoyState_t class object and calling it joySt.
    JoyState_t joySt;
    
    // Declare globally used variables
    int buttons = 0;


void setup()
{
    // Enable Serial port for basic console debugging. 
    Serial.begin(9600);

    /*
     * This sets the pull up on each of the buttons. 
     * 
     * Meaning you don't have to externally pull up the button pin. Just connect the switch to this pin and ground. 
     * 
     */

    pinMode(0, INPUT_PULLUP);  // Gamepad Button 1
    pinMode(1, INPUT_PULLUP);  // Gamepad Button 2   
    pinMode(2, INPUT_PULLUP);  // Gamepad Button 3
    pinMode(3, INPUT_PULLUP);  // Gamepad Button 4
    pinMode(4, INPUT_PULLUP);  // Gamepad Button 5
    pinMode(5, INPUT_PULLUP);  // Gamepad Button 6  
    pinMode(6, INPUT_PULLUP);  // Gamepad Button 7  
    pinMode(7, INPUT_PULLUP);  // Gamepad Button 8  
    pinMode(8, INPUT_PULLUP);  // Gamepad Button 9
    pinMode(9, INPUT_PULLUP);  // Gamepad Button 10  
    pinMode(10, INPUT_PULLUP);  // Gamepad Button 11  

    pinMode(14, INPUT_PULLUP);  // Gamepad Button 12 
    pinMode(15, INPUT_PULLUP);  // Gamepad Button 13
    pinMode(16, INPUT_PULLUP);  // Gamepad Button 14   
        
    // Zero the initial values of all the inputs
    joySt.xAxis = 0;
    joySt.yAxis = 0;
    joySt.zAxis = 0;
    joySt.xRotAxis = 0;
    joySt.yRotAxis = 0;
    joySt.zRotAxis = 0;
    joySt.throttle = 0;
    joySt.rudder = 0;
    joySt.buttons = 0;
       
}// end setup


//----------------------------------------------------------------------------------------------------------------

/*
 * Main Program loop.
 * 
 * Gathers all the inputs, puts them in the appropiate places and then sends them to the PC
 * 
 * Nice and easy.
 */

void loop()
{
        // Read all the buttons
        joySt.buttons = 0;
        if (buttons_Enable){
              buttons = (digitalRead(button1) << 0) + (digitalRead(button2) << 1) + (digitalRead(button3) << 2)
                      + (digitalRead(button4) << 3) + (digitalRead(button5) << 4) + (digitalRead(button6) << 5)
                      + (digitalRead(button7) << 6) + (digitalRead(button8) << 7) + (digitalRead(button9) << 8) + (digitalRead(button10) << 9)
                      + (digitalRead(button11) << 10);
          //amount of buttons are settable in the HID.cpp
          joySt.buttons = ~buttons; // logic high is a one, so read the NOT version of the buttons
        }  

        // Read all the Analogue Axis
        joySt.xAxis = 512;
        if (xAxis_Enable){  
          joySt.xAxis = analogRead(A0); // Default A0 pin
        }

        joySt.yAxis = 512;
        yValue = analogRead(A1);
        yValue = 1023 - yValue;
        if(yAxis_Enable) {
          joySt.yAxis = yValue; // Default A1 pin
        }

        joySt.zAxis = 512; 
        if(zAxis_Enable) {
          joySt.zAxis = analogRead(A2); // Default A2 pin
        }


        joySt.xRotAxis = 512;
        if(xRotAxis_Enable) {
          joySt.xRotAxis = analogRead(A2); // Default A0
        }

        joySt.yRotAxis = 512; 
        if(yRotAxis_Enable) {
          joySt.yRotAxis = analogRead(A2); // Default A0
        }

        joySt.zRotAxis = 512; 
        if(zRotAxis_Enable) {
          joySt.zRotAxis = analogRead(A2); // Default A0
        }
       
        
        joySt.throttle = 512;
        if(throttle_Enable) {
          joySt.throttle = analogRead(A2);  // Default A0
        }

        joySt.rudder = 512;
        if(rudder_Enable) {
          joySt.rudder = analogRead(A2);  // Default A0
        }

        
        // Complete! Send all these values to Joystick.setState(&joySt) in the HID.cpp file to send it to the PC! >>>>>>>>>>>>>>>>
        Joystick.setState(&joySt);


}// end main program loop

Here's the error i'm getting.

SBcontroller.cpp.o: In function `loop':
C:\Program Files (x86)\Arduino/SBcontroller.ino:170: undefined reference to `Joystick'
C:\Program Files (x86)\Arduino/SBcontroller.ino:170: undefined reference to `Joystick_::setState(JoyState*)'
collect2.exe: error: ld returned 1 exit status
Error compiling.

And i'll attach my sam-core/usb HID.cpp and USBAPI.h files.

I should note, it seems like it's not even seeing the hid file. so i'm not sure if i have to add a reference to it in another files. My SAM core files didn't even have the hid file, i used one edited from Arduino DUE as a HID Joystick and PPM Decoder - Arduino Due - Arduino Forum
And tweaked it using code from my other leondardo hid file, but neither work. (tweaked for 10bit resolution)

It would be nice to get joystick, and keyboard all working together. Mouse is less important.
Reason for going the Due route? I need a LOT of buttons and axis. Why so many? Modified steel Battalion controller.

HID.cpp (17.5 KB)

USBAPI.h (7.29 KB)

Any time you are modifying the core Arduino files, you have to stop and think: Am I fixing a bug in Arduino or am I adding a feature that should be added somewhere else?

I haven't spent a lot of time messing with this HID stuff but I think it's easier on the Teensy. Paul spends a lot of time getting it right for the Teensy core libraries. It always seems like the Due never got finished by the Arduino team.

The teensy is an option, but it's not ideal. The teensy++ 2.0 doesn't have enough GPIO pins, analog or digital.

I can make the leojoy work for a leonardo, micro or pro micro using such configurations. I've already confirmed this. So an expensive Teensy may not be necessary.

All that said, none of this helps with my dilemma. I'd like to get this done with the Due, as i'd like there to be pins left over incase i decide to expand the code to control other stuff.

I admit i may have to go the teensy route, i'm not too happy about this though. It would mean i would need to use dedicated pins for some buttons and a matrix grid for the rest of the buttons (meaning 2 can't be pressed at 1 time.) Or i could use 2x teensys which would be even more expensive. :frowning:
Or 1x teensy 3.2 and 1x arduino micro/pro-micro.

Alright, after checking. The button matrix is not an option. Long story short, buttons share a common ground.
So my only options now are the Due, or using 2 Teensys at the same time. (or a teensy and another MCU)

If anyone knows how to get the Due to work. I really would appreciate it. It would be a 1 shot solution for my problems. It won't just benefit me, it would benefit everyone who wants to do something similar.

If nothing else, at least tell me how to get it to reference the joystick line in my hid.cpp. It's like it doesn't even see the file at all.