Merge branch 'test'
This commit is contained in:
commit
3a07b4bdcd
@ -30,6 +30,27 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----- Types -----
|
||||||
|
|
||||||
|
// - NOTE -
|
||||||
|
// It is possible to change the maximum state and indexing positions of the state machine.
|
||||||
|
// This usually affects the SRAM usage quite a bit, so it can be used to fit the code on smaller uCs
|
||||||
|
// Or to allow for nearly infinite states.
|
||||||
|
// TODO Make selectable from layout variable
|
||||||
|
//typedef uint32_t var_uint_t;
|
||||||
|
typedef uint16_t var_uint_t;
|
||||||
|
//typedef uint8_t var_uint_t;
|
||||||
|
|
||||||
|
// - NOTE -
|
||||||
|
// Native pointer length
|
||||||
|
// This needs to be defined per microcontroller
|
||||||
|
// e.g. mk20s -> 32 bit
|
||||||
|
// atmega -> 16 bit
|
||||||
|
typedef uint32_t nat_ptr_t;
|
||||||
|
//typedef uint16_t nat_ptr_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----- Structs -----
|
// ----- Structs -----
|
||||||
|
|
||||||
// -- Result Macro
|
// -- Result Macro
|
||||||
@ -47,7 +68,7 @@
|
|||||||
// ResultMacro struct, one is created per ResultMacro, no duplicates
|
// ResultMacro struct, one is created per ResultMacro, no duplicates
|
||||||
typedef struct ResultMacro {
|
typedef struct ResultMacro {
|
||||||
const uint8_t *guide;
|
const uint8_t *guide;
|
||||||
unsigned int pos;
|
var_uint_t pos;
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
uint8_t stateType;
|
uint8_t stateType;
|
||||||
} ResultMacro;
|
} ResultMacro;
|
||||||
@ -94,8 +115,8 @@ typedef enum TriggerMacroState {
|
|||||||
// TriggerMacro struct, one is created per TriggerMacro, no duplicates
|
// TriggerMacro struct, one is created per TriggerMacro, no duplicates
|
||||||
typedef struct TriggerMacro {
|
typedef struct TriggerMacro {
|
||||||
const uint8_t *guide;
|
const uint8_t *guide;
|
||||||
unsigned int result;
|
var_uint_t result;
|
||||||
unsigned int pos;
|
var_uint_t pos;
|
||||||
TriggerMacroState state;
|
TriggerMacroState state;
|
||||||
} TriggerMacro;
|
} TriggerMacro;
|
||||||
|
|
||||||
@ -168,7 +189,7 @@ typedef struct Capability {
|
|||||||
// * layer - basename of the layer
|
// * layer - basename of the layer
|
||||||
// * scanCode - Hex value of the scanCode
|
// * scanCode - Hex value of the scanCode
|
||||||
// * triggerList - Trigger List (see Trigger Lists)
|
// * triggerList - Trigger List (see Trigger Lists)
|
||||||
#define Define_TL( layer, scanCode ) const unsigned int layer##_tl_##scanCode[]
|
#define Define_TL( layer, scanCode ) const nat_ptr_t layer##_tl_##scanCode[]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -192,7 +213,7 @@ typedef struct Capability {
|
|||||||
// The name is defined for cli debugging purposes (Null terminated string)
|
// The name is defined for cli debugging purposes (Null terminated string)
|
||||||
|
|
||||||
typedef struct Layer {
|
typedef struct Layer {
|
||||||
const unsigned int **triggerMap;
|
const nat_ptr_t **triggerMap;
|
||||||
const char *name;
|
const char *name;
|
||||||
const uint8_t max;
|
const uint8_t max;
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
|
@ -202,6 +202,12 @@ void Macro_layerState_capability( uint8_t state, uint8_t stateType, uint8_t *arg
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only use capability on press or release
|
||||||
|
// TODO Analog
|
||||||
|
// XXX This may cause issues, might be better to implement state table here to decide -HaaTa
|
||||||
|
if ( stateType == 0x00 && state == 0x02 ) // Hold condition
|
||||||
|
return;
|
||||||
|
|
||||||
// Get layer index from arguments
|
// Get layer index from arguments
|
||||||
// Cast pointer to uint8_t to unsigned int then access that memory location
|
// Cast pointer to uint8_t to unsigned int then access that memory location
|
||||||
uint16_t layer = *(uint16_t*)(&args[0]);
|
uint16_t layer = *(uint16_t*)(&args[0]);
|
||||||
@ -224,6 +230,12 @@ void Macro_layerLatch_capability( uint8_t state, uint8_t stateType, uint8_t *arg
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only use capability on press
|
||||||
|
// TODO Analog
|
||||||
|
// XXX To make sense, this code be on press or release. Or it could even be a sticky shift (why? dunno) -HaaTa
|
||||||
|
if ( stateType == 0x00 && state != 0x01 ) // All normal key conditions except press
|
||||||
|
return;
|
||||||
|
|
||||||
// Get layer index from arguments
|
// Get layer index from arguments
|
||||||
// Cast pointer to uint8_t to unsigned int then access that memory location
|
// Cast pointer to uint8_t to unsigned int then access that memory location
|
||||||
uint16_t layer = *(uint16_t*)(&args[0]);
|
uint16_t layer = *(uint16_t*)(&args[0]);
|
||||||
@ -243,6 +255,12 @@ void Macro_layerLock_capability( uint8_t state, uint8_t stateType, uint8_t *args
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only use capability on press
|
||||||
|
// TODO Analog
|
||||||
|
// XXX Could also be on release, but that's sorta dumb -HaaTa
|
||||||
|
if ( stateType == 0x00 && state != 0x01 ) // All normal key conditions except press
|
||||||
|
return;
|
||||||
|
|
||||||
// Get layer index from arguments
|
// Get layer index from arguments
|
||||||
// Cast pointer to uint8_t to unsigned int then access that memory location
|
// Cast pointer to uint8_t to unsigned int then access that memory location
|
||||||
uint16_t layer = *(uint16_t*)(&args[0]);
|
uint16_t layer = *(uint16_t*)(&args[0]);
|
||||||
@ -262,6 +280,11 @@ void Macro_layerShift_capability( uint8_t state, uint8_t stateType, uint8_t *arg
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only use capability on press or release
|
||||||
|
// TODO Analog
|
||||||
|
if ( stateType == 0x00 && ( state == 0x00 || state == 0x02 ) ) // Only pass press or release conditions
|
||||||
|
return;
|
||||||
|
|
||||||
// Get layer index from arguments
|
// Get layer index from arguments
|
||||||
// Cast pointer to uint8_t to unsigned int then access that memory location
|
// Cast pointer to uint8_t to unsigned int then access that memory location
|
||||||
uint16_t layer = *(uint16_t*)(&args[0]);
|
uint16_t layer = *(uint16_t*)(&args[0]);
|
||||||
@ -275,7 +298,7 @@ void Macro_layerShift_capability( uint8_t state, uint8_t stateType, uint8_t *arg
|
|||||||
|
|
||||||
// Looks up the trigger list for the given scan code (from the active layer)
|
// Looks up the trigger list for the given scan code (from the active layer)
|
||||||
// NOTE: Calling function must handle the NULL pointer case
|
// NOTE: Calling function must handle the NULL pointer case
|
||||||
unsigned int *Macro_layerLookup( uint8_t scanCode )
|
nat_ptr_t *Macro_layerLookup( uint8_t scanCode )
|
||||||
{
|
{
|
||||||
// If no trigger macro is defined at the given layer, fallthrough to the next layer
|
// If no trigger macro is defined at the given layer, fallthrough to the next layer
|
||||||
for ( unsigned int layerIndex = 0; layerIndex < macroLayerIndexStackSize; layerIndex++ )
|
for ( unsigned int layerIndex = 0; layerIndex < macroLayerIndexStackSize; layerIndex++ )
|
||||||
@ -297,7 +320,7 @@ unsigned int *Macro_layerLookup( uint8_t scanCode )
|
|||||||
if ( (layer->state & 0x01) ^ (latch>>1) ^ ((layer->state & 0x04)>>2) )
|
if ( (layer->state & 0x01) ^ (latch>>1) ^ ((layer->state & 0x04)>>2) )
|
||||||
{
|
{
|
||||||
// Lookup layer
|
// Lookup layer
|
||||||
unsigned int **map = (unsigned int**)layer->triggerMap;
|
nat_ptr_t **map = (nat_ptr_t**)layer->triggerMap;
|
||||||
|
|
||||||
// Determine if layer has key defined
|
// Determine if layer has key defined
|
||||||
if ( map != 0 && *map[ scanCode ] != 0 )
|
if ( map != 0 && *map[ scanCode ] != 0 )
|
||||||
@ -306,7 +329,7 @@ unsigned int *Macro_layerLookup( uint8_t scanCode )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do lookup on default layer
|
// Do lookup on default layer
|
||||||
unsigned int **map = (unsigned int**)LayerIndex[0].triggerMap;
|
nat_ptr_t **map = (nat_ptr_t**)LayerIndex[0].triggerMap;
|
||||||
|
|
||||||
// Determine if layer has key defined
|
// Determine if layer has key defined
|
||||||
if ( map == 0 && *map[ scanCode ] == 0 )
|
if ( map == 0 && *map[ scanCode ] == 0 )
|
||||||
@ -704,10 +727,10 @@ inline TriggerMacroEval Macro_evalTriggerMacro( unsigned int triggerMacroIndex )
|
|||||||
return TriggerMacroEval_Remove;
|
return TriggerMacroEval_Remove;
|
||||||
}
|
}
|
||||||
// Otherwise, just remove the macro on key release
|
// Otherwise, just remove the macro on key release
|
||||||
// XXX Might cause some issues
|
// One more result has to be called to indicate to the ResultMacro that the key transitioned to the release state
|
||||||
else if ( overallVote & TriggerMacroVote_Release )
|
else if ( overallVote & TriggerMacroVote_Release )
|
||||||
{
|
{
|
||||||
return TriggerMacroEval_Remove;
|
return TriggerMacroEval_DoResultAndRemove;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is a short macro, just remove it
|
// If this is a short macro, just remove it
|
||||||
@ -781,10 +804,10 @@ inline void Macro_updateTriggerMacroPendingList()
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Lookup Trigger List
|
// Lookup Trigger List
|
||||||
unsigned int *triggerList = Macro_layerLookup( macroTriggerListBuffer[ key ].scanCode );
|
nat_ptr_t *triggerList = Macro_layerLookup( macroTriggerListBuffer[ key ].scanCode );
|
||||||
|
|
||||||
// Number of Triggers in list
|
// Number of Triggers in list
|
||||||
unsigned int triggerListSize = triggerList[0];
|
nat_ptr_t triggerListSize = triggerList[0];
|
||||||
|
|
||||||
// Iterate over triggerList to see if any TriggerMacros need to be added
|
// Iterate over triggerList to see if any TriggerMacros need to be added
|
||||||
// First item is the number of items in the TriggerList
|
// First item is the number of items in the TriggerList
|
||||||
|
@ -110,6 +110,11 @@ void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *a
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Analog inputs
|
||||||
|
// Only send keypresses if press or hold state
|
||||||
|
if ( stateType == 0x00 && state == 0x03 ) // Release state
|
||||||
|
return;
|
||||||
|
|
||||||
// Get the keycode from arguments
|
// Get the keycode from arguments
|
||||||
uint8_t key = args[0];
|
uint8_t key = args[0];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user