Skip to content

Commit

Permalink
update to 015cd3d
Browse files Browse the repository at this point in the history
  • Loading branch information
Narukara committed Sep 2, 2024
1 parent b109780 commit 5c73e55
Show file tree
Hide file tree
Showing 43 changed files with 194 additions and 182 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ ENV LANG=C.UTF-8
# Arguments
ARG CONTAINER_USER=esp
ARG CONTAINER_GROUP=esp
ARG NIGHTLY_VERSION=nightly-2023-11-14
ARG ESP_IDF_VERSION=v5.1.2
ARG NIGHTLY_VERSION=nightly-2024-06-30
ARG ESP_IDF_VERSION=v5.2.2
ARG ESP_BOARD=esp32c3

# Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// "build": {
// "dockerfile": "Dockerfile",
// "args": {
// "NIGHTLY_VERSION": "nightly-2023-11-14"
// "NIGHTLY_VERSION": "nightly-2024-06-30"
// }
// },
"customizations": {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
这里是 https://github.com/esp-rs/std-training 的简体中文翻译

目前进度:已经翻译完成(部分更新的内容需要重新翻译),跟踪到 3ce0971
目前进度:已经翻译完成(部分更新的内容需要重新翻译),跟踪到 015cd3d

---

Expand Down
7 changes: 4 additions & 3 deletions advanced/button-interrupt/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]

[unstable]
build-std = ["panic_abort", "std"]
build-std-features = ["panic_immediate_abort"]

[env]
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
ESP_IDF_VERSION = { value = "tag:v5.1.2" }
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
ESP_IDF_VERSION = { value = "tag:v5.2.2" }

# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
Expand All @@ -26,3 +25,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
CRATE_CC_NO_DEFAULTS = "1"
10 changes: 7 additions & 3 deletions advanced/button-interrupt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ authors = [
edition = "2021"
resolver = "2"

[[bin]]
name = "button-interrupt"
harness = false # We can't use the default rust libtest harness for a crosscompile target

[profile.release]
opt-level = "s"

Expand All @@ -17,9 +21,9 @@ debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"

[dependencies]
anyhow = "=1.0.75"
esp-idf-svc = "=0.47.3"
anyhow = "=1.0.86"
esp-idf-svc = "=0.49.0"
rgb-led = { path = "../../common/lib/rgb-led" }

[build-dependencies]
embuild = "=0.31.4"
embuild = "=0.32.0"
3 changes: 3 additions & 0 deletions advanced/button-interrupt/examples/solution_led.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ fn main() -> Result<()> {
})?;
}

println!("Hello world!");


// ANCHOR: loop
loop {
// Enable interrupt and wait for new notificaton
Expand Down
2 changes: 1 addition & 1 deletion advanced/button-interrupt/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-11-14"
channel = "nightly-2024-06-30"
components = ["rust-src"]
7 changes: 4 additions & 3 deletions advanced/i2c-driver/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]

[unstable]
build-std = ["panic_abort", "std"]
build-std-features = ["panic_immediate_abort"]

[env]
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
ESP_IDF_VERSION = { value = "tag:v5.1.2" }
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
ESP_IDF_VERSION = { value = "tag:v5.2.2" }

# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
Expand All @@ -26,3 +25,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
CRATE_CC_NO_DEFAULTS = "1"
10 changes: 7 additions & 3 deletions advanced/i2c-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ authors = [
edition = "2021"
resolver = "2"

[[bin]]
name = "i2c-driver"
harness = false # We can't use the default rust libtest harness for a crosscompile target

[profile.release]
opt-level = "s"

Expand All @@ -16,9 +20,9 @@ debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"

[dependencies]
anyhow = "=1.0.75"
anyhow = "=1.0.86"
embedded-hal = "=0.2.7"
esp-idf-svc = "=0.47.3"
esp-idf-svc = "=0.49.0"

[build-dependencies]
embuild = "=0.31.4"
embuild = "=0.32.0"
2 changes: 1 addition & 1 deletion advanced/i2c-driver/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-11-14"
channel = "nightly-2024-06-30"
components = ["rust-src"]
7 changes: 4 additions & 3 deletions advanced/i2c-sensor-reading/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]

[unstable]
build-std = ["panic_abort", "std"]
build-std-features = ["panic_immediate_abort"]

[env]
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
ESP_IDF_VERSION = { value = "tag:v5.1.2" }
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
ESP_IDF_VERSION = { value = "tag:v5.2.2" }

# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
Expand All @@ -26,3 +25,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
CRATE_CC_NO_DEFAULTS = "1"
10 changes: 7 additions & 3 deletions advanced/i2c-sensor-reading/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ authors = [
edition = "2021"
resolver = "2"

[[bin]]
name = "i2c-sensor-reading"
harness = false # We can't use the default rust libtest harness for a crosscompile target

[profile.release]
opt-level = "s"

Expand All @@ -16,13 +20,13 @@ debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"

[dependencies]
anyhow = "=1.0.75"
anyhow = "=1.0.86"
embedded-hal = "=0.2.7"
esp-idf-svc = "=0.47.3"
esp-idf-svc = "=0.49.0"
icm42670 = "=0.1.1"
lis3dh = "=0.4.2"
shared-bus = "=0.3.1"
shtcx = "=0.11.0"

[build-dependencies]
embuild = "=0.31.4"
embuild = "=0.32.0"
2 changes: 1 addition & 1 deletion advanced/i2c-sensor-reading/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-11-14"
channel = "nightly-2024-06-30"
components = ["rust-src"]
4 changes: 2 additions & 2 deletions book/src/02_2_software.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

✅ 如果你的电脑上还没有安装 Rust,从 <https://rustup.rs/> 获取它

此外,对于 ESP32-C3,目前需要 Rust 工具链的 [*nightly* 版本](https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust)。本教程中我们将使用 `nightly-2023-11-14` 版本。
此外,对于 ESP32-C3,目前需要 Rust 工具链的 [*nightly* 版本](https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust)。本教程中我们将使用 `nightly-2024-06-30` 版本。

✅ 用以下命令安装 *nightly* Rust,并添加对目标架构的支持:

```console
rustup toolchain install nightly-2023-11-14 --component rust-src
rustup toolchain install nightly-2024-06-30 --component rust-src
```

🔎 Rust 能够交叉编译到任何支持的目标架构(参见 `rustup 目标列表`)。默认情况下,仅会安装本机的架构。
Expand Down
2 changes: 1 addition & 1 deletion book/src/02_3_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cd std-training

❗ Windows 用户可能会遇到[长路径名问题][windows-long-path]

[windows-long-path]: https://esp-rs.github.io/book/misc/troubleshooting.html#long-path-names
[windows-long-path]: https://docs.esp-rs.org/book/troubleshooting/index.html#long-path-names

## 仓库内容

Expand Down
2 changes: 1 addition & 1 deletion book/src/03_2_cargo_generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" } # 添加这一行

```toml
[toolchain]
channel = "nightly-2023-11-14" # 修改这一行
channel = "nightly-2024-06-30" # 修改这一行
```

✅ 在 `hello-world` 目录中用下面的命令来运行项目:
Expand Down
61 changes: 4 additions & 57 deletions book/src/03_5_3_mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,19 @@ client.subscribe(subscribe_topic, QoS::AtLeastOnce)
## 处理收到的消息


处理函数闭包里的 `message_event` 参数的类型是 `Result<Event<EspMqttMessage>`
因为我们只对接收成功的消息感兴趣,我们可以在闭包里使用模式匹配
处理函数闭包里的 `message_event` 参数的类型是 `EspMqttEvent`,它有一个 `payload()` 方法,用于访问 `EventPayload`
由于我们只对接收成功的消息感兴趣

```rust
let mut client =
EspMqttClient::new(
broker_url,
&mqtt_config,
move |message_event| match message_event {
Ok(Received(msg)) => process_message(msg, &mut led),
_ => warn!("Received from MQTT: {:?}", message_event),
},
)?;
{{#include ../../intro/mqtt/exercise/examples/solution_publ_rcv.rs:mqtt_client}}
```

在处理函数中,我们将会处理 `Complete` 消息。

💡 使用 Rust Analyzer 来生成缺失的 match 分支,或者匹配所有其他类型,输出一个 `info!()`

```rust
match message.details() {
// 本练习中的消息都会是 `Complete` 类型的
// `Details` 枚举的其他变体用于更大的消息 payload
Complete => {

// Cow<&[u8]> 可以被强制转换为 slice &[u8] 或 Vec<u8>
// 你可以将它强制转换为 slice ,用 try_from() 发送
let message_data: &[u8] = &message.data();
if let Ok(ColorData::BoardLed(color)) = ColorData::try_from(message_data) {
// 把 LED 配置为新收到的颜色

}
}
// 使用 Rust Analyzer 来生成缺失的 match 分支,或者匹配非 complete 的消息来输出日志消息。
}
{{#include ../../intro/mqtt/exercise/examples/solution_publ_rcv.rs:process_message}}
```

💡 用 logger 来查看接收到的东西,例如:`info!("{}", color);``dbg!(color)`
Expand All @@ -98,7 +76,6 @@ let raw = RawCommandData {
path: command,
data: message.data(),
};

```

检查 `host-client`:
Expand All @@ -109,36 +86,6 @@ let raw = RawCommandData {
let command = Command::BoardLed(color)
```

✅ 在 `process_message()` 函数中,你需要解析主题。

```rust
match message.details() {
Complete => {
// 本练习中的消息都会是 `Complete` 类型的
// `Details` 枚举的其他变体用于更大的消息 payload
//

// Cow<str> 的行为很像其他 Rust 字符串 (&str, String)
let topic: Cow<str> = message.topic(token);

// 确认我们是否对这个主题感兴趣
// 并根据它的内容来分发
let is_command_topic: bool = /* ... */;
if is_command_topic {
let raw = RawCommandData { /* ... */ };
if let Ok(Command::BoardLed(color)) = Command::try_from(raw) {
// 把 LED 配置为新收到的颜色
}

},
_ => {}
}
}
```

💡 由于你需要遍历 MQTT 主题,你需要对字符串执行 `split()` 并得到一个迭代器。你可以用 [`nth()`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.nth) 来直接访问迭代器中的特定项。
💡 可以用 `cargo run --example solution2` 运行实现了层次结构的解答。可以用 `cargo run``cargo run --example solution1` 运行未实现层次结构的解答。

### 其他任务

✅ 利用 [`serde_json`](https://docs.serde.rs/serde_json/) 将消息数据编码/解码为 JSON。
Expand Down
6 changes: 3 additions & 3 deletions common/lib/get-uuid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ authors = [
edition = "2021"

[dependencies]
anyhow = "=1.0.75"
anyhow = "=1.0.86"

[build-dependencies]
anyhow = "=1.0.75"
uuid = { version = "=1.6.1", features = ["v4"] }
anyhow = "=1.0.86"
uuid = { version = "=1.9.1", features = ["v4"] }
2 changes: 1 addition & 1 deletion common/lib/mqtt-messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ authors = [
edition = "2021"

[dependencies]
rgb = "=0.8.37"
rgb = "=0.8.40"
7 changes: 4 additions & 3 deletions common/lib/rgb-led/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]

[unstable]
build-std = ["panic_abort", "std"]
build-std-features = ["panic_immediate_abort"]

[env]
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
ESP_IDF_VERSION = { value = "tag:v5.1.2" }
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
ESP_IDF_VERSION = { value = "tag:v5.2.2" }

# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
Expand All @@ -26,3 +25,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
CRATE_CC_NO_DEFAULTS = "1"
8 changes: 4 additions & 4 deletions common/lib/rgb-led/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ edition = "2021"
authors = ["Sergio Gasquez <sergio.gasquez@gmail.com>"]

[dependencies]
anyhow = "=1.0.75"
esp-idf-svc = "=0.47.3"
log = "=0.4.20"
anyhow = "=1.0.86"
esp-idf-svc = "=0.49.0"
log = "=0.4.22"
rgb = "0.8.29"

[build-dependencies]
embuild = "=0.31.4"
embuild = "=0.32.0"
2 changes: 1 addition & 1 deletion common/lib/rgb-led/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-11-14"
channel = "nightly-2024-06-30"
components = ["rust-src"]
7 changes: 4 additions & 3 deletions common/lib/wifi/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]

[unstable]
build-std = ["panic_abort", "std"]
build-std-features = ["panic_immediate_abort"]

[env]
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
ESP_IDF_VERSION = { value = "tag:v5.1.2" }
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
ESP_IDF_VERSION = { value = "tag:v5.2.2" }

# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
Expand All @@ -26,3 +25,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
CRATE_CC_NO_DEFAULTS = "1"
Loading

0 comments on commit 5c73e55

Please sign in to comment.