diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index a0bb66eb..4899676e 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -1,16 +1,19 @@ #![macro_use] +use crate::dma; +use crate::gpio::{AnyPin, NoPin, OptionalPin}; +use crate::pac::spi::vals; +use crate::peripherals; +use crate::rcc::RccPeripheral; +use core::marker::PhantomData; + #[cfg_attr(spi_v1, path = "v1.rs")] #[cfg_attr(spi_f1, path = "v1.rs")] #[cfg_attr(spi_v2, path = "v2.rs")] #[cfg_attr(spi_v3, path = "v3.rs")] mod _version; -use crate::pac::spi::vals; -use crate::{dma, peripherals, rcc::RccPeripheral}; pub use _version::*; -use crate::gpio::{NoPin, OptionalPin}; - #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { @@ -89,6 +92,16 @@ impl Default for Config { } } +pub struct Spi<'d, T: Instance, Tx, Rx> { + sck: Option, + mosi: Option, + miso: Option, + txdma: Tx, + rxdma: Rx, + current_word_size: WordSize, + phantom: PhantomData<&'d mut T>, +} + pub(crate) mod sealed { use super::*; diff --git a/embassy-stm32/src/spi/v1.rs b/embassy-stm32/src/spi/v1.rs index a41c7991..d7075dc4 100644 --- a/embassy-stm32/src/spi/v1.rs +++ b/embassy-stm32/src/spi/v1.rs @@ -3,7 +3,6 @@ use crate::dma::NoDma; use crate::gpio::sealed::AFType; use crate::gpio::sealed::Pin; -use crate::gpio::AnyPin; use crate::pac::spi; use crate::spi::{ ByteOrder, Config, Error, Instance, MisoPin, MosiPin, RxDmaChannel, SckPin, TxDmaChannel, @@ -20,15 +19,7 @@ pub use embedded_hal::blocking; pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; use futures::future::join3; -pub struct Spi<'d, T: Instance, Tx, Rx> { - sck: Option, - mosi: Option, - miso: Option, - txdma: Tx, - rxdma: Rx, - current_word_size: WordSize, - phantom: PhantomData<&'d mut T>, -} +use super::Spi; impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { pub fn new( diff --git a/embassy-stm32/src/spi/v2.rs b/embassy-stm32/src/spi/v2.rs index 0c0d24ce..94e5ca08 100644 --- a/embassy-stm32/src/spi/v2.rs +++ b/embassy-stm32/src/spi/v2.rs @@ -2,7 +2,6 @@ use crate::dma::NoDma; use crate::gpio::sealed::Pin; -use crate::gpio::AnyPin; use crate::pac::spi; use crate::spi::{ ByteOrder, Config, Error, Instance, MisoPin, MosiPin, RxDmaChannel, SckPin, TxDmaChannel, @@ -18,15 +17,7 @@ use embassy_traits::spi as traits; pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; use futures::future::{join, join3}; -pub struct Spi<'d, T: Instance, Tx, Rx> { - sck: Option, - mosi: Option, - miso: Option, - txdma: Tx, - rxdma: Rx, - current_word_size: WordSize, - phantom: PhantomData<&'d mut T>, -} +use super::Spi; impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { pub fn new( diff --git a/embassy-stm32/src/spi/v3.rs b/embassy-stm32/src/spi/v3.rs index e2751ce2..99c3eac1 100644 --- a/embassy-stm32/src/spi/v3.rs +++ b/embassy-stm32/src/spi/v3.rs @@ -2,7 +2,6 @@ use crate::dma::NoDma; use crate::gpio::sealed::Pin; -use crate::gpio::AnyPin; use crate::pac::spi; use crate::spi::{ ByteOrder, Config, Error, Instance, MisoPin, MosiPin, RxDmaChannel, SckPin, TxDmaChannel, @@ -19,16 +18,7 @@ pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_ use futures::future::join3; -#[allow(unused)] -pub struct Spi<'d, T: Instance, Tx = NoDma, Rx = NoDma> { - sck: Option, - mosi: Option, - miso: Option, - txdma: Tx, - rxdma: Rx, - current_word_size: WordSize, - phantom: PhantomData<&'d mut T>, -} +use super::Spi; impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { pub fn new( @@ -338,7 +328,7 @@ impl<'d, T: Instance, Tx, Rx> Drop for Spi<'d, T, Tx, Rx> { } } -impl<'d, T: Instance> embedded_hal::blocking::spi::Write for Spi<'d, T, NoDma> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Write for Spi<'d, T, NoDma, NoDma> { type Error = Error; fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> { @@ -386,7 +376,7 @@ impl<'d, T: Instance> embedded_hal::blocking::spi::Write for Spi<'d, T, NoDm } } -impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer for Spi<'d, T, NoDma> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer for Spi<'d, T, NoDma, NoDma> { type Error = Error; fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> { @@ -443,7 +433,7 @@ impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer for Spi<'d, T, N } } -impl<'d, T: Instance> embedded_hal::blocking::spi::Write for Spi<'d, T, NoDma> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Write for Spi<'d, T, NoDma, NoDma> { type Error = Error; fn write(&mut self, words: &[u16]) -> Result<(), Self::Error> { @@ -492,7 +482,7 @@ impl<'d, T: Instance> embedded_hal::blocking::spi::Write for Spi<'d, T, NoD } } -impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer for Spi<'d, T, NoDma> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer for Spi<'d, T, NoDma, NoDma> { type Error = Error; fn transfer<'w>(&mut self, words: &'w mut [u16]) -> Result<&'w [u16], Self::Error> {