5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
jacobjohnson
Date:
Mon Feb 27 17:45:05 2017 +0000
Revision:
1:f30bdcd2b33b
Parent:
0:098463de4c5d
changed the inputscale from 1 to 7 in analogin_api.c.  This will need to be changed later, and accessed from the main level, but for now this allows the  adc to read a value from 0 to 3.7V, instead of just up to 1V.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-onsemi 0:098463de4c5d 1 #! /usr/bin/env python
group-onsemi 0:098463de4c5d 2 """
group-onsemi 0:098463de4c5d 3 mbed SDK
group-onsemi 0:098463de4c5d 4 Copyright (c) 2011-2013 ARM Limited
group-onsemi 0:098463de4c5d 5
group-onsemi 0:098463de4c5d 6 Licensed under the Apache License, Version 2.0 (the "License");
group-onsemi 0:098463de4c5d 7 you may not use this file except in compliance with the License.
group-onsemi 0:098463de4c5d 8 You may obtain a copy of the License at
group-onsemi 0:098463de4c5d 9
group-onsemi 0:098463de4c5d 10 http://www.apache.org/licenses/LICENSE-2.0
group-onsemi 0:098463de4c5d 11
group-onsemi 0:098463de4c5d 12 Unless required by applicable law or agreed to in writing, software
group-onsemi 0:098463de4c5d 13 distributed under the License is distributed on an "AS IS" BASIS,
group-onsemi 0:098463de4c5d 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
group-onsemi 0:098463de4c5d 15 See the License for the specific language governing permissions and
group-onsemi 0:098463de4c5d 16 limitations under the License.
group-onsemi 0:098463de4c5d 17 """
group-onsemi 0:098463de4c5d 18 import sys
group-onsemi 0:098463de4c5d 19 from time import time
group-onsemi 0:098463de4c5d 20 from os.path import join, abspath, dirname, normpath
group-onsemi 0:098463de4c5d 21 from optparse import OptionParser
group-onsemi 0:098463de4c5d 22 import json
group-onsemi 0:098463de4c5d 23
group-onsemi 0:098463de4c5d 24 # Be sure that the tools directory is in the search path
group-onsemi 0:098463de4c5d 25 ROOT = abspath(join(dirname(__file__), ".."))
group-onsemi 0:098463de4c5d 26 sys.path.insert(0, ROOT)
group-onsemi 0:098463de4c5d 27
group-onsemi 0:098463de4c5d 28 from tools.build_api import build_library
group-onsemi 0:098463de4c5d 29 from tools.build_api import write_build_report
group-onsemi 0:098463de4c5d 30 from tools.targets import TARGET_MAP, TARGET_NAMES
group-onsemi 0:098463de4c5d 31 from tools.toolchains import TOOLCHAINS
group-onsemi 0:098463de4c5d 32 from tools.test_exporters import ReportExporter, ResultExporterType
group-onsemi 0:098463de4c5d 33 from tools.test_api import find_tests, build_tests, test_spec_from_test_builds
group-onsemi 0:098463de4c5d 34 from tools.build_release import OFFICIAL_MBED_LIBRARY_BUILD
group-onsemi 0:098463de4c5d 35
group-onsemi 0:098463de4c5d 36 if __name__ == '__main__':
group-onsemi 0:098463de4c5d 37 try:
group-onsemi 0:098463de4c5d 38 parser = OptionParser()
group-onsemi 0:098463de4c5d 39
group-onsemi 0:098463de4c5d 40 parser.add_option("--source", dest="source_dir",
group-onsemi 0:098463de4c5d 41 default=None, help="The source (input) directory (for sources other than tests). Defaults to current directory.", action="append")
group-onsemi 0:098463de4c5d 42
group-onsemi 0:098463de4c5d 43 parser.add_option("--build", dest="build_dir",
group-onsemi 0:098463de4c5d 44 default=None, help="The build (output) directory")
group-onsemi 0:098463de4c5d 45
group-onsemi 0:098463de4c5d 46 parser.add_option('-c', '--clean',
group-onsemi 0:098463de4c5d 47 dest='clean',
group-onsemi 0:098463de4c5d 48 metavar=False,
group-onsemi 0:098463de4c5d 49 action="store_true",
group-onsemi 0:098463de4c5d 50 help='Clean the build directory')
group-onsemi 0:098463de4c5d 51
group-onsemi 0:098463de4c5d 52 parser.add_option('-a', '--all', dest="all", default=False, action="store_true",
group-onsemi 0:098463de4c5d 53 help="Build every target (including unofficial targets) and with each of the supported toolchains")
group-onsemi 0:098463de4c5d 54
group-onsemi 0:098463de4c5d 55 parser.add_option('-o', '--official', dest="official_only", default=False, action="store_true",
group-onsemi 0:098463de4c5d 56 help="Build using only the official toolchain for each target")
group-onsemi 0:098463de4c5d 57
group-onsemi 0:098463de4c5d 58 parser.add_option("-D", "",
group-onsemi 0:098463de4c5d 59 action="append",
group-onsemi 0:098463de4c5d 60 dest="macros",
group-onsemi 0:098463de4c5d 61 help="Add a macro definition")
group-onsemi 0:098463de4c5d 62
group-onsemi 0:098463de4c5d 63 parser.add_option("-j", "--jobs", type="int", dest="jobs",
group-onsemi 0:098463de4c5d 64 default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
group-onsemi 0:098463de4c5d 65
group-onsemi 0:098463de4c5d 66 parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
group-onsemi 0:098463de4c5d 67 default=False, help="Verbose diagnostic output")
group-onsemi 0:098463de4c5d 68
group-onsemi 0:098463de4c5d 69 parser.add_option("-t", "--toolchains", dest="toolchains", help="Use toolchains names separated by comma")
group-onsemi 0:098463de4c5d 70
group-onsemi 0:098463de4c5d 71 parser.add_option("-p", "--platforms", dest="platforms", default="", help="Build only for the platform namesseparated by comma")
group-onsemi 0:098463de4c5d 72
group-onsemi 0:098463de4c5d 73 parser.add_option("", "--config", action="store_true", dest="list_config",
group-onsemi 0:098463de4c5d 74 default=False, help="List the platforms and toolchains in the release in JSON")
group-onsemi 0:098463de4c5d 75
group-onsemi 0:098463de4c5d 76 parser.add_option("", "--test-spec", dest="test_spec",
group-onsemi 0:098463de4c5d 77 default=None, help="Destination path for a test spec file that can be used by the Greentea automated test tool")
group-onsemi 0:098463de4c5d 78
group-onsemi 0:098463de4c5d 79 parser.add_option("", "--build-report-junit", dest="build_report_junit", help="Output the build results to an junit xml file")
group-onsemi 0:098463de4c5d 80
group-onsemi 0:098463de4c5d 81 parser.add_option("--continue-on-build-fail", action="store_true", dest="continue_on_build_fail",
group-onsemi 0:098463de4c5d 82 default=False, help="Continue trying to build all tests if a build failure occurs")
group-onsemi 0:098463de4c5d 83
group-onsemi 0:098463de4c5d 84 options, args = parser.parse_args()
group-onsemi 0:098463de4c5d 85
group-onsemi 0:098463de4c5d 86 # Get set of valid targets
group-onsemi 0:098463de4c5d 87 all_platforms = set(TARGET_NAMES)
group-onsemi 0:098463de4c5d 88 bad_platforms = set()
group-onsemi 0:098463de4c5d 89 platforms = set()
group-onsemi 0:098463de4c5d 90 if options.platforms != "":
group-onsemi 0:098463de4c5d 91 platforms = set(options.platforms.split(","))
group-onsemi 0:098463de4c5d 92 bad_platforms = platforms.difference(all_platforms)
group-onsemi 0:098463de4c5d 93 platforms = platforms.intersection(all_platforms)
group-onsemi 0:098463de4c5d 94 elif options.all:
group-onsemi 0:098463de4c5d 95 platforms = all_platforms
group-onsemi 0:098463de4c5d 96 else:
group-onsemi 0:098463de4c5d 97 platforms = set(x[0] for x in OFFICIAL_MBED_LIBRARY_BUILD)
group-onsemi 0:098463de4c5d 98 bad_platforms = platforms.difference(all_platforms)
group-onsemi 0:098463de4c5d 99 platforms = platforms.intersection(all_platforms)
group-onsemi 0:098463de4c5d 100
group-onsemi 0:098463de4c5d 101 for bad_platform in bad_platforms:
group-onsemi 0:098463de4c5d 102 print "Platform '%s' is not a valid platform. Skipping." % bad_platform
group-onsemi 0:098463de4c5d 103
group-onsemi 0:098463de4c5d 104 if options.platforms:
group-onsemi 0:098463de4c5d 105 print "Limiting build to the following platforms: %s" % ",".join(platforms)
group-onsemi 0:098463de4c5d 106
group-onsemi 0:098463de4c5d 107 # Get set of valid toolchains
group-onsemi 0:098463de4c5d 108 all_toolchains = set(TOOLCHAINS)
group-onsemi 0:098463de4c5d 109 bad_toolchains = set()
group-onsemi 0:098463de4c5d 110 toolchains = set()
group-onsemi 0:098463de4c5d 111
group-onsemi 0:098463de4c5d 112 if options.toolchains:
group-onsemi 0:098463de4c5d 113 toolchains = set(options.toolchains.split(","))
group-onsemi 0:098463de4c5d 114 bad_toolchains = toolchains.difference(all_toolchains)
group-onsemi 0:098463de4c5d 115 toolchains = toolchains.intersection(all_toolchains)
group-onsemi 0:098463de4c5d 116 else:
group-onsemi 0:098463de4c5d 117 toolchains = all_toolchains
group-onsemi 0:098463de4c5d 118
group-onsemi 0:098463de4c5d 119 for bad_toolchain in bad_toolchains:
group-onsemi 0:098463de4c5d 120 print "Toolchain '%s' is not a valid toolchain. Skipping." % bad_toolchain
group-onsemi 0:098463de4c5d 121
group-onsemi 0:098463de4c5d 122 if options.toolchains:
group-onsemi 0:098463de4c5d 123 print "Limiting build to the following toolchains: %s" % ",".join(toolchains)
group-onsemi 0:098463de4c5d 124
group-onsemi 0:098463de4c5d 125 build_config = {}
group-onsemi 0:098463de4c5d 126
group-onsemi 0:098463de4c5d 127 for platform in platforms:
group-onsemi 0:098463de4c5d 128 target = TARGET_MAP[platform]
group-onsemi 0:098463de4c5d 129
group-onsemi 0:098463de4c5d 130 if options.official_only:
group-onsemi 0:098463de4c5d 131 default_toolchain = getattr(target, 'default_toolchain', 'ARM')
group-onsemi 0:098463de4c5d 132 build_config[platform] = list(toolchains.intersection(set([default_toolchain])))
group-onsemi 0:098463de4c5d 133 else:
group-onsemi 0:098463de4c5d 134 build_config[platform] = list(toolchains.intersection(set(target.supported_toolchains)))
group-onsemi 0:098463de4c5d 135
group-onsemi 0:098463de4c5d 136 if options.list_config:
group-onsemi 0:098463de4c5d 137 print json.dumps(build_config, indent=4)
group-onsemi 0:098463de4c5d 138 sys.exit(0)
group-onsemi 0:098463de4c5d 139
group-onsemi 0:098463de4c5d 140 # Ensure build directory is set
group-onsemi 0:098463de4c5d 141 if not options.build_dir:
group-onsemi 0:098463de4c5d 142 print "[ERROR] You must specify a build path"
group-onsemi 0:098463de4c5d 143 sys.exit(1)
group-onsemi 0:098463de4c5d 144
group-onsemi 0:098463de4c5d 145 # Default base source path is the current directory
group-onsemi 0:098463de4c5d 146 base_source_paths = options.source_dir
group-onsemi 0:098463de4c5d 147 if not base_source_paths:
group-onsemi 0:098463de4c5d 148 base_source_paths = ['.']
group-onsemi 0:098463de4c5d 149
group-onsemi 0:098463de4c5d 150
group-onsemi 0:098463de4c5d 151 start = time()
group-onsemi 0:098463de4c5d 152 build_report = {}
group-onsemi 0:098463de4c5d 153 build_properties = {}
group-onsemi 0:098463de4c5d 154 test_builds = {}
group-onsemi 0:098463de4c5d 155 total_build_success = True
group-onsemi 0:098463de4c5d 156
group-onsemi 0:098463de4c5d 157 for target_name, target_toolchains in build_config.iteritems():
group-onsemi 0:098463de4c5d 158 target = TARGET_MAP[target_name]
group-onsemi 0:098463de4c5d 159
group-onsemi 0:098463de4c5d 160 for target_toolchain in target_toolchains:
group-onsemi 0:098463de4c5d 161 library_build_success = True
group-onsemi 0:098463de4c5d 162
group-onsemi 0:098463de4c5d 163 try:
group-onsemi 0:098463de4c5d 164 build_directory = join(options.build_dir, target_name, target_toolchain)
group-onsemi 0:098463de4c5d 165 # Build sources
group-onsemi 0:098463de4c5d 166 build_library(base_source_paths, build_directory, target, target_toolchain,
group-onsemi 0:098463de4c5d 167 jobs=options.jobs,
group-onsemi 0:098463de4c5d 168 clean=options.clean,
group-onsemi 0:098463de4c5d 169 report=build_report,
group-onsemi 0:098463de4c5d 170 properties=build_properties,
group-onsemi 0:098463de4c5d 171 name="mbed-os",
group-onsemi 0:098463de4c5d 172 macros=options.macros,
group-onsemi 0:098463de4c5d 173 verbose=options.verbose,
group-onsemi 0:098463de4c5d 174 archive=False)
group-onsemi 0:098463de4c5d 175 except Exception, e:
group-onsemi 0:098463de4c5d 176 library_build_success = False
group-onsemi 0:098463de4c5d 177 print "Failed to build library"
group-onsemi 0:098463de4c5d 178 print e
group-onsemi 0:098463de4c5d 179
group-onsemi 0:098463de4c5d 180 if options.continue_on_build_fail or library_build_success:
group-onsemi 0:098463de4c5d 181 # Build all the tests
group-onsemi 0:098463de4c5d 182 all_tests = find_tests(base_source_paths[0], target_name, toolchain_name)
group-onsemi 0:098463de4c5d 183 test_build_success, test_build = build_tests(all_tests, [build_directory], build_directory, target, target_toolchain,
group-onsemi 0:098463de4c5d 184 clean=options.clean,
group-onsemi 0:098463de4c5d 185 report=build_report,
group-onsemi 0:098463de4c5d 186 properties=build_properties,
group-onsemi 0:098463de4c5d 187 macros=options.macros,
group-onsemi 0:098463de4c5d 188 verbose=options.verbose,
group-onsemi 0:098463de4c5d 189 jobs=options.jobs,
group-onsemi 0:098463de4c5d 190 continue_on_build_fail=options.continue_on_build_fail)
group-onsemi 0:098463de4c5d 191
group-onsemi 0:098463de4c5d 192 if not test_build_success:
group-onsemi 0:098463de4c5d 193 total_build_success = False
group-onsemi 0:098463de4c5d 194 print "Failed to build some tests, check build log for details"
group-onsemi 0:098463de4c5d 195
group-onsemi 0:098463de4c5d 196 test_builds.update(test_build)
group-onsemi 0:098463de4c5d 197 else:
group-onsemi 0:098463de4c5d 198 total_build_success = False
group-onsemi 0:098463de4c5d 199 break
group-onsemi 0:098463de4c5d 200
group-onsemi 0:098463de4c5d 201 # If a path to a test spec is provided, write it to a file
group-onsemi 0:098463de4c5d 202 if options.test_spec:
group-onsemi 0:098463de4c5d 203 test_spec_data = test_spec_from_test_builds(test_builds)
group-onsemi 0:098463de4c5d 204
group-onsemi 0:098463de4c5d 205 # Create the target dir for the test spec if necessary
group-onsemi 0:098463de4c5d 206 # mkdir will not create the dir if it already exists
group-onsemi 0:098463de4c5d 207 test_spec_dir = dirname(options.test_spec)
group-onsemi 0:098463de4c5d 208 if test_spec_dir:
group-onsemi 0:098463de4c5d 209 mkdir(test_spec_dir)
group-onsemi 0:098463de4c5d 210
group-onsemi 0:098463de4c5d 211 try:
group-onsemi 0:098463de4c5d 212 with open(options.test_spec, 'w') as f:
group-onsemi 0:098463de4c5d 213 f.write(json.dumps(test_spec_data, indent=2))
group-onsemi 0:098463de4c5d 214 except IOError, e:
group-onsemi 0:098463de4c5d 215 print "[ERROR] Error writing test spec to file"
group-onsemi 0:098463de4c5d 216 print e
group-onsemi 0:098463de4c5d 217
group-onsemi 0:098463de4c5d 218 # If a path to a JUnit build report spec is provided, write it to a file
group-onsemi 0:098463de4c5d 219 if options.build_report_junit:
group-onsemi 0:098463de4c5d 220 report_exporter = ReportExporter(ResultExporterType.JUNIT)
group-onsemi 0:098463de4c5d 221 report_exporter.report_to_file(build_report, options.build_report_junit, test_suite_properties=build_properties)
group-onsemi 0:098463de4c5d 222
group-onsemi 0:098463de4c5d 223 print "\n\nCompleted in: (%.2f)s" % (time() - start)
group-onsemi 0:098463de4c5d 224
group-onsemi 0:098463de4c5d 225 print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build")
group-onsemi 0:098463de4c5d 226 status = print_report_exporter.report(build_report)
group-onsemi 0:098463de4c5d 227
group-onsemi 0:098463de4c5d 228 if status:
group-onsemi 0:098463de4c5d 229 sys.exit(0)
group-onsemi 0:098463de4c5d 230 else:
group-onsemi 0:098463de4c5d 231 sys.exit(1)
group-onsemi 0:098463de4c5d 232
group-onsemi 0:098463de4c5d 233 except KeyboardInterrupt, e:
group-onsemi 0:098463de4c5d 234 print "\n[CTRL+c] exit"
group-onsemi 0:098463de4c5d 235 except Exception,e:
group-onsemi 0:098463de4c5d 236 import traceback
group-onsemi 0:098463de4c5d 237 traceback.print_exc(file=sys.stdout)
group-onsemi 0:098463de4c5d 238 print "[ERROR] %s" % str(e)
group-onsemi 0:098463de4c5d 239 sys.exit(1)