Fix bootloader jump

This commit is contained in:
William Toohey
2016-03-20 21:14:14 +10:00
parent 9a6ae6d3c8
commit 523dd87df3
4 changed files with 24 additions and 17 deletions

View File

@@ -13,21 +13,6 @@ static tatacon_config_t defaults PROGMEM = {
HID_KEYBOARD_SC_Z,
HID_KEYBOARD_SC_C,
HID_KEYBOARD_SC_V },
// ---- monty
//HID_KEYBOARD_SC_X,
//HID_KEYBOARD_SC_Z,
//HID_KEYBOARD_SC_DOT_AND_GREATER_THAN_SIGN,
//HID_KEYBOARD_SC_SLASH_AND_QUESTION_MARK },
// ---- sand
//HID_KEYBOARD_SC_S,
//HID_KEYBOARD_SC_A,
//HID_KEYBOARD_SC_G,
//HID_KEYBOARD_SC_H },
// ---- tobuei
//HID_KEYBOARD_SC_S,
//HID_KEYBOARD_SC_A,
//HID_KEYBOARD_SC_K,
//HID_KEYBOARD_SC_L },
.ledsOn = true,
.debounce = 30
};

View File

@@ -115,6 +115,22 @@ static uint8_t nunchuckReady = 0;
static uint8_t debugDelay = 100; // don't do anything for 100ms
#endif
uint32_t Boot_Key ATTR_NO_INIT;
#define MAGIC_BOOT_KEY 0xDEADBE7A
// offset * word size
#define BOOTLOADER_START_ADDRESS (0x1c00 * 2)
void Bootloader_Jump_Check(void) ATTR_INIT_SECTION(3);
void Bootloader_Jump_Check(void)
{
// If the reset source was the bootloader and the key is correct, clear it and jump to the bootloader
if ((MCUSR & (1 << WDRF)) && (Boot_Key == MAGIC_BOOT_KEY))
{
Boot_Key = 0;
((void (*)(void))BOOTLOADER_START_ADDRESS)();
}
}
//todo: neater
#define NUNCHUCK_ADDR (0x52 << 1)
void Nunchuck_back(void) {
@@ -421,6 +437,12 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI
uint8_t* ConfigReport = (uint8_t*)ReportData;
// So we can upgrade firmware without having to hit the button
if(ConfigReport[TATACON_CONFIG_BYTES-1] == MAGIC_RESET_NUMBER) {
// With this uncommented, reboot fails. Odd.
//USB_Disable();
cli();
// Back to the bootloader
Boot_Key = MAGIC_BOOT_KEY;
wdt_enable(WDTO_250MS);
while(1);
}

View File

@@ -49,7 +49,7 @@ debug: clean flash
v1debug: CC_FLAGS += -DV1_BUILD -DDEBUG
v1debug: clean all
init: erase wfuse flashboot
init: erase wfuse flashboot flash
erase:
$(AVRDUDE) -e

View File

@@ -42,7 +42,7 @@
var title = document.createElement("div");
title.className = "title";
title.textContent = "Tatacon to USB v" + device.config[configBytes.version];
title.textContent = "Tatacon to USB v" + device.config[configBytes.version]/10;
ui.appendChild(title);
var tatacon = document.createElement("div");