aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Kistner <ralf@embarkmobile.com>2014-04-27 14:06:01 +0200
committerRalf Kistner <ralf@embarkmobile.com>2014-12-18 16:25:50 +0200
commit8fed01fe372173d6d859dcb59716bf3d7211be61 (patch)
tree53422b351aca65dd1365bb59fc9456313ac0969e
parentb21ad94e6145de21881ab499396c0eedfd0cc471 (diff)
Allow device reset with sysex message F0 01 F7.
-rw-r--r--avr/cores/arcore/MIDIUSB.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/avr/cores/arcore/MIDIUSB.cpp b/avr/cores/arcore/MIDIUSB.cpp
index fcce78d..cef81f7 100644
--- a/avr/cores/arcore/MIDIUSB.cpp
+++ b/avr/cores/arcore/MIDIUSB.cpp
@@ -3,6 +3,7 @@
#include "USBAPI.h"
#include "USBDesc.h"
#include "MIDIUSB.h"
+#include <avr/wdt.h>
#if defined(USBCON)
#ifdef MIDI_ENABLED
@@ -25,6 +26,15 @@
#define JACK3 0x03
#define JACK4 0x04
+
+
+void watchdogReset() {
+ // Reset after 120ms
+ *(uint16_t *)0x0800 = 0x7777;
+ wdt_enable(WDTO_120MS);
+}
+
+
extern const ACDescriptor _acInterface PROGMEM;
const ACDescriptor _acInterface =
{
@@ -114,6 +124,12 @@ MIDIEvent MIDIUSB_::peek(void)
result.m1 = buffer->buffer[(buffer->tail+1) % MIDI_BUFFER_SIZE];
result.m2 = buffer->buffer[(buffer->tail+2) % MIDI_BUFFER_SIZE];
result.m3 = buffer->buffer[(buffer->tail+3) % MIDI_BUFFER_SIZE];
+
+ // This should perhaps be in accept(), but the check is must simpler / faster here.
+ // It does require the user sketch to read MIDI events though.
+ if(result.type == 0x07 && result.m1 == 0xF0 && result.m3 == 0xF7 && result.m2 == 0x01) {
+ watchdogReset();
+ }
return result;
}
}