From d51885c0eb5bc0d46db49c7ffd8f58128e5c983e Mon Sep 17 00:00:00 2001 From: Grant Miller Date: Mon, 6 Dec 2021 14:13:25 -0600 Subject: [PATCH] Move WordSize methods to mod --- embassy-stm32/src/spi/mod.rs | 43 ++++++++++++++++++++++++++++++++++++ embassy-stm32/src/spi/v1.rs | 9 -------- embassy-stm32/src/spi/v2.rs | 16 -------------- embassy-stm32/src/spi/v3.rs | 16 -------------- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 8668f6344..a0bb66eb0 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -5,6 +5,7 @@ #[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::*; @@ -31,6 +32,48 @@ enum WordSize { SixteenBit, } +impl WordSize { + #[cfg(any(spi_v1, spi_f1))] + fn dff(&self) -> vals::Dff { + match self { + WordSize::EightBit => vals::Dff::EIGHTBIT, + WordSize::SixteenBit => vals::Dff::SIXTEENBIT, + } + } + + #[cfg(spi_v2)] + fn ds(&self) -> vals::Ds { + match self { + WordSize::EightBit => vals::Ds::EIGHTBIT, + WordSize::SixteenBit => vals::Ds::SIXTEENBIT, + } + } + + #[cfg(spi_v2)] + fn frxth(&self) -> vals::Frxth { + match self { + WordSize::EightBit => vals::Frxth::QUARTER, + WordSize::SixteenBit => vals::Frxth::HALF, + } + } + + #[cfg(spi_v3)] + fn dsize(&self) -> u8 { + match self { + WordSize::EightBit => 0b0111, + WordSize::SixteenBit => 0b1111, + } + } + + #[cfg(spi_v3)] + fn _frxth(&self) -> vals::Fthlv { + match self { + WordSize::EightBit => vals::Fthlv::ONEFRAME, + WordSize::SixteenBit => vals::Fthlv::ONEFRAME, + } + } +} + #[non_exhaustive] pub struct Config { pub mode: Mode, diff --git a/embassy-stm32/src/spi/v1.rs b/embassy-stm32/src/spi/v1.rs index 9ad9397a4..08bee758b 100644 --- a/embassy-stm32/src/spi/v1.rs +++ b/embassy-stm32/src/spi/v1.rs @@ -20,15 +20,6 @@ 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; -impl WordSize { - fn dff(&self) -> spi::vals::Dff { - match self { - WordSize::EightBit => spi::vals::Dff::EIGHTBIT, - WordSize::SixteenBit => spi::vals::Dff::SIXTEENBIT, - } - } -} - pub struct Spi<'d, T: Instance, Tx, Rx> { sck: Option, mosi: Option, diff --git a/embassy-stm32/src/spi/v2.rs b/embassy-stm32/src/spi/v2.rs index aa04fcca4..b281c7548 100644 --- a/embassy-stm32/src/spi/v2.rs +++ b/embassy-stm32/src/spi/v2.rs @@ -18,22 +18,6 @@ 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}; -impl WordSize { - fn ds(&self) -> spi::vals::Ds { - match self { - WordSize::EightBit => spi::vals::Ds::EIGHTBIT, - WordSize::SixteenBit => spi::vals::Ds::SIXTEENBIT, - } - } - - fn frxth(&self) -> spi::vals::Frxth { - match self { - WordSize::EightBit => spi::vals::Frxth::QUARTER, - WordSize::SixteenBit => spi::vals::Frxth::HALF, - } - } -} - pub struct Spi<'d, T: Instance, Tx, Rx> { sck: Option, mosi: Option, diff --git a/embassy-stm32/src/spi/v3.rs b/embassy-stm32/src/spi/v3.rs index dbd9d78c9..cd88acb7a 100644 --- a/embassy-stm32/src/spi/v3.rs +++ b/embassy-stm32/src/spi/v3.rs @@ -19,22 +19,6 @@ pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_ use futures::future::join3; -impl WordSize { - fn dsize(&self) -> u8 { - match self { - WordSize::EightBit => 0b0111, - WordSize::SixteenBit => 0b1111, - } - } - - fn _frxth(&self) -> spi::vals::Fthlv { - match self { - WordSize::EightBit => spi::vals::Fthlv::ONEFRAME, - WordSize::SixteenBit => spi::vals::Fthlv::ONEFRAME, - } - } -} - #[allow(unused)] pub struct Spi<'d, T: Instance, Tx = NoDma, Rx = NoDma> { sck: Option,