Skip to content

Commit

Permalink
hidden WRaw & RRaw for better docs
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Jun 6, 2023
1 parent 129a548 commit d77344a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 8 additions & 15 deletions src/generate/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ impl<REG: Readable + Writable> Reg<REG> {
///
/// Result of the `read` methods of registers. Also used as a closure argument in the `modify`
/// method.
pub struct R<REG: RegisterSpec + ?Sized> {
pub type R<REG> = RRaw<REG>;

#[doc(hidden)]
pub struct RRaw<REG: RegisterSpec> {
pub(crate) bits: REG::Ux,
_reg: marker::PhantomData<REG>,
}
Expand Down Expand Up @@ -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<REG: RegisterSpec + ?Sized> {
pub type W<REG> = WRaw<REG>;

#[doc(hidden)]
pub struct WRaw<REG: RegisterSpec> {
///Writable bits
pub(crate) bits: REG::Ux,
_reg: marker::PhantomData<REG>,
}

impl<REG: RegisterSpec> W<REG> {
/// 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<FI = u8>
where
Expand Down
7 changes: 3 additions & 4 deletions src/generate/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
});
Expand All @@ -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);
}
Expand Down

0 comments on commit d77344a

Please sign in to comment.