Skip to content

Commit

Permalink
Remove unnecessary enum
Browse files Browse the repository at this point in the history
Co-authored-by: Dominic Fischer <[email protected]>
  • Loading branch information
bugadani and Dominaezzz committed Sep 3, 2024
1 parent 9edd024 commit 83ce2e7
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions esp-hal/src/gpio/any_pin.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
use super::*;

#[derive(Clone, Copy)]
enum Inverted {
NonInverted,
Inverted,
}

impl Inverted {
fn is_inverted(&self) -> bool {
match self {
Inverted::NonInverted => false,
Inverted::Inverted => true,
}
}
}

/// 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 ()>,
}

Expand All @@ -34,7 +19,7 @@ impl<'d> AnyPin<'d> {

Self {
pin,
inverted: Inverted::NonInverted,
is_inverted: false,
_phantom: PhantomData,
}
}
Expand All @@ -50,7 +35,7 @@ impl<'d> AnyPin<'d> {

Self {
pin,
inverted: Inverted::Inverted,
is_inverted: true,
_phantom: PhantomData,
}
}
Expand All @@ -62,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,
}
}
Expand Down Expand Up @@ -115,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,
);
}
Expand All @@ -132,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,
Expand Down Expand Up @@ -169,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,
);
}
Expand All @@ -182,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,
Expand Down

0 comments on commit 83ce2e7

Please sign in to comment.