Skip to content

Commit

Permalink
Add RegisterBlock trait
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Jun 2, 2020
1 parent d894fd1 commit e10defc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- RegisterBlock trait (like `Deref`, but don't require `self` instance,
only for fixed in memory peripherals)
- Generated crates now contain the git commit hash and date of svd2rust
compilation.

Expand Down
9 changes: 9 additions & 0 deletions src/generate/generic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
use core::marker;

///This trait allows to get raw pointer on derived peripheral
///as block of registers of base peripheral (like unsafe `Deref`)
pub trait RegisterBlock {
///Type of RegisterBlock of base peripheral
type RB;
///Take peripheral address as raw pointer
fn rb() -> *const Self::RB;
}

/// Trait implemented by readable registers to enable the `read` method.
///
/// Registers marked with `Writable` can be also `modify`'ed.
Expand Down
8 changes: 8 additions & 0 deletions src/generate/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ pub fn render(
unsafe { &*#name_pc::ptr() }
}
}
impl crate::RegisterBlock for #name_pc {
type RB = #base::RegisterBlock;

#[inline(always)]
fn rb() -> *const Self::RB {
#name_pc::ptr()
}
}
});

// Derived peripherals may not require re-implementation, and will instead
Expand Down

0 comments on commit e10defc

Please sign in to comment.