diff --git a/CHANGELOG.md b/CHANGELOG.md index e09bbcd1..39c718c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Use independent `Spi` and `SpiSlave` structures instead of `OP` generic [#462] - Take `&Clocks` instead of `Clocks` [#498] - Temporary replace `stm32f1` with `stm32f1-staging` [#503] +- Remove `PULL` generic from `Input` mode [#512] + Fix `as_(mode)` in #421 [#512] ### Changed @@ -62,6 +64,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). [#509]: https://github.com/stm32-rs/stm32f1xx-hal/pull/509 [#510]: https://github.com/stm32-rs/stm32f1xx-hal/pull/510 [#511]: https://github.com/stm32-rs/stm32f1xx-hal/pull/511 +[#512]: https://github.com/stm32-rs/stm32f1xx-hal/pull/512 ## [v0.10.0] - 2022-12-12 diff --git a/examples/can-loopback.rs b/examples/can-loopback.rs index 09ca81c2..eb0cda1b 100644 --- a/examples/can-loopback.rs +++ b/examples/can-loopback.rs @@ -12,7 +12,7 @@ use panic_halt as _; use cortex_m_rt::entry; use nb::block; -use stm32f1xx_hal::{can::Can, gpio::Floating, pac, prelude::*}; +use stm32f1xx_hal::{can::Can, pac, prelude::*}; #[entry] fn main() -> ! { @@ -25,7 +25,7 @@ fn main() -> ! { // resonator must be used. rcc.cfgr.use_hse(8.MHz()).freeze(&mut flash.acr); - let can = Can::<_, Floating>::new_loopback( + let can = Can::new_loopback( dp.CAN1, #[cfg(not(feature = "connectivity"))] dp.USB, diff --git a/examples/can-rtic.rs b/examples/can-rtic.rs index 415a5c43..dbd963c5 100644 --- a/examples/can-rtic.rs +++ b/examples/can-rtic.rs @@ -55,7 +55,7 @@ mod app { use super::{enqueue_frame, PriorityFrame}; use bxcan::{filter::Mask32, ExtendedId, Fifo, Frame, Interrupts, Rx0, StandardId, Tx}; use heapless::binary_heap::{BinaryHeap, Max}; - use stm32f1xx_hal::{can::Can, gpio::Floating, pac::CAN1, prelude::*}; + use stm32f1xx_hal::{can::Can, pac::CAN1, prelude::*}; #[local] struct Local { @@ -89,14 +89,14 @@ mod app { let mut afio = cx.device.AFIO.constrain(); #[cfg(not(feature = "connectivity"))] - let can = Can::<_, Floating>::new( + let can = Can::new( cx.device.CAN1, cx.device.USB, (can_tx_pin, can_rx_pin, &mut afio.mapr), ); #[cfg(feature = "connectivity")] - let can = Can::<_, Floating>::new(cx.device.CAN1, (can_tx_pin, can_rx_pin, &mut afio.mapr)); + let can = Can::new(cx.device.CAN1, (can_tx_pin, can_rx_pin, &mut afio.mapr)); // APB1 (PCLK1): 16MHz, Bit rate: 1000kBit/s, Sample Point 87.5% // Value was calculated with http://www.bittiming.can-wiki.info/ diff --git a/examples/exti.rs b/examples/exti.rs index 57eb8c57..a2216fbc 100644 --- a/examples/exti.rs +++ b/examples/exti.rs @@ -19,10 +19,8 @@ use stm32f1xx_hal::{pac, prelude::*}; // where the interrupt is not yet enabled (i.e. no concurrent accesses can occur). // After enabling the interrupt, main() may not have any references to these objects any more. // For the sake of minimalism, we do not use RTIC here, which would be the better way. -static mut LED: MaybeUninit>> = - MaybeUninit::uninit(); -static mut INT_PIN: MaybeUninit>> = - MaybeUninit::uninit(); +static mut LED: MaybeUninit> = MaybeUninit::uninit(); +static mut INT_PIN: MaybeUninit> = MaybeUninit::uninit(); #[interrupt] fn EXTI9_5() { diff --git a/examples/exti_rtic.rs b/examples/exti_rtic.rs index 07e449d9..aaf1a7b0 100644 --- a/examples/exti_rtic.rs +++ b/examples/exti_rtic.rs @@ -8,7 +8,7 @@ use panic_halt as _; #[rtic::app(device = stm32f1xx_hal::pac)] mod app { use stm32f1xx_hal::{ - gpio::{gpioa::PA0, gpioc::PC13, Edge, ExtiPin, Input, Output, PullDown, PushPull}, + gpio::{gpioa::PA0, gpioc::PC13, Edge, ExtiPin, Input, Output}, prelude::*, }; @@ -17,8 +17,8 @@ mod app { #[local] struct Local { - button: PA0>, - led: PC13>, + button: PA0, + led: PC13, } #[init] diff --git a/examples/mfrc522.rs b/examples/mfrc522.rs index cbb57e76..cddc2555 100644 --- a/examples/mfrc522.rs +++ b/examples/mfrc522.rs @@ -32,9 +32,9 @@ fn main() -> ! { let clocks = rcc.cfgr.freeze(&mut flash.acr); - let sck = gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl); + let sck = gpioa.pa5; let miso = gpioa.pa6; - let mosi = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl); + let mosi = gpioa.pa7; let spi = Spi::new( dp.SPI1, (sck, miso, mosi, &mut afio.mapr), diff --git a/examples/multi_mode_gpio.rs b/examples/multi_mode_gpio.rs.disabled similarity index 100% rename from examples/multi_mode_gpio.rs rename to examples/multi_mode_gpio.rs.disabled diff --git a/src/afio.rs b/src/afio.rs index d4e0b845..3f4f0ba6 100644 --- a/src/afio.rs +++ b/src/afio.rs @@ -4,7 +4,7 @@ use crate::pac::{self, afio, AFIO, RCC}; use crate::rcc::{Enable, Reset}; use crate::gpio::{ - Debugger, Floating, Input, PA15, {PB3, PB4}, + Debugger, Input, PA15, {PB3, PB4}, }; use crate::sealed::Sealed; @@ -94,11 +94,7 @@ impl MAPR { pa15: PA15, pb3: PB3, pb4: PB4, - ) -> ( - PA15>, - PB3>, - PB4>, - ) { + ) -> (PA15, PB3, PB4) { self.jtag_enabled = false; // Avoid duplicating swj_cfg write code self.modify_mapr(|_, w| w); diff --git a/src/can.rs b/src/can.rs index 1ddd5d9e..2a6b77a7 100644 --- a/src/can.rs +++ b/src/can.rs @@ -20,13 +20,9 @@ //! | RX | PB5 | PB12 | use crate::afio::Remap; -use crate::gpio::{self, Alternate, Cr, Floating, Input, NoPin, PinMode, PullUp, PushPull}; +use crate::gpio::{self, Alternate, Cr, Input, NoPin, PushPull}; use crate::pac::{self, RCC}; -pub trait InMode {} -impl InMode for Floating {} -impl InMode for PullUp {} - pub struct Pins { pub tx: TX, pub rx: RX, @@ -72,36 +68,32 @@ macro_rules! remap { )+ None(NoPin), } - pub enum Rx { + pub enum Rx { $( - $RX(gpio::$RX>), + $RX(gpio::$RX), )+ - None(NoPin), + None(NoPin), } $( - impl From<(gpio::$TX, gpio::$RX>, &mut <$PER as Remap>::Mapr)> for Pins> { - fn from(p: (gpio::$TX, gpio::$RX>, &mut <$PER as Remap>::Mapr)) -> Self { + impl From<(gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins { + fn from(p: (gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)) -> Self { <$PER>::remap(p.2, $remap); Self { tx: Tx::$TX(p.0), rx: Rx::$RX(p.1) } } } - impl From<(gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins> - where - Input: PinMode, - PULL: InMode, - { + impl From<(gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins { fn from(p: (gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)) -> Self { let mut cr = Cr; let tx = p.0.into_mode(&mut cr); - let rx = p.1.into_mode(&mut cr); + let rx = p.1; <$PER>::remap(p.2, $remap); Self { tx: Tx::$TX(tx), rx: Rx::$RX(rx) } } } - impl From<(gpio::$TX, &mut <$PER as Remap>::Mapr)> for Pins> { + impl From<(gpio::$TX, &mut <$PER as Remap>::Mapr)> for Pins { fn from(p: (gpio::$TX, &mut <$PER as Remap>::Mapr)) -> Self { let tx = p.0.into_mode(&mut Cr); <$PER>::remap(p.1, $remap); @@ -109,13 +101,9 @@ macro_rules! remap { } } - impl From<(gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins> - where - Input: PinMode, - PULL: InMode, - { + impl From<(gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins { fn from(p: (gpio::$RX, &mut <$PER as Remap>::Mapr)) -> Self { - let rx = p.0.into_mode(&mut Cr); + let rx = p.0; <$PER>::remap(p.1, $remap); Self { tx: Tx::None(NoPin::new()), rx: Rx::$RX(rx) } } @@ -129,20 +117,17 @@ pub trait CanExt: Sized + Instance { fn can( self, #[cfg(not(feature = "connectivity"))] usb: pac::USB, - pins: impl Into>>, - ) -> Can; - fn can_loopback( - self, - #[cfg(not(feature = "connectivity"))] usb: pac::USB, - ) -> Can; + pins: impl Into>, + ) -> Can; + fn can_loopback(self, #[cfg(not(feature = "connectivity"))] usb: pac::USB) -> Can; } impl CanExt for CAN { fn can( self, #[cfg(not(feature = "connectivity"))] usb: pac::USB, - pins: impl Into>>, - ) -> Can { + pins: impl Into>, + ) -> Can { Can::new( self, #[cfg(not(feature = "connectivity"))] @@ -150,10 +135,7 @@ impl CanExt for CAN { pins, ) } - fn can_loopback( - self, - #[cfg(not(feature = "connectivity"))] usb: pac::USB, - ) -> Can { + fn can_loopback(self, #[cfg(not(feature = "connectivity"))] usb: pac::USB) -> Can { Can::new_loopback( self, #[cfg(not(feature = "connectivity"))] @@ -164,26 +146,26 @@ impl CanExt for CAN { pub trait Instance: crate::rcc::Enable { type Tx; - type Rx; + type Rx; } impl Instance for pac::CAN1 { type Tx = can1::Tx; - type Rx = can1::Rx; + type Rx = can1::Rx; } #[cfg(feature = "connectivity")] impl Instance for pac::CAN2 { type Tx = can2::Tx; - type Rx = can2::Rx; + type Rx = can2::Rx; } /// Interface to the CAN peripheral. #[allow(unused)] -pub struct Can { +pub struct Can { can: CAN, - pins: Option>>, + pins: Option>, } -impl Can { +impl Can { /// Creates a CAN interface. /// /// CAN shares SRAM with the USB peripheral. Take ownership of USB to @@ -191,8 +173,8 @@ impl Can { pub fn new( can: CAN, #[cfg(not(feature = "connectivity"))] _usb: pac::USB, - pins: impl Into>>, - ) -> Can { + pins: impl Into>, + ) -> Can { let rcc = unsafe { &(*RCC::ptr()) }; CAN::enable(rcc); @@ -204,7 +186,7 @@ impl Can { pub fn new_loopback( can: CAN, #[cfg(not(feature = "connectivity"))] _usb: pac::USB, - ) -> Can { + ) -> Can { let rcc = unsafe { &(*RCC::ptr()) }; CAN::enable(rcc); @@ -212,18 +194,18 @@ impl Can { } } -unsafe impl bxcan::Instance for Can { +unsafe impl bxcan::Instance for Can { const REGISTERS: *mut bxcan::RegisterBlock = pac::CAN1::ptr() as *mut _; } #[cfg(feature = "connectivity")] -unsafe impl bxcan::Instance for Can { +unsafe impl bxcan::Instance for Can { const REGISTERS: *mut bxcan::RegisterBlock = pac::CAN2::ptr() as *mut _; } -unsafe impl bxcan::FilterOwner for Can { +unsafe impl bxcan::FilterOwner for Can { const NUM_FILTER_BANKS: u8 = 28; } #[cfg(feature = "connectivity")] -unsafe impl bxcan::MasterInstance for Can {} +unsafe impl bxcan::MasterInstance for Can {} diff --git a/src/gpio.rs b/src/gpio.rs index bd1b62af..6718f45d 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -156,25 +156,28 @@ pub trait Active {} /// Input mode (type state) #[derive(Default)] -pub struct Input(PhantomData); - -impl Active for Input {} - -/// Used by the debugger (type state) -#[derive(Default)] -pub struct Debugger; +pub struct Input; + +/// Pull setting for an input. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub enum Pull { + /// Floating + None = 0, + /// Pulled up + Up = 1, + /// Pulled down + Down = 2, +} -/// Floating input (type state) #[derive(Default)] -pub struct Floating; +struct PulledInput; -/// Pulled down input (type state) -#[derive(Default)] -pub struct PullDown; +impl Active for Input {} -/// Pulled up input (type state) +/// Used by the debugger (type state) #[derive(Default)] -pub struct PullUp; +pub struct Debugger; /// Output mode (type state) #[derive(Default)] @@ -222,7 +225,6 @@ mod sealed { pub trait PinMode: Default { const CNF: super::Cnf; const MODE: super::Mode; - const PULL: Option = None; } } @@ -231,7 +233,7 @@ use crate::pac::gpioa::crl::{CNF0 as Cnf, MODE0 as Mode}; use sealed::Interruptable; pub(crate) use sealed::PinMode; -impl Interruptable for Input {} +impl Interruptable for Input {} impl Interruptable for Dynamic {} /// External Interrupt Pin @@ -375,7 +377,7 @@ macro_rules! gpio { pub mod $gpiox { use crate::pac::{$GPIOX, RCC}; use crate::rcc::{Enable, Reset}; - use super::{Active, Floating, GpioExt, Input, PartiallyErasedPin, ErasedPin, Pin, Cr}; + use super::{Active, GpioExt, Input, PartiallyErasedPin, ErasedPin, Pin, Cr}; #[allow(unused)] use super::Debugger; @@ -392,7 +394,7 @@ macro_rules! gpio { } $( - pub type $PXi> = Pin<$port_id, $pin_number, MODE>; + pub type $PXi = Pin<$port_id, $pin_number, MODE>; )+ impl GpioExt for $GPIOX { @@ -455,7 +457,7 @@ macro_rules! gpio { /// - `P` is port name: `A` for GPIOA, `B` for GPIOB, etc. /// - `N` is pin number: from `0` to `15`. /// - `MODE` is one of the pin modes (see [Modes](crate::gpio#modes) section). -pub struct Pin> { +pub struct Pin { mode: MODE, } @@ -505,7 +507,7 @@ impl Pin { /// must enforce that the pin is really in this /// state in the hardware. #[allow(dead_code)] - pub(crate) unsafe fn activate(self) -> Pin> { + pub(crate) unsafe fn activate(self) -> Pin { Pin::new() } } @@ -616,7 +618,7 @@ impl Pin> { } } -impl Pin> { +impl Pin { #[inline] pub fn is_high(&self) -> bool { !self._is_low() @@ -628,6 +630,59 @@ impl Pin> { } } +impl Pin { + fn _set_pull_up(&mut self) { + let gpio = unsafe { &(*gpiox::

()) }; + gpio.bsrr().write(|w| w.bs(N).set_bit()); + } + fn _pull_up(mut self) -> Self { + self._set_pull_up(); + self + } + fn _set_pull_down(&mut self) { + let gpio = unsafe { &(*gpiox::

()) }; + gpio.bsrr().write(|w| w.br(N).set_bit()); + } + fn _pull_down(mut self) -> Self { + self._set_pull_down(); + self + } +} +impl Pin { + /// Set the internal pull-up and pull-down resistor + pub fn set_internal_resistor(&mut self, pull: Pull) { + match pull { + Pull::None => { + let gpio = unsafe { &(*gpiox::

()) }; + match N { + 0..=7 => { + gpio.crl().modify(|_, w| w.cnf(N).variant(Cnf::OpenDrain)); + } + 8..=15 => { + gpio.crh() + .modify(|_, w| unsafe { w.cnf(N - 16).bits(Cnf::OpenDrain as u8) }); + } + _ => unreachable!(), + } + } + Pull::Up => { + self.mode::(); + self._set_pull_up() + } + Pull::Down => { + self.mode::(); + self._set_pull_down() + } + } + } + + /// Set the internal pull-up and pull-down resistor + pub fn internal_resistor(mut self, pull: Pull) -> Self { + self.set_internal_resistor(pull); + self + } +} + impl Pin> { #[inline] pub fn is_high(&self) -> bool { @@ -671,20 +726,22 @@ where /// Configures the pin to operate as a floating input pin #[inline] - pub fn into_floating_input(self, cr: &mut ::Cr) -> Pin> { + pub fn into_floating_input(self, cr: &mut ::Cr) -> Pin { self.into_mode(cr) } /// Configures the pin to operate as a pulled down input pin #[inline] - pub fn into_pull_down_input(self, cr: &mut ::Cr) -> Pin> { - self.into_mode(cr) + pub fn into_pull_down_input(mut self, _cr: &mut ::Cr) -> Pin { + self.mode::(); + Pin::new()._pull_down() } /// Configures the pin to operate as a pulled up input pin #[inline] - pub fn into_pull_up_input(self, cr: &mut ::Cr) -> Pin> { - self.into_mode(cr) + pub fn into_pull_up_input(mut self, _cr: &mut ::Cr) -> Pin { + self.mode::(); + Pin::new()._pull_up() } /// Configures the pin to operate as an open-drain output pin. @@ -745,8 +802,8 @@ where /// and output without changing the type. It starts out /// as a floating input #[inline] - pub fn into_dynamic(mut self, cr: &mut ::Cr) -> Pin { - self.mode::>(cr); + pub fn into_dynamic(mut self, _cr: &mut ::Cr) -> Pin { + self.mode::(); Pin::new() } } @@ -762,14 +819,13 @@ macro_rules! impl_temp_output { #[inline] pub fn $fn_name( &mut self, - cr: &mut ::Cr, + _cr: &mut ::Cr, mut f: impl FnMut(&mut Pin), ) { - self.mode::<$mode>(cr); + self.mode::<$mode>(); let mut temp = Pin::::new(); f(&mut temp); - self.mode::<$mode>(cr); - Self::new(); + temp.mode::(); } /// Temporarily change the mode of the pin. @@ -780,33 +836,31 @@ macro_rules! impl_temp_output { #[inline] pub fn $stateful_fn_name( &mut self, - cr: &mut ::Cr, + _cr: &mut ::Cr, state: PinState, mut f: impl FnMut(&mut Pin), ) { self._set_state(state); - self.mode::<$mode>(cr); + self.mode::<$mode>(); let mut temp = Pin::::new(); f(&mut temp); - self.mode::<$mode>(cr); - Self::new(); + temp.mode::(); } }; } macro_rules! impl_temp_input { - ($fn_name:ident, $mode:ty) => { + ($fn_name:ident, $mode:ty $(, $pull:ident)?) => { /// Temporarily change the mode of the pin. #[inline] pub fn $fn_name( &mut self, - cr: &mut ::Cr, - mut f: impl FnMut(&mut Pin), + _cr: &mut ::Cr, + mut f: impl FnMut(&mut Pin), ) { - self.mode::<$mode>(cr); - let mut temp = Pin::::new(); + self.mode::<$mode>(); + let mut temp = Pin::::new() $(.$pull())?; f(&mut temp); - self.mode::<$mode>(cr); - Self::new(); + temp.mode::(); } }; } @@ -826,9 +880,9 @@ where as_open_drain_output_with_state, Output ); - impl_temp_input!(as_floating_input, Input); - impl_temp_input!(as_pull_up_input, Input); - impl_temp_input!(as_pull_down_input, Input); + impl_temp_input!(as_floating_input, Input); + impl_temp_input!(as_pull_up_input, PulledInput, _pull_up); + impl_temp_input!(as_pull_down_input, PulledInput, _pull_down); } impl Pin @@ -877,37 +931,39 @@ where Self: HL, { #[inline] - pub fn make_pull_up_input(&mut self, cr: &mut ::Cr) { + pub fn make_pull_up_input(&mut self, _cr: &mut ::Cr) { // NOTE(unsafe), we have a mutable reference to the current pin - self.mode::>(cr); + self.mode::(); + self._set_pull_up(); self.mode = Dynamic::InputPullUp; } #[inline] - pub fn make_pull_down_input(&mut self, cr: &mut ::Cr) { + pub fn make_pull_down_input(&mut self, _cr: &mut ::Cr) { // NOTE(unsafe), we have a mutable reference to the current pin - self.mode::>(cr); + self.mode::(); + self._set_pull_down(); self.mode = Dynamic::InputPullDown; } #[inline] - pub fn make_floating_input(&mut self, cr: &mut ::Cr) { + pub fn make_floating_input(&mut self, _cr: &mut ::Cr) { // NOTE(unsafe), we have a mutable reference to the current pin - self.mode::>(cr); + self.mode::(); self.mode = Dynamic::InputFloating; } #[inline] - pub fn make_push_pull_output(&mut self, cr: &mut ::Cr) { + pub fn make_push_pull_output(&mut self, _cr: &mut ::Cr) { // NOTE(unsafe), we have a mutable reference to the current pin - self.mode::>(cr); + self.mode::>(); self.mode = Dynamic::OutputPushPull; } #[inline] - pub fn make_open_drain_output(&mut self, cr: &mut ::Cr) { + pub fn make_open_drain_output(&mut self, _cr: &mut ::Cr) { // NOTE(unsafe), we have a mutable reference to the current pin - self.mode::>(cr); + self.mode::>(); self.mode = Dynamic::OutputOpenDrain; } } @@ -917,21 +973,14 @@ impl PinMode for Analog { const CNF: Cnf = Cnf::PushPull; } -impl PinMode for Input { +impl PinMode for Input { const MODE: Mode = Mode::Input; const CNF: Cnf = Cnf::OpenDrain; } -impl PinMode for Input { - const MODE: Mode = Mode::Input; - const CNF: Cnf = Cnf::AltPushPull; - const PULL: Option = Some(false); -} - -impl PinMode for Input { +impl PinMode for PulledInput { const MODE: Mode = Mode::Input; const CNF: Cnf = Cnf::AltPushPull; - const PULL: Option = Some(true); } impl PinMode for Output { @@ -954,24 +1003,10 @@ impl PinMode for Alternate { const CNF: Cnf = Cnf::AltOpenDrain; } -impl Pin -where - Self: HL, -{ - fn mode(&mut self, _cr: &mut ::Cr) { +impl Pin { + fn mode(&mut self) { let gpio = unsafe { &(*gpiox::

()) }; - // Input or Input mode - if let Some(pull) = MODE::PULL { - gpio.bsrr().write(|w| { - if pull { - w.bs(N).set_bit() - } else { - w.br(N).set_bit() - } - }) - } - match N { 0..=7 => { gpio.crl() @@ -986,10 +1021,18 @@ where _ => unreachable!(), } } +} +impl Pin +where + Self: HL, +{ #[inline] - pub(crate) fn into_mode(mut self, cr: &mut ::Cr) -> Pin { - self.mode::(cr); + pub(crate) fn into_mode( + mut self, + _cr: &mut ::Cr, + ) -> Pin { + self.mode::(); Pin::new() } } @@ -1007,17 +1050,27 @@ impl Analog { } } -impl Input { +impl Input { pub fn new( - pin: Pin, + mut pin: Pin, cr: &mut as HL>::Cr, - _pull: PULL, + pull: Pull, ) -> Pin where Pin: HL, Self: PinMode, { - pin.into_mode(cr) + match pull { + Pull::None => pin.into_mode(cr), + Pull::Up => { + pin.mode::(); + Pin::new()._pull_up() + } + Pull::Down => { + pin.mode::(); + Pin::new()._pull_down() + } + } } } diff --git a/src/gpio/erased.rs b/src/gpio/erased.rs index f09bff71..2b6a90d3 100644 --- a/src/gpio/erased.rs +++ b/src/gpio/erased.rs @@ -57,7 +57,7 @@ macro_rules! impl_pxx { } } - impl ErasedPin> { + impl ErasedPin { pub fn is_high(&self) -> bool { match self { $(Self::$pin(pin) => pin.is_high()),* diff --git a/src/gpio/hal_02.rs b/src/gpio/hal_02.rs index 54baa8ab..127b87f9 100644 --- a/src/gpio/hal_02.rs +++ b/src/gpio/hal_02.rs @@ -72,7 +72,7 @@ impl ToggleableOutputPin for Pin InputPin for Pin> { +impl InputPin for Pin { type Error = Infallible; #[inline] fn is_high(&self) -> Result { @@ -152,7 +152,7 @@ impl InputPin for PartiallyErasedPin> { } } -impl InputPin for PartiallyErasedPin> { +impl InputPin for PartiallyErasedPin { type Error = Infallible; #[inline(always)] @@ -191,7 +191,7 @@ impl StatefulOutputPin for ErasedPin> { } } -impl InputPin for ErasedPin> { +impl InputPin for ErasedPin { type Error = Infallible; fn is_high(&self) -> Result { Ok(self.is_high()) diff --git a/src/gpio/hal_1.rs b/src/gpio/hal_1.rs index a3d4bc40..f63417d5 100644 --- a/src/gpio/hal_1.rs +++ b/src/gpio/hal_1.rs @@ -16,7 +16,7 @@ fn into_state(state: PinState) -> super::PinState { impl ErrorType for Pin> { type Error = Infallible; } -impl ErrorType for Pin> { +impl ErrorType for Pin { type Error = Infallible; } @@ -88,7 +88,7 @@ impl StatefulOutputPin for Pin InputPin for Pin> { +impl InputPin for Pin { #[inline] fn is_high(&mut self) -> Result { Ok((*self).is_high()) @@ -156,7 +156,7 @@ impl InputPin for PartiallyErasedPin> { } } -impl InputPin for PartiallyErasedPin> { +impl InputPin for PartiallyErasedPin { #[inline(always)] fn is_high(&mut self) -> Result { Ok((*self).is_high()) @@ -196,7 +196,7 @@ impl StatefulOutputPin for ErasedPin> { } } -impl InputPin for ErasedPin> { +impl InputPin for ErasedPin { fn is_high(&mut self) -> Result { Ok((*self).is_high()) } diff --git a/src/gpio/partially_erased.rs b/src/gpio/partially_erased.rs index 4aef818b..f0380acc 100644 --- a/src/gpio/partially_erased.rs +++ b/src/gpio/partially_erased.rs @@ -102,7 +102,7 @@ impl PartiallyErasedPin> { } } -impl PartiallyErasedPin> { +impl PartiallyErasedPin { #[inline(always)] pub fn is_high(&self) -> bool { !self.is_low() diff --git a/src/serial.rs b/src/serial.rs index f1547787..a568340d 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -68,7 +68,7 @@ use embedded_dma::{ReadBuffer, WriteBuffer}; use crate::afio::Remap; use crate::dma::{dma1, CircBuffer, RxDma, Transfer, TxDma, R, W}; -use crate::gpio::{self, Alternate, Cr, Floating, Input, NoPin, PinMode, PullUp, PushPull}; +use crate::gpio::{self, Alternate, Cr, Input, NoPin, PinMode, PushPull}; use crate::pac::{self, RCC}; use crate::rcc::{BusClock, Clocks, Enable, Reset}; use crate::time::{Bps, U32Ext}; @@ -76,10 +76,6 @@ use crate::time::{Bps, U32Ext}; mod hal_02; mod hal_1; -pub trait InMode {} -impl InMode for Floating {} -impl InMode for PullUp {} - pub struct Pins { pub tx: TX, pub rx: RX, @@ -138,44 +134,42 @@ macro_rules! remap { )+ None(NoPin), } - pub enum Rx { + pub enum Rx { $( - $RX(gpio::$RX>), + $RX(gpio::$RX), )+ - None(NoPin), + None(NoPin), } $( - impl From<(gpio::$TX>, gpio::$RX>, &mut <$PER as Remap>::Mapr)> for Pins, Rx> { - fn from(p: (gpio::$TX>, gpio::$RX>, &mut <$PER as Remap>::Mapr)) -> Self { + impl From<(gpio::$TX>, gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins, Rx> { + fn from(p: (gpio::$TX>, gpio::$RX, &mut <$PER as Remap>::Mapr)) -> Self { <$PER>::remap(p.2, $remap); Self { tx: Tx::$TX(p.0), rx: Rx::$RX(p.1) } } } - impl From<(gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins, Rx> + impl From<(gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins, Rx> where Alternate: PinMode, - Input: PinMode, - PULL: InMode, { fn from(p: (gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)) -> Self { let mut cr = Cr; let tx = p.0.into_mode(&mut cr); - let rx = p.1.into_mode(&mut cr); + let rx = p.1; <$PER>::remap(p.2, $remap); Self { tx: Tx::$TX(tx), rx: Rx::$RX(rx) } } } - impl From<(gpio::$TX>, &mut <$PER as Remap>::Mapr)> for Pins, Rx> { + impl From<(gpio::$TX>, &mut <$PER as Remap>::Mapr)> for Pins, Rx> { fn from(p: (gpio::$TX>, &mut <$PER as Remap>::Mapr)) -> Self { <$PER>::remap(p.1, $remap); Self { tx: Tx::$TX(p.0), rx: Rx::None(NoPin::new()) } } } - impl From<(gpio::$TX, &mut <$PER as Remap>::Mapr)> for Pins, Rx> + impl From<(gpio::$TX, &mut <$PER as Remap>::Mapr)> for Pins, Rx> where Alternate: PinMode, { @@ -186,11 +180,8 @@ macro_rules! remap { } } - impl From<(gpio::$RX>, &mut <$PER as Remap>::Mapr)> for Pins, Rx> - where - PULL: InMode, - { - fn from(p: (gpio::$RX>, &mut <$PER as Remap>::Mapr)) -> Self { + impl From<(gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins, Rx> { + fn from(p: (gpio::$RX, &mut <$PER as Remap>::Mapr)) -> Self { <$PER>::remap(p.1, $remap); Self { tx: Tx::None(NoPin::new()), rx: Rx::$RX(p.0) } } @@ -203,13 +194,13 @@ use remap; pub trait SerialExt: Sized + Instance { fn serial( self, - pins: impl Into, Self::Rx>>, + pins: impl Into, Self::Rx>>, config: impl Into, clocks: &Clocks, - ) -> Serial; + ) -> Serial; fn tx( self, - pins: impl Into, Self::Rx>>, + pins: impl Into, Self::Rx>>, config: impl Into, clocks: &Clocks, ) -> Tx { @@ -217,7 +208,7 @@ pub trait SerialExt: Sized + Instance { } fn rx( self, - pins: impl Into, Self::Rx>>, + pins: impl Into, Self::Rx>>, config: impl Into, clocks: &Clocks, ) -> Rx { @@ -228,7 +219,7 @@ pub trait SerialExt: Sized + Instance { impl SerialExt for USART { fn serial( self, - pins: impl Into, Self::Rx>>, + pins: impl Into, Self::Rx>>, config: impl Into, clocks: &Clocks, ) -> Serial { @@ -242,7 +233,7 @@ pub trait Instance: crate::Sealed + Deref + Enable + Reset + BusClock { type Tx; - type Rx; + type Rx; #[doc(hidden)] fn ptr() -> *const uart_base::RegisterBlock; @@ -253,7 +244,7 @@ macro_rules! inst { $( impl Instance for $USARTX { type Tx = $usart::Tx; - type Rx = $usart::Rx; + type Rx = $usart::Rx; fn ptr() -> *const uart_base::RegisterBlock { <$USARTX>::ptr() @@ -384,11 +375,11 @@ impl From for Config { } /// Serial abstraction -pub struct Serial { +pub struct Serial { pub tx: Tx, pub rx: Rx, #[allow(clippy::type_complexity)] - pub token: ReleaseToken, USART::Rx)>, + pub token: ReleaseToken, USART::Rx)>, } /// Serial transmitter @@ -407,10 +398,10 @@ pub struct ReleaseToken { pins: PINS, } -impl Serial { +impl Serial { pub fn tx( usart: USART, - pins: impl Into, USART::Rx>>, + pins: impl Into, USART::Rx>>, config: impl Into, clocks: &Clocks, ) -> Tx { @@ -418,10 +409,10 @@ impl Serial { } } -impl Serial { +impl Serial { pub fn rx( usart: USART, - pins: impl Into, USART::Rx>>, + pins: impl Into, USART::Rx>>, config: impl Into, clocks: &Clocks, ) -> Rx { @@ -429,7 +420,7 @@ impl Serial { } } -impl Serial { +impl Serial { /// Configures the serial interface and creates the interface /// struct. /// @@ -447,7 +438,7 @@ impl Serial { /// corresponding pins. `APBX` is used to reset the USART.) pub fn new( usart: USART, - pins: impl Into, USART::Rx>>, + pins: impl Into, USART::Rx>>, config: impl Into, clocks: &Clocks, ) -> Self { @@ -515,7 +506,7 @@ impl Serial { /// let (usart, (tx_pin, rx_pin)) = serial.release(); /// ``` #[allow(clippy::type_complexity)] - pub fn release(self) -> (USART, (USART::Tx, USART::Rx)) { + pub fn release(self) -> (USART, (USART::Tx, USART::Rx)) { (self.token.usart, self.token.pins) } @@ -755,7 +746,7 @@ pub enum Event { Idle, } -impl Serial { +impl Serial { /// Starts listening to the USART by enabling the _Received data /// ready to be read (RXNE)_ interrupt and _Transmit data /// register empty (TXE)_ interrupt diff --git a/src/spi.rs b/src/spi.rs index 67beaddc..a77219e3 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -46,7 +46,7 @@ use crate::dma::dma1; #[cfg(feature = "connectivity")] use crate::dma::dma2; use crate::dma::{Receive, RxDma, RxTxDma, Transfer, TransferPayload, Transmit, TxDma, R, W}; -use crate::gpio::{self, Alternate, Cr, Floating, Input, NoPin, PinMode, PullUp, PushPull}; +use crate::gpio::{self, Alternate, Cr, Input, NoPin, PinMode, PushPull}; use crate::rcc::{BusClock, Clocks, Enable, Reset}; use crate::time::Hertz; @@ -104,10 +104,6 @@ pub enum Error { use core::marker::PhantomData; -pub trait InMode {} -impl InMode for Floating {} -impl InMode for PullUp {} - pub struct MasterPins { pub sck: SCK, pub mi: MISO, @@ -169,11 +165,11 @@ macro_rules! remap { None(NoPin), } - pub enum Mi { + pub enum Mi { $( - $MISO(gpio::$MISO>), + $MISO(gpio::$MISO), )+ - None(NoPin), + None(NoPin), } pub enum So { @@ -190,59 +186,51 @@ macro_rules! remap { None(NoPin), } - pub enum Si { + pub enum Si { $( - $MOSI(gpio::$MOSI>), + $MOSI(gpio::$MOSI), )+ - None(NoPin), + None(NoPin), } $( // For master mode - impl From<(gpio::$SCK, gpio::$MISO>, gpio::$MOSI $(, &mut $MAPR)?)> for MasterPins, Mo> { - fn from(p: (gpio::$SCK, gpio::$MISO>, gpio::$MOSI $(, &mut $MAPR)?)) -> Self { + impl From<(gpio::$SCK, gpio::$MISO, gpio::$MOSI $(, &mut $MAPR)?)> for MasterPins { + fn from(p: (gpio::$SCK, gpio::$MISO, gpio::$MOSI $(, &mut $MAPR)?)) -> Self { $(<$PER>::remap(p.3, $remap);)? Self { sck: Sck::$SCK(p.0), mi: Mi::$MISO(p.1), mo: Mo::$MOSI(p.2) } } } - impl From<(gpio::$SCK, gpio::$MISO, gpio::$MOSI $(, &mut $MAPR)?)> for MasterPins, Mo> - where - Input: PinMode, - PULL: InMode, - { + impl From<(gpio::$SCK, gpio::$MISO, gpio::$MOSI $(, &mut $MAPR)?)> for MasterPins { fn from(p: (gpio::$SCK, gpio::$MISO, gpio::$MOSI $(, &mut $MAPR)?)) -> Self { let mut cr = Cr; let sck = p.0.into_mode(&mut cr); - let miso = p.1.into_mode(&mut cr); + let miso = p.1; let mosi = p.2.into_mode(&mut cr); $(<$PER>::remap(p.3, $remap);)? Self { sck: Sck::$SCK(sck), mi: Mi::$MISO(miso), mo: Mo::$MOSI(mosi) } } } - impl From<(gpio::$SCK, gpio::$MISO> $(, &mut $MAPR)?)> for MasterPins, Mo> { - fn from(p: (gpio::$SCK, gpio::$MISO> $(, &mut $MAPR)?)) -> Self { + impl From<(gpio::$SCK, gpio::$MISO $(, &mut $MAPR)?)> for MasterPins { + fn from(p: (gpio::$SCK, gpio::$MISO $(, &mut $MAPR)?)) -> Self { $(<$PER>::remap(p.2, $remap);)? Self { sck: Sck::$SCK(p.0), mi: Mi::$MISO(p.1), mo: Mo::None(NoPin::new()) } } } - impl From<(gpio::$SCK, gpio::$MISO $(, &mut $MAPR)?)> for super::MasterPins, Mo> - where - Input: PinMode, - PULL: InMode, - { + impl From<(gpio::$SCK, gpio::$MISO $(, &mut $MAPR)?)> for super::MasterPins { fn from(p: (gpio::$SCK, gpio::$MISO $(, &mut $MAPR)?)) -> Self { let mut cr = Cr; let sck = p.0.into_mode(&mut cr); - let miso = p.1.into_mode(&mut cr); + let miso = p.1; $(<$PER>::remap(p.2, $remap);)? Self { sck: Sck::$SCK(sck), mi: Mi::$MISO(miso), mo: Mo::None(NoPin::new()) } } } - impl From<(gpio::$SCK, gpio::$MOSI $(, &mut $MAPR)?)> for super::MasterPins, Mo> { + impl From<(gpio::$SCK, gpio::$MOSI $(, &mut $MAPR)?)> for super::MasterPins { fn from(p: (gpio::$SCK, gpio::$MOSI $(, &mut $MAPR)?)) -> Self { let mut cr = Cr; let sck = p.0.into_mode(&mut cr); @@ -254,30 +242,28 @@ macro_rules! remap { // For slave mode - impl From<(gpio::$SCK, gpio::$MISO>, gpio::$MOSI> $(, &mut $MAPR)?)> for SlavePins, Si> { - fn from(p: (gpio::$SCK, gpio::$MISO>, gpio::$MOSI> $(, &mut $MAPR)?)) -> Self { + impl From<(gpio::$SCK, gpio::$MISO>, gpio::$MOSI $(, &mut $MAPR)?)> for SlavePins, Si> { + fn from(p: (gpio::$SCK, gpio::$MISO>, gpio::$MOSI $(, &mut $MAPR)?)) -> Self { $(<$PER>::remap(p.3, $remap);)? Self { sck: Sck::$SCK(p.0), so: So::$MISO(p.1), si: Si::$MOSI(p.2) } } } - impl From<(gpio::$SCK, gpio::$MISO, gpio::$MOSI $(, &mut $MAPR)?)> for SlavePins, Si> + impl From<(gpio::$SCK, gpio::$MISO, gpio::$MOSI $(, &mut $MAPR)?)> for SlavePins, Si> where Alternate: PinMode, - Input: PinMode, - PULL: InMode, { fn from(p: (gpio::$SCK, gpio::$MISO, gpio::$MOSI $(, &mut $MAPR)?)) -> Self { let mut cr = Cr; let sck = p.0.into_mode(&mut cr); let miso = p.1.into_mode(&mut cr); - let mosi = p.2.into_mode(&mut cr); + let mosi = p.2; $(<$PER>::remap(p.3, $remap);)? Self { sck: Sck::$SCK(sck), so: So::$MISO(miso), si: Si::$MOSI(mosi) } } } - impl From<(gpio::$SCK, gpio::$MISO $(, &mut $MAPR)?)> for SlavePins, Si> + impl From<(gpio::$SCK, gpio::$MISO $(, &mut $MAPR)?)> for SlavePins, Si> where Alternate: PinMode, { @@ -290,15 +276,11 @@ macro_rules! remap { } } - impl From<(gpio::$SCK, gpio::$MOSI $(, &mut $MAPR)?)> for SlavePins, Si> - where - Input: PinMode, - PULL: InMode, - { + impl From<(gpio::$SCK, gpio::$MOSI $(, &mut $MAPR)?)> for SlavePins, Si> { fn from(p: (gpio::$SCK, gpio::$MOSI $(, &mut $MAPR)?)) -> Self { let mut cr = Cr; let sck = p.0.into_mode(&mut cr); - let mosi = p.1.into_mode(&mut cr); + let mosi = p.1; $(<$PER>::remap(p.2, $remap);)? Self { sck: Sck::$SCK(sck), so: So::None(NoPin::new()), si: Si::$MOSI(mosi) } } @@ -311,14 +293,14 @@ use remap; pub trait SpiExt: Sized + Instance { fn spi( self, - pins: impl Into, Self::Mo>>, + pins: impl Into>, mode: Mode, freq: Hertz, clocks: &Clocks, - ) -> Spi; + ) -> Spi; fn spi_u16( self, - pins: impl Into, Self::Mo>>, + pins: impl Into>, mode: Mode, freq: Hertz, clocks: &Clocks, @@ -327,14 +309,14 @@ pub trait SpiExt: Sized + Instance { } fn spi_slave( self, - pins: impl Into, Self::Si>>, + pins: impl Into, Self::Si>>, mode: Mode, - ) -> SpiSlave; + ) -> SpiSlave; fn spi_slave_u16( self, - pins: impl Into, Self::Si>>, + pins: impl Into, Self::Si>>, mode: Mode, - ) -> SpiSlave { + ) -> SpiSlave { Self::spi_slave(self, pins, mode).frame_size_16bit() } } @@ -342,18 +324,18 @@ pub trait SpiExt: Sized + Instance { impl SpiExt for SPI { fn spi( self, - pins: impl Into, Self::Mo>>, + pins: impl Into>, mode: Mode, freq: Hertz, clocks: &Clocks, - ) -> Spi { + ) -> Spi { Spi::new(self, pins, mode, freq, clocks) } fn spi_slave( self, - pins: impl Into, Self::Si>>, + pins: impl Into, Self::Si>>, mode: Mode, - ) -> SpiSlave { + ) -> SpiSlave { SpiSlave::new(self, pins, mode) } } @@ -373,38 +355,38 @@ impl SpiInner { } /// Spi in Master mode -pub struct Spi { +pub struct Spi { inner: SpiInner, - pins: (SPI::Sck, SPI::Mi, SPI::Mo), + pins: (SPI::Sck, SPI::Mi, SPI::Mo), } /// Spi in Slave mode -pub struct SpiSlave { +pub struct SpiSlave { inner: SpiInner, - pins: (SPI::Sck, SPI::So, SPI::Si), + pins: (SPI::Sck, SPI::So, SPI::Si), } -impl Deref for Spi { +impl Deref for Spi { type Target = SpiInner; fn deref(&self) -> &Self::Target { &self.inner } } -impl DerefMut for Spi { +impl DerefMut for Spi { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner } } -impl Deref for SpiSlave { +impl Deref for SpiSlave { type Target = SpiInner; fn deref(&self) -> &Self::Target { &self.inner } } -impl DerefMut for SpiSlave { +impl DerefMut for SpiSlave { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner } @@ -423,36 +405,36 @@ pub trait Instance: crate::Sealed + Deref + Enable + Reset + BusClock { type Sck; - type Mi; + type Mi; type So; type Mo; - type Si; + type Si; } impl Instance for pac::SPI1 { type Sck = spi1::Sck; - type Mi = spi1::Mi; + type Mi = spi1::Mi; type So = spi1::So; type Mo = spi1::Mo; - type Si = spi1::Si; + type Si = spi1::Si; } impl Instance for pac::SPI2 { type Sck = spi2::Sck; - type Mi = spi2::Mi; + type Mi = spi2::Mi; type So = spi2::So; type Mo = spi2::Mo; - type Si = spi2::Si; + type Si = spi2::Si; } #[cfg(any(feature = "high", feature = "connectivity"))] impl Instance for pac::SPI3 { type Sck = spi3::Sck; - type Mi = spi3::Mi; + type Mi = spi3::Mi; type So = spi3::So; type Mo = spi3::Mo; - type Si = spi3::Si; + type Si = spi3::Si; } -impl Spi { +impl Spi { /** Constructs an SPI instance using SPI1 in 8bit dataframe mode. @@ -462,7 +444,7 @@ impl Spi { */ pub fn new( spi: SPI, - pins: impl Into, SPI::Mo>>, + pins: impl Into>, mode: Mode, freq: Hertz, clocks: &Clocks, @@ -521,12 +503,12 @@ impl Spi { } #[allow(clippy::type_complexity)] - pub fn release(self) -> (SPI, (SPI::Sck, SPI::Mi, SPI::Mo)) { + pub fn release(self) -> (SPI, (SPI::Sck, SPI::Mi, SPI::Mo)) { (self.inner.spi, self.pins) } } -impl SpiSlave { +impl SpiSlave { /** Constructs an SPI instance using SPI1 in 8bit dataframe mode. @@ -536,7 +518,7 @@ impl SpiSlave { */ pub fn new( spi: SPI, - pins: impl Into, SPI::Si>>, + pins: impl Into, SPI::Si>>, mode: Mode, ) -> Self { // enable or reset SPI @@ -579,7 +561,7 @@ impl SpiSlave { } #[allow(clippy::type_complexity)] - pub fn release(self) -> (SPI, (SPI::Sck, SPI::So, SPI::Si)) { + pub fn release(self) -> (SPI, (SPI::Sck, SPI::So, SPI::Si)) { (self.inner.spi, self.pins) } } @@ -686,9 +668,9 @@ impl SpiInner { } } -impl Spi { +impl Spi { /// Converts from 8bit dataframe to 16bit. - pub fn frame_size_16bit(self) -> Spi { + pub fn frame_size_16bit(self) -> Spi { self.spi.cr1().modify(|_, w| w.spe().clear_bit()); self.spi.cr1().modify(|_, w| w.dff().set_bit()); self.spi.cr1().modify(|_, w| w.spe().set_bit()); @@ -699,9 +681,9 @@ impl Spi { } } -impl SpiSlave { +impl SpiSlave { /// Converts from 8bit dataframe to 16bit. - pub fn frame_size_16bit(self) -> SpiSlave { + pub fn frame_size_16bit(self) -> SpiSlave { self.spi.cr1().modify(|_, w| w.spe().clear_bit()); self.spi.cr1().modify(|_, w| w.dff().set_bit()); self.spi.cr1().modify(|_, w| w.spe().set_bit()); @@ -712,9 +694,9 @@ impl SpiSlave { } } -impl Spi { +impl Spi { /// Converts from 16bit dataframe to 8bit. - pub fn frame_size_8bit(self) -> Spi { + pub fn frame_size_8bit(self) -> Spi { self.spi.cr1().modify(|_, w| w.spe().clear_bit()); self.spi.cr1().modify(|_, w| w.dff().clear_bit()); self.spi.cr1().modify(|_, w| w.spe().set_bit()); @@ -725,9 +707,9 @@ impl Spi { } } -impl SpiSlave { +impl SpiSlave { /// Converts from 16bit dataframe to 8bit. - pub fn frame_size_8bit(self) -> SpiSlave { + pub fn frame_size_8bit(self) -> SpiSlave { self.spi.cr1().modify(|_, w| w.spe().clear_bit()); self.spi.cr1().modify(|_, w| w.dff().clear_bit()); self.spi.cr1().modify(|_, w| w.spe().set_bit()); @@ -783,17 +765,14 @@ where // DMA -pub type SpiTxDma = TxDma, CHANNEL>; -pub type SpiRxDma = RxDma, CHANNEL>; -pub type SpiRxTxDma = - RxTxDma, RXCHANNEL, TXCHANNEL>; +pub type SpiTxDma = TxDma, CHANNEL>; +pub type SpiRxDma = RxDma, CHANNEL>; +pub type SpiRxTxDma = RxTxDma, RXCHANNEL, TXCHANNEL>; -pub type SpiSlaveTxDma = - TxDma, CHANNEL>; -pub type SpiSlaveRxDma = - RxDma, CHANNEL>; -pub type SpiSlaveRxTxDma = - RxTxDma, RXCHANNEL, TXCHANNEL>; +pub type SpiSlaveTxDma = TxDma, CHANNEL>; +pub type SpiSlaveRxDma = RxDma, CHANNEL>; +pub type SpiSlaveRxTxDma = + RxTxDma, RXCHANNEL, TXCHANNEL>; macro_rules! spi_dma { ( @@ -807,39 +786,39 @@ macro_rules! spi_dma { $slavetxdma:ident, $slaverxtxdma:ident ) => { - pub type $rxdma = SpiRxDma<$SPIi, $RCi, PULL>; - pub type $txdma = SpiTxDma<$SPIi, $TCi, PULL>; - pub type $rxtxdma = SpiRxTxDma<$SPIi, $RCi, $TCi, PULL>; + pub type $rxdma = SpiRxDma<$SPIi, $RCi>; + pub type $txdma = SpiTxDma<$SPIi, $TCi>; + pub type $rxtxdma = SpiRxTxDma<$SPIi, $RCi, $TCi>; - impl Transmit for SpiTxDma<$SPIi, $TCi, PULL> { + impl Transmit for SpiTxDma<$SPIi, $TCi> { type TxChannel = $TCi; type ReceivedWord = u8; } - impl Receive for SpiRxDma<$SPIi, $RCi, PULL> { + impl Receive for SpiRxDma<$SPIi, $RCi> { type RxChannel = $RCi; type TransmittedWord = u8; } - impl Transmit for SpiRxTxDma<$SPIi, $RCi, $TCi, PULL> { + impl Transmit for SpiRxTxDma<$SPIi, $RCi, $TCi> { type TxChannel = $TCi; type ReceivedWord = u8; } - impl Receive for SpiRxTxDma<$SPIi, $RCi, $TCi, PULL> { + impl Receive for SpiRxTxDma<$SPIi, $RCi, $TCi> { type RxChannel = $RCi; type TransmittedWord = u8; } - impl Spi<$SPIi, u8, PULL> { - pub fn with_tx_dma(self, channel: $TCi) -> SpiTxDma<$SPIi, $TCi, PULL> { + impl Spi<$SPIi, u8> { + pub fn with_tx_dma(self, channel: $TCi) -> SpiTxDma<$SPIi, $TCi> { self.spi.cr2().modify(|_, w| w.txdmaen().set_bit()); SpiTxDma { payload: self, channel, } } - pub fn with_rx_dma(self, channel: $RCi) -> SpiRxDma<$SPIi, $RCi, PULL> { + pub fn with_rx_dma(self, channel: $RCi) -> SpiRxDma<$SPIi, $RCi> { self.spi.cr2().modify(|_, w| w.rxdmaen().set_bit()); SpiRxDma { payload: self, @@ -850,7 +829,7 @@ macro_rules! spi_dma { self, rxchannel: $RCi, txchannel: $TCi, - ) -> SpiRxTxDma<$SPIi, $RCi, $TCi, PULL> { + ) -> SpiRxTxDma<$SPIi, $RCi, $TCi> { self.spi .cr2() .modify(|_, w| w.rxdmaen().set_bit().txdmaen().set_bit()); @@ -862,24 +841,24 @@ macro_rules! spi_dma { } } - impl SpiTxDma<$SPIi, $TCi, PULL> { - pub fn release(self) -> (Spi<$SPIi, u8, PULL>, $TCi) { + impl SpiTxDma<$SPIi, $TCi> { + pub fn release(self) -> (Spi<$SPIi, u8>, $TCi) { let SpiTxDma { payload, channel } = self; payload.spi.cr2().modify(|_, w| w.txdmaen().clear_bit()); (payload, channel) } } - impl SpiRxDma<$SPIi, $RCi, PULL> { - pub fn release(self) -> (Spi<$SPIi, u8, PULL>, $RCi) { + impl SpiRxDma<$SPIi, $RCi> { + pub fn release(self) -> (Spi<$SPIi, u8>, $RCi) { let SpiRxDma { payload, channel } = self; payload.spi.cr2().modify(|_, w| w.rxdmaen().clear_bit()); (payload, channel) } } - impl SpiRxTxDma<$SPIi, $RCi, $TCi, PULL> { - pub fn release(self) -> (Spi<$SPIi, u8, PULL>, $RCi, $TCi) { + impl SpiRxTxDma<$SPIi, $RCi, $TCi> { + pub fn release(self) -> (Spi<$SPIi, u8>, $RCi, $TCi) { let SpiRxTxDma { payload, rxchannel, @@ -893,7 +872,7 @@ macro_rules! spi_dma { } } - impl TransferPayload for SpiTxDma<$SPIi, $TCi, PULL> { + impl TransferPayload for SpiTxDma<$SPIi, $TCi> { fn start(&mut self) { self.channel.start(); } @@ -902,7 +881,7 @@ macro_rules! spi_dma { } } - impl TransferPayload for SpiRxDma<$SPIi, $RCi, PULL> { + impl TransferPayload for SpiRxDma<$SPIi, $RCi> { fn start(&mut self) { self.channel.start(); } @@ -911,7 +890,7 @@ macro_rules! spi_dma { } } - impl TransferPayload for SpiRxTxDma<$SPIi, $RCi, $TCi, PULL> { + impl TransferPayload for SpiRxTxDma<$SPIi, $RCi, $TCi> { fn start(&mut self) { self.rxchannel.start(); self.txchannel.start(); @@ -922,7 +901,7 @@ macro_rules! spi_dma { } } - impl crate::dma::ReadDma for SpiRxDma<$SPIi, $RCi, PULL> + impl crate::dma::ReadDma for SpiRxDma<$SPIi, $RCi> where B: WriteBuffer, { @@ -958,7 +937,7 @@ macro_rules! spi_dma { } } - impl crate::dma::WriteDma for SpiTxDma<$SPIi, $TCi, PULL> + impl crate::dma::WriteDma for SpiTxDma<$SPIi, $TCi> where B: ReadBuffer, { @@ -994,8 +973,7 @@ macro_rules! spi_dma { } } - impl crate::dma::ReadWriteDma - for SpiRxTxDma<$SPIi, $RCi, $TCi, PULL> + impl crate::dma::ReadWriteDma for SpiRxTxDma<$SPIi, $RCi, $TCi> where RXB: WriteBuffer, TXB: ReadBuffer, @@ -1063,42 +1041,39 @@ macro_rules! spi_dma { } } - pub type $slaverxdma = - SpiSlaveRxDma<$SPIi, $RCi, Otype, PULL>; - pub type $slavetxdma = - SpiSlaveTxDma<$SPIi, $TCi, Otype, PULL>; - pub type $slaverxtxdma = - SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype, PULL>; + pub type $slaverxdma = SpiSlaveRxDma<$SPIi, $RCi, Otype>; + pub type $slavetxdma = SpiSlaveTxDma<$SPIi, $TCi, Otype>; + pub type $slaverxtxdma = SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype>; - impl Transmit for SpiSlaveTxDma<$SPIi, $TCi, Otype, PULL> { + impl Transmit for SpiSlaveTxDma<$SPIi, $TCi, Otype> { type TxChannel = $TCi; type ReceivedWord = u8; } - impl Receive for SpiSlaveRxDma<$SPIi, $RCi, Otype, PULL> { + impl Receive for SpiSlaveRxDma<$SPIi, $RCi, Otype> { type RxChannel = $RCi; type TransmittedWord = u8; } - impl Transmit for SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype, PULL> { + impl Transmit for SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype> { type TxChannel = $TCi; type ReceivedWord = u8; } - impl Receive for SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype, PULL> { + impl Receive for SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype> { type RxChannel = $RCi; type TransmittedWord = u8; } - impl SpiSlave<$SPIi, u8, Otype, PULL> { - pub fn with_tx_dma(self, channel: $TCi) -> SpiSlaveTxDma<$SPIi, $TCi, Otype, PULL> { + impl SpiSlave<$SPIi, u8, Otype> { + pub fn with_tx_dma(self, channel: $TCi) -> SpiSlaveTxDma<$SPIi, $TCi, Otype> { self.spi.cr2().modify(|_, w| w.txdmaen().set_bit()); SpiSlaveTxDma { payload: self, channel, } } - pub fn with_rx_dma(self, channel: $RCi) -> SpiSlaveRxDma<$SPIi, $RCi, Otype, PULL> { + pub fn with_rx_dma(self, channel: $RCi) -> SpiSlaveRxDma<$SPIi, $RCi, Otype> { self.spi.cr2().modify(|_, w| w.rxdmaen().set_bit()); SpiSlaveRxDma { payload: self, @@ -1109,7 +1084,7 @@ macro_rules! spi_dma { self, rxchannel: $RCi, txchannel: $TCi, - ) -> SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype, PULL> { + ) -> SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype> { self.spi .cr2() .modify(|_, w| w.rxdmaen().set_bit().txdmaen().set_bit()); @@ -1121,24 +1096,24 @@ macro_rules! spi_dma { } } - impl SpiSlaveTxDma<$SPIi, $TCi, Otype, PULL> { - pub fn release(self) -> (SpiSlave<$SPIi, u8, Otype, PULL>, $TCi) { + impl SpiSlaveTxDma<$SPIi, $TCi, Otype> { + pub fn release(self) -> (SpiSlave<$SPIi, u8, Otype>, $TCi) { let SpiSlaveTxDma { payload, channel } = self; payload.spi.cr2().modify(|_, w| w.txdmaen().clear_bit()); (payload, channel) } } - impl SpiSlaveRxDma<$SPIi, $RCi, Otype, PULL> { - pub fn release(self) -> (SpiSlave<$SPIi, u8, Otype, PULL>, $RCi) { + impl SpiSlaveRxDma<$SPIi, $RCi, Otype> { + pub fn release(self) -> (SpiSlave<$SPIi, u8, Otype>, $RCi) { let SpiSlaveRxDma { payload, channel } = self; payload.spi.cr2().modify(|_, w| w.rxdmaen().clear_bit()); (payload, channel) } } - impl SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype, PULL> { - pub fn release(self) -> (SpiSlave<$SPIi, u8, Otype, PULL>, $RCi, $TCi) { + impl SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype> { + pub fn release(self) -> (SpiSlave<$SPIi, u8, Otype>, $RCi, $TCi) { let SpiSlaveRxTxDma { payload, rxchannel, @@ -1152,7 +1127,7 @@ macro_rules! spi_dma { } } - impl TransferPayload for SpiSlaveTxDma<$SPIi, $TCi, Otype, PULL> { + impl TransferPayload for SpiSlaveTxDma<$SPIi, $TCi, Otype> { fn start(&mut self) { self.channel.start(); } @@ -1161,7 +1136,7 @@ macro_rules! spi_dma { } } - impl TransferPayload for SpiSlaveRxDma<$SPIi, $RCi, Otype, PULL> { + impl TransferPayload for SpiSlaveRxDma<$SPIi, $RCi, Otype> { fn start(&mut self) { self.channel.start(); } @@ -1170,7 +1145,7 @@ macro_rules! spi_dma { } } - impl TransferPayload for SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype, PULL> { + impl TransferPayload for SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype> { fn start(&mut self) { self.rxchannel.start(); self.txchannel.start(); @@ -1181,7 +1156,7 @@ macro_rules! spi_dma { } } - impl crate::dma::ReadDma for SpiSlaveRxDma<$SPIi, $RCi, Otype, PULL> + impl crate::dma::ReadDma for SpiSlaveRxDma<$SPIi, $RCi, Otype> where B: WriteBuffer, { @@ -1217,7 +1192,7 @@ macro_rules! spi_dma { } } - impl crate::dma::WriteDma for SpiSlaveTxDma<$SPIi, $TCi, Otype, PULL> + impl crate::dma::WriteDma for SpiSlaveTxDma<$SPIi, $TCi, Otype> where B: ReadBuffer, { @@ -1253,8 +1228,8 @@ macro_rules! spi_dma { } } - impl crate::dma::ReadWriteDma - for SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype, PULL> + impl crate::dma::ReadWriteDma + for SpiSlaveRxTxDma<$SPIi, $RCi, $TCi, Otype> where RXB: WriteBuffer, TXB: ReadBuffer, diff --git a/src/spi/hal_02.rs b/src/spi/hal_02.rs index 2e410153..bb346efc 100644 --- a/src/spi/hal_02.rs +++ b/src/spi/hal_02.rs @@ -30,7 +30,7 @@ impl From for super::Mode { } } -impl spi::FullDuplex for Spi +impl spi::FullDuplex for Spi where SPI: Instance, W: Copy, @@ -46,14 +46,14 @@ where } } -impl blocking::transfer::Default for Spi +impl blocking::transfer::Default for Spi where SPI: Instance, W: Copy, { } -impl blocking::Write for Spi { +impl blocking::Write for Spi { type Error = Error; fn write(&mut self, words: &[u8]) -> Result<(), Error> { @@ -61,7 +61,7 @@ impl blocking::Write for Spi { } } -impl blocking::Write for Spi { +impl blocking::Write for Spi { type Error = Error; fn write(&mut self, words: &[u16]) -> Result<(), Error> { diff --git a/src/spi/hal_1.rs b/src/spi/hal_1.rs index f038ac72..633fde11 100644 --- a/src/spi/hal_1.rs +++ b/src/spi/hal_1.rs @@ -38,7 +38,7 @@ impl embedded_hal::spi::Error for Error { } } -impl ErrorType for Spi { +impl ErrorType for Spi { type Error = Error; } @@ -46,7 +46,7 @@ mod nb { use super::{Error, Instance, Spi}; use embedded_hal_nb::spi::FullDuplex; - impl FullDuplex for Spi + impl FullDuplex for Spi where SPI: Instance, W: Copy, @@ -66,7 +66,7 @@ mod blocking { use core::ops::DerefMut; use embedded_hal::spi::SpiBus; - impl SpiBus for Spi + impl SpiBus for Spi where SPI: Instance, W: Copy + 'static, diff --git a/src/timer/pwm_input.rs b/src/timer/pwm_input.rs index 78bb7c42..fef296b8 100644 --- a/src/timer/pwm_input.rs +++ b/src/timer/pwm_input.rs @@ -16,11 +16,11 @@ pub trait Pins {} use super::pins::{sealed::Remap, CPin}; -impl Pins for (P1, P2) +impl Pins for (P1, P2) where REMAP: Remap, - P1: CPin + gpio::PinExt>, - P2: CPin + gpio::PinExt>, + P1: CPin + gpio::PinExt, + P2: CPin + gpio::PinExt, { } diff --git a/src/usb.rs b/src/usb.rs index f86d408a..d0a6d6c4 100644 --- a/src/usb.rs +++ b/src/usb.rs @@ -9,13 +9,13 @@ use crate::rcc::{Enable, Reset}; use stm32_usbd::UsbPeripheral; use crate::gpio::gpioa::{PA11, PA12}; -use crate::gpio::{Floating, Input}; +use crate::gpio::Input; pub use stm32_usbd::UsbBus; pub struct Peripheral { pub usb: USB, - pub pin_dm: PA11>, - pub pin_dp: PA12>, + pub pin_dm: PA11, + pub pin_dp: PA12, } unsafe impl Sync for Peripheral {}