From cb163a21bc9d4376357286dc6b66f759f786e244 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Fri, 3 Jul 2020 01:37:00 +1200 Subject: [PATCH] Get the examples compiling again --- Cargo.toml | 8 ++++++-- core_generator/build.rs | 21 ++++++++++++++++----- examples/spi.rs | 4 ++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 634869e..e60deed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,10 @@ build = "core_generator/build.rs" keywords = ["avr", "arduino", "uno"] -[build-dependencies] -avr-mcu = "0.2" +[dependencies] +target-cpu-macro = "0.1" + +[build-dependencies] +avr-mcu = "0.3" +target-cpu-fetch = "0.1.0" diff --git a/core_generator/build.rs b/core_generator/build.rs index 7e19bcc..d64cb4d 100644 --- a/core_generator/build.rs +++ b/core_generator/build.rs @@ -23,7 +23,11 @@ fn cores_path() -> PathBuf { } fn core_module_name(mcu: &Mcu) -> String { - mcu.device.name.to_lowercase().to_owned() + normalize_device_name(&mcu.device.name) +} + +fn normalize_device_name(device_name: &str) -> String { + device_name.to_lowercase().to_owned() } fn main() { @@ -31,7 +35,7 @@ fn main() { fs::create_dir_all(&cores_path()).expect("could not create cores directory"); } - let current_mcu = if cfg!(arch = "avr") { + let current_mcu = if avr_mcu::current::is_compiling_for_avr() { avr_mcu::current::mcu() .expect("no target cpu specified") } else { @@ -76,14 +80,21 @@ fn generate_cores_mod_rs(mcus: &[Mcu]) -> Result<(), io::Error> { let path = cores_path().join("mod.rs"); let mut w = File::create(&path)?; + if avr_mcu::current::is_compiling_for_avr() { + let current_mcu_name = target_cpu_fetch::target_cpu().expect("could not get the target CPU for ruduino core generation"); + + writeln!(w)?; + if let Some(current_mcu_name) = current_mcu_name { + writeln!(w, "/// Expose the current MCU core ({}).", current_mcu_name)?; + writeln!(w, "pub use self::{} as current;", current_mcu_name)?; + } + } + writeln!(w)?; for mcu in mcus { let module_name = core_module_name(mcu); writeln!(w, "/// The {}.", mcu.device.name)?; writeln!(w, "pub mod {};", module_name)?; - - writeln!(w, "#[cfg(all(target_arch = \"avr\", target_cpu = \"{}\"))]", module_name)?; - writeln!(w, "pub use self::{} as current;", module_name)?; } writeln!(w) } diff --git a/examples/spi.rs b/examples/spi.rs index ccecf27..1ff200d 100644 --- a/examples/spi.rs +++ b/examples/spi.rs @@ -1,8 +1,8 @@ #![no_std] #![no_main] -extern crate arduino; -use arduino::cores::current; +extern crate ruduino; +use ruduino::cores::current; // Some devices may have multiple SPI modules. // The ATmega328p only has one.