Skip to content

Commit 88b6f87

Browse files
author
Jonathan Pallant (42 Technology)
committed
Pair up register writes.
1 parent 1358356 commit 88b6f87

File tree

3 files changed

+69
-94
lines changed

3 files changed

+69
-94
lines changed

nrf52-hal-common/src/gpio.rs

Lines changed: 50 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,11 @@ impl<MODE> Pin<MODE> {
8383
.pin_cnf[self.pin as usize]
8484
}
8585
.write(|w| {
86-
w.dir()
87-
.input()
88-
.input()
89-
.connect()
90-
.pull()
91-
.disabled()
92-
.drive()
93-
.s0s1()
94-
.sense()
95-
.disabled()
86+
w.dir().input();
87+
w.input().connect();
88+
w.pull().disabled();
89+
w.drive().s0s1();
90+
w.sense().disabled();
9691
});
9792

9893
Pin {
@@ -121,16 +116,11 @@ impl<MODE> Pin<MODE> {
121116
.pin_cnf[self.pin as usize]
122117
}
123118
.write(|w| {
124-
w.dir()
125-
.input()
126-
.input()
127-
.connect()
128-
.pull()
129-
.pullup()
130-
.drive()
131-
.s0s1()
132-
.sense()
133-
.disabled()
119+
w.dir().input();
120+
w.input().connect();
121+
w.pull().pullup();
122+
w.drive().s0s1();
123+
w.sense().disabled();
134124
});
135125

136126
Pin {
@@ -159,16 +149,11 @@ impl<MODE> Pin<MODE> {
159149
.pin_cnf[self.pin as usize]
160150
}
161151
.write(|w| {
162-
w.dir()
163-
.input()
164-
.input()
165-
.connect()
166-
.pull()
167-
.pulldown()
168-
.drive()
169-
.s0s1()
170-
.sense()
171-
.disabled()
152+
w.dir().input();
153+
w.input().connect();
154+
w.pull().pulldown();
155+
w.drive().s0s1();
156+
w.sense().disabled();
172157
});
173158

174159
Pin {
@@ -211,16 +196,11 @@ impl<MODE> Pin<MODE> {
211196
.pin_cnf[self.pin as usize]
212197
}
213198
.write(|w| {
214-
w.dir()
215-
.output()
216-
.input()
217-
.connect() // AJM - hack for SPI
218-
.pull()
219-
.disabled()
220-
.drive()
221-
.s0s1()
222-
.sense()
223-
.disabled()
199+
w.dir().output();
200+
w.input().connect(); // AJM - hack for SPI
201+
w.pull().disabled();
202+
w.drive().s0s1();
203+
w.sense().disabled();
224204
});
225205

226206
pin
@@ -267,16 +247,11 @@ impl<MODE> Pin<MODE> {
267247
.pin_cnf[self.pin as usize]
268248
};
269249
pin_cnf.write(|w| {
270-
w.dir()
271-
.output()
272-
.input()
273-
.disconnect()
274-
.pull()
275-
.disabled()
276-
.drive()
277-
.variant(config.variant())
278-
.sense()
279-
.disabled()
250+
w.dir().output();
251+
w.input().disconnect();
252+
w.pull().disabled();
253+
w.drive().variant(config.variant());
254+
w.sense().disabled();
280255
});
281256

282257
pin
@@ -500,11 +475,11 @@ macro_rules! gpio {
500475
/// Convert the pin to be a floating input
501476
pub fn into_floating_input(self) -> $PXi<Input<Floating>> {
502477
unsafe { &(*$PX::ptr()).pin_cnf[$i] }.write(|w| {
503-
w.dir().input()
504-
.input().connect()
505-
.pull().disabled()
506-
.drive().s0s1()
507-
.sense().disabled()
478+
w.dir().input();
479+
w.input().connect();
480+
w.pull().disabled();
481+
w.drive().s0s1();
482+
w.sense().disabled();
508483
});
509484

510485
$PXi {
@@ -513,11 +488,11 @@ macro_rules! gpio {
513488
}
514489
pub fn into_pulldown_input(self) -> $PXi<Input<PullDown>> {
515490
unsafe { &(*$PX::ptr()).pin_cnf[$i] }.write(|w| {
516-
w.dir().input()
517-
.input().connect()
518-
.pull().pulldown()
519-
.drive().s0s1()
520-
.sense().disabled()
491+
w.dir().input();
492+
w.input().connect();
493+
w.pull().pulldown();
494+
w.drive().s0s1();
495+
w.sense().disabled();
521496
});
522497

523498
$PXi {
@@ -526,11 +501,11 @@ macro_rules! gpio {
526501
}
527502
pub fn into_pullup_input(self) -> $PXi<Input<PullUp>> {
528503
unsafe { &(*$PX::ptr()).pin_cnf[$i] }.write(|w| {
529-
w.dir().input()
530-
.input().connect()
531-
.pull().pullup()
532-
.drive().s0s1()
533-
.sense().disabled()
504+
w.dir().input();
505+
w.input().connect();
506+
w.pull().pullup();
507+
w.drive().s0s1();
508+
w.sense().disabled();
534509
});
535510

536511
$PXi {
@@ -552,11 +527,11 @@ macro_rules! gpio {
552527
}
553528

554529
unsafe { &(*$PX::ptr()).pin_cnf[$i] }.write(|w| {
555-
w.dir().output()
556-
.input().disconnect()
557-
.pull().disabled()
558-
.drive().s0s1()
559-
.sense().disabled()
530+
w.dir().output();
531+
w.input().disconnect();
532+
w.pull().disabled();
533+
w.drive().s0s1();
534+
w.sense().disabled();
560535
});
561536

562537
pin
@@ -587,12 +562,11 @@ macro_rules! gpio {
587562
&(*$PX::ptr()).pin_cnf[$i]
588563
};
589564
pin_cnf.write(|w| {
590-
w
591-
.dir().output()
592-
.input().disconnect()
593-
.pull().disabled()
594-
.drive().variant(config.variant())
595-
.sense().disabled()
565+
w.dir().output();
566+
w.input().disconnect();
567+
w.pull().disabled();
568+
w.drive().variant(config.variant());
569+
w.sense().disabled();
596570
});
597571

598572
pin

nrf52-hal-common/src/saadc.rs

100755100644
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,13 @@ impl Saadc {
4444
saadc.samplerate.write(|w| w.mode().task());
4545

4646
saadc.ch[0].config.write(|w| {
47-
w.refsel()
48-
.variant(reference)
49-
.gain()
50-
.variant(gain)
51-
.tacq()
52-
.variant(time)
53-
.mode()
54-
.se()
55-
.resp()
56-
.variant(resistor)
57-
.resn()
58-
.bypass()
59-
.burst()
60-
.enabled()
47+
w.refsel().variant(reference);
48+
w.gain().variant(gain);
49+
w.tacq().variant(time);
50+
w.mode().se();
51+
w.resp().variant(resistor);
52+
w.resn().bypass();
53+
w.burst().enabled();
6154
});
6255
saadc.ch[0].pseln.write(|w| w.pseln().nc());
6356

nrf52-hal-common/src/spim.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,21 @@ where
125125
spim.config.write(|w| {
126126
// Can't match on `mode` due to embedded-hal, see https://github.com/rust-embedded/embedded-hal/pull/126
127127
if mode == MODE_0 {
128-
w.order().msb_first().cpol().active_high().cpha().leading()
128+
w.order().msb_first();
129+
w.cpol().active_high();
130+
w.cpha().leading();
129131
} else if mode == MODE_1 {
130-
w.order().msb_first().cpol().active_high().cpha().trailing()
132+
w.order().msb_first();
133+
w.cpol().active_high();
134+
w.cpha().trailing();
131135
} else if mode == MODE_2 {
132-
w.order().msb_first().cpol().active_low().cpha().leading()
136+
w.order().msb_first();
137+
w.cpol().active_low();
138+
w.cpha().leading();
133139
} else {
134-
w.order().msb_first().cpol().active_low().cpha().trailing()
140+
w.order().msb_first();
141+
w.cpol().active_low();
142+
w.cpha().trailing();
135143
}
136144
});
137145

0 commit comments

Comments
 (0)