diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 3da5f9506f2..8fff1f229f4 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed the `async`, `embedded-hal-02`, `embedded-hal`, `embedded-io`, `embedded-io-async`, and `ufmt` features (#2070) - Removed the `GpioN` type aliasses. Use `GpioPin` instead. (#2073) - Removed `Peripherals::take`. Use `esp_hal::init` to obtain `Peripherals` (#1999) +- Removed `AnyInputOnlyPin` in favour of `AnyPin`. (#2071) ## [0.20.1] - 2024-08-30 diff --git a/esp-hal/MIGRATING-0.20.md b/esp-hal/MIGRATING-0.20.md index 6c6da2d65b6..4902d004644 100644 --- a/esp-hal/MIGRATING-0.20.md +++ b/esp-hal/MIGRATING-0.20.md @@ -38,4 +38,6 @@ Instead of manually grabbing peripherals and setting up clocks, you should now c ## GPIO changes -The `GpioN` type aliasses are no longer available. You can use `GpioPin` instead. + - The `GpioN` type aliasses are no longer available. You can use `GpioPin` instead. + - The `AnyInputOnlyPin` has been removed. Replace any use with `AnyPin`. + - The `NoPinType` has been removed. You can use `DummyPin` in its place. diff --git a/esp-hal/src/gpio/any_pin.rs b/esp-hal/src/gpio/any_pin.rs index 640ce8dafa7..e82e48acaf3 100644 --- a/esp-hal/src/gpio/any_pin.rs +++ b/esp-hal/src/gpio/any_pin.rs @@ -1,39 +1,25 @@ use super::*; -#[derive(Clone, Copy)] -enum Inverted { - NonInverted, - Inverted, -} - -impl Inverted { - fn is_inverted(&self) -> bool { - match self { - Inverted::NonInverted => false, - Inverted::Inverted => true, - } - } -} - -/// Generic pin wrapper for pins which can be Output or Input. +/// A type-erased GPIO pin, with additional configuration options. +/// +/// Note that accessing unsupported pin functions (e.g. trying to use an +/// input-only pin as output) will panic. pub struct AnyPin<'d> { pin: ErasedPin, - inverted: Inverted, + is_inverted: bool, _phantom: PhantomData<&'d ()>, } impl<'d> AnyPin<'d> { /// Create wrapper for the given pin. #[inline] - pub fn new( - pin: impl crate::peripheral::Peripheral

+ 'd, - ) -> Self { + pub fn new(pin: impl crate::peripheral::Peripheral

+ 'd) -> Self { crate::into_ref!(pin); let pin = pin.erased_pin(private::Internal); Self { pin, - inverted: Inverted::NonInverted, + is_inverted: false, _phantom: PhantomData, } } @@ -49,7 +35,7 @@ impl<'d> AnyPin<'d> { Self { pin, - inverted: Inverted::Inverted, + is_inverted: true, _phantom: PhantomData, } } @@ -61,7 +47,7 @@ impl<'d> crate::peripheral::Peripheral for AnyPin<'d> { unsafe fn clone_unchecked(&mut self) -> Self::P { Self { pin: unsafe { self.pin.clone_unchecked() }, - inverted: self.inverted, + is_inverted: self.is_inverted, _phantom: PhantomData, } } @@ -114,10 +100,10 @@ impl<'d> OutputPin for AnyPin<'d> { fn connect_peripheral_to_output(&mut self, signal: OutputSignal, _internal: private::Internal) { self.pin.connect_peripheral_to_output_with_options( signal, - self.inverted.is_inverted(), + self.is_inverted, false, false, - self.inverted.is_inverted(), + self.is_inverted, private::Internal, ); } @@ -131,7 +117,7 @@ impl<'d> OutputPin for AnyPin<'d> { force_via_gpio_mux: bool, _internal: private::Internal, ) { - if self.inverted.is_inverted() { + if self.is_inverted { self.pin.connect_peripheral_to_output_with_options( signal, true, @@ -168,8 +154,8 @@ impl<'d> InputPin for AnyPin<'d> { fn connect_input_to_peripheral(&mut self, signal: InputSignal, _internal: private::Internal) { self.pin.connect_input_to_peripheral_with_options( signal, - self.inverted.is_inverted(), - self.inverted.is_inverted(), + self.is_inverted, + self.is_inverted, private::Internal, ); } @@ -181,7 +167,7 @@ impl<'d> InputPin for AnyPin<'d> { force_via_gpio_mux: bool, _internal: private::Internal, ) { - if self.inverted.is_inverted() { + if self.is_inverted { self.pin.connect_input_to_peripheral_with_options( signal, true, @@ -198,85 +184,3 @@ impl<'d> InputPin for AnyPin<'d> { } } } - -/// Generic pin wrapper for pins which can only be Input. -pub struct AnyInputOnlyPin<'d> { - pin: ErasedPin, - inverted: Inverted, - _phantom: PhantomData<&'d ()>, -} - -impl<'d> AnyInputOnlyPin<'d> { - /// Create wrapper for the given pin. - #[inline] - pub fn new( - pin: impl crate::peripheral::Peripheral

+ 'd, - ) -> Self { - crate::into_ref!(pin); - let pin = pin.erased_pin(private::Internal); - - Self { - pin, - inverted: Inverted::NonInverted, - _phantom: PhantomData, - } - } -} - -impl<'d> crate::peripheral::Peripheral for AnyInputOnlyPin<'d> { - type P = Self; - - unsafe fn clone_unchecked(&mut self) -> Self::P { - Self { - pin: unsafe { self.pin.clone_unchecked() }, - inverted: self.inverted, - _phantom: PhantomData, - } - } -} - -impl<'d> private::Sealed for AnyInputOnlyPin<'d> {} - -impl<'d> Pin for AnyInputOnlyPin<'d> { - delegate::delegate! { - to self.pin { - fn number(&self, _internal: private::Internal) -> u8; - fn sleep_mode(&mut self, on: bool, _internal: private::Internal); - fn set_alternate_function(&mut self, alternate: AlternateFunction, _internal: private::Internal); - fn is_listening(&self, _internal: private::Internal) -> bool; - fn listen_with_options( - &mut self, - event: Event, - int_enable: bool, - nmi_enable: bool, - wake_up_from_light_sleep: bool, - _internal: private::Internal, - ); - fn unlisten(&mut self, _internal: private::Internal); - fn is_interrupt_set(&self, _internal: private::Internal) -> bool; - fn clear_interrupt(&mut self, _internal: private::Internal); - fn wakeup_enable(&mut self, enable: bool, event: WakeEvent, _internal: private::Internal); - } - } -} - -impl<'d> InputPin for AnyInputOnlyPin<'d> { - delegate::delegate! { - to self.pin { - fn init_input(&self, pull_down: bool, pull_up: bool, _internal: private::Internal); - fn set_to_input(&mut self, _internal: private::Internal); - fn enable_input(&mut self, on: bool, _internal: private::Internal); - fn enable_input_in_sleep_mode(&mut self, on: bool, _internal: private::Internal); - fn is_input_high(&self, _internal: private::Internal) -> bool; - fn connect_input_to_peripheral(&mut self, signal: InputSignal, _internal: private::Internal); - fn connect_input_to_peripheral_with_options( - &mut self, - signal: InputSignal, - invert: bool, - force_via_gpio_mux: bool, - _internal: private::Internal, - ); - fn disconnect_input_from_peripheral(&mut self, signal: InputSignal, _internal: private::Internal); - } - } -} diff --git a/esp-hal/src/gpio/mod.rs b/esp-hal/src/gpio/mod.rs index 4db777a39d0..7cb0c93aac2 100644 --- a/esp-hal/src/gpio/mod.rs +++ b/esp-hal/src/gpio/mod.rs @@ -25,8 +25,7 @@ //! - [Input] pins can be used as digital inputs. //! - [Output] and [OutputOpenDrain] pins can be used as digital outputs. //! - [Flex] pin is a pin that can be used as an input and output pin. -//! - [AnyPin] and [AnyInputOnlyPin] are type-erased GPIO pins with support for -//! inverted signalling. +//! - [AnyPin] is a type-erased GPIO pin with support for inverted signalling. //! - [DummyPin] is a useful for cases where peripheral driver requires a pin, //! but real pin cannot be used. //! @@ -77,7 +76,7 @@ pub(crate) use crate::{touch_common, touch_into}; mod any_pin; mod dummy_pin; -pub use any_pin::{AnyInputOnlyPin, AnyPin}; +pub use any_pin::AnyPin; pub use dummy_pin::DummyPin; #[cfg(soc_etm)]