From 87429bc02b319633bbb0950b560f6c3aee49e1aa Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Tue, 7 Jan 2025 10:38:56 +0100 Subject: [PATCH 1/3] Fix naming violations for `spi::Mode` --- esp-hal/src/dma/mod.rs | 2 +- esp-hal/src/spi/master.rs | 8 +++--- esp-hal/src/spi/mod.rs | 8 +++--- esp-hal/src/spi/slave.rs | 27 +++++++++---------- examples/src/bin/embassy_spi.rs | 2 +- examples/src/bin/spi_loopback.rs | 2 +- examples/src/bin/spi_loopback_dma_psram.rs | 2 +- examples/src/bin/spi_slave_dma.rs | 2 +- hil-test/tests/embassy_interrupt_spi_dma.rs | 6 ++--- hil-test/tests/qspi.rs | 2 +- hil-test/tests/spi_half_duplex_read.rs | 2 +- hil-test/tests/spi_half_duplex_write.rs | 2 +- hil-test/tests/spi_half_duplex_write_psram.rs | 2 +- hil-test/tests/spi_slave.rs | 2 +- qa-test/src/bin/qspi_flash.rs | 2 +- .../spi_halfduplex_read_manufacturer_id.rs | 2 +- 16 files changed, 36 insertions(+), 37 deletions(-) diff --git a/esp-hal/src/dma/mod.rs b/esp-hal/src/dma/mod.rs index 83faa2a2efa..536e565535c 100644 --- a/esp-hal/src/dma/mod.rs +++ b/esp-hal/src/dma/mod.rs @@ -28,7 +28,7 @@ //! //! let mut spi = Spi::new( //! peripherals.SPI2, -//! Config::default().with_frequency(100.kHz()).with_mode(Mode::Mode0) +//! Config::default().with_frequency(100.kHz()).with_mode(Mode::_0) //! ) //! .unwrap() //! .with_sck(sclk) diff --git a/esp-hal/src/spi/master.rs b/esp-hal/src/spi/master.rs index 6dd9acdaf74..2d2fe7e8590 100644 --- a/esp-hal/src/spi/master.rs +++ b/esp-hal/src/spi/master.rs @@ -44,7 +44,7 @@ //! //! let mut spi = Spi::new( //! peripherals.SPI2, -//! Config::default().with_frequency(100.kHz()).with_mode(Mode::Mode0) +//! Config::default().with_frequency(100.kHz()).with_mode(Mode::_0) //! ) //! .unwrap() //! .with_sck(sclk) @@ -469,7 +469,7 @@ impl Default for Config { use fugit::RateExtU32; Config { frequency: 1_u32.MHz(), - mode: Mode::Mode0, + mode: Mode::_0, read_bit_order: BitOrder::MsbFirst, write_bit_order: BitOrder::MsbFirst, } @@ -2945,11 +2945,11 @@ impl Driver { pin_reg.modify(|_, w| { w.ck_idle_edge() - .bit(matches!(data_mode, Mode::Mode2 | Mode::Mode3)) + .bit(matches!(data_mode, Mode::_2 | Mode::_3)) }); reg_block.user().modify(|_, w| { w.ck_out_edge() - .bit(matches!(data_mode, Mode::Mode1 | Mode::Mode2)) + .bit(matches!(data_mode, Mode::_1 | Mode::_2)) }); } diff --git a/esp-hal/src/spi/mod.rs b/esp-hal/src/spi/mod.rs index 6c23cede33a..7ee0cf22bea 100644 --- a/esp-hal/src/spi/mod.rs +++ b/esp-hal/src/spi/mod.rs @@ -71,16 +71,16 @@ impl embedded_hal::spi::Error for Error { pub enum Mode { /// Mode 0 (CPOL = 0, CPHA = 0): Clock is low when idle, data is captured on /// the rising edge and propagated on the falling edge. - Mode0, + _0, /// Mode 1 (CPOL = 0, CPHA = 1): Clock is low when idle, data is captured on /// the falling edge and propagated on the rising edge. - Mode1, + _1, /// Mode 2 (CPOL = 1, CPHA = 0): Clock is high when idle, data is captured /// on the falling edge and propagated on the rising edge. - Mode2, + _2, /// Mode 3 (CPOL = 1, CPHA = 1): Clock is high when idle, data is captured /// on the rising edge and propagated on the falling edge. - Mode3, + _3, } /// SPI Bit Order diff --git a/esp-hal/src/spi/slave.rs b/esp-hal/src/spi/slave.rs index ebd48ef9981..7108b4d95d5 100644 --- a/esp-hal/src/spi/slave.rs +++ b/esp-hal/src/spi/slave.rs @@ -29,7 +29,7 @@ //! dma_buffers!(32000); //! let mut spi = Spi::new( //! peripherals.SPI2, -//! Mode::Mode0, +//! Mode::_0, //! ) //! .with_sck(sclk) //! .with_mosi(mosi) @@ -699,33 +699,32 @@ impl Info { { reg_block.pin().modify(|_, w| { w.ck_idle_edge() - .bit(matches!(data_mode, Mode::Mode0 | Mode::Mode1)) - }); - reg_block.user().modify(|_, w| { - w.ck_i_edge() - .bit(matches!(data_mode, Mode::Mode1 | Mode::Mode2)) + .bit(matches!(data_mode, Mode::_0 | Mode::_1)) }); + reg_block + .user() + .modify(|_, w| w.ck_i_edge().bit(matches!(data_mode, Mode::_1 | Mode::_2))); reg_block.ctrl2().modify(|_, w| unsafe { match data_mode { - Mode::Mode0 => { + Mode::_0 => { w.miso_delay_mode().bits(0); w.miso_delay_num().bits(0); w.mosi_delay_mode().bits(2); w.mosi_delay_num().bits(2) } - Mode::Mode1 => { + Mode::_1 => { w.miso_delay_mode().bits(2); w.miso_delay_num().bits(0); w.mosi_delay_mode().bits(0); w.mosi_delay_num().bits(0) } - Mode::Mode2 => { + Mode::_2 => { w.miso_delay_mode().bits(0); w.miso_delay_num().bits(0); w.mosi_delay_mode().bits(1); w.mosi_delay_num().bits(2) } - Mode::Mode3 => { + Mode::_3 => { w.miso_delay_mode().bits(1); w.miso_delay_num().bits(0); w.mosi_delay_mode().bits(0); @@ -736,7 +735,7 @@ impl Info { if dma { assert!( - matches!(data_mode, Mode::Mode1 | Mode::Mode3), + matches!(data_mode, Mode::_1 | Mode::_3), "Mode {:?} is not supported with DMA", data_mode ); @@ -755,13 +754,13 @@ impl Info { } reg_block.user().modify(|_, w| { w.tsck_i_edge() - .bit(matches!(data_mode, Mode::Mode1 | Mode::Mode2)); + .bit(matches!(data_mode, Mode::_1 | Mode::_2)); w.rsck_i_edge() - .bit(matches!(data_mode, Mode::Mode1 | Mode::Mode2)) + .bit(matches!(data_mode, Mode::_1 | Mode::_2)) }); ctrl1_reg.modify(|_, w| { w.clk_mode_13() - .bit(matches!(data_mode, Mode::Mode1 | Mode::Mode3)) + .bit(matches!(data_mode, Mode::_1 | Mode::_3)) }); } } diff --git a/examples/src/bin/embassy_spi.rs b/examples/src/bin/embassy_spi.rs index 4c1bec74f79..fbf1e8c26fc 100644 --- a/examples/src/bin/embassy_spi.rs +++ b/examples/src/bin/embassy_spi.rs @@ -61,7 +61,7 @@ async fn main(_spawner: Spawner) { peripherals.SPI2, Config::default() .with_frequency(100.kHz()) - .with_mode(Mode::Mode0), + .with_mode(Mode::_0), ) .unwrap() .with_sck(sclk) diff --git a/examples/src/bin/spi_loopback.rs b/examples/src/bin/spi_loopback.rs index a3b6d249f52..4390fffc6f2 100644 --- a/examples/src/bin/spi_loopback.rs +++ b/examples/src/bin/spi_loopback.rs @@ -43,7 +43,7 @@ fn main() -> ! { peripherals.SPI2, Config::default() .with_frequency(100.kHz()) - .with_mode(Mode::Mode0), + .with_mode(Mode::_0), ) .unwrap() .with_sck(sclk) diff --git a/examples/src/bin/spi_loopback_dma_psram.rs b/examples/src/bin/spi_loopback_dma_psram.rs index 41b785b486b..c8125241e64 100644 --- a/examples/src/bin/spi_loopback_dma_psram.rs +++ b/examples/src/bin/spi_loopback_dma_psram.rs @@ -93,7 +93,7 @@ fn main() -> ! { peripherals.SPI2, Config::default() .with_frequency(100.kHz()) - .with_mode(Mode::Mode0), + .with_mode(Mode::_0), ) .unwrap() .with_sck(sclk) diff --git a/examples/src/bin/spi_slave_dma.rs b/examples/src/bin/spi_slave_dma.rs index b6184613df5..89e7c5c9bb2 100644 --- a/examples/src/bin/spi_slave_dma.rs +++ b/examples/src/bin/spi_slave_dma.rs @@ -64,7 +64,7 @@ fn main() -> ! { let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(32000); - let mut spi = Spi::new(peripherals.SPI2, Mode::Mode0) + let mut spi = Spi::new(peripherals.SPI2, Mode::_0) .with_sck(slave_sclk) .with_mosi(slave_mosi) .with_miso(slave_miso) diff --git a/hil-test/tests/embassy_interrupt_spi_dma.rs b/hil-test/tests/embassy_interrupt_spi_dma.rs index 019b02889b2..8404bcd8f75 100644 --- a/hil-test/tests/embassy_interrupt_spi_dma.rs +++ b/hil-test/tests/embassy_interrupt_spi_dma.rs @@ -121,7 +121,7 @@ mod test { peripherals.SPI2, Config::default() .with_frequency(10000.kHz()) - .with_mode(Mode::Mode0), + .with_mode(Mode::_0), ) .unwrap() .with_miso(unsafe { mosi.clone_unchecked() }) @@ -135,7 +135,7 @@ mod test { peripherals.SPI3, Config::default() .with_frequency(10000.kHz()) - .with_mode(Mode::Mode0), + .with_mode(Mode::_0), ) .unwrap() .with_dma(dma_channel2) @@ -229,7 +229,7 @@ mod test { peripherals.spi, Config::default() .with_frequency(100.kHz()) - .with_mode(Mode::Mode0), + .with_mode(Mode::_0), ) .unwrap() .with_dma(peripherals.dma_channel) diff --git a/hil-test/tests/qspi.rs b/hil-test/tests/qspi.rs index 2c86fa0faad..b0aeffbebb3 100644 --- a/hil-test/tests/qspi.rs +++ b/hil-test/tests/qspi.rs @@ -212,7 +212,7 @@ mod tests { peripherals.SPI2, Config::default() .with_frequency(100.kHz()) - .with_mode(Mode::Mode0), + .with_mode(Mode::_0), ) .unwrap(); diff --git a/hil-test/tests/spi_half_duplex_read.rs b/hil-test/tests/spi_half_duplex_read.rs index ab0d4529544..07254a3b7a1 100644 --- a/hil-test/tests/spi_half_duplex_read.rs +++ b/hil-test/tests/spi_half_duplex_read.rs @@ -50,7 +50,7 @@ mod tests { peripherals.SPI2, Config::default() .with_frequency(100.kHz()) - .with_mode(Mode::Mode0), + .with_mode(Mode::_0), ) .unwrap() .with_sck(sclk) diff --git a/hil-test/tests/spi_half_duplex_write.rs b/hil-test/tests/spi_half_duplex_write.rs index 6de721fd0d5..4985f23bf34 100644 --- a/hil-test/tests/spi_half_duplex_write.rs +++ b/hil-test/tests/spi_half_duplex_write.rs @@ -54,7 +54,7 @@ mod tests { peripherals.SPI2, Config::default() .with_frequency(100.kHz()) - .with_mode(Mode::Mode0), + .with_mode(Mode::_0), ) .unwrap() .with_sck(sclk) diff --git a/hil-test/tests/spi_half_duplex_write_psram.rs b/hil-test/tests/spi_half_duplex_write_psram.rs index 5027dc5ffb8..9a64edd72be 100644 --- a/hil-test/tests/spi_half_duplex_write_psram.rs +++ b/hil-test/tests/spi_half_duplex_write_psram.rs @@ -66,7 +66,7 @@ mod tests { peripherals.SPI2, Config::default() .with_frequency(100.kHz()) - .with_mode(Mode::Mode0), + .with_mode(Mode::_0), ) .unwrap() .with_sck(sclk) diff --git a/hil-test/tests/spi_slave.rs b/hil-test/tests/spi_slave.rs index a33fac64629..4e123155ae2 100644 --- a/hil-test/tests/spi_slave.rs +++ b/hil-test/tests/spi_slave.rs @@ -125,7 +125,7 @@ mod tests { let miso = unsafe { miso_gpio.clone_unchecked() }.into_peripheral_output(); Context { - spi: Spi::new(peripherals.SPI2, Mode::Mode1) + spi: Spi::new(peripherals.SPI2, Mode::_1) .with_sck(sclk) .with_mosi(mosi) .with_miso(miso) diff --git a/qa-test/src/bin/qspi_flash.rs b/qa-test/src/bin/qspi_flash.rs index 261aebbf648..9f4a137a972 100644 --- a/qa-test/src/bin/qspi_flash.rs +++ b/qa-test/src/bin/qspi_flash.rs @@ -81,7 +81,7 @@ fn main() -> ! { peripherals.SPI2, Config::default() .with_frequency(100.kHz()) - .with_mode(Mode::Mode0), + .with_mode(Mode::_0), ) .unwrap() .with_sck(sclk) diff --git a/qa-test/src/bin/spi_halfduplex_read_manufacturer_id.rs b/qa-test/src/bin/spi_halfduplex_read_manufacturer_id.rs index a77284e53ba..444b45fa4ea 100644 --- a/qa-test/src/bin/spi_halfduplex_read_manufacturer_id.rs +++ b/qa-test/src/bin/spi_halfduplex_read_manufacturer_id.rs @@ -67,7 +67,7 @@ fn main() -> ! { peripherals.SPI2, Config::default() .with_frequency(100.kHz()) - .with_mode(Mode::Mode0), + .with_mode(Mode::_0), ) .unwrap() .with_sck(sclk) From 4b77786b4bf91c6dd93079d7577d7eb462642e16 Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Tue, 7 Jan 2025 16:16:19 +0100 Subject: [PATCH 2/3] Update migration guide --- esp-hal/MIGRATING-0.22.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/esp-hal/MIGRATING-0.22.md b/esp-hal/MIGRATING-0.22.md index ef7e4e3ae80..d50fd69c278 100644 --- a/esp-hal/MIGRATING-0.22.md +++ b/esp-hal/MIGRATING-0.22.md @@ -245,7 +245,7 @@ is not compatible with the hardware. peripherals.SPI2, Config { frequency: 100.kHz(), - mode: SpiMode::Mode0, + mode: SpiMode::_0, ..Config::default() }, -); @@ -405,3 +405,12 @@ The specific CPU clock variants are renamed from e.g. `Clock80MHz` to `_80MHz`. ``` Additionally the enum is marked as non-exhaustive. + +## SPI Modes + +The SPI mode variants are renamed from e.g. `Mode0` to `_0`. + +```diff +- Mode::Mode0 ++ Mode::_0 +``` From 3bb7281b11cb3592dd1929e87ccad380148ddc6a Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Tue, 7 Jan 2025 16:26:17 +0100 Subject: [PATCH 3/3] Update `CHANGELOG.md` --- esp-hal/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 9380bc7e123..9613fcabfc8 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -95,6 +95,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - UART: Fix naming violations for `DataBits`, `Parity`, and `StopBits` enum variants (#2893) - UART: Remove blocking version of `read_bytes` and rename `drain_fifo` to `read_bytes` instead (#2895) - Renamed variants of `CpuClock`, made the enum non-exhaustive (#2899) +- SPI: Fix naming violations for `Mode` enum variants (#2902) ### Fixed