Skip to content

Commit 904b44e

Browse files
committed
peripheral
1 parent 25c2ba5 commit 904b44e

File tree

6 files changed

+240
-86
lines changed

6 files changed

+240
-86
lines changed

src/config.rs

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub struct Config {
3636
pub field_names_for_enums: bool,
3737
pub base_address_shift: u64,
3838
pub raw_access: bool,
39-
pub raw_read_write: bool,
4039
}
4140

4241
#[allow(clippy::upper_case_acronyms)]

src/generate/device.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
6363

6464
out.extend(quote! {
6565
use core::ops::Deref;
66-
use core::marker::PhantomData;
6766
});
67+
if !config.raw_access {
68+
out.extend(quote! {
69+
use core::marker::PhantomData;
70+
});
71+
}
6872

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

142146
let generic_file = include_str!("generic.rs");
143-
let generic_reg_file = if config.raw_read_write {
147+
let generic_reg_file = if config.raw_access {
144148
include_str!("generic_reg_raw.rs")
145149
} else {
146150
include_str!("generic_reg_vcell.rs")
@@ -253,9 +257,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
253257
#feature_attribute
254258
pub #p_singleton: #p_ty,
255259
});
256-
exprs.extend(
257-
quote!(#feature_attribute #p_singleton: #p_ty { _marker: PhantomData },),
258-
);
260+
exprs.extend(quote!(#feature_attribute #p_singleton: unsafe { #p_ty::steal() },));
259261
}
260262
Peripheral::Array(p, dim_element) => {
261263
for p_name in names(p, dim_element) {
@@ -271,7 +273,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
271273
pub #p_singleton: #p_ty,
272274
});
273275
exprs.extend(
274-
quote!(#feature_attribute #p_singleton: #p_ty { _marker: PhantomData },),
276+
quote!(#feature_attribute #p_singleton: unsafe { #p_ty::steal() },),
275277
);
276278
}
277279
}

src/generate/generic_reg_raw.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
/// This structure provides unsafe volatile access to registers.
22
pub struct Reg<REG: RegisterSpec> {
3+
ptr: *mut u8,
34
_marker: marker::PhantomData<REG>,
45
}
56

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

89
impl<REG: RegisterSpec> Reg<REG> {
10+
#[inline(always)]
11+
pub const fn new(ptr: *mut u8) -> Self {
12+
Self {
13+
ptr,
14+
_marker: marker::PhantomData,
15+
}
16+
}
917
/// Returns the underlying memory address of register.
1018
///
1119
/// ```ignore
1220
/// let reg_ptr = periph.reg.as_ptr();
1321
/// ```
1422
#[inline(always)]
15-
pub fn as_ptr(&self) -> *mut REG::Ux {
16-
(self as *const Self).cast_mut().cast()
23+
pub const fn as_ptr(&self) -> *mut REG::Ux {
24+
self.ptr.cast()
1725
}
1826
}
1927

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

162170
impl<REG: Readable> core::fmt::Debug for crate::generic::Reg<REG>
163171
where
164-
R<REG>: core::fmt::Debug
172+
R<REG>: core::fmt::Debug,
165173
{
166174
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
167175
unsafe { core::fmt::Debug::fmt(&self.read(), f) }

0 commit comments

Comments
 (0)