Skip to content

Commit

Permalink
Pair up register writes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Pallant (42 Technology) committed Oct 30, 2019
1 parent 1358356 commit 88b6f87
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 94 deletions.
126 changes: 50 additions & 76 deletions nrf52-hal-common/src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,11 @@ impl<MODE> Pin<MODE> {
.pin_cnf[self.pin as usize]
}
.write(|w| {
w.dir()
.input()
.input()
.connect()
.pull()
.disabled()
.drive()
.s0s1()
.sense()
.disabled()
w.dir().input();
w.input().connect();
w.pull().disabled();
w.drive().s0s1();
w.sense().disabled();
});

Pin {
Expand Down Expand Up @@ -121,16 +116,11 @@ impl<MODE> Pin<MODE> {
.pin_cnf[self.pin as usize]
}
.write(|w| {
w.dir()
.input()
.input()
.connect()
.pull()
.pullup()
.drive()
.s0s1()
.sense()
.disabled()
w.dir().input();
w.input().connect();
w.pull().pullup();
w.drive().s0s1();
w.sense().disabled();
});

Pin {
Expand Down Expand Up @@ -159,16 +149,11 @@ impl<MODE> Pin<MODE> {
.pin_cnf[self.pin as usize]
}
.write(|w| {
w.dir()
.input()
.input()
.connect()
.pull()
.pulldown()
.drive()
.s0s1()
.sense()
.disabled()
w.dir().input();
w.input().connect();
w.pull().pulldown();
w.drive().s0s1();
w.sense().disabled();
});

Pin {
Expand Down Expand Up @@ -211,16 +196,11 @@ impl<MODE> Pin<MODE> {
.pin_cnf[self.pin as usize]
}
.write(|w| {
w.dir()
.output()
.input()
.connect() // AJM - hack for SPI
.pull()
.disabled()
.drive()
.s0s1()
.sense()
.disabled()
w.dir().output();
w.input().connect(); // AJM - hack for SPI
w.pull().disabled();
w.drive().s0s1();
w.sense().disabled();
});

pin
Expand Down Expand Up @@ -267,16 +247,11 @@ impl<MODE> Pin<MODE> {
.pin_cnf[self.pin as usize]
};
pin_cnf.write(|w| {
w.dir()
.output()
.input()
.disconnect()
.pull()
.disabled()
.drive()
.variant(config.variant())
.sense()
.disabled()
w.dir().output();
w.input().disconnect();
w.pull().disabled();
w.drive().variant(config.variant());
w.sense().disabled();
});

pin
Expand Down Expand Up @@ -500,11 +475,11 @@ macro_rules! gpio {
/// Convert the pin to be a floating input
pub fn into_floating_input(self) -> $PXi<Input<Floating>> {
unsafe { &(*$PX::ptr()).pin_cnf[$i] }.write(|w| {
w.dir().input()
.input().connect()
.pull().disabled()
.drive().s0s1()
.sense().disabled()
w.dir().input();
w.input().connect();
w.pull().disabled();
w.drive().s0s1();
w.sense().disabled();
});

$PXi {
Expand All @@ -513,11 +488,11 @@ macro_rules! gpio {
}
pub fn into_pulldown_input(self) -> $PXi<Input<PullDown>> {
unsafe { &(*$PX::ptr()).pin_cnf[$i] }.write(|w| {
w.dir().input()
.input().connect()
.pull().pulldown()
.drive().s0s1()
.sense().disabled()
w.dir().input();
w.input().connect();
w.pull().pulldown();
w.drive().s0s1();
w.sense().disabled();
});

$PXi {
Expand All @@ -526,11 +501,11 @@ macro_rules! gpio {
}
pub fn into_pullup_input(self) -> $PXi<Input<PullUp>> {
unsafe { &(*$PX::ptr()).pin_cnf[$i] }.write(|w| {
w.dir().input()
.input().connect()
.pull().pullup()
.drive().s0s1()
.sense().disabled()
w.dir().input();
w.input().connect();
w.pull().pullup();
w.drive().s0s1();
w.sense().disabled();
});

$PXi {
Expand All @@ -552,11 +527,11 @@ macro_rules! gpio {
}

unsafe { &(*$PX::ptr()).pin_cnf[$i] }.write(|w| {
w.dir().output()
.input().disconnect()
.pull().disabled()
.drive().s0s1()
.sense().disabled()
w.dir().output();
w.input().disconnect();
w.pull().disabled();
w.drive().s0s1();
w.sense().disabled();
});

pin
Expand Down Expand Up @@ -587,12 +562,11 @@ macro_rules! gpio {
&(*$PX::ptr()).pin_cnf[$i]
};
pin_cnf.write(|w| {
w
.dir().output()
.input().disconnect()
.pull().disabled()
.drive().variant(config.variant())
.sense().disabled()
w.dir().output();
w.input().disconnect();
w.pull().disabled();
w.drive().variant(config.variant());
w.sense().disabled();
});

pin
Expand Down
21 changes: 7 additions & 14 deletions nrf52-hal-common/src/saadc.rs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,13 @@ impl Saadc {
saadc.samplerate.write(|w| w.mode().task());

saadc.ch[0].config.write(|w| {
w.refsel()
.variant(reference)
.gain()
.variant(gain)
.tacq()
.variant(time)
.mode()
.se()
.resp()
.variant(resistor)
.resn()
.bypass()
.burst()
.enabled()
w.refsel().variant(reference);
w.gain().variant(gain);
w.tacq().variant(time);
w.mode().se();
w.resp().variant(resistor);
w.resn().bypass();
w.burst().enabled();
});
saadc.ch[0].pseln.write(|w| w.pseln().nc());

Expand Down
16 changes: 12 additions & 4 deletions nrf52-hal-common/src/spim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,21 @@ where
spim.config.write(|w| {
// Can't match on `mode` due to embedded-hal, see https://github.com/rust-embedded/embedded-hal/pull/126
if mode == MODE_0 {
w.order().msb_first().cpol().active_high().cpha().leading()
w.order().msb_first();
w.cpol().active_high();
w.cpha().leading();
} else if mode == MODE_1 {
w.order().msb_first().cpol().active_high().cpha().trailing()
w.order().msb_first();
w.cpol().active_high();
w.cpha().trailing();
} else if mode == MODE_2 {
w.order().msb_first().cpol().active_low().cpha().leading()
w.order().msb_first();
w.cpol().active_low();
w.cpha().leading();
} else {
w.order().msb_first().cpol().active_low().cpha().trailing()
w.order().msb_first();
w.cpol().active_low();
w.cpha().trailing();
}
});

Expand Down

0 comments on commit 88b6f87

Please # to comment.