@@ -141,7 +141,11 @@ impl Cr2 {
141141
142142 pub fn read (& self ) -> Cr2R { .. }
143143
144- pub fn write (& mut self , value : Cr2W ) { .. }
144+ pub fn write <F >(& mut self , f : F )
145+ where F : FnOnce (& mut Cr2W ) -> & mut Cr2W ,
146+ {
147+ ..
148+ }
145149}
146150```
147151
@@ -172,10 +176,12 @@ if i2c1.c2r.read().sadd0() {
172176```
173177
174178The ` write ` method performs a single, volatile ` STR ` instruction to write a value to the ` CR2 `
175- register. This method takes a ` Cr2W ` struct that only allows constructing valid states of the ` CR2 `
176- register. The only constructor that ` Cr2W ` provides is ` reset_value ` which returns the value of the
177- ` CR2 ` register after a reset. The rest of ` Cr2W ` methods are "builder" like and can be used to set
178- or reset the writable bits of the ` CR2 ` register.
179+ register. This method involves the ` Cr2W ` struct which only allows constructing valid states of the
180+ ` CR2 ` register.
181+
182+ The only constructor that ` Cr2W ` provides is ` reset_value ` which returns the value of the ` CR2 `
183+ register after a reset. The rest of ` Cr2W ` methods are "builder" like and can be used to set or
184+ reset the writable bits of the ` CR2 ` register.
179185
180186``` rust
181187impl Cr2W {
@@ -192,10 +198,15 @@ impl Cr2W {
192198}
193199```
194200
201+ The ` write ` method takes a closure with signature ` &mut Cr2W -> &mut Cr2W ` . If passed the identity
202+ closure, ` |w| w ` , the ` write ` method will set the ` CR2 ` register to its reset value. Otherwise, the
203+ closure specifies how that reset value will be modified before it's written to ` CR2 ` .
204+
195205Usage looks like this:
196206
197207``` rust
198- i2c1 . cr2. write (* Cr2W :: reset_value (). sadd0 (true ). sadd1 (0b0011110 ));
208+ // Write to CR2, its reset value but with its SADD0 and SADD1 fields set to `true` and `0b0011110`
209+ i2c1 . cr2. write (| w | w . sadd0 (true ). sadd1 (0b0011110 ));
199210```
200211
201212Finally, the ` modify ` method performs a read-modify-write operation that involves at least a ` LDR `
0 commit comments