From f8016112933d1d746baa539f27e8f4363ed5804d Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Sat, 17 Aug 2024 08:51:00 +0100 Subject: [PATCH 1/2] 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) { From 1e06c4f81752ceec2b15e3130343606028d41d60 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sat, 17 Aug 2024 12:38:00 +0100 Subject: [PATCH 2/2] Fix comment typo in rp2040-hal/src/spi.rs --- rp2040-hal/src/spi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rp2040-hal/src/spi.rs b/rp2040-hal/src/spi.rs index d37815c3d..f8c8590bf 100644 --- a/rp2040-hal/src/spi.rs +++ b/rp2040-hal/src/spi.rs @@ -278,7 +278,7 @@ impl, const DS: u8> Spi { /// /// 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 + /// If your 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 {