Skip to content

Commit 7b8387d

Browse files
bors[bot]aelray
andauthored
Merge #400
400: Make SPI clock pin optional for use with WS2812 r=jonas-schievink a=aelray smart-leds-rs uses SPI without clock for controlling WS2812 LEDs. Co-authored-by: aelray <aelray@gmail.com>
2 parents 18ff51a + 0e48842 commit 7b8387d

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

nrf-hal-common/src/spi.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,14 @@ where
9393

9494
#[cfg(feature = "51")]
9595
fn set_pins(spi: &mut T, pins: Pins) {
96-
spi.pselsck
97-
.write(|w| unsafe { w.bits(pins.sck.pin().into()) });
98-
99-
// Optional pins.
96+
spi.pselsck.write(|w| unsafe {
97+
if let Some(ref pin) = pins.sck {
98+
w.bits(pin.pin().into())
99+
} else {
100+
// Disconnect
101+
w.bits(0xFFFFFFFF)
102+
}
103+
});
100104
spi.pselmosi.write(|w| unsafe {
101105
if let Some(ref pin) = pins.mosi {
102106
w.bits(pin.pin().into())
@@ -118,11 +122,9 @@ where
118122

119123
#[cfg(not(feature = "51"))]
120124
fn set_pins(spi: &mut T, pins: Pins) {
121-
spi.psel
122-
.sck
123-
.write(|w| unsafe { w.bits(pins.sck.pin().into()) });
124-
125-
// Optional pins.
125+
if let Some(ref pin) = pins.sck {
126+
spi.psel.sck.write(|w| unsafe { w.bits(pin.pin().into()) });
127+
}
126128
if let Some(ref pin) = pins.mosi {
127129
spi.psel.mosi.write(|w| unsafe { w.bits(pin.pin().into()) });
128130
}
@@ -140,7 +142,9 @@ where
140142
/// GPIO pins for SPI interface.
141143
pub struct Pins {
142144
/// SPI clock.
143-
pub sck: Pin<Output<PushPull>>,
145+
///
146+
/// None if unused.
147+
pub sck: Option<Pin<Output<PushPull>>>,
144148

145149
/// MOSI Master out, slave in.
146150
///

0 commit comments

Comments
 (0)