Skip to content

Commit

Permalink
Merge pull request #146 from facchinm/samd
Browse files Browse the repository at this point in the history
Port to SAMD architecture
  • Loading branch information
NicoHood authored Sep 15, 2018
2 parents 266fe92 + 756b32e commit b632a63
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/HID-APIs/SystemAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void SystemAPI::releaseAll(void){
}

void SystemAPI::press(SystemKeycode s){
#ifdef USBCON
#if defined(__AVR__) && defined(USBCON)
if (s == SYSTEM_WAKE_UP)
USBDevice.wakeupHost();
else
Expand Down
60 changes: 60 additions & 0 deletions src/HID-Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,64 @@ THE SOFTWARE.

#ifndef HID_REPORTID_SURFACEDIAL
#define HID_REPORTID_SURFACEDIAL 10
#endif

#if defined(ARDUINO_ARCH_AVR)

#include "PluggableUSB.h"

#define EPTYPE_DESCRIPTOR_SIZE uint8_t

#elif defined(ARDUINO_ARCH_SAM)

#include "USB/PluggableUSB.h"

#define EPTYPE_DESCRIPTOR_SIZE uint32_t
#define EP_TYPE_INTERRUPT_IN (UOTGHS_DEVEPTCFG_EPSIZE_512_BYTE | \
UOTGHS_DEVEPTCFG_EPDIR_IN | \
UOTGHS_DEVEPTCFG_EPTYPE_BLK | \
UOTGHS_DEVEPTCFG_EPBK_1_BANK | \
UOTGHS_DEVEPTCFG_NBTRANS_1_TRANS | \
UOTGHS_DEVEPTCFG_ALLOC)
#define EP_TYPE_INTERRUPT_OUT (UOTGHS_DEVEPTCFG_EPSIZE_512_BYTE | \
UOTGHS_DEVEPTCFG_EPTYPE_BLK | \
UOTGHS_DEVEPTCFG_EPBK_1_BANK | \
UOTGHS_DEVEPTCFG_NBTRANS_1_TRANS | \
UOTGHS_DEVEPTCFG_ALLOC)
#define USB_EP_SIZE EPX_SIZE
#define USB_SendControl USBD_SendControl
#define USB_Available USBD_Available
#define USB_Recv USBD_Recv
#define USB_Send USBD_Send
#define USB_Flush USBD_Flush

#elif defined(ARDUINO_ARCH_SAMD)

#include "USB/PluggableUSB.h"

#define EPTYPE_DESCRIPTOR_SIZE uint32_t
#define EP_TYPE_INTERRUPT_IN USB_ENDPOINT_TYPE_INTERRUPT | USB_ENDPOINT_IN(0);
#define EP_TYPE_INTERRUPT_OUT USB_ENDPOINT_TYPE_INTERRUPT | USB_ENDPOINT_OUT(0);
#define USB_EP_SIZE EPX_SIZE
//#define USB_SendControl USBDevice.sendControl -> real C++ functions to take care of PGM overloading
#define USB_Available USBDevice.available
#define USB_Recv USBDevice.recv
#define USB_RecvControl USBDevice.recvControl
#define USB_Send USBDevice.send
#define USB_Flush USBDevice.flush

int USB_SendControl(void* y, uint8_t z);
int USB_SendControl(uint8_t x, const void* y, uint8_t z);

#define TRANSFER_PGM 0
#define TRANSFER_RELEASE 0

#define HID_REPORT_TYPE_INPUT 1
#define HID_REPORT_TYPE_OUTPUT 2
#define HID_REPORT_TYPE_FEATURE 3

#else

#error "Unsupported architecture"

#endif
1 change: 0 additions & 1 deletion src/MultiReport/AbsoluteMouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/AbsoluteMouseAPI.h"
Expand Down
1 change: 0 additions & 1 deletion src/MultiReport/Consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/ConsumerAPI.h"
Expand Down
1 change: 0 additions & 1 deletion src/MultiReport/Gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/GamepadAPI.h"
Expand Down
2 changes: 2 additions & 0 deletions src/MultiReport/ImprovedKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ int Keyboard_::send(void)
}

void Keyboard_::wakeupHost(void){
#ifdef __AVR__
USBDevice.wakeupHost();
#endif
}

Keyboard_ Keyboard;
Expand Down
1 change: 0 additions & 1 deletion src/MultiReport/ImprovedKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/DefaultKeyboardAPI.h"
Expand Down
1 change: 0 additions & 1 deletion src/MultiReport/ImprovedMouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/MouseAPI.h"
Expand Down
1 change: 0 additions & 1 deletion src/MultiReport/NKROKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/NKROKeyboardAPI.h"
Expand Down
1 change: 0 additions & 1 deletion src/MultiReport/SurfaceDial.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/SurfaceDialAPI.h"
Expand Down
1 change: 0 additions & 1 deletion src/MultiReport/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/SystemAPI.h"
Expand Down
6 changes: 6 additions & 0 deletions src/SingleReport/BootKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,16 @@ bool BootKeyboard_::setup(USBSetup& setup)
}
if (request == HID_GET_PROTOCOL) {
// TODO improve
#ifdef __AVR__
UEDATX = protocol;
#endif
return true;
}
if (request == HID_GET_IDLE) {
// TODO improve
#ifdef __AVR__
UEDATX = idle;
#endif
return true;
}
}
Expand Down Expand Up @@ -196,7 +200,9 @@ int BootKeyboard_::send(void){
}

void BootKeyboard_::wakeupHost(void){
#ifdef __AVR__
USBDevice.wakeupHost();
#endif
}


Expand Down
3 changes: 1 addition & 2 deletions src/SingleReport/BootKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/DefaultKeyboardAPI.h"
Expand Down Expand Up @@ -72,7 +71,7 @@ class BootKeyboard_ : public PluggableUSBModule, public DefaultKeyboardAPI
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);

uint8_t epType[1];
EPTYPE_DESCRIPTOR_SIZE epType[1];
uint8_t protocol;
uint8_t idle;

Expand Down
3 changes: 1 addition & 2 deletions src/SingleReport/BootMouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/MouseAPI.h"
Expand All @@ -43,7 +42,7 @@ class BootMouse_ : public PluggableUSBModule, public MouseAPI
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);

uint8_t epType[1];
EPTYPE_DESCRIPTOR_SIZE epType[1];
uint8_t protocol;
uint8_t idle;

Expand Down
3 changes: 1 addition & 2 deletions src/SingleReport/RawHID.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"

Expand Down Expand Up @@ -164,7 +163,7 @@ class RawHID_ : public PluggableUSBModule, public Stream
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);

uint8_t epType[1];
EPTYPE_DESCRIPTOR_SIZE epType[1];
uint8_t protocol;
uint8_t idle;

Expand Down
3 changes: 1 addition & 2 deletions src/SingleReport/SingleAbsoluteMouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/AbsoluteMouseAPI.h"
Expand All @@ -44,7 +43,7 @@ class SingleAbsoluteMouse_ : public PluggableUSBModule, public AbsoluteMouseAPI
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);

uint8_t epType[1];
EPTYPE_DESCRIPTOR_SIZE epType[1];
uint8_t protocol;
uint8_t idle;

Expand Down
3 changes: 1 addition & 2 deletions src/SingleReport/SingleConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/ConsumerAPI.h"
Expand All @@ -44,7 +43,7 @@ class SingleConsumer_ : public PluggableUSBModule, public ConsumerAPI
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);

uint8_t epType[1];
EPTYPE_DESCRIPTOR_SIZE epType[1];
uint8_t protocol;
uint8_t idle;

Expand Down
3 changes: 1 addition & 2 deletions src/SingleReport/SingleGamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/GamepadAPI.h"
Expand All @@ -42,7 +41,7 @@ class SingleGamepad_ : public PluggableUSBModule, public GamepadAPI
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);

uint8_t epType[1];
EPTYPE_DESCRIPTOR_SIZE epType[1];
uint8_t protocol;
uint8_t idle;

Expand Down
3 changes: 1 addition & 2 deletions src/SingleReport/SingleNKROKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/NKROKeyboardAPI.h"
Expand All @@ -46,7 +45,7 @@ class SingleNKROKeyboard_ : public PluggableUSBModule, public NKROKeyboardAPI
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);

uint8_t epType[1];
EPTYPE_DESCRIPTOR_SIZE epType[1];
uint8_t protocol;
uint8_t idle;

Expand Down
3 changes: 1 addition & 2 deletions src/SingleReport/SingleSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
#pragma once

#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/SystemAPI.h"
Expand All @@ -44,7 +43,7 @@ class SingleSystem_ : public PluggableUSBModule, public SystemAPI
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);

uint8_t epType[1];
EPTYPE_DESCRIPTOR_SIZE epType[1];
uint8_t protocol;
uint8_t idle;

Expand Down
13 changes: 13 additions & 0 deletions src/port/samd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "Arduino.h"

#ifdef ARDUINO_ARCH_SAMD

int USB_SendControl(void* b, unsigned char c) {
USBDevice.sendControl(b, c);
}

int USB_SendControl(uint8_t a, const void* b, uint8_t c) {
USBDevice.sendControl(b, c);
}

#endif

0 comments on commit b632a63

Please sign in to comment.