From d82ba9ff7b18dba6467471c11e8ecf5fff495c3d Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 17 Feb 2023 13:47:26 +1300 Subject: [PATCH 01/23] chore(PlatformIO): Initial commit on PlatformIO integration. --- .gitattributes | 2 +- .gitignore | 1 + include/README | 39 +++++++++++++++++++++++++++++++++++++++ lib/README | 46 ++++++++++++++++++++++++++++++++++++++++++++++ platformio.ini | 14 ++++++++++++++ test/README | 11 +++++++++++ 6 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 include/README create mode 100644 lib/README create mode 100644 platformio.ini create mode 100644 test/README diff --git a/.gitattributes b/.gitattributes index 84c69ed0..1a7c36f1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,7 @@ *.c text eol=lf *.cpp text eol=lf *.h text eol=lf -*.ino text eol=lf linguist-language=c++ +*.ini text eol=lf *.md text eol=lf *.properties text eol=lf *.txt text eol=lf diff --git a/.gitignore b/.gitignore index 94af1db5..07b728f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Artefacts for compiling the code /build/ +/.pio/ # Artefacts for Visual Studio Code /.vscode/ diff --git a/include/README b/include/README new file mode 100644 index 00000000..194dcd43 --- /dev/null +++ b/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/lib/README b/lib/README new file mode 100644 index 00000000..6debab1e --- /dev/null +++ b/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/platformio.ini b/platformio.ini new file mode 100644 index 00000000..3e8aa78d --- /dev/null +++ b/platformio.ini @@ -0,0 +1,14 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:adafruit_metro_m4] +platform = atmelsam +board = adafruit_metro_m4 +framework = arduino diff --git a/test/README b/test/README new file mode 100644 index 00000000..9b1e87bc --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner 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 PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html From 99b4c6361cf135d8edd2c263a2e39f707d0941e5 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 17 Feb 2023 13:48:58 +1300 Subject: [PATCH 02/23] chore(PlatformIO): Rename channels.ino to channels.cpp --- .../channels.ino => lib/CRSFforArduino/examples/channels.cpp | 1 + 1 file changed, 1 insertion(+) rename examples/channels/channels.ino => lib/CRSFforArduino/examples/channels.cpp (99%) diff --git a/examples/channels/channels.ino b/lib/CRSFforArduino/examples/channels.cpp similarity index 99% rename from examples/channels/channels.ino rename to lib/CRSFforArduino/examples/channels.cpp index 7e47d803..afced07b 100644 --- a/examples/channels/channels.ino +++ b/lib/CRSFforArduino/examples/channels.cpp @@ -87,6 +87,7 @@ * */ +#include #include "CRSFforArduino.h" CRSFforArduino crsf = CRSFforArduino(&Serial1); From 9912bdcd890a408b14467a452b507e95326e754a Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 17 Feb 2023 13:50:20 +1300 Subject: [PATCH 03/23] chore(PlatformIO): Move CRSFforArduino source files into lib subfolder. --- {src => lib/CRSFforArduino/src}/CRSFforArduino.cpp | 2 +- {src => lib/CRSFforArduino/src}/CRSFforArduino.h | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename {src => lib/CRSFforArduino/src}/CRSFforArduino.cpp (99%) rename {src => lib/CRSFforArduino/src}/CRSFforArduino.h (100%) diff --git a/src/CRSFforArduino.cpp b/lib/CRSFforArduino/src/CRSFforArduino.cpp similarity index 99% rename from src/CRSFforArduino.cpp rename to lib/CRSFforArduino/src/CRSFforArduino.cpp index 2fed52cc..907faa07 100644 --- a/src/CRSFforArduino.cpp +++ b/lib/CRSFforArduino/src/CRSFforArduino.cpp @@ -170,7 +170,7 @@ bool CRSFforArduino::update() // Check if the packet is a CRSF frame. if (_crsfFrame.frame.deviceAddress == CRSF_ADDRESS_FLIGHT_CONTROLLER) { - uint8_t payloadSize = _crsfFrame.frame.frameLength - 2; + // uint8_t payloadSize = _crsfFrame.frame.frameLength - 2; // Check if the packet is a CRSF RC frame. if (_crsfFrame.frame.type == CRSF_FRAMETYPE_RC_CHANNELS_PACKED) diff --git a/src/CRSFforArduino.h b/lib/CRSFforArduino/src/CRSFforArduino.h similarity index 100% rename from src/CRSFforArduino.h rename to lib/CRSFforArduino/src/CRSFforArduino.h From e2c40610443e7805aa637b3a5a414c688f63d3e7 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 17 Feb 2023 13:52:14 +1300 Subject: [PATCH 04/23] chore(PlatformIO): Use main.cpp for development purposes. All development of my library is conducted in this file & it is located in the src subfolder. --- src/main.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/main.cpp diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 00000000..a8dee2eb --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,47 @@ +#include +#include "CRSFforArduino.h" + +CRSFforArduino crsf = CRSFforArduino(&Serial1); + +void setup() +{ + // Initialize the serial port & wait for the port to open. + Serial.begin(115200); + while (!Serial) + { + ; + } + + // Initialize the CRSFforArduino library. + crsf.begin(); + + // Show the user that the sketch is ready. + Serial.println("Channels Example"); + delay(1000); + Serial.println("Ready"); + delay(1000); +} + +void loop() +{ + if (crsf.update()) + { + Serial.print("RC Channels "); + } +} From e20fac04b2caf849f4542781e3f9f132dadf3002 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 17 Feb 2023 13:58:36 +1300 Subject: [PATCH 05/23] chore(source code): Format main.cpp & channels.cpp --- lib/CRSFforArduino/examples/channels.cpp | 2 +- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/CRSFforArduino/examples/channels.cpp b/lib/CRSFforArduino/examples/channels.cpp index afced07b..3b400708 100644 --- a/lib/CRSFforArduino/examples/channels.cpp +++ b/lib/CRSFforArduino/examples/channels.cpp @@ -87,7 +87,7 @@ * */ -#include +#include "Arduino.h" #include "CRSFforArduino.h" CRSFforArduino crsf = CRSFforArduino(&Serial1); diff --git a/src/main.cpp b/src/main.cpp index a8dee2eb..8f82450a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include +#include "Arduino.h" #include "CRSFforArduino.h" CRSFforArduino crsf = CRSFforArduino(&Serial1); From 5dea855a4960a50c6da7e8d114a65426cb299ac9 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 17 Feb 2023 14:26:10 +1300 Subject: [PATCH 06/23] docs(readme): Update README. Abridge discontinuation notice. --- README.md | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 40867844..1e3a5f7a 100644 --- a/README.md +++ b/README.md @@ -9,30 +9,9 @@ Cassandra "ZZ Cat" Robinson -## Discontinuation of Arduino IDE +## Warnings -Arduino IDE support in Visual Studio Code is being discontinued. -The Visual Studo Code extension that adds support for Arduino is discontinuing support for the Arduino IDE. -This means that I too am discontinuing support for the Arduino IDE in all of my projects - starting with CRSF for Arduino. -The good news is that my library is in its early stages of development, I have not yet made any official releases of my library, & it isn't being widely used yet. This makes it easier for me to adapt to the new changes. - -Does this mean that I may need to rebrand my library? Yes. -I originally created my library for use within the Arduino IDE (assuming 1.8, here. Not 2.0) without being aware of the fact that the IDE itself had already reached the end of its life, & Arduino themselves had discontinued it. -If I kept the name "CRSF for Arduino" moving forward, this would imply that you can still use it in the (now discontinued) Arduino IDE. Thus, sending the wrong message about what my library is compatible with. - -What of my two existing branches involving telemetry? -Well... for starters, I rebased Telemetry-Feedback & during that rebase, I somehow managed to completely obliterate my code for telemetry feedback. == -I don't know how I did that, but it happened. I was already planning on refactoring it anyway, so now I am having to rewrite it entirely. - -So, where to, from here? -I am no longer using the Arduino IDE. -In fact, I haven't actually used the Arduino IDE itself in a _very_ long time. All of my development is done in Visual Studio Code, these days. For my Arduino-related projects, I have been using an extension in Visual Studio Code that adds support for the Arduino IDE. The developers of this extension are discontinuing support for the Arduino IDE altogether, & they have no plans to introduce support for version 2.0 of the Arduino IDE. - -It _just so happens_ that over the last two days, I have been conducting preliminary tests with PlatformIO & learning how to develop with that. PlatformIO is 100% platform agnostic, has its own built-in debugging system, it even has its own Continuous Integration/Continuous Deployment (I have been chasing after decent CI/CD ever since I started my project), & it has everything that I need & nothing that I don't need. -At this point, I am like "Where has this been all my life & why am I not already using it?" -Using PlatformIO is a no-brainer, for me. So, there you go. From 2023-02-17 10:48 Hrs NZDT, I am using PlatformIO as my IDE of choice for developing my embedded systems projects. - -## Warning +### This is not yet ready for prime time release CRSFforArduino is undergoing active development & is not yet ready for prime time release. If you choose to use CRSFforArduino in its current state, do so at your own risk. @@ -42,6 +21,11 @@ Fear not! I am working on this library (aside from flying my helicopters & helpi If you have spotted any bugs, something isn't working the way it should, or you have any suggestions on what you want to see in CRSFforArduino, don't hesitate to open an Issue. The Discussions tab is also open, so if you want to chat to me about my library, feel free to do so there. +### Arduino IDE is discontinued + +Arduino IDE support in Visual Studio Code is discontinued. +As of 2023-02-17 10:48 Hrs NZDT, I am using PlatformIO as my IDE of choice for development. + ## Description Traditional PWM RC receivers are becoming a thing of the past & (by extension) are getting harder & harder to come by. From bef901965aff6ecec8a23b823f9337f364e616fe Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 17 Feb 2023 14:57:52 +1300 Subject: [PATCH 07/23] chore(gitignore): Ignore README files Ignore README files in include, lib & tests subfolders. --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 07b728f7..6776327d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,8 @@ # Development artefacts /.development + +# PlatformIO specific README files +/include/README +/lib/README +/test/README From 9ea31cd464153ee2234f837afa295a9e4c2fe6c5 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 17 Feb 2023 15:10:52 +1300 Subject: [PATCH 08/23] chore(gitignore): Remove all references to the Arduino IDE. --- .gitignore | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitignore b/.gitignore index 6776327d..1ca9ffc4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,9 @@ # Artefacts for compiling the code -/build/ /.pio/ # Artefacts for Visual Studio Code /.vscode/ -# Development artefacts -/.development - # PlatformIO specific README files /include/README /lib/README From dde2365ed4b8ffe804aab744d4d02631b64217f2 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 17 Feb 2023 15:34:35 +1300 Subject: [PATCH 09/23] chore(gitignore): Remove leading forward slashes. --- .gitignore | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 1ca9ffc4..72f857b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,10 @@ # Artefacts for compiling the code -/.pio/ +.pio/ # Artefacts for Visual Studio Code -/.vscode/ +.vscode/ # PlatformIO specific README files -/include/README -/lib/README -/test/README +include/README +lib/README +test/README From b65fc9499bfb8bab67bf9d2b4a6e9f4846e6ea6b Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 17 Feb 2023 16:04:28 +1300 Subject: [PATCH 10/23] chore(platformio): Add JLink debug tool. --- platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/platformio.ini b/platformio.ini index 3e8aa78d..60129344 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,3 +12,4 @@ platform = atmelsam board = adafruit_metro_m4 framework = arduino +debug_tool = jlink From b8a7f304e32c73d33065fc38ddd2987d474b123e Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Fri, 17 Feb 2023 19:11:36 +1300 Subject: [PATCH 11/23] build(config): Force sam-ba for firmware updates. This allows the firmware update protocol to be overridden, if the default somehow fails. --- platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/platformio.ini b/platformio.ini index 60129344..20a8994b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,4 +12,5 @@ platform = atmelsam board = adafruit_metro_m4 framework = arduino +upload_protocol = sam-ba debug_tool = jlink From b4fe99ebc36238a840d4314a1bd14452f2b8f3f6 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sat, 18 Feb 2023 12:52:37 +1300 Subject: [PATCH 12/23] build(platformio): Add compile options for optimizing code. --- platformio.ini | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/platformio.ini b/platformio.ini index 20a8994b..2e7490bb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,6 +11,31 @@ [env:adafruit_metro_m4] platform = atmelsam board = adafruit_metro_m4 +board_build.mcu = samd51j19a +; CPU frequency, in Hz: +; 120000000L = 120 MHz (Default) +; 150000000L = 150 MHz (Overclock) +; 180000000L = 180 MHz (Overclock) +; 200000000L = 200 MHz (Maximum Overclock) +board_build.f_cpu = 120000000L +build_flags = + ; Compile optimizations: + ; -Os = Standard Arduino optimization. + ; -O2 = Fast code, but large size. + ; -O3 = Faster code, but larger size. + ; -Ofast = Fastest code, but larger size. + ; -Ofast -funroll-loops = Fastest code, largest size, & with loop unrolling. AKA "Here be dragons". + -Os + ; Exceptions: + ; -fno-exceptions = Disable exceptions. (Default) + ; -fexceptions = Enable exceptions. BEWARE: This may crash your code when exceptions are thrown! + -fno-exceptions + ; TinyUSB: + ; -DUSE_TINYUSB = Enable TinyUSB. (Default) (Requires TinyUSB to be installed) + ; -DUSE_TINYUSB framework = arduino +; Upload protocol: +; sam-ba = Native USB (Default) +; jlink = J-Link Debugger upload_protocol = sam-ba debug_tool = jlink From 690b5931159b2a4868d09a93df54c37280149ecb Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sat, 18 Feb 2023 14:33:00 +1300 Subject: [PATCH 13/23] chore: Remove obsolete library.PROPERTIES --- .gitattributes | 1 - library.PROPERTIES | 11 ----------- 2 files changed, 12 deletions(-) delete mode 100644 library.PROPERTIES diff --git a/.gitattributes b/.gitattributes index 1a7c36f1..ccaaf184 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,6 +3,5 @@ *.h text eol=lf *.ini text eol=lf *.md text eol=lf -*.properties text eol=lf *.txt text eol=lf *.yml text eol=lf diff --git a/library.PROPERTIES b/library.PROPERTIES deleted file mode 100644 index 0c60ac5c..00000000 --- a/library.PROPERTIES +++ /dev/null @@ -1,11 +0,0 @@ -name=CRSF for Arduino -version=0.1.0 -author=Cassandra Robinson -maintainer=Cassandra Robinson -sentence=Make PWM RC receivers a thing of the past with CRSF for Arduino! -paragraph=CRSF (Better known as The Crossfire Protocol) is the de-facto standard for RC nowadays, & it is time to bring it to the world of Arduino! This library is compatible with any Arduino board that has either a SAMD21 or a SAMD51 processor (EG Arduino Zero, Adafruit Feather M0, Adafruit Metro M4 etc). -category=Communication -url=https://github.com/ZZ-Cat/CRSFforArduino -architectures=samd -depends=Adafruit_ZeroDMA -includes=CRSFforArduno.h From 7f17e99290b401fc5cf92f270007bf81bff5f1ca Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sat, 18 Feb 2023 14:33:36 +1300 Subject: [PATCH 14/23] chore(platformio): Add library.json manifest file. --- .gitattributes | 1 + library.json | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 library.json diff --git a/.gitattributes b/.gitattributes index ccaaf184..3a97772d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,6 +2,7 @@ *.cpp text eol=lf *.h text eol=lf *.ini text eol=lf +*.json text eol=lf *.md text eol=lf *.txt text eol=lf *.yml text eol=lf diff --git a/library.json b/library.json new file mode 100644 index 00000000..ff682ed1 --- /dev/null +++ b/library.json @@ -0,0 +1,45 @@ +{ + "$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json", + "name": "CRSFforArduino", + "version": "0.1.0", + "description": "Arduino library for Crossfire protocol", + "keywords": [ + "adafruit", + "arduino", + "communication", + "crossfire", + "crsf", + "elrs", + "expresslrs", + "tbs", + "telemetry", + "protocol", + "remote control", + "rc" + ], + "repository": + { + "type": "git", + "url": "https://github.com/ZZ-Cat/CRSFforArduino" + }, + "authors": [ + { + "name": "Cassandra \"ZZ Cat\" Robinson", + "email": "nicad.heli.flier@gmail.com", + "maintainer": true + } + ], + "license": "GPL-3.0-or-later", + "frameworks": "arduino", + "platforms": "atmelsam", + "headers": [ + "Arduino.h", + "CRSFforArduino.h" + ], + "dependencies": + { + "adafruit/Adafruit Zero DMA Library": "@^1.1.1", + "frameworks": "arduino", + "platforms": "atmelsam" + } +} From ed52d073c5c6b89965f00deb3a3eed52c985bf88 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sun, 19 Feb 2023 11:27:40 +1300 Subject: [PATCH 15/23] chore(platformio): Sort project configurations into alphabetical order. --- platformio.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index 2e7490bb..060b0979 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,6 @@ ; https://docs.platformio.org/page/projectconf.html [env:adafruit_metro_m4] -platform = atmelsam board = adafruit_metro_m4 board_build.mcu = samd51j19a ; CPU frequency, in Hz: @@ -33,9 +32,10 @@ build_flags = ; TinyUSB: ; -DUSE_TINYUSB = Enable TinyUSB. (Default) (Requires TinyUSB to be installed) ; -DUSE_TINYUSB +debug_tool = jlink framework = arduino +platform = atmelsam ; Upload protocol: ; sam-ba = Native USB (Default) ; jlink = J-Link Debugger upload_protocol = sam-ba -debug_tool = jlink From a00dd84e5f7ee75d5bb6d2facc90a48d69dfc67e Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sun, 19 Feb 2023 11:28:29 +1300 Subject: [PATCH 16/23] chore(platformio): Add Adafruit Zero DMA dependency to platformio.ini. --- platformio.ini | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platformio.ini b/platformio.ini index 060b0979..d3f70292 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,6 +8,10 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[common] +lib_deps = + adafruit/Adafruit Zero DMA Library@^1.1.1 + [env:adafruit_metro_m4] board = adafruit_metro_m4 board_build.mcu = samd51j19a @@ -34,6 +38,7 @@ build_flags = ; -DUSE_TINYUSB debug_tool = jlink framework = arduino +lib_deps = ${common.lib_deps} platform = atmelsam ; Upload protocol: ; sam-ba = Native USB (Default) From 7672d1685d8bef60fb27bdb7ad3e4ac2cf4c8582 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sun, 19 Feb 2023 11:34:05 +1300 Subject: [PATCH 17/23] chore(platformio): Move library manifest into lib/CRSFforArduino directory --- library.json => lib/CRSFforArduino/library.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename library.json => lib/CRSFforArduino/library.json (100%) diff --git a/library.json b/lib/CRSFforArduino/library.json similarity index 100% rename from library.json rename to lib/CRSFforArduino/library.json From 1a9896d6fbc627e0d29fa281a00372bf7e8027eb Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sun, 19 Feb 2023 11:50:35 +1300 Subject: [PATCH 18/23] chore(rc channels): Move RC channels into lib/CRSFforArduino/examples/channels directory. This is one of the example files, & its configuration is set in the platformio.ini file. If you want to flash a different example, you need to change this directory to match that of where your example is located. --- lib/CRSFforArduino/examples/{ => channels}/channels.cpp | 2 +- platformio.ini | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) rename lib/CRSFforArduino/examples/{ => channels}/channels.cpp (99%) diff --git a/lib/CRSFforArduino/examples/channels.cpp b/lib/CRSFforArduino/examples/channels/channels.cpp similarity index 99% rename from lib/CRSFforArduino/examples/channels.cpp rename to lib/CRSFforArduino/examples/channels/channels.cpp index 3b400708..af8d76c6 100644 --- a/lib/CRSFforArduino/examples/channels.cpp +++ b/lib/CRSFforArduino/examples/channels/channels.cpp @@ -105,7 +105,7 @@ void setup() crsf.begin(); // Show the user that the sketch is ready. - Serial.println("Channels Example"); + Serial.println("RC Channels Example"); delay(1000); Serial.println("Ready"); delay(1000); diff --git a/platformio.ini b/platformio.ini index d3f70292..12f12fb3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -44,3 +44,6 @@ platform = atmelsam ; sam-ba = Native USB (Default) ; jlink = J-Link Debugger upload_protocol = sam-ba + +[platformio] +src_dir = lib/CRSFforArduino/examples/channels From 4fc5ade29eafe8a7962bf77c09a87aa7503bd6aa Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sun, 19 Feb 2023 11:52:43 +1300 Subject: [PATCH 19/23] revert(main): Revert main.cpp back to its default appearance. --- src/main.cpp | 40 ++-------------------------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8f82450a..de1fc514 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,47 +1,11 @@ #include "Arduino.h" -#include "CRSFforArduino.h" - -CRSFforArduino crsf = CRSFforArduino(&Serial1); void setup() { - // Initialize the serial port & wait for the port to open. - Serial.begin(115200); - while (!Serial) - { - ; - } - - // Initialize the CRSFforArduino library. - crsf.begin(); - - // Show the user that the sketch is ready. - Serial.println("Channels Example"); - delay(1000); - Serial.println("Ready"); - delay(1000); + // put your setup code here, to run once: } void loop() { - if (crsf.update()) - { - Serial.print("RC Channels "); - } + // put your main code here, to run repeatedly: } From 2e2a2a90e89d5f4b0f52fe2a3279cb62c8d16198 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Sun, 19 Feb 2023 23:16:22 +1300 Subject: [PATCH 20/23] docs(readme): Update README.md --- README.md | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1e3a5f7a..287a9d0c 100644 --- a/README.md +++ b/README.md @@ -47,18 +47,31 @@ These installation instructions will be updated as soon as the transition to Pla ### Prerequisites -You need these before you can use CRSFforArduino. +You need these before you can use CRSF for Arduino. -- [Adafruit's SAMD Board Support package](https://github.com/adafruit/ArduinoCore-samd) -- [Adafruit's Zero DMA driver](https://github.com/adafruit/Adafruit_ZeroDMA) -- [Arduino's SAMD Board Support package](https://github.com/arduino/ArduinoCore-samd) -- [Arduino IDE](https://www.arduino.cc/en/software) If you are using the VSCode plugin, use the Arduino IDE version 1.8.19. Otherwise, use the very latest version of the Arduino IDE. +- [Visual Studio Code](https://code.visualstudio.com/) with the following extensions: + - [C/C++ Extensions Pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack), which includes: + - C/C++ + - C/C++ Themes + - CMake + - CMake Tools + - [PlatformIO IDE](https://platformio.org/) ### Download CRSFforArduino -1. Click the green code button & hit "Download ZIP". -2. Extract that to your libraries' directory. EG ```C:\Users\..\Documents\Arduino\libraries``` -3. Start up the Arduino IDE (or VSCode, if you're using that instead). +#### Quick-&-easy way + +- COMING SOON + +#### The "Old Skool" way + +1. Click on the green "<> Code" button. +2. Click "Download ZIP" & extract it to wherever is convenient for you. +3. Go into the CRSFforArduino folder, here is where Arduino diverges from PlatformIO. + - **Arduino IDE:** + - Go into the lib folder & copy the _CRSFforArduino_ folder to your Arduino IDE's library directory. + - **PlatformIO:** + - Go into the _top level_ CRSFforArduino folder & copy the _lib_ folder to your PlatformIO project's directory. ## How to use CRSFforArduino @@ -134,16 +147,19 @@ void loop() ### Example Sketches -In the ```examples``` folder, there is a sketch called ```channels.ino``` that I used to test this library. +In the ```examples``` folder, there is a sketch called ```channels.cpp``` that I used to test this library. It contains instructions on how to set your hardware up & how to connect your receiver to your development board. It also details binding procedures (if needed), & the channel ranges & channel order. The example sketch also demonstrates how to read RC channels data from your connected ExpressLRS receiver. +You can build this example to see how CRSF for Arduino works. + ### Flashing -1. Verify your sketch. -2. Select your com port that your development board is connected to. -3. Upload your sketch to your development board. +Flashing is a lot simpler with PlatformIO when compared to the Arduino IDE. + +1. Build your sketch ► ```pio run``` in your CLI or ```ctrl+alt+b``` on your keyboard. +2. Flash your sketch ► ```pio run -t upload``` or ```ctrl+alt+u``` on your keyboard. ### Viewing RC data From f6424baeac9b41b5eef6907bfdcf7d690e68ac69 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Mon, 20 Feb 2023 13:30:53 +1300 Subject: [PATCH 21/23] chore(rc channels): Update boiler plate. Boiler Plate instructions reflect the recent shift to PlatformIO. --- .../examples/channels/channels.cpp | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/lib/CRSFforArduino/examples/channels/channels.cpp b/lib/CRSFforArduino/examples/channels/channels.cpp index af8d76c6..9bc057f4 100644 --- a/lib/CRSFforArduino/examples/channels/channels.cpp +++ b/lib/CRSFforArduino/examples/channels/channels.cpp @@ -23,31 +23,29 @@ * * @section Dependencies * - * This example sketch depends on the following libraries: - * - Adafruit_ZeroDMA (This is included with the Adafruit Metro M4 Express board package.) - * - Arduino.h (This is included with the Arduino IDE.) - * - CRSFforArduino.h + * PlatformIO will automatically install the following dependencies: + * - Adafruit ZeroDMA Library * * @section Quick Start * * 1. Connect the receiver to the Metro M4 Express using the following pinout: - * - TX pin to Metro M4 Express RX (Pin 0). - * - RX pin to Metro M4 Express TX (Pin 1). - * - GND pin to Metro M4 Express GND. - * - 5V pin to Metro M4 Express 5V. + * - TX pin to Metro M4 Express RX (Pin 0). + * - RX pin to Metro M4 Express TX (Pin 1). + * - GND pin to Metro M4 Express GND. + * - 5V pin to Metro M4 Express 5V. * 2. Connect the Metro M4 Express to your computer using a USB cable. - * 3. Select the Metro M4 Express board and the correct port in the Arduino IDE. - * - Tools > Board > Adafruit Metro M4 (SAMD51) - * - Tools > Port > COM# (where # is the port number) - * 4. Open the CRSFforArduino library example sketch channels.ino. - * - File > Examples > CRSFforArduino > channels - * 5. Upload the sketch to the Metro M4 Express. - * - Sketch > Upload - * 6. Open the Serial Monitor. - * - Tools > Serial Monitor - * 7. Set the Serial Monitor baud rate to 115200. - * 8. Set the Serial Monitor line ending to "Both NL & CR". - * 9. Turn on your transmitter. + * 3. Build the firmware: + * - Method 1: pio run + * - Method 2: ctlr+alt+B + * 4. Flash your Metro M4 Express. + * - Method 1: pio run -t upload + * - Method 2: ctlr+alt+U + * 5. Configure the Serial Monitor: + * - Port: Select the port that your Metro M4 Express is connected to. + * - Baud Rate: 115200 + * - Line Ending: Both NL & CR + * 6. Turn on your transmitter. + * 7. Click "Start Monitoring" on the Serial Monitor. * * @section Binding (Optional & only needed for the first time) * @@ -61,15 +59,15 @@ * @par TBS Crossfire: * 1. Turn on your transmitter. * 2. On your transmitter, open up the TBS Agent Lite app. - * - Radio Settings > Tools > TBS Agent Lite + * - Radio Settings > Tools > TBS Agent Lite * 3. In TBS Agent Lite, select the Micro TX & enable Binding Mode. - * - XF Micro TX > Bind > Execute + * - XF Micro TX > Bind > Execute * 4. Power on the Nano Diversity Receiver. - * - If you have already powered on the receiver, power it off and then back on again. - * - You do not need to hold the bind button on the receiver. - * - Binding will begin automatically. - * - The Status LED will turn solid green when the receiver is bound. - * - The Status LED on the Micro TX will turn solid green when the receiver is bound. + * - If you have already powered on the receiver, power it off and then back on again. + * - You do not need to hold the bind button on the receiver. + * - Binding will begin automatically. + * - The Status LED will turn solid green when the receiver is bound. + * - The Status LED on the Micro TX will turn solid green when the receiver is bound. * 5. Close TBS Agent Lite. * * @section Output From 0eb04968c09084a2a2ac732e36262c581762af6a Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Mon, 20 Feb 2023 16:28:16 +1300 Subject: [PATCH 22/23] fix(hardware): Fix board compatibility/support. Additionally, support for Adafruit's Gemma & Adafruit Crickit boards have been dropped. --- README.md | 6 +- lib/CRSFforArduino/src/CRSFforArduino.cpp | 10 +- platformio.ini | 138 +++++++++++++++++++--- 3 files changed, 124 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 287a9d0c..55d1332a 100644 --- a/README.md +++ b/README.md @@ -171,9 +171,7 @@ Flashing is a lot simpler with PlatformIO when compared to the Arduino IDE. Here is a list of target development boards CRSFforArduino is compatible with: - SAMD21 based boards: - - Adafruit Crickit M0 - Adafruit Feather M0 & variants - - Adafruit Gemma M0 - Adafruit ItsyBitsy M0 Express - Adafruit QtPy M0 - Adafruit Trinket M0 @@ -181,12 +179,12 @@ Here is a list of target development boards CRSFforArduino is compatible with: - Arduino Zero - SAMD51 based boards: - Adafruit Feather M4 Express - - Adafruit Feather M4 CAN Express + - Adafruit Grand Central M4 - Adafruit ItsyBitsy M4 Express - Adafruit Metro M4 Express - Adafruit Metro M4 Express AirLift Lite - SAME51 based boards: - - Adafruit Grand Central M4 + - Adafruit Feather M4 CAN Express Compatibility with other microcontroller boards may be added in the future, if there is demand for it. Keep in mind that this will be subject to hardware limitations of the host microcontroller itself. diff --git a/lib/CRSFforArduino/src/CRSFforArduino.cpp b/lib/CRSFforArduino/src/CRSFforArduino.cpp index 907faa07..44dff659 100644 --- a/lib/CRSFforArduino/src/CRSFforArduino.cpp +++ b/lib/CRSFforArduino/src/CRSFforArduino.cpp @@ -292,19 +292,15 @@ Sercom *CRSFforArduino::_getSercom() #if defined(__SAMD21E18A__) -/* Adafruit Gemma M0, QtPy M0 & Trinket M0. */ -#if defined(ADAFRUIT_GEMMA_M0) || defined(ADAFRUIT_QTPY_M0) || defined(ADAFRUIT_TRINKET_M0) +/* Adafruit QtPy M0 & Trinket M0. */ +#if defined(ADAFRUIT_QTPY_M0) || defined(ADAFRUIT_TRINKET_M0) sercom = SERCOM0; #endif #elif defined(__SAMD21G18A__) -/* Adafruit Crickit M0. */ -#if defined(ADAFRUIT_CRICKIT_M0) - sercom = SERCOM5; - /* Adafruit Feather M0 , Feather M0 Express, ItsyBitsy M0 & Metro M0 Express. */ -#elif defined(ADAFRUIT_FEATHER_M0) || defined(ADAFRUIT_FEATHER_M0_EXPRESS) || defined(ADAFRUIT_ITSYBITSY_M0) || \ +#if defined(ADAFRUIT_FEATHER_M0) || defined(ADAFRUIT_FEATHER_M0_EXPRESS) || defined(ADAFRUIT_ITSYBITSY_M0) || \ defined(ADAFRUIT_METRO_M0_EXPRESS) sercom = SERCOM0; diff --git a/platformio.ini b/platformio.ini index 12f12fb3..4f5f3182 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,19 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [common] -lib_deps = - adafruit/Adafruit Zero DMA Library@^1.1.1 - -[env:adafruit_metro_m4] -board = adafruit_metro_m4 -board_build.mcu = samd51j19a -; CPU frequency, in Hz: -; 120000000L = 120 MHz (Default) -; 150000000L = 150 MHz (Overclock) -; 180000000L = 180 MHz (Overclock) -; 200000000L = 200 MHz (Maximum Overclock) -board_build.f_cpu = 120000000L -build_flags = +compile_flags = ; Compile optimizations: ; -Os = Standard Arduino optimization. ; -O2 = Fast code, but large size. @@ -36,14 +24,126 @@ build_flags = ; TinyUSB: ; -DUSE_TINYUSB = Enable TinyUSB. (Default) (Requires TinyUSB to be installed) ; -DUSE_TINYUSB -debug_tool = jlink -framework = arduino -lib_deps = ${common.lib_deps} -platform = atmelsam +; CPU frequency, in Hz: +; 120000000L = 120 MHz (Default) +; 150000000L = 150 MHz (Overclock) +; 180000000L = 180 MHz (Overclock) +; 200000000L = 200 MHz (Maximum Overclock) +cpu_speed = 120000000L +debugger = jlink +example_sketch_directory = lib/CRSFforArduino/examples/channels +lib_deps = + adafruit/Adafruit Zero DMA Library@^1.1.1 ; Upload protocol: ; sam-ba = Native USB (Default) ; jlink = J-Link Debugger -upload_protocol = sam-ba +sketch_upload_protocol = sam-ba + +[env] +framework = arduino +platform = atmelsam + +; Cortex M0+ boards: +[env:adafruit_feather_m0] +board = adafruit_feather_m0 +lib_deps = ${common.lib_deps} + +[env:adafruit_feather_m0_express] +board = adafruit_feather_m0_express +lib_deps = ${common.lib_deps} + +[env:adafruit_itsybitsy_m0] +board = adafruit_itsybitsy_m0 +lib_deps = ${common.lib_deps} + +[env:adafruit_metro_m0] +board = adafruit_metro_m0 +lib_deps = ${common.lib_deps} + +[env:mkrfox1200] +board = mkrfox1200 +lib_deps = ${common.lib_deps} + +[env:mkrgsm1400] +board = mkrgsm1400 +lib_deps = ${common.lib_deps} + +[env:mkrnb1500] +board = mkrnb1500 +lib_deps = ${common.lib_deps} + +[env:mkrvidor4000] +board = mkrvidor4000 +lib_deps = ${common.lib_deps} + +[env:mkrwan1300] +board = mkrwan1300 +lib_deps = ${common.lib_deps} + +[env:mkrwan1310] +board = mkrwan1310 +lib_deps = ${common.lib_deps} + +[env:mkrwifi1010] +board = mkrwifi1010 +lib_deps = ${common.lib_deps} + +[env:mkrzero] +board = mkrzero +lib_deps = ${common.lib_deps} + +[env:zero] +board = zero +lib_deps = ${common.lib_deps} + +[env:zeroUSB] +board = zeroUSB +lib_deps = ${common.lib_deps} + +; Cortex M4F boards: +[env:adafruit_feather_m4] +board = adafruit_feather_m4 +board_build.f_cpu = ${common.cpu_speed} +build_flags = ${common.compile_flags} +lib_deps = ${common.lib_deps} +upload_protocol = ${common.sketch_upload_protocol} + +[env:adafruit_feather_m4_can] +board = adafruit_feather_m4_can +board_build.f_cpu = ${common.cpu_speed} +build_flags = ${common.compile_flags} +lib_deps = ${common.lib_deps} + +[env:adafruit_grand_central_m4] +board = adafruit_grand_central_m4 +board_build.f_cpu = ${common.cpu_speed} +build_flags = ${common.compile_flags} +debug_tool = ${common.debugger} +lib_deps = ${common.lib_deps} +upload_protocol = ${common.sketch_upload_protocol} + +[env:adafruit_itsybitsy_m4] +board = adafruit_itsybitsy_m4 +board_build.f_cpu = ${common.cpu_speed} +build_flags = ${common.compile_flags} +lib_deps = ${common.lib_deps} + +[env:adafruit_metro_m4] +board = adafruit_metro_m4 +board_build.f_cpu = ${common.cpu_speed} +build_flags = ${common.compile_flags} +debug_tool = ${common.debugger} +lib_deps = ${common.lib_deps} +upload_protocol = ${common.sketch_upload_protocol} + +[env:adafruit_metro_m4_airliftlite] +board = adafruit_metro_m4_airliftlite +board_build.f_cpu = ${common.cpu_speed} +build_flags = ${common.compile_flags} +debug_tool = ${common.debugger} +lib_deps = ${common.lib_deps} +upload_protocol = ${common.sketch_upload_protocol} [platformio] -src_dir = lib/CRSFforArduino/examples/channels +default_envs = adafruit_metro_m4 +src_dir = ${common.example_sketch_directory} From 5cd302540cb2cc9622a6a3773e485f0f355d7196 Mon Sep 17 00:00:00 2001 From: "Cassandra \"ZZ Cat\" Robinson" Date: Mon, 20 Feb 2023 16:29:22 +1300 Subject: [PATCH 23/23] docs(readme): Remove trailing whitespace. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 55d1332a..7eb1c285 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ You need these before you can use CRSF for Arduino. 3. Go into the CRSFforArduino folder, here is where Arduino diverges from PlatformIO. - **Arduino IDE:** - Go into the lib folder & copy the _CRSFforArduino_ folder to your Arduino IDE's library directory. - - **PlatformIO:** + - **PlatformIO:** - Go into the _top level_ CRSFforArduino folder & copy the _lib_ folder to your PlatformIO project's directory. ## How to use CRSFforArduino