diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index 14625097..c959e1a6 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs @@ -332,7 +332,7 @@ impl Gen { .unwrap(); fs::write( self.opts.out_dir.join("src/common.rs"), - include_bytes!("../../stm32-metapac/src/common.rs"), + chiptool::generate::COMMON_MODULE, ) .unwrap(); fs::write( diff --git a/stm32-metapac/build.rs b/stm32-metapac/build.rs index 44c10ece..32939eef 100644 --- a/stm32-metapac/build.rs +++ b/stm32-metapac/build.rs @@ -58,6 +58,10 @@ fn main() { out_dir.display(), chip_core_name ); + println!( + "cargo:rustc-env=STM32_METAPAC_COMMON_PATH={}/src/common.rs", + out_dir.display(), + ); println!("cargo:rerun-if-changed=build.rs"); } diff --git a/stm32-metapac/build_pregenerated.rs b/stm32-metapac/build_pregenerated.rs index 2219acb5..660a9553 100644 --- a/stm32-metapac/build_pregenerated.rs +++ b/stm32-metapac/build_pregenerated.rs @@ -33,6 +33,10 @@ fn main() { "cargo:rustc-env=STM32_METAPAC_METADATA_PATH=chips/{}/metadata.rs", chip_core_name ); + println!( + "cargo:rustc-env=STM32_METAPAC_COMMON_PATH={}/src/common.rs", + crate_dir.display(), + ); println!("cargo:rerun-if-changed=build.rs"); } diff --git a/stm32-metapac/src/common.rs b/stm32-metapac/src/common.rs deleted file mode 100644 index 568a9848..00000000 --- a/stm32-metapac/src/common.rs +++ /dev/null @@ -1,80 +0,0 @@ -use core::marker::PhantomData; - -#[derive(Copy, Clone, PartialEq, Eq)] -pub struct RW; -#[derive(Copy, Clone, PartialEq, Eq)] -pub struct R; -#[derive(Copy, Clone, PartialEq, Eq)] -pub struct W; - -mod sealed { - use super::*; - pub trait Access {} - impl Access for R {} - impl Access for W {} - impl Access for RW {} -} - -pub trait Access: sealed::Access + Copy {} -impl Access for R {} -impl Access for W {} -impl Access for RW {} - -pub trait Read: Access {} -impl Read for RW {} -impl Read for R {} - -pub trait Write: Access {} -impl Write for RW {} -impl Write for W {} - -#[derive(Copy, Clone, PartialEq, Eq)] -pub struct Reg { - ptr: *mut u8, - phantom: PhantomData<*mut (T, A)>, -} -unsafe impl Send for Reg {} -unsafe impl Sync for Reg {} - -impl Reg { - pub fn from_ptr(ptr: *mut u8) -> Self { - Self { - ptr, - phantom: PhantomData, - } - } - - pub fn ptr(&self) -> *mut T { - self.ptr as _ - } -} - -impl Reg { - pub unsafe fn read(&self) -> T { - (self.ptr as *mut T).read_volatile() - } -} - -impl Reg { - pub unsafe fn write_value(&self, val: T) { - (self.ptr as *mut T).write_volatile(val) - } -} - -impl Reg { - pub unsafe fn write(&self, f: impl FnOnce(&mut T) -> R) -> R { - let mut val = Default::default(); - let res = f(&mut val); - self.write_value(val); - res - } -} - -impl Reg { - pub unsafe fn modify(&self, f: impl FnOnce(&mut T) -> R) -> R { - let mut val = self.read(); - let res = f(&mut val); - self.write_value(val); - res - } -} diff --git a/stm32-metapac/src/lib.rs b/stm32-metapac/src/lib.rs index 4eab2986..58a1c5e4 100644 --- a/stm32-metapac/src/lib.rs +++ b/stm32-metapac/src/lib.rs @@ -4,7 +4,9 @@ #![allow(non_camel_case_types)] #![doc(html_no_source)] -pub mod common; +pub mod common { + include!(env!("STM32_METAPAC_COMMON_PATH")); +} #[cfg(feature = "pac")] include!(env!("STM32_METAPAC_PAC_PATH"));