Skip to content

Commit

Permalink
provide a docker based build script
Browse files Browse the repository at this point in the history
  • Loading branch information
jandelgado committed Feb 14, 2021
1 parent 3703994 commit 2ca13b4
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 7 deletions.
24 changes: 24 additions & 0 deletions examples/raspi_pico/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# A minimal dockerfile to provide a build environment to compile the JLed
# raspberry pi pico JLed in a docker container.
FROM ubuntu:20.04

LABEL MAINTAINER "Jan Delgado <jdelgado@gmx.net>"

ARG TZ=Europe/Berlin
ENV DEBIAN_FRONTEND=noninteractive

RUN echo ${TZ} > /etc/timezone && rm -f /etc/localtime \
&& cat /etc/timezone\
&& apt-get update \
&& apt-get install -y git cmake gcc-arm-none-eabi libnewlib-arm-none-eabi \
build-essential vim python3 python3-pip

RUN mkdir /pico
WORKDIR /pico

# install SDK
RUN git clone --depth=1 -b master https://github.com/raspberrypi/pico-sdk.git \
&& cd pico-sdk && git submodule update --init

ENV PICO_SDK_PATH=/pico/pico-sdk

47 changes: 41 additions & 6 deletions examples/raspi_pico/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,54 @@
# JLed for the Raspberry Pi Pico

This examples demonstrates how to use JLed on the Raspberry Pi Pico. The
built-in LED and a LED on GPIO 16 will be faded.
built-in LED (GPIO 25) and a LED on GPIO 16 will be faded.

Also a Dockerfile is provided to enable a hassle-free build.

<!-- vim-markdown-toc GFM -->

* [Building the demo](#building-the-demo)
* [Docker build](#docker-build)
* [Local build](#local-build)
* [Deploy the sketch to the Raspberry Pi Pico](#deploy-the-sketch-to-the-raspberry-pi-pico)
* [Author](#author)

<!-- vim-markdown-toc -->
## Building the demo

You have two options to build the demo. Either use a docker image (recommended),
or setup everything yourself (consult Pico Quickstart Guide).

### Docker build

A [Dockerfile](Dockerfile) and a [build-script](build.sh) are provided to
enable a hassle-free build of the demo. The script will first build a
docker-image containing the build environment, then build the example.

* run `./build.sh docker-image` to build the docker image with the build
environment (compilers, pico SDK etc.) - only needed to run once (as long
as the Dockerfile is not changed).
* run `./build.sh compile` to compile the example. The resulting `pico_demo.uf2`
file to be uploaded will be found in this directory afterwards.
* run `./build.sh clean` to clean up all files created during a build.

### Local build

You need the [pico-sdk](https://github.com/raspberrypi/pico-sdk) and
necessary tools to compile everything installed.

The `PICO_SDK_PATH` environment variable must point to the installation
directory of the SDK.

* to compile the demo sketch, run `cmake . && make`
* To deploy the demo sketch, press and hold `BOOTSEL` on the Pico and connect
the Pico to your PC. The Pico will now be mounted as an external drive. Copy
the file `pico_demo.uf2` to the mount point. The sketch should now start
automatically.
To compile the demo sketch, run `cmake . && make`. The resulting
`pico_demo.uf2` file to be uploaded will be found in this directory afterwards.

## Deploy the sketch to the Raspberry Pi Pico

To deploy the demo sketch `pico_demo.uf2`, press and hold `BOOTSEL` on the Pico
and connect the Pico to your PC. The Pico will now be mounted as an external
drive. Copy the file `pico_demo.uf2` to the mount point. The sketch should now
start automatically.

## Author

Expand Down
45 changes: 45 additions & 0 deletions examples/raspi_pico/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
# build the raspberry pi pico JLed example using a docker container.
# Run "./build.sh docker-image" first to build the docker-image,
# then run "./build.sh compile" to compile the example.
#
# Jan Delgado 02/2021
set -eou pipefail

usage() {
echo "$0: <docker-image|compile|shell|clean>"
}

build_image() {
docker build \
--build-arg="TZ=$(timedatectl show -p Timezone --value)" \
-t picosdk:latest .
}

run_cmd() {
docker run -ti --rm \
--user="$(id -u):$(id -g)" \
-v "$(pwd)/../..:/src:z" \
picosdk:latest "$@"
}

main() {
case $action in
docker-image) build_image ;;
compile)
run_cmd sh -c "cd /src/examples/raspi_pico && cmake . && make"
local -r line=$(printf '=%.0s' {1..75})
echo "$line"
echo "BUILD SUCCESSFUL."
echo "Now upload the file pico_demo.uf2 to your Pico manually."
echo "$line"
;;
shell) run_cmd bash ;;
clean) git clean -d -x -f ;;
*) usage ;;
esac
}

action=${1:-""}
main action

5 changes: 4 additions & 1 deletion examples/raspi_pico/pico_demo.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// JLed demo for the Raspberry Pi Pico
// Fade the built-in LED (GPIO 25) and a LED on GPIO 16.
//
// Copyright 2021 by Jan Delgado. All rights reserved.
// https://github.com/jandelgado/jled
//
#include "pico/stdlib.h" // NOLINT
#include "jled.h" // NOLINT

int main() {
auto led1 = JLed(LED_PIN).FadeOff(2000).DelayAfter(1000).Forever();
auto led1 = JLed(25).FadeOff(2000).DelayAfter(1000).Forever();
auto led2 = JLed(16).FadeOn(2000).DelayAfter(1000).Forever();

while (true) {
Expand Down

0 comments on commit 2ca13b4

Please sign in to comment.