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 5, 2023
1 parent 1d53369 commit 1a6c768
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

- removed register writer & reader wrappers, generic `REG` in field writers (#731)

## [v0.29.0] - 2023-06-05

- `FieldFpec` instead or `fty` generic (#722)
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 1a6c768

Please sign in to comment.