Skip to content

Add support for Arduino Zero, M0, and MKR family #101

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 <[email protected]>
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
13 changes: 13 additions & 0 deletions Joystick/src/DynamicHID/DynamicHID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions Joystick/src/DynamicHID/DynamicHID.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <stdint.h>
#include <Arduino.h>

#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
Expand Down Expand Up @@ -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];
Expand Down