Initial commit

Signed-off-by: Thomas Klaehn <thomas.klaehn@perinet.io>
This commit is contained in:
Thomas Klaehn
2025-02-12 05:32:06 +01:00
commit 03a3c8732f
19 changed files with 2941 additions and 0 deletions

79
.devcontainer/Dockerfile Normal file
View File

@@ -0,0 +1,79 @@
# Base image
FROM debian:bookworm-slim
ENV DEBIAN_FRONTEND=noninteractive
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
# Arguments
ARG CONTAINER_USER=esp
ARG CONTAINER_GROUP=esp
ARG NIGHTLY_VERSION=nightly-2024-06-30
ARG ESP_IDF_VERSION=v5.2.2
ARG ESP_BOARD=esp32c6
# Install dependencies
RUN apt-get update \
&& apt-get install -y git wget flex bison gperf python3 python3-pip python3-venv \
cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0 \
llvm-dev libclang-dev clang pkg-config unzip libusb-1.0-0 \
libpython3-all-dev python3-virtualenv curl \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/* /tmp/library-scripts
# Set users
RUN adduser --disabled-password --gecos "" ${CONTAINER_USER}
RUN adduser ${CONTAINER_USER} root
USER ${CONTAINER_USER}
WORKDIR /home/${CONTAINER_USER}
# Install rustup
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
--default-toolchain ${NIGHTLY_VERSION} -y --profile minimal \
--component rust-src,clippy,rustfmt
# Update envs
ENV PATH=${PATH}:$HOME/.cargo/bin
# Install extra crates
RUN ARCH=$($HOME/.cargo/bin/rustup show | grep "Default host" | sed -e 's/.* //') && \
curl -L "https://github.com/esp-rs/espflash/releases/latest/download/cargo-espflash-${ARCH}.zip" -o "${HOME}/.cargo/bin/cargo-espflash.zip" && \
unzip "${HOME}/.cargo/bin/cargo-espflash.zip" -d "${HOME}/.cargo/bin/" && \
rm "${HOME}/.cargo/bin/cargo-espflash.zip" && \
chmod u+x "${HOME}/.cargo/bin/cargo-espflash" && \
curl -L "https://github.com/esp-rs/espflash/releases/latest/download/espflash-${ARCH}.zip" -o "${HOME}/.cargo/bin/espflash.zip" && \
unzip "${HOME}/.cargo/bin/espflash.zip" -d "${HOME}/.cargo/bin/" && \
rm "${HOME}/.cargo/bin/espflash.zip" && \
chmod u+x "${HOME}/.cargo/bin/espflash" && \
curl -L "https://github.com/esp-rs/esp-web-flash-server/releases/latest/download/web-flash-${ARCH}.zip" -o "${HOME}/.cargo/bin/web-flash.zip" && \
unzip "${HOME}/.cargo/bin/web-flash.zip" -d "${HOME}/.cargo/bin/" && \
rm "${HOME}/.cargo/bin/web-flash.zip" && \
chmod u+x "${HOME}/.cargo/bin/web-flash" && \
curl -L "https://github.com/esp-rs/embuild/releases/latest/download/ldproxy-${ARCH}.zip" -o "${HOME}/.cargo/bin/ldproxy.zip" && \
unzip "${HOME}/.cargo/bin/ldproxy.zip" -d "${HOME}/.cargo/bin/" && \
rm "${HOME}/.cargo/bin/ldproxy.zip" && \
chmod u+x "${HOME}/.cargo/bin/ldproxy" && \
GENERATE_VERSION=$(git ls-remote --refs --sort="version:refname" --tags "https://github.com/cargo-generate/cargo-generate" | cut -d/ -f3- | tail -n1) && \
GENERATE_URL="https://github.com/cargo-generate/cargo-generate/releases/latest/download/cargo-generate-${GENERATE_VERSION}-${ARCH}.tar.gz" && \
curl -L "${GENERATE_URL}" -o "${HOME}/.cargo/bin/cargo-generate.tar.gz" && \
tar xf "${HOME}/.cargo/bin/cargo-generate.tar.gz" -C "${HOME}/.cargo/bin/" && \
rm "${HOME}/.cargo/bin/cargo-generate.tar.gz" && \
chmod u+x "${HOME}/.cargo/bin/cargo-generate"
# Install esp-idf
RUN mkdir -p ${HOME}/.espressif/frameworks/ \
&& git clone --branch ${ESP_IDF_VERSION} -q --depth 1 --shallow-submodules \
--recursive https://github.com/espressif/esp-idf.git \
${HOME}/.espressif/frameworks/esp-idf \
&& python3 ${HOME}/.espressif/frameworks/esp-idf/tools/idf_tools.py install cmake \
&& ${HOME}/.espressif/frameworks/esp-idf/install.sh ${ESP_BOARD} \
&& rm -rf .espressif/dist \
&& rm -rf .espressif/frameworks/esp-idf/docs \
&& rm -rf .espressif/frameworks/esp-idf/examples \
&& rm -rf .espressif/frameworks/esp-idf/tools/esp_app_trace \
&& rm -rf .espressif/frameworks/esp-idf/tools/test_idf_size
# Activate ESP environment
ENV IDF_TOOLS_PATH=${HOME}/.espressif
RUN echo "source ${HOME}/.espressif/frameworks/esp-idf/export.sh > /dev/null 2>&1" >> ~/.bashrc
CMD "/bin/bash"

46
.devcontainer/devcontainer.json Executable file
View File

@@ -0,0 +1,46 @@
{
"name": "esp32-dev",
"build": {
"dockerfile": "Dockerfile",
"args": {
"NIGHTLY_VERSION": "nightly-2025-01-01"
}
},
// Privileged container in order to access /dev
"privileged": true,
// Mount USB devices (debug probes, UART interfaces, ...)
"mounts": [
"source=/dev/bus/usb/,target=/dev/bus/usb/,type=bind"
],
"runArgs": [
"--device=/dev/ttyACM0"
],
"customizations": {
"vscode": {
"settings": {
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "modifications",
"editor.formatOnType": true,
"lldb.executable": "/usr/bin/lldb",
"files.watcherExclude": {
"**/target/**": true
},
"rust-analyzer.checkOnSave.command": "clippy",
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
},
"extensions": [
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"vadimcn.vscode-lldb",
"mutantdino.resourcemonitor",
"yzhang.markdown-all-in-one"
]
}
},
"remoteUser": "esp",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
"workspaceFolder": "/workspace"
}

50
.devcontainer/test.sh Normal file
View File

@@ -0,0 +1,50 @@
#!/bin/sh
set -ef
echo "Compiling $1"
cd /home/esp/workspace/$1
if [ -f cfg.toml.example ]; then
# Rename file to cfg.toml
cp cfg.toml.example cfg.toml
# Replace defaults
sed -i 's/wifi_ssid = "FBI Surveillance Van"/wifi_ssid = "Wokwi-GUEST"/g' cfg.toml
sed -i 's/wifi_psk = "hunter2"/wifi_psk = ""/g' cfg.toml
sed -i 's/mqtt_user = "horse"/mqtt_user = "user"/g' cfg.toml
sed -i 's/mqtt_pass = "CorrectHorseBatteryStaple"/mqtt_pass = "pass"/g' cfg.toml
sed -i 's/mqtt_host = "yourpc.local"/mqtt_host = "host"/g' cfg.toml
fi
$HOME/.cargo/bin/cargo clean
$HOME/.cargo/bin/cargo build
# Check examples
if [[ "$1" == advanced/button-interrupt ]]; then
$HOME/.cargo/bin/cargo build --example solution
$HOME/.cargo/bin/cargo build --example solution_led
# Simulate with Wokwi
sed -i 's/^[[:space:]]*firmware[[:space:]]*=[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"']\([[:space:]]*\)$/\nfirmware = "target\/riscv32imc-esp-espidf\/debug\/examples\/solution"/' wokwi.toml
fi
if [[ "$1" == advanced/i2c-sensor-reading ]]; then
$HOME/.cargo/bin/cargo build --example part_1
$HOME/.cargo/bin/cargo build --example part_2
fi
if [[ "$1" == intro/http-client ]]; then
$HOME/.cargo/bin/cargo build --example http_client
$HOME/.cargo/bin/cargo build --example https_client
# Simulate with Wokwi
sed -i 's/^[[:space:]]*firmware[[:space:]]*=[[:space:]]*["'"'"']\([^"'"'"']*\)["'"'"']\([[:space:]]*\)$/\nfirmware = "target\/riscv32imc-esp-espidf\/debug\/examples\/http_client"/' wokwi.toml
fi
if [[ "$1" == intro/http-server ]]; then
$HOME/.cargo/bin/cargo build --example http_server
fi
if [[ "$1" == intro/mqtt/exercise ]]; then
$HOME/.cargo/bin/cargo build --example solution_publ_rcv
$HOME/.cargo/bin/cargo build --example solution_publ
fi