File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,34 @@ where
168168 }
169169 }
170170
171+ /// Set this set of pins to the state given in a single operation.
172+ ///
173+ /// The state passed in must be a mask where each bit corresponds to a gpio.
174+ ///
175+ /// For example, if the group contains Gpio1 and Gpio3, a read may yield:
176+ /// ```text
177+ /// 0b0000_0000__0000_0000__0000_0000__0000_1010
178+ /// This is Gpio3 ↑↑↑
179+ /// Gpio2 is not used ||
180+ /// This is Gpio1 |
181+ /// ```
182+ ///
183+ /// State corresponding to bins not in this group are ignored.
184+ pub fn set_u32 ( & mut self , state : u32 ) {
185+ use super :: pin:: pin_sealed:: PinIdOps ;
186+ let mask = self . 0 . write_mask ( ) ;
187+ let state_masked = mask & state;
188+ let head_id = self . 0 . head . borrow ( ) . id ( ) ;
189+ // UNSAFE: this register is 32bit wide and all bits are valid.
190+ // The value set is masked
191+ head_id. sio_out ( ) . modify ( |r, w| unsafe {
192+ // clear all bit part of this group
193+ let cleared = r. bits ( ) & !mask;
194+ // set bits according to state
195+ w. bits ( cleared | state_masked)
196+ } ) ;
197+ }
198+
171199 /// Toggles this set of pins all at the same time.
172200 ///
173201 /// This only affects output pins. Input pins in the
You can’t perform that action at this time.
0 commit comments