Skip to content

Commit

Permalink
spi: move set_format to all states
Browse files Browse the repository at this point in the history
There are other drivers in the wild (uboot, zephyr) that set the format
without disabling the peripheral, so we’ll assume it is fine to do so.
  • Loading branch information
ithinuel committed Aug 17, 2024
1 parent 5eeaca4 commit 50ecafd
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions rp2040-hal/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,26 +247,9 @@ impl<S: State, D: SpiDevice, P: ValidSpiPinout<D>, const DS: u8> Spi<S, D, P, DS
// Return the frequency we were able to achieve
(freq_in / (prescale as u32 * (1 + postdiv as u32))).Hz()
}
}

impl<D: SpiDevice, P: ValidSpiPinout<D>, const DS: u8> Spi<Disabled, D, P, DS> {
/// Create new not initialized Spi bus. Initialize it with [`.init`][Self::init]
/// or [`.init_slave`][Self::init_slave].
///
/// Valid pin sets are in the form of `(Tx, Sck)` or `(Tx, Rx, Sck)`
///
/// If you pins are dynamically identified (`Pin<DynPinId, _, _>`) they will first need to pass
/// validation using their corresponding [`ValidatedPinXX`](ValidatedPinTx).
pub fn new(device: D, pins: P) -> Spi<Disabled, D, P, DS> {
Spi {
device,
pins,
state: PhantomData,
}
}

/// Set format and datasize
fn set_format(&mut self, data_bits: u8, frame_format: FrameFormat) {
pub fn set_format(&mut self, data_bits: u8, frame_format: FrameFormat) {
self.device.sspcr0().modify(|_, w| unsafe {
w.dss().bits(data_bits - 1).frf().bits(match &frame_format {
FrameFormat::MotorolaSpi(_) => 0x00,
Expand All @@ -288,6 +271,24 @@ impl<D: SpiDevice, P: ValidSpiPinout<D>, const DS: u8> Spi<Disabled, D, P, DS> {
});
}

}

impl<D: SpiDevice, P: ValidSpiPinout<D>, const DS: u8> Spi<Disabled, D, P, DS> {
/// Create new not initialized Spi bus. Initialize it with [`.init`][Self::init]
/// or [`.init_slave`][Self::init_slave].
///
/// Valid pin sets are in the form of `(Tx, Sck)` or `(Tx, Rx, Sck)`
///
/// If you pins are dynamically identified (`Pin<DynPinId, _, _>`) they will first need to pass
/// validation using their corresponding [`ValidatedPinXX`](ValidatedPinTx).
pub fn new(device: D, pins: P) -> Spi<Disabled, D, P, DS> {
Spi {
device,
pins,
state: PhantomData,
}
}

/// Set master/slave
fn set_slave(&mut self, slave: bool) {
if slave {
Expand Down

0 comments on commit 50ecafd

Please sign in to comment.