Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
# There are a few Dockerfile restrictions when using Github Actions
# See: https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions

# 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-2023-02-28
ARG ESP_IDF_VERSION=v4.4.4
ARG ESP_BOARD=esp32c3

# Install dependencies
RUN apt-get update \
&& apt-get install -y git curl ninja-build llvm-dev libclang-dev \
&& apt-get install -y git curl ninja-build llvm-dev libclang-dev libusb-1.0-0\
clang unzip python3 python3-pip python3-venv libpython3-all-dev python3-virtualenv pkg-config libssl-dev \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/* /tmp/library-scripts

# Set users
RUN adduser --disabled-password --gecos "" ${CONTAINER_USER}
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
--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/" && \
Expand All @@ -51,6 +56,7 @@ RUN ARCH=$($HOME/.cargo/bin/rustup show | grep "Default host" | sed -e 's/.* //'
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 \
Expand All @@ -63,6 +69,7 @@ RUN mkdir -p ${HOME}/.espressif/frameworks/ \
&& 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

Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"vadimcn.vscode-lldb",
"serayuzgur.crates",
"mutantdino.resourcemonitor",
"yzhang.markdown-all-in-one"
"yzhang.markdown-all-in-one",
"Wokwi.wokwi-vscode"
]
}
},
Expand Down
10 changes: 6 additions & 4 deletions .devcontainer/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

set -ef

WORK_DIR=/home/esp/workspace/$1

echo "Compiling $1"

cd /home/esp/workspace/$1
Expand All @@ -12,8 +10,8 @@ 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 = "ssid"/g' cfg.toml
sed -i 's/wifi_psk = "hunter2"/wifi_psk = "pass"/g' cfg.toml
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
Expand All @@ -26,6 +24,8 @@ $HOME/.cargo/bin/cargo build
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
Expand All @@ -36,6 +36,8 @@ 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
Expand Down
17 changes: 17 additions & 0 deletions .github/button-interrupt.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: button-interrupt test
version: 1
author: Sergio Gasquez Arcos

steps:
- wait-serial: "GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:1"
# Press once
- set-control:
part-id: btn1
control: pressed
value: 1
- delay: 100ms
- set-control:
part-id: btn1
control: pressed
value: 0
- wait-serial: "Button pressed!"
7 changes: 7 additions & 0 deletions .github/hardware-check.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: hardware-check test
version: 1
author: Sergio Gasquez Arcos

steps:
- delay: 5000ms
- wait-serial: "Hello, world!"
7 changes: 7 additions & 0 deletions .github/http-client.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: http-client test
version: 1
author: Sergio Gasquez Arcos

steps:
- delay: 5000ms
- wait-serial: "Response code: 200"
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ on:
- "book/"
- "book/**"
- "**/README.md"
- ".github/workflows/wokwi_projects.yml"
pull_request:
branches: [main]
paths-ignore:
- "book/"
- "book/**"
- "**/README.md"
- ".github/workflows/wokwi_projects.yml"
schedule:
- cron: "50 7 * * *"

Expand Down Expand Up @@ -67,3 +68,13 @@ jobs:
image: espressif/rust-std-training:latest
options: -u esp -v ${{ github.workspace }}:/home/esp/workspace
run: /bin/bash /home/esp/workspace/.devcontainer/test.sh ${{ matrix.project.path }}

- name: Wokwi CI check
if: matrix.project.name == 'button-interrupt' || matrix.project.name == 'http-client' || matrix.project.name == 'hardware-check'
uses: wokwi/wokwi-ci-action@v1
with:
token: ${{ secrets.WOKWI_CLI_TOKEN }}
path: ${{ matrix.project.path }}
timeout: 30000
scenario: ${{ github.workspace }}/.github/${{ matrix.project.name }}.test.yaml
fail_text: 'Error'
90 changes: 90 additions & 0 deletions .github/workflows/wokwi_projects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
name: Wokwi.com CI

on:
push:
paths:
- '.github/workflows/wokwi_projects.yml'
pull_request:
paths:
- '.github/workflows/wokwi_projects.yml'
schedule:
- cron: "50 7 * * *"
workflow_dispatch:

jobs:
wokwi-check:
name: ${{ matrix.project.name }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
project:
- name: "hardware-check"
id: "360342886675214337"
path: "intro/hardware-check"
- name: http-client
id: "333372159510446675"
path: "intro/http-client"
- name: button-interrupt
id: "333374799393849940"
path: "advanced/button-interrupt"

steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Download project code
run: |
wget -q -O ${{ matrix.project.name }}.zip https://wokwi.com/api/projects/${{ matrix.project.id }}/zip
unzip ${{ matrix.project.name }}.zip -d ${{ matrix.project.name }}
mkdir -p ${{ matrix.project.name }}/src
rm -rf ${{ matrix.project.path }}/src/*.rs
cp ${{ matrix.project.name }}/*.rs ${{ matrix.project.path }}/src/
rm -rf ${{ matrix.project.path }}/Cargo.toml
cp ${{ matrix.project.name }}/Cargo.toml ${{ matrix.project.path }}/Cargo.toml

- name: Create wokwi.toml
run: echo -e "[wokwi]\nversion = 1\nfirmware = '${{ matrix.project.name }}/${{ matrix.project.name }}'\nelf = '${{ matrix.project.name }}/${{ matrix.project.name }}'" > ${{ matrix.project.path }}/wokwi.toml

- name: Update ownership
run: |
sudo chown 1000:1000 -R ${{ matrix.project.path }}

- name: Pull Docker image
run: docker image pull espressif/rust-std-training

- name: Test code example in Docker image
uses: addnab/docker-run-action@v3
with:
image: espressif/rust-std-training:latest
options: -u esp -v ${{ github.workspace }}:/home/esp/workspace
run: |
cd /home/esp/workspace/${{ matrix.project.path }}
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
fi
/home/esp/.cargo/bin/cargo build --release --out-dir /home/esp/workspace/${{ matrix.project.path }}/${{ matrix.project.name }} -Z unstable-options
rm -rf /home/esp/workspace/${{ matrix.project.path }}/target

- run: cat ${{ matrix.project.path }}/wokwi.toml

- name: Wokwi CI check
uses: wokwi/wokwi-ci-action@v1
with:
token: ${{ secrets.WOKWI_CLI_TOKEN }}
path: ${{ matrix.project.path }}
timeout: 30000
scenario: ${{ github.workspace }}/.github/${{ matrix.project.name }}.test.yaml
fail_text: 'Error'

- name: Upload source code
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.project.name }}_${{ matrix.project.id }}
path: ${{ matrix.project.path }}
62 changes: 62 additions & 0 deletions advanced/button-interrupt/diagram.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"version": 1,
"author": "Sergio Gasquez Arcos",
"editor": "wokwi",
"parts": [
{
"type": "board-esp32-c3-rust-1",
"id": "esp",
"top": -99.32,
"left": 34.67,
"attrs": {
"builder": "rust-training-esp32c3"
}
},
{
"type": "wokwi-pushbutton",
"id": "btn1",
"top": 2.81,
"left": -49.66,
"rotate": 90,
"attrs": {
"color": "green",
"bounce": "0"
}
}
],
"connections": [
[
"esp:21",
"$serialMonitor:RX",
"",
[]
],
[
"esp:20",
"$serialMonitor:TX",
"",
[]
],
[
"esp:9",
"btn1:1.r",
"green",
[
"h0"
]
],
[
"esp:GND",
"btn1:2.r",
"black",
[
"h-97.82",
"v114.6",
"h26"
]
]
],
"serialMonitor": {
"display": "auto"
}
}
1 change: 1 addition & 0 deletions advanced/button-interrupt/examples/solution_led.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ fn main() -> Result<()> {

match res {
1 => {
println!("Button pressed!");
// Generates random rgb values and sets them in the led.
random_light(&mut led);
}
Expand Down
13 changes: 13 additions & 0 deletions advanced/button-interrupt/wokwi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[wokwi]
version = 1
# Exercise
firmware = "target/riscv32imc-esp-espidf/debug/examples/solution"
elf = 'target/riscv32imc-esp-espidf/debug/button-interrupt'

# Solution
# firmware = 'target/riscv32imc-esp-espidf/debug/examples/solution'
# elf = 'target/riscv32imc-esp-espidf/debug/examples/solution'

# Solution - LED
# firmware = 'target/riscv32imc-esp-espidf/debug/examples/solution_led'
# elf = 'target/riscv32imc-esp-espidf/debug/examples/solution_led'
30 changes: 30 additions & 0 deletions advanced/i2c-driver/diagram.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": 1,
"author": "Sergio Gasquez Arcos",
"editor": "wokwi",
"parts": [
{
"type": "board-esp32-c3-rust-1",
"id": "esp",
"top": -187.16,
"left": -43.05,
"attrs": {
"builder": "rust-training-esp32c3"
}
}
],
"connections": [
[
"esp:21",
"$serialMonitor:RX",
"",
[]
],
[
"esp:20",
"$serialMonitor:TX",
"",
[]
]
]
}
4 changes: 2 additions & 2 deletions advanced/i2c-driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![no_std]

// Uncomment the following line to run the solution, check main.rs for further instructions
// pub mod icm42670p_solution;
pub mod icm42670p_solution;

// Comment out the following line to run the solution, check main.rs for further instructions
pub mod icm42670p;
// pub mod icm42670p;
4 changes: 2 additions & 2 deletions advanced/i2c-driver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use esp_idf_hal::{
use esp_idf_sys as _;

// Uncomment the following line to run the solution, check lib.rs for further instructions
// use i2c_driver::icm42670p_solution::{DeviceAddr, ICM42670P};
use i2c_driver::icm42670p_solution::{DeviceAddr, ICM42670P};

// Comment out the following line to run the solution, check lib.rs for further instructions
use i2c_driver::icm42670p::{DeviceAddr, ICM42670P};
// use i2c_driver::icm42670p::{DeviceAddr, ICM42670P};

// Dont change this file. Work in the icm42670p.rs and modify it so main.rs runs.

Expand Down
Loading