Remove AnyInputOnlyPin (#2071)

* Remove AnyInputOnlyPin

* Add section to migration guide

* Remove unnecessary enum

Co-authored-by: Dominic Fischer <14130965+Dominaezzz@users.noreply.github.com>

---------

Co-authored-by: Dominic Fischer <14130965+Dominaezzz@users.noreply.github.com>
Co-authored-by: Jesse Braham <jessebraham@users.noreply.github.com>
This commit is contained in:
Dániel Buga 2024-09-04 17:11:08 +02:00 committed by GitHub
parent 39109a4a05
commit e898e89f60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 115 deletions

View File

@ -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 `async`, `embedded-hal-02`, `embedded-hal`, `embedded-io`, `embedded-io-async`, and `ufmt` features (#2070)
- Removed the `GpioN` type aliasses. Use `GpioPin<N>` instead. (#2073) - Removed the `GpioN` type aliasses. Use `GpioPin<N>` instead. (#2073)
- Removed `Peripherals::take`. Use `esp_hal::init` to obtain `Peripherals` (#1999) - Removed `Peripherals::take`. Use `esp_hal::init` to obtain `Peripherals` (#1999)
- Removed `AnyInputOnlyPin` in favour of `AnyPin`. (#2071)
## [0.20.1] - 2024-08-30 ## [0.20.1] - 2024-08-30

View File

@ -38,4 +38,6 @@ Instead of manually grabbing peripherals and setting up clocks, you should now c
## GPIO changes ## GPIO changes
The `GpioN` type aliasses are no longer available. You can use `GpioPin<N>` instead. - The `GpioN` type aliasses are no longer available. You can use `GpioPin<N>` instead.
- The `AnyInputOnlyPin` has been removed. Replace any use with `AnyPin`.
- The `NoPinType` has been removed. You can use `DummyPin` in its place.

View File

@ -1,39 +1,25 @@
use super::*; use super::*;
#[derive(Clone, Copy)] /// A type-erased GPIO pin, with additional configuration options.
enum Inverted { ///
NonInverted, /// Note that accessing unsupported pin functions (e.g. trying to use an
Inverted, /// input-only pin as output) will panic.
}
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.
pub struct AnyPin<'d> { pub struct AnyPin<'d> {
pin: ErasedPin, pin: ErasedPin,
inverted: Inverted, is_inverted: bool,
_phantom: PhantomData<&'d ()>, _phantom: PhantomData<&'d ()>,
} }
impl<'d> AnyPin<'d> { impl<'d> AnyPin<'d> {
/// Create wrapper for the given pin. /// Create wrapper for the given pin.
#[inline] #[inline]
pub fn new<P: OutputPin + InputPin + CreateErasedPin>( pub fn new<P: CreateErasedPin>(pin: impl crate::peripheral::Peripheral<P = P> + 'd) -> Self {
pin: impl crate::peripheral::Peripheral<P = P> + 'd,
) -> Self {
crate::into_ref!(pin); crate::into_ref!(pin);
let pin = pin.erased_pin(private::Internal); let pin = pin.erased_pin(private::Internal);
Self { Self {
pin, pin,
inverted: Inverted::NonInverted, is_inverted: false,
_phantom: PhantomData, _phantom: PhantomData,
} }
} }
@ -49,7 +35,7 @@ impl<'d> AnyPin<'d> {
Self { Self {
pin, pin,
inverted: Inverted::Inverted, is_inverted: true,
_phantom: PhantomData, _phantom: PhantomData,
} }
} }
@ -61,7 +47,7 @@ impl<'d> crate::peripheral::Peripheral for AnyPin<'d> {
unsafe fn clone_unchecked(&mut self) -> Self::P { unsafe fn clone_unchecked(&mut self) -> Self::P {
Self { Self {
pin: unsafe { self.pin.clone_unchecked() }, pin: unsafe { self.pin.clone_unchecked() },
inverted: self.inverted, is_inverted: self.is_inverted,
_phantom: PhantomData, _phantom: PhantomData,
} }
} }
@ -114,10 +100,10 @@ impl<'d> OutputPin for AnyPin<'d> {
fn connect_peripheral_to_output(&mut self, signal: OutputSignal, _internal: private::Internal) { fn connect_peripheral_to_output(&mut self, signal: OutputSignal, _internal: private::Internal) {
self.pin.connect_peripheral_to_output_with_options( self.pin.connect_peripheral_to_output_with_options(
signal, signal,
self.inverted.is_inverted(), self.is_inverted,
false, false,
false, false,
self.inverted.is_inverted(), self.is_inverted,
private::Internal, private::Internal,
); );
} }
@ -131,7 +117,7 @@ impl<'d> OutputPin for AnyPin<'d> {
force_via_gpio_mux: bool, force_via_gpio_mux: bool,
_internal: private::Internal, _internal: private::Internal,
) { ) {
if self.inverted.is_inverted() { if self.is_inverted {
self.pin.connect_peripheral_to_output_with_options( self.pin.connect_peripheral_to_output_with_options(
signal, signal,
true, true,
@ -168,8 +154,8 @@ impl<'d> InputPin for AnyPin<'d> {
fn connect_input_to_peripheral(&mut self, signal: InputSignal, _internal: private::Internal) { fn connect_input_to_peripheral(&mut self, signal: InputSignal, _internal: private::Internal) {
self.pin.connect_input_to_peripheral_with_options( self.pin.connect_input_to_peripheral_with_options(
signal, signal,
self.inverted.is_inverted(), self.is_inverted,
self.inverted.is_inverted(), self.is_inverted,
private::Internal, private::Internal,
); );
} }
@ -181,7 +167,7 @@ impl<'d> InputPin for AnyPin<'d> {
force_via_gpio_mux: bool, force_via_gpio_mux: bool,
_internal: private::Internal, _internal: private::Internal,
) { ) {
if self.inverted.is_inverted() { if self.is_inverted {
self.pin.connect_input_to_peripheral_with_options( self.pin.connect_input_to_peripheral_with_options(
signal, signal,
true, 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<P: InputPin + CreateErasedPin>(
pin: impl crate::peripheral::Peripheral<P = P> + '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);
}
}
}

View File

@ -25,8 +25,7 @@
//! - [Input] pins can be used as digital inputs. //! - [Input] pins can be used as digital inputs.
//! - [Output] and [OutputOpenDrain] pins can be used as digital outputs. //! - [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. //! - [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 //! - [AnyPin] is a type-erased GPIO pin with support for inverted signalling.
//! inverted signalling.
//! - [DummyPin] is a useful for cases where peripheral driver requires a pin, //! - [DummyPin] is a useful for cases where peripheral driver requires a pin,
//! but real pin cannot be used. //! but real pin cannot be used.
//! //!
@ -77,7 +76,7 @@ pub(crate) use crate::{touch_common, touch_into};
mod any_pin; mod any_pin;
mod dummy_pin; mod dummy_pin;
pub use any_pin::{AnyInputOnlyPin, AnyPin}; pub use any_pin::AnyPin;
pub use dummy_pin::DummyPin; pub use dummy_pin::DummyPin;
#[cfg(soc_etm)] #[cfg(soc_etm)]