From eed3156ebcb171af55a9d423a187a96858226b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Wed, 8 Jan 2025 13:15:13 +0100 Subject: [PATCH] Remove all instance type params --- documentation/API-GUIDELINES.md | 6 +- esp-hal-embassy/src/time_driver.rs | 4 +- esp-hal/CHANGELOG.md | 2 + esp-hal/MIGRATING-0.22.md | 9 + esp-hal/src/gpio/interconnect.rs | 32 +- esp-hal/src/gpio/mod.rs | 335 ++++----------------- esp-hal/src/i2c/master/mod.rs | 56 +--- esp-hal/src/i2s/master.rs | 254 +++++----------- esp-hal/src/i2s/parallel.rs | 65 ++-- esp-hal/src/spi/master.rs | 293 ++++++------------ esp-hal/src/spi/slave.rs | 61 ++-- esp-hal/src/timer/mod.rs | 77 ++--- esp-hal/src/twai/mod.rs | 123 +++----- esp-hal/src/uart.rs | 223 ++++---------- esp-wifi/src/lib.rs | 2 +- hil-test/tests/embassy_timers_executors.rs | 4 +- hil-test/tests/spi_full_duplex.rs | 1 - 17 files changed, 434 insertions(+), 1113 deletions(-) diff --git a/documentation/API-GUIDELINES.md b/documentation/API-GUIDELINES.md index 28c41026d8..717d238065 100644 --- a/documentation/API-GUIDELINES.md +++ b/documentation/API-GUIDELINES.md @@ -26,17 +26,15 @@ In general, the [Rust API Guidelines](https://rust-lang.github.io/api-guidelines - Drivers must take peripherals via the `PeripheralRef` pattern - they don't consume peripherals directly. - If a driver requires pins, those pins should be configured using `fn with_signal_name(self, pin: impl Peripheral

+ 'd) -> Self` or `fn with_signal_name(self, pin: impl Peripheral

+ 'd) -> Self` - If a driver supports multiple peripheral instances (for example, I2C0 is one such instance): - - The peripheral instance type must be positioned as the last type parameter of the driver type. - - The peripheral instance type must default to a type that supports any of the peripheral instances. + - The driver should not be generic over the peripheral instance. - The author must to use `crate::any_peripheral` to define the "any" peripheral instance type. - - The driver must implement a `new` constructor that automatically converts the peripheral instance into the any type, and a `new_typed` that preserves the peripheral type. + - The driver must implement a `new` constructor that automatically converts the peripheral instance into the any type. - If a driver is configurable, configuration options should be implemented as a `Config` struct in the same module where the driver is located. - The driver's constructor should take the config struct by value, and it should return `Result`. - The `ConfigError` enum should be separate from other `Error` enums used by the driver. - The driver should implement `fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>`. - In case the driver's configuration is infallible (all possible combinations of options are supported by the hardware), the `ConfigError` should be implemented as an empty `enum`. - Configuration structs should derive `procmacros::BuilderLite` in order to automatically implement the Builder Lite pattern for them. -- If a driver only supports a single peripheral instance, no instance type parameter is necessary. - If a driver implements both blocking and async operations, or only implements blocking operations, but may support asynchronous ones in the future, the driver's type signature must include a `crate::Mode` type parameter. - By default, constructors must configure the driver for blocking mode. The driver must implement `into_async` (and a matching `into_blocking`) function that reconfigures the driver. - `into_async` must configure the driver and/or the associated DMA channels. This most often means enabling an interrupt handler. diff --git a/esp-hal-embassy/src/time_driver.rs b/esp-hal-embassy/src/time_driver.rs index d4b465b348..e6a6447914 100644 --- a/esp-hal-embassy/src/time_driver.rs +++ b/esp-hal-embassy/src/time_driver.rs @@ -5,11 +5,11 @@ use esp_hal::{ interrupt::{InterruptHandler, Priority}, sync::Locked, time::{now, ExtU64}, - timer::{AnyTimer, OneShotTimer}, + timer::OneShotTimer, Blocking, }; -pub type Timer = OneShotTimer<'static, Blocking, AnyTimer>; +pub type Timer = OneShotTimer<'static, Blocking>; enum AlarmState { Created(extern "C" fn()), diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 3b4ec8961b..9f9a13459f 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -123,6 +123,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The `prelude` module has been removed (#2845) +- Removed all peripheral instance type parameters and `new_typed` constructors (#?) + ## [0.22.0] - 2024-11-20 ### Added diff --git a/esp-hal/MIGRATING-0.22.md b/esp-hal/MIGRATING-0.22.md index 76fa15d7fb..82a382453c 100644 --- a/esp-hal/MIGRATING-0.22.md +++ b/esp-hal/MIGRATING-0.22.md @@ -262,6 +262,15 @@ is not compatible with the hardware. +.unwrap(); ``` +## Peripheral instance type parameters and `new_typed` constructors have been removed + +Call `new` instead and remove the type parameters if you've used them. + +```diff +-let mut spi: Spi<'lt, SPI2> = Spi::new_typed(..).unwrap(); ++let mut spi: Spi<'lt> = Spi::new(..).unwrap(); +``` + ## LCD_CAM configuration changes - `cam` now has a `Config` strurct that contains frequency, bit/byte order, VSync filter options. diff --git a/esp-hal/src/gpio/interconnect.rs b/esp-hal/src/gpio/interconnect.rs index 07a61e3f8e..2cab3518c8 100644 --- a/esp-hal/src/gpio/interconnect.rs +++ b/esp-hal/src/gpio/interconnect.rs @@ -41,8 +41,8 @@ impl PeripheralInput for P {} impl PeripheralOutput for P {} // Pin drivers -impl PeripheralInput for Flex<'static, P> {} -impl PeripheralOutput for Flex<'static, P> {} +impl PeripheralInput for Flex<'static> {} +impl PeripheralOutput for Flex<'static> {} // Placeholders impl PeripheralInput for NoPin {} @@ -226,11 +226,8 @@ where } } -impl

From> for InputSignal -where - P: InputPin, -{ - fn from(input: Flex<'static, P>) -> Self { +impl From> for InputSignal { + fn from(input: Flex<'static>) -> Self { Self::new(input.degrade()) } } @@ -364,11 +361,8 @@ where } } -impl

From> for OutputSignal -where - P: OutputPin, -{ - fn from(input: Flex<'static, P>) -> Self { +impl From> for OutputSignal { + fn from(input: Flex<'static>) -> Self { Self::new(input.degrade()) } } @@ -576,11 +570,8 @@ impl From for InputConnection { } } -impl

From> for InputConnection -where - P: InputPin, -{ - fn from(pin: Flex<'static, P>) -> Self { +impl From> for InputConnection { + fn from(pin: Flex<'static>) -> Self { pin.peripheral_input().into() } } @@ -668,11 +659,8 @@ impl From for OutputConnection { } } -impl

From> for OutputConnection -where - P: OutputPin, -{ - fn from(pin: Flex<'static, P>) -> Self { +impl From> for OutputConnection { + fn from(pin: Flex<'static>) -> Self { pin.into_peripheral_output().into() } } diff --git a/esp-hal/src/gpio/mod.rs b/esp-hal/src/gpio/mod.rs index 1c9a3b9a8a..6542852958 100644 --- a/esp-hal/src/gpio/mod.rs +++ b/esp-hal/src/gpio/mod.rs @@ -18,10 +18,7 @@ //! into peripheral signals for advanced use. //! //! Pin drivers can be created using [`Flex::new`], [`Input::new`], -//! [`Output::new`] and [`OutputOpenDrain::new`]. If you need the pin drivers to -//! carry the type of the pin, you can use the [`Flex::new_typed`], -//! [`Input::new_typed`], [`Output::new_typed`], and -//! [`OutputOpenDrain::new_typed`] functions. +//! [`Output::new`] and [`OutputOpenDrain::new`]. //! //! Each pin is a different type initially. Internally, `esp-hal` will often //! erase their types automatically, but they can also be converted into @@ -1096,7 +1093,7 @@ macro_rules! gpio { } impl $crate::gpio::AnyPin { - /// Conjure a new, type-erased GPIO pin out of thin air. + /// Conjure a new GPIO pin out of thin air. /// /// # Safety /// @@ -1110,6 +1107,15 @@ macro_rules! gpio { assert!(PINS.contains(&pin), "Pin {} does not exist", pin); Self(pin) } + + pub(crate) fn is_output(&self) -> bool { + match self.0 { + $( + $gpionum => $crate::if_output_pin!($($type),* { true } else { false }), + )+ + _ => false, + } + } } // These macros call the code block on the actually contained GPIO pin. @@ -1208,21 +1214,21 @@ macro_rules! gpio { /// for both high and low logical [`Level`]s. #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct Output<'d, P = AnyPin> { - pin: Flex<'d, P>, +pub struct Output<'d> { + pin: Flex<'d>, } -impl

private::Sealed for Output<'_, P> {} +impl private::Sealed for Output<'_> {} -impl<'d, P> Peripheral for Output<'d, P> { - type P = Flex<'d, P>; +impl<'d> Peripheral for Output<'d> { + type P = Flex<'d>; unsafe fn clone_unchecked(&self) -> Self::P { self.pin.clone_unchecked() } } impl<'d> Output<'d> { - /// Creates a new, type-erased GPIO output driver. + /// Creates a new GPIO output driver. /// /// The `initial_output` parameter sets the initial output level of the pin. /// @@ -1251,47 +1257,7 @@ impl<'d> Output<'d> { /// ``` #[inline] pub fn new(pin: impl Peripheral

+ 'd, initial_output: Level) -> Self { - Self::new_typed(pin.map_into(), initial_output) - } -} - -impl<'d, P> Output<'d, P> -where - P: OutputPin, -{ - /// Creates a new, typed GPIO output driver. - /// - /// The `initial_output` parameter sets the initial output level of the pin. - /// - /// This constructor is useful when you want to limit which GPIO pin can be - /// used for a particular function. - /// - /// ## Example - /// - /// The following example configures `GPIO5` to pulse a LED once. The - /// example assumes that the LED is connected such that it is on when - /// the pin is low. - /// - /// ```rust, no_run - #[doc = crate::before_snippet!()] - /// use esp_hal::gpio::{GpioPin, Level, Output}; - /// use esp_hal::delay::Delay; - /// - /// fn blink_once(led: &mut Output<'_, GpioPin<5>>, delay: &mut Delay) { - /// led.set_low(); - /// delay.delay_millis(500); - /// led.set_high(); - /// } - /// - /// let mut led = Output::new_typed(peripherals.GPIO5, Level::High); - /// let mut delay = Delay::new(); - /// - /// blink_once(&mut led, &mut delay); - /// # } - /// ``` - #[inline] - pub fn new_typed(pin: impl Peripheral

+ 'd, initial_output: Level) -> Self { - let mut pin = Flex::new_typed(pin); + let mut pin = Flex::new(pin); pin.set_level(initial_output); pin.set_as_output(); @@ -1381,21 +1347,21 @@ where /// voltage of their pins and convert it to a logical [`Level`]. #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct Input<'d, P = AnyPin> { - pin: Flex<'d, P>, +pub struct Input<'d> { + pin: Flex<'d>, } -impl

private::Sealed for Input<'_, P> {} +impl private::Sealed for Input<'_> {} -impl<'d, P> Peripheral for Input<'d, P> { - type P = Flex<'d, P>; +impl<'d> Peripheral for Input<'d> { + type P = Flex<'d>; unsafe fn clone_unchecked(&self) -> Self::P { self.pin.clone_unchecked() } } impl<'d> Input<'d> { - /// Creates a new, type-erased GPIO input. + /// Creates a new GPIO input. /// /// The `pull` parameter configures internal pull-up or pull-down /// resistors. @@ -1434,60 +1400,7 @@ impl<'d> Input<'d> { /// ``` #[inline] pub fn new(pin: impl Peripheral

+ 'd, pull: Pull) -> Self { - Self::new_typed(pin.map_into(), pull) - } -} - -impl<'d, P> Input<'d, P> -where - P: InputPin, -{ - /// Creates a new, typed GPIO input. - /// - /// The `pull` parameter configures internal pull-up or pull-down - /// resistors. - /// - /// This constructor is useful when you want to limit which GPIO pin can be - /// used for a particular function. - /// - /// ## Example - /// - /// The following example configures `GPIO5` to read a button press. The - /// example assumes that the button is connected such that the pin is low - /// when the button is pressed. - /// - /// ```rust, no_run - #[doc = crate::before_snippet!()] - /// use esp_hal::gpio::{GpioPin, Level, Input, Pull}; - /// use esp_hal::delay::Delay; - /// - /// fn print_when_pressed( - /// button: &mut Input<'_, GpioPin<5>>, - /// delay: &mut Delay, - /// ) { - /// let mut was_pressed = false; - /// loop { - /// let is_pressed = button.is_low(); - /// if is_pressed && !was_pressed { - /// println!("Button pressed!"); - /// } - /// was_pressed = is_pressed; - /// delay.delay_millis(100); - /// } - /// } - /// - /// let mut button = Input::new_typed( - /// peripherals.GPIO5, - /// Pull::Up, - /// ); - /// let mut delay = Delay::new(); - /// - /// print_when_pressed(&mut button, &mut delay); - /// # } - /// ``` - #[inline] - pub fn new_typed(pin: impl Peripheral

+ 'd, pull: Pull) -> Self { - let mut pin = Flex::new_typed(pin); + let mut pin = Flex::new(pin); pin.set_as_input(pull); @@ -1620,12 +1533,7 @@ where pub fn wakeup_enable(&mut self, enable: bool, event: WakeEvent) { self.pin.wakeup_enable(enable, event); } -} -impl

Input<'_, P> -where - P: InputPin + OutputPin, -{ /// Split the pin into an input and output signal. /// /// Peripheral signals allow connecting peripherals together without using @@ -1654,21 +1562,21 @@ where /// resistors. #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct OutputOpenDrain<'d, P = AnyPin> { - pin: Flex<'d, P>, +pub struct OutputOpenDrain<'d> { + pin: Flex<'d>, } -impl

private::Sealed for OutputOpenDrain<'_, P> {} +impl private::Sealed for OutputOpenDrain<'_> {} -impl<'d, P> Peripheral for OutputOpenDrain<'d, P> { - type P = Flex<'d, P>; +impl<'d> Peripheral for OutputOpenDrain<'d> { + type P = Flex<'d>; unsafe fn clone_unchecked(&self) -> Self::P { self.pin.clone_unchecked() } } impl<'d> OutputOpenDrain<'d> { - /// Creates a new, type-erased GPIO output driver. + /// Creates a new GPIO output driver. /// /// The `initial_output` parameter sets the initial output level of the pin. /// The `pull` parameter configures internal pull-up or pull-down @@ -1707,53 +1615,7 @@ impl<'d> OutputOpenDrain<'d> { initial_output: Level, pull: Pull, ) -> Self { - Self::new_typed(pin.map_into(), initial_output, pull) - } -} - -impl<'d, P> OutputOpenDrain<'d, P> -where - P: InputPin + OutputPin, -{ - /// Creates a new, typed GPIO output driver. - /// - /// The `initial_output` parameter sets the initial output level of the pin. - /// The `pull` parameter configures internal pull-up or pull-down - /// resistors. - /// - /// ## Example - /// - /// The following example configures `GPIO5` to pulse a LED once. The - /// example assumes that the LED is connected such that it is on when - /// the pin is low. - /// - /// ```rust, no_run - #[doc = crate::before_snippet!()] - /// use esp_hal::gpio::{GpioPin, Level, OutputOpenDrain, Pull}; - /// use esp_hal::delay::Delay; - /// - /// fn blink_once( - /// led: &mut OutputOpenDrain<'_, GpioPin<5>>, - /// delay: &mut Delay, - /// ) { - /// led.set_low(); - /// delay.delay_millis(500); - /// led.set_high(); - /// } - /// - /// let mut led = OutputOpenDrain::new_typed( - /// peripherals.GPIO5, - /// Level::High, - /// Pull::Up, - /// ); - /// let mut delay = Delay::new(); - /// - /// blink_once(&mut led, &mut delay); - /// # } - /// ``` - #[inline] - pub fn new_typed(pin: impl Peripheral

+ 'd, initial_output: Level, pull: Pull) -> Self { - let mut pin = Flex::new_typed(pin); + let mut pin = Flex::new(pin); pin.set_level(initial_output); pin.set_as_open_drain(pull); @@ -1879,17 +1741,17 @@ where /// This driver allows changing the pin mode between input and output. #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct Flex<'d, P = AnyPin> { - pin: PeripheralRef<'d, P>, +pub struct Flex<'d> { + pin: PeripheralRef<'d, AnyPin>, } -impl

private::Sealed for Flex<'_, P> {} +impl private::Sealed for Flex<'_> {} -impl

Peripheral for Flex<'_, P> { +impl Peripheral for Flex<'_> { type P = Self; unsafe fn clone_unchecked(&self) -> Self::P { Self { - pin: PeripheralRef::new(core::ptr::read(&*self.pin as *const P)), + pin: PeripheralRef::new(core::ptr::read(&*self.pin as *const AnyPin)), } } } @@ -1899,19 +1761,7 @@ impl<'d> Flex<'d> { /// No mode change happens. #[inline] pub fn new(pin: impl Peripheral

> + 'd) -> Self { - Self::new_typed(pin.map_into()) - } -} - -impl<'d, P> Flex<'d, P> -where - P: Pin, -{ - /// Create flexible pin driver for a [Pin]. - /// No mode change happens. - #[inline] - pub fn new_typed(pin: impl Peripheral

+ 'd) -> Self { - crate::into_ref!(pin); + crate::into_mapped_ref!(pin); Self { pin } } @@ -1923,12 +1773,7 @@ where pub fn peripheral_input(&self) -> interconnect::InputSignal { self.pin.degrade_pin(private::Internal).split().0 } -} -impl

Flex<'_, P> -where - P: InputPin, -{ /// Set the GPIO to input mode. pub fn set_as_input(&mut self, pull: Pull) { self.pin.init_input(pull, private::Internal); @@ -2020,12 +1865,7 @@ where pub fn wakeup_enable(&mut self, enable: bool, event: WakeEvent) { self.listen_with_options(event.into(), false, false, enable); } -} -impl

Flex<'_, P> -where - P: OutputPin, -{ /// Set the GPIO to output mode. #[instability::unstable] #[inline] @@ -2093,6 +1933,7 @@ where /// Peripheral signals allow connecting peripherals together without using /// external hardware. pub fn split(self) -> (interconnect::InputSignal, interconnect::OutputSignal) { + assert!(self.pin.is_output()); self.pin.degrade_pin(private::Internal).split() } @@ -2110,7 +1951,7 @@ where // Unfortunate implementation details responsible for: // - making pin drivers work with the peripheral signal system // - making the pin drivers work with the sleep API -impl Pin for Flex<'_, P> { +impl Pin for Flex<'_> { delegate::delegate! { to self.pin { fn number(&self) -> u8; @@ -2120,7 +1961,7 @@ impl Pin for Flex<'_, P> { } } } -impl RtcPin for Flex<'_, P> { +impl RtcPin for Flex<'_> { delegate::delegate! { to self.pin { #[cfg(xtensa)] @@ -2133,7 +1974,7 @@ impl RtcPin for Flex<'_, P> { } } } -impl RtcPinWithResistors for Flex<'_, P> { +impl RtcPinWithResistors for Flex<'_> { delegate::delegate! { to self.pin { fn rtcio_pullup(&mut self, enable: bool); @@ -2348,10 +2189,7 @@ mod asynch { pub(super) static PIN_WAKERS: [AtomicWaker; NUM_PINS] = [const { AtomicWaker::new() }; NUM_PINS]; - impl

Flex<'_, P> - where - P: InputPin, - { + impl Flex<'_> { /// Wait until the pin experiences a particular [`Event`]. /// /// The GPIO driver will disable listening for the event once it occurs, @@ -2434,10 +2272,7 @@ mod asynch { } } - impl

Input<'_, P> - where - P: InputPin, - { + impl Input<'_> { /// Wait until the pin experiences a particular [`Event`]. /// /// The GPIO driver will disable listening for the event once it occurs, @@ -2488,11 +2323,11 @@ mod asynch { } #[must_use = "futures do nothing unless you `.await` or poll them"] - struct PinFuture<'d, P: InputPin> { - pin: Flex<'d, P>, + struct PinFuture<'d> { + pin: Flex<'d>, } - impl PinFuture<'_, P> { + impl PinFuture<'_> { fn pin_mask(&self) -> u32 { let bank = GpioRegisterAccess::from(self.pin.number() as usize); 1 << (self.pin.number() - bank.offset()) @@ -2509,7 +2344,7 @@ mod asynch { } } - impl core::future::Future for PinFuture<'_, P> { + impl core::future::Future for PinFuture<'_> { type Output = (); fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { @@ -2523,7 +2358,7 @@ mod asynch { } } - impl Drop for PinFuture<'_, P> { + impl Drop for PinFuture<'_> { fn drop(&mut self) { // If the pin isn't listening, the future has either been dropped before setup, // or the interrupt has already been handled. @@ -2554,17 +2389,11 @@ mod embedded_hal_impls { use super::*; - impl

digital::ErrorType for Input<'_, P> - where - P: InputPin, - { + impl digital::ErrorType for Input<'_> { type Error = core::convert::Infallible; } - impl

digital::InputPin for Input<'_, P> - where - P: InputPin, - { + impl digital::InputPin for Input<'_> { fn is_high(&mut self) -> Result { Ok(Self::is_high(self)) } @@ -2574,17 +2403,11 @@ mod embedded_hal_impls { } } - impl

digital::ErrorType for Output<'_, P> - where - P: OutputPin, - { + impl digital::ErrorType for Output<'_> { type Error = core::convert::Infallible; } - impl

digital::OutputPin for Output<'_, P> - where - P: OutputPin, - { + impl digital::OutputPin for Output<'_> { fn set_low(&mut self) -> Result<(), Self::Error> { Self::set_low(self); Ok(()) @@ -2596,10 +2419,7 @@ mod embedded_hal_impls { } } - impl

digital::StatefulOutputPin for Output<'_, P> - where - P: OutputPin, - { + impl digital::StatefulOutputPin for Output<'_> { fn is_set_high(&mut self) -> Result { Ok(Self::is_set_high(self)) } @@ -2609,10 +2429,7 @@ mod embedded_hal_impls { } } - impl

digital::InputPin for OutputOpenDrain<'_, P> - where - P: InputPin + OutputPin, - { + impl digital::InputPin for OutputOpenDrain<'_> { fn is_high(&mut self) -> Result { Ok(Self::is_high(self)) } @@ -2622,17 +2439,11 @@ mod embedded_hal_impls { } } - impl

digital::ErrorType for OutputOpenDrain<'_, P> - where - P: InputPin + OutputPin, - { + impl digital::ErrorType for OutputOpenDrain<'_> { type Error = core::convert::Infallible; } - impl

digital::OutputPin for OutputOpenDrain<'_, P> - where - P: InputPin + OutputPin, - { + impl digital::OutputPin for OutputOpenDrain<'_> { fn set_low(&mut self) -> Result<(), Self::Error> { Self::set_low(self); Ok(()) @@ -2644,10 +2455,7 @@ mod embedded_hal_impls { } } - impl

digital::StatefulOutputPin for OutputOpenDrain<'_, P> - where - P: InputPin + OutputPin, - { + impl digital::StatefulOutputPin for OutputOpenDrain<'_> { fn is_set_high(&mut self) -> Result { Ok(Self::is_set_high(self)) } @@ -2657,10 +2465,7 @@ mod embedded_hal_impls { } } - impl

digital::InputPin for Flex<'_, P> - where - P: InputPin, - { + impl digital::InputPin for Flex<'_> { fn is_high(&mut self) -> Result { Ok(Self::is_high(self)) } @@ -2670,14 +2475,11 @@ mod embedded_hal_impls { } } - impl

digital::ErrorType for Flex<'_, P> { + impl digital::ErrorType for Flex<'_> { type Error = core::convert::Infallible; } - impl

digital::OutputPin for Flex<'_, P> - where - P: OutputPin, - { + impl digital::OutputPin for Flex<'_> { fn set_low(&mut self) -> Result<(), Self::Error> { Self::set_low(self); Ok(()) @@ -2689,10 +2491,7 @@ mod embedded_hal_impls { } } - impl

digital::StatefulOutputPin for Flex<'_, P> - where - P: OutputPin, - { + impl digital::StatefulOutputPin for Flex<'_> { fn is_set_high(&mut self) -> Result { Ok(Self::is_set_high(self)) } @@ -2708,10 +2507,7 @@ mod embedded_hal_async_impls { use super::*; - impl

Wait for Flex<'_, P> - where - P: InputPin, - { + impl Wait for Flex<'_> { async fn wait_for_high(&mut self) -> Result<(), Self::Error> { Self::wait_for_high(self).await; Ok(()) @@ -2738,10 +2534,7 @@ mod embedded_hal_async_impls { } } - impl

Wait for Input<'_, P> - where - P: InputPin, - { + impl Wait for Input<'_> { async fn wait_for_high(&mut self) -> Result<(), Self::Error> { Self::wait_for_high(self).await; Ok(()) diff --git a/esp-hal/src/i2c/master/mod.rs b/esp-hal/src/i2c/master/mod.rs index d317c9384c..d090dba897 100644 --- a/esp-hal/src/i2c/master/mod.rs +++ b/esp-hal/src/i2c/master/mod.rs @@ -320,8 +320,8 @@ impl Default for Config { /// I2C driver #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct I2c<'d, Dm: DriverMode, T = AnyI2c> { - i2c: PeripheralRef<'d, T>, +pub struct I2c<'d, Dm: DriverMode> { + i2c: PeripheralRef<'d, AnyI2c>, phantom: PhantomData, config: Config, guard: PeripheralGuard, @@ -329,7 +329,7 @@ pub struct I2c<'d, Dm: DriverMode, T = AnyI2c> { #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl SetConfig for I2c<'_, Dm, T> { +impl SetConfig for I2c<'_, Dm> { type Config = Config; type ConfigError = ConfigError; @@ -338,14 +338,11 @@ impl SetConfig for I2c<'_, Dm, T> { } } -impl embedded_hal::i2c::ErrorType for I2c<'_, Dm, T> { +impl embedded_hal::i2c::ErrorType for I2c<'_, Dm> { type Error = Error; } -impl embedded_hal::i2c::I2c for I2c<'_, Dm, T> -where - T: Instance, -{ +impl embedded_hal::i2c::I2c for I2c<'_, Dm> { fn transaction( &mut self, address: u8, @@ -356,10 +353,7 @@ where } } -impl<'d, T, Dm: DriverMode> I2c<'d, Dm, T> -where - T: Instance, -{ +impl<'d, Dm: DriverMode> I2c<'d, Dm> { fn driver(&self) -> Driver<'_> { Driver { info: self.i2c.info(), @@ -475,22 +469,7 @@ impl<'d> I2c<'d, Blocking> { i2c: impl Peripheral

+ 'd, config: Config, ) -> Result { - Self::new_typed(i2c.map_into(), config) - } -} - -impl<'d, T> I2c<'d, Blocking, T> -where - T: Instance, -{ - /// Create a new I2C instance - /// This will enable the peripheral but the peripheral won't get - /// automatically disabled when this gets dropped. - pub fn new_typed( - i2c: impl Peripheral

+ 'd, - config: Config, - ) -> Result { - crate::into_ref!(i2c); + crate::into_mapped_ref!(i2c); let guard = PeripheralGuard::new(i2c.info().peripheral); @@ -509,7 +488,7 @@ where // TODO: missing interrupt APIs /// Configures the I2C peripheral to operate in asynchronous mode. - pub fn into_async(mut self) -> I2c<'d, Async, T> { + pub fn into_async(mut self) -> I2c<'d, Async> { self.set_interrupt_handler(self.driver().info.async_handler); I2c { @@ -581,12 +560,9 @@ where } } -impl private::Sealed for I2c<'_, Blocking, T> where T: Instance {} +impl private::Sealed for I2c<'_, Blocking> {} -impl InterruptConfigurable for I2c<'_, Blocking, T> -where - T: Instance, -{ +impl InterruptConfigurable for I2c<'_, Blocking> { fn set_interrupt_handler(&mut self, handler: crate::interrupt::InterruptHandler) { let interrupt = self.driver().info.interrupt; for core in Cpu::other() { @@ -698,12 +674,9 @@ impl core::future::Future for I2cFuture<'_> { } } -impl<'d, T> I2c<'d, Async, T> -where - T: Instance, -{ +impl<'d> I2c<'d, Async> { /// Configure the I2C peripheral to operate in blocking mode. - pub fn into_blocking(self) -> I2c<'d, Blocking, T> { + pub fn into_blocking(self) -> I2c<'d, Blocking> { crate::interrupt::disable(Cpu::current(), self.driver().info.interrupt); I2c { @@ -832,10 +805,7 @@ where } } -impl embedded_hal_async::i2c::I2c for I2c<'_, Async, T> -where - T: Instance, -{ +impl embedded_hal_async::i2c::I2c for I2c<'_, Async> { async fn transaction( &mut self, address: u8, diff --git a/esp-hal/src/i2s/master.rs b/esp-hal/src/i2s/master.rs index 827b0215fc..22f4849cda 100644 --- a/esp-hal/src/i2s/master.rs +++ b/esp-hal/src/i2s/master.rs @@ -90,7 +90,6 @@ use crate::{ DmaTransferRxCircular, DmaTransferTx, DmaTransferTxCircular, - PeripheralDmaChannel, PeripheralRxChannel, PeripheralTxChannel, ReadBuffer, @@ -251,67 +250,18 @@ impl DataFormat { /// Instance of the I2S peripheral driver #[non_exhaustive] -pub struct I2s<'d, Dm, T = AnyI2s> +pub struct I2s<'d, Dm> where - T: RegisterAccess, Dm: DriverMode, { /// Handles the reception (RX) side of the I2S peripheral. - pub i2s_rx: RxCreator<'d, Dm, T>, + pub i2s_rx: RxCreator<'d, Dm>, /// Handles the transmission (TX) side of the I2S peripheral. - pub i2s_tx: TxCreator<'d, Dm, T>, + pub i2s_tx: TxCreator<'d, Dm>, } -impl<'d, T> I2s<'d, Blocking, T> +impl I2s<'_, Dm> where - T: RegisterAccess, -{ - #[allow(clippy::too_many_arguments)] - fn new_internal( - i2s: PeripheralRef<'d, T>, - standard: Standard, - data_format: DataFormat, - sample_rate: impl Into, - channel: PeripheralRef<'d, PeripheralDmaChannel>, - rx_descriptors: &'static mut [DmaDescriptor], - tx_descriptors: &'static mut [DmaDescriptor], - ) -> Self { - let channel = Channel::new(channel); - channel.runtime_ensure_compatible(&i2s); - // on ESP32-C3 / ESP32-S3 and later RX and TX are independent and - // could be configured totally independently but for now handle all - // the targets the same and force same configuration for both, TX and RX - - // make sure the peripheral is enabled before configuring it - let peripheral = i2s.peripheral(); - let rx_guard = PeripheralGuard::new(peripheral); - let tx_guard = PeripheralGuard::new(peripheral); - - i2s.set_clock(calculate_clock(sample_rate, 2, data_format.channel_bits())); - i2s.configure(&standard, &data_format); - i2s.set_master(); - i2s.update(); - - Self { - i2s_rx: RxCreator { - i2s: unsafe { i2s.clone_unchecked() }, - rx_channel: channel.rx, - descriptors: rx_descriptors, - guard: rx_guard, - }, - i2s_tx: TxCreator { - i2s, - tx_channel: channel.tx, - descriptors: tx_descriptors, - guard: tx_guard, - }, - } - } -} - -impl I2s<'_, Dm, T> -where - T: RegisterAccess, Dm: DriverMode, { /// Sets the interrupt handler @@ -347,16 +297,10 @@ where } } -impl crate::private::Sealed for I2s<'_, Dm, I> -where - I: RegisterAccess, - Dm: DriverMode, -{ -} +impl crate::private::Sealed for I2s<'_, Dm> where Dm: DriverMode {} -impl InterruptConfigurable for I2s<'_, Dm, I> +impl InterruptConfigurable for I2s<'_, Dm> where - I: RegisterAccess, Dm: DriverMode, { fn set_interrupt_handler(&mut self, handler: crate::interrupt::InterruptHandler) { @@ -379,52 +323,46 @@ impl<'d> I2s<'d, Blocking> { ) -> Self where CH: DmaChannelFor, - { - Self::new_typed( - i2s.map_into(), - standard, - data_format, - sample_rate, - channel, - rx_descriptors, - tx_descriptors, - ) - } -} - -impl<'d, T> I2s<'d, Blocking, T> -where - T: RegisterAccess, -{ - /// Construct a new I2S peripheral driver instance for the first I2S - /// peripheral - #[allow(clippy::too_many_arguments)] - pub fn new_typed( - i2s: impl Peripheral

+ 'd, - standard: Standard, - data_format: DataFormat, - sample_rate: impl Into, - channel: impl Peripheral

+ 'd, - rx_descriptors: &'static mut [DmaDescriptor], - tx_descriptors: &'static mut [DmaDescriptor], - ) -> Self - where - CH: DmaChannelFor, { crate::into_ref!(i2s); - Self::new_internal( - i2s, - standard, - data_format, - sample_rate, - channel.map(|ch| ch.degrade()).into_ref(), - rx_descriptors, - tx_descriptors, - ) + + let channel = Channel::new(channel.map(|ch| ch.degrade())); + channel.runtime_ensure_compatible(&i2s); + + // on ESP32-C3 / ESP32-S3 and later RX and TX are independent and + // could be configured totally independently but for now handle all + // the targets the same and force same configuration for both, TX and RX + + // make sure the peripheral is enabled before configuring it + let peripheral = i2s.peripheral(); + let rx_guard = PeripheralGuard::new(peripheral); + let tx_guard = PeripheralGuard::new(peripheral); + + i2s.set_clock(calculate_clock(sample_rate, 2, data_format.channel_bits())); + i2s.configure(&standard, &data_format); + i2s.set_master(); + i2s.update(); + + let i2s = i2s.map_into(); + + Self { + i2s_rx: RxCreator { + i2s: unsafe { i2s.clone_unchecked() }, + rx_channel: channel.rx, + descriptors: rx_descriptors, + guard: rx_guard, + }, + i2s_tx: TxCreator { + i2s, + tx_channel: channel.tx, + descriptors: tx_descriptors, + guard: tx_guard, + }, + } } /// Converts the I2S instance into async mode. - pub fn into_async(self) -> I2s<'d, Async, T> { + pub fn into_async(self) -> I2s<'d, Async> { I2s { i2s_rx: RxCreator { i2s: self.i2s_rx.i2s, @@ -442,9 +380,8 @@ where } } -impl<'d, Dm, T> I2s<'d, Dm, T> +impl<'d, Dm> I2s<'d, Dm> where - T: RegisterAccess, Dm: DriverMode, { /// Configures the I2S peripheral to use a master clock (MCLK) output pin. @@ -458,20 +395,18 @@ where } /// I2S TX channel -pub struct I2sTx<'d, Dm, T = AnyI2s> +pub struct I2sTx<'d, Dm> where - T: RegisterAccess, Dm: DriverMode, { - i2s: PeripheralRef<'d, T>, - tx_channel: ChannelTx<'d, Dm, PeripheralTxChannel>, + i2s: PeripheralRef<'d, AnyI2s>, + tx_channel: ChannelTx<'d, Dm, PeripheralTxChannel>, tx_chain: DescriptorChain, _guard: PeripheralGuard, } -impl core::fmt::Debug for I2sTx<'_, Dm, T> +impl core::fmt::Debug for I2sTx<'_, Dm> where - T: RegisterAccess, Dm: DriverMode, { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { @@ -479,9 +414,8 @@ where } } -impl DmaSupport for I2sTx<'_, Dm, T> +impl DmaSupport for I2sTx<'_, Dm> where - T: RegisterAccess, Dm: DriverMode, { fn peripheral_wait_dma(&mut self, _is_rx: bool, _is_tx: bool) { @@ -493,12 +427,11 @@ where } } -impl<'d, Dm, T> DmaSupportTx for I2sTx<'d, Dm, T> +impl<'d, Dm> DmaSupportTx for I2sTx<'d, Dm> where - T: RegisterAccess, Dm: DriverMode, { - type TX = ChannelTx<'d, Dm, PeripheralTxChannel>; + type TX = ChannelTx<'d, Dm, PeripheralTxChannel>; fn tx(&mut self) -> &mut Self::TX { &mut self.tx_channel @@ -509,9 +442,8 @@ where } } -impl I2sTx<'_, Dm, T> +impl I2sTx<'_, Dm> where - T: RegisterAccess, Dm: DriverMode, { fn write_bytes(&mut self, data: &[u8]) -> Result<(), Error> { @@ -591,20 +523,18 @@ where } /// I2S RX channel -pub struct I2sRx<'d, Dm, T = AnyI2s> +pub struct I2sRx<'d, Dm> where - T: RegisterAccess, Dm: DriverMode, { - i2s: PeripheralRef<'d, T>, - rx_channel: ChannelRx<'d, Dm, PeripheralRxChannel>, + i2s: PeripheralRef<'d, AnyI2s>, + rx_channel: ChannelRx<'d, Dm, PeripheralRxChannel>, rx_chain: DescriptorChain, _guard: PeripheralGuard, } -impl core::fmt::Debug for I2sRx<'_, Dm, T> +impl core::fmt::Debug for I2sRx<'_, Dm> where - T: RegisterAccess, Dm: DriverMode, { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { @@ -612,9 +542,8 @@ where } } -impl DmaSupport for I2sRx<'_, Dm, T> +impl DmaSupport for I2sRx<'_, Dm> where - T: RegisterAccess, Dm: DriverMode, { fn peripheral_wait_dma(&mut self, _is_rx: bool, _is_tx: bool) { @@ -626,12 +555,11 @@ where } } -impl<'d, Dm, T> DmaSupportRx for I2sRx<'d, Dm, T> +impl<'d, Dm> DmaSupportRx for I2sRx<'d, Dm> where - T: RegisterAccess, Dm: DriverMode, { - type RX = ChannelRx<'d, Dm, PeripheralRxChannel>; + type RX = ChannelRx<'d, Dm, PeripheralRxChannel>; fn rx(&mut self) -> &mut Self::RX { &mut self.rx_channel @@ -642,9 +570,8 @@ where } } -impl I2sRx<'_, Dm, T> +impl I2sRx<'_, Dm> where - T: RegisterAccess, Dm: DriverMode, { fn read_bytes(&mut self, mut data: &mut [u8]) -> Result<(), Error> { @@ -761,23 +688,21 @@ mod private { DriverMode, }; - pub struct TxCreator<'d, Dm, T> + pub struct TxCreator<'d, Dm> where - T: RegisterAccess, Dm: DriverMode, { - pub i2s: PeripheralRef<'d, T>, - pub tx_channel: ChannelTx<'d, Dm, PeripheralTxChannel>, + pub i2s: PeripheralRef<'d, AnyI2s>, + pub tx_channel: ChannelTx<'d, Dm, PeripheralTxChannel>, pub descriptors: &'static mut [DmaDescriptor], pub(crate) guard: PeripheralGuard, } - impl<'d, Dm, T> TxCreator<'d, Dm, T> + impl<'d, Dm> TxCreator<'d, Dm> where Dm: DriverMode, - T: RegisterAccess, { - pub fn build(self) -> I2sTx<'d, Dm, T> { + pub fn build(self) -> I2sTx<'d, Dm> { let peripheral = self.i2s.peripheral(); I2sTx { i2s: self.i2s, @@ -821,23 +746,21 @@ mod private { } } - pub struct RxCreator<'d, Dm, T> + pub struct RxCreator<'d, Dm> where - T: RegisterAccess, Dm: DriverMode, { - pub i2s: PeripheralRef<'d, T>, - pub rx_channel: ChannelRx<'d, Dm, PeripheralRxChannel>, + pub i2s: PeripheralRef<'d, AnyI2s>, + pub rx_channel: ChannelRx<'d, Dm, PeripheralRxChannel>, pub descriptors: &'static mut [DmaDescriptor], pub(crate) guard: PeripheralGuard, } - impl<'d, Dm, T> RxCreator<'d, Dm, T> + impl<'d, Dm> RxCreator<'d, Dm> where Dm: DriverMode, - T: RegisterAccess, { - pub fn build(self) -> I2sRx<'d, Dm, T> { + pub fn build(self) -> I2sRx<'d, Dm> { let peripheral = self.i2s.peripheral(); I2sRx { i2s: self.i2s, @@ -1876,10 +1799,11 @@ mod private { /// Async functionality pub mod asynch { - use super::{Error, I2sRx, I2sTx, RegisterAccess}; + use super::{Error, I2sRx, I2sTx, RegisterAccessPrivate}; use crate::{ dma::{ asynch::{DmaRxDoneChFuture, DmaRxFuture, DmaTxDoneChFuture, DmaTxFuture}, + DmaEligible, ReadBuffer, Rx, RxCircularState, @@ -1890,10 +1814,7 @@ pub mod asynch { Async, }; - impl<'d, T> I2sTx<'d, Async, T> - where - T: RegisterAccess, - { + impl<'d> I2sTx<'d, Async> { /// One-shot write I2S. pub async fn write_dma_async(&mut self, words: &mut [u8]) -> Result<(), Error> { let (ptr, len) = (words.as_ptr(), words.len()); @@ -1920,7 +1841,7 @@ pub mod asynch { pub fn write_dma_circular_async( mut self, words: TXBUF, - ) -> Result, Error> { + ) -> Result, Error> { let (ptr, len) = unsafe { words.read_buffer() }; // Reset TX unit and TX FIFO @@ -1951,19 +1872,13 @@ pub mod asynch { } /// An in-progress async circular DMA write transfer. - pub struct I2sWriteDmaTransferAsync<'d, BUFFER, T = super::AnyI2s> - where - T: RegisterAccess, - { - i2s_tx: I2sTx<'d, Async, T>, + pub struct I2sWriteDmaTransferAsync<'d, BUFFER> { + i2s_tx: I2sTx<'d, Async>, state: TxCircularState, _buffer: BUFFER, } - impl I2sWriteDmaTransferAsync<'_, BUFFER, T> - where - T: RegisterAccess, - { + impl I2sWriteDmaTransferAsync<'_, BUFFER> { /// How many bytes can be pushed into the DMA transaction. /// Will wait for more than 0 bytes available. pub async fn available(&mut self) -> Result { @@ -2000,10 +1915,7 @@ pub mod asynch { } } - impl<'d, T> I2sRx<'d, Async, T> - where - T: RegisterAccess, - { + impl<'d> I2sRx<'d, Async> { /// One-shot read I2S. pub async fn read_dma_async(&mut self, words: &mut [u8]) -> Result<(), Error> { let (ptr, len) = (words.as_mut_ptr(), words.len()); @@ -2038,7 +1950,7 @@ pub mod asynch { pub fn read_dma_circular_async( mut self, mut words: RXBUF, - ) -> Result, Error> + ) -> Result, Error> where RXBUF: WriteBuffer, { @@ -2074,19 +1986,13 @@ pub mod asynch { } /// An in-progress async circular DMA read transfer. - pub struct I2sReadDmaTransferAsync<'d, BUFFER, T = super::AnyI2s> - where - T: RegisterAccess, - { - i2s_rx: I2sRx<'d, Async, T>, + pub struct I2sReadDmaTransferAsync<'d, BUFFER> { + i2s_rx: I2sRx<'d, Async>, state: RxCircularState, _buffer: BUFFER, } - impl I2sReadDmaTransferAsync<'_, BUFFER, T> - where - T: RegisterAccess, - { + impl I2sReadDmaTransferAsync<'_, BUFFER> { /// How many bytes can be popped from the DMA transaction. /// Will wait for more than 0 bytes available. pub async fn available(&mut self) -> Result { diff --git a/esp-hal/src/i2s/parallel.rs b/esp-hal/src/i2s/parallel.rs index 3f29eb6866..3bb814b6ef 100644 --- a/esp-hal/src/i2s/parallel.rs +++ b/esp-hal/src/i2s/parallel.rs @@ -235,13 +235,13 @@ impl<'d> TxPins<'d> for TxEightBits<'d> { } /// I2S Parallel Interface -pub struct I2sParallel<'d, Dm, I = AnyI2s> +pub struct I2sParallel<'d, Dm> where Dm: DriverMode, I: Instance, { - instance: PeripheralRef<'d, I>, - tx_channel: ChannelTx<'d, Dm, PeripheralTxChannel>, + instance: PeripheralRef<'d, AnyI2s>, + tx_channel: ChannelTx<'d, Dm, PeripheralTxChannel>, _guard: PeripheralGuard, } @@ -251,32 +251,13 @@ impl<'d> I2sParallel<'d, Blocking> { i2s: impl Peripheral

+ 'd, channel: impl Peripheral

+ 'd, frequency: impl Into, - pins: impl TxPins<'d>, - clock_pin: impl Peripheral

+ 'd, - ) -> Self - where - CH: DmaChannelFor, - { - Self::new_typed(i2s.map_into(), channel, frequency, pins, clock_pin) - } -} - -impl<'d, I> I2sParallel<'d, Blocking, I> -where - I: Instance, -{ - /// Create a new I2S Parallel Interface - pub fn new_typed( - i2s: impl Peripheral

+ 'd, - channel: impl Peripheral

+ 'd, - frequency: impl Into, mut pins: impl TxPins<'d>, clock_pin: impl Peripheral

+ 'd, ) -> Self where - CH: DmaChannelFor, + CH: DmaChannelFor, { - crate::into_ref!(i2s); + crate::into_mapped_ref!(i2s); crate::into_mapped_ref!(clock_pin); let channel = Channel::new(channel.map(|ch| ch.degrade())); @@ -299,7 +280,7 @@ where } /// Converts the I2S instance into async mode. - pub fn into_async(self) -> I2sParallel<'d, Async, I> { + pub fn into_async(self) -> I2sParallel<'d, Async> { I2sParallel { instance: self.instance, tx_channel: self.tx_channel.into_async(), @@ -308,12 +289,9 @@ where } } -impl<'d, I> I2sParallel<'d, Async, I> -where - I: Instance, -{ +impl<'d> I2sParallel<'d, Async> { /// Converts the I2S instance into async mode. - pub fn into_blocking(self) -> I2sParallel<'d, Blocking, I> { + pub fn into_blocking(self) -> I2sParallel<'d, Blocking> { I2sParallel { instance: self.instance, tx_channel: self.tx_channel.into_blocking(), @@ -322,16 +300,15 @@ where } } -impl<'d, I, Dm> I2sParallel<'d, Dm, I> +impl<'d, Dm> I2sParallel<'d, Dm> where - I: Instance, Dm: DriverMode, { /// Write data to the I2S peripheral pub fn send( mut self, mut data: BUF, - ) -> Result, (DmaError, Self, BUF)> { + ) -> Result, (DmaError, Self, BUF)> { self.instance.tx_reset(); self.instance.tx_fifo_reset(); let result = unsafe { @@ -353,19 +330,17 @@ where /// Represents an ongoing (or potentially finished) transfer using the i2s /// parallel interface -pub struct I2sParallelTransfer<'d, BUF, Dm, I = AnyI2s> +pub struct I2sParallelTransfer<'d, BUF, Dm> where - I: Instance, BUF: DmaTxBuffer, Dm: DriverMode, { - i2s: ManuallyDrop>, + i2s: ManuallyDrop>, buf_view: ManuallyDrop, } -impl<'d, I, BUF, Dm> I2sParallelTransfer<'d, BUF, Dm, I> +impl<'d, BUF, Dm> I2sParallelTransfer<'d, BUF, Dm> where - I: Instance, BUF: DmaTxBuffer, Dm: DriverMode, { @@ -375,7 +350,7 @@ where } /// Wait for the transfer to finish - pub fn wait(mut self) -> (I2sParallel<'d, Dm, I>, BUF) { + pub fn wait(mut self) -> (I2sParallel<'d, Dm>, BUF) { self.i2s.instance.tx_wait_done(); let i2s = unsafe { ManuallyDrop::take(&mut self.i2s) }; let view = unsafe { ManuallyDrop::take(&mut self.buf_view) }; @@ -389,9 +364,8 @@ where } } -impl<'d, I, BUF> I2sParallelTransfer<'d, BUF, Async, I> +impl<'d, BUF> I2sParallelTransfer<'d, BUF, Async> where - I: Instance, BUF: DmaTxBuffer, { /// Wait for the transfer to finish @@ -400,9 +374,8 @@ where } } -impl Deref for I2sParallelTransfer<'_, BUF, Dm, I> +impl Deref for I2sParallelTransfer<'_, BUF, Dm> where - I: Instance, BUF: DmaTxBuffer, Dm: DriverMode, { @@ -413,9 +386,8 @@ where } } -impl DerefMut for I2sParallelTransfer<'_, BUF, Dm, I> +impl DerefMut for I2sParallelTransfer<'_, BUF, Dm> where - I: Instance, BUF: DmaTxBuffer, Dm: DriverMode, { @@ -424,9 +396,8 @@ where } } -impl Drop for I2sParallelTransfer<'_, BUF, Dm, I> +impl Drop for I2sParallelTransfer<'_, BUF, Dm> where - I: Instance, BUF: DmaTxBuffer, Dm: DriverMode, { diff --git a/esp-hal/src/spi/master.rs b/esp-hal/src/spi/master.rs index 2d2fe7e859..467acc1b43 100644 --- a/esp-hal/src/spi/master.rs +++ b/esp-hal/src/spi/master.rs @@ -485,17 +485,16 @@ pub enum ConfigError {} /// SPI peripheral driver #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct Spi<'d, Dm, T = AnySpi> { - spi: PeripheralRef<'d, T>, +pub struct Spi<'d, Dm> { + spi: PeripheralRef<'d, AnySpi>, _mode: PhantomData, guard: PeripheralGuard, } -impl Sealed for Spi<'_, Dm, T> {} +impl Sealed for Spi<'_, Dm> {} -impl Spi<'_, Dm, T> +impl Spi<'_, Dm> where - T: Instance, Dm: DriverMode, { fn driver(&self) -> Driver { @@ -539,16 +538,38 @@ impl<'d> Spi<'d, Blocking> { spi: impl Peripheral

+ 'd, config: Config, ) -> Result { - Self::new_typed(spi.map_into(), config) + crate::into_mapped_ref!(spi); + + let guard = PeripheralGuard::new(spi.info().peripheral); + + let mut this = Spi { + spi, + _mode: PhantomData, + guard, + }; + + this.driver().init(); + this.apply_config(&config)?; + + let this = this + .with_mosi(NoPin) + .with_miso(NoPin) + .with_sck(NoPin) + .with_cs(NoPin); + + let is_qspi = this.driver().info.sio2_input.is_some(); + if is_qspi { + unwrap!(this.driver().info.sio2_input).connect_to(NoPin); + unwrap!(this.driver().info.sio2_output).connect_to(NoPin); + unwrap!(this.driver().info.sio3_input).connect_to(NoPin); + unwrap!(this.driver().info.sio3_output).connect_to(NoPin); + } + + Ok(this) } -} -impl<'d, T> Spi<'d, Blocking, T> -where - T: Instance, -{ /// Converts the SPI instance into async mode. - pub fn into_async(mut self) -> Spi<'d, Async, T> { + pub fn into_async(mut self) -> Spi<'d, Async> { self.set_interrupt_handler(self.spi.handler()); Spi { spi: self.spi, @@ -563,18 +584,15 @@ where /// and returns an instance of `SpiDma` that supports DMA /// operations. #[instability::unstable] - pub fn with_dma(self, channel: impl Peripheral

+ 'd) -> SpiDma<'d, Blocking, T> + pub fn with_dma(self, channel: impl Peripheral

+ 'd) -> SpiDma<'d, Blocking> where - CH: DmaChannelFor, + CH: DmaChannelFor, { SpiDma::new(self.spi, channel.map(|ch| ch.degrade()).into_ref()) } } -impl InterruptConfigurable for Spi<'_, Blocking, T> -where - T: Instance, -{ +impl InterruptConfigurable for Spi<'_, Blocking> { /// Sets the interrupt handler /// /// Interrupts are not enabled at the peripheral level here. @@ -588,12 +606,9 @@ where } } -impl<'d, T> Spi<'d, Async, T> -where - T: Instance, -{ +impl<'d> Spi<'d, Async> { /// Converts the SPI instance into blocking mode. - pub fn into_blocking(self) -> Spi<'d, Blocking, T> { + pub fn into_blocking(self) -> Spi<'d, Blocking> { crate::interrupt::disable(Cpu::current(), self.driver().info.interrupt); Spi { spi: self.spi, @@ -624,46 +639,10 @@ where } } -impl<'d, Dm, T> Spi<'d, Dm, T> +impl<'d, Dm> Spi<'d, Dm> where - T: Instance, Dm: DriverMode, { - /// Constructs an SPI instance in 8bit dataframe mode. - pub fn new_typed( - spi: impl Peripheral

+ 'd, - config: Config, - ) -> Result { - crate::into_ref!(spi); - - let guard = PeripheralGuard::new(spi.info().peripheral); - - let mut this = Spi { - spi, - _mode: PhantomData, - guard, - }; - - this.driver().init(); - this.apply_config(&config)?; - - let this = this - .with_mosi(NoPin) - .with_miso(NoPin) - .with_sck(NoPin) - .with_cs(NoPin); - - let is_qspi = this.driver().info.sio2_input.is_some(); - if is_qspi { - unwrap!(this.driver().info.sio2_input).connect_to(NoPin); - unwrap!(this.driver().info.sio2_output).connect_to(NoPin); - unwrap!(this.driver().info.sio3_input).connect_to(NoPin); - unwrap!(this.driver().info.sio3_output).connect_to(NoPin); - } - - Ok(this) - } - /// Assign the MOSI (Master Out Slave In) pin for the SPI instance. /// /// Enables both input and output functionality for the pin, and connects it @@ -742,9 +721,8 @@ where #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl SetConfig for Spi<'_, Dm, T> +impl SetConfig for Spi<'_, Dm> where - T: Instance, Dm: DriverMode, { type Config = Config; @@ -755,9 +733,8 @@ where } } -impl<'d, Dm, T> Spi<'d, Dm, T> +impl<'d, Dm> Spi<'d, Dm> where - T: Instance + QspiInstance, Dm: DriverMode, { /// Assign the SIO2 pin for the SPI instance. @@ -765,10 +742,8 @@ where /// Enables both input and output functionality for the pin, and connects it /// to the SIO2 output and input signals. #[instability::unstable] - pub fn with_sio2(self, sio2: impl Peripheral

+ 'd) -> Self - where - T: QspiInstance, - { + pub fn with_sio2(self, sio2: impl Peripheral

+ 'd) -> Self { + // TODO: panic if not QSPI? crate::into_mapped_ref!(sio2); sio2.enable_input(true, private::Internal); sio2.enable_output(true, private::Internal); @@ -784,10 +759,8 @@ where /// Enables both input and output functionality for the pin, and connects it /// to the SIO3 output and input signals. #[instability::unstable] - pub fn with_sio3(self, sio3: impl Peripheral

+ 'd) -> Self - where - T: QspiInstance, - { + pub fn with_sio3(self, sio3: impl Peripheral

+ 'd) -> Self { + // TODO: panic if not QSPI? crate::into_mapped_ref!(sio3); sio3.enable_input(true, private::Internal); sio3.enable_output(true, private::Internal); @@ -799,9 +772,8 @@ where } } -impl Spi<'_, Dm, T> +impl Spi<'_, Dm> where - T: Instance, Dm: DriverMode, { /// Half-duplex read. @@ -927,13 +899,12 @@ mod dma { /// embedded-hal traits. #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[instability::unstable] - pub struct SpiDma<'d, Dm, T = AnySpi> + pub struct SpiDma<'d, Dm> where - T: Instance, Dm: DriverMode, { - pub(crate) spi: PeripheralRef<'d, T>, - pub(crate) channel: Channel<'d, Dm, PeripheralDmaChannel>, + pub(crate) spi: PeripheralRef<'d, AnySpi>, + pub(crate) channel: Channel<'d, Dm, PeripheralDmaChannel>, tx_transfer_in_progress: bool, rx_transfer_in_progress: bool, #[cfg(all(esp32, spi_address_workaround))] @@ -941,20 +912,12 @@ mod dma { guard: PeripheralGuard, } - impl crate::private::Sealed for SpiDma<'_, Dm, T> - where - T: Instance, - Dm: DriverMode, - { - } + impl crate::private::Sealed for SpiDma<'_, Dm> where Dm: DriverMode {} - impl<'d, T> SpiDma<'d, Blocking, T> - where - T: Instance, - { + impl<'d> SpiDma<'d, Blocking> { /// Converts the SPI instance into async mode. #[instability::unstable] - pub fn into_async(self) -> SpiDma<'d, Async, T> { + pub fn into_async(self) -> SpiDma<'d, Async> { SpiDma { spi: self.spi, channel: self.channel.into_async(), @@ -967,13 +930,10 @@ mod dma { } } - impl<'d, T> SpiDma<'d, Async, T> - where - T: Instance, - { + impl<'d> SpiDma<'d, Async> { /// Converts the SPI instance into async mode. #[instability::unstable] - pub fn into_blocking(self) -> SpiDma<'d, Blocking, T> { + pub fn into_blocking(self) -> SpiDma<'d, Blocking> { SpiDma { spi: self.spi, channel: self.channel.into_blocking(), @@ -986,9 +946,8 @@ mod dma { } } - impl core::fmt::Debug for SpiDma<'_, Dm, T> + impl core::fmt::Debug for SpiDma<'_, Dm> where - T: Instance + core::fmt::Debug, Dm: DriverMode, { /// Formats the `SpiDma` instance for debugging purposes. @@ -1000,10 +959,7 @@ mod dma { } } - impl InterruptConfigurable for SpiDma<'_, Blocking, T> - where - T: Instance, - { + impl InterruptConfigurable for SpiDma<'_, Blocking> { /// Sets the interrupt handler /// /// Interrupts are not enabled at the peripheral level here. @@ -1019,10 +975,7 @@ mod dma { #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] - impl SpiDma<'_, Blocking, T> - where - T: Instance, - { + impl SpiDma<'_, Blocking> { /// Listen for the given interrupts pub fn listen(&mut self, interrupts: impl Into>) { self.driver().enable_listen(interrupts.into(), true); @@ -1044,13 +997,10 @@ mod dma { } } - impl<'d, T> SpiDma<'d, Blocking, T> - where - T: Instance, - { + impl<'d> SpiDma<'d, Blocking> { pub(super) fn new( - spi: PeripheralRef<'d, T>, - channel: PeripheralRef<'d, PeripheralDmaChannel>, + spi: PeripheralRef<'d, AnySpi>, + channel: PeripheralRef<'d, PeripheralDmaChannel>, ) -> Self { let channel = Channel::new(channel); channel.runtime_ensure_compatible(&spi); @@ -1088,9 +1038,8 @@ mod dma { } } - impl<'d, Dm, T> SpiDma<'d, Dm, T> + impl<'d, Dm> SpiDma<'d, Dm> where - T: Instance, Dm: DriverMode, { fn driver(&self) -> Driver { @@ -1273,20 +1222,15 @@ mod dma { /// It returns an instance of `SpiDmaBus` that can be used for SPI /// communication. #[instability::unstable] - pub fn with_buffers( - self, - dma_rx_buf: DmaRxBuf, - dma_tx_buf: DmaTxBuf, - ) -> SpiDmaBus<'d, Dm, T> { + pub fn with_buffers(self, dma_rx_buf: DmaRxBuf, dma_tx_buf: DmaTxBuf) -> SpiDmaBus<'d, Dm> { SpiDmaBus::new(self, dma_rx_buf, dma_tx_buf) } } #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] - impl SetConfig for SpiDma<'_, Dm, T> + impl SetConfig for SpiDma<'_, Dm> where - T: Instance, Dm: DriverMode, { type Config = Config; @@ -1302,21 +1246,19 @@ mod dma { /// This structure holds references to the SPI instance, DMA buffers, and /// transfer status. #[instability::unstable] - pub struct SpiDmaTransfer<'d, Dm, Buf, T = AnySpi> + pub struct SpiDmaTransfer<'d, Dm, Buf> where - T: Instance, Dm: DriverMode, { - spi_dma: ManuallyDrop>, + spi_dma: ManuallyDrop>, dma_buf: ManuallyDrop, } - impl<'d, Dm, T, Buf> SpiDmaTransfer<'d, Dm, Buf, T> + impl<'d, Dm, Buf> SpiDmaTransfer<'d, Dm, Buf> where - T: Instance, Dm: DriverMode, { - fn new(spi_dma: SpiDma<'d, Dm, T>, dma_buf: Buf) -> Self { + fn new(spi_dma: SpiDma<'d, Dm>, dma_buf: Buf) -> Self { Self { spi_dma: ManuallyDrop::new(spi_dma), dma_buf: ManuallyDrop::new(dma_buf), @@ -1336,7 +1278,7 @@ mod dma { /// This method blocks until the transfer is finished and returns the /// `SpiDma` instance and the associated buffer. #[instability::unstable] - pub fn wait(mut self) -> (SpiDma<'d, Dm, T>, Buf) { + pub fn wait(mut self) -> (SpiDma<'d, Dm>, Buf) { self.spi_dma.wait_for_idle(); let retval = unsafe { ( @@ -1357,9 +1299,8 @@ mod dma { } } - impl Drop for SpiDmaTransfer<'_, Dm, Buf, T> + impl Drop for SpiDmaTransfer<'_, Dm, Buf> where - T: Instance, Dm: DriverMode, { fn drop(&mut self) { @@ -1375,10 +1316,7 @@ mod dma { } } - impl SpiDmaTransfer<'_, Async, Buf, T> - where - T: Instance, - { + impl SpiDmaTransfer<'_, Async, Buf> { /// Waits for the DMA transfer to complete asynchronously. /// /// This method awaits the completion of both RX and TX operations. @@ -1388,9 +1326,8 @@ mod dma { } } - impl<'d, Dm, T> SpiDma<'d, Dm, T> + impl<'d, Dm> SpiDma<'d, Dm> where - T: Instance, Dm: DriverMode, { /// # Safety: @@ -1418,7 +1355,7 @@ mod dma { mut self, bytes_to_write: usize, mut buffer: TX, - ) -> Result, (Error, Self, TX)> { + ) -> Result, (Error, Self, TX)> { self.wait_for_idle(); match unsafe { self.start_dma_write(bytes_to_write, &mut buffer) } { @@ -1452,7 +1389,7 @@ mod dma { mut self, bytes_to_read: usize, mut buffer: RX, - ) -> Result, (Error, Self, RX)> { + ) -> Result, (Error, Self, RX)> { self.wait_for_idle(); match unsafe { self.start_dma_read(bytes_to_read, &mut buffer) } { Ok(_) => Ok(SpiDmaTransfer::new(self, buffer)), @@ -1489,7 +1426,7 @@ mod dma { mut rx_buffer: RX, bytes_to_write: usize, mut tx_buffer: TX, - ) -> Result, (Error, Self, RX, TX)> { + ) -> Result, (Error, Self, RX, TX)> { self.wait_for_idle(); match unsafe { self.start_dma_transfer( @@ -1543,7 +1480,7 @@ mod dma { dummy: u8, bytes_to_read: usize, mut buffer: RX, - ) -> Result, (Error, Self, RX)> { + ) -> Result, (Error, Self, RX)> { self.wait_for_idle(); match unsafe { @@ -1609,7 +1546,7 @@ mod dma { dummy: u8, bytes_to_write: usize, mut buffer: TX, - ) -> Result, (Error, Self, TX)> { + ) -> Result, (Error, Self, TX)> { self.wait_for_idle(); match unsafe { @@ -1635,30 +1572,21 @@ mod dma { #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[instability::unstable] - pub struct SpiDmaBus<'d, Dm, T = AnySpi> + pub struct SpiDmaBus<'d, Dm> where - T: Instance, Dm: DriverMode, { - spi_dma: SpiDma<'d, Dm, T>, + spi_dma: SpiDma<'d, Dm>, rx_buf: DmaRxBuf, tx_buf: DmaTxBuf, } - impl crate::private::Sealed for SpiDmaBus<'_, Dm, T> - where - T: Instance, - Dm: DriverMode, - { - } + impl crate::private::Sealed for SpiDmaBus<'_, Dm> where Dm: DriverMode {} - impl<'d, T> SpiDmaBus<'d, Blocking, T> - where - T: Instance, - { + impl<'d> SpiDmaBus<'d, Blocking> { /// Converts the SPI instance into async mode. #[instability::unstable] - pub fn into_async(self) -> SpiDmaBus<'d, Async, T> { + pub fn into_async(self) -> SpiDmaBus<'d, Async> { SpiDmaBus { spi_dma: self.spi_dma.into_async(), rx_buf: self.rx_buf, @@ -1667,13 +1595,10 @@ mod dma { } } - impl<'d, T> SpiDmaBus<'d, Async, T> - where - T: Instance, - { + impl<'d> SpiDmaBus<'d, Async> { /// Converts the SPI instance into async mode. #[instability::unstable] - pub fn into_blocking(self) -> SpiDmaBus<'d, Blocking, T> { + pub fn into_blocking(self) -> SpiDmaBus<'d, Blocking> { SpiDmaBus { spi_dma: self.spi_dma.into_blocking(), rx_buf: self.rx_buf, @@ -1682,14 +1607,13 @@ mod dma { } } - impl<'d, Dm, T> SpiDmaBus<'d, Dm, T> + impl<'d, Dm> SpiDmaBus<'d, Dm> where - T: Instance, Dm: DriverMode, { /// Creates a new `SpiDmaBus` with the specified SPI instance and DMA /// buffers. - pub fn new(spi_dma: SpiDma<'d, Dm, T>, rx_buf: DmaRxBuf, tx_buf: DmaTxBuf) -> Self { + pub fn new(spi_dma: SpiDma<'d, Dm>, rx_buf: DmaRxBuf, tx_buf: DmaTxBuf) -> Self { Self { spi_dma, rx_buf, @@ -1699,16 +1623,13 @@ mod dma { /// Splits [SpiDmaBus] back into [SpiDma], [DmaRxBuf] and [DmaTxBuf]. #[instability::unstable] - pub fn split(mut self) -> (SpiDma<'d, Dm, T>, DmaRxBuf, DmaTxBuf) { + pub fn split(mut self) -> (SpiDma<'d, Dm>, DmaRxBuf, DmaTxBuf) { self.wait_for_idle(); (self.spi_dma, self.rx_buf, self.tx_buf) } } - impl InterruptConfigurable for SpiDmaBus<'_, Blocking, T> - where - T: Instance, - { + impl InterruptConfigurable for SpiDmaBus<'_, Blocking> { /// Sets the interrupt handler /// /// Interrupts are not enabled at the peripheral level here. @@ -1719,10 +1640,7 @@ mod dma { #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] - impl SpiDmaBus<'_, Blocking, T> - where - T: Instance, - { + impl SpiDmaBus<'_, Blocking> { /// Listen for the given interrupts pub fn listen(&mut self, interrupts: impl Into>) { self.spi_dma.listen(interrupts.into()); @@ -1744,9 +1662,8 @@ mod dma { } } - impl SpiDmaBus<'_, Dm, T> + impl SpiDmaBus<'_, Dm> where - T: Instance, Dm: DriverMode, { fn wait_for_idle(&mut self) { @@ -1943,9 +1860,8 @@ mod dma { #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] - impl SetConfig for SpiDmaBus<'_, Dm, T> + impl SetConfig for SpiDmaBus<'_, Dm> where - T: Instance, Dm: DriverMode, { type Config = Config; @@ -2006,10 +1922,7 @@ mod dma { #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] - impl SpiDmaBus<'_, Async, T> - where - T: Instance, - { + impl SpiDmaBus<'_, Async> { /// Fill the given buffer with data from the bus. #[instability::unstable] pub async fn read_async(&mut self, words: &mut [u8]) -> Result<(), Error> { @@ -2140,10 +2053,7 @@ mod dma { #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] - impl embedded_hal_async::spi::SpiBus for SpiDmaBus<'_, Async, T> - where - T: Instance, - { + impl embedded_hal_async::spi::SpiBus for SpiDmaBus<'_, Async> { async fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error> { self.read_async(words).await } @@ -2176,9 +2086,8 @@ mod dma { #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] - impl ErrorType for SpiDmaBus<'_, Dm, T> + impl ErrorType for SpiDmaBus<'_, Dm> where - T: Instance, Dm: DriverMode, { type Error = Error; @@ -2186,9 +2095,8 @@ mod dma { #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] - impl SpiBus for SpiDmaBus<'_, Dm, T> + impl SpiBus for SpiDmaBus<'_, Dm> where - T: Instance, Dm: DriverMode, { fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error> { @@ -2222,13 +2130,12 @@ mod ehal1 { use super::*; - impl embedded_hal::spi::ErrorType for Spi<'_, Dm, T> { + impl embedded_hal::spi::ErrorType for Spi<'_, Dm> { type Error = Error; } - impl FullDuplex for Spi<'_, Dm, T> + impl FullDuplex for Spi<'_, Dm> where - T: Instance, Dm: DriverMode, { fn read(&mut self) -> nb::Result { @@ -2240,9 +2147,8 @@ mod ehal1 { } } - impl SpiBus for Spi<'_, Dm, T> + impl SpiBus for Spi<'_, Dm> where - T: Instance, Dm: DriverMode, { fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error> { @@ -2308,10 +2214,7 @@ mod ehal1 { } } - impl SpiBusAsync for Spi<'_, Async, T> - where - T: Instance, - { + impl SpiBusAsync for Spi<'_, Async> { async fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error> { // We need to flush because the blocking transfer functions may return while a // transfer is still in progress. diff --git a/esp-hal/src/spi/slave.rs b/esp-hal/src/spi/slave.rs index 7108b4d95d..e70ca88840 100644 --- a/esp-hal/src/spi/slave.rs +++ b/esp-hal/src/spi/slave.rs @@ -94,8 +94,8 @@ const MAX_DMA_SIZE: usize = 32768 - 32; /// /// See the [module-level documentation][self] for more details. #[instability::unstable] -pub struct Spi<'d, Dm, T = AnySpi> { - spi: PeripheralRef<'d, T>, +pub struct Spi<'d, Dm> { + spi: PeripheralRef<'d, AnySpi>, #[allow(dead_code)] data_mode: Mode, _mode: PhantomData, @@ -105,18 +105,7 @@ impl<'d> Spi<'d, Blocking> { /// Constructs an SPI instance in 8bit dataframe mode. #[instability::unstable] pub fn new(spi: impl Peripheral

+ 'd, mode: Mode) -> Spi<'d, Blocking> { - Self::new_typed(spi.map_into(), mode) - } -} - -impl<'d, Dm, T> Spi<'d, Dm, T> -where - T: Instance, -{ - /// Constructs an SPI instance in 8bit dataframe mode. - #[instability::unstable] - pub fn new_typed(spi: impl Peripheral

+ 'd, mode: Mode) -> Spi<'d, Dm, T> { - crate::into_ref!(spi); + crate::into_mapped_ref!(spi); let guard = PeripheralGuard::new(spi.info().peripheral); @@ -200,10 +189,7 @@ pub mod dma { DriverMode, }; - impl<'d, T> Spi<'d, Blocking, T> - where - T: InstanceDma, - { + impl<'d> Spi<'d, Blocking> { /// Configures the SPI peripheral with the provided DMA channel and /// descriptors. #[cfg_attr(esp32, doc = "\n\n**Note**: ESP32 only supports Mode 1 and 3.")] @@ -213,9 +199,9 @@ pub mod dma { channel: impl Peripheral

+ 'd, rx_descriptors: &'static mut [DmaDescriptor], tx_descriptors: &'static mut [DmaDescriptor], - ) -> SpiDma<'d, Blocking, T> + ) -> SpiDma<'d, Blocking> where - CH: DmaChannelFor, + CH: DmaChannelFor, { self.spi.info().set_data_mode(self.data_mode, true); SpiDma::new( @@ -229,21 +215,19 @@ pub mod dma { /// A DMA capable SPI instance. #[instability::unstable] - pub struct SpiDma<'d, Dm, T = AnySpi> + pub struct SpiDma<'d, Dm> where - T: InstanceDma, Dm: DriverMode, { - pub(crate) spi: PeripheralRef<'d, T>, - pub(crate) channel: Channel<'d, Dm, PeripheralDmaChannel>, + pub(crate) spi: PeripheralRef<'d, AnySpi>, + pub(crate) channel: Channel<'d, Dm, PeripheralDmaChannel>, rx_chain: DescriptorChain, tx_chain: DescriptorChain, _guard: PeripheralGuard, } - impl core::fmt::Debug for SpiDma<'_, Dm, T> + impl core::fmt::Debug for SpiDma<'_, Dm> where - T: InstanceDma, Dm: DriverMode, { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { @@ -251,9 +235,8 @@ pub mod dma { } } - impl DmaSupport for SpiDma<'_, Dm, T> + impl DmaSupport for SpiDma<'_, Dm> where - T: InstanceDma, Dm: DriverMode, { fn peripheral_wait_dma(&mut self, is_rx: bool, is_tx: bool) { @@ -270,12 +253,11 @@ pub mod dma { } } - impl<'d, Dm, T> DmaSupportTx for SpiDma<'d, Dm, T> + impl<'d, Dm> DmaSupportTx for SpiDma<'d, Dm> where - T: InstanceDma, Dm: DriverMode, { - type TX = ChannelTx<'d, Dm, PeripheralTxChannel>; + type TX = ChannelTx<'d, Dm, PeripheralTxChannel>; fn tx(&mut self) -> &mut Self::TX { &mut self.channel.tx @@ -286,12 +268,11 @@ pub mod dma { } } - impl<'d, Dm, T> DmaSupportRx for SpiDma<'d, Dm, T> + impl<'d, Dm> DmaSupportRx for SpiDma<'d, Dm> where - T: InstanceDma, Dm: DriverMode, { - type RX = ChannelRx<'d, Dm, PeripheralRxChannel>; + type RX = ChannelRx<'d, Dm, PeripheralRxChannel>; fn rx(&mut self) -> &mut Self::RX { &mut self.channel.rx @@ -302,13 +283,10 @@ pub mod dma { } } - impl<'d, T> SpiDma<'d, Blocking, T> - where - T: InstanceDma, - { + impl<'d> SpiDma<'d, Blocking> { fn new( - spi: PeripheralRef<'d, T>, - channel: PeripheralRef<'d, PeripheralDmaChannel>, + spi: PeripheralRef<'d, AnySpi>, + channel: PeripheralRef<'d, PeripheralDmaChannel>, rx_descriptors: &'static mut [DmaDescriptor], tx_descriptors: &'static mut [DmaDescriptor], ) -> Self { @@ -326,10 +304,9 @@ pub mod dma { } } - impl SpiDma<'_, Dm, T> + impl SpiDma<'_, Dm> where Dm: DriverMode, - T: InstanceDma, { fn driver(&self) -> DmaDriver { DmaDriver { diff --git a/esp-hal/src/timer/mod.rs b/esp-hal/src/timer/mod.rs index ddbc716a2b..ab35b34b2c 100644 --- a/esp-hal/src/timer/mod.rs +++ b/esp-hal/src/timer/mod.rs @@ -119,33 +119,25 @@ pub trait Timer: Into + InterruptConfigurable + 'static + crate::priva } /// A one-shot timer. -pub struct OneShotTimer<'d, Dm, T = AnyTimer> { - inner: PeripheralRef<'d, T>, +pub struct OneShotTimer<'d, Dm> { + inner: PeripheralRef<'d, AnyTimer>, _ph: PhantomData, } impl<'d> OneShotTimer<'d, Blocking> { /// Construct a new instance of [`OneShotTimer`]. pub fn new(inner: impl Peripheral

+ 'd) -> OneShotTimer<'d, Blocking> { - Self::new_typed(inner.map_into()) - } -} - -impl<'d, T> OneShotTimer<'d, Blocking, T> -where - T: Timer, -{ - /// Construct a typed instance of [`OneShotTimer`]. - pub fn new_typed(inner: impl Peripheral

+ 'd) -> Self { - crate::into_ref!(inner); + crate::into_mapped_ref!(inner); Self { inner, _ph: PhantomData, } } +} +impl<'d> OneShotTimer<'d, Blocking> { /// Converts the driver to [`Async`] mode. - pub fn into_async(mut self) -> OneShotTimer<'d, Async, T> { + pub fn into_async(mut self) -> OneShotTimer<'d, Async> { let handler = self.inner.async_interrupt_handler(); self.inner.set_interrupt_handler(handler); OneShotTimer { @@ -155,10 +147,7 @@ where } } -impl OneShotTimer<'_, Async, T> -where - T: Timer, -{ +impl OneShotTimer<'_, Async> { /// Converts the driver to [`Blocking`] mode. pub fn into_blocking(self) -> Self { crate::interrupt::disable(Cpu::current(), self.inner.peripheral_interrupt()); @@ -167,12 +156,7 @@ where _ph: PhantomData, } } -} -impl OneShotTimer<'_, Async, T> -where - T: Timer, -{ /// Delay for *at least* `ns` nanoseconds. pub async fn delay_nanos_async(&mut self, ns: u32) { self.delay_async(MicrosDurationU64::from_ticks(ns.div_ceil(1000) as u64)) @@ -197,10 +181,9 @@ where } } -impl OneShotTimer<'_, Dm, T> +impl OneShotTimer<'_, Dm> where Dm: DriverMode, - T: Timer, { /// Delay for *at least* `ms` milliseconds. pub fn delay_millis(&mut self, ms: u32) { @@ -267,61 +250,39 @@ where } } -impl crate::private::Sealed for OneShotTimer<'_, Dm, T> -where - T: Timer, - Dm: DriverMode, -{ -} +impl crate::private::Sealed for OneShotTimer<'_, Dm> where Dm: DriverMode {} -impl InterruptConfigurable for OneShotTimer<'_, Dm, T> +impl InterruptConfigurable for OneShotTimer<'_, Dm> where Dm: DriverMode, - T: Timer, { fn set_interrupt_handler(&mut self, handler: crate::interrupt::InterruptHandler) { OneShotTimer::set_interrupt_handler(self, handler); } } -impl embedded_hal::delay::DelayNs for OneShotTimer<'_, Blocking, T> -where - T: Timer, -{ +impl embedded_hal::delay::DelayNs for OneShotTimer<'_, Blocking> { fn delay_ns(&mut self, ns: u32) { self.delay_nanos(ns); } } -impl embedded_hal_async::delay::DelayNs for OneShotTimer<'_, Async, T> -where - T: Timer, -{ +impl embedded_hal_async::delay::DelayNs for OneShotTimer<'_, Async> { async fn delay_ns(&mut self, ns: u32) { self.delay_nanos_async(ns).await } } /// A periodic timer. -pub struct PeriodicTimer<'d, Dm, T = AnyTimer> { - inner: PeripheralRef<'d, T>, +pub struct PeriodicTimer<'d, Dm> { + inner: PeripheralRef<'d, AnyTimer>, _ph: PhantomData, } impl<'d> PeriodicTimer<'d, Blocking> { /// Construct a new instance of [`PeriodicTimer`]. pub fn new(inner: impl Peripheral

+ 'd) -> PeriodicTimer<'d, Blocking> { - Self::new_typed(inner.map_into()) - } -} - -impl<'d, T> PeriodicTimer<'d, Blocking, T> -where - T: Timer, -{ - /// Construct a typed instance of [`PeriodicTimer`]. - pub fn new_typed(inner: impl Peripheral

+ 'd) -> Self { - crate::into_ref!(inner); + crate::into_mapped_ref!(inner); Self { inner, _ph: PhantomData, @@ -329,10 +290,9 @@ where } } -impl PeriodicTimer<'_, Dm, T> +impl PeriodicTimer<'_, Dm> where Dm: DriverMode, - T: Timer, { /// Start a new count down. pub fn start(&mut self, timeout: MicrosDurationU64) -> Result<(), Error> { @@ -390,12 +350,11 @@ where } } -impl crate::private::Sealed for PeriodicTimer<'_, Dm, T> where T: Timer {} +impl crate::private::Sealed for PeriodicTimer<'_, Dm> {} -impl InterruptConfigurable for PeriodicTimer<'_, Dm, T> +impl InterruptConfigurable for PeriodicTimer<'_, Dm> where Dm: DriverMode, - T: Timer, { fn set_interrupt_handler(&mut self, handler: crate::interrupt::InterruptHandler) { PeriodicTimer::set_interrupt_handler(self, handler); diff --git a/esp-hal/src/twai/mod.rs b/esp-hal/src/twai/mod.rs index 884d2e70d3..1a83d7a0dd 100644 --- a/esp-hal/src/twai/mod.rs +++ b/esp-hal/src/twai/mod.rs @@ -134,6 +134,7 @@ use crate::{ twai::filter::SingleStandardFilter, Async, Blocking, + DriverMode, }; pub mod filter; @@ -662,28 +663,26 @@ impl BaudRate { } /// An inactive TWAI peripheral in the "Reset"/configuration state. -pub struct TwaiConfiguration<'d, Dm: crate::DriverMode, T = AnyTwai> { - twai: PeripheralRef<'d, T>, +pub struct TwaiConfiguration<'d, Dm: DriverMode> { + twai: PeripheralRef<'d, AnyTwai>, filter: Option<(FilterType, [u8; 8])>, phantom: PhantomData, mode: TwaiMode, _guard: PeripheralGuard, } -impl<'d, Dm, T> TwaiConfiguration<'d, Dm, T> +impl<'d, Dm> TwaiConfiguration<'d, Dm> where - T: Instance, - Dm: crate::DriverMode, + Dm: DriverMode, { fn new_internal( - twai: impl Peripheral

+ 'd, + twai: PeripheralRef<'d, AnyTwai>, rx_pin: impl Peripheral

+ 'd, tx_pin: impl Peripheral

+ 'd, baud_rate: BaudRate, no_transceiver: bool, mode: TwaiMode, ) -> Self { - crate::into_ref!(twai); crate::into_mapped_ref!(tx_pin, rx_pin); let guard = PeripheralGuard::new(twai.peripheral()); @@ -906,7 +905,7 @@ where /// Put the peripheral into Operation Mode, allowing the transmission and /// reception of packets using the new object. - pub fn start(self) -> Twai<'d, Dm, T> { + pub fn start(self) -> Twai<'d, Dm> { self.apply_filter(); self.set_mode(self.mode); @@ -975,7 +974,8 @@ impl<'d> TwaiConfiguration<'d, Blocking> { baud_rate: BaudRate, mode: TwaiMode, ) -> Self { - Self::new_typed(peripheral.map_into(), rx_pin, tx_pin, baud_rate, mode) + crate::into_mapped_ref!(peripheral); + Self::new_internal(peripheral, rx_pin, tx_pin, baud_rate, false, mode) } /// Create a new instance of [TwaiConfiguration] meant to connect two ESP32s @@ -990,44 +990,12 @@ impl<'d> TwaiConfiguration<'d, Blocking> { baud_rate: BaudRate, mode: TwaiMode, ) -> Self { - Self::new_no_transceiver_typed(peripheral.map_into(), rx_pin, tx_pin, baud_rate, mode) - } -} - -impl<'d, T> TwaiConfiguration<'d, Blocking, T> -where - T: Instance, -{ - /// Create a new instance of [TwaiConfiguration] - /// - /// You will need to use a transceiver to connect to the TWAI bus - pub fn new_typed( - peripheral: impl Peripheral

+ 'd, - rx_pin: impl Peripheral

+ 'd, - tx_pin: impl Peripheral

+ 'd, - baud_rate: BaudRate, - mode: TwaiMode, - ) -> Self { - Self::new_internal(peripheral, rx_pin, tx_pin, baud_rate, false, mode) - } - - /// Create a new instance of [TwaiConfiguration] meant to connect two ESP32s - /// directly - /// - /// You don't need a transceiver by following the description in the - /// `twai.rs` example - pub fn new_no_transceiver_typed( - peripheral: impl Peripheral

+ 'd, - rx_pin: impl Peripheral

+ 'd, - tx_pin: impl Peripheral

+ 'd, - baud_rate: BaudRate, - mode: TwaiMode, - ) -> Self { + crate::into_mapped_ref!(peripheral); Self::new_internal(peripheral, rx_pin, tx_pin, baud_rate, true, mode) } /// Convert the configuration into an async configuration. - pub fn into_async(mut self) -> TwaiConfiguration<'d, Async, T> { + pub fn into_async(mut self) -> TwaiConfiguration<'d, Async> { self.set_interrupt_handler(self.twai.async_handler()); TwaiConfiguration { twai: self.twai, @@ -1039,12 +1007,9 @@ where } } -impl<'d, T> TwaiConfiguration<'d, Async, T> -where - T: Instance, -{ +impl<'d> TwaiConfiguration<'d, Async> { /// Convert the configuration into a blocking configuration. - pub fn into_blocking(self) -> TwaiConfiguration<'d, Blocking, T> { + pub fn into_blocking(self) -> TwaiConfiguration<'d, Blocking> { use crate::{interrupt, Cpu}; interrupt::disable(Cpu::current(), self.twai.interrupt()); @@ -1060,12 +1025,9 @@ where } } -impl crate::private::Sealed for TwaiConfiguration<'_, Blocking, T> where T: Instance {} +impl crate::private::Sealed for TwaiConfiguration<'_, Blocking> {} -impl InterruptConfigurable for TwaiConfiguration<'_, Blocking, T> -where - T: Instance, -{ +impl InterruptConfigurable for TwaiConfiguration<'_, Blocking> { fn set_interrupt_handler(&mut self, handler: crate::interrupt::InterruptHandler) { self.internal_set_interrupt_handler(handler); } @@ -1075,17 +1037,16 @@ where /// /// In this mode, the TWAI controller can transmit and receive messages /// including error signals (such as error and overload frames). -pub struct Twai<'d, Dm: crate::DriverMode, T = AnyTwai> { - twai: PeripheralRef<'d, T>, - tx: TwaiTx<'d, Dm, T>, - rx: TwaiRx<'d, Dm, T>, +pub struct Twai<'d, Dm: DriverMode> { + twai: PeripheralRef<'d, AnyTwai>, + tx: TwaiTx<'d, Dm>, + rx: TwaiRx<'d, Dm>, phantom: PhantomData, } -impl<'d, T, Dm> Twai<'d, Dm, T> +impl<'d, Dm> Twai<'d, Dm> where - T: Instance, - Dm: crate::DriverMode, + Dm: DriverMode, { fn mode(&self) -> TwaiMode { let mode = self.twai.register_block().mode().read(); @@ -1101,7 +1062,7 @@ where /// Stop the peripheral, putting it into reset mode and enabling /// reconfiguration. - pub fn stop(self) -> TwaiConfiguration<'d, Dm, T> { + pub fn stop(self) -> TwaiConfiguration<'d, Dm> { // Put the peripheral into reset/configuration mode by setting the reset mode // bit. self.twai @@ -1190,22 +1151,21 @@ where /// Consumes this `Twai` instance and splits it into transmitting and /// receiving halves. - pub fn split(self) -> (TwaiRx<'d, Dm, T>, TwaiTx<'d, Dm, T>) { + pub fn split(self) -> (TwaiRx<'d, Dm>, TwaiTx<'d, Dm>) { (self.rx, self.tx) } } /// Interface to the TWAI transmitter part. -pub struct TwaiTx<'d, Dm: crate::DriverMode, T = AnyTwai> { - twai: PeripheralRef<'d, T>, +pub struct TwaiTx<'d, Dm: DriverMode> { + twai: PeripheralRef<'d, AnyTwai>, phantom: PhantomData, _guard: PeripheralGuard, } -impl TwaiTx<'_, Dm, T> +impl TwaiTx<'_, Dm> where - T: Instance, - Dm: crate::DriverMode, + Dm: DriverMode, { /// Transmit a frame. /// @@ -1239,16 +1199,15 @@ where } /// Interface to the TWAI receiver part. -pub struct TwaiRx<'d, Dm: crate::DriverMode, T = AnyTwai> { - twai: PeripheralRef<'d, T>, +pub struct TwaiRx<'d, Dm: DriverMode> { + twai: PeripheralRef<'d, AnyTwai>, phantom: PhantomData, _guard: PeripheralGuard, } -impl TwaiRx<'_, Dm, T> +impl TwaiRx<'_, Dm> where - T: Instance, - Dm: crate::DriverMode, + Dm: DriverMode, { /// Receive a frame pub fn receive(&mut self) -> nb::Result { @@ -1335,10 +1294,9 @@ unsafe fn copy_to_data_register(dest: *mut u32, src: &[u8]) { } #[cfg(any(doc, feature = "unstable"))] -impl embedded_can::nb::Can for Twai<'_, Dm, T> +impl embedded_can::nb::Can for Twai<'_, Dm> where - T: Instance, - Dm: crate::DriverMode, + Dm: DriverMode, { type Frame = EspTwaiFrame; type Error = EspTwaiError; @@ -1699,10 +1657,7 @@ mod asynch { } } - impl Twai<'_, crate::Async, T> - where - T: Instance, - { + impl Twai<'_, Async> { /// Transmits an `EspTwaiFrame` asynchronously over the TWAI bus. pub async fn transmit_async(&mut self, frame: &EspTwaiFrame) -> Result<(), EspTwaiError> { self.tx.transmit_async(frame).await @@ -1713,10 +1668,7 @@ mod asynch { } } - impl TwaiTx<'_, crate::Async, T> - where - T: Instance, - { + impl TwaiTx<'_, Async> { /// Transmits an `EspTwaiFrame` asynchronously over the TWAI bus. pub async fn transmit_async(&mut self, frame: &EspTwaiFrame) -> Result<(), EspTwaiError> { self.twai.enable_interrupts(); @@ -1743,10 +1695,7 @@ mod asynch { } } - impl TwaiRx<'_, crate::Async, T> - where - T: Instance, - { + impl TwaiRx<'_, Async> { /// Receives an `EspTwaiFrame` asynchronously over the TWAI bus. pub async fn receive_async(&mut self) -> Result { self.twai.enable_interrupts(); diff --git a/esp-hal/src/uart.rs b/esp-hal/src/uart.rs index bfedac448c..2b99fd05cf 100644 --- a/esp-hal/src/uart.rs +++ b/esp-hal/src/uart.rs @@ -481,18 +481,17 @@ impl Default for AtCmdConfig { } } -struct UartBuilder<'d, Dm, T = AnyUart> { - uart: PeripheralRef<'d, T>, +struct UartBuilder<'d, Dm> { + uart: PeripheralRef<'d, AnyUart>, phantom: PhantomData, } -impl<'d, Dm, T> UartBuilder<'d, Dm, T> +impl<'d, Dm> UartBuilder<'d, Dm> where - T: Instance, Dm: DriverMode, { - fn new(uart: impl Peripheral

+ 'd) -> Self { - crate::into_ref!(uart); + fn new(uart: impl Peripheral

+ 'd) -> Self { + crate::into_mapped_ref!(uart); Self { uart, phantom: PhantomData, @@ -517,7 +516,7 @@ where self } - fn init(self, config: Config) -> Result, ConfigError> { + fn init(self, config: Config) -> Result, ConfigError> { let rx_guard = PeripheralGuard::new(self.uart.parts().0.peripheral); let tx_guard = PeripheralGuard::new(self.uart.parts().0.peripheral); @@ -540,21 +539,21 @@ where } /// UART (Full-duplex) -pub struct Uart<'d, Dm, T = AnyUart> { - rx: UartRx<'d, Dm, T>, - tx: UartTx<'d, Dm, T>, +pub struct Uart<'d, Dm> { + rx: UartRx<'d, Dm>, + tx: UartTx<'d, Dm>, } /// UART (Transmit) -pub struct UartTx<'d, Dm, T = AnyUart> { - uart: PeripheralRef<'d, T>, +pub struct UartTx<'d, Dm> { + uart: PeripheralRef<'d, AnyUart>, phantom: PhantomData, guard: PeripheralGuard, } /// UART (Receive) -pub struct UartRx<'d, Dm, T = AnyUart> { - uart: PeripheralRef<'d, T>, +pub struct UartRx<'d, Dm> { + uart: PeripheralRef<'d, AnyUart>, phantom: PhantomData, guard: PeripheralGuard, } @@ -585,9 +584,8 @@ impl core::fmt::Display for ConfigError { #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl SetConfig for Uart<'_, Dm, T> +impl SetConfig for Uart<'_, Dm> where - T: Instance, Dm: DriverMode, { type Config = Config; @@ -600,9 +598,8 @@ where #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl SetConfig for UartRx<'_, Dm, T> +impl SetConfig for UartRx<'_, Dm> where - T: Instance, Dm: DriverMode, { type Config = Config; @@ -615,9 +612,8 @@ where #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl SetConfig for UartTx<'_, Dm, T> +impl SetConfig for UartTx<'_, Dm> where - T: Instance, Dm: DriverMode, { type Config = Config; @@ -628,9 +624,8 @@ where } } -impl<'d, Dm, T> UartTx<'d, Dm, T> +impl<'d, Dm> UartTx<'d, Dm> where - T: Instance, Dm: DriverMode, { /// Configure RTS pin @@ -738,30 +733,13 @@ impl<'d> UartTx<'d, Blocking> { config: Config, tx: impl Peripheral

+ 'd, ) -> Result { - Self::new_typed(uart.map_into(), config, tx) - } -} - -impl<'d, T> UartTx<'d, Blocking, T> -where - T: Instance, -{ - /// Create a new UART TX instance in [`Blocking`] mode. - pub fn new_typed( - uart: impl Peripheral

+ 'd, - config: Config, - tx: impl Peripheral

+ 'd, - ) -> Result { - let (_, uart_tx) = UartBuilder::<'d, Blocking, T>::new(uart) - .with_tx(tx) - .init(config)? - .split(); + let (_, uart_tx) = UartBuilder::new(uart).with_tx(tx).init(config)?.split(); Ok(uart_tx) } /// Reconfigures the driver to operate in [`Async`] mode. - pub fn into_async(self) -> UartTx<'d, Async, T> { + pub fn into_async(self) -> UartTx<'d, Async> { if !self.uart.state().is_rx_async.load(Ordering::Acquire) { self.uart .info() @@ -777,12 +755,9 @@ where } } -impl<'d, T> UartTx<'d, Async, T> -where - T: Instance, -{ +impl<'d> UartTx<'d, Async> { /// Reconfigures the driver to operate in [`Blocking`] mode. - pub fn into_blocking(self) -> UartTx<'d, Blocking, T> { + pub fn into_blocking(self) -> UartTx<'d, Blocking> { self.uart .state() .is_tx_async @@ -819,9 +794,8 @@ fn sync_regs(_register_block: &RegisterBlock) { } } -impl<'d, Dm, T> UartRx<'d, Dm, T> +impl<'d, Dm> UartRx<'d, Dm> where - T: Instance, Dm: DriverMode, { /// Configure CTS pin @@ -951,20 +925,6 @@ impl<'d> UartRx<'d, Blocking> { uart: impl Peripheral

+ 'd, config: Config, rx: impl Peripheral

+ 'd, - ) -> Result { - UartRx::new_typed(uart.map_into(), config, rx) - } -} - -impl<'d, T> UartRx<'d, Blocking, T> -where - T: Instance, -{ - /// Create a new UART RX instance in [`Blocking`] mode. - pub fn new_typed( - uart: impl Peripheral

+ 'd, - config: Config, - rx: impl Peripheral

+ 'd, ) -> Result { let (uart_rx, _) = UartBuilder::new(uart).with_rx(rx).init(config)?.split(); @@ -972,7 +932,7 @@ where } /// Reconfigures the driver to operate in [`Async`] mode. - pub fn into_async(self) -> UartRx<'d, Async, T> { + pub fn into_async(self) -> UartRx<'d, Async> { if !self.uart.state().is_tx_async.load(Ordering::Acquire) { self.uart .info() @@ -988,12 +948,9 @@ where } } -impl<'d, T> UartRx<'d, Async, T> -where - T: Instance, -{ +impl<'d> UartRx<'d, Async> { /// Reconfigures the driver to operate in [`Blocking`] mode. - pub fn into_blocking(self) -> UartRx<'d, Blocking, T> { + pub fn into_blocking(self) -> UartRx<'d, Blocking> { self.uart .state() .is_rx_async @@ -1017,27 +974,12 @@ impl<'d> Uart<'d, Blocking> { config: Config, rx: impl Peripheral

+ 'd, tx: impl Peripheral

+ 'd, - ) -> Result { - Self::new_typed(uart.map_into(), config, rx, tx) - } -} - -impl<'d, T> Uart<'d, Blocking, T> -where - T: Instance, -{ - /// Create a new UART instance in [`Blocking`] mode. - pub fn new_typed( - uart: impl Peripheral

+ 'd, - config: Config, - rx: impl Peripheral

+ 'd, - tx: impl Peripheral

+ 'd, ) -> Result { UartBuilder::new(uart).with_tx(tx).with_rx(rx).init(config) } /// Reconfigures the driver to operate in [`Async`] mode. - pub fn into_async(self) -> Uart<'d, Async, T> { + pub fn into_async(self) -> Uart<'d, Async> { Uart { rx: self.rx.into_async(), tx: self.tx.into_async(), @@ -1045,12 +987,9 @@ where } } -impl<'d, T> Uart<'d, Async, T> -where - T: Instance, -{ +impl<'d> Uart<'d, Async> { /// Reconfigures the driver to operate in [`Blocking`] mode. - pub fn into_blocking(self) -> Uart<'d, Blocking, T> { + pub fn into_blocking(self) -> Uart<'d, Blocking> { Uart { rx: self.rx.into_blocking(), tx: self.tx.into_blocking(), @@ -1075,9 +1014,8 @@ pub enum UartInterrupt { RxFifoFull, } -impl<'d, Dm, T> Uart<'d, Dm, T> +impl<'d, Dm> Uart<'d, Dm> where - T: Instance, Dm: DriverMode, { /// Configure CTS pin @@ -1101,7 +1039,7 @@ where /// /// This is particularly useful when having two tasks correlating to /// transmitting and receiving. - pub fn split(self) -> (UartRx<'d, Dm, T>, UartTx<'d, Dm, T>) { + pub fn split(self) -> (UartRx<'d, Dm>, UartTx<'d, Dm>) { (self.rx, self.tx) } @@ -1250,22 +1188,16 @@ where } } -impl crate::private::Sealed for Uart<'_, Blocking, T> where T: Instance {} +impl crate::private::Sealed for Uart<'_, Blocking> {} -impl InterruptConfigurable for Uart<'_, Blocking, T> -where - T: Instance, -{ +impl InterruptConfigurable for Uart<'_, Blocking> { fn set_interrupt_handler(&mut self, handler: crate::interrupt::InterruptHandler) { // `self.tx.uart` and `self.rx.uart` are the same self.tx.uart.info().set_interrupt_handler(handler); } } -impl Uart<'_, Blocking, T> -where - T: Instance, -{ +impl Uart<'_, Blocking> { /// Listen for the given interrupts pub fn listen(&mut self, interrupts: impl Into>) { self.tx.uart.info().enable_listen(interrupts.into(), true) @@ -1287,9 +1219,8 @@ where } } -impl ufmt_write::uWrite for Uart<'_, Dm, T> +impl ufmt_write::uWrite for Uart<'_, Dm> where - T: Instance, Dm: DriverMode, { type Error = Error; @@ -1305,9 +1236,8 @@ where } } -impl ufmt_write::uWrite for UartTx<'_, Dm, T> +impl ufmt_write::uWrite for UartTx<'_, Dm> where - T: Instance, Dm: DriverMode, { type Error = Error; @@ -1319,9 +1249,8 @@ where } } -impl core::fmt::Write for Uart<'_, Dm, T> +impl core::fmt::Write for Uart<'_, Dm> where - T: Instance, Dm: DriverMode, { #[inline] @@ -1330,9 +1259,8 @@ where } } -impl core::fmt::Write for UartTx<'_, Dm, T> +impl core::fmt::Write for UartTx<'_, Dm> where - T: Instance, Dm: DriverMode, { #[inline] @@ -1343,21 +1271,20 @@ where } } -impl embedded_hal_nb::serial::ErrorType for Uart<'_, Dm, T> { +impl embedded_hal_nb::serial::ErrorType for Uart<'_, Dm> { type Error = Error; } -impl embedded_hal_nb::serial::ErrorType for UartTx<'_, Dm, T> { +impl embedded_hal_nb::serial::ErrorType for UartTx<'_, Dm> { type Error = Error; } -impl embedded_hal_nb::serial::ErrorType for UartRx<'_, Dm, T> { +impl embedded_hal_nb::serial::ErrorType for UartRx<'_, Dm> { type Error = Error; } -impl embedded_hal_nb::serial::Read for Uart<'_, Dm, T> +impl embedded_hal_nb::serial::Read for Uart<'_, Dm> where - T: Instance, Dm: DriverMode, { fn read(&mut self) -> nb::Result { @@ -1365,9 +1292,8 @@ where } } -impl embedded_hal_nb::serial::Read for UartRx<'_, Dm, T> +impl embedded_hal_nb::serial::Read for UartRx<'_, Dm> where - T: Instance, Dm: DriverMode, { fn read(&mut self) -> nb::Result { @@ -1375,9 +1301,8 @@ where } } -impl embedded_hal_nb::serial::Write for Uart<'_, Dm, T> +impl embedded_hal_nb::serial::Write for Uart<'_, Dm> where - T: Instance, Dm: DriverMode, { fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> { @@ -1389,9 +1314,8 @@ where } } -impl embedded_hal_nb::serial::Write for UartTx<'_, Dm, T> +impl embedded_hal_nb::serial::Write for UartTx<'_, Dm> where - T: Instance, Dm: DriverMode, { fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> { @@ -1405,27 +1329,26 @@ where #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl embedded_io::ErrorType for Uart<'_, Dm, T> { +impl embedded_io::ErrorType for Uart<'_, Dm> { type Error = Error; } #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl embedded_io::ErrorType for UartTx<'_, Dm, T> { +impl embedded_io::ErrorType for UartTx<'_, Dm> { type Error = Error; } #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl embedded_io::ErrorType for UartRx<'_, Dm, T> { +impl embedded_io::ErrorType for UartRx<'_, Dm> { type Error = Error; } #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl embedded_io::Read for Uart<'_, Dm, T> +impl embedded_io::Read for Uart<'_, Dm> where - T: Instance, Dm: DriverMode, { fn read(&mut self, buf: &mut [u8]) -> Result { @@ -1435,9 +1358,8 @@ where #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl embedded_io::Read for UartRx<'_, Dm, T> +impl embedded_io::Read for UartRx<'_, Dm> where - T: Instance, Dm: DriverMode, { fn read(&mut self, buf: &mut [u8]) -> Result { @@ -1455,9 +1377,8 @@ where #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl embedded_io::ReadReady for Uart<'_, Dm, T> +impl embedded_io::ReadReady for Uart<'_, Dm> where - T: Instance, Dm: DriverMode, { fn read_ready(&mut self) -> Result { @@ -1467,9 +1388,8 @@ where #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl embedded_io::ReadReady for UartRx<'_, Dm, T> +impl embedded_io::ReadReady for UartRx<'_, Dm> where - T: Instance, Dm: DriverMode, { fn read_ready(&mut self) -> Result { @@ -1479,9 +1399,8 @@ where #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl embedded_io::Write for Uart<'_, Dm, T> +impl embedded_io::Write for Uart<'_, Dm> where - T: Instance, Dm: DriverMode, { fn write(&mut self, buf: &[u8]) -> Result { @@ -1495,9 +1414,8 @@ where #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl embedded_io::Write for UartTx<'_, Dm, T> +impl embedded_io::Write for UartTx<'_, Dm> where - T: Instance, Dm: DriverMode, { fn write(&mut self, buf: &[u8]) -> Result { @@ -1701,10 +1619,7 @@ impl Drop for UartTxFuture { } } -impl Uart<'_, Async, T> -where - T: Instance, -{ +impl Uart<'_, Async> { /// Asynchronously reads data from the UART receive buffer into the /// provided buffer. pub async fn read_async(&mut self, buf: &mut [u8]) -> Result { @@ -1722,10 +1637,7 @@ where } } -impl UartTx<'_, Async, T> -where - T: Instance, -{ +impl UartTx<'_, Async> { /// Asynchronously writes data to the UART transmit buffer in chunks. /// /// This function sends the contents of the provided buffer `words` over @@ -1772,10 +1684,7 @@ where } } -impl UartRx<'_, Async, T> -where - T: Instance, -{ +impl UartRx<'_, Async> { /// Read async to buffer slice `buf`. /// Waits until at least one byte is in the Rx FiFo /// and one of the following interrupts occurs: @@ -1854,10 +1763,7 @@ where #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl embedded_io_async::Read for Uart<'_, Async, T> -where - T: Instance, -{ +impl embedded_io_async::Read for Uart<'_, Async> { /// In contrast to the documentation of embedded_io_async::Read, this /// method blocks until an uart interrupt occurs. /// See UartRx::read_async for more details. @@ -1868,10 +1774,7 @@ where #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl embedded_io_async::Read for UartRx<'_, Async, T> -where - T: Instance, -{ +impl embedded_io_async::Read for UartRx<'_, Async> { /// In contrast to the documentation of embedded_io_async::Read, this /// method blocks until an uart interrupt occurs. /// See UartRx::read_async for more details. @@ -1882,10 +1785,7 @@ where #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl embedded_io_async::Write for Uart<'_, Async, T> -where - T: Instance, -{ +impl embedded_io_async::Write for Uart<'_, Async> { async fn write(&mut self, buf: &[u8]) -> Result { self.write_async(buf).await } @@ -1897,10 +1797,7 @@ where #[cfg(any(doc, feature = "unstable"))] #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))] -impl embedded_io_async::Write for UartTx<'_, Async, T> -where - T: Instance, -{ +impl embedded_io_async::Write for UartTx<'_, Async> { async fn write(&mut self, buf: &[u8]) -> Result { self.write_async(buf).await } diff --git a/esp-wifi/src/lib.rs b/esp-wifi/src/lib.rs index 4fa728485e..5d824d0c5f 100644 --- a/esp-wifi/src/lib.rs +++ b/esp-wifi/src/lib.rs @@ -234,7 +234,7 @@ const _: () = { core::assert!(CONFIG.rx_ba_win < (CONFIG.static_rx_buf_num * 2), "WiFi configuration check: rx_ba_win should not be larger than double of the static_rx_buf_num!"); }; -type TimeBase = PeriodicTimer<'static, Blocking, AnyTimer>; +type TimeBase = PeriodicTimer<'static, Blocking>; pub(crate) mod flags { use portable_atomic::{AtomicBool, AtomicUsize}; diff --git a/hil-test/tests/embassy_timers_executors.rs b/hil-test/tests/embassy_timers_executors.rs index 942b287ce9..95c98e404d 100644 --- a/hil-test/tests/embassy_timers_executors.rs +++ b/hil-test/tests/embassy_timers_executors.rs @@ -64,7 +64,7 @@ mod test_cases { } pub fn run_test_periodic_timer(timer: impl Peripheral

) { - let mut periodic = PeriodicTimer::new_typed(timer); + let mut periodic = PeriodicTimer::new(timer); let t1 = esp_hal::time::now(); periodic.start(100.millis()).unwrap(); @@ -81,7 +81,7 @@ mod test_cases { } pub fn run_test_oneshot_timer(timer: impl Peripheral

) { - let mut timer = OneShotTimer::new_typed(timer); + let mut timer = OneShotTimer::new(timer); let t1 = esp_hal::time::now(); timer.delay_millis(50); diff --git a/hil-test/tests/spi_full_duplex.rs b/hil-test/tests/spi_full_duplex.rs index 683e627e64..20b68921bb 100644 --- a/hil-test/tests/spi_full_duplex.rs +++ b/hil-test/tests/spi_full_duplex.rs @@ -14,7 +14,6 @@ use esp_hal::{ dma::{DmaDescriptor, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{Level, NoPin}, - peripheral::Peripheral, spi::master::{Config, Spi}, time::RateExtU32, Blocking,