Add support for Raspberry Pi WiringPi framework // Resolve #372

This commit is contained in:
Ivan Kravets
2015-12-14 19:50:50 +02:00
parent d4e4ab07a6
commit 004125a2ca
24 changed files with 704 additions and 20 deletions

View File

@ -4,9 +4,12 @@ Release History
PlatformIO 2.0
--------------
2.5.1 (2015-12-??)
2.6.0 (2015-12-??)
~~~~~~~~~~~~~~~~~~
* Added support for Raspberry Pi `WiringPi <http://docs.platformio.org/en/latest/frameworks/wiringpi.html>`__
framework
(`issue #372 <https://github.com/platformio/platformio/issues/372>`_)
* Implemented Over The Air (OTA) upgrades for `Espressif <http://docs.platformio.org/en/latest/platforms/espressif.html>`__
development platform.
(`issue #365 <https://github.com/platformio/platformio/issues/365>`_)

View File

@ -23,3 +23,4 @@ Frameworks
libopencm3
mbed
spl
wiringpi

View File

@ -0,0 +1,62 @@
.. Copyright 2014-2015 Ivan Kravets <me@ikravets.com>
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.
.. _framework_wiringpi:
Framework ``wiringpi``
======================
WiringPi is a GPIO access library written in C for the BCM2835 used in the Raspberry Pi. It's designed to be familiar to people who have used the Arduino "wiring" system.
For more detailed information please visit `vendor site <http://wiringpi.com>`_.
.. contents::
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.
Raspberry Pi
~~~~~~~~~~~~
.. list-table::
:header-rows: 1
* - Type ``board``
- Name
- Microcontroller
- Frequency
- Flash
- RAM
* - ``raspberrypi_1b``
- `Raspberry Pi 1 Model B <https://www.raspberrypi.org>`_
- BCM2835
- 700 MHz
- 524288 Kb
- 524288 Kb
* - ``raspberrypi_2b``
- `Raspberry Pi 2 Model B <https://www.raspberrypi.org>`_
- BCM2836
- 900 MHz
- 1048576 Kb
- 1048576 Kb
* - ``raspberrypi_zero``
- `Raspberry Pi Zero <https://www.raspberrypi.org>`_
- BCM2835
- 1000 MHz
- 524288 Kb
- 524288 Kb

View File

@ -17,4 +17,47 @@ Native development platform is intended to be used for desktop OS. This platform
For more detailed information please visit `vendor site <http://platformio.org/#!/platforms/native>`_.
.. contents::
.. contents::
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.
Raspberry Pi
~~~~~~~~~~~~
.. list-table::
:header-rows: 1
* - Type ``board``
- Name
- Microcontroller
- Frequency
- Flash
- RAM
* - ``raspberrypi_1b``
- `Raspberry Pi 1 Model B <https://www.raspberrypi.org>`_
- BCM2835
- 700 MHz
- 524288 Kb
- 524288 Kb
* - ``raspberrypi_2b``
- `Raspberry Pi 2 Model B <https://www.raspberrypi.org>`_
- BCM2836
- 900 MHz
- 1048576 Kb
- 1048576 Kb
* - ``raspberrypi_zero``
- `Raspberry Pi Zero <https://www.raspberrypi.org>`_
- BCM2835
- 1000 MHz
- 524288 Kb
- 524288 Kb

View File

@ -0,0 +1 @@
.pioenvs

View File

@ -0,0 +1,65 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < http://docs.platformio.org/en/latest/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < http://docs.platformio.org/en/latest/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < http://docs.platformio.org/en/latest/userguide/cmd_ci.html >
#
#
# Please choice one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#
#
# Template #1: General project. Test it using existing `platformio.ini`.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
#
# script:
# - platformio run
#
# Template #2: The project is intended to by used as a library with examples
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
#
# script:
# - platformio ci --lib="." --board=TYPE_1 --board=TYPE_2 --board=TYPE_N

View File

@ -0,0 +1,29 @@
.. Copyright 2014-2015 Ivan Kravets <me@ikravets.com>
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.
How to build PlatformIO based project
=====================================
1. `Install PlatformIO <http://docs.platformio.org/en/latest/installation.html>`_
2. Download `source code with examples <https://github.com/platformio/platformio/archive/develop.zip>`_
3. Extract ZIP archive
4. Run these commands:
.. code-block:: bash
# Change directory to example
> cd platformio-develop/examples/raspberrypi/wiringpi-blink
# Process example project
> platformio run
# Run program
> .pioenvs/raspberrypi_2b/program

View File

@ -0,0 +1,38 @@
This directory is intended for the project specific (private) libraries.
PlatformIO will compile them to static libraries and link to executable file.
The source code of each library should be placed in separate directory, like
"lib/private_lib/[here are source files]".
For example, see how can be organised `Foo` and `Bar` libraries:
|--lib
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |- readme.txt --> THIS FILE
|- platformio.ini
|--src
|- main.c
Then in `src/main.c` you should use:
#include <Foo.h>
#include <Bar.h>
// rest H/C/CPP code
PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.
See additional options for PlatformIO Library Dependency Finder `lib_*`:
http://docs.platformio.org/en/latest/projectconf.html#lib-install

View File

@ -0,0 +1,23 @@
#
# Project Configuration File
#
# A detailed documentation with the EXAMPLES is located here:
# http://docs.platformio.org/en/latest/projectconf.html
#
# A sign `#` at the beginning of the line indicates a comment
# Comment lines are ignored.
# Simple and base environment
# [env:mybaseenv]
# platform = %INSTALLED_PLATFORM_NAME_HERE%
# framework =
# board =
#
# Automatic targets - enable auto-uploading
# targets = upload
[env:raspberrypi_2b]
platform = native
framework = wiringpi
board = raspberrypi_2b

View File

@ -0,0 +1,48 @@
/*
* blink.c:
* Standard "blink" program in wiringPi. Blinks an LED connected
* to the first GPIO pin.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
// LED Pin - wiringPi pin 0 is BCM_GPIO 17.
#define LED 0
int main (void)
{
printf ("Raspberry Pi blink\n") ;
wiringPiSetup () ;
pinMode (LED, OUTPUT) ;
for (;;)
{
digitalWrite (LED, HIGH) ; // On
delay (500) ; // mS
digitalWrite (LED, LOW) ; // Off
delay (500) ;
}
return 0 ;
}

View File

@ -0,0 +1 @@
.pioenvs

View File

@ -0,0 +1,65 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < http://docs.platformio.org/en/latest/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < http://docs.platformio.org/en/latest/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < http://docs.platformio.org/en/latest/userguide/cmd_ci.html >
#
#
# Please choice one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#
#
# Template #1: General project. Test it using existing `platformio.ini`.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
#
# script:
# - platformio run
#
# Template #2: The project is intended to by used as a library with examples
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
#
# script:
# - platformio ci --lib="." --board=TYPE_1 --board=TYPE_2 --board=TYPE_N

View File

@ -0,0 +1,29 @@
.. Copyright 2014-2015 Ivan Kravets <me@ikravets.com>
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.
How to build PlatformIO based project
=====================================
1. `Install PlatformIO <http://docs.platformio.org/en/latest/installation.html>`_
2. Download `source code with examples <https://github.com/platformio/platformio/archive/develop.zip>`_
3. Extract ZIP archive
4. Run these commands:
.. code-block:: bash
# Change directory to example
> cd platformio-develop/examples/raspberrypi/wiringpi-serial
# Process example project
> platformio run
# Run program
> .pioenvs/raspberrypi_2b/program

View File

@ -0,0 +1,38 @@
This directory is intended for the project specific (private) libraries.
PlatformIO will compile them to static libraries and link to executable file.
The source code of each library should be placed in separate directory, like
"lib/private_lib/[here are source files]".
For example, see how can be organised `Foo` and `Bar` libraries:
|--lib
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |- readme.txt --> THIS FILE
|- platformio.ini
|--src
|- main.c
Then in `src/main.c` you should use:
#include <Foo.h>
#include <Bar.h>
// rest H/C/CPP code
PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.
See additional options for PlatformIO Library Dependency Finder `lib_*`:
http://docs.platformio.org/en/latest/projectconf.html#lib-install

View File

@ -0,0 +1,23 @@
#
# Project Configuration File
#
# A detailed documentation with the EXAMPLES is located here:
# http://docs.platformio.org/en/latest/projectconf.html
#
# A sign `#` at the beginning of the line indicates a comment
# Comment lines are ignored.
# Simple and base environment
# [env:mybaseenv]
# platform = %INSTALLED_PLATFORM_NAME_HERE%
# framework =
# board =
#
# Automatic targets - enable auto-uploading
# targets = upload
[env:raspberrypi_2b]
platform = native
framework = wiringpi
board = raspberrypi_2b

View File

@ -0,0 +1,75 @@
/*
* serialTest.c:
* Very simple program to test the serial port. Expects
* the port to be looped back to itself
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <wiringPi.h>
#include <wiringSerial.h>
int main ()
{
int fd ;
int count ;
unsigned int nextTime ;
if ((fd = serialOpen ("/dev/ttyAMA0", 115200)) < 0)
{
fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
return 1 ;
}
if (wiringPiSetup () == -1)
{
fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ;
return 1 ;
}
nextTime = millis () + 300 ;
for (count = 0 ; count < 256 ; )
{
if (millis () > nextTime)
{
printf ("\nOut: %3d: ", count) ;
fflush (stdout) ;
serialPutchar (fd, count) ;
nextTime += 300 ;
++count ;
}
delay (3) ;
while (serialDataAvail (fd))
{
printf (" -> %3d", serialGetchar (fd)) ;
fflush (stdout) ;
}
}
printf ("\n") ;
return 0 ;
}

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
VERSION = (2, 5, "1.dev1")
VERSION = (2, 6, "0.dev0")
__version__ = ".".join([str(s) for s in VERSION])
__title__ = "platformio"

View File

@ -0,0 +1,53 @@
{
"raspberrypi_1b": {
"build": {
"extra_flags": "-DRASPBERRYPI -DRASPBERRYPI1",
"f_cpu": "700000000L",
"mcu": "bcm2835"
},
"frameworks": ["wiringpi"],
"name": "Raspberry Pi 1 Model B",
"platform": "native",
"upload": {
"maximum_ram_size": 536870912,
"maximum_size": 536870912
},
"url": "https://www.raspberrypi.org",
"vendor": "Raspberry Pi"
},
"raspberrypi_2b": {
"build": {
"core": "esp8266",
"extra_flags": "-DRASPBERRYPI -DRASPBERRYPI2",
"f_cpu": "900000000L",
"mcu": "bcm2836"
},
"frameworks": ["wiringpi"],
"name": "Raspberry Pi 2 Model B",
"platform": "native",
"upload": {
"maximum_ram_size": 1073741824,
"maximum_size": 1073741824
},
"url": "https://www.raspberrypi.org",
"vendor": "Raspberry Pi"
},
"raspberrypi_zero": {
"build": {
"extra_flags": "-DRASPBERRYPI -DRASPBERRYPIZERO",
"f_cpu": "1000000000L",
"mcu": "bcm2835"
},
"frameworks": ["wiringpi"],
"name": "Raspberry Pi Zero",
"platform": "native",
"upload": {
"maximum_ram_size": 536870912,
"maximum_size": 536870912
},
"url": "https://www.raspberrypi.org",
"vendor": "Raspberry Pi"
}
}

View File

@ -0,0 +1,65 @@
# Copyright 2014-2015 Ivan Kravets <me@ikravets.com>
#
# 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.
"""
WiringPi
WiringPi is a GPIO access library written in C for the BCM2835 used in the
Raspberry Pi. It's designed to be familiar to people who have used the Arduino
"wiring" system.
http://wiringpi.com
"""
from os.path import join
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
env.Replace(
CPPFLAGS=[
"-O2",
"-Wformat=2",
"-Wall",
"-Winline",
"-pipe",
"-fPIC"
],
LIBS=["pthread"]
)
env.Append(
CPPDEFINES=[
"_GNU_SOURCE"
],
CPPPATH=[
join("$BUILD_DIR", "FrameworkWiringPi")
]
)
#
# Target: Build Core Library
#
libs = []
libs.append(env.BuildLibrary(
join("$BUILD_DIR", "FrameworkWiringPi"),
join("$PIOPACKAGES_DIR", "framework-wiringpi", "wiringPi")
))
env.Append(LIBS=libs)

View File

@ -46,7 +46,10 @@ def BuildProgram(env):
env.get("BUILD_FLAGS"),
getenv("PLATFORMIO_BUILD_FLAGS"),
])
env.BuildFramework()
if env.get("FRAMEWORK"):
env.BuildFrameworks([
f.lower().strip() for f in env.get("FRAMEWORK", "").split(",")])
# build dependent libs
deplibs = env.BuildDependentLibraries("$PROJECTSRC_DIR")
@ -171,23 +174,26 @@ def LookupSources(env, variant_dir, src_dir, duplicate=True, src_filter=None):
return sources
def BuildFramework(env):
if "FRAMEWORK" not in env or "uploadlazy" in COMMAND_LINE_TARGETS:
def BuildFrameworks(env, frameworks):
if not frameworks or "uploadlazy" in COMMAND_LINE_TARGETS:
return
if env['FRAMEWORK'].lower() in ("arduino", "energia"):
env.ConvertInoToCpp()
for f in env['FRAMEWORK'].split(","):
framework = f.strip().lower()
if framework in env.get("BOARD_OPTIONS", {}).get("frameworks"):
SConscript(
env.subst(join("$PIOBUILDER_DIR", "scripts", "frameworks",
"%s.py" % framework))
)
board_frameworks = env.get("BOARD_OPTIONS", {}).get("frameworks")
if frameworks == ["platformio"]:
if board_frameworks:
frameworks.insert(0, board_frameworks[0])
else:
Exit("Error: This board doesn't support %s framework!" %
framework)
Exit("Error: Please specify board type")
for f in frameworks:
if f in ("arduino", "energia"):
env.ConvertInoToCpp()
if f in board_frameworks:
SConscript(env.subst(
join("$PIOBUILDER_DIR", "scripts", "frameworks", "%s.py" % f)))
else:
Exit("Error: This board doesn't support %s framework!" % f)
def BuildLibrary(env, variant_dir, src_dir, src_filter=None):
@ -351,7 +357,7 @@ def generate(env):
env.AddMethod(IsFileWithExt)
env.AddMethod(VariantDirWrap)
env.AddMethod(LookupSources)
env.AddMethod(BuildFramework)
env.AddMethod(BuildFrameworks)
env.AddMethod(BuildLibrary)
env.AddMethod(BuildDependentLibraries)
return env

View File

@ -226,6 +226,18 @@ def generate_framework(type_, data):
print "Processing framework: %s" % type_
lines = []
lines.append(""".. Copyright 2014-2015 Ivan Kravets <me@ikravets.com>
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("")
@ -248,15 +260,19 @@ Platforms
* - 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

View File

@ -28,7 +28,7 @@ def pytest_generate_tests(metafunc):
example_dirs = normpath(join(dirname(__file__), "..", "examples"))
project_dirs = []
for root, _, files in walk(example_dirs):
if "platformio.ini" not in files:
if "platformio.ini" not in files or ".skiptest" in files:
continue
project_dirs.append(root)
project_dirs.sort()