changeset 15:02cbd90e8919

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
author Jacob Alexander <haata@kiibohd.com>
date Tue, 16 Sep 2014 17:01:40 -0700
parents 3f819272a8a7
children e3051d204f87
files backends/kiibohd.py kll_lib/containers.py templates/kiibohdKeymap.h
diffstat 3 files changed, 72 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/backends/kiibohd.py	Tue Sep 16 15:39:21 2014 -0700
+++ b/backends/kiibohd.py	Tue Sep 16 17:01:40 2014 -0700
@@ -65,8 +65,28 @@
 		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 @@
 		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 @@
 			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 @@
 
 
 		## 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
--- a/kll_lib/containers.py	Tue Sep 16 15:39:21 2014 -0700
+++ b/kll_lib/containers.py	Tue Sep 16 17:01:40 2014 -0700
@@ -31,7 +31,9 @@
 
 ### Parsing ###
 
+
  ## Containers
+
 class Capabilities:
 	# Container for capabilities dictionary and convenience functions
 	def __init__( self ):
@@ -99,6 +101,7 @@
 		self.triggersIndexSorted = []
 		self.triggerList = []
 		self.maxScanCode = []
+		self.firstScanCode = []
 
 		# USBCode Assignment Cache
 		self.assignmentCache = []
@@ -252,9 +255,40 @@
 			# 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
+
--- a/templates/kiibohdKeymap.h	Tue Sep 16 15:39:21 2014 -0700
+++ b/templates/kiibohdKeymap.h	Tue Sep 16 17:01:40 2014 -0700
@@ -14,7 +14,8 @@
  * along with this file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-// 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