Skip to content

Added support for SAMD devices #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Joystick/library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name=Joystick
version=2.0.5
author=Matthew Heironimus
maintainer=Matthew Heironimus <heironimus@live.com>
sentence=Arduino library that allows an Arduino Leonardo, Arduino Micro, or Arudino Due to appear as a Joystick or Gamepad.
sentence=Arduino library that allows an Arduino Leonardo, Arduino Micro, or Arudino Due/MKR to appear as a Joystick or Gamepad.
paragraph=This library is built on the PluggableUSB library. It can be used with or without other HID-based libraries (Mouse, Keyboard, etc.).
category=Device Control
url=https://github.com/MHeironimus/ArduinoJoystickLibrary
architectures=avr,sam
architectures=avr,sam,samd
4 changes: 4 additions & 0 deletions Joystick/src/DynamicHID/DynamicHID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "DynamicHID.h"

#if !defined(ARDUINO_SAMD_VARIANT_COMPLIANCE)

#if defined(USBCON)

#ifdef _VARIANT_ARDUINO_DUE_X_
Expand Down Expand Up @@ -167,3 +169,5 @@ int DynamicHID_::begin(void)
}

#endif /* if defined(USBCON) */

#endif // !defined(!defined(ARDUINO_SAMD_VARIANT_COMPLIANCE))
4 changes: 4 additions & 0 deletions Joystick/src/DynamicHID/DynamicHID.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <stdint.h>
#include <Arduino.h>

#if !defined(ARDUINO_SAMD_VARIANT_COMPLIANCE)

#ifdef _VARIANT_ARDUINO_DUE_X_
// The following values are the same as AVR's USBAPI.h
// Reproduced here because SAM doesn't have these in
Expand Down Expand Up @@ -142,3 +144,5 @@ DynamicHID_& DynamicHID();
#endif // USBCON

#endif // DYNAMIC_HID_h

#endif // !defined(ARDUINO_SAMD_VARIANT_COMPLIANCE)
18 changes: 14 additions & 4 deletions Joystick/src/Joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "Joystick.h"

#if defined(_USING_DYNAMIC_HID)
#if defined(_USING_DYNAMIC_HID) || defined(_USING_HID)

#define JOYSTICK_REPORT_ID_INDEX 7
#define JOYSTICK_AXIS_MINIMUM -32767
Expand Down Expand Up @@ -435,8 +435,14 @@ Joystick_::Joystick_(
memcpy(customHidReportDescriptor, tempHidReportDescriptor, hidReportDescriptorSize);

// Register HID Report Description
DynamicHIDSubDescriptor *node = new DynamicHIDSubDescriptor(customHidReportDescriptor, hidReportDescriptorSize, false);
DynamicHID().AppendDescriptor(node);
#if defined(_USING_DYNAMIC_HID)
DynamicHIDSubDescriptor *node = new DynamicHIDSubDescriptor(customHidReportDescriptor, hidReportDescriptorSize, false);
DynamicHID().AppendDescriptor(node);
#else
static HIDSubDescriptor node(customHidReportDescriptor, hidReportDescriptorSize);
HID().AppendDescriptor(&node);
#endif


// Setup Joystick State
if (buttonCount > 0) {
Expand Down Expand Up @@ -674,7 +680,11 @@ void Joystick_::sendState()
index += buildAndSetSimulationValue(_includeSimulatorFlags & JOYSTICK_INCLUDE_BRAKE, _brake, _brakeMinimum, _brakeMaximum, &(data[index]));
index += buildAndSetSimulationValue(_includeSimulatorFlags & JOYSTICK_INCLUDE_STEERING, _steering, _steeringMinimum, _steeringMaximum, &(data[index]));

DynamicHID().SendReport(_hidReportId, data, _hidReportSize);
#if defined(_USING_DYNAMIC_HID)
DynamicHID().SendReport(_hidReportId, data, _hidReportSize);
#else
HID().SendReport(_hidReportId,data,_hidReportSize);
#endif
}

#endif
12 changes: 9 additions & 3 deletions Joystick/src/Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
#ifndef JOYSTICK_h
#define JOYSTICK_h

#include <Arduino.h>

#if defined(ARDUINO_SAMD_VARIANT_COMPLIANCE)
#include <HID.h>
#else
#include <DynamicHID/DynamicHID.h>
#endif // defined(ARDUINO_SAMD_VARIANT_COMPLIANCE)

#if ARDUINO < 10606
#error The Joystick library requires Arduino IDE 1.6.6 or greater. Please update your IDE.
Expand All @@ -33,11 +39,11 @@
#endif // !defined(USBCON)
#endif // ARDUINO > 10606

#if !defined(_USING_DYNAMIC_HID)
#if !defined(_USING_DYNAMIC_HID) && !defined(_USING_HID)

#warning "Using legacy HID core (non pluggable)"

#else // !defined(_USING_DYNAMIC_HID)
#else // !defined(_USING_DYNAMIC_HID) && !defined(_USING_HID)

//================================================================================
// Joystick (Gamepad)
Expand Down Expand Up @@ -214,5 +220,5 @@ class Joystick_
void sendState();
};

#endif // !defined(_USING_DYNAMIC_HID)
#endif // !defined(_USING_DYNAMIC_HID) && !defined(_USING_HID)
#endif // JOYSTICK_h