From 0516e82a71a5fad9158be139bf3d8fe8c71f71c2 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Sun, 16 Oct 2011 00:45:10 -0700 Subject: [PATCH] Adding soft entry bootloader via key sequence. - Fixed up basic Macro module (still not to my liking) - Added the bootloader entry bits - Added logic for key sequence tracking --- Keymap/keymap.h | 11 +++++- Macro/basic/macro.c | 94 ++++++++++++++++++++++++++++++++++++++++++++- USB/pjrc/usb_com.c | 3 +- 3 files changed, 103 insertions(+), 5 deletions(-) diff --git a/Keymap/keymap.h b/Keymap/keymap.h index 61bb3ac..16837fe 100644 --- a/Keymap/keymap.h +++ b/Keymap/keymap.h @@ -34,9 +34,13 @@ // ----- Variables ----- +// Lots of these variables are not used, so ignore gcc unused warnings +// But just for the variables in this file (and those included into it) +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic push + static uint8_t tandy1000_modifierMask[] = { 0x1D, 0x2A, 0x36, 0x38, 0x46 }; -/* static uint8_t tandy1000_map[] = { 0, KEY_ESC, KEY_1, @@ -129,7 +133,6 @@ static uint8_t tandy1000_map[] = { 0, KEY_F11, KEY_F12, // 0x5A }; -*/ static uint8_t tandy1000_colemak[] = { 0, KEY_ESC, @@ -449,5 +452,9 @@ static uint8_t colemakMap[] = { 0, KEY_RIGHT_ALT, KEY_SPACE }; */ + +// Only ignore unused warnings for the above variables +#pragma GCC diagnostic pop + #endif diff --git a/Macro/basic/macro.c b/Macro/basic/macro.c index c704708..bf04851 100644 --- a/Macro/basic/macro.c +++ b/Macro/basic/macro.c @@ -22,6 +22,8 @@ // ----- Includes ----- // AVR Includes +#include +#include // Project Includes #include @@ -38,30 +40,93 @@ +// ----- Variables ----- + +// Keeps track of the sequence used to reflash the teensy in software +static uint8_t Bootloader_ConditionSequence[] = {1,16,6,11}; + uint8_t Bootloader_ConditionState = 0; + uint8_t Bootloader_NextPositionReady = 1; + + + // ----- Functions ----- +void jumpToBootloader(void) +{ + cli(); + // disable watchdog, if enabled + // disable all peripherals + UDCON = 1; + USBCON = (1< total as per typical PCB labels) for ( uint8_t key = 0; key < numberOfKeys + 1; key++ ) { if ( keys[key] & (1 << 7) ) { + processed_keys++; + // Display the detected scancode char tmpStr[4]; int8ToStr( key, tmpStr ); dPrintStrs( tmpStr, " " ); + // Is this a bootloader sequence key? + if ( !Bootloader_KeyDetected + && Bootloader_NextPositionReady + && key == Bootloader_ConditionSequence[Bootloader_ConditionState] ) + { + Bootloader_KeyDetected = 1; + Bootloader_NextPositionReady = 0; + Bootloader_ConditionState++; + } + else if ( Bootloader_ConditionState > 0 && key == Bootloader_ConditionSequence[Bootloader_ConditionState - 1] ) + { + Bootloader_KeyDetected = 1; + } + // Determine if the key is a modifier uint8_t modFound = 0; for ( uint8_t mod = 0; mod < numberOfModifiers; mod++ ) { // Modifier found if ( modifiers[mod] == key ) { - //USBKeys_Modifiers |= map[key]; + USBKeys_Modifiers |= map[key]; modFound = 1; break; } @@ -85,6 +150,23 @@ inline void keyPressDetection( uint8_t *keys, uint8_t numberOfKeys, uint8_t *mod } } + // Boot loader sequence state handler + switch ( processed_keys ) + { + // The next bootloader key can now be pressed, if there were no keys processed + case 0: + Bootloader_NextPositionReady = 1; + break; + // If keys were detected, and it wasn't in the sequence (or there was multiple keys detected), start bootloader sequence over + // This case purposely falls through + case 1: + if ( Bootloader_KeyDetected ) + break; + default: + Bootloader_ConditionState = 0; + break; + } + // Add debug separator if keys sent via USB if ( USBKeys_Sent > 0 ) print("\033[1;32m|\033[0m\n"); @@ -92,7 +174,15 @@ inline void keyPressDetection( uint8_t *keys, uint8_t numberOfKeys, uint8_t *mod inline void process_macros(void) { + // Online process macros once (if some were found), until the next USB send + if ( USBKeys_Sent != 0 ) + return; + // Debounce Sampling Array to USB Data Array keyPressDetection( KeyIndex_Array, KeyIndex_Size, MODIFIER_MASK, sizeof(MODIFIER_MASK), KEYINDEX_MASK ); + + // Check for bootloader condition + if ( Bootloader_ConditionState == sizeof( Bootloader_ConditionSequence ) ) + jumpToBootloader(); } diff --git a/USB/pjrc/usb_com.c b/USB/pjrc/usb_com.c index 66192ad..af2d9c7 100644 --- a/USB/pjrc/usb_com.c +++ b/USB/pjrc/usb_com.c @@ -79,7 +79,8 @@ inline void usb_send(void) // Send keypresses usb_keyboard_send(); - // Clear modifiers + // Clear modifiers and keys USBKeys_Modifiers = 0; + USBKeys_Sent = 0; }