Skip to content

Commit 6e9acaa

Browse files
committed
always raw access
1 parent 1760b5e commit 6e9acaa

9 files changed

Lines changed: 504 additions & 64 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
99

10+
- Add `raw-access` options
1011
- Use marker struct instead of address in `Periph` with `PeripheralSpec` trait
1112

1213
## [v0.37.1] - 2025-10-17
@@ -973,7 +974,8 @@ peripheral.register.write(|w| w.field().set());
973974

974975
- Initial version of the `svd2rust` tool
975976

976-
[Unreleased]: https://github.com/rust-embedded/svd2rust/compare/v0.37.0...HEAD
977+
[Unreleased]: https://github.com/rust-embedded/svd2rust/compare/v0.37.1...HEAD
978+
[v0.37.1]: https://github.com/rust-embedded/svd2rust/compare/v0.37.0...v0.37.1
977979
[v0.37.0]: https://github.com/rust-embedded/svd2rust/compare/v0.36.1...v0.37.0
978980
[v0.36.1]: https://github.com/rust-embedded/svd2rust/compare/v0.36.0...v0.36.1
979981
[v0.36.0]: https://github.com/rust-embedded/svd2rust/compare/v0.35.0...v0.36.0

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub struct Config {
4141
pub ident_formats_theme: Option<IdentFormatsTheme>,
4242
pub field_names_for_enums: bool,
4343
pub base_address_shift: u64,
44+
pub raw_access: bool,
4445
/// Path to YAML file with chip-specific settings
4546
pub settings_file: Option<PathBuf>,
4647
/// Chip-specific settings

src/generate/device.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
137137
}
138138

139139
let generic_file = include_str!("generic.rs");
140-
let generic_reg_file = include_str!("generic_reg_vcell.rs");
140+
let generic_reg_file = if config.raw_access {
141+
include_str!("generic_reg_raw.rs")
142+
} else {
143+
include_str!("generic_reg_vcell.rs")
144+
};
141145
let generic_atomic_file = include_str!("generic_atomic.rs");
142146
if config.generic_mod {
143147
let mut file = File::create(

src/generate/generic.rs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
use core::marker;
22

3-
/// Generic peripheral accessor
4-
pub struct Periph<PER: PeripheralSpec> {
5-
_marker: marker::PhantomData<PER>,
6-
}
7-
8-
/// Peripheral data
9-
pub trait PeripheralSpec {
10-
/// RegisterBlock associated with peripheral
11-
type RB;
12-
/// Address of the register block
13-
const ADDRESS: usize;
14-
/// Debug name
15-
const NAME: &'static str;
16-
}
17-
183
unsafe impl<PER: PeripheralSpec> Send for Periph<PER> {}
194

205
impl<PER: PeripheralSpec> core::fmt::Debug for Periph<PER> {
@@ -32,34 +17,6 @@ impl<PER: PeripheralSpec> Periph<PER> {
3217
pub const fn ptr() -> *const PER::RB {
3318
Self::PTR
3419
}
35-
36-
/// Steal an instance of this peripheral
37-
///
38-
/// # Safety
39-
///
40-
/// Ensure that the new instance of the peripheral cannot be used in a way
41-
/// that may race with any existing instances, for example by only
42-
/// accessing read-only or write-only registers, or by consuming the
43-
/// original peripheral and using critical sections to coordinate
44-
/// access between multiple new instances.
45-
///
46-
/// Additionally, other software such as HALs may rely on only one
47-
/// peripheral instance existing to ensure memory safety; ensure
48-
/// no stolen instances are passed to such software.
49-
pub unsafe fn steal() -> Self {
50-
Self {
51-
_marker: marker::PhantomData,
52-
}
53-
}
54-
}
55-
56-
impl<PER: PeripheralSpec> core::ops::Deref for Periph<PER> {
57-
type Target = PER::RB;
58-
59-
#[inline(always)]
60-
fn deref(&self) -> &Self::Target {
61-
unsafe { &*Self::PTR }
62-
}
6320
}
6421

6522
/// Raw register type (`u8`, `u16`, `u32`, ...)

0 commit comments

Comments
 (0)