Made Magic Key Settings more flexible

This commit is contained in:
NicoHood 2015-08-07 19:36:28 +02:00
parent 78700c6556
commit deb59fd605
1 changed files with 20 additions and 3 deletions

View File

@ -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;