Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spi: move set_format to all states #831

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 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 @@ -287,6 +270,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
Loading