Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
madskjeldgaard committed Jul 16, 2024
0 parents commit 413b555
Show file tree
Hide file tree
Showing 12 changed files with 737 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: PlatformIO CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install PlatformIO Core
run: pip install --upgrade platformio

- name: Build PlatformIO Project
run: pio run
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

.pio
.cache
168 changes: 168 additions & 0 deletions .scripts/commands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#! /bin/bash

# A helper script to help build and upload firmware projects based on PlatformIO

function list_environments(){
pio project config|grep ^env:|sed "s,env:,,"
}

function generate_vscode_tasks() {
# Lists all environments, and creates a vscode build and upload tasks for each environment
# This is useful for creating a vscode task.json file

for env in $(list_environments); do
echo "
// Upload ${env}
{
\"label\": \"upload ${env}\",
\"type\": \"shell\",
\"command\": \"pio run -t upload -e ${env}\",
},
// Build ${env}
{
\"label\": \"build ${env}\",
\"type\": \"shell\",
\"command\": \"pio run -e ${env}\",
},"
done
}

function update_vscode_tasks_json () {
# Updates the vscode tasks.json file with the tasks generated by generate_vscode_tasks

if [ ! -f .vscode/tasks.json ]; then
echo "tasks.json file not found. Please run this command from the root of the project"
exit 1
fi

# Backup the tasks.json file
cp .vscode/tasks.json .vscode/tasks.json.bak

# Create the top part
echo ' {
// This file is auto generated by the commands.sh script. Any edits will be overwritten automatically.
"version": "2.0.0",
"tasks": [
// Build all
{
"label": "Build all",
"type": "shell",
"command": "pio run",
"group": {
"kind": "build",
"isDefault": true
}
},
// Make compiledb to allow LSP to work
{
"label": "Build compiledb database for LSP / clangd",
"type": "shell",
"command": "pio run -t compiledb",
},
' > .vscode/tasks.json



# Generate the tasks
generate_vscode_tasks >> .vscode/tasks.json

# Close the tasks.json file
echo "] }" >> .vscode/tasks.json

echo "tasks.json updated successfully"
}

function print_help() {
echo "Usage: $0 <command>"
echo "Commands:"
echo " list"
echo " show"
echo " build-all"
echo " build <environment>"
echo " upload <environment>"
echo " fzf_boards"
echo " update_vscode_tasks"
exit 1
}

function build() {
if [ $# -ne 1 ]; then
echo "Usage: $0 build <environment>"
echo "See list of available environments by running $0 list"
exit 1
fi

pio run -e $1
}

function build_all() {
pio run
}

function upload() {
if [ $# -ne 1 ]; then
echo "Usage: $0 upload <environment>"
echo "See list of available environments by running $0 list"
exit 1
fi

pio run -e $1 --target upload
}

function show() {
pio project --list-targets
}

function fzf_boards() {
# Fuzzy search boards and return the board id

# Check if fzf installed
if ! command -v fzf &> /dev/null; then
echo "fzf is not installed. Please install fzf to use this feature."
exit 1
fi

pio boards --json-output | jq -r '.[] | .id + " " + .name' | fzf | awk '{print $1}'
}

function main() {
# parse the command line arguments
if [ $# -eq 0 ]; then
print_help
exit 1
fi

case $1 in
list)
list_environments
;;
show)
show
;;
upload)
shift
upload $@
;;
build-all)
build_all
;;
build)
shift
build $@
;;
fzf_boards)
fzf_boards
;;
update_vscode_tasks)
update_vscode_tasks_json
;;
*)
print_help
exit 1
;;
esac
}

main $@
102 changes: 102 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
// This file is auto generated by the commands.sh script. Any edits will be overwritten automatically.
"version": "2.0.0",
"tasks": [

// Build all
{
"label": "Build all",
"type": "shell",
"command": "pio run",
"group": {
"kind": "build",
"isDefault": true
}
},

// Make compiledb to allow LSP to work
{
"label": "Build compiledb database for LSP / clangd",
"type": "shell",
"command": "pio run -t compiledb",
},


// Upload raspberrypi-pico
{
"label": "upload raspberrypi-pico",
"type": "shell",
"command": "pio run -t upload -e raspberrypi-pico",
},
// Build raspberrypi-pico
{
"label": "build raspberrypi-pico",
"type": "shell",
"command": "pio run -e raspberrypi-pico",
},

// Upload raspberrypi-picow
{
"label": "upload raspberrypi-picow",
"type": "shell",
"command": "pio run -t upload -e raspberrypi-picow",
},
// Build raspberrypi-picow
{
"label": "build raspberrypi-picow",
"type": "shell",
"command": "pio run -e raspberrypi-picow",
},

// Upload esp32dev
{
"label": "upload esp32dev",
"type": "shell",
"command": "pio run -t upload -e esp32dev",
},
// Build esp32dev
{
"label": "build esp32dev",
"type": "shell",
"command": "pio run -e esp32dev",
},

// Upload nodemcuv2-esp8266
{
"label": "upload nodemcuv2-esp8266",
"type": "shell",
"command": "pio run -t upload -e nodemcuv2-esp8266",
},
// Build nodemcuv2-esp8266
{
"label": "build nodemcuv2-esp8266",
"type": "shell",
"command": "pio run -e nodemcuv2-esp8266",
},

// Upload teensy41
{
"label": "upload teensy41",
"type": "shell",
"command": "pio run -t upload -e teensy41",
},
// Build teensy41
{
"label": "build teensy41",
"type": "shell",
"command": "pio run -e teensy41",
},

// Upload teensy40
{
"label": "upload teensy40",
"type": "shell",
"command": "pio run -t upload -e teensy40",
},
// Build teensy40
{
"label": "build teensy40",
"type": "shell",
"command": "pio run -e teensy40",
},
] }
Loading

0 comments on commit 413b555

Please sign in to comment.