From 0d4fe762354a8feddae686bfa66c2994d1f9e49f Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Wed, 8 Nov 2023 15:15:38 +0100 Subject: [PATCH 01/18] feat: Add Wokwi files --- advanced/button-interrupt/diagram.json | 62 +++++++++++ advanced/button-interrupt/wokwi.toml | 13 +++ advanced/i2c-driver/diagram.json | 82 ++++++++++++++ advanced/i2c-driver/src/lib.rs | 4 +- advanced/i2c-driver/src/main.rs | 4 +- advanced/i2c-driver/wokwi.toml | 4 + advanced/i2c-sensor-reading/diagram.json | 132 +++++++++++++++++++++++ advanced/i2c-sensor-reading/wokwi.toml | 13 +++ intro/hardware-check/diagram.json | 33 ++++++ intro/hardware-check/wokwi.toml | 4 + intro/http-client/diagram.json | 33 ++++++ intro/http-client/wokwi.toml | 13 +++ 12 files changed, 393 insertions(+), 4 deletions(-) create mode 100644 advanced/button-interrupt/diagram.json create mode 100644 advanced/button-interrupt/wokwi.toml create mode 100644 advanced/i2c-driver/diagram.json create mode 100644 advanced/i2c-driver/wokwi.toml create mode 100644 advanced/i2c-sensor-reading/diagram.json create mode 100644 advanced/i2c-sensor-reading/wokwi.toml create mode 100644 intro/hardware-check/diagram.json create mode 100644 intro/hardware-check/wokwi.toml create mode 100644 intro/http-client/diagram.json create mode 100644 intro/http-client/wokwi.toml diff --git a/advanced/button-interrupt/diagram.json b/advanced/button-interrupt/diagram.json new file mode 100644 index 00000000..c397a648 --- /dev/null +++ b/advanced/button-interrupt/diagram.json @@ -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" + } +} diff --git a/advanced/button-interrupt/wokwi.toml b/advanced/button-interrupt/wokwi.toml new file mode 100644 index 00000000..8fe55d3b --- /dev/null +++ b/advanced/button-interrupt/wokwi.toml @@ -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' diff --git a/advanced/i2c-driver/diagram.json b/advanced/i2c-driver/diagram.json new file mode 100644 index 00000000..979ad45e --- /dev/null +++ b/advanced/i2c-driver/diagram.json @@ -0,0 +1,82 @@ +{ + "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" + } + }, + { + "type": "chip-imc42670p", + "id": "chip1", + "top": -91.9, + "left": -231.89, + "attrs": {} + } + ], + "connections": [ + [ + "esp:21", + "$serialMonitor:RX", + "", + [] + ], + [ + "esp:20", + "$serialMonitor:TX", + "", + [] + ], + [ + "esp:GND", + "chip1:GND", + "black", + [ + "h-9.6", + "v38.4" + ] + ], + [ + "esp:3V3", + "chip1:VCC", + "red", + [ + "h-19.2", + "v48" + ] + ], + [ + "esp:10", + "chip1:SDA", + "green", + [ + "v-0.36", + "h34.24", + "v69.78", + "h-133.4", + "v-134.77" + ] + ], + [ + "esp:8.2", + "chip1:SCL", + "yellow", + [ + "v0.69", + "h43.47", + "v86.88", + "h-152.56", + "v-132.49" + ] + ] + ], + "dependencies": { + "chip-imc42670p": "github:SergioGasquez/wokwi-icm42670p@0.0.4" + } +} diff --git a/advanced/i2c-driver/src/lib.rs b/advanced/i2c-driver/src/lib.rs index 7c01339a..13ddc36f 100644 --- a/advanced/i2c-driver/src/lib.rs +++ b/advanced/i2c-driver/src/lib.rs @@ -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; diff --git a/advanced/i2c-driver/src/main.rs b/advanced/i2c-driver/src/main.rs index 158e086e..445876c0 100644 --- a/advanced/i2c-driver/src/main.rs +++ b/advanced/i2c-driver/src/main.rs @@ -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. diff --git a/advanced/i2c-driver/wokwi.toml b/advanced/i2c-driver/wokwi.toml new file mode 100644 index 00000000..62f3bd58 --- /dev/null +++ b/advanced/i2c-driver/wokwi.toml @@ -0,0 +1,4 @@ +[wokwi] +version = 1 +firmware = 'target/riscv32imc-esp-espidf/debug/i2c-driver' +elf = 'target/riscv32imc-esp-espidf/debug/i2c-driver' diff --git a/advanced/i2c-sensor-reading/diagram.json b/advanced/i2c-sensor-reading/diagram.json new file mode 100644 index 00000000..e7eaace3 --- /dev/null +++ b/advanced/i2c-sensor-reading/diagram.json @@ -0,0 +1,132 @@ +{ + "version": 1, + "author": "Sergio Gasquez Arcos", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-c3-rust-1", + "id": "esp", + "top": -185.86, + "left": -45.01, + "attrs": { + "builder": "rust-training-esp32c3" + } + }, + { + "type": "chip-imc42670p", + "id": "chip1", + "top": -91.9, + "left": -231.89, + "attrs": {} + }, + { + "type": "chip-shtc3", + "id": "chip2", + "top": -37.38, + "left": -233.39, + "attrs": {} + } + ], + "connections": [ + [ + "esp:21", + "$serialMonitor:RX", + "", + [] + ], + [ + "esp:20", + "$serialMonitor:TX", + "", + [] + ], + [ + "esp:GND", + "chip1:GND", + "black", + [ + "h-9.6", + "v38.4" + ] + ], + [ + "esp:3V3", + "chip1:VCC", + "red", + [ + "h-19.2", + "v48" + ] + ], + [ + "esp:GND", + "chip2:GND", + "black", + [ + "h-9.6", + "v38.4" + ] + ], + [ + "esp:3V3", + "chip2:VCC", + "red", + [ + "h-19.2", + "v48" + ] + ], + [ + "esp:8.2", + "chip2:SCL", + "yellow", + [ + "v-2.61", + "h19.36", + "v83.06", + "h-137.87", + "v-194.94" + ] + ], + [ + "esp:8.2", + "chip1:SCL", + "yellow", + [ + "v-3.18", + "h18.79", + "v83.06", + "h-137.31", + "v-100.58" + ] + ], + [ + "esp:10", + "chip1:SDA", + "green", + [ + "v-1.47", + "h30.09", + "v81.93", + "h-161.6", + "v-116.4" + ] + ], + [ + "esp:10", + "chip2:SDA", + "green", + [ + "v0.22", + "h29.53", + "v79.67", + "h-159.91", + "v-213.02" + ] + ] + ], + "dependencies": { + "chip-imc42670p": "github:SergioGasquez/wokwi-icm42670p@0.0.4", + "chip-shtc3": "github:SergioGasquez/wokwi-shtc3@0.0.1" + } +} diff --git a/advanced/i2c-sensor-reading/wokwi.toml b/advanced/i2c-sensor-reading/wokwi.toml new file mode 100644 index 00000000..22cc1b2f --- /dev/null +++ b/advanced/i2c-sensor-reading/wokwi.toml @@ -0,0 +1,13 @@ +[wokwi] +version = 1 +# # Exercise +firmware = 'target/riscv32imc-esp-espidf/debug/i2c-sensor-reading' +elf = 'target/riscv32imc-esp-espidf/debug/i2c-sensor-reading' + +# Solution - Part 1 +# firmware = 'target/riscv32imc-esp-espidf/debug/examples/part_1' +# elf = 'target/riscv32imc-esp-espidf/debug/examples/part_1' + +# Solution - Part 2 +# firmware = 'target/riscv32imc-esp-espidf/debug/examples/part_2' +# elf = 'target/riscv32imc-esp-espidf/debug/examples/part_2' diff --git a/intro/hardware-check/diagram.json b/intro/hardware-check/diagram.json new file mode 100644 index 00000000..82022b0e --- /dev/null +++ b/intro/hardware-check/diagram.json @@ -0,0 +1,33 @@ +{ + "version": 1, + "author": "Sergio Gasquez Arcos", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-c3-rust-1", + "id": "esp", + "top": -126.57, + "left": 46.35, + "attrs": { + "builder": "rust-training-esp32c3" + } + } + ], + "connections": [ + [ + "esp:21", + "$serialMonitor:RX", + "", + [] + ], + [ + "esp:20", + "$serialMonitor:TX", + "", + [] + ] + ], + "serialMonitor": { + "display": "auto" + } +} diff --git a/intro/hardware-check/wokwi.toml b/intro/hardware-check/wokwi.toml new file mode 100644 index 00000000..cfc01f4b --- /dev/null +++ b/intro/hardware-check/wokwi.toml @@ -0,0 +1,4 @@ +[wokwi] +version = 1 +firmware = 'target/riscv32imc-esp-espidf/debug/hardware-check' +elf = 'target/riscv32imc-esp-espidf/debug/hardware-check' diff --git a/intro/http-client/diagram.json b/intro/http-client/diagram.json new file mode 100644 index 00000000..c35ad0d9 --- /dev/null +++ b/intro/http-client/diagram.json @@ -0,0 +1,33 @@ +{ + "version": 1, + "author": "Sergio Gasquez Arcos", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-c3-rust-1", + "id": "esp", + "top": -155.32, + "left": 54, + "attrs": { + "builder": "rust-training-esp32c3" + } + } + ], + "connections": [ + [ + "esp:21", + "$serialMonitor:RX", + "", + [] + ], + [ + "esp:20", + "$serialMonitor:TX", + "", + [] + ] + ], + "serialMonitor": { + "display": "auto" + } +} diff --git a/intro/http-client/wokwi.toml b/intro/http-client/wokwi.toml new file mode 100644 index 00000000..9e946db3 --- /dev/null +++ b/intro/http-client/wokwi.toml @@ -0,0 +1,13 @@ +[wokwi] +version = 1 +# # Exercise +firmware = 'target/riscv32imc-esp-espidf/debug/http-client' +elf = 'target/riscv32imc-esp-espidf/debug/http-client' + +# Solution - HTTP +# firmware = 'target/riscv32imc-esp-espidf/debug/examples/http_client' +# elf = 'target/riscv32imc-esp-espidf/debug/examples/http_client' + +# Solution - HTTPS +# firmware = 'target/riscv32imc-esp-espidf/debug/examples/https_client' +# elf = 'target/riscv32imc-esp-espidf/debug/examples/https_client' From d3405e99d6286d1085891e44fe02bce47e786ec1 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Wed, 8 Nov 2023 15:16:09 +0100 Subject: [PATCH 02/18] ci: Simulate projects --- .devcontainer/test.sh | 6 ++++-- .github/button-interrupt.test.yaml | 18 ++++++++++++++++++ .github/hardware-check.test.yaml | 7 +++++++ .github/http-client.test.yaml | 7 +++++++ .github/workflows/ci.yml | 10 ++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 .github/button-interrupt.test.yaml create mode 100644 .github/hardware-check.test.yaml create mode 100644 .github/http-client.test.yaml diff --git a/.devcontainer/test.sh b/.devcontainer/test.sh index 32f30eb3..951fa42a 100644 --- a/.devcontainer/test.sh +++ b/.devcontainer/test.sh @@ -2,8 +2,6 @@ set -ef -WORK_DIR=/home/esp/workspace/$1 - echo "Compiling $1" cd /home/esp/workspace/$1 @@ -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 @@ -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 diff --git a/.github/button-interrupt.test.yaml b/.github/button-interrupt.test.yaml new file mode 100644 index 00000000..8a6fa169 --- /dev/null +++ b/.github/button-interrupt.test.yaml @@ -0,0 +1,18 @@ +name: button-interrupt test +version: 1 +author: Sergio Gasquez Arcos + +steps: + - delay: 100ms + - 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!" diff --git a/.github/hardware-check.test.yaml b/.github/hardware-check.test.yaml new file mode 100644 index 00000000..92a96534 --- /dev/null +++ b/.github/hardware-check.test.yaml @@ -0,0 +1,7 @@ +name: hardware-check test +version: 1 +author: Sergio Gasquez Arcos + +steps: + - delay: 5000ms + - wait-serial: "Hello, world!" diff --git a/.github/http-client.test.yaml b/.github/http-client.test.yaml new file mode 100644 index 00000000..10328553 --- /dev/null +++ b/.github/http-client.test.yaml @@ -0,0 +1,7 @@ +name: http-client test +version: 1 +author: Sergio Gasquez Arcos + +steps: + - delay: 5000ms + - wait-serial: "Response code: 200" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0e6e285..31e8fa2a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,3 +67,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' From e452e8ca6ce346ae177e0519276b61c72e3e5247 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 9 Nov 2023 10:58:26 +0100 Subject: [PATCH 03/18] feat: Update default SSID --- intro/hardware-check/src/main.rs | 2 +- intro/http-client/examples/http_client.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/intro/hardware-check/src/main.rs b/intro/hardware-check/src/main.rs index bc20460e..e3a5ac8e 100644 --- a/intro/hardware-check/src/main.rs +++ b/intro/hardware-check/src/main.rs @@ -11,7 +11,7 @@ use esp_idf_sys as _; /// file `cfg.toml`. #[toml_cfg::toml_config] pub struct Config { - #[default("")] + #[default("Wokwi-GUEST")] wifi_ssid: &'static str, #[default("")] wifi_psk: &'static str, diff --git a/intro/http-client/examples/http_client.rs b/intro/http-client/examples/http_client.rs index 4720f091..d34f8ca8 100644 --- a/intro/http-client/examples/http_client.rs +++ b/intro/http-client/examples/http_client.rs @@ -15,7 +15,7 @@ use esp_idf_sys as _; #[toml_cfg::toml_config] pub struct Config { - #[default("")] + #[default("Wokwi-GUEST")] wifi_ssid: &'static str, #[default("")] wifi_psk: &'static str, @@ -95,7 +95,7 @@ fn get(url: impl AsRef) -> Result<()> { // print it and reset the offset to 0. print!("{}", text); offset = 0; - }, + } Err(error) => { // The buffer contains incomplete UTF-8 data, we will // print the valid part, copy the invalid sequence to From ad7de891e5f6eec600704cb3bd33a50d12395c36 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 9 Nov 2023 10:59:09 +0100 Subject: [PATCH 04/18] ci: Add wokwi.com checks --- .github/workflows/ci.yml | 2 + .github/workflows/wokwi_projects.yml | 67 ++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 .github/workflows/wokwi_projects.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31e8fa2a..e36bc50c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,12 +7,14 @@ 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 * * *" diff --git a/.github/workflows/wokwi_projects.yml b/.github/workflows/wokwi_projects.yml new file mode 100644 index 00000000..e84356c6 --- /dev/null +++ b/.github/workflows/wokwi_projects.yml @@ -0,0 +1,67 @@ +--- +name: CI + +on: + 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" + - name: http-client + id: "333372159510446675" + - name: button-interrupt + id: "333374799393849940" + 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 }} + + - name: Create wokwi.toml + run: echo -e "[wokwi]\nversion = 1\nfirmware = '${{ matrix.project.name }}'\nelf = '${{ matrix.project.name }}'" > ${{ matrix.project.name }}/wokwi.toml + + - name: Update ownership + run: | + sudo chown 1000:1000 -R ${{ matrix.project.name }} + + - 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: wokwi/builder-rust-${{ matrix.project.env }}-esp + options: -u esp -v ${{ github.workspace }}:/home/esp/workspace + run: | + . /home/esp/export-esp.sh + cp /home/esp/workspace/${{ matrix.project.name }}/*.rs ${{ matrix.project.name }}/src/ + cd ${{ matrix.project.name }} + cargo build --release --out-dir /home/esp/workspace/${{ matrix.project.name }} -Z unstable-options + + - name: Wokwi CI check + uses: wokwi/wokwi-ci-action@v1 + with: + token: ${{ secrets.WOKWI_CLI_TOKEN }} + path: ${{ matrix.project.name }} + 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.name }} From e5ba728acace13b5cf50444866c8df04092a15fc Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 9 Nov 2023 11:01:19 +0100 Subject: [PATCH 05/18] ci: Update conditions --- .github/workflows/wokwi_projects.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/wokwi_projects.yml b/.github/workflows/wokwi_projects.yml index e84356c6..7b684b9d 100644 --- a/.github/workflows/wokwi_projects.yml +++ b/.github/workflows/wokwi_projects.yml @@ -2,6 +2,12 @@ name: CI on: + push: + paths: + - '.github/workflows/wokwi_projects.yml' + pull_request: + paths: + - '.github/workflows/wokwi_projects.yml' schedule: - cron: "50 7 * * *" workflow_dispatch: From 41fd79573fc2eb37d6ee6dbb9ed1d539c535e18f Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 9 Nov 2023 11:02:47 +0100 Subject: [PATCH 06/18] ci: Update name --- .github/workflows/wokwi_projects.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wokwi_projects.yml b/.github/workflows/wokwi_projects.yml index 7b684b9d..51befb9d 100644 --- a/.github/workflows/wokwi_projects.yml +++ b/.github/workflows/wokwi_projects.yml @@ -1,5 +1,5 @@ --- -name: CI +name: Wokwi.com CI on: push: From 7eb9962c3fcb5effb25a25d22a6bb4415cd4e623 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 9 Nov 2023 11:18:41 +0100 Subject: [PATCH 07/18] ci: Fix image --- .github/workflows/wokwi_projects.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wokwi_projects.yml b/.github/workflows/wokwi_projects.yml index 51befb9d..6632fccb 100644 --- a/.github/workflows/wokwi_projects.yml +++ b/.github/workflows/wokwi_projects.yml @@ -48,7 +48,7 @@ jobs: - name: Test code example in Docker image uses: addnab/docker-run-action@v3 with: - image: wokwi/builder-rust-${{ matrix.project.env }}-esp + image: espressif/rust-std-training options: -u esp -v ${{ github.workspace }}:/home/esp/workspace run: | . /home/esp/export-esp.sh From dd56f4f0a76b68a5366d87dd65613594cfbb6db0 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 9 Nov 2023 11:31:08 +0100 Subject: [PATCH 08/18] ci: Remove source commadn --- .github/workflows/wokwi_projects.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/wokwi_projects.yml b/.github/workflows/wokwi_projects.yml index 6632fccb..6b0d6869 100644 --- a/.github/workflows/wokwi_projects.yml +++ b/.github/workflows/wokwi_projects.yml @@ -34,6 +34,8 @@ jobs: 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 + cp ${{ matrix.project.name }}/*.rs ${{ matrix.project.name }}/src/ - name: Create wokwi.toml run: echo -e "[wokwi]\nversion = 1\nfirmware = '${{ matrix.project.name }}'\nelf = '${{ matrix.project.name }}'" > ${{ matrix.project.name }}/wokwi.toml @@ -48,13 +50,11 @@ jobs: - name: Test code example in Docker image uses: addnab/docker-run-action@v3 with: - image: espressif/rust-std-training + image: espressif/rust-std-training:latest options: -u esp -v ${{ github.workspace }}:/home/esp/workspace run: | - . /home/esp/export-esp.sh - cp /home/esp/workspace/${{ matrix.project.name }}/*.rs ${{ matrix.project.name }}/src/ - cd ${{ matrix.project.name }} - cargo build --release --out-dir /home/esp/workspace/${{ matrix.project.name }} -Z unstable-options + cd /home/esp/workspace/${{ matrix.project.name }} + /home/esp/.cargo/bin/cargo build --release --out-dir /home/esp/workspace/${{ matrix.project.name }} -Z unstable-options - name: Wokwi CI check uses: wokwi/wokwi-ci-action@v1 From a642a2ac7f30d5d70e75ffb62b459d4ce701f974 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 9 Nov 2023 12:08:33 +0100 Subject: [PATCH 09/18] ci: Update path --- .github/workflows/wokwi_projects.yml | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/wokwi_projects.yml b/.github/workflows/wokwi_projects.yml index 6b0d6869..d97adda5 100644 --- a/.github/workflows/wokwi_projects.yml +++ b/.github/workflows/wokwi_projects.yml @@ -22,10 +22,14 @@ jobs: 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 @@ -35,14 +39,17 @@ jobs: 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 - cp ${{ matrix.project.name }}/*.rs ${{ 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 }}'\nelf = '${{ matrix.project.name }}'" > ${{ matrix.project.name }}/wokwi.toml + run: echo -e "[wokwi]\nversion = 1\nfirmware = '${{ matrix.project.name }}'\nelf = '${{ matrix.project.name }}'" > ${{ matrix.project.path }}/wokwi.toml - name: Update ownership run: | - sudo chown 1000:1000 -R ${{ matrix.project.name }} + sudo chown 1000:1000 -R ${{ matrix.project.path }} - name: Pull Docker image run: docker image pull espressif/rust-std-training @@ -53,14 +60,15 @@ jobs: image: espressif/rust-std-training:latest options: -u esp -v ${{ github.workspace }}:/home/esp/workspace run: | - cd /home/esp/workspace/${{ matrix.project.name }} - /home/esp/.cargo/bin/cargo build --release --out-dir /home/esp/workspace/${{ matrix.project.name }} -Z unstable-options + cd /home/esp/workspace/${{ matrix.project.path }} + /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 - name: Wokwi CI check uses: wokwi/wokwi-ci-action@v1 with: token: ${{ secrets.WOKWI_CLI_TOKEN }} - path: ${{ matrix.project.name }} + path: ${{ matrix.project.path }} timeout: 30000 scenario: ${{ github.workspace }}/.github/${{ matrix.project.name }}.test.yaml fail_text: 'Error' @@ -70,4 +78,4 @@ jobs: uses: actions/upload-artifact@v3 with: name: ${{ matrix.project.name }}_${{ matrix.project.id }} - path: ${{ matrix.project.name }} + path: ${{ matrix.project.path }} From b39a4218daa292c58b38aef5bc5c4791d9cf5d4c Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 9 Nov 2023 13:00:45 +0100 Subject: [PATCH 10/18] build: Update deps and rust components --- .devcontainer/Dockerfile | 17 ++++++++++++----- .github/workflows/wokwi_projects.yml | 7 +++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 65c5a263..6f232826 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -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/" && \ @@ -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 \ @@ -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 diff --git a/.github/workflows/wokwi_projects.yml b/.github/workflows/wokwi_projects.yml index d97adda5..551c1671 100644 --- a/.github/workflows/wokwi_projects.yml +++ b/.github/workflows/wokwi_projects.yml @@ -61,6 +61,13 @@ jobs: 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 From 06073123381b41604b7c6f8c351e571de002eb51 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 9 Nov 2023 14:33:38 +0100 Subject: [PATCH 11/18] chore: Update SSID for Wokwi simulation --- .devcontainer/test.sh | 4 ++-- intro/hardware-check/src/main.rs | 2 +- intro/http-client/examples/http_client.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.devcontainer/test.sh b/.devcontainer/test.sh index 951fa42a..71d40da8 100644 --- a/.devcontainer/test.sh +++ b/.devcontainer/test.sh @@ -10,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 diff --git a/intro/hardware-check/src/main.rs b/intro/hardware-check/src/main.rs index e3a5ac8e..bc20460e 100644 --- a/intro/hardware-check/src/main.rs +++ b/intro/hardware-check/src/main.rs @@ -11,7 +11,7 @@ use esp_idf_sys as _; /// file `cfg.toml`. #[toml_cfg::toml_config] pub struct Config { - #[default("Wokwi-GUEST")] + #[default("")] wifi_ssid: &'static str, #[default("")] wifi_psk: &'static str, diff --git a/intro/http-client/examples/http_client.rs b/intro/http-client/examples/http_client.rs index d34f8ca8..3fdecf8e 100644 --- a/intro/http-client/examples/http_client.rs +++ b/intro/http-client/examples/http_client.rs @@ -15,7 +15,7 @@ use esp_idf_sys as _; #[toml_cfg::toml_config] pub struct Config { - #[default("Wokwi-GUEST")] + #[default("")] wifi_ssid: &'static str, #[default("")] wifi_psk: &'static str, From 854a1204f54e7ab361a397610895a2068d5a7af1 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 9 Nov 2023 14:46:07 +0100 Subject: [PATCH 12/18] chore: Debug wokwi.toml --- .github/workflows/wokwi_projects.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/wokwi_projects.yml b/.github/workflows/wokwi_projects.yml index 551c1671..4f77c582 100644 --- a/.github/workflows/wokwi_projects.yml +++ b/.github/workflows/wokwi_projects.yml @@ -71,6 +71,8 @@ jobs: /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: From ec92abb28dee36cdf5a54973eef109fc38ce483c Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 9 Nov 2023 14:52:35 +0100 Subject: [PATCH 13/18] ci: Update conditions --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e36bc50c..3d350b2c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,6 @@ on: - "**/README.md" - ".github/workflows/wokwi_projects.yml" pull_request: - branches: [main] paths-ignore: - "book/" - "book/**" From faf7f2a58ae96f2bb94a60eaa451ec86a4f2cf83 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Mon, 20 Nov 2023 12:31:29 +0100 Subject: [PATCH 14/18] feat: Add wokwi vscode extension --- .devcontainer/devcontainer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 3065b54b..2bf3225b 100755 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -31,7 +31,8 @@ "vadimcn.vscode-lldb", "serayuzgur.crates", "mutantdino.resourcemonitor", - "yzhang.markdown-all-in-one" + "yzhang.markdown-all-in-one", + "Wokwi.wokwi-vscode" ] } }, From 20ee877b90c89e069d528245c03d88fe350139be Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Mon, 20 Nov 2023 12:33:13 +0100 Subject: [PATCH 15/18] feat: Update Wokwi files --- advanced/i2c-driver/diagram.json | 54 +----------- advanced/i2c-sensor-reading/diagram.json | 104 +---------------------- advanced/i2c-sensor-reading/wokwi.toml | 2 +- intro/http-client/wokwi.toml | 6 +- 4 files changed, 4 insertions(+), 162 deletions(-) diff --git a/advanced/i2c-driver/diagram.json b/advanced/i2c-driver/diagram.json index 979ad45e..e025c468 100644 --- a/advanced/i2c-driver/diagram.json +++ b/advanced/i2c-driver/diagram.json @@ -11,13 +11,6 @@ "attrs": { "builder": "rust-training-esp32c3" } - }, - { - "type": "chip-imc42670p", - "id": "chip1", - "top": -91.9, - "left": -231.89, - "attrs": {} } ], "connections": [ @@ -32,51 +25,6 @@ "$serialMonitor:TX", "", [] - ], - [ - "esp:GND", - "chip1:GND", - "black", - [ - "h-9.6", - "v38.4" - ] - ], - [ - "esp:3V3", - "chip1:VCC", - "red", - [ - "h-19.2", - "v48" - ] - ], - [ - "esp:10", - "chip1:SDA", - "green", - [ - "v-0.36", - "h34.24", - "v69.78", - "h-133.4", - "v-134.77" - ] - ], - [ - "esp:8.2", - "chip1:SCL", - "yellow", - [ - "v0.69", - "h43.47", - "v86.88", - "h-152.56", - "v-132.49" - ] ] - ], - "dependencies": { - "chip-imc42670p": "github:SergioGasquez/wokwi-icm42670p@0.0.4" - } + ] } diff --git a/advanced/i2c-sensor-reading/diagram.json b/advanced/i2c-sensor-reading/diagram.json index e7eaace3..9ac65086 100644 --- a/advanced/i2c-sensor-reading/diagram.json +++ b/advanced/i2c-sensor-reading/diagram.json @@ -11,20 +11,6 @@ "attrs": { "builder": "rust-training-esp32c3" } - }, - { - "type": "chip-imc42670p", - "id": "chip1", - "top": -91.9, - "left": -231.89, - "attrs": {} - }, - { - "type": "chip-shtc3", - "id": "chip2", - "top": -37.38, - "left": -233.39, - "attrs": {} } ], "connections": [ @@ -39,94 +25,6 @@ "$serialMonitor:TX", "", [] - ], - [ - "esp:GND", - "chip1:GND", - "black", - [ - "h-9.6", - "v38.4" - ] - ], - [ - "esp:3V3", - "chip1:VCC", - "red", - [ - "h-19.2", - "v48" - ] - ], - [ - "esp:GND", - "chip2:GND", - "black", - [ - "h-9.6", - "v38.4" - ] - ], - [ - "esp:3V3", - "chip2:VCC", - "red", - [ - "h-19.2", - "v48" - ] - ], - [ - "esp:8.2", - "chip2:SCL", - "yellow", - [ - "v-2.61", - "h19.36", - "v83.06", - "h-137.87", - "v-194.94" - ] - ], - [ - "esp:8.2", - "chip1:SCL", - "yellow", - [ - "v-3.18", - "h18.79", - "v83.06", - "h-137.31", - "v-100.58" - ] - ], - [ - "esp:10", - "chip1:SDA", - "green", - [ - "v-1.47", - "h30.09", - "v81.93", - "h-161.6", - "v-116.4" - ] - ], - [ - "esp:10", - "chip2:SDA", - "green", - [ - "v0.22", - "h29.53", - "v79.67", - "h-159.91", - "v-213.02" - ] ] - ], - "dependencies": { - "chip-imc42670p": "github:SergioGasquez/wokwi-icm42670p@0.0.4", - "chip-shtc3": "github:SergioGasquez/wokwi-shtc3@0.0.1" - } + ] } diff --git a/advanced/i2c-sensor-reading/wokwi.toml b/advanced/i2c-sensor-reading/wokwi.toml index 22cc1b2f..7ccdbde0 100644 --- a/advanced/i2c-sensor-reading/wokwi.toml +++ b/advanced/i2c-sensor-reading/wokwi.toml @@ -1,6 +1,6 @@ [wokwi] version = 1 -# # Exercise +# Exercise firmware = 'target/riscv32imc-esp-espidf/debug/i2c-sensor-reading' elf = 'target/riscv32imc-esp-espidf/debug/i2c-sensor-reading' diff --git a/intro/http-client/wokwi.toml b/intro/http-client/wokwi.toml index 9e946db3..a2e7aa4f 100644 --- a/intro/http-client/wokwi.toml +++ b/intro/http-client/wokwi.toml @@ -1,13 +1,9 @@ [wokwi] version = 1 -# # Exercise +# Exercise firmware = 'target/riscv32imc-esp-espidf/debug/http-client' elf = 'target/riscv32imc-esp-espidf/debug/http-client' # Solution - HTTP # firmware = 'target/riscv32imc-esp-espidf/debug/examples/http_client' # elf = 'target/riscv32imc-esp-espidf/debug/examples/http_client' - -# Solution - HTTPS -# firmware = 'target/riscv32imc-esp-espidf/debug/examples/https_client' -# elf = 'target/riscv32imc-esp-espidf/debug/examples/https_client' From 6a1ceceed16fab0cd7c7e52ed6ab6f5826dce9da Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Mon, 20 Nov 2023 12:38:00 +0100 Subject: [PATCH 16/18] docs: Add simulation documentation --- book/src/02_0_preparations.md | 14 ++++++++++++++ book/src/02_4_hello_board.md | 12 ++++++++++-- book/src/03_3_2_http_client.md | 12 ++++++++++++ book/src/04_3_1_i2c.md | 14 ++++++++++++++ book/src/04_3_2_i2c.md | 12 ++++++++++++ book/src/04_4_1_interrupts.md | 13 +++++++++++++ 6 files changed, 75 insertions(+), 2 deletions(-) diff --git a/book/src/02_0_preparations.md b/book/src/02_0_preparations.md index 5cb2a8b6..b0d3b42c 100644 --- a/book/src/02_0_preparations.md +++ b/book/src/02_0_preparations.md @@ -20,6 +20,20 @@ We use Icons to mark different kinds of information in the book: > No additional debugger/probe hardware is required. +## Simulating Projects + +Certain projects can be simulated with [Wokwi][wokwi]. Look for indications in the book to identify projects available for simulation. Simulation can be accomplished through two methods: +- Using wokwi.com: Conduct the build process and code editing directly through the browser. +- Using [Wokwi VS Code extension][wokwi-vscode]: Leverage VS Code to edit projects and perform builds. Utilize the Wokwi VS Code extension to simulate the resulting binaries. + - This approach requires some [installation][wokwi-installation] + - This approach assumes that the project is built in debug mode + - This approach allows [debugging the project][wokwi-debug] + +[wokwi]: https://wokwi.com/ +[wokwi-vscode]: https://docs.wokwi.com/vscode/getting-started +[wokwi-installation]: https://docs.wokwi.com/vscode/getting-started#installation +[wokwi-debug]: https://docs.wokwi.com/vscode/debugging + ## Ensuring a Working Setup diff --git a/book/src/02_4_hello_board.md b/book/src/02_4_hello_board.md index b99dec23..46c2e7b7 100644 --- a/book/src/02_4_hello_board.md +++ b/book/src/02_4_hello_board.md @@ -76,10 +76,18 @@ You can also monitor the device without flashing it with the following command: espflash monitor ``` +## Simulation -# Troubleshooting +This project is available for simulation through two methods: +- [Wokwi project](https://wokwi.com/projects/360342886675214337?build-cache=disable) +- Wokwi VS Code extension: + 1. Press F1, select `Wokwi: Select Config File`, and choose `intro/hardware-check/wokwi.toml`. + 2. Build your project. + 3. Press F1 again and select `Wokwi: Start Simulator`. -## Build Errors +## Troubleshooting + +### Build Errors ```console error[E0463]: can't find crate for `core` diff --git a/book/src/03_3_2_http_client.md b/book/src/03_3_2_http_client.md index f4c25c71..631cf171 100644 --- a/book/src/03_3_2_http_client.md +++ b/book/src/03_3_2_http_client.md @@ -71,6 +71,18 @@ The status error can be returned with the [Anyhow](https://docs.rs/anyhow/latest ✅ Write a custom `Error` enum to represent these errors. Implement the `std::error::Error` trait for your error. +## Simulation + +This project is available for simulation through two methods: +- Wokwi projects: + - [Exercise](https://wokwi.com/projects/360722140931768321?build-cache=disable) + - [Solution](https://wokwi.com/projects/333372159510446675?build-cache=disable) +- Wokwi files are also present in the project folder to simulate it with Wokwi VS Code extension: + 1. Press F1, select `Wokwi: Select Config File` and choose `intro/http-client/wokwi.toml` + - Edit the `wokwi.toml` file to select between exercise and solution simulation + 2. Build you project + 3. Press F1 again and select `Wokwi: Start Simulator` + ## Troubleshooting - `missing WiFi name/password`: ensure that you've configured `cfg.toml` according to `cfg.toml.example` - a common problem is that the package name and config section name don't match. diff --git a/book/src/04_3_1_i2c.md b/book/src/04_3_1_i2c.md index 2fa9d13e..4bfaad0e 100644 --- a/book/src/04_3_1_i2c.md +++ b/book/src/04_3_1_i2c.md @@ -125,3 +125,17 @@ GYRO: X: 0.00 Y: 0.00 Z: 0:00 TEMP: [local temperature] °C HUM: [local humidity] % ``` + +## Simulation + +This project is available for simulation through two methods: +- Wokwi projects + - [Exercise](https://wokwi.com/projects/360623713943950337?build-cache=disable) + - [Solution Part 2](https://wokwi.com/projects/360344742047853569?build-cache=disable) +- Wokwi files are also present in the project folder to simulate it with Wokwi VS Code extension: + 1. Press F1, select `Wokwi: Select Config File` and choose `advanced/i2c-sensor-reading/wokwi.toml` + - Edit the `wokwi.toml` file to select between exercise and solutions simulation + 2. Build you project + 3. Press F1 again and select `Wokwi: Start Simulator` + +When simulating this project, expect the following hardcoded values: `TEMP: 24.61 °C | HUM: 36.65 % | GYRO: X= 0.00 Y= 0.00 Z= 0.00` diff --git a/book/src/04_3_2_i2c.md b/book/src/04_3_2_i2c.md index 740e4fd3..12062f3a 100644 --- a/book/src/04_3_2_i2c.md +++ b/book/src/04_3_2_i2c.md @@ -110,3 +110,15 @@ In this specific context, we are using an external device (since it is a sensor, You can find the register map of the ICM-42670 in [section 14](https://invensense.tdk.com/wp-content/uploads/2021/07/DS-000451-ICM-42670-P-v1.0.pdf) should you want to try to get other interesting data from this sensor. + + +## Simulation + +This project is available for simulation through two methods: +- Wokwi projects + - [Exercise](https://wokwi.com/projects/360728357589094401?build-cache=disable) + - [Solution](https://wokwi.com/projects/333375074521317970?build-cache=disable) +- Wokwi files are also present in the project folder to simulate it with Wokwi VS Code extension: + 1. Press F1, select `Wokwi: Select Config File` and choose `advanced/i2c-driver/wokwi.toml` + 2. Build you project + 3. Press F1 again and select `Wokwi: Start Simulator` diff --git a/book/src/04_4_1_interrupts.md b/book/src/04_4_1_interrupts.md index 09476ee9..d413cf13 100644 --- a/book/src/04_4_1_interrupts.md +++ b/book/src/04_4_1_interrupts.md @@ -83,3 +83,16 @@ If the interrupt fires, an event is added to the queue. 9. Handle the value of `res`, so that "Button pushed!" is logged, if the button is pushed. 10. Run the program and push the `BOOT` button, so see how it works! + +## Simulation + +This project is available for simulation through two methods: +- Wokwi projects + - [Exercise](https://wokwi.com/projects/360623288920412161?build-cache=disable) + - [Solution](https://wokwi.com/projects/333374799393849940?build-cache=disable) + - The Solution project contains solution for [Random LED Color on pushinig a Button](./04_4_2_interrupts.md) +- Wokwi files are also present in the project folder to simulate it with Wokwi VS Code extension: + 1. Press F1, select `Wokwi: Select Config File` and choose `advanced/button-interrupt/wokwi.toml` + - Edit the `wokwi.toml` file to select between exercise and solution simulation + 2. Build you project + 3. Press F1 again and select `Wokwi: Start Simulator` From 1240817d03389f1f1d91125b83610a1812917105 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Mon, 20 Nov 2023 13:06:04 +0100 Subject: [PATCH 17/18] ci: Update path --- .github/button-interrupt.test.yaml | 1 - .github/workflows/wokwi_projects.yml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/button-interrupt.test.yaml b/.github/button-interrupt.test.yaml index 8a6fa169..06c61ee5 100644 --- a/.github/button-interrupt.test.yaml +++ b/.github/button-interrupt.test.yaml @@ -3,7 +3,6 @@ version: 1 author: Sergio Gasquez Arcos steps: - - delay: 100ms - wait-serial: "GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:1" # Press once - set-control: diff --git a/.github/workflows/wokwi_projects.yml b/.github/workflows/wokwi_projects.yml index 4f77c582..20eae441 100644 --- a/.github/workflows/wokwi_projects.yml +++ b/.github/workflows/wokwi_projects.yml @@ -45,7 +45,7 @@ jobs: 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 }}'\nelf = '${{ matrix.project.name }}'" > ${{ matrix.project.path }}/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: | From af340fbb1a28e33c4a449a398ea2a7e4c11e1e42 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Mon, 20 Nov 2023 14:30:49 +0100 Subject: [PATCH 18/18] feat: Add button pressed message --- advanced/button-interrupt/examples/solution_led.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/button-interrupt/examples/solution_led.rs b/advanced/button-interrupt/examples/solution_led.rs index 0e5f7760..6e5686f7 100644 --- a/advanced/button-interrupt/examples/solution_led.rs +++ b/advanced/button-interrupt/examples/solution_led.rs @@ -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); }