def fill_project_envs(project_file, board_types, disable_auto_uploading): builtin_boards = get_boards() content = [] for type_ in board_types: if type_ not in builtin_boards: continue else: content.append("") data = builtin_boards[type_] framework = data.get("build", {}).get("core", None) if framework in ("msp430", "lm4f"): framework = "energia" content.append("[env:autogen_%s]" % type_) content.append("platform = %s" % data['platform']) if framework: content.append("framework = %s" % framework) content.append("board = %s" % type_) content.append("%stargets = upload" % ("# " if disable_auto_uploading else "")) with open(project_file, "a") as f: f.write("\n".join(content))
def generate_framework(type_, data): print "Processing framework: %s" % type_ lines = [] lines.append(".. _framework_%s:" % type_) lines.append("") _title = "Framework ``%s``" % type_ lines.append(_title) lines.append("=" * len(_title)) lines.append(data['description']) lines.append(""" For more detailed information please visit `vendor site <%s>`_. """ % data['url']) lines.append(".. contents::") lines.append(""" Platforms --------- .. list-table:: :header-rows: 1 * - Name - Description""") for platform in sorted(PlatformFactory.get_platforms().keys()): if not is_compat_platform_and_framework(platform, type_): continue p = PlatformFactory.newPlatform(platform) lines.append(""" * - :ref:`platform_{type_}` - {description}""".format( type_=platform, description=p.get_description())) lines.append(""" Boards ------ .. note:: * You can list pre-configured boards by :ref:`cmd_boards` command or `PlatformIO Boards Explorer <http://platformio.org/#!/boards>`_ * For more detailed ``board`` information please scroll tables below by horizontal. """) vendors = {} for board, data in util.get_boards().items(): frameworks = data['frameworks'] vendor = data['vendor'] if type_ in frameworks: if vendor in vendors: vendors[vendor].append({board: data}) else: vendors[vendor] = [{board: data}] for vendor, boards in sorted(vendors.iteritems()): lines.append(str(vendor)) lines.append("~" * len(vendor)) lines.append(generate_boards(boards)) return "\n".join(lines)
def validate_boards(ctx, param, value): # pylint: disable=W0613 unknown_boards = set(value) - set(get_boards().keys()) try: assert not unknown_boards return value except AssertionError: raise click.BadParameter( "%s. Please search for the board types using " "`platformio boards` command" % ", ".join(unknown_boards))
def ouput_boards_json(query): result = {} for type_, data in get_boards().items(): if query: search_data = "%s %s" % (type_, json.dumps(data).lower()) if query.lower() not in search_data.lower(): continue result[type_] = data click.echo(json.dumps(result))
def cli(query, json_output): # pylint: disable=R0912 if json_output: return ouput_boards_json(query) BOARDLIST_TPL = ("{type:<30} {mcu:<14} {frequency:<8} " " {flash:<7} {ram:<6} {name}") terminal_width, _ = click.get_terminal_size() grpboards = {} for type_, data in get_boards().items(): if data['platform'] not in grpboards: grpboards[data['platform']] = {} grpboards[data['platform']][type_] = data for (platform, boards) in sorted(grpboards.items()): if query: search_data = json.dumps(boards).lower() if query.lower() not in search_data.lower(): continue click.echo("") click.echo("Platform: ", nl=False) click.secho(platform, bold=True) click.echo("-" * terminal_width) click.echo(BOARDLIST_TPL.format( type=click.style("Type", fg="cyan"), mcu="MCU", frequency="Frequency", flash="Flash", ram="RAM", name="Name")) click.echo("-" * terminal_width) for type_, data in sorted(boards.items(), key=lambda b: b[1]['name']): if query: search_data = "%s %s" % (type_, json.dumps(data).lower()) if query.lower() not in search_data.lower(): continue flash_size = "" if "maximum_size" in data.get("upload", None): flash_size = int(data['upload']['maximum_size']) flash_size = "%dKb" % (flash_size / 1024) ram_size = "" if "maximum_ram_size" in data.get("upload", None): ram_size = int(data['upload']['maximum_ram_size']) if ram_size >= 1024: if ram_size % 1024: ram_size = "%.1fKb" % (ram_size / 1024.0) else: ram_size = "%dKb" % (ram_size / 1024) else: ram_size = "%dB" % ram_size click.echo(BOARDLIST_TPL.format( type=click.style(type_, fg="cyan"), mcu=data['build']['mcu'], frequency="%dMhz" % ( int(data['build']['f_cpu'][:-1]) / 1000000), flash=flash_size, ram=ram_size, name=data['name']))
def validate_boards(ctx, param, value): # pylint: disable=W0613 unknown_boards = set(value) - set(get_boards().keys()) try: assert not unknown_boards return value except AssertionError: raise click.BadParameter("%s. Please search for the board types using " "`platformio boards` command" % ", ".join(unknown_boards))
def test_board_ldscripts(platformio_setup, clirunner, validate_cliresult): result = clirunner.invoke( install_cli, ["ststm32", "--skip-default-package", "--with-package=ldscripts"]) validate_cliresult(result) ldscripts_path = join(util.get_home_dir(), "packages", "ldscripts") for _, opts in util.get_boards().iteritems(): if opts['build'].get("ldscript"): assert isfile(join(ldscripts_path, opts['build'].get("ldscript")))
def test_board_ldscripts(platformio_setup, clirunner, validate_cliresult): result = clirunner.invoke(cmd_platforms_install, ["ststm32", "--skip-default-package", "--with-package=ldscripts"]) validate_cliresult(result) ldscripts_path = join(util.get_home_dir(), "packages", "ldscripts") for _, opts in util.get_boards().iteritems(): if opts["build"].get("ldscript"): if "libopencm3" in opts["frameworks"]: continue assert isfile(join(ldscripts_path, opts["build"].get("ldscript")))
def configure_default_packages(self, envoptions, targets): if envoptions.get("board"): board = get_boards(envoptions.get("board")) disable_tool = "tool-micronucleus" if "digispark" in board['build']['core']: disable_tool = "tool-avrdude" del self.PACKAGES[disable_tool]['alias'] return BasePlatform.configure_default_packages(self, envoptions, targets)
def configure_default_packages(self, envoptions, targets): if envoptions.get("board"): board = get_boards(envoptions.get("board")) if "digispark" in board['build']['core']: self.PACKAGES['tool-micronucleus']['alias'] = "uploader" else: self.PACKAGES['tool-avrdude']['alias'] = "uploader" return BasePlatform.configure_default_packages( self, envoptions, targets)
def configure_default_packages(self, envoptions, targets): if envoptions.get("board"): board = get_boards(envoptions.get("board")) disable_tool = "tool-micronucleus" if "digispark" in board['build']['core']: disable_tool = "tool-avrdude" del self.PACKAGES[disable_tool]['alias'] return BasePlatform.configure_default_packages( self, envoptions, targets)
def configure_default_packages(self, envoptions, targets): if envoptions.get("board"): board = get_boards(envoptions.get("board")) if "digispark" in board['build']['core']: self.PACKAGES['tool-micronucleus']['alias'] = "uploader" else: self.PACKAGES['tool-avrdude']['alias'] = "uploader" return BasePlatform.configure_default_packages(self, envoptions, targets)
def configure_default_packages(self, envoptions, targets): if envoptions.get("board"): board = get_boards(envoptions.get("board")) if board['build']['core'] == "teensy": name = "toolchain-atmelavr" else: name = "toolchain-gccarmnoneeabi" self.PACKAGES[name]['alias'] = "toolchain" self.PACKAGES[name]['default'] = True return BasePlatform.configure_default_packages(self, envoptions, targets)
def run(self, variables, targets, verbose): for v in variables: if "BOARD=" not in v: continue disable_tool = "tool-micronucleus" _, board = v.split("=") bdata = get_boards(board) if "digispark" in bdata['build']['core']: disable_tool = "tool-avrdude" del self.PACKAGES[disable_tool]['alias'] break return BasePlatform.run(self, variables, targets, verbose)
def configure_default_packages(self, envoptions, targets): if envoptions.get("board"): board = get_boards(envoptions.get("board")) if board['build']['core'] == "teensy": name = "toolchain-atmelavr" else: name = "toolchain-gccarmnoneeabi" self.PACKAGES[name]['alias'] = "toolchain" self.PACKAGES[name]['default'] = True return BasePlatform.configure_default_packages( self, envoptions, targets)
def run(self, variables, targets): for v in variables: if "BOARD=" not in v: continue tuploader = "tool-avrdude" _, board = v.split("=") bdata = get_boards(board) if "digispark" in bdata['build']['core']: tuploader = "tool-micronucleus" self.PACKAGES[tuploader]['alias'] = "uploader" break return BasePlatform.run(self, variables, targets)
def update_embedded_boards(): lines = [] lines.append(""".. Copyright 2014-present Ivan Kravets <*****@*****.**> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """) lines.append(".. _embedded_boards:") lines.append("") lines.append("Embedded Boards") lines.append("===============") lines.append(""" Rapid Embedded Development, Continuous and IDE integration in a few steps with PlatformIO thanks to built-in project generator for the most popular embedded boards and IDE. * You can list pre-configured boards using :ref:`cmd_boards` command or `PlatformIO Boards Explorer <http://platformio.org/boards>`_ * For more detailed ``board`` information please scroll tables below by horizontal. """) lines.append(".. contents::") lines.append("") vendors = {} for board, data in util.get_boards().items(): vendor = data['vendor'] if vendor in vendors: vendors[vendor].append({board: data}) else: vendors[vendor] = [{board: data}] for vendor, boards in sorted(vendors.iteritems()): lines.append(str(vendor)) lines.append("~" * len(vendor)) lines.append(generate_boards(boards)) emboards_rst = join(dirname(realpath(__file__)), "..", "docs", "platforms", "embedded_boards.rst") with open(emboards_rst, "w") as f: f.write("\n".join(lines))
def run(self, variables, targets): for v in variables: if "BOARD=" not in v: continue _, board = v.split("=") bdata = get_boards(board) if bdata['build']['core'] == "teensy": tpackage = "toolchain-atmelavr" else: tpackage = "toolchain-gccarmnoneeabi" self.PACKAGES[tpackage]['alias'] = "toolchain" break return BasePlatform.run(self, variables, targets)
def run(self, variables, targets, verbose): for v in variables: if "BOARD=" not in v: continue _, board = v.split("=") bdata = get_boards(board) if bdata['build']['core'] == "teensy": tpackage = "toolchain-atmelavr" else: tpackage = "toolchain-gccarmnoneeabi" self.PACKAGES[tpackage]['alias'] = "toolchain" break return BasePlatform.run(self, variables, targets, verbose)
def test_board_ldscripts(platformio_setup, clirunner, validate_cliresult): result = clirunner.invoke( cmd_platforms_install, ["ststm32", "--skip-default-package", "--with-package=ldscripts"]) validate_cliresult(result) ldscripts_path = join(util.get_home_dir(), "packages", "ldscripts") for type_, opts in util.get_boards().iteritems(): if opts['build'].get("ldscript"): frameworks = opts['frameworks'] if (any(fw in frameworks for fw in ["libopencm3", "mbed"]) or type_ in ("rfduino", )): continue assert isfile(join(ldscripts_path, opts['build'].get("ldscript")))
def test_board_options(platformio_setup, clirunner, validate_cliresult): required_opts = set(["build", "platform", "upload", "name"]) # fetch available platforms result = clirunner.invoke(cmd_platforms_search, ["--json-output"]) validate_cliresult(result) search_result = json.loads(result.output) assert isinstance(search_result, list) assert len(search_result) platforms = [item["type"] for item in search_result] for _, opts in util.get_boards().iteritems(): assert required_opts.issubset(set(opts)) assert opts["platform"] in platforms
def test_board_options(platformio_setup, clirunner, validate_cliresult): required_opts = set(["build", "platform", "upload", "name"]) # fetch available platforms result = clirunner.invoke(cmd_platforms_search, ["--json-output"]) validate_cliresult(result) search_result = json.loads(result.output) assert isinstance(search_result, list) assert len(search_result) platforms = [item['type'] for item in search_result] for _, opts in util.get_boards().iteritems(): assert required_opts.issubset(set(opts)) assert opts['platform'] in platforms
def cli(query): BOARDLIST_TPL = ("{type:<30} {mcu:<13} {frequency:<8} " " {flash:<7} {ram:<6} {name}") grpboards = {} for type_, data in get_boards().items(): if data['platform'] not in grpboards: grpboards[data['platform']] = {} grpboards[data['platform']][type_] = data for (platform, boards) in grpboards.items(): if query: search_data = json.dumps(boards).lower() if query.lower() not in search_data.lower(): continue click.echo("\nPlatform: %s" % platform) click.echo("-" * 75) click.echo(BOARDLIST_TPL.format( type=click.style("Type", fg="cyan"), mcu="MCU", frequency="Frequency", flash="Flash", ram="RAM", name="Name")) click.echo("-" * 75) for type_, data in sorted(boards.items(), key=lambda b: b[1]['name']): if query: search_data = "%s %s" % (type_, json.dumps(data).lower()) if query.lower() not in search_data.lower(): continue flash_size = "" if "maximum_size" in data.get("upload", None): flash_size = int(data['upload']['maximum_size']) flash_size = "%dKb" % (flash_size / 1024) ram_size = "" if "maximum_ram_size" in data.get("upload", None): ram_size = int(data['upload']['maximum_ram_size']) if ram_size >= 1024: ram_size = "%dKb" % (ram_size / 1024) else: ram_size = "%dB" % ram_size click.echo(BOARDLIST_TPL.format( type=click.style(type_, fg="cyan"), mcu=data['build']['mcu'], frequency="%dMhz" % (int(data['build']['f_cpu'][:-1]) / 1000000), flash=flash_size, ram=ram_size, name=data['name']))
def test_board_ldscripts(platformio_setup, clirunner, validate_cliresult): result = clirunner.invoke( cmd_platforms_install, [ "ststm32", "--skip-default-package", "--with-package=ldscripts" ]) validate_cliresult(result) ldscripts_path = join(util.get_home_dir(), "packages", "ldscripts") for type_, opts in util.get_boards().iteritems(): if opts['build'].get("ldscript"): frameworks = opts['frameworks'] if (any(fw in frameworks for fw in ["libopencm3", "mbed"]) or type_ in ("rfduino", )): continue assert isfile(join(ldscripts_path, opts['build'].get("ldscript")))
def test_init_special_board(platformio_setup, clirunner, validate_cliresult): with clirunner.isolated_filesystem(): result = clirunner.invoke(cli, ["-b", "uno"]) validate_cliresult(result) validate_pioproject(getcwd()) uno = util.get_boards("uno") config = util.get_project_config() expected_result = [("platform", str(uno['platform'])), ("framework", str(uno['frameworks'][0])), ("board", "uno"), ("targets", "upload")] assert config.has_section("env:autogen_uno") assert len( set(expected_result).symmetric_difference( set(config.items("env:autogen_uno")))) == 0
def generate_boards(boards): def _round_memory_size(size): if size == 1: return 1 size = ceil(size) for b in (64, 32, 16, 8, 4, 2, 1): if b < size: return int(ceil(size / b) * b) assert NotImplemented() lines = [] lines.append(""" .. list-table:: :header-rows: 1 * - Type ``board`` - Name - Microcontroller - Frequency - Flash - RAM""") for board in sorted(boards): for type_, data in board.iteritems(): assert type_ in util.get_boards() board_ram = float(data['upload']['maximum_ram_size']) / 1024 lines.append(""" * - ``{type}`` - `{name} <{url}>`_ - {mcu} - {f_cpu:d} MHz - {rom} Kb - {ram} Kb""".format( type=type_, name=data['name'], url=data['url'], mcu=data['build']['mcu'].upper(), f_cpu=int((data['build']['f_cpu'][:-1])) / 1000000, ram=int(board_ram) if board_ram % 1 == 0 else board_ram, rom=_round_memory_size( data['upload']['maximum_size'] / 1024) )) return "\n".join(lines + [""])
def generate_boards(boards): def _round_memory_size(size): if size == 1: return 1; size = ceil(size) for b in (64, 32, 16, 8, 4, 2, 1): if b < size: return int(ceil(size / b) * b) assert NotImplemented() lines = [] lines.append(""" .. list-table:: :header-rows: 1 * - Type ``board`` - Name - Microcontroller - Frequency - Flash - RAM""") for board in sorted(boards): for type_, data in board.iteritems(): assert type_ in util.get_boards() board_ram = float(data['upload']['maximum_ram_size']) / 1024 lines.append(""" * - ``{type}`` - `{name} <{url}>`_ - {mcu} - {f_cpu:d} MHz - {rom} Kb - {ram} Kb""".format( type=type_, name=data['name'], url=data['url'], mcu=data['build']['mcu'].upper(), f_cpu=int((data['build']['f_cpu'][:-1])) / 1000000, ram=int(board_ram) if board_ram % 1 == 0 else board_ram, rom=_round_memory_size( data['upload']['maximum_size'] / 1024) )) return "\n".join(lines + [""])
def configure_default_packages(self, envoptions, targets): if envoptions.get("board"): board = get_boards(envoptions.get("board")) upload_protocol = board.get("upload", {}).get("protocol", None) upload_tool = None if upload_protocol == "openocd": upload_tool = "tool-openocd" elif upload_protocol == "sam-ba": upload_tool = "tool-bossac" elif upload_protocol == "stk500v2": upload_tool = "tool-avrdude" if upload_tool: self.PACKAGES[upload_tool]['alias'] = "uploader" return BasePlatform.configure_default_packages(self, envoptions, targets)
def test_init_special_board(platformio_setup, clirunner, validate_cliresult): with clirunner.isolated_filesystem(): result = clirunner.invoke(cli, ["-b", "uno"]) validate_cliresult(result) validate_pioproject(getcwd()) uno = util.get_boards("uno") config = util.get_project_config() expected_result = [ ("platform", str(uno['platform'])), ("framework", str(uno['frameworks'][0])), ("board", "uno") ] assert config.has_section("env:uno") assert len(set(expected_result).symmetric_difference( set(config.items("env:uno")))) == 0
def configure_default_packages(self, envoptions, targets): if envoptions.get("board"): board = get_boards(envoptions.get("board")) upload_protocol = board.get("upload", {}).get("protocol", None) upload_tool = None if upload_protocol == "openocd": upload_tool = "tool-openocd" elif upload_protocol == "sam-ba": upload_tool = "tool-bossac" elif upload_protocol == "stk500v2": upload_tool = "tool-avrdude" if upload_tool: self.PACKAGES[upload_tool]['alias'] = "uploader" return BasePlatform.configure_default_packages( self, envoptions, targets)
def cli(project_dir, board, disable_auto_uploading): project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") if all([isfile(project_file), isdir(src_dir), isdir(lib_dir)]): raise ProjectInitialized() builtin_boards = set(get_boards().keys()) if board and not set(board).issubset(builtin_boards): raise UnknownBoard(", ".join(set(board).difference(builtin_boards))) if project_dir == getcwd(): click.secho("The current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho( "will be used for the new project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.\n", fg="yellow") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File" % click.style("platformio.ini", fg="cyan")) click.echo("%s - a source directory. Put your source code here" % click.style("src", fg="cyan")) click.echo("%s - a directory for the project specific libraries" % click.style("lib", fg="cyan")) if (not app.get_setting("enable_prompts") or click.confirm("Do you want to continue?")): for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs(project_file, board, disable_auto_uploading) click.secho( "Project has been successfully initialized!\n" "Now you can process it with `platformio run` command.", fg="green") else: click.secho("Aborted by user", fg="red")
def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals ctx, platformio_ini, board_types, enable_auto_uploading, env_prefix, force_download): builtin_boards = get_boards() content = [] used_boards = [] used_platforms = [] config = util.get_project_config(platformio_ini) for section in config.sections(): if not all( [section.startswith("env:"), config.has_option(section, "board")]): continue used_boards.append(config.get(section, "board")) for type_ in board_types: data = builtin_boards[type_] used_platforms.append(data['platform']) if type_ in used_boards: continue content.append("") content.append("[env:%s%s]" % (env_prefix, type_)) content.append("platform = %s" % data['platform']) # find default framework for board frameworks = data.get("frameworks") if frameworks: content.append("framework = %s" % frameworks[0]) content.append("board = %s" % type_) if enable_auto_uploading: content.append("targets = upload") if force_download and used_platforms: _install_dependent_platforms(ctx, used_platforms) if not content: return with open(platformio_ini, "a") as f: content.append("") f.write("\n".join(content))
def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals ctx, platformio_ini, board_types, enable_auto_uploading, env_prefix, force_download): builtin_boards = util.get_boards() content = [] used_boards = [] used_platforms = [] config = util.get_project_config(platformio_ini) for section in config.sections(): if not all([section.startswith("env:"), config.has_option(section, "board")]): continue used_boards.append(config.get(section, "board")) for type_ in board_types: data = builtin_boards[type_] used_platforms.append(data['platform']) if type_ in used_boards: continue content.append("") content.append("[env:%s%s]" % (env_prefix, type_)) content.append("platform = %s" % data['platform']) # find default framework for board frameworks = data.get("frameworks") if frameworks: content.append("framework = %s" % frameworks[0]) content.append("board = %s" % type_) if enable_auto_uploading: content.append("targets = upload") if force_download and used_platforms: _install_dependent_platforms(ctx, used_platforms) if not content: return with open(platformio_ini, "a") as f: content.append("") f.write("\n".join(content))
def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals ctx, platformio_ini, board_types, enable_auto_uploading, env_prefix, force_download): builtin_boards = get_boards() content = [] used_envs = [] used_platforms = [] with open(platformio_ini) as f: used_envs = [ l.strip() for l in f.read().splitlines() if l.strip().startswith("[env:") ] for type_ in board_types: data = builtin_boards[type_] used_platforms.append(data['platform']) env_name = "[env:%s%s]" % (env_prefix, type_) if env_name in used_envs: continue content.append("") content.append(env_name) content.append("platform = %s" % data['platform']) # find default framework for board frameworks = data.get("frameworks") if frameworks: content.append("framework = %s" % frameworks[0]) content.append("board = %s" % type_) if enable_auto_uploading: content.append("targets = upload") if force_download and used_platforms: _install_dependent_platforms(ctx, used_platforms) if not content: return with open(platformio_ini, "a") as f: content.append("") f.write("\n".join(content))
def fill_project_envs(ctx, project_file, board_types, disable_auto_uploading, env_prefix): builtin_boards = get_boards() content = [] used_envs = [] used_platforms = [] with open(project_file) as f: used_envs = [ l.strip() for l in f.read().splitlines() if l.strip().startswith("[env:") ] for type_ in board_types: data = builtin_boards[type_] used_platforms.append(data['platform']) env_name = "[env:%s%s]" % (env_prefix, type_) if env_name in used_envs: continue content.append("") content.append(env_name) content.append("platform = %s" % data['platform']) # find default framework for board frameworks = data.get("frameworks") if frameworks: content.append("framework = %s" % frameworks[0]) content.append("board = %s" % type_) content.append("%stargets = upload" % ("# " if disable_auto_uploading else "")) _install_dependent_platforms(ctx, used_platforms) if not content: return with open(project_file, "a") as f: content.append("") f.write("\n".join(content))
def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals ctx, project_file, board_types, enable_auto_uploading, env_prefix, force_download): builtin_boards = get_boards() content = [] used_envs = [] used_platforms = [] with open(project_file) as f: used_envs = [l.strip() for l in f.read().splitlines() if l.strip().startswith("[env:")] for type_ in board_types: data = builtin_boards[type_] used_platforms.append(data['platform']) env_name = "[env:%s%s]" % (env_prefix, type_) if env_name in used_envs: continue content.append("") content.append(env_name) content.append("platform = %s" % data['platform']) # find default framework for board frameworks = data.get("frameworks") if frameworks: content.append("framework = %s" % frameworks[0]) content.append("board = %s" % type_) if enable_auto_uploading: content.append("targets = upload") if force_download and used_platforms: _install_dependent_platforms(ctx, used_platforms) if not content: return with open(project_file, "a") as f: content.append("") f.write("\n".join(content))
def fill_project_envs(project_file, board_types, disable_auto_uploading): builtin_boards = get_boards() content = [] for type_ in board_types: if type_ not in builtin_boards: continue else: content.append("") data = builtin_boards[type_] # find default framework for board frameworks = data.get("frameworks") content.append("[env:autogen_%s]" % type_) content.append("platform = %s" % data['platform']) if frameworks: content.append("framework = %s" % frameworks[0]) content.append("board = %s" % type_) content.append("%stargets = upload" % ("# " if disable_auto_uploading else "")) with open(project_file, "a") as f: f.write("\n".join(content))
def fill_project_envs(project_file, board_types, disable_auto_uploading, env_prefix): builtin_boards = get_boards() content = [] used_envs = [] with open(project_file) as f: used_envs = [l.strip() for l in f.read().splitlines() if l.strip().startswith("[env:")] for type_ in board_types: data = builtin_boards[type_] env_name = "[env:%s%s]" % (env_prefix, type_) if env_name in used_envs: continue content.append("") content.append(env_name) content.append("platform = %s" % data['platform']) # find default framework for board frameworks = data.get("frameworks") if frameworks: content.append("framework = %s" % frameworks[0]) content.append("board = %s" % type_) content.append("%stargets = upload" % ("# " if disable_auto_uploading else "")) if not content: return with open(project_file, "a") as f: content.append("") f.write("\n".join(content))
def _get_build_options(board): """ :type board: str """ with util.cd(pm.PLATFORMIO_WORKSPACE_PATH): config = util.get_project_config() if not config.sections(): raise exception.ProjectEnvsNotAvailable() known = set([s[4:] for s in config.sections() if s.startswith("env:")]) unknown = set((board,)) - known if unknown: return None for section in config.sections(): envName = section[4:] if board and envName and envName == board: build_options = {k: v for k, v in config.items(section)} build_options["boardData"] = get_boards(build_options["board"]) return build_options raise CompilerException(ERROR_BOARD_NOT_SUPPORTED, board)
def cli(project_dir, board, disable_auto_uploading): project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") if all([isfile(project_file), isdir(src_dir), isdir(lib_dir)]): raise exception.ProjectInitialized() builtin_boards = set(get_boards().keys()) if board and not set(board).issubset(builtin_boards): raise exception.UnknownBoard(", ".join( set(board).difference(builtin_boards))) # ask about auto-uploading if board and app.get_setting("enable_prompts"): disable_auto_uploading = not click.confirm( "\nWould you like to enable firmware auto-uploading when project " "is successfully built using `platformio run` command? \n" "Don't forget that you can upload firmware manually using " "`platformio run --target upload` command.") if project_dir == getcwd(): click.secho("\nThe current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho( "will be used for the new project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.\n", fg="yellow") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" % click.style("platformio.ini", fg="cyan")) click.echo("%s - Put your source code here" % click.style("src", fg="cyan")) click.echo("%s - Put here project specific or 3-rd party libraries" % click.style("lib", fg="cyan")) if (not app.get_setting("enable_prompts") or click.confirm("Do you want to continue?")): for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs(project_file, board, disable_auto_uploading) click.secho( "Project has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " "directory\n" "`platformio run --target upload` or `platformio run -t upload` " "- upload firmware to embedded board\n" "`platformio run --target clean` - clean project (remove compiled " "files)", fg="green") else: raise exception.AbortedByUser()
def generate_platform(name): print "Processing platform: %s" % name lines = [] lines.append(""".. Copyright 2014-2015 Ivan Kravets <*****@*****.**> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """) lines.append(".. _platform_%s:" % name) lines.append("") _title = "Platform ``%s``" % name lines.append(_title) lines.append("=" * len(_title)) p = PlatformFactory.newPlatform(name) lines.append(p.get_description()) lines.append(""" For more detailed information please visit `vendor site <%s>`_.""" % p.get_vendor_url()) lines.append(""" .. contents::""") # # Packages # _packages_content = generate_packages(p.get_packages(), p.is_embedded()) if _packages_content: lines.append(_packages_content) # # Frameworks # _frameworks = util.get_frameworks() _frameworks_lines = [] for framework in sorted(_frameworks.keys()): if not is_compat_platform_and_framework(name, framework): continue _frameworks_lines.append(""" * - :ref:`framework_{type_}` - {description}""".format( type_=framework, description=_frameworks[framework]['description'])) if _frameworks_lines: lines.append(""" Frameworks ---------- .. list-table:: :header-rows: 1 * - Name - Description""") lines.extend(_frameworks_lines) # # Boards # vendors = {} for board, data in util.get_boards().items(): platform = data['platform'] vendor = data['vendor'] if name in platform: if vendor in vendors: vendors[vendor].append({board: data}) else: vendors[vendor] = [{board: data}] if vendors: lines.append(""" Boards ------ .. note:: * You can list pre-configured boards by :ref:`cmd_boards` command or `PlatformIO Boards Explorer <http://platformio.org/#!/boards>`_ * For more detailed ``board`` information please scroll tables below by horizontal. """) for vendor, boards in sorted(vendors.iteritems()): lines.append(str(vendor)) lines.append("~" * len(vendor)) lines.append(generate_boards(boards)) return "\n".join(lines)
def cli(project_dir, board, disable_auto_uploading): project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") lib_dir = join(project_dir, "lib") if all([isfile(project_file), isdir(src_dir), isdir(lib_dir)]): raise exception.ProjectInitialized() builtin_boards = set(get_boards().keys()) if board and not set(board).issubset(builtin_boards): raise exception.UnknownBoard( ", ".join(set(board).difference(builtin_boards))) # ask about auto-uploading if board and app.get_setting("enable_prompts"): disable_auto_uploading = not click.confirm( "\nWould you like to enable firmware auto-uploading when project " "is successfully built using `platformio run` command? \n" "Don't forget that you can upload firmware manually using " "`platformio run --target upload` command." ) if project_dir == getcwd(): click.secho("\nThe current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho( "will be used for the new project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.\n", fg="yellow" ) click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" % click.style("platformio.ini", fg="cyan")) click.echo("%s - Put your source code here" % click.style("src", fg="cyan")) click.echo("%s - Put here project specific or 3-rd party libraries" % click.style("lib", fg="cyan")) if (not app.get_setting("enable_prompts") or click.confirm("Do you want to continue?")): for d in (src_dir, lib_dir): if not isdir(d): makedirs(d) if not isfile(project_file): copyfile(join(get_source_dir(), "projectconftpl.ini"), project_file) if board: fill_project_envs(project_file, board, disable_auto_uploading) click.secho( "Project has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " "directory\n" "`platformio run --target upload` or `platformio run -t upload` " "- upload firmware to embedded board\n" "`platformio run --target clean` - clean project (remove compiled " "files)", fg="green" ) else: raise exception.AbortedByUser()
def generate_framework(type_, data): print "Processing framework: %s" % type_ lines = [] lines.append(""".. Copyright 2014-2015 Ivan Kravets <*****@*****.**> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """) lines.append(".. _framework_%s:" % type_) lines.append("") _title = "Framework ``%s``" % type_ lines.append(_title) lines.append("=" * len(_title)) lines.append(data['description']) lines.append(""" For more detailed information please visit `vendor site <%s>`_. """ % data['url']) lines.append(".. contents::") lines.append(""" Platforms --------- .. list-table:: :header-rows: 1 * - Name - Description""") _found_platform = False for platform in sorted(PlatformFactory.get_platforms().keys()): if not is_compat_platform_and_framework(platform, type_): continue _found_platform = True p = PlatformFactory.newPlatform(platform) lines.append(""" * - :ref:`platform_{type_}` - {description}""".format(type_=platform, description=p.get_description())) if not _found_platform: del lines[-1] lines.append(""" Boards ------ .. note:: * You can list pre-configured boards by :ref:`cmd_boards` command or `PlatformIO Boards Explorer <http://platformio.org/#!/boards>`_ * For more detailed ``board`` information please scroll tables below by horizontal. """) vendors = {} for board, data in util.get_boards().items(): frameworks = data['frameworks'] vendor = data['vendor'] if type_ in frameworks: if vendor in vendors: vendors[vendor].append({board: data}) else: vendors[vendor] = [{board: data}] for vendor, boards in sorted(vendors.iteritems()): lines.append(str(vendor)) lines.append("~" * len(vendor)) lines.append(generate_boards(boards)) return "\n".join(lines)
def generate_framework(type_, data): print "Processing framework: %s" % type_ lines = [] lines.append(""".. Copyright 2014-2015 Ivan Kravets <*****@*****.**> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """) lines.append(".. _framework_%s:" % type_) lines.append("") _title = "Framework ``%s``" % type_ lines.append(_title) lines.append("=" * len(_title)) lines.append(data['description']) lines.append(""" For more detailed information please visit `vendor site <%s>`_. """ % data['url']) lines.append(".. contents::") lines.append(""" Platforms --------- .. list-table:: :header-rows: 1 * - Name - Description""") _found_platform = False for platform in sorted(PlatformFactory.get_platforms().keys()): if not is_compat_platform_and_framework(platform, type_): continue _found_platform = True p = PlatformFactory.newPlatform(platform) lines.append(""" * - :ref:`platform_{type_}` - {description}""".format( type_=platform, description=p.get_description())) if not _found_platform: del lines[-1] lines.append(""" Boards ------ .. note:: * You can list pre-configured boards by :ref:`cmd_boards` command or `PlatformIO Boards Explorer <http://platformio.org/#!/boards>`_ * For more detailed ``board`` information please scroll tables below by horizontal. """) vendors = {} for board, data in util.get_boards().items(): frameworks = data['frameworks'] vendor = data['vendor'] if type_ in frameworks: if vendor in vendors: vendors[vendor].append({board: data}) else: vendors[vendor] = [{board: data}] for vendor, boards in sorted(vendors.iteritems()): lines.append(str(vendor)) lines.append("~" * len(vendor)) lines.append(generate_boards(boards)) return "\n".join(lines)
PIOENVS_DIR=util.get_pioenvs_dir(), PIOBUILDER_DIR=join(util.get_source_dir(), "builder"), PIOPACKAGES_DIR=join("$PIOHOME_DIR", "packages"), BUILD_DIR=join("$PIOENVS_DIR", "$PIOENV"), BUILDSRC_DIR=join("$BUILD_DIR", "src"), LIBSOURCE_DIRS=[ "$PROJECTLIB_DIR", util.get_lib_dir(), join("$PLATFORMFW_DIR", "libraries") ]) env = DefaultEnvironment() if "BOARD" in env: try: env.Replace(BOARD_OPTIONS=util.get_boards(env.subst("$BOARD"))) except UnknownBoard as e: env.Exit("Error: %s" % str(e)) if "BOARD_MCU" not in env: env.Replace(BOARD_MCU="${BOARD_OPTIONS['build']['mcu']}") if "BOARD_F_CPU" not in env: env.Replace(BOARD_F_CPU="${BOARD_OPTIONS['build']['f_cpu']}") if "UPLOAD_PROTOCOL" not in env: env.Replace( UPLOAD_PROTOCOL="${BOARD_OPTIONS['upload'].get('protocol', None)}") if "UPLOAD_SPEED" not in env: env.Replace( UPLOAD_SPEED="${BOARD_OPTIONS['upload'].get('speed', None)}") if "ldscript" in env.get("BOARD_OPTIONS", {}).get("build", {}): env.Replace(
def generate_platform(name): print "Processing platform: %s" % name lines = [] lines.append(".. _platform_%s:" % name) lines.append("") _title = "Platform ``%s``" % name lines.append(_title) lines.append("=" * len(_title)) p = PlatformFactory.newPlatform(name) lines.append(p.get_description()) lines.append(""" For more detailed information please visit `vendor site <%s>`_.""" % p.get_vendor_url()) lines.append(""" .. contents::""") lines.append(""" Packages -------- """) lines.append(generate_packages(p.get_packages())) lines.append(""" Frameworks ---------- .. list-table:: :header-rows: 1 * - Name - Description""") _frameworks = util.get_frameworks() for framework in sorted(_frameworks.keys()): if not is_compat_platform_and_framework(name, framework): continue lines.append(""" * - :ref:`framework_{type_}` - {description}""".format( type_=framework, description=_frameworks[framework]['description'])) lines.append(""" Boards ------ .. note:: * You can list pre-configured boards by :ref:`cmd_boards` command or `PlatformIO Boards Explorer <http://platformio.org/#!/boards>`_ * For more detailed ``board`` information please scroll tables below by horizontal. """) vendors = {} for board, data in util.get_boards().items(): platform = data['platform'] vendor = data['vendor'] if name in platform: if vendor in vendors: vendors[vendor].append({board: data}) else: vendors[vendor] = [{board: data}] for vendor, boards in sorted(vendors.iteritems()): lines.append(str(vendor)) lines.append("~" * len(vendor)) lines.append(generate_boards(boards)) return "\n".join(lines)
BUILDSRC_DIR=join("$BUILD_DIR", "src"), LIBSOURCE_DIRS=[ "$PROJECTLIB_DIR", util.get_lib_dir(), join("$PLATFORMFW_DIR", "libraries") ], PYTHONEXE=normpath(sys.executable) ) env = DefaultEnvironment() env.Prepend(LIBPATH=[join("$PIOPACKAGES_DIR", "ldscripts")]) if "BOARD" in env: try: env.Replace(BOARD_OPTIONS=util.get_boards(env.subst("$BOARD"))) except UnknownBoard as e: env.Exit("Error: %s" % str(e)) for k in commonvars.keys(): if (k in env or not any([k.startswith("BOARD_"), k.startswith("UPLOAD_")])): continue _opt, _val = k.lower().split("_", 1) if _opt == "board": _opt = "build" if _val in env['BOARD_OPTIONS'][_opt]: env.Replace(**{k: "${BOARD_OPTIONS['%s']['%s']}" % (_opt, _val)}) if "ldscript" in env.get("BOARD_OPTIONS", {}).get("build", {}): env.Replace(