@@ -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
@@ -98,17 +98,17 @@ impl<REG: Writable> Reg<REG> {
98
98
///
99
99
/// Unsafe to use with registers which don't allow to write 0.
100
100
#[ 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
102
102
where
103
103
F : FnOnce ( & mut W < REG > ) -> & mut W < REG > ,
104
104
{
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
112
112
}
113
113
}
114
114
@@ -139,25 +139,24 @@ impl<REG: Readable + Writable> Reg<REG> {
139
139
/// ```
140
140
/// Other fields will have the value they had before the call to `modify`.
141
141
#[ inline( always) ]
142
- pub fn modify < F > ( & self , f : F )
142
+ pub fn modify < F > ( & self , f : F ) -> REG :: Ux
143
143
where
144
144
for < ' w > F : FnOnce ( & R < REG > , & ' w mut W < REG > ) -> & ' w mut W < REG > ,
145
145
{
146
146
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
161
160
}
162
161
}
163
162
0 commit comments