From 385d4030035dbaf41591309dbde47653bd03841b Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Wed, 5 Jul 2017 10:27:50 -0400 Subject: adds QMK board with definable LEDs and matrix scan --- Bootloaders/DFU/BootloaderDFU.c | 46 ++++++++++++++++++++++++++++++++++------- Bootloaders/DFU/Descriptors.c | 4 ++-- Bootloaders/DFU/makefile | 10 ++++----- 3 files changed, 46 insertions(+), 14 deletions(-) (limited to 'Bootloaders') diff --git a/Bootloaders/DFU/BootloaderDFU.c b/Bootloaders/DFU/BootloaderDFU.c index 8da725d24..928cf6fe3 100644 --- a/Bootloaders/DFU/BootloaderDFU.c +++ b/Bootloaders/DFU/BootloaderDFU.c @@ -136,8 +136,8 @@ void Application_Jump_Check(void) if (boot_lock_fuse_bits_get(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_ROW) & NUM(QMK_ESC_ROW)); + if ((DFU_State == dfuIDLE) && (keypress > 5000) && pressed) { + break; + } + if (pressed) { + keypress++; + } else { + keypress = 0; + } + + #endif + } /* Reset configured hardware back to their original states for the user application */ ResetHardware(); @@ -212,6 +230,15 @@ static void SetupHardware(void) MCUCR = (1 << IVCE); MCUCR = (1 << IVSEL); + #if (BOARD == BOARD_QMK) + // column setup + DDR(QMK_ESC_COL) |= NUM(QMK_ESC_COL); + PORT(QMK_ESC_COL) |= NUM(QMK_ESC_COL); + + // row setup + DDR(QMK_ESC_ROW) |= NUM(QMK_ESC_ROW); + #endif + /* Initialize the USB and other board hardware drivers */ USB_Init(); LEDs_Init(); @@ -219,7 +246,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) @@ -235,6 +263,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_COL) = PORT(QMK_ESC_COL) = DDR(QMK_ESC_ROW) = PORT(QMK_ESC_ROW) = 0; + #endif } /** ISR to periodically toggle the LEDs on the board to indicate that the bootloader is active. */ diff --git a/Bootloaders/DFU/Descriptors.c b/Bootloaders/DFU/Descriptors.c index f7fe1cbb4..6b7b6d490 100644 --- a/Bootloaders/DFU/Descriptors.c +++ b/Bootloaders/DFU/Descriptors.c @@ -125,13 +125,13 @@ const USB_Descriptor_String_t LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGU * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device * Descriptor. */ -const USB_Descriptor_String_t ManufacturerString = USB_STRING_DESCRIPTOR(L"Dean Camera"); +const USB_Descriptor_String_t ManufacturerString = USB_STRING_DESCRIPTOR(L"QMK"); /** Product descriptor string. This is a Unicode string containing the product's details in human readable form, * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device * Descriptor. */ -const USB_Descriptor_String_t ProductString = USB_STRING_DESCRIPTOR(L"LUFA DFU"); +const USB_Descriptor_String_t ProductString = USB_STRING_DESCRIPTOR(L"KB"); /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" * documentation) by the application code so that the address and size of a requested descriptor can be given diff --git a/Bootloaders/DFU/makefile b/Bootloaders/DFU/makefile index 6e15cedfc..0d2014015 100644 --- a/Bootloaders/DFU/makefile +++ b/Bootloaders/DFU/makefile @@ -11,10 +11,10 @@ # Run "make help" for target help. -MCU = at90usb1287 +MCU = atmega32u4 ARCH = AVR8 -BOARD = USBKEY -F_CPU = 8000000 +BOARD = QMK +F_CPU = 16000000 F_USB = $(F_CPU) OPTIMIZATION = s TARGET = BootloaderDFU @@ -26,8 +26,8 @@ LD_FLAGS = -Wl,--section-start=.text=$(BOOT_START_OFFSET) $(BOOT_API_LD_FLAG # Flash size and bootloader section sizes of the target, in KB. These must # match the target's total FLASH size and the bootloader size set in the # device's fuses. -FLASH_SIZE_KB = 128 -BOOT_SECTION_SIZE_KB = 8 +FLASH_SIZE_KB = 32 +BOOT_SECTION_SIZE_KB = 4 # Bootloader address calculation formulas # Do not modify these macros, but rather modify the dependent values above. -- cgit v1.2.3