Get the examples compiling again

This commit is contained in:
Dylan McKay 2020-07-03 01:37:00 +12:00
parent bd9d6d14e9
commit cb163a21bc
3 changed files with 24 additions and 9 deletions

View File

@ -19,6 +19,10 @@ build = "core_generator/build.rs"
keywords = ["avr", "arduino", "uno"] keywords = ["avr", "arduino", "uno"]
[build-dependencies] [dependencies]
avr-mcu = "0.2" target-cpu-macro = "0.1"
[build-dependencies]
avr-mcu = "0.3"
target-cpu-fetch = "0.1.0"

View File

@ -23,7 +23,11 @@ fn cores_path() -> PathBuf {
} }
fn core_module_name(mcu: &Mcu) -> String { 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() { fn main() {
@ -31,7 +35,7 @@ fn main() {
fs::create_dir_all(&cores_path()).expect("could not create cores directory"); 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() avr_mcu::current::mcu()
.expect("no target cpu specified") .expect("no target cpu specified")
} else { } else {
@ -76,14 +80,21 @@ fn generate_cores_mod_rs(mcus: &[Mcu]) -> Result<(), io::Error> {
let path = cores_path().join("mod.rs"); let path = cores_path().join("mod.rs");
let mut w = File::create(&path)?; 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)?; writeln!(w)?;
for mcu in mcus { for mcu in mcus {
let module_name = core_module_name(mcu); let module_name = core_module_name(mcu);
writeln!(w, "/// The {}.", mcu.device.name)?; writeln!(w, "/// The {}.", mcu.device.name)?;
writeln!(w, "pub mod {};", module_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) writeln!(w)
} }

View File

@ -1,8 +1,8 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
extern crate arduino; extern crate ruduino;
use arduino::cores::current; use ruduino::cores::current;
// Some devices may have multiple SPI modules. // Some devices may have multiple SPI modules.
// The ATmega328p only has one. // The ATmega328p only has one.