aboutsummaryrefslogtreecommitdiff
path: root/cores
diff options
context:
space:
mode:
authorNicoHood <NicoHood@users.noreply.github.com>2015-08-07 19:36:28 +0200
committerNicoHood <NicoHood@users.noreply.github.com>2015-08-12 17:48:09 +0200
commitdeb59fd6054ce105487bd107dec014fab116cc3a (patch)
treeca7dc1bd9f8a71ef06983e3eeb7bb6cbdc4f6050 /cores
parent78700c655602c850c357f5c557ef756860b33357 (diff)
Made Magic Key Settings more flexible
Diffstat (limited to 'cores')
-rw-r--r--cores/arduino/CDC.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/cores/arduino/CDC.cpp b/cores/arduino/CDC.cpp
index d694a2d..63983d9 100644
--- a/cores/arduino/CDC.cpp
+++ b/cores/arduino/CDC.cpp
@@ -92,11 +92,24 @@ bool CDC_Setup(USBSetup& setup)
// with a relatively long period so it can finish housekeeping tasks
// like servicing endpoints before the sketch ends
+#ifndef MAGIC_KEY
+#define MAGIC_KEY 0x7777
+#endif
+#ifndef MAGIC_KEY_POS
+#define MAGIC_KEY_POS 0x0800
+#endif
+
// We check DTR state to determine if host port is open (bit 0 of lineState).
if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0)
{
- *(uint16_t *)(RAMEND-1) = *(uint16_t *)0x0800;
- *(uint16_t *)0x0800 = 0x7777;
+#if MAGIC_KEY_POS != (RAMEND-1)
+ *(uint16_t *)(RAMEND-1) = *(uint16_t *)MAGIC_KEY_POS;
+ *(uint16_t *)MAGIC_KEY_POS = MAGIC_KEY;
+#else
+ // for future boards save the key in the inproblematic RAMEND
+ // which is reserved for the main() return value (which will never return)
+ *(uint16_t *)MAGIC_KEY_POS = MAGIC_KEY;
+#endif
wdt_enable(WDTO_120MS);
}
else
@@ -108,7 +121,11 @@ bool CDC_Setup(USBSetup& setup)
wdt_disable();
wdt_reset();
- *(uint16_t *)0x0800 = *(uint16_t *)(RAMEND-1);
+#if MAGIC_KEY_POS != (RAMEND-1)
+ *(uint16_t *)MAGIC_KEY_POS = *(uint16_t *)(RAMEND-1);
+#else
+ *(uint16_t *)MAGIC_KEY_POS = 0x0000;
+#endif
}
}
return true;