Skip to content

Commit 1a6c768

Browse files
committed
hidden WRaw & RRaw for better docs
1 parent 1d53369 commit 1a6c768

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
99

10+
- removed register writer & reader wrappers, generic `REG` in field writers (#731)
11+
1012
## [v0.29.0] - 2023-06-05
1113

1214
- `FieldFpec` instead or `fty` generic (#722)

src/generate/generic.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,10 @@ impl<REG: Readable + Writable> Reg<REG> {
256256
///
257257
/// Result of the `read` methods of registers. Also used as a closure argument in the `modify`
258258
/// method.
259-
pub struct R<REG: RegisterSpec + ?Sized> {
259+
pub type R<REG> = RRaw<REG>;
260+
261+
#[doc(hidden)]
262+
pub struct RRaw<REG: RegisterSpec> {
260263
pub(crate) bits: REG::Ux,
261264
_reg: marker::PhantomData<REG>,
262265
}
@@ -284,25 +287,15 @@ where
284287
/// Register writer.
285288
///
286289
/// Used as an argument to the closures in the `write` and `modify` methods of the register.
287-
pub struct W<REG: RegisterSpec + ?Sized> {
290+
pub type W<REG> = WRaw<REG>;
291+
292+
#[doc(hidden)]
293+
pub struct WRaw<REG: RegisterSpec> {
288294
///Writable bits
289295
pub(crate) bits: REG::Ux,
290296
_reg: marker::PhantomData<REG>,
291297
}
292298

293-
impl<REG: RegisterSpec> W<REG> {
294-
/// Writes raw bits to the register.
295-
///
296-
/// # Safety
297-
///
298-
/// Read datasheet or reference manual to find what values are allowed to pass.
299-
#[inline(always)]
300-
pub unsafe fn bits(&mut self, bits: REG::Ux) -> &mut Self {
301-
self.bits = bits;
302-
self
303-
}
304-
}
305-
306299
#[doc(hidden)]
307300
pub struct FieldReaderRaw<FI = u8>
308301
where

src/generate/register.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ pub fn render_register_mod(
273273

274274
mod_items.extend(w_impl_items);
275275

276-
/*
277276
// the writer can be safe if:
278277
// * there is a single field that covers the entire register
279278
// * that field can represent all values
@@ -293,7 +292,7 @@ pub fn render_register_mod(
293292
#[doc = "Writes raw bits to the register."]
294293
#[inline(always)]
295294
pub fn bits(&mut self, bits: #rty) -> &mut Self {
296-
unsafe { self.0.bits(bits) };
295+
self.bits = bits;
297296
self
298297
}
299298
});
@@ -302,11 +301,11 @@ pub fn render_register_mod(
302301
#[doc = "Writes raw bits to the register."]
303302
#[inline(always)]
304303
pub unsafe fn bits(&mut self, bits: #rty) -> &mut Self {
305-
self.0.bits(bits);
304+
self.bits = bits;
306305
self
307306
}
308307
});
309-
}*/
308+
}
310309

311310
close.to_tokens(&mut mod_items);
312311
}

0 commit comments

Comments
 (0)