Skip to content

Commit 810eb4a

Browse files
authored
feat: Compile Examples during CI (#80)
feat: Compile Examples during CI * Breakout ST example compilation * chore: rework examples * Ensure examples compiled with latest updates * feat: Compile for Adafruit nRF2840 Express * feat: Support Adafruit M4 Express
1 parent 72fca3d commit 810eb4a

File tree

9 files changed

+415
-123
lines changed

9 files changed

+415
-123
lines changed

.devcontainer/devcontainer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/docker-existing-dockerfile
3+
{
4+
"name": "Arduino Development Environment Dockerfile",
5+
6+
// Sets the run context to one level up instead of the .devcontainer folder.
7+
"context": "..",
8+
9+
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
10+
//"dockerFile": "../.github/actions/compile-examples/Dockerfile",
11+
"dockerFile": "../.github/actions/run-tests-in-container/Dockerfile",
12+
13+
// Set *default* container specific settings.json values on container create.
14+
"settings": {},
15+
16+
// Add the IDs of extensions you want installed when the container is created.
17+
"extensions": [
18+
"ms-vscode.cpptools",
19+
],
20+
21+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
22+
// "forwardPorts": [],
23+
// Uncomment the next line to run commands after the container is created - for example installing curl.
24+
// "postCreateCommand": "apt-get update && apt-get install -y curl",
25+
// Uncomment when using a ptrace-based debugger like C++, Go, and Rust
26+
// "runArgs": [
27+
// "--device=/dev/bus/usb/"
28+
// ],
29+
30+
// Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker.
31+
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],
32+
// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
33+
// "remoteUser": "blues"
34+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Copyright 2022 Blues Inc. All rights reserved.
2+
# Use of this source code is governed by licenses granted by the
3+
# copyright holder including that found in the LICENSE file.
4+
5+
# Build development environment
6+
# docker build --file Dockerfile.arduino-cli --tag arduino-cli .
7+
8+
# Launch development environment
9+
# docker run --entrypoint bash --interactive --rm --tty --volume "$(pwd)":/host-volume/ --workdir /host-volume/ arduino-cli
10+
11+
# Define global arguments
12+
ARG ARDUINO_CLI_VERSION=0.22.0
13+
ARG DEBIAN_FRONTEND="noninteractive"
14+
ARG UID=1000
15+
ARG USER="blues"
16+
17+
# POSIX compatible (Linux/Unix) base image
18+
FROM debian:stable-slim
19+
20+
# Import global arguments
21+
ARG ARDUINO_CLI_VERSION
22+
ARG DEBIAN_FRONTEND
23+
ARG UID
24+
ARG USER
25+
26+
# Define local arguments
27+
ARG BINDIR=/usr/local/bin
28+
ARG ECHO_BC_FILE='$bcfile'
29+
30+
# Define environment variables
31+
ENV ARDUINO_UPDATER_ENABLE_NOTIFICATION=false
32+
33+
# Create Non-Root User
34+
RUN ["dash", "-c", "\
35+
addgroup \
36+
--gid ${UID} \
37+
\"${USER}\" \
38+
&& adduser \
39+
--disabled-password \
40+
--gecos \"\" \
41+
--ingroup \"${USER}\" \
42+
--uid ${UID} \
43+
\"${USER}\" \
44+
&& usermod \
45+
--append \
46+
--groups \"dialout,plugdev\" \
47+
\"${USER}\" \
48+
"]
49+
50+
# Establish development environment
51+
RUN ["dash", "-c", "\
52+
apt-get update --quiet \
53+
&& apt-get install --assume-yes --no-install-recommends --quiet \
54+
bash \
55+
ca-certificates \
56+
curl \
57+
python-is-python3 \
58+
python3 \
59+
python3-pip \
60+
ssh \
61+
tree \
62+
&& pip install \
63+
adafruit-nrfutil \
64+
pyserial \
65+
&& apt-get clean \
66+
&& apt-get purge \
67+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
68+
"]
69+
70+
# Download/Install Arduino CLI
71+
RUN ["dash", "-c", "\
72+
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=${BINDIR} sh -s ${ARDUINO_CLI_VERSION} \
73+
# && arduino-cli completion bash > /usr/share/bash-completion/completions/arduino-cli.sh \
74+
&& mkdir -p /etc/bash_completion.d/ \
75+
&& arduino-cli completion bash > /etc/bash_completion.d/arduino-cli.sh \
76+
&& echo >> /etc/bash.bashrc \
77+
# && echo \"for bcfile in /usr/share/bash-completion/completions/* ; do\" >> /etc/bash.bashrc \
78+
# && echo \"for bcfile in /etc/bash_completion.d/* ; do\" >> /etc/bash.bashrc \
79+
# && echo \" [ -f \\\"${ECHO_BC_FILE}\\\" ] && . \\\"${ECHO_BC_FILE}\\\"\" >> /etc/bash.bashrc \
80+
# && echo \"done\" >> /etc/bash.bashrc \
81+
"]
82+
83+
# Configure Arduino CLI
84+
USER ${USER}
85+
RUN ["dash", "-c", "\
86+
arduino-cli config init \
87+
&& arduino-cli config add board_manager.additional_urls \
88+
https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/main/package_stmicroelectronics_index.json \
89+
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json \
90+
https://raw.githubusercontent.com/sparkfun/Arduino_Apollo3/main/package_sparkfun_apollo3_index.json \
91+
https://raw.githubusercontent.com/adafruit/arduino-board-index/gh-pages/package_adafruit_index.json \
92+
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json \
93+
&& arduino-cli core update-index \
94+
&& arduino-cli core install adafruit:nrf52 \
95+
&& arduino-cli core install adafruit:samd \
96+
&& arduino-cli core install arduino:avr \
97+
&& arduino-cli core install arduino:mbed_nano \
98+
&& arduino-cli core install arduino:samd \
99+
&& arduino-cli core install esp32:esp32 \
100+
&& arduino-cli core install rp2040:rp2040 \
101+
&& arduino-cli core install SparkFun:apollo3 \
102+
&& arduino-cli core install STMicroelectronics:stm32 \
103+
&& arduino-cli lib install \"Adafruit BME680 Library\" \
104+
"]
105+
106+
# Set Execution Environment
107+
USER root
108+
WORKDIR /host-volume
109+
110+
ENTRYPOINT ["arduino-cli"]
111+
112+
CMD ["help"]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: 'Compile Examples'
2+
author: 'Zachary J. Fields'
3+
description: 'Validate examples by compiling for supported platforms'
4+
runs:
5+
using: 'docker'
6+
image: './Dockerfile'
7+
entrypoint: 'bash'
8+
args:
9+
- -c
10+
- "cp -r . /home/blues/Arduino/libraries/Blues_Wireless_Notecard \
11+
&& HOME=/home/blues arduino-cli compile \
12+
--build-property compiler.cpp.extra_flags='-Wno-unused-parameter -Werror' \
13+
--fqbn ${{ inputs.fully-qualified-board-name }} \
14+
--warnings all \
15+
${{ inputs.example-sketch }}"

.github/workflows/note-arduino-ci.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [ master ]
88

99
jobs:
10-
validate_code: # job id
10+
validate_library: # job id
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout Code
@@ -26,3 +26,40 @@ jobs:
2626
uses: coverallsapp/github-action@master
2727
with:
2828
github-token: ${{ secrets.GITHUB_TOKEN }}
29+
validate_examples: # job id
30+
runs-on: ubuntu-latest
31+
continue-on-error: true
32+
strategy:
33+
matrix:
34+
example-sketch:
35+
- ./examples/Example0_LibrarylessCommunication/Example0_LibrarylessCommunication.ino
36+
- ./examples/Example1_NotecardBasics/Example1_NotecardBasics.ino
37+
- ./examples/Example2_PeriodicCommunications/Example2_PeriodicCommunications.ino
38+
- ./examples/Example3_InboundPolling/Example3_InboundPolling.ino
39+
- ./examples/Example4_InboundInterrupts/Example4_InboundInterrupts.ino
40+
- ./examples/Example5_UsingTemplates/Example5_UsingTemplates.ino
41+
- ./examples/Example6_SensorTutorial/Example6_SensorTutorial.ino
42+
- ./examples/Example7_PowerControl/Example7_PowerControl.ino
43+
fully-qualified-board-name:
44+
- STMicroelectronics:stm32:BluesW:pnum=SWAN_R5
45+
- esp32:esp32:featheresp32
46+
- adafruit:samd:adafruit_feather_m4
47+
- STMicroelectronics:stm32:GenF4:pnum=FEATHER_F405
48+
- arduino:mbed_nano:nano33ble
49+
- SparkFun:apollo3:sfe_artemis_thing_plus
50+
- STMicroelectronics:stm32:Nucleo_32:pnum=NUCLEO_L432KC
51+
- adafruit:nrf52:feather52840:softdevice=s140v6
52+
- rp2040:rp2040:rpipico
53+
- arduino:avr:uno
54+
steps:
55+
- name: Checkout Code
56+
id: checkout
57+
uses: actions/checkout@v2
58+
with:
59+
submodules: true
60+
- name: Compile Examples
61+
id: compile_examples
62+
uses: ./.github/actions/compile-examples
63+
with:
64+
example-sketch: ${{ matrix.example-sketch }}
65+
fully-qualified-board-name: ${{ matrix.fully-qualified-board-name }}

examples/Example0_LibrarylessCommunication/Example0_LibrarylessCommunication.ino

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@
1616
// Note that both of these definitions are optional; just prefix either line with // to remove it.
1717
// Remove serialNotecard if you wired your Notecard using I2C SDA/SCL pins instead of serial RX/TX
1818

19+
#if defined(ARDUINO_ARCH_AVR) && not defined(HAVE_HWSERIAL1)
20+
#define serialNotecard Serial
21+
#elif defined(ARDUINO_ARCH_STM32) && not defined(HAVE_HWSERIAL1)
22+
#define serialNotecard Serial
23+
#else
1924
#define serialNotecard Serial1
25+
#endif
26+
27+
#ifdef ARDUINO_NRF52840_FEATHER
28+
#include "Adafruit_TinyUSB.h"
29+
#endif
2030

2131
// This is the unique Product Identifier for your device. This Product ID tells the Notecard what
2232
// type of device has embedded the Notecard, and by extension which vendor or customer is in charge

examples/Example2_PeriodicCommunications/Example2_PeriodicCommunications.ino

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,40 @@
88
// gather sensor measurements "offline", then perform uploads on a periodic basis.
99
//
1010

11+
#define ledPin LED_BUILTIN
12+
1113
// Define the pin number of the pushbutton pin
12-
#if defined(ARDUINO_ARCH_ESP32)
13-
#define buttonPin 21
14-
#define buttonPressedState LOW
15-
#define ledPin 13
16-
#elif defined(ARDUINO_ARCH_NRF52)
17-
#define buttonPin 7
18-
#define buttonPressedState LOW
19-
#define ledPin LED_RED
20-
#elif defined(ARDUINO_ARCH_AVR)
21-
#define buttonPin 6
14+
#define buttonPin B0
2215
#define buttonPressedState LOW
23-
#define ledPin 4
16+
17+
#if defined(ARDUINO_FEATHER_F405)
18+
#define NON_AF_COMPAT_FEATHER
19+
#elif defined(ARDUINO_ARCH_APOLLO3)
20+
// #undef buttonPin
21+
// #define buttonPin 10
22+
#elif defined(ARDUINO_NUCLEO_L432KC)
23+
#define BREADBOARD_REQUIRED
2424
#elif defined(ARDUINO_ARCH_STM32)
25-
#define buttonPin USER_BTN
26-
#define buttonPressedState LOW
27-
#define ledPin LED_BUILTIN
28-
#else
29-
#error "please add a board definition for button and led"
30-
#define buttonPin ? // Change to any GPIO pin where there is an active-high button
31-
#define buttonPressedState ? // Active high, or active low
32-
#define ledPin ? // Change to any GPIO pin where there is an LED
25+
#undef buttonPin
26+
#define buttonPin USER_BTN
27+
#elif defined(ARDUINO_NRF52840_FEATHER)
28+
#undef buttonPin
29+
#define buttonPin 7
30+
#elif defined(ARDUINO_RASPBERRY_PI_PICO)
31+
#define BREADBOARD_REQUIRED
32+
#elif defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MBED)
33+
#define BREADBOARD_REQUIRED
34+
#endif
35+
36+
#ifdef NON_AF_COMPAT_FEATHER
37+
#pragma message("This feather does not support the Notecarrier-AF button, additional hardware is required.")
38+
#undef buttonPin
39+
#define buttonPin A5
40+
#endif
41+
#ifdef BREADBOARD_REQUIRED
42+
#pragma message("The board selected requires additional hardware.")
43+
#undef buttonPin
44+
#define buttonPin 3
3345
#endif
3446

3547
// Include the Arduino library for the Notecard
@@ -47,8 +59,8 @@
4759
Notecard notecard;
4860

4961
// Button handling
50-
#define BUTTON_IDLE 0
51-
#define BUTTON_PRESS 1
62+
#define BUTTON_IDLE 0
63+
#define BUTTON_PRESS 1
5264
#define BUTTON_DOUBLEPRESS 2
5365
int buttonPress(void);
5466

examples/Example3_InboundPolling/Example3_InboundPolling.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void setup()
5858
#endif
5959

6060
// Configure the productUID, and instruct the Notecard to stay connected to the service
61-
req = notecard.newRequest("hub.set");
61+
J *req = notecard.newRequest("hub.set");
6262
JAddStringToObject(req, "product", myProductID);
6363
#if myLiveDemo
6464
JAddStringToObject(req, "mode", "continuous");

0 commit comments

Comments
 (0)