diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-03-26 16:01:37 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-03-27 15:18:06 +0100 |
| commit | d41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch) | |
| tree | 678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-stm32/src | |
| parent | 9edf5b7f049f95742b60b041e4443967d8a6b708 (diff) | |
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-stm32/src')
75 files changed, 1207 insertions, 1455 deletions
diff --git a/embassy-stm32/src/adc/c0.rs b/embassy-stm32/src/adc/c0.rs index 84763ad4f..a9c1d8faf 100644 --- a/embassy-stm32/src/adc/c0.rs +++ b/embassy-stm32/src/adc/c0.rs | |||
| @@ -8,7 +8,7 @@ use super::{ | |||
| 8 | }; | 8 | }; |
| 9 | use crate::dma::Transfer; | 9 | use crate::dma::Transfer; |
| 10 | use crate::time::Hertz; | 10 | use crate::time::Hertz; |
| 11 | use crate::{pac, rcc, Peripheral}; | 11 | use crate::{pac, rcc, Peri}; |
| 12 | 12 | ||
| 13 | /// Default VREF voltage used for sample conversion to millivolts. | 13 | /// Default VREF voltage used for sample conversion to millivolts. |
| 14 | pub const VREF_DEFAULT_MV: u32 = 3300; | 14 | pub const VREF_DEFAULT_MV: u32 = 3300; |
| @@ -154,8 +154,7 @@ pub enum Averaging { | |||
| 154 | 154 | ||
| 155 | impl<'d, T: Instance> Adc<'d, T> { | 155 | impl<'d, T: Instance> Adc<'d, T> { |
| 156 | /// Create a new ADC driver. | 156 | /// Create a new ADC driver. |
| 157 | pub fn new(adc: impl Peripheral<P = T> + 'd, sample_time: SampleTime, resolution: Resolution) -> Self { | 157 | pub fn new(adc: Peri<'d, T>, sample_time: SampleTime, resolution: Resolution) -> Self { |
| 158 | embassy_hal_internal::into_ref!(adc); | ||
| 159 | rcc::enable_and_reset::<T>(); | 158 | rcc::enable_and_reset::<T>(); |
| 160 | 159 | ||
| 161 | T::regs().cfgr2().modify(|w| w.set_ckmode(Ckmode::SYSCLK)); | 160 | T::regs().cfgr2().modify(|w| w.set_ckmode(Ckmode::SYSCLK)); |
| @@ -319,7 +318,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 319 | Self::apply_channel_conf() | 318 | Self::apply_channel_conf() |
| 320 | } | 319 | } |
| 321 | 320 | ||
| 322 | async fn dma_convert(&mut self, rx_dma: &mut impl RxDma<T>, readings: &mut [u16]) { | 321 | async fn dma_convert(&mut self, rx_dma: Peri<'_, impl RxDma<T>>, readings: &mut [u16]) { |
| 323 | // Enable overrun control, so no new DMA requests will be generated until | 322 | // Enable overrun control, so no new DMA requests will be generated until |
| 324 | // previous DR values is read. | 323 | // previous DR values is read. |
| 325 | T::regs().isr().modify(|reg| { | 324 | T::regs().isr().modify(|reg| { |
| @@ -374,7 +373,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 374 | /// TODO(chudsaviet): externalize generic code and merge with read(). | 373 | /// TODO(chudsaviet): externalize generic code and merge with read(). |
| 375 | pub async fn read_in_hw_order( | 374 | pub async fn read_in_hw_order( |
| 376 | &mut self, | 375 | &mut self, |
| 377 | rx_dma: &mut impl RxDma<T>, | 376 | rx_dma: Peri<'_, impl RxDma<T>>, |
| 378 | hw_channel_selection: u32, | 377 | hw_channel_selection: u32, |
| 379 | scandir: Scandir, | 378 | scandir: Scandir, |
| 380 | readings: &mut [u16], | 379 | readings: &mut [u16], |
| @@ -415,7 +414,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 415 | // For other channels, use `read_in_hw_order()` or blocking read. | 414 | // For other channels, use `read_in_hw_order()` or blocking read. |
| 416 | pub async fn read( | 415 | pub async fn read( |
| 417 | &mut self, | 416 | &mut self, |
| 418 | rx_dma: &mut impl RxDma<T>, | 417 | rx_dma: Peri<'_, impl RxDma<T>>, |
| 419 | channel_sequence: impl ExactSizeIterator<Item = &mut AnyAdcChannel<T>>, | 418 | channel_sequence: impl ExactSizeIterator<Item = &mut AnyAdcChannel<T>>, |
| 420 | readings: &mut [u16], | 419 | readings: &mut [u16], |
| 421 | ) { | 420 | ) { |
diff --git a/embassy-stm32/src/adc/f1.rs b/embassy-stm32/src/adc/f1.rs index b37ec260f..fa6255c23 100644 --- a/embassy-stm32/src/adc/f1.rs +++ b/embassy-stm32/src/adc/f1.rs | |||
| @@ -2,12 +2,10 @@ use core::future::poll_fn; | |||
| 2 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 3 | use core::task::Poll; | 3 | use core::task::Poll; |
| 4 | 4 | ||
| 5 | use embassy_hal_internal::into_ref; | ||
| 6 | |||
| 7 | use super::blocking_delay_us; | 5 | use super::blocking_delay_us; |
| 8 | use crate::adc::{Adc, AdcChannel, Instance, SampleTime}; | 6 | use crate::adc::{Adc, AdcChannel, Instance, SampleTime}; |
| 9 | use crate::time::Hertz; | 7 | use crate::time::Hertz; |
| 10 | use crate::{interrupt, rcc, Peripheral}; | 8 | use crate::{interrupt, rcc, Peri}; |
| 11 | 9 | ||
| 12 | pub const VDDA_CALIB_MV: u32 = 3300; | 10 | pub const VDDA_CALIB_MV: u32 = 3300; |
| 13 | pub const ADC_MAX: u32 = (1 << 12) - 1; | 11 | pub const ADC_MAX: u32 = (1 << 12) - 1; |
| @@ -48,8 +46,7 @@ impl<T: Instance> super::SealedAdcChannel<T> for Temperature { | |||
| 48 | } | 46 | } |
| 49 | 47 | ||
| 50 | impl<'d, T: Instance> Adc<'d, T> { | 48 | impl<'d, T: Instance> Adc<'d, T> { |
| 51 | pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self { | 49 | pub fn new(adc: Peri<'d, T>) -> Self { |
| 52 | into_ref!(adc); | ||
| 53 | rcc::enable_and_reset::<T>(); | 50 | rcc::enable_and_reset::<T>(); |
| 54 | T::regs().cr2().modify(|reg| reg.set_adon(true)); | 51 | T::regs().cr2().modify(|reg| reg.set_adon(true)); |
| 55 | 52 | ||
diff --git a/embassy-stm32/src/adc/f3.rs b/embassy-stm32/src/adc/f3.rs index 0ebeb8a9e..3aeb6f2c7 100644 --- a/embassy-stm32/src/adc/f3.rs +++ b/embassy-stm32/src/adc/f3.rs | |||
| @@ -2,13 +2,11 @@ use core::future::poll_fn; | |||
| 2 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 3 | use core::task::Poll; | 3 | use core::task::Poll; |
| 4 | 4 | ||
| 5 | use embassy_hal_internal::into_ref; | ||
| 6 | |||
| 7 | use super::blocking_delay_us; | 5 | use super::blocking_delay_us; |
| 8 | use crate::adc::{Adc, AdcChannel, Instance, SampleTime}; | 6 | use crate::adc::{Adc, AdcChannel, Instance, SampleTime}; |
| 9 | use crate::interrupt::typelevel::Interrupt; | 7 | use crate::interrupt::typelevel::Interrupt; |
| 10 | use crate::time::Hertz; | 8 | use crate::time::Hertz; |
| 11 | use crate::{interrupt, rcc, Peripheral}; | 9 | use crate::{interrupt, rcc, Peri}; |
| 12 | 10 | ||
| 13 | pub const VDDA_CALIB_MV: u32 = 3300; | 11 | pub const VDDA_CALIB_MV: u32 = 3300; |
| 14 | pub const ADC_MAX: u32 = (1 << 12) - 1; | 12 | pub const ADC_MAX: u32 = (1 << 12) - 1; |
| @@ -56,13 +54,11 @@ impl<T: Instance> super::SealedAdcChannel<T> for Temperature { | |||
| 56 | 54 | ||
| 57 | impl<'d, T: Instance> Adc<'d, T> { | 55 | impl<'d, T: Instance> Adc<'d, T> { |
| 58 | pub fn new( | 56 | pub fn new( |
| 59 | adc: impl Peripheral<P = T> + 'd, | 57 | adc: Peri<'d, T>, |
| 60 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 58 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 61 | ) -> Self { | 59 | ) -> Self { |
| 62 | use crate::pac::adc::vals; | 60 | use crate::pac::adc::vals; |
| 63 | 61 | ||
| 64 | into_ref!(adc); | ||
| 65 | |||
| 66 | rcc::enable_and_reset::<T>(); | 62 | rcc::enable_and_reset::<T>(); |
| 67 | 63 | ||
| 68 | // Enable the adc regulator | 64 | // Enable the adc regulator |
diff --git a/embassy-stm32/src/adc/f3_v1_1.rs b/embassy-stm32/src/adc/f3_v1_1.rs index 291a3861e..944e971bb 100644 --- a/embassy-stm32/src/adc/f3_v1_1.rs +++ b/embassy-stm32/src/adc/f3_v1_1.rs | |||
| @@ -3,14 +3,13 @@ use core::marker::PhantomData; | |||
| 3 | use core::task::Poll; | 3 | use core::task::Poll; |
| 4 | 4 | ||
| 5 | use embassy_futures::yield_now; | 5 | use embassy_futures::yield_now; |
| 6 | use embassy_hal_internal::into_ref; | ||
| 7 | use embassy_time::Instant; | 6 | use embassy_time::Instant; |
| 8 | 7 | ||
| 9 | use super::Resolution; | 8 | use super::Resolution; |
| 10 | use crate::adc::{Adc, AdcChannel, Instance, SampleTime}; | 9 | use crate::adc::{Adc, AdcChannel, Instance, SampleTime}; |
| 11 | use crate::interrupt::typelevel::Interrupt; | 10 | use crate::interrupt::typelevel::Interrupt; |
| 12 | use crate::time::Hertz; | 11 | use crate::time::Hertz; |
| 13 | use crate::{interrupt, rcc, Peripheral}; | 12 | use crate::{interrupt, rcc, Peri}; |
| 14 | 13 | ||
| 15 | const ADC_FREQ: Hertz = crate::rcc::HSI_FREQ; | 14 | const ADC_FREQ: Hertz = crate::rcc::HSI_FREQ; |
| 16 | 15 | ||
| @@ -138,11 +137,9 @@ impl<T: Instance> Drop for Temperature<T> { | |||
| 138 | 137 | ||
| 139 | impl<'d, T: Instance> Adc<'d, T> { | 138 | impl<'d, T: Instance> Adc<'d, T> { |
| 140 | pub fn new( | 139 | pub fn new( |
| 141 | adc: impl Peripheral<P = T> + 'd, | 140 | adc: Peri<'d, T>, |
| 142 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 141 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 143 | ) -> Self { | 142 | ) -> Self { |
| 144 | into_ref!(adc); | ||
| 145 | |||
| 146 | rcc::enable_and_reset::<T>(); | 143 | rcc::enable_and_reset::<T>(); |
| 147 | 144 | ||
| 148 | //let r = T::regs(); | 145 | //let r = T::regs(); |
diff --git a/embassy-stm32/src/adc/g4.rs b/embassy-stm32/src/adc/g4.rs index 0291ef4de..6a00e788e 100644 --- a/embassy-stm32/src/adc/g4.rs +++ b/embassy-stm32/src/adc/g4.rs | |||
| @@ -11,7 +11,7 @@ use super::{blocking_delay_us, Adc, AdcChannel, AnyAdcChannel, Instance, Resolut | |||
| 11 | use crate::adc::SealedAdcChannel; | 11 | use crate::adc::SealedAdcChannel; |
| 12 | use crate::dma::Transfer; | 12 | use crate::dma::Transfer; |
| 13 | use crate::time::Hertz; | 13 | use crate::time::Hertz; |
| 14 | use crate::{pac, rcc, Peripheral}; | 14 | use crate::{pac, rcc, Peri}; |
| 15 | 15 | ||
| 16 | /// Default VREF voltage used for sample conversion to millivolts. | 16 | /// Default VREF voltage used for sample conversion to millivolts. |
| 17 | pub const VREF_DEFAULT_MV: u32 = 3300; | 17 | pub const VREF_DEFAULT_MV: u32 = 3300; |
| @@ -135,8 +135,7 @@ impl Prescaler { | |||
| 135 | 135 | ||
| 136 | impl<'d, T: Instance> Adc<'d, T> { | 136 | impl<'d, T: Instance> Adc<'d, T> { |
| 137 | /// Create a new ADC driver. | 137 | /// Create a new ADC driver. |
| 138 | pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self { | 138 | pub fn new(adc: Peri<'d, T>) -> Self { |
| 139 | embassy_hal_internal::into_ref!(adc); | ||
| 140 | rcc::enable_and_reset::<T>(); | 139 | rcc::enable_and_reset::<T>(); |
| 141 | 140 | ||
| 142 | let prescaler = Prescaler::from_ker_ck(T::frequency()); | 141 | let prescaler = Prescaler::from_ker_ck(T::frequency()); |
| @@ -364,8 +363,8 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 364 | /// use embassy_stm32::adc::{Adc, AdcChannel} | 363 | /// use embassy_stm32::adc::{Adc, AdcChannel} |
| 365 | /// | 364 | /// |
| 366 | /// let mut adc = Adc::new(p.ADC1); | 365 | /// let mut adc = Adc::new(p.ADC1); |
| 367 | /// let mut adc_pin0 = p.PA0.degrade_adc(); | 366 | /// let mut adc_pin0 = p.PA0.into(); |
| 368 | /// let mut adc_pin1 = p.PA1.degrade_adc(); | 367 | /// let mut adc_pin1 = p.PA1.into(); |
| 369 | /// let mut measurements = [0u16; 2]; | 368 | /// let mut measurements = [0u16; 2]; |
| 370 | /// | 369 | /// |
| 371 | /// adc.read_async( | 370 | /// adc.read_async( |
| @@ -382,7 +381,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 382 | /// ``` | 381 | /// ``` |
| 383 | pub async fn read( | 382 | pub async fn read( |
| 384 | &mut self, | 383 | &mut self, |
| 385 | rx_dma: &mut impl RxDma<T>, | 384 | rx_dma: Peri<'_, impl RxDma<T>>, |
| 386 | sequence: impl ExactSizeIterator<Item = (&mut AnyAdcChannel<T>, SampleTime)>, | 385 | sequence: impl ExactSizeIterator<Item = (&mut AnyAdcChannel<T>, SampleTime)>, |
| 387 | readings: &mut [u16], | 386 | readings: &mut [u16], |
| 388 | ) { | 387 | ) { |
diff --git a/embassy-stm32/src/adc/mod.rs b/embassy-stm32/src/adc/mod.rs index 31a08b6eb..321db7431 100644 --- a/embassy-stm32/src/adc/mod.rs +++ b/embassy-stm32/src/adc/mod.rs | |||
| @@ -22,6 +22,7 @@ use core::marker::PhantomData; | |||
| 22 | #[allow(unused)] | 22 | #[allow(unused)] |
| 23 | #[cfg(not(any(adc_f3_v2)))] | 23 | #[cfg(not(any(adc_f3_v2)))] |
| 24 | pub use _version::*; | 24 | pub use _version::*; |
| 25 | use embassy_hal_internal::{impl_peripheral, PeripheralType}; | ||
| 25 | #[cfg(any(adc_f1, adc_f3, adc_v1, adc_l0, adc_f3_v1_1))] | 26 | #[cfg(any(adc_f1, adc_f3, adc_v1, adc_l0, adc_f3_v1_1))] |
| 26 | use embassy_sync::waitqueue::AtomicWaker; | 27 | use embassy_sync::waitqueue::AtomicWaker; |
| 27 | 28 | ||
| @@ -42,7 +43,7 @@ dma_trait!(RxDma4, adc4::Instance); | |||
| 42 | /// Analog to Digital driver. | 43 | /// Analog to Digital driver. |
| 43 | pub struct Adc<'d, T: Instance> { | 44 | pub struct Adc<'d, T: Instance> { |
| 44 | #[allow(unused)] | 45 | #[allow(unused)] |
| 45 | adc: crate::PeripheralRef<'d, T>, | 46 | adc: crate::Peri<'d, T>, |
| 46 | #[cfg(not(any(adc_f3_v2, adc_f3_v1_1)))] | 47 | #[cfg(not(any(adc_f3_v2, adc_f3_v1_1)))] |
| 47 | sample_time: SampleTime, | 48 | sample_time: SampleTime, |
| 48 | } | 49 | } |
| @@ -111,7 +112,7 @@ pub(crate) fn blocking_delay_us(us: u32) { | |||
| 111 | adc_c0 | 112 | adc_c0 |
| 112 | )))] | 113 | )))] |
| 113 | #[allow(private_bounds)] | 114 | #[allow(private_bounds)] |
| 114 | pub trait Instance: SealedInstance + crate::Peripheral<P = Self> { | 115 | pub trait Instance: SealedInstance + crate::PeripheralType { |
| 115 | type Interrupt: crate::interrupt::typelevel::Interrupt; | 116 | type Interrupt: crate::interrupt::typelevel::Interrupt; |
| 116 | } | 117 | } |
| 117 | /// ADC instance. | 118 | /// ADC instance. |
| @@ -132,7 +133,7 @@ pub trait Instance: SealedInstance + crate::Peripheral<P = Self> { | |||
| 132 | adc_c0 | 133 | adc_c0 |
| 133 | ))] | 134 | ))] |
| 134 | #[allow(private_bounds)] | 135 | #[allow(private_bounds)] |
| 135 | pub trait Instance: SealedInstance + crate::Peripheral<P = Self> + crate::rcc::RccPeripheral { | 136 | pub trait Instance: SealedInstance + crate::PeripheralType + crate::rcc::RccPeripheral { |
| 136 | type Interrupt: crate::interrupt::typelevel::Interrupt; | 137 | type Interrupt: crate::interrupt::typelevel::Interrupt; |
| 137 | } | 138 | } |
| 138 | 139 | ||
| @@ -159,7 +160,7 @@ pub struct AnyAdcChannel<T> { | |||
| 159 | channel: u8, | 160 | channel: u8, |
| 160 | _phantom: PhantomData<T>, | 161 | _phantom: PhantomData<T>, |
| 161 | } | 162 | } |
| 162 | 163 | impl_peripheral!(AnyAdcChannel<T: Instance>); | |
| 163 | impl<T: Instance> AdcChannel<T> for AnyAdcChannel<T> {} | 164 | impl<T: Instance> AdcChannel<T> for AnyAdcChannel<T> {} |
| 164 | impl<T: Instance> SealedAdcChannel<T> for AnyAdcChannel<T> { | 165 | impl<T: Instance> SealedAdcChannel<T> for AnyAdcChannel<T> { |
| 165 | fn channel(&self) -> u8 { | 166 | fn channel(&self) -> u8 { |
| @@ -233,11 +234,11 @@ foreach_adc!( | |||
| 233 | 234 | ||
| 234 | macro_rules! impl_adc_pin { | 235 | macro_rules! impl_adc_pin { |
| 235 | ($inst:ident, $pin:ident, $ch:expr) => { | 236 | ($inst:ident, $pin:ident, $ch:expr) => { |
| 236 | impl crate::adc::AdcChannel<peripherals::$inst> for crate::peripherals::$pin {} | 237 | impl crate::adc::AdcChannel<peripherals::$inst> for crate::Peri<'_, crate::peripherals::$pin> {} |
| 237 | impl crate::adc::SealedAdcChannel<peripherals::$inst> for crate::peripherals::$pin { | 238 | impl crate::adc::SealedAdcChannel<peripherals::$inst> for crate::Peri<'_, crate::peripherals::$pin> { |
| 238 | #[cfg(any(adc_v1, adc_c0, adc_l0, adc_v2, adc_g4, adc_v4, adc_u5))] | 239 | #[cfg(any(adc_v1, adc_c0, adc_l0, adc_v2, adc_g4, adc_v4, adc_u5))] |
| 239 | fn setup(&mut self) { | 240 | fn setup(&mut self) { |
| 240 | <Self as crate::gpio::SealedPin>::set_as_analog(self); | 241 | <crate::peripherals::$pin as crate::gpio::SealedPin>::set_as_analog(self); |
| 241 | } | 242 | } |
| 242 | 243 | ||
| 243 | fn channel(&self) -> u8 { | 244 | fn channel(&self) -> u8 { |
diff --git a/embassy-stm32/src/adc/ringbuffered_v2.rs b/embassy-stm32/src/adc/ringbuffered_v2.rs index f3d1ca0ab..fabf0284b 100644 --- a/embassy-stm32/src/adc/ringbuffered_v2.rs +++ b/embassy-stm32/src/adc/ringbuffered_v2.rs | |||
| @@ -2,13 +2,12 @@ use core::marker::PhantomData; | |||
| 2 | use core::mem; | 2 | use core::mem; |
| 3 | use core::sync::atomic::{compiler_fence, Ordering}; | 3 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 4 | 4 | ||
| 5 | use embassy_hal_internal::{into_ref, Peripheral}; | ||
| 6 | use stm32_metapac::adc::vals::SampleTime; | 5 | use stm32_metapac::adc::vals::SampleTime; |
| 7 | 6 | ||
| 8 | use crate::adc::{Adc, AdcChannel, Instance, RxDma}; | 7 | use crate::adc::{Adc, AdcChannel, Instance, RxDma}; |
| 9 | use crate::dma::{Priority, ReadableRingBuffer, TransferOptions}; | 8 | use crate::dma::{Priority, ReadableRingBuffer, TransferOptions}; |
| 10 | use crate::pac::adc::vals; | 9 | use crate::pac::adc::vals; |
| 11 | use crate::rcc; | 10 | use crate::{rcc, Peri}; |
| 12 | 11 | ||
| 13 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 12 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 14 | pub struct OverrunError; | 13 | pub struct OverrunError; |
| @@ -103,13 +102,8 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 103 | /// It is critical to call `read` frequently to prevent DMA buffer overrun. | 102 | /// It is critical to call `read` frequently to prevent DMA buffer overrun. |
| 104 | /// | 103 | /// |
| 105 | /// [`read`]: #method.read | 104 | /// [`read`]: #method.read |
| 106 | pub fn into_ring_buffered( | 105 | pub fn into_ring_buffered(self, dma: Peri<'d, impl RxDma<T>>, dma_buf: &'d mut [u16]) -> RingBufferedAdc<'d, T> { |
| 107 | self, | ||
| 108 | dma: impl Peripheral<P = impl RxDma<T>> + 'd, | ||
| 109 | dma_buf: &'d mut [u16], | ||
| 110 | ) -> RingBufferedAdc<'d, T> { | ||
| 111 | assert!(!dma_buf.is_empty() && dma_buf.len() <= 0xFFFF); | 106 | assert!(!dma_buf.is_empty() && dma_buf.len() <= 0xFFFF); |
| 112 | into_ref!(dma); | ||
| 113 | 107 | ||
| 114 | let opts: crate::dma::TransferOptions = TransferOptions { | 108 | let opts: crate::dma::TransferOptions = TransferOptions { |
| 115 | half_transfer_ir: true, | 109 | half_transfer_ir: true, |
diff --git a/embassy-stm32/src/adc/u5_adc4.rs b/embassy-stm32/src/adc/u5_adc4.rs index cec88d482..a5cfbfdcf 100644 --- a/embassy-stm32/src/adc/u5_adc4.rs +++ b/embassy-stm32/src/adc/u5_adc4.rs | |||
| @@ -6,7 +6,7 @@ use crate::dma::Transfer; | |||
| 6 | pub use crate::pac::adc::regs::Adc4Chselrmod0; | 6 | pub use crate::pac::adc::regs::Adc4Chselrmod0; |
| 7 | pub use crate::pac::adc::vals::{Adc4Presc as Presc, Adc4Res as Resolution, Adc4SampleTime as SampleTime}; | 7 | pub use crate::pac::adc::vals::{Adc4Presc as Presc, Adc4Res as Resolution, Adc4SampleTime as SampleTime}; |
| 8 | use crate::time::Hertz; | 8 | use crate::time::Hertz; |
| 9 | use crate::{pac, rcc, Peripheral}; | 9 | use crate::{pac, rcc, Peri}; |
| 10 | 10 | ||
| 11 | const MAX_ADC_CLK_FREQ: Hertz = Hertz::mhz(55); | 11 | const MAX_ADC_CLK_FREQ: Hertz = Hertz::mhz(55); |
| 12 | 12 | ||
| @@ -169,13 +169,13 @@ pub trait SealedInstance { | |||
| 169 | fn regs() -> crate::pac::adc::Adc4; | 169 | fn regs() -> crate::pac::adc::Adc4; |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | pub trait Instance: SealedInstance + crate::Peripheral<P = Self> + crate::rcc::RccPeripheral { | 172 | pub trait Instance: SealedInstance + crate::PeripheralType + crate::rcc::RccPeripheral { |
| 173 | type Interrupt: crate::interrupt::typelevel::Interrupt; | 173 | type Interrupt: crate::interrupt::typelevel::Interrupt; |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | pub struct Adc4<'d, T: Instance> { | 176 | pub struct Adc4<'d, T: Instance> { |
| 177 | #[allow(unused)] | 177 | #[allow(unused)] |
| 178 | adc: crate::PeripheralRef<'d, T>, | 178 | adc: crate::Peri<'d, T>, |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | #[derive(Debug)] | 181 | #[derive(Debug)] |
| @@ -186,8 +186,7 @@ pub enum Adc4Error { | |||
| 186 | 186 | ||
| 187 | impl<'d, T: Instance> Adc4<'d, T> { | 187 | impl<'d, T: Instance> Adc4<'d, T> { |
| 188 | /// Create a new ADC driver. | 188 | /// Create a new ADC driver. |
| 189 | pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self { | 189 | pub fn new(adc: Peri<'d, T>) -> Self { |
| 190 | embassy_hal_internal::into_ref!(adc); | ||
| 191 | rcc::enable_and_reset::<T>(); | 190 | rcc::enable_and_reset::<T>(); |
| 192 | let prescaler = Prescaler::from_ker_ck(T::frequency()); | 191 | let prescaler = Prescaler::from_ker_ck(T::frequency()); |
| 193 | 192 | ||
| @@ -379,15 +378,15 @@ impl<'d, T: Instance> Adc4<'d, T> { | |||
| 379 | /// let mut adc4 = adc4::Adc4::new(p.ADC4); | 378 | /// let mut adc4 = adc4::Adc4::new(p.ADC4); |
| 380 | /// let mut adc4_pin1 = p.PC1; | 379 | /// let mut adc4_pin1 = p.PC1; |
| 381 | /// let mut adc4_pin2 = p.PC0; | 380 | /// let mut adc4_pin2 = p.PC0; |
| 382 | /// let mut degraded41 = adc4_pin1.degrade_adc(); | 381 | /// let mut.into()d41 = adc4_pin1.into(); |
| 383 | /// let mut degraded42 = adc4_pin2.degrade_adc(); | 382 | /// let mut.into()d42 = adc4_pin2.into(); |
| 384 | /// let mut measurements = [0u16; 2]; | 383 | /// let mut measurements = [0u16; 2]; |
| 385 | /// // not that the channels must be in ascending order | 384 | /// // not that the channels must be in ascending order |
| 386 | /// adc4.read( | 385 | /// adc4.read( |
| 387 | /// &mut p.GPDMA1_CH1, | 386 | /// &mut p.GPDMA1_CH1, |
| 388 | /// [ | 387 | /// [ |
| 389 | /// &mut degraded42, | 388 | /// &mut.into()d42, |
| 390 | /// &mut degraded41, | 389 | /// &mut.into()d41, |
| 391 | /// ] | 390 | /// ] |
| 392 | /// .into_iter(), | 391 | /// .into_iter(), |
| 393 | /// &mut measurements, | 392 | /// &mut measurements, |
| @@ -395,7 +394,7 @@ impl<'d, T: Instance> Adc4<'d, T> { | |||
| 395 | /// ``` | 394 | /// ``` |
| 396 | pub async fn read( | 395 | pub async fn read( |
| 397 | &mut self, | 396 | &mut self, |
| 398 | rx_dma: &mut impl RxDma4<T>, | 397 | rx_dma: Peri<'_, impl RxDma4<T>>, |
| 399 | sequence: impl ExactSizeIterator<Item = &mut AnyAdcChannel<T>>, | 398 | sequence: impl ExactSizeIterator<Item = &mut AnyAdcChannel<T>>, |
| 400 | readings: &mut [u16], | 399 | readings: &mut [u16], |
| 401 | ) -> Result<(), Adc4Error> { | 400 | ) -> Result<(), Adc4Error> { |
diff --git a/embassy-stm32/src/adc/v1.rs b/embassy-stm32/src/adc/v1.rs index d5cd14661..fb6f5b7d0 100644 --- a/embassy-stm32/src/adc/v1.rs +++ b/embassy-stm32/src/adc/v1.rs | |||
| @@ -2,7 +2,6 @@ use core::future::poll_fn; | |||
| 2 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 3 | use core::task::Poll; | 3 | use core::task::Poll; |
| 4 | 4 | ||
| 5 | use embassy_hal_internal::into_ref; | ||
| 6 | #[cfg(adc_l0)] | 5 | #[cfg(adc_l0)] |
| 7 | use stm32_metapac::adc::vals::Ckmode; | 6 | use stm32_metapac::adc::vals::Ckmode; |
| 8 | 7 | ||
| @@ -10,7 +9,7 @@ use super::blocking_delay_us; | |||
| 10 | use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime}; | 9 | use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime}; |
| 11 | use crate::interrupt::typelevel::Interrupt; | 10 | use crate::interrupt::typelevel::Interrupt; |
| 12 | use crate::peripherals::ADC1; | 11 | use crate::peripherals::ADC1; |
| 13 | use crate::{interrupt, rcc, Peripheral}; | 12 | use crate::{interrupt, rcc, Peri}; |
| 14 | 13 | ||
| 15 | pub const VDDA_CALIB_MV: u32 = 3300; | 14 | pub const VDDA_CALIB_MV: u32 = 3300; |
| 16 | pub const VREF_INT: u32 = 1230; | 15 | pub const VREF_INT: u32 = 1230; |
| @@ -63,10 +62,9 @@ impl super::SealedAdcChannel<ADC1> for Temperature { | |||
| 63 | 62 | ||
| 64 | impl<'d, T: Instance> Adc<'d, T> { | 63 | impl<'d, T: Instance> Adc<'d, T> { |
| 65 | pub fn new( | 64 | pub fn new( |
| 66 | adc: impl Peripheral<P = T> + 'd, | 65 | adc: Peri<'d, T>, |
| 67 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 66 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 68 | ) -> Self { | 67 | ) -> Self { |
| 69 | into_ref!(adc); | ||
| 70 | rcc::enable_and_reset::<T>(); | 68 | rcc::enable_and_reset::<T>(); |
| 71 | 69 | ||
| 72 | // Delay 1μs when using HSI14 as the ADC clock. | 70 | // Delay 1μs when using HSI14 as the ADC clock. |
diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs index 842a5ee6d..e94a25b24 100644 --- a/embassy-stm32/src/adc/v2.rs +++ b/embassy-stm32/src/adc/v2.rs | |||
| @@ -1,10 +1,8 @@ | |||
| 1 | use embassy_hal_internal::into_ref; | ||
| 2 | |||
| 3 | use super::blocking_delay_us; | 1 | use super::blocking_delay_us; |
| 4 | use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime}; | 2 | use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime}; |
| 5 | use crate::peripherals::ADC1; | 3 | use crate::peripherals::ADC1; |
| 6 | use crate::time::Hertz; | 4 | use crate::time::Hertz; |
| 7 | use crate::{rcc, Peripheral}; | 5 | use crate::{rcc, Peri}; |
| 8 | 6 | ||
| 9 | mod ringbuffered_v2; | 7 | mod ringbuffered_v2; |
| 10 | pub use ringbuffered_v2::{RingBufferedAdc, Sequence}; | 8 | pub use ringbuffered_v2::{RingBufferedAdc, Sequence}; |
| @@ -97,8 +95,7 @@ impl<'d, T> Adc<'d, T> | |||
| 97 | where | 95 | where |
| 98 | T: Instance, | 96 | T: Instance, |
| 99 | { | 97 | { |
| 100 | pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self { | 98 | pub fn new(adc: Peri<'d, T>) -> Self { |
| 101 | into_ref!(adc); | ||
| 102 | rcc::enable_and_reset::<T>(); | 99 | rcc::enable_and_reset::<T>(); |
| 103 | 100 | ||
| 104 | let presc = Prescaler::from_pclk2(T::frequency()); | 101 | let presc = Prescaler::from_pclk2(T::frequency()); |
diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs index 7a608a44e..2de12d1d6 100644 --- a/embassy-stm32/src/adc/v3.rs +++ b/embassy-stm32/src/adc/v3.rs | |||
| @@ -1,12 +1,11 @@ | |||
| 1 | use cfg_if::cfg_if; | 1 | use cfg_if::cfg_if; |
| 2 | use embassy_hal_internal::into_ref; | ||
| 3 | use pac::adc::vals::Dmacfg; | 2 | use pac::adc::vals::Dmacfg; |
| 4 | 3 | ||
| 5 | use super::{ | 4 | use super::{ |
| 6 | blocking_delay_us, Adc, AdcChannel, AnyAdcChannel, Instance, Resolution, RxDma, SampleTime, SealedAdcChannel, | 5 | blocking_delay_us, Adc, AdcChannel, AnyAdcChannel, Instance, Resolution, RxDma, SampleTime, SealedAdcChannel, |
| 7 | }; | 6 | }; |
| 8 | use crate::dma::Transfer; | 7 | use crate::dma::Transfer; |
| 9 | use crate::{pac, rcc, Peripheral}; | 8 | use crate::{pac, rcc, Peri}; |
| 10 | 9 | ||
| 11 | /// Default VREF voltage used for sample conversion to millivolts. | 10 | /// Default VREF voltage used for sample conversion to millivolts. |
| 12 | pub const VREF_DEFAULT_MV: u32 = 3300; | 11 | pub const VREF_DEFAULT_MV: u32 = 3300; |
| @@ -95,8 +94,7 @@ cfg_if! { | |||
| 95 | } | 94 | } |
| 96 | 95 | ||
| 97 | impl<'d, T: Instance> Adc<'d, T> { | 96 | impl<'d, T: Instance> Adc<'d, T> { |
| 98 | pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self { | 97 | pub fn new(adc: Peri<'d, T>) -> Self { |
| 99 | into_ref!(adc); | ||
| 100 | rcc::enable_and_reset::<T>(); | 98 | rcc::enable_and_reset::<T>(); |
| 101 | T::regs().cr().modify(|reg| { | 99 | T::regs().cr().modify(|reg| { |
| 102 | #[cfg(not(any(adc_g0, adc_u0)))] | 100 | #[cfg(not(any(adc_g0, adc_u0)))] |
| @@ -288,7 +286,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 288 | /// ``` | 286 | /// ``` |
| 289 | pub async fn read( | 287 | pub async fn read( |
| 290 | &mut self, | 288 | &mut self, |
| 291 | rx_dma: &mut impl RxDma<T>, | 289 | rx_dma: Peri<'_, impl RxDma<T>>, |
| 292 | sequence: impl ExactSizeIterator<Item = (&mut AnyAdcChannel<T>, SampleTime)>, | 290 | sequence: impl ExactSizeIterator<Item = (&mut AnyAdcChannel<T>, SampleTime)>, |
| 293 | readings: &mut [u16], | 291 | readings: &mut [u16], |
| 294 | ) { | 292 | ) { |
diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs index 9860efa8a..5910eef30 100644 --- a/embassy-stm32/src/adc/v4.rs +++ b/embassy-stm32/src/adc/v4.rs | |||
| @@ -9,7 +9,7 @@ use super::{ | |||
| 9 | }; | 9 | }; |
| 10 | use crate::dma::Transfer; | 10 | use crate::dma::Transfer; |
| 11 | use crate::time::Hertz; | 11 | use crate::time::Hertz; |
| 12 | use crate::{pac, rcc, Peripheral}; | 12 | use crate::{pac, rcc, Peri}; |
| 13 | 13 | ||
| 14 | /// Default VREF voltage used for sample conversion to millivolts. | 14 | /// Default VREF voltage used for sample conversion to millivolts. |
| 15 | pub const VREF_DEFAULT_MV: u32 = 3300; | 15 | pub const VREF_DEFAULT_MV: u32 = 3300; |
| @@ -158,8 +158,7 @@ pub enum Averaging { | |||
| 158 | 158 | ||
| 159 | impl<'d, T: Instance> Adc<'d, T> { | 159 | impl<'d, T: Instance> Adc<'d, T> { |
| 160 | /// Create a new ADC driver. | 160 | /// Create a new ADC driver. |
| 161 | pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self { | 161 | pub fn new(adc: Peri<'d, T>) -> Self { |
| 162 | embassy_hal_internal::into_ref!(adc); | ||
| 163 | rcc::enable_and_reset::<T>(); | 162 | rcc::enable_and_reset::<T>(); |
| 164 | 163 | ||
| 165 | let prescaler = Prescaler::from_ker_ck(T::frequency()); | 164 | let prescaler = Prescaler::from_ker_ck(T::frequency()); |
| @@ -344,8 +343,8 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 344 | /// use embassy_stm32::adc::{Adc, AdcChannel} | 343 | /// use embassy_stm32::adc::{Adc, AdcChannel} |
| 345 | /// | 344 | /// |
| 346 | /// let mut adc = Adc::new(p.ADC1); | 345 | /// let mut adc = Adc::new(p.ADC1); |
| 347 | /// let mut adc_pin0 = p.PA0.degrade_adc(); | 346 | /// let mut adc_pin0 = p.PA0.into(); |
| 348 | /// let mut adc_pin2 = p.PA2.degrade_adc(); | 347 | /// let mut adc_pin2 = p.PA2.into(); |
| 349 | /// let mut measurements = [0u16; 2]; | 348 | /// let mut measurements = [0u16; 2]; |
| 350 | /// | 349 | /// |
| 351 | /// adc.read_async( | 350 | /// adc.read_async( |
| @@ -362,7 +361,7 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 362 | /// ``` | 361 | /// ``` |
| 363 | pub async fn read( | 362 | pub async fn read( |
| 364 | &mut self, | 363 | &mut self, |
| 365 | rx_dma: &mut impl RxDma<T>, | 364 | rx_dma: Peri<'_, impl RxDma<T>>, |
| 366 | sequence: impl ExactSizeIterator<Item = (&mut AnyAdcChannel<T>, SampleTime)>, | 365 | sequence: impl ExactSizeIterator<Item = (&mut AnyAdcChannel<T>, SampleTime)>, |
| 367 | readings: &mut [u16], | 366 | readings: &mut [u16], |
| 368 | ) { | 367 | ) { |
diff --git a/embassy-stm32/src/can/bxcan/mod.rs b/embassy-stm32/src/can/bxcan/mod.rs index c0b3c730b..305666d5b 100644 --- a/embassy-stm32/src/can/bxcan/mod.rs +++ b/embassy-stm32/src/can/bxcan/mod.rs | |||
| @@ -6,7 +6,7 @@ use core::marker::PhantomData; | |||
| 6 | use core::task::Poll; | 6 | use core::task::Poll; |
| 7 | 7 | ||
| 8 | use embassy_hal_internal::interrupt::InterruptExt; | 8 | use embassy_hal_internal::interrupt::InterruptExt; |
| 9 | use embassy_hal_internal::into_ref; | 9 | use embassy_hal_internal::PeripheralType; |
| 10 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | 10 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; |
| 11 | use embassy_sync::channel::Channel; | 11 | use embassy_sync::channel::Channel; |
| 12 | use embassy_sync::waitqueue::AtomicWaker; | 12 | use embassy_sync::waitqueue::AtomicWaker; |
| @@ -21,7 +21,7 @@ use crate::can::enums::{BusError, InternalOperation, TryReadError}; | |||
| 21 | use crate::gpio::{AfType, OutputType, Pull, Speed}; | 21 | use crate::gpio::{AfType, OutputType, Pull, Speed}; |
| 22 | use crate::interrupt::typelevel::Interrupt; | 22 | use crate::interrupt::typelevel::Interrupt; |
| 23 | use crate::rcc::{self, RccPeripheral}; | 23 | use crate::rcc::{self, RccPeripheral}; |
| 24 | use crate::{interrupt, peripherals, Peripheral}; | 24 | use crate::{interrupt, peripherals, Peri}; |
| 25 | 25 | ||
| 26 | /// Interrupt handler. | 26 | /// Interrupt handler. |
| 27 | pub struct TxInterruptHandler<T: Instance> { | 27 | pub struct TxInterruptHandler<T: Instance> { |
| @@ -173,16 +173,15 @@ impl<'d> Can<'d> { | |||
| 173 | /// Creates a new Bxcan instance, keeping the peripheral in sleep mode. | 173 | /// Creates a new Bxcan instance, keeping the peripheral in sleep mode. |
| 174 | /// You must call [Can::enable_non_blocking] to use the peripheral. | 174 | /// You must call [Can::enable_non_blocking] to use the peripheral. |
| 175 | pub fn new<T: Instance>( | 175 | pub fn new<T: Instance>( |
| 176 | _peri: impl Peripheral<P = T> + 'd, | 176 | _peri: Peri<'d, T>, |
| 177 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 177 | rx: Peri<'d, impl RxPin<T>>, |
| 178 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 178 | tx: Peri<'d, impl TxPin<T>>, |
| 179 | _irqs: impl interrupt::typelevel::Binding<T::TXInterrupt, TxInterruptHandler<T>> | 179 | _irqs: impl interrupt::typelevel::Binding<T::TXInterrupt, TxInterruptHandler<T>> |
| 180 | + interrupt::typelevel::Binding<T::RX0Interrupt, Rx0InterruptHandler<T>> | 180 | + interrupt::typelevel::Binding<T::RX0Interrupt, Rx0InterruptHandler<T>> |
| 181 | + interrupt::typelevel::Binding<T::RX1Interrupt, Rx1InterruptHandler<T>> | 181 | + interrupt::typelevel::Binding<T::RX1Interrupt, Rx1InterruptHandler<T>> |
| 182 | + interrupt::typelevel::Binding<T::SCEInterrupt, SceInterruptHandler<T>> | 182 | + interrupt::typelevel::Binding<T::SCEInterrupt, SceInterruptHandler<T>> |
| 183 | + 'd, | 183 | + 'd, |
| 184 | ) -> Self { | 184 | ) -> Self { |
| 185 | into_ref!(_peri, rx, tx); | ||
| 186 | let info = T::info(); | 185 | let info = T::info(); |
| 187 | let regs = &T::info().regs; | 186 | let regs = &T::info().regs; |
| 188 | 187 | ||
| @@ -1083,7 +1082,7 @@ trait SealedInstance { | |||
| 1083 | 1082 | ||
| 1084 | /// CAN instance trait. | 1083 | /// CAN instance trait. |
| 1085 | #[allow(private_bounds)] | 1084 | #[allow(private_bounds)] |
| 1086 | pub trait Instance: Peripheral<P = Self> + SealedInstance + RccPeripheral + 'static { | 1085 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + 'static { |
| 1087 | /// TX interrupt for this instance. | 1086 | /// TX interrupt for this instance. |
| 1088 | type TXInterrupt: crate::interrupt::typelevel::Interrupt; | 1087 | type TXInterrupt: crate::interrupt::typelevel::Interrupt; |
| 1089 | /// RX0 interrupt for this instance. | 1088 | /// RX0 interrupt for this instance. |
diff --git a/embassy-stm32/src/can/fdcan.rs b/embassy-stm32/src/can/fdcan.rs index f950b6f99..5467a40f1 100644 --- a/embassy-stm32/src/can/fdcan.rs +++ b/embassy-stm32/src/can/fdcan.rs | |||
| @@ -4,7 +4,7 @@ use core::marker::PhantomData; | |||
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | 5 | ||
| 6 | use embassy_hal_internal::interrupt::InterruptExt; | 6 | use embassy_hal_internal::interrupt::InterruptExt; |
| 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 7 | use embassy_hal_internal::PeripheralType; |
| 8 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | 8 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; |
| 9 | use embassy_sync::channel::Channel; | 9 | use embassy_sync::channel::Channel; |
| 10 | use embassy_sync::waitqueue::AtomicWaker; | 10 | use embassy_sync::waitqueue::AtomicWaker; |
| @@ -13,7 +13,7 @@ use crate::can::fd::peripheral::Registers; | |||
| 13 | use crate::gpio::{AfType, OutputType, Pull, Speed}; | 13 | use crate::gpio::{AfType, OutputType, Pull, Speed}; |
| 14 | use crate::interrupt::typelevel::Interrupt; | 14 | use crate::interrupt::typelevel::Interrupt; |
| 15 | use crate::rcc::{self, RccPeripheral}; | 15 | use crate::rcc::{self, RccPeripheral}; |
| 16 | use crate::{interrupt, peripherals, Peripheral}; | 16 | use crate::{interrupt, peripherals, Peri}; |
| 17 | 17 | ||
| 18 | pub(crate) mod fd; | 18 | pub(crate) mod fd; |
| 19 | 19 | ||
| @@ -175,15 +175,13 @@ impl<'d> CanConfigurator<'d> { | |||
| 175 | /// Creates a new Fdcan instance, keeping the peripheral in sleep mode. | 175 | /// Creates a new Fdcan instance, keeping the peripheral in sleep mode. |
| 176 | /// You must call [Fdcan::enable_non_blocking] to use the peripheral. | 176 | /// You must call [Fdcan::enable_non_blocking] to use the peripheral. |
| 177 | pub fn new<T: Instance>( | 177 | pub fn new<T: Instance>( |
| 178 | _peri: impl Peripheral<P = T> + 'd, | 178 | _peri: Peri<'d, T>, |
| 179 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 179 | rx: Peri<'d, impl RxPin<T>>, |
| 180 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 180 | tx: Peri<'d, impl TxPin<T>>, |
| 181 | _irqs: impl interrupt::typelevel::Binding<T::IT0Interrupt, IT0InterruptHandler<T>> | 181 | _irqs: impl interrupt::typelevel::Binding<T::IT0Interrupt, IT0InterruptHandler<T>> |
| 182 | + interrupt::typelevel::Binding<T::IT1Interrupt, IT1InterruptHandler<T>> | 182 | + interrupt::typelevel::Binding<T::IT1Interrupt, IT1InterruptHandler<T>> |
| 183 | + 'd, | 183 | + 'd, |
| 184 | ) -> CanConfigurator<'d> { | 184 | ) -> CanConfigurator<'d> { |
| 185 | into_ref!(_peri, rx, tx); | ||
| 186 | |||
| 187 | rx.set_as_af(rx.af_num(), AfType::input(Pull::None)); | 185 | rx.set_as_af(rx.af_num(), AfType::input(Pull::None)); |
| 188 | tx.set_as_af(tx.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 186 | tx.set_as_af(tx.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 189 | 187 | ||
| @@ -957,7 +955,7 @@ trait SealedInstance { | |||
| 957 | 955 | ||
| 958 | /// Instance trait | 956 | /// Instance trait |
| 959 | #[allow(private_bounds)] | 957 | #[allow(private_bounds)] |
| 960 | pub trait Instance: SealedInstance + RccPeripheral + 'static { | 958 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + 'static { |
| 961 | /// Interrupt 0 | 959 | /// Interrupt 0 |
| 962 | type IT0Interrupt: crate::interrupt::typelevel::Interrupt; | 960 | type IT0Interrupt: crate::interrupt::typelevel::Interrupt; |
| 963 | /// Interrupt 1 | 961 | /// Interrupt 1 |
| @@ -965,7 +963,7 @@ pub trait Instance: SealedInstance + RccPeripheral + 'static { | |||
| 965 | } | 963 | } |
| 966 | 964 | ||
| 967 | /// Fdcan Instance struct | 965 | /// Fdcan Instance struct |
| 968 | pub struct FdcanInstance<'a, T>(PeripheralRef<'a, T>); | 966 | pub struct FdcanInstance<'a, T: Instance>(Peri<'a, T>); |
| 969 | 967 | ||
| 970 | macro_rules! impl_fdcan { | 968 | macro_rules! impl_fdcan { |
| 971 | ($inst:ident, | 969 | ($inst:ident, |
diff --git a/embassy-stm32/src/cordic/mod.rs b/embassy-stm32/src/cordic/mod.rs index fb342d2e7..320774857 100644 --- a/embassy-stm32/src/cordic/mod.rs +++ b/embassy-stm32/src/cordic/mod.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | //! coordinate rotation digital computer (CORDIC) | 1 | //! coordinate rotation digital computer (CORDIC) |
| 2 | 2 | ||
| 3 | use embassy_hal_internal::drop::OnDrop; | 3 | use embassy_hal_internal::drop::OnDrop; |
| 4 | use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; | 4 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 5 | 5 | ||
| 6 | use crate::pac::cordic::vals; | 6 | use crate::pac::cordic::vals; |
| 7 | use crate::{dma, peripherals, rcc}; | 7 | use crate::{dma, peripherals, rcc}; |
| @@ -16,7 +16,7 @@ pub mod utils; | |||
| 16 | 16 | ||
| 17 | /// CORDIC driver | 17 | /// CORDIC driver |
| 18 | pub struct Cordic<'d, T: Instance> { | 18 | pub struct Cordic<'d, T: Instance> { |
| 19 | peri: PeripheralRef<'d, T>, | 19 | peri: Peri<'d, T>, |
| 20 | config: Config, | 20 | config: Config, |
| 21 | } | 21 | } |
| 22 | 22 | ||
| @@ -137,7 +137,7 @@ trait SealedInstance { | |||
| 137 | 137 | ||
| 138 | /// CORDIC instance trait | 138 | /// CORDIC instance trait |
| 139 | #[allow(private_bounds)] | 139 | #[allow(private_bounds)] |
| 140 | pub trait Instance: SealedInstance + Peripheral<P = Self> + crate::rcc::RccPeripheral {} | 140 | pub trait Instance: SealedInstance + PeripheralType + crate::rcc::RccPeripheral {} |
| 141 | 141 | ||
| 142 | /// CORDIC configuration | 142 | /// CORDIC configuration |
| 143 | #[derive(Debug)] | 143 | #[derive(Debug)] |
| @@ -198,11 +198,9 @@ impl<'d, T: Instance> Cordic<'d, T> { | |||
| 198 | /// Note: | 198 | /// Note: |
| 199 | /// If you need a peripheral -> CORDIC -> peripheral mode, | 199 | /// If you need a peripheral -> CORDIC -> peripheral mode, |
| 200 | /// you may want to set Cordic into [Mode::ZeroOverhead] mode, and add extra arguments with [Self::extra_config] | 200 | /// you may want to set Cordic into [Mode::ZeroOverhead] mode, and add extra arguments with [Self::extra_config] |
| 201 | pub fn new(peri: impl Peripheral<P = T> + 'd, config: Config) -> Self { | 201 | pub fn new(peri: Peri<'d, T>, config: Config) -> Self { |
| 202 | rcc::enable_and_reset::<T>(); | 202 | rcc::enable_and_reset::<T>(); |
| 203 | 203 | ||
| 204 | into_ref!(peri); | ||
| 205 | |||
| 206 | let mut instance = Self { peri, config }; | 204 | let mut instance = Self { peri, config }; |
| 207 | 205 | ||
| 208 | instance.reconfigure(); | 206 | instance.reconfigure(); |
| @@ -378,8 +376,8 @@ impl<'d, T: Instance> Cordic<'d, T> { | |||
| 378 | /// If you want to make sure ARG2 is set to +1, consider run [.reconfigure()](Self::reconfigure). | 376 | /// If you want to make sure ARG2 is set to +1, consider run [.reconfigure()](Self::reconfigure). |
| 379 | pub async fn async_calc_32bit( | 377 | pub async fn async_calc_32bit( |
| 380 | &mut self, | 378 | &mut self, |
| 381 | write_dma: impl Peripheral<P = impl WriteDma<T>>, | 379 | mut write_dma: Peri<'_, impl WriteDma<T>>, |
| 382 | read_dma: impl Peripheral<P = impl ReadDma<T>>, | 380 | mut read_dma: Peri<'_, impl ReadDma<T>>, |
| 383 | arg: &[u32], | 381 | arg: &[u32], |
| 384 | res: &mut [u32], | 382 | res: &mut [u32], |
| 385 | arg1_only: bool, | 383 | arg1_only: bool, |
| @@ -393,8 +391,6 @@ impl<'d, T: Instance> Cordic<'d, T> { | |||
| 393 | 391 | ||
| 394 | let active_res_buf = &mut res[..res_cnt]; | 392 | let active_res_buf = &mut res[..res_cnt]; |
| 395 | 393 | ||
| 396 | into_ref!(write_dma, read_dma); | ||
| 397 | |||
| 398 | self.peri | 394 | self.peri |
| 399 | .set_argument_count(if arg1_only { AccessCount::One } else { AccessCount::Two }); | 395 | .set_argument_count(if arg1_only { AccessCount::One } else { AccessCount::Two }); |
| 400 | 396 | ||
| @@ -416,7 +412,7 @@ impl<'d, T: Instance> Cordic<'d, T> { | |||
| 416 | 412 | ||
| 417 | unsafe { | 413 | unsafe { |
| 418 | let write_transfer = dma::Transfer::new_write( | 414 | let write_transfer = dma::Transfer::new_write( |
| 419 | &mut write_dma, | 415 | write_dma.reborrow(), |
| 420 | write_req, | 416 | write_req, |
| 421 | arg, | 417 | arg, |
| 422 | T::regs().wdata().as_ptr() as *mut _, | 418 | T::regs().wdata().as_ptr() as *mut _, |
| @@ -424,7 +420,7 @@ impl<'d, T: Instance> Cordic<'d, T> { | |||
| 424 | ); | 420 | ); |
| 425 | 421 | ||
| 426 | let read_transfer = dma::Transfer::new_read( | 422 | let read_transfer = dma::Transfer::new_read( |
| 427 | &mut read_dma, | 423 | read_dma.reborrow(), |
| 428 | read_req, | 424 | read_req, |
| 429 | T::regs().rdata().as_ptr() as *mut _, | 425 | T::regs().rdata().as_ptr() as *mut _, |
| 430 | active_res_buf, | 426 | active_res_buf, |
| @@ -519,8 +515,8 @@ impl<'d, T: Instance> Cordic<'d, T> { | |||
| 519 | /// User will take respond to merge two u16 arguments into one u32 data, and/or split one u32 data into two u16 results. | 515 | /// User will take respond to merge two u16 arguments into one u32 data, and/or split one u32 data into two u16 results. |
| 520 | pub async fn async_calc_16bit( | 516 | pub async fn async_calc_16bit( |
| 521 | &mut self, | 517 | &mut self, |
| 522 | write_dma: impl Peripheral<P = impl WriteDma<T>>, | 518 | mut write_dma: Peri<'_, impl WriteDma<T>>, |
| 523 | read_dma: impl Peripheral<P = impl ReadDma<T>>, | 519 | mut read_dma: Peri<'_, impl ReadDma<T>>, |
| 524 | arg: &[u32], | 520 | arg: &[u32], |
| 525 | res: &mut [u32], | 521 | res: &mut [u32], |
| 526 | ) -> Result<usize, CordicError> { | 522 | ) -> Result<usize, CordicError> { |
| @@ -536,8 +532,6 @@ impl<'d, T: Instance> Cordic<'d, T> { | |||
| 536 | 532 | ||
| 537 | let active_res_buf = &mut res[..res_cnt]; | 533 | let active_res_buf = &mut res[..res_cnt]; |
| 538 | 534 | ||
| 539 | into_ref!(write_dma, read_dma); | ||
| 540 | |||
| 541 | // In q1.15 mode, 1 write/read to access 2 arguments/results | 535 | // In q1.15 mode, 1 write/read to access 2 arguments/results |
| 542 | self.peri.set_argument_count(AccessCount::One); | 536 | self.peri.set_argument_count(AccessCount::One); |
| 543 | self.peri.set_result_count(AccessCount::One); | 537 | self.peri.set_result_count(AccessCount::One); |
| @@ -557,7 +551,7 @@ impl<'d, T: Instance> Cordic<'d, T> { | |||
| 557 | 551 | ||
| 558 | unsafe { | 552 | unsafe { |
| 559 | let write_transfer = dma::Transfer::new_write( | 553 | let write_transfer = dma::Transfer::new_write( |
| 560 | &mut write_dma, | 554 | write_dma.reborrow(), |
| 561 | write_req, | 555 | write_req, |
| 562 | arg, | 556 | arg, |
| 563 | T::regs().wdata().as_ptr() as *mut _, | 557 | T::regs().wdata().as_ptr() as *mut _, |
| @@ -565,7 +559,7 @@ impl<'d, T: Instance> Cordic<'d, T> { | |||
| 565 | ); | 559 | ); |
| 566 | 560 | ||
| 567 | let read_transfer = dma::Transfer::new_read( | 561 | let read_transfer = dma::Transfer::new_read( |
| 568 | &mut read_dma, | 562 | read_dma.reborrow(), |
| 569 | read_req, | 563 | read_req, |
| 570 | T::regs().rdata().as_ptr() as *mut _, | 564 | T::regs().rdata().as_ptr() as *mut _, |
| 571 | active_res_buf, | 565 | active_res_buf, |
diff --git a/embassy-stm32/src/crc/v1.rs b/embassy-stm32/src/crc/v1.rs index f3d13de7c..a78b3c2b7 100644 --- a/embassy-stm32/src/crc/v1.rs +++ b/embassy-stm32/src/crc/v1.rs | |||
| @@ -1,23 +1,18 @@ | |||
| 1 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 2 | |||
| 3 | use crate::pac::CRC as PAC_CRC; | 1 | use crate::pac::CRC as PAC_CRC; |
| 4 | use crate::peripherals::CRC; | 2 | use crate::peripherals::CRC; |
| 5 | use crate::{rcc, Peripheral}; | 3 | use crate::{rcc, Peri}; |
| 6 | 4 | ||
| 7 | /// CRC driver. | 5 | /// CRC driver. |
| 8 | pub struct Crc<'d> { | 6 | pub struct Crc<'d> { |
| 9 | _peri: PeripheralRef<'d, CRC>, | 7 | _peri: Peri<'d, CRC>, |
| 10 | } | 8 | } |
| 11 | 9 | ||
| 12 | impl<'d> Crc<'d> { | 10 | impl<'d> Crc<'d> { |
| 13 | /// Instantiates the CRC32 peripheral and initializes it to default values. | 11 | /// Instantiates the CRC32 peripheral and initializes it to default values. |
| 14 | pub fn new(peripheral: impl Peripheral<P = CRC> + 'd) -> Self { | 12 | pub fn new(peripheral: Peri<'d, CRC>) -> Self { |
| 15 | into_ref!(peripheral); | ||
| 16 | |||
| 17 | // Note: enable and reset come from RccPeripheral. | 13 | // Note: enable and reset come from RccPeripheral. |
| 18 | // enable CRC clock in RCC. | 14 | // enable CRC clock in RCC. |
| 19 | rcc::enable_and_reset::<CRC>(); | 15 | rcc::enable_and_reset::<CRC>(); |
| 20 | // Peripheral the peripheral | ||
| 21 | let mut instance = Self { _peri: peripheral }; | 16 | let mut instance = Self { _peri: peripheral }; |
| 22 | instance.reset(); | 17 | instance.reset(); |
| 23 | instance | 18 | instance |
diff --git a/embassy-stm32/src/crc/v2v3.rs b/embassy-stm32/src/crc/v2v3.rs index ecb507ff4..c94c9f380 100644 --- a/embassy-stm32/src/crc/v2v3.rs +++ b/embassy-stm32/src/crc/v2v3.rs | |||
| @@ -1,13 +1,11 @@ | |||
| 1 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 2 | |||
| 3 | use crate::pac::crc::vals; | 1 | use crate::pac::crc::vals; |
| 4 | use crate::pac::CRC as PAC_CRC; | 2 | use crate::pac::CRC as PAC_CRC; |
| 5 | use crate::peripherals::CRC; | 3 | use crate::peripherals::CRC; |
| 6 | use crate::{rcc, Peripheral}; | 4 | use crate::{rcc, Peri}; |
| 7 | 5 | ||
| 8 | /// CRC driver. | 6 | /// CRC driver. |
| 9 | pub struct Crc<'d> { | 7 | pub struct Crc<'d> { |
| 10 | _peripheral: PeripheralRef<'d, CRC>, | 8 | _peripheral: Peri<'d, CRC>, |
| 11 | _config: Config, | 9 | _config: Config, |
| 12 | } | 10 | } |
| 13 | 11 | ||
| @@ -80,11 +78,10 @@ pub enum PolySize { | |||
| 80 | 78 | ||
| 81 | impl<'d> Crc<'d> { | 79 | impl<'d> Crc<'d> { |
| 82 | /// Instantiates the CRC32 peripheral and initializes it to default values. | 80 | /// Instantiates the CRC32 peripheral and initializes it to default values. |
| 83 | pub fn new(peripheral: impl Peripheral<P = CRC> + 'd, config: Config) -> Self { | 81 | pub fn new(peripheral: Peri<'d, CRC>, config: Config) -> Self { |
| 84 | // Note: enable and reset come from RccPeripheral. | 82 | // Note: enable and reset come from RccPeripheral. |
| 85 | // reset to default values and enable CRC clock in RCC. | 83 | // reset to default values and enable CRC clock in RCC. |
| 86 | rcc::enable_and_reset::<CRC>(); | 84 | rcc::enable_and_reset::<CRC>(); |
| 87 | into_ref!(peripheral); | ||
| 88 | let mut instance = Self { | 85 | let mut instance = Self { |
| 89 | _peripheral: peripheral, | 86 | _peripheral: peripheral, |
| 90 | _config: config, | 87 | _config: config, |
diff --git a/embassy-stm32/src/cryp/mod.rs b/embassy-stm32/src/cryp/mod.rs index 54d2c30e5..fba3c0fd7 100644 --- a/embassy-stm32/src/cryp/mod.rs +++ b/embassy-stm32/src/cryp/mod.rs | |||
| @@ -4,13 +4,13 @@ use core::cmp::min; | |||
| 4 | use core::marker::PhantomData; | 4 | use core::marker::PhantomData; |
| 5 | use core::ptr; | 5 | use core::ptr; |
| 6 | 6 | ||
| 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 7 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 8 | use embassy_sync::waitqueue::AtomicWaker; | 8 | use embassy_sync::waitqueue::AtomicWaker; |
| 9 | 9 | ||
| 10 | use crate::dma::{ChannelAndRequest, TransferOptions}; | 10 | use crate::dma::{ChannelAndRequest, TransferOptions}; |
| 11 | use crate::interrupt::typelevel::Interrupt; | 11 | use crate::interrupt::typelevel::Interrupt; |
| 12 | use crate::mode::{Async, Blocking, Mode}; | 12 | use crate::mode::{Async, Blocking, Mode}; |
| 13 | use crate::{interrupt, pac, peripherals, rcc, Peripheral}; | 13 | use crate::{interrupt, pac, peripherals, rcc}; |
| 14 | 14 | ||
| 15 | const DES_BLOCK_SIZE: usize = 8; // 64 bits | 15 | const DES_BLOCK_SIZE: usize = 8; // 64 bits |
| 16 | const AES_BLOCK_SIZE: usize = 16; // 128 bits | 16 | const AES_BLOCK_SIZE: usize = 16; // 128 bits |
| @@ -988,7 +988,7 @@ pub enum Direction { | |||
| 988 | 988 | ||
| 989 | /// Crypto Accelerator Driver | 989 | /// Crypto Accelerator Driver |
| 990 | pub struct Cryp<'d, T: Instance, M: Mode> { | 990 | pub struct Cryp<'d, T: Instance, M: Mode> { |
| 991 | _peripheral: PeripheralRef<'d, T>, | 991 | _peripheral: Peri<'d, T>, |
| 992 | _phantom: PhantomData<M>, | 992 | _phantom: PhantomData<M>, |
| 993 | indma: Option<ChannelAndRequest<'d>>, | 993 | indma: Option<ChannelAndRequest<'d>>, |
| 994 | outdma: Option<ChannelAndRequest<'d>>, | 994 | outdma: Option<ChannelAndRequest<'d>>, |
| @@ -997,11 +997,10 @@ pub struct Cryp<'d, T: Instance, M: Mode> { | |||
| 997 | impl<'d, T: Instance> Cryp<'d, T, Blocking> { | 997 | impl<'d, T: Instance> Cryp<'d, T, Blocking> { |
| 998 | /// Create a new CRYP driver in blocking mode. | 998 | /// Create a new CRYP driver in blocking mode. |
| 999 | pub fn new_blocking( | 999 | pub fn new_blocking( |
| 1000 | peri: impl Peripheral<P = T> + 'd, | 1000 | peri: Peri<'d, T>, |
| 1001 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 1001 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 1002 | ) -> Self { | 1002 | ) -> Self { |
| 1003 | rcc::enable_and_reset::<T>(); | 1003 | rcc::enable_and_reset::<T>(); |
| 1004 | into_ref!(peri); | ||
| 1005 | let instance = Self { | 1004 | let instance = Self { |
| 1006 | _peripheral: peri, | 1005 | _peripheral: peri, |
| 1007 | _phantom: PhantomData, | 1006 | _phantom: PhantomData, |
| @@ -1461,13 +1460,12 @@ impl<'d, T: Instance, M: Mode> Cryp<'d, T, M> { | |||
| 1461 | impl<'d, T: Instance> Cryp<'d, T, Async> { | 1460 | impl<'d, T: Instance> Cryp<'d, T, Async> { |
| 1462 | /// Create a new CRYP driver. | 1461 | /// Create a new CRYP driver. |
| 1463 | pub fn new( | 1462 | pub fn new( |
| 1464 | peri: impl Peripheral<P = T> + 'd, | 1463 | peri: Peri<'d, T>, |
| 1465 | indma: impl Peripheral<P = impl DmaIn<T>> + 'd, | 1464 | indma: Peri<'d, impl DmaIn<T>>, |
| 1466 | outdma: impl Peripheral<P = impl DmaOut<T>> + 'd, | 1465 | outdma: Peri<'d, impl DmaOut<T>>, |
| 1467 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 1466 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 1468 | ) -> Self { | 1467 | ) -> Self { |
| 1469 | rcc::enable_and_reset::<T>(); | 1468 | rcc::enable_and_reset::<T>(); |
| 1470 | into_ref!(peri, indma, outdma); | ||
| 1471 | let instance = Self { | 1469 | let instance = Self { |
| 1472 | _peripheral: peri, | 1470 | _peripheral: peri, |
| 1473 | _phantom: PhantomData, | 1471 | _phantom: PhantomData, |
| @@ -1879,7 +1877,7 @@ trait SealedInstance { | |||
| 1879 | 1877 | ||
| 1880 | /// CRYP instance trait. | 1878 | /// CRYP instance trait. |
| 1881 | #[allow(private_bounds)] | 1879 | #[allow(private_bounds)] |
| 1882 | pub trait Instance: SealedInstance + Peripheral<P = Self> + crate::rcc::RccPeripheral + 'static + Send { | 1880 | pub trait Instance: SealedInstance + PeripheralType + crate::rcc::RccPeripheral + 'static + Send { |
| 1883 | /// Interrupt for this CRYP instance. | 1881 | /// Interrupt for this CRYP instance. |
| 1884 | type Interrupt: interrupt::typelevel::Interrupt; | 1882 | type Interrupt: interrupt::typelevel::Interrupt; |
| 1885 | } | 1883 | } |
diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 7a63dc5fc..30046849b 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs | |||
| @@ -3,16 +3,15 @@ | |||
| 3 | 3 | ||
| 4 | use core::marker::PhantomData; | 4 | use core::marker::PhantomData; |
| 5 | 5 | ||
| 6 | use embassy_hal_internal::into_ref; | ||
| 7 | |||
| 8 | use crate::dma::ChannelAndRequest; | 6 | use crate::dma::ChannelAndRequest; |
| 9 | use crate::mode::{Async, Blocking, Mode as PeriMode}; | 7 | use crate::mode::{Async, Blocking, Mode as PeriMode}; |
| 10 | #[cfg(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7))] | 8 | #[cfg(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7))] |
| 11 | use crate::pac::dac; | 9 | use crate::pac::dac; |
| 12 | use crate::rcc::{self, RccPeripheral}; | 10 | use crate::rcc::{self, RccPeripheral}; |
| 13 | use crate::{peripherals, Peripheral}; | 11 | use crate::{peripherals, Peri}; |
| 14 | 12 | ||
| 15 | mod tsel; | 13 | mod tsel; |
| 14 | use embassy_hal_internal::PeripheralType; | ||
| 16 | pub use tsel::TriggerSel; | 15 | pub use tsel::TriggerSel; |
| 17 | 16 | ||
| 18 | /// Operating mode for DAC channel | 17 | /// Operating mode for DAC channel |
| @@ -121,12 +120,7 @@ impl<'d, T: Instance, C: Channel> DacChannel<'d, T, C, Async> { | |||
| 121 | /// | 120 | /// |
| 122 | /// By default, triggering is disabled, but it can be enabled using | 121 | /// By default, triggering is disabled, but it can be enabled using |
| 123 | /// [`DacChannel::set_trigger()`]. | 122 | /// [`DacChannel::set_trigger()`]. |
| 124 | pub fn new( | 123 | pub fn new(peri: Peri<'d, T>, dma: Peri<'d, impl Dma<T, C>>, pin: Peri<'d, impl DacPin<T, C>>) -> Self { |
| 125 | peri: impl Peripheral<P = T> + 'd, | ||
| 126 | dma: impl Peripheral<P = impl Dma<T, C>> + 'd, | ||
| 127 | pin: impl Peripheral<P = impl DacPin<T, C>> + 'd, | ||
| 128 | ) -> Self { | ||
| 129 | into_ref!(dma, pin); | ||
| 130 | pin.set_as_analog(); | 124 | pin.set_as_analog(); |
| 131 | Self::new_inner( | 125 | Self::new_inner( |
| 132 | peri, | 126 | peri, |
| @@ -147,8 +141,7 @@ impl<'d, T: Instance, C: Channel> DacChannel<'d, T, C, Async> { | |||
| 147 | /// By default, triggering is disabled, but it can be enabled using | 141 | /// By default, triggering is disabled, but it can be enabled using |
| 148 | /// [`DacChannel::set_trigger()`]. | 142 | /// [`DacChannel::set_trigger()`]. |
| 149 | #[cfg(all(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7), not(any(stm32h56x, stm32h57x))))] | 143 | #[cfg(all(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7), not(any(stm32h56x, stm32h57x))))] |
| 150 | pub fn new_internal(peri: impl Peripheral<P = T> + 'd, dma: impl Peripheral<P = impl Dma<T, C>> + 'd) -> Self { | 144 | pub fn new_internal(peri: Peri<'d, T>, dma: Peri<'d, impl Dma<T, C>>) -> Self { |
| 151 | into_ref!(dma); | ||
| 152 | Self::new_inner(peri, new_dma!(dma), Mode::NormalInternalUnbuffered) | 145 | Self::new_inner(peri, new_dma!(dma), Mode::NormalInternalUnbuffered) |
| 153 | } | 146 | } |
| 154 | 147 | ||
| @@ -204,8 +197,7 @@ impl<'d, T: Instance, C: Channel> DacChannel<'d, T, C, Blocking> { | |||
| 204 | /// | 197 | /// |
| 205 | /// By default, triggering is disabled, but it can be enabled using | 198 | /// By default, triggering is disabled, but it can be enabled using |
| 206 | /// [`DacChannel::set_trigger()`]. | 199 | /// [`DacChannel::set_trigger()`]. |
| 207 | pub fn new_blocking(peri: impl Peripheral<P = T> + 'd, pin: impl Peripheral<P = impl DacPin<T, C>> + 'd) -> Self { | 200 | pub fn new_blocking(peri: Peri<'d, T>, pin: Peri<'d, impl DacPin<T, C>>) -> Self { |
| 208 | into_ref!(pin); | ||
| 209 | pin.set_as_analog(); | 201 | pin.set_as_analog(); |
| 210 | Self::new_inner( | 202 | Self::new_inner( |
| 211 | peri, | 203 | peri, |
| @@ -226,14 +218,14 @@ impl<'d, T: Instance, C: Channel> DacChannel<'d, T, C, Blocking> { | |||
| 226 | /// By default, triggering is disabled, but it can be enabled using | 218 | /// By default, triggering is disabled, but it can be enabled using |
| 227 | /// [`DacChannel::set_trigger()`]. | 219 | /// [`DacChannel::set_trigger()`]. |
| 228 | #[cfg(all(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7), not(any(stm32h56x, stm32h57x))))] | 220 | #[cfg(all(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7), not(any(stm32h56x, stm32h57x))))] |
| 229 | pub fn new_internal_blocking(peri: impl Peripheral<P = T> + 'd) -> Self { | 221 | pub fn new_internal_blocking(peri: Peri<'d, T>) -> Self { |
| 230 | Self::new_inner(peri, None, Mode::NormalInternalUnbuffered) | 222 | Self::new_inner(peri, None, Mode::NormalInternalUnbuffered) |
| 231 | } | 223 | } |
| 232 | } | 224 | } |
| 233 | 225 | ||
| 234 | impl<'d, T: Instance, C: Channel, M: PeriMode> DacChannel<'d, T, C, M> { | 226 | impl<'d, T: Instance, C: Channel, M: PeriMode> DacChannel<'d, T, C, M> { |
| 235 | fn new_inner( | 227 | fn new_inner( |
| 236 | _peri: impl Peripheral<P = T> + 'd, | 228 | _peri: Peri<'d, T>, |
| 237 | dma: Option<ChannelAndRequest<'d>>, | 229 | dma: Option<ChannelAndRequest<'d>>, |
| 238 | #[cfg(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7))] mode: Mode, | 230 | #[cfg(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7))] mode: Mode, |
| 239 | ) -> Self { | 231 | ) -> Self { |
| @@ -395,13 +387,12 @@ impl<'d, T: Instance> Dac<'d, T, Async> { | |||
| 395 | /// By default, triggering is disabled, but it can be enabled using the `set_trigger()` | 387 | /// By default, triggering is disabled, but it can be enabled using the `set_trigger()` |
| 396 | /// method on the underlying channels. | 388 | /// method on the underlying channels. |
| 397 | pub fn new( | 389 | pub fn new( |
| 398 | peri: impl Peripheral<P = T> + 'd, | 390 | peri: Peri<'d, T>, |
| 399 | dma_ch1: impl Peripheral<P = impl Dma<T, Ch1>> + 'd, | 391 | dma_ch1: Peri<'d, impl Dma<T, Ch1>>, |
| 400 | dma_ch2: impl Peripheral<P = impl Dma<T, Ch2>> + 'd, | 392 | dma_ch2: Peri<'d, impl Dma<T, Ch2>>, |
| 401 | pin_ch1: impl Peripheral<P = impl DacPin<T, Ch1> + crate::gpio::Pin> + 'd, | 393 | pin_ch1: Peri<'d, impl DacPin<T, Ch1> + crate::gpio::Pin>, |
| 402 | pin_ch2: impl Peripheral<P = impl DacPin<T, Ch2> + crate::gpio::Pin> + 'd, | 394 | pin_ch2: Peri<'d, impl DacPin<T, Ch2> + crate::gpio::Pin>, |
| 403 | ) -> Self { | 395 | ) -> Self { |
| 404 | into_ref!(dma_ch1, dma_ch2, pin_ch1, pin_ch2); | ||
| 405 | pin_ch1.set_as_analog(); | 396 | pin_ch1.set_as_analog(); |
| 406 | pin_ch2.set_as_analog(); | 397 | pin_ch2.set_as_analog(); |
| 407 | Self::new_inner( | 398 | Self::new_inner( |
| @@ -429,11 +420,10 @@ impl<'d, T: Instance> Dac<'d, T, Async> { | |||
| 429 | /// method on the underlying channels. | 420 | /// method on the underlying channels. |
| 430 | #[cfg(all(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7), not(any(stm32h56x, stm32h57x))))] | 421 | #[cfg(all(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7), not(any(stm32h56x, stm32h57x))))] |
| 431 | pub fn new_internal( | 422 | pub fn new_internal( |
| 432 | peri: impl Peripheral<P = T> + 'd, | 423 | peri: Peri<'d, T>, |
| 433 | dma_ch1: impl Peripheral<P = impl Dma<T, Ch1>> + 'd, | 424 | dma_ch1: Peri<'d, impl Dma<T, Ch1>>, |
| 434 | dma_ch2: impl Peripheral<P = impl Dma<T, Ch2>> + 'd, | 425 | dma_ch2: Peri<'d, impl Dma<T, Ch2>>, |
| 435 | ) -> Self { | 426 | ) -> Self { |
| 436 | into_ref!(dma_ch1, dma_ch2); | ||
| 437 | Self::new_inner( | 427 | Self::new_inner( |
| 438 | peri, | 428 | peri, |
| 439 | new_dma!(dma_ch1), | 429 | new_dma!(dma_ch1), |
| @@ -457,11 +447,10 @@ impl<'d, T: Instance> Dac<'d, T, Blocking> { | |||
| 457 | /// By default, triggering is disabled, but it can be enabled using the `set_trigger()` | 447 | /// By default, triggering is disabled, but it can be enabled using the `set_trigger()` |
| 458 | /// method on the underlying channels. | 448 | /// method on the underlying channels. |
| 459 | pub fn new_blocking( | 449 | pub fn new_blocking( |
| 460 | peri: impl Peripheral<P = T> + 'd, | 450 | peri: Peri<'d, T>, |
| 461 | pin_ch1: impl Peripheral<P = impl DacPin<T, Ch1> + crate::gpio::Pin> + 'd, | 451 | pin_ch1: Peri<'d, impl DacPin<T, Ch1> + crate::gpio::Pin>, |
| 462 | pin_ch2: impl Peripheral<P = impl DacPin<T, Ch2> + crate::gpio::Pin> + 'd, | 452 | pin_ch2: Peri<'d, impl DacPin<T, Ch2> + crate::gpio::Pin>, |
| 463 | ) -> Self { | 453 | ) -> Self { |
| 464 | into_ref!(pin_ch1, pin_ch2); | ||
| 465 | pin_ch1.set_as_analog(); | 454 | pin_ch1.set_as_analog(); |
| 466 | pin_ch2.set_as_analog(); | 455 | pin_ch2.set_as_analog(); |
| 467 | Self::new_inner( | 456 | Self::new_inner( |
| @@ -488,14 +477,14 @@ impl<'d, T: Instance> Dac<'d, T, Blocking> { | |||
| 488 | /// By default, triggering is disabled, but it can be enabled using the `set_trigger()` | 477 | /// By default, triggering is disabled, but it can be enabled using the `set_trigger()` |
| 489 | /// method on the underlying channels. | 478 | /// method on the underlying channels. |
| 490 | #[cfg(all(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7), not(any(stm32h56x, stm32h57x))))] | 479 | #[cfg(all(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7), not(any(stm32h56x, stm32h57x))))] |
| 491 | pub fn new_internal(peri: impl Peripheral<P = T> + 'd) -> Self { | 480 | pub fn new_internal(peri: Peri<'d, T>) -> Self { |
| 492 | Self::new_inner(peri, None, None, Mode::NormalInternalUnbuffered) | 481 | Self::new_inner(peri, None, None, Mode::NormalInternalUnbuffered) |
| 493 | } | 482 | } |
| 494 | } | 483 | } |
| 495 | 484 | ||
| 496 | impl<'d, T: Instance, M: PeriMode> Dac<'d, T, M> { | 485 | impl<'d, T: Instance, M: PeriMode> Dac<'d, T, M> { |
| 497 | fn new_inner( | 486 | fn new_inner( |
| 498 | _peri: impl Peripheral<P = T> + 'd, | 487 | _peri: Peri<'d, T>, |
| 499 | dma_ch1: Option<ChannelAndRequest<'d>>, | 488 | dma_ch1: Option<ChannelAndRequest<'d>>, |
| 500 | dma_ch2: Option<ChannelAndRequest<'d>>, | 489 | dma_ch2: Option<ChannelAndRequest<'d>>, |
| 501 | #[cfg(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7))] mode: Mode, | 490 | #[cfg(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7))] mode: Mode, |
| @@ -572,7 +561,7 @@ trait SealedInstance { | |||
| 572 | 561 | ||
| 573 | /// DAC instance. | 562 | /// DAC instance. |
| 574 | #[allow(private_bounds)] | 563 | #[allow(private_bounds)] |
| 575 | pub trait Instance: SealedInstance + RccPeripheral + 'static {} | 564 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + 'static {} |
| 576 | 565 | ||
| 577 | /// Channel 1 marker type. | 566 | /// Channel 1 marker type. |
| 578 | pub enum Ch1 {} | 567 | pub enum Ch1 {} |
diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs index 4ba4e824e..d05faee21 100644 --- a/embassy-stm32/src/dcmi.rs +++ b/embassy-stm32/src/dcmi.rs | |||
| @@ -3,13 +3,13 @@ use core::future::poll_fn; | |||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | 5 | ||
| 6 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 6 | use embassy_hal_internal::PeripheralType; |
| 7 | use embassy_sync::waitqueue::AtomicWaker; | 7 | use embassy_sync::waitqueue::AtomicWaker; |
| 8 | 8 | ||
| 9 | use crate::dma::Transfer; | 9 | use crate::dma::Transfer; |
| 10 | use crate::gpio::{AfType, Pull}; | 10 | use crate::gpio::{AfType, Pull}; |
| 11 | use crate::interrupt::typelevel::Interrupt; | 11 | use crate::interrupt::typelevel::Interrupt; |
| 12 | use crate::{interrupt, rcc, Peripheral}; | 12 | use crate::{interrupt, rcc, Peri}; |
| 13 | 13 | ||
| 14 | /// Interrupt handler. | 14 | /// Interrupt handler. |
| 15 | pub struct InterruptHandler<T: Instance> { | 15 | pub struct InterruptHandler<T: Instance> { |
| @@ -106,8 +106,7 @@ impl Default for Config { | |||
| 106 | 106 | ||
| 107 | macro_rules! config_pins { | 107 | macro_rules! config_pins { |
| 108 | ($($pin:ident),*) => { | 108 | ($($pin:ident),*) => { |
| 109 | into_ref!($($pin),*); | 109 | critical_section::with(|_| { |
| 110 | critical_section::with(|_| { | ||
| 111 | $( | 110 | $( |
| 112 | $pin.set_as_af($pin.af_num(), AfType::input(Pull::None)); | 111 | $pin.set_as_af($pin.af_num(), AfType::input(Pull::None)); |
| 113 | )* | 112 | )* |
| @@ -117,8 +116,8 @@ macro_rules! config_pins { | |||
| 117 | 116 | ||
| 118 | /// DCMI driver. | 117 | /// DCMI driver. |
| 119 | pub struct Dcmi<'d, T: Instance, Dma: FrameDma<T>> { | 118 | pub struct Dcmi<'d, T: Instance, Dma: FrameDma<T>> { |
| 120 | inner: PeripheralRef<'d, T>, | 119 | inner: Peri<'d, T>, |
| 121 | dma: PeripheralRef<'d, Dma>, | 120 | dma: Peri<'d, Dma>, |
| 122 | } | 121 | } |
| 123 | 122 | ||
| 124 | impl<'d, T, Dma> Dcmi<'d, T, Dma> | 123 | impl<'d, T, Dma> Dcmi<'d, T, Dma> |
| @@ -128,23 +127,22 @@ where | |||
| 128 | { | 127 | { |
| 129 | /// Create a new DCMI driver with 8 data bits. | 128 | /// Create a new DCMI driver with 8 data bits. |
| 130 | pub fn new_8bit( | 129 | pub fn new_8bit( |
| 131 | peri: impl Peripheral<P = T> + 'd, | 130 | peri: Peri<'d, T>, |
| 132 | dma: impl Peripheral<P = Dma> + 'd, | 131 | dma: Peri<'d, Dma>, |
| 133 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 132 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 134 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 133 | d0: Peri<'d, impl D0Pin<T>>, |
| 135 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 134 | d1: Peri<'d, impl D1Pin<T>>, |
| 136 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 135 | d2: Peri<'d, impl D2Pin<T>>, |
| 137 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 136 | d3: Peri<'d, impl D3Pin<T>>, |
| 138 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 137 | d4: Peri<'d, impl D4Pin<T>>, |
| 139 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 138 | d5: Peri<'d, impl D5Pin<T>>, |
| 140 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 139 | d6: Peri<'d, impl D6Pin<T>>, |
| 141 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 140 | d7: Peri<'d, impl D7Pin<T>>, |
| 142 | v_sync: impl Peripheral<P = impl VSyncPin<T>> + 'd, | 141 | v_sync: Peri<'d, impl VSyncPin<T>>, |
| 143 | h_sync: impl Peripheral<P = impl HSyncPin<T>> + 'd, | 142 | h_sync: Peri<'d, impl HSyncPin<T>>, |
| 144 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, | 143 | pixclk: Peri<'d, impl PixClkPin<T>>, |
| 145 | config: Config, | 144 | config: Config, |
| 146 | ) -> Self { | 145 | ) -> Self { |
| 147 | into_ref!(peri, dma); | ||
| 148 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7); | 146 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7); |
| 149 | config_pins!(v_sync, h_sync, pixclk); | 147 | config_pins!(v_sync, h_sync, pixclk); |
| 150 | 148 | ||
| @@ -153,25 +151,24 @@ where | |||
| 153 | 151 | ||
| 154 | /// Create a new DCMI driver with 10 data bits. | 152 | /// Create a new DCMI driver with 10 data bits. |
| 155 | pub fn new_10bit( | 153 | pub fn new_10bit( |
| 156 | peri: impl Peripheral<P = T> + 'd, | 154 | peri: Peri<'d, T>, |
| 157 | dma: impl Peripheral<P = Dma> + 'd, | 155 | dma: Peri<'d, Dma>, |
| 158 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 156 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 159 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 157 | d0: Peri<'d, impl D0Pin<T>>, |
| 160 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 158 | d1: Peri<'d, impl D1Pin<T>>, |
| 161 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 159 | d2: Peri<'d, impl D2Pin<T>>, |
| 162 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 160 | d3: Peri<'d, impl D3Pin<T>>, |
| 163 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 161 | d4: Peri<'d, impl D4Pin<T>>, |
| 164 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 162 | d5: Peri<'d, impl D5Pin<T>>, |
| 165 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 163 | d6: Peri<'d, impl D6Pin<T>>, |
| 166 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 164 | d7: Peri<'d, impl D7Pin<T>>, |
| 167 | d8: impl Peripheral<P = impl D8Pin<T>> + 'd, | 165 | d8: Peri<'d, impl D8Pin<T>>, |
| 168 | d9: impl Peripheral<P = impl D9Pin<T>> + 'd, | 166 | d9: Peri<'d, impl D9Pin<T>>, |
| 169 | v_sync: impl Peripheral<P = impl VSyncPin<T>> + 'd, | 167 | v_sync: Peri<'d, impl VSyncPin<T>>, |
| 170 | h_sync: impl Peripheral<P = impl HSyncPin<T>> + 'd, | 168 | h_sync: Peri<'d, impl HSyncPin<T>>, |
| 171 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, | 169 | pixclk: Peri<'d, impl PixClkPin<T>>, |
| 172 | config: Config, | 170 | config: Config, |
| 173 | ) -> Self { | 171 | ) -> Self { |
| 174 | into_ref!(peri, dma); | ||
| 175 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9); | 172 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9); |
| 176 | config_pins!(v_sync, h_sync, pixclk); | 173 | config_pins!(v_sync, h_sync, pixclk); |
| 177 | 174 | ||
| @@ -180,27 +177,26 @@ where | |||
| 180 | 177 | ||
| 181 | /// Create a new DCMI driver with 12 data bits. | 178 | /// Create a new DCMI driver with 12 data bits. |
| 182 | pub fn new_12bit( | 179 | pub fn new_12bit( |
| 183 | peri: impl Peripheral<P = T> + 'd, | 180 | peri: Peri<'d, T>, |
| 184 | dma: impl Peripheral<P = Dma> + 'd, | 181 | dma: Peri<'d, Dma>, |
| 185 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 182 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 186 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 183 | d0: Peri<'d, impl D0Pin<T>>, |
| 187 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 184 | d1: Peri<'d, impl D1Pin<T>>, |
| 188 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 185 | d2: Peri<'d, impl D2Pin<T>>, |
| 189 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 186 | d3: Peri<'d, impl D3Pin<T>>, |
| 190 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 187 | d4: Peri<'d, impl D4Pin<T>>, |
| 191 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 188 | d5: Peri<'d, impl D5Pin<T>>, |
| 192 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 189 | d6: Peri<'d, impl D6Pin<T>>, |
| 193 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 190 | d7: Peri<'d, impl D7Pin<T>>, |
| 194 | d8: impl Peripheral<P = impl D8Pin<T>> + 'd, | 191 | d8: Peri<'d, impl D8Pin<T>>, |
| 195 | d9: impl Peripheral<P = impl D9Pin<T>> + 'd, | 192 | d9: Peri<'d, impl D9Pin<T>>, |
| 196 | d10: impl Peripheral<P = impl D10Pin<T>> + 'd, | 193 | d10: Peri<'d, impl D10Pin<T>>, |
| 197 | d11: impl Peripheral<P = impl D11Pin<T>> + 'd, | 194 | d11: Peri<'d, impl D11Pin<T>>, |
| 198 | v_sync: impl Peripheral<P = impl VSyncPin<T>> + 'd, | 195 | v_sync: Peri<'d, impl VSyncPin<T>>, |
| 199 | h_sync: impl Peripheral<P = impl HSyncPin<T>> + 'd, | 196 | h_sync: Peri<'d, impl HSyncPin<T>>, |
| 200 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, | 197 | pixclk: Peri<'d, impl PixClkPin<T>>, |
| 201 | config: Config, | 198 | config: Config, |
| 202 | ) -> Self { | 199 | ) -> Self { |
| 203 | into_ref!(peri, dma); | ||
| 204 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11); | 200 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11); |
| 205 | config_pins!(v_sync, h_sync, pixclk); | 201 | config_pins!(v_sync, h_sync, pixclk); |
| 206 | 202 | ||
| @@ -209,29 +205,28 @@ where | |||
| 209 | 205 | ||
| 210 | /// Create a new DCMI driver with 14 data bits. | 206 | /// Create a new DCMI driver with 14 data bits. |
| 211 | pub fn new_14bit( | 207 | pub fn new_14bit( |
| 212 | peri: impl Peripheral<P = T> + 'd, | 208 | peri: Peri<'d, T>, |
| 213 | dma: impl Peripheral<P = Dma> + 'd, | 209 | dma: Peri<'d, Dma>, |
| 214 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 210 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 215 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 211 | d0: Peri<'d, impl D0Pin<T>>, |
| 216 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 212 | d1: Peri<'d, impl D1Pin<T>>, |
| 217 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 213 | d2: Peri<'d, impl D2Pin<T>>, |
| 218 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 214 | d3: Peri<'d, impl D3Pin<T>>, |
| 219 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 215 | d4: Peri<'d, impl D4Pin<T>>, |
| 220 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 216 | d5: Peri<'d, impl D5Pin<T>>, |
| 221 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 217 | d6: Peri<'d, impl D6Pin<T>>, |
| 222 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 218 | d7: Peri<'d, impl D7Pin<T>>, |
| 223 | d8: impl Peripheral<P = impl D8Pin<T>> + 'd, | 219 | d8: Peri<'d, impl D8Pin<T>>, |
| 224 | d9: impl Peripheral<P = impl D9Pin<T>> + 'd, | 220 | d9: Peri<'d, impl D9Pin<T>>, |
| 225 | d10: impl Peripheral<P = impl D10Pin<T>> + 'd, | 221 | d10: Peri<'d, impl D10Pin<T>>, |
| 226 | d11: impl Peripheral<P = impl D11Pin<T>> + 'd, | 222 | d11: Peri<'d, impl D11Pin<T>>, |
| 227 | d12: impl Peripheral<P = impl D12Pin<T>> + 'd, | 223 | d12: Peri<'d, impl D12Pin<T>>, |
| 228 | d13: impl Peripheral<P = impl D13Pin<T>> + 'd, | 224 | d13: Peri<'d, impl D13Pin<T>>, |
| 229 | v_sync: impl Peripheral<P = impl VSyncPin<T>> + 'd, | 225 | v_sync: Peri<'d, impl VSyncPin<T>>, |
| 230 | h_sync: impl Peripheral<P = impl HSyncPin<T>> + 'd, | 226 | h_sync: Peri<'d, impl HSyncPin<T>>, |
| 231 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, | 227 | pixclk: Peri<'d, impl PixClkPin<T>>, |
| 232 | config: Config, | 228 | config: Config, |
| 233 | ) -> Self { | 229 | ) -> Self { |
| 234 | into_ref!(peri, dma); | ||
| 235 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13); | 230 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13); |
| 236 | config_pins!(v_sync, h_sync, pixclk); | 231 | config_pins!(v_sync, h_sync, pixclk); |
| 237 | 232 | ||
| @@ -240,21 +235,20 @@ where | |||
| 240 | 235 | ||
| 241 | /// Create a new DCMI driver with 8 data bits, with embedded synchronization. | 236 | /// Create a new DCMI driver with 8 data bits, with embedded synchronization. |
| 242 | pub fn new_es_8bit( | 237 | pub fn new_es_8bit( |
| 243 | peri: impl Peripheral<P = T> + 'd, | 238 | peri: Peri<'d, T>, |
| 244 | dma: impl Peripheral<P = Dma> + 'd, | 239 | dma: Peri<'d, Dma>, |
| 245 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 240 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 246 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 241 | d0: Peri<'d, impl D0Pin<T>>, |
| 247 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 242 | d1: Peri<'d, impl D1Pin<T>>, |
| 248 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 243 | d2: Peri<'d, impl D2Pin<T>>, |
| 249 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 244 | d3: Peri<'d, impl D3Pin<T>>, |
| 250 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 245 | d4: Peri<'d, impl D4Pin<T>>, |
| 251 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 246 | d5: Peri<'d, impl D5Pin<T>>, |
| 252 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 247 | d6: Peri<'d, impl D6Pin<T>>, |
| 253 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 248 | d7: Peri<'d, impl D7Pin<T>>, |
| 254 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, | 249 | pixclk: Peri<'d, impl PixClkPin<T>>, |
| 255 | config: Config, | 250 | config: Config, |
| 256 | ) -> Self { | 251 | ) -> Self { |
| 257 | into_ref!(peri, dma); | ||
| 258 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7); | 252 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7); |
| 259 | config_pins!(pixclk); | 253 | config_pins!(pixclk); |
| 260 | 254 | ||
| @@ -263,23 +257,22 @@ where | |||
| 263 | 257 | ||
| 264 | /// Create a new DCMI driver with 10 data bits, with embedded synchronization. | 258 | /// Create a new DCMI driver with 10 data bits, with embedded synchronization. |
| 265 | pub fn new_es_10bit( | 259 | pub fn new_es_10bit( |
| 266 | peri: impl Peripheral<P = T> + 'd, | 260 | peri: Peri<'d, T>, |
| 267 | dma: impl Peripheral<P = Dma> + 'd, | 261 | dma: Peri<'d, Dma>, |
| 268 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 262 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 269 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 263 | d0: Peri<'d, impl D0Pin<T>>, |
| 270 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 264 | d1: Peri<'d, impl D1Pin<T>>, |
| 271 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 265 | d2: Peri<'d, impl D2Pin<T>>, |
| 272 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 266 | d3: Peri<'d, impl D3Pin<T>>, |
| 273 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 267 | d4: Peri<'d, impl D4Pin<T>>, |
| 274 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 268 | d5: Peri<'d, impl D5Pin<T>>, |
| 275 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 269 | d6: Peri<'d, impl D6Pin<T>>, |
| 276 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 270 | d7: Peri<'d, impl D7Pin<T>>, |
| 277 | d8: impl Peripheral<P = impl D8Pin<T>> + 'd, | 271 | d8: Peri<'d, impl D8Pin<T>>, |
| 278 | d9: impl Peripheral<P = impl D9Pin<T>> + 'd, | 272 | d9: Peri<'d, impl D9Pin<T>>, |
| 279 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, | 273 | pixclk: Peri<'d, impl PixClkPin<T>>, |
| 280 | config: Config, | 274 | config: Config, |
| 281 | ) -> Self { | 275 | ) -> Self { |
| 282 | into_ref!(peri, dma); | ||
| 283 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9); | 276 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9); |
| 284 | config_pins!(pixclk); | 277 | config_pins!(pixclk); |
| 285 | 278 | ||
| @@ -288,25 +281,24 @@ where | |||
| 288 | 281 | ||
| 289 | /// Create a new DCMI driver with 12 data bits, with embedded synchronization. | 282 | /// Create a new DCMI driver with 12 data bits, with embedded synchronization. |
| 290 | pub fn new_es_12bit( | 283 | pub fn new_es_12bit( |
| 291 | peri: impl Peripheral<P = T> + 'd, | 284 | peri: Peri<'d, T>, |
| 292 | dma: impl Peripheral<P = Dma> + 'd, | 285 | dma: Peri<'d, Dma>, |
| 293 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 286 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 294 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 287 | d0: Peri<'d, impl D0Pin<T>>, |
| 295 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 288 | d1: Peri<'d, impl D1Pin<T>>, |
| 296 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 289 | d2: Peri<'d, impl D2Pin<T>>, |
| 297 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 290 | d3: Peri<'d, impl D3Pin<T>>, |
| 298 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 291 | d4: Peri<'d, impl D4Pin<T>>, |
| 299 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 292 | d5: Peri<'d, impl D5Pin<T>>, |
| 300 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 293 | d6: Peri<'d, impl D6Pin<T>>, |
| 301 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 294 | d7: Peri<'d, impl D7Pin<T>>, |
| 302 | d8: impl Peripheral<P = impl D8Pin<T>> + 'd, | 295 | d8: Peri<'d, impl D8Pin<T>>, |
| 303 | d9: impl Peripheral<P = impl D9Pin<T>> + 'd, | 296 | d9: Peri<'d, impl D9Pin<T>>, |
| 304 | d10: impl Peripheral<P = impl D10Pin<T>> + 'd, | 297 | d10: Peri<'d, impl D10Pin<T>>, |
| 305 | d11: impl Peripheral<P = impl D11Pin<T>> + 'd, | 298 | d11: Peri<'d, impl D11Pin<T>>, |
| 306 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, | 299 | pixclk: Peri<'d, impl PixClkPin<T>>, |
| 307 | config: Config, | 300 | config: Config, |
| 308 | ) -> Self { | 301 | ) -> Self { |
| 309 | into_ref!(peri, dma); | ||
| 310 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11); | 302 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11); |
| 311 | config_pins!(pixclk); | 303 | config_pins!(pixclk); |
| 312 | 304 | ||
| @@ -315,27 +307,26 @@ where | |||
| 315 | 307 | ||
| 316 | /// Create a new DCMI driver with 14 data bits, with embedded synchronization. | 308 | /// Create a new DCMI driver with 14 data bits, with embedded synchronization. |
| 317 | pub fn new_es_14bit( | 309 | pub fn new_es_14bit( |
| 318 | peri: impl Peripheral<P = T> + 'd, | 310 | peri: Peri<'d, T>, |
| 319 | dma: impl Peripheral<P = Dma> + 'd, | 311 | dma: Peri<'d, Dma>, |
| 320 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 312 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 321 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 313 | d0: Peri<'d, impl D0Pin<T>>, |
| 322 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 314 | d1: Peri<'d, impl D1Pin<T>>, |
| 323 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 315 | d2: Peri<'d, impl D2Pin<T>>, |
| 324 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 316 | d3: Peri<'d, impl D3Pin<T>>, |
| 325 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 317 | d4: Peri<'d, impl D4Pin<T>>, |
| 326 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 318 | d5: Peri<'d, impl D5Pin<T>>, |
| 327 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 319 | d6: Peri<'d, impl D6Pin<T>>, |
| 328 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 320 | d7: Peri<'d, impl D7Pin<T>>, |
| 329 | d8: impl Peripheral<P = impl D8Pin<T>> + 'd, | 321 | d8: Peri<'d, impl D8Pin<T>>, |
| 330 | d9: impl Peripheral<P = impl D9Pin<T>> + 'd, | 322 | d9: Peri<'d, impl D9Pin<T>>, |
| 331 | d10: impl Peripheral<P = impl D10Pin<T>> + 'd, | 323 | d10: Peri<'d, impl D10Pin<T>>, |
| 332 | d11: impl Peripheral<P = impl D11Pin<T>> + 'd, | 324 | d11: Peri<'d, impl D11Pin<T>>, |
| 333 | d12: impl Peripheral<P = impl D12Pin<T>> + 'd, | 325 | d12: Peri<'d, impl D12Pin<T>>, |
| 334 | d13: impl Peripheral<P = impl D13Pin<T>> + 'd, | 326 | d13: Peri<'d, impl D13Pin<T>>, |
| 335 | pixclk: impl Peripheral<P = impl PixClkPin<T>> + 'd, | 327 | pixclk: Peri<'d, impl PixClkPin<T>>, |
| 336 | config: Config, | 328 | config: Config, |
| 337 | ) -> Self { | 329 | ) -> Self { |
| 338 | into_ref!(peri, dma); | ||
| 339 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13); | 330 | config_pins!(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13); |
| 340 | config_pins!(pixclk); | 331 | config_pins!(pixclk); |
| 341 | 332 | ||
| @@ -343,8 +334,8 @@ where | |||
| 343 | } | 334 | } |
| 344 | 335 | ||
| 345 | fn new_inner( | 336 | fn new_inner( |
| 346 | peri: PeripheralRef<'d, T>, | 337 | peri: Peri<'d, T>, |
| 347 | dma: PeripheralRef<'d, Dma>, | 338 | dma: Peri<'d, Dma>, |
| 348 | config: Config, | 339 | config: Config, |
| 349 | use_embedded_synchronization: bool, | 340 | use_embedded_synchronization: bool, |
| 350 | edm: u8, | 341 | edm: u8, |
| @@ -396,7 +387,7 @@ where | |||
| 396 | let r = self.inner.regs(); | 387 | let r = self.inner.regs(); |
| 397 | let src = r.dr().as_ptr() as *mut u32; | 388 | let src = r.dr().as_ptr() as *mut u32; |
| 398 | let request = self.dma.request(); | 389 | let request = self.dma.request(); |
| 399 | let dma_read = unsafe { Transfer::new_read(&mut self.dma, request, src, buffer, Default::default()) }; | 390 | let dma_read = unsafe { Transfer::new_read(self.dma.reborrow(), request, src, buffer, Default::default()) }; |
| 400 | 391 | ||
| 401 | Self::clear_interrupt_flags(); | 392 | Self::clear_interrupt_flags(); |
| 402 | Self::enable_irqs(); | 393 | Self::enable_irqs(); |
| @@ -435,7 +426,7 @@ trait SealedInstance: crate::rcc::RccPeripheral { | |||
| 435 | 426 | ||
| 436 | /// DCMI instance. | 427 | /// DCMI instance. |
| 437 | #[allow(private_bounds)] | 428 | #[allow(private_bounds)] |
| 438 | pub trait Instance: SealedInstance + 'static { | 429 | pub trait Instance: SealedInstance + PeripheralType + 'static { |
| 439 | /// Interrupt for this instance. | 430 | /// Interrupt for this instance. |
| 440 | type Interrupt: interrupt::typelevel::Interrupt; | 431 | type Interrupt: interrupt::typelevel::Interrupt; |
| 441 | } | 432 | } |
diff --git a/embassy-stm32/src/dma/dma_bdma.rs b/embassy-stm32/src/dma/dma_bdma.rs index d31f4d01a..7dbbe7b72 100644 --- a/embassy-stm32/src/dma/dma_bdma.rs +++ b/embassy-stm32/src/dma/dma_bdma.rs | |||
| @@ -3,7 +3,7 @@ use core::pin::Pin; | |||
| 3 | use core::sync::atomic::{fence, AtomicUsize, Ordering}; | 3 | use core::sync::atomic::{fence, AtomicUsize, Ordering}; |
| 4 | use core::task::{Context, Poll, Waker}; | 4 | use core::task::{Context, Poll, Waker}; |
| 5 | 5 | ||
| 6 | use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; | 6 | use embassy_hal_internal::Peri; |
| 7 | use embassy_sync::waitqueue::AtomicWaker; | 7 | use embassy_sync::waitqueue::AtomicWaker; |
| 8 | 8 | ||
| 9 | use super::ringbuffer::{DmaCtrl, Error, ReadableDmaRingBuffer, WritableDmaRingBuffer}; | 9 | use super::ringbuffer::{DmaCtrl, Error, ReadableDmaRingBuffer, WritableDmaRingBuffer}; |
| @@ -571,13 +571,13 @@ impl AnyChannel { | |||
| 571 | /// DMA transfer. | 571 | /// DMA transfer. |
| 572 | #[must_use = "futures do nothing unless you `.await` or poll them"] | 572 | #[must_use = "futures do nothing unless you `.await` or poll them"] |
| 573 | pub struct Transfer<'a> { | 573 | pub struct Transfer<'a> { |
| 574 | channel: PeripheralRef<'a, AnyChannel>, | 574 | channel: Peri<'a, AnyChannel>, |
| 575 | } | 575 | } |
| 576 | 576 | ||
| 577 | impl<'a> Transfer<'a> { | 577 | impl<'a> Transfer<'a> { |
| 578 | /// Create a new read DMA transfer (peripheral to memory). | 578 | /// Create a new read DMA transfer (peripheral to memory). |
| 579 | pub unsafe fn new_read<W: Word>( | 579 | pub unsafe fn new_read<W: Word>( |
| 580 | channel: impl Peripheral<P = impl Channel> + 'a, | 580 | channel: Peri<'a, impl Channel>, |
| 581 | request: Request, | 581 | request: Request, |
| 582 | peri_addr: *mut W, | 582 | peri_addr: *mut W, |
| 583 | buf: &'a mut [W], | 583 | buf: &'a mut [W], |
| @@ -588,16 +588,14 @@ impl<'a> Transfer<'a> { | |||
| 588 | 588 | ||
| 589 | /// Create a new read DMA transfer (peripheral to memory), using raw pointers. | 589 | /// Create a new read DMA transfer (peripheral to memory), using raw pointers. |
| 590 | pub unsafe fn new_read_raw<W: Word>( | 590 | pub unsafe fn new_read_raw<W: Word>( |
| 591 | channel: impl Peripheral<P = impl Channel> + 'a, | 591 | channel: Peri<'a, impl Channel>, |
| 592 | request: Request, | 592 | request: Request, |
| 593 | peri_addr: *mut W, | 593 | peri_addr: *mut W, |
| 594 | buf: *mut [W], | 594 | buf: *mut [W], |
| 595 | options: TransferOptions, | 595 | options: TransferOptions, |
| 596 | ) -> Self { | 596 | ) -> Self { |
| 597 | into_ref!(channel); | ||
| 598 | |||
| 599 | Self::new_inner( | 597 | Self::new_inner( |
| 600 | channel.map_into(), | 598 | channel.into(), |
| 601 | request, | 599 | request, |
| 602 | Dir::PeripheralToMemory, | 600 | Dir::PeripheralToMemory, |
| 603 | peri_addr as *const u32, | 601 | peri_addr as *const u32, |
| @@ -612,7 +610,7 @@ impl<'a> Transfer<'a> { | |||
| 612 | 610 | ||
| 613 | /// Create a new write DMA transfer (memory to peripheral). | 611 | /// Create a new write DMA transfer (memory to peripheral). |
| 614 | pub unsafe fn new_write<MW: Word, PW: Word>( | 612 | pub unsafe fn new_write<MW: Word, PW: Word>( |
| 615 | channel: impl Peripheral<P = impl Channel> + 'a, | 613 | channel: Peri<'a, impl Channel>, |
| 616 | request: Request, | 614 | request: Request, |
| 617 | buf: &'a [MW], | 615 | buf: &'a [MW], |
| 618 | peri_addr: *mut PW, | 616 | peri_addr: *mut PW, |
| @@ -623,16 +621,14 @@ impl<'a> Transfer<'a> { | |||
| 623 | 621 | ||
| 624 | /// Create a new write DMA transfer (memory to peripheral), using raw pointers. | 622 | /// Create a new write DMA transfer (memory to peripheral), using raw pointers. |
| 625 | pub unsafe fn new_write_raw<MW: Word, PW: Word>( | 623 | pub unsafe fn new_write_raw<MW: Word, PW: Word>( |
| 626 | channel: impl Peripheral<P = impl Channel> + 'a, | 624 | channel: Peri<'a, impl Channel>, |
| 627 | request: Request, | 625 | request: Request, |
| 628 | buf: *const [MW], | 626 | buf: *const [MW], |
| 629 | peri_addr: *mut PW, | 627 | peri_addr: *mut PW, |
| 630 | options: TransferOptions, | 628 | options: TransferOptions, |
| 631 | ) -> Self { | 629 | ) -> Self { |
| 632 | into_ref!(channel); | ||
| 633 | |||
| 634 | Self::new_inner( | 630 | Self::new_inner( |
| 635 | channel.map_into(), | 631 | channel.into(), |
| 636 | request, | 632 | request, |
| 637 | Dir::MemoryToPeripheral, | 633 | Dir::MemoryToPeripheral, |
| 638 | peri_addr as *const u32, | 634 | peri_addr as *const u32, |
| @@ -647,17 +643,15 @@ impl<'a> Transfer<'a> { | |||
| 647 | 643 | ||
| 648 | /// Create a new write DMA transfer (memory to peripheral), writing the same value repeatedly. | 644 | /// Create a new write DMA transfer (memory to peripheral), writing the same value repeatedly. |
| 649 | pub unsafe fn new_write_repeated<W: Word>( | 645 | pub unsafe fn new_write_repeated<W: Word>( |
| 650 | channel: impl Peripheral<P = impl Channel> + 'a, | 646 | channel: Peri<'a, impl Channel>, |
| 651 | request: Request, | 647 | request: Request, |
| 652 | repeated: &'a W, | 648 | repeated: &'a W, |
| 653 | count: usize, | 649 | count: usize, |
| 654 | peri_addr: *mut W, | 650 | peri_addr: *mut W, |
| 655 | options: TransferOptions, | 651 | options: TransferOptions, |
| 656 | ) -> Self { | 652 | ) -> Self { |
| 657 | into_ref!(channel); | ||
| 658 | |||
| 659 | Self::new_inner( | 653 | Self::new_inner( |
| 660 | channel.map_into(), | 654 | channel.into(), |
| 661 | request, | 655 | request, |
| 662 | Dir::MemoryToPeripheral, | 656 | Dir::MemoryToPeripheral, |
| 663 | peri_addr as *const u32, | 657 | peri_addr as *const u32, |
| @@ -671,7 +665,7 @@ impl<'a> Transfer<'a> { | |||
| 671 | } | 665 | } |
| 672 | 666 | ||
| 673 | unsafe fn new_inner( | 667 | unsafe fn new_inner( |
| 674 | channel: PeripheralRef<'a, AnyChannel>, | 668 | channel: Peri<'a, AnyChannel>, |
| 675 | _request: Request, | 669 | _request: Request, |
| 676 | dir: Dir, | 670 | dir: Dir, |
| 677 | peri_addr: *const u32, | 671 | peri_addr: *const u32, |
| @@ -769,7 +763,7 @@ impl<'a> Future for Transfer<'a> { | |||
| 769 | 763 | ||
| 770 | // ============================== | 764 | // ============================== |
| 771 | 765 | ||
| 772 | struct DmaCtrlImpl<'a>(PeripheralRef<'a, AnyChannel>); | 766 | struct DmaCtrlImpl<'a>(Peri<'a, AnyChannel>); |
| 773 | 767 | ||
| 774 | impl<'a> DmaCtrl for DmaCtrlImpl<'a> { | 768 | impl<'a> DmaCtrl for DmaCtrlImpl<'a> { |
| 775 | fn get_remaining_transfers(&self) -> usize { | 769 | fn get_remaining_transfers(&self) -> usize { |
| @@ -795,21 +789,20 @@ impl<'a> DmaCtrl for DmaCtrlImpl<'a> { | |||
| 795 | 789 | ||
| 796 | /// Ringbuffer for receiving data using DMA circular mode. | 790 | /// Ringbuffer for receiving data using DMA circular mode. |
| 797 | pub struct ReadableRingBuffer<'a, W: Word> { | 791 | pub struct ReadableRingBuffer<'a, W: Word> { |
| 798 | channel: PeripheralRef<'a, AnyChannel>, | 792 | channel: Peri<'a, AnyChannel>, |
| 799 | ringbuf: ReadableDmaRingBuffer<'a, W>, | 793 | ringbuf: ReadableDmaRingBuffer<'a, W>, |
| 800 | } | 794 | } |
| 801 | 795 | ||
| 802 | impl<'a, W: Word> ReadableRingBuffer<'a, W> { | 796 | impl<'a, W: Word> ReadableRingBuffer<'a, W> { |
| 803 | /// Create a new ring buffer. | 797 | /// Create a new ring buffer. |
| 804 | pub unsafe fn new( | 798 | pub unsafe fn new( |
| 805 | channel: impl Peripheral<P = impl Channel> + 'a, | 799 | channel: Peri<'a, impl Channel>, |
| 806 | _request: Request, | 800 | _request: Request, |
| 807 | peri_addr: *mut W, | 801 | peri_addr: *mut W, |
| 808 | buffer: &'a mut [W], | 802 | buffer: &'a mut [W], |
| 809 | mut options: TransferOptions, | 803 | mut options: TransferOptions, |
| 810 | ) -> Self { | 804 | ) -> Self { |
| 811 | into_ref!(channel); | 805 | let channel: Peri<'a, AnyChannel> = channel.into(); |
| 812 | let channel: PeripheralRef<'a, AnyChannel> = channel.map_into(); | ||
| 813 | 806 | ||
| 814 | let buffer_ptr = buffer.as_mut_ptr(); | 807 | let buffer_ptr = buffer.as_mut_ptr(); |
| 815 | let len = buffer.len(); | 808 | let len = buffer.len(); |
| @@ -948,21 +941,20 @@ impl<'a, W: Word> Drop for ReadableRingBuffer<'a, W> { | |||
| 948 | 941 | ||
| 949 | /// Ringbuffer for writing data using DMA circular mode. | 942 | /// Ringbuffer for writing data using DMA circular mode. |
| 950 | pub struct WritableRingBuffer<'a, W: Word> { | 943 | pub struct WritableRingBuffer<'a, W: Word> { |
| 951 | channel: PeripheralRef<'a, AnyChannel>, | 944 | channel: Peri<'a, AnyChannel>, |
| 952 | ringbuf: WritableDmaRingBuffer<'a, W>, | 945 | ringbuf: WritableDmaRingBuffer<'a, W>, |
| 953 | } | 946 | } |
| 954 | 947 | ||
| 955 | impl<'a, W: Word> WritableRingBuffer<'a, W> { | 948 | impl<'a, W: Word> WritableRingBuffer<'a, W> { |
| 956 | /// Create a new ring buffer. | 949 | /// Create a new ring buffer. |
| 957 | pub unsafe fn new( | 950 | pub unsafe fn new( |
| 958 | channel: impl Peripheral<P = impl Channel> + 'a, | 951 | channel: Peri<'a, impl Channel>, |
| 959 | _request: Request, | 952 | _request: Request, |
| 960 | peri_addr: *mut W, | 953 | peri_addr: *mut W, |
| 961 | buffer: &'a mut [W], | 954 | buffer: &'a mut [W], |
| 962 | mut options: TransferOptions, | 955 | mut options: TransferOptions, |
| 963 | ) -> Self { | 956 | ) -> Self { |
| 964 | into_ref!(channel); | 957 | let channel: Peri<'a, AnyChannel> = channel.into(); |
| 965 | let channel: PeripheralRef<'a, AnyChannel> = channel.map_into(); | ||
| 966 | 958 | ||
| 967 | let len = buffer.len(); | 959 | let len = buffer.len(); |
| 968 | let dir = Dir::MemoryToPeripheral; | 960 | let dir = Dir::MemoryToPeripheral; |
diff --git a/embassy-stm32/src/dma/gpdma.rs b/embassy-stm32/src/dma/gpdma.rs index 799b8b355..ade70fb55 100644 --- a/embassy-stm32/src/dma/gpdma.rs +++ b/embassy-stm32/src/dma/gpdma.rs | |||
| @@ -5,7 +5,7 @@ use core::pin::Pin; | |||
| 5 | use core::sync::atomic::{fence, Ordering}; | 5 | use core::sync::atomic::{fence, Ordering}; |
| 6 | use core::task::{Context, Poll}; | 6 | use core::task::{Context, Poll}; |
| 7 | 7 | ||
| 8 | use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; | 8 | use embassy_hal_internal::Peri; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | 10 | ||
| 11 | use super::word::{Word, WordSize}; | 11 | use super::word::{Word, WordSize}; |
| @@ -109,13 +109,13 @@ impl AnyChannel { | |||
| 109 | /// DMA transfer. | 109 | /// DMA transfer. |
| 110 | #[must_use = "futures do nothing unless you `.await` or poll them"] | 110 | #[must_use = "futures do nothing unless you `.await` or poll them"] |
| 111 | pub struct Transfer<'a> { | 111 | pub struct Transfer<'a> { |
| 112 | channel: PeripheralRef<'a, AnyChannel>, | 112 | channel: Peri<'a, AnyChannel>, |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | impl<'a> Transfer<'a> { | 115 | impl<'a> Transfer<'a> { |
| 116 | /// Create a new read DMA transfer (peripheral to memory). | 116 | /// Create a new read DMA transfer (peripheral to memory). |
| 117 | pub unsafe fn new_read<W: Word>( | 117 | pub unsafe fn new_read<W: Word>( |
| 118 | channel: impl Peripheral<P = impl Channel> + 'a, | 118 | channel: Peri<'a, impl Channel>, |
| 119 | request: Request, | 119 | request: Request, |
| 120 | peri_addr: *mut W, | 120 | peri_addr: *mut W, |
| 121 | buf: &'a mut [W], | 121 | buf: &'a mut [W], |
| @@ -126,16 +126,14 @@ impl<'a> Transfer<'a> { | |||
| 126 | 126 | ||
| 127 | /// Create a new read DMA transfer (peripheral to memory), using raw pointers. | 127 | /// Create a new read DMA transfer (peripheral to memory), using raw pointers. |
| 128 | pub unsafe fn new_read_raw<W: Word>( | 128 | pub unsafe fn new_read_raw<W: Word>( |
| 129 | channel: impl Peripheral<P = impl Channel> + 'a, | 129 | channel: Peri<'a, impl Channel>, |
| 130 | request: Request, | 130 | request: Request, |
| 131 | peri_addr: *mut W, | 131 | peri_addr: *mut W, |
| 132 | buf: *mut [W], | 132 | buf: *mut [W], |
| 133 | options: TransferOptions, | 133 | options: TransferOptions, |
| 134 | ) -> Self { | 134 | ) -> Self { |
| 135 | into_ref!(channel); | ||
| 136 | |||
| 137 | Self::new_inner( | 135 | Self::new_inner( |
| 138 | channel.map_into(), | 136 | channel.into(), |
| 139 | request, | 137 | request, |
| 140 | Dir::PeripheralToMemory, | 138 | Dir::PeripheralToMemory, |
| 141 | peri_addr as *const u32, | 139 | peri_addr as *const u32, |
| @@ -150,7 +148,7 @@ impl<'a> Transfer<'a> { | |||
| 150 | 148 | ||
| 151 | /// Create a new write DMA transfer (memory to peripheral). | 149 | /// Create a new write DMA transfer (memory to peripheral). |
| 152 | pub unsafe fn new_write<MW: Word, PW: Word>( | 150 | pub unsafe fn new_write<MW: Word, PW: Word>( |
| 153 | channel: impl Peripheral<P = impl Channel> + 'a, | 151 | channel: Peri<'a, impl Channel>, |
| 154 | request: Request, | 152 | request: Request, |
| 155 | buf: &'a [MW], | 153 | buf: &'a [MW], |
| 156 | peri_addr: *mut PW, | 154 | peri_addr: *mut PW, |
| @@ -161,16 +159,14 @@ impl<'a> Transfer<'a> { | |||
| 161 | 159 | ||
| 162 | /// Create a new write DMA transfer (memory to peripheral), using raw pointers. | 160 | /// Create a new write DMA transfer (memory to peripheral), using raw pointers. |
| 163 | pub unsafe fn new_write_raw<MW: Word, PW: Word>( | 161 | pub unsafe fn new_write_raw<MW: Word, PW: Word>( |
| 164 | channel: impl Peripheral<P = impl Channel> + 'a, | 162 | channel: Peri<'a, impl Channel>, |
| 165 | request: Request, | 163 | request: Request, |
| 166 | buf: *const [MW], | 164 | buf: *const [MW], |
| 167 | peri_addr: *mut PW, | 165 | peri_addr: *mut PW, |
| 168 | options: TransferOptions, | 166 | options: TransferOptions, |
| 169 | ) -> Self { | 167 | ) -> Self { |
| 170 | into_ref!(channel); | ||
| 171 | |||
| 172 | Self::new_inner( | 168 | Self::new_inner( |
| 173 | channel.map_into(), | 169 | channel.into(), |
| 174 | request, | 170 | request, |
| 175 | Dir::MemoryToPeripheral, | 171 | Dir::MemoryToPeripheral, |
| 176 | peri_addr as *const u32, | 172 | peri_addr as *const u32, |
| @@ -185,17 +181,15 @@ impl<'a> Transfer<'a> { | |||
| 185 | 181 | ||
| 186 | /// Create a new write DMA transfer (memory to peripheral), writing the same value repeatedly. | 182 | /// Create a new write DMA transfer (memory to peripheral), writing the same value repeatedly. |
| 187 | pub unsafe fn new_write_repeated<MW: Word, PW: Word>( | 183 | pub unsafe fn new_write_repeated<MW: Word, PW: Word>( |
| 188 | channel: impl Peripheral<P = impl Channel> + 'a, | 184 | channel: Peri<'a, impl Channel>, |
| 189 | request: Request, | 185 | request: Request, |
| 190 | repeated: &'a MW, | 186 | repeated: &'a MW, |
| 191 | count: usize, | 187 | count: usize, |
| 192 | peri_addr: *mut PW, | 188 | peri_addr: *mut PW, |
| 193 | options: TransferOptions, | 189 | options: TransferOptions, |
| 194 | ) -> Self { | 190 | ) -> Self { |
| 195 | into_ref!(channel); | ||
| 196 | |||
| 197 | Self::new_inner( | 191 | Self::new_inner( |
| 198 | channel.map_into(), | 192 | channel.into(), |
| 199 | request, | 193 | request, |
| 200 | Dir::MemoryToPeripheral, | 194 | Dir::MemoryToPeripheral, |
| 201 | peri_addr as *const u32, | 195 | peri_addr as *const u32, |
| @@ -209,7 +203,7 @@ impl<'a> Transfer<'a> { | |||
| 209 | } | 203 | } |
| 210 | 204 | ||
| 211 | unsafe fn new_inner( | 205 | unsafe fn new_inner( |
| 212 | channel: PeripheralRef<'a, AnyChannel>, | 206 | channel: Peri<'a, AnyChannel>, |
| 213 | request: Request, | 207 | request: Request, |
| 214 | dir: Dir, | 208 | dir: Dir, |
| 215 | peri_addr: *const u32, | 209 | peri_addr: *const u32, |
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index ac4a0f98e..d3b070a6d 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs | |||
| @@ -22,7 +22,7 @@ pub(crate) use util::*; | |||
| 22 | pub(crate) mod ringbuffer; | 22 | pub(crate) mod ringbuffer; |
| 23 | pub mod word; | 23 | pub mod word; |
| 24 | 24 | ||
| 25 | use embassy_hal_internal::{impl_peripheral, Peripheral}; | 25 | use embassy_hal_internal::{impl_peripheral, PeripheralType}; |
| 26 | 26 | ||
| 27 | use crate::interrupt; | 27 | use crate::interrupt; |
| 28 | 28 | ||
| @@ -51,17 +51,7 @@ pub(crate) trait ChannelInterrupt { | |||
| 51 | 51 | ||
| 52 | /// DMA channel. | 52 | /// DMA channel. |
| 53 | #[allow(private_bounds)] | 53 | #[allow(private_bounds)] |
| 54 | pub trait Channel: SealedChannel + Peripheral<P = Self> + Into<AnyChannel> + 'static { | 54 | pub trait Channel: SealedChannel + PeripheralType + Into<AnyChannel> + 'static {} |
| 55 | /// Type-erase (degrade) this pin into an `AnyChannel`. | ||
| 56 | /// | ||
| 57 | /// This converts DMA channel singletons (`DMA1_CH3`, `DMA2_CH1`, ...), which | ||
| 58 | /// are all different types, into the same type. It is useful for | ||
| 59 | /// creating arrays of channels, or avoiding generics. | ||
| 60 | #[inline] | ||
| 61 | fn degrade(self) -> AnyChannel { | ||
| 62 | AnyChannel { id: self.id() } | ||
| 63 | } | ||
| 64 | } | ||
| 65 | 55 | ||
| 66 | macro_rules! dma_channel_impl { | 56 | macro_rules! dma_channel_impl { |
| 67 | ($channel_peri:ident, $index:expr) => { | 57 | ($channel_peri:ident, $index:expr) => { |
| @@ -79,8 +69,10 @@ macro_rules! dma_channel_impl { | |||
| 79 | impl crate::dma::Channel for crate::peripherals::$channel_peri {} | 69 | impl crate::dma::Channel for crate::peripherals::$channel_peri {} |
| 80 | 70 | ||
| 81 | impl From<crate::peripherals::$channel_peri> for crate::dma::AnyChannel { | 71 | impl From<crate::peripherals::$channel_peri> for crate::dma::AnyChannel { |
| 82 | fn from(x: crate::peripherals::$channel_peri) -> Self { | 72 | fn from(val: crate::peripherals::$channel_peri) -> Self { |
| 83 | crate::dma::Channel::degrade(x) | 73 | Self { |
| 74 | id: crate::dma::SealedChannel::id(&val), | ||
| 75 | } | ||
| 84 | } | 76 | } |
| 85 | } | 77 | } |
| 86 | }; | 78 | }; |
diff --git a/embassy-stm32/src/dma/util.rs b/embassy-stm32/src/dma/util.rs index 5e1158182..8bf89e2fe 100644 --- a/embassy-stm32/src/dma/util.rs +++ b/embassy-stm32/src/dma/util.rs | |||
| @@ -1,13 +1,12 @@ | |||
| 1 | use embassy_hal_internal::PeripheralRef; | ||
| 2 | |||
| 3 | use super::word::Word; | 1 | use super::word::Word; |
| 4 | use super::{AnyChannel, Request, Transfer, TransferOptions}; | 2 | use super::{AnyChannel, Request, Transfer, TransferOptions}; |
| 3 | use crate::Peri; | ||
| 5 | 4 | ||
| 6 | /// Convenience wrapper, contains a channel and a request number. | 5 | /// Convenience wrapper, contains a channel and a request number. |
| 7 | /// | 6 | /// |
| 8 | /// Commonly used in peripheral drivers that own DMA channels. | 7 | /// Commonly used in peripheral drivers that own DMA channels. |
| 9 | pub(crate) struct ChannelAndRequest<'d> { | 8 | pub(crate) struct ChannelAndRequest<'d> { |
| 10 | pub channel: PeripheralRef<'d, AnyChannel>, | 9 | pub channel: Peri<'d, AnyChannel>, |
| 11 | pub request: Request, | 10 | pub request: Request, |
| 12 | } | 11 | } |
| 13 | 12 | ||
| @@ -18,7 +17,7 @@ impl<'d> ChannelAndRequest<'d> { | |||
| 18 | buf: &'a mut [W], | 17 | buf: &'a mut [W], |
| 19 | options: TransferOptions, | 18 | options: TransferOptions, |
| 20 | ) -> Transfer<'a> { | 19 | ) -> Transfer<'a> { |
| 21 | Transfer::new_read(&mut self.channel, self.request, peri_addr, buf, options) | 20 | Transfer::new_read(self.channel.reborrow(), self.request, peri_addr, buf, options) |
| 22 | } | 21 | } |
| 23 | 22 | ||
| 24 | pub unsafe fn read_raw<'a, W: Word>( | 23 | pub unsafe fn read_raw<'a, W: Word>( |
| @@ -27,7 +26,7 @@ impl<'d> ChannelAndRequest<'d> { | |||
| 27 | buf: *mut [W], | 26 | buf: *mut [W], |
| 28 | options: TransferOptions, | 27 | options: TransferOptions, |
| 29 | ) -> Transfer<'a> { | 28 | ) -> Transfer<'a> { |
| 30 | Transfer::new_read_raw(&mut self.channel, self.request, peri_addr, buf, options) | 29 | Transfer::new_read_raw(self.channel.reborrow(), self.request, peri_addr, buf, options) |
| 31 | } | 30 | } |
| 32 | 31 | ||
| 33 | pub unsafe fn write<'a, W: Word>( | 32 | pub unsafe fn write<'a, W: Word>( |
| @@ -36,7 +35,7 @@ impl<'d> ChannelAndRequest<'d> { | |||
| 36 | peri_addr: *mut W, | 35 | peri_addr: *mut W, |
| 37 | options: TransferOptions, | 36 | options: TransferOptions, |
| 38 | ) -> Transfer<'a> { | 37 | ) -> Transfer<'a> { |
| 39 | Transfer::new_write(&mut self.channel, self.request, buf, peri_addr, options) | 38 | Transfer::new_write(self.channel.reborrow(), self.request, buf, peri_addr, options) |
| 40 | } | 39 | } |
| 41 | 40 | ||
| 42 | pub unsafe fn write_raw<'a, MW: Word, PW: Word>( | 41 | pub unsafe fn write_raw<'a, MW: Word, PW: Word>( |
| @@ -45,7 +44,7 @@ impl<'d> ChannelAndRequest<'d> { | |||
| 45 | peri_addr: *mut PW, | 44 | peri_addr: *mut PW, |
| 46 | options: TransferOptions, | 45 | options: TransferOptions, |
| 47 | ) -> Transfer<'a> { | 46 | ) -> Transfer<'a> { |
| 48 | Transfer::new_write_raw(&mut self.channel, self.request, buf, peri_addr, options) | 47 | Transfer::new_write_raw(self.channel.reborrow(), self.request, buf, peri_addr, options) |
| 49 | } | 48 | } |
| 50 | 49 | ||
| 51 | #[allow(dead_code)] | 50 | #[allow(dead_code)] |
| @@ -56,6 +55,13 @@ impl<'d> ChannelAndRequest<'d> { | |||
| 56 | peri_addr: *mut W, | 55 | peri_addr: *mut W, |
| 57 | options: TransferOptions, | 56 | options: TransferOptions, |
| 58 | ) -> Transfer<'a> { | 57 | ) -> Transfer<'a> { |
| 59 | Transfer::new_write_repeated(&mut self.channel, self.request, repeated, count, peri_addr, options) | 58 | Transfer::new_write_repeated( |
| 59 | self.channel.reborrow(), | ||
| 60 | self.request, | ||
| 61 | repeated, | ||
| 62 | count, | ||
| 63 | peri_addr, | ||
| 64 | options, | ||
| 65 | ) | ||
| 60 | } | 66 | } |
| 61 | } | 67 | } |
diff --git a/embassy-stm32/src/dsihost.rs b/embassy-stm32/src/dsihost.rs index 77c3d95c3..e97ccd9d0 100644 --- a/embassy-stm32/src/dsihost.rs +++ b/embassy-stm32/src/dsihost.rs | |||
| @@ -2,12 +2,12 @@ | |||
| 2 | 2 | ||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | 4 | ||
| 5 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 5 | use embassy_hal_internal::PeripheralType; |
| 6 | 6 | ||
| 7 | //use crate::gpio::{AnyPin, SealedPin}; | 7 | //use crate::gpio::{AnyPin, SealedPin}; |
| 8 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; | 8 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; |
| 9 | use crate::rcc::{self, RccPeripheral}; | 9 | use crate::rcc::{self, RccPeripheral}; |
| 10 | use crate::{peripherals, Peripheral}; | 10 | use crate::{peripherals, Peri}; |
| 11 | 11 | ||
| 12 | /// Performs a busy-wait delay for a specified number of microseconds. | 12 | /// Performs a busy-wait delay for a specified number of microseconds. |
| 13 | pub fn blocking_delay_ms(ms: u32) { | 13 | pub fn blocking_delay_ms(ms: u32) { |
| @@ -69,14 +69,12 @@ impl From<PacketType> for u8 { | |||
| 69 | /// DSIHOST driver. | 69 | /// DSIHOST driver. |
| 70 | pub struct DsiHost<'d, T: Instance> { | 70 | pub struct DsiHost<'d, T: Instance> { |
| 71 | _peri: PhantomData<&'d mut T>, | 71 | _peri: PhantomData<&'d mut T>, |
| 72 | _te: PeripheralRef<'d, AnyPin>, | 72 | _te: Peri<'d, AnyPin>, |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | impl<'d, T: Instance> DsiHost<'d, T> { | 75 | impl<'d, T: Instance> DsiHost<'d, T> { |
| 76 | /// Note: Full-Duplex modes are not supported at this time | 76 | /// Note: Full-Duplex modes are not supported at this time |
| 77 | pub fn new(_peri: impl Peripheral<P = T> + 'd, te: impl Peripheral<P = impl TePin<T>> + 'd) -> Self { | 77 | pub fn new(_peri: Peri<'d, T>, te: Peri<'d, impl TePin<T>>) -> Self { |
| 78 | into_ref!(te); | ||
| 79 | |||
| 80 | rcc::enable_and_reset::<T>(); | 78 | rcc::enable_and_reset::<T>(); |
| 81 | 79 | ||
| 82 | // Set Tearing Enable pin according to CubeMx example | 80 | // Set Tearing Enable pin according to CubeMx example |
| @@ -88,7 +86,7 @@ impl<'d, T: Instance> DsiHost<'d, T> { | |||
| 88 | */ | 86 | */ |
| 89 | Self { | 87 | Self { |
| 90 | _peri: PhantomData, | 88 | _peri: PhantomData, |
| 91 | _te: te.map_into(), | 89 | _te: te.into(), |
| 92 | } | 90 | } |
| 93 | } | 91 | } |
| 94 | 92 | ||
| @@ -412,7 +410,7 @@ trait SealedInstance: crate::rcc::SealedRccPeripheral { | |||
| 412 | 410 | ||
| 413 | /// DSI instance trait. | 411 | /// DSI instance trait. |
| 414 | #[allow(private_bounds)] | 412 | #[allow(private_bounds)] |
| 415 | pub trait Instance: SealedInstance + RccPeripheral + 'static {} | 413 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + 'static {} |
| 416 | 414 | ||
| 417 | pin_trait!(TePin, Instance); | 415 | pin_trait!(TePin, Instance); |
| 418 | 416 | ||
diff --git a/embassy-stm32/src/dts/mod.rs b/embassy-stm32/src/dts/mod.rs index 58d7cf841..1f39c8db5 100644 --- a/embassy-stm32/src/dts/mod.rs +++ b/embassy-stm32/src/dts/mod.rs | |||
| @@ -4,13 +4,13 @@ use core::future::poll_fn; | |||
| 4 | use core::sync::atomic::{compiler_fence, Ordering}; | 4 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 5 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | 6 | ||
| 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 7 | use embassy_hal_internal::Peri; |
| 8 | use embassy_sync::waitqueue::AtomicWaker; | 8 | use embassy_sync::waitqueue::AtomicWaker; |
| 9 | 9 | ||
| 10 | use crate::interrupt::InterruptExt; | 10 | use crate::interrupt::InterruptExt; |
| 11 | use crate::peripherals::DTS; | 11 | use crate::peripherals::DTS; |
| 12 | use crate::time::Hertz; | 12 | use crate::time::Hertz; |
| 13 | use crate::{interrupt, pac, rcc, Peripheral}; | 13 | use crate::{interrupt, pac, rcc}; |
| 14 | 14 | ||
| 15 | mod tsel; | 15 | mod tsel; |
| 16 | pub use tsel::TriggerSel; | 16 | pub use tsel::TriggerSel; |
| @@ -72,7 +72,7 @@ const MAX_DTS_CLK_FREQ: Hertz = Hertz::mhz(1); | |||
| 72 | 72 | ||
| 73 | /// Digital temperature sensor driver. | 73 | /// Digital temperature sensor driver. |
| 74 | pub struct Dts<'d> { | 74 | pub struct Dts<'d> { |
| 75 | _peri: PeripheralRef<'d, DTS>, | 75 | _peri: Peri<'d, DTS>, |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | static WAKER: AtomicWaker = AtomicWaker::new(); | 78 | static WAKER: AtomicWaker = AtomicWaker::new(); |
| @@ -80,11 +80,10 @@ static WAKER: AtomicWaker = AtomicWaker::new(); | |||
| 80 | impl<'d> Dts<'d> { | 80 | impl<'d> Dts<'d> { |
| 81 | /// Create a new temperature sensor driver. | 81 | /// Create a new temperature sensor driver. |
| 82 | pub fn new( | 82 | pub fn new( |
| 83 | _peri: impl Peripheral<P = DTS> + 'd, | 83 | _peri: Peri<'d, DTS>, |
| 84 | _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::DTS, InterruptHandler> + 'd, | 84 | _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::DTS, InterruptHandler> + 'd, |
| 85 | config: Config, | 85 | config: Config, |
| 86 | ) -> Self { | 86 | ) -> Self { |
| 87 | into_ref!(_peri); | ||
| 88 | rcc::enable_and_reset::<DTS>(); | 87 | rcc::enable_and_reset::<DTS>(); |
| 89 | 88 | ||
| 90 | let prescaler = rcc::frequency::<DTS>() / MAX_DTS_CLK_FREQ; | 89 | let prescaler = rcc::frequency::<DTS>() / MAX_DTS_CLK_FREQ; |
diff --git a/embassy-stm32/src/eth/mod.rs b/embassy-stm32/src/eth/mod.rs index 109ceeeb3..97d7b4347 100644 --- a/embassy-stm32/src/eth/mod.rs +++ b/embassy-stm32/src/eth/mod.rs | |||
| @@ -9,6 +9,7 @@ mod generic_phy; | |||
| 9 | use core::mem::MaybeUninit; | 9 | use core::mem::MaybeUninit; |
| 10 | use core::task::Context; | 10 | use core::task::Context; |
| 11 | 11 | ||
| 12 | use embassy_hal_internal::PeripheralType; | ||
| 12 | use embassy_net_driver::{Capabilities, HardwareAddress, LinkState}; | 13 | use embassy_net_driver::{Capabilities, HardwareAddress, LinkState}; |
| 13 | use embassy_sync::waitqueue::AtomicWaker; | 14 | use embassy_sync::waitqueue::AtomicWaker; |
| 14 | 15 | ||
| @@ -199,7 +200,7 @@ trait SealedInstance { | |||
| 199 | 200 | ||
| 200 | /// Ethernet instance. | 201 | /// Ethernet instance. |
| 201 | #[allow(private_bounds)] | 202 | #[allow(private_bounds)] |
| 202 | pub trait Instance: SealedInstance + RccPeripheral + Send + 'static {} | 203 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + Send + 'static {} |
| 203 | 204 | ||
| 204 | impl SealedInstance for crate::peripherals::ETH { | 205 | impl SealedInstance for crate::peripherals::ETH { |
| 205 | fn regs() -> crate::pac::eth::Eth { | 206 | fn regs() -> crate::pac::eth::Eth { |
diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index e12ac2fef..640191d69 100644 --- a/embassy-stm32/src/eth/v1/mod.rs +++ b/embassy-stm32/src/eth/v1/mod.rs | |||
| @@ -6,7 +6,7 @@ mod tx_desc; | |||
| 6 | use core::marker::PhantomData; | 6 | use core::marker::PhantomData; |
| 7 | use core::sync::atomic::{fence, Ordering}; | 7 | use core::sync::atomic::{fence, Ordering}; |
| 8 | 8 | ||
| 9 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 9 | use embassy_hal_internal::Peri; |
| 10 | use stm32_metapac::eth::vals::{Apcs, Cr, Dm, DmaomrSr, Fes, Ftf, Ifg, MbProgress, Mw, Pbl, Rsf, St, Tsf}; | 10 | use stm32_metapac::eth::vals::{Apcs, Cr, Dm, DmaomrSr, Fes, Ftf, Ifg, MbProgress, Mw, Pbl, Rsf, St, Tsf}; |
| 11 | 11 | ||
| 12 | pub(crate) use self::rx_desc::{RDes, RDesRing}; | 12 | pub(crate) use self::rx_desc::{RDes, RDesRing}; |
| @@ -15,6 +15,7 @@ use super::*; | |||
| 15 | #[cfg(eth_v1a)] | 15 | #[cfg(eth_v1a)] |
| 16 | use crate::gpio::Pull; | 16 | use crate::gpio::Pull; |
| 17 | use crate::gpio::{AfType, AnyPin, OutputType, SealedPin, Speed}; | 17 | use crate::gpio::{AfType, AnyPin, OutputType, SealedPin, Speed}; |
| 18 | use crate::interrupt; | ||
| 18 | use crate::interrupt::InterruptExt; | 19 | use crate::interrupt::InterruptExt; |
| 19 | #[cfg(eth_v1a)] | 20 | #[cfg(eth_v1a)] |
| 20 | use crate::pac::AFIO; | 21 | use crate::pac::AFIO; |
| @@ -22,7 +23,6 @@ use crate::pac::AFIO; | |||
| 22 | use crate::pac::SYSCFG; | 23 | use crate::pac::SYSCFG; |
| 23 | use crate::pac::{ETH, RCC}; | 24 | use crate::pac::{ETH, RCC}; |
| 24 | use crate::rcc::SealedRccPeripheral; | 25 | use crate::rcc::SealedRccPeripheral; |
| 25 | use crate::{interrupt, Peripheral}; | ||
| 26 | 26 | ||
| 27 | /// Interrupt handler. | 27 | /// Interrupt handler. |
| 28 | pub struct InterruptHandler {} | 28 | pub struct InterruptHandler {} |
| @@ -47,11 +47,11 @@ impl interrupt::typelevel::Handler<interrupt::typelevel::ETH> for InterruptHandl | |||
| 47 | 47 | ||
| 48 | /// Ethernet driver. | 48 | /// Ethernet driver. |
| 49 | pub struct Ethernet<'d, T: Instance, P: Phy> { | 49 | pub struct Ethernet<'d, T: Instance, P: Phy> { |
| 50 | _peri: PeripheralRef<'d, T>, | 50 | _peri: Peri<'d, T>, |
| 51 | pub(crate) tx: TDesRing<'d>, | 51 | pub(crate) tx: TDesRing<'d>, |
| 52 | pub(crate) rx: RDesRing<'d>, | 52 | pub(crate) rx: RDesRing<'d>, |
| 53 | 53 | ||
| 54 | pins: [PeripheralRef<'d, AnyPin>; 9], | 54 | pins: [Peri<'d, AnyPin>; 9], |
| 55 | pub(crate) phy: P, | 55 | pub(crate) phy: P, |
| 56 | pub(crate) station_management: EthernetStationManagement<T>, | 56 | pub(crate) station_management: EthernetStationManagement<T>, |
| 57 | pub(crate) mac_addr: [u8; 6], | 57 | pub(crate) mac_addr: [u8; 6], |
| @@ -95,22 +95,20 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 95 | /// safety: the returned instance is not leak-safe | 95 | /// safety: the returned instance is not leak-safe |
| 96 | pub fn new<const TX: usize, const RX: usize>( | 96 | pub fn new<const TX: usize, const RX: usize>( |
| 97 | queue: &'d mut PacketQueue<TX, RX>, | 97 | queue: &'d mut PacketQueue<TX, RX>, |
| 98 | peri: impl Peripheral<P = T> + 'd, | 98 | peri: Peri<'d, T>, |
| 99 | _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, | 99 | _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, |
| 100 | ref_clk: impl Peripheral<P = impl RefClkPin<T>> + 'd, | 100 | ref_clk: Peri<'d, impl RefClkPin<T>>, |
| 101 | mdio: impl Peripheral<P = impl MDIOPin<T>> + 'd, | 101 | mdio: Peri<'d, impl MDIOPin<T>>, |
| 102 | mdc: impl Peripheral<P = impl MDCPin<T>> + 'd, | 102 | mdc: Peri<'d, impl MDCPin<T>>, |
| 103 | crs: impl Peripheral<P = impl CRSPin<T>> + 'd, | 103 | crs: Peri<'d, impl CRSPin<T>>, |
| 104 | rx_d0: impl Peripheral<P = impl RXD0Pin<T>> + 'd, | 104 | rx_d0: Peri<'d, impl RXD0Pin<T>>, |
| 105 | rx_d1: impl Peripheral<P = impl RXD1Pin<T>> + 'd, | 105 | rx_d1: Peri<'d, impl RXD1Pin<T>>, |
| 106 | tx_d0: impl Peripheral<P = impl TXD0Pin<T>> + 'd, | 106 | tx_d0: Peri<'d, impl TXD0Pin<T>>, |
| 107 | tx_d1: impl Peripheral<P = impl TXD1Pin<T>> + 'd, | 107 | tx_d1: Peri<'d, impl TXD1Pin<T>>, |
| 108 | tx_en: impl Peripheral<P = impl TXEnPin<T>> + 'd, | 108 | tx_en: Peri<'d, impl TXEnPin<T>>, |
| 109 | phy: P, | 109 | phy: P, |
| 110 | mac_addr: [u8; 6], | 110 | mac_addr: [u8; 6], |
| 111 | ) -> Self { | 111 | ) -> Self { |
| 112 | into_ref!(peri, ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); | ||
| 113 | |||
| 114 | // Enable the necessary Clocks | 112 | // Enable the necessary Clocks |
| 115 | #[cfg(eth_v1a)] | 113 | #[cfg(eth_v1a)] |
| 116 | critical_section::with(|_| { | 114 | critical_section::with(|_| { |
| @@ -213,15 +211,15 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 213 | }; | 211 | }; |
| 214 | 212 | ||
| 215 | let pins = [ | 213 | let pins = [ |
| 216 | ref_clk.map_into(), | 214 | ref_clk.into(), |
| 217 | mdio.map_into(), | 215 | mdio.into(), |
| 218 | mdc.map_into(), | 216 | mdc.into(), |
| 219 | crs.map_into(), | 217 | crs.into(), |
| 220 | rx_d0.map_into(), | 218 | rx_d0.into(), |
| 221 | rx_d1.map_into(), | 219 | rx_d1.into(), |
| 222 | tx_d0.map_into(), | 220 | tx_d0.into(), |
| 223 | tx_d1.map_into(), | 221 | tx_d1.into(), |
| 224 | tx_en.map_into(), | 222 | tx_en.into(), |
| 225 | ]; | 223 | ]; |
| 226 | 224 | ||
| 227 | let mut this = Self { | 225 | let mut this = Self { |
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index 26e4eeb63..034c5dd88 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs | |||
| @@ -3,16 +3,16 @@ mod descriptors; | |||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | use core::sync::atomic::{fence, Ordering}; | 4 | use core::sync::atomic::{fence, Ordering}; |
| 5 | 5 | ||
| 6 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 6 | use embassy_hal_internal::Peri; |
| 7 | use stm32_metapac::syscfg::vals::EthSelPhy; | 7 | use stm32_metapac::syscfg::vals::EthSelPhy; |
| 8 | 8 | ||
| 9 | pub(crate) use self::descriptors::{RDes, RDesRing, TDes, TDesRing}; | 9 | pub(crate) use self::descriptors::{RDes, RDesRing, TDes, TDesRing}; |
| 10 | use super::*; | 10 | use super::*; |
| 11 | use crate::gpio::{AfType, AnyPin, OutputType, SealedPin as _, Speed}; | 11 | use crate::gpio::{AfType, AnyPin, OutputType, SealedPin as _, Speed}; |
| 12 | use crate::interrupt; | ||
| 12 | use crate::interrupt::InterruptExt; | 13 | use crate::interrupt::InterruptExt; |
| 13 | use crate::pac::ETH; | 14 | use crate::pac::ETH; |
| 14 | use crate::rcc::SealedRccPeripheral; | 15 | use crate::rcc::SealedRccPeripheral; |
| 15 | use crate::{interrupt, Peripheral}; | ||
| 16 | 16 | ||
| 17 | /// Interrupt handler. | 17 | /// Interrupt handler. |
| 18 | pub struct InterruptHandler {} | 18 | pub struct InterruptHandler {} |
| @@ -37,7 +37,7 @@ impl interrupt::typelevel::Handler<interrupt::typelevel::ETH> for InterruptHandl | |||
| 37 | 37 | ||
| 38 | /// Ethernet driver. | 38 | /// Ethernet driver. |
| 39 | pub struct Ethernet<'d, T: Instance, P: Phy> { | 39 | pub struct Ethernet<'d, T: Instance, P: Phy> { |
| 40 | _peri: PeripheralRef<'d, T>, | 40 | _peri: Peri<'d, T>, |
| 41 | pub(crate) tx: TDesRing<'d>, | 41 | pub(crate) tx: TDesRing<'d>, |
| 42 | pub(crate) rx: RDesRing<'d>, | 42 | pub(crate) rx: RDesRing<'d>, |
| 43 | pins: Pins<'d>, | 43 | pins: Pins<'d>, |
| @@ -48,8 +48,8 @@ pub struct Ethernet<'d, T: Instance, P: Phy> { | |||
| 48 | 48 | ||
| 49 | /// Pins of ethernet driver. | 49 | /// Pins of ethernet driver. |
| 50 | enum Pins<'d> { | 50 | enum Pins<'d> { |
| 51 | Rmii([PeripheralRef<'d, AnyPin>; 9]), | 51 | Rmii([Peri<'d, AnyPin>; 9]), |
| 52 | Mii([PeripheralRef<'d, AnyPin>; 14]), | 52 | Mii([Peri<'d, AnyPin>; 14]), |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | macro_rules! config_pins { | 55 | macro_rules! config_pins { |
| @@ -67,17 +67,17 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 67 | /// Create a new RMII ethernet driver using 9 pins. | 67 | /// Create a new RMII ethernet driver using 9 pins. |
| 68 | pub fn new<const TX: usize, const RX: usize>( | 68 | pub fn new<const TX: usize, const RX: usize>( |
| 69 | queue: &'d mut PacketQueue<TX, RX>, | 69 | queue: &'d mut PacketQueue<TX, RX>, |
| 70 | peri: impl Peripheral<P = T> + 'd, | 70 | peri: Peri<'d, T>, |
| 71 | irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, | 71 | irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, |
| 72 | ref_clk: impl Peripheral<P = impl RefClkPin<T>> + 'd, | 72 | ref_clk: Peri<'d, impl RefClkPin<T>>, |
| 73 | mdio: impl Peripheral<P = impl MDIOPin<T>> + 'd, | 73 | mdio: Peri<'d, impl MDIOPin<T>>, |
| 74 | mdc: impl Peripheral<P = impl MDCPin<T>> + 'd, | 74 | mdc: Peri<'d, impl MDCPin<T>>, |
| 75 | crs: impl Peripheral<P = impl CRSPin<T>> + 'd, | 75 | crs: Peri<'d, impl CRSPin<T>>, |
| 76 | rx_d0: impl Peripheral<P = impl RXD0Pin<T>> + 'd, | 76 | rx_d0: Peri<'d, impl RXD0Pin<T>>, |
| 77 | rx_d1: impl Peripheral<P = impl RXD1Pin<T>> + 'd, | 77 | rx_d1: Peri<'d, impl RXD1Pin<T>>, |
| 78 | tx_d0: impl Peripheral<P = impl TXD0Pin<T>> + 'd, | 78 | tx_d0: Peri<'d, impl TXD0Pin<T>>, |
| 79 | tx_d1: impl Peripheral<P = impl TXD1Pin<T>> + 'd, | 79 | tx_d1: Peri<'d, impl TXD1Pin<T>>, |
| 80 | tx_en: impl Peripheral<P = impl TXEnPin<T>> + 'd, | 80 | tx_en: Peri<'d, impl TXEnPin<T>>, |
| 81 | phy: P, | 81 | phy: P, |
| 82 | mac_addr: [u8; 6], | 82 | mac_addr: [u8; 6], |
| 83 | ) -> Self { | 83 | ) -> Self { |
| @@ -92,19 +92,18 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 92 | crate::pac::SYSCFG.pmcr().modify(|w| w.set_eth_sel_phy(EthSelPhy::RMII)); | 92 | crate::pac::SYSCFG.pmcr().modify(|w| w.set_eth_sel_phy(EthSelPhy::RMII)); |
| 93 | }); | 93 | }); |
| 94 | 94 | ||
| 95 | into_ref!(ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); | ||
| 96 | config_pins!(ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); | 95 | config_pins!(ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); |
| 97 | 96 | ||
| 98 | let pins = Pins::Rmii([ | 97 | let pins = Pins::Rmii([ |
| 99 | ref_clk.map_into(), | 98 | ref_clk.into(), |
| 100 | mdio.map_into(), | 99 | mdio.into(), |
| 101 | mdc.map_into(), | 100 | mdc.into(), |
| 102 | crs.map_into(), | 101 | crs.into(), |
| 103 | rx_d0.map_into(), | 102 | rx_d0.into(), |
| 104 | rx_d1.map_into(), | 103 | rx_d1.into(), |
| 105 | tx_d0.map_into(), | 104 | tx_d0.into(), |
| 106 | tx_d1.map_into(), | 105 | tx_d1.into(), |
| 107 | tx_en.map_into(), | 106 | tx_en.into(), |
| 108 | ]); | 107 | ]); |
| 109 | 108 | ||
| 110 | Self::new_inner(queue, peri, irq, pins, phy, mac_addr) | 109 | Self::new_inner(queue, peri, irq, pins, phy, mac_addr) |
| @@ -113,22 +112,22 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 113 | /// Create a new MII ethernet driver using 14 pins. | 112 | /// Create a new MII ethernet driver using 14 pins. |
| 114 | pub fn new_mii<const TX: usize, const RX: usize>( | 113 | pub fn new_mii<const TX: usize, const RX: usize>( |
| 115 | queue: &'d mut PacketQueue<TX, RX>, | 114 | queue: &'d mut PacketQueue<TX, RX>, |
| 116 | peri: impl Peripheral<P = T> + 'd, | 115 | peri: Peri<'d, T>, |
| 117 | irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, | 116 | irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, |
| 118 | rx_clk: impl Peripheral<P = impl RXClkPin<T>> + 'd, | 117 | rx_clk: Peri<'d, impl RXClkPin<T>>, |
| 119 | tx_clk: impl Peripheral<P = impl TXClkPin<T>> + 'd, | 118 | tx_clk: Peri<'d, impl TXClkPin<T>>, |
| 120 | mdio: impl Peripheral<P = impl MDIOPin<T>> + 'd, | 119 | mdio: Peri<'d, impl MDIOPin<T>>, |
| 121 | mdc: impl Peripheral<P = impl MDCPin<T>> + 'd, | 120 | mdc: Peri<'d, impl MDCPin<T>>, |
| 122 | rxdv: impl Peripheral<P = impl RXDVPin<T>> + 'd, | 121 | rxdv: Peri<'d, impl RXDVPin<T>>, |
| 123 | rx_d0: impl Peripheral<P = impl RXD0Pin<T>> + 'd, | 122 | rx_d0: Peri<'d, impl RXD0Pin<T>>, |
| 124 | rx_d1: impl Peripheral<P = impl RXD1Pin<T>> + 'd, | 123 | rx_d1: Peri<'d, impl RXD1Pin<T>>, |
| 125 | rx_d2: impl Peripheral<P = impl RXD2Pin<T>> + 'd, | 124 | rx_d2: Peri<'d, impl RXD2Pin<T>>, |
| 126 | rx_d3: impl Peripheral<P = impl RXD3Pin<T>> + 'd, | 125 | rx_d3: Peri<'d, impl RXD3Pin<T>>, |
| 127 | tx_d0: impl Peripheral<P = impl TXD0Pin<T>> + 'd, | 126 | tx_d0: Peri<'d, impl TXD0Pin<T>>, |
| 128 | tx_d1: impl Peripheral<P = impl TXD1Pin<T>> + 'd, | 127 | tx_d1: Peri<'d, impl TXD1Pin<T>>, |
| 129 | tx_d2: impl Peripheral<P = impl TXD2Pin<T>> + 'd, | 128 | tx_d2: Peri<'d, impl TXD2Pin<T>>, |
| 130 | tx_d3: impl Peripheral<P = impl TXD3Pin<T>> + 'd, | 129 | tx_d3: Peri<'d, impl TXD3Pin<T>>, |
| 131 | tx_en: impl Peripheral<P = impl TXEnPin<T>> + 'd, | 130 | tx_en: Peri<'d, impl TXEnPin<T>>, |
| 132 | phy: P, | 131 | phy: P, |
| 133 | mac_addr: [u8; 6], | 132 | mac_addr: [u8; 6], |
| 134 | ) -> Self { | 133 | ) -> Self { |
| @@ -145,24 +144,23 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 145 | .modify(|w| w.set_eth_sel_phy(EthSelPhy::MII_GMII)); | 144 | .modify(|w| w.set_eth_sel_phy(EthSelPhy::MII_GMII)); |
| 146 | }); | 145 | }); |
| 147 | 146 | ||
| 148 | into_ref!(rx_clk, tx_clk, mdio, mdc, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en); | ||
| 149 | config_pins!(rx_clk, tx_clk, mdio, mdc, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en); | 147 | config_pins!(rx_clk, tx_clk, mdio, mdc, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en); |
| 150 | 148 | ||
| 151 | let pins = Pins::Mii([ | 149 | let pins = Pins::Mii([ |
| 152 | rx_clk.map_into(), | 150 | rx_clk.into(), |
| 153 | tx_clk.map_into(), | 151 | tx_clk.into(), |
| 154 | mdio.map_into(), | 152 | mdio.into(), |
| 155 | mdc.map_into(), | 153 | mdc.into(), |
| 156 | rxdv.map_into(), | 154 | rxdv.into(), |
| 157 | rx_d0.map_into(), | 155 | rx_d0.into(), |
| 158 | rx_d1.map_into(), | 156 | rx_d1.into(), |
| 159 | rx_d2.map_into(), | 157 | rx_d2.into(), |
| 160 | rx_d3.map_into(), | 158 | rx_d3.into(), |
| 161 | tx_d0.map_into(), | 159 | tx_d0.into(), |
| 162 | tx_d1.map_into(), | 160 | tx_d1.into(), |
| 163 | tx_d2.map_into(), | 161 | tx_d2.into(), |
| 164 | tx_d3.map_into(), | 162 | tx_d3.into(), |
| 165 | tx_en.map_into(), | 163 | tx_en.into(), |
| 166 | ]); | 164 | ]); |
| 167 | 165 | ||
| 168 | Self::new_inner(queue, peri, irq, pins, phy, mac_addr) | 166 | Self::new_inner(queue, peri, irq, pins, phy, mac_addr) |
| @@ -170,7 +168,7 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 170 | 168 | ||
| 171 | fn new_inner<const TX: usize, const RX: usize>( | 169 | fn new_inner<const TX: usize, const RX: usize>( |
| 172 | queue: &'d mut PacketQueue<TX, RX>, | 170 | queue: &'d mut PacketQueue<TX, RX>, |
| 173 | peri: impl Peripheral<P = T> + 'd, | 171 | peri: Peri<'d, T>, |
| 174 | _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, | 172 | _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, |
| 175 | pins: Pins<'d>, | 173 | pins: Pins<'d>, |
| 176 | phy: P, | 174 | phy: P, |
| @@ -254,7 +252,7 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 254 | }; | 252 | }; |
| 255 | 253 | ||
| 256 | let mut this = Self { | 254 | let mut this = Self { |
| 257 | _peri: peri.into_ref(), | 255 | _peri: peri, |
| 258 | tx: TDesRing::new(&mut queue.tx_desc, &mut queue.tx_buf), | 256 | tx: TDesRing::new(&mut queue.tx_desc, &mut queue.tx_buf), |
| 259 | rx: RDesRing::new(&mut queue.rx_desc, &mut queue.rx_buf), | 257 | rx: RDesRing::new(&mut queue.rx_desc, &mut queue.rx_buf), |
| 260 | pins, | 258 | pins, |
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index 9604c5149..9fce78f95 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs | |||
| @@ -5,13 +5,13 @@ use core::marker::PhantomData; | |||
| 5 | use core::pin::Pin; | 5 | use core::pin::Pin; |
| 6 | use core::task::{Context, Poll}; | 6 | use core::task::{Context, Poll}; |
| 7 | 7 | ||
| 8 | use embassy_hal_internal::{impl_peripheral, into_ref}; | 8 | use embassy_hal_internal::{impl_peripheral, PeripheralType}; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | 10 | ||
| 11 | use crate::gpio::{AnyPin, Input, Level, Pin as GpioPin, Pull}; | 11 | use crate::gpio::{AnyPin, Input, Level, Pin as GpioPin, Pull}; |
| 12 | use crate::pac::exti::regs::Lines; | 12 | use crate::pac::exti::regs::Lines; |
| 13 | use crate::pac::EXTI; | 13 | use crate::pac::EXTI; |
| 14 | use crate::{interrupt, pac, peripherals, Peripheral}; | 14 | use crate::{interrupt, pac, peripherals, Peri}; |
| 15 | 15 | ||
| 16 | const EXTI_COUNT: usize = 16; | 16 | const EXTI_COUNT: usize = 16; |
| 17 | static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [const { AtomicWaker::new() }; EXTI_COUNT]; | 17 | static EXTI_WAKERS: [AtomicWaker; EXTI_COUNT] = [const { AtomicWaker::new() }; EXTI_COUNT]; |
| @@ -105,13 +105,7 @@ impl<'d> Unpin for ExtiInput<'d> {} | |||
| 105 | 105 | ||
| 106 | impl<'d> ExtiInput<'d> { | 106 | impl<'d> ExtiInput<'d> { |
| 107 | /// Create an EXTI input. | 107 | /// Create an EXTI input. |
| 108 | pub fn new<T: GpioPin>( | 108 | pub fn new<T: GpioPin>(pin: Peri<'d, T>, ch: Peri<'d, T::ExtiChannel>, pull: Pull) -> Self { |
| 109 | pin: impl Peripheral<P = T> + 'd, | ||
| 110 | ch: impl Peripheral<P = T::ExtiChannel> + 'd, | ||
| 111 | pull: Pull, | ||
| 112 | ) -> Self { | ||
| 113 | into_ref!(pin, ch); | ||
| 114 | |||
| 115 | // Needed if using AnyPin+AnyChannel. | 109 | // Needed if using AnyPin+AnyChannel. |
| 116 | assert_eq!(pin.pin(), ch.number()); | 110 | assert_eq!(pin.pin(), ch.number()); |
| 117 | 111 | ||
| @@ -338,23 +332,12 @@ trait SealedChannel {} | |||
| 338 | 332 | ||
| 339 | /// EXTI channel trait. | 333 | /// EXTI channel trait. |
| 340 | #[allow(private_bounds)] | 334 | #[allow(private_bounds)] |
| 341 | pub trait Channel: SealedChannel + Sized { | 335 | pub trait Channel: PeripheralType + SealedChannel + Sized { |
| 342 | /// Get the EXTI channel number. | 336 | /// Get the EXTI channel number. |
| 343 | fn number(&self) -> u8; | 337 | fn number(&self) -> u8; |
| 344 | |||
| 345 | /// Type-erase (degrade) this channel into an `AnyChannel`. | ||
| 346 | /// | ||
| 347 | /// This converts EXTI channel singletons (`EXTI0`, `EXTI1`, ...), which | ||
| 348 | /// are all different types, into the same type. It is useful for | ||
| 349 | /// creating arrays of channels, or avoiding generics. | ||
| 350 | fn degrade(self) -> AnyChannel { | ||
| 351 | AnyChannel { | ||
| 352 | number: self.number() as u8, | ||
| 353 | } | ||
| 354 | } | ||
| 355 | } | 338 | } |
| 356 | 339 | ||
| 357 | /// Type-erased (degraded) EXTI channel. | 340 | /// Type-erased EXTI channel. |
| 358 | /// | 341 | /// |
| 359 | /// This represents ownership over any EXTI channel, known at runtime. | 342 | /// This represents ownership over any EXTI channel, known at runtime. |
| 360 | pub struct AnyChannel { | 343 | pub struct AnyChannel { |
| @@ -377,6 +360,14 @@ macro_rules! impl_exti { | |||
| 377 | $number | 360 | $number |
| 378 | } | 361 | } |
| 379 | } | 362 | } |
| 363 | |||
| 364 | impl From<peripherals::$type> for AnyChannel { | ||
| 365 | fn from(val: peripherals::$type) -> Self { | ||
| 366 | Self { | ||
| 367 | number: val.number() as u8, | ||
| 368 | } | ||
| 369 | } | ||
| 370 | } | ||
| 380 | }; | 371 | }; |
| 381 | } | 372 | } |
| 382 | 373 | ||
diff --git a/embassy-stm32/src/flash/asynch.rs b/embassy-stm32/src/flash/asynch.rs index 9468ac632..599b7bb4e 100644 --- a/embassy-stm32/src/flash/asynch.rs +++ b/embassy-stm32/src/flash/asynch.rs | |||
| @@ -2,7 +2,6 @@ use core::marker::PhantomData; | |||
| 2 | use core::sync::atomic::{fence, Ordering}; | 2 | use core::sync::atomic::{fence, Ordering}; |
| 3 | 3 | ||
| 4 | use embassy_hal_internal::drop::OnDrop; | 4 | use embassy_hal_internal::drop::OnDrop; |
| 5 | use embassy_hal_internal::into_ref; | ||
| 6 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | 5 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; |
| 7 | use embassy_sync::mutex::Mutex; | 6 | use embassy_sync::mutex::Mutex; |
| 8 | 7 | ||
| @@ -12,18 +11,16 @@ use super::{ | |||
| 12 | }; | 11 | }; |
| 13 | use crate::interrupt::InterruptExt; | 12 | use crate::interrupt::InterruptExt; |
| 14 | use crate::peripherals::FLASH; | 13 | use crate::peripherals::FLASH; |
| 15 | use crate::{interrupt, Peripheral}; | 14 | use crate::{interrupt, Peri}; |
| 16 | 15 | ||
| 17 | pub(super) static REGION_ACCESS: Mutex<CriticalSectionRawMutex, ()> = Mutex::new(()); | 16 | pub(super) static REGION_ACCESS: Mutex<CriticalSectionRawMutex, ()> = Mutex::new(()); |
| 18 | 17 | ||
| 19 | impl<'d> Flash<'d, Async> { | 18 | impl<'d> Flash<'d, Async> { |
| 20 | /// Create a new flash driver with async capabilities. | 19 | /// Create a new flash driver with async capabilities. |
| 21 | pub fn new( | 20 | pub fn new( |
| 22 | p: impl Peripheral<P = FLASH> + 'd, | 21 | p: Peri<'d, FLASH>, |
| 23 | _irq: impl interrupt::typelevel::Binding<crate::interrupt::typelevel::FLASH, InterruptHandler> + 'd, | 22 | _irq: impl interrupt::typelevel::Binding<crate::interrupt::typelevel::FLASH, InterruptHandler> + 'd, |
| 24 | ) -> Self { | 23 | ) -> Self { |
| 25 | into_ref!(p); | ||
| 26 | |||
| 27 | crate::interrupt::FLASH.unpend(); | 24 | crate::interrupt::FLASH.unpend(); |
| 28 | unsafe { crate::interrupt::FLASH.enable() }; | 25 | unsafe { crate::interrupt::FLASH.enable() }; |
| 29 | 26 | ||
diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs index 0004a7488..1376ca4b4 100644 --- a/embassy-stm32/src/flash/common.rs +++ b/embassy-stm32/src/flash/common.rs | |||
| @@ -2,27 +2,24 @@ use core::marker::PhantomData; | |||
| 2 | use core::sync::atomic::{fence, Ordering}; | 2 | use core::sync::atomic::{fence, Ordering}; |
| 3 | 3 | ||
| 4 | use embassy_hal_internal::drop::OnDrop; | 4 | use embassy_hal_internal::drop::OnDrop; |
| 5 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 6 | 5 | ||
| 7 | use super::{ | 6 | use super::{ |
| 8 | family, Async, Blocking, Error, FlashBank, FlashLayout, FlashRegion, FlashSector, FLASH_SIZE, MAX_ERASE_SIZE, | 7 | family, Async, Blocking, Error, FlashBank, FlashLayout, FlashRegion, FlashSector, FLASH_SIZE, MAX_ERASE_SIZE, |
| 9 | READ_SIZE, WRITE_SIZE, | 8 | READ_SIZE, WRITE_SIZE, |
| 10 | }; | 9 | }; |
| 10 | use crate::Peri; | ||
| 11 | use crate::_generated::FLASH_BASE; | 11 | use crate::_generated::FLASH_BASE; |
| 12 | use crate::peripherals::FLASH; | 12 | use crate::peripherals::FLASH; |
| 13 | use crate::Peripheral; | ||
| 14 | 13 | ||
| 15 | /// Internal flash memory driver. | 14 | /// Internal flash memory driver. |
| 16 | pub struct Flash<'d, MODE = Async> { | 15 | pub struct Flash<'d, MODE = Async> { |
| 17 | pub(crate) inner: PeripheralRef<'d, FLASH>, | 16 | pub(crate) inner: Peri<'d, FLASH>, |
| 18 | pub(crate) _mode: PhantomData<MODE>, | 17 | pub(crate) _mode: PhantomData<MODE>, |
| 19 | } | 18 | } |
| 20 | 19 | ||
| 21 | impl<'d> Flash<'d, Blocking> { | 20 | impl<'d> Flash<'d, Blocking> { |
| 22 | /// Create a new flash driver, usable in blocking mode. | 21 | /// Create a new flash driver, usable in blocking mode. |
| 23 | pub fn new_blocking(p: impl Peripheral<P = FLASH> + 'd) -> Self { | 22 | pub fn new_blocking(p: Peri<'d, FLASH>) -> Self { |
| 24 | into_ref!(p); | ||
| 25 | |||
| 26 | Self { | 23 | Self { |
| 27 | inner: p, | 24 | inner: p, |
| 28 | _mode: PhantomData, | 25 | _mode: PhantomData, |
diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs index 86afdce8a..687eabaeb 100644 --- a/embassy-stm32/src/flash/f4.rs +++ b/embassy-stm32/src/flash/f4.rs | |||
| @@ -13,8 +13,7 @@ use crate::pac; | |||
| 13 | mod alt_regions { | 13 | mod alt_regions { |
| 14 | use core::marker::PhantomData; | 14 | use core::marker::PhantomData; |
| 15 | 15 | ||
| 16 | use embassy_hal_internal::PeripheralRef; | 16 | use crate::Peri; |
| 17 | |||
| 18 | use crate::_generated::flash_regions::{OTPRegion, BANK1_REGION1, BANK1_REGION2, BANK1_REGION3, OTP_REGION}; | 17 | use crate::_generated::flash_regions::{OTPRegion, BANK1_REGION1, BANK1_REGION2, BANK1_REGION3, OTP_REGION}; |
| 19 | use crate::_generated::FLASH_SIZE; | 18 | use crate::_generated::FLASH_SIZE; |
| 20 | use crate::flash::{asynch, Async, Bank1Region1, Bank1Region2, Blocking, Error, Flash, FlashBank, FlashRegion}; | 19 | use crate::flash::{asynch, Async, Bank1Region1, Bank1Region2, Blocking, Error, Flash, FlashBank, FlashRegion}; |
| @@ -50,10 +49,10 @@ mod alt_regions { | |||
| 50 | &ALT_BANK2_REGION3, | 49 | &ALT_BANK2_REGION3, |
| 51 | ]; | 50 | ]; |
| 52 | 51 | ||
| 53 | pub struct AltBank1Region3<'d, MODE = Async>(pub &'static FlashRegion, PeripheralRef<'d, FLASH>, PhantomData<MODE>); | 52 | pub struct AltBank1Region3<'d, MODE = Async>(pub &'static FlashRegion, Peri<'d, FLASH>, PhantomData<MODE>); |
| 54 | pub struct AltBank2Region1<'d, MODE = Async>(pub &'static FlashRegion, PeripheralRef<'d, FLASH>, PhantomData<MODE>); | 53 | pub struct AltBank2Region1<'d, MODE = Async>(pub &'static FlashRegion, Peri<'d, FLASH>, PhantomData<MODE>); |
| 55 | pub struct AltBank2Region2<'d, MODE = Async>(pub &'static FlashRegion, PeripheralRef<'d, FLASH>, PhantomData<MODE>); | 54 | pub struct AltBank2Region2<'d, MODE = Async>(pub &'static FlashRegion, Peri<'d, FLASH>, PhantomData<MODE>); |
| 56 | pub struct AltBank2Region3<'d, MODE = Async>(pub &'static FlashRegion, PeripheralRef<'d, FLASH>, PhantomData<MODE>); | 55 | pub struct AltBank2Region3<'d, MODE = Async>(pub &'static FlashRegion, Peri<'d, FLASH>, PhantomData<MODE>); |
| 57 | 56 | ||
| 58 | pub struct AltFlashLayout<'d, MODE = Async> { | 57 | pub struct AltFlashLayout<'d, MODE = Async> { |
| 59 | pub bank1_region1: Bank1Region1<'d, MODE>, | 58 | pub bank1_region1: Bank1Region1<'d, MODE>, |
diff --git a/embassy-stm32/src/fmc.rs b/embassy-stm32/src/fmc.rs index 83b49a3dd..71ca775cb 100644 --- a/embassy-stm32/src/fmc.rs +++ b/embassy-stm32/src/fmc.rs | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | //! Flexible Memory Controller (FMC) / Flexible Static Memory Controller (FSMC) | 1 | //! Flexible Memory Controller (FMC) / Flexible Static Memory Controller (FSMC) |
| 2 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 3 | 3 | ||
| 4 | use embassy_hal_internal::into_ref; | 4 | use embassy_hal_internal::PeripheralType; |
| 5 | 5 | ||
| 6 | use crate::gpio::{AfType, OutputType, Pull, Speed}; | 6 | use crate::gpio::{AfType, OutputType, Pull, Speed}; |
| 7 | use crate::{rcc, Peripheral}; | 7 | use crate::{rcc, Peri}; |
| 8 | 8 | ||
| 9 | /// FMC driver | 9 | /// FMC driver |
| 10 | pub struct Fmc<'d, T: Instance> { | 10 | pub struct Fmc<'d, T: Instance> { |
| @@ -21,7 +21,7 @@ where | |||
| 21 | /// | 21 | /// |
| 22 | /// **Note:** This is currently used to provide access to some basic FMC functions | 22 | /// **Note:** This is currently used to provide access to some basic FMC functions |
| 23 | /// for manual configuration for memory types that stm32-fmc does not support. | 23 | /// for manual configuration for memory types that stm32-fmc does not support. |
| 24 | pub fn new_raw(_instance: impl Peripheral<P = T> + 'd) -> Self { | 24 | pub fn new_raw(_instance: Peri<'d, T>) -> Self { |
| 25 | Self { peri: PhantomData } | 25 | Self { peri: PhantomData } |
| 26 | } | 26 | } |
| 27 | 27 | ||
| @@ -74,8 +74,7 @@ where | |||
| 74 | 74 | ||
| 75 | macro_rules! config_pins { | 75 | macro_rules! config_pins { |
| 76 | ($($pin:ident),*) => { | 76 | ($($pin:ident),*) => { |
| 77 | into_ref!($($pin),*); | 77 | $( |
| 78 | $( | ||
| 79 | $pin.set_as_af($pin.af_num(), AfType::output_pull(OutputType::PushPull, Speed::VeryHigh, Pull::Up)); | 78 | $pin.set_as_af($pin.af_num(), AfType::output_pull(OutputType::PushPull, Speed::VeryHigh, Pull::Up)); |
| 80 | )* | 79 | )* |
| 81 | }; | 80 | }; |
| @@ -92,12 +91,12 @@ macro_rules! fmc_sdram_constructor { | |||
| 92 | )) => { | 91 | )) => { |
| 93 | /// Create a new FMC instance. | 92 | /// Create a new FMC instance. |
| 94 | pub fn $name<CHIP: stm32_fmc::SdramChip>( | 93 | pub fn $name<CHIP: stm32_fmc::SdramChip>( |
| 95 | _instance: impl Peripheral<P = T> + 'd, | 94 | _instance: Peri<'d, T>, |
| 96 | $($addr_pin_name: impl Peripheral<P = impl $addr_signal<T>> + 'd),*, | 95 | $($addr_pin_name: Peri<'d, impl $addr_signal<T>>),*, |
| 97 | $($ba_pin_name: impl Peripheral<P = impl $ba_signal<T>> + 'd),*, | 96 | $($ba_pin_name: Peri<'d, impl $ba_signal<T>>),*, |
| 98 | $($d_pin_name: impl Peripheral<P = impl $d_signal<T>> + 'd),*, | 97 | $($d_pin_name: Peri<'d, impl $d_signal<T>>),*, |
| 99 | $($nbl_pin_name: impl Peripheral<P = impl $nbl_signal<T>> + 'd),*, | 98 | $($nbl_pin_name: Peri<'d, impl $nbl_signal<T>>),*, |
| 100 | $($ctrl_pin_name: impl Peripheral<P = impl $ctrl_signal<T>> + 'd),*, | 99 | $($ctrl_pin_name: Peri<'d, impl $ctrl_signal<T>>),*, |
| 101 | chip: CHIP | 100 | chip: CHIP |
| 102 | ) -> stm32_fmc::Sdram<Fmc<'d, T>, CHIP> { | 101 | ) -> stm32_fmc::Sdram<Fmc<'d, T>, CHIP> { |
| 103 | 102 | ||
| @@ -245,7 +244,7 @@ trait SealedInstance: crate::rcc::RccPeripheral { | |||
| 245 | 244 | ||
| 246 | /// FMC instance trait. | 245 | /// FMC instance trait. |
| 247 | #[allow(private_bounds)] | 246 | #[allow(private_bounds)] |
| 248 | pub trait Instance: SealedInstance + 'static {} | 247 | pub trait Instance: SealedInstance + PeripheralType + 'static {} |
| 249 | 248 | ||
| 250 | foreach_peripheral!( | 249 | foreach_peripheral!( |
| 251 | (fmc, $inst:ident) => { | 250 | (fmc, $inst:ident) => { |
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 65e1bfb8c..bb37c4194 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs | |||
| @@ -4,10 +4,10 @@ | |||
| 4 | use core::convert::Infallible; | 4 | use core::convert::Infallible; |
| 5 | 5 | ||
| 6 | use critical_section::CriticalSection; | 6 | use critical_section::CriticalSection; |
| 7 | use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; | 7 | use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType}; |
| 8 | 8 | ||
| 9 | use crate::pac::gpio::{self, vals}; | 9 | use crate::pac::gpio::{self, vals}; |
| 10 | use crate::{peripherals, Peripheral}; | 10 | use crate::peripherals; |
| 11 | 11 | ||
| 12 | /// GPIO flexible pin. | 12 | /// GPIO flexible pin. |
| 13 | /// | 13 | /// |
| @@ -15,7 +15,7 @@ use crate::{peripherals, Peripheral}; | |||
| 15 | /// set while not in output mode, so the pin's level will be 'remembered' when it is not in output | 15 | /// set while not in output mode, so the pin's level will be 'remembered' when it is not in output |
| 16 | /// mode. | 16 | /// mode. |
| 17 | pub struct Flex<'d> { | 17 | pub struct Flex<'d> { |
| 18 | pub(crate) pin: PeripheralRef<'d, AnyPin>, | 18 | pub(crate) pin: Peri<'d, AnyPin>, |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | impl<'d> Flex<'d> { | 21 | impl<'d> Flex<'d> { |
| @@ -25,10 +25,9 @@ impl<'d> Flex<'d> { | |||
| 25 | /// before the pin is put into output mode. | 25 | /// before the pin is put into output mode. |
| 26 | /// | 26 | /// |
| 27 | #[inline] | 27 | #[inline] |
| 28 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd) -> Self { | 28 | pub fn new(pin: Peri<'d, impl Pin>) -> Self { |
| 29 | into_ref!(pin); | ||
| 30 | // Pin will be in disconnected state. | 29 | // Pin will be in disconnected state. |
| 31 | Self { pin: pin.map_into() } | 30 | Self { pin: pin.into() } |
| 32 | } | 31 | } |
| 33 | 32 | ||
| 34 | /// Put the pin into input mode. | 33 | /// Put the pin into input mode. |
| @@ -310,7 +309,7 @@ pub struct Input<'d> { | |||
| 310 | impl<'d> Input<'d> { | 309 | impl<'d> Input<'d> { |
| 311 | /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration. | 310 | /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration. |
| 312 | #[inline] | 311 | #[inline] |
| 313 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, pull: Pull) -> Self { | 312 | pub fn new(pin: Peri<'d, impl Pin>, pull: Pull) -> Self { |
| 314 | let mut pin = Flex::new(pin); | 313 | let mut pin = Flex::new(pin); |
| 315 | pin.set_as_input(pull); | 314 | pin.set_as_input(pull); |
| 316 | Self { pin } | 315 | Self { pin } |
| @@ -375,7 +374,7 @@ pub struct Output<'d> { | |||
| 375 | impl<'d> Output<'d> { | 374 | impl<'d> Output<'d> { |
| 376 | /// Create GPIO output driver for a [Pin] with the provided [Level] and [Speed] configuration. | 375 | /// Create GPIO output driver for a [Pin] with the provided [Level] and [Speed] configuration. |
| 377 | #[inline] | 376 | #[inline] |
| 378 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level, speed: Speed) -> Self { | 377 | pub fn new(pin: Peri<'d, impl Pin>, initial_output: Level, speed: Speed) -> Self { |
| 379 | let mut pin = Flex::new(pin); | 378 | let mut pin = Flex::new(pin); |
| 380 | match initial_output { | 379 | match initial_output { |
| 381 | Level::High => pin.set_high(), | 380 | Level::High => pin.set_high(), |
| @@ -440,7 +439,7 @@ pub struct OutputOpenDrain<'d> { | |||
| 440 | impl<'d> OutputOpenDrain<'d> { | 439 | impl<'d> OutputOpenDrain<'d> { |
| 441 | /// Create a new GPIO open drain output driver for a [Pin] with the provided [Level] and [Speed]. | 440 | /// Create a new GPIO open drain output driver for a [Pin] with the provided [Level] and [Speed]. |
| 442 | #[inline] | 441 | #[inline] |
| 443 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level, speed: Speed) -> Self { | 442 | pub fn new(pin: Peri<'d, impl Pin>, initial_output: Level, speed: Speed) -> Self { |
| 444 | let mut pin = Flex::new(pin); | 443 | let mut pin = Flex::new(pin); |
| 445 | match initial_output { | 444 | match initial_output { |
| 446 | Level::High => pin.set_high(), | 445 | Level::High => pin.set_high(), |
| @@ -454,7 +453,7 @@ impl<'d> OutputOpenDrain<'d> { | |||
| 454 | /// and [Pull]. | 453 | /// and [Pull]. |
| 455 | #[inline] | 454 | #[inline] |
| 456 | #[cfg(gpio_v2)] | 455 | #[cfg(gpio_v2)] |
| 457 | pub fn new_pull(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level, speed: Speed, pull: Pull) -> Self { | 456 | pub fn new_pull(pin: Peri<'d, impl Pin>, initial_output: Level, speed: Speed, pull: Pull) -> Self { |
| 458 | let mut pin = Flex::new(pin); | 457 | let mut pin = Flex::new(pin); |
| 459 | match initial_output { | 458 | match initial_output { |
| 460 | Level::High => pin.set_high(), | 459 | Level::High => pin.set_high(), |
| @@ -780,7 +779,7 @@ pub(crate) trait SealedPin { | |||
| 780 | 779 | ||
| 781 | /// GPIO pin trait. | 780 | /// GPIO pin trait. |
| 782 | #[allow(private_bounds)] | 781 | #[allow(private_bounds)] |
| 783 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static { | 782 | pub trait Pin: PeripheralType + Into<AnyPin> + SealedPin + Sized + 'static { |
| 784 | /// EXTI channel assigned to this pin. | 783 | /// EXTI channel assigned to this pin. |
| 785 | /// | 784 | /// |
| 786 | /// For example, PC4 uses EXTI4. | 785 | /// For example, PC4 uses EXTI4. |
| @@ -798,18 +797,6 @@ pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static | |||
| 798 | fn port(&self) -> u8 { | 797 | fn port(&self) -> u8 { |
| 799 | self._port() | 798 | self._port() |
| 800 | } | 799 | } |
| 801 | |||
| 802 | /// Type-erase (degrade) this pin into an `AnyPin`. | ||
| 803 | /// | ||
| 804 | /// This converts pin singletons (`PA5`, `PB6`, ...), which | ||
| 805 | /// are all different types, into the same type. It is useful for | ||
| 806 | /// creating arrays of pins, or avoiding generics. | ||
| 807 | #[inline] | ||
| 808 | fn degrade(self) -> AnyPin { | ||
| 809 | AnyPin { | ||
| 810 | pin_port: self.pin_port(), | ||
| 811 | } | ||
| 812 | } | ||
| 813 | } | 800 | } |
| 814 | 801 | ||
| 815 | /// Type-erased GPIO pin | 802 | /// Type-erased GPIO pin |
| @@ -822,8 +809,8 @@ impl AnyPin { | |||
| 822 | /// | 809 | /// |
| 823 | /// `pin_port` is `port_num * 16 + pin_num`, where `port_num` is 0 for port `A`, 1 for port `B`, etc... | 810 | /// `pin_port` is `port_num * 16 + pin_num`, where `port_num` is 0 for port `A`, 1 for port `B`, etc... |
| 824 | #[inline] | 811 | #[inline] |
| 825 | pub unsafe fn steal(pin_port: u8) -> Self { | 812 | pub unsafe fn steal(pin_port: u8) -> Peri<'static, Self> { |
| 826 | Self { pin_port } | 813 | Peri::new_unchecked(Self { pin_port }) |
| 827 | } | 814 | } |
| 828 | 815 | ||
| 829 | #[inline] | 816 | #[inline] |
| @@ -867,8 +854,10 @@ foreach_pin!( | |||
| 867 | } | 854 | } |
| 868 | 855 | ||
| 869 | impl From<peripherals::$pin_name> for AnyPin { | 856 | impl From<peripherals::$pin_name> for AnyPin { |
| 870 | fn from(x: peripherals::$pin_name) -> Self { | 857 | fn from(val: peripherals::$pin_name) -> Self { |
| 871 | x.degrade() | 858 | Self { |
| 859 | pin_port: val.pin_port(), | ||
| 860 | } | ||
| 872 | } | 861 | } |
| 873 | } | 862 | } |
| 874 | }; | 863 | }; |
diff --git a/embassy-stm32/src/hash/mod.rs b/embassy-stm32/src/hash/mod.rs index 3951e9d63..1258e8923 100644 --- a/embassy-stm32/src/hash/mod.rs +++ b/embassy-stm32/src/hash/mod.rs | |||
| @@ -8,7 +8,7 @@ use core::ptr; | |||
| 8 | #[cfg(hash_v2)] | 8 | #[cfg(hash_v2)] |
| 9 | use core::task::Poll; | 9 | use core::task::Poll; |
| 10 | 10 | ||
| 11 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 11 | use embassy_hal_internal::PeripheralType; |
| 12 | use embassy_sync::waitqueue::AtomicWaker; | 12 | use embassy_sync::waitqueue::AtomicWaker; |
| 13 | use stm32_metapac::hash::regs::*; | 13 | use stm32_metapac::hash::regs::*; |
| 14 | 14 | ||
| @@ -19,7 +19,7 @@ use crate::interrupt::typelevel::Interrupt; | |||
| 19 | use crate::mode::Async; | 19 | use crate::mode::Async; |
| 20 | use crate::mode::{Blocking, Mode}; | 20 | use crate::mode::{Blocking, Mode}; |
| 21 | use crate::peripherals::HASH; | 21 | use crate::peripherals::HASH; |
| 22 | use crate::{interrupt, pac, peripherals, rcc, Peripheral}; | 22 | use crate::{interrupt, pac, peripherals, rcc, Peri}; |
| 23 | 23 | ||
| 24 | #[cfg(hash_v1)] | 24 | #[cfg(hash_v1)] |
| 25 | const NUM_CONTEXT_REGS: usize = 51; | 25 | const NUM_CONTEXT_REGS: usize = 51; |
| @@ -119,7 +119,7 @@ type HmacKey<'k> = Option<&'k [u8]>; | |||
| 119 | 119 | ||
| 120 | /// HASH driver. | 120 | /// HASH driver. |
| 121 | pub struct Hash<'d, T: Instance, M: Mode> { | 121 | pub struct Hash<'d, T: Instance, M: Mode> { |
| 122 | _peripheral: PeripheralRef<'d, T>, | 122 | _peripheral: Peri<'d, T>, |
| 123 | _phantom: PhantomData<M>, | 123 | _phantom: PhantomData<M>, |
| 124 | #[cfg(hash_v2)] | 124 | #[cfg(hash_v2)] |
| 125 | dma: Option<ChannelAndRequest<'d>>, | 125 | dma: Option<ChannelAndRequest<'d>>, |
| @@ -128,11 +128,10 @@ pub struct Hash<'d, T: Instance, M: Mode> { | |||
| 128 | impl<'d, T: Instance> Hash<'d, T, Blocking> { | 128 | impl<'d, T: Instance> Hash<'d, T, Blocking> { |
| 129 | /// Instantiates, resets, and enables the HASH peripheral. | 129 | /// Instantiates, resets, and enables the HASH peripheral. |
| 130 | pub fn new_blocking( | 130 | pub fn new_blocking( |
| 131 | peripheral: impl Peripheral<P = T> + 'd, | 131 | peripheral: Peri<'d, T>, |
| 132 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 132 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 133 | ) -> Self { | 133 | ) -> Self { |
| 134 | rcc::enable_and_reset::<HASH>(); | 134 | rcc::enable_and_reset::<HASH>(); |
| 135 | into_ref!(peripheral); | ||
| 136 | let instance = Self { | 135 | let instance = Self { |
| 137 | _peripheral: peripheral, | 136 | _peripheral: peripheral, |
| 138 | _phantom: PhantomData, | 137 | _phantom: PhantomData, |
| @@ -396,12 +395,11 @@ impl<'d, T: Instance, M: Mode> Hash<'d, T, M> { | |||
| 396 | impl<'d, T: Instance> Hash<'d, T, Async> { | 395 | impl<'d, T: Instance> Hash<'d, T, Async> { |
| 397 | /// Instantiates, resets, and enables the HASH peripheral. | 396 | /// Instantiates, resets, and enables the HASH peripheral. |
| 398 | pub fn new( | 397 | pub fn new( |
| 399 | peripheral: impl Peripheral<P = T> + 'd, | 398 | peripheral: Peri<'d, T>, |
| 400 | dma: impl Peripheral<P = impl Dma<T>> + 'd, | 399 | dma: Peri<'d, impl Dma<T>>, |
| 401 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 400 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 402 | ) -> Self { | 401 | ) -> Self { |
| 403 | rcc::enable_and_reset::<HASH>(); | 402 | rcc::enable_and_reset::<HASH>(); |
| 404 | into_ref!(peripheral, dma); | ||
| 405 | let instance = Self { | 403 | let instance = Self { |
| 406 | _peripheral: peripheral, | 404 | _peripheral: peripheral, |
| 407 | _phantom: PhantomData, | 405 | _phantom: PhantomData, |
| @@ -583,7 +581,7 @@ trait SealedInstance { | |||
| 583 | 581 | ||
| 584 | /// HASH instance trait. | 582 | /// HASH instance trait. |
| 585 | #[allow(private_bounds)] | 583 | #[allow(private_bounds)] |
| 586 | pub trait Instance: SealedInstance + Peripheral<P = Self> + crate::rcc::RccPeripheral + 'static + Send { | 584 | pub trait Instance: SealedInstance + PeripheralType + crate::rcc::RccPeripheral + 'static + Send { |
| 587 | /// Interrupt for this HASH instance. | 585 | /// Interrupt for this HASH instance. |
| 588 | type Interrupt: interrupt::typelevel::Interrupt; | 586 | type Interrupt: interrupt::typelevel::Interrupt; |
| 589 | } | 587 | } |
diff --git a/embassy-stm32/src/hrtim/mod.rs b/embassy-stm32/src/hrtim/mod.rs index d9b7c16fb..1d0594125 100644 --- a/embassy-stm32/src/hrtim/mod.rs +++ b/embassy-stm32/src/hrtim/mod.rs | |||
| @@ -4,12 +4,12 @@ mod traits; | |||
| 4 | 4 | ||
| 5 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 6 | 6 | ||
| 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 7 | use embassy_hal_internal::Peri; |
| 8 | pub use traits::Instance; | 8 | pub use traits::Instance; |
| 9 | 9 | ||
| 10 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; | 10 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; |
| 11 | use crate::rcc; | ||
| 11 | use crate::time::Hertz; | 12 | use crate::time::Hertz; |
| 12 | use crate::{rcc, Peripheral}; | ||
| 13 | 13 | ||
| 14 | /// HRTIM burst controller instance. | 14 | /// HRTIM burst controller instance. |
| 15 | pub struct BurstController<T: Instance> { | 15 | pub struct BurstController<T: Instance> { |
| @@ -62,13 +62,13 @@ pub trait AdvancedChannel<T: Instance>: SealedAdvancedChannel<T> {} | |||
| 62 | 62 | ||
| 63 | /// HRTIM PWM pin. | 63 | /// HRTIM PWM pin. |
| 64 | pub struct PwmPin<'d, T, C> { | 64 | pub struct PwmPin<'d, T, C> { |
| 65 | _pin: PeripheralRef<'d, AnyPin>, | 65 | _pin: Peri<'d, AnyPin>, |
| 66 | phantom: PhantomData<(T, C)>, | 66 | phantom: PhantomData<(T, C)>, |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | /// HRTIM complementary PWM pin. | 69 | /// HRTIM complementary PWM pin. |
| 70 | pub struct ComplementaryPwmPin<'d, T, C> { | 70 | pub struct ComplementaryPwmPin<'d, T, C> { |
| 71 | _pin: PeripheralRef<'d, AnyPin>, | 71 | _pin: Peri<'d, AnyPin>, |
| 72 | phantom: PhantomData<(T, C)>, | 72 | phantom: PhantomData<(T, C)>, |
| 73 | } | 73 | } |
| 74 | 74 | ||
| @@ -76,8 +76,7 @@ macro_rules! advanced_channel_impl { | |||
| 76 | ($new_chx:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => { | 76 | ($new_chx:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => { |
| 77 | impl<'d, T: Instance> PwmPin<'d, T, $channel<T>> { | 77 | impl<'d, T: Instance> PwmPin<'d, T, $channel<T>> { |
| 78 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] | 78 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] |
| 79 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self { | 79 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self { |
| 80 | into_ref!(pin); | ||
| 81 | critical_section::with(|_| { | 80 | critical_section::with(|_| { |
| 82 | pin.set_low(); | 81 | pin.set_low(); |
| 83 | pin.set_as_af( | 82 | pin.set_as_af( |
| @@ -86,7 +85,7 @@ macro_rules! advanced_channel_impl { | |||
| 86 | ); | 85 | ); |
| 87 | }); | 86 | }); |
| 88 | PwmPin { | 87 | PwmPin { |
| 89 | _pin: pin.map_into(), | 88 | _pin: pin.into(), |
| 90 | phantom: PhantomData, | 89 | phantom: PhantomData, |
| 91 | } | 90 | } |
| 92 | } | 91 | } |
| @@ -94,8 +93,7 @@ macro_rules! advanced_channel_impl { | |||
| 94 | 93 | ||
| 95 | impl<'d, T: Instance> ComplementaryPwmPin<'d, T, $channel<T>> { | 94 | impl<'d, T: Instance> ComplementaryPwmPin<'d, T, $channel<T>> { |
| 96 | #[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance.")] | 95 | #[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance.")] |
| 97 | pub fn $new_chx(pin: impl Peripheral<P = impl $complementary_pin_trait<T>> + 'd) -> Self { | 96 | pub fn $new_chx(pin: Peri<'d, impl $complementary_pin_trait<T>>) -> Self { |
| 98 | into_ref!(pin); | ||
| 99 | critical_section::with(|_| { | 97 | critical_section::with(|_| { |
| 100 | pin.set_low(); | 98 | pin.set_low(); |
| 101 | pin.set_as_af( | 99 | pin.set_as_af( |
| @@ -104,7 +102,7 @@ macro_rules! advanced_channel_impl { | |||
| 104 | ); | 102 | ); |
| 105 | }); | 103 | }); |
| 106 | ComplementaryPwmPin { | 104 | ComplementaryPwmPin { |
| 107 | _pin: pin.map_into(), | 105 | _pin: pin.into(), |
| 108 | phantom: PhantomData, | 106 | phantom: PhantomData, |
| 109 | } | 107 | } |
| 110 | } | 108 | } |
| @@ -129,7 +127,7 @@ advanced_channel_impl!(new_chf, ChF, 5, ChannelFPin, ChannelFComplementaryPin); | |||
| 129 | 127 | ||
| 130 | /// Struct used to divide a high resolution timer into multiple channels | 128 | /// Struct used to divide a high resolution timer into multiple channels |
| 131 | pub struct AdvancedPwm<'d, T: Instance> { | 129 | pub struct AdvancedPwm<'d, T: Instance> { |
| 132 | _inner: PeripheralRef<'d, T>, | 130 | _inner: Peri<'d, T>, |
| 133 | /// Master instance. | 131 | /// Master instance. |
| 134 | pub master: Master<T>, | 132 | pub master: Master<T>, |
| 135 | /// Burst controller. | 133 | /// Burst controller. |
| @@ -154,7 +152,7 @@ impl<'d, T: Instance> AdvancedPwm<'d, T> { | |||
| 154 | /// | 152 | /// |
| 155 | /// This splits the HRTIM into its constituent parts, which you can then use individually. | 153 | /// This splits the HRTIM into its constituent parts, which you can then use individually. |
| 156 | pub fn new( | 154 | pub fn new( |
| 157 | tim: impl Peripheral<P = T> + 'd, | 155 | tim: Peri<'d, T>, |
| 158 | _cha: Option<PwmPin<'d, T, ChA<T>>>, | 156 | _cha: Option<PwmPin<'d, T, ChA<T>>>, |
| 159 | _chan: Option<ComplementaryPwmPin<'d, T, ChA<T>>>, | 157 | _chan: Option<ComplementaryPwmPin<'d, T, ChA<T>>>, |
| 160 | _chb: Option<PwmPin<'d, T, ChB<T>>>, | 158 | _chb: Option<PwmPin<'d, T, ChB<T>>>, |
| @@ -171,9 +169,7 @@ impl<'d, T: Instance> AdvancedPwm<'d, T> { | |||
| 171 | Self::new_inner(tim) | 169 | Self::new_inner(tim) |
| 172 | } | 170 | } |
| 173 | 171 | ||
| 174 | fn new_inner(tim: impl Peripheral<P = T> + 'd) -> Self { | 172 | fn new_inner(tim: Peri<'d, T>) -> Self { |
| 175 | into_ref!(tim); | ||
| 176 | |||
| 177 | rcc::enable_and_reset::<T>(); | 173 | rcc::enable_and_reset::<T>(); |
| 178 | 174 | ||
| 179 | #[cfg(stm32f334)] | 175 | #[cfg(stm32f334)] |
diff --git a/embassy-stm32/src/hrtim/traits.rs b/embassy-stm32/src/hrtim/traits.rs index 75f9971e2..6c0661146 100644 --- a/embassy-stm32/src/hrtim/traits.rs +++ b/embassy-stm32/src/hrtim/traits.rs | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | use embassy_hal_internal::PeripheralType; | ||
| 2 | |||
| 1 | use crate::rcc::RccPeripheral; | 3 | use crate::rcc::RccPeripheral; |
| 2 | use crate::time::Hertz; | 4 | use crate::time::Hertz; |
| 3 | 5 | ||
| @@ -153,7 +155,7 @@ pub(crate) trait SealedInstance: RccPeripheral { | |||
| 153 | 155 | ||
| 154 | /// HRTIM instance trait. | 156 | /// HRTIM instance trait. |
| 155 | #[allow(private_bounds)] | 157 | #[allow(private_bounds)] |
| 156 | pub trait Instance: SealedInstance + 'static {} | 158 | pub trait Instance: SealedInstance + PeripheralType + 'static {} |
| 157 | 159 | ||
| 158 | foreach_interrupt! { | 160 | foreach_interrupt! { |
| 159 | ($inst:ident, hrtim, HRTIM, MASTER, $irq:ident) => { | 161 | ($inst:ident, hrtim, HRTIM, MASTER, $irq:ident) => { |
diff --git a/embassy-stm32/src/hsem/mod.rs b/embassy-stm32/src/hsem/mod.rs index 06ab7a9bc..31527bcdb 100644 --- a/embassy-stm32/src/hsem/mod.rs +++ b/embassy-stm32/src/hsem/mod.rs | |||
| @@ -1,13 +1,14 @@ | |||
| 1 | //! Hardware Semaphore (HSEM) | 1 | //! Hardware Semaphore (HSEM) |
| 2 | 2 | ||
| 3 | use embassy_hal_internal::PeripheralType; | ||
| 4 | |||
| 5 | use crate::pac; | ||
| 6 | use crate::rcc::RccPeripheral; | ||
| 3 | // TODO: This code works for all HSEM implemenations except for the STM32WBA52/4/5xx MCUs. | 7 | // TODO: This code works for all HSEM implemenations except for the STM32WBA52/4/5xx MCUs. |
| 4 | // Those MCUs have a different HSEM implementation (Secure semaphore lock support, | 8 | // Those MCUs have a different HSEM implementation (Secure semaphore lock support, |
| 5 | // Privileged / unprivileged semaphore lock support, Semaphore lock protection via semaphore attribute), | 9 | // Privileged / unprivileged semaphore lock support, Semaphore lock protection via semaphore attribute), |
| 6 | // which is not yet supported by this code. | 10 | // which is not yet supported by this code. |
| 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 11 | use crate::Peri; |
| 8 | |||
| 9 | use crate::rcc::RccPeripheral; | ||
| 10 | use crate::{pac, Peripheral}; | ||
| 11 | 12 | ||
| 12 | /// HSEM error. | 13 | /// HSEM error. |
| 13 | #[derive(Debug)] | 14 | #[derive(Debug)] |
| @@ -73,13 +74,12 @@ fn core_id_to_index(core: CoreId) -> usize { | |||
| 73 | 74 | ||
| 74 | /// HSEM driver | 75 | /// HSEM driver |
| 75 | pub struct HardwareSemaphore<'d, T: Instance> { | 76 | pub struct HardwareSemaphore<'d, T: Instance> { |
| 76 | _peri: PeripheralRef<'d, T>, | 77 | _peri: Peri<'d, T>, |
| 77 | } | 78 | } |
| 78 | 79 | ||
| 79 | impl<'d, T: Instance> HardwareSemaphore<'d, T> { | 80 | impl<'d, T: Instance> HardwareSemaphore<'d, T> { |
| 80 | /// Creates a new HardwareSemaphore instance. | 81 | /// Creates a new HardwareSemaphore instance. |
| 81 | pub fn new(peripheral: impl Peripheral<P = T> + 'd) -> Self { | 82 | pub fn new(peripheral: Peri<'d, T>) -> Self { |
| 82 | into_ref!(peripheral); | ||
| 83 | HardwareSemaphore { _peri: peripheral } | 83 | HardwareSemaphore { _peri: peripheral } |
| 84 | } | 84 | } |
| 85 | 85 | ||
| @@ -177,7 +177,7 @@ trait SealedInstance { | |||
| 177 | 177 | ||
| 178 | /// HSEM instance trait. | 178 | /// HSEM instance trait. |
| 179 | #[allow(private_bounds)] | 179 | #[allow(private_bounds)] |
| 180 | pub trait Instance: SealedInstance + RccPeripheral + Send + 'static {} | 180 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + Send + 'static {} |
| 181 | 181 | ||
| 182 | impl SealedInstance for crate::peripherals::HSEM { | 182 | impl SealedInstance for crate::peripherals::HSEM { |
| 183 | fn regs() -> crate::pac::hsem::Hsem { | 183 | fn regs() -> crate::pac::hsem::Hsem { |
diff --git a/embassy-stm32/src/hspi/mod.rs b/embassy-stm32/src/hspi/mod.rs index 54b442481..62bc0e979 100644 --- a/embassy-stm32/src/hspi/mod.rs +++ b/embassy-stm32/src/hspi/mod.rs | |||
| @@ -13,15 +13,15 @@ pub mod enums; | |||
| 13 | use core::marker::PhantomData; | 13 | use core::marker::PhantomData; |
| 14 | 14 | ||
| 15 | use embassy_embedded_hal::{GetConfig, SetConfig}; | 15 | use embassy_embedded_hal::{GetConfig, SetConfig}; |
| 16 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 16 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 17 | pub use enums::*; | 17 | pub use enums::*; |
| 18 | 18 | ||
| 19 | use crate::dma::{word, ChannelAndRequest}; | 19 | use crate::dma::{word, ChannelAndRequest}; |
| 20 | use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; | 20 | use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; |
| 21 | use crate::mode::{Async, Blocking, Mode as PeriMode}; | 21 | use crate::mode::{Async, Blocking, Mode as PeriMode}; |
| 22 | use crate::pac::hspi::Hspi as Regs; | 22 | use crate::pac::hspi::Hspi as Regs; |
| 23 | use crate::peripherals; | ||
| 23 | use crate::rcc::{self, RccPeripheral}; | 24 | use crate::rcc::{self, RccPeripheral}; |
| 24 | use crate::{peripherals, Peripheral}; | ||
| 25 | 25 | ||
| 26 | /// HSPI driver config. | 26 | /// HSPI driver config. |
| 27 | #[derive(Clone, Copy)] | 27 | #[derive(Clone, Copy)] |
| @@ -163,27 +163,27 @@ pub enum HspiError { | |||
| 163 | 163 | ||
| 164 | /// HSPI driver. | 164 | /// HSPI driver. |
| 165 | pub struct Hspi<'d, T: Instance, M: PeriMode> { | 165 | pub struct Hspi<'d, T: Instance, M: PeriMode> { |
| 166 | _peri: PeripheralRef<'d, T>, | 166 | _peri: Peri<'d, T>, |
| 167 | sck: Option<PeripheralRef<'d, AnyPin>>, | 167 | sck: Option<Peri<'d, AnyPin>>, |
| 168 | d0: Option<PeripheralRef<'d, AnyPin>>, | 168 | d0: Option<Peri<'d, AnyPin>>, |
| 169 | d1: Option<PeripheralRef<'d, AnyPin>>, | 169 | d1: Option<Peri<'d, AnyPin>>, |
| 170 | d2: Option<PeripheralRef<'d, AnyPin>>, | 170 | d2: Option<Peri<'d, AnyPin>>, |
| 171 | d3: Option<PeripheralRef<'d, AnyPin>>, | 171 | d3: Option<Peri<'d, AnyPin>>, |
| 172 | d4: Option<PeripheralRef<'d, AnyPin>>, | 172 | d4: Option<Peri<'d, AnyPin>>, |
| 173 | d5: Option<PeripheralRef<'d, AnyPin>>, | 173 | d5: Option<Peri<'d, AnyPin>>, |
| 174 | d6: Option<PeripheralRef<'d, AnyPin>>, | 174 | d6: Option<Peri<'d, AnyPin>>, |
| 175 | d7: Option<PeripheralRef<'d, AnyPin>>, | 175 | d7: Option<Peri<'d, AnyPin>>, |
| 176 | d8: Option<PeripheralRef<'d, AnyPin>>, | 176 | d8: Option<Peri<'d, AnyPin>>, |
| 177 | d9: Option<PeripheralRef<'d, AnyPin>>, | 177 | d9: Option<Peri<'d, AnyPin>>, |
| 178 | d10: Option<PeripheralRef<'d, AnyPin>>, | 178 | d10: Option<Peri<'d, AnyPin>>, |
| 179 | d11: Option<PeripheralRef<'d, AnyPin>>, | 179 | d11: Option<Peri<'d, AnyPin>>, |
| 180 | d12: Option<PeripheralRef<'d, AnyPin>>, | 180 | d12: Option<Peri<'d, AnyPin>>, |
| 181 | d13: Option<PeripheralRef<'d, AnyPin>>, | 181 | d13: Option<Peri<'d, AnyPin>>, |
| 182 | d14: Option<PeripheralRef<'d, AnyPin>>, | 182 | d14: Option<Peri<'d, AnyPin>>, |
| 183 | d15: Option<PeripheralRef<'d, AnyPin>>, | 183 | d15: Option<Peri<'d, AnyPin>>, |
| 184 | nss: Option<PeripheralRef<'d, AnyPin>>, | 184 | nss: Option<Peri<'d, AnyPin>>, |
| 185 | dqs0: Option<PeripheralRef<'d, AnyPin>>, | 185 | dqs0: Option<Peri<'d, AnyPin>>, |
| 186 | dqs1: Option<PeripheralRef<'d, AnyPin>>, | 186 | dqs1: Option<Peri<'d, AnyPin>>, |
| 187 | dma: Option<ChannelAndRequest<'d>>, | 187 | dma: Option<ChannelAndRequest<'d>>, |
| 188 | _phantom: PhantomData<M>, | 188 | _phantom: PhantomData<M>, |
| 189 | config: Config, | 189 | config: Config, |
| @@ -247,34 +247,32 @@ impl<'d, T: Instance, M: PeriMode> Hspi<'d, T, M> { | |||
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | fn new_inner( | 249 | fn new_inner( |
| 250 | peri: impl Peripheral<P = T> + 'd, | 250 | peri: Peri<'d, T>, |
| 251 | d0: Option<PeripheralRef<'d, AnyPin>>, | 251 | d0: Option<Peri<'d, AnyPin>>, |
| 252 | d1: Option<PeripheralRef<'d, AnyPin>>, | 252 | d1: Option<Peri<'d, AnyPin>>, |
| 253 | d2: Option<PeripheralRef<'d, AnyPin>>, | 253 | d2: Option<Peri<'d, AnyPin>>, |
| 254 | d3: Option<PeripheralRef<'d, AnyPin>>, | 254 | d3: Option<Peri<'d, AnyPin>>, |
| 255 | d4: Option<PeripheralRef<'d, AnyPin>>, | 255 | d4: Option<Peri<'d, AnyPin>>, |
| 256 | d5: Option<PeripheralRef<'d, AnyPin>>, | 256 | d5: Option<Peri<'d, AnyPin>>, |
| 257 | d6: Option<PeripheralRef<'d, AnyPin>>, | 257 | d6: Option<Peri<'d, AnyPin>>, |
| 258 | d7: Option<PeripheralRef<'d, AnyPin>>, | 258 | d7: Option<Peri<'d, AnyPin>>, |
| 259 | d8: Option<PeripheralRef<'d, AnyPin>>, | 259 | d8: Option<Peri<'d, AnyPin>>, |
| 260 | d9: Option<PeripheralRef<'d, AnyPin>>, | 260 | d9: Option<Peri<'d, AnyPin>>, |
| 261 | d10: Option<PeripheralRef<'d, AnyPin>>, | 261 | d10: Option<Peri<'d, AnyPin>>, |
| 262 | d11: Option<PeripheralRef<'d, AnyPin>>, | 262 | d11: Option<Peri<'d, AnyPin>>, |
| 263 | d12: Option<PeripheralRef<'d, AnyPin>>, | 263 | d12: Option<Peri<'d, AnyPin>>, |
| 264 | d13: Option<PeripheralRef<'d, AnyPin>>, | 264 | d13: Option<Peri<'d, AnyPin>>, |
| 265 | d14: Option<PeripheralRef<'d, AnyPin>>, | 265 | d14: Option<Peri<'d, AnyPin>>, |
| 266 | d15: Option<PeripheralRef<'d, AnyPin>>, | 266 | d15: Option<Peri<'d, AnyPin>>, |
| 267 | sck: Option<PeripheralRef<'d, AnyPin>>, | 267 | sck: Option<Peri<'d, AnyPin>>, |
| 268 | nss: Option<PeripheralRef<'d, AnyPin>>, | 268 | nss: Option<Peri<'d, AnyPin>>, |
| 269 | dqs0: Option<PeripheralRef<'d, AnyPin>>, | 269 | dqs0: Option<Peri<'d, AnyPin>>, |
| 270 | dqs1: Option<PeripheralRef<'d, AnyPin>>, | 270 | dqs1: Option<Peri<'d, AnyPin>>, |
| 271 | dma: Option<ChannelAndRequest<'d>>, | 271 | dma: Option<ChannelAndRequest<'d>>, |
| 272 | config: Config, | 272 | config: Config, |
| 273 | width: HspiWidth, | 273 | width: HspiWidth, |
| 274 | dual_memory_mode: bool, | 274 | dual_memory_mode: bool, |
| 275 | ) -> Self { | 275 | ) -> Self { |
| 276 | into_ref!(peri); | ||
| 277 | |||
| 278 | // System configuration | 276 | // System configuration |
| 279 | rcc::enable_and_reset::<T>(); | 277 | rcc::enable_and_reset::<T>(); |
| 280 | 278 | ||
| @@ -579,11 +577,11 @@ impl<'d, T: Instance, M: PeriMode> Hspi<'d, T, M> { | |||
| 579 | impl<'d, T: Instance> Hspi<'d, T, Blocking> { | 577 | impl<'d, T: Instance> Hspi<'d, T, Blocking> { |
| 580 | /// Create new blocking HSPI driver for single spi external chip | 578 | /// Create new blocking HSPI driver for single spi external chip |
| 581 | pub fn new_blocking_singlespi( | 579 | pub fn new_blocking_singlespi( |
| 582 | peri: impl Peripheral<P = T> + 'd, | 580 | peri: Peri<'d, T>, |
| 583 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 581 | sck: Peri<'d, impl SckPin<T>>, |
| 584 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 582 | d0: Peri<'d, impl D0Pin<T>>, |
| 585 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 583 | d1: Peri<'d, impl D1Pin<T>>, |
| 586 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 584 | nss: Peri<'d, impl NSSPin<T>>, |
| 587 | config: Config, | 585 | config: Config, |
| 588 | ) -> Self { | 586 | ) -> Self { |
| 589 | Self::new_inner( | 587 | Self::new_inner( |
| @@ -620,18 +618,18 @@ impl<'d, T: Instance> Hspi<'d, T, Blocking> { | |||
| 620 | 618 | ||
| 621 | /// Create new blocking HSPI driver for octospi external chip | 619 | /// Create new blocking HSPI driver for octospi external chip |
| 622 | pub fn new_blocking_octospi( | 620 | pub fn new_blocking_octospi( |
| 623 | peri: impl Peripheral<P = T> + 'd, | 621 | peri: Peri<'d, T>, |
| 624 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 622 | sck: Peri<'d, impl SckPin<T>>, |
| 625 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 623 | d0: Peri<'d, impl D0Pin<T>>, |
| 626 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 624 | d1: Peri<'d, impl D1Pin<T>>, |
| 627 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 625 | d2: Peri<'d, impl D2Pin<T>>, |
| 628 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 626 | d3: Peri<'d, impl D3Pin<T>>, |
| 629 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 627 | d4: Peri<'d, impl D4Pin<T>>, |
| 630 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 628 | d5: Peri<'d, impl D5Pin<T>>, |
| 631 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 629 | d6: Peri<'d, impl D6Pin<T>>, |
| 632 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 630 | d7: Peri<'d, impl D7Pin<T>>, |
| 633 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 631 | nss: Peri<'d, impl NSSPin<T>>, |
| 634 | dqs0: impl Peripheral<P = impl DQS0Pin<T>> + 'd, | 632 | dqs0: Peri<'d, impl DQS0Pin<T>>, |
| 635 | config: Config, | 633 | config: Config, |
| 636 | ) -> Self { | 634 | ) -> Self { |
| 637 | Self::new_inner( | 635 | Self::new_inner( |
| @@ -670,12 +668,12 @@ impl<'d, T: Instance> Hspi<'d, T, Blocking> { | |||
| 670 | impl<'d, T: Instance> Hspi<'d, T, Async> { | 668 | impl<'d, T: Instance> Hspi<'d, T, Async> { |
| 671 | /// Create new HSPI driver for a single spi external chip | 669 | /// Create new HSPI driver for a single spi external chip |
| 672 | pub fn new_singlespi( | 670 | pub fn new_singlespi( |
| 673 | peri: impl Peripheral<P = T> + 'd, | 671 | peri: Peri<'d, T>, |
| 674 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 672 | sck: Peri<'d, impl SckPin<T>>, |
| 675 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 673 | d0: Peri<'d, impl D0Pin<T>>, |
| 676 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 674 | d1: Peri<'d, impl D1Pin<T>>, |
| 677 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 675 | nss: Peri<'d, impl NSSPin<T>>, |
| 678 | dma: impl Peripheral<P = impl HspiDma<T>> + 'd, | 676 | dma: Peri<'d, impl HspiDma<T>>, |
| 679 | config: Config, | 677 | config: Config, |
| 680 | ) -> Self { | 678 | ) -> Self { |
| 681 | Self::new_inner( | 679 | Self::new_inner( |
| @@ -712,19 +710,19 @@ impl<'d, T: Instance> Hspi<'d, T, Async> { | |||
| 712 | 710 | ||
| 713 | /// Create new HSPI driver for octospi external chip | 711 | /// Create new HSPI driver for octospi external chip |
| 714 | pub fn new_octospi( | 712 | pub fn new_octospi( |
| 715 | peri: impl Peripheral<P = T> + 'd, | 713 | peri: Peri<'d, T>, |
| 716 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 714 | sck: Peri<'d, impl SckPin<T>>, |
| 717 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 715 | d0: Peri<'d, impl D0Pin<T>>, |
| 718 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 716 | d1: Peri<'d, impl D1Pin<T>>, |
| 719 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 717 | d2: Peri<'d, impl D2Pin<T>>, |
| 720 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 718 | d3: Peri<'d, impl D3Pin<T>>, |
| 721 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 719 | d4: Peri<'d, impl D4Pin<T>>, |
| 722 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 720 | d5: Peri<'d, impl D5Pin<T>>, |
| 723 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 721 | d6: Peri<'d, impl D6Pin<T>>, |
| 724 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 722 | d7: Peri<'d, impl D7Pin<T>>, |
| 725 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 723 | nss: Peri<'d, impl NSSPin<T>>, |
| 726 | dqs0: impl Peripheral<P = impl DQS0Pin<T>> + 'd, | 724 | dqs0: Peri<'d, impl DQS0Pin<T>>, |
| 727 | dma: impl Peripheral<P = impl HspiDma<T>> + 'd, | 725 | dma: Peri<'d, impl HspiDma<T>>, |
| 728 | config: Config, | 726 | config: Config, |
| 729 | ) -> Self { | 727 | ) -> Self { |
| 730 | Self::new_inner( | 728 | Self::new_inner( |
| @@ -943,7 +941,7 @@ pub(crate) trait SealedInstance { | |||
| 943 | 941 | ||
| 944 | /// HSPI instance trait. | 942 | /// HSPI instance trait. |
| 945 | #[allow(private_bounds)] | 943 | #[allow(private_bounds)] |
| 946 | pub trait Instance: Peripheral<P = Self> + SealedInstance + RccPeripheral {} | 944 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral {} |
| 947 | 945 | ||
| 948 | pin_trait!(SckPin, Instance); | 946 | pin_trait!(SckPin, Instance); |
| 949 | pin_trait!(NckPin, Instance); | 947 | pin_trait!(NckPin, Instance); |
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 3a9954663..1689fdb84 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs | |||
| @@ -9,7 +9,7 @@ use core::future::Future; | |||
| 9 | use core::iter; | 9 | use core::iter; |
| 10 | use core::marker::PhantomData; | 10 | use core::marker::PhantomData; |
| 11 | 11 | ||
| 12 | use embassy_hal_internal::{Peripheral, PeripheralRef}; | 12 | use embassy_hal_internal::Peri; |
| 13 | use embassy_sync::waitqueue::AtomicWaker; | 13 | use embassy_sync::waitqueue::AtomicWaker; |
| 14 | #[cfg(feature = "time")] | 14 | #[cfg(feature = "time")] |
| 15 | use embassy_time::{Duration, Instant}; | 15 | use embassy_time::{Duration, Instant}; |
| @@ -131,8 +131,8 @@ pub struct I2c<'d, M: Mode> { | |||
| 131 | info: &'static Info, | 131 | info: &'static Info, |
| 132 | state: &'static State, | 132 | state: &'static State, |
| 133 | kernel_clock: Hertz, | 133 | kernel_clock: Hertz, |
| 134 | scl: Option<PeripheralRef<'d, AnyPin>>, | 134 | scl: Option<Peri<'d, AnyPin>>, |
| 135 | sda: Option<PeripheralRef<'d, AnyPin>>, | 135 | sda: Option<Peri<'d, AnyPin>>, |
| 136 | tx_dma: Option<ChannelAndRequest<'d>>, | 136 | tx_dma: Option<ChannelAndRequest<'d>>, |
| 137 | rx_dma: Option<ChannelAndRequest<'d>>, | 137 | rx_dma: Option<ChannelAndRequest<'d>>, |
| 138 | #[cfg(feature = "time")] | 138 | #[cfg(feature = "time")] |
| @@ -143,14 +143,14 @@ pub struct I2c<'d, M: Mode> { | |||
| 143 | impl<'d> I2c<'d, Async> { | 143 | impl<'d> I2c<'d, Async> { |
| 144 | /// Create a new I2C driver. | 144 | /// Create a new I2C driver. |
| 145 | pub fn new<T: Instance>( | 145 | pub fn new<T: Instance>( |
| 146 | peri: impl Peripheral<P = T> + 'd, | 146 | peri: Peri<'d, T>, |
| 147 | scl: impl Peripheral<P = impl SclPin<T>> + 'd, | 147 | scl: Peri<'d, impl SclPin<T>>, |
| 148 | sda: impl Peripheral<P = impl SdaPin<T>> + 'd, | 148 | sda: Peri<'d, impl SdaPin<T>>, |
| 149 | _irq: impl interrupt::typelevel::Binding<T::EventInterrupt, EventInterruptHandler<T>> | 149 | _irq: impl interrupt::typelevel::Binding<T::EventInterrupt, EventInterruptHandler<T>> |
| 150 | + interrupt::typelevel::Binding<T::ErrorInterrupt, ErrorInterruptHandler<T>> | 150 | + interrupt::typelevel::Binding<T::ErrorInterrupt, ErrorInterruptHandler<T>> |
| 151 | + 'd, | 151 | + 'd, |
| 152 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 152 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 153 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 153 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 154 | freq: Hertz, | 154 | freq: Hertz, |
| 155 | config: Config, | 155 | config: Config, |
| 156 | ) -> Self { | 156 | ) -> Self { |
| @@ -169,9 +169,9 @@ impl<'d> I2c<'d, Async> { | |||
| 169 | impl<'d> I2c<'d, Blocking> { | 169 | impl<'d> I2c<'d, Blocking> { |
| 170 | /// Create a new blocking I2C driver. | 170 | /// Create a new blocking I2C driver. |
| 171 | pub fn new_blocking<T: Instance>( | 171 | pub fn new_blocking<T: Instance>( |
| 172 | peri: impl Peripheral<P = T> + 'd, | 172 | peri: Peri<'d, T>, |
| 173 | scl: impl Peripheral<P = impl SclPin<T>> + 'd, | 173 | scl: Peri<'d, impl SclPin<T>>, |
| 174 | sda: impl Peripheral<P = impl SdaPin<T>> + 'd, | 174 | sda: Peri<'d, impl SdaPin<T>>, |
| 175 | freq: Hertz, | 175 | freq: Hertz, |
| 176 | config: Config, | 176 | config: Config, |
| 177 | ) -> Self { | 177 | ) -> Self { |
| @@ -190,9 +190,9 @@ impl<'d> I2c<'d, Blocking> { | |||
| 190 | impl<'d, M: Mode> I2c<'d, M> { | 190 | impl<'d, M: Mode> I2c<'d, M> { |
| 191 | /// Create a new I2C driver. | 191 | /// Create a new I2C driver. |
| 192 | fn new_inner<T: Instance>( | 192 | fn new_inner<T: Instance>( |
| 193 | _peri: impl Peripheral<P = T> + 'd, | 193 | _peri: Peri<'d, T>, |
| 194 | scl: Option<PeripheralRef<'d, AnyPin>>, | 194 | scl: Option<Peri<'d, AnyPin>>, |
| 195 | sda: Option<PeripheralRef<'d, AnyPin>>, | 195 | sda: Option<Peri<'d, AnyPin>>, |
| 196 | tx_dma: Option<ChannelAndRequest<'d>>, | 196 | tx_dma: Option<ChannelAndRequest<'d>>, |
| 197 | rx_dma: Option<ChannelAndRequest<'d>>, | 197 | rx_dma: Option<ChannelAndRequest<'d>>, |
| 198 | freq: Hertz, | 198 | freq: Hertz, |
diff --git a/embassy-stm32/src/i2s.rs b/embassy-stm32/src/i2s.rs index ce166d718..5005a5cdb 100644 --- a/embassy-stm32/src/i2s.rs +++ b/embassy-stm32/src/i2s.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | //! Inter-IC Sound (I2S) | 1 | //! Inter-IC Sound (I2S) |
| 2 | 2 | ||
| 3 | use embassy_futures::join::join; | 3 | use embassy_futures::join::join; |
| 4 | use embassy_hal_internal::into_ref; | ||
| 5 | use stm32_metapac::spi::vals; | 4 | use stm32_metapac::spi::vals; |
| 6 | 5 | ||
| 7 | use crate::dma::{ringbuffer, ChannelAndRequest, ReadableRingBuffer, TransferOptions, WritableRingBuffer}; | 6 | use crate::dma::{ringbuffer, ChannelAndRequest, ReadableRingBuffer, TransferOptions, WritableRingBuffer}; |
| @@ -9,7 +8,7 @@ use crate::gpio::{AfType, AnyPin, OutputType, SealedPin, Speed}; | |||
| 9 | use crate::mode::Async; | 8 | use crate::mode::Async; |
| 10 | use crate::spi::{Config as SpiConfig, RegsExt as _, *}; | 9 | use crate::spi::{Config as SpiConfig, RegsExt as _, *}; |
| 11 | use crate::time::Hertz; | 10 | use crate::time::Hertz; |
| 12 | use crate::{Peripheral, PeripheralRef}; | 11 | use crate::Peri; |
| 13 | 12 | ||
| 14 | /// I2S mode | 13 | /// I2S mode |
| 15 | #[derive(Copy, Clone)] | 14 | #[derive(Copy, Clone)] |
| @@ -225,11 +224,11 @@ pub struct I2S<'d, W: Word> { | |||
| 225 | #[allow(dead_code)] | 224 | #[allow(dead_code)] |
| 226 | mode: Mode, | 225 | mode: Mode, |
| 227 | spi: Spi<'d, Async>, | 226 | spi: Spi<'d, Async>, |
| 228 | txsd: Option<PeripheralRef<'d, AnyPin>>, | 227 | txsd: Option<Peri<'d, AnyPin>>, |
| 229 | rxsd: Option<PeripheralRef<'d, AnyPin>>, | 228 | rxsd: Option<Peri<'d, AnyPin>>, |
| 230 | ws: Option<PeripheralRef<'d, AnyPin>>, | 229 | ws: Option<Peri<'d, AnyPin>>, |
| 231 | ck: Option<PeripheralRef<'d, AnyPin>>, | 230 | ck: Option<Peri<'d, AnyPin>>, |
| 232 | mck: Option<PeripheralRef<'d, AnyPin>>, | 231 | mck: Option<Peri<'d, AnyPin>>, |
| 233 | tx_ring_buffer: Option<WritableRingBuffer<'d, W>>, | 232 | tx_ring_buffer: Option<WritableRingBuffer<'d, W>>, |
| 234 | rx_ring_buffer: Option<ReadableRingBuffer<'d, W>>, | 233 | rx_ring_buffer: Option<ReadableRingBuffer<'d, W>>, |
| 235 | } | 234 | } |
| @@ -237,12 +236,12 @@ pub struct I2S<'d, W: Word> { | |||
| 237 | impl<'d, W: Word> I2S<'d, W> { | 236 | impl<'d, W: Word> I2S<'d, W> { |
| 238 | /// Create a transmitter driver. | 237 | /// Create a transmitter driver. |
| 239 | pub fn new_txonly<T: Instance>( | 238 | pub fn new_txonly<T: Instance>( |
| 240 | peri: impl Peripheral<P = T> + 'd, | 239 | peri: Peri<'d, T>, |
| 241 | sd: impl Peripheral<P = impl MosiPin<T>> + 'd, | 240 | sd: Peri<'d, impl MosiPin<T>>, |
| 242 | ws: impl Peripheral<P = impl WsPin<T>> + 'd, | 241 | ws: Peri<'d, impl WsPin<T>>, |
| 243 | ck: impl Peripheral<P = impl CkPin<T>> + 'd, | 242 | ck: Peri<'d, impl CkPin<T>>, |
| 244 | mck: impl Peripheral<P = impl MckPin<T>> + 'd, | 243 | mck: Peri<'d, impl MckPin<T>>, |
| 245 | txdma: impl Peripheral<P = impl TxDma<T>> + 'd, | 244 | txdma: Peri<'d, impl TxDma<T>>, |
| 246 | txdma_buf: &'d mut [W], | 245 | txdma_buf: &'d mut [W], |
| 247 | freq: Hertz, | 246 | freq: Hertz, |
| 248 | config: Config, | 247 | config: Config, |
| @@ -264,11 +263,11 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 264 | 263 | ||
| 265 | /// Create a transmitter driver without a master clock pin. | 264 | /// Create a transmitter driver without a master clock pin. |
| 266 | pub fn new_txonly_nomck<T: Instance>( | 265 | pub fn new_txonly_nomck<T: Instance>( |
| 267 | peri: impl Peripheral<P = T> + 'd, | 266 | peri: Peri<'d, T>, |
| 268 | sd: impl Peripheral<P = impl MosiPin<T>> + 'd, | 267 | sd: Peri<'d, impl MosiPin<T>>, |
| 269 | ws: impl Peripheral<P = impl WsPin<T>> + 'd, | 268 | ws: Peri<'d, impl WsPin<T>>, |
| 270 | ck: impl Peripheral<P = impl CkPin<T>> + 'd, | 269 | ck: Peri<'d, impl CkPin<T>>, |
| 271 | txdma: impl Peripheral<P = impl TxDma<T>> + 'd, | 270 | txdma: Peri<'d, impl TxDma<T>>, |
| 272 | txdma_buf: &'d mut [W], | 271 | txdma_buf: &'d mut [W], |
| 273 | freq: Hertz, | 272 | freq: Hertz, |
| 274 | config: Config, | 273 | config: Config, |
| @@ -290,12 +289,12 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 290 | 289 | ||
| 291 | /// Create a receiver driver. | 290 | /// Create a receiver driver. |
| 292 | pub fn new_rxonly<T: Instance>( | 291 | pub fn new_rxonly<T: Instance>( |
| 293 | peri: impl Peripheral<P = T> + 'd, | 292 | peri: Peri<'d, T>, |
| 294 | sd: impl Peripheral<P = impl MisoPin<T>> + 'd, | 293 | sd: Peri<'d, impl MisoPin<T>>, |
| 295 | ws: impl Peripheral<P = impl WsPin<T>> + 'd, | 294 | ws: Peri<'d, impl WsPin<T>>, |
| 296 | ck: impl Peripheral<P = impl CkPin<T>> + 'd, | 295 | ck: Peri<'d, impl CkPin<T>>, |
| 297 | mck: impl Peripheral<P = impl MckPin<T>> + 'd, | 296 | mck: Peri<'d, impl MckPin<T>>, |
| 298 | rxdma: impl Peripheral<P = impl RxDma<T>> + 'd, | 297 | rxdma: Peri<'d, impl RxDma<T>>, |
| 299 | rxdma_buf: &'d mut [W], | 298 | rxdma_buf: &'d mut [W], |
| 300 | freq: Hertz, | 299 | freq: Hertz, |
| 301 | config: Config, | 300 | config: Config, |
| @@ -318,15 +317,15 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 318 | #[cfg(spi_v3)] | 317 | #[cfg(spi_v3)] |
| 319 | /// Create a full duplex driver. | 318 | /// Create a full duplex driver. |
| 320 | pub fn new_full_duplex<T: Instance>( | 319 | pub fn new_full_duplex<T: Instance>( |
| 321 | peri: impl Peripheral<P = T> + 'd, | 320 | peri: Peri<'d, T>, |
| 322 | txsd: impl Peripheral<P = impl MosiPin<T>> + 'd, | 321 | txsd: Peri<'d, impl MosiPin<T>>, |
| 323 | rxsd: impl Peripheral<P = impl MisoPin<T>> + 'd, | 322 | rxsd: Peri<'d, impl MisoPin<T>>, |
| 324 | ws: impl Peripheral<P = impl WsPin<T>> + 'd, | 323 | ws: Peri<'d, impl WsPin<T>>, |
| 325 | ck: impl Peripheral<P = impl CkPin<T>> + 'd, | 324 | ck: Peri<'d, impl CkPin<T>>, |
| 326 | mck: impl Peripheral<P = impl MckPin<T>> + 'd, | 325 | mck: Peri<'d, impl MckPin<T>>, |
| 327 | txdma: impl Peripheral<P = impl TxDma<T>> + 'd, | 326 | txdma: Peri<'d, impl TxDma<T>>, |
| 328 | txdma_buf: &'d mut [W], | 327 | txdma_buf: &'d mut [W], |
| 329 | rxdma: impl Peripheral<P = impl RxDma<T>> + 'd, | 328 | rxdma: Peri<'d, impl RxDma<T>>, |
| 330 | rxdma_buf: &'d mut [W], | 329 | rxdma_buf: &'d mut [W], |
| 331 | freq: Hertz, | 330 | freq: Hertz, |
| 332 | config: Config, | 331 | config: Config, |
| @@ -466,20 +465,18 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 466 | } | 465 | } |
| 467 | 466 | ||
| 468 | fn new_inner<T: Instance>( | 467 | fn new_inner<T: Instance>( |
| 469 | peri: impl Peripheral<P = T> + 'd, | 468 | peri: Peri<'d, T>, |
| 470 | txsd: Option<PeripheralRef<'d, AnyPin>>, | 469 | txsd: Option<Peri<'d, AnyPin>>, |
| 471 | rxsd: Option<PeripheralRef<'d, AnyPin>>, | 470 | rxsd: Option<Peri<'d, AnyPin>>, |
| 472 | ws: impl Peripheral<P = impl WsPin<T>> + 'd, | 471 | ws: Peri<'d, impl WsPin<T>>, |
| 473 | ck: impl Peripheral<P = impl CkPin<T>> + 'd, | 472 | ck: Peri<'d, impl CkPin<T>>, |
| 474 | mck: Option<PeripheralRef<'d, AnyPin>>, | 473 | mck: Option<Peri<'d, AnyPin>>, |
| 475 | txdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, | 474 | txdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, |
| 476 | rxdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, | 475 | rxdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, |
| 477 | freq: Hertz, | 476 | freq: Hertz, |
| 478 | config: Config, | 477 | config: Config, |
| 479 | function: Function, | 478 | function: Function, |
| 480 | ) -> Self { | 479 | ) -> Self { |
| 481 | into_ref!(ws, ck); | ||
| 482 | |||
| 483 | ws.set_as_af(ws.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 480 | ws.set_as_af(ws.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 484 | ck.set_as_af(ck.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 481 | ck.set_as_af(ck.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 485 | 482 | ||
| @@ -583,11 +580,11 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 583 | Self { | 580 | Self { |
| 584 | mode: config.mode, | 581 | mode: config.mode, |
| 585 | spi, | 582 | spi, |
| 586 | txsd: txsd.map(|w| w.map_into()), | 583 | txsd: txsd.map(|w| w.into()), |
| 587 | rxsd: rxsd.map(|w| w.map_into()), | 584 | rxsd: rxsd.map(|w| w.into()), |
| 588 | ws: Some(ws.map_into()), | 585 | ws: Some(ws.into()), |
| 589 | ck: Some(ck.map_into()), | 586 | ck: Some(ck.into()), |
| 590 | mck: mck.map(|w| w.map_into()), | 587 | mck: mck.map(|w| w.into()), |
| 591 | tx_ring_buffer: txdma.map(|(ch, buf)| unsafe { | 588 | tx_ring_buffer: txdma.map(|(ch, buf)| unsafe { |
| 592 | WritableRingBuffer::new(ch.channel, ch.request, regs.tx_ptr(), buf, opts) | 589 | WritableRingBuffer::new(ch.channel, ch.request, regs.tx_ptr(), buf, opts) |
| 593 | }), | 590 | }), |
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index c37908dbc..4d7aac81f 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -211,7 +211,7 @@ macro_rules! bind_interrupts { | |||
| 211 | 211 | ||
| 212 | // Reexports | 212 | // Reexports |
| 213 | pub use _generated::{peripherals, Peripherals}; | 213 | pub use _generated::{peripherals, Peripherals}; |
| 214 | pub use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; | 214 | pub use embassy_hal_internal::{Peri, PeripheralType}; |
| 215 | #[cfg(feature = "unstable-pac")] | 215 | #[cfg(feature = "unstable-pac")] |
| 216 | pub use stm32_metapac as pac; | 216 | pub use stm32_metapac as pac; |
| 217 | #[cfg(not(feature = "unstable-pac"))] | 217 | #[cfg(not(feature = "unstable-pac"))] |
diff --git a/embassy-stm32/src/lptim/mod.rs b/embassy-stm32/src/lptim/mod.rs index 1649cc5b4..e0ddba1c7 100644 --- a/embassy-stm32/src/lptim/mod.rs +++ b/embassy-stm32/src/lptim/mod.rs | |||
| @@ -10,6 +10,7 @@ use crate::rcc::RccPeripheral; | |||
| 10 | mod channel; | 10 | mod channel; |
| 11 | #[cfg(any(lptim_v2a, lptim_v2b))] | 11 | #[cfg(any(lptim_v2a, lptim_v2b))] |
| 12 | pub use channel::Channel; | 12 | pub use channel::Channel; |
| 13 | use embassy_hal_internal::PeripheralType; | ||
| 13 | 14 | ||
| 14 | pin_trait!(OutputPin, BasicInstance); | 15 | pin_trait!(OutputPin, BasicInstance); |
| 15 | pin_trait!(Channel1Pin, BasicInstance); | 16 | pin_trait!(Channel1Pin, BasicInstance); |
| @@ -22,7 +23,7 @@ pub(crate) trait SealedBasicInstance: RccPeripheral {} | |||
| 22 | 23 | ||
| 23 | /// LPTIM basic instance trait. | 24 | /// LPTIM basic instance trait. |
| 24 | #[allow(private_bounds)] | 25 | #[allow(private_bounds)] |
| 25 | pub trait BasicInstance: SealedBasicInstance + 'static {} | 26 | pub trait BasicInstance: PeripheralType + SealedBasicInstance + 'static {} |
| 26 | 27 | ||
| 27 | /// LPTIM instance trait. | 28 | /// LPTIM instance trait. |
| 28 | #[allow(private_bounds)] | 29 | #[allow(private_bounds)] |
diff --git a/embassy-stm32/src/lptim/pwm.rs b/embassy-stm32/src/lptim/pwm.rs index 132f5815e..2f2d7ba01 100644 --- a/embassy-stm32/src/lptim/pwm.rs +++ b/embassy-stm32/src/lptim/pwm.rs | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | 4 | ||
| 5 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 5 | use embassy_hal_internal::Peri; |
| 6 | 6 | ||
| 7 | use super::timer::Timer; | 7 | use super::timer::Timer; |
| 8 | #[cfg(not(any(lptim_v2a, lptim_v2b)))] | 8 | #[cfg(not(any(lptim_v2a, lptim_v2b)))] |
| @@ -14,7 +14,6 @@ use super::{BasicInstance, Instance}; | |||
| 14 | use crate::gpio::Pull; | 14 | use crate::gpio::Pull; |
| 15 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; | 15 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; |
| 16 | use crate::time::Hertz; | 16 | use crate::time::Hertz; |
| 17 | use crate::Peripheral; | ||
| 18 | 17 | ||
| 19 | /// Output marker type. | 18 | /// Output marker type. |
| 20 | pub enum Output {} | 19 | pub enum Output {} |
| @@ -27,7 +26,7 @@ pub enum Ch2 {} | |||
| 27 | /// | 26 | /// |
| 28 | /// This wraps a pin to make it usable with PWM. | 27 | /// This wraps a pin to make it usable with PWM. |
| 29 | pub struct PwmPin<'d, T, C> { | 28 | pub struct PwmPin<'d, T, C> { |
| 30 | _pin: PeripheralRef<'d, AnyPin>, | 29 | _pin: Peri<'d, AnyPin>, |
| 31 | phantom: PhantomData<(T, C)>, | 30 | phantom: PhantomData<(T, C)>, |
| 32 | } | 31 | } |
| 33 | 32 | ||
| @@ -48,8 +47,7 @@ macro_rules! channel_impl { | |||
| 48 | ($new_chx:ident, $new_chx_with_config:ident, $channel:ident, $pin_trait:ident) => { | 47 | ($new_chx:ident, $new_chx_with_config:ident, $channel:ident, $pin_trait:ident) => { |
| 49 | impl<'d, T: BasicInstance> PwmPin<'d, T, $channel> { | 48 | impl<'d, T: BasicInstance> PwmPin<'d, T, $channel> { |
| 50 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] | 49 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] |
| 51 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self { | 50 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self { |
| 52 | into_ref!(pin); | ||
| 53 | critical_section::with(|_| { | 51 | critical_section::with(|_| { |
| 54 | pin.set_low(); | 52 | pin.set_low(); |
| 55 | pin.set_as_af( | 53 | pin.set_as_af( |
| @@ -58,16 +56,12 @@ macro_rules! channel_impl { | |||
| 58 | ); | 56 | ); |
| 59 | }); | 57 | }); |
| 60 | PwmPin { | 58 | PwmPin { |
| 61 | _pin: pin.map_into(), | 59 | _pin: pin.into(), |
| 62 | phantom: PhantomData, | 60 | phantom: PhantomData, |
| 63 | } | 61 | } |
| 64 | } | 62 | } |
| 65 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance with config.")] | 63 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance with config.")] |
| 66 | pub fn $new_chx_with_config( | 64 | pub fn $new_chx_with_config(pin: Peri<'d, impl $pin_trait<T>>, pin_config: PwmPinConfig) -> Self { |
| 67 | pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, | ||
| 68 | pin_config: PwmPinConfig, | ||
| 69 | ) -> Self { | ||
| 70 | into_ref!(pin); | ||
| 71 | critical_section::with(|_| { | 65 | critical_section::with(|_| { |
| 72 | pin.set_low(); | 66 | pin.set_low(); |
| 73 | pin.set_as_af( | 67 | pin.set_as_af( |
| @@ -79,7 +73,7 @@ macro_rules! channel_impl { | |||
| 79 | ); | 73 | ); |
| 80 | }); | 74 | }); |
| 81 | PwmPin { | 75 | PwmPin { |
| 82 | _pin: pin.map_into(), | 76 | _pin: pin.into(), |
| 83 | phantom: PhantomData, | 77 | phantom: PhantomData, |
| 84 | } | 78 | } |
| 85 | } | 79 | } |
| @@ -102,7 +96,7 @@ pub struct Pwm<'d, T: Instance> { | |||
| 102 | #[cfg(not(any(lptim_v2a, lptim_v2b)))] | 96 | #[cfg(not(any(lptim_v2a, lptim_v2b)))] |
| 103 | impl<'d, T: Instance> Pwm<'d, T> { | 97 | impl<'d, T: Instance> Pwm<'d, T> { |
| 104 | /// Create a new PWM driver. | 98 | /// Create a new PWM driver. |
| 105 | pub fn new(tim: impl Peripheral<P = T> + 'd, _output_pin: PwmPin<'d, T, Output>, freq: Hertz) -> Self { | 99 | pub fn new(tim: Peri<'d, T>, _output_pin: PwmPin<'d, T, Output>, freq: Hertz) -> Self { |
| 106 | Self::new_inner(tim, freq) | 100 | Self::new_inner(tim, freq) |
| 107 | } | 101 | } |
| 108 | 102 | ||
| @@ -128,7 +122,7 @@ impl<'d, T: Instance> Pwm<'d, T> { | |||
| 128 | impl<'d, T: Instance> Pwm<'d, T> { | 122 | impl<'d, T: Instance> Pwm<'d, T> { |
| 129 | /// Create a new PWM driver. | 123 | /// Create a new PWM driver. |
| 130 | pub fn new( | 124 | pub fn new( |
| 131 | tim: impl Peripheral<P = T> + 'd, | 125 | tim: Peri<'d, T>, |
| 132 | _ch1_pin: Option<PwmPin<'d, T, Ch1>>, | 126 | _ch1_pin: Option<PwmPin<'d, T, Ch1>>, |
| 133 | _ch2_pin: Option<PwmPin<'d, T, Ch2>>, | 127 | _ch2_pin: Option<PwmPin<'d, T, Ch2>>, |
| 134 | freq: Hertz, | 128 | freq: Hertz, |
| @@ -174,7 +168,7 @@ impl<'d, T: Instance> Pwm<'d, T> { | |||
| 174 | } | 168 | } |
| 175 | 169 | ||
| 176 | impl<'d, T: Instance> Pwm<'d, T> { | 170 | impl<'d, T: Instance> Pwm<'d, T> { |
| 177 | fn new_inner(tim: impl Peripheral<P = T> + 'd, freq: Hertz) -> Self { | 171 | fn new_inner(tim: Peri<'d, T>, freq: Hertz) -> Self { |
| 178 | let mut this = Self { inner: Timer::new(tim) }; | 172 | let mut this = Self { inner: Timer::new(tim) }; |
| 179 | 173 | ||
| 180 | this.inner.enable(); | 174 | this.inner.enable(); |
diff --git a/embassy-stm32/src/lptim/timer/mod.rs b/embassy-stm32/src/lptim/timer/mod.rs index e62fcab49..a629be62b 100644 --- a/embassy-stm32/src/lptim/timer/mod.rs +++ b/embassy-stm32/src/lptim/timer/mod.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | //! Low-level timer driver. | 1 | //! Low-level timer driver. |
| 2 | mod prescaler; | 2 | mod prescaler; |
| 3 | 3 | ||
| 4 | use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; | 4 | use embassy_hal_internal::Peri; |
| 5 | 5 | ||
| 6 | #[cfg(any(lptim_v2a, lptim_v2b))] | 6 | #[cfg(any(lptim_v2a, lptim_v2b))] |
| 7 | use super::channel::Channel; | 7 | use super::channel::Channel; |
| @@ -17,14 +17,12 @@ use crate::time::Hertz; | |||
| 17 | 17 | ||
| 18 | /// Low-level timer driver. | 18 | /// Low-level timer driver. |
| 19 | pub struct Timer<'d, T: Instance> { | 19 | pub struct Timer<'d, T: Instance> { |
| 20 | _tim: PeripheralRef<'d, T>, | 20 | _tim: Peri<'d, T>, |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | impl<'d, T: Instance> Timer<'d, T> { | 23 | impl<'d, T: Instance> Timer<'d, T> { |
| 24 | /// Create a new timer driver. | 24 | /// Create a new timer driver. |
| 25 | pub fn new(tim: impl Peripheral<P = T> + 'd) -> Self { | 25 | pub fn new(tim: Peri<'d, T>) -> Self { |
| 26 | into_ref!(tim); | ||
| 27 | |||
| 28 | rcc::enable_and_reset::<T>(); | 26 | rcc::enable_and_reset::<T>(); |
| 29 | 27 | ||
| 30 | Self { _tim: tim } | 28 | Self { _tim: tim } |
diff --git a/embassy-stm32/src/ltdc.rs b/embassy-stm32/src/ltdc.rs index 16210b7dc..0f6ef569c 100644 --- a/embassy-stm32/src/ltdc.rs +++ b/embassy-stm32/src/ltdc.rs | |||
| @@ -6,7 +6,7 @@ use core::future::poll_fn; | |||
| 6 | use core::marker::PhantomData; | 6 | use core::marker::PhantomData; |
| 7 | use core::task::Poll; | 7 | use core::task::Poll; |
| 8 | 8 | ||
| 9 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 9 | use embassy_hal_internal::PeripheralType; |
| 10 | use embassy_sync::waitqueue::AtomicWaker; | 10 | use embassy_sync::waitqueue::AtomicWaker; |
| 11 | use stm32_metapac::ltdc::regs::Dccr; | 11 | use stm32_metapac::ltdc::regs::Dccr; |
| 12 | use stm32_metapac::ltdc::vals::{Bf1, Bf2, Cfuif, Clif, Crrif, Cterrif, Pf, Vbr}; | 12 | use stm32_metapac::ltdc::vals::{Bf1, Bf2, Cfuif, Clif, Crrif, Cterrif, Pf, Vbr}; |
| @@ -14,7 +14,7 @@ use stm32_metapac::ltdc::vals::{Bf1, Bf2, Cfuif, Clif, Crrif, Cterrif, Pf, Vbr}; | |||
| 14 | use crate::gpio::{AfType, OutputType, Speed}; | 14 | use crate::gpio::{AfType, OutputType, Speed}; |
| 15 | use crate::interrupt::typelevel::Interrupt; | 15 | use crate::interrupt::typelevel::Interrupt; |
| 16 | use crate::interrupt::{self}; | 16 | use crate::interrupt::{self}; |
| 17 | use crate::{peripherals, rcc, Peripheral}; | 17 | use crate::{peripherals, rcc, Peri}; |
| 18 | 18 | ||
| 19 | static LTDC_WAKER: AtomicWaker = AtomicWaker::new(); | 19 | static LTDC_WAKER: AtomicWaker = AtomicWaker::new(); |
| 20 | 20 | ||
| @@ -83,7 +83,7 @@ pub enum PolarityActive { | |||
| 83 | 83 | ||
| 84 | /// LTDC driver. | 84 | /// LTDC driver. |
| 85 | pub struct Ltdc<'d, T: Instance> { | 85 | pub struct Ltdc<'d, T: Instance> { |
| 86 | _peri: PeripheralRef<'d, T>, | 86 | _peri: Peri<'d, T>, |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | /// LTDC interrupt handler. | 89 | /// LTDC interrupt handler. |
| @@ -178,47 +178,45 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 178 | impl<'d, T: Instance> Ltdc<'d, T> { | 178 | impl<'d, T: Instance> Ltdc<'d, T> { |
| 179 | // Create a new LTDC driver without specifying color and control pins. This is typically used if you want to drive a display though a DsiHost | 179 | // Create a new LTDC driver without specifying color and control pins. This is typically used if you want to drive a display though a DsiHost |
| 180 | /// Note: Full-Duplex modes are not supported at this time | 180 | /// Note: Full-Duplex modes are not supported at this time |
| 181 | pub fn new(peri: impl Peripheral<P = T> + 'd) -> Self { | 181 | pub fn new(peri: Peri<'d, T>) -> Self { |
| 182 | Self::setup_clocks(); | 182 | Self::setup_clocks(); |
| 183 | into_ref!(peri); | ||
| 184 | Self { _peri: peri } | 183 | Self { _peri: peri } |
| 185 | } | 184 | } |
| 186 | 185 | ||
| 187 | /// Create a new LTDC driver. 8 pins per color channel for blue, green and red | 186 | /// Create a new LTDC driver. 8 pins per color channel for blue, green and red |
| 188 | #[allow(clippy::too_many_arguments)] | 187 | #[allow(clippy::too_many_arguments)] |
| 189 | pub fn new_with_pins( | 188 | pub fn new_with_pins( |
| 190 | peri: impl Peripheral<P = T> + 'd, | 189 | peri: Peri<'d, T>, |
| 191 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 190 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 192 | clk: impl Peripheral<P = impl ClkPin<T>> + 'd, | 191 | clk: Peri<'d, impl ClkPin<T>>, |
| 193 | hsync: impl Peripheral<P = impl HsyncPin<T>> + 'd, | 192 | hsync: Peri<'d, impl HsyncPin<T>>, |
| 194 | vsync: impl Peripheral<P = impl VsyncPin<T>> + 'd, | 193 | vsync: Peri<'d, impl VsyncPin<T>>, |
| 195 | b0: impl Peripheral<P = impl B0Pin<T>> + 'd, | 194 | b0: Peri<'d, impl B0Pin<T>>, |
| 196 | b1: impl Peripheral<P = impl B1Pin<T>> + 'd, | 195 | b1: Peri<'d, impl B1Pin<T>>, |
| 197 | b2: impl Peripheral<P = impl B2Pin<T>> + 'd, | 196 | b2: Peri<'d, impl B2Pin<T>>, |
| 198 | b3: impl Peripheral<P = impl B3Pin<T>> + 'd, | 197 | b3: Peri<'d, impl B3Pin<T>>, |
| 199 | b4: impl Peripheral<P = impl B4Pin<T>> + 'd, | 198 | b4: Peri<'d, impl B4Pin<T>>, |
| 200 | b5: impl Peripheral<P = impl B5Pin<T>> + 'd, | 199 | b5: Peri<'d, impl B5Pin<T>>, |
| 201 | b6: impl Peripheral<P = impl B6Pin<T>> + 'd, | 200 | b6: Peri<'d, impl B6Pin<T>>, |
| 202 | b7: impl Peripheral<P = impl B7Pin<T>> + 'd, | 201 | b7: Peri<'d, impl B7Pin<T>>, |
| 203 | g0: impl Peripheral<P = impl G0Pin<T>> + 'd, | 202 | g0: Peri<'d, impl G0Pin<T>>, |
| 204 | g1: impl Peripheral<P = impl G1Pin<T>> + 'd, | 203 | g1: Peri<'d, impl G1Pin<T>>, |
| 205 | g2: impl Peripheral<P = impl G2Pin<T>> + 'd, | 204 | g2: Peri<'d, impl G2Pin<T>>, |
| 206 | g3: impl Peripheral<P = impl G3Pin<T>> + 'd, | 205 | g3: Peri<'d, impl G3Pin<T>>, |
| 207 | g4: impl Peripheral<P = impl G4Pin<T>> + 'd, | 206 | g4: Peri<'d, impl G4Pin<T>>, |
| 208 | g5: impl Peripheral<P = impl G5Pin<T>> + 'd, | 207 | g5: Peri<'d, impl G5Pin<T>>, |
| 209 | g6: impl Peripheral<P = impl G6Pin<T>> + 'd, | 208 | g6: Peri<'d, impl G6Pin<T>>, |
| 210 | g7: impl Peripheral<P = impl G7Pin<T>> + 'd, | 209 | g7: Peri<'d, impl G7Pin<T>>, |
| 211 | r0: impl Peripheral<P = impl R0Pin<T>> + 'd, | 210 | r0: Peri<'d, impl R0Pin<T>>, |
| 212 | r1: impl Peripheral<P = impl R1Pin<T>> + 'd, | 211 | r1: Peri<'d, impl R1Pin<T>>, |
| 213 | r2: impl Peripheral<P = impl R2Pin<T>> + 'd, | 212 | r2: Peri<'d, impl R2Pin<T>>, |
| 214 | r3: impl Peripheral<P = impl R3Pin<T>> + 'd, | 213 | r3: Peri<'d, impl R3Pin<T>>, |
| 215 | r4: impl Peripheral<P = impl R4Pin<T>> + 'd, | 214 | r4: Peri<'d, impl R4Pin<T>>, |
| 216 | r5: impl Peripheral<P = impl R5Pin<T>> + 'd, | 215 | r5: Peri<'d, impl R5Pin<T>>, |
| 217 | r6: impl Peripheral<P = impl R6Pin<T>> + 'd, | 216 | r6: Peri<'d, impl R6Pin<T>>, |
| 218 | r7: impl Peripheral<P = impl R7Pin<T>> + 'd, | 217 | r7: Peri<'d, impl R7Pin<T>>, |
| 219 | ) -> Self { | 218 | ) -> Self { |
| 220 | Self::setup_clocks(); | 219 | Self::setup_clocks(); |
| 221 | into_ref!(peri); | ||
| 222 | new_pin!(clk, AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 220 | new_pin!(clk, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 223 | new_pin!(hsync, AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 221 | new_pin!(hsync, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 224 | new_pin!(vsync, AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 222 | new_pin!(vsync, AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| @@ -529,7 +527,7 @@ trait SealedInstance: crate::rcc::SealedRccPeripheral { | |||
| 529 | 527 | ||
| 530 | /// LTDC instance trait. | 528 | /// LTDC instance trait. |
| 531 | #[allow(private_bounds)] | 529 | #[allow(private_bounds)] |
| 532 | pub trait Instance: SealedInstance + Peripheral<P = Self> + crate::rcc::RccPeripheral + 'static + Send { | 530 | pub trait Instance: SealedInstance + PeripheralType + crate::rcc::RccPeripheral + 'static + Send { |
| 533 | /// Interrupt for this LTDC instance. | 531 | /// Interrupt for this LTDC instance. |
| 534 | type Interrupt: interrupt::typelevel::Interrupt; | 532 | type Interrupt: interrupt::typelevel::Interrupt; |
| 535 | } | 533 | } |
diff --git a/embassy-stm32/src/macros.rs b/embassy-stm32/src/macros.rs index 000773e2d..2c181a254 100644 --- a/embassy-stm32/src/macros.rs +++ b/embassy-stm32/src/macros.rs | |||
| @@ -14,7 +14,7 @@ macro_rules! peri_trait { | |||
| 14 | 14 | ||
| 15 | /// Peripheral instance trait. | 15 | /// Peripheral instance trait. |
| 16 | #[allow(private_bounds)] | 16 | #[allow(private_bounds)] |
| 17 | pub trait Instance: crate::Peripheral<P = Self> + SealedInstance + crate::rcc::RccPeripheral { | 17 | pub trait Instance: SealedInstance + crate::PeripheralType + crate::rcc::RccPeripheral { |
| 18 | $($( | 18 | $($( |
| 19 | /// Interrupt for this peripheral. | 19 | /// Interrupt for this peripheral. |
| 20 | type $irq: crate::interrupt::typelevel::Interrupt; | 20 | type $irq: crate::interrupt::typelevel::Interrupt; |
| @@ -88,10 +88,10 @@ macro_rules! dma_trait_impl { | |||
| 88 | #[allow(unused)] | 88 | #[allow(unused)] |
| 89 | macro_rules! new_dma_nonopt { | 89 | macro_rules! new_dma_nonopt { |
| 90 | ($name:ident) => {{ | 90 | ($name:ident) => {{ |
| 91 | let dma = $name.into_ref(); | 91 | let dma = $name; |
| 92 | let request = dma.request(); | 92 | let request = dma.request(); |
| 93 | crate::dma::ChannelAndRequest { | 93 | crate::dma::ChannelAndRequest { |
| 94 | channel: dma.map_into(), | 94 | channel: dma.into(), |
| 95 | request, | 95 | request, |
| 96 | } | 96 | } |
| 97 | }}; | 97 | }}; |
| @@ -99,10 +99,10 @@ macro_rules! new_dma_nonopt { | |||
| 99 | 99 | ||
| 100 | macro_rules! new_dma { | 100 | macro_rules! new_dma { |
| 101 | ($name:ident) => {{ | 101 | ($name:ident) => {{ |
| 102 | let dma = $name.into_ref(); | 102 | let dma = $name; |
| 103 | let request = dma.request(); | 103 | let request = dma.request(); |
| 104 | Some(crate::dma::ChannelAndRequest { | 104 | Some(crate::dma::ChannelAndRequest { |
| 105 | channel: dma.map_into(), | 105 | channel: dma.into(), |
| 106 | request, | 106 | request, |
| 107 | }) | 107 | }) |
| 108 | }}; | 108 | }}; |
| @@ -110,8 +110,8 @@ macro_rules! new_dma { | |||
| 110 | 110 | ||
| 111 | macro_rules! new_pin { | 111 | macro_rules! new_pin { |
| 112 | ($name:ident, $af_type:expr) => {{ | 112 | ($name:ident, $af_type:expr) => {{ |
| 113 | let pin = $name.into_ref(); | 113 | let pin = $name; |
| 114 | pin.set_as_af(pin.af_num(), $af_type); | 114 | pin.set_as_af(pin.af_num(), $af_type); |
| 115 | Some(pin.map_into()) | 115 | Some(pin.into()) |
| 116 | }}; | 116 | }}; |
| 117 | } | 117 | } |
diff --git a/embassy-stm32/src/opamp.rs b/embassy-stm32/src/opamp.rs index c7610f4b5..a81493c1b 100644 --- a/embassy-stm32/src/opamp.rs +++ b/embassy-stm32/src/opamp.rs | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | //! Operational Amplifier (OPAMP) | 1 | //! Operational Amplifier (OPAMP) |
| 2 | #![macro_use] | 2 | #![macro_use] |
| 3 | 3 | ||
| 4 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 4 | use embassy_hal_internal::PeripheralType; |
| 5 | 5 | ||
| 6 | use crate::pac::opamp::vals::*; | 6 | use crate::pac::opamp::vals::*; |
| 7 | use crate::Peripheral; | 7 | use crate::Peri; |
| 8 | 8 | ||
| 9 | /// Gain | 9 | /// Gain |
| 10 | #[allow(missing_docs)] | 10 | #[allow(missing_docs)] |
| @@ -52,16 +52,14 @@ pub struct OpAmpInternalOutput<'d, T: Instance> { | |||
| 52 | 52 | ||
| 53 | /// OpAmp driver. | 53 | /// OpAmp driver. |
| 54 | pub struct OpAmp<'d, T: Instance> { | 54 | pub struct OpAmp<'d, T: Instance> { |
| 55 | _inner: PeripheralRef<'d, T>, | 55 | _inner: Peri<'d, T>, |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | impl<'d, T: Instance> OpAmp<'d, T> { | 58 | impl<'d, T: Instance> OpAmp<'d, T> { |
| 59 | /// Create a new driver instance. | 59 | /// Create a new driver instance. |
| 60 | /// | 60 | /// |
| 61 | /// Does not enable the opamp, but does set the speed mode on some families. | 61 | /// Does not enable the opamp, but does set the speed mode on some families. |
| 62 | pub fn new(opamp: impl Peripheral<P = T> + 'd, #[cfg(opamp_g4)] speed: OpAmpSpeed) -> Self { | 62 | pub fn new(opamp: Peri<'d, T>, #[cfg(opamp_g4)] speed: OpAmpSpeed) -> Self { |
| 63 | into_ref!(opamp); | ||
| 64 | |||
| 65 | #[cfg(opamp_g4)] | 63 | #[cfg(opamp_g4)] |
| 66 | T::regs().csr().modify(|w| { | 64 | T::regs().csr().modify(|w| { |
| 67 | w.set_opahsm(speed.into()); | 65 | w.set_opahsm(speed.into()); |
| @@ -82,12 +80,10 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 82 | /// [`OpAmpOutput`] is dropped. | 80 | /// [`OpAmpOutput`] is dropped. |
| 83 | pub fn buffer_ext( | 81 | pub fn buffer_ext( |
| 84 | &mut self, | 82 | &mut self, |
| 85 | in_pin: impl Peripheral<P = impl NonInvertingPin<T> + crate::gpio::Pin>, | 83 | in_pin: Peri<'_, impl NonInvertingPin<T> + crate::gpio::Pin>, |
| 86 | out_pin: impl Peripheral<P = impl OutputPin<T> + crate::gpio::Pin>, | 84 | out_pin: Peri<'_, impl OutputPin<T> + crate::gpio::Pin>, |
| 87 | gain: OpAmpGain, | 85 | gain: OpAmpGain, |
| 88 | ) -> OpAmpOutput<'_, T> { | 86 | ) -> OpAmpOutput<'_, T> { |
| 89 | into_ref!(in_pin); | ||
| 90 | into_ref!(out_pin); | ||
| 91 | in_pin.set_as_analog(); | 87 | in_pin.set_as_analog(); |
| 92 | out_pin.set_as_analog(); | 88 | out_pin.set_as_analog(); |
| 93 | 89 | ||
| @@ -119,11 +115,7 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 119 | /// directly used as an ADC input. The opamp will be disabled when the | 115 | /// directly used as an ADC input. The opamp will be disabled when the |
| 120 | /// [`OpAmpOutput`] is dropped. | 116 | /// [`OpAmpOutput`] is dropped. |
| 121 | #[cfg(opamp_g4)] | 117 | #[cfg(opamp_g4)] |
| 122 | pub fn buffer_dac( | 118 | pub fn buffer_dac(&mut self, out_pin: Peri<'_, impl OutputPin<T> + crate::gpio::Pin>) -> OpAmpOutput<'_, T> { |
| 123 | &mut self, | ||
| 124 | out_pin: impl Peripheral<P = impl OutputPin<T> + crate::gpio::Pin>, | ||
| 125 | ) -> OpAmpOutput<'_, T> { | ||
| 126 | into_ref!(out_pin); | ||
| 127 | out_pin.set_as_analog(); | 119 | out_pin.set_as_analog(); |
| 128 | 120 | ||
| 129 | T::regs().csr().modify(|w| { | 121 | T::regs().csr().modify(|w| { |
| @@ -149,10 +141,9 @@ impl<'d, T: Instance> OpAmp<'d, T> { | |||
| 149 | #[cfg(opamp_g4)] | 141 | #[cfg(opamp_g4)] |
| 150 | pub fn buffer_int( | 142 | pub fn buffer_int( |
| 151 | &mut self, | 143 | &mut self, |
| 152 | pin: impl Peripheral<P = impl NonInvertingPin<T> + crate::gpio::Pin>, | 144 | pin: Peri<'_, impl NonInvertingPin<T> + crate::gpio::Pin>, |
| 153 | gain: OpAmpGain, | 145 | gain: OpAmpGain, |
| 154 | ) -> OpAmpInternalOutput<'_, T> { | 146 | ) -> OpAmpInternalOutput<'_, T> { |
| 155 | into_ref!(pin); | ||
| 156 | pin.set_as_analog(); | 147 | pin.set_as_analog(); |
| 157 | 148 | ||
| 158 | // PGA_GAIN value may have different meaning in different MCU serials, use with caution. | 149 | // PGA_GAIN value may have different meaning in different MCU serials, use with caution. |
| @@ -211,7 +202,7 @@ pub(crate) trait SealedOutputPin<T: Instance> {} | |||
| 211 | 202 | ||
| 212 | /// Opamp instance trait. | 203 | /// Opamp instance trait. |
| 213 | #[allow(private_bounds)] | 204 | #[allow(private_bounds)] |
| 214 | pub trait Instance: SealedInstance + 'static {} | 205 | pub trait Instance: SealedInstance + PeripheralType + 'static {} |
| 215 | /// Non-inverting pin trait. | 206 | /// Non-inverting pin trait. |
| 216 | #[allow(private_bounds)] | 207 | #[allow(private_bounds)] |
| 217 | pub trait NonInvertingPin<T: Instance>: SealedNonInvertingPin<T> {} | 208 | pub trait NonInvertingPin<T: Instance>: SealedNonInvertingPin<T> {} |
diff --git a/embassy-stm32/src/ospi/mod.rs b/embassy-stm32/src/ospi/mod.rs index 5dff3c4c3..74edfd5e4 100644 --- a/embassy-stm32/src/ospi/mod.rs +++ b/embassy-stm32/src/ospi/mod.rs | |||
| @@ -8,7 +8,7 @@ pub mod enums; | |||
| 8 | use core::marker::PhantomData; | 8 | use core::marker::PhantomData; |
| 9 | 9 | ||
| 10 | use embassy_embedded_hal::{GetConfig, SetConfig}; | 10 | use embassy_embedded_hal::{GetConfig, SetConfig}; |
| 11 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 11 | use embassy_hal_internal::PeripheralType; |
| 12 | pub use enums::*; | 12 | pub use enums::*; |
| 13 | use stm32_metapac::octospi::vals::{PhaseMode, SizeInBits}; | 13 | use stm32_metapac::octospi::vals::{PhaseMode, SizeInBits}; |
| 14 | 14 | ||
| @@ -19,7 +19,7 @@ use crate::pac::octospi::{vals, Octospi as Regs}; | |||
| 19 | #[cfg(octospim_v1)] | 19 | #[cfg(octospim_v1)] |
| 20 | use crate::pac::octospim::Octospim; | 20 | use crate::pac::octospim::Octospim; |
| 21 | use crate::rcc::{self, RccPeripheral}; | 21 | use crate::rcc::{self, RccPeripheral}; |
| 22 | use crate::{peripherals, Peripheral}; | 22 | use crate::{peripherals, Peri}; |
| 23 | 23 | ||
| 24 | /// OPSI driver config. | 24 | /// OPSI driver config. |
| 25 | #[derive(Clone, Copy)] | 25 | #[derive(Clone, Copy)] |
| @@ -160,18 +160,18 @@ pub enum OspiError { | |||
| 160 | 160 | ||
| 161 | /// OSPI driver. | 161 | /// OSPI driver. |
| 162 | pub struct Ospi<'d, T: Instance, M: PeriMode> { | 162 | pub struct Ospi<'d, T: Instance, M: PeriMode> { |
| 163 | _peri: PeripheralRef<'d, T>, | 163 | _peri: Peri<'d, T>, |
| 164 | sck: Option<PeripheralRef<'d, AnyPin>>, | 164 | sck: Option<Peri<'d, AnyPin>>, |
| 165 | d0: Option<PeripheralRef<'d, AnyPin>>, | 165 | d0: Option<Peri<'d, AnyPin>>, |
| 166 | d1: Option<PeripheralRef<'d, AnyPin>>, | 166 | d1: Option<Peri<'d, AnyPin>>, |
| 167 | d2: Option<PeripheralRef<'d, AnyPin>>, | 167 | d2: Option<Peri<'d, AnyPin>>, |
| 168 | d3: Option<PeripheralRef<'d, AnyPin>>, | 168 | d3: Option<Peri<'d, AnyPin>>, |
| 169 | d4: Option<PeripheralRef<'d, AnyPin>>, | 169 | d4: Option<Peri<'d, AnyPin>>, |
| 170 | d5: Option<PeripheralRef<'d, AnyPin>>, | 170 | d5: Option<Peri<'d, AnyPin>>, |
| 171 | d6: Option<PeripheralRef<'d, AnyPin>>, | 171 | d6: Option<Peri<'d, AnyPin>>, |
| 172 | d7: Option<PeripheralRef<'d, AnyPin>>, | 172 | d7: Option<Peri<'d, AnyPin>>, |
| 173 | nss: Option<PeripheralRef<'d, AnyPin>>, | 173 | nss: Option<Peri<'d, AnyPin>>, |
| 174 | dqs: Option<PeripheralRef<'d, AnyPin>>, | 174 | dqs: Option<Peri<'d, AnyPin>>, |
| 175 | dma: Option<ChannelAndRequest<'d>>, | 175 | dma: Option<ChannelAndRequest<'d>>, |
| 176 | _phantom: PhantomData<M>, | 176 | _phantom: PhantomData<M>, |
| 177 | config: Config, | 177 | config: Config, |
| @@ -245,25 +245,23 @@ impl<'d, T: Instance, M: PeriMode> Ospi<'d, T, M> { | |||
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | fn new_inner( | 247 | fn new_inner( |
| 248 | peri: impl Peripheral<P = T> + 'd, | 248 | peri: Peri<'d, T>, |
| 249 | d0: Option<PeripheralRef<'d, AnyPin>>, | 249 | d0: Option<Peri<'d, AnyPin>>, |
| 250 | d1: Option<PeripheralRef<'d, AnyPin>>, | 250 | d1: Option<Peri<'d, AnyPin>>, |
| 251 | d2: Option<PeripheralRef<'d, AnyPin>>, | 251 | d2: Option<Peri<'d, AnyPin>>, |
| 252 | d3: Option<PeripheralRef<'d, AnyPin>>, | 252 | d3: Option<Peri<'d, AnyPin>>, |
| 253 | d4: Option<PeripheralRef<'d, AnyPin>>, | 253 | d4: Option<Peri<'d, AnyPin>>, |
| 254 | d5: Option<PeripheralRef<'d, AnyPin>>, | 254 | d5: Option<Peri<'d, AnyPin>>, |
| 255 | d6: Option<PeripheralRef<'d, AnyPin>>, | 255 | d6: Option<Peri<'d, AnyPin>>, |
| 256 | d7: Option<PeripheralRef<'d, AnyPin>>, | 256 | d7: Option<Peri<'d, AnyPin>>, |
| 257 | sck: Option<PeripheralRef<'d, AnyPin>>, | 257 | sck: Option<Peri<'d, AnyPin>>, |
| 258 | nss: Option<PeripheralRef<'d, AnyPin>>, | 258 | nss: Option<Peri<'d, AnyPin>>, |
| 259 | dqs: Option<PeripheralRef<'d, AnyPin>>, | 259 | dqs: Option<Peri<'d, AnyPin>>, |
| 260 | dma: Option<ChannelAndRequest<'d>>, | 260 | dma: Option<ChannelAndRequest<'d>>, |
| 261 | config: Config, | 261 | config: Config, |
| 262 | width: OspiWidth, | 262 | width: OspiWidth, |
| 263 | dual_quad: bool, | 263 | dual_quad: bool, |
| 264 | ) -> Self { | 264 | ) -> Self { |
| 265 | into_ref!(peri); | ||
| 266 | |||
| 267 | #[cfg(octospim_v1)] | 265 | #[cfg(octospim_v1)] |
| 268 | { | 266 | { |
| 269 | // RCC for octospim should be enabled before writing register | 267 | // RCC for octospim should be enabled before writing register |
| @@ -685,11 +683,11 @@ impl<'d, T: Instance, M: PeriMode> Ospi<'d, T, M> { | |||
| 685 | impl<'d, T: Instance> Ospi<'d, T, Blocking> { | 683 | impl<'d, T: Instance> Ospi<'d, T, Blocking> { |
| 686 | /// Create new blocking OSPI driver for a single spi external chip | 684 | /// Create new blocking OSPI driver for a single spi external chip |
| 687 | pub fn new_blocking_singlespi( | 685 | pub fn new_blocking_singlespi( |
| 688 | peri: impl Peripheral<P = T> + 'd, | 686 | peri: Peri<'d, T>, |
| 689 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 687 | sck: Peri<'d, impl SckPin<T>>, |
| 690 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 688 | d0: Peri<'d, impl D0Pin<T>>, |
| 691 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 689 | d1: Peri<'d, impl D1Pin<T>>, |
| 692 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 690 | nss: Peri<'d, impl NSSPin<T>>, |
| 693 | config: Config, | 691 | config: Config, |
| 694 | ) -> Self { | 692 | ) -> Self { |
| 695 | Self::new_inner( | 693 | Self::new_inner( |
| @@ -717,11 +715,11 @@ impl<'d, T: Instance> Ospi<'d, T, Blocking> { | |||
| 717 | 715 | ||
| 718 | /// Create new blocking OSPI driver for a dualspi external chip | 716 | /// Create new blocking OSPI driver for a dualspi external chip |
| 719 | pub fn new_blocking_dualspi( | 717 | pub fn new_blocking_dualspi( |
| 720 | peri: impl Peripheral<P = T> + 'd, | 718 | peri: Peri<'d, T>, |
| 721 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 719 | sck: Peri<'d, impl SckPin<T>>, |
| 722 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 720 | d0: Peri<'d, impl D0Pin<T>>, |
| 723 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 721 | d1: Peri<'d, impl D1Pin<T>>, |
| 724 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 722 | nss: Peri<'d, impl NSSPin<T>>, |
| 725 | config: Config, | 723 | config: Config, |
| 726 | ) -> Self { | 724 | ) -> Self { |
| 727 | Self::new_inner( | 725 | Self::new_inner( |
| @@ -749,13 +747,13 @@ impl<'d, T: Instance> Ospi<'d, T, Blocking> { | |||
| 749 | 747 | ||
| 750 | /// Create new blocking OSPI driver for a quadspi external chip | 748 | /// Create new blocking OSPI driver for a quadspi external chip |
| 751 | pub fn new_blocking_quadspi( | 749 | pub fn new_blocking_quadspi( |
| 752 | peri: impl Peripheral<P = T> + 'd, | 750 | peri: Peri<'d, T>, |
| 753 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 751 | sck: Peri<'d, impl SckPin<T>>, |
| 754 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 752 | d0: Peri<'d, impl D0Pin<T>>, |
| 755 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 753 | d1: Peri<'d, impl D1Pin<T>>, |
| 756 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 754 | d2: Peri<'d, impl D2Pin<T>>, |
| 757 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 755 | d3: Peri<'d, impl D3Pin<T>>, |
| 758 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 756 | nss: Peri<'d, impl NSSPin<T>>, |
| 759 | config: Config, | 757 | config: Config, |
| 760 | ) -> Self { | 758 | ) -> Self { |
| 761 | Self::new_inner( | 759 | Self::new_inner( |
| @@ -783,17 +781,17 @@ impl<'d, T: Instance> Ospi<'d, T, Blocking> { | |||
| 783 | 781 | ||
| 784 | /// Create new blocking OSPI driver for two quadspi external chips | 782 | /// Create new blocking OSPI driver for two quadspi external chips |
| 785 | pub fn new_blocking_dualquadspi( | 783 | pub fn new_blocking_dualquadspi( |
| 786 | peri: impl Peripheral<P = T> + 'd, | 784 | peri: Peri<'d, T>, |
| 787 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 785 | sck: Peri<'d, impl SckPin<T>>, |
| 788 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 786 | d0: Peri<'d, impl D0Pin<T>>, |
| 789 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 787 | d1: Peri<'d, impl D1Pin<T>>, |
| 790 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 788 | d2: Peri<'d, impl D2Pin<T>>, |
| 791 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 789 | d3: Peri<'d, impl D3Pin<T>>, |
| 792 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 790 | d4: Peri<'d, impl D4Pin<T>>, |
| 793 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 791 | d5: Peri<'d, impl D5Pin<T>>, |
| 794 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 792 | d6: Peri<'d, impl D6Pin<T>>, |
| 795 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 793 | d7: Peri<'d, impl D7Pin<T>>, |
| 796 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 794 | nss: Peri<'d, impl NSSPin<T>>, |
| 797 | config: Config, | 795 | config: Config, |
| 798 | ) -> Self { | 796 | ) -> Self { |
| 799 | Self::new_inner( | 797 | Self::new_inner( |
| @@ -821,17 +819,17 @@ impl<'d, T: Instance> Ospi<'d, T, Blocking> { | |||
| 821 | 819 | ||
| 822 | /// Create new blocking OSPI driver for octospi external chips | 820 | /// Create new blocking OSPI driver for octospi external chips |
| 823 | pub fn new_blocking_octospi( | 821 | pub fn new_blocking_octospi( |
| 824 | peri: impl Peripheral<P = T> + 'd, | 822 | peri: Peri<'d, T>, |
| 825 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 823 | sck: Peri<'d, impl SckPin<T>>, |
| 826 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 824 | d0: Peri<'d, impl D0Pin<T>>, |
| 827 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 825 | d1: Peri<'d, impl D1Pin<T>>, |
| 828 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 826 | d2: Peri<'d, impl D2Pin<T>>, |
| 829 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 827 | d3: Peri<'d, impl D3Pin<T>>, |
| 830 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 828 | d4: Peri<'d, impl D4Pin<T>>, |
| 831 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 829 | d5: Peri<'d, impl D5Pin<T>>, |
| 832 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 830 | d6: Peri<'d, impl D6Pin<T>>, |
| 833 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 831 | d7: Peri<'d, impl D7Pin<T>>, |
| 834 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 832 | nss: Peri<'d, impl NSSPin<T>>, |
| 835 | config: Config, | 833 | config: Config, |
| 836 | ) -> Self { | 834 | ) -> Self { |
| 837 | Self::new_inner( | 835 | Self::new_inner( |
| @@ -861,12 +859,12 @@ impl<'d, T: Instance> Ospi<'d, T, Blocking> { | |||
| 861 | impl<'d, T: Instance> Ospi<'d, T, Async> { | 859 | impl<'d, T: Instance> Ospi<'d, T, Async> { |
| 862 | /// Create new blocking OSPI driver for a single spi external chip | 860 | /// Create new blocking OSPI driver for a single spi external chip |
| 863 | pub fn new_singlespi( | 861 | pub fn new_singlespi( |
| 864 | peri: impl Peripheral<P = T> + 'd, | 862 | peri: Peri<'d, T>, |
| 865 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 863 | sck: Peri<'d, impl SckPin<T>>, |
| 866 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 864 | d0: Peri<'d, impl D0Pin<T>>, |
| 867 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 865 | d1: Peri<'d, impl D1Pin<T>>, |
| 868 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 866 | nss: Peri<'d, impl NSSPin<T>>, |
| 869 | dma: impl Peripheral<P = impl OctoDma<T>> + 'd, | 867 | dma: Peri<'d, impl OctoDma<T>>, |
| 870 | config: Config, | 868 | config: Config, |
| 871 | ) -> Self { | 869 | ) -> Self { |
| 872 | Self::new_inner( | 870 | Self::new_inner( |
| @@ -894,12 +892,12 @@ impl<'d, T: Instance> Ospi<'d, T, Async> { | |||
| 894 | 892 | ||
| 895 | /// Create new blocking OSPI driver for a dualspi external chip | 893 | /// Create new blocking OSPI driver for a dualspi external chip |
| 896 | pub fn new_dualspi( | 894 | pub fn new_dualspi( |
| 897 | peri: impl Peripheral<P = T> + 'd, | 895 | peri: Peri<'d, T>, |
| 898 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 896 | sck: Peri<'d, impl SckPin<T>>, |
| 899 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 897 | d0: Peri<'d, impl D0Pin<T>>, |
| 900 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 898 | d1: Peri<'d, impl D1Pin<T>>, |
| 901 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 899 | nss: Peri<'d, impl NSSPin<T>>, |
| 902 | dma: impl Peripheral<P = impl OctoDma<T>> + 'd, | 900 | dma: Peri<'d, impl OctoDma<T>>, |
| 903 | config: Config, | 901 | config: Config, |
| 904 | ) -> Self { | 902 | ) -> Self { |
| 905 | Self::new_inner( | 903 | Self::new_inner( |
| @@ -927,14 +925,14 @@ impl<'d, T: Instance> Ospi<'d, T, Async> { | |||
| 927 | 925 | ||
| 928 | /// Create new blocking OSPI driver for a quadspi external chip | 926 | /// Create new blocking OSPI driver for a quadspi external chip |
| 929 | pub fn new_quadspi( | 927 | pub fn new_quadspi( |
| 930 | peri: impl Peripheral<P = T> + 'd, | 928 | peri: Peri<'d, T>, |
| 931 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 929 | sck: Peri<'d, impl SckPin<T>>, |
| 932 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 930 | d0: Peri<'d, impl D0Pin<T>>, |
| 933 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 931 | d1: Peri<'d, impl D1Pin<T>>, |
| 934 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 932 | d2: Peri<'d, impl D2Pin<T>>, |
| 935 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 933 | d3: Peri<'d, impl D3Pin<T>>, |
| 936 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 934 | nss: Peri<'d, impl NSSPin<T>>, |
| 937 | dma: impl Peripheral<P = impl OctoDma<T>> + 'd, | 935 | dma: Peri<'d, impl OctoDma<T>>, |
| 938 | config: Config, | 936 | config: Config, |
| 939 | ) -> Self { | 937 | ) -> Self { |
| 940 | Self::new_inner( | 938 | Self::new_inner( |
| @@ -962,18 +960,18 @@ impl<'d, T: Instance> Ospi<'d, T, Async> { | |||
| 962 | 960 | ||
| 963 | /// Create new blocking OSPI driver for two quadspi external chips | 961 | /// Create new blocking OSPI driver for two quadspi external chips |
| 964 | pub fn new_dualquadspi( | 962 | pub fn new_dualquadspi( |
| 965 | peri: impl Peripheral<P = T> + 'd, | 963 | peri: Peri<'d, T>, |
| 966 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 964 | sck: Peri<'d, impl SckPin<T>>, |
| 967 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 965 | d0: Peri<'d, impl D0Pin<T>>, |
| 968 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 966 | d1: Peri<'d, impl D1Pin<T>>, |
| 969 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 967 | d2: Peri<'d, impl D2Pin<T>>, |
| 970 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 968 | d3: Peri<'d, impl D3Pin<T>>, |
| 971 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 969 | d4: Peri<'d, impl D4Pin<T>>, |
| 972 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 970 | d5: Peri<'d, impl D5Pin<T>>, |
| 973 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 971 | d6: Peri<'d, impl D6Pin<T>>, |
| 974 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 972 | d7: Peri<'d, impl D7Pin<T>>, |
| 975 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 973 | nss: Peri<'d, impl NSSPin<T>>, |
| 976 | dma: impl Peripheral<P = impl OctoDma<T>> + 'd, | 974 | dma: Peri<'d, impl OctoDma<T>>, |
| 977 | config: Config, | 975 | config: Config, |
| 978 | ) -> Self { | 976 | ) -> Self { |
| 979 | Self::new_inner( | 977 | Self::new_inner( |
| @@ -1001,18 +999,18 @@ impl<'d, T: Instance> Ospi<'d, T, Async> { | |||
| 1001 | 999 | ||
| 1002 | /// Create new blocking OSPI driver for octospi external chips | 1000 | /// Create new blocking OSPI driver for octospi external chips |
| 1003 | pub fn new_octospi( | 1001 | pub fn new_octospi( |
| 1004 | peri: impl Peripheral<P = T> + 'd, | 1002 | peri: Peri<'d, T>, |
| 1005 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 1003 | sck: Peri<'d, impl SckPin<T>>, |
| 1006 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 1004 | d0: Peri<'d, impl D0Pin<T>>, |
| 1007 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 1005 | d1: Peri<'d, impl D1Pin<T>>, |
| 1008 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 1006 | d2: Peri<'d, impl D2Pin<T>>, |
| 1009 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 1007 | d3: Peri<'d, impl D3Pin<T>>, |
| 1010 | d4: impl Peripheral<P = impl D4Pin<T>> + 'd, | 1008 | d4: Peri<'d, impl D4Pin<T>>, |
| 1011 | d5: impl Peripheral<P = impl D5Pin<T>> + 'd, | 1009 | d5: Peri<'d, impl D5Pin<T>>, |
| 1012 | d6: impl Peripheral<P = impl D6Pin<T>> + 'd, | 1010 | d6: Peri<'d, impl D6Pin<T>>, |
| 1013 | d7: impl Peripheral<P = impl D7Pin<T>> + 'd, | 1011 | d7: Peri<'d, impl D7Pin<T>>, |
| 1014 | nss: impl Peripheral<P = impl NSSPin<T>> + 'd, | 1012 | nss: Peri<'d, impl NSSPin<T>>, |
| 1015 | dma: impl Peripheral<P = impl OctoDma<T>> + 'd, | 1013 | dma: Peri<'d, impl OctoDma<T>>, |
| 1016 | config: Config, | 1014 | config: Config, |
| 1017 | ) -> Self { | 1015 | ) -> Self { |
| 1018 | Self::new_inner( | 1016 | Self::new_inner( |
| @@ -1221,12 +1219,12 @@ pub(crate) trait SealedInstance { | |||
| 1221 | /// OSPI instance trait. | 1219 | /// OSPI instance trait. |
| 1222 | #[cfg(octospim_v1)] | 1220 | #[cfg(octospim_v1)] |
| 1223 | #[allow(private_bounds)] | 1221 | #[allow(private_bounds)] |
| 1224 | pub trait Instance: Peripheral<P = Self> + SealedInstance + RccPeripheral + SealedOctospimInstance {} | 1222 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + SealedOctospimInstance {} |
| 1225 | 1223 | ||
| 1226 | /// OSPI instance trait. | 1224 | /// OSPI instance trait. |
| 1227 | #[cfg(not(octospim_v1))] | 1225 | #[cfg(not(octospim_v1))] |
| 1228 | #[allow(private_bounds)] | 1226 | #[allow(private_bounds)] |
| 1229 | pub trait Instance: Peripheral<P = Self> + SealedInstance + RccPeripheral {} | 1227 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral {} |
| 1230 | 1228 | ||
| 1231 | pin_trait!(SckPin, Instance); | 1229 | pin_trait!(SckPin, Instance); |
| 1232 | pin_trait!(NckPin, Instance); | 1230 | pin_trait!(NckPin, Instance); |
diff --git a/embassy-stm32/src/qspi/mod.rs b/embassy-stm32/src/qspi/mod.rs index 411e533c9..0df057c53 100644 --- a/embassy-stm32/src/qspi/mod.rs +++ b/embassy-stm32/src/qspi/mod.rs | |||
| @@ -6,7 +6,7 @@ pub mod enums; | |||
| 6 | 6 | ||
| 7 | use core::marker::PhantomData; | 7 | use core::marker::PhantomData; |
| 8 | 8 | ||
| 9 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 9 | use embassy_hal_internal::PeripheralType; |
| 10 | use enums::*; | 10 | use enums::*; |
| 11 | 11 | ||
| 12 | use crate::dma::ChannelAndRequest; | 12 | use crate::dma::ChannelAndRequest; |
| @@ -14,7 +14,7 @@ use crate::gpio::{AfType, AnyPin, OutputType, Pull, Speed}; | |||
| 14 | use crate::mode::{Async, Blocking, Mode as PeriMode}; | 14 | use crate::mode::{Async, Blocking, Mode as PeriMode}; |
| 15 | use crate::pac::quadspi::Quadspi as Regs; | 15 | use crate::pac::quadspi::Quadspi as Regs; |
| 16 | use crate::rcc::{self, RccPeripheral}; | 16 | use crate::rcc::{self, RccPeripheral}; |
| 17 | use crate::{peripherals, Peripheral}; | 17 | use crate::{peripherals, Peri}; |
| 18 | 18 | ||
| 19 | /// QSPI transfer configuration. | 19 | /// QSPI transfer configuration. |
| 20 | pub struct TransferConfig { | 20 | pub struct TransferConfig { |
| @@ -75,13 +75,13 @@ impl Default for Config { | |||
| 75 | /// QSPI driver. | 75 | /// QSPI driver. |
| 76 | #[allow(dead_code)] | 76 | #[allow(dead_code)] |
| 77 | pub struct Qspi<'d, T: Instance, M: PeriMode> { | 77 | pub struct Qspi<'d, T: Instance, M: PeriMode> { |
| 78 | _peri: PeripheralRef<'d, T>, | 78 | _peri: Peri<'d, T>, |
| 79 | sck: Option<PeripheralRef<'d, AnyPin>>, | 79 | sck: Option<Peri<'d, AnyPin>>, |
| 80 | d0: Option<PeripheralRef<'d, AnyPin>>, | 80 | d0: Option<Peri<'d, AnyPin>>, |
| 81 | d1: Option<PeripheralRef<'d, AnyPin>>, | 81 | d1: Option<Peri<'d, AnyPin>>, |
| 82 | d2: Option<PeripheralRef<'d, AnyPin>>, | 82 | d2: Option<Peri<'d, AnyPin>>, |
| 83 | d3: Option<PeripheralRef<'d, AnyPin>>, | 83 | d3: Option<Peri<'d, AnyPin>>, |
| 84 | nss: Option<PeripheralRef<'d, AnyPin>>, | 84 | nss: Option<Peri<'d, AnyPin>>, |
| 85 | dma: Option<ChannelAndRequest<'d>>, | 85 | dma: Option<ChannelAndRequest<'d>>, |
| 86 | _phantom: PhantomData<M>, | 86 | _phantom: PhantomData<M>, |
| 87 | config: Config, | 87 | config: Config, |
| @@ -89,19 +89,17 @@ pub struct Qspi<'d, T: Instance, M: PeriMode> { | |||
| 89 | 89 | ||
| 90 | impl<'d, T: Instance, M: PeriMode> Qspi<'d, T, M> { | 90 | impl<'d, T: Instance, M: PeriMode> Qspi<'d, T, M> { |
| 91 | fn new_inner( | 91 | fn new_inner( |
| 92 | peri: impl Peripheral<P = T> + 'd, | 92 | peri: Peri<'d, T>, |
| 93 | d0: Option<PeripheralRef<'d, AnyPin>>, | 93 | d0: Option<Peri<'d, AnyPin>>, |
| 94 | d1: Option<PeripheralRef<'d, AnyPin>>, | 94 | d1: Option<Peri<'d, AnyPin>>, |
| 95 | d2: Option<PeripheralRef<'d, AnyPin>>, | 95 | d2: Option<Peri<'d, AnyPin>>, |
| 96 | d3: Option<PeripheralRef<'d, AnyPin>>, | 96 | d3: Option<Peri<'d, AnyPin>>, |
| 97 | sck: Option<PeripheralRef<'d, AnyPin>>, | 97 | sck: Option<Peri<'d, AnyPin>>, |
| 98 | nss: Option<PeripheralRef<'d, AnyPin>>, | 98 | nss: Option<Peri<'d, AnyPin>>, |
| 99 | dma: Option<ChannelAndRequest<'d>>, | 99 | dma: Option<ChannelAndRequest<'d>>, |
| 100 | config: Config, | 100 | config: Config, |
| 101 | fsel: FlashSelection, | 101 | fsel: FlashSelection, |
| 102 | ) -> Self { | 102 | ) -> Self { |
| 103 | into_ref!(peri); | ||
| 104 | |||
| 105 | rcc::enable_and_reset::<T>(); | 103 | rcc::enable_and_reset::<T>(); |
| 106 | 104 | ||
| 107 | while T::REGS.sr().read().busy() {} | 105 | while T::REGS.sr().read().busy() {} |
| @@ -272,13 +270,13 @@ impl<'d, T: Instance, M: PeriMode> Qspi<'d, T, M> { | |||
| 272 | impl<'d, T: Instance> Qspi<'d, T, Blocking> { | 270 | impl<'d, T: Instance> Qspi<'d, T, Blocking> { |
| 273 | /// Create a new QSPI driver for bank 1, in blocking mode. | 271 | /// Create a new QSPI driver for bank 1, in blocking mode. |
| 274 | pub fn new_blocking_bank1( | 272 | pub fn new_blocking_bank1( |
| 275 | peri: impl Peripheral<P = T> + 'd, | 273 | peri: Peri<'d, T>, |
| 276 | d0: impl Peripheral<P = impl BK1D0Pin<T>> + 'd, | 274 | d0: Peri<'d, impl BK1D0Pin<T>>, |
| 277 | d1: impl Peripheral<P = impl BK1D1Pin<T>> + 'd, | 275 | d1: Peri<'d, impl BK1D1Pin<T>>, |
| 278 | d2: impl Peripheral<P = impl BK1D2Pin<T>> + 'd, | 276 | d2: Peri<'d, impl BK1D2Pin<T>>, |
| 279 | d3: impl Peripheral<P = impl BK1D3Pin<T>> + 'd, | 277 | d3: Peri<'d, impl BK1D3Pin<T>>, |
| 280 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 278 | sck: Peri<'d, impl SckPin<T>>, |
| 281 | nss: impl Peripheral<P = impl BK1NSSPin<T>> + 'd, | 279 | nss: Peri<'d, impl BK1NSSPin<T>>, |
| 282 | config: Config, | 280 | config: Config, |
| 283 | ) -> Self { | 281 | ) -> Self { |
| 284 | Self::new_inner( | 282 | Self::new_inner( |
| @@ -300,13 +298,13 @@ impl<'d, T: Instance> Qspi<'d, T, Blocking> { | |||
| 300 | 298 | ||
| 301 | /// Create a new QSPI driver for bank 2, in blocking mode. | 299 | /// Create a new QSPI driver for bank 2, in blocking mode. |
| 302 | pub fn new_blocking_bank2( | 300 | pub fn new_blocking_bank2( |
| 303 | peri: impl Peripheral<P = T> + 'd, | 301 | peri: Peri<'d, T>, |
| 304 | d0: impl Peripheral<P = impl BK2D0Pin<T>> + 'd, | 302 | d0: Peri<'d, impl BK2D0Pin<T>>, |
| 305 | d1: impl Peripheral<P = impl BK2D1Pin<T>> + 'd, | 303 | d1: Peri<'d, impl BK2D1Pin<T>>, |
| 306 | d2: impl Peripheral<P = impl BK2D2Pin<T>> + 'd, | 304 | d2: Peri<'d, impl BK2D2Pin<T>>, |
| 307 | d3: impl Peripheral<P = impl BK2D3Pin<T>> + 'd, | 305 | d3: Peri<'d, impl BK2D3Pin<T>>, |
| 308 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 306 | sck: Peri<'d, impl SckPin<T>>, |
| 309 | nss: impl Peripheral<P = impl BK2NSSPin<T>> + 'd, | 307 | nss: Peri<'d, impl BK2NSSPin<T>>, |
| 310 | config: Config, | 308 | config: Config, |
| 311 | ) -> Self { | 309 | ) -> Self { |
| 312 | Self::new_inner( | 310 | Self::new_inner( |
| @@ -330,14 +328,14 @@ impl<'d, T: Instance> Qspi<'d, T, Blocking> { | |||
| 330 | impl<'d, T: Instance> Qspi<'d, T, Async> { | 328 | impl<'d, T: Instance> Qspi<'d, T, Async> { |
| 331 | /// Create a new QSPI driver for bank 1. | 329 | /// Create a new QSPI driver for bank 1. |
| 332 | pub fn new_bank1( | 330 | pub fn new_bank1( |
| 333 | peri: impl Peripheral<P = T> + 'd, | 331 | peri: Peri<'d, T>, |
| 334 | d0: impl Peripheral<P = impl BK1D0Pin<T>> + 'd, | 332 | d0: Peri<'d, impl BK1D0Pin<T>>, |
| 335 | d1: impl Peripheral<P = impl BK1D1Pin<T>> + 'd, | 333 | d1: Peri<'d, impl BK1D1Pin<T>>, |
| 336 | d2: impl Peripheral<P = impl BK1D2Pin<T>> + 'd, | 334 | d2: Peri<'d, impl BK1D2Pin<T>>, |
| 337 | d3: impl Peripheral<P = impl BK1D3Pin<T>> + 'd, | 335 | d3: Peri<'d, impl BK1D3Pin<T>>, |
| 338 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 336 | sck: Peri<'d, impl SckPin<T>>, |
| 339 | nss: impl Peripheral<P = impl BK1NSSPin<T>> + 'd, | 337 | nss: Peri<'d, impl BK1NSSPin<T>>, |
| 340 | dma: impl Peripheral<P = impl QuadDma<T>> + 'd, | 338 | dma: Peri<'d, impl QuadDma<T>>, |
| 341 | config: Config, | 339 | config: Config, |
| 342 | ) -> Self { | 340 | ) -> Self { |
| 343 | Self::new_inner( | 341 | Self::new_inner( |
| @@ -359,14 +357,14 @@ impl<'d, T: Instance> Qspi<'d, T, Async> { | |||
| 359 | 357 | ||
| 360 | /// Create a new QSPI driver for bank 2. | 358 | /// Create a new QSPI driver for bank 2. |
| 361 | pub fn new_bank2( | 359 | pub fn new_bank2( |
| 362 | peri: impl Peripheral<P = T> + 'd, | 360 | peri: Peri<'d, T>, |
| 363 | d0: impl Peripheral<P = impl BK2D0Pin<T>> + 'd, | 361 | d0: Peri<'d, impl BK2D0Pin<T>>, |
| 364 | d1: impl Peripheral<P = impl BK2D1Pin<T>> + 'd, | 362 | d1: Peri<'d, impl BK2D1Pin<T>>, |
| 365 | d2: impl Peripheral<P = impl BK2D2Pin<T>> + 'd, | 363 | d2: Peri<'d, impl BK2D2Pin<T>>, |
| 366 | d3: impl Peripheral<P = impl BK2D3Pin<T>> + 'd, | 364 | d3: Peri<'d, impl BK2D3Pin<T>>, |
| 367 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 365 | sck: Peri<'d, impl SckPin<T>>, |
| 368 | nss: impl Peripheral<P = impl BK2NSSPin<T>> + 'd, | 366 | nss: Peri<'d, impl BK2NSSPin<T>>, |
| 369 | dma: impl Peripheral<P = impl QuadDma<T>> + 'd, | 367 | dma: Peri<'d, impl QuadDma<T>>, |
| 370 | config: Config, | 368 | config: Config, |
| 371 | ) -> Self { | 369 | ) -> Self { |
| 372 | Self::new_inner( | 370 | Self::new_inner( |
| @@ -465,7 +463,7 @@ trait SealedInstance { | |||
| 465 | 463 | ||
| 466 | /// QSPI instance trait. | 464 | /// QSPI instance trait. |
| 467 | #[allow(private_bounds)] | 465 | #[allow(private_bounds)] |
| 468 | pub trait Instance: Peripheral<P = Self> + SealedInstance + RccPeripheral {} | 466 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral {} |
| 469 | 467 | ||
| 470 | pin_trait!(SckPin, Instance); | 468 | pin_trait!(SckPin, Instance); |
| 471 | pin_trait!(BK1D0Pin, Instance); | 469 | pin_trait!(BK1D0Pin, Instance); |
diff --git a/embassy-stm32/src/rcc/mco.rs b/embassy-stm32/src/rcc/mco.rs index d1ce14c86..c50e071fb 100644 --- a/embassy-stm32/src/rcc/mco.rs +++ b/embassy-stm32/src/rcc/mco.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy_hal_internal::into_ref; | 3 | use embassy_hal_internal::PeripheralType; |
| 4 | 4 | ||
| 5 | use crate::gpio::{AfType, OutputType, Speed}; | 5 | use crate::gpio::{AfType, OutputType, Speed}; |
| 6 | #[cfg(not(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37)))] | 6 | #[cfg(not(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37)))] |
| @@ -32,7 +32,7 @@ pub use crate::pac::rcc::vals::Mcosel as McoSource; | |||
| 32 | ))] | 32 | ))] |
| 33 | pub use crate::pac::rcc::vals::{Mco1sel as Mco1Source, Mco2sel as Mco2Source}; | 33 | pub use crate::pac::rcc::vals::{Mco1sel as Mco1Source, Mco2sel as Mco2Source}; |
| 34 | use crate::pac::RCC; | 34 | use crate::pac::RCC; |
| 35 | use crate::{peripherals, Peripheral}; | 35 | use crate::{peripherals, Peri}; |
| 36 | 36 | ||
| 37 | #[cfg(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37))] | 37 | #[cfg(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37))] |
| 38 | #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] | 38 | #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
| @@ -43,7 +43,7 @@ pub enum McoPrescaler { | |||
| 43 | pub(crate) trait SealedMcoInstance {} | 43 | pub(crate) trait SealedMcoInstance {} |
| 44 | 44 | ||
| 45 | #[allow(private_bounds)] | 45 | #[allow(private_bounds)] |
| 46 | pub trait McoInstance: SealedMcoInstance + 'static { | 46 | pub trait McoInstance: PeripheralType + SealedMcoInstance + 'static { |
| 47 | type Source; | 47 | type Source; |
| 48 | 48 | ||
| 49 | #[doc(hidden)] | 49 | #[doc(hidden)] |
| @@ -91,14 +91,7 @@ pub struct Mco<'d, T: McoInstance> { | |||
| 91 | 91 | ||
| 92 | impl<'d, T: McoInstance> Mco<'d, T> { | 92 | impl<'d, T: McoInstance> Mco<'d, T> { |
| 93 | /// Create a new MCO instance. | 93 | /// Create a new MCO instance. |
| 94 | pub fn new( | 94 | pub fn new(_peri: Peri<'d, T>, pin: Peri<'d, impl McoPin<T>>, source: T::Source, prescaler: McoPrescaler) -> Self { |
| 95 | _peri: impl Peripheral<P = T> + 'd, | ||
| 96 | pin: impl Peripheral<P = impl McoPin<T>> + 'd, | ||
| 97 | source: T::Source, | ||
| 98 | prescaler: McoPrescaler, | ||
| 99 | ) -> Self { | ||
| 100 | into_ref!(pin); | ||
| 101 | |||
| 102 | critical_section::with(|_| unsafe { | 95 | critical_section::with(|_| unsafe { |
| 103 | T::_apply_clock_settings(source, prescaler); | 96 | T::_apply_clock_settings(source, prescaler); |
| 104 | pin.set_as_af(pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 97 | pin.set_as_af(pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index b96200e5e..250a08a39 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs | |||
| @@ -5,12 +5,12 @@ use core::future::poll_fn; | |||
| 5 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 6 | use core::task::Poll; | 6 | use core::task::Poll; |
| 7 | 7 | ||
| 8 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 8 | use embassy_hal_internal::PeripheralType; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | use rand_core::{CryptoRng, RngCore}; | 10 | use rand_core::{CryptoRng, RngCore}; |
| 11 | 11 | ||
| 12 | use crate::interrupt::typelevel::Interrupt; | 12 | use crate::interrupt::typelevel::Interrupt; |
| 13 | use crate::{interrupt, pac, peripherals, rcc, Peripheral}; | 13 | use crate::{interrupt, pac, peripherals, rcc, Peri}; |
| 14 | 14 | ||
| 15 | static RNG_WAKER: AtomicWaker = AtomicWaker::new(); | 15 | static RNG_WAKER: AtomicWaker = AtomicWaker::new(); |
| 16 | 16 | ||
| @@ -43,17 +43,16 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 43 | 43 | ||
| 44 | /// RNG driver. | 44 | /// RNG driver. |
| 45 | pub struct Rng<'d, T: Instance> { | 45 | pub struct Rng<'d, T: Instance> { |
| 46 | _inner: PeripheralRef<'d, T>, | 46 | _inner: Peri<'d, T>, |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | impl<'d, T: Instance> Rng<'d, T> { | 49 | impl<'d, T: Instance> Rng<'d, T> { |
| 50 | /// Create a new RNG driver. | 50 | /// Create a new RNG driver. |
| 51 | pub fn new( | 51 | pub fn new( |
| 52 | inner: impl Peripheral<P = T> + 'd, | 52 | inner: Peri<'d, T>, |
| 53 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 53 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 54 | ) -> Self { | 54 | ) -> Self { |
| 55 | rcc::enable_and_reset::<T>(); | 55 | rcc::enable_and_reset::<T>(); |
| 56 | into_ref!(inner); | ||
| 57 | let mut random = Self { _inner: inner }; | 56 | let mut random = Self { _inner: inner }; |
| 58 | random.reset(); | 57 | random.reset(); |
| 59 | 58 | ||
| @@ -228,7 +227,7 @@ trait SealedInstance { | |||
| 228 | 227 | ||
| 229 | /// RNG instance trait. | 228 | /// RNG instance trait. |
| 230 | #[allow(private_bounds)] | 229 | #[allow(private_bounds)] |
| 231 | pub trait Instance: SealedInstance + Peripheral<P = Self> + crate::rcc::RccPeripheral + 'static + Send { | 230 | pub trait Instance: SealedInstance + PeripheralType + crate::rcc::RccPeripheral + 'static + Send { |
| 232 | /// Interrupt for this RNG instance. | 231 | /// Interrupt for this RNG instance. |
| 233 | type Interrupt: interrupt::typelevel::Interrupt; | 232 | type Interrupt: interrupt::typelevel::Interrupt; |
| 234 | } | 233 | } |
diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index c2919e2bd..b16c6fdca 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs | |||
| @@ -29,9 +29,9 @@ use crate::time::Hertz; | |||
| 29 | mod _version; | 29 | mod _version; |
| 30 | #[allow(unused_imports)] | 30 | #[allow(unused_imports)] |
| 31 | pub use _version::*; | 31 | pub use _version::*; |
| 32 | use embassy_hal_internal::Peripheral; | ||
| 33 | 32 | ||
| 34 | use crate::peripherals::RTC; | 33 | use crate::peripherals::RTC; |
| 34 | use crate::Peri; | ||
| 35 | 35 | ||
| 36 | /// Errors that can occur on methods on [RtcClock] | 36 | /// Errors that can occur on methods on [RtcClock] |
| 37 | #[non_exhaustive] | 37 | #[non_exhaustive] |
| @@ -151,7 +151,7 @@ pub enum RtcCalibrationCyclePeriod { | |||
| 151 | 151 | ||
| 152 | impl Rtc { | 152 | impl Rtc { |
| 153 | /// Create a new RTC instance. | 153 | /// Create a new RTC instance. |
| 154 | pub fn new(_rtc: impl Peripheral<P = RTC>, rtc_config: RtcConfig) -> Self { | 154 | pub fn new(_rtc: Peri<'static, RTC>, rtc_config: RtcConfig) -> Self { |
| 155 | #[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))] | 155 | #[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))] |
| 156 | crate::rcc::enable_and_reset::<RTC>(); | 156 | crate::rcc::enable_and_reset::<RTC>(); |
| 157 | 157 | ||
diff --git a/embassy-stm32/src/sai/mod.rs b/embassy-stm32/src/sai/mod.rs index 39ed44712..0c9c27797 100644 --- a/embassy-stm32/src/sai/mod.rs +++ b/embassy-stm32/src/sai/mod.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 6 | 6 | ||
| 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 7 | use embassy_hal_internal::PeripheralType; |
| 8 | 8 | ||
| 9 | pub use crate::dma::word; | 9 | pub use crate::dma::word; |
| 10 | #[cfg(not(gpdma))] | 10 | #[cfg(not(gpdma))] |
| @@ -12,7 +12,7 @@ use crate::dma::{ringbuffer, Channel, ReadableRingBuffer, Request, TransferOptio | |||
| 12 | use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; | 12 | use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; |
| 13 | use crate::pac::sai::{vals, Sai as Regs}; | 13 | use crate::pac::sai::{vals, Sai as Regs}; |
| 14 | use crate::rcc::{self, RccPeripheral}; | 14 | use crate::rcc::{self, RccPeripheral}; |
| 15 | use crate::{peripherals, Peripheral}; | 15 | use crate::{peripherals, Peri}; |
| 16 | 16 | ||
| 17 | /// SAI error | 17 | /// SAI error |
| 18 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 18 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
| @@ -679,7 +679,7 @@ fn get_af_types(mode: Mode, tx_rx: TxRx) -> (AfType, AfType) { | |||
| 679 | 679 | ||
| 680 | #[cfg(not(gpdma))] | 680 | #[cfg(not(gpdma))] |
| 681 | fn get_ring_buffer<'d, T: Instance, W: word::Word>( | 681 | fn get_ring_buffer<'d, T: Instance, W: word::Word>( |
| 682 | dma: impl Peripheral<P = impl Channel> + 'd, | 682 | dma: Peri<'d, impl Channel>, |
| 683 | dma_buf: &'d mut [W], | 683 | dma_buf: &'d mut [W], |
| 684 | request: Request, | 684 | request: Request, |
| 685 | sub_block: WhichSubBlock, | 685 | sub_block: WhichSubBlock, |
| @@ -718,16 +718,15 @@ fn update_synchronous_config(config: &mut Config) { | |||
| 718 | } | 718 | } |
| 719 | 719 | ||
| 720 | /// SAI subblock instance. | 720 | /// SAI subblock instance. |
| 721 | pub struct SubBlock<'d, T, S: SubBlockInstance> { | 721 | pub struct SubBlock<'d, T: Instance, S: SubBlockInstance> { |
| 722 | peri: PeripheralRef<'d, T>, | 722 | peri: Peri<'d, T>, |
| 723 | _phantom: PhantomData<S>, | 723 | _phantom: PhantomData<S>, |
| 724 | } | 724 | } |
| 725 | 725 | ||
| 726 | /// Split the main SAIx peripheral into the two subblocks. | 726 | /// Split the main SAIx peripheral into the two subblocks. |
| 727 | /// | 727 | /// |
| 728 | /// You can then create a [`Sai`] driver for each each half. | 728 | /// You can then create a [`Sai`] driver for each each half. |
| 729 | pub fn split_subblocks<'d, T: Instance>(peri: impl Peripheral<P = T> + 'd) -> (SubBlock<'d, T, A>, SubBlock<'d, T, B>) { | 729 | pub fn split_subblocks<'d, T: Instance>(peri: Peri<'d, T>) -> (SubBlock<'d, T, A>, SubBlock<'d, T, B>) { |
| 730 | into_ref!(peri); | ||
| 731 | rcc::enable_and_reset::<T>(); | 730 | rcc::enable_and_reset::<T>(); |
| 732 | 731 | ||
| 733 | ( | 732 | ( |
| @@ -744,11 +743,11 @@ pub fn split_subblocks<'d, T: Instance>(peri: impl Peripheral<P = T> + 'd) -> (S | |||
| 744 | 743 | ||
| 745 | /// SAI sub-block driver. | 744 | /// SAI sub-block driver. |
| 746 | pub struct Sai<'d, T: Instance, W: word::Word> { | 745 | pub struct Sai<'d, T: Instance, W: word::Word> { |
| 747 | _peri: PeripheralRef<'d, T>, | 746 | _peri: Peri<'d, T>, |
| 748 | sd: Option<PeripheralRef<'d, AnyPin>>, | 747 | sd: Option<Peri<'d, AnyPin>>, |
| 749 | fs: Option<PeripheralRef<'d, AnyPin>>, | 748 | fs: Option<Peri<'d, AnyPin>>, |
| 750 | sck: Option<PeripheralRef<'d, AnyPin>>, | 749 | sck: Option<Peri<'d, AnyPin>>, |
| 751 | mclk: Option<PeripheralRef<'d, AnyPin>>, | 750 | mclk: Option<Peri<'d, AnyPin>>, |
| 752 | #[cfg(gpdma)] | 751 | #[cfg(gpdma)] |
| 753 | ring_buffer: PhantomData<W>, | 752 | ring_buffer: PhantomData<W>, |
| 754 | #[cfg(not(gpdma))] | 753 | #[cfg(not(gpdma))] |
| @@ -763,16 +762,14 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 763 | /// You can obtain the [`SubBlock`] with [`split_subblocks`]. | 762 | /// You can obtain the [`SubBlock`] with [`split_subblocks`]. |
| 764 | pub fn new_asynchronous_with_mclk<S: SubBlockInstance>( | 763 | pub fn new_asynchronous_with_mclk<S: SubBlockInstance>( |
| 765 | peri: SubBlock<'d, T, S>, | 764 | peri: SubBlock<'d, T, S>, |
| 766 | sck: impl Peripheral<P = impl SckPin<T, S>> + 'd, | 765 | sck: Peri<'d, impl SckPin<T, S>>, |
| 767 | sd: impl Peripheral<P = impl SdPin<T, S>> + 'd, | 766 | sd: Peri<'d, impl SdPin<T, S>>, |
| 768 | fs: impl Peripheral<P = impl FsPin<T, S>> + 'd, | 767 | fs: Peri<'d, impl FsPin<T, S>>, |
| 769 | mclk: impl Peripheral<P = impl MclkPin<T, S>> + 'd, | 768 | mclk: Peri<'d, impl MclkPin<T, S>>, |
| 770 | dma: impl Peripheral<P = impl Channel + Dma<T, S>> + 'd, | 769 | dma: Peri<'d, impl Channel + Dma<T, S>>, |
| 771 | dma_buf: &'d mut [W], | 770 | dma_buf: &'d mut [W], |
| 772 | mut config: Config, | 771 | mut config: Config, |
| 773 | ) -> Self { | 772 | ) -> Self { |
| 774 | into_ref!(mclk); | ||
| 775 | |||
| 776 | let (_sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); | 773 | let (_sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); |
| 777 | mclk.set_as_af(mclk.af_num(), ck_af_type); | 774 | mclk.set_as_af(mclk.af_num(), ck_af_type); |
| 778 | 775 | ||
| @@ -788,15 +785,14 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 788 | /// You can obtain the [`SubBlock`] with [`split_subblocks`]. | 785 | /// You can obtain the [`SubBlock`] with [`split_subblocks`]. |
| 789 | pub fn new_asynchronous<S: SubBlockInstance>( | 786 | pub fn new_asynchronous<S: SubBlockInstance>( |
| 790 | peri: SubBlock<'d, T, S>, | 787 | peri: SubBlock<'d, T, S>, |
| 791 | sck: impl Peripheral<P = impl SckPin<T, S>> + 'd, | 788 | sck: Peri<'d, impl SckPin<T, S>>, |
| 792 | sd: impl Peripheral<P = impl SdPin<T, S>> + 'd, | 789 | sd: Peri<'d, impl SdPin<T, S>>, |
| 793 | fs: impl Peripheral<P = impl FsPin<T, S>> + 'd, | 790 | fs: Peri<'d, impl FsPin<T, S>>, |
| 794 | dma: impl Peripheral<P = impl Channel + Dma<T, S>> + 'd, | 791 | dma: Peri<'d, impl Channel + Dma<T, S>>, |
| 795 | dma_buf: &'d mut [W], | 792 | dma_buf: &'d mut [W], |
| 796 | config: Config, | 793 | config: Config, |
| 797 | ) -> Self { | 794 | ) -> Self { |
| 798 | let peri = peri.peri; | 795 | let peri = peri.peri; |
| 799 | into_ref!(peri, dma, sck, sd, fs); | ||
| 800 | 796 | ||
| 801 | let (sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); | 797 | let (sd_af_type, ck_af_type) = get_af_types(config.mode, config.tx_rx); |
| 802 | sd.set_as_af(sd.af_num(), sd_af_type); | 798 | sd.set_as_af(sd.af_num(), sd_af_type); |
| @@ -809,10 +805,10 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 809 | Self::new_inner( | 805 | Self::new_inner( |
| 810 | peri, | 806 | peri, |
| 811 | sub_block, | 807 | sub_block, |
| 812 | Some(sck.map_into()), | 808 | Some(sck.into()), |
| 813 | None, | 809 | None, |
| 814 | Some(sd.map_into()), | 810 | Some(sd.into()), |
| 815 | Some(fs.map_into()), | 811 | Some(fs.into()), |
| 816 | get_ring_buffer::<T, W>(dma, dma_buf, request, sub_block, config.tx_rx), | 812 | get_ring_buffer::<T, W>(dma, dma_buf, request, sub_block, config.tx_rx), |
| 817 | config, | 813 | config, |
| 818 | ) | 814 | ) |
| @@ -823,15 +819,14 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 823 | /// You can obtain the [`SubBlock`] with [`split_subblocks`]. | 819 | /// You can obtain the [`SubBlock`] with [`split_subblocks`]. |
| 824 | pub fn new_synchronous<S: SubBlockInstance>( | 820 | pub fn new_synchronous<S: SubBlockInstance>( |
| 825 | peri: SubBlock<'d, T, S>, | 821 | peri: SubBlock<'d, T, S>, |
| 826 | sd: impl Peripheral<P = impl SdPin<T, S>> + 'd, | 822 | sd: Peri<'d, impl SdPin<T, S>>, |
| 827 | dma: impl Peripheral<P = impl Channel + Dma<T, S>> + 'd, | 823 | dma: Peri<'d, impl Channel + Dma<T, S>>, |
| 828 | dma_buf: &'d mut [W], | 824 | dma_buf: &'d mut [W], |
| 829 | mut config: Config, | 825 | mut config: Config, |
| 830 | ) -> Self { | 826 | ) -> Self { |
| 831 | update_synchronous_config(&mut config); | 827 | update_synchronous_config(&mut config); |
| 832 | 828 | ||
| 833 | let peri = peri.peri; | 829 | let peri = peri.peri; |
| 834 | into_ref!(dma, peri, sd); | ||
| 835 | 830 | ||
| 836 | let (sd_af_type, _ck_af_type) = get_af_types(config.mode, config.tx_rx); | 831 | let (sd_af_type, _ck_af_type) = get_af_types(config.mode, config.tx_rx); |
| 837 | sd.set_as_af(sd.af_num(), sd_af_type); | 832 | sd.set_as_af(sd.af_num(), sd_af_type); |
| @@ -844,7 +839,7 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 844 | sub_block, | 839 | sub_block, |
| 845 | None, | 840 | None, |
| 846 | None, | 841 | None, |
| 847 | Some(sd.map_into()), | 842 | Some(sd.into()), |
| 848 | None, | 843 | None, |
| 849 | get_ring_buffer::<T, W>(dma, dma_buf, request, sub_block, config.tx_rx), | 844 | get_ring_buffer::<T, W>(dma, dma_buf, request, sub_block, config.tx_rx), |
| 850 | config, | 845 | config, |
| @@ -852,12 +847,12 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 852 | } | 847 | } |
| 853 | 848 | ||
| 854 | fn new_inner( | 849 | fn new_inner( |
| 855 | peri: impl Peripheral<P = T> + 'd, | 850 | peri: Peri<'d, T>, |
| 856 | sub_block: WhichSubBlock, | 851 | sub_block: WhichSubBlock, |
| 857 | sck: Option<PeripheralRef<'d, AnyPin>>, | 852 | sck: Option<Peri<'d, AnyPin>>, |
| 858 | mclk: Option<PeripheralRef<'d, AnyPin>>, | 853 | mclk: Option<Peri<'d, AnyPin>>, |
| 859 | sd: Option<PeripheralRef<'d, AnyPin>>, | 854 | sd: Option<Peri<'d, AnyPin>>, |
| 860 | fs: Option<PeripheralRef<'d, AnyPin>>, | 855 | fs: Option<Peri<'d, AnyPin>>, |
| 861 | ring_buffer: RingBuffer<'d, W>, | 856 | ring_buffer: RingBuffer<'d, W>, |
| 862 | config: Config, | 857 | config: Config, |
| 863 | ) -> Self { | 858 | ) -> Self { |
| @@ -947,7 +942,7 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> { | |||
| 947 | } | 942 | } |
| 948 | 943 | ||
| 949 | Self { | 944 | Self { |
| 950 | _peri: peri.into_ref(), | 945 | _peri: peri, |
| 951 | sub_block, | 946 | sub_block, |
| 952 | sck, | 947 | sck, |
| 953 | mclk, | 948 | mclk, |
| @@ -1106,7 +1101,7 @@ impl SubBlockInstance for B {} | |||
| 1106 | 1101 | ||
| 1107 | /// SAI instance trait. | 1102 | /// SAI instance trait. |
| 1108 | #[allow(private_bounds)] | 1103 | #[allow(private_bounds)] |
| 1109 | pub trait Instance: Peripheral<P = Self> + SealedInstance + RccPeripheral {} | 1104 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral {} |
| 1110 | 1105 | ||
| 1111 | pin_trait!(SckPin, Instance, SubBlockInstance); | 1106 | pin_trait!(SckPin, Instance, SubBlockInstance); |
| 1112 | pin_trait!(FsPin, Instance, SubBlockInstance); | 1107 | pin_trait!(FsPin, Instance, SubBlockInstance); |
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index d8671caf7..8f3c45f50 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs | |||
| @@ -8,7 +8,7 @@ use core::ops::{Deref, DerefMut}; | |||
| 8 | use core::task::Poll; | 8 | use core::task::Poll; |
| 9 | 9 | ||
| 10 | use embassy_hal_internal::drop::OnDrop; | 10 | use embassy_hal_internal::drop::OnDrop; |
| 11 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 11 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 12 | use embassy_sync::waitqueue::AtomicWaker; | 12 | use embassy_sync::waitqueue::AtomicWaker; |
| 13 | use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID, CSD, OCR, SCR}; | 13 | use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID, CSD, OCR, SCR}; |
| 14 | 14 | ||
| @@ -21,7 +21,7 @@ use crate::interrupt::typelevel::Interrupt; | |||
| 21 | use crate::pac::sdmmc::Sdmmc as RegBlock; | 21 | use crate::pac::sdmmc::Sdmmc as RegBlock; |
| 22 | use crate::rcc::{self, RccPeripheral}; | 22 | use crate::rcc::{self, RccPeripheral}; |
| 23 | use crate::time::Hertz; | 23 | use crate::time::Hertz; |
| 24 | use crate::{interrupt, peripherals, Peripheral}; | 24 | use crate::{interrupt, peripherals}; |
| 25 | 25 | ||
| 26 | /// Interrupt handler. | 26 | /// Interrupt handler. |
| 27 | pub struct InterruptHandler<T: Instance> { | 27 | pub struct InterruptHandler<T: Instance> { |
| @@ -303,16 +303,16 @@ impl Default for Config { | |||
| 303 | 303 | ||
| 304 | /// Sdmmc device | 304 | /// Sdmmc device |
| 305 | pub struct Sdmmc<'d, T: Instance> { | 305 | pub struct Sdmmc<'d, T: Instance> { |
| 306 | _peri: PeripheralRef<'d, T>, | 306 | _peri: Peri<'d, T>, |
| 307 | #[cfg(sdmmc_v1)] | 307 | #[cfg(sdmmc_v1)] |
| 308 | dma: ChannelAndRequest<'d>, | 308 | dma: ChannelAndRequest<'d>, |
| 309 | 309 | ||
| 310 | clk: PeripheralRef<'d, AnyPin>, | 310 | clk: Peri<'d, AnyPin>, |
| 311 | cmd: PeripheralRef<'d, AnyPin>, | 311 | cmd: Peri<'d, AnyPin>, |
| 312 | d0: PeripheralRef<'d, AnyPin>, | 312 | d0: Peri<'d, AnyPin>, |
| 313 | d1: Option<PeripheralRef<'d, AnyPin>>, | 313 | d1: Option<Peri<'d, AnyPin>>, |
| 314 | d2: Option<PeripheralRef<'d, AnyPin>>, | 314 | d2: Option<Peri<'d, AnyPin>>, |
| 315 | d3: Option<PeripheralRef<'d, AnyPin>>, | 315 | d3: Option<Peri<'d, AnyPin>>, |
| 316 | 316 | ||
| 317 | config: Config, | 317 | config: Config, |
| 318 | /// Current clock to card | 318 | /// Current clock to card |
| @@ -338,16 +338,14 @@ const DATA_AF: AfType = CMD_AF; | |||
| 338 | impl<'d, T: Instance> Sdmmc<'d, T> { | 338 | impl<'d, T: Instance> Sdmmc<'d, T> { |
| 339 | /// Create a new SDMMC driver, with 1 data lane. | 339 | /// Create a new SDMMC driver, with 1 data lane. |
| 340 | pub fn new_1bit( | 340 | pub fn new_1bit( |
| 341 | sdmmc: impl Peripheral<P = T> + 'd, | 341 | sdmmc: Peri<'d, T>, |
| 342 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 342 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 343 | dma: impl Peripheral<P = impl SdmmcDma<T>> + 'd, | 343 | dma: Peri<'d, impl SdmmcDma<T>>, |
| 344 | clk: impl Peripheral<P = impl CkPin<T>> + 'd, | 344 | clk: Peri<'d, impl CkPin<T>>, |
| 345 | cmd: impl Peripheral<P = impl CmdPin<T>> + 'd, | 345 | cmd: Peri<'d, impl CmdPin<T>>, |
| 346 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 346 | d0: Peri<'d, impl D0Pin<T>>, |
| 347 | config: Config, | 347 | config: Config, |
| 348 | ) -> Self { | 348 | ) -> Self { |
| 349 | into_ref!(dma, clk, cmd, d0); | ||
| 350 | |||
| 351 | critical_section::with(|_| { | 349 | critical_section::with(|_| { |
| 352 | clk.set_as_af(clk.af_num(), CLK_AF); | 350 | clk.set_as_af(clk.af_num(), CLK_AF); |
| 353 | cmd.set_as_af(cmd.af_num(), CMD_AF); | 351 | cmd.set_as_af(cmd.af_num(), CMD_AF); |
| @@ -357,9 +355,9 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 357 | Self::new_inner( | 355 | Self::new_inner( |
| 358 | sdmmc, | 356 | sdmmc, |
| 359 | new_dma_nonopt!(dma), | 357 | new_dma_nonopt!(dma), |
| 360 | clk.map_into(), | 358 | clk.into(), |
| 361 | cmd.map_into(), | 359 | cmd.into(), |
| 362 | d0.map_into(), | 360 | d0.into(), |
| 363 | None, | 361 | None, |
| 364 | None, | 362 | None, |
| 365 | None, | 363 | None, |
| @@ -369,19 +367,17 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 369 | 367 | ||
| 370 | /// Create a new SDMMC driver, with 4 data lanes. | 368 | /// Create a new SDMMC driver, with 4 data lanes. |
| 371 | pub fn new_4bit( | 369 | pub fn new_4bit( |
| 372 | sdmmc: impl Peripheral<P = T> + 'd, | 370 | sdmmc: Peri<'d, T>, |
| 373 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 371 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 374 | dma: impl Peripheral<P = impl SdmmcDma<T>> + 'd, | 372 | dma: Peri<'d, impl SdmmcDma<T>>, |
| 375 | clk: impl Peripheral<P = impl CkPin<T>> + 'd, | 373 | clk: Peri<'d, impl CkPin<T>>, |
| 376 | cmd: impl Peripheral<P = impl CmdPin<T>> + 'd, | 374 | cmd: Peri<'d, impl CmdPin<T>>, |
| 377 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 375 | d0: Peri<'d, impl D0Pin<T>>, |
| 378 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 376 | d1: Peri<'d, impl D1Pin<T>>, |
| 379 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 377 | d2: Peri<'d, impl D2Pin<T>>, |
| 380 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 378 | d3: Peri<'d, impl D3Pin<T>>, |
| 381 | config: Config, | 379 | config: Config, |
| 382 | ) -> Self { | 380 | ) -> Self { |
| 383 | into_ref!(clk, cmd, d0, d1, d2, d3); | ||
| 384 | |||
| 385 | critical_section::with(|_| { | 381 | critical_section::with(|_| { |
| 386 | clk.set_as_af(clk.af_num(), CLK_AF); | 382 | clk.set_as_af(clk.af_num(), CLK_AF); |
| 387 | cmd.set_as_af(cmd.af_num(), CMD_AF); | 383 | cmd.set_as_af(cmd.af_num(), CMD_AF); |
| @@ -394,12 +390,12 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 394 | Self::new_inner( | 390 | Self::new_inner( |
| 395 | sdmmc, | 391 | sdmmc, |
| 396 | new_dma_nonopt!(dma), | 392 | new_dma_nonopt!(dma), |
| 397 | clk.map_into(), | 393 | clk.into(), |
| 398 | cmd.map_into(), | 394 | cmd.into(), |
| 399 | d0.map_into(), | 395 | d0.into(), |
| 400 | Some(d1.map_into()), | 396 | Some(d1.into()), |
| 401 | Some(d2.map_into()), | 397 | Some(d2.into()), |
| 402 | Some(d3.map_into()), | 398 | Some(d3.into()), |
| 403 | config, | 399 | config, |
| 404 | ) | 400 | ) |
| 405 | } | 401 | } |
| @@ -409,47 +405,34 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 409 | impl<'d, T: Instance> Sdmmc<'d, T> { | 405 | impl<'d, T: Instance> Sdmmc<'d, T> { |
| 410 | /// Create a new SDMMC driver, with 1 data lane. | 406 | /// Create a new SDMMC driver, with 1 data lane. |
| 411 | pub fn new_1bit( | 407 | pub fn new_1bit( |
| 412 | sdmmc: impl Peripheral<P = T> + 'd, | 408 | sdmmc: Peri<'d, T>, |
| 413 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 409 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 414 | clk: impl Peripheral<P = impl CkPin<T>> + 'd, | 410 | clk: Peri<'d, impl CkPin<T>>, |
| 415 | cmd: impl Peripheral<P = impl CmdPin<T>> + 'd, | 411 | cmd: Peri<'d, impl CmdPin<T>>, |
| 416 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 412 | d0: Peri<'d, impl D0Pin<T>>, |
| 417 | config: Config, | 413 | config: Config, |
| 418 | ) -> Self { | 414 | ) -> Self { |
| 419 | into_ref!(clk, cmd, d0); | ||
| 420 | |||
| 421 | critical_section::with(|_| { | 415 | critical_section::with(|_| { |
| 422 | clk.set_as_af(clk.af_num(), CLK_AF); | 416 | clk.set_as_af(clk.af_num(), CLK_AF); |
| 423 | cmd.set_as_af(cmd.af_num(), CMD_AF); | 417 | cmd.set_as_af(cmd.af_num(), CMD_AF); |
| 424 | d0.set_as_af(d0.af_num(), DATA_AF); | 418 | d0.set_as_af(d0.af_num(), DATA_AF); |
| 425 | }); | 419 | }); |
| 426 | 420 | ||
| 427 | Self::new_inner( | 421 | Self::new_inner(sdmmc, clk.into(), cmd.into(), d0.into(), None, None, None, config) |
| 428 | sdmmc, | ||
| 429 | clk.map_into(), | ||
| 430 | cmd.map_into(), | ||
| 431 | d0.map_into(), | ||
| 432 | None, | ||
| 433 | None, | ||
| 434 | None, | ||
| 435 | config, | ||
| 436 | ) | ||
| 437 | } | 422 | } |
| 438 | 423 | ||
| 439 | /// Create a new SDMMC driver, with 4 data lanes. | 424 | /// Create a new SDMMC driver, with 4 data lanes. |
| 440 | pub fn new_4bit( | 425 | pub fn new_4bit( |
| 441 | sdmmc: impl Peripheral<P = T> + 'd, | 426 | sdmmc: Peri<'d, T>, |
| 442 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 427 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 443 | clk: impl Peripheral<P = impl CkPin<T>> + 'd, | 428 | clk: Peri<'d, impl CkPin<T>>, |
| 444 | cmd: impl Peripheral<P = impl CmdPin<T>> + 'd, | 429 | cmd: Peri<'d, impl CmdPin<T>>, |
| 445 | d0: impl Peripheral<P = impl D0Pin<T>> + 'd, | 430 | d0: Peri<'d, impl D0Pin<T>>, |
| 446 | d1: impl Peripheral<P = impl D1Pin<T>> + 'd, | 431 | d1: Peri<'d, impl D1Pin<T>>, |
| 447 | d2: impl Peripheral<P = impl D2Pin<T>> + 'd, | 432 | d2: Peri<'d, impl D2Pin<T>>, |
| 448 | d3: impl Peripheral<P = impl D3Pin<T>> + 'd, | 433 | d3: Peri<'d, impl D3Pin<T>>, |
| 449 | config: Config, | 434 | config: Config, |
| 450 | ) -> Self { | 435 | ) -> Self { |
| 451 | into_ref!(clk, cmd, d0, d1, d2, d3); | ||
| 452 | |||
| 453 | critical_section::with(|_| { | 436 | critical_section::with(|_| { |
| 454 | clk.set_as_af(clk.af_num(), CLK_AF); | 437 | clk.set_as_af(clk.af_num(), CLK_AF); |
| 455 | cmd.set_as_af(cmd.af_num(), CMD_AF); | 438 | cmd.set_as_af(cmd.af_num(), CMD_AF); |
| @@ -461,12 +444,12 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 461 | 444 | ||
| 462 | Self::new_inner( | 445 | Self::new_inner( |
| 463 | sdmmc, | 446 | sdmmc, |
| 464 | clk.map_into(), | 447 | clk.into(), |
| 465 | cmd.map_into(), | 448 | cmd.into(), |
| 466 | d0.map_into(), | 449 | d0.into(), |
| 467 | Some(d1.map_into()), | 450 | Some(d1.into()), |
| 468 | Some(d2.map_into()), | 451 | Some(d2.into()), |
| 469 | Some(d3.map_into()), | 452 | Some(d3.into()), |
| 470 | config, | 453 | config, |
| 471 | ) | 454 | ) |
| 472 | } | 455 | } |
| @@ -474,18 +457,16 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 474 | 457 | ||
| 475 | impl<'d, T: Instance> Sdmmc<'d, T> { | 458 | impl<'d, T: Instance> Sdmmc<'d, T> { |
| 476 | fn new_inner( | 459 | fn new_inner( |
| 477 | sdmmc: impl Peripheral<P = T> + 'd, | 460 | sdmmc: Peri<'d, T>, |
| 478 | #[cfg(sdmmc_v1)] dma: ChannelAndRequest<'d>, | 461 | #[cfg(sdmmc_v1)] dma: ChannelAndRequest<'d>, |
| 479 | clk: PeripheralRef<'d, AnyPin>, | 462 | clk: Peri<'d, AnyPin>, |
| 480 | cmd: PeripheralRef<'d, AnyPin>, | 463 | cmd: Peri<'d, AnyPin>, |
| 481 | d0: PeripheralRef<'d, AnyPin>, | 464 | d0: Peri<'d, AnyPin>, |
| 482 | d1: Option<PeripheralRef<'d, AnyPin>>, | 465 | d1: Option<Peri<'d, AnyPin>>, |
| 483 | d2: Option<PeripheralRef<'d, AnyPin>>, | 466 | d2: Option<Peri<'d, AnyPin>>, |
| 484 | d3: Option<PeripheralRef<'d, AnyPin>>, | 467 | d3: Option<Peri<'d, AnyPin>>, |
| 485 | config: Config, | 468 | config: Config, |
| 486 | ) -> Self { | 469 | ) -> Self { |
| 487 | into_ref!(sdmmc); | ||
| 488 | |||
| 489 | rcc::enable_and_reset::<T>(); | 470 | rcc::enable_and_reset::<T>(); |
| 490 | 471 | ||
| 491 | T::Interrupt::unpend(); | 472 | T::Interrupt::unpend(); |
| @@ -1478,7 +1459,7 @@ trait SealedInstance { | |||
| 1478 | 1459 | ||
| 1479 | /// SDMMC instance trait. | 1460 | /// SDMMC instance trait. |
| 1480 | #[allow(private_bounds)] | 1461 | #[allow(private_bounds)] |
| 1481 | pub trait Instance: SealedInstance + RccPeripheral + 'static { | 1462 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + 'static { |
| 1482 | /// Interrupt for this instance. | 1463 | /// Interrupt for this instance. |
| 1483 | type Interrupt: interrupt::typelevel::Interrupt; | 1464 | type Interrupt: interrupt::typelevel::Interrupt; |
| 1484 | } | 1465 | } |
diff --git a/embassy-stm32/src/spdifrx/mod.rs b/embassy-stm32/src/spdifrx/mod.rs index a205780ad..08dba04fe 100644 --- a/embassy-stm32/src/spdifrx/mod.rs +++ b/embassy-stm32/src/spdifrx/mod.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 6 | 6 | ||
| 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 8 | use embassy_sync::waitqueue::AtomicWaker; | 7 | use embassy_sync::waitqueue::AtomicWaker; |
| 9 | 8 | ||
| 10 | use crate::dma::ringbuffer::Error as RingbufferError; | 9 | use crate::dma::ringbuffer::Error as RingbufferError; |
| @@ -16,7 +15,7 @@ use crate::gpio::{AfType, AnyPin, Pull, SealedPin as _}; | |||
| 16 | use crate::interrupt::typelevel::Interrupt; | 15 | use crate::interrupt::typelevel::Interrupt; |
| 17 | use crate::pac::spdifrx::Spdifrx as Regs; | 16 | use crate::pac::spdifrx::Spdifrx as Regs; |
| 18 | use crate::rcc::{RccInfo, SealedRccPeripheral}; | 17 | use crate::rcc::{RccInfo, SealedRccPeripheral}; |
| 19 | use crate::{interrupt, peripherals, Peripheral}; | 18 | use crate::{interrupt, peripherals, Peri}; |
| 20 | 19 | ||
| 21 | /// Possible S/PDIF preamble types. | 20 | /// Possible S/PDIF preamble types. |
| 22 | #[allow(dead_code)] | 21 | #[allow(dead_code)] |
| @@ -36,10 +35,10 @@ enum PreambleType { | |||
| 36 | 35 | ||
| 37 | macro_rules! new_spdifrx_pin { | 36 | macro_rules! new_spdifrx_pin { |
| 38 | ($name:ident, $af_type:expr) => {{ | 37 | ($name:ident, $af_type:expr) => {{ |
| 39 | let pin = $name.into_ref(); | 38 | let pin = $name; |
| 40 | let input_sel = pin.input_sel(); | 39 | let input_sel = pin.input_sel(); |
| 41 | pin.set_as_af(pin.af_num(), $af_type); | 40 | pin.set_as_af(pin.af_num(), $af_type); |
| 42 | (Some(pin.map_into()), input_sel) | 41 | (Some(pin.into()), input_sel) |
| 43 | }}; | 42 | }}; |
| 44 | } | 43 | } |
| 45 | 44 | ||
| @@ -61,8 +60,8 @@ macro_rules! impl_spdifrx_pin { | |||
| 61 | /// Data is read by DMAs and stored in a ring buffer. | 60 | /// Data is read by DMAs and stored in a ring buffer. |
| 62 | #[cfg(not(gpdma))] | 61 | #[cfg(not(gpdma))] |
| 63 | pub struct Spdifrx<'d, T: Instance> { | 62 | pub struct Spdifrx<'d, T: Instance> { |
| 64 | _peri: PeripheralRef<'d, T>, | 63 | _peri: Peri<'d, T>, |
| 65 | spdifrx_in: Option<PeripheralRef<'d, AnyPin>>, | 64 | spdifrx_in: Option<Peri<'d, AnyPin>>, |
| 66 | data_ring_buffer: ReadableRingBuffer<'d, u32>, | 65 | data_ring_buffer: ReadableRingBuffer<'d, u32>, |
| 67 | } | 66 | } |
| 68 | 67 | ||
| @@ -131,18 +130,16 @@ impl<'d, T: Instance> Spdifrx<'d, T> { | |||
| 131 | 130 | ||
| 132 | /// Create a new `Spdifrx` instance. | 131 | /// Create a new `Spdifrx` instance. |
| 133 | pub fn new( | 132 | pub fn new( |
| 134 | peri: impl Peripheral<P = T> + 'd, | 133 | peri: Peri<'d, T>, |
| 135 | _irq: impl interrupt::typelevel::Binding<T::GlobalInterrupt, GlobalInterruptHandler<T>> + 'd, | 134 | _irq: impl interrupt::typelevel::Binding<T::GlobalInterrupt, GlobalInterruptHandler<T>> + 'd, |
| 136 | config: Config, | 135 | config: Config, |
| 137 | spdifrx_in: impl Peripheral<P = impl InPin<T>> + 'd, | 136 | spdifrx_in: Peri<'d, impl InPin<T>>, |
| 138 | data_dma: impl Peripheral<P = impl Channel + Dma<T>> + 'd, | 137 | data_dma: Peri<'d, impl Channel + Dma<T>>, |
| 139 | data_dma_buf: &'d mut [u32], | 138 | data_dma_buf: &'d mut [u32], |
| 140 | ) -> Self { | 139 | ) -> Self { |
| 141 | let (spdifrx_in, input_sel) = new_spdifrx_pin!(spdifrx_in, AfType::input(Pull::None)); | 140 | let (spdifrx_in, input_sel) = new_spdifrx_pin!(spdifrx_in, AfType::input(Pull::None)); |
| 142 | Self::setup(config, input_sel); | 141 | Self::setup(config, input_sel); |
| 143 | 142 | ||
| 144 | into_ref!(peri, data_dma); | ||
| 145 | |||
| 146 | let regs = T::info().regs; | 143 | let regs = T::info().regs; |
| 147 | let dr_request = data_dma.request(); | 144 | let dr_request = data_dma.request(); |
| 148 | let dr_ring_buffer = | 145 | let dr_ring_buffer = |
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index a43da1b5a..6578aa1aa 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -6,7 +6,6 @@ use core::ptr; | |||
| 6 | 6 | ||
| 7 | use embassy_embedded_hal::SetConfig; | 7 | use embassy_embedded_hal::SetConfig; |
| 8 | use embassy_futures::join::join; | 8 | use embassy_futures::join::join; |
| 9 | use embassy_hal_internal::PeripheralRef; | ||
| 10 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; | 9 | pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; |
| 11 | 10 | ||
| 12 | use crate::dma::{word, ChannelAndRequest}; | 11 | use crate::dma::{word, ChannelAndRequest}; |
| @@ -15,7 +14,7 @@ use crate::mode::{Async, Blocking, Mode as PeriMode}; | |||
| 15 | use crate::pac::spi::{regs, vals, Spi as Regs}; | 14 | use crate::pac::spi::{regs, vals, Spi as Regs}; |
| 16 | use crate::rcc::{RccInfo, SealedRccPeripheral}; | 15 | use crate::rcc::{RccInfo, SealedRccPeripheral}; |
| 17 | use crate::time::Hertz; | 16 | use crate::time::Hertz; |
| 18 | use crate::Peripheral; | 17 | use crate::Peri; |
| 19 | 18 | ||
| 20 | /// SPI error. | 19 | /// SPI error. |
| 21 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 20 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
| @@ -130,9 +129,9 @@ impl Config { | |||
| 130 | pub struct Spi<'d, M: PeriMode> { | 129 | pub struct Spi<'d, M: PeriMode> { |
| 131 | pub(crate) info: &'static Info, | 130 | pub(crate) info: &'static Info, |
| 132 | kernel_clock: Hertz, | 131 | kernel_clock: Hertz, |
| 133 | sck: Option<PeripheralRef<'d, AnyPin>>, | 132 | sck: Option<Peri<'d, AnyPin>>, |
| 134 | mosi: Option<PeripheralRef<'d, AnyPin>>, | 133 | mosi: Option<Peri<'d, AnyPin>>, |
| 135 | miso: Option<PeripheralRef<'d, AnyPin>>, | 134 | miso: Option<Peri<'d, AnyPin>>, |
| 136 | tx_dma: Option<ChannelAndRequest<'d>>, | 135 | tx_dma: Option<ChannelAndRequest<'d>>, |
| 137 | rx_dma: Option<ChannelAndRequest<'d>>, | 136 | rx_dma: Option<ChannelAndRequest<'d>>, |
| 138 | _phantom: PhantomData<M>, | 137 | _phantom: PhantomData<M>, |
| @@ -142,10 +141,10 @@ pub struct Spi<'d, M: PeriMode> { | |||
| 142 | 141 | ||
| 143 | impl<'d, M: PeriMode> Spi<'d, M> { | 142 | impl<'d, M: PeriMode> Spi<'d, M> { |
| 144 | fn new_inner<T: Instance>( | 143 | fn new_inner<T: Instance>( |
| 145 | _peri: impl Peripheral<P = T> + 'd, | 144 | _peri: Peri<'d, T>, |
| 146 | sck: Option<PeripheralRef<'d, AnyPin>>, | 145 | sck: Option<Peri<'d, AnyPin>>, |
| 147 | mosi: Option<PeripheralRef<'d, AnyPin>>, | 146 | mosi: Option<Peri<'d, AnyPin>>, |
| 148 | miso: Option<PeripheralRef<'d, AnyPin>>, | 147 | miso: Option<Peri<'d, AnyPin>>, |
| 149 | tx_dma: Option<ChannelAndRequest<'d>>, | 148 | tx_dma: Option<ChannelAndRequest<'d>>, |
| 150 | rx_dma: Option<ChannelAndRequest<'d>>, | 149 | rx_dma: Option<ChannelAndRequest<'d>>, |
| 151 | config: Config, | 150 | config: Config, |
| @@ -465,10 +464,10 @@ impl<'d, M: PeriMode> Spi<'d, M> { | |||
| 465 | impl<'d> Spi<'d, Blocking> { | 464 | impl<'d> Spi<'d, Blocking> { |
| 466 | /// Create a new blocking SPI driver. | 465 | /// Create a new blocking SPI driver. |
| 467 | pub fn new_blocking<T: Instance>( | 466 | pub fn new_blocking<T: Instance>( |
| 468 | peri: impl Peripheral<P = T> + 'd, | 467 | peri: Peri<'d, T>, |
| 469 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 468 | sck: Peri<'d, impl SckPin<T>>, |
| 470 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, | 469 | mosi: Peri<'d, impl MosiPin<T>>, |
| 471 | miso: impl Peripheral<P = impl MisoPin<T>> + 'd, | 470 | miso: Peri<'d, impl MisoPin<T>>, |
| 472 | config: Config, | 471 | config: Config, |
| 473 | ) -> Self { | 472 | ) -> Self { |
| 474 | Self::new_inner( | 473 | Self::new_inner( |
| @@ -484,9 +483,9 @@ impl<'d> Spi<'d, Blocking> { | |||
| 484 | 483 | ||
| 485 | /// Create a new blocking SPI driver, in RX-only mode (only MISO pin, no MOSI). | 484 | /// Create a new blocking SPI driver, in RX-only mode (only MISO pin, no MOSI). |
| 486 | pub fn new_blocking_rxonly<T: Instance>( | 485 | pub fn new_blocking_rxonly<T: Instance>( |
| 487 | peri: impl Peripheral<P = T> + 'd, | 486 | peri: Peri<'d, T>, |
| 488 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 487 | sck: Peri<'d, impl SckPin<T>>, |
| 489 | miso: impl Peripheral<P = impl MisoPin<T>> + 'd, | 488 | miso: Peri<'d, impl MisoPin<T>>, |
| 490 | config: Config, | 489 | config: Config, |
| 491 | ) -> Self { | 490 | ) -> Self { |
| 492 | Self::new_inner( | 491 | Self::new_inner( |
| @@ -502,9 +501,9 @@ impl<'d> Spi<'d, Blocking> { | |||
| 502 | 501 | ||
| 503 | /// Create a new blocking SPI driver, in TX-only mode (only MOSI pin, no MISO). | 502 | /// Create a new blocking SPI driver, in TX-only mode (only MOSI pin, no MISO). |
| 504 | pub fn new_blocking_txonly<T: Instance>( | 503 | pub fn new_blocking_txonly<T: Instance>( |
| 505 | peri: impl Peripheral<P = T> + 'd, | 504 | peri: Peri<'d, T>, |
| 506 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 505 | sck: Peri<'d, impl SckPin<T>>, |
| 507 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, | 506 | mosi: Peri<'d, impl MosiPin<T>>, |
| 508 | config: Config, | 507 | config: Config, |
| 509 | ) -> Self { | 508 | ) -> Self { |
| 510 | Self::new_inner( | 509 | Self::new_inner( |
| @@ -522,8 +521,8 @@ impl<'d> Spi<'d, Blocking> { | |||
| 522 | /// | 521 | /// |
| 523 | /// This can be useful for bit-banging non-SPI protocols. | 522 | /// This can be useful for bit-banging non-SPI protocols. |
| 524 | pub fn new_blocking_txonly_nosck<T: Instance>( | 523 | pub fn new_blocking_txonly_nosck<T: Instance>( |
| 525 | peri: impl Peripheral<P = T> + 'd, | 524 | peri: Peri<'d, T>, |
| 526 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, | 525 | mosi: Peri<'d, impl MosiPin<T>>, |
| 527 | config: Config, | 526 | config: Config, |
| 528 | ) -> Self { | 527 | ) -> Self { |
| 529 | Self::new_inner( | 528 | Self::new_inner( |
| @@ -541,12 +540,12 @@ impl<'d> Spi<'d, Blocking> { | |||
| 541 | impl<'d> Spi<'d, Async> { | 540 | impl<'d> Spi<'d, Async> { |
| 542 | /// Create a new SPI driver. | 541 | /// Create a new SPI driver. |
| 543 | pub fn new<T: Instance>( | 542 | pub fn new<T: Instance>( |
| 544 | peri: impl Peripheral<P = T> + 'd, | 543 | peri: Peri<'d, T>, |
| 545 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 544 | sck: Peri<'d, impl SckPin<T>>, |
| 546 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, | 545 | mosi: Peri<'d, impl MosiPin<T>>, |
| 547 | miso: impl Peripheral<P = impl MisoPin<T>> + 'd, | 546 | miso: Peri<'d, impl MisoPin<T>>, |
| 548 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 547 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 549 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 548 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 550 | config: Config, | 549 | config: Config, |
| 551 | ) -> Self { | 550 | ) -> Self { |
| 552 | Self::new_inner( | 551 | Self::new_inner( |
| @@ -562,11 +561,11 @@ impl<'d> Spi<'d, Async> { | |||
| 562 | 561 | ||
| 563 | /// Create a new SPI driver, in RX-only mode (only MISO pin, no MOSI). | 562 | /// Create a new SPI driver, in RX-only mode (only MISO pin, no MOSI). |
| 564 | pub fn new_rxonly<T: Instance>( | 563 | pub fn new_rxonly<T: Instance>( |
| 565 | peri: impl Peripheral<P = T> + 'd, | 564 | peri: Peri<'d, T>, |
| 566 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 565 | sck: Peri<'d, impl SckPin<T>>, |
| 567 | miso: impl Peripheral<P = impl MisoPin<T>> + 'd, | 566 | miso: Peri<'d, impl MisoPin<T>>, |
| 568 | #[cfg(any(spi_v1, spi_f1, spi_v2))] tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 567 | #[cfg(any(spi_v1, spi_f1, spi_v2))] tx_dma: Peri<'d, impl TxDma<T>>, |
| 569 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 568 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 570 | config: Config, | 569 | config: Config, |
| 571 | ) -> Self { | 570 | ) -> Self { |
| 572 | Self::new_inner( | 571 | Self::new_inner( |
| @@ -585,10 +584,10 @@ impl<'d> Spi<'d, Async> { | |||
| 585 | 584 | ||
| 586 | /// Create a new SPI driver, in TX-only mode (only MOSI pin, no MISO). | 585 | /// Create a new SPI driver, in TX-only mode (only MOSI pin, no MISO). |
| 587 | pub fn new_txonly<T: Instance>( | 586 | pub fn new_txonly<T: Instance>( |
| 588 | peri: impl Peripheral<P = T> + 'd, | 587 | peri: Peri<'d, T>, |
| 589 | sck: impl Peripheral<P = impl SckPin<T>> + 'd, | 588 | sck: Peri<'d, impl SckPin<T>>, |
| 590 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, | 589 | mosi: Peri<'d, impl MosiPin<T>>, |
| 591 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 590 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 592 | config: Config, | 591 | config: Config, |
| 593 | ) -> Self { | 592 | ) -> Self { |
| 594 | Self::new_inner( | 593 | Self::new_inner( |
| @@ -606,9 +605,9 @@ impl<'d> Spi<'d, Async> { | |||
| 606 | /// | 605 | /// |
| 607 | /// This can be useful for bit-banging non-SPI protocols. | 606 | /// This can be useful for bit-banging non-SPI protocols. |
| 608 | pub fn new_txonly_nosck<T: Instance>( | 607 | pub fn new_txonly_nosck<T: Instance>( |
| 609 | peri: impl Peripheral<P = T> + 'd, | 608 | peri: Peri<'d, T>, |
| 610 | mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, | 609 | mosi: Peri<'d, impl MosiPin<T>>, |
| 611 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 610 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 612 | config: Config, | 611 | config: Config, |
| 613 | ) -> Self { | 612 | ) -> Self { |
| 614 | Self::new_inner( | 613 | Self::new_inner( |
| @@ -625,9 +624,9 @@ impl<'d> Spi<'d, Async> { | |||
| 625 | #[cfg(stm32wl)] | 624 | #[cfg(stm32wl)] |
| 626 | /// Useful for on chip peripherals like SUBGHZ which are hardwired. | 625 | /// Useful for on chip peripherals like SUBGHZ which are hardwired. |
| 627 | pub fn new_subghz<T: Instance>( | 626 | pub fn new_subghz<T: Instance>( |
| 628 | peri: impl Peripheral<P = T> + 'd, | 627 | peri: Peri<'d, T>, |
| 629 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 628 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 630 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 629 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 631 | ) -> Self { | 630 | ) -> Self { |
| 632 | // see RM0453 rev 1 section 7.2.13 page 291 | 631 | // see RM0453 rev 1 section 7.2.13 page 291 |
| 633 | // The SUBGHZSPI_SCK frequency is obtained by PCLK3 divided by two. | 632 | // The SUBGHZSPI_SCK frequency is obtained by PCLK3 divided by two. |
| @@ -644,7 +643,7 @@ impl<'d> Spi<'d, Async> { | |||
| 644 | 643 | ||
| 645 | #[allow(dead_code)] | 644 | #[allow(dead_code)] |
| 646 | pub(crate) fn new_internal<T: Instance>( | 645 | pub(crate) fn new_internal<T: Instance>( |
| 647 | peri: impl Peripheral<P = T> + 'd, | 646 | peri: Peri<'d, T>, |
| 648 | tx_dma: Option<ChannelAndRequest<'d>>, | 647 | tx_dma: Option<ChannelAndRequest<'d>>, |
| 649 | rx_dma: Option<ChannelAndRequest<'d>>, | 648 | rx_dma: Option<ChannelAndRequest<'d>>, |
| 650 | config: Config, | 649 | config: Config, |
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs index 02c01e900..f543bafab 100644 --- a/embassy-stm32/src/timer/complementary_pwm.rs +++ b/embassy-stm32/src/timer/complementary_pwm.rs | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | 2 | ||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | 4 | ||
| 5 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 6 | use stm32_metapac::timer::vals::Ckd; | 5 | use stm32_metapac::timer::vals::Ckd; |
| 7 | 6 | ||
| 8 | use super::low_level::{CountingMode, OutputPolarity, Timer}; | 7 | use super::low_level::{CountingMode, OutputPolarity, Timer}; |
| @@ -14,13 +13,13 @@ use super::{ | |||
| 14 | use crate::gpio::{AnyPin, OutputType}; | 13 | use crate::gpio::{AnyPin, OutputType}; |
| 15 | use crate::time::Hertz; | 14 | use crate::time::Hertz; |
| 16 | use crate::timer::low_level::OutputCompareMode; | 15 | use crate::timer::low_level::OutputCompareMode; |
| 17 | use crate::Peripheral; | 16 | use crate::Peri; |
| 18 | 17 | ||
| 19 | /// Complementary PWM pin wrapper. | 18 | /// Complementary PWM pin wrapper. |
| 20 | /// | 19 | /// |
| 21 | /// This wraps a pin to make it usable with PWM. | 20 | /// This wraps a pin to make it usable with PWM. |
| 22 | pub struct ComplementaryPwmPin<'d, T, C> { | 21 | pub struct ComplementaryPwmPin<'d, T, C> { |
| 23 | _pin: PeripheralRef<'d, AnyPin>, | 22 | _pin: Peri<'d, AnyPin>, |
| 24 | phantom: PhantomData<(T, C)>, | 23 | phantom: PhantomData<(T, C)>, |
| 25 | } | 24 | } |
| 26 | 25 | ||
| @@ -28,8 +27,7 @@ macro_rules! complementary_channel_impl { | |||
| 28 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { | 27 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { |
| 29 | impl<'d, T: AdvancedInstance4Channel> ComplementaryPwmPin<'d, T, $channel> { | 28 | impl<'d, T: AdvancedInstance4Channel> ComplementaryPwmPin<'d, T, $channel> { |
| 30 | #[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance.")] | 29 | #[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance.")] |
| 31 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, output_type: OutputType) -> Self { | 30 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>, output_type: OutputType) -> Self { |
| 32 | into_ref!(pin); | ||
| 33 | critical_section::with(|_| { | 31 | critical_section::with(|_| { |
| 34 | pin.set_low(); | 32 | pin.set_low(); |
| 35 | pin.set_as_af( | 33 | pin.set_as_af( |
| @@ -38,7 +36,7 @@ macro_rules! complementary_channel_impl { | |||
| 38 | ); | 36 | ); |
| 39 | }); | 37 | }); |
| 40 | ComplementaryPwmPin { | 38 | ComplementaryPwmPin { |
| 41 | _pin: pin.map_into(), | 39 | _pin: pin.into(), |
| 42 | phantom: PhantomData, | 40 | phantom: PhantomData, |
| 43 | } | 41 | } |
| 44 | } | 42 | } |
| @@ -60,7 +58,7 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> { | |||
| 60 | /// Create a new complementary PWM driver. | 58 | /// Create a new complementary PWM driver. |
| 61 | #[allow(clippy::too_many_arguments)] | 59 | #[allow(clippy::too_many_arguments)] |
| 62 | pub fn new( | 60 | pub fn new( |
| 63 | tim: impl Peripheral<P = T> + 'd, | 61 | tim: Peri<'d, T>, |
| 64 | _ch1: Option<PwmPin<'d, T, Ch1>>, | 62 | _ch1: Option<PwmPin<'d, T, Ch1>>, |
| 65 | _ch1n: Option<ComplementaryPwmPin<'d, T, Ch1>>, | 63 | _ch1n: Option<ComplementaryPwmPin<'d, T, Ch1>>, |
| 66 | _ch2: Option<PwmPin<'d, T, Ch2>>, | 64 | _ch2: Option<PwmPin<'d, T, Ch2>>, |
| @@ -75,7 +73,7 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> { | |||
| 75 | Self::new_inner(tim, freq, counting_mode) | 73 | Self::new_inner(tim, freq, counting_mode) |
| 76 | } | 74 | } |
| 77 | 75 | ||
| 78 | fn new_inner(tim: impl Peripheral<P = T> + 'd, freq: Hertz, counting_mode: CountingMode) -> Self { | 76 | fn new_inner(tim: Peri<'d, T>, freq: Hertz, counting_mode: CountingMode) -> Self { |
| 79 | let mut this = Self { inner: Timer::new(tim) }; | 77 | let mut this = Self { inner: Timer::new(tim) }; |
| 80 | 78 | ||
| 81 | this.inner.set_counting_mode(counting_mode); | 79 | this.inner.set_counting_mode(counting_mode); |
diff --git a/embassy-stm32/src/timer/input_capture.rs b/embassy-stm32/src/timer/input_capture.rs index b7c13343c..0450f14fa 100644 --- a/embassy-stm32/src/timer/input_capture.rs +++ b/embassy-stm32/src/timer/input_capture.rs | |||
| @@ -5,8 +5,6 @@ use core::marker::PhantomData; | |||
| 5 | use core::pin::Pin; | 5 | use core::pin::Pin; |
| 6 | use core::task::{Context, Poll}; | 6 | use core::task::{Context, Poll}; |
| 7 | 7 | ||
| 8 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 9 | |||
| 10 | use super::low_level::{CountingMode, FilterValue, InputCaptureMode, InputTISelection, Timer}; | 8 | use super::low_level::{CountingMode, FilterValue, InputCaptureMode, InputTISelection, Timer}; |
| 11 | use super::{ | 9 | use super::{ |
| 12 | CaptureCompareInterruptHandler, Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, | 10 | CaptureCompareInterruptHandler, Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, |
| @@ -15,7 +13,7 @@ use super::{ | |||
| 15 | use crate::gpio::{AfType, AnyPin, Pull}; | 13 | use crate::gpio::{AfType, AnyPin, Pull}; |
| 16 | use crate::interrupt::typelevel::{Binding, Interrupt}; | 14 | use crate::interrupt::typelevel::{Binding, Interrupt}; |
| 17 | use crate::time::Hertz; | 15 | use crate::time::Hertz; |
| 18 | use crate::Peripheral; | 16 | use crate::Peri; |
| 19 | 17 | ||
| 20 | /// Channel 1 marker type. | 18 | /// Channel 1 marker type. |
| 21 | pub enum Ch1 {} | 19 | pub enum Ch1 {} |
| @@ -30,7 +28,7 @@ pub enum Ch4 {} | |||
| 30 | /// | 28 | /// |
| 31 | /// This wraps a pin to make it usable with capture. | 29 | /// This wraps a pin to make it usable with capture. |
| 32 | pub struct CapturePin<'d, T, C> { | 30 | pub struct CapturePin<'d, T, C> { |
| 33 | _pin: PeripheralRef<'d, AnyPin>, | 31 | _pin: Peri<'d, AnyPin>, |
| 34 | phantom: PhantomData<(T, C)>, | 32 | phantom: PhantomData<(T, C)>, |
| 35 | } | 33 | } |
| 36 | 34 | ||
| @@ -38,11 +36,10 @@ macro_rules! channel_impl { | |||
| 38 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { | 36 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { |
| 39 | impl<'d, T: GeneralInstance4Channel> CapturePin<'d, T, $channel> { | 37 | impl<'d, T: GeneralInstance4Channel> CapturePin<'d, T, $channel> { |
| 40 | #[doc = concat!("Create a new ", stringify!($channel), " capture pin instance.")] | 38 | #[doc = concat!("Create a new ", stringify!($channel), " capture pin instance.")] |
| 41 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, pull: Pull) -> Self { | 39 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>, pull: Pull) -> Self { |
| 42 | into_ref!(pin); | ||
| 43 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 40 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 44 | CapturePin { | 41 | CapturePin { |
| 45 | _pin: pin.map_into(), | 42 | _pin: pin.into(), |
| 46 | phantom: PhantomData, | 43 | phantom: PhantomData, |
| 47 | } | 44 | } |
| 48 | } | 45 | } |
| @@ -63,7 +60,7 @@ pub struct InputCapture<'d, T: GeneralInstance4Channel> { | |||
| 63 | impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> { | 60 | impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> { |
| 64 | /// Create a new input capture driver. | 61 | /// Create a new input capture driver. |
| 65 | pub fn new( | 62 | pub fn new( |
| 66 | tim: impl Peripheral<P = T> + 'd, | 63 | tim: Peri<'d, T>, |
| 67 | _ch1: Option<CapturePin<'d, T, Ch1>>, | 64 | _ch1: Option<CapturePin<'d, T, Ch1>>, |
| 68 | _ch2: Option<CapturePin<'d, T, Ch2>>, | 65 | _ch2: Option<CapturePin<'d, T, Ch2>>, |
| 69 | _ch3: Option<CapturePin<'d, T, Ch3>>, | 66 | _ch3: Option<CapturePin<'d, T, Ch3>>, |
| @@ -75,7 +72,7 @@ impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> { | |||
| 75 | Self::new_inner(tim, freq, counting_mode) | 72 | Self::new_inner(tim, freq, counting_mode) |
| 76 | } | 73 | } |
| 77 | 74 | ||
| 78 | fn new_inner(tim: impl Peripheral<P = T> + 'd, freq: Hertz, counting_mode: CountingMode) -> Self { | 75 | fn new_inner(tim: Peri<'d, T>, freq: Hertz, counting_mode: CountingMode) -> Self { |
| 79 | let mut this = Self { inner: Timer::new(tim) }; | 76 | let mut this = Self { inner: Timer::new(tim) }; |
| 80 | 77 | ||
| 81 | this.inner.set_counting_mode(counting_mode); | 78 | this.inner.set_counting_mode(counting_mode); |
diff --git a/embassy-stm32/src/timer/low_level.rs b/embassy-stm32/src/timer/low_level.rs index 5b0c95109..8fc32c1f3 100644 --- a/embassy-stm32/src/timer/low_level.rs +++ b/embassy-stm32/src/timer/low_level.rs | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | use core::mem::ManuallyDrop; | 9 | use core::mem::ManuallyDrop; |
| 10 | 10 | ||
| 11 | use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; | 11 | use embassy_hal_internal::Peri; |
| 12 | // Re-export useful enums | 12 | // Re-export useful enums |
| 13 | pub use stm32_metapac::timer::vals::{FilterValue, Sms as SlaveMode, Ts as TriggerSource}; | 13 | pub use stm32_metapac::timer::vals::{FilterValue, Sms as SlaveMode, Ts as TriggerSource}; |
| 14 | 14 | ||
| @@ -181,7 +181,7 @@ impl From<OutputPolarity> for bool { | |||
| 181 | 181 | ||
| 182 | /// Low-level timer driver. | 182 | /// Low-level timer driver. |
| 183 | pub struct Timer<'d, T: CoreInstance> { | 183 | pub struct Timer<'d, T: CoreInstance> { |
| 184 | tim: PeripheralRef<'d, T>, | 184 | tim: Peri<'d, T>, |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | impl<'d, T: CoreInstance> Drop for Timer<'d, T> { | 187 | impl<'d, T: CoreInstance> Drop for Timer<'d, T> { |
| @@ -192,9 +192,7 @@ impl<'d, T: CoreInstance> Drop for Timer<'d, T> { | |||
| 192 | 192 | ||
| 193 | impl<'d, T: CoreInstance> Timer<'d, T> { | 193 | impl<'d, T: CoreInstance> Timer<'d, T> { |
| 194 | /// Create a new timer driver. | 194 | /// Create a new timer driver. |
| 195 | pub fn new(tim: impl Peripheral<P = T> + 'd) -> Self { | 195 | pub fn new(tim: Peri<'d, T>) -> Self { |
| 196 | into_ref!(tim); | ||
| 197 | |||
| 198 | rcc::enable_and_reset::<T>(); | 196 | rcc::enable_and_reset::<T>(); |
| 199 | 197 | ||
| 200 | Self { tim } | 198 | Self { tim } |
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index 97740c2ed..765a3d9fa 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | 4 | ||
| 5 | use embassy_hal_internal::Peripheral; | 5 | use embassy_hal_internal::PeripheralType; |
| 6 | use embassy_sync::waitqueue::AtomicWaker; | 6 | use embassy_sync::waitqueue::AtomicWaker; |
| 7 | 7 | ||
| 8 | #[cfg(not(stm32l0))] | 8 | #[cfg(not(stm32l0))] |
| @@ -66,7 +66,7 @@ impl State { | |||
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | trait SealedInstance: RccPeripheral + Peripheral<P = Self> { | 69 | trait SealedInstance: RccPeripheral + PeripheralType { |
| 70 | /// Async state for this timer | 70 | /// Async state for this timer |
| 71 | fn state() -> &'static State; | 71 | fn state() -> &'static State; |
| 72 | } | 72 | } |
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs index e3eb6042a..98b798634 100644 --- a/embassy-stm32/src/timer/pwm_input.rs +++ b/embassy-stm32/src/timer/pwm_input.rs | |||
| @@ -1,12 +1,10 @@ | |||
| 1 | //! PWM Input driver. | 1 | //! PWM Input driver. |
| 2 | 2 | ||
| 3 | use embassy_hal_internal::into_ref; | ||
| 4 | |||
| 5 | use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource}; | 3 | use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource}; |
| 6 | use super::{Channel, Channel1Pin, Channel2Pin, GeneralInstance4Channel}; | 4 | use super::{Channel, Channel1Pin, Channel2Pin, GeneralInstance4Channel}; |
| 7 | use crate::gpio::{AfType, Pull}; | 5 | use crate::gpio::{AfType, Pull}; |
| 8 | use crate::time::Hertz; | 6 | use crate::time::Hertz; |
| 9 | use crate::Peripheral; | 7 | use crate::Peri; |
| 10 | 8 | ||
| 11 | /// PWM Input driver. | 9 | /// PWM Input driver. |
| 12 | pub struct PwmInput<'d, T: GeneralInstance4Channel> { | 10 | pub struct PwmInput<'d, T: GeneralInstance4Channel> { |
| @@ -16,34 +14,20 @@ pub struct PwmInput<'d, T: GeneralInstance4Channel> { | |||
| 16 | 14 | ||
| 17 | impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | 15 | impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { |
| 18 | /// Create a new PWM input driver. | 16 | /// Create a new PWM input driver. |
| 19 | pub fn new( | 17 | pub fn new(tim: Peri<'d, T>, pin: Peri<'d, impl Channel1Pin<T>>, pull: Pull, freq: Hertz) -> Self { |
| 20 | tim: impl Peripheral<P = T> + 'd, | ||
| 21 | pin: impl Peripheral<P = impl Channel1Pin<T>> + 'd, | ||
| 22 | pull: Pull, | ||
| 23 | freq: Hertz, | ||
| 24 | ) -> Self { | ||
| 25 | into_ref!(pin); | ||
| 26 | |||
| 27 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 18 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 28 | 19 | ||
| 29 | Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) | 20 | Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) |
| 30 | } | 21 | } |
| 31 | 22 | ||
| 32 | /// Create a new PWM input driver. | 23 | /// Create a new PWM input driver. |
| 33 | pub fn new_alt( | 24 | pub fn new_alt(tim: Peri<'d, T>, pin: Peri<'d, impl Channel2Pin<T>>, pull: Pull, freq: Hertz) -> Self { |
| 34 | tim: impl Peripheral<P = T> + 'd, | ||
| 35 | pin: impl Peripheral<P = impl Channel2Pin<T>> + 'd, | ||
| 36 | pull: Pull, | ||
| 37 | freq: Hertz, | ||
| 38 | ) -> Self { | ||
| 39 | into_ref!(pin); | ||
| 40 | |||
| 41 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 25 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 42 | 26 | ||
| 43 | Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) | 27 | Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) |
| 44 | } | 28 | } |
| 45 | 29 | ||
| 46 | fn new_inner(tim: impl Peripheral<P = T> + 'd, freq: Hertz, ch1: Channel, ch2: Channel) -> Self { | 30 | fn new_inner(tim: Peri<'d, T>, freq: Hertz, ch1: Channel, ch2: Channel) -> Self { |
| 47 | let mut inner = Timer::new(tim); | 31 | let mut inner = Timer::new(tim); |
| 48 | 32 | ||
| 49 | inner.set_counting_mode(CountingMode::EdgeAlignedUp); | 33 | inner.set_counting_mode(CountingMode::EdgeAlignedUp); |
diff --git a/embassy-stm32/src/timer/qei.rs b/embassy-stm32/src/timer/qei.rs index fc5835414..bac290f28 100644 --- a/embassy-stm32/src/timer/qei.rs +++ b/embassy-stm32/src/timer/qei.rs | |||
| @@ -2,13 +2,12 @@ | |||
| 2 | 2 | ||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | 4 | ||
| 5 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 6 | use stm32_metapac::timer::vals; | 5 | use stm32_metapac::timer::vals; |
| 7 | 6 | ||
| 8 | use super::low_level::Timer; | 7 | use super::low_level::Timer; |
| 9 | use super::{Channel1Pin, Channel2Pin, GeneralInstance4Channel}; | 8 | use super::{Channel1Pin, Channel2Pin, GeneralInstance4Channel}; |
| 10 | use crate::gpio::{AfType, AnyPin, Pull}; | 9 | use crate::gpio::{AfType, AnyPin, Pull}; |
| 11 | use crate::Peripheral; | 10 | use crate::Peri; |
| 12 | 11 | ||
| 13 | /// Counting direction | 12 | /// Counting direction |
| 14 | pub enum Direction { | 13 | pub enum Direction { |
| @@ -25,7 +24,7 @@ pub enum Ch2 {} | |||
| 25 | 24 | ||
| 26 | /// Wrapper for using a pin with QEI. | 25 | /// Wrapper for using a pin with QEI. |
| 27 | pub struct QeiPin<'d, T, Channel> { | 26 | pub struct QeiPin<'d, T, Channel> { |
| 28 | _pin: PeripheralRef<'d, AnyPin>, | 27 | _pin: Peri<'d, AnyPin>, |
| 29 | phantom: PhantomData<(T, Channel)>, | 28 | phantom: PhantomData<(T, Channel)>, |
| 30 | } | 29 | } |
| 31 | 30 | ||
| @@ -33,14 +32,13 @@ macro_rules! channel_impl { | |||
| 33 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { | 32 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { |
| 34 | impl<'d, T: GeneralInstance4Channel> QeiPin<'d, T, $channel> { | 33 | impl<'d, T: GeneralInstance4Channel> QeiPin<'d, T, $channel> { |
| 35 | #[doc = concat!("Create a new ", stringify!($channel), " QEI pin instance.")] | 34 | #[doc = concat!("Create a new ", stringify!($channel), " QEI pin instance.")] |
| 36 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self { | 35 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self { |
| 37 | into_ref!(pin); | ||
| 38 | critical_section::with(|_| { | 36 | critical_section::with(|_| { |
| 39 | pin.set_low(); | 37 | pin.set_low(); |
| 40 | pin.set_as_af(pin.af_num(), AfType::input(Pull::None)); | 38 | pin.set_as_af(pin.af_num(), AfType::input(Pull::None)); |
| 41 | }); | 39 | }); |
| 42 | QeiPin { | 40 | QeiPin { |
| 43 | _pin: pin.map_into(), | 41 | _pin: pin.into(), |
| 44 | phantom: PhantomData, | 42 | phantom: PhantomData, |
| 45 | } | 43 | } |
| 46 | } | 44 | } |
| @@ -58,11 +56,11 @@ pub struct Qei<'d, T: GeneralInstance4Channel> { | |||
| 58 | 56 | ||
| 59 | impl<'d, T: GeneralInstance4Channel> Qei<'d, T> { | 57 | impl<'d, T: GeneralInstance4Channel> Qei<'d, T> { |
| 60 | /// Create a new quadrature decoder driver. | 58 | /// Create a new quadrature decoder driver. |
| 61 | pub fn new(tim: impl Peripheral<P = T> + 'd, _ch1: QeiPin<'d, T, Ch1>, _ch2: QeiPin<'d, T, Ch2>) -> Self { | 59 | pub fn new(tim: Peri<'d, T>, _ch1: QeiPin<'d, T, Ch1>, _ch2: QeiPin<'d, T, Ch2>) -> Self { |
| 62 | Self::new_inner(tim) | 60 | Self::new_inner(tim) |
| 63 | } | 61 | } |
| 64 | 62 | ||
| 65 | fn new_inner(tim: impl Peripheral<P = T> + 'd) -> Self { | 63 | fn new_inner(tim: Peri<'d, T>) -> Self { |
| 66 | let inner = Timer::new(tim); | 64 | let inner = Timer::new(tim); |
| 67 | let r = inner.regs_gp16(); | 65 | let r = inner.regs_gp16(); |
| 68 | 66 | ||
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs index c5a366cd5..54ab7d0d5 100644 --- a/embassy-stm32/src/timer/simple_pwm.rs +++ b/embassy-stm32/src/timer/simple_pwm.rs | |||
| @@ -3,15 +3,13 @@ | |||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | use core::mem::ManuallyDrop; | 4 | use core::mem::ManuallyDrop; |
| 5 | 5 | ||
| 6 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 7 | |||
| 8 | use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer}; | 6 | use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer}; |
| 9 | use super::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance4Channel, TimerBits}; | 7 | use super::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance4Channel, TimerBits}; |
| 10 | #[cfg(gpio_v2)] | 8 | #[cfg(gpio_v2)] |
| 11 | use crate::gpio::Pull; | 9 | use crate::gpio::Pull; |
| 12 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; | 10 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; |
| 13 | use crate::time::Hertz; | 11 | use crate::time::Hertz; |
| 14 | use crate::Peripheral; | 12 | use crate::Peri; |
| 15 | 13 | ||
| 16 | /// Channel 1 marker type. | 14 | /// Channel 1 marker type. |
| 17 | pub enum Ch1 {} | 15 | pub enum Ch1 {} |
| @@ -26,7 +24,7 @@ pub enum Ch4 {} | |||
| 26 | /// | 24 | /// |
| 27 | /// This wraps a pin to make it usable with PWM. | 25 | /// This wraps a pin to make it usable with PWM. |
| 28 | pub struct PwmPin<'d, T, C> { | 26 | pub struct PwmPin<'d, T, C> { |
| 29 | _pin: PeripheralRef<'d, AnyPin>, | 27 | _pin: Peri<'d, AnyPin>, |
| 30 | phantom: PhantomData<(T, C)>, | 28 | phantom: PhantomData<(T, C)>, |
| 31 | } | 29 | } |
| 32 | 30 | ||
| @@ -47,24 +45,19 @@ macro_rules! channel_impl { | |||
| 47 | ($new_chx:ident, $new_chx_with_config:ident, $channel:ident, $pin_trait:ident) => { | 45 | ($new_chx:ident, $new_chx_with_config:ident, $channel:ident, $pin_trait:ident) => { |
| 48 | impl<'d, T: GeneralInstance4Channel> PwmPin<'d, T, $channel> { | 46 | impl<'d, T: GeneralInstance4Channel> PwmPin<'d, T, $channel> { |
| 49 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] | 47 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] |
| 50 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, output_type: OutputType) -> Self { | 48 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>, output_type: OutputType) -> Self { |
| 51 | into_ref!(pin); | ||
| 52 | critical_section::with(|_| { | 49 | critical_section::with(|_| { |
| 53 | pin.set_low(); | 50 | pin.set_low(); |
| 54 | pin.set_as_af(pin.af_num(), AfType::output(output_type, Speed::VeryHigh)); | 51 | pin.set_as_af(pin.af_num(), AfType::output(output_type, Speed::VeryHigh)); |
| 55 | }); | 52 | }); |
| 56 | PwmPin { | 53 | PwmPin { |
| 57 | _pin: pin.map_into(), | 54 | _pin: pin.into(), |
| 58 | phantom: PhantomData, | 55 | phantom: PhantomData, |
| 59 | } | 56 | } |
| 60 | } | 57 | } |
| 61 | 58 | ||
| 62 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance with config.")] | 59 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance with config.")] |
| 63 | pub fn $new_chx_with_config( | 60 | pub fn $new_chx_with_config(pin: Peri<'d, impl $pin_trait<T>>, pin_config: PwmPinConfig) -> Self { |
| 64 | pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, | ||
| 65 | pin_config: PwmPinConfig, | ||
| 66 | ) -> Self { | ||
| 67 | into_ref!(pin); | ||
| 68 | critical_section::with(|_| { | 61 | critical_section::with(|_| { |
| 69 | pin.set_low(); | 62 | pin.set_low(); |
| 70 | pin.set_as_af( | 63 | pin.set_as_af( |
| @@ -76,7 +69,7 @@ macro_rules! channel_impl { | |||
| 76 | ); | 69 | ); |
| 77 | }); | 70 | }); |
| 78 | PwmPin { | 71 | PwmPin { |
| 79 | _pin: pin.map_into(), | 72 | _pin: pin.into(), |
| 80 | phantom: PhantomData, | 73 | phantom: PhantomData, |
| 81 | } | 74 | } |
| 82 | } | 75 | } |
| @@ -202,7 +195,7 @@ pub struct SimplePwm<'d, T: GeneralInstance4Channel> { | |||
| 202 | impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { | 195 | impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { |
| 203 | /// Create a new simple PWM driver. | 196 | /// Create a new simple PWM driver. |
| 204 | pub fn new( | 197 | pub fn new( |
| 205 | tim: impl Peripheral<P = T> + 'd, | 198 | tim: Peri<'d, T>, |
| 206 | _ch1: Option<PwmPin<'d, T, Ch1>>, | 199 | _ch1: Option<PwmPin<'d, T, Ch1>>, |
| 207 | _ch2: Option<PwmPin<'d, T, Ch2>>, | 200 | _ch2: Option<PwmPin<'d, T, Ch2>>, |
| 208 | _ch3: Option<PwmPin<'d, T, Ch3>>, | 201 | _ch3: Option<PwmPin<'d, T, Ch3>>, |
| @@ -213,7 +206,7 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { | |||
| 213 | Self::new_inner(tim, freq, counting_mode) | 206 | Self::new_inner(tim, freq, counting_mode) |
| 214 | } | 207 | } |
| 215 | 208 | ||
| 216 | fn new_inner(tim: impl Peripheral<P = T> + 'd, freq: Hertz, counting_mode: CountingMode) -> Self { | 209 | fn new_inner(tim: Peri<'d, T>, freq: Hertz, counting_mode: CountingMode) -> Self { |
| 217 | let mut this = Self { inner: Timer::new(tim) }; | 210 | let mut this = Self { inner: Timer::new(tim) }; |
| 218 | 211 | ||
| 219 | this.inner.set_counting_mode(counting_mode); | 212 | this.inner.set_counting_mode(counting_mode); |
| @@ -331,14 +324,7 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { | |||
| 331 | /// | 324 | /// |
| 332 | /// Note: | 325 | /// Note: |
| 333 | /// you will need to provide corresponding TIMx_UP DMA channel to use this method. | 326 | /// you will need to provide corresponding TIMx_UP DMA channel to use this method. |
| 334 | pub async fn waveform_up( | 327 | pub async fn waveform_up(&mut self, dma: Peri<'_, impl super::UpDma<T>>, channel: Channel, duty: &[u16]) { |
| 335 | &mut self, | ||
| 336 | dma: impl Peripheral<P = impl super::UpDma<T>>, | ||
| 337 | channel: Channel, | ||
| 338 | duty: &[u16], | ||
| 339 | ) { | ||
| 340 | into_ref!(dma); | ||
| 341 | |||
| 342 | #[allow(clippy::let_unit_value)] // eg. stm32f334 | 328 | #[allow(clippy::let_unit_value)] // eg. stm32f334 |
| 343 | let req = dma.request(); | 329 | let req = dma.request(); |
| 344 | 330 | ||
| @@ -368,7 +354,7 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { | |||
| 368 | }; | 354 | }; |
| 369 | 355 | ||
| 370 | Transfer::new_write( | 356 | Transfer::new_write( |
| 371 | &mut dma, | 357 | dma, |
| 372 | req, | 358 | req, |
| 373 | duty, | 359 | duty, |
| 374 | self.inner.regs_1ch().ccr(channel.index()).as_ptr() as *mut u16, | 360 | self.inner.regs_1ch().ccr(channel.index()).as_ptr() as *mut u16, |
| @@ -399,11 +385,9 @@ macro_rules! impl_waveform_chx { | |||
| 399 | ($fn_name:ident, $dma_ch:ident, $cc_ch:ident) => { | 385 | ($fn_name:ident, $dma_ch:ident, $cc_ch:ident) => { |
| 400 | impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { | 386 | impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { |
| 401 | /// Generate a sequence of PWM waveform | 387 | /// Generate a sequence of PWM waveform |
| 402 | pub async fn $fn_name(&mut self, dma: impl Peripheral<P = impl super::$dma_ch<T>>, duty: &[u16]) { | 388 | pub async fn $fn_name(&mut self, dma: Peri<'_, impl super::$dma_ch<T>>, duty: &[u16]) { |
| 403 | use crate::pac::timer::vals::Ccds; | 389 | use crate::pac::timer::vals::Ccds; |
| 404 | 390 | ||
| 405 | into_ref!(dma); | ||
| 406 | |||
| 407 | #[allow(clippy::let_unit_value)] // eg. stm32f334 | 391 | #[allow(clippy::let_unit_value)] // eg. stm32f334 |
| 408 | let req = dma.request(); | 392 | let req = dma.request(); |
| 409 | 393 | ||
| @@ -443,7 +427,7 @@ macro_rules! impl_waveform_chx { | |||
| 443 | match self.inner.bits() { | 427 | match self.inner.bits() { |
| 444 | TimerBits::Bits16 => { | 428 | TimerBits::Bits16 => { |
| 445 | Transfer::new_write( | 429 | Transfer::new_write( |
| 446 | &mut dma, | 430 | dma, |
| 447 | req, | 431 | req, |
| 448 | duty, | 432 | duty, |
| 449 | self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u16, | 433 | self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u16, |
| @@ -458,7 +442,7 @@ macro_rules! impl_waveform_chx { | |||
| 458 | 442 | ||
| 459 | #[cfg(any(bdma, gpdma))] | 443 | #[cfg(any(bdma, gpdma))] |
| 460 | Transfer::new_write( | 444 | Transfer::new_write( |
| 461 | &mut dma, | 445 | dma, |
| 462 | req, | 446 | req, |
| 463 | duty, | 447 | duty, |
| 464 | self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u32, | 448 | self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u32, |
diff --git a/embassy-stm32/src/tsc/mod.rs b/embassy-stm32/src/tsc/mod.rs index 0d5c27465..9359d83e9 100644 --- a/embassy-stm32/src/tsc/mod.rs +++ b/embassy-stm32/src/tsc/mod.rs | |||
| @@ -98,6 +98,7 @@ use core::marker::PhantomData; | |||
| 98 | 98 | ||
| 99 | pub use acquisition_banks::*; | 99 | pub use acquisition_banks::*; |
| 100 | pub use config::*; | 100 | pub use config::*; |
| 101 | use embassy_hal_internal::PeripheralType; | ||
| 101 | use embassy_sync::waitqueue::AtomicWaker; | 102 | use embassy_sync::waitqueue::AtomicWaker; |
| 102 | pub use errors::*; | 103 | pub use errors::*; |
| 103 | pub use io_pin::*; | 104 | pub use io_pin::*; |
| @@ -106,7 +107,7 @@ pub use tsc::*; | |||
| 106 | pub use types::*; | 107 | pub use types::*; |
| 107 | 108 | ||
| 108 | use crate::rcc::RccPeripheral; | 109 | use crate::rcc::RccPeripheral; |
| 109 | use crate::{interrupt, peripherals, Peripheral}; | 110 | use crate::{interrupt, peripherals}; |
| 110 | 111 | ||
| 111 | #[cfg(tsc_v1)] | 112 | #[cfg(tsc_v1)] |
| 112 | const TSC_NUM_GROUPS: usize = 6; | 113 | const TSC_NUM_GROUPS: usize = 6; |
| @@ -142,7 +143,7 @@ pub(crate) trait SealedInstance { | |||
| 142 | 143 | ||
| 143 | /// TSC instance trait | 144 | /// TSC instance trait |
| 144 | #[allow(private_bounds)] | 145 | #[allow(private_bounds)] |
| 145 | pub trait Instance: Peripheral<P = Self> + SealedInstance + RccPeripheral { | 146 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral { |
| 146 | /// Interrupt for this TSC instance | 147 | /// Interrupt for this TSC instance |
| 147 | type Interrupt: interrupt::typelevel::Interrupt; | 148 | type Interrupt: interrupt::typelevel::Interrupt; |
| 148 | } | 149 | } |
diff --git a/embassy-stm32/src/tsc/pin_groups.rs b/embassy-stm32/src/tsc/pin_groups.rs index 1f3aafa35..6f914a94e 100644 --- a/embassy-stm32/src/tsc/pin_groups.rs +++ b/embassy-stm32/src/tsc/pin_groups.rs | |||
| @@ -1,13 +1,11 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | use core::ops::BitOr; | 2 | use core::ops::BitOr; |
| 3 | 3 | ||
| 4 | use embassy_hal_internal::{into_ref, PeripheralRef}; | ||
| 5 | |||
| 6 | use super::errors::GroupError; | 4 | use super::errors::GroupError; |
| 7 | use super::io_pin::*; | 5 | use super::io_pin::*; |
| 8 | use super::Instance; | 6 | use super::Instance; |
| 9 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; | 7 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; |
| 10 | use crate::Peripheral; | 8 | use crate::Peri; |
| 11 | 9 | ||
| 12 | /// Pin type definition to control IO parameters | 10 | /// Pin type definition to control IO parameters |
| 13 | #[derive(PartialEq, Clone, Copy)] | 11 | #[derive(PartialEq, Clone, Copy)] |
| @@ -23,7 +21,7 @@ pub enum PinType { | |||
| 23 | /// Pin struct that maintains usage | 21 | /// Pin struct that maintains usage |
| 24 | #[allow(missing_docs)] | 22 | #[allow(missing_docs)] |
| 25 | pub struct Pin<'d, T, Group> { | 23 | pub struct Pin<'d, T, Group> { |
| 26 | _pin: PeripheralRef<'d, AnyPin>, | 24 | _pin: Peri<'d, AnyPin>, |
| 27 | role: PinType, | 25 | role: PinType, |
| 28 | tsc_io_pin: IOPin, | 26 | tsc_io_pin: IOPin, |
| 29 | phantom: PhantomData<(T, Group)>, | 27 | phantom: PhantomData<(T, Group)>, |
| @@ -426,17 +424,13 @@ macro_rules! trait_to_io_pin { | |||
| 426 | macro_rules! impl_set_io { | 424 | macro_rules! impl_set_io { |
| 427 | ($method:ident, $group:ident, $trait:ident, $index:expr) => { | 425 | ($method:ident, $group:ident, $trait:ident, $index:expr) => { |
| 428 | #[doc = concat!("Create a new pin1 for ", stringify!($group), " TSC group instance.")] | 426 | #[doc = concat!("Create a new pin1 for ", stringify!($group), " TSC group instance.")] |
| 429 | pub fn $method<Role: pin_roles::Role>( | 427 | pub fn $method<Role: pin_roles::Role>(&mut self, pin: Peri<'d, impl $trait<T>>) -> IOPinWithRole<$group, Role> { |
| 430 | &mut self, | ||
| 431 | pin: impl Peripheral<P = impl $trait<T>> + 'd, | ||
| 432 | ) -> IOPinWithRole<$group, Role> { | ||
| 433 | into_ref!(pin); | ||
| 434 | critical_section::with(|_| { | 428 | critical_section::with(|_| { |
| 435 | pin.set_low(); | 429 | pin.set_low(); |
| 436 | pin.set_as_af(pin.af_num(), AfType::output(Role::output_type(), Speed::VeryHigh)); | 430 | pin.set_as_af(pin.af_num(), AfType::output(Role::output_type(), Speed::VeryHigh)); |
| 437 | let tsc_io_pin = trait_to_io_pin!($trait); | 431 | let tsc_io_pin = trait_to_io_pin!($trait); |
| 438 | let new_pin = Pin { | 432 | let new_pin = Pin { |
| 439 | _pin: pin.map_into(), | 433 | _pin: pin.into(), |
| 440 | role: Role::pin_type(), | 434 | role: Role::pin_type(), |
| 441 | tsc_io_pin, | 435 | tsc_io_pin, |
| 442 | phantom: PhantomData, | 436 | phantom: PhantomData, |
diff --git a/embassy-stm32/src/tsc/tsc.rs b/embassy-stm32/src/tsc/tsc.rs index 17d2da82f..e92479c26 100644 --- a/embassy-stm32/src/tsc/tsc.rs +++ b/embassy-stm32/src/tsc/tsc.rs | |||
| @@ -3,7 +3,7 @@ use core::marker::PhantomData; | |||
| 3 | use core::ops::BitOr; | 3 | use core::ops::BitOr; |
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | 5 | ||
| 6 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 6 | use embassy_hal_internal::Peri; |
| 7 | 7 | ||
| 8 | use super::acquisition_banks::*; | 8 | use super::acquisition_banks::*; |
| 9 | use super::config::*; | 9 | use super::config::*; |
| @@ -14,7 +14,7 @@ use super::types::*; | |||
| 14 | use super::{Instance, InterruptHandler, TSC_NUM_GROUPS}; | 14 | use super::{Instance, InterruptHandler, TSC_NUM_GROUPS}; |
| 15 | use crate::interrupt::typelevel::Interrupt; | 15 | use crate::interrupt::typelevel::Interrupt; |
| 16 | use crate::mode::{Async, Blocking, Mode as PeriMode}; | 16 | use crate::mode::{Async, Blocking, Mode as PeriMode}; |
| 17 | use crate::{interrupt, rcc, Peripheral}; | 17 | use crate::{interrupt, rcc}; |
| 18 | 18 | ||
| 19 | /// Internal structure holding masks for different types of TSC IOs. | 19 | /// Internal structure holding masks for different types of TSC IOs. |
| 20 | /// | 20 | /// |
| @@ -31,7 +31,7 @@ struct IOMasks { | |||
| 31 | 31 | ||
| 32 | /// TSC driver | 32 | /// TSC driver |
| 33 | pub struct Tsc<'d, T: Instance, K: PeriMode> { | 33 | pub struct Tsc<'d, T: Instance, K: PeriMode> { |
| 34 | _peri: PeripheralRef<'d, T>, | 34 | _peri: Peri<'d, T>, |
| 35 | _pin_groups: PinGroups<'d, T>, | 35 | _pin_groups: PinGroups<'d, T>, |
| 36 | state: State, | 36 | state: State, |
| 37 | config: Config, | 37 | config: Config, |
| @@ -218,13 +218,7 @@ impl<'d, T: Instance, K: PeriMode> Tsc<'d, T, K> { | |||
| 218 | groups | 218 | groups |
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | fn new_inner( | 221 | fn new_inner(peri: Peri<'d, T>, pin_groups: PinGroups<'d, T>, config: Config) -> Result<Self, GroupError> { |
| 222 | peri: impl Peripheral<P = T> + 'd, | ||
| 223 | pin_groups: PinGroups<'d, T>, | ||
| 224 | config: Config, | ||
| 225 | ) -> Result<Self, GroupError> { | ||
| 226 | into_ref!(peri); | ||
| 227 | |||
| 228 | pin_groups.check()?; | 222 | pin_groups.check()?; |
| 229 | 223 | ||
| 230 | let masks = IOMasks { | 224 | let masks = IOMasks { |
| @@ -410,7 +404,7 @@ impl<'d, T: Instance, K: PeriMode> Drop for Tsc<'d, T, K> { | |||
| 410 | impl<'d, T: Instance> Tsc<'d, T, Async> { | 404 | impl<'d, T: Instance> Tsc<'d, T, Async> { |
| 411 | /// Create a Tsc instance that can be awaited for completion | 405 | /// Create a Tsc instance that can be awaited for completion |
| 412 | pub fn new_async( | 406 | pub fn new_async( |
| 413 | peri: impl Peripheral<P = T> + 'd, | 407 | peri: Peri<'d, T>, |
| 414 | pin_groups: PinGroups<'d, T>, | 408 | pin_groups: PinGroups<'d, T>, |
| 415 | config: Config, | 409 | config: Config, |
| 416 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 410 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| @@ -441,11 +435,7 @@ impl<'d, T: Instance> Tsc<'d, T, Async> { | |||
| 441 | 435 | ||
| 442 | impl<'d, T: Instance> Tsc<'d, T, Blocking> { | 436 | impl<'d, T: Instance> Tsc<'d, T, Blocking> { |
| 443 | /// Create a Tsc instance that must be polled for completion | 437 | /// Create a Tsc instance that must be polled for completion |
| 444 | pub fn new_blocking( | 438 | pub fn new_blocking(peri: Peri<'d, T>, pin_groups: PinGroups<'d, T>, config: Config) -> Result<Self, GroupError> { |
| 445 | peri: impl Peripheral<P = T> + 'd, | ||
| 446 | pin_groups: PinGroups<'d, T>, | ||
| 447 | config: Config, | ||
| 448 | ) -> Result<Self, GroupError> { | ||
| 449 | Self::new_inner(peri, pin_groups, config) | 439 | Self::new_inner(peri, pin_groups, config) |
| 450 | } | 440 | } |
| 451 | 441 | ||
diff --git a/embassy-stm32/src/ucpd.rs b/embassy-stm32/src/ucpd.rs index c40ee8ad0..87693f148 100644 --- a/embassy-stm32/src/ucpd.rs +++ b/embassy-stm32/src/ucpd.rs | |||
| @@ -20,15 +20,15 @@ use core::sync::atomic::{AtomicBool, Ordering}; | |||
| 20 | use core::task::Poll; | 20 | use core::task::Poll; |
| 21 | 21 | ||
| 22 | use embassy_hal_internal::drop::OnDrop; | 22 | use embassy_hal_internal::drop::OnDrop; |
| 23 | use embassy_hal_internal::{into_ref, Peripheral}; | 23 | use embassy_hal_internal::PeripheralType; |
| 24 | use embassy_sync::waitqueue::AtomicWaker; | 24 | use embassy_sync::waitqueue::AtomicWaker; |
| 25 | 25 | ||
| 26 | use crate::dma::{ChannelAndRequest, TransferOptions}; | 26 | use crate::dma::{ChannelAndRequest, TransferOptions}; |
| 27 | use crate::interrupt; | ||
| 28 | use crate::interrupt::typelevel::Interrupt; | 27 | use crate::interrupt::typelevel::Interrupt; |
| 29 | use crate::pac::ucpd::vals::{Anamode, Ccenable, PscUsbpdclk, Txmode}; | 28 | use crate::pac::ucpd::vals::{Anamode, Ccenable, PscUsbpdclk, Txmode}; |
| 30 | pub use crate::pac::ucpd::vals::{Phyccsel as CcSel, Rxordset, TypecVstateCc as CcVState}; | 29 | pub use crate::pac::ucpd::vals::{Phyccsel as CcSel, Rxordset, TypecVstateCc as CcVState}; |
| 31 | use crate::rcc::{self, RccPeripheral}; | 30 | use crate::rcc::{self, RccPeripheral}; |
| 31 | use crate::{interrupt, Peri}; | ||
| 32 | 32 | ||
| 33 | pub(crate) fn init( | 33 | pub(crate) fn init( |
| 34 | _cs: critical_section::CriticalSection, | 34 | _cs: critical_section::CriticalSection, |
| @@ -122,13 +122,12 @@ pub struct Ucpd<'d, T: Instance> { | |||
| 122 | impl<'d, T: Instance> Ucpd<'d, T> { | 122 | impl<'d, T: Instance> Ucpd<'d, T> { |
| 123 | /// Creates a new UCPD driver instance. | 123 | /// Creates a new UCPD driver instance. |
| 124 | pub fn new( | 124 | pub fn new( |
| 125 | _peri: impl Peripheral<P = T> + 'd, | 125 | _peri: Peri<'d, T>, |
| 126 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 126 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 127 | cc1: impl Peripheral<P = impl Cc1Pin<T>> + 'd, | 127 | cc1: Peri<'d, impl Cc1Pin<T>>, |
| 128 | cc2: impl Peripheral<P = impl Cc2Pin<T>> + 'd, | 128 | cc2: Peri<'d, impl Cc2Pin<T>>, |
| 129 | config: Config, | 129 | config: Config, |
| 130 | ) -> Self { | 130 | ) -> Self { |
| 131 | into_ref!(cc1, cc2); | ||
| 132 | cc1.set_as_analog(); | 131 | cc1.set_as_analog(); |
| 133 | cc2.set_as_analog(); | 132 | cc2.set_as_analog(); |
| 134 | 133 | ||
| @@ -208,8 +207,8 @@ impl<'d, T: Instance> Ucpd<'d, T> { | |||
| 208 | /// and a Power Delivery (PD) PHY with receiver and transmitter. | 207 | /// and a Power Delivery (PD) PHY with receiver and transmitter. |
| 209 | pub fn split_pd_phy( | 208 | pub fn split_pd_phy( |
| 210 | self, | 209 | self, |
| 211 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 210 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 212 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 211 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 213 | cc_sel: CcSel, | 212 | cc_sel: CcSel, |
| 214 | ) -> (CcPhy<'d, T>, PdPhy<'d, T>) { | 213 | ) -> (CcPhy<'d, T>, PdPhy<'d, T>) { |
| 215 | let r = T::REGS; | 214 | let r = T::REGS; |
| @@ -229,7 +228,6 @@ impl<'d, T: Instance> Ucpd<'d, T> { | |||
| 229 | // Both parts must be dropped before the peripheral can be disabled. | 228 | // Both parts must be dropped before the peripheral can be disabled. |
| 230 | T::state().drop_not_ready.store(true, Ordering::Relaxed); | 229 | T::state().drop_not_ready.store(true, Ordering::Relaxed); |
| 231 | 230 | ||
| 232 | into_ref!(rx_dma, tx_dma); | ||
| 233 | let rx_dma_req = rx_dma.request(); | 231 | let rx_dma_req = rx_dma.request(); |
| 234 | let tx_dma_req = tx_dma.request(); | 232 | let tx_dma_req = tx_dma.request(); |
| 235 | ( | 233 | ( |
| @@ -237,11 +235,11 @@ impl<'d, T: Instance> Ucpd<'d, T> { | |||
| 237 | PdPhy { | 235 | PdPhy { |
| 238 | _lifetime: PhantomData, | 236 | _lifetime: PhantomData, |
| 239 | rx_dma: ChannelAndRequest { | 237 | rx_dma: ChannelAndRequest { |
| 240 | channel: rx_dma.map_into(), | 238 | channel: rx_dma.into(), |
| 241 | request: rx_dma_req, | 239 | request: rx_dma_req, |
| 242 | }, | 240 | }, |
| 243 | tx_dma: ChannelAndRequest { | 241 | tx_dma: ChannelAndRequest { |
| 244 | channel: tx_dma.map_into(), | 242 | channel: tx_dma.into(), |
| 245 | request: tx_dma_req, | 243 | request: tx_dma_req, |
| 246 | }, | 244 | }, |
| 247 | }, | 245 | }, |
| @@ -689,7 +687,7 @@ trait SealedInstance { | |||
| 689 | 687 | ||
| 690 | /// UCPD instance trait. | 688 | /// UCPD instance trait. |
| 691 | #[allow(private_bounds)] | 689 | #[allow(private_bounds)] |
| 692 | pub trait Instance: SealedInstance + RccPeripheral { | 690 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral { |
| 693 | /// Interrupt for this instance. | 691 | /// Interrupt for this instance. |
| 694 | type Interrupt: crate::interrupt::typelevel::Interrupt; | 692 | type Interrupt: crate::interrupt::typelevel::Interrupt; |
| 695 | } | 693 | } |
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index 7fa9ee08e..b1640b6dc 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs | |||
| @@ -6,7 +6,7 @@ use core::task::Poll; | |||
| 6 | 6 | ||
| 7 | use embassy_embedded_hal::SetConfig; | 7 | use embassy_embedded_hal::SetConfig; |
| 8 | use embassy_hal_internal::atomic_ring_buffer::RingBuffer; | 8 | use embassy_hal_internal::atomic_ring_buffer::RingBuffer; |
| 9 | use embassy_hal_internal::{Peripheral, PeripheralRef}; | 9 | use embassy_hal_internal::Peri; |
| 10 | use embassy_sync::waitqueue::AtomicWaker; | 10 | use embassy_sync::waitqueue::AtomicWaker; |
| 11 | 11 | ||
| 12 | #[cfg(not(any(usart_v1, usart_v2)))] | 12 | #[cfg(not(any(usart_v1, usart_v2)))] |
| @@ -159,9 +159,9 @@ pub struct BufferedUartTx<'d> { | |||
| 159 | info: &'static Info, | 159 | info: &'static Info, |
| 160 | state: &'static State, | 160 | state: &'static State, |
| 161 | kernel_clock: Hertz, | 161 | kernel_clock: Hertz, |
| 162 | tx: Option<PeripheralRef<'d, AnyPin>>, | 162 | tx: Option<Peri<'d, AnyPin>>, |
| 163 | cts: Option<PeripheralRef<'d, AnyPin>>, | 163 | cts: Option<Peri<'d, AnyPin>>, |
| 164 | de: Option<PeripheralRef<'d, AnyPin>>, | 164 | de: Option<Peri<'d, AnyPin>>, |
| 165 | is_borrowed: bool, | 165 | is_borrowed: bool, |
| 166 | } | 166 | } |
| 167 | 167 | ||
| @@ -172,8 +172,8 @@ pub struct BufferedUartRx<'d> { | |||
| 172 | info: &'static Info, | 172 | info: &'static Info, |
| 173 | state: &'static State, | 173 | state: &'static State, |
| 174 | kernel_clock: Hertz, | 174 | kernel_clock: Hertz, |
| 175 | rx: Option<PeripheralRef<'d, AnyPin>>, | 175 | rx: Option<Peri<'d, AnyPin>>, |
| 176 | rts: Option<PeripheralRef<'d, AnyPin>>, | 176 | rts: Option<Peri<'d, AnyPin>>, |
| 177 | is_borrowed: bool, | 177 | is_borrowed: bool, |
| 178 | } | 178 | } |
| 179 | 179 | ||
| @@ -207,10 +207,10 @@ impl<'d> SetConfig for BufferedUartTx<'d> { | |||
| 207 | impl<'d> BufferedUart<'d> { | 207 | impl<'d> BufferedUart<'d> { |
| 208 | /// Create a new bidirectional buffered UART driver | 208 | /// Create a new bidirectional buffered UART driver |
| 209 | pub fn new<T: Instance>( | 209 | pub fn new<T: Instance>( |
| 210 | peri: impl Peripheral<P = T> + 'd, | 210 | peri: Peri<'d, T>, |
| 211 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 211 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 212 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 212 | rx: Peri<'d, impl RxPin<T>>, |
| 213 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 213 | tx: Peri<'d, impl TxPin<T>>, |
| 214 | tx_buffer: &'d mut [u8], | 214 | tx_buffer: &'d mut [u8], |
| 215 | rx_buffer: &'d mut [u8], | 215 | rx_buffer: &'d mut [u8], |
| 216 | config: Config, | 216 | config: Config, |
| @@ -230,12 +230,12 @@ impl<'d> BufferedUart<'d> { | |||
| 230 | 230 | ||
| 231 | /// Create a new bidirectional buffered UART driver with request-to-send and clear-to-send pins | 231 | /// Create a new bidirectional buffered UART driver with request-to-send and clear-to-send pins |
| 232 | pub fn new_with_rtscts<T: Instance>( | 232 | pub fn new_with_rtscts<T: Instance>( |
| 233 | peri: impl Peripheral<P = T> + 'd, | 233 | peri: Peri<'d, T>, |
| 234 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 234 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 235 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 235 | rx: Peri<'d, impl RxPin<T>>, |
| 236 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 236 | tx: Peri<'d, impl TxPin<T>>, |
| 237 | rts: impl Peripheral<P = impl RtsPin<T>> + 'd, | 237 | rts: Peri<'d, impl RtsPin<T>>, |
| 238 | cts: impl Peripheral<P = impl CtsPin<T>> + 'd, | 238 | cts: Peri<'d, impl CtsPin<T>>, |
| 239 | tx_buffer: &'d mut [u8], | 239 | tx_buffer: &'d mut [u8], |
| 240 | rx_buffer: &'d mut [u8], | 240 | rx_buffer: &'d mut [u8], |
| 241 | config: Config, | 241 | config: Config, |
| @@ -255,11 +255,11 @@ impl<'d> BufferedUart<'d> { | |||
| 255 | 255 | ||
| 256 | /// Create a new bidirectional buffered UART driver with only the RTS pin as the DE pin | 256 | /// Create a new bidirectional buffered UART driver with only the RTS pin as the DE pin |
| 257 | pub fn new_with_rts_as_de<T: Instance>( | 257 | pub fn new_with_rts_as_de<T: Instance>( |
| 258 | peri: impl Peripheral<P = T> + 'd, | 258 | peri: Peri<'d, T>, |
| 259 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 259 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 260 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 260 | rx: Peri<'d, impl RxPin<T>>, |
| 261 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 261 | tx: Peri<'d, impl TxPin<T>>, |
| 262 | rts: impl Peripheral<P = impl RtsPin<T>> + 'd, | 262 | rts: Peri<'d, impl RtsPin<T>>, |
| 263 | tx_buffer: &'d mut [u8], | 263 | tx_buffer: &'d mut [u8], |
| 264 | rx_buffer: &'d mut [u8], | 264 | rx_buffer: &'d mut [u8], |
| 265 | config: Config, | 265 | config: Config, |
| @@ -279,11 +279,11 @@ impl<'d> BufferedUart<'d> { | |||
| 279 | 279 | ||
| 280 | /// Create a new bidirectional buffered UART driver with only the request-to-send pin | 280 | /// Create a new bidirectional buffered UART driver with only the request-to-send pin |
| 281 | pub fn new_with_rts<T: Instance>( | 281 | pub fn new_with_rts<T: Instance>( |
| 282 | peri: impl Peripheral<P = T> + 'd, | 282 | peri: Peri<'d, T>, |
| 283 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 283 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 284 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 284 | rx: Peri<'d, impl RxPin<T>>, |
| 285 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 285 | tx: Peri<'d, impl TxPin<T>>, |
| 286 | rts: impl Peripheral<P = impl RtsPin<T>> + 'd, | 286 | rts: Peri<'d, impl RtsPin<T>>, |
| 287 | tx_buffer: &'d mut [u8], | 287 | tx_buffer: &'d mut [u8], |
| 288 | rx_buffer: &'d mut [u8], | 288 | rx_buffer: &'d mut [u8], |
| 289 | config: Config, | 289 | config: Config, |
| @@ -304,11 +304,11 @@ impl<'d> BufferedUart<'d> { | |||
| 304 | /// Create a new bidirectional buffered UART driver with a driver-enable pin | 304 | /// Create a new bidirectional buffered UART driver with a driver-enable pin |
| 305 | #[cfg(not(any(usart_v1, usart_v2)))] | 305 | #[cfg(not(any(usart_v1, usart_v2)))] |
| 306 | pub fn new_with_de<T: Instance>( | 306 | pub fn new_with_de<T: Instance>( |
| 307 | peri: impl Peripheral<P = T> + 'd, | 307 | peri: Peri<'d, T>, |
| 308 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 308 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 309 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 309 | rx: Peri<'d, impl RxPin<T>>, |
| 310 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 310 | tx: Peri<'d, impl TxPin<T>>, |
| 311 | de: impl Peripheral<P = impl DePin<T>> + 'd, | 311 | de: Peri<'d, impl DePin<T>>, |
| 312 | tx_buffer: &'d mut [u8], | 312 | tx_buffer: &'d mut [u8], |
| 313 | rx_buffer: &'d mut [u8], | 313 | rx_buffer: &'d mut [u8], |
| 314 | config: Config, | 314 | config: Config, |
| @@ -339,8 +339,8 @@ impl<'d> BufferedUart<'d> { | |||
| 339 | /// on the line must be managed by software (for instance by using a centralized arbiter). | 339 | /// on the line must be managed by software (for instance by using a centralized arbiter). |
| 340 | #[doc(alias("HDSEL"))] | 340 | #[doc(alias("HDSEL"))] |
| 341 | pub fn new_half_duplex<T: Instance>( | 341 | pub fn new_half_duplex<T: Instance>( |
| 342 | peri: impl Peripheral<P = T> + 'd, | 342 | peri: Peri<'d, T>, |
| 343 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 343 | tx: Peri<'d, impl TxPin<T>>, |
| 344 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 344 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 345 | tx_buffer: &'d mut [u8], | 345 | tx_buffer: &'d mut [u8], |
| 346 | rx_buffer: &'d mut [u8], | 346 | rx_buffer: &'d mut [u8], |
| @@ -379,8 +379,8 @@ impl<'d> BufferedUart<'d> { | |||
| 379 | #[cfg(not(any(usart_v1, usart_v2)))] | 379 | #[cfg(not(any(usart_v1, usart_v2)))] |
| 380 | #[doc(alias("HDSEL"))] | 380 | #[doc(alias("HDSEL"))] |
| 381 | pub fn new_half_duplex_on_rx<T: Instance>( | 381 | pub fn new_half_duplex_on_rx<T: Instance>( |
| 382 | peri: impl Peripheral<P = T> + 'd, | 382 | peri: Peri<'d, T>, |
| 383 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 383 | rx: Peri<'d, impl RxPin<T>>, |
| 384 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 384 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 385 | tx_buffer: &'d mut [u8], | 385 | tx_buffer: &'d mut [u8], |
| 386 | rx_buffer: &'d mut [u8], | 386 | rx_buffer: &'d mut [u8], |
| @@ -405,12 +405,12 @@ impl<'d> BufferedUart<'d> { | |||
| 405 | } | 405 | } |
| 406 | 406 | ||
| 407 | fn new_inner<T: Instance>( | 407 | fn new_inner<T: Instance>( |
| 408 | _peri: impl Peripheral<P = T> + 'd, | 408 | _peri: Peri<'d, T>, |
| 409 | rx: Option<PeripheralRef<'d, AnyPin>>, | 409 | rx: Option<Peri<'d, AnyPin>>, |
| 410 | tx: Option<PeripheralRef<'d, AnyPin>>, | 410 | tx: Option<Peri<'d, AnyPin>>, |
| 411 | rts: Option<PeripheralRef<'d, AnyPin>>, | 411 | rts: Option<Peri<'d, AnyPin>>, |
| 412 | cts: Option<PeripheralRef<'d, AnyPin>>, | 412 | cts: Option<Peri<'d, AnyPin>>, |
| 413 | de: Option<PeripheralRef<'d, AnyPin>>, | 413 | de: Option<Peri<'d, AnyPin>>, |
| 414 | tx_buffer: &'d mut [u8], | 414 | tx_buffer: &'d mut [u8], |
| 415 | rx_buffer: &'d mut [u8], | 415 | rx_buffer: &'d mut [u8], |
| 416 | config: Config, | 416 | config: Config, |
| @@ -505,17 +505,17 @@ impl<'d> BufferedUart<'d> { | |||
| 505 | info: self.tx.info, | 505 | info: self.tx.info, |
| 506 | state: self.tx.state, | 506 | state: self.tx.state, |
| 507 | kernel_clock: self.tx.kernel_clock, | 507 | kernel_clock: self.tx.kernel_clock, |
| 508 | tx: self.tx.tx.as_mut().map(PeripheralRef::reborrow), | 508 | tx: self.tx.tx.as_mut().map(Peri::reborrow), |
| 509 | cts: self.tx.cts.as_mut().map(PeripheralRef::reborrow), | 509 | cts: self.tx.cts.as_mut().map(Peri::reborrow), |
| 510 | de: self.tx.de.as_mut().map(PeripheralRef::reborrow), | 510 | de: self.tx.de.as_mut().map(Peri::reborrow), |
| 511 | is_borrowed: true, | 511 | is_borrowed: true, |
| 512 | }, | 512 | }, |
| 513 | BufferedUartRx { | 513 | BufferedUartRx { |
| 514 | info: self.rx.info, | 514 | info: self.rx.info, |
| 515 | state: self.rx.state, | 515 | state: self.rx.state, |
| 516 | kernel_clock: self.rx.kernel_clock, | 516 | kernel_clock: self.rx.kernel_clock, |
| 517 | rx: self.rx.rx.as_mut().map(PeripheralRef::reborrow), | 517 | rx: self.rx.rx.as_mut().map(Peri::reborrow), |
| 518 | rts: self.rx.rts.as_mut().map(PeripheralRef::reborrow), | 518 | rts: self.rx.rts.as_mut().map(Peri::reborrow), |
| 519 | is_borrowed: true, | 519 | is_borrowed: true, |
| 520 | }, | 520 | }, |
| 521 | ) | 521 | ) |
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 568067360..675e90c7f 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -9,7 +9,7 @@ use core::task::Poll; | |||
| 9 | 9 | ||
| 10 | use embassy_embedded_hal::SetConfig; | 10 | use embassy_embedded_hal::SetConfig; |
| 11 | use embassy_hal_internal::drop::OnDrop; | 11 | use embassy_hal_internal::drop::OnDrop; |
| 12 | use embassy_hal_internal::PeripheralRef; | 12 | use embassy_hal_internal::PeripheralType; |
| 13 | use embassy_sync::waitqueue::AtomicWaker; | 13 | use embassy_sync::waitqueue::AtomicWaker; |
| 14 | use futures_util::future::{select, Either}; | 14 | use futures_util::future::{select, Either}; |
| 15 | 15 | ||
| @@ -30,7 +30,7 @@ use crate::pac::usart::Usart as Regs; | |||
| 30 | use crate::pac::usart::{regs, vals}; | 30 | use crate::pac::usart::{regs, vals}; |
| 31 | use crate::rcc::{RccInfo, SealedRccPeripheral}; | 31 | use crate::rcc::{RccInfo, SealedRccPeripheral}; |
| 32 | use crate::time::Hertz; | 32 | use crate::time::Hertz; |
| 33 | use crate::Peripheral; | 33 | use crate::Peri; |
| 34 | 34 | ||
| 35 | /// Interrupt handler. | 35 | /// Interrupt handler. |
| 36 | pub struct InterruptHandler<T: Instance> { | 36 | pub struct InterruptHandler<T: Instance> { |
| @@ -348,9 +348,9 @@ pub struct UartTx<'d, M: Mode> { | |||
| 348 | info: &'static Info, | 348 | info: &'static Info, |
| 349 | state: &'static State, | 349 | state: &'static State, |
| 350 | kernel_clock: Hertz, | 350 | kernel_clock: Hertz, |
| 351 | tx: Option<PeripheralRef<'d, AnyPin>>, | 351 | tx: Option<Peri<'d, AnyPin>>, |
| 352 | cts: Option<PeripheralRef<'d, AnyPin>>, | 352 | cts: Option<Peri<'d, AnyPin>>, |
| 353 | de: Option<PeripheralRef<'d, AnyPin>>, | 353 | de: Option<Peri<'d, AnyPin>>, |
| 354 | tx_dma: Option<ChannelAndRequest<'d>>, | 354 | tx_dma: Option<ChannelAndRequest<'d>>, |
| 355 | duplex: Duplex, | 355 | duplex: Duplex, |
| 356 | _phantom: PhantomData<M>, | 356 | _phantom: PhantomData<M>, |
| @@ -398,8 +398,8 @@ pub struct UartRx<'d, M: Mode> { | |||
| 398 | info: &'static Info, | 398 | info: &'static Info, |
| 399 | state: &'static State, | 399 | state: &'static State, |
| 400 | kernel_clock: Hertz, | 400 | kernel_clock: Hertz, |
| 401 | rx: Option<PeripheralRef<'d, AnyPin>>, | 401 | rx: Option<Peri<'d, AnyPin>>, |
| 402 | rts: Option<PeripheralRef<'d, AnyPin>>, | 402 | rts: Option<Peri<'d, AnyPin>>, |
| 403 | rx_dma: Option<ChannelAndRequest<'d>>, | 403 | rx_dma: Option<ChannelAndRequest<'d>>, |
| 404 | detect_previous_overrun: bool, | 404 | detect_previous_overrun: bool, |
| 405 | #[cfg(any(usart_v1, usart_v2))] | 405 | #[cfg(any(usart_v1, usart_v2))] |
| @@ -419,9 +419,9 @@ impl<'d, M: Mode> SetConfig for UartRx<'d, M> { | |||
| 419 | impl<'d> UartTx<'d, Async> { | 419 | impl<'d> UartTx<'d, Async> { |
| 420 | /// Useful if you only want Uart Tx. It saves 1 pin and consumes a little less power. | 420 | /// Useful if you only want Uart Tx. It saves 1 pin and consumes a little less power. |
| 421 | pub fn new<T: Instance>( | 421 | pub fn new<T: Instance>( |
| 422 | peri: impl Peripheral<P = T> + 'd, | 422 | peri: Peri<'d, T>, |
| 423 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 423 | tx: Peri<'d, impl TxPin<T>>, |
| 424 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 424 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 425 | config: Config, | 425 | config: Config, |
| 426 | ) -> Result<Self, ConfigError> { | 426 | ) -> Result<Self, ConfigError> { |
| 427 | Self::new_inner( | 427 | Self::new_inner( |
| @@ -435,10 +435,10 @@ impl<'d> UartTx<'d, Async> { | |||
| 435 | 435 | ||
| 436 | /// Create a new tx-only UART with a clear-to-send pin | 436 | /// Create a new tx-only UART with a clear-to-send pin |
| 437 | pub fn new_with_cts<T: Instance>( | 437 | pub fn new_with_cts<T: Instance>( |
| 438 | peri: impl Peripheral<P = T> + 'd, | 438 | peri: Peri<'d, T>, |
| 439 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 439 | tx: Peri<'d, impl TxPin<T>>, |
| 440 | cts: impl Peripheral<P = impl CtsPin<T>> + 'd, | 440 | cts: Peri<'d, impl CtsPin<T>>, |
| 441 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 441 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 442 | config: Config, | 442 | config: Config, |
| 443 | ) -> Result<Self, ConfigError> { | 443 | ) -> Result<Self, ConfigError> { |
| 444 | Self::new_inner( | 444 | Self::new_inner( |
| @@ -478,8 +478,8 @@ impl<'d> UartTx<'d, Blocking> { | |||
| 478 | /// | 478 | /// |
| 479 | /// Useful if you only want Uart Tx. It saves 1 pin and consumes a little less power. | 479 | /// Useful if you only want Uart Tx. It saves 1 pin and consumes a little less power. |
| 480 | pub fn new_blocking<T: Instance>( | 480 | pub fn new_blocking<T: Instance>( |
| 481 | peri: impl Peripheral<P = T> + 'd, | 481 | peri: Peri<'d, T>, |
| 482 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 482 | tx: Peri<'d, impl TxPin<T>>, |
| 483 | config: Config, | 483 | config: Config, |
| 484 | ) -> Result<Self, ConfigError> { | 484 | ) -> Result<Self, ConfigError> { |
| 485 | Self::new_inner( | 485 | Self::new_inner( |
| @@ -493,9 +493,9 @@ impl<'d> UartTx<'d, Blocking> { | |||
| 493 | 493 | ||
| 494 | /// Create a new blocking tx-only UART with a clear-to-send pin | 494 | /// Create a new blocking tx-only UART with a clear-to-send pin |
| 495 | pub fn new_blocking_with_cts<T: Instance>( | 495 | pub fn new_blocking_with_cts<T: Instance>( |
| 496 | peri: impl Peripheral<P = T> + 'd, | 496 | peri: Peri<'d, T>, |
| 497 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 497 | tx: Peri<'d, impl TxPin<T>>, |
| 498 | cts: impl Peripheral<P = impl CtsPin<T>> + 'd, | 498 | cts: Peri<'d, impl CtsPin<T>>, |
| 499 | config: Config, | 499 | config: Config, |
| 500 | ) -> Result<Self, ConfigError> { | 500 | ) -> Result<Self, ConfigError> { |
| 501 | Self::new_inner( | 501 | Self::new_inner( |
| @@ -510,9 +510,9 @@ impl<'d> UartTx<'d, Blocking> { | |||
| 510 | 510 | ||
| 511 | impl<'d, M: Mode> UartTx<'d, M> { | 511 | impl<'d, M: Mode> UartTx<'d, M> { |
| 512 | fn new_inner<T: Instance>( | 512 | fn new_inner<T: Instance>( |
| 513 | _peri: impl Peripheral<P = T> + 'd, | 513 | _peri: Peri<'d, T>, |
| 514 | tx: Option<PeripheralRef<'d, AnyPin>>, | 514 | tx: Option<Peri<'d, AnyPin>>, |
| 515 | cts: Option<PeripheralRef<'d, AnyPin>>, | 515 | cts: Option<Peri<'d, AnyPin>>, |
| 516 | tx_dma: Option<ChannelAndRequest<'d>>, | 516 | tx_dma: Option<ChannelAndRequest<'d>>, |
| 517 | config: Config, | 517 | config: Config, |
| 518 | ) -> Result<Self, ConfigError> { | 518 | ) -> Result<Self, ConfigError> { |
| @@ -650,10 +650,10 @@ impl<'d> UartRx<'d, Async> { | |||
| 650 | /// | 650 | /// |
| 651 | /// Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power. | 651 | /// Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power. |
| 652 | pub fn new<T: Instance>( | 652 | pub fn new<T: Instance>( |
| 653 | peri: impl Peripheral<P = T> + 'd, | 653 | peri: Peri<'d, T>, |
| 654 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 654 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 655 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 655 | rx: Peri<'d, impl RxPin<T>>, |
| 656 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 656 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 657 | config: Config, | 657 | config: Config, |
| 658 | ) -> Result<Self, ConfigError> { | 658 | ) -> Result<Self, ConfigError> { |
| 659 | Self::new_inner( | 659 | Self::new_inner( |
| @@ -667,11 +667,11 @@ impl<'d> UartRx<'d, Async> { | |||
| 667 | 667 | ||
| 668 | /// Create a new rx-only UART with a request-to-send pin | 668 | /// Create a new rx-only UART with a request-to-send pin |
| 669 | pub fn new_with_rts<T: Instance>( | 669 | pub fn new_with_rts<T: Instance>( |
| 670 | peri: impl Peripheral<P = T> + 'd, | 670 | peri: Peri<'d, T>, |
| 671 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 671 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 672 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 672 | rx: Peri<'d, impl RxPin<T>>, |
| 673 | rts: impl Peripheral<P = impl RtsPin<T>> + 'd, | 673 | rts: Peri<'d, impl RtsPin<T>>, |
| 674 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 674 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 675 | config: Config, | 675 | config: Config, |
| 676 | ) -> Result<Self, ConfigError> { | 676 | ) -> Result<Self, ConfigError> { |
| 677 | Self::new_inner( | 677 | Self::new_inner( |
| @@ -908,8 +908,8 @@ impl<'d> UartRx<'d, Blocking> { | |||
| 908 | /// | 908 | /// |
| 909 | /// Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power. | 909 | /// Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power. |
| 910 | pub fn new_blocking<T: Instance>( | 910 | pub fn new_blocking<T: Instance>( |
| 911 | peri: impl Peripheral<P = T> + 'd, | 911 | peri: Peri<'d, T>, |
| 912 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 912 | rx: Peri<'d, impl RxPin<T>>, |
| 913 | config: Config, | 913 | config: Config, |
| 914 | ) -> Result<Self, ConfigError> { | 914 | ) -> Result<Self, ConfigError> { |
| 915 | Self::new_inner(peri, new_pin!(rx, AfType::input(config.rx_pull)), None, None, config) | 915 | Self::new_inner(peri, new_pin!(rx, AfType::input(config.rx_pull)), None, None, config) |
| @@ -917,9 +917,9 @@ impl<'d> UartRx<'d, Blocking> { | |||
| 917 | 917 | ||
| 918 | /// Create a new rx-only UART with a request-to-send pin | 918 | /// Create a new rx-only UART with a request-to-send pin |
| 919 | pub fn new_blocking_with_rts<T: Instance>( | 919 | pub fn new_blocking_with_rts<T: Instance>( |
| 920 | peri: impl Peripheral<P = T> + 'd, | 920 | peri: Peri<'d, T>, |
| 921 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 921 | rx: Peri<'d, impl RxPin<T>>, |
| 922 | rts: impl Peripheral<P = impl RtsPin<T>> + 'd, | 922 | rts: Peri<'d, impl RtsPin<T>>, |
| 923 | config: Config, | 923 | config: Config, |
| 924 | ) -> Result<Self, ConfigError> { | 924 | ) -> Result<Self, ConfigError> { |
| 925 | Self::new_inner( | 925 | Self::new_inner( |
| @@ -934,9 +934,9 @@ impl<'d> UartRx<'d, Blocking> { | |||
| 934 | 934 | ||
| 935 | impl<'d, M: Mode> UartRx<'d, M> { | 935 | impl<'d, M: Mode> UartRx<'d, M> { |
| 936 | fn new_inner<T: Instance>( | 936 | fn new_inner<T: Instance>( |
| 937 | _peri: impl Peripheral<P = T> + 'd, | 937 | _peri: Peri<'d, T>, |
| 938 | rx: Option<PeripheralRef<'d, AnyPin>>, | 938 | rx: Option<Peri<'d, AnyPin>>, |
| 939 | rts: Option<PeripheralRef<'d, AnyPin>>, | 939 | rts: Option<Peri<'d, AnyPin>>, |
| 940 | rx_dma: Option<ChannelAndRequest<'d>>, | 940 | rx_dma: Option<ChannelAndRequest<'d>>, |
| 941 | config: Config, | 941 | config: Config, |
| 942 | ) -> Result<Self, ConfigError> { | 942 | ) -> Result<Self, ConfigError> { |
| @@ -1104,12 +1104,12 @@ fn drop_tx_rx(info: &Info, state: &State) { | |||
| 1104 | impl<'d> Uart<'d, Async> { | 1104 | impl<'d> Uart<'d, Async> { |
| 1105 | /// Create a new bidirectional UART | 1105 | /// Create a new bidirectional UART |
| 1106 | pub fn new<T: Instance>( | 1106 | pub fn new<T: Instance>( |
| 1107 | peri: impl Peripheral<P = T> + 'd, | 1107 | peri: Peri<'d, T>, |
| 1108 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 1108 | rx: Peri<'d, impl RxPin<T>>, |
| 1109 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 1109 | tx: Peri<'d, impl TxPin<T>>, |
| 1110 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 1110 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 1111 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 1111 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 1112 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 1112 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 1113 | config: Config, | 1113 | config: Config, |
| 1114 | ) -> Result<Self, ConfigError> { | 1114 | ) -> Result<Self, ConfigError> { |
| 1115 | Self::new_inner( | 1115 | Self::new_inner( |
| @@ -1127,14 +1127,14 @@ impl<'d> Uart<'d, Async> { | |||
| 1127 | 1127 | ||
| 1128 | /// Create a new bidirectional UART with request-to-send and clear-to-send pins | 1128 | /// Create a new bidirectional UART with request-to-send and clear-to-send pins |
| 1129 | pub fn new_with_rtscts<T: Instance>( | 1129 | pub fn new_with_rtscts<T: Instance>( |
| 1130 | peri: impl Peripheral<P = T> + 'd, | 1130 | peri: Peri<'d, T>, |
| 1131 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 1131 | rx: Peri<'d, impl RxPin<T>>, |
| 1132 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 1132 | tx: Peri<'d, impl TxPin<T>>, |
| 1133 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 1133 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 1134 | rts: impl Peripheral<P = impl RtsPin<T>> + 'd, | 1134 | rts: Peri<'d, impl RtsPin<T>>, |
| 1135 | cts: impl Peripheral<P = impl CtsPin<T>> + 'd, | 1135 | cts: Peri<'d, impl CtsPin<T>>, |
| 1136 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 1136 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 1137 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 1137 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 1138 | config: Config, | 1138 | config: Config, |
| 1139 | ) -> Result<Self, ConfigError> { | 1139 | ) -> Result<Self, ConfigError> { |
| 1140 | Self::new_inner( | 1140 | Self::new_inner( |
| @@ -1153,13 +1153,13 @@ impl<'d> Uart<'d, Async> { | |||
| 1153 | #[cfg(not(any(usart_v1, usart_v2)))] | 1153 | #[cfg(not(any(usart_v1, usart_v2)))] |
| 1154 | /// Create a new bidirectional UART with a driver-enable pin | 1154 | /// Create a new bidirectional UART with a driver-enable pin |
| 1155 | pub fn new_with_de<T: Instance>( | 1155 | pub fn new_with_de<T: Instance>( |
| 1156 | peri: impl Peripheral<P = T> + 'd, | 1156 | peri: Peri<'d, T>, |
| 1157 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 1157 | rx: Peri<'d, impl RxPin<T>>, |
| 1158 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 1158 | tx: Peri<'d, impl TxPin<T>>, |
| 1159 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 1159 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 1160 | de: impl Peripheral<P = impl DePin<T>> + 'd, | 1160 | de: Peri<'d, impl DePin<T>>, |
| 1161 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 1161 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 1162 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 1162 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 1163 | config: Config, | 1163 | config: Config, |
| 1164 | ) -> Result<Self, ConfigError> { | 1164 | ) -> Result<Self, ConfigError> { |
| 1165 | Self::new_inner( | 1165 | Self::new_inner( |
| @@ -1188,11 +1188,11 @@ impl<'d> Uart<'d, Async> { | |||
| 1188 | /// on the line must be managed by software (for instance by using a centralized arbiter). | 1188 | /// on the line must be managed by software (for instance by using a centralized arbiter). |
| 1189 | #[doc(alias("HDSEL"))] | 1189 | #[doc(alias("HDSEL"))] |
| 1190 | pub fn new_half_duplex<T: Instance>( | 1190 | pub fn new_half_duplex<T: Instance>( |
| 1191 | peri: impl Peripheral<P = T> + 'd, | 1191 | peri: Peri<'d, T>, |
| 1192 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 1192 | tx: Peri<'d, impl TxPin<T>>, |
| 1193 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 1193 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 1194 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 1194 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 1195 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 1195 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 1196 | mut config: Config, | 1196 | mut config: Config, |
| 1197 | readback: HalfDuplexReadback, | 1197 | readback: HalfDuplexReadback, |
| 1198 | half_duplex: HalfDuplexConfig, | 1198 | half_duplex: HalfDuplexConfig, |
| @@ -1228,11 +1228,11 @@ impl<'d> Uart<'d, Async> { | |||
| 1228 | #[cfg(not(any(usart_v1, usart_v2)))] | 1228 | #[cfg(not(any(usart_v1, usart_v2)))] |
| 1229 | #[doc(alias("HDSEL"))] | 1229 | #[doc(alias("HDSEL"))] |
| 1230 | pub fn new_half_duplex_on_rx<T: Instance>( | 1230 | pub fn new_half_duplex_on_rx<T: Instance>( |
| 1231 | peri: impl Peripheral<P = T> + 'd, | 1231 | peri: Peri<'d, T>, |
| 1232 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 1232 | rx: Peri<'d, impl RxPin<T>>, |
| 1233 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 1233 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 1234 | tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, | 1234 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 1235 | rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, | 1235 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 1236 | mut config: Config, | 1236 | mut config: Config, |
| 1237 | readback: HalfDuplexReadback, | 1237 | readback: HalfDuplexReadback, |
| 1238 | half_duplex: HalfDuplexConfig, | 1238 | half_duplex: HalfDuplexConfig, |
| @@ -1277,9 +1277,9 @@ impl<'d> Uart<'d, Async> { | |||
| 1277 | impl<'d> Uart<'d, Blocking> { | 1277 | impl<'d> Uart<'d, Blocking> { |
| 1278 | /// Create a new blocking bidirectional UART. | 1278 | /// Create a new blocking bidirectional UART. |
| 1279 | pub fn new_blocking<T: Instance>( | 1279 | pub fn new_blocking<T: Instance>( |
| 1280 | peri: impl Peripheral<P = T> + 'd, | 1280 | peri: Peri<'d, T>, |
| 1281 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 1281 | rx: Peri<'d, impl RxPin<T>>, |
| 1282 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 1282 | tx: Peri<'d, impl TxPin<T>>, |
| 1283 | config: Config, | 1283 | config: Config, |
| 1284 | ) -> Result<Self, ConfigError> { | 1284 | ) -> Result<Self, ConfigError> { |
| 1285 | Self::new_inner( | 1285 | Self::new_inner( |
| @@ -1297,11 +1297,11 @@ impl<'d> Uart<'d, Blocking> { | |||
| 1297 | 1297 | ||
| 1298 | /// Create a new bidirectional UART with request-to-send and clear-to-send pins | 1298 | /// Create a new bidirectional UART with request-to-send and clear-to-send pins |
| 1299 | pub fn new_blocking_with_rtscts<T: Instance>( | 1299 | pub fn new_blocking_with_rtscts<T: Instance>( |
| 1300 | peri: impl Peripheral<P = T> + 'd, | 1300 | peri: Peri<'d, T>, |
| 1301 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 1301 | rx: Peri<'d, impl RxPin<T>>, |
| 1302 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 1302 | tx: Peri<'d, impl TxPin<T>>, |
| 1303 | rts: impl Peripheral<P = impl RtsPin<T>> + 'd, | 1303 | rts: Peri<'d, impl RtsPin<T>>, |
| 1304 | cts: impl Peripheral<P = impl CtsPin<T>> + 'd, | 1304 | cts: Peri<'d, impl CtsPin<T>>, |
| 1305 | config: Config, | 1305 | config: Config, |
| 1306 | ) -> Result<Self, ConfigError> { | 1306 | ) -> Result<Self, ConfigError> { |
| 1307 | Self::new_inner( | 1307 | Self::new_inner( |
| @@ -1320,10 +1320,10 @@ impl<'d> Uart<'d, Blocking> { | |||
| 1320 | #[cfg(not(any(usart_v1, usart_v2)))] | 1320 | #[cfg(not(any(usart_v1, usart_v2)))] |
| 1321 | /// Create a new bidirectional UART with a driver-enable pin | 1321 | /// Create a new bidirectional UART with a driver-enable pin |
| 1322 | pub fn new_blocking_with_de<T: Instance>( | 1322 | pub fn new_blocking_with_de<T: Instance>( |
| 1323 | peri: impl Peripheral<P = T> + 'd, | 1323 | peri: Peri<'d, T>, |
| 1324 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 1324 | rx: Peri<'d, impl RxPin<T>>, |
| 1325 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 1325 | tx: Peri<'d, impl TxPin<T>>, |
| 1326 | de: impl Peripheral<P = impl DePin<T>> + 'd, | 1326 | de: Peri<'d, impl DePin<T>>, |
| 1327 | config: Config, | 1327 | config: Config, |
| 1328 | ) -> Result<Self, ConfigError> { | 1328 | ) -> Result<Self, ConfigError> { |
| 1329 | Self::new_inner( | 1329 | Self::new_inner( |
| @@ -1351,8 +1351,8 @@ impl<'d> Uart<'d, Blocking> { | |||
| 1351 | /// on the line must be managed by software (for instance by using a centralized arbiter). | 1351 | /// on the line must be managed by software (for instance by using a centralized arbiter). |
| 1352 | #[doc(alias("HDSEL"))] | 1352 | #[doc(alias("HDSEL"))] |
| 1353 | pub fn new_blocking_half_duplex<T: Instance>( | 1353 | pub fn new_blocking_half_duplex<T: Instance>( |
| 1354 | peri: impl Peripheral<P = T> + 'd, | 1354 | peri: Peri<'d, T>, |
| 1355 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | 1355 | tx: Peri<'d, impl TxPin<T>>, |
| 1356 | mut config: Config, | 1356 | mut config: Config, |
| 1357 | readback: HalfDuplexReadback, | 1357 | readback: HalfDuplexReadback, |
| 1358 | half_duplex: HalfDuplexConfig, | 1358 | half_duplex: HalfDuplexConfig, |
| @@ -1388,8 +1388,8 @@ impl<'d> Uart<'d, Blocking> { | |||
| 1388 | #[cfg(not(any(usart_v1, usart_v2)))] | 1388 | #[cfg(not(any(usart_v1, usart_v2)))] |
| 1389 | #[doc(alias("HDSEL"))] | 1389 | #[doc(alias("HDSEL"))] |
| 1390 | pub fn new_blocking_half_duplex_on_rx<T: Instance>( | 1390 | pub fn new_blocking_half_duplex_on_rx<T: Instance>( |
| 1391 | peri: impl Peripheral<P = T> + 'd, | 1391 | peri: Peri<'d, T>, |
| 1392 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | 1392 | rx: Peri<'d, impl RxPin<T>>, |
| 1393 | mut config: Config, | 1393 | mut config: Config, |
| 1394 | readback: HalfDuplexReadback, | 1394 | readback: HalfDuplexReadback, |
| 1395 | half_duplex: HalfDuplexConfig, | 1395 | half_duplex: HalfDuplexConfig, |
| @@ -1413,12 +1413,12 @@ impl<'d> Uart<'d, Blocking> { | |||
| 1413 | 1413 | ||
| 1414 | impl<'d, M: Mode> Uart<'d, M> { | 1414 | impl<'d, M: Mode> Uart<'d, M> { |
| 1415 | fn new_inner<T: Instance>( | 1415 | fn new_inner<T: Instance>( |
| 1416 | _peri: impl Peripheral<P = T> + 'd, | 1416 | _peri: Peri<'d, T>, |
| 1417 | rx: Option<PeripheralRef<'d, AnyPin>>, | 1417 | rx: Option<Peri<'d, AnyPin>>, |
| 1418 | tx: Option<PeripheralRef<'d, AnyPin>>, | 1418 | tx: Option<Peri<'d, AnyPin>>, |
| 1419 | rts: Option<PeripheralRef<'d, AnyPin>>, | 1419 | rts: Option<Peri<'d, AnyPin>>, |
| 1420 | cts: Option<PeripheralRef<'d, AnyPin>>, | 1420 | cts: Option<Peri<'d, AnyPin>>, |
| 1421 | de: Option<PeripheralRef<'d, AnyPin>>, | 1421 | de: Option<Peri<'d, AnyPin>>, |
| 1422 | tx_dma: Option<ChannelAndRequest<'d>>, | 1422 | tx_dma: Option<ChannelAndRequest<'d>>, |
| 1423 | rx_dma: Option<ChannelAndRequest<'d>>, | 1423 | rx_dma: Option<ChannelAndRequest<'d>>, |
| 1424 | config: Config, | 1424 | config: Config, |
| @@ -2050,7 +2050,7 @@ pub(crate) trait SealedInstance: crate::rcc::RccPeripheral { | |||
| 2050 | 2050 | ||
| 2051 | /// USART peripheral instance trait. | 2051 | /// USART peripheral instance trait. |
| 2052 | #[allow(private_bounds)] | 2052 | #[allow(private_bounds)] |
| 2053 | pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { | 2053 | pub trait Instance: SealedInstance + PeripheralType + 'static + Send { |
| 2054 | /// Interrupt for this peripheral. | 2054 | /// Interrupt for this peripheral. |
| 2055 | type Interrupt: interrupt::typelevel::Interrupt; | 2055 | type Interrupt: interrupt::typelevel::Interrupt; |
| 2056 | } | 2056 | } |
diff --git a/embassy-stm32/src/usart/ringbuffered.rs b/embassy-stm32/src/usart/ringbuffered.rs index ffd4ee544..600e72582 100644 --- a/embassy-stm32/src/usart/ringbuffered.rs +++ b/embassy-stm32/src/usart/ringbuffered.rs | |||
| @@ -4,7 +4,6 @@ use core::sync::atomic::{compiler_fence, Ordering}; | |||
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | 5 | ||
| 6 | use embassy_embedded_hal::SetConfig; | 6 | use embassy_embedded_hal::SetConfig; |
| 7 | use embassy_hal_internal::PeripheralRef; | ||
| 8 | use embedded_io_async::ReadReady; | 7 | use embedded_io_async::ReadReady; |
| 9 | use futures_util::future::{select, Either}; | 8 | use futures_util::future::{select, Either}; |
| 10 | 9 | ||
| @@ -18,6 +17,7 @@ use crate::mode::Async; | |||
| 18 | use crate::pac::usart::regs; | 17 | use crate::pac::usart::regs; |
| 19 | use crate::time::Hertz; | 18 | use crate::time::Hertz; |
| 20 | use crate::usart::{Regs, Sr}; | 19 | use crate::usart::{Regs, Sr}; |
| 20 | use crate::Peri; | ||
| 21 | 21 | ||
| 22 | /// Rx-only Ring-buffered UART Driver | 22 | /// Rx-only Ring-buffered UART Driver |
| 23 | /// | 23 | /// |
| @@ -26,8 +26,8 @@ pub struct RingBufferedUartRx<'d> { | |||
| 26 | info: &'static Info, | 26 | info: &'static Info, |
| 27 | state: &'static State, | 27 | state: &'static State, |
| 28 | kernel_clock: Hertz, | 28 | kernel_clock: Hertz, |
| 29 | rx: Option<PeripheralRef<'d, AnyPin>>, | 29 | rx: Option<Peri<'d, AnyPin>>, |
| 30 | rts: Option<PeripheralRef<'d, AnyPin>>, | 30 | rts: Option<Peri<'d, AnyPin>>, |
| 31 | ring_buf: ReadableRingBuffer<'d, u8>, | 31 | ring_buf: ReadableRingBuffer<'d, u8>, |
| 32 | } | 32 | } |
| 33 | 33 | ||
diff --git a/embassy-stm32/src/usb/otg.rs b/embassy-stm32/src/usb/otg.rs index d3c7978e4..51429b8cc 100644 --- a/embassy-stm32/src/usb/otg.rs +++ b/embassy-stm32/src/usb/otg.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy_hal_internal::{into_ref, Peripheral}; | 3 | use embassy_hal_internal::PeripheralType; |
| 4 | use embassy_usb_driver::{EndpointAddress, EndpointAllocError, EndpointType, Event, Unsupported}; | 4 | use embassy_usb_driver::{EndpointAddress, EndpointAllocError, EndpointType, Event, Unsupported}; |
| 5 | use embassy_usb_synopsys_otg::otg_v1::vals::Dspd; | 5 | use embassy_usb_synopsys_otg::otg_v1::vals::Dspd; |
| 6 | use embassy_usb_synopsys_otg::otg_v1::Otg; | 6 | use embassy_usb_synopsys_otg::otg_v1::Otg; |
| @@ -11,9 +11,9 @@ use embassy_usb_synopsys_otg::{ | |||
| 11 | }; | 11 | }; |
| 12 | 12 | ||
| 13 | use crate::gpio::{AfType, OutputType, Speed}; | 13 | use crate::gpio::{AfType, OutputType, Speed}; |
| 14 | use crate::interrupt; | ||
| 15 | use crate::interrupt::typelevel::Interrupt; | 14 | use crate::interrupt::typelevel::Interrupt; |
| 16 | use crate::rcc::{self, RccPeripheral}; | 15 | use crate::rcc::{self, RccPeripheral}; |
| 16 | use crate::{interrupt, Peri}; | ||
| 17 | 17 | ||
| 18 | const MAX_EP_COUNT: usize = 9; | 18 | const MAX_EP_COUNT: usize = 9; |
| 19 | 19 | ||
| @@ -32,8 +32,7 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 32 | 32 | ||
| 33 | macro_rules! config_ulpi_pins { | 33 | macro_rules! config_ulpi_pins { |
| 34 | ($($pin:ident),*) => { | 34 | ($($pin:ident),*) => { |
| 35 | into_ref!($($pin),*); | 35 | critical_section::with(|_| { |
| 36 | critical_section::with(|_| { | ||
| 37 | $( | 36 | $( |
| 38 | $pin.set_as_af($pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 37 | $pin.set_as_af($pin.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 39 | )* | 38 | )* |
| @@ -62,15 +61,13 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 62 | /// Must be large enough to fit all OUT endpoint max packet sizes. | 61 | /// Must be large enough to fit all OUT endpoint max packet sizes. |
| 63 | /// Endpoint allocation will fail if it is too small. | 62 | /// Endpoint allocation will fail if it is too small. |
| 64 | pub fn new_fs( | 63 | pub fn new_fs( |
| 65 | _peri: impl Peripheral<P = T> + 'd, | 64 | _peri: Peri<'d, T>, |
| 66 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 65 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 67 | dp: impl Peripheral<P = impl DpPin<T>> + 'd, | 66 | dp: Peri<'d, impl DpPin<T>>, |
| 68 | dm: impl Peripheral<P = impl DmPin<T>> + 'd, | 67 | dm: Peri<'d, impl DmPin<T>>, |
| 69 | ep_out_buffer: &'d mut [u8], | 68 | ep_out_buffer: &'d mut [u8], |
| 70 | config: Config, | 69 | config: Config, |
| 71 | ) -> Self { | 70 | ) -> Self { |
| 72 | into_ref!(dp, dm); | ||
| 73 | |||
| 74 | dp.set_as_af(dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 71 | dp.set_as_af(dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 75 | dm.set_as_af(dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 72 | dm.set_as_af(dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 76 | 73 | ||
| @@ -100,17 +97,16 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 100 | /// Must be large enough to fit all OUT endpoint max packet sizes. | 97 | /// Must be large enough to fit all OUT endpoint max packet sizes. |
| 101 | /// Endpoint allocation will fail if it is too small. | 98 | /// Endpoint allocation will fail if it is too small. |
| 102 | pub fn new_hs( | 99 | pub fn new_hs( |
| 103 | _peri: impl Peripheral<P = T> + 'd, | 100 | _peri: Peri<'d, T>, |
| 104 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 101 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 105 | _dp: impl Peripheral<P = impl DpPin<T>> + 'd, | 102 | _dp: Peri<'d, impl DpPin<T>>, |
| 106 | _dm: impl Peripheral<P = impl DmPin<T>> + 'd, | 103 | _dm: Peri<'d, impl DmPin<T>>, |
| 107 | ep_out_buffer: &'d mut [u8], | 104 | ep_out_buffer: &'d mut [u8], |
| 108 | config: Config, | 105 | config: Config, |
| 109 | ) -> Self { | 106 | ) -> Self { |
| 110 | // For STM32U5 High speed pins need to be left in analog mode | 107 | // For STM32U5 High speed pins need to be left in analog mode |
| 111 | #[cfg(not(all(stm32u5, peri_usb_otg_hs)))] | 108 | #[cfg(not(all(stm32u5, peri_usb_otg_hs)))] |
| 112 | { | 109 | { |
| 113 | into_ref!(_dp, _dm); | ||
| 114 | _dp.set_as_af(_dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 110 | _dp.set_as_af(_dp.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 115 | _dm.set_as_af(_dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 111 | _dm.set_as_af(_dm.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| 116 | } | 112 | } |
| @@ -139,20 +135,20 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 139 | /// Must be large enough to fit all OUT endpoint max packet sizes. | 135 | /// Must be large enough to fit all OUT endpoint max packet sizes. |
| 140 | /// Endpoint allocation will fail if it is too small. | 136 | /// Endpoint allocation will fail if it is too small. |
| 141 | pub fn new_fs_ulpi( | 137 | pub fn new_fs_ulpi( |
| 142 | _peri: impl Peripheral<P = T> + 'd, | 138 | _peri: Peri<'d, T>, |
| 143 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 139 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 144 | ulpi_clk: impl Peripheral<P = impl UlpiClkPin<T>> + 'd, | 140 | ulpi_clk: Peri<'d, impl UlpiClkPin<T>>, |
| 145 | ulpi_dir: impl Peripheral<P = impl UlpiDirPin<T>> + 'd, | 141 | ulpi_dir: Peri<'d, impl UlpiDirPin<T>>, |
| 146 | ulpi_nxt: impl Peripheral<P = impl UlpiNxtPin<T>> + 'd, | 142 | ulpi_nxt: Peri<'d, impl UlpiNxtPin<T>>, |
| 147 | ulpi_stp: impl Peripheral<P = impl UlpiStpPin<T>> + 'd, | 143 | ulpi_stp: Peri<'d, impl UlpiStpPin<T>>, |
| 148 | ulpi_d0: impl Peripheral<P = impl UlpiD0Pin<T>> + 'd, | 144 | ulpi_d0: Peri<'d, impl UlpiD0Pin<T>>, |
| 149 | ulpi_d1: impl Peripheral<P = impl UlpiD1Pin<T>> + 'd, | 145 | ulpi_d1: Peri<'d, impl UlpiD1Pin<T>>, |
| 150 | ulpi_d2: impl Peripheral<P = impl UlpiD2Pin<T>> + 'd, | 146 | ulpi_d2: Peri<'d, impl UlpiD2Pin<T>>, |
| 151 | ulpi_d3: impl Peripheral<P = impl UlpiD3Pin<T>> + 'd, | 147 | ulpi_d3: Peri<'d, impl UlpiD3Pin<T>>, |
| 152 | ulpi_d4: impl Peripheral<P = impl UlpiD4Pin<T>> + 'd, | 148 | ulpi_d4: Peri<'d, impl UlpiD4Pin<T>>, |
| 153 | ulpi_d5: impl Peripheral<P = impl UlpiD5Pin<T>> + 'd, | 149 | ulpi_d5: Peri<'d, impl UlpiD5Pin<T>>, |
| 154 | ulpi_d6: impl Peripheral<P = impl UlpiD6Pin<T>> + 'd, | 150 | ulpi_d6: Peri<'d, impl UlpiD6Pin<T>>, |
| 155 | ulpi_d7: impl Peripheral<P = impl UlpiD7Pin<T>> + 'd, | 151 | ulpi_d7: Peri<'d, impl UlpiD7Pin<T>>, |
| 156 | ep_out_buffer: &'d mut [u8], | 152 | ep_out_buffer: &'d mut [u8], |
| 157 | config: Config, | 153 | config: Config, |
| 158 | ) -> Self { | 154 | ) -> Self { |
| @@ -185,20 +181,20 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 185 | /// Must be large enough to fit all OUT endpoint max packet sizes. | 181 | /// Must be large enough to fit all OUT endpoint max packet sizes. |
| 186 | /// Endpoint allocation will fail if it is too small. | 182 | /// Endpoint allocation will fail if it is too small. |
| 187 | pub fn new_hs_ulpi( | 183 | pub fn new_hs_ulpi( |
| 188 | _peri: impl Peripheral<P = T> + 'd, | 184 | _peri: Peri<'d, T>, |
| 189 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 185 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 190 | ulpi_clk: impl Peripheral<P = impl UlpiClkPin<T>> + 'd, | 186 | ulpi_clk: Peri<'d, impl UlpiClkPin<T>>, |
| 191 | ulpi_dir: impl Peripheral<P = impl UlpiDirPin<T>> + 'd, | 187 | ulpi_dir: Peri<'d, impl UlpiDirPin<T>>, |
| 192 | ulpi_nxt: impl Peripheral<P = impl UlpiNxtPin<T>> + 'd, | 188 | ulpi_nxt: Peri<'d, impl UlpiNxtPin<T>>, |
| 193 | ulpi_stp: impl Peripheral<P = impl UlpiStpPin<T>> + 'd, | 189 | ulpi_stp: Peri<'d, impl UlpiStpPin<T>>, |
| 194 | ulpi_d0: impl Peripheral<P = impl UlpiD0Pin<T>> + 'd, | 190 | ulpi_d0: Peri<'d, impl UlpiD0Pin<T>>, |
| 195 | ulpi_d1: impl Peripheral<P = impl UlpiD1Pin<T>> + 'd, | 191 | ulpi_d1: Peri<'d, impl UlpiD1Pin<T>>, |
| 196 | ulpi_d2: impl Peripheral<P = impl UlpiD2Pin<T>> + 'd, | 192 | ulpi_d2: Peri<'d, impl UlpiD2Pin<T>>, |
| 197 | ulpi_d3: impl Peripheral<P = impl UlpiD3Pin<T>> + 'd, | 193 | ulpi_d3: Peri<'d, impl UlpiD3Pin<T>>, |
| 198 | ulpi_d4: impl Peripheral<P = impl UlpiD4Pin<T>> + 'd, | 194 | ulpi_d4: Peri<'d, impl UlpiD4Pin<T>>, |
| 199 | ulpi_d5: impl Peripheral<P = impl UlpiD5Pin<T>> + 'd, | 195 | ulpi_d5: Peri<'d, impl UlpiD5Pin<T>>, |
| 200 | ulpi_d6: impl Peripheral<P = impl UlpiD6Pin<T>> + 'd, | 196 | ulpi_d6: Peri<'d, impl UlpiD6Pin<T>>, |
| 201 | ulpi_d7: impl Peripheral<P = impl UlpiD7Pin<T>> + 'd, | 197 | ulpi_d7: Peri<'d, impl UlpiD7Pin<T>>, |
| 202 | ep_out_buffer: &'d mut [u8], | 198 | ep_out_buffer: &'d mut [u8], |
| 203 | config: Config, | 199 | config: Config, |
| 204 | ) -> Self { | 200 | ) -> Self { |
| @@ -411,7 +407,7 @@ trait SealedInstance { | |||
| 411 | 407 | ||
| 412 | /// USB instance trait. | 408 | /// USB instance trait. |
| 413 | #[allow(private_bounds)] | 409 | #[allow(private_bounds)] |
| 414 | pub trait Instance: SealedInstance + RccPeripheral + 'static { | 410 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + 'static { |
| 415 | /// Interrupt for this USB instance. | 411 | /// Interrupt for this USB instance. |
| 416 | type Interrupt: interrupt::typelevel::Interrupt; | 412 | type Interrupt: interrupt::typelevel::Interrupt; |
| 417 | } | 413 | } |
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index 6682374d3..0b878915a 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs | |||
| @@ -5,7 +5,7 @@ use core::marker::PhantomData; | |||
| 5 | use core::sync::atomic::{AtomicBool, Ordering}; | 5 | use core::sync::atomic::{AtomicBool, Ordering}; |
| 6 | use core::task::Poll; | 6 | use core::task::Poll; |
| 7 | 7 | ||
| 8 | use embassy_hal_internal::into_ref; | 8 | use embassy_hal_internal::PeripheralType; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | use embassy_usb_driver as driver; | 10 | use embassy_usb_driver as driver; |
| 11 | use embassy_usb_driver::{ | 11 | use embassy_usb_driver::{ |
| @@ -16,7 +16,7 @@ use crate::pac::usb::regs; | |||
| 16 | use crate::pac::usb::vals::{EpType, Stat}; | 16 | use crate::pac::usb::vals::{EpType, Stat}; |
| 17 | use crate::pac::USBRAM; | 17 | use crate::pac::USBRAM; |
| 18 | use crate::rcc::RccPeripheral; | 18 | use crate::rcc::RccPeripheral; |
| 19 | use crate::{interrupt, Peripheral}; | 19 | use crate::{interrupt, Peri}; |
| 20 | 20 | ||
| 21 | /// Interrupt handler. | 21 | /// Interrupt handler. |
| 22 | pub struct InterruptHandler<T: Instance> { | 22 | pub struct InterruptHandler<T: Instance> { |
| @@ -290,13 +290,12 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 290 | /// Create a new USB driver with start-of-frame (SOF) output. | 290 | /// Create a new USB driver with start-of-frame (SOF) output. |
| 291 | #[cfg(not(stm32l1))] | 291 | #[cfg(not(stm32l1))] |
| 292 | pub fn new_with_sof( | 292 | pub fn new_with_sof( |
| 293 | _usb: impl Peripheral<P = T> + 'd, | 293 | _usb: Peri<'d, T>, |
| 294 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 294 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 295 | dp: impl Peripheral<P = impl DpPin<T>> + 'd, | 295 | dp: Peri<'d, impl DpPin<T>>, |
| 296 | dm: impl Peripheral<P = impl DmPin<T>> + 'd, | 296 | dm: Peri<'d, impl DmPin<T>>, |
| 297 | sof: impl Peripheral<P = impl SofPin<T>> + 'd, | 297 | sof: Peri<'d, impl SofPin<T>>, |
| 298 | ) -> Self { | 298 | ) -> Self { |
| 299 | into_ref!(sof); | ||
| 300 | { | 299 | { |
| 301 | use crate::gpio::{AfType, OutputType, Speed}; | 300 | use crate::gpio::{AfType, OutputType, Speed}; |
| 302 | sof.set_as_af(sof.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 301 | sof.set_as_af(sof.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); |
| @@ -307,13 +306,11 @@ impl<'d, T: Instance> Driver<'d, T> { | |||
| 307 | 306 | ||
| 308 | /// Create a new USB driver. | 307 | /// Create a new USB driver. |
| 309 | pub fn new( | 308 | pub fn new( |
| 310 | _usb: impl Peripheral<P = T> + 'd, | 309 | _usb: Peri<'d, T>, |
| 311 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | 310 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, |
| 312 | dp: impl Peripheral<P = impl DpPin<T>> + 'd, | 311 | dp: Peri<'d, impl DpPin<T>>, |
| 313 | dm: impl Peripheral<P = impl DmPin<T>> + 'd, | 312 | dm: Peri<'d, impl DmPin<T>>, |
| 314 | ) -> Self { | 313 | ) -> Self { |
| 315 | into_ref!(dp, dm); | ||
| 316 | |||
| 317 | super::common_init::<T>(); | 314 | super::common_init::<T>(); |
| 318 | 315 | ||
| 319 | let regs = T::regs(); | 316 | let regs = T::regs(); |
| @@ -1236,7 +1233,7 @@ trait SealedInstance { | |||
| 1236 | 1233 | ||
| 1237 | /// USB instance trait. | 1234 | /// USB instance trait. |
| 1238 | #[allow(private_bounds)] | 1235 | #[allow(private_bounds)] |
| 1239 | pub trait Instance: SealedInstance + RccPeripheral + 'static { | 1236 | pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + 'static { |
| 1240 | /// Interrupt for this USB instance. | 1237 | /// Interrupt for this USB instance. |
| 1241 | type Interrupt: interrupt::typelevel::Interrupt; | 1238 | type Interrupt: interrupt::typelevel::Interrupt; |
| 1242 | } | 1239 | } |
diff --git a/embassy-stm32/src/wdg/mod.rs b/embassy-stm32/src/wdg/mod.rs index ab21c4b6b..fb5c3d930 100644 --- a/embassy-stm32/src/wdg/mod.rs +++ b/embassy-stm32/src/wdg/mod.rs | |||
| @@ -1,10 +1,11 @@ | |||
| 1 | //! Watchdog Timer (IWDG, WWDG) | 1 | //! Watchdog Timer (IWDG, WWDG) |
| 2 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 3 | 3 | ||
| 4 | use embassy_hal_internal::{into_ref, Peripheral}; | 4 | use embassy_hal_internal::PeripheralType; |
| 5 | use stm32_metapac::iwdg::vals::{Key, Pr}; | 5 | use stm32_metapac::iwdg::vals::{Key, Pr}; |
| 6 | 6 | ||
| 7 | use crate::rcc::LSI_FREQ; | 7 | use crate::rcc::LSI_FREQ; |
| 8 | use crate::Peri; | ||
| 8 | 9 | ||
| 9 | /// Independent watchdog (IWDG) driver. | 10 | /// Independent watchdog (IWDG) driver. |
| 10 | pub struct IndependentWatchdog<'d, T: Instance> { | 11 | pub struct IndependentWatchdog<'d, T: Instance> { |
| @@ -29,9 +30,7 @@ impl<'d, T: Instance> IndependentWatchdog<'d, T> { | |||
| 29 | /// | 30 | /// |
| 30 | /// [Self] has to be started with [Self::unleash()]. | 31 | /// [Self] has to be started with [Self::unleash()]. |
| 31 | /// Once timer expires, MCU will be reset. To prevent this, timer must be reloaded by repeatedly calling [Self::pet()] within timeout interval. | 32 | /// Once timer expires, MCU will be reset. To prevent this, timer must be reloaded by repeatedly calling [Self::pet()] within timeout interval. |
| 32 | pub fn new(_instance: impl Peripheral<P = T> + 'd, timeout_us: u32) -> Self { | 33 | pub fn new(_instance: Peri<'d, T>, timeout_us: u32) -> Self { |
| 33 | into_ref!(_instance); | ||
| 34 | |||
| 35 | // Find lowest prescaler value, which makes watchdog period longer or equal to timeout. | 34 | // Find lowest prescaler value, which makes watchdog period longer or equal to timeout. |
| 36 | // This iterates from 4 (2^2) to 256 (2^8). | 35 | // This iterates from 4 (2^2) to 256 (2^8). |
| 37 | let psc_power = unwrap!((2..=8).find(|psc_power| { | 36 | let psc_power = unwrap!((2..=8).find(|psc_power| { |
| @@ -86,7 +85,7 @@ trait SealedInstance { | |||
| 86 | 85 | ||
| 87 | /// IWDG instance trait. | 86 | /// IWDG instance trait. |
| 88 | #[allow(private_bounds)] | 87 | #[allow(private_bounds)] |
| 89 | pub trait Instance: SealedInstance {} | 88 | pub trait Instance: SealedInstance + PeripheralType {} |
| 90 | 89 | ||
| 91 | foreach_peripheral!( | 90 | foreach_peripheral!( |
| 92 | (iwdg, $inst:ident) => { | 91 | (iwdg, $inst:ident) => { |
