aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Delmar Davis <don@suspectdevices.com>2013-09-27 01:59:45 -0700
committerDonald Delmar Davis <don@suspectdevices.com>2013-09-27 01:59:45 -0700
commit8b1bcab92572124582a99dd5ac8eb03e56d50d53 (patch)
treef06ac33b14e280d10fba0f04ebcdce227debed37
parentd24d49ea00201dd5722cc8f7c833263e662bdf03 (diff)
Put unprocessed sysexes into a buffer;
Start pushing USB_MIDI functionality away from main program.
-rw-r--r--MinSysex.c80
-rw-r--r--MinSysex.h9
-rw-r--r--README.md13
-rwxr-xr-xUSB_MIDI.c (renamed from MIDI.c)13
-rwxr-xr-xUSB_MIDI.h (renamed from MIDI.h)0
-rwxr-xr-xloadhex.py6
-rwxr-xr-xmakefile2
7 files changed, 102 insertions, 21 deletions
diff --git a/MinSysex.c b/MinSysex.c
index 9b17767..9935de7 100644
--- a/MinSysex.c
+++ b/MinSysex.c
@@ -41,8 +41,6 @@
#include <avr/wdt.h>
#include <util/delay.h>
-#define MAX_SYSEX_SIZE ((256+1)/4)
-
/********************************* ACHTUNG! ignores usbmidi cable ********************************/
const MIDI_EVENT_PACKET_t standardIDResponse[]={
{ CIN_SYSEX,
@@ -78,7 +76,7 @@ const MIDI_EVENT_PACKET_t standardIDResponse[]={
};
typedef enum {NOT_IN_SYSEX=0,COULD_BE_MY_SYSEX,YUP_ITS_MY_SYSEX,ITS_NOT_MY_SYSEX} sysexStates;
-volatile MIDI_EVENT_PACKET_t sysexBuffer[MAX_SYSEX_SIZE];
+volatile MIDI_EVENT_PACKET_t sysexBuffer[MAX_LGL_SYSEX_SIZE];
volatile sysexStates sysexState;
volatile int sysexFinger=0;
@@ -125,14 +123,27 @@ void dealWithItQuickly(){
break;
case ARDUINO_MMA_VENDOR_1:
if (sysexBuffer[1].midi2==LGL_RESET_CMD) {
-
Jump_To_Bootloader();
- /* Can't happen. */
- //ASSERT_FAULT(0);
-
+
}
default:
+ // userland sysex copy the sysex to the buffer if its not handled by us....
+ mySysexBufferIndex=0;
+ for (uint8_t i=0; i<sysexFinger; i++) {
+ mySysexBuffer[mySysexBufferIndex++]=sysexBuffer[i].midi0;
+ if ((sysexBuffer[i].cin == CIN_SYSEX_ENDS_IN_1)
+ ||(sysexBuffer[i].cin == CIN_1BYTE)
+ ) continue;
+ mySysexBuffer[mySysexBufferIndex++]=sysexBuffer[i].midi1;
+ if ((sysexBuffer[i].cin == CIN_SYSEX_ENDS_IN_2)
+ ||(sysexBuffer[i].cin == CIN_PROGRAM_CHANGE)
+ ||(sysexBuffer[i].cin == CIN_CHANNEL_PRESSURE)
+ ||(sysexBuffer[i].cin == CIN_2BYTE_SYS_COMMON)
+ ) continue;
+ mySysexBuffer[mySysexBufferIndex++]=sysexBuffer[i].midi2;
+ }
+
break;
}
;//turn the led on?
@@ -148,7 +159,8 @@ void minSysexHandler(MIDI_EVENT_PACKET_t e) {
}
if ((sysexState==YUP_ITS_MY_SYSEX) && (sysexFinger>MAX_SYSEX_SIZE)){
- sysexState=ITS_NOT_MY_SYSEX; //eisenhower policy. Even if its mine I cant deal with it.
+ sysexState=ITS_NOT_MY_SYSEX;
+ // move the data here to the sysex buffer....
}
switch (e.cin) {
@@ -157,8 +169,6 @@ void minSysexHandler(MIDI_EVENT_PACKET_t e) {
case NOT_IN_SYSEX : // new sysex.
sysexFinger=0;
if (e.midi0 == MIDIv1_SYSEX_START) {
-
-
if (e.midi1==USYSEX_REAL_TIME
||e.midi1==USYSEX_NON_REAL_TIME) {
if ((e.midi2==myMidiChannel)
@@ -182,11 +192,39 @@ void minSysexHandler(MIDI_EVENT_PACKET_t e) {
sysexBuffer[sysexFinger++]=e;
} else {
sysexState=ITS_NOT_MY_SYSEX;
+ sysexBuffer[sysexFinger++]=e;
+ //move previous data to sysex
+ mySysexBufferIndex=0;
+ for (uint8_t i=0; i<sysexFinger; i++) {
+ mySysexBuffer[mySysexBufferIndex++]=sysexBuffer[i].midi0;
+ if ((sysexBuffer[i].cin == CIN_SYSEX_ENDS_IN_1)
+ ||(sysexBuffer[i].cin == CIN_1BYTE)
+ ) continue;
+ mySysexBuffer[mySysexBufferIndex++]=sysexBuffer[i].midi1;
+ if ((sysexBuffer[i].cin == CIN_SYSEX_ENDS_IN_2)
+ ||(sysexBuffer[i].cin == CIN_PROGRAM_CHANGE)
+ ||(sysexBuffer[i].cin == CIN_CHANNEL_PRESSURE)
+ ||(sysexBuffer[i].cin == CIN_2BYTE_SYS_COMMON)
+ ) continue;
+ mySysexBuffer[mySysexBufferIndex++]=sysexBuffer[i].midi2;
+ }
+
}
break;
case YUP_ITS_MY_SYSEX:
sysexBuffer[sysexFinger++]=e;
break;
+ case ITS_NOT_MY_SYSEX:
+ // if the buffer is full DTMFA
+ if ((mySysexBufferIndex+3)<MAX_SYSEX_SIZE) {
+ mySysexBufferIndex=0;
+ sysexState=NOT_IN_SYSEX;
+ } else {
+ mySysexBuffer[mySysexBufferIndex++]=e.midi0;
+ mySysexBuffer[mySysexBufferIndex++]=e.midi1;
+ mySysexBuffer[mySysexBufferIndex++]=e.midi2;
+ }
+
default:
break;
}
@@ -198,8 +236,16 @@ void minSysexHandler(MIDI_EVENT_PACKET_t e) {
if (sysexState==YUP_ITS_MY_SYSEX) {
dealWithItQuickly(); // its our sysex and we will cry if we want to
LEDs_ToggleLEDs(LEDS_LED2);
+ } else {
+ mySysexBuffer[mySysexBufferIndex++]=e.midi0;
+ if (e.cin != CIN_SYSEX_ENDS_IN_1) {
+ mySysexBuffer[mySysexBufferIndex++]=e.midi1;
+ } else if (e.cin == CIN_SYSEX_ENDS_IN_3) {
+ mySysexBuffer[mySysexBufferIndex++]=e.midi2;
+ }
}
- //sysexFinger=0;
+
+ //move sysex data to buffer...
sysexState=NOT_IN_SYSEX;
break;
default:
@@ -218,4 +264,16 @@ void Jump_To_Bootloader(void)
*(uint16_t *)0x0800 = 0x7777;
wdt_enable(WDTO_250MS);
for (;;);
+}
+
+void Software_Reset(void)
+{
+ // If USB is used, detach from the bus and reset it
+ USB_Disable(); // Disable all interrupts
+ cli();
+ // Wait for the USB detachment to register on the host
+ Delay_MS(500);
+ *(uint16_t *)0x0800 = 0;
+ wdt_enable(WDTO_250MS);
+ for (;;);
} \ No newline at end of file
diff --git a/MinSysex.h b/MinSysex.h
index 8a16b98..a7b31b7 100644
--- a/MinSysex.h
+++ b/MinSysex.h
@@ -10,7 +10,7 @@
#include "MidiSpecs.h"
-#include "MIDI.h"
+#include "USB_MIDI.h"
//#include "LGL.h"
#define ARDUINO_MMA_VENDOR_1 0x7D
@@ -25,12 +25,19 @@
#define DEFAULT_MIDI_DEVICE 0x0A
#define DEFAULT_MIDI_CABLE 0x00
+#define MAX_LGL_SYSEX_SIZE ((16+1)/4)
+#define MAX_SYSEX_SIZE (128)
+
// eventually all of this should be in a place for settings which can be written to flash.
extern volatile uint8_t myMidiChannel;
extern volatile uint8_t myMidiDevice;
extern volatile uint8_t myMidiCable;
extern volatile uint8_t myMidiID[];
extern USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface;
+extern volatile uint8_t mySysexBuffer[];
+extern volatile uint8_t mySysexBufferIndex;
+
+
void LglSysexHandler(uint32_t *midiBufferRx,uint32_t *rx_offset,uint32_t *n_unread_bytes);
void minSysexHandler(MIDI_EVENT_PACKET_t e);
diff --git a/README.md b/README.md
index f14a517..152ffaa 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,14 @@
The idea here is to create a lufa based midi framework for use on the stock arduino.
+The goal is twofold 1) to isolate the lower level usb functions from the actual programs
+and 2) to create a minimal framework for identifying resetting and loading code onto
+midi devices.
+
+Packet midi.
+The majority of the usb-midi specification is in simgle 4 byte events or packets.
+The exception to this are sysex messages which are arbitrary in length.
+
+Because of this the two streams are split out.
+
+
+
+
diff --git a/MIDI.c b/USB_MIDI.c
index e5cf63b..b1a505d 100755
--- a/MIDI.c
+++ b/USB_MIDI.c
@@ -34,7 +34,7 @@
* the demo and is responsible for the initial application hardware configuration.
*/
-#include "MIDI.h"
+#include "USB_MIDI.h"
/** LUFA MIDI Class driver interface configuration and state information. This structure is
* passed to all MIDI Class driver functions, so that multiple instances of the same class
@@ -64,6 +64,8 @@ volatile uint8_t myMidiChannel=DEFAULT_MIDI_CHANNEL;
volatile uint8_t myMidiDevice=DEFAULT_MIDI_DEVICE;
volatile uint8_t myMidiCable=DEFAULT_MIDI_CABLE;
volatile uint8_t myMidiID[]={ARDUINO_MMA_VENDOR_1 ,ARDUINO_MMA_VENDOR_2,ARDUINO_MMA_VENDOR_3};
+volatile uint8_t mySysexBuffer[MAX_SYSEX_SIZE];
+volatile uint8_t mySysexBufferIndex;
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
@@ -82,8 +84,11 @@ int main(void)
while (MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, (MIDI_EventPacket_t *)(&e)))
{
- minSysexHandler(e);
-
+ if (CIN_IS_SYSEX(e.cin)) {
+ minSysexHandler(e);
+
+ }
+
}
MIDI_Device_USBTask(&USB_MIDI_Interface);
@@ -114,9 +119,7 @@ void SetupHardware(void)
#endif
/* Hardware Initialization */
-// Joystick_Init();
LEDs_Init();
-// Buttons_Init();
USB_Init();
}
diff --git a/MIDI.h b/USB_MIDI.h
index ba257ea..ba257ea 100755
--- a/MIDI.h
+++ b/USB_MIDI.h
diff --git a/loadhex.py b/loadhex.py
index ff877d0..8b22780 100755
--- a/loadhex.py
+++ b/loadhex.py
@@ -50,8 +50,8 @@ ARDUINO_MMA_VENDOR_1 =0x7D
ARDUINO_MMA_VENDOR_2 =0x23
ARDUINO_MMA_VENDOR_3 =0x41
-LGL_RESET_CMD =0x1e
-#LGL_BOOTLOADER_CMD =0x1f
+LGL_RESET_CMD =0x1f
+LGL_BOOTLOADER_CMD =0x1e
we_are_done=False
@@ -64,7 +64,7 @@ resetthedevice=[SYSEX_BEGIN,
ARDUINO_MMA_VENDOR_2,
ARDUINO_MMA_VENDOR_3,
0x0a, #device/channel is currently ignored...
- LGL_RESET_CMD,
+ LGL_BOOTLOADER_CMD,
SYSEX_END_SYSEX]
# main code begins here.
diff --git a/makefile b/makefile
index 5c2fd21..b9912dd 100755
--- a/makefile
+++ b/makefile
@@ -17,7 +17,7 @@ BOARD = LEONARDO
F_CPU = 16000000
F_USB = $(F_CPU)
OPTIMIZATION = s
-TARGET = MIDI
+TARGET = USB_MIDI
SRC = $(TARGET).c Descriptors.c MinSysex.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS)
LUFA_PATH = ../../../../LUFA
CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/