From 6f38054501ad1fec385830a7cea33eebcfdb6054 Mon Sep 17 00:00:00 2001 From: gdsports Date: Tue, 30 Oct 2018 20:54:42 -1000 Subject: [PATCH] Add support for Arduino Zero, M0, and MKR family --- Joystick/library.properties | 4 ++-- Joystick/src/DynamicHID/DynamicHID.cpp | 13 +++++++++++++ Joystick/src/DynamicHID/DynamicHID.h | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Joystick/library.properties b/Joystick/library.properties index abb7a26..1840edc 100644 --- a/Joystick/library.properties +++ b/Joystick/library.properties @@ -2,8 +2,8 @@ name=Joystick version=2.0.5 author=Matthew Heironimus maintainer=Matthew Heironimus -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, Arduino Due, Arduino Zero/M0, or Arduino MKR family 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 diff --git a/Joystick/src/DynamicHID/DynamicHID.cpp b/Joystick/src/DynamicHID/DynamicHID.cpp index 6c46a2c..c04f8e4 100644 --- a/Joystick/src/DynamicHID/DynamicHID.cpp +++ b/Joystick/src/DynamicHID/DynamicHID.cpp @@ -26,6 +26,10 @@ #ifdef _VARIANT_ARDUINO_DUE_X_ #define USB_SendControl USBD_SendControl #define USB_Send USBD_Send +#elif defined(ARDUINO_ARCH_SAMD) +#define USB_SendControl(flags, d, len) USBDevice.sendControl(d, len) +#define USB_Send USBDevice.send +#define TRANSFER_RELEASE 0x00 #endif DynamicHID_& DynamicHID() @@ -122,7 +126,12 @@ bool DynamicHID_::setup(USBSetup& setup) return true; } if (request == DYNAMIC_HID_GET_IDLE) { +#ifdef ARDUINO_ARCH_SAMD + USBDevice.armSend(0, &idle, 1); + return true; +#else // TODO: Send8(idle); +#endif } } @@ -157,7 +166,11 @@ DynamicHID_::DynamicHID_(void) : PluggableUSBModule(1, 1, epType), rootNode(NULL), descriptorSize(0), protocol(DYNAMIC_HID_REPORT_PROTOCOL), idle(1) { +#ifdef ARDUINO_ARCH_SAMD + epType[0] = USB_ENDPOINT_TYPE_INTERRUPT | USB_ENDPOINT_IN(0); +#else epType[0] = EP_TYPE_INTERRUPT_IN; +#endif PluggableUSB().plug(this); } diff --git a/Joystick/src/DynamicHID/DynamicHID.h b/Joystick/src/DynamicHID/DynamicHID.h index 0a9a6ef..f2e202e 100644 --- a/Joystick/src/DynamicHID/DynamicHID.h +++ b/Joystick/src/DynamicHID/DynamicHID.h @@ -25,7 +25,7 @@ #include #include -#ifdef _VARIANT_ARDUINO_DUE_X_ +#if defined(_VARIANT_ARDUINO_DUE_X_) || defined(ARDUINO_ARCH_SAMD) // The following values are the same as AVR's USBAPI.h // Reproduced here because SAM doesn't have these in // its own USBAPI.H @@ -119,7 +119,7 @@ class DynamicHID_ : public PluggableUSBModule uint8_t getShortName(char* name); private: - #ifdef _VARIANT_ARDUINO_DUE_X_ + #if defined(_VARIANT_ARDUINO_DUE_X_) || defined(ARDUINO_ARCH_SAMD) uint32_t epType[1]; #else uint8_t epType[1];