Skip to content

Commit 18bd8a3

Browse files
bors[bot]Jonas Schievink
andauthored
Merge #406
406: SPIM: make SCK optional to match SPI r=jonas-schievink a=jonas-schievink Followup to #400 to make the APIs match again bors r+ Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2 parents 2e255ba + b7c6957 commit 18bd8a3

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

examples/i2s-peripheral-demo/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ mod app {
7272
spim::Pins {
7373
miso: None,
7474
mosi: Some(rgb_data_pin),
75-
sck: rgb_clk_pin,
75+
sck: Some(rgb_clk_pin),
7676
},
7777
Frequency::M4,
7878
SPIMode {

examples/spi-demo/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() -> ! {
4444

4545
let mut tests_ok = true;
4646
let pins = nrf52832_hal::spim::Pins {
47-
sck: spiclk,
47+
sck: Some(spiclk),
4848
miso: Some(spimiso),
4949
mosi: Some(spimosi),
5050
};

nrf-hal-common/src/spim.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ use core::sync::atomic::{compiler_fence, Ordering::SeqCst};
99
use crate::pac::{spim0_ns as spim0, SPIM0_NS as SPIM0};
1010

1111
#[cfg(feature = "9160")]
12-
use crate::pac::{
13-
SPIM1_NS as SPIM1,
14-
SPIM2_NS as SPIM2,
15-
SPIM3_NS as SPIM3,
16-
};
12+
use crate::pac::{SPIM1_NS as SPIM1, SPIM2_NS as SPIM2, SPIM3_NS as SPIM3};
1713

1814
#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))]
1915
use crate::pac::{spim0, SPIM0};
@@ -106,11 +102,13 @@ where
106102

107103
pub fn new(spim: T, pins: Pins, frequency: Frequency, mode: Mode, orc: u8) -> Self {
108104
// Select pins.
109-
spim.psel.sck.write(|w| {
110-
unsafe { w.bits(pins.sck.psel_bits()) };
111-
w.connect().connected()
112-
});
113-
105+
match pins.sck {
106+
Some(sck) => spim.psel.sck.write(|w| {
107+
unsafe { w.bits(sck.psel_bits()) };
108+
w.connect().connected()
109+
}),
110+
None => spim.psel.sck.write(|w| w.connect().disconnected()),
111+
}
114112
match pins.mosi {
115113
Some(mosi) => spim.psel.mosi.write(|w| {
116114
unsafe { w.bits(mosi.psel_bits()) };
@@ -375,7 +373,11 @@ where
375373
(
376374
self.0,
377375
Pins {
378-
sck: unsafe { Pin::from_psel_bits(sck.bits()) },
376+
sck: if sck.connect().bit_is_set() {
377+
Some(unsafe { Pin::from_psel_bits(sck.bits()) })
378+
} else {
379+
None
380+
},
379381
mosi: if mosi.connect().bit_is_set() {
380382
Some(unsafe { Pin::from_psel_bits(mosi.bits()) })
381383
} else {
@@ -393,8 +395,10 @@ where
393395

394396
/// GPIO pins for SPIM interface
395397
pub struct Pins {
396-
/// SPI clock
397-
pub sck: Pin<Output<PushPull>>,
398+
/// SPI clock.
399+
///
400+
/// None if unused.
401+
pub sck: Option<Pin<Output<PushPull>>>,
398402

399403
/// MOSI Master out, slave in
400404
/// None if unused
@@ -438,7 +442,12 @@ mod _spim1 {
438442
impl sealed::Sealed for SPIM1 {}
439443
}
440444

441-
#[cfg(any(feature = "52832", feature = "52833", feature = "52840", feature = "9160"))]
445+
#[cfg(any(
446+
feature = "52832",
447+
feature = "52833",
448+
feature = "52840",
449+
feature = "9160"
450+
))]
442451
mod _spim2 {
443452
use super::*;
444453
impl Instance for SPIM2 {}

0 commit comments

Comments
 (0)