Skip to content

Commit

Permalink
Make SPI clock pin optional for use with WS2812
Browse files Browse the repository at this point in the history
smart-leds-rs uses SPI without clock for controlling WS2812 LEDs.
  • Loading branch information
aelray committed Sep 20, 2022
1 parent 612902a commit 0e48842
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions nrf-hal-common/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ where

#[cfg(feature = "51")]
fn set_pins(spi: &mut T, pins: Pins) {
spi.pselsck
.write(|w| unsafe { w.bits(pins.sck.pin().into()) });

// Optional pins.
spi.pselsck.write(|w| unsafe {
if let Some(ref pin) = pins.sck {
w.bits(pin.pin().into())
} else {
// Disconnect
w.bits(0xFFFFFFFF)
}
});
spi.pselmosi.write(|w| unsafe {
if let Some(ref pin) = pins.mosi {
w.bits(pin.pin().into())
Expand All @@ -118,11 +122,9 @@ where

#[cfg(not(feature = "51"))]
fn set_pins(spi: &mut T, pins: Pins) {
spi.psel
.sck
.write(|w| unsafe { w.bits(pins.sck.pin().into()) });

// Optional pins.
if let Some(ref pin) = pins.sck {
spi.psel.sck.write(|w| unsafe { w.bits(pin.pin().into()) });
}
if let Some(ref pin) = pins.mosi {
spi.psel.mosi.write(|w| unsafe { w.bits(pin.pin().into()) });
}
Expand All @@ -140,7 +142,9 @@ where
/// GPIO pins for SPI interface.
pub struct Pins {
/// SPI clock.
pub sck: Pin<Output<PushPull>>,
///
/// None if unused.
pub sck: Option<Pin<Output<PushPull>>>,

/// MOSI Master out, slave in.
///
Expand Down

0 comments on commit 0e48842

Please sign in to comment.