Skip to content

Commit 8f161c1

Browse files
author
Piet Geursen
committed
Allow setting SPI Mode on an initialised device
1 parent 8d52f37 commit 8f161c1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

rp2040-hal/src/spi.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ impl<S: State, D: SpiDevice, const DS: u8> Spi<S, D, DS> {
123123
use fugit::RateExtU32;
124124
(freq_in / (prescale as u32 * (1 + postdiv as u32))).Hz()
125125
}
126+
127+
/// Set the mode
128+
pub fn set_mode(&mut self, mode: Mode) {
129+
self.device.sspcr0.modify(|_, w| {
130+
w.spo()
131+
.bit(mode.polarity == Polarity::IdleHigh)
132+
.sph()
133+
.bit(mode.phase == Phase::CaptureOnSecondTransition)
134+
});
135+
}
126136
}
127137

128138
impl<D: SpiDevice, const DS: u8> Spi<Disabled, D, DS> {

0 commit comments

Comments
 (0)