Skip to content

Commit

Permalink
Constrain Flex conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Nov 4, 2024
1 parent 40457a6 commit c6ce9f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
3 changes: 3 additions & 0 deletions esp-hal/MIGRATING-0.21.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,6 @@ The previous signal function have been replaced by `split`. This change affects
-let output_signal = gpioN.into_peripheral_output();
+let (input_signal, output_signal) = gpioN.split();
```

`into_peripheral_output`, `split` (for output pins only) and `peripheral_input` have been added to
the GPIO drivers (`Input`, `Output`, `OutputOpenDrain` and `Flex`) instead.
41 changes: 18 additions & 23 deletions esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,14 +1526,6 @@ where
Self { pin }
}

/// Split the pin into an input and output signal.
///
/// Peripheral signals allow connecting peripherals together without using
/// external hardware.
pub fn split(self) -> (interconnect::InputSignal, interconnect::OutputSignal) {
self.pin.degrade_pin(private::Internal).split()
}

/// Returns a peripheral [input][interconnect::InputSignal] connected to
/// this pin.
///
Expand All @@ -1542,16 +1534,6 @@ where
pub fn peripheral_input(&self) -> interconnect::InputSignal {
self.pin.degrade_pin(private::Internal).split().0
}

/// Turns the pin object into a peripheral
/// [output][interconnect::OutputSignal].
///
/// The output signal can be passed to peripherals in place of an output
/// pin.
#[inline]
pub fn into_peripheral_output(self) -> interconnect::OutputSignal {
self.split().1
}
}

impl<P> Flex<'_, P>
Expand Down Expand Up @@ -1701,17 +1683,30 @@ where
pub fn set_drive_strength(&mut self, strength: DriveStrength) {
self.pin.set_drive_strength(strength, private::Internal);
}
}

impl<P> Flex<'_, P>
where
P: InputPin + OutputPin,
{
/// Set the GPIO to open-drain mode.
pub fn set_as_open_drain(&mut self, pull: Pull) {
self.pin.set_to_open_drain_output(private::Internal);
self.pin.pull_direction(pull, private::Internal);
}

/// Split the pin into an input and output signal.
///
/// Peripheral signals allow connecting peripherals together without using
/// external hardware.
pub fn split(self) -> (interconnect::InputSignal, interconnect::OutputSignal) {
self.pin.degrade_pin(private::Internal).split()
}

/// Turns the pin object into a peripheral
/// [output][interconnect::OutputSignal].
///
/// The output signal can be passed to peripherals in place of an output
/// pin.
#[inline]
pub fn into_peripheral_output(self) -> interconnect::OutputSignal {
self.split().1
}
}

pub(crate) mod internal {
Expand Down

0 comments on commit c6ce9f3

Please sign in to comment.