From 1fd777815b465951ba558f290f9be8d7b241b95c Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Sun, 22 Jun 2014 20:45:56 -0700 Subject: [PATCH] Initial work for partial layers and macros. --- Macro/PartialMap/generatedKeymap.h | 455 +++++++++++++++++++++++++++++ Macro/PartialMap/macro.c | 172 ++++++++--- Macro/PartialMap/macro.h | 3 + Scan/DPH/scan_loop.c | 15 +- 4 files changed, 604 insertions(+), 41 deletions(-) create mode 100644 Macro/PartialMap/generatedKeymap.h diff --git a/Macro/PartialMap/generatedKeymap.h b/Macro/PartialMap/generatedKeymap.h new file mode 100644 index 0000000..8fa71e8 --- /dev/null +++ b/Macro/PartialMap/generatedKeymap.h @@ -0,0 +1,455 @@ +/* Copyright (C) 2014 by Jacob Alexander + * + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this file. If not, see . + */ + +// Generated MSG /w timestamp and compiler information + +#ifndef __generatedKeymap_h +#define __generatedKeymap_h + +// ----- Includes ----- + +#include + +// USB HID Keymap list +#include + + + +// ----- Structs ----- + +// -- Result Macro +// Defines the sequence of combinations to as the Result of Trigger Macro +// +// Capability + args per USB send +// Default Args (always sent): key state/analog of last key +// Combo Length of 0 signifies end of sequence +// +// ResultMacro.guide -> [||||||...||...|0] +// ResultMacro.pos -> +// ResultMacro.state -> +// ResultMacro.stateType -> + +typedef struct ResultMacro { + unsigned int *guide; + unsigned int pos; + uint8_t state; + uint8_t stateType; +} ResultMacro; + + +// -- Trigger Macro +// Defines the sequence of combinations to Trigger a Result Macro +// Key Types: +// * 0x00 Normal (Press/Hold/Release) +// * 0x01 LED State (On/Off) +// * 0x02 Analog (Threshold) +// * 0x03-0xFF Reserved +// +// Flag State: +// * Not processed - 0x00 (all flag states) +// * On/Off - 0x01/0x02 +// * Press/Hold/Release - 0x01/0x02/0x03 +// * Threshold (Range) - 0x01 (Released), 0x10 (Light press), 0xFF (Max press) +// +// Combo Length of 0 signifies end of sequence +// +// TriggerMacro.guide -> [||...||...|0] +// TriggerMacro.state -> [......] +// TriggerMacro.result -> +// TriggerMacro.pos -> + +typedef struct TriggerMacro { + uint8_t *guide; + uint8_t *state; + ResultMacro *result; + unsigned int pos; +} TriggerMacro; + + + +// ----- Macros ----- + +#define debugPrint_cap( arg ) (unsigned int) debugPrint_capability, 1, arg +void debugPrint_capability( uint8_t state, uint8_t stateType, uint8_t arg ) +{ + dbug_msg("Capability Print: "); + print(" statetype( "); + printHex( stateType ); + print(" ) state ( "); + printHex( state ); + print(" ) arg ( "); + printHex( arg ); + print( " )" NL ); +} + + +// -- Result Macros + +// Guide_RM / Define_RM Pair +// Guide_RM( name ) = result; +// * name - Result Macro name +// * result - Result Macro guide (see ResultMacro) +// Define_RM( name ); +// * name - Result Macro name +// Must be used after Guide_RM +#define Guide_RM( name ) \ + static unsigned int name##_guide[] +#define Define_RM( name ) \ + ResultMacro name = { name##_guide, 0, 0, 0 } + +Guide_RM( rm1 ) = { 1, debugPrint_cap( 0xBA ), 0 }; +Define_RM( rm1 ); + + +// -- Trigger Macros + +// NOTES: +// Compiler must calculate number of combos per macro to define the size of the state array +// ( sizeof( macro_guide ) - ( + 1 ) ) / 2 = +#define GuideSize( name, combos ) ( sizeof( name##_guide ) - ( combos + 1 ) ) / 2 + +// Guide_TM / Define_TM Pair +// Guide_TM( name ) = trigger; +// * name - Trigger Macro name +// * trigger - Trigger Macro guide (see TriggerMacro) +// Define_TM( name, result ); +// * name - Trigger Macro name +// * result - Result Macro which is triggered by this Trigger Macro +#define Guide_TM( name ) static uint8_t name##_guide[] +#define Define_TM( name, result ) \ + uint8_t name##_state[ GuideSize( name, 1 ) ] = { 0 }; \ + TriggerMacro name = { name##_guide, name##_state, &result, 0 } +#define tm( number ) (unsigned int)&tm##number + +Guide_TM( tm1 ) = { 1, 0x00, 0x73, 0 }; +Define_TM( tm1, rm1 ); + + + +// ----- Trigger Maps ----- + +// Define_TL( layer, scanCode ) = triggerList; +// * layer - basename of the layer +// * scanCode - Hex value of the scanCode +// * triggerList - Trigger List (see Trigger Lists) +#define Define_TL( layer, scanCode ) static unsigned int layer##_tl_##scanCode[] + +// -- Trigger Lists +// +// Index 0: # of triggers in list +// Index n: pointer to trigger macro - use tm() macro + +// Default Layer +Define_TL( default, 0x00 ) = { 0 }; +Define_TL( default, 0x01 ) = { 0 }; +Define_TL( default, 0x02 ) = { 0 }; +Define_TL( default, 0x03 ) = { 0 }; +Define_TL( default, 0x04 ) = { 0 }; +Define_TL( default, 0x05 ) = { 0 }; +Define_TL( default, 0x06 ) = { 0 }; +Define_TL( default, 0x07 ) = { 0 }; +Define_TL( default, 0x08 ) = { 0 }; +Define_TL( default, 0x09 ) = { 0 }; +Define_TL( default, 0x0A ) = { 0 }; +Define_TL( default, 0x0B ) = { 0 }; +Define_TL( default, 0x0C ) = { 0 }; +Define_TL( default, 0x0D ) = { 0 }; +Define_TL( default, 0x0E ) = { 0 }; +Define_TL( default, 0x0F ) = { 0 }; +Define_TL( default, 0x10 ) = { 0 }; +Define_TL( default, 0x11 ) = { 0 }; +Define_TL( default, 0x12 ) = { 0 }; +Define_TL( default, 0x13 ) = { 0 }; +Define_TL( default, 0x14 ) = { 0 }; +Define_TL( default, 0x15 ) = { 0 }; +Define_TL( default, 0x16 ) = { 0 }; +Define_TL( default, 0x17 ) = { 0 }; +Define_TL( default, 0x18 ) = { 0 }; +Define_TL( default, 0x19 ) = { 0 }; +Define_TL( default, 0x1A ) = { 0 }; +Define_TL( default, 0x1B ) = { 0 }; +Define_TL( default, 0x1C ) = { 0 }; +Define_TL( default, 0x1D ) = { 0 }; +Define_TL( default, 0x1E ) = { 0 }; +Define_TL( default, 0x1F ) = { 0 }; +Define_TL( default, 0x20 ) = { 0 }; +Define_TL( default, 0x21 ) = { 0 }; +Define_TL( default, 0x22 ) = { 0 }; +Define_TL( default, 0x23 ) = { 0 }; +Define_TL( default, 0x24 ) = { 0 }; +Define_TL( default, 0x25 ) = { 0 }; +Define_TL( default, 0x26 ) = { 0 }; +Define_TL( default, 0x27 ) = { 0 }; +Define_TL( default, 0x28 ) = { 0 }; +Define_TL( default, 0x29 ) = { 0 }; +Define_TL( default, 0x2A ) = { 0 }; +Define_TL( default, 0x2B ) = { 0 }; +Define_TL( default, 0x2C ) = { 0 }; +Define_TL( default, 0x2D ) = { 0 }; +Define_TL( default, 0x2E ) = { 0 }; +Define_TL( default, 0x2F ) = { 0 }; +Define_TL( default, 0x30 ) = { 0 }; +Define_TL( default, 0x31 ) = { 0 }; +Define_TL( default, 0x32 ) = { 0 }; +Define_TL( default, 0x33 ) = { 0 }; +Define_TL( default, 0x34 ) = { 0 }; +Define_TL( default, 0x35 ) = { 0 }; +Define_TL( default, 0x36 ) = { 0 }; +Define_TL( default, 0x37 ) = { 0 }; +Define_TL( default, 0x38 ) = { 0 }; +Define_TL( default, 0x39 ) = { 0 }; +Define_TL( default, 0x3A ) = { 0 }; +Define_TL( default, 0x3B ) = { 0 }; +Define_TL( default, 0x3C ) = { 0 }; +Define_TL( default, 0x3D ) = { 0 }; +Define_TL( default, 0x3E ) = { 0 }; +Define_TL( default, 0x3F ) = { 0 }; +Define_TL( default, 0x40 ) = { 0 }; +Define_TL( default, 0x41 ) = { 0 }; +Define_TL( default, 0x42 ) = { 0 }; +Define_TL( default, 0x43 ) = { 0 }; +Define_TL( default, 0x44 ) = { 0 }; +Define_TL( default, 0x45 ) = { 0 }; +Define_TL( default, 0x46 ) = { 0 }; +Define_TL( default, 0x47 ) = { 0 }; +Define_TL( default, 0x48 ) = { 0 }; +Define_TL( default, 0x49 ) = { 0 }; +Define_TL( default, 0x4A ) = { 0 }; +Define_TL( default, 0x4B ) = { 0 }; +Define_TL( default, 0x4C ) = { 0 }; +Define_TL( default, 0x4D ) = { 0 }; +Define_TL( default, 0x4E ) = { 0 }; +Define_TL( default, 0x4F ) = { 0 }; +Define_TL( default, 0x50 ) = { 0 }; +Define_TL( default, 0x51 ) = { 0 }; +Define_TL( default, 0x52 ) = { 0 }; +Define_TL( default, 0x53 ) = { 0 }; +Define_TL( default, 0x54 ) = { 0 }; +Define_TL( default, 0x55 ) = { 0 }; +Define_TL( default, 0x56 ) = { 0 }; +Define_TL( default, 0x57 ) = { 0 }; +Define_TL( default, 0x58 ) = { 0 }; +Define_TL( default, 0x59 ) = { 0 }; +Define_TL( default, 0x5A ) = { 0 }; +Define_TL( default, 0x5B ) = { 0 }; +Define_TL( default, 0x5C ) = { 0 }; +Define_TL( default, 0x5D ) = { 0 }; +Define_TL( default, 0x5E ) = { 0 }; +Define_TL( default, 0x5F ) = { 0 }; +Define_TL( default, 0x60 ) = { 0 }; +Define_TL( default, 0x61 ) = { 0 }; +Define_TL( default, 0x62 ) = { 0 }; +Define_TL( default, 0x63 ) = { 0 }; +Define_TL( default, 0x64 ) = { 0 }; +Define_TL( default, 0x65 ) = { 0 }; +Define_TL( default, 0x66 ) = { 0 }; +Define_TL( default, 0x67 ) = { 0 }; +Define_TL( default, 0x68 ) = { 0 }; +Define_TL( default, 0x69 ) = { 0 }; +Define_TL( default, 0x6A ) = { 0 }; +Define_TL( default, 0x6B ) = { 0 }; +Define_TL( default, 0x6C ) = { 0 }; +Define_TL( default, 0x6D ) = { 0 }; +Define_TL( default, 0x6E ) = { 0 }; +Define_TL( default, 0x6F ) = { 0 }; +Define_TL( default, 0x70 ) = { 0 }; +Define_TL( default, 0x71 ) = { 0 }; +Define_TL( default, 0x72 ) = { 0 }; +Define_TL( default, 0x73 ) = { 1, tm(1) }; +Define_TL( default, 0x74 ) = { 0 }; +Define_TL( default, 0x75 ) = { 0 }; +Define_TL( default, 0x76 ) = { 0 }; +Define_TL( default, 0x77 ) = { 0 }; +Define_TL( default, 0x78 ) = { 0 }; +Define_TL( default, 0x79 ) = { 0 }; +Define_TL( default, 0x7A ) = { 0 }; +Define_TL( default, 0x7B ) = { 0 }; +Define_TL( default, 0x7C ) = { 0 }; +Define_TL( default, 0x7D ) = { 0 }; +Define_TL( default, 0x7E ) = { 0 }; +Define_TL( default, 0x7F ) = { 0 }; +Define_TL( default, 0x80 ) = { 0 }; +Define_TL( default, 0x81 ) = { 0 }; +Define_TL( default, 0x82 ) = { 0 }; +Define_TL( default, 0x83 ) = { 0 }; +Define_TL( default, 0x84 ) = { 0 }; +Define_TL( default, 0x85 ) = { 0 }; +Define_TL( default, 0x86 ) = { 0 }; +Define_TL( default, 0x87 ) = { 0 }; +Define_TL( default, 0x88 ) = { 0 }; +Define_TL( default, 0x89 ) = { 0 }; +Define_TL( default, 0x8A ) = { 0 }; +Define_TL( default, 0x8B ) = { 0 }; +Define_TL( default, 0x8C ) = { 0 }; +Define_TL( default, 0x8D ) = { 0 }; +Define_TL( default, 0x8E ) = { 0 }; +Define_TL( default, 0x8F ) = { 0 }; +Define_TL( default, 0x90 ) = { 0 }; +Define_TL( default, 0x91 ) = { 0 }; +Define_TL( default, 0x92 ) = { 0 }; +Define_TL( default, 0x93 ) = { 0 }; +Define_TL( default, 0x94 ) = { 0 }; +Define_TL( default, 0x95 ) = { 0 }; +Define_TL( default, 0x96 ) = { 0 }; +Define_TL( default, 0x97 ) = { 0 }; +Define_TL( default, 0x98 ) = { 0 }; +Define_TL( default, 0x99 ) = { 0 }; +Define_TL( default, 0x9A ) = { 0 }; +Define_TL( default, 0x9B ) = { 0 }; +Define_TL( default, 0x9C ) = { 0 }; +Define_TL( default, 0x9D ) = { 0 }; +Define_TL( default, 0x9E ) = { 0 }; +Define_TL( default, 0x9F ) = { 0 }; +Define_TL( default, 0xA0 ) = { 0 }; +Define_TL( default, 0xA1 ) = { 0 }; +Define_TL( default, 0xA2 ) = { 0 }; +Define_TL( default, 0xA3 ) = { 0 }; +Define_TL( default, 0xA4 ) = { 0 }; +Define_TL( default, 0xA5 ) = { 0 }; +Define_TL( default, 0xA6 ) = { 0 }; +Define_TL( default, 0xA7 ) = { 0 }; +Define_TL( default, 0xA8 ) = { 0 }; +Define_TL( default, 0xA9 ) = { 0 }; +Define_TL( default, 0xAA ) = { 0 }; +Define_TL( default, 0xAB ) = { 0 }; +Define_TL( default, 0xAC ) = { 0 }; +Define_TL( default, 0xAD ) = { 0 }; +Define_TL( default, 0xAE ) = { 0 }; +Define_TL( default, 0xAF ) = { 0 }; +Define_TL( default, 0xB0 ) = { 0 }; +Define_TL( default, 0xB1 ) = { 0 }; +Define_TL( default, 0xB2 ) = { 0 }; +Define_TL( default, 0xB3 ) = { 0 }; +Define_TL( default, 0xB4 ) = { 0 }; +Define_TL( default, 0xB5 ) = { 0 }; +Define_TL( default, 0xB6 ) = { 0 }; +Define_TL( default, 0xB7 ) = { 0 }; +Define_TL( default, 0xB8 ) = { 0 }; +Define_TL( default, 0xB9 ) = { 0 }; +Define_TL( default, 0xBA ) = { 0 }; +Define_TL( default, 0xBB ) = { 0 }; +Define_TL( default, 0xBC ) = { 0 }; +Define_TL( default, 0xBD ) = { 0 }; +Define_TL( default, 0xBE ) = { 0 }; +Define_TL( default, 0xBF ) = { 0 }; +Define_TL( default, 0xC0 ) = { 0 }; +Define_TL( default, 0xC1 ) = { 0 }; +Define_TL( default, 0xC2 ) = { 0 }; +Define_TL( default, 0xC3 ) = { 0 }; +Define_TL( default, 0xC4 ) = { 0 }; +Define_TL( default, 0xC5 ) = { 0 }; +Define_TL( default, 0xC6 ) = { 0 }; +Define_TL( default, 0xC7 ) = { 0 }; +Define_TL( default, 0xC8 ) = { 0 }; +Define_TL( default, 0xC9 ) = { 0 }; +Define_TL( default, 0xCA ) = { 0 }; +Define_TL( default, 0xCB ) = { 0 }; +Define_TL( default, 0xCC ) = { 0 }; +Define_TL( default, 0xCD ) = { 0 }; +Define_TL( default, 0xCE ) = { 0 }; +Define_TL( default, 0xCF ) = { 0 }; +Define_TL( default, 0xD0 ) = { 0 }; +Define_TL( default, 0xD1 ) = { 0 }; +Define_TL( default, 0xD2 ) = { 0 }; +Define_TL( default, 0xD3 ) = { 0 }; +Define_TL( default, 0xD4 ) = { 0 }; +Define_TL( default, 0xD5 ) = { 0 }; +Define_TL( default, 0xD6 ) = { 0 }; +Define_TL( default, 0xD7 ) = { 0 }; +Define_TL( default, 0xD8 ) = { 0 }; +Define_TL( default, 0xD9 ) = { 0 }; +Define_TL( default, 0xDA ) = { 0 }; +Define_TL( default, 0xDB ) = { 0 }; +Define_TL( default, 0xDC ) = { 0 }; +Define_TL( default, 0xDD ) = { 0 }; +Define_TL( default, 0xDE ) = { 0 }; +Define_TL( default, 0xDF ) = { 0 }; +Define_TL( default, 0xE0 ) = { 0 }; +Define_TL( default, 0xE1 ) = { 0 }; +Define_TL( default, 0xE2 ) = { 0 }; +Define_TL( default, 0xE3 ) = { 0 }; +Define_TL( default, 0xE4 ) = { 0 }; +Define_TL( default, 0xE5 ) = { 0 }; +Define_TL( default, 0xE6 ) = { 0 }; +Define_TL( default, 0xE7 ) = { 0 }; +Define_TL( default, 0xE8 ) = { 0 }; +Define_TL( default, 0xE9 ) = { 0 }; +Define_TL( default, 0xEA ) = { 0 }; +Define_TL( default, 0xEB ) = { 0 }; +Define_TL( default, 0xEC ) = { 0 }; +Define_TL( default, 0xED ) = { 0 }; +Define_TL( default, 0xEE ) = { 0 }; +Define_TL( default, 0xEF ) = { 0 }; +Define_TL( default, 0xF0 ) = { 0 }; +Define_TL( default, 0xF1 ) = { 0 }; +Define_TL( default, 0xF2 ) = { 0 }; +Define_TL( default, 0xF3 ) = { 0 }; +Define_TL( default, 0xF4 ) = { 0 }; +Define_TL( default, 0xF5 ) = { 0 }; +Define_TL( default, 0xF6 ) = { 0 }; +Define_TL( default, 0xF7 ) = { 0 }; +Define_TL( default, 0xF8 ) = { 0 }; +Define_TL( default, 0xF9 ) = { 0 }; +Define_TL( default, 0xFA ) = { 0 }; +Define_TL( default, 0xFB ) = { 0 }; +Define_TL( default, 0xFC ) = { 0 }; +Define_TL( default, 0xFD ) = { 0 }; +Define_TL( default, 0xFE ) = { 0 }; +Define_TL( default, 0xFF ) = { 0 }; + + +// myname Layer +// TODO + + +// myname2 Layer +// TODO + + +// -- ScanCode Indexed Maps +// Maps to a trigger list of macro pointers +// _ +// -> |T| +// |r| -> +// |i| +// |g| -> +// |g| +// |e| -> +// |r| +// |s| -> +// - + +// Default Map for ScanCode Lookup +static unsigned int *default_scanMap[] = { +default_tl_0x00, default_tl_0x01, default_tl_0x02, default_tl_0x03, default_tl_0x04, default_tl_0x05, default_tl_0x06, default_tl_0x07, default_tl_0x08, default_tl_0x09, default_tl_0x0A, default_tl_0x0B, default_tl_0x0C, default_tl_0x0D, default_tl_0x0E, default_tl_0x0F, default_tl_0x10, default_tl_0x11, default_tl_0x12, default_tl_0x13, default_tl_0x14, default_tl_0x15, default_tl_0x16, default_tl_0x17, default_tl_0x18, default_tl_0x19, default_tl_0x1A, default_tl_0x1B, default_tl_0x1C, default_tl_0x1D, default_tl_0x1E, default_tl_0x1F, default_tl_0x20, default_tl_0x21, default_tl_0x22, default_tl_0x23, default_tl_0x24, default_tl_0x25, default_tl_0x26, default_tl_0x27, default_tl_0x28, default_tl_0x29, default_tl_0x2A, default_tl_0x2B, default_tl_0x2C, default_tl_0x2D, default_tl_0x2E, default_tl_0x2F, default_tl_0x30, default_tl_0x31, default_tl_0x32, default_tl_0x33, default_tl_0x34, default_tl_0x35, default_tl_0x36, default_tl_0x37, default_tl_0x38, default_tl_0x39, default_tl_0x3A, default_tl_0x3B, default_tl_0x3C, default_tl_0x3D, default_tl_0x3E, default_tl_0x3F, default_tl_0x40, default_tl_0x41, default_tl_0x42, default_tl_0x43, default_tl_0x44, default_tl_0x45, default_tl_0x46, default_tl_0x47, default_tl_0x48, default_tl_0x49, default_tl_0x4A, default_tl_0x4B, default_tl_0x4C, default_tl_0x4D, default_tl_0x4E, default_tl_0x4F, default_tl_0x50, default_tl_0x51, default_tl_0x52, default_tl_0x53, default_tl_0x54, default_tl_0x55, default_tl_0x56, default_tl_0x57, default_tl_0x58, default_tl_0x59, default_tl_0x5A, default_tl_0x5B, default_tl_0x5C, default_tl_0x5D, default_tl_0x5E, default_tl_0x5F, default_tl_0x60, default_tl_0x61, default_tl_0x62, default_tl_0x63, default_tl_0x64, default_tl_0x65, default_tl_0x66, default_tl_0x67, default_tl_0x68, default_tl_0x69, default_tl_0x6A, default_tl_0x6B, default_tl_0x6C, default_tl_0x6D, default_tl_0x6E, default_tl_0x6F, default_tl_0x70, default_tl_0x71, default_tl_0x72, default_tl_0x73, default_tl_0x74, default_tl_0x75, default_tl_0x76, default_tl_0x77, default_tl_0x78, default_tl_0x79, default_tl_0x7A, default_tl_0x7B, default_tl_0x7C, default_tl_0x7D, default_tl_0x7E, default_tl_0x7F, default_tl_0x80, default_tl_0x81, default_tl_0x82, default_tl_0x83, default_tl_0x84, default_tl_0x85, default_tl_0x86, default_tl_0x87, default_tl_0x88, default_tl_0x89, default_tl_0x8A, default_tl_0x8B, default_tl_0x8C, default_tl_0x8D, default_tl_0x8E, default_tl_0x8F, default_tl_0x90, default_tl_0x91, default_tl_0x92, default_tl_0x93, default_tl_0x94, default_tl_0x95, default_tl_0x96, default_tl_0x97, default_tl_0x98, default_tl_0x99, default_tl_0x9A, default_tl_0x9B, default_tl_0x9C, default_tl_0x9D, default_tl_0x9E, default_tl_0x9F, default_tl_0xA0, default_tl_0xA1, default_tl_0xA2, default_tl_0xA3, default_tl_0xA4, default_tl_0xA5, default_tl_0xA6, default_tl_0xA7, default_tl_0xA8, default_tl_0xA9, default_tl_0xAA, default_tl_0xAB, default_tl_0xAC, default_tl_0xAD, default_tl_0xAE, default_tl_0xAF, default_tl_0xB0, default_tl_0xB1, default_tl_0xB2, default_tl_0xB3, default_tl_0xB4, default_tl_0xB5, default_tl_0xB6, default_tl_0xB7, default_tl_0xB8, default_tl_0xB9, default_tl_0xBA, default_tl_0xBB, default_tl_0xBC, default_tl_0xBD, default_tl_0xBE, default_tl_0xBF, default_tl_0xC0, default_tl_0xC1, default_tl_0xC2, default_tl_0xC3, default_tl_0xC4, default_tl_0xC5, default_tl_0xC6, default_tl_0xC7, default_tl_0xC8, default_tl_0xC9, default_tl_0xCA, default_tl_0xCB, default_tl_0xCC, default_tl_0xCD, default_tl_0xCE, default_tl_0xCF, default_tl_0xD0, default_tl_0xD1, default_tl_0xD2, default_tl_0xD3, default_tl_0xD4, default_tl_0xD5, default_tl_0xD6, default_tl_0xD7, default_tl_0xD8, default_tl_0xD9, default_tl_0xDA, default_tl_0xDB, default_tl_0xDC, default_tl_0xDD, default_tl_0xDE, default_tl_0xDF, default_tl_0xE0, default_tl_0xE1, default_tl_0xE2, default_tl_0xE3, default_tl_0xE4, default_tl_0xE5, default_tl_0xE6, default_tl_0xE7, default_tl_0xE8, default_tl_0xE9, default_tl_0xEA, default_tl_0xEB, default_tl_0xEC, default_tl_0xED, default_tl_0xEE, default_tl_0xEF, default_tl_0xF0, default_tl_0xF1, default_tl_0xF2, default_tl_0xF3, default_tl_0xF4, default_tl_0xF5, default_tl_0xF6, default_tl_0xF7, default_tl_0xF8, default_tl_0xF9, default_tl_0xFA, default_tl_0xFB, default_tl_0xFC, default_tl_0xFD, default_tl_0xFE, default_tl_0xFF, +}; + +// Layer for ScanCode Lookup +static unsigned int myname_scanMap[] = { +}; + +// Layer for ScanCode Lookup +static unsigned int myname2_scanMap[] = { +}; + + + +// ----- Result Maps ----- + + + +#endif // __generatedKeymap_h + diff --git a/Macro/PartialMap/macro.c b/Macro/PartialMap/macro.c index 968835e..966bd04 100644 --- a/Macro/PartialMap/macro.c +++ b/Macro/PartialMap/macro.c @@ -1,22 +1,17 @@ /* Copyright (C) 2014 by Jacob Alexander * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. + * You should have received a copy of the GNU General Public License + * along with this file. If not, see . */ // ----- Includes ----- @@ -34,6 +29,7 @@ // Keymaps #include "usb_hid.h" #include +#include "generatedKeymap.h" // TODO Use actual generated version // Local Includes #include "macro.h" @@ -69,43 +65,114 @@ CLIDictItem macroCLIDict[] = { // Macro debug flag - If set, clears the USB Buffers after signalling processing completion uint8_t macroDebugMode = 0; +// Key Trigger List Buffer +// * Item 1: scan code +// * Item 2: state +// ... +uint8_t macroTriggerListBuffer[0xFF * 2] = { 0 }; // Each key has a state to be cached (this can be decreased to save RAM) +uint8_t macroTriggerListBufferSize = 0; + +// TODO, figure out a good way to scale this array size without wasting too much memory, but not rejecting macros +// Possibly could be calculated by the KLL compiler +TriggerMacro *triggerMacroPendingList[30]; + // ----- Functions ----- -// Looks up the start of the function ptr list for the active layer, by scan code -inline void *Macro_layerLookup( uint8_t scanCode ) +// Looks up the trigger list for the given scan code (from the active layer) +unsigned int *Macro_layerLookup( uint8_t scanCode ) +{ + // TODO - No layer fallthrough lookup + return default_scanMap[ scanCode ]; +} + + +// Update the scancode key state +// States: +// * 0x00 - Reserved +// * 0x01 - Pressed +// * 0x02 - Held +// * 0x03 - Released +// * 0x04 - Unpressed (this is currently ignored) +inline void Macro_keyState( uint8_t scanCode, uint8_t state ) +{ + // Only add to macro trigger list if one of three states + switch ( state ) + { + case 0x01: // Pressed + case 0x02: // Held + case 0x03: // Released + macroTriggerListBuffer[ macroTriggerListBufferSize++ ] = scanCode; + macroTriggerListBuffer[ macroTriggerListBufferSize++ ] = state; + break; + } +} + + +// Update the scancode analog state +// States: +// * 0x00 - Reserved +// * 0x01 - Released +// * 0x02-0xFF - Analog value (low to high) +inline void Macro_analogState( uint8_t scanCode, uint8_t state ) { // TODO - return 0; } -// Called for each key from the Scan Module for one of three cases: -// 1. Key is pressed (PRESSED) -// 2. Key is being held down (HELD) -// 3. Key is released (RELEASED) -// If Scan Module is for an analog sense keyboard, do not use the defined keystates -// This function should not be called if not pressed (depressed) or at 0% -inline void Macro_keyUpdate( uint8_t scanCode, uint8_t state ) +// Update led state +// States: +// * 0x00 - Reserved +// * 0x01 - On +// * 0x02 - Off +inline void Macro_ledState( uint8_t ledCode, uint8_t state ) { - // Do layer lookup to find which capabilities to map - void *capabilities = Macro_layerLookup( scanCode ); + // TODO } +// Evaluate/Update the TriggerMacro +void Macro_evalTriggerMacro( TriggerMacro *triggerMacro ) +{ + // Which combo in the sequence is being evaluated + unsigned int comboPos = triggerMacro->pos; + // If combo length is more than 1, cancel trigger macro if an incorrect key is found + uint8_t comboLength = triggerMacro->guide[ comboPos ]; + // Iterate over list of keys currently pressed + for ( uint8_t keyPressed = 0; keyPressed < macroTriggerListBufferSize; keyPressed += 2 ) + { + // Compare with keys in combo + for ( unsigned int comboKey = 0; comboKey < comboLength; comboKey++ ) + { + // Lookup key in combo + uint8_t guideKey = triggerMacro->guide[ comboPos + comboKey + 2 ]; // TODO Only Press/Hold/Release atm + // Sequence Case + if ( comboLength == 1 ) + { + // If key matches and only 1 key pressed, increment the TriggerMacro combo position + if ( guideKey == macroTriggerListBuffer[ keyPressed ] && macroTriggerListBufferSize == 1 ) + { + triggerMacro->pos += comboLength * 2 + 1; + // TODO check if TriggerMacro is finished, register ResultMacro + return; + } - - - - - - - - + // If key does not match or more than 1 key pressed, reset the TriggerMacro combo position + triggerMacro->pos = 0; + return; + } + // Combo Case + else + { + // TODO + } + } + } +} @@ -166,6 +233,37 @@ inline void Macro_process() if ( USBKeys_Sent != 0 ) return; + // Loop through macro trigger buffer + for ( uint8_t index = 0; index < macroTriggerListBufferSize; index += 2 ) + { + // Get scanCode, first item of macroTriggerListBuffer pairs + uint8_t scanCode = macroTriggerListBuffer[ index ]; + + // Lookup trigger list for this key + unsigned int *triggerList = Macro_layerLookup( scanCode ); + + // The first element is the length of the trigger list + unsigned int triggerListSize = triggerList[0]; + + // Loop through the trigger list + for ( unsigned int trigger = 0; trigger < triggerListSize; trigger++ ) + { + // Lookup TriggerMacro + TriggerMacro *triggerMacro = (TriggerMacro*)triggerList[ trigger + 1 ]; + + // Get triggered state of scan code, second item of macroTriggerListBuffer pairs + uint8_t state = macroTriggerListBuffer[ index + 1 ]; + + // Evaluate Macro + Macro_evalTriggerMacro( triggerMacro ); + } + } + + + + + + /* TODO // Loop through input buffer for ( uint8_t index = 0; index < KeyIndex_BufferUsed && !macroDebugMode; index++ ) { @@ -204,6 +302,7 @@ inline void Macro_process() errorLED( 1 ); } } + */ // Signal buffer that we've used it Scan_finishedWithBuffer( KeyIndex_BufferUsed ); @@ -223,6 +322,9 @@ inline void Macro_setup() // Disable Macro debug mode macroDebugMode = 0; + + // Make sure macro trigger buffer is empty + macroTriggerListBufferSize = 0; } diff --git a/Macro/PartialMap/macro.h b/Macro/PartialMap/macro.h index 377f9ec..6722c2c 100644 --- a/Macro/PartialMap/macro.h +++ b/Macro/PartialMap/macro.h @@ -48,6 +48,9 @@ // ----- Functions ----- +void Macro_keyState( uint8_t scanCode, uint8_t state ); +void Macro_analogState( uint8_t scanCode, uint8_t state ); +void Macro_ledState( uint8_t ledCode, uint8_t state ); void Macro_bufferAdd( uint8_t byte ); void Macro_bufferRemove( uint8_t byte ); void Macro_finishWithUSBBuffer( uint8_t sentKeys ); diff --git a/Scan/DPH/scan_loop.c b/Scan/DPH/scan_loop.c index c4d4284..69d5719 100644 --- a/Scan/DPH/scan_loop.c +++ b/Scan/DPH/scan_loop.c @@ -803,10 +803,13 @@ void testColumn( uint8_t strobe ) print(" "); } - // Only add the key to the buffer once - // NOTE: Buffer can easily handle multiple adds, just more efficient - // and nicer debug messages :P - Macro_bufferAdd( key ); + // Initial Keypress + Macro_keyState( key, 0x01 ); + } + else if ( keys_debounce[key] >= DEBOUNCE_THRESHOLD ) + { + // Held Key + Macro_keyState( key, 0x02 ); } keys_debounce[key]++; @@ -840,10 +843,10 @@ void testColumn( uint8_t strobe ) // Clear debounce entry if no keypress detected else { - // If the key was previously pressed, remove from the buffer + // Release Key if ( KeyIndex_BufferUsed > 0 && keys_debounce[key] >= DEBOUNCE_THRESHOLD ) { - Macro_bufferRemove( key ); + Macro_keyState( key, 0x03 ); } // Clear debounce entry