Skip to content

Commit d3b28a4

Browse files
committed
Implement set_u32 for PinGroup on rp235x
1 parent bfde496 commit d3b28a4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

rp235x-hal/src/gpio/pin_group.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)