Skip to content

Commit 8e1ad7e

Browse files
PalakisMHeironimus
authored andcommitted
Arduino Due compatibility (MHeironimus#71)
* Arduino Due support * DynamicHID: send report with only one Send() call On a Due, Reports don't seem to be took into account with the previous implementation. This new implementation works on the Due, as well as previous supported boards too, and has the benefit of sending everything in one Send() call instead of two. * Update README * Arduino IDE: add ARM SAM (Due CPU) architecture * DynamicHID::SendReport: fix buffer size * General: version bump * Add credit in README
1 parent be26a45 commit 8e1ad7e

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

Joystick/library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=Joystick
2-
version=2.0.4
2+
version=2.0.5
33
author=Matthew Heironimus
44
maintainer=Matthew Heironimus <[email protected]>
5-
sentence=Arduino library that allows an Arduino Leonardo or Arduino Micro to appear as a Joystick or Gamepad.
5+
sentence=Arduino library that allows an Arduino Leonardo or Arduino Micro to appear as a Joystick or Gamepad.
66
paragraph=This library is built on the PluggableUSB library. It can be used with or without other HID-based libraries (Mouse, Keyboard, etc.).
77
category=Device Control
88
url=https://github.com/MHeironimus/ArduinoJoystickLibrary
9-
architectures=avr
9+
architectures=avr,sam

Joystick/src/DynamicHID/DynamicHID.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323

2424
#if defined(USBCON)
2525

26+
#ifdef _VARIANT_ARDUINO_DUE_X_
27+
#define USB_SendControl USBD_SendControl
28+
#define USB_Send USBD_Send
29+
#endif
30+
2631
DynamicHID_& DynamicHID()
2732
{
2833
static DynamicHID_ obj;
@@ -91,11 +96,10 @@ void DynamicHID_::AppendDescriptor(DynamicHIDSubDescriptor *node)
9196

9297
int DynamicHID_::SendReport(uint8_t id, const void* data, int len)
9398
{
94-
auto ret = USB_Send(pluggedEndpoint, &id, 1);
95-
if (ret < 0) return ret;
96-
auto ret2 = USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, len);
97-
if (ret2 < 0) return ret2;
98-
return ret + ret2;
99+
uint8_t p[len + 1];
100+
p[0] = id;
101+
memcpy(&p[1], data, len);
102+
return USB_Send(pluggedEndpoint | TRANSFER_RELEASE, p, len + 1);
99103
}
100104

101105
bool DynamicHID_::setup(USBSetup& setup)

Joystick/src/DynamicHID/DynamicHID.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,18 @@
2424

2525
#include <stdint.h>
2626
#include <Arduino.h>
27-
#include "PluggableUSB.h"
27+
28+
#ifdef _VARIANT_ARDUINO_DUE_X_
29+
// The following values are the same as AVR's USBAPI.h
30+
// Reproduced here because SAM doesn't have these in
31+
// its own USBAPI.H
32+
#define USB_EP_SIZE 64
33+
#define TRANSFER_PGM 0x80
34+
35+
#include "USB/PluggableUSB.h"
36+
#else
37+
#include "PluggableUSB.h"
38+
#endif
2839

2940
#if defined(USBCON)
3041

@@ -108,7 +119,11 @@ class DynamicHID_ : public PluggableUSBModule
108119
uint8_t getShortName(char* name);
109120

110121
private:
122+
#ifdef _VARIANT_ARDUINO_DUE_X_
123+
uint32_t epType[1];
124+
#else
111125
uint8_t epType[1];
126+
#endif
112127

113128
DynamicHIDSubDescriptor* rootNode;
114129
uint16_t descriptorSize;

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Arduino Joystick Library
2-
#### Version 2.0.4
2+
#### Version 2.0.5
33
This library can be used with Arduino IDE 1.6.6 (or above) to add one or more joysticks (or gamepads) to the list of HID devices an [Arduino Leonardo](https://www.arduino.cc/en/Main/ArduinoBoardLeonardo) or [Arduino Micro](https://www.arduino.cc/en/Main/ArduinoBoardMicro) (or any Arduino clone that is based on the ATmega32u4) can support. This will not work with Arduino IDE 1.6.5 (or below) or with non-32u4 based Arduino devices (e.g. Arduino UNO, Arduino MEGA, etc.).
44

55
## Features
@@ -213,6 +213,7 @@ Others have tested this library with the following boards:
213213

214214
- [SparkFun Pro Micro](https://www.sparkfun.com/products/12640)
215215
- [RobotDyn Micro ATmega32U4-MU](http://robotdyn.com/catalog/boards/micro_atmega32u4_mu/) by [@Sylverzerom](https://github.com/Sylverzerom)
216+
- [Arduino Due](https://www.arduino.cc/en/Main/ArduinoBoardDue) by [@Palakis](https://github.com/Palakis)
216217

217218
Boards that should work, but I have not personally tested:
218219

@@ -221,8 +222,6 @@ Boards that should work, but I have not personally tested:
221222
- [Arduino Yún](https://store.arduino.cc/usa/arduino-yun)
222223

223224
Other board notes:
224-
- [Arduino Due](https://www.arduino.cc/en/Main/ArduinoBoardDue) - NOT Supported - I have been told that the old Arduino IDE 1.6.5 (and below) version of this library (see [Add USB Game Controller to Arduino Leonardo or Micro](http://mheironimus.blogspot.com/2015/03/add-usb-game-controller-to-arduino.html))
225-
works with the Arduino Due. I have also been told Version 1.x of the the Arduino Joystick Library will work with the Arduino Duo. However, Version 2.x of the Arduino Joystick Library does not work with Arduino Due at this time.
226225
- [Arduino UNO](https://www.arduino.cc/en/Main/ArduinoBoardUno) - NOT Supported - However, it might work with the [NicoHood/HoodLoader2](https://github.com/NicoHood/HoodLoader2) library, but I have not had a chance to try this out yet.
227226
- [Arduino MEGA](https://www.arduino.cc/en/Main/ArduinoBoardMega2560) - NOT Supported - However, it might work with the [NicoHood/HoodLoader2](https://github.com/NicoHood/HoodLoader2) library, but I have not had a chance to try this out yet.
228227

0 commit comments

Comments
 (0)