Remove duplicate stm32-metapac/src/common.rs with chiptool

This commit is contained in:
Nicolas Viennot 2022-03-15 03:20:19 -04:00
parent cb1be3983a
commit cfa7f4e55b
5 changed files with 12 additions and 82 deletions

View File

@ -332,7 +332,7 @@ impl Gen {
.unwrap(); .unwrap();
fs::write( fs::write(
self.opts.out_dir.join("src/common.rs"), self.opts.out_dir.join("src/common.rs"),
include_bytes!("../../stm32-metapac/src/common.rs"), chiptool::generate::COMMON_MODULE,
) )
.unwrap(); .unwrap();
fs::write( fs::write(

View File

@ -58,6 +58,10 @@ fn main() {
out_dir.display(), out_dir.display(),
chip_core_name chip_core_name
); );
println!(
"cargo:rustc-env=STM32_METAPAC_COMMON_PATH={}/src/common.rs",
out_dir.display(),
);
println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=build.rs");
} }

View File

@ -33,6 +33,10 @@ fn main() {
"cargo:rustc-env=STM32_METAPAC_METADATA_PATH=chips/{}/metadata.rs", "cargo:rustc-env=STM32_METAPAC_METADATA_PATH=chips/{}/metadata.rs",
chip_core_name chip_core_name
); );
println!(
"cargo:rustc-env=STM32_METAPAC_COMMON_PATH={}/src/common.rs",
crate_dir.display(),
);
println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=build.rs");
} }

View File

@ -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<T: Copy, A: Access> {
ptr: *mut u8,
phantom: PhantomData<*mut (T, A)>,
}
unsafe impl<T: Copy, A: Access> Send for Reg<T, A> {}
unsafe impl<T: Copy, A: Access> Sync for Reg<T, A> {}
impl<T: Copy, A: Access> Reg<T, A> {
pub fn from_ptr(ptr: *mut u8) -> Self {
Self {
ptr,
phantom: PhantomData,
}
}
pub fn ptr(&self) -> *mut T {
self.ptr as _
}
}
impl<T: Copy, A: Read> Reg<T, A> {
pub unsafe fn read(&self) -> T {
(self.ptr as *mut T).read_volatile()
}
}
impl<T: Copy, A: Write> Reg<T, A> {
pub unsafe fn write_value(&self, val: T) {
(self.ptr as *mut T).write_volatile(val)
}
}
impl<T: Default + Copy, A: Write> Reg<T, A> {
pub unsafe fn write<R>(&self, f: impl FnOnce(&mut T) -> R) -> R {
let mut val = Default::default();
let res = f(&mut val);
self.write_value(val);
res
}
}
impl<T: Copy, A: Read + Write> Reg<T, A> {
pub unsafe fn modify<R>(&self, f: impl FnOnce(&mut T) -> R) -> R {
let mut val = self.read();
let res = f(&mut val);
self.write_value(val);
res
}
}

View File

@ -4,7 +4,9 @@
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
#![doc(html_no_source)] #![doc(html_no_source)]
pub mod common; pub mod common {
include!(env!("STM32_METAPAC_COMMON_PATH"));
}
#[cfg(feature = "pac")] #[cfg(feature = "pac")]
include!(env!("STM32_METAPAC_PAC_PATH")); include!(env!("STM32_METAPAC_PAC_PATH"));