forked from platformio/platformio-core
Allow to initialise project with the specified embedded boards // Resolve #21
This commit is contained in:
@@ -9,6 +9,9 @@ Release History
|
|||||||
* Added support of *Engduino* boards for
|
* Added support of *Engduino* boards for
|
||||||
`atmelavr <http://docs.platformio.ikravets.com/en/latest/platforms/atmelavr.html#engduino>`__
|
`atmelavr <http://docs.platformio.ikravets.com/en/latest/platforms/atmelavr.html#engduino>`__
|
||||||
platform (`issue #38 <https://github.com/ivankravets/platformio/issues/38>`_)
|
platform (`issue #38 <https://github.com/ivankravets/platformio/issues/38>`_)
|
||||||
|
* Added ``--board`` option to `platformio init <http://docs.platformio.ikravets.com/en/latest/userguide/cmd_init.html>`_
|
||||||
|
command which allows to initialise project with the specified embedded boards
|
||||||
|
(`issue #21 <https://github.com/ivankravets/platformio/issues/21>`_)
|
||||||
* Added `example with uploading firmware <http://docs.platformio.ikravets.com/en/latest/projectconf.html#examples>`_
|
* Added `example with uploading firmware <http://docs.platformio.ikravets.com/en/latest/projectconf.html#examples>`_
|
||||||
via USB programmer (USBasp) for
|
via USB programmer (USBasp) for
|
||||||
`atmelavr <http://docs.platformio.ikravets.com/en/latest/platforms/atmelavr.html>`_
|
`atmelavr <http://docs.platformio.ikravets.com/en/latest/platforms/atmelavr.html>`_
|
||||||
|
@@ -58,18 +58,24 @@ For example, ``[env:hello_world]``.
|
|||||||
Options
|
Options
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
|
||||||
|
.. _projectconf_env_platform:
|
||||||
|
|
||||||
``platform``
|
``platform``
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
|
|
||||||
:ref:`Platform <platforms>` type
|
:ref:`Platform <platforms>` type
|
||||||
|
|
||||||
|
|
||||||
|
.. _projectconf_env_framework:
|
||||||
|
|
||||||
``framework``
|
``framework``
|
||||||
^^^^^^^^^^^^^
|
^^^^^^^^^^^^^
|
||||||
|
|
||||||
See ``framework`` type in *Frameworks* section of :ref:`platforms`
|
See ``framework`` type in *Frameworks* section of :ref:`platforms`
|
||||||
|
|
||||||
|
|
||||||
|
.. _projectconf_env_board:
|
||||||
|
|
||||||
``board``
|
``board``
|
||||||
^^^^^^^^^
|
^^^^^^^^^
|
||||||
|
|
||||||
|
@@ -7,33 +7,18 @@ Quickstart
|
|||||||
Please read `Get Started <http://platformio.ikravets.com/#!/get-started>`_
|
Please read `Get Started <http://platformio.ikravets.com/#!/get-started>`_
|
||||||
article from the official WebSite.
|
article from the official WebSite.
|
||||||
|
|
||||||
First, :ref:`Install PlatformIO <installation>`.
|
1. :ref:`Install PlatformIO <installation>`.
|
||||||
|
|
||||||
Print all available development platforms for installing
|
2. Find board ``type`` from :ref:`platforms` (you can choose multiple board
|
||||||
|
types).
|
||||||
|
|
||||||
|
3. Initialize new PlatformIO based project with the pre-configured
|
||||||
|
environments for your boards:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio search
|
$ platformio init --board=TYPE1 --board=TYPE2
|
||||||
[ ... ]
|
|
||||||
|
|
||||||
|
|
||||||
Install new development platform
|
|
||||||
|
|
||||||
.. code-block:: bash
|
|
||||||
|
|
||||||
$ platformio install PLATFORM
|
|
||||||
Downloading [####################################] 100%
|
|
||||||
Unpacking [####################################] 100%
|
|
||||||
Installing .....
|
|
||||||
[ ... ]
|
|
||||||
The platform 'PLATFORM' has been successfully installed!
|
|
||||||
|
|
||||||
|
|
||||||
Initialize new PlatformIO based project
|
|
||||||
|
|
||||||
.. code-block:: bash
|
|
||||||
|
|
||||||
$ platformio init
|
|
||||||
The current working directory *** will be used for the new project.
|
The current working directory *** will be used for the new project.
|
||||||
You can specify another project directory via
|
You can specify another project directory via
|
||||||
`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.
|
`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.
|
||||||
@@ -46,29 +31,23 @@ Initialize new PlatformIO based project
|
|||||||
Project has been successfully initialized!
|
Project has been successfully initialized!
|
||||||
Now you can process it with `platformio run` command.
|
Now you can process it with `platformio run` command.
|
||||||
|
|
||||||
|
More detailed information about this command is here :ref:`cmd_init`.
|
||||||
|
|
||||||
Setup environments in ``platformio.ini``. For more examples go to
|
4. Process the project's environments.
|
||||||
:ref:`Project Configuration File <projectconf_examples>`
|
|
||||||
|
|
||||||
.. code-block:: ini
|
|
||||||
|
|
||||||
# Simple and base environment
|
|
||||||
[env:mybaseenv]
|
|
||||||
platform = %INSTALLED_PLATFORM_NAME_HERE%
|
|
||||||
|
|
||||||
|
|
||||||
Process the project's environments
|
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio run
|
$ platformio run
|
||||||
|
|
||||||
# if embedded project then upload firmware
|
# if you don't have specified `targets = upload` option for environment,
|
||||||
|
# then you can upload firmware manually with this command:
|
||||||
$ platformio run --target upload
|
$ platformio run --target upload
|
||||||
|
|
||||||
# clean project
|
# clean project
|
||||||
$ platformio run --target clean
|
$ platformio run --target clean
|
||||||
|
|
||||||
|
If you don't have installed required platforms, then *PlatformIO* will propose
|
||||||
|
you to install them automatically.
|
||||||
|
|
||||||
Further examples can be found in the ``examples/`` directory in the source
|
Further examples can be found in the ``examples/`` directory in the source
|
||||||
distribution or `on the web <https://github.com/ivankravets/platformio/tree/develop/examples>`_.
|
distribution or `on the web <https://github.com/ivankravets/platformio/tree/develop/examples>`_.
|
||||||
|
@@ -32,8 +32,27 @@ Options
|
|||||||
.. option::
|
.. option::
|
||||||
--project-dir, -d
|
--project-dir, -d
|
||||||
|
|
||||||
Specified path to the directory where *PlatformIO* will initialize new project.
|
A path to the directory where *PlatformIO* will initialise new project.
|
||||||
|
|
||||||
|
.. option::
|
||||||
|
--board, -b
|
||||||
|
|
||||||
|
If you specify board ``type`` (you can pass multiple ``--board`` options), then
|
||||||
|
*PlatformIO* will automatically generate environment for :ref:`projectconf` and
|
||||||
|
pre-fill these data:
|
||||||
|
|
||||||
|
* :ref:`projectconf_env_platform`
|
||||||
|
* :ref:`projectconf_env_framework`
|
||||||
|
* :ref:`projectconf_env_board`
|
||||||
|
|
||||||
|
The full list with pre-configured boards is available here :ref:`platforms`.
|
||||||
|
|
||||||
|
.. option::
|
||||||
|
--disable-auto-uploading
|
||||||
|
|
||||||
|
If you initialise project with the specified ``--board``, then *PlatformIO*
|
||||||
|
will create environment with enabled firmware auto-uploading. This option
|
||||||
|
allows you to disable firmware auto-uploading by default.
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
@@ -43,6 +62,7 @@ Examples
|
|||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio init
|
$ platformio init
|
||||||
|
|
||||||
The current working directory *** will be used for the new project.
|
The current working directory *** will be used for the new project.
|
||||||
You can specify another project directory via
|
You can specify another project directory via
|
||||||
`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.
|
`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.
|
||||||
@@ -61,6 +81,21 @@ Examples
|
|||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio init -d %PATH_TO_DIR%
|
$ platformio init -d %PATH_TO_DIR%
|
||||||
|
|
||||||
|
The next files/directories will be created in ***
|
||||||
|
platformio.ini - Project Configuration File
|
||||||
|
src - a source directory. Put your source code here
|
||||||
|
lib - a directory for the project specific libraries
|
||||||
|
Do you want to continue? [y/N]: y
|
||||||
|
Project has been successfully initialized!
|
||||||
|
Now you can process it with `platformio run` command.
|
||||||
|
|
||||||
|
3. Initialise project for Arduino Uno
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
$ platformio init --board uno
|
||||||
|
|
||||||
The next files/directories will be created in ***
|
The next files/directories will be created in ***
|
||||||
platformio.ini - Project Configuration File
|
platformio.ini - Project Configuration File
|
||||||
src - a source directory. Put your source code here
|
src - a source directory. Put your source code here
|
||||||
|
@@ -8,15 +8,17 @@ from shutil import copyfile
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from platformio import app
|
from platformio import app
|
||||||
from platformio.exception import ProjectInitialized
|
from platformio.exception import ProjectInitialized, UnknownBoard
|
||||||
from platformio.util import get_source_dir
|
from platformio.util import get_boards, get_source_dir
|
||||||
|
|
||||||
|
|
||||||
@click.command("init", short_help="Initialize new PlatformIO based project")
|
@click.command("init", short_help="Initialize new PlatformIO based project")
|
||||||
@click.option("--project-dir", "-d", default=getcwd(),
|
@click.option("--project-dir", "-d", default=getcwd(),
|
||||||
type=click.Path(exists=True, file_okay=False, dir_okay=True,
|
type=click.Path(exists=True, file_okay=False, dir_okay=True,
|
||||||
writable=True, resolve_path=True))
|
writable=True, resolve_path=True))
|
||||||
def cli(project_dir):
|
@click.option("--board", "-b", multiple=True, metavar="TYPE")
|
||||||
|
@click.option('--disable-auto-uploading', is_flag=True)
|
||||||
|
def cli(project_dir, board, disable_auto_uploading):
|
||||||
|
|
||||||
project_file = join(project_dir, "platformio.ini")
|
project_file = join(project_dir, "platformio.ini")
|
||||||
src_dir = join(project_dir, "src")
|
src_dir = join(project_dir, "src")
|
||||||
@@ -24,6 +26,10 @@ def cli(project_dir):
|
|||||||
if all([isfile(project_file), isdir(src_dir), isdir(lib_dir)]):
|
if all([isfile(project_file), isdir(src_dir), isdir(lib_dir)]):
|
||||||
raise ProjectInitialized()
|
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():
|
if project_dir == getcwd():
|
||||||
click.secho("The current working directory", fg="yellow", nl=False)
|
click.secho("The current working directory", fg="yellow", nl=False)
|
||||||
click.secho(" %s " % project_dir, fg="cyan", nl=False)
|
click.secho(" %s " % project_dir, fg="cyan", nl=False)
|
||||||
@@ -51,6 +57,8 @@ def cli(project_dir):
|
|||||||
if not isfile(project_file):
|
if not isfile(project_file):
|
||||||
copyfile(join(get_source_dir(), "projectconftpl.ini"),
|
copyfile(join(get_source_dir(), "projectconftpl.ini"),
|
||||||
project_file)
|
project_file)
|
||||||
|
if board:
|
||||||
|
fill_project_envs(project_file, board, disable_auto_uploading)
|
||||||
click.secho(
|
click.secho(
|
||||||
"Project has been successfully initialized!\n"
|
"Project has been successfully initialized!\n"
|
||||||
"Now you can process it with `platformio run` command.",
|
"Now you can process it with `platformio run` command.",
|
||||||
@@ -58,3 +66,31 @@ def cli(project_dir):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
click.secho("Aborted by user", fg="red")
|
click.secho("Aborted by user", fg="red")
|
||||||
|
|
||||||
|
|
||||||
|
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))
|
||||||
|
@@ -30,6 +30,11 @@ class UnknownCLICommand(PlatformioException):
|
|||||||
" to see all available commands")
|
" to see all available commands")
|
||||||
|
|
||||||
|
|
||||||
|
class UnknownBoard(PlatformioException):
|
||||||
|
|
||||||
|
MESSAGE = "Unknown board type '%s'"
|
||||||
|
|
||||||
|
|
||||||
class UnknownPackage(PlatformioException):
|
class UnknownPackage(PlatformioException):
|
||||||
|
|
||||||
MESSAGE = "Detected unknown package '%s'"
|
MESSAGE = "Detected unknown package '%s'"
|
||||||
|
@@ -5,6 +5,14 @@
|
|||||||
# http://docs.platformio.ikravets.com/en/latest/projectconf.html
|
# http://docs.platformio.ikravets.com/en/latest/projectconf.html
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# A sign `#` at the beginning of the line indicate a comment
|
||||||
|
# Comment lines are ignored.
|
||||||
|
|
||||||
# Simple and base environment
|
# Simple and base environment
|
||||||
#[env:mybaseenv]
|
# [env:mybaseenv]
|
||||||
#platform = %INSTALLED_PLATFORM_NAME_HERE%
|
# platform = %INSTALLED_PLATFORM_NAME_HERE%
|
||||||
|
# framework =
|
||||||
|
# board =
|
||||||
|
#
|
||||||
|
# Automatic targets - enable auto-uploading
|
||||||
|
# targets = upload
|
||||||
|
Reference in New Issue
Block a user