diff --git a/mdbook/src/09-led-compass/Cargo.toml b/mdbook/src/09-led-compass/Cargo.toml index fc7bbe2..d35b513 100644 --- a/mdbook/src/09-led-compass/Cargo.toml +++ b/mdbook/src/09-led-compass/Cargo.toml @@ -6,10 +6,13 @@ edition = "2021" [dependencies] microbit-v2 = "0.15.0" -cortex-m = "0.7.7" cortex-m-rt = "0.7.3" rtt-target = "0.5.0" panic-rtt-target = "0.1.3" lsm303agr = "1.1.0" libm = "0.2.8" embedded-hal = "1.0.0" + +[dependencies.cortex-m] +version = "0.7.7" +features = ["critical-section-single-core"] diff --git a/mdbook/src/09-led-compass/src/calibration.rs b/mdbook/src/09-led-compass/src/calibration.rs index 6bf13f4..c3360f7 100644 --- a/mdbook/src/09-led-compass/src/calibration.rs +++ b/mdbook/src/09-led-compass/src/calibration.rs @@ -1,8 +1,8 @@ //! Translated from use core::fmt::Debug; -use embedded_hal::blocking::delay::DelayUs; -use embedded_hal::blocking::i2c::{Write, WriteRead}; +use embedded_hal::i2c::I2c; +use embedded_hal::delay::DelayNs; use libm::{fabsf, sqrtf}; use lsm303agr::interface::I2cInterface; use lsm303agr::mode::MagContinuous; @@ -43,8 +43,8 @@ pub fn calc_calibration( timer: &mut T, ) -> Calibration where - T: DelayUs, - I: Write + WriteRead, + T: DelayNs, + I: I2c, E: Debug, { let data = get_data(sensor, display, timer); @@ -57,8 +57,8 @@ fn get_data( timer: &mut T, ) -> [Measurement; 25] where - T: DelayUs, - I: Write + WriteRead, + T: DelayNs, + I: I2c, E: Debug, { let mut leds = [ diff --git a/mdbook/src/10-punch-o-meter/Cargo.toml b/mdbook/src/10-punch-o-meter/Cargo.toml index 0bbb5cd..981c1bc 100644 --- a/mdbook/src/10-punch-o-meter/Cargo.toml +++ b/mdbook/src/10-punch-o-meter/Cargo.toml @@ -6,9 +6,11 @@ edition = "2021" [dependencies] microbit-v2 = "0.15.0" -cortex-m = "0.7.7" cortex-m-rt = "0.7.3" rtt-target = "0.5.0" panic-rtt-target = "0.1.3" lsm303agr = "1.1.0" -nb = "1.1.0" + +[dependencies.cortex-m] +version = "0.7.7" +features = ["inline-asm", "critical-section-single-core"] diff --git a/mdbook/src/10-punch-o-meter/build.rs b/mdbook/src/10-punch-o-meter/build.rs deleted file mode 100644 index c8d8c91..0000000 --- a/mdbook/src/10-punch-o-meter/build.rs +++ /dev/null @@ -1,30 +0,0 @@ -//! This build script copies the `memory.x` file from the crate root into -//! a directory where the linker can always find it at build time. -//! For many projects this is optional, as the linker always searches the -//! project root directory (wherever `Cargo.toml` is). However, if you -//! are using a workspace or have a more complicated build setup, this -//! build script becomes required. Additionally, by requesting that -//! Cargo re-run the build script whenever `memory.x` is changed, -//! a rebuild of the application with new memory settings is ensured after updating `memory.x`. - -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - // Put `memory.x` in our output directory and ensure it's - // on the linker search path. - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - File::create(out.join("memory.x")) - .unwrap() - .write_all(include_bytes!("memory.x")) - .unwrap(); - println!("cargo:rustc-link-search={}", out.display()); - - // By default, Cargo will re-run a build script whenever - // any file in the project changes. By specifying `memory.x` - // here, we ensure the build script is only re-run when - // `memory.x` is changed. - println!("cargo:rerun-if-changed=memory.x"); -} diff --git a/mdbook/src/10-punch-o-meter/memory.x b/mdbook/src/10-punch-o-meter/memory.x deleted file mode 100644 index 9e2ab65..0000000 --- a/mdbook/src/10-punch-o-meter/memory.x +++ /dev/null @@ -1,6 +0,0 @@ -MEMORY -{ - /* NOTE K = KiBi = 1024 bytes */ - FLASH : ORIGIN = 0x00000000, LENGTH = 256K - RAM : ORIGIN = 0x20000000, LENGTH = 16K -} diff --git a/mdbook/src/10-punch-o-meter/src/main.rs b/mdbook/src/10-punch-o-meter/src/main.rs index d14dc20..9a38836 100644 --- a/mdbook/src/10-punch-o-meter/src/main.rs +++ b/mdbook/src/10-punch-o-meter/src/main.rs @@ -2,14 +2,17 @@ #![no_main] #![no_std] +use cortex_m::asm::wfi; use cortex_m_rt::entry; -use rtt_target::rtt_init_print; use panic_rtt_target as _; +use rtt_target::rtt_init_print; #[entry] fn main() -> ! { rtt_init_print!(); let _board = microbit::Board::take().unwrap(); - loop {} + loop { + wfi(); + } }