aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Kistner <ralf.kistner@gmail.com>2013-03-18 21:31:27 +0200
committerRalf Kistner <ralf.kistner@gmail.com>2013-03-18 21:31:27 +0200
commit94cfd154d47dc9b4a8345ed9df196a7623143d9f (patch)
tree0d03cc41525ec7862a4775b6cfaff34bbdd242d5
parent1c216226e4152799352bfc08b22b49d258489164 (diff)
MIDI-USB descriptors.
-rw-r--r--avr/cores/arcore/MIDIUSB.cpp75
-rw-r--r--avr/cores/arcore/MIDIUSB.h0
-rw-r--r--avr/cores/arcore/USBAPI.h8
-rw-r--r--avr/cores/arcore/USBCore.cpp21
-rw-r--r--avr/cores/arcore/USBCore.h85
-rw-r--r--avr/cores/arcore/USBDesc.h25
6 files changed, 209 insertions, 5 deletions
diff --git a/avr/cores/arcore/MIDIUSB.cpp b/avr/cores/arcore/MIDIUSB.cpp
new file mode 100644
index 0000000..925cdf7
--- /dev/null
+++ b/avr/cores/arcore/MIDIUSB.cpp
@@ -0,0 +1,75 @@
+
+#include "Platform.h"
+#include "USBAPI.h"
+#include "USBDesc.h"
+
+#if defined(USBCON)
+#ifdef MIDI_ENABLED
+
+#define WEAK __attribute__ ((weak))
+
+#define CLASS_AUDIO 0x01
+#define SUBCLASS_AUDIO_CONTROL 0x01
+#define SUBCLASS_MIDISTREAMING 0x03
+
+#define TYPE_CS_INTERFACE 0x24
+#define SUBTYPE_HEADER 0x01
+#define SUBTYPE_MIDI_IN_JACK 0x02
+#define SUBTYPE_MIDI_OUT_JACK 0x03
+#define JACK_EMBEDDED 0x01
+#define JACK_EXTERNAL 0x02
+
+#define JACK1 0x01
+#define JACK2 0x02
+#define JACK3 0x03
+#define JACK4 0x04
+
+extern const ACDescriptor _acInterface PROGMEM;
+const ACDescriptor _acInterface =
+{
+ D_INTERFACE(AC_INTERFACE,0,CLASS_AUDIO,SUBCLASS_AUDIO_CONTROL,0),
+ {9, TYPE_CS_INTERFACE, SUBTYPE_HEADER, 0x0100, 9, 0x01, MIDI_INTERFACE}
+};
+
+int WEAK AC_GetInterface(u8* interfaceNum)
+{
+ interfaceNum[0] += 1; // uses 1
+ return USB_SendControl(TRANSFER_PGM,&_acInterface,sizeof(_acInterface));
+}
+
+extern const MIDIDescriptor _midiInterface PROGMEM;
+const MIDIDescriptor _midiInterface =
+{
+ D_INTERFACE(MIDI_INTERFACE,MIDI_ENDPOINT_COUNT,CLASS_AUDIO,SUBCLASS_MIDISTREAMING,0),
+ {7, TYPE_CS_INTERFACE, SUBTYPE_HEADER, 0x0100, 34},
+ {6, TYPE_CS_INTERFACE, SUBTYPE_MIDI_IN_JACK, JACK_EMBEDDED, JACK1, 0x00},
+ {9, TYPE_CS_INTERFACE, SUBTYPE_MIDI_OUT_JACK, JACK_EMBEDDED, JACK2, 1, JACK3, 1, 0x00},
+ {6, TYPE_CS_INTERFACE, SUBTYPE_MIDI_IN_JACK, JACK_EXTERNAL, JACK3, 0x00},
+ {9, TYPE_CS_INTERFACE, SUBTYPE_MIDI_OUT_JACK, JACK_EXTERNAL, JACK4, 1, JACK1, 1, 0x00},
+ {
+ D_ENDPOINT(USB_ENDPOINT_OUT(MIDI_ENDPOINT_OUT), USB_ENDPOINT_TYPE_BULK, 0x0040, 0x00),
+ { 5, 0x25, 0x01, 0x01, JACK1 }
+ },
+ {
+ D_ENDPOINT(USB_ENDPOINT_IN(MIDI_ENDPOINT_IN), USB_ENDPOINT_TYPE_BULK, 0x0040, 0x00),
+ { 5, 0x25, 0x01, 0x01, JACK2 }
+ }
+};
+
+
+int WEAK MIDI_GetInterface(u8* interfaceNum)
+{
+ interfaceNum[0] += 1; // uses 1
+ return USB_SendControl(TRANSFER_PGM,&_midiInterface,sizeof(_midiInterface));
+}
+
+bool WEAK MIDI_Setup(Setup& setup)
+{
+ u8 r = setup.bRequest;
+ u8 requestType = setup.bmRequestType;
+
+ return false;
+}
+
+#endif
+#endif
diff --git a/avr/cores/arcore/MIDIUSB.h b/avr/cores/arcore/MIDIUSB.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/avr/cores/arcore/MIDIUSB.h
diff --git a/avr/cores/arcore/USBAPI.h b/avr/cores/arcore/USBAPI.h
index eb2e593..f12277e 100644
--- a/avr/cores/arcore/USBAPI.h
+++ b/avr/cores/arcore/USBAPI.h
@@ -177,6 +177,14 @@ bool CDC_Setup(Setup& setup);
//================================================================================
//================================================================================
+// MIDI/AC 'Driver'
+
+int AC_GetInterface(uint8_t* interfaceNum);
+int MIDI_GetInterface(uint8_t* interfaceNum);
+bool MIDI_Setup(Setup& setup);
+
+//================================================================================
+//================================================================================
#define TRANSFER_PGM 0x80
#define TRANSFER_RELEASE 0x40
diff --git a/avr/cores/arcore/USBCore.cpp b/avr/cores/arcore/USBCore.cpp
index d3e0170..735ca18 100644
--- a/avr/cores/arcore/USBCore.cpp
+++ b/avr/cores/arcore/USBCore.cpp
@@ -329,7 +329,12 @@ const u8 _initEndpoints[] =
#endif
#ifdef HID_ENABLED
- EP_TYPE_INTERRUPT_IN // HID_ENDPOINT_INT
+ EP_TYPE_INTERRUPT_IN, // HID_ENDPOINT_INT
+#endif
+
+#ifdef MIDI_ENABLED
+ EP_TYPE_BULK_OUT,
+ EP_TYPE_BULK_IN,
#endif
};
@@ -374,6 +379,11 @@ bool ClassInterfaceRequest(Setup& setup)
if (HID_INTERFACE == i)
return HID_Setup(setup);
#endif
+
+#ifdef MIDI_ENABLED
+ if (MIDI_INTERFACE == i)
+ return MIDI_Setup(setup);
+#endif
return false;
}
@@ -440,6 +450,11 @@ int SendInterfaces()
total += HID_GetInterface(&interfaces);
#endif
+#ifdef MIDI_ENABLED
+ total += AC_GetInterface(&interfaces);
+ total += MIDI_GetInterface(&interfaces);
+#endif
+
return interfaces;
}
@@ -614,7 +629,9 @@ ISR(USB_GEN_vect)
if (USB_Available(CDC_RX)) // Handle received bytes (if any)
Serial.accept();
#endif
-
+#ifdef MIDI_ENABLED
+ // TODO: implement midi receive here
+#endif
// check whether the one-shot period has elapsed. if so, turn off the LED
if (TxLEDPulse && !(--TxLEDPulse))
TXLED0;
diff --git a/avr/cores/arcore/USBCore.h b/avr/cores/arcore/USBCore.h
index 8d13806..bf75862 100644
--- a/avr/cores/arcore/USBCore.h
+++ b/avr/cores/arcore/USBCore.h
@@ -277,6 +277,89 @@ typedef struct
EndpointDescriptor in;
} HIDDescriptor;
+typedef struct
+{
+ u8 len; // 9
+ u8 dtype; // 0x24
+ u8 subtype; // 0x01
+ u16 revision; // 0x0100
+ u16 totalLen; // 0x0009
+ u8 nsi; // 0x01
+ u8 inr; // 0x01
+} ACInterfaceDescriptor;
+
+typedef struct
+{
+ InterfaceDescriptor ac;
+ ACInterfaceDescriptor desc;
+} ACDescriptor;
+
+typedef struct
+{
+ u8 len; // 5
+ u8 dtype; // 0x25
+ u8 subtype; //0x01
+ u8 n; //0x01;
+ u8 jackId; //0x01;
+} MIDIEndpointDescriptor;
+
+typedef struct
+{
+ EndpointDescriptor midi;
+ MIDIEndpointDescriptor desc;
+} MIDIEndpoint;
+
+// 0 1 0x05 Size of this descriptor, in bytes.
+// 1 bDescriptorType 1 0x25 CS_ENDPOINT descriptor
+// 2 bDescriptorSubtype 1 0x01 MS_GENERAL subtype.
+// 3 bNumEmbMIDIJack 1 0x01 Number of embedded MIDI IN Jacks.
+// 4 BaAssocJackID(1) 1 0x01 ID of the Embedded MIDI IN Jack.
+
+typedef struct
+{
+ u8 len; // 7
+ u8 dtype; // 0x24
+ u8 subtype; // 0x01
+ u16 revision; // 0x0100
+ u16 totalLen; // 0x0000
+} MIDIInterfaceDescriptor;
+
+typedef struct
+{
+ u8 len; // 6
+ u8 dtype; // 0x24
+ u8 subtype; // MIDI_IN_JACK
+ u8 jackType;
+ u8 index;
+ u8 unused;
+} MIDIJackIn;
+
+typedef struct
+{
+ u8 len; // 9
+ u8 dtype; // 0x24
+ u8 subtype; // MIDI_OUT_JACK
+ u8 jackType;
+ u8 index;
+ u8 nrPins;
+ u8 sourceId;
+ u8 sourcePin;
+ u8 unused;
+} MIDIJackOut;
+
+typedef struct
+{
+ InterfaceDescriptor midi;
+ MIDIInterfaceDescriptor desc;
+ MIDIJackIn jack1;
+ MIDIJackOut jack2;
+ MIDIJackIn jack3;
+ MIDIJackOut jack4;
+ MIDIEndpoint endpoint1;
+ MIDIEndpoint endpoint2;
+} MIDIDescriptor;
+
+
#define D_DEVICE(_class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs) \
{ 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
@@ -300,4 +383,4 @@ typedef struct
#define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 }
-#endif \ No newline at end of file
+#endif
diff --git a/avr/cores/arcore/USBDesc.h b/avr/cores/arcore/USBDesc.h
index 900713e..77de89c 100644
--- a/avr/cores/arcore/USBDesc.h
+++ b/avr/cores/arcore/USBDesc.h
@@ -18,7 +18,7 @@
#define CDC_ENABLED
#define HID_ENABLED
-
+#define MIDI_ENABLED
#ifdef CDC_ENABLED
#define CDC_INTERFACE_COUNT 2
@@ -36,6 +36,16 @@
#define HID_ENPOINT_COUNT 0
#endif
+
+#ifdef MIDI_ENABLED
+#define MIDI_INTERFACE_COUNT 2
+#define MIDI_ENDPOINT_COUNT 2
+#else
+#define MIDI_INTERFACE_COUNT 0
+#define MIDI_ENDPOINT_COUNT 0
+#endif
+
+
#define CDC_ACM_INTERFACE 0 // CDC ACM
#define CDC_DATA_INTERFACE 1 // CDC Data
#define CDC_FIRST_ENDPOINT 1
@@ -47,7 +57,13 @@
#define HID_FIRST_ENDPOINT (CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT)
#define HID_ENDPOINT_INT (HID_FIRST_ENDPOINT)
-#define INTERFACE_COUNT (MSC_INTERFACE + MSC_INTERFACE_COUNT)
+#define AC_INTERFACE (HID_INTERFACE + HID_INTERFACE_COUNT)
+#define MIDI_INTERFACE (AC_INTERFACE+1)
+#define MIDI_FIRST_ENDPOINT (HID_FIRST_ENDPOINT + HID_ENPOINT_COUNT)
+#define MIDI_ENDPOINT_OUT (MIDI_FIRST_ENDPOINT)
+#define MIDI_ENDPOINT_IN (MIDI_FIRST_ENDPOINT+1)
+
+#define INTERFACE_COUNT (AC_INTERFACE + MIDI_INTERFACE_COUNT)
#ifdef CDC_ENABLED
#define CDC_RX CDC_ENDPOINT_OUT
@@ -58,6 +74,11 @@
#define HID_TX HID_ENDPOINT_INT
#endif
+#ifdef MIDI_ENABLED
+#define MIDI_RX MIDI_ENDPOINT_OUT
+#define MIDI_TX MIDI_ENDPOINT_IN
+#endif
+
#define IMANUFACTURER 1
#define IPRODUCT 2