Skip to content

Commit

Permalink
Port SPI changes from rp2040-hal to rp235x-hal
Browse files Browse the repository at this point in the history
The updates from rp-rs#831 were only applied to rp2040-hal.
This patch ports them to rp235x-hal.
  • Loading branch information
jannic committed Aug 24, 2024
1 parent 84e1bf0 commit 1adf2b4
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions rp235x-hal/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,26 +273,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 @@ -313,6 +296,23 @@ impl<D: SpiDevice, P: ValidSpiPinout<D>, const DS: u8> Spi<Disabled, D, P, DS> {
w
});
}
}

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 your 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) {
Expand Down

0 comments on commit 1adf2b4

Please sign in to comment.