@@ -354,7 +354,8 @@ def get_config_data(self):
354354 return all_params , macros
355355
356356 # Helper: verify if there are any required parameters without a value in 'params'
357- def _check_required_parameters (self , params ):
357+ @staticmethod
358+ def _check_required_parameters (params ):
358359 for p in params .values ():
359360 if p .required and (p .value is None ):
360361 raise ConfigException ("Required parameter '%s' defined by '%s' doesn't have a value" % (p .name , p .defined_by ))
@@ -371,11 +372,18 @@ def parameters_to_macros(params):
371372 def config_macros_to_macros (macros ):
372373 return [m .name for m in macros .values ()]
373374
375+ # Return the configuration data converted to a list of C macros
376+ # config - configuration data as (ConfigParam instances, ConfigMacro instances) tuple
377+ # (as returned by get_config_data())
378+ @staticmethod
379+ def config_to_macros (config ):
380+ params , macros = config [0 ], config [1 ]
381+ Config ._check_required_parameters (params )
382+ return Config .config_macros_to_macros (macros ) + Config .parameters_to_macros (params )
383+
374384 # Return the configuration data converted to a list of C macros
375385 def get_config_data_macros (self ):
376- params , macros = self .get_config_data ()
377- self ._check_required_parameters (params )
378- return self .config_macros_to_macros (macros ) + self .parameters_to_macros (params )
386+ return self .config_to_macros (self .get_config_data ())
379387
380388 # Returns any features in the configuration data
381389 def get_features (self ):
@@ -419,14 +427,16 @@ def load_resources(self, resources):
419427
420428 return resources
421429
422-
423430 # Return the configuration data converted to the content of a C header file,
424431 # meant to be included to a C/C++ file. The content is returned as a string.
425432 # If 'fname' is given, the content is also written to the file called "fname".
426433 # WARNING: if 'fname' names an existing file, that file will be overwritten!
427- def get_config_data_header (self , fname = None ):
428- params , macros = self .get_config_data ()
429- self ._check_required_parameters (params )
434+ # config - configuration data as (ConfigParam instances, ConfigMacro instances) tuple
435+ # (as returned by get_config_data())
436+ @staticmethod
437+ def config_to_header (config , fname = None ):
438+ params , macros = config [0 ], config [1 ]
439+ Config ._check_required_parameters (params )
430440 header_data = "// Automatically generated configuration file.\n "
431441 header_data += "// DO NOT EDIT, content will be overwritten.\n \n "
432442 header_data += "#ifndef __MBED_CONFIG_DATA__\n "
@@ -459,3 +469,10 @@ def get_config_data_header(self, fname = None):
459469 with open (fname , "wt" ) as f :
460470 f .write (header_data )
461471 return header_data
472+
473+ # Return the configuration data converted to the content of a C header file,
474+ # meant to be included to a C/C++ file. The content is returned as a string.
475+ # If 'fname' is given, the content is also written to the file called "fname".
476+ # WARNING: if 'fname' names an existing file, that file will be overwritten!
477+ def get_config_data_header (self , fname = None ):
478+ return self .config_to_header (self .get_config_data (), fname )
0 commit comments