Make SPI clock pin optional for use with WS2812
smart-leds-rs uses SPI without clock for controlling WS2812 LEDs.
@@ -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())
@@ -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()) });
}
@@ -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.
///
