diff --git a/Cargo.lock b/Cargo.lock index 4c5dbc7e1c401dde15195de86bb2ee6cb21d616c..3215f9d65fb72b0e6aaf8012c0d0397abc38a7d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -284,6 +284,14 @@ name = "rustc-demangle" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "sensor-plot" +version = "0.1.0" +dependencies = [ + "card10-l0dable 0.1.1", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "shlex" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index abacb54b54a7d6d93d904c616cf49ed7906ca5ba..3df3a6cfa9187e338a362a882e7169a6bd32a88f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = [ "l0dable", "example", "rkanoid", + "sensor-plot", ] default-members = [ "example", diff --git a/sensor-plot/.cargo/config b/sensor-plot/.cargo/config new file mode 100644 index 0000000000000000000000000000000000000000..ce93b2d04c5c1545b035246ce836dc02801bf6a2 --- /dev/null +++ b/sensor-plot/.cargo/config @@ -0,0 +1,10 @@ +[target.thumbv7em-none-eabi] +rustflags = [ + "-C", "linker=arm-none-eabi-gcc", + "-C", "link-args=-Tl0dable.ld -n -pie -fPIC", + "-C", "relocation-model=pic", +] + +[build] +target = "thumbv7em-none-eabi" # Cortex-M4F and Cortex-M7F (with FPU) + diff --git a/sensor-plot/Cargo.toml b/sensor-plot/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..e8b4df5009fdfd71a405da3aa5f7d7d419d0ecd7 --- /dev/null +++ b/sensor-plot/Cargo.toml @@ -0,0 +1,11 @@ +[package] +edition = "2018" +name = "sensor-plot" +version = "0.1.0" +authors = ["Raphael Nestler <rnestler@coredump.ch>"] + +[dependencies] +card10-l0dable = { path = "../l0dable" } + +[build-dependencies] +cc = "1.0" diff --git a/sensor-plot/src/main.rs b/sensor-plot/src/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..f1fd62e91cfba346e7e9989ce2e8fd536b116a6f --- /dev/null +++ b/sensor-plot/src/main.rs @@ -0,0 +1,31 @@ +#![no_std] +#![no_main] + +use card10_l0dable::*; +use core::fmt::Write; + +main!(main); +fn main() { + writeln!(UART, "Hello from Rust\r").unwrap(); + + let mut buffer = [0u16; Display::W as usize]; + let mut index = 0usize; + + let display = Display::open(); + let light = LightSensor::start(); + + loop { + let sample = light.get().unwrap_or(0); + buffer[index] = sample; + index += 1; + if index >= Display::W as usize { + index = 0; + } + + display.clear(Color::black()); + for i in 0..Display::W { + display.pixel(i, Display::H - 1 - buffer[i as usize], Color::white()); + } + display.update(); + } +}