Skip to content

Commit 6c0e369

Browse files
Ivar Jönssontmplt
Ivar Jönsson
authored andcommitted
hal/pio/reg: into_peripheral: correctly set/clear abcdsr
Before this commit other pin bits were not preserved. Closes atsams-rs#16.
1 parent 23eb020 commit 6c0e369

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

hal/src/pio/reg.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,22 @@ pub(in crate::pio) unsafe trait RegisterInterface {
3131
fn into_peripheral(&mut self, cfg: DynPeripheral) {
3232
use DynPeripheral::*;
3333
let (sr0, sr1) = match cfg {
34-
A => (0, 0),
35-
B => (1, 0),
36-
C => (0, 1),
37-
D => (1, 1),
34+
A => (false, false),
35+
B => (true, false),
36+
C => (false, true),
37+
D => (true, true),
3838
};
3939
let idx = self.id().num;
4040

41-
// configure function
42-
self.reg().pio_abcdsr[0].modify(|_, w| unsafe { w.bits(sr0 << idx) });
43-
self.reg().pio_abcdsr[1].modify(|_, w| unsafe { w.bits(sr1 << idx) });
41+
// configure function, preserving other pin bits
42+
for (i, bit) in (0..=1).zip([sr0, sr1]) {
43+
self.reg().pio_abcdsr[i].modify(|r, w| unsafe {
44+
w.bits(match bit {
45+
true => r.bits() | 1 << idx,
46+
false => r.bits() & !(1 << idx),
47+
})
48+
});
49+
}
4450

4551
// give pin to peripheral
4652
self.reg().pio_pdr.write(|w| unsafe { w.bits(self.mask()) });

0 commit comments

Comments
 (0)