diff --git a/CHANGELOG.md b/CHANGELOG.md index f7281f75..91066df4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). - `FieldWriter` takes offset as struct field instead of const generic. Improves SVD field array access + Add `width`, `offset` methods - *breaking change* Always numerates field arrays from 0 ## [v0.30.2] - 2023-10-22 diff --git a/src/generate/generic.rs b/src/generate/generic.rs index e3cfa631..c34c2324 100644 --- a/src/generate/generic.rs +++ b/src/generate/generic.rs @@ -464,6 +464,18 @@ where /// Field width pub const WIDTH: u8 = WI; + /// Field width + #[inline(always)] + pub const fn width(&self) -> u8 { + WI + } + + /// Field offset + #[inline(always)] + pub const fn offset(&self) -> u8 { + self.o + } + /// Writes raw bits to the field /// /// # Safety @@ -491,6 +503,18 @@ where /// Field width pub const WIDTH: u8 = WI; + /// Field width + #[inline(always)] + pub const fn width(&self) -> u8 { + WI + } + + /// Field offset + #[inline(always)] + pub const fn offset(&self) -> u8 { + self.o + } + /// Writes raw bits to the field #[inline(always)] pub fn bits(self, value: FI::Ux) -> &'a mut W { @@ -521,6 +545,18 @@ macro_rules! bit_proxy { /// Field width pub const WIDTH: u8 = 1; + /// Field width + #[inline(always)] + pub const fn width(&self) -> u8 { + 1 + } + + /// Field offset + #[inline(always)] + pub const fn offset(&self) -> u8 { + self.o + } + /// Writes bit to the field #[inline(always)] pub fn bit(self, value: bool) -> &'a mut W {