Skip to content

Simplify header file a bit #10

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

Merged
merged 2 commits into from
Jan 29, 2016
Merged
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
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ sentence=Allows an Arduino board with USB capabilites to act as a MIDI instrumen
paragraph=
category=Device Control
url=http://www.arduino.cc/en/Reference/MIDIUSB
architectures=*
architectures=avr,sam,samd
57 changes: 29 additions & 28 deletions src/MIDIUSB.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#error MIDIUSB can only be used with an USB MCU.
#endif

#if defined(USBCON)

typedef struct
{
uint8_t header;
Expand All @@ -29,52 +27,56 @@ typedef struct
#if defined(ARDUINO_ARCH_AVR)

#include "PluggableUSB.h"

#define EPTYPE_DESCRIPTOR_SIZE uint8_t
#define EP_TYPE_BULK_OUT_MIDI EP_TYPE_BULK_OUT
#define EP_TYPE_BULK_IN_MIDI EP_TYPE_BULK_IN
#define MIDI_BUFFER_SIZE 64
#define EP_TYPE_BULK_IN_MIDI USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_IN(0);
#define EP_TYPE_BULK_OUT_MIDI USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_OUT(0);
#define MIDI_BUFFER_SIZE USB_EP_SIZE
#define is_write_enabled(x) (1)

#else
#elif defined(ARDUINO_ARCH_SAM)

#include "USB/PluggableUSB.h"
#define EPTYPE_DESCRIPTOR_SIZE uint32_t
#define MIDI_BUFFER_SIZE 512

#if defined(ARDUINO_ARCH_SAM)
#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
#define is_write_enabled(x) Is_udd_write_enabled(x)

#define EPTYPE_DESCRIPTOR_SIZE uint32_t
#define EP_TYPE_BULK_IN_MIDI (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_BULK_OUT_MIDI (UOTGHS_DEVEPTCFG_EPSIZE_512_BYTE | \
UOTGHS_DEVEPTCFG_EPTYPE_BLK | \
UOTGHS_DEVEPTCFG_EPBK_1_BANK | \
UOTGHS_DEVEPTCFG_NBTRANS_1_TRANS | \
UOTGHS_DEVEPTCFG_ALLOC)
#endif
#define MIDI_BUFFER_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
#define is_write_enabled(x) Is_udd_write_enabled(x)

#elif defined(ARDUINO_ARCH_SAMD)

#if defined(__SAMD21G18A__)
#define USB_SendControl USBDevice.sendControl
#define USB_Available USBDevice.available
#define USB_Recv USBDevice.recv
#define USB_Send USBDevice.send
#define USB_Flush USBDevice.flush
#define is_write_enabled(x) (1)
#include "USB/PluggableUSB.h"

#define EPTYPE_DESCRIPTOR_SIZE uint32_t
#define EP_TYPE_BULK_IN_MIDI USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_IN(0);
#define EP_TYPE_BULK_OUT_MIDI USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_OUT(0);
#define MIDI_BUFFER_SIZE EPX_SIZE
#define USB_SendControl USBDevice.sendControl
#define USB_Available USBDevice.available
#define USB_Recv USBDevice.recv
#define USB_Send USBDevice.send
#define USB_Flush USBDevice.flush
#define is_write_enabled(x) (1)

#else

#error "Unsupported architecture"

#endif
#endif

#define MIDI_AUDIO 0x01
Expand Down Expand Up @@ -220,5 +222,4 @@ class MIDI_ : public PluggableUSBModule
};
extern MIDI_ MidiUSB;

#endif /* USBCON */
#endif /* MIDIUSB_h */
#endif /* MIDIUSB_h */