From f8016112933d1d746baa539f27e8f4363ed5804d Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Sat, 17 Aug 2024 08:51:00 +0100 Subject: [PATCH] spi: move set_format to all states MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- rp2040-hal/src/spi.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/rp2040-hal/src/spi.rs b/rp2040-hal/src/spi.rs index f890e9aa6..d37815c3d 100644 --- a/rp2040-hal/src/spi.rs +++ b/rp2040-hal/src/spi.rs @@ -247,26 +247,9 @@ impl, const DS: u8> Spi, const DS: u8> Spi { - /// 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`) they will first need to pass - /// validation using their corresponding [`ValidatedPinXX`](ValidatedPinTx). - pub fn new(device: D, pins: P) -> Spi { - 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, @@ -287,6 +270,23 @@ impl, const DS: u8> Spi { w }); } +} + +impl, const DS: u8> Spi { + /// 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`) they will first need to pass + /// validation using their corresponding [`ValidatedPinXX`](ValidatedPinTx). + pub fn new(device: D, pins: P) -> Spi { + Spi { + device, + pins, + state: PhantomData, + } + } /// Set master/slave fn set_slave(&mut self, slave: bool) {