Skip to content

Commit

Permalink
peripheral
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed May 18, 2024
1 parent 25c2ba5 commit 904b44e
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 86 deletions.
1 change: 0 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub struct Config {
pub field_names_for_enums: bool,
pub base_address_shift: u64,
pub raw_access: bool,
pub raw_read_write: bool,
}

#[allow(clippy::upper_case_acronyms)]
Expand Down
14 changes: 8 additions & 6 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke

out.extend(quote! {
use core::ops::Deref;
use core::marker::PhantomData;
});
if !config.raw_access {
out.extend(quote! {
use core::marker::PhantomData;
});
}

// Retaining the previous assumption
let mut fpu_present = true;
Expand Down Expand Up @@ -140,7 +144,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
}

let generic_file = include_str!("generic.rs");
let generic_reg_file = if config.raw_read_write {
let generic_reg_file = if config.raw_access {
include_str!("generic_reg_raw.rs")
} else {
include_str!("generic_reg_vcell.rs")
Expand Down Expand Up @@ -253,9 +257,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
#feature_attribute
pub #p_singleton: #p_ty,
});
exprs.extend(
quote!(#feature_attribute #p_singleton: #p_ty { _marker: PhantomData },),
);
exprs.extend(quote!(#feature_attribute #p_singleton: unsafe { #p_ty::steal() },));
}
Peripheral::Array(p, dim_element) => {
for p_name in names(p, dim_element) {
Expand All @@ -271,7 +273,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
pub #p_singleton: #p_ty,
});
exprs.extend(
quote!(#feature_attribute #p_singleton: #p_ty { _marker: PhantomData },),
quote!(#feature_attribute #p_singleton: unsafe { #p_ty::steal() },),
);
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/generate/generic_reg_raw.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
/// This structure provides unsafe volatile access to registers.
pub struct Reg<REG: RegisterSpec> {
ptr: *mut u8,
_marker: marker::PhantomData<REG>,
}

unsafe impl<REG: RegisterSpec> Send for Reg<REG> where REG::Ux: Send {}

impl<REG: RegisterSpec> Reg<REG> {
#[inline(always)]
pub const fn new(ptr: *mut u8) -> Self {
Self {
ptr,
_marker: marker::PhantomData,
}
}
/// Returns the underlying memory address of register.
///
/// ```ignore
/// let reg_ptr = periph.reg.as_ptr();
/// ```
#[inline(always)]
pub fn as_ptr(&self) -> *mut REG::Ux {
(self as *const Self).cast_mut().cast()
pub const fn as_ptr(&self) -> *mut REG::Ux {
self.ptr.cast()
}
}

Expand Down Expand Up @@ -161,7 +169,7 @@ impl<REG: Readable + Writable> Reg<REG> {

impl<REG: Readable> core::fmt::Debug for crate::generic::Reg<REG>
where
R<REG>: core::fmt::Debug
R<REG>: core::fmt::Debug,
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
unsafe { core::fmt::Debug::fmt(&self.read(), f) }
Expand Down
Loading

0 comments on commit 904b44e

Please sign in to comment.