Merge #667
667: Remove duplicate stm32-metapac/src/common.rs with chiptool r=Dirbaio a=nviennot There's a duplicate file common.rs with the chiptool crate. This PR makes the source of truth the one in chiptool. This PR is a good pair with https://github.com/embassy-rs/chiptool/pull/4 Co-authored-by: Nicolas Viennot <nicolas@viennot.biz>
This commit is contained in:
commit
01f8aa19a5
@ -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(
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -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"));
|
||||
|
Loading…
Reference in New Issue
Block a user