@@ -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 /// Writes bits to a `Writable` register and produce a value.
@@ -143,17 +143,17 @@ impl<REG: Writable> Reg<REG> {
143143 ///
144144 /// Unsafe to use with registers which don't allow to write 0.
145145 #[ 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
147147 where
148148 F : FnOnce ( & mut W < REG > ) -> & mut W < REG > ,
149149 {
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
157157 }
158158
159159 /// Writes 0 to a `Writable` register and produces a value.
@@ -208,25 +208,24 @@ impl<REG: Readable + Writable> Reg<REG> {
208208 /// ```
209209 /// Other fields will have the value they had before the call to `modify`.
210210 #[ inline( always) ]
211- pub fn modify < F > ( & self , f : F )
211+ pub fn modify < F > ( & self , f : F ) -> REG :: Ux
212212 where
213213 for < ' w > F : FnOnce ( & R < REG > , & ' w mut W < REG > ) -> & ' w mut W < REG > ,
214214 {
215215 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
230229 }
231230
232231 /// Modifies the contents of the register by reading and then writing it
0 commit comments