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:
parent
d63886954c
commit
b4c1951b0d
@ -83,25 +83,25 @@ typedef enum MacroType {
|
|||||||
//
|
//
|
||||||
// ResultMacro.type -> <Type of macro>
|
// ResultMacro.type -> <Type of macro>
|
||||||
// ResultMacro.guide -> [<combo length>|<capability index>|<arg1>|<argn>|<capability index>|...|<combo length>|...|0]
|
// 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.pos -> <current combo position>
|
||||||
// ResultMacroRecord.state -> <last key state>
|
// ResultMacroRecord.state -> <last key state>
|
||||||
// ResultMacroRecord.stateType -> <last key state type>
|
// ResultMacroRecord.stateType -> <last key state type>
|
||||||
|
|
||||||
// ResultMacro struct, one is created per ResultMacro, no duplicates
|
// ResultMacroRecord struct, one is created per ResultMacro, no duplicates, if a MacroType_Normal
|
||||||
typedef struct ResultMacro {
|
|
||||||
const MacroType type;
|
|
||||||
const uint8_t *guide;
|
|
||||||
const uint8_t triggerKey;
|
|
||||||
} ResultMacro;
|
|
||||||
|
|
||||||
typedef struct ResultMacroRecord {
|
typedef struct ResultMacroRecord {
|
||||||
var_uint_t pos;
|
var_uint_t pos;
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
uint8_t stateType;
|
uint8_t stateType;
|
||||||
} ResultMacroRecord;
|
} 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
|
// Guide, key element
|
||||||
#define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ (guidePtr)->index ].argCount
|
#define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ (guidePtr)->index ].argCount
|
||||||
typedef struct ResultGuide {
|
typedef struct ResultGuide {
|
||||||
@ -144,18 +144,20 @@ typedef enum TriggerMacroState {
|
|||||||
TriggerMacro_Waiting, // Awaiting user input
|
TriggerMacro_Waiting, // Awaiting user input
|
||||||
} TriggerMacroState;
|
} TriggerMacroState;
|
||||||
|
|
||||||
// TriggerMacro struct, one is created per TriggerMacro, no duplicates
|
// TriggerMacroRecord struct, one is created per TriggerMacro, no duplicates, if a MacroType_Normal
|
||||||
typedef struct TriggerMacro {
|
|
||||||
const MacroType type;
|
|
||||||
const uint8_t *guide;
|
|
||||||
const var_uint_t result;
|
|
||||||
} TriggerMacro;
|
|
||||||
|
|
||||||
typedef struct TriggerMacroRecord {
|
typedef struct TriggerMacroRecord {
|
||||||
var_uint_t pos;
|
var_uint_t pos;
|
||||||
TriggerMacroState state;
|
TriggerMacroState state;
|
||||||
} TriggerMacroRecord;
|
} 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
|
// Guide, key element
|
||||||
#define TriggerGuideSize sizeof( TriggerGuide )
|
#define TriggerGuideSize sizeof( TriggerGuide )
|
||||||
typedef struct TriggerGuide {
|
typedef struct TriggerGuide {
|
||||||
@ -170,8 +172,8 @@ typedef struct TriggerGuide {
|
|||||||
|
|
||||||
// Capability
|
// Capability
|
||||||
typedef struct Capability {
|
typedef struct Capability {
|
||||||
const void *func;
|
const void *func;
|
||||||
const uint8_t argCount;
|
const uint8_t argCount;
|
||||||
} Capability;
|
} Capability;
|
||||||
|
|
||||||
// Total Number of Capabilities
|
// Total Number of Capabilities
|
||||||
@ -180,15 +182,20 @@ typedef struct Capability {
|
|||||||
|
|
||||||
// -- Result Macros
|
// -- Result Macros
|
||||||
|
|
||||||
// Guide_RM / Define_RM Pair
|
// Guide_RM / Record_RM / Define_RM
|
||||||
// Guide_RM( index ) = result;
|
// Guide_RM( index ) = result;
|
||||||
// * index - Result Macro index number
|
// * index - Result Macro index number
|
||||||
// * result - Result Macro guide (see ResultMacro)
|
// * result - Result Macro guide (see ResultMacro)
|
||||||
|
// Record_RM( index );
|
||||||
|
// * index - Result Macro index number
|
||||||
// Define_RM( index );
|
// Define_RM( index );
|
||||||
// * index - Result Macro index number
|
// * 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 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
|
// -- Result Macro List
|
||||||
@ -200,21 +207,19 @@ typedef struct Capability {
|
|||||||
|
|
||||||
// -- Trigger Macros
|
// -- Trigger Macros
|
||||||
|
|
||||||
// Guide_TM / Define_TM Trigger Setup
|
// Guide_TM / Record_TM / Define_TM Trigger Setup
|
||||||
// Guide_TM( index ) = trigger;
|
// Guide_TM( index ) = trigger;
|
||||||
// * index - Trigger Macro index number
|
// * index - Trigger Macro index number
|
||||||
// * trigger - Trigger Macro guide (see TriggerMacro)
|
// * trigger - Trigger Macro guide (see TriggerMacro)
|
||||||
// Define_TM( index, result );
|
// Record_TM( index );
|
||||||
// <State-ful sequence of combinations TriggerMacro>
|
|
||||||
// * index - Trigger Macro index number
|
// * index - Trigger Macro index number
|
||||||
// * result - Result Macro index number which is triggered by this Trigger Macro
|
// Define_TM( index, result );
|
||||||
// Define_STM( index, result );
|
|
||||||
// <State-less single combination TriggerMacro>
|
|
||||||
// * index - Trigger Macro index number
|
// * index - Trigger Macro index number
|
||||||
// * result - Result Macro index number which is triggered by this Trigger Macro
|
// * result - Result Macro index number which is triggered by this Trigger Macro
|
||||||
#define Guide_TM( index ) const uint8_t tm##index##_guide[]
|
#define Guide_TM( index ) const uint8_t tm##index##_guide[]
|
||||||
#define Define_TM( index, result ) { MacroType_Normal, tm##index##_guide, result }
|
#define Record_TM( index ) TriggerMacroRecord tm##index##_record
|
||||||
#define Define_STM( index, result ) { MacroType_Simple, tm##index##_guide, result }
|
#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
|
// -- Trigger Macro List
|
||||||
@ -259,9 +264,9 @@ typedef struct Capability {
|
|||||||
|
|
||||||
typedef struct Layer {
|
typedef struct Layer {
|
||||||
const nat_ptr_t **triggerMap;
|
const nat_ptr_t **triggerMap;
|
||||||
const char *name;
|
const char *name;
|
||||||
const uint8_t first;
|
const uint8_t first;
|
||||||
const uint8_t last;
|
const uint8_t last;
|
||||||
} Layer;
|
} Layer;
|
||||||
|
|
||||||
// Layer_IN( map, name, first );
|
// Layer_IN( map, name, first );
|
||||||
|
@ -1,24 +1,29 @@
|
|||||||
###| CMake Kiibohd Controller Macro Module |###
|
###| 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
|
# 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
|
set ( SubModule 1 )
|
||||||
"The 'Common' module is not a stand-alone module, and requires further setup."
|
|
||||||
)
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Module C files
|
# Module C files
|
||||||
#
|
#
|
||||||
|
set ( Module_SRCS
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Module Specific Options
|
# Compiler Family Compatibility
|
||||||
#
|
#
|
||||||
|
set ( ModuleCompatibility
|
||||||
|
arm
|
||||||
|
avr
|
||||||
|
)
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include <scan_loop.h>
|
#include <scan_loop.h>
|
||||||
|
|
||||||
// Keymaps
|
// Keymaps
|
||||||
#include "usb_hid.h"
|
#include <usb_hid.h>
|
||||||
#include <generatedKeymap.h> // Generated using kll at compile time, in build directory
|
#include <generatedKeymap.h> // Generated using kll at compile time, in build directory
|
||||||
|
|
||||||
// Local Includes
|
// Local Includes
|
||||||
@ -485,13 +485,13 @@ inline void Macro_appendResultMacroToPendingList( const TriggerMacro *triggerMac
|
|||||||
{
|
{
|
||||||
if ( macroTriggerListBuffer[ keyIndex ].scanCode == scanCode )
|
if ( macroTriggerListBuffer[ keyIndex ].scanCode == scanCode )
|
||||||
{
|
{
|
||||||
ResultMacroRecordList[ resultMacroIndex ].state = macroTriggerListBuffer[ keyIndex ].state;
|
ResultMacroList[ resultMacroIndex ].record->state = macroTriggerListBuffer[ keyIndex ].state;
|
||||||
ResultMacroRecordList[ resultMacroIndex ].stateType = macroTriggerListBuffer[ keyIndex ].type;
|
ResultMacroList[ resultMacroIndex ].record->stateType = macroTriggerListBuffer[ keyIndex ].type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the macro position
|
// 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
|
// Lookup TriggerMacro
|
||||||
const TriggerMacro *macro = &TriggerMacroList[ triggerMacroIndex ];
|
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
|
// Check if macro has finished and should be incremented sequence elements
|
||||||
if ( record->state == TriggerMacro_Release )
|
if ( record->state == TriggerMacro_Release )
|
||||||
@ -797,7 +797,7 @@ inline ResultMacroEval Macro_evalResultMacro( var_uint_t resultMacroIndex )
|
|||||||
{
|
{
|
||||||
// Lookup ResultMacro
|
// Lookup ResultMacro
|
||||||
const ResultMacro *macro = &ResultMacroList[ resultMacroIndex ];
|
const ResultMacro *macro = &ResultMacroList[ resultMacroIndex ];
|
||||||
ResultMacroRecord *record = &ResultMacroRecordList[ resultMacroIndex ];
|
ResultMacroRecord *record = ResultMacroList[ resultMacroIndex ].record;
|
||||||
|
|
||||||
// Current Macro position
|
// Current Macro position
|
||||||
var_uint_t pos = record->pos;
|
var_uint_t pos = record->pos;
|
||||||
@ -889,8 +889,8 @@ inline void Macro_updateTriggerMacroPendingList()
|
|||||||
macroTriggerMacroPendingList[ macroTriggerMacroPendingListSize++ ] = triggerMacroIndex;
|
macroTriggerMacroPendingList[ macroTriggerMacroPendingListSize++ ] = triggerMacroIndex;
|
||||||
|
|
||||||
// Reset macro position
|
// Reset macro position
|
||||||
TriggerMacroRecordList[ triggerMacroIndex ].pos = 0;
|
TriggerMacroList[ triggerMacroIndex ].record->pos = 0;
|
||||||
TriggerMacroRecordList[ triggerMacroIndex ].state = TriggerMacro_Waiting;
|
TriggerMacroList[ triggerMacroIndex ].record->state = TriggerMacro_Waiting;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1011,16 +1011,16 @@ inline void Macro_setup()
|
|||||||
// Initialize TriggerMacro states
|
// Initialize TriggerMacro states
|
||||||
for ( var_uint_t macro = 0; macro < TriggerMacroNum; macro++ )
|
for ( var_uint_t macro = 0; macro < TriggerMacroNum; macro++ )
|
||||||
{
|
{
|
||||||
TriggerMacroRecordList[ macro ].pos = 0;
|
TriggerMacroList[ macro ].record->pos = 0;
|
||||||
TriggerMacroRecordList[ macro ].state = TriggerMacro_Waiting;
|
TriggerMacroList[ macro ].record->state = TriggerMacro_Waiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize ResultMacro states
|
// Initialize ResultMacro states
|
||||||
for ( var_uint_t macro = 0; macro < ResultMacroNum; macro++ )
|
for ( var_uint_t macro = 0; macro < ResultMacroNum; macro++ )
|
||||||
{
|
{
|
||||||
ResultMacroRecordList[ macro ].pos = 0;
|
ResultMacroList[ macro ].record->pos = 0;
|
||||||
ResultMacroRecordList[ macro ].state = 0;
|
ResultMacroList[ macro ].record->state = 0;
|
||||||
ResultMacroRecordList[ macro ].stateType = 0;
|
ResultMacroList[ macro ].record->stateType = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1358,7 +1358,7 @@ void macroDebugShowTrigger( var_uint_t index )
|
|||||||
|
|
||||||
// Trigger Macro Show
|
// Trigger Macro Show
|
||||||
const TriggerMacro *macro = &TriggerMacroList[ index ];
|
const TriggerMacro *macro = &TriggerMacroList[ index ];
|
||||||
TriggerMacroRecord *record = &TriggerMacroRecordList[ index ];
|
TriggerMacroRecord *record = TriggerMacroList[ index ].record;
|
||||||
|
|
||||||
print( NL );
|
print( NL );
|
||||||
info_msg("Trigger Macro Index: ");
|
info_msg("Trigger Macro Index: ");
|
||||||
@ -1430,7 +1430,7 @@ void macroDebugShowResult( var_uint_t index )
|
|||||||
|
|
||||||
// Trigger Macro Show
|
// Trigger Macro Show
|
||||||
const ResultMacro *macro = &ResultMacroList[ index ];
|
const ResultMacro *macro = &ResultMacroList[ index ];
|
||||||
ResultMacroRecord *record = &ResultMacroRecordList[ index ];
|
ResultMacroRecord *record = ResultMacroList[ index ].record;
|
||||||
|
|
||||||
print( NL );
|
print( NL );
|
||||||
info_msg("Result Macro Index: ");
|
info_msg("Result Macro Index: ");
|
||||||
|
@ -7,6 +7,12 @@
|
|||||||
###
|
###
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# Required Sub-modules
|
||||||
|
#
|
||||||
|
AddModule ( Macro Common )
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Module C files
|
# Module C files
|
||||||
#
|
#
|
||||||
|
Reference in New Issue
Block a user