mbed os with nrf51 internal bandgap enabled to read battery level
Dependents: BLE_file_test BLE_Blink ExternalEncoder
tools/get_config.py@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | #! /usr/bin/env python2 |
elessair | 0:f269e3021894 | 2 | """ |
elessair | 0:f269e3021894 | 3 | mbed SDK |
elessair | 0:f269e3021894 | 4 | Copyright (c) 2011-2013 ARM Limited |
elessair | 0:f269e3021894 | 5 | |
elessair | 0:f269e3021894 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
elessair | 0:f269e3021894 | 7 | you may not use this file except in compliance with the License. |
elessair | 0:f269e3021894 | 8 | You may obtain a copy of the License at |
elessair | 0:f269e3021894 | 9 | |
elessair | 0:f269e3021894 | 10 | http://www.apache.org/licenses/LICENSE-2.0 |
elessair | 0:f269e3021894 | 11 | |
elessair | 0:f269e3021894 | 12 | Unless required by applicable law or agreed to in writing, software |
elessair | 0:f269e3021894 | 13 | distributed under the License is distributed on an "AS IS" BASIS, |
elessair | 0:f269e3021894 | 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
elessair | 0:f269e3021894 | 15 | See the License for the specific language governing permissions and |
elessair | 0:f269e3021894 | 16 | limitations under the License. |
elessair | 0:f269e3021894 | 17 | |
elessair | 0:f269e3021894 | 18 | """ |
elessair | 0:f269e3021894 | 19 | import sys |
elessair | 0:f269e3021894 | 20 | from os.path import isdir, abspath, dirname, join |
elessair | 0:f269e3021894 | 21 | from os import _exit |
elessair | 0:f269e3021894 | 22 | |
elessair | 0:f269e3021894 | 23 | # Be sure that the tools directory is in the search path |
elessair | 0:f269e3021894 | 24 | ROOT = abspath(join(dirname(__file__), "..")) |
elessair | 0:f269e3021894 | 25 | sys.path.insert(0, ROOT) |
elessair | 0:f269e3021894 | 26 | |
elessair | 0:f269e3021894 | 27 | from tools.utils import args_error |
elessair | 0:f269e3021894 | 28 | from tools.options import get_default_options_parser |
elessair | 0:f269e3021894 | 29 | from tools.build_api import get_config |
elessair | 0:f269e3021894 | 30 | from config import Config |
elessair | 0:f269e3021894 | 31 | from utils import argparse_filestring_type |
elessair | 0:f269e3021894 | 32 | try: |
elessair | 0:f269e3021894 | 33 | import tools.private_settings as ps |
elessair | 0:f269e3021894 | 34 | except: |
elessair | 0:f269e3021894 | 35 | ps = object() |
elessair | 0:f269e3021894 | 36 | |
elessair | 0:f269e3021894 | 37 | if __name__ == '__main__': |
elessair | 0:f269e3021894 | 38 | # Parse Options |
elessair | 0:f269e3021894 | 39 | parser = get_default_options_parser(add_clean=False, add_options=False) |
elessair | 0:f269e3021894 | 40 | parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, required=True, |
elessair | 0:f269e3021894 | 41 | default=[], help="The source (input) directory", action="append") |
elessair | 0:f269e3021894 | 42 | parser.add_argument("--prefix", dest="prefix", action="append", |
elessair | 0:f269e3021894 | 43 | default=[], help="Restrict listing to parameters that have this prefix") |
elessair | 0:f269e3021894 | 44 | parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", |
elessair | 0:f269e3021894 | 45 | default=False, help="Verbose diagnostic output") |
elessair | 0:f269e3021894 | 46 | |
elessair | 0:f269e3021894 | 47 | options = parser.parse_args() |
elessair | 0:f269e3021894 | 48 | |
elessair | 0:f269e3021894 | 49 | # Target |
elessair | 0:f269e3021894 | 50 | if options.mcu is None : |
elessair | 0:f269e3021894 | 51 | args_error(parser, "argument -m/--mcu is required") |
elessair | 0:f269e3021894 | 52 | target = options.mcu[0] |
elessair | 0:f269e3021894 | 53 | |
elessair | 0:f269e3021894 | 54 | # Toolchain |
elessair | 0:f269e3021894 | 55 | if options.tool is None: |
elessair | 0:f269e3021894 | 56 | args_error(parser, "argument -t/--toolchain is required") |
elessair | 0:f269e3021894 | 57 | toolchain = options.tool[0] |
elessair | 0:f269e3021894 | 58 | |
elessair | 0:f269e3021894 | 59 | options.prefix = options.prefix or [""] |
elessair | 0:f269e3021894 | 60 | |
elessair | 0:f269e3021894 | 61 | try: |
elessair | 0:f269e3021894 | 62 | params, macros, features = get_config(options.source_dir, target, toolchain) |
elessair | 0:f269e3021894 | 63 | if not params and not macros: |
elessair | 0:f269e3021894 | 64 | print "No configuration data available." |
elessair | 0:f269e3021894 | 65 | _exit(0) |
elessair | 0:f269e3021894 | 66 | if params: |
elessair | 0:f269e3021894 | 67 | print "Configuration parameters" |
elessair | 0:f269e3021894 | 68 | print "------------------------" |
elessair | 0:f269e3021894 | 69 | for p in params: |
elessair | 0:f269e3021894 | 70 | for s in options.prefix: |
elessair | 0:f269e3021894 | 71 | if p.startswith(s): |
elessair | 0:f269e3021894 | 72 | print(str(params[p]) if not options.verbose else params[p].get_verbose_description()) |
elessair | 0:f269e3021894 | 73 | break |
elessair | 0:f269e3021894 | 74 | print "" |
elessair | 0:f269e3021894 | 75 | |
elessair | 0:f269e3021894 | 76 | print "Macros" |
elessair | 0:f269e3021894 | 77 | print "------" |
elessair | 0:f269e3021894 | 78 | if macros: |
elessair | 0:f269e3021894 | 79 | print 'Defined with "macros":', Config.config_macros_to_macros(macros) |
elessair | 0:f269e3021894 | 80 | print "Generated from configuration parameters:", Config.parameters_to_macros(params) |
elessair | 0:f269e3021894 | 81 | |
elessair | 0:f269e3021894 | 82 | except KeyboardInterrupt, e: |
elessair | 0:f269e3021894 | 83 | print "\n[CTRL+c] exit" |
elessair | 0:f269e3021894 | 84 | except Exception,e: |
elessair | 0:f269e3021894 | 85 | if options.verbose: |
elessair | 0:f269e3021894 | 86 | import traceback |
elessair | 0:f269e3021894 | 87 | traceback.print_exc(file=sys.stdout) |
elessair | 0:f269e3021894 | 88 | else: |
elessair | 0:f269e3021894 | 89 | print "[ERROR] %s" % str(e) |
elessair | 0:f269e3021894 | 90 | |
elessair | 0:f269e3021894 | 91 | sys.exit(1) |