Skip to content

Commit cdee930

Browse files
committed
return raw value from write/modify
1 parent 29bcfd8 commit cdee930

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

CHANGELOG.md

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

88
## [Unreleased]
99

10+
- *breaking change* Return raw writtened value
1011
- Add warning about indexing register arrays
1112
- Skip generating `.add(0)` and `1 *` in accessors
1213
- Bump MSRV of generated code to 1.76

src/generate/generic_reg_vcell.rs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,18 @@ impl<REG: Resettable + Writable> Reg<REG> {
7474
/// ```
7575
/// In the latter case, other fields will be set to their reset value.
7676
#[inline(always)]
77-
pub fn write<F>(&self, f: F)
77+
pub fn write<F>(&self, f: F) -> REG::Ux
7878
where
7979
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
8080
{
81-
self.register.set(
82-
f(&mut W {
83-
bits: REG::RESET_VALUE & !REG::ONE_TO_MODIFY_FIELDS_BITMAP
84-
| REG::ZERO_TO_MODIFY_FIELDS_BITMAP,
85-
_reg: marker::PhantomData,
86-
})
87-
.bits,
88-
);
81+
let value = f(&mut W {
82+
bits: REG::RESET_VALUE & !REG::ONE_TO_MODIFY_FIELDS_BITMAP
83+
| REG::ZERO_TO_MODIFY_FIELDS_BITMAP,
84+
_reg: marker::PhantomData,
85+
})
86+
.bits;
87+
self.register.set(value);
88+
value
8989
}
9090
}
9191

@@ -98,17 +98,17 @@ impl<REG: Writable> Reg<REG> {
9898
///
9999
/// Unsafe to use with registers which don't allow to write 0.
100100
#[inline(always)]
101-
pub unsafe fn write_with_zero<F>(&self, f: F)
101+
pub unsafe fn write_with_zero<F>(&self, f: F) -> REG::Ux
102102
where
103103
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
104104
{
105-
self.register.set(
106-
f(&mut W {
107-
bits: REG::Ux::default(),
108-
_reg: marker::PhantomData,
109-
})
110-
.bits,
111-
);
105+
let value = f(&mut W {
106+
bits: REG::Ux::default(),
107+
_reg: marker::PhantomData,
108+
})
109+
.bits;
110+
self.register.set(value);
111+
value
112112
}
113113
}
114114

@@ -139,25 +139,24 @@ impl<REG: Readable + Writable> Reg<REG> {
139139
/// ```
140140
/// Other fields will have the value they had before the call to `modify`.
141141
#[inline(always)]
142-
pub fn modify<F>(&self, f: F)
142+
pub fn modify<F>(&self, f: F) -> REG::Ux
143143
where
144144
for<'w> F: FnOnce(&R<REG>, &'w mut W<REG>) -> &'w mut W<REG>,
145145
{
146146
let bits = self.register.get();
147-
self.register.set(
148-
f(
149-
&R {
150-
bits,
151-
_reg: marker::PhantomData,
152-
},
153-
&mut W {
154-
bits: bits & !REG::ONE_TO_MODIFY_FIELDS_BITMAP
155-
| REG::ZERO_TO_MODIFY_FIELDS_BITMAP,
156-
_reg: marker::PhantomData,
157-
},
158-
)
159-
.bits,
160-
);
147+
let value = f(
148+
&R {
149+
bits,
150+
_reg: marker::PhantomData,
151+
},
152+
&mut W {
153+
bits: bits & !REG::ONE_TO_MODIFY_FIELDS_BITMAP | REG::ZERO_TO_MODIFY_FIELDS_BITMAP,
154+
_reg: marker::PhantomData,
155+
},
156+
)
157+
.bits;
158+
self.register.set(value);
159+
value
161160
}
162161
}
163162

0 commit comments

Comments
 (0)