tomoyuki-nakabayashi / embedded-rust-from-basics Goto Github PK
View Code? Open in Web Editor NEW中林智之、井田健太が執筆した『基礎から学ぶ 組込みRust』 (C&R研究所) のサポートサイトです。
中林智之、井田健太が執筆した『基礎から学ぶ 組込みRust』 (C&R研究所) のサポートサイトです。
P.227 の ADC 入力を 1 回取得する
の部分のタイトルが OneSho
になっています。
OneShot
が正しいかと思います。
wio::Pins::new()
により生成した各ピンは、デフォルトで Input<Floating>
という型なのですよね。
例えば p.170 で、改めて pins.button1.into_floating_input(&mut pins.port)
のように
into_floating_input()
を呼んでいるのはなぜなのでしょうか?
試しに into_floating_input()
を呼ばず、 let button1 = pins.button1;
などと書くと
コンパイルできますがボタン入力が読めませんでしたので、何か差があるとは思うのですが。
お疲れさまです。
P107から my_lib が出て来ているので、その流れからしてP108~109に記載されている new_module は my_module の方が良さそうに思います。
P108の下の方の
$ cargo new my_module
$ cd my_module
が正しい前提です。
(合わせるとしたら、 my_module の部分を new_module に変えた方が変更箇所は少ないのですけれど・・・)
些細なところですが改版の予定がありましたら、ついでに修正のご検討をお願いします。
(こちらの考えに誤りがありましたら無視して頂いて結構です)
些細な記載ミスです
p.283
誤) $ cargo hf2 --example hello_lcd
正) $ cargo hf2 --example 7-4-hello_lcd
お疲れさまです。
P174
誤植だと思われます。
非同期シリアル通信の後の()の中
誤:歩調同期方式
正:調歩同期方式
ご確認お願いします。
p.166の第1段落で
しかし、P.132のコードではsplit()メソッドを使用せず、atsamd-halクレートが用意しているより便利なAPIを利用しています。
とあります。
「便利なAPI」とは support::init()
のことでしょうか?
だとすると、p.166で紹介されている define_pins!
との関連性がよく分かりませんでした……
support::init()
が内部で define_pins!
を利用している、ということなのでしょうか?
もしかして、p.132ではなくp.165の一番上に書いてあるコード辺のことを指しているのであれば、
確かにsplit()を使用せず、(define_pins!により定義した?)Pins構造体を使っており、説明が符合すると感じますが。
度々すみません。
読むのに全然支障はないのですが、増刷のときとかに直っていると嬉しいです。
P.208の本文:
Rustの安全性の補償範囲外であるためunsafeな処理です。
補償範囲外
→ 保証範囲外
P.209のソースコード中:
カウントダウンタイマを現すトレイト
現す
→ 表す
P.214の本文:
Wio Terminalファームウェアを書き込むと
Wio Terminalファームウェアを
→ Wio Terminalにファームウェアを
P.224の本文:
マイコンにはADCが内蔵されているもの多く
内蔵されているもの多く
→ 内蔵されているものが多く
P.226のソースコード中:
PD1をACD入力として初期化し
ACD
→ ADC
P.232の本文:
I2Cはクロック信号で同期を行う同期式のリアル通信方式です。
リアル通信方式
→ シリアル通信方式
p.280のサンプルコード中のコメントに記載ミスがありました。
// データの送受信時は、D/Cをhightレベルにする
誤) hight
正) high
P.295 のストップウォッチのチャタリングの説明で
この現象への対象を簡単にするため
となっていますが、おそらくは
この現象への対応を簡単にするため
だと思われます。
LCDに接続しているピン一覧(p.272)
書籍(初版)の表が【誤】の方になっていると思います。
ご確認いただきたくお願いいたします。
【正】
説明 ピン名
MISO B18
MOSI B19
SCK B20
CS B21
【誤】
説明 ピン名
SCK B18
CS B19
MOSI B20
MISO B21
p.273の図、p.274のコードが正しいと思います。
embedded_graphics_web_simulator::*
のままではビルドできませんでした。
以下に変更することで npm start
できました。
@@ -1,26 +1,28 @@
-use embedded_graphics_web_simulator::*;
+use embedded_graphics_web_simulator::{
+ display::WebSimulatorDisplay, output_settings::OutputSettingsBuilder,
+};
use wasm_bindgen::prelude::*;
use web_sys::console;
use embedded_graphics::{
image::*,
pixelcolor::Rgb565,
prelude::*,
};
use wio_splash::WioSplash;
// This is like the `main` function, except for JavaScript.
#[wasm_bindgen(start)]
pub fn main_js() -> Result<(), JsValue> {
#[cfg(debug_assertions)]
console_error_panic_hook::set_once();
let output_settings = OutputSettingsBuilder::new().build();
let mut display = WebSimulatorDisplay::new((320, 240), &output_settings);
let raw = ImageRawLE::new(include_bytes!("./assets/ferris.raw"), 86, 64);
let splash = WioSplash::new(Rgb565::GREEN, raw);
splash.draw(&mut display).unwrap();
Ok(())
}
修正前のコード (書籍のまま) だと以下のエラーになりました。
$ cargo build
warning: Found `debug_assertions` in `target.'cfg(...)'.dependencies`. This value is not supported for selecting dependencies and will not work as expected. To learn more visit https://doc.rust-lang.org/carg
o/reference/specifying-dependencies.html#platform-specific-dependencies
Compiling basic_example v0.1.0 (/home/sago35/dev/src/github.com/rahul-thakoor/embedded-graphics-web-simulator/examples/basic)
error[E0433]: failed to resolve: use of undeclared type `OutputSettingsBuilder`
--> src/lib.rs:18:27
|
18 | let output_settings = OutputSettingsBuilder::new().build();
| ^^^^^^^^^^^^^^^^^^^^^ not found in this scope
|
help: consider importing one of these items
|
1 | use crate::output_settings::OutputSettingsBuilder;
|
1 | use embedded_graphics_web_simulator::output_settings::OutputSettingsBuilder;
|
error[E0433]: failed to resolve: use of undeclared type `WebSimulatorDisplay`
--> src/lib.rs:19:23
|
19 | let mut display = WebSimulatorDisplay::new((320, 240), &output_settings);
| ^^^^^^^^^^^^^^^^^^^ not found in this scope
|
help: consider importing one of these items
|
1 | use crate::display::WebSimulatorDisplay;
|
1 | use embedded_graphics_web_simulator::display::WebSimulatorDisplay;
|
warning: unused import: `embedded_graphics_web_simulator::*`
--> src/lib.rs:1:5
|
1 | use embedded_graphics_web_simulator::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `web_sys::console`
--> src/lib.rs:3:5
|
3 | use web_sys::console;
| ^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors; 2 warnings emitted
For more information about this error, try `rustc --explain E0433`.
error: could not compile `basic_example`
To learn more, run the command again with --verbose.
version 等は以下の通りです。
$ git remote -v
origin https://github.com/rahul-thakoor/embedded-graphics-web-simulator (fetch)
origin [email protected]:rahul-thakoor/embedded-graphics-web-simulator (push)
$ git rev-parse HEAD
8ba90f5404b59d3846b689d87f81254352adebee
P133のLチカを書いてみるで、コードを書き込んだのちcargo runをしようとしたのですが以下のエラーが出てしまいました。
何が問題でしょうか。よろしくお願いします。
error: failed to parse manifest at C:\Users\ユーザー名\my-blink\Cargo.toml
Caused by:
could not parse input as TOML
Caused by:
invalid escape character in string: c
at line 2 column 29
本書では GPIO をピン単位で読み書きする方法(split() する方法)は紹介されているのですが、
バイト単位(あるいは 32 ビット単位でも可)で読み書きする方法を知りたいです。
なぜかというと、PB0~PB7 に同じタイミングで信号を出したいからです。
試しに、PB0~PB3 の各ピンを順に set_high()
し、その後 set_low()
することを繰り返すプログラムを書いてみました。
こんな感じです。
loop {
pb0.set_high().unwrap();
pb1.set_high().unwrap();
pb2.set_high().unwrap();
pb3.set_high().unwrap();
pb0.set_low().unwrap();
pb1.set_low().unwrap();
pb2.set_low().unwrap();
pb3.set_low().unwrap();
}
各ピンの波形を観察すると、PB0~PB3 の信号は一斉にではなく、順に変化することが分かりました。
cargo build --release
でリリースビルドしたので、もしかしたら最適化されないかなと思いましたが、ダメでした。
オシロスコープの仕様で、4 つのグリッドに上から順にプローブ 1、3、2、4 が表示されています。
上から PB0、1、2、3 と並ぶように Wio Terminal とプローブを接続しています。
本当に些細なtypoです。
P.51の本文:
mutが付いていない変数はletで束縛したあとに値を変できないことが瞬時にわかります。
変できない
→ 変更できない
P.84の本文:
SensorFusionオブジェクトは、lightとtemparatureの所有権を保有しています。
temparature
→ temperature
p.159では「wio-examples」というプロジェクト名を付けることになっています。
cargo generateを実行してその名前を指定すると、その名前のディレクトリ以下に展開されます。
一方、p.252やp.284では「wio_examples」というディレクトリ名を期待していると思います。
p.159の記載を「wio_examples」に改めて、不一致を解消するのが良いのではないでしょうか。
https://github.com/tomoyuki-nakabayashi/Embedded-Rust-from-Basics/tree/main/debug
- "executable": "./target/thumbv7em-none-eabihf/debug/examples/8-2-led_and_button",
+ "executable": "./target/thumbv7em-none-eabihf/debug/examples/6-2-led_and_button",
私の環境の問題かもしれませんが、プログラムをWio-Terninalに書き込もうとすると、hf2がpanicする
Compiling wio-examples v0.1.0 (/Users/user/Developer/Rust/wio_examples)
Finished dev [unoptimized + debuginfo] target(s) in 10.52s
Searching for a connected device with known vid/pid pair.
Trying Ok(Some("Seeed Studio")) Ok(Some("Wio Terminal"))
Flashing "/Users/user/Developer/Rust/wio_examples/target/thumbv7em-none-eabihf/debug/examples/6-2-led_and_button"
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Communication', /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-hf2-0.3.1/src/main.rs:118:47
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
hf2の方にもissue出しました。
jacobrosenthal/hf2-rs#38
-//! $ cargo hf2 --example 7-4-splash
+//! $ cargo hf2 --example 7-4-splash --features="splash" --release
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.