Reduce generics noise

This commit is contained in:
Ulf Lilleengen 2021-06-08 13:10:58 +02:00
parent ed29d82071
commit 939ea3bbd0
4 changed files with 23 additions and 26 deletions

View File

@ -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<T: Instance>: sealed::SckPin<T> + 'static {}

View File

@ -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<F>(
pclk: Hertz,
_peri: impl Unborrow<Target = T> + '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<u8> for Spi<'d, T> {
impl<'d, T: Instance> embedded_hal::blocking::spi::Write<u8> 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<u8> for
}
}
impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer<u8> for Spi<'d, T> {
impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer<u8> 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<u8>
}
}
impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write<u16> for Spi<'d, T> {
impl<'d, T: Instance> embedded_hal::blocking::spi::Write<u16> 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<u16> fo
}
}
impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer<u16> for Spi<'d, T> {
impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer<u16> for Spi<'d, T> {
type Error = Error;
fn transfer<'w>(&mut self, words: &'w mut [u16]) -> Result<&'w [u16], Self::Error> {

View File

@ -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<F>(
pclk: Hertz,
_peri: impl Unborrow<Target = T> + '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<W: Word>(regs: &'static crate::pac::spi::Spi) -> Result<W, Error> {
}
}
impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write<u8> for Spi<'d, T> {
impl<'d, T: Instance> embedded_hal::blocking::spi::Write<u8> 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<u8> for
}
}
impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer<u8> for Spi<'d, T> {
impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer<u8> 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<u8>
}
}
impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write<u16> for Spi<'d, T> {
impl<'d, T: Instance> embedded_hal::blocking::spi::Write<u16> 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<u16> fo
}
}
impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer<u16> for Spi<'d, T> {
impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer<u16> for Spi<'d, T> {
type Error = Error;
fn transfer<'w>(&mut self, words: &'w mut [u16]) -> Result<&'w [u16], Self::Error> {

View File

@ -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<F>(
pclk: Hertz,
_peri: impl Unborrow<Target = T> + '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<u8> for Spi<'d, T> {
impl<'d, T: Instance> embedded_hal::blocking::spi::Write<u8> 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<u8> for
}
}
impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer<u8> for Spi<'d, T> {
impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer<u8> 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<u8>
}
}
impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Write<u16> for Spi<'d, T> {
impl<'d, T: Instance> embedded_hal::blocking::spi::Write<u16> 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<u16> fo
}
}
impl<'d, T: Instance + RccPeripheral> embedded_hal::blocking::spi::Transfer<u16> for Spi<'d, T> {
impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer<u16> for Spi<'d, T> {
type Error = Error;
fn transfer<'w>(&mut self, words: &'w mut [u16]) -> Result<&'w [u16], Self::Error> {