From 523dd87df36fc24e51339b5e72addafdd26fded5 Mon Sep 17 00:00:00 2001 From: William Toohey Date: Sun, 20 Mar 2016 21:14:14 +1000 Subject: [PATCH] Fix bootloader jump --- Firmware/Keyboard/Config.c | 15 --------------- Firmware/Keyboard/Keyboard.c | 22 ++++++++++++++++++++++ Firmware/Keyboard/makefile | 2 +- Software/Tataconfig/tataconfig.js | 2 +- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Firmware/Keyboard/Config.c b/Firmware/Keyboard/Config.c index 1f0bfdc..3219474 100644 --- a/Firmware/Keyboard/Config.c +++ b/Firmware/Keyboard/Config.c @@ -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 }; diff --git a/Firmware/Keyboard/Keyboard.c b/Firmware/Keyboard/Keyboard.c index 7feb715..36c9b51 100644 --- a/Firmware/Keyboard/Keyboard.c +++ b/Firmware/Keyboard/Keyboard.c @@ -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); } diff --git a/Firmware/Keyboard/makefile b/Firmware/Keyboard/makefile index 0a7794f..5a32b30 100644 --- a/Firmware/Keyboard/makefile +++ b/Firmware/Keyboard/makefile @@ -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 diff --git a/Software/Tataconfig/tataconfig.js b/Software/Tataconfig/tataconfig.js index 0bf1784..91aa8c8 100644 --- a/Software/Tataconfig/tataconfig.js +++ b/Software/Tataconfig/tataconfig.js @@ -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");