From 59a4b27de52b82bf7991ea3cbeed786f38fce1ac Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Tue, 16 Sep 2014 17:01:40 -0700 Subject: [PATCH] Adding support for firstScanCode calculation and initial Variable container implementation - To better support RAM/Flash packing adding support for first scan code calculation - This way if the first scan code is high (e.g. 0x40) RAM is not used for the scan codes without keys assigned - Some initial work for KLL variables - Will be used to influence runtime and compiler features of the firmware --- backends/kiibohd.py | 37 ++++++++++++++++++++++++++++++++----- kll_lib/containers.py | 34 ++++++++++++++++++++++++++++++++++ templates/kiibohdKeymap.h | 7 ++++++- 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/backends/kiibohd.py b/backends/kiibohd.py index 64cfb6c..1abf8e5 100644 --- a/backends/kiibohd.py +++ b/backends/kiibohd.py @@ -65,8 +65,28 @@ class Backend: return "usbKeyOut"; + def layerInformation( self, name, date, author ): + self.fill_dict['Information'] += "// Name: {0}\n".format( "TODO" ) + self.fill_dict['Information'] += "// Version: {0}\n".format( "TODO" ) + self.fill_dict['Information'] += "// Date: {0}\n".format( "TODO" ) + self.fill_dict['Information'] += "// Author: {0}\n".format( "TODO" ) + + # Processes content for fill tags and does any needed dataset calculations def process( self, capabilities, macros ): + ## Information ## + # TODO + self.fill_dict['Information'] = "// This file was generated by the kll compiler, DO NOT EDIT.\n" + self.fill_dict['Information'] += "// Generation Date: {0}\n".format( "TODO" ) + self.fill_dict['Information'] += "// Compiler arguments: {0}\n".format( "TODO" ) + self.fill_dict['Information'] += "// KLL Backend: {0}\n".format( "TODO" ) + self.fill_dict['Information'] += "// KLL Git Rev: {0}\n".format( "TODO" ) + self.fill_dict['Information'] += "//\n" + self.fill_dict['Information'] += "// - Base Layer -\n" + self.fill_dict['Information'] += "// - Default Layer -\n" + self.fill_dict['Information'] += "// - Partial Layers -\n" + + ## Capabilities ## self.fill_dict['CapabilitiesList'] = "const Capability CapabilitiesList[] = {\n" @@ -162,7 +182,7 @@ class Backend: self.fill_dict['DefaultLayerScanMap'] = "const nat_ptr_t *default_scanMap[] = {\n" # Iterate over triggerList and generate a C trigger array for the default map and default map array - for triggerList in range( 0, len( macros.triggerList[ 0 ] ) ): + for triggerList in range( macros.firstScanCode[ 0 ], len( macros.triggerList[ 0 ] ) ): # Generate ScanCode index and triggerList length self.fill_dict['DefaultLayerTriggerList'] += "Define_TL( default, 0x{0:02X} ) = {{ {1}".format( triggerList, len( macros.triggerList[ 0 ][ triggerList ] ) ) @@ -191,7 +211,7 @@ class Backend: self.fill_dict['PartialLayerTriggerLists'] += "// Partial Layer {0}\n".format( layer ) # Iterate over triggerList and generate a C trigger array for the layer - for triggerList in range( 0, len( macros.triggerList[ layer ] ) ): + for triggerList in range( macros.firstScanCode[ layer ], len( macros.triggerList[ layer ] ) ): # Generate ScanCode index and triggerList length self.fill_dict['PartialLayerTriggerLists'] += "Define_TL( layer{0}, 0x{1:02X} ) = {{ {2}".format( layer, triggerList, len( macros.triggerList[ layer ][ triggerList ] ) ) @@ -211,19 +231,26 @@ class Backend: ## Layer Index List ## - self.fill_dict['LayerIndexList'] = "Layer LayerIndex[] = {\n" + self.fill_dict['LayerIndexList'] = "const Layer LayerIndex[] = {\n" # Iterate over each layer, adding it to the list for layer in range( 0, len( macros.triggerList ) ): + # Lookup first scancode in map + firstScanCode = macros.firstScanCode[ layer ] + # Default map is a special case, always the first index # TODO Fix names if layer == 0: - self.fill_dict['LayerIndexList'] += '\tLayer_IN( default_scanMap, "DefaultMap" ),\n' + self.fill_dict['LayerIndexList'] += '\tLayer_IN( default_scanMap, "DefaultMap", 0x{0:02X} ),\n'.format( firstScanCode ) else: - self.fill_dict['LayerIndexList'] += '\tLayer_IN( layer{0}_scanMap, "Layer {0}" ),\n'.format( layer ) + self.fill_dict['LayerIndexList'] += '\tLayer_IN( layer{0}_scanMap, "Layer {0}", 0x{1:02X} ),\n'.format( layer, firstScanCode ) self.fill_dict['LayerIndexList'] += "};" + ## Layer State ## + self.fill_dict['LayerState'] = "uint8_t LayerState[ LayerNum ];" + + # Generates the output keymap with fill tags filled def generate( self, filepath ): # Process each line of the template, outputting to the target path diff --git a/kll_lib/containers.py b/kll_lib/containers.py index d54ff10..b96cc32 100644 --- a/kll_lib/containers.py +++ b/kll_lib/containers.py @@ -31,7 +31,9 @@ ERROR = '\033[5;1;31mERROR\033[0m:' ### Parsing ### + ## Containers + class Capabilities: # Container for capabilities dictionary and convenience functions def __init__( self ): @@ -99,6 +101,7 @@ class Macros: self.triggersIndexSorted = [] self.triggerList = [] self.maxScanCode = [] + self.firstScanCode = [] # USBCode Assignment Cache self.assignmentCache = [] @@ -252,9 +255,40 @@ class Macros: # Shrink triggerList to actual max size self.triggerList[ layer ] = self.triggerList[ layer ][ : self.maxScanCode[ layer ] + 1 ] + # Calculate first scan code for layer, useful for uC implementations trying to save RAM + firstScanCode = 0 + for triggerList in range( 0, len( self.triggerList[ layer ] ) ): + firstScanCode = triggerList + + # Break if triggerList has items + if len( self.triggerList[ layer ][ triggerList ] ) > 0: + break; + self.firstScanCode.append( firstScanCode ) + # Determine overall maxScanCode self.overallMaxScanCode = 0x00 for maxVal in self.maxScanCode: if maxVal > self.overallMaxScanCode: self.overallMaxScanCode = maxVal + +class Variables: + # Container for variables + # Stores three sets of variables, the overall combined set, per layer, and per file + def __init__( self ): + pass + + def baseLayerFinished( self ): + pass + + def setCurrentFile( self, name ): + # Store using filename and current layer + pass + + def setCurrentLayer( self, layer ): + # Store using layer index + pass + + def assignVariable( self, key, value ): + pass + diff --git a/templates/kiibohdKeymap.h b/templates/kiibohdKeymap.h index 693164c..2d0c293 100644 --- a/templates/kiibohdKeymap.h +++ b/templates/kiibohdKeymap.h @@ -14,7 +14,8 @@ * along with this file. If not, see . */ -// Generated MSG /w timestamp and compiler information +<|Information|> + #ifndef __generatedKeymap_h #define __generatedKeymap_h @@ -110,6 +111,10 @@ <|LayerIndexList|> +// - Layer State +<|LayerState|> + + #endif // __generatedKeymap_h