diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e23d32f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +.pio diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..89e9d3e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,26 @@ +language: python +python: + - "2.7" + - "3.6" + +env: + - PLATFORMIO_PROJECT_DIR=examples/arduino-blink + - PLATFORMIO_PROJECT_DIR=examples/arduino-external-libs + - PLATFORMIO_PROJECT_DIR=examples/arduino-internal-libs + - PLATFORMIO_PROJECT_DIR=examples/native-blink + +install: + - pip install -U https://github.com/platformio/platformio/archive/develop.zip + - platformio platform install file://. + +script: + - platformio run -d $PLATFORMIO_PROJECT_DIR + +notifications: + email: false + + slack: + rooms: + secure: l3gd68M7ZBaMPkXQiyG8yQdWlmGLQ5E75NgRpFY+zNpIZB2EbQFqYacGwt8KyICJ4IC3Z3Db78FqxpUpKiYD+AX74GwsLHKc7GlLsEzRaOByAtm/xFRut7Fh32OL6xEigz0LUaCDF/ZDXqPYZHhiX9/7jzyjHOhDUIuk9j924qFtT/CRa5FHh8zeXCVlO79YXCir/+pdhoQLW3majfm+MWnSFGFB4wbYrb0RzP6hs45uJWb1tFaw4xKe/qi65FEFgQ33R+A944xAiNfiKgEEKkFcGXn+0ljCTLpu+svd+COKXWOMD0f5GDj5pVni1s4i4uCZXznKacD3QSKLhLBypd5pebCAdq6s9SBXwpNUNZ7EvzCAOZ3maH2XbkckfSyh7fZZq4tnluOCmnu6gEdLSciemJCfv8Xe+TXgs05LlLg1q3gsqfZ/1kyILfADdVwprVpjwwgAsFF8VTuzV6WRw+gZm3giVIdlu7sLT+GPQ07vsS+3lsybQivm4ZjJuEIMuI8Gig7JcQwHbD1GD7Q5hoeBuEz5XEVxhc+0pUzMdKkajS9BP5ap1g6rylkesSNlAIpPnTQXx0Ejj7jAPBJE9UWJPZVRBuT4FYeJR5vYUSZ0dFv4WoS7dGMqelg9xj+Rbnb2TP3m0QkIEaUNz6nF/ARnJBsTW/6w+Iqc5otA1Yg= + on_failure: always + on_success: change diff --git a/README.md b/README.md index 3442f91..c73a245 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,35 @@ -# platform-atmelmegaavr -Atmel megaAVR: development platform for PlatformIO +# Atmel megaAVR: development platform for [PlatformIO](http://platformio.org) +[![Build Status](https://travis-ci.org/platformio/platform-atmelmegaavr.svg?branch=develop)](https://travis-ci.org/platformio/platform-atmelmegaavr) +[![Build status](https://ci.appveyor.com/api/projects/status/wm6hx8n8c23dfbnk/branch/develop?svg=true)](https://ci.appveyor.com/project/ivankravets/platform-atmelmegaavr/branch/develop) + +Microchip's megaAVR is suitable for applications requiring large amounts of code and offers substantial program and data memories with performance up to 20 MIPS. Based on industry-leading, proven technology, the megaAVR family offers Microchip's widest selection of devices in terms of memories, pin counts, and peripherals. + +* [Home](http://platformio.org/platforms/atmelmegaavr) (home page in PlatformIO Platform Registry) +* [Documentation](http://docs.platformio.org/page/platforms/atmelmegaavr.html) (advanced usage, packages, boards, frameworks, etc.) + +# Usage + +1. [Install PlatformIO](http://platformio.org) +2. Create PlatformIO project and configure a platform option in [platformio.ini](http://docs.platformio.org/page/projectconf.html) file: + +## Stable version + +```ini +[env:stable] +platform = atmelmegaavr +board = ... +... +``` + +## Development version + +```ini +[env:development] +platform = https://github.com/platformio/platform-atmelmegaavr.git +board = ... +... +``` + +# Configuration + +Please navigate to [documentation](http://docs.platformio.org/page/platforms/atmelmegaavr.html). diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..fff76d8 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,25 @@ +build: off +environment: + + matrix: + - PLATFORMIO_PROJECT_DIR: "examples/arduino-blink" + - PLATFORMIO_PROJECT_DIR: "examples/arduino-external-libs" + - PLATFORMIO_PROJECT_DIR: "examples/arduino-internal-libs" + - PLATFORMIO_PROJECT_DIR: "examples/native-blink" + +install: +- cmd: git submodule update --init --recursive +- cmd: SET PATH=C:\Python36\Scripts;%PATH% +- cmd: pip3 install -U https://github.com/platformio/platformio/archive/develop.zip +- cmd: platformio platform install file://. + +test_script: +- cmd: platformio run -d %PLATFORMIO_PROJECT_DIR% + +notifications: + - provider: Slack + incoming_webhook: + secure: E9H0SU0Ju7WLDvgxsV8cs3J62T3nTTX7QkEjsczN0Sto/c9hWkVfhc5gGWUkxhlD975cokHByKGJIdwYwCewqOI+7BrcT8U+nlga4Uau7J8= + on_build_success: false + on_build_failure: true + on_build_status_changed: true diff --git a/boards/nano_every.json b/boards/nano_every.json new file mode 100644 index 0000000..f41d9f6 --- /dev/null +++ b/boards/nano_every.json @@ -0,0 +1,38 @@ +{ + "build": { + "core": "arduino", + "extra_flags": "-DARDUINO_AVR_NANO_EVERY -DAVR_NANO_4809_328MODE -DMILLIS_USE_TIMERB3 -DNO_EXTERNAL_I2C_PULLUP", + "f_cpu": "16000000L", + "hwids": [ + [ + "0x2341", + "0x0058" + ] + ], + "mcu": "atmega4809", + "usb_product": "Arduino Nano Every", + "variant": "nona4809" + }, + "bootloader": { + "SYSCFG0": "0xC9", + "file": "atmega4809_uart_bl.hex", + "fuses_file": "fuses_4809.bin", + "BOOTEND": "0x00", + "OSCCFG": "0x01" + }, + "frameworks": [ + "arduino" + ], + "name": "Arduino Nano Every", + "upload": { + "maximum_ram_size": 6144, + "maximum_size": 48640, + "protocol": "jtag2updi", + "require_upload_port": true, + "speed": 115200, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "https://www.arduino.cc/en/Guide/NANOEvery", + "vendor": "Arduino" +} diff --git a/boards/uno_wifi_rev2.json b/boards/uno_wifi_rev2.json new file mode 100644 index 0000000..5d4f52a --- /dev/null +++ b/boards/uno_wifi_rev2.json @@ -0,0 +1,39 @@ +{ + "build": { + "core": "arduino", + "extra_flags": "-DARDUINO_AVR_UNO_WIFI_REV2 -DUNO_WIFI_REV2_328MODE -DMILLIS_USE_TIMERB3", + "text_section_start": "0x200", + "f_cpu": "16000000L", + "hwids": [ + [ + "0x03eb", + "0x2145" + ] + ], + "mcu": "atmega4809", + "usb_product": "Arduino Uno WiFi Rev2", + "variant": "uno2018" + }, + "bootloader": { + "file": "atmega4809_uart_bl.hex", + "fuses_file": "fuses_4809.bin", + "BOOTEND": "0x02", + "SYSCFG0": "0xC9", + "OSCCFG": "0x01" + }, + "frameworks": [ + "arduino" + ], + "name": "Arduino Uno WiFi Rev2", + "upload": { + "disable_flushing": true, + "maximum_ram_size": 6144, + "maximum_size": 48640, + "protocol": "xplainedmini_updi", + "require_upload_port": true, + "speed": 115200, + "wait_for_upload_port": true + }, + "url": "https://www.arduino.cc/en/Guide/ArduinoUnoWiFiRev2", + "vendor": "Arduino" +} diff --git a/builder/frameworks/_bare.py b/builder/frameworks/_bare.py new file mode 100644 index 0000000..c006879 --- /dev/null +++ b/builder/frameworks/_bare.py @@ -0,0 +1,66 @@ +# Copyright 2019-present PlatformIO +# +# 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. + +# +# Default flags for bare-metal programming (without any framework layers) +# + +from SCons.Script import Import + +Import("env") + +env.Append( + ASFLAGS=["-x", "assembler-with-cpp"], + + CFLAGS=[ + "-std=gnu11", + "-fno-fat-lto-objects" + ], + + CCFLAGS=[ + "-Os", + "-w", + "-ffunction-sections", + "-fdata-sections", + "-flto", + "-mmcu=$BOARD_MCU" + ], + + CPPDEFINES=[ + ("F_CPU", "$BOARD_F_CPU") + ], + + CXXFLAGS=[ + "-std=gnu++11", + "-fno-exceptions", + "-fno-threadsafe-statics", + "-fpermissive", + "-Wno-error=narrowing" + ], + + LINKFLAGS=[ + "-Os", + "-flto", + "-mmcu=$BOARD_MCU", + "-Wl,--gc-sections", + "-Wl,--section-start=.text=%s" % env.BoardConfig().get( + "build.text_section_start", "0x0"), + "-fuse-linker-plugin" + ], + + LIBS=["m"] +) + +# copy CCFLAGS to ASFLAGS (-x assembler-with-cpp mode) +env.Append(ASFLAGS=env.get("CCFLAGS", [])[:]) diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py new file mode 100644 index 0000000..7aac52f --- /dev/null +++ b/builder/frameworks/arduino.py @@ -0,0 +1,122 @@ +# Copyright 2019-present PlatformIO +# +# 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. + +""" +Arduino + +Arduino Wiring-based Framework allows writing cross-platform software to +control devices attached to a wide range of Arduino boards to create all +kinds of creative coding, interactive objects, spaces or physical experiences. + +http://arduino.cc/en/Reference/HomePage +""" + +import sys +from os.path import isdir, isfile, join + +from SCons.Script import DefaultEnvironment + +env = DefaultEnvironment() +platform = env.PioPlatform() + +FRAMEWORK_DIR = platform.get_package_dir("framework-arduino-megaavr") +assert isdir(FRAMEWORK_DIR) + +board = env.BoardConfig() +build_core = board.get("build.core", "") + +CPPDEFINES = [ + "ARDUINO_ARCH_MEGAAVR", + ("ARDUINO", 10808) +] + +if "build.usb_product" in board: + CPPDEFINES += [ + ("USB_VID", board.get("build.hwids")[0][0]), + ("USB_PID", board.get("build.hwids")[0][1]), + ("USB_PRODUCT", '\\"%s\\"' % + board.get("build.usb_product", "").replace('"', "")), + ("USB_MANUFACTURER", '\\"%s\\"' % + board.get("vendor", "").replace('"', "")) + ] + +env.SConscript("_bare.py", exports="env") + +env.Append( + CPPDEFINES=CPPDEFINES, + + CPPPATH=[ + join(FRAMEWORK_DIR, "cores", build_core, "api", "deprecated"), + join(FRAMEWORK_DIR, "cores", build_core) + ], + + LIBSOURCE_DIRS=[ + join(FRAMEWORK_DIR, "libraries") + ] +) + +# Bootloader and fuses for uploading purposes +bootloader_config = board.get("bootloader", {}) +if "BOOTLOADER_CMD" not in env: + if env.subst("$BOARD") == "uno_wifi_rev2": + bootloader_path = join( + FRAMEWORK_DIR, "bootloaders", board.get("bootloader.file", "")) + if isfile(bootloader_path): + env.Replace(BOOTLOADER_CMD='-Uflash:w:"%s":i' % bootloader_path) + else: + sys.stderr.write( + "Error: Couldn't find bootloader image %s\n" % bootloader_path) + env.Exit(1) + +if "FUSES_CMD" not in env: + for fuse in ("OSCCFG", "SYSCFG0", "BOOTEND"): + if not bootloader_config.get(fuse, ""): + sys.stderr.write("Error: Missing %s fuse value\n" % fuse) + env.Exit(1) + + env.Replace( + FUSES_CMD="-Ufuse2:w:%s:m -Ufuse5:w:%s:m -Ufuse8:w:%s:m" % ( + bootloader_config.get("OSCCFG"), + bootloader_config.get("SYSCFG0"), + bootloader_config.get("BOOTEND") + ) + ) + +# +# Target: Build Core Library +# + +libs = [] + +if "build.variant" in board: + variants_dir = join( + "$PROJECT_DIR", board.get("build.variants_dir")) if board.get( + "build.variants_dir", "") else join(FRAMEWORK_DIR, "variants") + + env.Append( + CPPPATH=[ + join(variants_dir, board.get("build.variant")) + ] + ) + env.BuildSources( + join("$BUILD_DIR", "FrameworkArduinoVariant"), + join(variants_dir, board.get("build.variant")) + ) + +env.BuildSources( + join("$BUILD_DIR", "FrameworkArduino"), + join(FRAMEWORK_DIR, "cores", build_core) +) + +env.Prepend(LIBS=libs) diff --git a/builder/main.py b/builder/main.py new file mode 100644 index 0000000..98ffa1c --- /dev/null +++ b/builder/main.py @@ -0,0 +1,207 @@ +# Copyright 2019-present PlatformIO +# +# 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. + +from os.path import join + +from SCons.Script import (ARGUMENTS, COMMAND_LINE_TARGETS, AlwaysBuild, + Builder, Default, DefaultEnvironment) + +from platformio.util import get_serial_ports + + +def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 + upload_options = {} + if "BOARD" in env: + upload_options = env.BoardConfig().get("upload", {}) + + if env.subst("$UPLOAD_SPEED"): + env.Append(UPLOADERFLAGS=["-b", "$UPLOAD_SPEED"]) + + # extra upload flags + if "extra_flags" in upload_options: + env.Append(UPLOADERFLAGS=upload_options.get("extra_flags")) + + # disable erasing by default + env.Append(UPLOADERFLAGS=["-e"]) + + if upload_options and not upload_options.get("require_upload_port", False): + return + + env.AutodetectUploadPort() + env.Append(UPLOADERFLAGS=["-P", '"$UPLOAD_PORT"']) + + before_ports = get_serial_ports() + + if upload_options.get("use_1200bps_touch", False): + env.TouchSerialPort("$UPLOAD_PORT", 1200) + + if upload_options.get("wait_for_upload_port", False): + env.Replace(UPLOAD_PORT=env.WaitForNewSerialPort(before_ports)) + + +env = DefaultEnvironment() + +env.Replace( + AR="avr-gcc-ar", + AS="avr-as", + CC="avr-gcc", + GDB="avr-gdb", + CXX="avr-g++", + OBJCOPY="avr-objcopy", + RANLIB="avr-gcc-ranlib", + SIZETOOL="avr-size", + + ARFLAGS=["rc"], + + SIZEPROGREGEXP=r"^(?:\.text|\.data|\.bootloader)\s+([0-9]+).*", + SIZEDATAREGEXP=r"^(?:\.data|\.bss|\.noinit)\s+([0-9]+).* ", + SIZEEEPROMREGEXP=r"^(?:\.eeprom)\s+([0-9]+).*", + SIZECHECKCMD="$SIZETOOL -A -d $SOURCES", + SIZEPRINTCMD='$SIZETOOL --mcu=$BOARD_MCU -C -d $SOURCES', + + UPLOADER="avrdude", + UPLOADERFLAGS=[ + "-p", "$BOARD_MCU", "-C", + join(env.PioPlatform().get_package_dir("tool-avrdude-megaavr") or "", + "avrdude.conf"), "-c", "$UPLOAD_PROTOCOL", "-D", "-V" + ], + + PROGSUFFIX=".elf" +) + +env.Append( + BUILDERS=dict( + ElfToBin=Builder( + action=env.VerboseAction(" ".join([ + "$OBJCOPY", + "-O", + "binary", + "-R", + ".eeprom", + "$SOURCES", + "$TARGET" + ]), "Building $TARGET"), + suffix=".bin" + ), + + ElfToEep=Builder( + action=env.VerboseAction(" ".join([ + "$OBJCOPY", + "-O", + "ihex", + "-j", + ".eeprom", + '--set-section-flags=.eeprom="alloc,load"', + "--no-change-warnings", + "--change-section-lma", + ".eeprom=0", + "$SOURCES", + "$TARGET" + ]), "Building $TARGET"), + suffix=".eep" + ), + + ElfToHex=Builder( + action=env.VerboseAction(" ".join([ + "$OBJCOPY", + "-O", + "ihex", + "-R", + ".eeprom", + "$SOURCES", + "$TARGET" + ]), "Building $TARGET"), + suffix=".hex" + ) + ) +) + +# Allow user to override via pre:script +if env.get("PROGNAME", "program") == "program": + env.Replace(PROGNAME="firmware") + +if not env.get("PIOFRAMEWORK"): + env.SConscript("frameworks/_bare.py", exports="env") + +# +# Target: Build executable and linkable firmware +# + +target_elf = None +if "nobuild" in COMMAND_LINE_TARGETS: + target_elf = join("$BUILD_DIR", "${PROGNAME}.elf") + target_firm = join("$BUILD_DIR", "${PROGNAME}.hex") +else: + target_elf = env.BuildProgram() + target_firm = env.ElfToHex(join("$BUILD_DIR", "${PROGNAME}"), target_elf) + +AlwaysBuild(env.Alias("nobuild", target_firm)) +target_buildprog = env.Alias("buildprog", target_firm, target_firm) + +# +# Target: Print binary size +# + +target_size = env.Alias( + "size", target_elf, + env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE")) +AlwaysBuild(target_size) + +# +# Target: Upload by default .hex file +# + +upload_protocol = env.subst("$UPLOAD_PROTOCOL") + +if upload_protocol == "custom": + upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] +elif upload_protocol == "xplainedmini_updi": + env.Append(UPLOADERFLAGS=["-P", "usb", "-e", "-b", "$UPLOAD_SPEED"]) + upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] +else: + upload_actions = [ + env.VerboseAction(BeforeUpload, "Looking for upload port..."), + env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE") + ] + +if int(ARGUMENTS.get("PIOVERBOSE", 0)): + env.Prepend(UPLOADERFLAGS=["-v"]) + +upload_cmd = ["-U", "flash:w:$SOURCES:i"] + +if "FUSES_CMD" in env: + upload_cmd.append(env.get("FUSES_CMD")) + +if "BOOTLOADER_CMD" in env: + upload_cmd.append(env.get("BOOTLOADER_CMD")) + +env.Replace( + UPLOADCMD='$UPLOADER $UPLOADERFLAGS %s' % " ".join(upload_cmd)) + +AlwaysBuild(env.Alias("upload", target_firm, upload_actions)) + +# +# Target: Upload firmware using external programmer +# + +target_program = env.Alias( + "program", target_firm, + env.VerboseAction("$UPLOADCMD", "Programming $SOURCE")) +AlwaysBuild(target_program) + +# +# Setup default targets +# + +Default([target_buildprog, target_size]) diff --git a/examples/arduino-blink/.gitignore b/examples/arduino-blink/.gitignore new file mode 100644 index 0000000..6c69f4c --- /dev/null +++ b/examples/arduino-blink/.gitignore @@ -0,0 +1,2 @@ +.pioenvs +.piolibdeps diff --git a/examples/arduino-blink/.travis.yml b/examples/arduino-blink/.travis.yml new file mode 100644 index 0000000..7c486f1 --- /dev/null +++ b/examples/arduino-blink/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose 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 +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be 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 +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/arduino-blink/README.rst b/examples/arduino-blink/README.rst new file mode 100644 index 0000000..0f9a902 --- /dev/null +++ b/examples/arduino-blink/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2019-present PlatformIO + 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 Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-atmelmegaavr/examples/arduino-blink + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e uno_wifi_rev2 + + # Upload firmware for the specific environment + > platformio run -e uno_wifi_rev2 --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/arduino-blink/include/README b/examples/arduino-blink/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/arduino-blink/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/arduino-blink/lib/README b/examples/arduino-blink/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/arduino-blink/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/arduino-blink/platformio.ini b/examples/arduino-blink/platformio.ini new file mode 100644 index 0000000..0672aa4 --- /dev/null +++ b/examples/arduino-blink/platformio.ini @@ -0,0 +1,18 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[env:uno_wifi_rev2] +platform = atmelmegaavr +framework = arduino +board = uno_wifi_rev2 + +[env:nano_every] +platform = atmelmegaavr +framework = arduino +board = nano_every diff --git a/examples/arduino-blink/src/Blink.cpp b/examples/arduino-blink/src/Blink.cpp new file mode 100644 index 0000000..e99d8b0 --- /dev/null +++ b/examples/arduino-blink/src/Blink.cpp @@ -0,0 +1,25 @@ +/* + * Blink + * Turns on an LED on for one second, + * then off for one second, repeatedly. + */ + +#include + +void setup() +{ + // initialize LED digital pin as an output. + pinMode(LED_BUILTIN, OUTPUT); +} + +void loop() +{ + // turn the LED on (HIGH is the voltage level) + digitalWrite(LED_BUILTIN, HIGH); + // wait for a second + delay(1000); + // turn the LED off by making the voltage LOW + digitalWrite(LED_BUILTIN, LOW); + // wait for a second + delay(1000); +} diff --git a/examples/arduino-blink/test/README b/examples/arduino-blink/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/arduino-blink/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/examples/arduino-external-libs/.gitignore b/examples/arduino-external-libs/.gitignore new file mode 100644 index 0000000..6c69f4c --- /dev/null +++ b/examples/arduino-external-libs/.gitignore @@ -0,0 +1,2 @@ +.pioenvs +.piolibdeps diff --git a/examples/arduino-external-libs/.travis.yml b/examples/arduino-external-libs/.travis.yml new file mode 100644 index 0000000..7c486f1 --- /dev/null +++ b/examples/arduino-external-libs/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose 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 +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be 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 +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/arduino-external-libs/README.rst b/examples/arduino-external-libs/README.rst new file mode 100644 index 0000000..5ddeceb --- /dev/null +++ b/examples/arduino-external-libs/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2019-present PlatformIO + 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 Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-atmelmegaavr/examples/arduino-external-libs + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e uno_wifi_rev2 + + # Upload firmware for the specific environment + > platformio run -e uno_wifi_rev2 --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/arduino-external-libs/include/README b/examples/arduino-external-libs/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/arduino-external-libs/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/arduino-external-libs/lib/README b/examples/arduino-external-libs/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/arduino-external-libs/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/arduino-external-libs/platformio.ini b/examples/arduino-external-libs/platformio.ini new file mode 100644 index 0000000..5a86faf --- /dev/null +++ b/examples/arduino-external-libs/platformio.ini @@ -0,0 +1,26 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[common] +lib_deps = + SPI + Adafruit 9DOF Library + Ethernet + +[env:uno_wifi_rev2] +platform = atmelmegaavr +framework = arduino +board = uno_wifi_rev2 +lib_deps = ${common.lib_deps} + +[env:nano_every] +platform = atmelmegaavr +framework = arduino +board = nano_every +lib_deps = ${common.lib_deps} diff --git a/examples/arduino-external-libs/src/main.cpp b/examples/arduino-external-libs/src/main.cpp new file mode 100644 index 0000000..77388dd --- /dev/null +++ b/examples/arduino-external-libs/src/main.cpp @@ -0,0 +1,109 @@ +#include +#include +#include +#include +#include + +/* Assign a unique ID to the sensors */ +Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301); +Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(30302); +Adafruit_L3GD20_Unified gyro = Adafruit_L3GD20_Unified(20); + +void displaySensorDetails(void) +{ + sensor_t sensor; + + accel.getSensor(&sensor); + Serial.println(F("----------- ACCELEROMETER ----------")); + Serial.print (F("Sensor: ")); Serial.println(sensor.name); + Serial.print (F("Driver Ver: ")); Serial.println(sensor.version); + Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id); + Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F(" m/s^2")); + Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F(" m/s^2")); + Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F(" m/s^2")); + Serial.println(F("------------------------------------")); + Serial.println(F("")); + + gyro.getSensor(&sensor); + Serial.println(F("------------- GYROSCOPE -----------")); + Serial.print (F("Sensor: ")); Serial.println(sensor.name); + Serial.print (F("Driver Ver: ")); Serial.println(sensor.version); + Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id); + Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F(" rad/s")); + Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F(" rad/s")); + Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F(" rad/s")); + Serial.println(F("------------------------------------")); + Serial.println(F("")); + + mag.getSensor(&sensor); + Serial.println(F("----------- MAGNETOMETER -----------")); + Serial.print (F("Sensor: ")); Serial.println(sensor.name); + Serial.print (F("Driver Ver: ")); Serial.println(sensor.version); + Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id); + Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F(" uT")); + Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F(" uT")); + Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F(" uT")); + Serial.println(F("------------------------------------")); + Serial.println(F("")); + + delay(500); +} + +void setup(void) +{ + Serial.begin(115200); + Serial.println(F("Adafruit 9DOF Tester")); Serial.println(""); + + /* Initialise the sensors */ + if(!accel.begin()) + { + /* There was a problem detecting the ADXL345 ... check your connections */ + Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!")); + while(1); + } + if(!mag.begin()) + { + /* There was a problem detecting the LSM303 ... check your connections */ + Serial.println("Ooops, no LSM303 detected ... Check your wiring!"); + while(1); + } + if(!gyro.begin()) + { + /* There was a problem detecting the L3GD20 ... check your connections */ + Serial.print("Ooops, no L3GD20 detected ... Check your wiring or I2C ADDR!"); + while(1); + } + + /* Display some basic information on this sensor */ + displaySensorDetails(); +} + +void loop(void) +{ + /* Get a new sensor event */ + sensors_event_t event; + + /* Display the results (acceleration is measured in m/s^2) */ + accel.getEvent(&event); + Serial.print(F("ACCEL ")); + Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" "); + Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" "); + Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" ");Serial.println("m/s^2 "); + + /* Display the results (magnetic vector values are in micro-Tesla (uT)) */ + mag.getEvent(&event); + Serial.print(F("MAG ")); + Serial.print("X: "); Serial.print(event.magnetic.x); Serial.print(" "); + Serial.print("Y: "); Serial.print(event.magnetic.y); Serial.print(" "); + Serial.print("Z: "); Serial.print(event.magnetic.z); Serial.print(" ");Serial.println("uT"); + + /* Display the results (gyrocope values in rad/s) */ + gyro.getEvent(&event); + Serial.print(F("GYRO ")); + Serial.print("X: "); Serial.print(event.gyro.x); Serial.print(" "); + Serial.print("Y: "); Serial.print(event.gyro.y); Serial.print(" "); + Serial.print("Z: "); Serial.print(event.gyro.z); Serial.print(" ");Serial.println("rad/s "); + + Serial.println(F("")); + delay(1000); +} \ No newline at end of file diff --git a/examples/arduino-external-libs/test/README b/examples/arduino-external-libs/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/arduino-external-libs/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/examples/arduino-internal-libs/.gitignore b/examples/arduino-internal-libs/.gitignore new file mode 100644 index 0000000..6c69f4c --- /dev/null +++ b/examples/arduino-internal-libs/.gitignore @@ -0,0 +1,2 @@ +.pioenvs +.piolibdeps diff --git a/examples/arduino-internal-libs/.travis.yml b/examples/arduino-internal-libs/.travis.yml new file mode 100644 index 0000000..7c486f1 --- /dev/null +++ b/examples/arduino-internal-libs/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose 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 +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be 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 +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/arduino-internal-libs/README.rst b/examples/arduino-internal-libs/README.rst new file mode 100644 index 0000000..9650226 --- /dev/null +++ b/examples/arduino-internal-libs/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2019-present PlatformIO + 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 Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-atmelmegaavr/examples/arduino-internal-libs + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e uno_wifi_rev2 + + # Upload firmware for the specific environment + > platformio run -e uno_wifi_rev2 --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/arduino-internal-libs/include/README b/examples/arduino-internal-libs/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/arduino-internal-libs/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/arduino-internal-libs/lib/README b/examples/arduino-internal-libs/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/arduino-internal-libs/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/arduino-internal-libs/platformio.ini b/examples/arduino-internal-libs/platformio.ini new file mode 100644 index 0000000..ab99066 --- /dev/null +++ b/examples/arduino-internal-libs/platformio.ini @@ -0,0 +1,25 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[common] +lib_deps = + SPI + Ethernet + +[env:uno_wifi_rev2] +platform = atmelmegaavr +framework = arduino +board = uno_wifi_rev2 +lib_deps = ${common.lib_deps} + +[env:nano_every] +platform = atmelmegaavr +framework = arduino +board = nano_every +lib_deps = ${common.lib_deps} diff --git a/examples/arduino-internal-libs/src/ChatServer.ino b/examples/arduino-internal-libs/src/ChatServer.ino new file mode 100644 index 0000000..11a08ac --- /dev/null +++ b/examples/arduino-internal-libs/src/ChatServer.ino @@ -0,0 +1,81 @@ +/* + Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + Using an Arduino Wiznet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + * Analog inputs attached to pins A0 through A5 (optional) + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + + */ + +#include +#include +#include + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network. +// gateway and subnet are optional: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 0, 0); + + +// telnet defaults to port 23 +EthernetServer server(23); +boolean alreadyConnected = false; // whether or not the client was connected previously + +void setup() { + // initialize the ethernet device + Ethernet.begin(mac, ip, gateway, subnet); + // start listening for clients + server.begin(); + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + + Serial.print("Chat server address:"); + Serial.println(Ethernet.localIP()); +} + +void loop() { + // wait for a new client: + EthernetClient client = server.available(); + + // when the client sends the first byte, say hello: + if (client) { + if (!alreadyConnected) { + // clead out the input buffer: + client.flush(); + Serial.println("We have a new client"); + client.println("Hello, client!"); + alreadyConnected = true; + } + + if (client.available() > 0) { + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.write(thisChar); + } + } +} + + + diff --git a/examples/arduino-internal-libs/test/README b/examples/arduino-internal-libs/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/arduino-internal-libs/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/examples/native-blink/.gitignore b/examples/native-blink/.gitignore new file mode 100644 index 0000000..6c69f4c --- /dev/null +++ b/examples/native-blink/.gitignore @@ -0,0 +1,2 @@ +.pioenvs +.piolibdeps diff --git a/examples/native-blink/.travis.yml b/examples/native-blink/.travis.yml new file mode 100644 index 0000000..7c486f1 --- /dev/null +++ b/examples/native-blink/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose 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 +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be 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 +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/native-blink/README.rst b/examples/native-blink/README.rst new file mode 100644 index 0000000..443aaec --- /dev/null +++ b/examples/native-blink/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2019-present PlatformIO + 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 Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-atmelmegaavr/examples/native-blink + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e uno_wifi_rev2 + + # Upload firmware for the specific environment + > platformio run -e uno_wifi_rev2 --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/native-blink/include/README b/examples/native-blink/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/examples/native-blink/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/native-blink/lib/README b/examples/native-blink/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/examples/native-blink/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/native-blink/platformio.ini b/examples/native-blink/platformio.ini new file mode 100644 index 0000000..e1cb18c --- /dev/null +++ b/examples/native-blink/platformio.ini @@ -0,0 +1,16 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[env:uno_wifi_rev2] +platform = atmelmegaavr +board = uno_wifi_rev2 + +[env:nano_every] +platform = atmelmegaavr +board = nano_every diff --git a/examples/native-blink/src/main.c b/examples/native-blink/src/main.c new file mode 100644 index 0000000..f39eb4f --- /dev/null +++ b/examples/native-blink/src/main.c @@ -0,0 +1,31 @@ +/** + * Copyright (C) PlatformIO + * See LICENSE for details. + */ + +#include + +int main (void) +{ + /* Configure SW0 as input */ + PORTB.DIRCLR = PIN2_bm; + /* Configure LED0 pin as output */ + PORTB.DIRSET = PIN5_bm; + + while (1) + { + /* Check the status of SW0 */ + /* 0: Pressed */ + if (!(PORTB.IN & (PIN2_bm))) + { + /* LED0 on */ + PORTB.OUTSET = PIN5_bm; + } + /* 1: Released */ + else + { + /* LED0 off */ + PORTB.OUTCLR = PIN5_bm; + } + } +} diff --git a/examples/native-blink/test/README b/examples/native-blink/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/examples/native-blink/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/platform.json b/platform.json new file mode 100644 index 0000000..e32df63 --- /dev/null +++ b/platform.json @@ -0,0 +1,42 @@ +{ + "name": "atmelmegaavr", + "title": "Atmel megaAVR", + "description": "8-bit MCUs Built for Real-time Control with Core Independent Peripherals combining intelligent hardware peripherals along with the low-power capability of an AVR core, megaAVR microcontrollers (MCUs) broaden the effectiveness of your real-time control systems.", + "url": "https://www.microchip.com/design-centers/8-bit/avr-mcus/device-selection/atmega4809", + "homepage": "http://platformio.org/platforms/atmelmegaavr", + "license": "Apache-2.0", + "engines": { + "platformio": "<5" + }, + "repository": { + "type": "git", + "url": "https://github.com/platformio/platform-atmelmegaavr.git" + }, + "version": "1.0.0", + "packageRepositories": [ + "https://dl.bintray.com/platformio/dl-packages/manifest.json", + "http://dl.platformio.org/packages/manifest.json" + ], + "frameworks": { + "arduino": { + "package": "framework-arduino-megaavr", + "script": "builder/frameworks/arduino.py" + } + }, + "packages": { + "toolchain-atmelavr": { + "type": "toolchain", + "version": "~1.70300.0" + }, + "framework-arduino-megaavr": { + "type": "framework", + "optional": true, + "version": "~1.8.5" + }, + "tool-avrdude-megaavr": { + "type": "uploader", + "optional": true, + "version": "~1.60300.0" + } + } +}