# HG changeset patch # User Jacob Alexander # Date 1318751110 25200 # Node ID 6ca5b1a395dfeed3d09b8b3f56e717f57bceb2d0 # Parent 8b8cad3db8db767a268f3192ed042c927afec023 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 diff -r 8b8cad3db8db -r 6ca5b1a395df Keymap/keymap.h --- a/Keymap/keymap.h Sat Oct 15 20:01:46 2011 -0700 +++ b/Keymap/keymap.h Sun Oct 16 00:45:10 2011 -0700 @@ -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 @@ KEY_F11, KEY_F12, // 0x5A }; -*/ static uint8_t tandy1000_colemak[] = { 0, KEY_ESC, @@ -449,5 +452,9 @@ KEY_RIGHT_ALT, KEY_SPACE }; */ + +// Only ignore unused warnings for the above variables +#pragma GCC diagnostic pop + #endif diff -r 8b8cad3db8db -r 6ca5b1a395df Macro/basic/macro.c --- a/Macro/basic/macro.c Sat Oct 15 20:01:46 2011 -0700 +++ b/Macro/basic/macro.c Sun Oct 16 00:45:10 2011 -0700 @@ -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 @@ } } + // 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 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 -r 8b8cad3db8db -r 6ca5b1a395df USB/pjrc/usb_com.c --- a/USB/pjrc/usb_com.c Sat Oct 15 20:01:46 2011 -0700 +++ b/USB/pjrc/usb_com.c Sun Oct 16 00:45:10 2011 -0700 @@ -79,7 +79,8 @@ // Send keypresses usb_keyboard_send(); - // Clear modifiers + // Clear modifiers and keys USBKeys_Modifiers = 0; + USBKeys_Sent = 0; }