From d77344aca8d2fc70771a65cff1aad5533d949bc8 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Mon, 5 Jun 2023 20:08:26 +0300 Subject: [PATCH] hidden WRaw & RRaw for better docs --- CHANGELOG.md | 1 + src/generate/generic.rs | 23 ++++++++--------------- src/generate/register.rs | 7 +++---- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f837518..b386f07f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] +- removed register writer & reader wrappers, generic `REG` in field writers (#731) - Updated syn to version 2 (#732) ## [v0.29.0] - 2023-06-05 diff --git a/src/generate/generic.rs b/src/generate/generic.rs index c329da09..c589b149 100644 --- a/src/generate/generic.rs +++ b/src/generate/generic.rs @@ -256,7 +256,10 @@ impl Reg { /// /// Result of the `read` methods of registers. Also used as a closure argument in the `modify` /// method. -pub struct R { +pub type R = RRaw; + +#[doc(hidden)] +pub struct RRaw { pub(crate) bits: REG::Ux, _reg: marker::PhantomData, } @@ -284,25 +287,15 @@ where /// Register writer. /// /// Used as an argument to the closures in the `write` and `modify` methods of the register. -pub struct W { +pub type W = WRaw; + +#[doc(hidden)] +pub struct WRaw { ///Writable bits pub(crate) bits: REG::Ux, _reg: marker::PhantomData, } -impl W { - /// Writes raw bits to the register. - /// - /// # Safety - /// - /// Read datasheet or reference manual to find what values are allowed to pass. - #[inline(always)] - pub unsafe fn bits(&mut self, bits: REG::Ux) -> &mut Self { - self.bits = bits; - self - } -} - #[doc(hidden)] pub struct FieldReaderRaw where diff --git a/src/generate/register.rs b/src/generate/register.rs index 1e65886e..663b61c7 100644 --- a/src/generate/register.rs +++ b/src/generate/register.rs @@ -273,7 +273,6 @@ pub fn render_register_mod( mod_items.extend(w_impl_items); - /* // the writer can be safe if: // * there is a single field that covers the entire register // * that field can represent all values @@ -293,7 +292,7 @@ pub fn render_register_mod( #[doc = "Writes raw bits to the register."] #[inline(always)] pub fn bits(&mut self, bits: #rty) -> &mut Self { - unsafe { self.0.bits(bits) }; + self.bits = bits; self } }); @@ -302,11 +301,11 @@ pub fn render_register_mod( #[doc = "Writes raw bits to the register."] #[inline(always)] pub unsafe fn bits(&mut self, bits: #rty) -> &mut Self { - self.0.bits(bits); + self.bits = bits; self } }); - }*/ + } close.to_tokens(&mut mod_items); }