KLL Compiler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

kiibohd.py 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. #!/usr/bin/env python3
  2. '''
  3. KLL Kiibohd .h File Emitter
  4. '''
  5. # Copyright (C) 2016 by Jacob Alexander
  6. #
  7. # This file is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This file is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this file. If not, see <http://www.gnu.org/licenses/>.
  19. ### Imports ###
  20. import re
  21. import sys
  22. from datetime import date
  23. from common.emitter import Emitter, TextEmitter
  24. from common.hid_dict import kll_hid_lookup_dictionary
  25. ### Decorators ###
  26. ## Print Decorator Variables
  27. ERROR = '\033[5;1;31mERROR\033[0m:'
  28. WARNING = '\033[5;1;33mWARNING\033[0m:'
  29. ### Classes ###
  30. class Kiibohd( Emitter, TextEmitter ):
  31. '''
  32. Kiibohd .h file emitter for KLL
  33. '''
  34. # List of required capabilities
  35. requiredCapabilities = {
  36. 'CONS' : 'consCtrlOut',
  37. 'NONE' : 'noneOut',
  38. 'SYS' : 'sysCtrlOut',
  39. 'USB' : 'usbKeyOut',
  40. }
  41. def __init__( self, control ):
  42. '''
  43. Emitter initialization
  44. @param control: ControlStage object, used to access data from other stages
  45. '''
  46. Emitter.__init__( self, control )
  47. TextEmitter.__init__( self )
  48. # Defaults
  49. self.map_template = "templates/kiibohdKeymap.h"
  50. self.pixel_template = "templates/kiibohdPixelmap.c"
  51. self.def_template = "templates/kiibohdDefs.h"
  52. self.map_output = "generatedKeymap.h"
  53. self.pixel_output = "generatedPixelmap.c"
  54. self.def_output = "kll_defs.h"
  55. self.fill_dict = {}
  56. def command_line_args( self, args ):
  57. '''
  58. Group parser for command line arguments
  59. @param args: Name space of processed arguments
  60. '''
  61. self.def_template = args.def_template
  62. self.map_template = args.map_template
  63. self.pixel_template = args.pixel_template
  64. self.def_output = args.def_output
  65. self.map_output = args.map_output
  66. self.pixel_output = args.pixel_output
  67. def command_line_flags( self, parser ):
  68. '''
  69. Group parser for command line options
  70. @param parser: argparse setup object
  71. '''
  72. # Create new option group
  73. group = parser.add_argument_group('\033[1mKiibohd Emitter Configuration\033[0m')
  74. group.add_argument( '--def-template', type=str, default=self.def_template,
  75. help="Specify KLL define .h file template.\n"
  76. "\033[1mDefault\033[0m: {0}\n".format( self.def_template )
  77. )
  78. group.add_argument( '--map-template', type=str, default=self.map_template,
  79. help="Specify KLL map .h file template.\n"
  80. "\033[1mDefault\033[0m: {0}\n".format( self.map_template )
  81. )
  82. group.add_argument( '--pixel-template', type=str, default=self.pixel_template,
  83. help="Specify KLL pixel map .c file template.\n"
  84. "\033[1mDefault\033[0m: {0}\n".format( self.pixel_template )
  85. )
  86. group.add_argument( '--def-output', type=str, default=self.def_output,
  87. help="Specify KLL define .h file output.\n"
  88. "\033[1mDefault\033[0m: {0}\n".format( self.def_output )
  89. )
  90. group.add_argument( '--map-output', type=str, default=self.map_output,
  91. help="Specify KLL map .h file output.\n"
  92. "\033[1mDefault\033[0m: {0}\n".format( self.map_output )
  93. )
  94. group.add_argument( '--pixel-output', type=str, default=self.pixel_output,
  95. help="Specify KLL map .h file output.\n"
  96. "\033[1mDefault\033[0m: {0}\n".format( self.pixel_output )
  97. )
  98. def output( self ):
  99. '''
  100. Final Stage of Emitter
  101. Generate desired outputs from templates
  102. '''
  103. # Load define template and generate
  104. self.load_template( self.def_template )
  105. self.generate( self.def_output )
  106. # Load keymap template and generate
  107. # TODO
  108. #self.load_template( self.map_template )
  109. #self.generate( self.map_output )
  110. # Load pixelmap template and generate
  111. self.load_template( self.pixel_template )
  112. self.generate( self.pixel_output )
  113. def process( self ):
  114. '''
  115. Emitter Processing
  116. Takes KLL datastructures and Analysis results then populates the fill_dict
  117. The fill_dict is used populate the template files.
  118. '''
  119. # Acquire Datastructures
  120. early_contexts = self.control.stage('DataOrganizationStage').contexts
  121. base_context = self.control.stage('DataFinalizationStage').base_context
  122. default_context = self.control.stage('DataFinalizationStage').default_context
  123. partial_contexts = self.control.stage('DataFinalizationStage').partial_contexts
  124. full_context = self.control.stage('DataFinalizationStage').full_context
  125. # Build string list of compiler arguments
  126. compilerArgs = ""
  127. for arg in sys.argv:
  128. if "--" in arg or ".py" in arg:
  129. compilerArgs += "// {0}\n".format( arg )
  130. else:
  131. compilerArgs += "// {0}\n".format( arg )
  132. # Build a string of modified files, if any
  133. gitChangesStr = "\n"
  134. if len( self.control.git_changes ) > 0:
  135. for gitFile in self.control.git_changes:
  136. gitChangesStr += "// {0}\n".format( gitFile )
  137. else:
  138. gitChangesStr = " None\n"
  139. # Prepare BaseLayout and Layer Info
  140. configLayoutInfo = ""
  141. if 'ConfigurationContext' in early_contexts.keys():
  142. contexts = early_contexts['ConfigurationContext'].query_contexts( 'AssignmentExpression', 'Array' )
  143. for sub in contexts:
  144. name = sub[0].data['Name'].value
  145. configLayoutInfo += "// {0}\n// {1}\n".format( name, sub[1].parent.path )
  146. genericLayoutInfo = ""
  147. if 'GenericContext' in early_contexts.keys():
  148. contexts = early_contexts['GenericContext'].query_contexts( 'AssignmentExpression', 'Array' )
  149. for sub in contexts:
  150. name = sub[0].data['Name'].value
  151. genericLayoutInfo += "// {0}\n// {1}\n".format( name, sub[1].parent.path )
  152. baseLayoutInfo = ""
  153. if 'BaseMapContext' in early_contexts.keys():
  154. contexts = early_contexts['BaseMapContext'].query_contexts( 'AssignmentExpression', 'Array' )
  155. for sub in contexts:
  156. name = sub[0].data['Name'].value
  157. baseLayoutInfo += "// {0}\n// {1}\n".format( name, sub[1].parent.path )
  158. defaultLayerInfo = ""
  159. if 'DefaultMapContext' in early_contexts.keys():
  160. contexts = early_contexts['DefaultMapContext'].query_contexts( 'AssignmentExpression', 'Array' )
  161. for sub in contexts:
  162. name = sub[0].data['Name'].value
  163. defaultLayerInfo += "// {0}\n// {1}\n".format( name, sub[1].parent.path )
  164. partialLayersInfo = ""
  165. partial_context_list = [
  166. ( item[1].layer, item[0] )
  167. for item in early_contexts.items()
  168. if 'PartialMapContext' in item[0]
  169. ]
  170. for layer, tag in sorted( partial_context_list, key=lambda x: x[0] ):
  171. partialLayersInfo += "// Layer {0}\n".format( layer + 1 )
  172. contexts = early_contexts[ tag ].query_contexts( 'AssignmentExpression', 'Array' )
  173. for sub in contexts:
  174. name = sub[0].data['Name'].value
  175. partialLayersInfo += "// {0}\n// {1}\n".format( name, sub[1].parent.path )
  176. ## Information ##
  177. self.fill_dict['Information'] = "// This file was generated by the kll compiler, DO NOT EDIT.\n"
  178. self.fill_dict['Information'] += "// Generation Date: {0}\n".format( date.today() )
  179. self.fill_dict['Information'] += "// KLL Emitter: {0}\n".format(
  180. self.control.stage('CompilerConfigurationStage').emitter
  181. )
  182. self.fill_dict['Information'] += "// KLL Version: {0}\n".format( self.control.version )
  183. self.fill_dict['Information'] += "// KLL Git Changes:{0}".format( gitChangesStr )
  184. self.fill_dict['Information'] += "// Compiler arguments:\n{0}".format( compilerArgs )
  185. self.fill_dict['Information'] += "//\n"
  186. self.fill_dict['Information'] += "// - Configuration File -\n{0}".format( configLayoutInfo )
  187. self.fill_dict['Information'] += "// - Generic Files -\n{0}".format( genericLayoutInfo )
  188. self.fill_dict['Information'] += "// - Base Layer -\n{0}".format( baseLayoutInfo )
  189. self.fill_dict['Information'] += "// - Default Layer -\n{0}".format( defaultLayerInfo )
  190. self.fill_dict['Information'] += "// - Partial Layers -\n{0}".format( partialLayersInfo )
  191. ## Defines ##
  192. self.fill_dict['Defines'] = ""
  193. # Iterate through defines and lookup the variables
  194. defines = full_context.query( 'NameAssociationExpression', 'Define' )
  195. variables = full_context.query( 'AssignmentExpression', 'Variable' )
  196. for dkey, dvalue in sorted( defines.data.items() ):
  197. if dvalue.name in variables.data.keys():
  198. self.fill_dict['Defines'] += "\n#define {0} {1}".format(
  199. dvalue.association,
  200. variables.data[ dvalue.name ].value.replace( '\n', ' \\\n' ),
  201. )
  202. else:
  203. print( "{0} '{1}' not defined...".format( WARNING, dvalue.name ) )
  204. ## Capabilities ##
  205. self.fill_dict['CapabilitiesFuncDecl'] = ""
  206. self.fill_dict['CapabilitiesList'] = "const Capability CapabilitiesList[] = {\n"
  207. self.fill_dict['CapabilitiesIndices'] = "typedef enum CapabilityIndex {\n"
  208. # Keys are pre-sorted
  209. capabilities = full_context.query( 'NameAssociationExpression', 'Capability' )
  210. for dkey, dvalue in sorted( capabilities.data.items() ):
  211. funcName = dvalue.association.name
  212. argByteWidth = dvalue.association.total_arg_bytes()
  213. self.fill_dict['CapabilitiesList'] += "\t{{ {0}, {1} }},\n".format( funcName, argByteWidth )
  214. self.fill_dict['CapabilitiesFuncDecl'] += \
  215. "void {0}( uint8_t state, uint8_t stateType, uint8_t *args );\n".format( funcName )
  216. self.fill_dict['CapabilitiesIndices'] += "\t{0}_index,\n".format( funcName )
  217. self.fill_dict['CapabilitiesList'] += "};"
  218. self.fill_dict['CapabilitiesIndices'] += "} CapabilityIndex;"
  219. return
  220. ## Results Macros ##
  221. self.fill_dict['ResultMacros'] = ""
  222. # Iterate through each of the result macros
  223. for result in range( 0, len( macros.resultsIndexSorted ) ):
  224. self.fill_dict['ResultMacros'] += "Guide_RM( {0} ) = {{ ".format( result )
  225. # Add the result macro capability index guide (including capability arguments)
  226. # See kiibohd controller Macros/PartialMap/kll.h for exact formatting details
  227. for sequence in range( 0, len( macros.resultsIndexSorted[ result ] ) ):
  228. # If the sequence is longer than 1, prepend a sequence spacer
  229. # Needed for USB behaviour, otherwise, repeated keys will not work
  230. if sequence > 0:
  231. # <single element>, <usbCodeSend capability>, <USB Code 0x00>
  232. self.fill_dict['ResultMacros'] += "1, {0}, 0x00, ".format( capabilities.getIndex( self.capabilityLookup('USB') ) )
  233. # For each combo in the sequence, add the length of the combo
  234. self.fill_dict['ResultMacros'] += "{0}, ".format( len( macros.resultsIndexSorted[ result ][ sequence ] ) )
  235. # For each combo, add each of the capabilities used and their arguments
  236. for combo in range( 0, len( macros.resultsIndexSorted[ result ][ sequence ] ) ):
  237. resultItem = macros.resultsIndexSorted[ result ][ sequence ][ combo ]
  238. # Add the capability index
  239. self.fill_dict['ResultMacros'] += "{0}, ".format( capabilities.getIndex( resultItem[0] ) )
  240. # Add each of the arguments of the capability
  241. for arg in range( 0, len( resultItem[1] ) ):
  242. # Special cases
  243. if isinstance( resultItem[1][ arg ], str ):
  244. # If this is a CONSUMER_ element, needs to be split into 2 elements
  245. # AC_ and AL_ are other sections of consumer control
  246. if re.match( r'^(CONSUMER|AC|AL)_', resultItem[1][ arg ] ):
  247. tag = resultItem[1][ arg ].split( '_', 1 )[1]
  248. if '_' in tag:
  249. tag = tag.replace( '_', '' )
  250. try:
  251. lookupNum = kll_hid_lookup_dictionary['ConsCode'][ tag ][1]
  252. except KeyError as err:
  253. print ( "{0} {1} Consumer HID kll bug...please report.".format( ERROR, err ) )
  254. raise
  255. byteForm = lookupNum.to_bytes( 2, byteorder='little' ) # XXX Yes, little endian from how the uC structs work
  256. self.fill_dict['ResultMacros'] += "{0}, {1}, ".format( *byteForm )
  257. continue
  258. # None, fall-through disable
  259. elif resultItem[0] is self.capabilityLookup('NONE'):
  260. continue
  261. self.fill_dict['ResultMacros'] += "{0}, ".format( resultItem[1][ arg ] )
  262. # If sequence is longer than 1, append a sequence spacer at the end of the sequence
  263. # Required by USB to end at sequence without holding the key down
  264. if len( macros.resultsIndexSorted[ result ] ) > 1:
  265. # <single element>, <usbCodeSend capability>, <USB Code 0x00>
  266. self.fill_dict['ResultMacros'] += "1, {0}, 0x00, ".format( capabilities.getIndex( self.capabilityLookup('USB') ) )
  267. # Add list ending 0 and end of list
  268. self.fill_dict['ResultMacros'] += "0 };\n"
  269. self.fill_dict['ResultMacros'] = self.fill_dict['ResultMacros'][:-1] # Remove last newline
  270. ## Result Macro List ##
  271. self.fill_dict['ResultMacroList'] = "const ResultMacro ResultMacroList[] = {\n"
  272. # Iterate through each of the result macros
  273. for result in range( 0, len( macros.resultsIndexSorted ) ):
  274. self.fill_dict['ResultMacroList'] += "\tDefine_RM( {0} ),\n".format( result )
  275. self.fill_dict['ResultMacroList'] += "};"
  276. ## Result Macro Record ##
  277. self.fill_dict['ResultMacroRecord'] = "ResultMacroRecord ResultMacroRecordList[ ResultMacroNum ];"
  278. ## Trigger Macros ##
  279. self.fill_dict['TriggerMacros'] = ""
  280. # Iterate through each of the trigger macros
  281. for trigger in range( 0, len( macros.triggersIndexSorted ) ):
  282. self.fill_dict['TriggerMacros'] += "Guide_TM( {0} ) = {{ ".format( trigger )
  283. # Add the trigger macro scan code guide
  284. # See kiibohd controller Macros/PartialMap/kll.h for exact formatting details
  285. for sequence in range( 0, len( macros.triggersIndexSorted[ trigger ][0] ) ):
  286. # For each combo in the sequence, add the length of the combo
  287. self.fill_dict['TriggerMacros'] += "{0}, ".format( len( macros.triggersIndexSorted[ trigger ][0][ sequence ] ) )
  288. # For each combo, add the key type, key state and scan code
  289. for combo in range( 0, len( macros.triggersIndexSorted[ trigger ][0][ sequence ] ) ):
  290. triggerItemId = macros.triggersIndexSorted[ trigger ][0][ sequence ][ combo ]
  291. # Lookup triggerItem in ScanCodeStore
  292. triggerItemObj = macros.scanCodeStore[ triggerItemId ]
  293. triggerItem = triggerItemObj.offset( macros.interconnectOffset )
  294. # TODO Add support for Analog keys
  295. # TODO Add support for LED states
  296. self.fill_dict['TriggerMacros'] += "0x00, 0x01, 0x{0:02X}, ".format( triggerItem )
  297. # Add list ending 0 and end of list
  298. self.fill_dict['TriggerMacros'] += "0 };\n"
  299. self.fill_dict['TriggerMacros'] = self.fill_dict['TriggerMacros'][ :-1 ] # Remove last newline
  300. ## Trigger Macro List ##
  301. self.fill_dict['TriggerMacroList'] = "const TriggerMacro TriggerMacroList[] = {\n"
  302. # Iterate through each of the trigger macros
  303. for trigger in range( 0, len( macros.triggersIndexSorted ) ):
  304. # Use TriggerMacro Index, and the corresponding ResultMacro Index
  305. self.fill_dict['TriggerMacroList'] += "\tDefine_TM( {0}, {1} ),\n".format( trigger, macros.triggersIndexSorted[ trigger ][1] )
  306. self.fill_dict['TriggerMacroList'] += "};"
  307. ## Trigger Macro Record ##
  308. self.fill_dict['TriggerMacroRecord'] = "TriggerMacroRecord TriggerMacroRecordList[ TriggerMacroNum ];"
  309. ## Max Scan Code ##
  310. self.fill_dict['MaxScanCode'] = "#define MaxScanCode 0x{0:X}".format( macros.overallMaxScanCode )
  311. ## Interconnect ScanCode Offset List ##
  312. self.fill_dict['ScanCodeInterconnectOffsetList'] = "const uint8_t InterconnectOffsetList[] = {\n"
  313. for offset in range( 0, len( macros.interconnectOffset ) ):
  314. self.fill_dict['ScanCodeInterconnectOffsetList'] += "\t0x{0:02X},\n".format( macros.interconnectOffset[ offset ] )
  315. self.fill_dict['ScanCodeInterconnectOffsetList'] += "};"
  316. ## Max Interconnect Nodes ##
  317. self.fill_dict['InterconnectNodeMax'] = "#define InterconnectNodeMax 0x{0:X}\n".format( len( macros.interconnectOffset ) )
  318. ## Default Layer and Default Layer Scan Map ##
  319. self.fill_dict['DefaultLayerTriggerList'] = ""
  320. self.fill_dict['DefaultLayerScanMap'] = "const nat_ptr_t *default_scanMap[] = {\n"
  321. # Iterate over triggerList and generate a C trigger array for the default map and default map array
  322. for triggerList in range( macros.firstScanCode[0], len( macros.triggerList[0] ) ):
  323. # Generate ScanCode index and triggerList length
  324. self.fill_dict['DefaultLayerTriggerList'] += "Define_TL( default, 0x{0:02X} ) = {{ {1}".format( triggerList, len( macros.triggerList[0][ triggerList ] ) )
  325. # Add scanCode trigger list to Default Layer Scan Map
  326. self.fill_dict['DefaultLayerScanMap'] += "default_tl_0x{0:02X}, ".format( triggerList )
  327. # Add each item of the trigger list
  328. for triggerItem in macros.triggerList[0][ triggerList ]:
  329. self.fill_dict['DefaultLayerTriggerList'] += ", {0}".format( triggerItem )
  330. self.fill_dict['DefaultLayerTriggerList'] += " };\n"
  331. self.fill_dict['DefaultLayerTriggerList'] = self.fill_dict['DefaultLayerTriggerList'][:-1] # Remove last newline
  332. self.fill_dict['DefaultLayerScanMap'] = self.fill_dict['DefaultLayerScanMap'][:-2] # Remove last comma and space
  333. self.fill_dict['DefaultLayerScanMap'] += "\n};"
  334. ## Partial Layers and Partial Layer Scan Maps ##
  335. self.fill_dict['PartialLayerTriggerLists'] = ""
  336. self.fill_dict['PartialLayerScanMaps'] = ""
  337. # Iterate over each of the layers, excluding the default layer
  338. for layer in range( 1, len( macros.triggerList ) ):
  339. # Prepare each layer
  340. self.fill_dict['PartialLayerScanMaps'] += "// Partial Layer {0}\n".format( layer )
  341. self.fill_dict['PartialLayerScanMaps'] += "const nat_ptr_t *layer{0}_scanMap[] = {{\n".format( layer )
  342. self.fill_dict['PartialLayerTriggerLists'] += "// Partial Layer {0}\n".format( layer )
  343. # Iterate over triggerList and generate a C trigger array for the layer
  344. for triggerList in range( macros.firstScanCode[ layer ], len( macros.triggerList[ layer ] ) ):
  345. # Generate ScanCode index and triggerList length
  346. self.fill_dict['PartialLayerTriggerLists'] += "Define_TL( layer{0}, 0x{1:02X} ) = {{ {2}".format( layer, triggerList, len( macros.triggerList[ layer ][ triggerList ] ) )
  347. # Add scanCode trigger list to Default Layer Scan Map
  348. self.fill_dict['PartialLayerScanMaps'] += "layer{0}_tl_0x{1:02X}, ".format( layer, triggerList )
  349. # Add each item of the trigger list
  350. for trigger in macros.triggerList[ layer ][ triggerList ]:
  351. self.fill_dict['PartialLayerTriggerLists'] += ", {0}".format( trigger )
  352. self.fill_dict['PartialLayerTriggerLists'] += " };\n"
  353. self.fill_dict['PartialLayerTriggerLists'] += "\n"
  354. self.fill_dict['PartialLayerScanMaps'] = self.fill_dict['PartialLayerScanMaps'][:-2] # Remove last comma and space
  355. self.fill_dict['PartialLayerScanMaps'] += "\n};\n\n"
  356. self.fill_dict['PartialLayerTriggerLists'] = self.fill_dict['PartialLayerTriggerLists'][:-2] # Remove last 2 newlines
  357. self.fill_dict['PartialLayerScanMaps'] = self.fill_dict['PartialLayerScanMaps'][:-2] # Remove last 2 newlines
  358. ## Layer Index List ##
  359. self.fill_dict['LayerIndexList'] = "const Layer LayerIndex[] = {\n"
  360. # Iterate over each layer, adding it to the list
  361. for layer in range( 0, len( macros.triggerList ) ):
  362. # Lookup first scancode in map
  363. firstScanCode = macros.firstScanCode[ layer ]
  364. # Generate stacked name
  365. stackName = ""
  366. if '*NameStack' in variables.layerVariables[ layer ].keys():
  367. for name in range( 0, len( variables.layerVariables[ layer ]['*NameStack'] ) ):
  368. stackName += "{0} + ".format( variables.layerVariables[ layer ]['*NameStack'][ name ] )
  369. stackName = stackName[:-3]
  370. # Default map is a special case, always the first index
  371. if layer == 0:
  372. self.fill_dict['LayerIndexList'] += '\tLayer_IN( default_scanMap, "D: {1}", 0x{0:02X} ),\n'.format( firstScanCode, stackName )
  373. else:
  374. self.fill_dict['LayerIndexList'] += '\tLayer_IN( layer{0}_scanMap, "{0}: {2}", 0x{1:02X} ),\n'.format( layer, firstScanCode, stackName )
  375. self.fill_dict['LayerIndexList'] += "};"
  376. ## Layer State ##
  377. self.fill_dict['LayerState'] = "uint8_t LayerState[ LayerNum ];"