@@ -74,18 +74,18 @@ impl<REG: Resettable + Writable> Reg<REG> {
74
74
/// ```
75
75
/// In the latter case, other fields will be set to their reset value.
76
76
#[ inline( always) ]
77
- pub fn write < F > ( & self , f : F )
77
+ pub fn write < F > ( & self , f : F ) -> REG :: Ux
78
78
where
79
79
F : FnOnce ( & mut W < REG > ) -> & mut W < REG > ,
80
80
{
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
89
89
}
90
90
91
91
/// Writes bits to a `Writable` register and produce a value.
@@ -143,17 +143,17 @@ impl<REG: Writable> Reg<REG> {
143
143
///
144
144
/// Unsafe to use with registers which don't allow to write 0.
145
145
#[ inline( always) ]
146
- pub unsafe fn write_with_zero < F > ( & self , f : F )
146
+ pub unsafe fn write_with_zero < F > ( & self , f : F ) -> REG :: Ux
147
147
where
148
148
F : FnOnce ( & mut W < REG > ) -> & mut W < REG > ,
149
149
{
150
- self . register . set (
151
- f ( & mut W {
152
- bits : REG :: Ux :: default ( ) ,
153
- _reg : marker :: PhantomData ,
154
- } )
155
- . bits ,
156
- ) ;
150
+ let value = f ( & mut W {
151
+ bits : REG :: Ux :: default ( ) ,
152
+ _reg : marker :: PhantomData ,
153
+ } )
154
+ . bits ;
155
+ self . register . set ( value ) ;
156
+ value
157
157
}
158
158
159
159
/// Writes 0 to a `Writable` register and produces a value.
@@ -208,25 +208,24 @@ impl<REG: Readable + Writable> Reg<REG> {
208
208
/// ```
209
209
/// Other fields will have the value they had before the call to `modify`.
210
210
#[ inline( always) ]
211
- pub fn modify < F > ( & self , f : F )
211
+ pub fn modify < F > ( & self , f : F ) -> REG :: Ux
212
212
where
213
213
for < ' w > F : FnOnce ( & R < REG > , & ' w mut W < REG > ) -> & ' w mut W < REG > ,
214
214
{
215
215
let bits = self . register . get ( ) ;
216
- self . register . set (
217
- f (
218
- & R {
219
- bits,
220
- _reg : marker:: PhantomData ,
221
- } ,
222
- & mut W {
223
- bits : bits & !REG :: ONE_TO_MODIFY_FIELDS_BITMAP
224
- | REG :: ZERO_TO_MODIFY_FIELDS_BITMAP ,
225
- _reg : marker:: PhantomData ,
226
- } ,
227
- )
228
- . bits ,
229
- ) ;
216
+ let value = f (
217
+ & R {
218
+ bits,
219
+ _reg : marker:: PhantomData ,
220
+ } ,
221
+ & mut W {
222
+ bits : bits & !REG :: ONE_TO_MODIFY_FIELDS_BITMAP | REG :: ZERO_TO_MODIFY_FIELDS_BITMAP ,
223
+ _reg : marker:: PhantomData ,
224
+ } ,
225
+ )
226
+ . bits ;
227
+ self . register . set ( value) ;
228
+ value
230
229
}
231
230
232
231
/// Modifies the contents of the register by reading and then writing it
0 commit comments