aboutsummaryrefslogtreecommitdiffstats
path: root/Bootloaders/DFU/BootloaderDFU.c
diff options
context:
space:
mode:
Diffstat (limited to 'Bootloaders/DFU/BootloaderDFU.c')
-rw-r--r--Bootloaders/DFU/BootloaderDFU.c46
1 files changed, 39 insertions, 7 deletions
diff --git a/Bootloaders/DFU/BootloaderDFU.c b/Bootloaders/DFU/BootloaderDFU.c
index f20cdd72b..883afef03 100644
--- a/Bootloaders/DFU/BootloaderDFU.c
+++ b/Bootloaders/DFU/BootloaderDFU.c
@@ -136,8 +136,8 @@ void Application_Jump_Check(void)
if (!(BootloaderAPI_ReadFuse(GET_HIGH_FUSE_BITS) & ~FUSE_BOOTRST))
{
/* If the reset source was not an external reset or the key is correct, clear it and jump to the application */
- if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY))
- JumpToApplication = true;
+ //if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY))
+ // JumpToApplication = true;
/* Clear reset source */
MCUSR &= ~(1 << EXTRF);
@@ -146,8 +146,8 @@ void Application_Jump_Check(void)
{
/* If the reset source was the bootloader and the key is correct, clear it and jump to the application;
* this can happen in the HWBE fuse is set, and the HBE pin is low during the watchdog reset */
- if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY))
- JumpToApplication = true;
+ //if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY))
+ // JumpToApplication = true;
/* Clear reset source */
MCUSR &= ~(1 << WDRF);
@@ -182,14 +182,32 @@ int main(void)
SetupHardware();
/* Turn on first LED on the board to indicate that the bootloader has started */
- LEDs_SetAllLEDs(LEDS_LED1);
+ LEDs_SetAllLEDs(LEDS_LED1 | LEDS_LED2);
/* Enable global interrupts so that the USB stack can function */
GlobalInterruptEnable();
+
+ #if (BOARD == BOARD_QMK)
+ uint16_t keypress = 0;
+ #endif
+
/* Run the USB management task while the bootloader is supposed to be running */
- while (RunBootloader || WaitForExit)
+ while (RunBootloader || WaitForExit) {
USB_USBTask();
+ #if (BOARD == BOARD_QMK)
+ bool pressed = (PIN(QMK_ESC_INPUT) & NUM(QMK_ESC_INPUT));
+ if ((DFU_State == dfuIDLE) && (keypress > 5000) && pressed) {
+ break;
+ }
+ if (pressed) {
+ keypress++;
+ } else {
+ keypress = 0;
+ }
+
+ #endif
+ }
/* Wait a short time to end all USB transactions and then disconnect */
_delay_us(1000);
@@ -215,6 +233,15 @@ static void SetupHardware(void)
MCUCR = (1 << IVCE);
MCUCR = (1 << IVSEL);
+ #if (BOARD == BOARD_QMK)
+ // output setup
+ DDR(QMK_ESC_OUTPUT) |= NUM(QMK_ESC_OUTPUT);
+ PORT(QMK_ESC_OUTPUT) |= NUM(QMK_ESC_OUTPUT);
+
+ // row setup
+ DDR(QMK_ESC_INPUT) |= NUM(QMK_ESC_INPUT);
+ #endif
+
/* Initialize the USB and other board hardware drivers */
USB_Init();
LEDs_Init();
@@ -222,7 +249,8 @@ static void SetupHardware(void)
/* Bootloader active LED toggle timer initialization */
TIMSK1 = (1 << TOIE1);
TCCR1B = ((1 << CS11) | (1 << CS10));
-}
+
+}
/** Resets all configured hardware required for the bootloader back to their original states. */
static void ResetHardware(void)
@@ -238,6 +266,10 @@ static void ResetHardware(void)
/* Relocate the interrupt vector table back to the application section */
MCUCR = (1 << IVCE);
MCUCR = 0;
+
+ #if (BOARD == BOARD_QMK)
+ DDR(QMK_ESC_OUTPUT) = PORT(QMK_ESC_OUTPUT) = DDR(QMK_ESC_INPUT) = PORT(QMK_ESC_INPUT) = 0;
+ #endif
}
/** ISR to periodically toggle the LEDs on the board to indicate that the bootloader is active. */