From 939ea3bbd0bb41a1deed3ac27ca3974db0f7d043 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 8 Jun 2021 13:10:58 +0200 Subject: [PATCH] Reduce generics noise --- embassy-stm32/src/spi/mod.rs | 4 ++-- embassy-stm32/src/spi/v1.rs | 15 +++++++-------- embassy-stm32/src/spi/v2.rs | 15 +++++++-------- embassy-stm32/src/spi/v3.rs | 15 +++++++-------- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 730169ec0..9b04c03aa 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -4,7 +4,7 @@ #[cfg_attr(spi_v2, path = "v2.rs")] #[cfg_attr(spi_v3, path = "v3.rs")] mod _version; -use crate::peripherals; +use crate::{peripherals, rcc::RccPeripheral}; pub use _version::*; use crate::gpio::Pin; @@ -64,7 +64,7 @@ pub(crate) mod sealed { } } -pub trait Instance: sealed::Instance + 'static {} +pub trait Instance: sealed::Instance + RccPeripheral + 'static {} pub trait SckPin: sealed::SckPin + 'static {} diff --git a/embassy-stm32/src/spi/v1.rs b/embassy-stm32/src/spi/v1.rs index a4e4c0ba1..227a36a89 100644 --- a/embassy-stm32/src/spi/v1.rs +++ b/embassy-stm32/src/spi/v1.rs @@ -2,7 +2,6 @@ use crate::gpio::{sealed::Pin, AnyPin}; use crate::pac::spi; -use crate::rcc::RccPeripheral; use crate::spi::{ByteOrder, Config, Error, Instance, MisoPin, MosiPin, SckPin, WordSize}; use crate::time::Hertz; use core::marker::PhantomData; @@ -20,7 +19,7 @@ impl WordSize { } } -pub struct Spi<'d, T: Instance + RccPeripheral> { +pub struct Spi<'d, T: Instance> { sck: AnyPin, mosi: AnyPin, miso: AnyPin, @@ -28,7 +27,7 @@ pub struct Spi<'d, T: Instance + RccPeripheral> { phantom: PhantomData<&'d mut T>, } -impl<'d, T: Instance + RccPeripheral> Spi<'d, T> { +impl<'d, T: Instance> Spi<'d, T> { pub fn new( pclk: Hertz, _peri: impl Unborrow + 'd, @@ -131,7 +130,7 @@ impl<'d, T: Instance + RccPeripheral> Spi<'d, T> { } } -impl<'d, T: Instance + RccPeripheral> Drop for Spi<'d, T> { +impl<'d, T: Instance> Drop for Spi<'d, T> { fn drop(&mut self) { unsafe { self.sck.set_as_analog(); @@ -141,7 +140,7 @@ impl<'d, T: Instance + RccPeripheral> Drop for Spi<'d, T> { } } -impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write for Spi<'d, T> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Write for Spi<'d, T> { type Error = Error; fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> { @@ -177,7 +176,7 @@ impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write for } } -impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer for Spi<'d, T> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer for Spi<'d, T> { type Error = Error; fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> { @@ -218,7 +217,7 @@ impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer } } -impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write for Spi<'d, T> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Write for Spi<'d, T> { type Error = Error; fn write(&mut self, words: &[u16]) -> Result<(), Self::Error> { @@ -254,7 +253,7 @@ impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write fo } } -impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer for Spi<'d, T> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer for Spi<'d, T> { type Error = Error; fn transfer<'w>(&mut self, words: &'w mut [u16]) -> Result<&'w [u16], Self::Error> { diff --git a/embassy-stm32/src/spi/v2.rs b/embassy-stm32/src/spi/v2.rs index 8f91ca5a7..a7ac54cdd 100644 --- a/embassy-stm32/src/spi/v2.rs +++ b/embassy-stm32/src/spi/v2.rs @@ -4,7 +4,6 @@ use crate::gpio::{AnyPin, Pin}; use crate::pac::gpio::vals::{Afr, Moder}; use crate::pac::gpio::Gpio; use crate::pac::spi; -use crate::rcc::RccPeripheral; use crate::spi::{ByteOrder, Config, Error, Instance, MisoPin, MosiPin, SckPin, WordSize}; use crate::time::Hertz; use core::marker::PhantomData; @@ -29,14 +28,14 @@ impl WordSize { } } -pub struct Spi<'d, T: Instance + RccPeripheral> { +pub struct Spi<'d, T: Instance> { sck: AnyPin, mosi: AnyPin, miso: AnyPin, phantom: PhantomData<&'d mut T>, } -impl<'d, T: Instance + RccPeripheral> Spi<'d, T> { +impl<'d, T: Instance> Spi<'d, T> { pub fn new( pclk: Hertz, _peri: impl Unborrow + 'd, @@ -143,7 +142,7 @@ impl<'d, T: Instance + RccPeripheral> Spi<'d, T> { } } -impl<'d, T: Instance + RccPeripheral> Drop for Spi<'d, T> { +impl<'d, T: Instance> Drop for Spi<'d, T> { fn drop(&mut self) { unsafe { Self::unconfigure_pin(self.sck.block(), self.sck.pin() as _); @@ -201,7 +200,7 @@ fn read_word(regs: &'static crate::pac::spi::Spi) -> Result { } } -impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write for Spi<'d, T> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Write for Spi<'d, T> { type Error = Error; fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> { @@ -217,7 +216,7 @@ impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write for } } -impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer for Spi<'d, T> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer for Spi<'d, T> { type Error = Error; fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> { @@ -233,7 +232,7 @@ impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer } } -impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write for Spi<'d, T> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Write for Spi<'d, T> { type Error = Error; fn write(&mut self, words: &[u16]) -> Result<(), Self::Error> { @@ -249,7 +248,7 @@ impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write fo } } -impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer for Spi<'d, T> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer for Spi<'d, T> { type Error = Error; fn transfer<'w>(&mut self, words: &'w mut [u16]) -> Result<&'w [u16], Self::Error> { diff --git a/embassy-stm32/src/spi/v3.rs b/embassy-stm32/src/spi/v3.rs index 3b768751d..6073616bd 100644 --- a/embassy-stm32/src/spi/v3.rs +++ b/embassy-stm32/src/spi/v3.rs @@ -4,7 +4,6 @@ use crate::gpio::{AnyPin, Pin}; use crate::pac::gpio::vals::{Afr, Moder}; use crate::pac::gpio::Gpio; use crate::pac::spi; -use crate::rcc::RccPeripheral; use crate::spi::{ByteOrder, Config, Error, Instance, MisoPin, MosiPin, SckPin, WordSize}; use crate::time::Hertz; use core::marker::PhantomData; @@ -29,14 +28,14 @@ impl WordSize { } } -pub struct Spi<'d, T: Instance + RccPeripheral> { +pub struct Spi<'d, T: Instance> { sck: AnyPin, mosi: AnyPin, miso: AnyPin, phantom: PhantomData<&'d mut T>, } -impl<'d, T: Instance + RccPeripheral> Spi<'d, T> { +impl<'d, T: Instance> Spi<'d, T> { pub fn new( pclk: Hertz, _peri: impl Unborrow + 'd, @@ -164,7 +163,7 @@ impl<'d, T: Instance + RccPeripheral> Spi<'d, T> { } } -impl<'d, T: Instance + RccPeripheral> Drop for Spi<'d, T> { +impl<'d, T: Instance> Drop for Spi<'d, T> { fn drop(&mut self) { unsafe { Self::unconfigure_pin(self.sck.block(), self.sck.pin() as _); @@ -174,7 +173,7 @@ impl<'d, T: Instance + RccPeripheral> Drop for Spi<'d, T> { } } -impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write for Spi<'d, T> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Write for Spi<'d, T> { type Error = Error; fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> { @@ -211,7 +210,7 @@ impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write for } } -impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer for Spi<'d, T> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer for Spi<'d, T> { type Error = Error; fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> { @@ -268,7 +267,7 @@ impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer } } -impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write for Spi<'d, T> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Write for Spi<'d, T> { type Error = Error; fn write(&mut self, words: &[u16]) -> Result<(), Self::Error> { @@ -305,7 +304,7 @@ impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write fo } } -impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer for Spi<'d, T> { +impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer for Spi<'d, T> { type Error = Error; fn transfer<'w>(&mut self, words: &'w mut [u16]) -> Result<&'w [u16], Self::Error> {