Skip to content

Commit

Permalink
additional translation
Browse files Browse the repository at this point in the history
  • Loading branch information
Narukara committed Sep 2, 2024
1 parent 5c73e55 commit 6ab166a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
20 changes: 10 additions & 10 deletions book/src/02_0_preparations.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

> 注释示例:像这样的注释包含了有用的信息
## Code Annotations
## 代码注释

In some Rust files, you can find some anchor comments:
在某些 Rust 源文件里,有类似这样的 anchor 注释:
```rust,ignore
// ANCHOR: test
let foo = 1;
...
// ANCHOR_END: test
```
Anchor comments can be ignored, they are only used to introduce those parts of code in this book. See [`mdBook` documentation](https://rust-lang.github.io/mdBook/format/mdbook.html#including-portions-of-a-file)
你可以忽略 Anchor 注释,它们只是用于把包含的代码导入到本书中。详见 [`mdBook` 文档](https://rust-lang.github.io/mdBook/format/mdbook.html#including-portions-of-a-file)

## 需要的硬件

Expand All @@ -31,14 +31,14 @@ Anchor comments can be ignored, they are only used to introduce those parts of c

> 不需要额外的调试器硬件。
## 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][wokwi] 仿真。寻找书中的指示来确认可以仿真的项目。仿真有两种方法实现:
- 使用 wokwi.com:直接在浏览器中执行构建、编辑代码。
- 使用 [Wokwi VS Code 扩展][wokwi-vscode]:用 VS Code 来编辑项目、执行构建。用 Wokwi VS Code 扩展对生成的二进制文件进行仿真。
- 这种方法需要一些[安装][wokwi-installation]
- 这种方法假定项目是在 debug 模式下构建的
- 这种方法允许[调试项目][wokwi-debug]

[wokwi]: https://wokwi.com/
[wokwi-vscode]: https://docs.wokwi.com/vscode/getting-started
Expand Down
30 changes: 15 additions & 15 deletions book/src/04_4_1_interrupts.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ cargo run --example solution
- 输入模式
- 上拉
- 上升沿触发中断
2. Instantiate a new notification and notifier
- See `hal::task::notification` documentation
3. In an `unsafe` block, create a subscription and its callback function.
- See `PinDriver::subscribe` and `task::notify_and_yield`
- The reasons for being `unsafe` are:
- The callback function will run in the [ISR (Interrupt Service Routine)](https://en.wikipedia.org/wiki/Interrupt_handler), so we should avoid calling any blocking functions on it, this includes STD, `libc` or FreeRTOS APIs (except for a few allowed ones).
- Callback closure is capturing its environment and you can use static variables inserted onto it. Captured variables need to outlive the subscription. You can also, use non-static variables, but that requires extra caution, see `esp_idf_hal::gpio::PinDriver::subscribe_nonstatic` documentation for more details.
4. In the loop, enable the interrupt, and wait for the notification
- The interruption should be enabled after each received notification, from a non-ISR context
- `esp_idf_svc::hal::delay::BLOCK` can be used for waiting
5. Run the program, push the `BOOT` button, and see how it works!

🔎 In this exercise we are using notifications, which only give the latest value, so if the interrupt is triggered
multiple times before the value of the notification is read, you will only be able to read the latest one. Queues,
on the other hand, allow receiving multiple values. See `esp_idf_hal::task::queue::Queue` for more details.
2. 实例化一个新的通知(notification)和 notifier
- 查看 `hal::task::notification` 文档
3. `unsafe` 块中,创建一个订阅(subscription)及其回调函数
- 查看 `PinDriver::subscribe` `task::notify_and_yield`
- `unsafe` 的原因是:
- 回调函数会运行在 [ISR(中断服务函数)](https://en.wikipedia.org/wiki/Interrupt_handler)中,所以我们需要避免调用任何可能阻塞的函数,包括 STD `libc` FreeRTOS API(少数允许的除外)。
- 回调闭包会从环境中捕获东西,你可以使用其中的静态变量。捕获的变量需要具有比订阅(subscription)更长的生命周期。你也可以使用非静态变量,但这需要额外小心,更多细节请参阅 `esp_idf_hal::gpio::PinDriver::subscribe_nonstatic` 文档。
4. 在循环中,使能中断,并等待通知(notification
- 应在每次收到通知后,使能中断(在非 ISR 上下文中)
- `esp_idf_svc::hal::delay::BLOCK` 可以用于等待
5. 运行程序,按下 `BOOT` 按钮,看看效果如何!

🔎 在本练习中,我们使用通知(notification),它只会提供最新的值。
因此如果在读取通知的值之前,中断被多次触发,你只能得到最新的值。
另一方面,队列允许接收多个值。更多详细信息请参阅 `esp_idf_hal::task::queue::Queue`

## Simulation

Expand Down

0 comments on commit 6ab166a

Please sign in to comment.