Archived
1
0

Adding initial work for SimpleMap style macros

- Differentiating between simple and complex macros
- Worst case requires more flash
- Best case will use a lot less RAM
- Requires update to kll compiler
This commit is contained in:
Jacob Alexander 2015-02-09 22:18:01 -08:00
parent d63886954c
commit b4c1951b0d
4 changed files with 71 additions and 55 deletions

View File

@ -83,25 +83,25 @@ typedef enum MacroType {
//
// ResultMacro.type -> <Type of macro>
// ResultMacro.guide -> [<combo length>|<capability index>|<arg1>|<argn>|<capability index>|...|<combo length>|...|0]
// ResultMacro.triggerKey -> <scanCode of last key in TriggerMacro>
//
// ResultMacroRecord.pos -> <current combo position>
// ResultMacroRecord.state -> <last key state>
// ResultMacroRecord.stateType -> <last key state type>
// ResultMacro struct, one is created per ResultMacro, no duplicates
typedef struct ResultMacro {
const MacroType type;
const uint8_t *guide;
const uint8_t triggerKey;
} ResultMacro;
// ResultMacroRecord struct, one is created per ResultMacro, no duplicates, if a MacroType_Normal
typedef struct ResultMacroRecord {
var_uint_t pos;
uint8_t state;
uint8_t stateType;
uint8_t state;
uint8_t stateType;
} ResultMacroRecord;
// ResultMacro struct, one is created per ResultMacro, no duplicates
typedef const struct ResultMacro {
const MacroType type;
const uint8_t *guide;
ResultMacroRecord *record;
} ResultMacro;
// Guide, key element
#define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ (guidePtr)->index ].argCount
typedef struct ResultGuide {
@ -144,18 +144,20 @@ typedef enum TriggerMacroState {
TriggerMacro_Waiting, // Awaiting user input
} TriggerMacroState;
// TriggerMacro struct, one is created per TriggerMacro, no duplicates
typedef struct TriggerMacro {
const MacroType type;
const uint8_t *guide;
const var_uint_t result;
} TriggerMacro;
// TriggerMacroRecord struct, one is created per TriggerMacro, no duplicates, if a MacroType_Normal
typedef struct TriggerMacroRecord {
var_uint_t pos;
var_uint_t pos;
TriggerMacroState state;
} TriggerMacroRecord;
// TriggerMacro struct, one is created per TriggerMacro, no duplicates
typedef const struct TriggerMacro {
const MacroType type;
const uint8_t *guide;
const var_uint_t result;
TriggerMacroRecord *record;
} TriggerMacro;
// Guide, key element
#define TriggerGuideSize sizeof( TriggerGuide )
typedef struct TriggerGuide {
@ -170,8 +172,8 @@ typedef struct TriggerGuide {
// Capability
typedef struct Capability {
const void *func;
const uint8_t argCount;
const void *func;
const uint8_t argCount;
} Capability;
// Total Number of Capabilities
@ -180,15 +182,20 @@ typedef struct Capability {
// -- Result Macros
// Guide_RM / Define_RM Pair
// Guide_RM / Record_RM / Define_RM
// Guide_RM( index ) = result;
// * index - Result Macro index number
// * result - Result Macro guide (see ResultMacro)
// Record_RM( index );
// * index - Result Macro index number
// Define_RM( index );
// * index - Result Macro index number
// Must be used after Guide_RM
// Simple macros do not have a record
// Must be used after Guide_RM and Record_RM
#define Guide_RM( index ) const uint8_t rm##index##_guide[]
#define Define_RM( index ) { rm##index##_guide }
#define Record_RM( index ) ResultMacroRecord rm##index##_record
#define Define_RM_Normal( index ) { MacroType_Normal, rm##index##_guide, &rm##index##_record }
#define Define_RM_Simple( index ) { MacroType_Simple, rm##index##_guide, 0 }
// -- Result Macro List
@ -200,21 +207,19 @@ typedef struct Capability {
// -- Trigger Macros
// Guide_TM / Define_TM Trigger Setup
// Guide_TM / Record_TM / Define_TM Trigger Setup
// Guide_TM( index ) = trigger;
// * index - Trigger Macro index number
// * trigger - Trigger Macro guide (see TriggerMacro)
// Define_TM( index, result );
// <State-ful sequence of combinations TriggerMacro>
// Record_TM( index );
// * index - Trigger Macro index number
// * result - Result Macro index number which is triggered by this Trigger Macro
// Define_STM( index, result );
// <State-less single combination TriggerMacro>
// Define_TM( index, result );
// * index - Trigger Macro index number
// * result - Result Macro index number which is triggered by this Trigger Macro
#define Guide_TM( index ) const uint8_t tm##index##_guide[]
#define Define_TM( index, result ) { MacroType_Normal, tm##index##_guide, result }
#define Define_STM( index, result ) { MacroType_Simple, tm##index##_guide, result }
#define Record_TM( index ) TriggerMacroRecord tm##index##_record
#define Define_TM_Normal( index, result ) { MacroType_Normal, tm##index##_guide, result, &tm##index##_record }
#define Define_TM_Simple( index, result ) { MacroType_Simple, tm##index##_guide, result, 0 }
// -- Trigger Macro List
@ -259,9 +264,9 @@ typedef struct Capability {
typedef struct Layer {
const nat_ptr_t **triggerMap;
const char *name;
const uint8_t first;
const uint8_t last;
const char *name;
const uint8_t first;
const uint8_t last;
} Layer;
// Layer_IN( map, name, first );

View File

@ -1,24 +1,29 @@
###| CMake Kiibohd Controller Macro Module |###
#
# Written by Jacob Alexander in 2014 for the Kiibohd Controller
# Written by Jacob Alexander in 2014-2015 for the Kiibohd Controller
#
# Released into the Public Domain
#
###
###
# Warning, that this module is not meant to be built stand-alone
# Sub-module flag, cannot be included stand-alone
#
message( FATAL_ERROR
"The 'Common' module is not a stand-alone module, and requires further setup."
)
set ( SubModule 1 )
###
# Module C files
#
set ( Module_SRCS
)
###
# Module Specific Options
# Compiler Family Compatibility
#
set ( ModuleCompatibility
arm
avr
)

View File

@ -26,7 +26,7 @@
#include <scan_loop.h>
// Keymaps
#include "usb_hid.h"
#include <usb_hid.h>
#include <generatedKeymap.h> // Generated using kll at compile time, in build directory
// Local Includes
@ -485,13 +485,13 @@ inline void Macro_appendResultMacroToPendingList( const TriggerMacro *triggerMac
{
if ( macroTriggerListBuffer[ keyIndex ].scanCode == scanCode )
{
ResultMacroRecordList[ resultMacroIndex ].state = macroTriggerListBuffer[ keyIndex ].state;
ResultMacroRecordList[ resultMacroIndex ].stateType = macroTriggerListBuffer[ keyIndex ].type;
ResultMacroList[ resultMacroIndex ].record->state = macroTriggerListBuffer[ keyIndex ].state;
ResultMacroList[ resultMacroIndex ].record->stateType = macroTriggerListBuffer[ keyIndex ].type;
}
}
// Reset the macro position
ResultMacroRecordList[ resultMacroIndex ].pos = 0;
ResultMacroList[ resultMacroIndex ].record->pos = 0;
}
@ -644,7 +644,7 @@ TriggerMacroEval Macro_evalTriggerMacro( var_uint_t triggerMacroIndex )
{
// Lookup TriggerMacro
const TriggerMacro *macro = &TriggerMacroList[ triggerMacroIndex ];
TriggerMacroRecord *record = &TriggerMacroRecordList[ triggerMacroIndex ];
TriggerMacroRecord *record = TriggerMacroList[ triggerMacroIndex ].record;
// Check if macro has finished and should be incremented sequence elements
if ( record->state == TriggerMacro_Release )
@ -797,7 +797,7 @@ inline ResultMacroEval Macro_evalResultMacro( var_uint_t resultMacroIndex )
{
// Lookup ResultMacro
const ResultMacro *macro = &ResultMacroList[ resultMacroIndex ];
ResultMacroRecord *record = &ResultMacroRecordList[ resultMacroIndex ];
ResultMacroRecord *record = ResultMacroList[ resultMacroIndex ].record;
// Current Macro position
var_uint_t pos = record->pos;
@ -889,8 +889,8 @@ inline void Macro_updateTriggerMacroPendingList()
macroTriggerMacroPendingList[ macroTriggerMacroPendingListSize++ ] = triggerMacroIndex;
// Reset macro position
TriggerMacroRecordList[ triggerMacroIndex ].pos = 0;
TriggerMacroRecordList[ triggerMacroIndex ].state = TriggerMacro_Waiting;
TriggerMacroList[ triggerMacroIndex ].record->pos = 0;
TriggerMacroList[ triggerMacroIndex ].record->state = TriggerMacro_Waiting;
}
}
}
@ -1011,16 +1011,16 @@ inline void Macro_setup()
// Initialize TriggerMacro states
for ( var_uint_t macro = 0; macro < TriggerMacroNum; macro++ )
{
TriggerMacroRecordList[ macro ].pos = 0;
TriggerMacroRecordList[ macro ].state = TriggerMacro_Waiting;
TriggerMacroList[ macro ].record->pos = 0;
TriggerMacroList[ macro ].record->state = TriggerMacro_Waiting;
}
// Initialize ResultMacro states
for ( var_uint_t macro = 0; macro < ResultMacroNum; macro++ )
{
ResultMacroRecordList[ macro ].pos = 0;
ResultMacroRecordList[ macro ].state = 0;
ResultMacroRecordList[ macro ].stateType = 0;
ResultMacroList[ macro ].record->pos = 0;
ResultMacroList[ macro ].record->state = 0;
ResultMacroList[ macro ].record->stateType = 0;
}
}
@ -1358,7 +1358,7 @@ void macroDebugShowTrigger( var_uint_t index )
// Trigger Macro Show
const TriggerMacro *macro = &TriggerMacroList[ index ];
TriggerMacroRecord *record = &TriggerMacroRecordList[ index ];
TriggerMacroRecord *record = TriggerMacroList[ index ].record;
print( NL );
info_msg("Trigger Macro Index: ");
@ -1430,7 +1430,7 @@ void macroDebugShowResult( var_uint_t index )
// Trigger Macro Show
const ResultMacro *macro = &ResultMacroList[ index ];
ResultMacroRecord *record = &ResultMacroRecordList[ index ];
ResultMacroRecord *record = ResultMacroList[ index ].record;
print( NL );
info_msg("Result Macro Index: ");

View File

@ -7,6 +7,12 @@
###
###
# Required Sub-modules
#
AddModule ( Macro Common )
###
# Module C files
#